Skip to content

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): harden engine triage permissions (#354)

Strelizia0db1cba31c73
diff --git a/server/src/__tests__/agents-computer-engine-gemini.test.ts b/server/src/__tests__/agents-computer-engine-gemini.test.ts
index 7972539..0925dee 100644
--- a/server/src/__tests__/agents-computer-engine-gemini.test.ts
+++ b/server/src/__tests__/agents-computer-engine-gemini.test.ts
@@ -327,6 +327,22 @@ test('concurrent triage shares one cwd cleanly and leaves no staging files', { s
assert.deepEqual(stray, [], 'a rename was skipped and left a staging file behind')
})
+test('triage fails closed when its tool-free settings cannot be installed', { skip: IS_WIN }, async () => {
+ const f = await fixture()
+ await mkdir(join(f.home, '.cumora-gemini-triage.json'))
+ const res = await getAdapter('gemini').classify({
+ cwd: f.home, prompt: 'x', env: f.env, ...noop,
+ })
+ assert.notEqual(res.error, undefined)
+ assert.match(res.error ?? '', /could not install Gemini triage settings/)
+ assert.deepEqual(await fakeLog(f), [])
+ assert.deepEqual(
+ (await readdir(f.home)).filter((name) =>
+ name.startsWith('.cumora-gemini-triage.') && name !== '.cumora-gemini-triage.json'),
+ [],
+ )
+})
+
test('CUMORA_TRIAGE_MODEL overrides the triage model', { skip: IS_WIN }, async () => {
process.env.CUMORA_TRIAGE_MODEL = 'gemini-2.5-flash'
const f = await fixture()
diff --git a/server/src/__tests__/agents-computer-engine-maka.test.ts b/server/src/__tests__/agents-computer-engine-maka.test.ts
index 3a9c618..5d9de99 100644
--- a/server/src/__tests__/agents-computer-engine-maka.test.ts
+++ b/server/src/__tests__/agents-computer-engine-maka.test.ts
@@ -90,7 +90,9 @@ rl.on('line', (line) => {
send({ jsonrpc: '2.0', id: msg.id, result: { sessionId: msg.params.sessionId, configOptions: [] } })
}
} else if (msg.method === 'session/set_config_option') {
- if (msg.params?.configId !== 'permission_mode' || !['ask', 'bypass'].includes(msg.params?.value)) {
+ if (mode === 'reject-ask' && msg.params?.value === 'ask') {
+ send({ jsonrpc: '2.0', id: msg.id, error: { code: -32602, message: 'permission mode is unavailable' } })
+ } else if (msg.params?.configId !== 'permission_mode' || !['ask', 'bypass'].includes(msg.params?.value)) {
send({ jsonrpc: '2.0', id: msg.id, error: { code: -32602, message: 'Invalid params: Invalid Session configuration option' } })
} else {
send({ jsonrpc: '2.0', id: msg.id, result: { configOptions: [] } })
@@ -466,7 +468,7 @@ test('maka process dying MID-TURN resolves the turn as a failure, never rejects'
assert.equal(session.alive, false)
})
-test('maka seedHome writes AGENTS.md and .agents/skills, and classify/probe use bypass mode', async () => {
+test('maka seedHome writes AGENTS.md and .agents/skills, and classify uses ask mode', async () => {
const f = await makeFixture()
const adapter = getAdapter('maka')
await adapter.seedHome(f.home, {
@@ -492,7 +494,37 @@ test('maka seedHome writes AGENTS.md and .agents/skills, and classify/probe use
const calls = await f.readCalls()
const permCfg = calls.find((c) => c.method === 'session/set_config_option' && c.params?.configId === 'permission_mode')
- assert.equal(permCfg?.params?.value, 'bypass')
+ assert.equal(permCfg?.params?.value, 'ask')
+})
+
+test('maka triage cancels permission requests instead of approving them', async () => {
+ const f = await makeFixture('ask-permission')
+ const classified = await getAdapter('maka').classify({
+ cwd: f.home,
+ env: f.env,
+ prompt: 'classify without tools',
+ signal: new AbortController().signal,
+ })
+ assert.equal(classified.error, undefined)
+ const calls = await f.readCalls()
+ const permCfg = calls.find((c) => c.method === 'session/set_config_option' && c.params?.configId === 'permission_mode')
+ assert.equal(permCfg?.params?.value, 'ask')
+ const promptCall = calls.find((c) => c.method === 'session/prompt')
+ const reply = calls.find((c) => c.id === promptCall?.id && !c.method)
+ assert.deepEqual(reply?.result, { outcome: { outcome: 'cancelled' } })
+})
+
+test('maka triage fails closed when ask mode cannot be applied', async () => {
+ const f = await makeFixture('reject-ask')
+ const classified = await getAdapter('maka').classify({
+ cwd: f.home,
+ env: f.env,
+ prompt: 'classify without tools',
+ signal: new AbortController().signal,
+ })
+ assert.match(classified.error ?? '', /permission_mode=ask could not be applied/)
+ const calls = await f.readCalls()
+ assert.equal(calls.some((c) => c.method === 'session/prompt'), false)
})
test('maka probeWake exercises the acp handshake and one-shot run forwards resumeSessionId', async () => {
diff --git a/server/src/__tests__/agents-computer-engine-qwen.test.ts b/server/src/__tests__/agents-computer-engine-qwen.test.ts
index 7372df6..e295986 100644
--- a/server/src/__tests__/agents-computer-engine-qwen.test.ts
+++ b/server/src/__tests__/agents-computer-engine-qwen.test.ts
@@ -232,7 +232,7 @@ test('non-JSON noise and truncated lines are ignored', () => {
// ── triage ──────────────────────────────────────────────────────────────────
-test('triage runs safe-mode on the cheap model and gets the text back', { skip: IS_WIN }, async () => {
+test('triage runs safe-mode and plan mode on the cheap model', { skip: IS_WIN }, async () => {
const f = await fixture()
const res = await getAdapter('qwen').classify({ cwd: f.home, prompt: 'classify this', env: f.env, ...noop })
assert.equal(res.text, 'echo:classify this')
@@ -240,10 +240,10 @@ test('triage runs safe-mode on the cheap model and gets the text back', { skip:
const [call] = await fakeLog(f)
// --safe-mode leaves context files, hooks, extensions, skills and MCP
- // servers unloaded; --yolo is an argv flag and still wins over it, so
- // nothing can stall on an approval nobody is there to give.
+ // servers unloaded; plan mode removes automatic tool approval.
assert.ok(call.argv.includes('--safe-mode'))
- assert.ok(call.argv.includes('--yolo'))
+ assert.deepEqual(call.argv.slice(call.argv.indexOf('--approval-mode'), call.argv.indexOf('--approval-mode') + 2), ['--approval-mode', 'plan'])
+ assert.equal(call.argv.includes('--yolo'), false)
assert.equal(call.argv[call.argv.indexOf('--model') + 1], 'qwen3-coder-flash')
})
diff --git a/server/src/__tests__/agents-computer-engine.test.ts b/server/src/__tests__/agents-computer-engine.test.ts
index fa1d666..0c2eb35 100644
--- a/server/src/__tests__/agents-computer-engine.test.ts
+++ b/server/src/__tests__/agents-computer-engine.test.ts
@@ -588,6 +588,9 @@ else { process.stdin.resume(); process.stdin.on('end', reply) }
const env = secureClaudeEnv(root, { CLAUDE_CONFIG_DIR: configDir })
const triage = await getAdapter('claude').classify({ cwd: home, env, model: 'haiku', prompt: 'classify', signal: new AbortController().signal })
assert.equal(JSON.parse(triage.text).disabled, '1')
+ const triageArgv = JSON.parse(triage.text).argv as string[]
+ assert.equal(triageArgv[triageArgv.indexOf('--tools') + 1], '')
+ assert.equal(triageArgv.includes('--dangerously-skip-permissions'), false)
const doctor = await getAdapter('claude').probe({ cwd: home, env, tier: 'small', signal: new AbortController().signal })
assert.equal(JSON.parse(doctor.text).disabled, '1')
}
diff --git a/server/src/agents/computer/engine.ts b/server/src/agents/computer/engine.ts
index 9b43496..f8f174e 100644
--- a/server/src/agents/computer/engine.ts
+++ b/server/src/agents/computer/engine.ts
@@ -1709,7 +1709,7 @@ class ClaudeAdapter implements EngineAdapter {
const base = flags.length
? [...flags, '-p']
: allowUnsandboxedByoa(env)
- ? ['-p', ...model, '--output-format', 'json', '--dangerously-skip-permissions', '--strict-mcp-config']
+ ? ['-p', ...model, '--output-format', 'json', '--tools', '', '--strict-mcp-config']
: ['-p', ...model, '--output-format', 'json', '--restricted', '--tools', '', '--strict-mcp-config']
const argv = wantsStdinPrompt ? base : (flags.length ? [...base, args.prompt] : ['-p', args.prompt, ...base.slice(1)])
const res = await spawnCapture(command, argv, {
@@ -1742,7 +1742,7 @@ class ClaudeAdapter implements EngineAdapter {
const model = args.tier === 'small' ? claudeFastModelArgs(env) : main ? ['--model', main] : []
const { command, shell, wantsStdinPrompt } = resolveSpawn(this.bin)
const base = allowUnsandboxedByoa(env)
- ? ['-p', ...model, '--output-format', 'text', '--dangerously-skip-permissions', '--strict-mcp-config']
+ ? ['-p', ...model, '--output-format', 'text', '--tools', '', '--strict-mcp-config']
: ['-p', ...model, '--output-format', 'text', '--restricted', '--tools', '', '--strict-mcp-config']
const argv = wantsStdinPrompt ? base : ['-p', DOCTOR_PROMPT, ...base.slice(1)]
return spawnCapture(command, argv, {
@@ -1776,7 +1776,7 @@ class ClaudeAdapter implements EngineAdapter {
const main = claudeMainModel(env)
const model = main ? ['--model', main] : []
const base = allowUnsandboxedByoa(env)
- ? ['-p', ...model, '--output-format', 'text', '--append-system-prompt-file', promptFile, '--dangerously-skip-permissions']
+ ? ['-p', ...model, '--output-format', 'text', '--append-system-prompt-file', promptFile, '--tools', '', '--strict-mcp-config']
: [
'-p', ...model, '--output-format', 'text', '--append-system-prompt-file', promptFile,
'--restricted', '--tools', '', '--strict-mcp-config',
@@ -3524,6 +3524,7 @@ interface MakaTurnOptions {
prompt: string
model?: string | null
resumeSessionId?: string | null
+ permissionMode?: 'ask' | 'bypass'
signal: AbortSignal
onLog?: (line: string) => void
onHopUsage?: (r: EngineHopReport) => void
@@ -3532,6 +3533,7 @@ interface MakaTurnOptions {
interface MakaSessionOptions extends EngineSessionArgs {
onAgentText?: (text: string) => void
signal?: AbortSignal
+ permissionMode?: 'ask' | 'bypass'
}
const MAKA_MISSING_SESSION_RE =
@@ -3545,6 +3547,7 @@ class MakaSession implements EngineSession {
private readonly onHopUsage?: (r: EngineHopReport) => void
private readonly onAgentText?: (text: string) => void
private readonly model: string | null
+ private readonly permissionMode: 'ask' | 'bypass'
private permissionModeUnapplied = true
private modelWarned = false
private turn: { resolve: (r: EngineRunResult) => void } | null = null
@@ -3557,6 +3560,7 @@ class MakaSession implements EngineSession {
this.onHopUsage = opts.onHopUsage
this.onAgentText = opts.onAgentText
this.model = opts.model ?? null
+ this.permissionMode = opts.permissionMode ?? 'bypass'
this.conn = new AcpRpcConnection(
resolveMakaAcpSpawn(env),
home,
@@ -3651,11 +3655,14 @@ class MakaSession implements EngineSession {
await this.conn.rpc('session/set_config_option', {
sessionId: this.conn.sid,
configId: 'permission_mode',
- value: 'bypass',
+ value: this.permissionMode,
})
this.permissionModeUnapplied = false
} catch (err) {
const why = err instanceof Error ? err.message : String(err)
+ if (this.permissionMode === 'ask') {
+ throw new Error(`maka permission_mode=ask could not be applied: ${why}`)
+ }
this.log(`[maka] permission_mode pin rejected (${why}) — continuing`)
}
}
@@ -3688,6 +3695,10 @@ class MakaSession implements EngineSession {
private onUpdate(msg: AcpMsg): void {
if (msg.method === 'session/request_permission' && msg.id !== undefined) {
+ if (this.permissionMode === 'ask') {
+ this.conn.reply(msg.id, { outcome: { outcome: 'cancelled' } })
+ return
+ }
const options = Array.isArray(msg.params?.options)
? msg.params.options as Array<{ optionId?: unknown; kind?: unknown }>
: []
@@ -3729,6 +3740,7 @@ async function runMakaAcpTurn(opts: MakaTurnOptions): Promise<EngineRunResult &
onHopUsage: opts.onHopUsage,
onAgentText: (text) => chunks.push(text),
signal: opts.signal,
+ permissionMode: opts.permissionMode,
})
try {
return { ...await session.send(opts.prompt), text: chunks.join('') }
@@ -3775,6 +3787,7 @@ class MakaAdapter implements EngineAdapter {
model: args.model,
signal: args.signal,
onLog: args.onLog,
+ permissionMode: 'ask',
})
}
@@ -3784,6 +3797,7 @@ class MakaAdapter implements EngineAdapter {
env: args.env,
prompt: DOCTOR_PROMPT,
signal: args.signal,
+ permissionMode: 'ask',
})
}
@@ -5869,6 +5883,7 @@ class GeminiAdapter implements EngineAdapter {
const model = ['--model', args.model || triageModel('gemini-2.5-flash-lite')]
const settings = join(args.cwd, GEMINI_TRIAGE_SETTINGS_FILE)
let env = geminiEnv(args.env)
+ let staged: string | null = null
try {
// Write-then-rename, not writeFile onto the live path. The triage cwd is
// shared — the doctor hands the SAME dir to every engine's probe, and
@@ -5876,16 +5891,20 @@ class GeminiAdapter implements EngineAdapter {
// it writes, so a second caller can be mid-truncate while gemini is
// reading. Identical content does not save us from a zero-length read;
// rename is atomic, so a reader sees one whole file or the other.
- const staged = `${settings}.${process.pid}.${randomUUID().slice(0, 8)}`
+ staged = `${settings}.${process.pid}.${randomUUID().slice(0, 8)}`
await writeFile(staged, GEMINI_TRIAGE_SETTINGS, 'utf8')
await rename(staged, settings)
// System scope so it wins over any user/workspace settings the operator
// has; it MERGES with them, so their auth config is untouched.
env = { ...env, GEMINI_CLI_SYSTEM_SETTINGS_PATH: settings }
- } catch {
- // Triage still works with tools present — the cwd is neutral and the
- // prompt asks for a direct answer. Losing the guarantee is not worth
- // losing the classification.
+ } catch (err) {
+ if (staged) await rm(staged, { force: true }).catch(() => {})
+ return {
+ exitCode: 1,
+ error: `could not install Gemini triage settings: ${err instanceof Error ? err.message : String(err)}`,
+ sessionId: null,
+ text: '',
+ }
}
return spawnGeminiStream(
command,
@@ -6068,11 +6087,9 @@ class QwenAdapter implements EngineAdapter {
command,
// `--safe-mode` is qwen's own switch for "ignore every customization":
// context files, hooks, extensions, skills and MCP servers all stay
- // unloaded, which is the same thing --strict-mcp-config buys the Claude
- // triage path and keeps a cold triage spawn cheap. It deliberately does
- // NOT disable auth, and `-y` (an argv flag) still wins over it, so
- // nothing can stall waiting for an approval nobody is there to give.
- [...QwenAdapter.STREAM, '--safe-mode', '--yolo', ...model],
+ // unloaded, which keeps a cold triage spawn cheap. Plan mode removes
+ // automatic approval for tool use without changing authentication.
+ [...QwenAdapter.STREAM, '--safe-mode', '--approval-mode', 'plan', ...model],
{
cwd: args.cwd,
env: args.env,