Skip to content

fix: recognise opencode's MCP tool spelling for directive tools - #10331

Merged
iamwhatever merged 2 commits into
mainfrom
fix/opencode-directive-tool-spelling
Sep 12, 2026
Merged

iamwhatever merged 2 commits into
mainfrom
fix/opencode-directive-tool-spelling

Conversation

@iamwhatever

@iamwhatever iamwhatever commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

opencode names an MCP tool <server>_<tool> with a single underscore 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 the model called. Captured live off opencode 1.18.30 — one real turn whose only tool is a Crew MCP directive tool (kirocrew-core exposing monitor_start, mounted through session/new mcpServers), committed as test/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":{}}

rawInput is empty there and complete on the following in_progress refinement, and no _meta.kiro block appears anywhere in the turn.

Every recogniser in this repository returned "" for that spelling:

Recogniser What it knows kirocrew-core_monitor_start
directive_tool_for _meta.kiro server + tool "" — opencode sends no _meta.kiro
directive_tool_from_call title fallback @<server>/<tool> (KAS), mcp__<server>__<tool> (Claude) "" — neither prefix
match_tool a run of 2 or more underscores "" — one underscore
channel._blocked_tool_named normalizes runs of 2+ underscores no match — the lone _ is a word char, so the boundary lookbehind refuses

Two consequences, one per site. In session_directive a 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) — so monitor_start, ask_question, set_project, reset_conversation and friends answer the model and apply nothing, silently. In channel the same blind spot is a containment hole: a channel agent's kirocrew-core_send_message was 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 in directive_tool_from_call) matches f"{CORE_MCP_SERVER}_{name}" exactly, for name in DIRECTIVE_TOOLS. match_tool is deliberately untouched: teaching it that one underscore separates a qualifier would resolve do_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 named kirocrew-core_monitor_start spells its own id <that-server>_kirocrew-core_monitor_start and fails the prefix, and kirocrew-core_monitor_start_extra fails the DIRECTIVE_TOOLS membership check on the tool half.

channel._blocked_tool_named normalizes 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 and mcp__kirocrew-core__send_message comes back as mcp _send_message with the boundary re-broken. Keyed on the server-name shape rather than on "one underscore", because a bare single underscore unblocks do_send_message and 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 in session_directive, which is why that one is an exact match.

Only kirocrew-core serves DIRECTIVE_TOOLS (checked: mcp_core / mcp_tools/control.py), so the grant needs no second server name. channel's list spans core and kirocrew-work, which the prefix shape covers.

Downstream, nothing else needed changing: dashboard/chat_runner's _dir_for_digest already resolves through directive_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.TurnDriver resolves only through _meta.kiro and 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)
    • positive: every member of DIRECTIVE_TOOLS resolves from kirocrew-core_<tool> (parametrized off the set, so a tenth directive tool cannot be added without coverage).
    • negative: 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_.
    • end to end through the real consumer (chat_runner._run_chat), on the CAPTURED shape: no _meta.kiro anywhere, the tool named only by the single-underscore wire title, rawInput empty 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: added kirocrew-core_send_message, kirocrew-work_work_report, Running: kirocrew-core_session_send as blocked; do_send_message, evil_send_notification, kirocrew-core_send_message_v2 as not.
  • test/fixtures/acp_frames/opencode/mcp-directive-call-live.jsonl + snapshot: the three captured frames, replayed through the real parsers. The wire_title in the committed snapshot is the exact string the resolver now reads, and the snapshot also shows the digest-bearing raw_tool_params arriving on the refinement rather than the call.

