Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 26 additions & 13 deletions docs/subagent-cards.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ to a subagent tool is asked about.
(the conversation, as the state reports read it), `nested`, `call`, `tool`,
`tool_use_id`, `tasks[]` of `{title, prompt, type}`, `model`, `sealed`,
`isolation`, `background`, every field present, empty or `false` when the
call does not give it. The token rides an `Authorization: Bearer` header from
the script and `?token=` from the two modules, as in every other report.
call does not give it. `tool_use_id` is the payload's `tool_use_id`, or
Antigravity's `toolCall.id`. The token rides an `Authorization: Bearer` header
from the script and `?token=` from the two modules, as in every other report.
The script feeds curl the body on stdin and the header through a config on a
file descriptor, so neither the task nor the token is ever a process argument.

## How it behaves

Expand Down Expand Up @@ -74,21 +77,31 @@ The files each needs: `hooks/veto-subagent.sh` and `hooks/conversation-id.sh`
for all three; Antigravity's `hooks.json` also runs `hooks/report-tool.sh` and
`hooks/detail.jq` as before.

## Not measured
## Measured, and not

The tool names and the input fields are the contract's table, measured by lich
on 2026-11-22. These were not measured, and each fails to an allow or an empty
field when it is wrong:

- `tool_use_id` as a payload field outside Claude Code (Codex, Kiro, Crush, the
Claude Code-compatible hook Cursor runs); Antigravity sends none here.
- Kiro's payload envelope (`tool_name`, `tool_input`, `session_id`), where
`use_subagent` keeps its `subagents` (`content.subagents` or top level) and
how it spells the `InvokeSubagents` command.
on 2026-11-22. The same day lich measured these whole payloads, which the suite
replays:

