feat: replace session commands with a natural-language stop

Remove the /compact, /clear and /stop session commands. They were gated
to the main room or SESSION_COMMAND_ALLOWED_SENDERS, neither of which
exists in this deployment, so nobody could use them. The agent-runner
/compact passthrough goes with them.

Instead, a short human message whose whole intent is "stop" (그만, 멈춰,
중단해, 하지 마, 취소, stop, cancel, ...; see src/stop-intent.ts) stops the
room when it has something to stop: a running or queued run, an open
paired task, or unprocessed human messages before it. The message loop
then
- advances the room cursors past the stop message (memory + router_state)
- completes the open paired task as user_stopped, cancels its open turns
  and drops its execution lease
- closes stdin with a user-stop reason and kills the agent through the
  existing GroupQueue.closeStdin/killProcess
- replies "진행 중이던 작업을 중단했습니다." once
When nothing is running the message is handled as a normal message.

The user-stop close reason is treated like a human interruption, so the
killed paired turn releases its lease without counting a failure and
queues no follow-up, and the turn controller does not post the generic
failure text on top of the stop reply.

advanceLastAgentCursor no longer moves a cursor backwards, so a run that
finishes after the stop cannot rewind the cursor and re-dispatch the
stop message (the respawn seen when an agent was only killed).

Stale SESSION_COMMAND_* keys in .env are now ignored instead of failing
startup.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Codex
2026-10-01 19:26:10 +09:00
parent fe7c5a7b23
commit ce4547daa6
40 changed files with 949 additions and 1084 deletions

View File

@@ -14,11 +14,7 @@ import {
shouldSkipBotOnlyCollaboration,
} from './message-runtime-rules.js';
import { enqueuePairedFollowUpAfterEvent } from './message-runtime-follow-up.js';
import {
extractSessionCommand,
isSessionCommandAllowed,
} from './session-commands.js';
import { isSessionCommandSenderAllowed } from './config.js';
import { stopRoomWorkIfRequested, type RoomStopControls } from './room-stop.js';
import { hasReviewerLease } from './service-routing.js';
import type { ExecuteTurnFn } from './message-runtime-types.js';
import type { ScheduledPairedFollowUpIntentKind } from './paired-follow-up-scheduler.js';
@@ -224,7 +220,6 @@ export async function processLoopGroupMessages(args: {
channel: Channel;
assistantName: string;
failureFinalText: string;
triggerPattern: RegExp;
hasImplicitContinuationWindow: (
chatJid: string,
messages: NewMessage[],
@@ -242,11 +237,11 @@ export async function processLoopGroupMessages(args: {
sendQueuedMessage: (chatJid: string, text: string) => boolean;
closeStdin: (reason: string) => void;
isRunningMessageTurn: (chatJid: string) => boolean;
roomStopControls: RoomStopControls;
labelPairedSenders: (chatJid: string, messages: NewMessage[]) => NewMessage[];
formatMessages: (messages: NewMessage[], timezone: string) => string;
}): Promise<void> {
const { chatJid, group, groupMessages, channel } = args;
const isMainGroup = group.isMain === true;
const processableGroupMessages = getProcessableMessages(
chatJid,
groupMessages,
@@ -284,21 +279,20 @@ export async function processLoopGroupMessages(args: {
return;
}
const loopCmdMsg = groupMessages.find(
(msg) => extractSessionCommand(msg.content, args.triggerPattern) !== null,
);
if (loopCmdMsg) {
if (
isSessionCommandAllowed(
isMainGroup,
loopCmdMsg.is_from_me === true,
isSessionCommandSenderAllowed(loopCmdMsg.sender),
)
) {
args.closeStdin('session-command-detected');
const stopResult = await stopRoomWorkIfRequested({
chatJid,
group,
channel,
messages: processableGroupMessages,
assistantName: args.assistantName,
lastAgentTimestamps: args.lastAgentTimestamps,
saveState: args.saveState,
controls: args.roomStopControls,
});
if (stopResult.stopped) {
if (stopResult.hasMessagesAfterStop) {
args.enqueueMessageCheck();
}
args.enqueueMessageCheck();
return;
}