Repository navigation
fix: recognise opencode's MCP tool spelling for directive tools - #10331
Conversation
opencode names an MCP tool `<server>_<tool>` with a SINGLE underscore (`sanitize(server) + "_" + sanitize(tool)`) and emits no `_meta.kiro` at all, so on that harness a tool-call frame's wire title is the only channel that names the tool it called. Measured on 1.18.30: a stub Crew MCP server mounted through `session/new` `mcpServers` came back with `title` = `kirocrew-core_spike_marker_tool`. Every recogniser returned "" for that spelling. `directive_tool_for` needs `_meta.kiro`, `directive_tool_from_call`'s title fallback knew only `@<server>/<tool>` (KAS) and `mcp__<server>__<tool>` (Claude), and `match_tool` splits on a run of two or more underscores. With no resolvable tool the consumer records no input digest, so the out-of-band record a #755 directive tool parks is never claimed: the tool answers and the effect silently never applies. `channel._blocked_tool_named` failed the same way, and there its failure is a containment hole -- the lone `_` before the tool name is a word character, so the boundary lookbehind refused every blocked messaging tool named that way. Both fixes are exact rather than wide. `session_directive` matches `f"{CORE_MCP_SERVER}_{name}"` for a DIRECTIVE_TOOLS member, leaving `match_tool` alone: teaching it that one underscore separates a qualifier would resolve `do_monitor_start`, which it excludes on purpose. The server half stays the guard, as in the KAS and Claude branches. `channel` normalizes a Crew server-name prefix after the existing run-of-2+ pass, keyed on the server shape rather than on "one underscore" -- and there a name too many can only block more, which is the safe direction for a containment list. Independent of, but a prerequisite for, mounting Crew's control plane on opencode: without it the directive half of that control plane is inert. `messaging.driver.TurnDriver` still resolves only through `_meta.kiro` and has no digest path at all, so it is unchanged and untouched here.
Design Review (Fable 5) — 🟡 CONCERNSDesign-level review of Design-Verdict: CONCERNS Sound spelling fix, but the silent-no-op CLASS it fixes stays undetectable — the next naming drift reproduces it with zero signal, by the PR's own admission. WatchThe fix enumerates a fourth spelling; the failure class (a directive tool answers, records no digest, and the parked record is never claimed — nothing logs) remains alarm-free. The fixture README concedes the premise is one release: "it was observed on 1.18.30 only… nothing in this repository pins it across upgrades," so an opencode rename silently reverts every directive tool on that harness to answer-and-apply-nothing. The class is detectable independent of spelling — a parked Suggestions
[DESIGN-REVIEWED] ea44328 |
GPT 5.6 Review — ✅ no blocking findingsGPT 5.6 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
First Principles Review (Fable 5) — 🟡 CONCERNSPremise-level review of All claims verified against the repository. The key fact for the verdict: First-Principles-Verdict: CONCERNS Both hunks guard a path shipping code declares unreachable ( What this change shipsInventory (5 items) — 5 justifiedIntent: make directive tools and channel containment recognise opencode's single-underscore MCP tool naming — a FIX.
Watch
[FIRST-PRINCIPLES-REVIEWED] ea44328 |
Opus 4.8 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
GPT 5.6 Review — ✅ no blocking findingsGPT 5.6 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
The First Principles review's concern was right: the premise the whole fix
keys on -- opencode joining server and tool with ONE underscore -- was
attested only by prose plus a fixture labelled `synthesized`. If the
premise were wrong the grant branch would be dead code and the issue would
ship looking fixed.
So it is measured now. One real `opencode acp` 1.18.30 turn whose only tool
is a Crew MCP directive tool: a stdio element named `kirocrew-core`
exposing `monitor_start` on the `session/new` `mcpServers` array, a local
OpenAI-compatible model stub with no credential and no network, driven to
call it once. Three frames kept verbatim.
The capture also corrects the fixture's shape in a way that matters: real
`rawInput` is `{}` on the `tool_call` and complete on the following
`in_progress` refinement, so the input digest can only be recorded on the
refinement. The consumer already handles that (`chat_runner` re-digests
there for exactly this reason), and the end-to-end test now drives the
captured shape rather than the easier one.
Two review findings folded in. GPT 5.6: the channel prefix pattern used
`\b`, which treats `/` and `.` as boundaries, so a rendered PATH
(`cat /tmp/kirocrew-core_send_message`) normalized and over-blocked --
now the same left-boundary class `_BLOCKED_TOOL_RE` itself uses, with two
negative cases. First Principles: the black ride-along is reverted rather
than declared, so `test_channel_blocked_tools.py` stays in the baseline and
the baseline edit is gone with it.
49238a1 to
ea44328
Compare
Design CONCERNS — dispositionWatch: "the failure CLASS remains alarm-free — the next naming drift reproduces it with zero signal" → accepted, deferred to #10371 (the lane's own sanctioned path: "a turn-end log/refusal fires when a parked directive record goes unclaimed … (follow-up PR acceptable)"). Agreed on the substance, including the diagnosis of why: when the call resolves to no directive tool, no input digest is recorded, the parked Filed as #10371 with the sketch (turn-end check against Not folded into this PR deliberately. A new runtime signal carries decisions this diff has no business settling in passing — log level, whether it also refuses, whether a legitimately-late record trips it, and what if anything the model is told when the tool has already returned a confirmation. Those belong in a change whose subject they are. This PR is two hunks and a live capture; keeping it that way is what let both other lanes verify it line by line. Suggestion: "gate the sibling mirror on replaying a freshly captured turn per opencode version bump" → carried to the mirror PR, which is where the version contract can actually be enforced (it owns the projection and the harness's selection). The corpus already supports it with no test change: |
First Principles CONCERNS — dispositionThe Watch item has two halves. The first rests on a repository claim that is measurably false; the second is a real dependency, and it is older than this PR. 1. "The registry says opencode advertises no stdio, yet the fixture was captured off a stdio element" → rebutted, with measurement.
The registry's inference is the error, not the observation it was drawn from. Db = z.object({_meta: ..., http: z.boolean().optional().default(false),
sse: z.boolean().optional().default(false)})A conforming agent cannot advertise stdio. So The registry entry is not corrected here on purpose. It is the sibling mirror PR's subject (that entry is what excludes opencode from 2. " Every branch of the resolver keys on 3. "Both hunks guard a path shipping code declares unreachable" → accurate, stated in the PR, and the reason to land it first. Yes: with opencode Clears when: "the sibling mirror lands with a capture showing the The spelling's one-release bound and the alarm-free failure class are tracked in #10371. |
…dotdev#10331) * fix: recognise opencode's MCP tool spelling for directive tools opencode names an MCP tool `<server>_<tool>` with a SINGLE underscore (`sanitize(server) + "_" + sanitize(tool)`) and emits no `_meta.kiro` at all, so on that harness a tool-call frame's wire title is the only channel that names the tool it called. Measured on 1.18.30: a stub Crew MCP server mounted through `session/new` `mcpServers` came back with `title` = `kirocrew-core_spike_marker_tool`. Every recogniser returned "" for that spelling. `directive_tool_for` needs `_meta.kiro`, `directive_tool_from_call`'s title fallback knew only `@<server>/<tool>` (KAS) and `mcp__<server>__<tool>` (Claude), and `match_tool` splits on a run of two or more underscores. With no resolvable tool the consumer records no input digest, so the out-of-band record a kirodotdev#755 directive tool parks is never claimed: the tool answers and the effect silently never applies. `channel._blocked_tool_named` failed the same way, and there its failure is a containment hole -- the lone `_` before the tool name is a word character, so the boundary lookbehind refused every blocked messaging tool named that way. Both fixes are exact rather than wide. `session_directive` matches `f"{CORE_MCP_SERVER}_{name}"` for a DIRECTIVE_TOOLS member, leaving `match_tool` alone: teaching it that one underscore separates a qualifier would resolve `do_monitor_start`, which it excludes on purpose. The server half stays the guard, as in the KAS and Claude branches. `channel` normalizes a Crew server-name prefix after the existing run-of-2+ pass, keyed on the server shape rather than on "one underscore" -- and there a name too many can only block more, which is the safe direction for a containment list. Independent of, but a prerequisite for, mounting Crew's control plane on opencode: without it the directive half of that control plane is inert. `messaging.driver.TurnDriver` still resolves only through `_meta.kiro` and has no digest path at all, so it is unchanged and untouched here. * test: replace the opencode MCP fixture with a live capture The First Principles review's concern was right: the premise the whole fix keys on -- opencode joining server and tool with ONE underscore -- was attested only by prose plus a fixture labelled `synthesized`. If the premise were wrong the grant branch would be dead code and the issue would ship looking fixed. So it is measured now. One real `opencode acp` 1.18.30 turn whose only tool is a Crew MCP directive tool: a stdio element named `kirocrew-core` exposing `monitor_start` on the `session/new` `mcpServers` array, a local OpenAI-compatible model stub with no credential and no network, driven to call it once. Three frames kept verbatim. The capture also corrects the fixture's shape in a way that matters: real `rawInput` is `{}` on the `tool_call` and complete on the following `in_progress` refinement, so the input digest can only be recorded on the refinement. The consumer already handles that (`chat_runner` re-digests there for exactly this reason), and the end-to-end test now drives the captured shape rather than the easier one. Two review findings folded in. GPT 5.6: the channel prefix pattern used `\b`, which treats `/` and `.` as boundaries, so a rendered PATH (`cat /tmp/kirocrew-core_send_message`) normalized and over-blocked -- now the same left-boundary class `_BLOCKED_TOOL_RE` itself uses, with two negative cases. First Principles: the black ride-along is reverted rather than declared, so `test_channel_blocked_tools.py` stays in the baseline and the baseline edit is gone with it. --------- Co-authored-by: Joe Guo <zejiangg@amazon.com>
Problem / Motivation
opencode names an MCP tool
<server>_<tool>with a single underscore and emits no_meta.kiroat all, so on that harness atool_callframe's wire title is the only channel that names the tool the model called. Captured live off opencode 1.18.30 — one real turn whose only tool is a Crew MCP directive tool (kirocrew-coreexposingmonitor_start, mounted throughsession/newmcpServers), committed astest/fixtures/acp_frames/opencode/mcp-directive-call-live.jsonl:{"sessionUpdate":"tool_call","toolCallId":"call_live_1","title":"kirocrew-core_monitor_start","kind":"other","status":"pending","locations":[],"rawInput":{}}rawInputis empty there and complete on the followingin_progressrefinement, and no_meta.kiroblock appears anywhere in the turn.Every recogniser in this repository returned
""for that spelling:kirocrew-core_monitor_startdirective_tool_for_meta.kiroserver + tool""— opencode sends no_meta.kirodirective_tool_from_calltitle fallback@<server>/<tool>(KAS),mcp__<server>__<tool>(Claude)""— neither prefixmatch_tool""— one underscorechannel._blocked_tool_named_is a word char, so the boundary lookbehind refusesTwo consequences, one per site. In
session_directivea call that resolves to no directive tool records no input digest, and the digest is what claims the out-of-band record a #755 directive tool parked (dashboard/directive_queue) — somonitor_start,ask_question,set_project,reset_conversationand friends answer the model and apply nothing, silently. Inchannelthe same blind spot is a containment hole: a channel agent'skirocrew-core_send_messagewas not recognised as a blocked messaging tool.Why it matters
The directive half of Crew's control plane fails open on appearance and closed in effect on this harness: the model is told the loop is armed, the user sees the confirmation, and no loop exists. Nothing logs a refusal, because the gate that would log one never fires.
channel's half is worse in kind — a containment list that reads as absent is not a degraded control, it is no control.This is independent of, but a prerequisite for, mounting Crew's MCP servers on opencode (sibling PR): the mirror is what makes this path reachable, and landing the mirror without this ships the silent-no-op.
What changed (motivation → approach → change)
Root cause is that three recognisers each enumerate the spellings a backend can use, and a fourth spelling arrived. The fix adds that spelling — and does not relax the shared normalizer, which is where the temptation is.
session_directive._server_underscore_qualified(new, called last indirective_tool_from_call) matchesf"{CORE_MCP_SERVER}_{name}"exactly, fornameinDIRECTIVE_TOOLS.match_toolis deliberately untouched: teaching it that one underscore separates a qualifier would resolvedo_monitor_start, which its own comment excludes on purpose, and at one underscore there is no way to tell a qualified name from a bare tool name whose words happen to end in a directive name. Exactness costs nothing here — the whole point of this spelling is that both halves are on the wire. The server half stays the guard, as in the KAS and Claude branches: a third-party server exposing a tool literally namedkirocrew-core_monitor_startspells its own id<that-server>_kirocrew-core_monitor_startand fails the prefix, andkirocrew-core_monitor_start_extrafails theDIRECTIVE_TOOLSmembership check on the tool half.channel._blocked_tool_namednormalizes a Crew server-name prefix (\bkirocrew-[A-Za-z0-9-]+_) to a space after the existing run-of-2+ pass. Order matters: run it first andmcp__kirocrew-core__send_messagecomes back asmcp _send_messagewith the boundary re-broken. Keyed on the server-name shape rather than on "one underscore", because a bare single underscore unblocksdo_send_messageand every other identifier ending in a blocked name. Recognising one name too many here can only ever block more, which is the safe direction for a containment list — unlike the grant insession_directive, which is why that one is an exact match.Only
kirocrew-coreservesDIRECTIVE_TOOLS(checked:mcp_core/mcp_tools/control.py), so the grant needs no second server name.channel's list spans core andkirocrew-work, which the prefix shape covers.Downstream, nothing else needed changing:
dashboard/chat_runner's_dir_for_digestalready resolves throughdirective_tool_from_call, so the newly recognised title records a digest and the out-of-band claim lands, while the marker gate (_pending_dir_tool←directive_tool_for) still refuses on absent_meta.kiro— the fail-closed rule is unchanged.messaging.driver.TurnDriverresolves only through_meta.kiroand has no digest path at all, so opencode-as-a-channel-transport stays out of scope and untouched here.Tests
Revert-verified: with the two source hunks reverted, 10 of the new session-directive cases and 3 of the new channel cases fail; with them, all pass.
TestOpenCodeBackendResolvesTheTool(new,test_session_directive_input_digest.py)DIRECTIVE_TOOLSresolves fromkirocrew-core_<tool>(parametrized off the set, so a tenth directive tool cannot be added without coverage).evil-mcp_monitor_start,other_reset_conversation,evil-mcp_kirocrew-core_monitor_start,do_monitor_start,evilmonitor_start,kirocrew-core_monitor_start_extra,kirocrew-core_resource_status,kirocrew-core_spike_marker_tool,kirocrew-core,kirocrew-core_.chat_runner._run_chat), on the CAPTURED shape: no_meta.kiroanywhere, the tool named only by the single-underscore wire title,rawInputempty on the call and complete on the refinement, and a result carrying no marker at all — applies the parked record's payload once; and the same turn with a lookalike title (..._monitor_start_extra) applies nothing and leaves the record parked.test_channel_blocked_tools.py::test_blocked_tool_matcher_precision: addedkirocrew-core_send_message,kirocrew-work_work_report,Running: kirocrew-core_session_sendas blocked;do_send_message,evil_send_notification,kirocrew-core_send_message_v2as not.test/fixtures/acp_frames/opencode/mcp-directive-call-live.jsonl+ snapshot: the three captured frames, replayed through the real parsers. Thewire_titlein the committed snapshot is the exact string the resolver now reads, and the snapshot also shows the digest-bearingraw_tool_paramsarriving on the refinement rather than the call.Every existing
session_directivetest is unmodified. Suite state: the targeted files are green (300 passed acrosssession_directive,session_directive_input_digest,channel_blocked_tools,mcp_work,acp_frame_replay,acp_tool_identity,reset_conversation_directive,directive_refusal_not_lost_marker_8635). The full backend run's reds are host pollution, not this diff: the dominant error isNotImplementedError: atomic no-replace rename is unavailable, and the top five offender files reproduce 138 failures on a pristineorigin/mainworktree at the same base sha. No red anywhere names a file this diff touches.mypy src/kiro_crewreports one error, inapps/builtins/aws_control/.../test_review_findings_security.py, present onorigin/mainand untouched here.Manual verification
N/A — the measurement this fixes came from a live spike (recorded in the fixture's
_meta.noteand inagent-host-contract.md), and the consumer path is covered end to end by the real_run_chatloop rather than by a stub.Related Issues
Fixes #10313
Prerequisite for the OpenCode MCP-mirror PR (which mounts
kirocrew-coreon this harness and so makes the path reachable); the two are independent changes and can land in either order.Review disposition
Both First Principles CONCERNS items are addressed in commit 2 rather than argued with.
mcp-directive-call-synthesized.jsonlis replaced bymcp-directive-call-live.jsonl: one realopencode acp1.18.30 turn, akirocrew-corestdio element exposingmonitor_starton thesession/newarray, a local OpenAI-compatible model stub with no credential and no network. The capture also corrected the shape — realrawInputis{}on thetool_calland complete on the refinement, which is where the digest can be recorded at all — so the end-to-end test now drives the harder, real shape. Two things it still does not pin, stated in the fixture README: Crew sends this backend no MCP array today (§5), so the element is the capture harness's; and 1.18.30 is the only release observed.test_channel_blocked_tools.pyis reverted, so the file stays in the baseline and the.github/black-baseline.txtedit is gone with it. The diff is now nine files, all of them the change.Design Review PASS, GPT 5.6 and Opus 4.8 no findings, on commit 1.
Concurrent-edit note: #10326 (
test: replace synthesized ACP frame corpora with live captures) edits the same provenance sentence intest/fixtures/acp_frames/README.md. Textual only — whichever lands second rebases. No other open PR touches a seam this diff edits (checked 400 open PRs; #8983, #8696, #7163 touchsession_directive.pyand #7161 toucheschannel.py, none of them these functions).Pattern harvest
Pattern: a recogniser that enumerates the spellings of a qualified name, with no test that the set is exhaustive per harness.
Rule candidate: review-prompt
Three sites in this repo listed
@server/toolandmcp__server__tooland a run-of-2+ split; a fourth spelling made all three answer "not ours" — the fail-open-looking, fail-closed-in-effect direction, which logs nothing. When a harness is onboarded, every name-shaped recogniser (directive_tool_from_call,_blocked_tool_named,trust_patterns, the Slack/Webex label strippers) needs a row in that harness'sagent-host-contract.mdcolumn, measured rather than assumed. The<server>_<tool>join is not exotic: it is what any adapter does when a transport forbids the canonical__separator.Checklist
agent-host-contract.md§9 "Wire title of an MCP tool call" (OpenCode column), plus both fixture-corpus READMEs