feat: add /stop command to kill running agent process

- /stop, /cancel, /kill aliases all supported
- SIGTERM first (allows graceful AbortController cleanup), SIGKILL after 5s
- Wired through session-commands → GroupQueue.killProcess()
This commit is contained in:
Eyejoker
2026-03-29 18:44:37 +09:00
parent d01f98bd61
commit 2ec90fe086
4 changed files with 53 additions and 1 deletions

View File

@@ -503,6 +503,43 @@ export class GroupQueue {
}
}
/**
* Immediately kill the running agent process for a group.
* Returns true if a process was killed, false if nothing was running.
*/
killProcess(groupJid: string): boolean {
const state = this.getGroup(groupJid);
const proc = state.process;
if (!proc || !this.isProcessAlive(proc)) {
return false;
}
logger.info(
{
groupJid,
runId: state.currentRunId,
processName: state.processName,
},
'Killing agent process via /stop command',
);
try {
// SIGTERM allows the runner to call AbortController.abort() for graceful cleanup.
// Falls back to SIGKILL after 5 seconds if the process doesn't exit.
proc.kill('SIGTERM');
setTimeout(() => {
if (this.isProcessAlive(proc)) {
try {
proc.kill('SIGKILL');
} catch {
/* already dead */
}
}
}, 5000);
} catch {
/* already dead */
}
return true;
}
private async runForGroup(
groupJid: string,
reason: 'messages' | 'drain',