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:
@@ -18,7 +18,12 @@ import {
|
||||
} from './message-runtime-turns.js';
|
||||
import { handleMessageRuntimeAfterDeliverySuccess } from './message-runtime-after-delivery.js';
|
||||
import { deliverMessageRuntimeFinalText } from './message-runtime-final-delivery.js';
|
||||
import { createProcessGroupMessages } from './message-runtime-group-processing.js';
|
||||
import {
|
||||
createProcessGroupMessages,
|
||||
deliverRoomNotice,
|
||||
} from './message-runtime-group-processing.js';
|
||||
import { USER_STOP_CLOSE_REASON } from './message-close-reasons.js';
|
||||
import type { RoomStopControls } from './room-stop.js';
|
||||
|
||||
export { isDuplicateOfLastBotFinal };
|
||||
|
||||
@@ -27,7 +32,6 @@ export interface MessageRuntimeDeps {
|
||||
idleTimeout: number;
|
||||
pollInterval: number;
|
||||
timezone: string;
|
||||
triggerPattern: RegExp;
|
||||
channels: Channel[];
|
||||
queue: GroupQueue;
|
||||
getRoomBindings: () => Record<string, RegisteredGroup>;
|
||||
@@ -66,6 +70,26 @@ function createStartMessageLoop(args: {
|
||||
};
|
||||
}
|
||||
|
||||
function createRoomStopControls(
|
||||
deps: Pick<MessageRuntimeDeps, 'queue' | 'channels' | 'getRoomBindings'>,
|
||||
): RoomStopControls {
|
||||
return {
|
||||
hasQueuedWork: (chatJid) =>
|
||||
(deps.queue.getStatuses([chatJid])[0]?.status ?? 'inactive') !==
|
||||
'inactive',
|
||||
stopRunningAgent: (chatJid) => {
|
||||
deps.queue.closeStdin(chatJid, { reason: USER_STOP_CLOSE_REASON });
|
||||
return deps.queue.killProcess(chatJid);
|
||||
},
|
||||
sendReply: (chatJid, text) =>
|
||||
deliverRoomNotice(
|
||||
{ channels: deps.channels, getRoomBindings: deps.getRoomBindings },
|
||||
chatJid,
|
||||
text,
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
export function createMessageRuntime(deps: MessageRuntimeDeps): {
|
||||
processGroupMessages: (
|
||||
chatJid: string,
|
||||
@@ -181,28 +205,25 @@ export function createMessageRuntime(deps: MessageRuntimeDeps): {
|
||||
assistantName: deps.assistantName,
|
||||
failureFinalText: FAILURE_FINAL_TEXT,
|
||||
timezone: deps.timezone,
|
||||
triggerPattern: deps.triggerPattern,
|
||||
channels: deps.channels,
|
||||
queue: deps.queue,
|
||||
getRoomBindings: deps.getRoomBindings,
|
||||
getLastAgentTimestamps: deps.getLastAgentTimestamps,
|
||||
saveState: deps.saveState,
|
||||
clearSession: deps.clearSession,
|
||||
runAgent,
|
||||
executeTurn,
|
||||
hasImplicitContinuationWindow: continuationTracker.has,
|
||||
openContinuation: continuationTracker.open,
|
||||
isDuplicateOfLastBotFinal: checkDuplicateOfLastBotFinal,
|
||||
labelPairedSenders: labelPairedRuntimeSenders,
|
||||
});
|
||||
|
||||
const roomStopControls = createRoomStopControls(deps);
|
||||
|
||||
const startMessageLoop = createStartMessageLoop({
|
||||
pollInterval: deps.pollInterval,
|
||||
processTick: async () => {
|
||||
await processMessageLoopTick({
|
||||
assistantName: deps.assistantName,
|
||||
failureFinalText: FAILURE_FINAL_TEXT,
|
||||
triggerPattern: deps.triggerPattern,
|
||||
timezone: deps.timezone,
|
||||
channels: deps.channels,
|
||||
getRoomBindings: deps.getRoomBindings,
|
||||
@@ -222,6 +243,7 @@ export function createMessageRuntime(deps: MessageRuntimeDeps): {
|
||||
}),
|
||||
isRunningMessageTurn: (chatJid) =>
|
||||
deps.queue.getStatuses([chatJid])[0]?.runPhase === 'running_messages',
|
||||
roomStopControls,
|
||||
labelPairedSenders: labelPairedRuntimeSenders,
|
||||
});
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user