Skip to content

fix(kiro): refresh agent tools vocabulary and fail closed per agent - #3947

Merged
Daniel Meppiel (danielmeppiel) merged 9 commits into
mainfrom
danielmeppiel-community-bug-repro-0-37
Nov 19, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 9 commits into
mainfrom
danielmeppiel-community-bug-repro-0-37

Conversation

@danielmeppiel

@danielmeppiel Daniel Meppiel (danielmeppiel) commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

Description

TL;DR

Kiro agent tools validation now follows the current Kiro docs: category tags, current built-in tool IDs, @server / @server/tool selectors (MCP SEP-986 tool names), subagent/<agent>, @builtin, @mcp, *. An agent with an unsupported tool is still never written (req-tg-009), but its diagnostic is now a warning. Sibling agents in the same install still deploy and are recorded in apm.lock.yaml, and the install no longer aborts.

Problem (WHY)

  • The vocabulary was stale. It was a flat KIRO_AGENT_ALLOWED_TOOLS set (from 2026-08). It rejected current Kiro tool IDs (web_fetch, grep_search, read_file, execute_bash, …) and every @server selector.
  • One bad agent aborted the whole install. The rejection used diagnostics.error, and finalize_install_result fails any install with an error diagnostic.
  • The conformant sibling was left behind untracked. On main, a package with gatherer.agent.md (tools: [read, web_fetch, grep]) and control.agent.md (tools: [read, web]) exits 1. control.md is left on disk, untracked by apm.lock.yaml.

Why this matters: req-tg-009 requires "failure for one agent MUST NOT prevent deployment of other, vocabulary-conformant agent primitives from the same dependency or install operation".

Approach (WHAT)

# Fix
1 Split the vocabulary into tags, special values, tool IDs, and a bounded @server[/tool] / subagent/<agent> regex. Each part comes from kiro.dev/docs/tools and the tools-field reference.
2 Keep fail-closed per agent: zero bytes, and the check still runs before the adopt fast-path. Emit diagnostics.warn instead of diagnostics.error, so the install proceeds for siblings. The warning lists the full approved set, built from the constants (req-tg-009).
3 Keep context and todo_list for compatibility. CLI 2.x-only names (grep, glob, use_aws) and @builtin/x / @mcp/x stay rejected.

Implementation (HOW)

  • src/apm_cli/integration/agent_integrator.py
    • Adds KIRO_AGENT_TOOL_TAGS, KIRO_AGENT_TOOL_SPECIAL_VALUES, KIRO_AGENT_TOOL_IDS and KIRO_AGENT_TOOL_COMPAT_VALUES. KIRO_AGENT_ALLOWED_TOOLS is now their union.
    • Adds _KIRO_SELECTOR_RE for @server, @server/tool (SEP-986 characters) and subagent/<agent>, each segment bounded at 128 characters, and adds is_kiro_agent_tool().
    • The three per-agent rejections in _preflight_render_kiro_agent now warn, with one shared hint that lists the approved set.
    • Frontmatter passthrough (description/model/tools only) is unchanged.
  • tests/unit/integration/test_kiro_target.py
    • Adds parametrized accept cases (current IDs, MCP and subagent/ selectors) and reject cases (legacy and malformed selectors).
    • Adds tests for the scalar and non-list tools forms, and a test that the warning names the full approved set.
    • Moves three existing assertions from the error category to the warning category.
  • tests/spec_conformance/test_manifest_reqs.py
    • Adds a new @pytest.mark.req("req-tg-009") end-to-end CLI test: one rejected agent, conformant siblings, exit 0, siblings locked. On reinstall, an agent that turned invalid is removed and unlocked, and its sibling stays byte-identical.
    • The existing adopt-ordering test now expects the warning category.
  • CONFORMANCE.{json,md} are regenerated: req-tg-009 goes from 1 test to 2.
  • Docs
    • instructions-and-agents.md, ide-tool-integration.md and targets-matrix.md now describe the new vocabulary and the per-agent skip.
    • The apm-usage/package-authoring.md resource is updated the same way.
    • enterprise/security.md gets an "Agent tool capability gate (Kiro)" section on the non-fatal gate.

Diagrams

Legend: what happens to each Kiro agent during install after this PR. The key change is the right-hand branch, which no longer fails the install.