Every existing session_directive test is unmodified. Suite state: the targeted files are green (300 passed across session_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 is NotImplementedError: atomic no-replace rename is unavailable, and the top five offender files reproduce 138 failures on a pristine origin/main worktree at the same base sha. No red anywhere names a file this diff touches. mypy src/kiro_crew reports one error, in apps/builtins/aws_control/.../test_review_findings_security.py, present on origin/main and untouched here.

Manual verification

N/A — the measurement this fixes came from a live spike (recorded in the fixture's _meta.note and in agent-host-contract.md), and the consumer path is covered end to end by the real _run_chat loop rather than by a stub.

Related Issues

Fixes #10313

Prerequisite for the OpenCode MCP-mirror PR (which mounts kirocrew-core on 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.

  • "The load-bearing premise exists only as prose plus a synthesized fixture" — correct, and it is a live capture now. mcp-directive-call-synthesized.jsonl is replaced by mcp-directive-call-live.jsonl: one real opencode acp 1.18.30 turn, a kirocrew-core stdio element exposing monitor_start on the session/new array, a local OpenAI-compatible model stub with no credential and no network. The capture also corrected the shape — real rawInput is {} on the tool_call and 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.
  • "Black-baseline removal + reformat of an untouched statement — rides along, undeclared" — removed rather than declared. The reformat of the unrelated list comprehension in test_channel_blocked_tools.py is reverted, so the file stays in the baseline and the .github/black-baseline.txt edit 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 in test/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 touch session_directive.py and #7161 touches channel.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/tool and mcp__server__tool and 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's agent-host-contract.md column, 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

  • At most two commits (two here: the fix, then the live capture that replaces the synthesized fixture)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated — agent-host-contract.md §9 "Wire title of an MCP tool call" (OpenCode column), plus both fixture-corpus READMEs
  • No secrets, credentials, or internal references in the diff

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.
@iamwhatever
iamwhatever requested review from a team and CrysisDeu September 12, 2026 08:17
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Sep 12, 2026
@github-actions

github-actions Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5) — 🟡 CONCERNS

Design-level review of ea443288f135bed435a26d5b2731853cfe235581 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

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.

Watch

The 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 directive_queue record still unclaimed at turn end is exactly the condition — and the PR's own pattern-harvest chooses a review-prompt rule over any runtime signal.
Clears when: a turn-end log/refusal fires when a parked directive record goes unclaimed on a turn that ran a tool call (follow-up PR acceptable), or a maintainer explicitly accepts spelling-enumeration-plus-review as the only guard.

Suggestions

  • When the sibling mirror PR mounts kirocrew-core on opencode, gate it on replaying a freshly captured turn per opencode version bump — that turns the "1.18.30 only" caveat into a measured contract instead of a hope.

[DESIGN-REVIEWED] ea44328

@github-actions

github-actions Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ✅ no blocking findings

GPT 5.6 completed its review of ea443288f135bed435a26d5b2731853cfe235581 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] ea44328

False positive or not applicable? A repository writer can comment:
/ai-review override gpt ea443288f135bed435a26d5b2731853cfe235581: <one-sentence reason>

@github-actions

github-actions Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5) — 🟡 CONCERNS

Premise-level review of ea443288f135bed435a26d5b2731853cfe235581 — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

All claims verified against the repository. The key fact for the verdict: providers/mirrors/registry.py:169 declares opencode NO_CHANNEL — shipping code mounts no Crew MCP server on that harness today, so the fixed path is reachable only via the unlanded sibling mirror, and the capture's stdio mount is a transport the registry says this harness doesn't accept. The fix itself is small, exact, revert-verified, and its defect has committed live-capture provenance. Here is the review:

First-Principles-Verdict: CONCERNS

Both hunks guard a path shipping code declares unreachable (mirrors/registry.py:169, NO_CHANNEL), and the exact kirocrew-core_ premise is measured only on the capture harness's stdio mount.

What this change ships

Inventory (5 items) — 5 justified

Intent: make directive tools and channel containment recognise opencode's single-underscore MCP tool naming — a FIX.

  1. Directive tools on opencode now apply their effect instead of confirming and doing nothing — justified
  2. Channel agents on opencode are now blocked from naming Crew messaging/work tools — justified
  3. A fifth live opencode capture (an MCP directive turn) joins the frame corpus with its snapshot — justified
  4. The agent-host contract's opencode column records the single-underscore naming rule — justified
  5. Frame-corpus READMEs updated four→five with the new capture's facts — justified

Watch

  • The registry entry this repo ships says opencode advertises "mcpCapabilities of http and sse and no stdio", so "an opencode session therefore holds none of Crew's own tools, gateway on or off" (registry.py:169-192) — yet the fixture was captured off "a stdio element named kirocrew-core". The mirror that makes this path real must use a transport the capture never measured, and _server_underscore_qualified fires only if that projection registers the server under the literal name kirocrew-core. If the gateway endpoint mounts under any other name, the silent no-op this PR fixes returns, now with green tests.
    Clears when: the sibling mirror PR lands with a capture showing the kirocrew-core_<tool> wire title on the transport it actually uses.

[FIRST-PRINCIPLES-REVIEWED] ea44328

@github-actions

github-actions Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Opus 4.8 Review — ✅ no blocking findings

Reviewed ea443288f135bed435a26d5b2731853cfe235581 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] ea44328

Verdict parsed from the review's SHA-scoped output markers for commit ea443288f135bed435a26d5b2731853cfe235581.

False positive or not applicable? A repository writer can comment:
/ai-review override fable ea443288f135bed435a26d5b2731853cfe235581: <one-sentence reason>

@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Sep 12, 2026
@github-actions

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ✅ no blocking findings

GPT 5.6 completed its review of 7dd1e41fc9f535d99db34e9f4df60231f60bce32 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 7dd1e41

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 7dd1e41fc9f535d99db34e9f4df60231f60bce32: <one-sentence reason>

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention readiness: passed Eligible automated validation passed for the current revision labels Sep 12, 2026
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.
@iamwhatever
iamwhatever force-pushed the fix/opencode-directive-tool-spelling branch from 49238a1 to ea44328 Compare September 12, 2026 11:12
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: passed Eligible automated validation passed for the current revision readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention labels Sep 12, 2026
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Sep 12, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor Author

