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): --install-service installed a service that could never start (#296)
Xialie Zhuangbd8d43849ace
diff --git a/server/src/__tests__/agents-computer-install-service-optin.test.ts b/server/src/__tests__/agents-computer-install-service-optin.test.tsnew file mode 100644index 0000000..bb2ff84--- /dev/null+++ b/server/src/__tests__/agents-computer-install-service-optin.test.ts@@ -0,0 +1,79 @@+/**+ * `--install-service` must not install a service that cannot start.+ *+ * The service definitions carry exactly two variables — PATH and+ * CUMORA_SUPERVISED. An unsandboxed compatibility opt-in set in the user's+ * shell is dropped at install time.+ *+ * For a user whose only engine is a compatibility one (grok, cursor, gemini,+ * qwen, opencode, pi, antigravity) that is fatal, and every step of it is+ * something the product told them to do:+ *+ * 1. pairing fails, and the CLI prints the remediation itself:+ * "CUMORA_BYOA_ALLOW_UNSANDBOXED=1 npx cumora@latest agent computer ..."+ * 2. with the flag set, pairing succeeds and the foreground daemon runs+ * 3. that daemon prints "run `--install-service` to keep this running in the+ * background" (daemon.ts, the !SUPERVISED tip)+ * 4. the installed service starts WITHOUT the flag, so requireLocalEngine+ * finds an empty runnable set, doRun sets exitCode 70 and returns+ * 5. KeepAlive / Restart=always / the PowerShell supervisor loop restart it,+ * forever, every five seconds+ *+ * The flag is carried only when the machine genuinely has nothing runnable+ * without it, so it is never persisted into a background service just because+ * it happened to be set in the shell of someone whose secure engines were fine.+ */+import test from 'node:test'+import assert from 'node:assert/strict'+import { readFile } from 'node:fs/promises'+import { renderWindowsSupervisor, _needsUnsandboxedOptIn } from '../agents/computer/daemon.js'++const WIN = (carry: boolean) =>+ renderWindowsSupervisor('npx', 'https://api.cumora.ai', 'C:/log.txt', 'C:/disabled', 'C:/bin', carry)++test('the Windows supervisor carries the opt-in when the machine needs it', () => {+ assert.match(+ WIN(true), /\$env:CUMORA_BYOA_ALLOW_UNSANDBOXED = '1'/,+ 'the supervised daemon starts without the opt-in, exits 70, and this loop restarts it every 5s forever',+ )+})++test('and does not carry it when the machine does not', () => {+ // The guard rail: a security opt-in must not be baked into a background+ // service merely because it was set in the installing shell.+ assert.doesNotMatch(WIN(false), /CUMORA_BYOA_ALLOW_UNSANDBOXED/)+})++test('the opt-in is set before the daemon is launched, not after', () => {+ const lines = WIN(true).split('\r\n')+ const optIn = lines.findIndex((l) => l.includes('CUMORA_BYOA_ALLOW_UNSANDBOXED'))+ const launch = lines.findIndex((l) => l.includes('agent computer --server'))+ assert.ok(optIn >= 0 && launch >= 0)+ assert.ok(optIn < launch, 'the variable is exported after the daemon starts, so the daemon never sees it')+})++test('the probe answers no when the opt-in was never given', async () => {+ // No flag in the environment means nothing to carry, whatever is installed —+ // and the probe must not shell out to decide that.+ assert.equal(await _needsUnsandboxedOptIn({}), false)+ assert.equal(await _needsUnsandboxedOptIn({ CUMORA_BYOA_ALLOW_UNSANDBOXED: '0' }), false)+})++test('macOS and Linux service definitions carry it on the same condition', async () => {+ // Those two are template strings written straight to disk, so there is no+ // pure function to call. Read the source: all three platforms have to agree,+ // or the bug simply moves to whichever one was missed.+ const source = await readFile(new URL('../agents/computer/daemon.ts', import.meta.url), 'utf8')++ const plist = source.slice(source.indexOf('<key>CUMORA_SUPERVISED</key>'))+ assert.match(+ plist.slice(0, 220), /carryUnsandboxed \? '[^']*CUMORA_BYOA_ALLOW_UNSANDBOXED/,+ 'the LaunchAgent drops the opt-in again — it will exit 70 and KeepAlive will restart it forever',+ )++ const unit = source.slice(source.indexOf('Environment=CUMORA_SUPERVISED=1'))+ assert.match(+ unit.slice(0, 220), /carryUnsandboxed \? '[^']*CUMORA_BYOA_ALLOW_UNSANDBOXED/,+ 'the systemd unit drops the opt-in again — it will exit 70 and Restart=always will restart it forever',+ )+})diff --git a/server/src/agents/computer/daemon.ts b/server/src/agents/computer/daemon.tsindex 64b780d..a93ecb9 100644--- a/server/src/agents/computer/daemon.ts+++ b/server/src/agents/computer/daemon.ts@@ -3850,10 +3850,15 @@ export function renderWindowsSupervisor(logPath: string,disabledPath = windowsSupervisorDisabledPath(),path = process.env.PATH ?? '',+ // Carried only when the machine has nothing runnable without it — see+ // _needsUnsandboxedOptIn. Dropping it makes the supervised daemon exit 70 on+ // every start, and this loop restarts it every 5 seconds forever.+ carryUnsandboxed = false,): string {return ["$ErrorActionPreference = 'Continue'","$env:CUMORA_SUPERVISED = '1'",+ ...(carryUnsandboxed ? ["$env:CUMORA_BYOA_ALLOW_UNSANDBOXED = '1'"] : []),`$env:PATH = ${quotePowerShell(path)}`,'$utf8 = New-Object System.Text.UTF8Encoding($false)',`while (-not (Test-Path -LiteralPath ${quotePowerShell(disabledPath)})) {`,@@ -3925,6 +3930,36 @@ async function isWindowsTaskInstalled(taskName = windowsTaskName()): Promise<boo* `npx -y cumora@latest agent computer --server <url>` with auto-restart +* start-at-login. `@latest` + restart-on-update is what makes the daemon* self-update (see checkForUpdate). Must be paired first. */+/** Does the supervised daemon need the unsandboxed compatibility opt-in to+ * start at all?+ *+ * The service definitions carry only PATH and CUMORA_SUPERVISED, so an opt-in+ * that was set in the shell is dropped at install time. For a user whose only+ * engine is a compatibility one (grok, cursor, gemini, qwen, opencode, pi,+ * antigravity) that is fatal and silent: pairing succeeds in the foreground,+ * the daemon then prints "run --install-service to keep this running", and the+ * service it installs starts with an empty runnable set, exits 70, and is+ * restarted forever by KeepAlive / Restart=always / Task Scheduler.+ *+ * Answered by asking the real gate with the flag removed, so the flag is only+ * ever persisted when dropping it would actually break the service — not+ * baked into a background service because it happened to be set in the shell+ * of someone whose secure engines were fine all along. */+export async function _needsUnsandboxedOptIn(env: NodeJS.ProcessEnv = process.env): Promise<boolean> {+ if (!allowUnsandboxedByoa(env)) return false+ try {+ const detected = await detectEnginesWithStatus()+ if (!detected.reliable || detected.engines.length === 0) return false+ const without = { ...env, CUMORA_BYOA_ALLOW_UNSANDBOXED: '' }+ const evaluated = await evaluateRunnableEngines(detected.engines, without)+ return evaluated.runnable.length === 0+ } catch {+ // Never let the probe stop an install. Not carrying the flag is the+ // status quo, and --status/--logs will show the exit 70 if it matters.+ return false+ }+}+async function installService(serverUrl: string): Promise<void> {if (!(await loadConfig())) {throw new Error('pair this computer first: cumora agent computer --pair <code>')@@ -3932,6 +3967,13 @@ async function installService(serverUrl: string): Promise<void> {const npx = resolveNpx()const logPath = join(CONFIG_DIR, 'daemon.log')await mkdir(CONFIG_DIR, { recursive: true })+ const carryUnsandboxed = await _needsUnsandboxedOptIn()+ if (carryUnsandboxed) {+ console.warn('[computer] this machine has no secure engine, so the background service will')+ console.warn('[computer] carry CUMORA_BYOA_ALLOW_UNSANDBOXED=1 — without it the service exits 70')+ console.warn('[computer] on every start. Local engines may read host files and use the network.')+ console.warn('[computer] To undo: cumora agent computer --uninstall-service')+ }if (process.platform === 'darwin') {const dir = join(homedir(), 'Library', 'LaunchAgents')@@ -3949,7 +3991,7 @@ async function installService(serverUrl: string): Promise<void> {<key>StandardErrorPath</key><string>${logPath}</string><key>EnvironmentVariables</key><dict><key>PATH</key><string>${process.env.PATH ?? ''}</string>- <key>CUMORA_SUPERVISED</key><string>1</string>+ <key>CUMORA_SUPERVISED</key><string>1</string>${carryUnsandboxed ? '\n <key>CUMORA_BYOA_ALLOW_UNSANDBOXED</key><string>1</string>' : ''}</dict></dict></plist>`@@ -3974,7 +4016,7 @@ ExecStart=${npx} -y cumora@latest agent computer --server ${serverUrl}Restart=alwaysRestartSec=5Environment=PATH=${process.env.PATH ?? ''}-Environment=CUMORA_SUPERVISED=1+Environment=CUMORA_SUPERVISED=1${carryUnsandboxed ? '\nEnvironment=CUMORA_BYOA_ALLOW_UNSANDBOXED=1' : ''}[Install]WantedBy=default.target@@ -3992,7 +4034,7 @@ WantedBy=default.targetconst disabledPath = windowsSupervisorDisabledPath()const taskName = windowsTaskName()const replacing = await isWindowsTaskInstalled(taskName)- await writeFile(scriptPath, renderWindowsSupervisor(npx, serverUrl, logPath, disabledPath), 'utf8')+ await writeFile(scriptPath, renderWindowsSupervisor(npx, serverUrl, logPath, disabledPath, process.env.PATH ?? '', carryUnsandboxed), 'utf8')await writeFile(launcherPath, renderWindowsSupervisorLauncher(scriptPath), 'utf8')try {// Always recreate with /F: an existing task may still point at the old