flowchart LR
    A["agent tools value"] --> B{"is_kiro_agent_tool"}
    B -->|"tag, tool ID, @server, @server/tool, special"| C["render and write .kiro/agents/name.md"]
    C --> D["recorded in apm.lock.yaml deployed_files"]
    B -->|"anything else"| E["skip this agent, zero bytes"]
    E --> F["diagnostics.warn names the value"]
    F --> G["sibling agents keep deploying, install exits 0"]
Loading

Trade-offs

  • Warning, not error. I chose a warning so siblings deploy, as req-tg-009 requires. The rejected agent is still never written, so the fail-closed guarantee holds. The cost is that a CI run with a stale tool name exits 0. The warning names the value and the agent, and the change is documented in the CHANGELOG and enterprise/security.md. A strict or policy switch to make it fatal is deferred as out of scope.
  • Curated list, not passthrough. req-tg-009 mandates fail-closed against an enumerable vocabulary. Full field passthrough (mcpServers, permissions, hooks) stays out of scope (needs-design).
  • Compat values kept. context and todo_list are no longer in the Kiro docs. They stay accepted so agents that deploy today keep deploying, and removing them is a separate breaking decision.
  • Legacy CLI 2.x names stay rejected. Kiro documents grep, glob and use_aws as CLI 2.x only. The Markdown agents APM emits are a V3/IDE 1.0 format.

Benefits

  1. Agents using current Kiro tool IDs and MCP or subagent/ selectors deploy. 14 parametrized cases that were red on main are now green.
  2. One non-conformant agent no longer fails the install or leaves untracked files. The sibling is in deployed_files.
  3. The diagnostic lists the full approved set and links to the authoritative Kiro page.

Validation

Real CLI on this branch: gatherer uses read, web_fetch, grep_search, @github/get_issue, and legacy uses read, grep.

[!] [pkg] Kiro agent legacy.agent.md: unsupported tool(s) 'grep' -- agent will
not be deployed. Use a Kiro category tag (read, write, shell, web, subagent), a
built-in tool ID (e.g. read_file, grep_search, web_fetch), @server or
@server/tool, @builtin, @mcp, or *. Ref: https://kiro.dev/docs/tools/
[*] Installed 1 APM dependency in 1.9s.
exit=0
.kiro/agents/gatherer.md            # deployed_files: [.kiro/agents/gatherer.md]
Test and lint commands
Command Result
New tests on main (17993ab) 20 failed (red)
pytest tests/unit/integration/test_kiro_target.py tests/unit/integration/test_agent_integrator.py tests/spec_conformance/test_manifest_reqs.py 298 passed, 1 skipped
pytest tests/unit/integration tests/spec_conformance tests/unit/install 6927 passed, 11 skipped, 3 xfailed
APM_E2E_TESTS=1 APM_BINARY_PATH=.venv/bin/apm pytest tests/integration/test_kiro_agent_lifecycle.py 7 passed
Mutation: revert to diagnostics.error sibling req-tg-009 test fails (exit 1)
Mutation: drop the @server regex 2 MCP-selector cases fail
Mutations for the panel and Copilot folds (retain rejected record, scalar/non-list revert, example-only hint, pre-Copilot regex) each fails its test
CI on head 21704e0 all workflows green (one flaky red-team HTTP shard, unrelated, green on rerun)
uvx [email protected] check + format --check (CI paths) clean
pylint R0801, lint-auth-signals.sh, lint-architecture-boundaries.sh clean
spec collect-only + gen_statement no CONFORMANCE diff

Scenario evidence

# Scenario (user promise) Principle(s) Test(s) proving it Type
1 A Kiro agent using current tool IDs or @server selectors deploys Multi-harness, Portability by manifest tests/unit/integration/test_kiro_target.py::test_kiro_agents_current_kiro_tool_identifiers_deploy unit
2 Legacy or malformed tool values never reach .kiro/agents/ Secure by default tests/unit/integration/test_kiro_target.py::test_kiro_agents_reject_legacy_and_malformed_selectors unit
3 One bad agent does not block or orphan its sibling, the sibling is locked, and an agent that turns invalid is removed on reinstall Governed by policy, DevX tests/spec_conformance/test_manifest_reqs.py::test_kiro_agent_tools_gate_skips_one_agent_and_locks_siblings e2e (CLI)
4 A rejected agent is never adopted through the byte-identical fast-path Secure by default tests/spec_conformance/test_manifest_reqs.py::test_kiro_agent_tools_gate_fails_closed_before_adopt unit