Design CONCERNS — disposition

Watch: "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 directive_queue record is never claimed, the tool has already answered the model, and nothing logs. Every symptom points at the product working — which is precisely how the opencode case survived until a harness spike went looking for it. And the detector is spelling-independent, as the review says: a record parked for this session during this turn and still unclaimed at turn end, on a turn that ran a tool call, IS the condition, and it needs to know nothing about how any harness spells a name.

Filed as #10371 with the sketch (turn-end check against _turn_started, reusing the _seen_tool_identity map the existing lost-marker diagnostic already keeps) and the three drifts it would catch: an opencode naming change, a fifth harness, and a projection registering the core server under a name other than kirocrew-core.

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: test/fixtures/acp_frames/README.md documents that replacing a row with a fresh capture needs only a re-record plus a snapshot regen, and mcp-directive-call-live.jsonl is now the row to re-record. This PR states the bound rather than hiding it — the fixture README says 1.18.30 is the only release observed and that nothing here pins the rule across upgrades.

@iamwhatever

Copy link
Copy Markdown
Contributor Author

First Principles CONCERNS — disposition

The 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.

providers/mirrors/registry.py:169-192 is wrong, and this capture is the second independent demonstration of it. The stdio element in mcp-directive-call-live.jsonl was not a hypothetical: session/new accepted it, the child was spawned, it served initialize / notifications/initialized / tools/list, the element's env reached it, the tool appeared in the model's tool list, and tools/call reached the child — which is how a kirocrew-core_monitor_start frame exists at all.

The registry's inference is the error, not the observation it was drawn from. mcpCapabilities really does advertise only {http, sse} — and the ACP SDK's own zod schema has exactly two fields, neither of which is stdio:

Db = z.object({_meta: ..., http: z.boolean().optional().default(false),
                            sse:  z.boolean().optional().default(false)})

A conforming agent cannot advertise stdio. So {"http":true,"sse":true} is what full support looks like, and absence proves nothing. The adapter's own mapping takes the untagged member — {_meta, args[], command, env[], name} — down a type: "local" branch, and zod strips the unknown "type":"stdio" key on the way, which is why the tag is tolerated and meaningless rather than fatal.

The registry entry is not corrected here on purpose. It is the sibling mirror PR's subject (that entry is what excludes opencode from ACP_BACKENDS_SESSION_MCP_ARRAY, and the mirror is the change that flips it), and correcting shipping prose about a projection inside a two-hunk recogniser fix would be exactly the scope creep the other lanes checked this PR for the absence of. The inventory's own count stands: 5 items, 5 justified.

2. "_server_underscore_qualified fires only if the projection registers the server under the literal name kirocrew-core" → true, and it is the pre-existing shared assumption, not one this PR adds.

Every branch of the resolver keys on CORE_MCP_SERVER: the KAS branch on @kirocrew-core/<tool>, the Claude branch on mcp__kirocrew-core__<tool>, the trusted _meta.kiro gate on mcp_server_name == CORE_MCP_SERVER. A projection that registered the core server under another name would break all four at once, on every harness — this PR does not widen that dependency, it joins it. And nothing in the projection path invites the divergence: both element builders take the name verbatim from the entry key (acp/session_mcp.py::acp_server_element, mcp_gateway/session_servers.py::_acp_server_entry), and the key for Crew's own server is kirocrew-core in mcp_discovery.

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 NO_CHANNEL, the grant branch is unreachable today. That is the argument FOR this order rather than against it. Landing the mirror first ships the silent no-op — the tool answers, the directive never applies, nothing logs — during the window between the two PRs, and the channel half is a containment hole in that window, not a degraded feature. The two are independent and can land in either order; this one is inert until the other arrives.

Clears when: "the sibling mirror lands with a capture showing the kirocrew-core_<tool> wire title on the transport it actually uses." Carried to that PR as an acceptance condition. On this measurement the transport it should use is the session/new array, since the array demonstrably carries stdio — but if it lands on an http/sse endpoint instead, the naming rule is sanitize(server) + "_" + sanitize(tool) regardless of transport (opencode names the tool from the server's registered name, not from how it was reached), so the capture is worth taking either way rather than assumed.

The spelling's one-release bound and the alarm-free failure class are tracked in #10371.

@bolichen97 bolichen97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved

@iamwhatever
iamwhatever merged commit fb14e23 into main Sep 12, 2026
96 of 99 checks passed
@iamwhatever
iamwhatever deleted the fix/opencode-directive-tool-spelling branch September 12, 2026 18:20
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Sep 12, 2026
amadsalmon pushed a commit to amadsalmon/KiroCrew that referenced this pull request Sep 22, 2026
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

opencode: MCP projection channel measurement

2 participants