Repository navigation
refactor(kas): split kas_agents.py by moving mcp projection to owners - #37828
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 move behind the repo's existing [DESIGN-REVIEWED] c7e3f28 Description read[DESCRIPTION-READ] 710da7ed6980a7cb84d13a521f6b68dafb5ab2f8ba9c75965e06ceee87e33964 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: this is a pure move that the AGENTS.md 2,000-line cap requires, using the repository's existing What this change shipsInventory (6 items) — 6 justifiedIntent: bring
[FIRST-PRINCIPLES-REVIEWED] c7e3f28 Description read[DESCRIPTION-READ] c0e4f93ff89c51446f849875ea095942d1274fa959b67f2c1e13de57cd514cfc 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: |
Move the mcpServers projection (_project_mcp_servers and its constants) into acp/kas_agents_mcp_servers.py and the session-level hoist (hoist_servers_for_session and its helpers) into acp/kas_agents_session_hoist.py, verbatim. kas_agents.py drops from 2,004 to under 1,450 lines and becomes a _facade_mirror facade over those owners and kas_agents_registered.py, so every name stays importable and patchable at kiro_crew.acp.kas_agents. No logic change. Part of #36565
a51ec0a to
c7e3f28
Compare
Code change approver recommendation: A person should decideWhy: the decider estimates a 6% chance that this change introduces a defect, within the 12% limit for approving on its own, but it changes 1866 lines, more than the 400 it may approve on its own. This is a pure move of the mcpServers projection and the session-level hoist out of kas_agents.py into two sibling owners, with kas_agents.py kept as a _facade_mirror facade, the shape the repo's code-style spec requires. I checked that the moved bodies are unchanged, that every global they read is still bound on the facade (so a facade patch reaches them), that owners load in layer order and never import the facade, that the logger name is preserved, and that all is derived from the namespace as the spec says. A new facade test checks patch reach, owner order, which names are served, and the single logger. All CI checks are green. No behaviour change, regression or trust-boundary issue found. An automated recommendation, not a review: a maintainer still decides. It approves on its own only when the estimated chance of a defect is at most 12% and the change has at most 400 changed lines. Decider v3c (217fe607) · commit |
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
I reviewed head c7e3f28. Each moved definition (the mcpServers projection with its constants, and the session-level hoist with its helpers) has the same source text as the merge base, and every definition that stayed in kas_agents.py is unchanged. The facade still binds or serves every name it had before, the owners import the same source objects and log under the same logger name, and no owner imports the facade. On this head, every test file that references kas_agents plus the facade guard suites pass (5894 passed, 0 failed), and flake8 is clean on the touched files. This is a pure move with no behaviour change, so nothing blocks.
Problem / Motivation
Goal: Bring
src/kiro_crew/acp/kas_agents.py(2,004 lines) back under the 2,000-line cap with a pure move, so the main ratchet audit stops naming it.Main's Ratchet Audit has been red on every push since 11/13 because two files are over the cap (#36565). This PR handles
acp/kas_agents.py;hooks.pyis split separately.Why it matters
While a file is over the cap, every PR that touches it fails
backend-ratchets, and the whole-tree audit on main stays red, which hides real regressions behind a known failure.Not a goal
src/kiro_crew/hooks.py(handled in its own PR).kas_agents.projected_write_allowlist,kas_agents.withheld_credentials_notice).What changed (motivation → approach → change)
kas_agents.pyheld two jobs beside the agent projection: deciding themcpServersblock, and hoisting the active agent's managed servers into the session-level array. Each moves whole into its own owner, so the file can stay the projection and the one import path:acp/kas_agents_mcp_servers.py(403 lines):_project_mcp_serversand its constants (MANAGED_MCP_SERVER_NAMES,WithheldOut,NOT_RUN_*,_CREDENTIAL_BEARING_FIELDS,_WRAPPER_MARKERS).acp/kas_agents_session_hoist.py(311 lines):hoist_servers_for_session,_HOISTABLE_ENTRY_KEYS,_managed_first,_managed_entry,_tokened_managed_element.acp/kas_agents.py(2,004 → 1,439 lines) becomes a_facade_mirrorfacade over those owners and the existingkas_agents_registered.py. It keeps every import it had, imports back each moved name a caller or its own code reads, and serves the six owner-only names through the mirror. A patch ofkiro_crew.acp.kas_agents.<name>therefore still reaches the moved code (_registry_governedis read inside_project_mcp_servers). Both owners log askiro_crew.acp.kas_agents.__all__is derived from the namespace, as the spec asks for a module that had none.Moved bodies are byte-identical to main; only module headers are new.
Backwards compatibility
Compatible: every name
kiro_crew.acp.kas_agentsbound on main still resolves there, to the same object (proof below), and no caller or test import changed.The diff deletes definitions from
kas_agents.py(they move to the owners). Every reader still gets them from the old path:Reader: src/kiro_crew/acp/runtime.py:hoist_servers_for_session -- chat -- imported from
kiro_crew.acp.kas_agents, which binds the owner's function; test_kas_agents_mcp_servers.pyReader: src/kiro_crew/acp/runtime_session_create.py:hoist_servers_for_session -- chat -- same import, same object; test_kas_agents_mcp_spec_gate.py
Reader: src/kiro_crew/acp/runtime_session_load.py:hoist_servers_for_session -- chat -- same import, same object; test_kas_env_launch_resume.py
Reader: src/kiro_crew/acp/kas_withheld_notice.py:WithheldOut -- chat --
WithheldOutand the threeNOT_RUN_*constants are imported back onto the facade; test_acp_runtime.pyReader: src/kiro_crew/acp/kas_agents.py:to_client_custom_agent -- chat -- calls
_project_mcp_servers, imported back from its owner; test_kas_agents.pyReader: test/test_mate_work_ledger_mount.py:_project_mcp_servers -- subagent --
from kiro_crew.acp.kas_agents import _project_mcp_serversresolves to the owner's function; test_mate_work_ledger_mount.pyReader: test/test_kas_app_mcp_session_identity.py:MANAGED_MCP_SERVER_NAMES -- chat -- imported back onto the facade, same frozenset object; test_kas_app_mcp_session_identity.py
Reader: test/test_kas_agents_facade.py:_managed_first -- chat --
_managed_first,_managed_entry,_tokened_managed_element,_HOISTABLE_ENTRY_KEYS,_CREDENTIAL_BEARING_FIELDSand_WRAPPER_MARKERShave no reader outside the owners and are served from them by the mirror; test_kas_agents_facade.pyTests
test/test_kas_agents_facade.py: every name the test trees patch through the facade reaches every holder (including an owner,_registry_governed); the owners are exactly thekas_agents_*.pysiblings in layer order and never import the facade; only the six owner-only names are served; the family logs under one logger. Opts into the sharedknown_seamscheck.test/campaign_facade_inventories/kiro_crew.acp.kas_agents.json: the 120 public names main bound, and 99 import-bound ones checked against their home object.Proof of the split, against base fd4b0d4:
kiro_crew.acp.kas_agentson the base and on the branch. All 166 names bound on the base resolve on the branch (0 missing). Each name bound by import is its home module's own object (0 mismatches). The branch adds only mirror glue (_EXPORTS,_KAS_AGENTS_OWNERS,_SERVED,_MIRROR,_facade_mirror,_importlib,_sys,_owner).from kiro_crew.acp.kas_agents import,kas_agents.<name>orpatch("kiro_crew.acp.kas_agents.<name>")insrc/andtest/resolve on the branch. The only ones that do not,projected_write_allowlistandwithheld_credentials_notice, are comment citations that already fail to resolve on the base.SCOPED_TESTS_BASE_REF=<merge-base> scripts/run_scoped_tests.py --surface backend, 90 files) on a Linux DevSpace: 4679 passed, 5 skipped, 0 failed. With nothing red, no comparison run on base was needed. Locally,test_facade_mirror_guards.py,test_facade_shared_checks.py,test_campaign_facades_base_public_names.pyandtest_mirrored_owner_storage.pywith the new facade test: 1169 passed.scripts/check_file_line_cap.py: the scoped run passes. WithRATCHET_SCOPE_WHOLE_TREE=1the only file it names issrc/kiro_crew/hooks.py(the sibling split).kas_agents.pyhas no baseline row.mypy src/kiro_crew(4734 files, clean), the black gate (black 26.10.1), comment-history, brand-name, subprocess-encoding,test/test_flake_pattern_ratchet.py(71 passed),semgrep scan --config semgrep/ --baseline-commit <merge-base> --error(clean) andscripts/docs_lint.pyall pass.Manual verification
N/A — a pure move of whole definitions; the related backend set and the facade guards cover the import and patch surface.
Related Issues
Part of #36565
Open PRs that touch this file, and what each one meets after this split (from
gh pr diff):kas_agents.pymcp_cleanupimport (+mcp_entry_is_remote); 2 hunks in_project_mcp_serverskas_agents_mcp_servers.py_ceiling_permitted,to_client_custom_agentkas_agents.py; only line offsets shiftmcp_provenanceimport; 1 hunk in_project_mcp_serverskas_agents_mcp_servers.py_ceiling_permitted;to_client_custom_agent; deletes_managed_entry/_tokened_managed_element(-65 lines)_ceiling_permittedandto_client_custom_agenthunks stay inkas_agents.py. The deletion and itskas_managed_entriesimports move tokas_agents_session_hoist.py, and those two names leave_SERVEDand theTYPE_CHECKINGblockChecklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)