How to test

  • Create a package with two .apm/agents/*.agent.md files: one with tools: [read, web_fetch, "@git"], one with tools: [read, grep].
  • In a project with targets: [kiro] and a .kiro/ dir, run apm install ../pkg.
  • Expect exit 0, one [!] warning naming grep, and only the first agent in .kiro/agents/ and in apm.lock.yaml.

Issue and approved scope

Issue: Fixes #2671

Human scope-approval comment: #2671 (comment)

This completes the approved scope. Full Kiro field passthrough is explicitly out of scope, stays needs-design, and is not part of this PR.

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Maintenance / refactor

Testing

  • Tested locally
  • All existing tests pass
  • Added tests for new functionality (if applicable)

Changelog

  • One line in one section under ## [Unreleased] in CHANGELOG.md:
    user-visible effect first, 25 words or fewer, ending with (#PR);
    breaking changes only under upgrade notes; no Highlights; see
    .github/instructions/changelog.instructions.md.
  • N/A -- internal-only change (CI, tests, refactor).

Spec conformance (OpenAPM v0.1)

  • Spec edit: not needed. The behaviour now matches req-tg-009 as written.
  • Manifest edit: not needed.
  • Test edit: a @pytest.mark.req("req-tg-009") test under
    tests/spec_conformance/ added or extended.
  • CONFORMANCE.{md,json} regenerated via
    uv run --extra dev python -m tests.spec_conformance.gen_statement
    and committed.
  • N/A -- this PR does not change OpenAPM-observable behaviour.

Co-authored-by: Copilot [email protected]

Kiro agent `tools` validation now follows the current Kiro docs
(https://kiro.dev/docs/custom-agents/configuration-reference/#tools-field,
https://kiro.dev/docs/tools/): category tags, current built-in tool IDs,
@server and @server/tool selectors, @Builtin, @mcp and *. CLI 2.x-only
names such as grep and use_aws stay rejected.

An agent with an unsupported tool is still never written (req-tg-009),
but the diagnostic is now a warning, so conformant sibling agents in the
same install deploy and are recorded in apm.lock.yaml instead of the
whole install aborting.

Refs #2671

Co-authored-by: Copilot App <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 19, 2026 16:21

Copilot AI 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.

🟡 Changes recommended

The validator rejects valid subagent/<name> selectors and MCP tool selectors whose tool names begin with _, -, or ., causing otherwise valid agents to be skipped.

2 open issues
What changed in this PR

This PR refreshes APM’s Kiro agent tool validation and makes rejection non-fatal per agent, so conformant siblings can deploy and be recorded in the lockfile. Full Kiro configuration passthrough remains outside scope.

Changes:

  • Expands accepted tool IDs and MCP selectors while retaining compatibility values.
  • Changes rejected-agent diagnostics to warnings without allowing partial writes.
  • Adds validation and sibling-install coverage, updates documentation, and regenerates conformance records.
File Description
tests/​unit/​integration/​test_kiro_target.py Adds selector acceptance/rejection cases and updates warning assertions.
tests/​spec_conformance/​test_manifest_reqs.py Verifies rejected agents do not block sibling deployment or lockfile recording.
src/​apm_cli/​integration/​agent_integrator.py Expands tool validation and emits per-agent warnings.
packages/​apm-guide/​.apm/​skills/​apm-usage/​package-authoring.md Updates authoring guidance for selectors and skipped agents.
docs/​src/​content/​docs/​reference/​targets-matrix.md Describes updated Kiro tool support and failure isolation.
docs/​src/​content/​docs/​producer/​author-primitives/​instructions-and-agents.md Explains selector validation and sibling deployment behavior.
docs/​src/​content/​docs/​integrations/​ide-tool-integration.md Updates the Kiro integration behavior summary.
CONFORMANCE.md Updates the req-tg-009 test count.
CONFORMANCE.json Records the additional req-tg-009 test.
CHANGELOG.md Announces expanded tool support and per-agent warnings.

Review effort: Balanced

req-tg-009 requires the diagnostic to identify the unsupported value and
the approved set; the hint is now derived from the vocabulary constants so
message and code cannot drift. Adds unit coverage for scalar and non-list
tools forms. Addresses panel follow-ups (supply-chain-security-expert,
test-coverage-expert).

Co-authored-by: Copilot <[email protected]>
The per-agent skip lets reinstall complete, so a previously deployed agent
whose tools become unsupported must be removed and dropped from the
lockfile while siblings stay byte-identical (req-tg-009). Addresses panel
follow-up (test-coverage-expert, supply-chain-security-expert).

Co-authored-by: Copilot <[email protected]>
Addresses panel follow-up (supply-chain-security-expert).

Co-authored-by: Copilot <[email protected]>
Kiro's tools field restricts sub-agent dispatch with subagent/<name>
(kiro.dev/docs/custom-agents/subagents), and MCP tool names may start
with _, - or . (SEP-986). Both were rejected, skipping valid agents.
Addresses Copilot inline on src/apm_cli/integration/agent_integrator.py
lines 80 and 97.

Co-authored-by: Copilot <[email protected]>
Addresses delta panel follow-up (supply-chain-security-expert): the
security model now states that unsupported Kiro tools skip only that
agent, write nothing, are not locked, and exit 0.

Co-authored-by: Copilot <[email protected]>
@danielmeppiel

Copy link
Copy Markdown
Collaborator Author

APM Review Panel: ship_with_followups

Kiro agents now fail closed one agent at a time: an unsupported tool skips only that agent (zero bytes written, nothing locked), and its siblings still deploy and lock. All in-scope follow-ups are folded; one out-of-scope strict-mode item is deferred.

panel-mode=lean -> delta; personas=supply-chain-security-expert,test-coverage-expert,apm-ceo

cc Sergio Sisternes (@sergio-sisternes-epam) -- a fresh advisory pass is ready for your review.

The panel has converged, and the delta panelists confirmed every in-scope follow-up from the first pass (at b8717fe) is folded at 21704e0.

  • Test coverage: no findings. The req-tg-009 real-CLI test now covers a reinstall after an agent becomes invalid: install exits 0, the agent file is removed and dropped from apm.lock.yaml, and its sibling stays byte-identical. The scalar and non-list forms of tools now have unit tests.
  • Supply-chain security: the req-tg-009 diagnostic regression is fixed. The warning now lists the full approved set, built from the vocabulary constants and checked by a unit test. Fail-closed still holds: the check runs before any write or adopt step, so a rejected agent writes zero bytes and is never recorded.

Both Copilot inline items were checked against primary sources and folded:

  • MCP tool names: SEP-986 allows _, - and . anywhere in a tool name. The tool segment now accepts them and is still capped at 128 characters.
  • Sub-agent selector: Kiro documents subagent/<name> for limiting which sub-agents an agent can start. It is now accepted, also bounded.

Security reviewed both widened selectors and confirms they stay inside a safe ASCII boundary.

The exit-code change is disclosed in two places: the CHANGELOG line, and a new "Agent tool capability gate (Kiro)" section in enterprise/security.md. One item remains, and it is out of scope: a strict or policy switch that would make the gate fatal after siblings deploy. That adds a new governance surface beyond #2671's approved scope, so it should be tracked as its own issue.

Dissent. None. The supply-chain item was split in two: the docs disclosure is folded here, and the strict or policy switch is deferred.

Aligned with:

  • Secure by default: a rejected agent writes zero bytes and is never adopted or locked, and it is removed on reinstall. The real-CLI tests prove this.
  • Governed by policy: the gate warns by default and has no strict override yet. That is documented in the CHANGELOG and security.md.
  • Multi-harness: the Kiro vocabulary now follows current Kiro docs and the MCP SEP-986 naming rules.
  • Pragmatic as npm: one bad agent is skipped and the rest install, with a warning that lists the approved set.

Panel summary

Persona B R N Takeaway
Supply Chain Security Expert 0 1 0 The approved-set and reinstall findings are resolved. The widened selectors stay inside a safe ASCII boundary. Only the deferred strict switch and its security.md disclosure remain, and the disclosure is now folded.
Test Coverage Expert 0 0 0 Both earlier gaps are resolved: the reinstall-invalidation case is tested through the real CLI, and the scalar and non-list branches are covered. No gaps remain.

B = blocking-severity findings, R = recommended, N = nits.
Counts are signal strength, not gates. The maintainer ships.

Top 1 follow-up

  1. [Supply Chain Security Expert] Track separately, not in this PR: a strict or policy option that makes unsupported-capability rejections fatal after siblings deploy and lock. -- This would bring back CI gating for pipelines that relied on exit 1, but it is a new governance surface beyond [FEATURE] Preserve full Kiro custom-agent config when compiling to the kiro target #2671's approved scope.

Recommendation

Ship once CI on the head is green; it is now green at 21704e0. All in-scope folds are done: the full approved set in the diagnostic, the reinstall end-to-end test, the scalar and non-list tests, the CHANGELOG exit-code wording, the security.md disclosure, and both Copilot vocabulary fixes. The one thing to track is the out-of-scope strict or policy switch, as a separate issue.

Folded in this run

  • (supply-chain-security-expert) The rejection warning lists the full approved set, built from the constants (req-tg-009). Resolved in 40354b3.
  • (test-coverage-expert) Unit tests for the scalar and non-list forms of tools. Resolved in 40354b3.
  • (test-coverage-expert, supply-chain-security-expert) The req-tg-009 end-to-end test now covers an agent that becomes invalid on reinstall. Resolved in 54d15e0.
  • (supply-chain-security-expert) The CHANGELOG states the exit-code change. Resolved in 4e6d696.
  • (Copilot) SEP-986 MCP tool names and subagent/<agent> are accepted. Resolved in 65d5a04.
  • (supply-chain-security-expert, delta pass) enterprise/security.md documents the non-fatal gate. Resolved in 21704e0.

Copilot signals reviewed

  • src/apm_cli/integration/agent_integrator.py:80 -- LEGIT: SEP-986 allows _, - and . at the start of a tool name (resolved in 65d5a04).
  • src/apm_cli/integration/agent_integrator.py:97 -- LEGIT: Kiro documents subagent/<name> in tools (kiro.dev/docs/custom-agents/subagents) (resolved in 65d5a04).

Deferred (out-of-scope follow-ups)

Regression-trap evidence (mutation-break gate)

Each guard below was removed, the test failed as expected, and the guard was restored.

Test Guard removed
test_kiro_agent_tools_gate_skips_one_agent_and_locks_siblings The warning reverted to an error
test_kiro_agent_tools_gate_skips_one_agent_and_locks_siblings (reinstall step) A rejected agent's deployed record was retained
test_kiro_agents_current_kiro_tool_identifiers_deploy The @server selector regex was dropped, or the pre-Copilot regex was restored
test_kiro_agents_scalar_and_non_list_tools_forms The scalar branch reverted to an allow-list lookup, or the non-list branch reverted to an error
test_kiro_agents_rejection_names_the_full_approved_set The hint reverted to examples only

Lint contract

  • ruff check and ruff format --check (pinned at 0.15.12, CI paths): both silent.
  • pylint R0801, lint-auth-signals.sh and lint-architecture-boundaries.sh: all clean.

CI

All workflows are green on 21704e0: CI, Merge Gate, Spec conformance, CodeQL, NOTICE Drift, and Deploy Docs. It took 1 CI fix iteration. Build & Test Shard 1 hit a flake, tests/red_team/http/test_resource_exhaustion.py::TestDispatchThreadCap, which is unrelated to this PR and passed 3 of 3 locally. A failed-job rerun turned it green.

Mergeability status

PR head SHA CEO stance iters folds defers Copilot rounds CI mergeable mergeStateStatus notes
#3947 21704e0 ship_with_followups 2 6 1 1 green MERGEABLE BLOCKED pending required review
Full per-persona findings

Supply Chain Security Expert

  • [recommended] The gate is still non-fatal, there is no strict opt-in, and enterprise/security.md did not document it. At docs/src/content/docs/enterprise/security.md.
    • The CHANGELOG now discloses that a rejected agent means exit 0. The CI-gating trade-off remains, and deferring the switch is acceptable because it is out of scope. The persona contract says the security model doc must match behavior.
    • Suggested: add one sentence to security.md, and file a follow-up issue for the strict switch. The security.md sentence is folded in 21704e0.

Test Coverage Expert

No findings.

This panel is advisory. It does not block merge. Re-apply the
panel-review label after addressing feedback to re-run.


Generated by autopilot-pr-merge-worker. This comment is AI-generated and may contain errors.

@danielmeppiel Daniel Meppiel (danielmeppiel) added this to the 0.37.0 milestone Nov 19, 2026
@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit a532989 into main Nov 19, 2026
34 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the danielmeppiel-community-bug-repro-0-37 branch November 19, 2026 17:46
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 19, 2026
Resolve package-authoring.md Kiro conflict: keep main's per-agent fail-closed wording (#3947) with this PR's targets: [kiro] spelling.

Co-authored-by: Copilot <[email protected]>
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.

[FEATURE] Preserve full Kiro custom-agent config when compiling to the kiro target

2 participants