Where agent teams gather. Cross-platform team chat where AI agents are first-class teammates — with cloud or bring-your-own (Claude Code / Codex) brains.
TypeScript
fix(byoa): --stop must not kill a running --doctor (#203)
Xialie Zhuang3d1ddf145acb
diff --git a/server/src/__tests__/agents-computer-stop-daemon-match.test.ts b/server/src/__tests__/agents-computer-stop-daemon-match.test.tsindex 7a416e2..6496948 100644--- a/server/src/__tests__/agents-computer-stop-daemon-match.test.ts+++ b/server/src/__tests__/agents-computer-stop-daemon-match.test.ts@@ -15,7 +15,10 @@*/import { test } from 'node:test'import assert from 'node:assert/strict'-import { isStoppableDaemonCommand } from '../agents/computer/daemon.js'+import { readFileSync } from 'node:fs'+import { fileURLToPath } from 'node:url'+import { dirname, join } from 'node:path'+import { isStoppableDaemonCommand, ONE_SHOT_FLAGS } from '../agents/computer/daemon.js'// ── real long-running daemons: must be killed ────────────────────────────────@@ -62,18 +65,60 @@ test('the supervised daemon IS stoppable even with env noise in the command line// ── one-shot CLIs: must be spared ────────────────────────────────────────────test('every one-shot flag is spared', () => {- for (const flag of [- '--stop', '--status', '--restart', '--logs', '--version',- '--install-service', '--uninstall-service', '--pair',- ]) {+ for (const flag of ONE_SHOT_FLAGS) {assert.equal(- isStoppableDaemonCommand(`node /usr/local/bin/cumora agent computer ${flag}`),+ isStoppableDaemonCommand(`node /usr/local/bin/cumora agent computer --${flag}`),false,flag,)}})+test('every mode the parser treats as one-shot is in that list', () => {+ // The old version of the test above restated the matcher's own eight flags,+ // so a mode missing from BOTH could never be caught — which is how --doctor+ // spent minutes of engine probes being killed by a concurrent --stop.+ // Derive the expectation from parseArgs instead, so the next one-shot flag+ // added there fails here until --stop knows to spare it.+ const source = readFileSync(+ join(dirname(fileURLToPath(import.meta.url)), '..', 'agents', 'computer', 'daemon.ts'),+ 'utf8',+ )+ // Anchor inside the body: parseArgs' return type is a multi-line object+ // literal, so slicing from the declaration would stop at the type, not the code.+ const from = source.indexOf('const out: ReturnType<typeof parseArgs>')+ const body = from < 0 ? '' : source.slice(from, source.indexOf('return out', from))+ assert.ok(+ body.includes("argv[i] === '--status'"),+ 'parseArgs moved — update this guard alongside the refactor',+ )++ // Long flags the parser recognises, minus the ones that configure a daemon+ // rather than replacing it.+ // The only two that CONFIGURE a daemon rather than replacing it.+ const CONFIGURES_A_DAEMON = new Set(['server', 'engine'])+ const parsed = [...body.matchAll(/argv\[i\] === '--([a-z-]+)'/g)].map((m) => m[1])+ const oneShot = parsed.filter((flag) => !CONFIGURES_A_DAEMON.has(flag))++ const known = new Set<string>(ONE_SHOT_FLAGS)+ const missing = oneShot.filter((flag) => !known.has(flag))+ assert.deepEqual(missing, [], `--stop would kill these one-shot invocations: ${missing.join(', ')}`)+})++test('the bare `doctor` subcommand is spared too', () => {+ // parseArgs accepts `doctor` as well as `--doctor`, and that form has no `--`+ // to anchor on.+ assert.equal(isStoppableDaemonCommand('npx cumora@latest agent computer doctor'), false)+})++test('a path containing the word doctor is still a daemon', () => {+ // The bare-word rule must stay as tight as the `--` one.+ assert.equal(+ isStoppableDaemonCommand('node /opt/doctor-tools/cumora agent computer --server https://api.cumora.ai'),+ true,+ )+})+test('--pair with a value is spared', () => {assert.equal(isStoppableDaemonCommand('npx cumora@latest agent computer --pair 8lkqelTbO --server https://api.cumora.ai'),diff --git a/server/src/agents/computer/daemon.ts b/server/src/agents/computer/daemon.tsindex c630eeb..fd64071 100644--- a/server/src/agents/computer/daemon.ts+++ b/server/src/agents/computer/daemon.ts@@ -3906,8 +3906,18 @@ export async function restartService(hooks: RestartServiceHooks = {}): Promise<v/** One-shot CLI invocations: these do a thing and exit, so they are never the* long-running daemon we mean to stop. Anchored to the `--` so the words can't* match incidentally elsewhere in the command line. */-const ONE_SHOT_FLAG_RE =- /--(stop|status|restart|logs|version|install-service|uninstall-service|pair)\b/+export const ONE_SHOT_FLAGS = [+ 'stop', 'status', 'restart', 'logs', 'version', 'install-service',+ 'uninstall-service', 'pair', 'doctor', 'help',+] as const+const ONE_SHOT_FLAG_RE = new RegExp(`--(?:${ONE_SHOT_FLAGS.join('|')})\\b`)++/** `--doctor` and `--help` also answer to bare `doctor` / `help` (parseArgs+ * accepts both spellings), and those forms carry no `--` to anchor on. Anchor+ * them to the command instead of matching the bare word, so a path like+ * /opt/doctor-tools/ still reads as a daemon — the same rule the `--`+ * anchoring exists for. */+const ONE_SHOT_SUBCOMMAND_RE = /\bagent computer (?:doctor|help)\b//** Is this `ps`-reported command line a long-running BYOA daemon that `--stop`* should kill? True only for `agent computer` with no one-shot flag.@@ -3919,7 +3929,8 @@ const ONE_SHOT_FLAG_RE =* candidate set. Killing the wrapper's child is what actually stops the daemon,* and the wrapper exits with it. */export function isStoppableDaemonCommand(cmd: string): boolean {- return /agent computer/.test(cmd) && !ONE_SHOT_FLAG_RE.test(cmd)+ if (!/agent computer/.test(cmd)) return false+ return !ONE_SHOT_FLAG_RE.test(cmd) && !ONE_SHOT_SUBCOMMAND_RE.test(cmd)}async function commandLineForPid(pid: number): Promise<string> {