- Antigravity: camelCase, `conversationId` and `toolCall: {id, name, args:
{Prompt, Role, TypeName}}`. It also fires for the subagent's own tools, under
the subagent's `conversationId`, which lich tells apart by
`provider_session_id`.
- Kiro CLI over ACP, which lich spawns: `{hook_event_name, cwd, session_id,
tool_name: "subagent", tool_input: {task, mode, stages: [{name, role,
prompt_template}]}}`. Its classic chat sends no `session_id`, and its
`use_subagent` input is `{command: "InvokeSubagents", content: {subagents:
[{query}]}}` (after a `ListAgents`, which is not asked about).
- Cursor CLI, through the Claude Code install's hook: `{conversation_id,
session_id, tool_name: "Task", tool_input, tool_use_id, ...}`, no `agent_id`;
that hook vetoes with Claude Code's JSON in `cursor-agent -p`.

Still not measured, each failing to an allow or an empty field when wrong:

- `tool_use_id` on Codex and Crush payloads.
- How oh-my-pi's `context` joins each task's prompt (here: first, a blank line
after it).
- Cursor CLI's payload, taken to be Claude Code's.
- `win-veto.cmd`, on a Windows machine.
- `win-veto.cmd` and the file-descriptor config, on a Windows machine.

opencode 2 is left out: its subagent tool is `subagent` and the contract has no
row for it.
20 changes: 12 additions & 8 deletions hooks/veto-subagent.sh
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ body=$(printf '%s' "$payload" | jq -c --arg harness "$harness" --arg sid "$LICH_
elif $harness == "kiro" then
if $tool == "subagent" then
spawn([{title: ($in.stages[0].name? | s), prompt: ($in.task | s), type: ""}])
elif $tool == "use_subagent" and (($in.command // "InvokeSubagents") == "InvokeSubagents") then
spawn([($in.subagents // $in.content.subagents // [])[]? | {title: "", prompt: (.query | s), type: ""}])
elif $tool == "use_subagent" and $in.command == "InvokeSubagents" then
spawn([$in.content.subagents[]? | {title: "", prompt: (.query | s), type: ""}])
else empty end
elif $harness == "crush" then
if $tool == "agent" then spawn([{title: "", prompt: ($in.prompt | s), type: ""}]) else empty end
Expand All @@ -84,20 +84,24 @@ body=$(printf '%s' "$payload" | jq -c --arg harness "$harness" --arg sid "$LICH_
| select(.call == "wait" or .sealed == true
or ((.tasks | length) > 0 and all(.tasks[]; .prompt | test("\\S"))))
| {session_id: $sid, provider_session_id: $conversation, nested: $nested, tool: $tool,
tool_use_id: ($root.tool_use_id | s), model: "", sealed: false, isolation: "", background: false}
tool_use_id: ($root.tool_use_id // $root.toolCall.id | s), model: "", sealed: false, isolation: "", background: false}
+ .
' 2>/dev/null)
[ -n "$body" ] || allow

# The token rides a header fed through stdin, as in every report script: a
# query string or -H would put it in curl's command line. The answer comes back
# with its status on a last line of its own.
# Neither the token nor the body goes in curl's command line, which every user
# on the machine can read: the body, which carries the task, is fed on stdin and
# the token header through a config on fd 3, both from shell builtins. The
# answer comes back with its status on a last line of its own.
url="http://127.0.0.1:${LICH_PORT}/subagent"
answer=$(printf 'header = "Authorization: Bearer %s"\n' "$LICH_TOKEN" |
answer=$(printf '%s' "$body" |
curl -s --max-time 10 -X POST \
-H 'Content-Type: application/json' \
-H "X-Lich-Plugin: ${plugin_version}" \
-d "$body" -w '\n%{http_code}' -K - "$url" 2>/dev/null)
--data-binary @- -w '\n%{http_code}' -K /dev/fd/3 "$url" 2>/dev/null 3<<EOF
header = "Authorization: Bearer ${LICH_TOKEN}"
EOF
)
[ "$(printf '%s' "$answer" | tail -n 1)" = 200 ] || allow
decision=$(printf '%s' "$answer" | sed '$d' |
jq -c 'select(.decision == "deny" and (.reason | type) == "string" and .reason != "")' 2>/dev/null)
Expand Down
93 changes: 82 additions & 11 deletions tests/subagent.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
// registration spells it; opencode and omp run their modules in process.
//
// The answers are lich's own, replayed from subagent-cards.jsonl. The request
// payloads are the provider's, written here from the contract's table (Event →
// veto mapping): lich measured those names, and this suite holds the clients to
// them, not to a real run.
// payloads are the provider's: the contract's table (Event → veto mapping) for
// the names, and for Antigravity, Kiro CLI and Cursor CLI the whole payload as
// lich measured it on 2026-11-22, the long fields cut.
//
// Run: node --test tests/

import { test } from 'node:test'
import assert from 'node:assert/strict'
import { spawn } from 'node:child_process'
import { mkdtempSync, readFileSync, symlinkSync } from 'node:fs'
import { mkdtempSync, readFileSync, symlinkSync, writeFileSync } from 'node:fs'
import { tmpdir } from 'node:os'
import path from 'node:path'

Expand Down Expand Up @@ -233,8 +233,26 @@ const CALLS = [
{
name: "a Cursor CLI Task call, through the Claude Code install's hook",
harness: 'claude',
payload: { session_id: 'p1', tool_name: 'Task', tool_input: { description: 'Map it', prompt: 'Map the relay package.', subagent_type: 'explore' } },
body: body({ tool: 'Task', tasks: [{ title: 'Map it', prompt: 'Map the relay package.', type: 'explore' }] }),
// Cursor's own shape, not Claude Code's: no agent_id, and an id with a
// newline in it.
payload: {
conversation_id: 'p1',
generation_id: 'g1',
model: '',
tool_name: 'Task',
tool_input: { description: 'Map it', prompt: 'Map the relay package.', subagent_type: 'explore' },
tool_use_id: 'call-2f14-1\nfc_45ba_0',
session_id: 'p1',
hook_event_name: 'preToolUse',
cursor_version: '2026.10.19-6bbf2c4',
workspace_roots: ['/w'],
transcript_path: '/t.jsonl',
},
body: body({
tool: 'Task',
tool_use_id: 'call-2f14-1\nfc_45ba_0',
tasks: [{ title: 'Map it', prompt: 'Map the relay package.', type: 'explore' }],
}),
},
{
name: 'a Codex v1 spawn_agent call',
Expand All @@ -257,24 +275,46 @@ const CALLS = [
{
name: 'an Antigravity invoke_subagent call',
harness: 'antigravity',
payload: { conversationId: 'p1', toolCall: { name: 'invoke_subagent', args: { Prompt: FIX, TypeName: 'general' } } },
body: body({ tool: 'invoke_subagent', tasks: [{ title: '', prompt: FIX, type: 'general' }] }),
payload: {
artifactDirectoryPath: '/b/p1',
conversationId: 'p1',
cwd: '/w',
hookEventName: 'PreToolUse',
modelName: 'gemini-3.8-flash-high',
stepIdx: 3,
toolCall: { args: { Prompt: FIX, Role: 'Fixer', TypeName: 'self' }, id: 'call_8341775817706615516', name: 'invoke_subagent' },
workspacePaths: ['/w'],
},
body: body({ tool: 'invoke_subagent', tool_use_id: 'call_8341775817706615516', tasks: [{ title: '', prompt: FIX, type: 'self' }] }),
},
{
name: 'a Kiro CLI subagent call (ACP)',
harness: 'kiro',
payload: { session_id: 'p1', tool_name: 'subagent', tool_input: { task: FIX, stages: [{ name: 'Fix it' }, { name: 'Review' }] } },
body: body({ tool: 'subagent', tasks: [{ title: 'Fix it', prompt: FIX, type: '' }] }),
payload: {
hook_event_name: 'preToolUse',
cwd: '/w',
session_id: 'p1',
tool_name: 'subagent',
tool_input: {
task: FIX,
mode: 'blocking',
stages: [{ name: 'fix_handshake', role: 'kiro_default', prompt_template: 'Fix the race. Report what you changed.' }],
},
},
body: body({ tool: 'subagent', tasks: [{ title: 'fix_handshake', prompt: FIX, type: '' }] }),
},
{
// The classic chat names no session.
name: 'a Kiro CLI use_subagent call starting two subagents',
harness: 'kiro',
payload: {
session_id: 'p1',
hook_event_name: 'preToolUse',
cwd: '/w',
tool_name: 'use_subagent',
tool_input: { command: 'InvokeSubagents', content: { subagents: [{ query: 'Map the relay package.' }, { query: 'Fix #412.' }] } },
},
body: body({
provider_session_id: '',
tool: 'use_subagent',
tasks: [
{ title: '', prompt: 'Map the relay package.', type: '' },
Expand Down Expand Up @@ -368,6 +408,7 @@ const NOT_ASKED = [
['codex', { session_id: 'p1', tool_name: 'spawn_agent', tool_input: {} }],
['antigravity', { conversationId: 'p1', toolCall: { name: 'run_command', args: { CommandLine: 'ls' } } }],
['kiro', { session_id: 'p1', tool_name: 'use_subagent', tool_input: { command: 'ListAgents' } }],
['kiro', { session_id: 'p1', tool_name: 'use_subagent', tool_input: { content: { subagents: [{ query: 'Fix #412.' }] } } }],
['kiro', { session_id: 'p1', tool_name: 'use_subagent', tool_input: { command: 'InvokeSubagents', content: { subagents: [] } } }],
['crush', { session_id: 'p1', tool_name: 'bash', tool_input: { command: 'ls' } }],
['opencode', { input: { tool: 'bash', sessionID: 'p1', callID: 'c' }, args: { command: 'ls' } }],
Expand Down Expand Up @@ -507,6 +548,36 @@ test('without jq the script asks nothing and the call runs', async () => {
}
})

// The body carries the task, and the token is the session's: neither may be an
// argument of a process, which every user on the machine can read for as long
// as the hook waits.
test('the script keeps the task and the token out of every command line', async () => {
const bin = mkdtempSync(path.join(TMP, 'bin-recording-'))
const argv = path.join(bin, 'argv')
for (const tool of ['curl', 'printf', 'jq']) {
const real = await new Promise((resolve) => {
const which = spawn('/bin/sh', ['-c', `command -v ${tool}`])
let out = ''
which.stdout.on('data', (c) => (out += c))
which.on('close', () => resolve(out.trim()))
})
writeFileSync(path.join(bin, tool), `#!/bin/sh\necho "${tool} $*" >>"${argv}"\nexec "${real}" "$@"\n`, { mode: 0o755 })
}
writeFileSync(argv, '')
await withStub(
async (stub) => {
const env = { ...lichEnv(stub.port), PATH: `${bin}${path.delimiter}${process.env.PATH}` }
assert.deepEqual(await outcome('claude', callOf('claude').payload, env), { veto: DENY.reason })
subagentRequest('claude', stub)
const ran = readFileSync(argv, 'utf8')
assert.match(ran, /^curl /m, 'the recording curl never ran')
assert.ok(!ran.includes(TOKEN), `the token was an argument of a process:\n${ran}`)
assert.ok(!ran.includes(FIX), `the task was an argument of a process:\n${ran}`)
},
{ status: 200, body: JSON.stringify(DENY) },
)
})

// ----------------------------------------------------------- registrations --

// The tool names each registration's matcher lets through are the contract's
Expand Down
Loading