Repository navigation
refactor(agent): move the rebuild, prompts and grants to agent_parts - #22981
Conversation
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: this is a pure structural move. It follows the facade-compose pattern from #22890, keeps every import path and patch seam, and the inventory and contract tests pin both. [DESIGN-REVIEWED] fd80f36 Description read[DESCRIPTION-READ] 25788a6ecedf0f7b9bdff01389e37c6b6d6d97e9cb70d995ea41f00c87876a4f That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing blocks: a structural split that AGENTS.md's 2,000-line cap requires, with every public name still resolving on the facade. What this change shipsInventory (6 items) — 6 justifiedIntent: shrink
[FIRST-PRINCIPLES-REVIEWED] fd80f36 Description read[DESCRIPTION-READ] 6108e825ecead109e4ece75a0015dc5d463f4f8a77e2e55562c371f2be13b177 That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.5 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 6.1 Review — ✅ no blocking findingsGPT 6.1 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: |
be80704 to
16bbd86
Compare
The second of two PRs that bring agent.py under the 2,000-line cap. It moves the rebuild with its governance-ceiling projection, the agents' system prompts and their server grants, unchanged, into three more kiro_crew.agent_parts owners (spec_rebuild, spec_prompts, spec_grants); agent.py drops from 4,070 to 1,566 lines and leaves the line-cap baseline. The owners run on agent.py's module globals through kiro_crew._facade_compose.compose, as the first six do, so the rebuild's global rebinds still land on the facade that fork_refresh and the tests read. agent.py wraps rebuild_agent_config (and its alias install_agent) again around a rebound copy, since compose reaches the outcome tracker's wrapper but not the function its closure holds. The knowledge, research and heartbeat prompts stay in agent.py: their bytes spell the product name joined, which the brand gate refuses on a moved line. test/test_agent_parts.py grows to the nine owners and pins the re-wrap and the tracker's global rebinds; path-keyed test rows and the docs that cite the moved code follow it. Part of #20192
16bbd86 to
fd80f36
Compare
iamwhatever
left a comment
There was a problem hiding this comment.
APPROVE at fd80f36.
This is a faithful move. Of the 82 top-level units in BASE agent.py, 78 are AST-identical at their new home, 3 differ only in docstrings, and the last is the _PARTS tuple. So the grant tuples, require_fork_governance and the prompts move unchanged. The facade rebinds every owner function onto its own globals, then re-applies _tracks_rebuild_outcome around a rebound rebuild_agent_config and binds install_agent to the same object, as BASE did (agent.py L493-L510). Every AI lane passed with no notes, checks are green, and the branch merges cleanly into main.
— crew-pr-reviewer (r119)
Problem / Motivation
Goal: Bring
agent.pyunder the 2,000-line cap with every import path, patch seam and behaviour unchanged; this second PR moves the rebuild, its governance-ceiling projection, and the installed agents' prompts and grants intoagent_parts.src/kiro_crew/agent.pyis 4,070 lines on main after #22890, still over the repository's 2,000-line limit for hand-written files, and still listed in.github/file-line-cap-baseline.txt. Its largest unit,rebuild_agent_config(523 lines), is the function most agent-spec changes touch.Why it matters
The line cap only holds if the files on its baseline shrink. Until this half lands, every change to the rebuild order, a conductor prompt or a grant tuple edits a 4,000-line module, and the file keeps its baseline row.
Not a goal
kiro_crew.agentheld still resolves on it as the same object.agent_materializationowners, to howkiro_crew.agentforwards to them, or to the six owners refactor(agent): move spec writes, build and lookups to agent_parts #22890 added.agent.py's line-cap row, the inventory JSON, and the path rows of two tests that read moved code by path; five more test files get comment-only cite fixes.What changed (motivation → approach → change)
agent.pykeeps its import path and its facade shape from #22890; three more owners inkiro_crew.agent_partstake whole definitions moved without edits:agent_parts/spec_rebuild.py(1,420)rebuild_agent_configand its outcome tracking, the ceiling-projection memo and the entry points that re-project the specs, the fork-governance check,ensure_agent_materialized, and the installs the rebuild drivesagent_parts/spec_prompts.py(674)agent_parts/spec_grants.py(585)The same
kiro_crew._facade_compose.composecall runs the new owners' functions onagent.py's globals, so a patch throughkiro_crew.agentstill reaches the moved code andglobalrebinds still land there.rebuild_agent_configis wrapped where it is defined (_tracks_rebuild_outcome), and compose reaches a wrapper but not the function its closure holds, soagent.pywraps it again around a rebound copy and bindsinstall_agentto the same object, as it was.agent.pygoes from 4,070 to 1,566 lines and its baseline row is deleted.Backwards compatibility
Compatible: every name
kiro_crew.agentheld still resolves on it as the same object (pinned bytest/campaign_facade_inventories/kiro_crew.agent.json, now 76 names pinned to their home object, andtest_agent_refactor_contracts.py's frozen surface), and a patch through it still reaches the code that reads the name, because that code runs on its globals.Reader: src/kiro_crew/agent.py:rebuild_agent_config -- release -- re-wrapped on the facade around a rebound copy;
slack/gateway_runtime/service_boot.py:155andmcp_broker.py:164import it fromkiro_crew.agent; test_agent_parts.py::test_the_rebuild_tracker_rebinds_its_globals_on_the_facadeReader: src/kiro_crew/agent.py:rebuild_agent_config_reporting -- crew page -- composed from
agent_parts.spec_rebuild;dashboard/handlers/_shared_config_followups.py:42andconnections/ownership.py:712import it fromkiro_crew.agent; test_agent_home_isolation.pyReader: src/kiro_crew/agent.py:ensure_agent_materialized -- chat -- composed;
acp/client_start.py:257andacp/harness/kas.py:455reach it throughkiro_crew.agent; test_acp_harness_contract.pyReader: src/kiro_crew/agent.py:require_fork_governance -- chat -- composed;
acp/client_start.py:286andacp/harness/kas.py:453reach it throughkiro_crew.agent; test_agent_spec_hardened_reads.pyReader: src/kiro_crew/agent.py:prime_ceiling_projection -- release -- composed;
slack/gateway_runtime/service_boot.py:1116imports it fromkiro_crew.agent; test_conductor_allowed_tools_survive.pyReader: src/kiro_crew/agent.py:reproject_for_ceiling_change -- release -- composed;
service_boot.py:1141registers it as a post-install hook; test_agent_refactor_fork_refresh.pyReader: src/kiro_crew/agent.py:reproject_for_profile_change -- release -- composed;
service_boot.py:1095imports it fromkiro_crew.agent; test_governance_profile_reprojection.pyReader: src/kiro_crew/agent.py:retry_held_conductor_specs -- release -- composed;
slack/gateway_runtime/process_entry.py:439imports it fromkiro_crew.agent; test_agent_refactor_fork_refresh.pyReader: src/kiro_crew/agent.py:sync_aim_packages -- release -- composed; called by
rebuild_agent_configfrom the same globals; test_agent_refactor_contracts.pyTests
test/test_agent_parts.pycovers the three new owners with the same contract as refactor(agent): move spec writes, build and lookups to agent_parts #22890's six: every composed function runs onkiro_crew.agent's globals, names it as its module and is the object it binds; the bytecode sweep finds every global bound there; the patch scan of the test trees reaches each owner; owners import stdlib plainly and the facade only for type checking; nothing but the facade imports an owner. New here: the rebuild's outcome tracker rebinds_rebuild_incompleteand_projected_ceiling_generationon the facade when the rebuild raises; a facade patch reaches the rebuild;install_agentis the re-wrapped rebuild; the fresh-interpreter value check now covers at least 40 module-level values.test_ledger_conductor_agent.pyre-points its read fromagent.pytoagent_parts/spec_rebuild.py;test_agent_spec_hardened_reads.pykeysrequire_fork_governance's row onagent_parts/spec_rebuild.py.test/campaign_facade_inventories/kiro_crew.agent.json: the 84 BASE public names, 76 pinned to their home object.Local floor at this head (
-n 3, through the campaign's gate slots): the 608 test files that import, patch or readkiro_crew.agentor its owners, plus every test that scans the source tree and the repository guards. 30,525 passed, 98 skipped, 6 xfailed, 0 failed. Per-file line coverage (--cov=kiro_crew, the 234 test files that import the facade):spec_rebuild92.4%,spec_prompts100%,spec_grants100%,agent.py93.1%; the six #22890 owners stay at 89.9-97.4%.test/test_agent_parts.pypassed five times at-n0and in the-n 3floor; the flake-pattern and wait-discipline ratchets pass.Manual verification
N/A — a structural move: the move audit proves the moved code is unchanged, and the floor above runs every test that imports, patches or reads
kiro_crew.agent.Related Issues
Part of #20192
Move audit
python3 bin/move_audit.py --base <merge-base> --head <this head>(units keyed by AST, positions and comments ignored):Expris the facade's module docstring (rewritten for the layout) andAssignis the_PARTSowner tuple (three owners added). The three functions' only edit is a docstring reword; stripping docstrings, 82 of the 83 units of main'sagent.pyare AST-identical at their new home, and the 83rd is_PARTS. Every non-move edit inside moved code:rebuild_agent_config;rebuild_agent_configdocstring: names "AIM's mcp-servers directory" instead of a home-directory path, because the 523-line function cannot stay inagent.pyunder the cap;_install_aim_capabilitiesdocstring: "Amazon-internal package manager" -> "internal package manager";sync_aim_packagesdocstring: "Amazon-internal agents/skills/plugins package manager" -> "internal agents/skills/plugins package manager".rebuild_agent_configcomment abovesync_shared_server_refs: "viaaim mcp install" -> "via AIM's installer" (the internal content scan'saim-invocationrule; comment only, AST unchanged).Diff shape
git diff <merge-base>...HEAD | wc -c= 344,753 bytes.git diff --numstatandgit diff --minimal --numstatare identical for all 27 files;agent.py+73/-2577 under both.agent_parts/spec_rebuild.py1,420,spec_prompts.py674 andspec_grants.py585 lines.agent.pyends at 1,566 lines, so this PR deletes its row from.github/file-line-cap-baseline.txt.CI path references
None: no workflow path filter or file list names
agent.py.Facade target exception
The card's target for
agent.pyis 1,200 lines; it ends at 1,566 (Master ruling R2, inside the campaign's 1,600). What stays, and why:agent.pyTYPE_CHECKINGblocktest_agent_refactor_facade.pypins exactly one block equal to_EXPORTS_EXPORTS_BY_OWNERand the forwarding machinerykiro_crew.agent_materializationmay appear only in agent.py and that package_MANAGED_MCP_SERVERS_kirocrew_mcp_invocation)_all_skill_pathsand its alias.aimliterals stay in their original file (L31)_refresh_dynamic_fields_KIRO_MCP_JSON,_CC_MCP_JSON,_DEFAULT_KIRO_HOOKS_DIR_SHARED_KIRO_PATHSand the host-isolation ratchet key them by module_BUNDLED_CFG_DIR__file__at importSharedAgentHomeRefused,ForkGovernanceUnresolvedkiro_crew.agentas their moduleNotes for reviewers
agent.pyonce (fix(pi): honour an agent spec's zero-tool ban on pi sessions #22808 addedknowledge_agent_modelto the forwarding table and theTYPE_CHECKINGblock); those lines are kept, and nothing upstream touched the moved rebuild, prompts or grants.agent.logger(kiro_crew.agent), no owner binds a logger, no class moves._MANAGED_MCP_SERVERSis built; the pinned 7-statement tail is unchanged.docs/architecture/mcp.md:2255;docs/architecture/overview.md:29;docs/system-specs/modules/config.md:3973;heartbeat.md:114, 154;pipeline-conductor.md:37-38;session-control.md:1892, 2148;src/kiro_crew/docs/agent-spec-fields.md:846-847, 887, 894and a new "Where to look" row forspec_rebuild.py;src/kiro_crew/agent_files.py:120;src/kiro_crew/dashboard/side_readonly_spec.py:23;src/kiro_crew/mcp_discovery_config.py:224;src/kiro_crew/mcp_discovery_server_info.py:113;src/kiro_crew/mcp_gateway/rewriter_launch.py:193, 206. Test comments and docstrings (no assertion or code change):test/test_conductor_agent.py:181agent.py->agent_parts/spec_grants.py;test/test_goal_conductor_skill_grants.py:4agent.py->agent_parts/spec_grants.py;test/test_worker_agent_spawn_gate.py:316, 396"the definitions themselves" -> "the facade binding these names";test/worker_agent_helpers.py:48"defining every name" -> "binding every name";test/test_app_mcp_scoping.py:1186-1188"composed from the agent_materialization modules" -> "composed from its agent_parts owners and the agent_materialization modules";test/test_app_mcp_scoping.py:1342-1343"inagent.py" -> "inagent.pyand itsagent_partsowners".docs/request-for-change/and the RFCs and plans that name agent.py (Master ruling R7).scripts/local-gate.py --dry-runselects most of the suite (the bareagentstem matches it), so the floor above ran instead. Static gates at this head: black, isort (whole tree), flake8, coldmypy src/kiro_crewon agit archiveexport (3,507 files, clean), subprocess-encoding, agent-sdk boundary, sync-io, memory-store seam, lockdown, harness parity, comment history, brand, feature map, line cap, docs lint, cross-platform replay (0 findings), code-review.yml greps, semgrep 1.78 with the CI configs and--baseline-commit(0 findings, no parse errors), andcheck_inventory.py(84/84). Installed-mode smoke: a wheel built from agit archiveexport importskiro_crew.agentand all nine owners from site-packages, composed (rebuild_agent_configruns on the facade's globals andinstall_agentis the same object).Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement
Contributed under the project's Apache-2.0 license.