Repository navigation
refactor: split cli_server.py and mcp_shared.py into facade owners - #21648
Conversation
Sensitive change review
|
fb25e2e to
20cec79
Compare
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Sensitive Change ReviewSensitive files changed:
|
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Check that no test or caller assigns [DESIGN-REVIEWED] c380de7 Description read[DESCRIPTION-READ] 7969d7db0e98b29def44e79058b41fc61ee15a8510119aca49d456ac9552052d 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 Before merging, confirm the seven "changed" bodies in the move audit ( What this change shipsInventory (9 items) — 9 justifiedIntent: bring
[FIRST-PRINCIPLES-REVIEWED] c380de7 Description read[DESCRIPTION-READ] cbf4689f6345424bb2a921783036273a8228dc4550939218c76c11b10d32298e 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: |
Security Scope Review -- ✅ human override accepted@bolichen97 overrode this lane for [SCOPE-REVIEWED] c380de7 |
|
/ai-review override scope 20cec79: the 8 newly refused rows are inline payloads naming cli_server_ owner paths. They are the moved twins of payloads base already refuses for src/kiro_crew/cli_server.py (security.md mint surface: import or file path). Probed at base vs head: base allows exec(open('src/kiro_crew/cli_server_requests.py').read()); _token(None) and head refuses it; non-mint paths stay allowed. Narrowing would reopen that token mint. |
Human judgment recorded@bolichen97 marked the scope AI finding as false positive, not applicable, or explicitly accepted for
This decision applies only to this commit. A new push requires a new judgment. |
|
20cec79 to
bdfb14f
Compare
|
|
/ai-review override scope bdfb14f: same patch as 20cec79 (-U0 identical, rows aside). All 12 newly refused rows are inline payloads naming cli_server_ owner paths, moved twins of payloads base already refuses for src/kiro_crew/cli_server.py (security.md mint surface: import or file path). Probed at base vs head: base allows exec(open(src/kiro_crew/cli_server_requests.py).read()); _token(None) and head refuses it; non-mint paths stay allowed. Narrowing would reopen that token mint. |
Human judgment recorded@bolichen97 marked the scope AI finding as false positive, not applicable, or explicitly accepted for
This decision applies only to this commit. A new push requires a new judgment. |
|
|
cli_server.py (4,003 lines) and mcp_shared.py (3,504) were past the 2,000-line cap. Each becomes a kiro_crew._facade_mirror facade over sibling owners, so every name either module held still resolves on it and a patch through it reaches every module that holds the name. cli_server.py keeps file-delivery approve, status, gateway, run, service, sandbox and logs. The gateway peer proof and _CLI_LOOPBACK move to cli_server_peer, the token, logout and update-approve requests to cli_server_requests, and stop, restart and update to cli_server_stop, cli_server_restart and cli_server_update. mcp_shared.py keeps run_mcp_stdio_loop, its process identity and its hard-exit handlers; the wire, the tool-call model, the tool policy and the dispatch loop move to mcp_shared_wire, mcp_shared_calls, mcp_shared_policy and mcp_shared_dispatch. Each global rebound at run time stays with its writer and readers, the owners log under the facade names, and the moved exception and enum classes keep their module names. The inline-payload mint fence widens cli_server to cli_server_<role>, so the moved token, stop, restart and update commands stay mint surfaces. Path-keyed registries, specs and CI path lists follow the moved code. Part of #20192
bdfb14f to
c380de7
Compare
|
|
/ai-review override scope c380de7: same patch as bdfb14f (-U0 identical, rows aside). All 9 newly refused rows are inline payloads naming cli_server_ owner paths, moved twins of payloads base already refuses for src/kiro_crew/cli_server.py (security.md mint surface: import or file path). Probed at base vs head: base allows exec(open(src/kiro_crew/cli_server_requests.py).read()); _token(None) and head refuses it; non-mint paths stay allowed. Narrowing would reopen that token mint. |
Human judgment recorded@bolichen97 marked the scope AI finding as false positive, not applicable, or explicitly accepted for
This decision applies only to this commit. A new push requires a new judgment. |
|
|
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
Approved on the watch holder's request. Every check on the head passes; the triage cron held it on a size, path, checklist or lane-note rule. Any standing lane note stays on the record.
Problem / Motivation
Goal: Bring
cli_server.py(4,003 lines) andmcp_shared.py(3,504 lines) under the 2,000-line cap without changing what either does, so new work on the CLI's server commands and on the MCP stdio plumbing lands in modules sized for it.Both files are past the repository's 2,000-line cap for hand-written files and are listed in
.github/file-line-cap-baseline.txt.mcp_shared.pygrew 89 lines past its baseline row while this campaign ran. Every server command (stop,restart,update,token, ...) shares one file, and so do the stdio wire, the tool-call model, the tool policy and the dispatch loop of every managed MCP server.Security fence change (maintainer attention)
The inline-payload mint gate (
security/inline_payload.py,_MINT_SURFACE_RE) namedkiro_crew.cli_serveras a credential-mint surface. Thetokencommand, the gateway peer proof,stop,restartandupdatenow live incli_server_requests,cli_server_peer,cli_server_stop,cli_server_restartandcli_server_update, which the old pattern does not match, sopython -c "from kiro_crew.cli_server_restart import _restart; _restart()"(which prints a fresh token URL) would no longer be denied. Branches 1 and 3 of the pattern widen fromcli_server(?![a-z0-9_])tocli_server(?:_[a-z0-9]+)*(?![a-z0-9_]), and nothing else in the pattern changes. That restores the reach the gate had over this code before the split; it denies nothing it did not deny before.test_cli_server_facade.pypins it both ways: every owner path is a mint surface,security.is_deniedrefuses the payload above, and a neighbouring module (cli_setup, a made-upcli_serverless) is not one. Without the widening, those cases are red; see Tests.security.mdnames the owners in the sentence that lists the mint surface. The security package's line total is unchanged (the edit is two lines in place). The Master granted this edit.Why it matters
A file over the cap makes every feature PR that touches it grow a baselined file, which the line-cap guard reports and the campaign must later undo. These two are among the most-edited files in the tree:
cli_server.pygrew 451 lines in one change while this PR was in review, and_run_stdio_dispatch_loopalone grew from 707 to 1,317 lines in two weeks.Not a goal
kiro_crew.cli_serverandkiro_crew.mcp_sharedoffer, or to how a test patches them._run_stdio_dispatch_loopitself: it moves whole and stays one 1,317-line function.What changed (motivation → approach → change)
Each file becomes a mirror facade (
kiro_crew._facade_mirror, the shapecli.pyandmcp_core.pyalready use) over sibling owner modules. The facade keeps its import header byte-identical and the code that sits on top, imports its owners, and serves every name they define, sokiro_crew.cli_server.<name>andkiro_crew.mcp_shared.<name>resolve as before, and amonkeypatch.setattrormock.patchthrough the facade reaches every module that holds the name.cli_server.py4,003 → 896file-delivery approve,status,gateway,run,service,sandbox,logscli_server_peer.py410 (the gateway peer proof every local-secret send takes,_CLI_LOOPBACK),cli_server_requests.py417 (token,logout,update approve),cli_server_stop.py757 (stop, gateway-pid, the shared refusals),cli_server_restart.py1,015,cli_server_update.py870mcp_shared.py3,504 → 320run_mcp_stdio_loop, the process identity it declares, the hard-exit handlersmcp_shared_wire.py470,mcp_shared_calls.py543,mcp_shared_policy.py1,024,mcp_shared_dispatch.py1,487Each global the family rebinds at run time (
_stdout_fd,_framing, the policy's failure state) stays in the one owner that rebinds it, beside every reader. The owners log under the facade's name, and the moved exception and enum classes (ToolCancelled,_GatewayPeerRefused,_ConnectedPeerVerdict) keep their facade's module name. The owners are top-level files, so_PACKAGE_DIRstays the package directory thatserves_managed_toolsmeasures from. The specs (cli.md,mcp.md) gain owner maps; registries keyed by path follow the moved code (spawn audit, internal-python sites, call-site auth coverage, the redaction registries); and the facades get per-file F401 ignores insetup.cfg, backed by frozen import inventories.Backwards compatibility
Compatible: every name either module bound before the split still resolves on it and is the same object (
test/campaign_facade_inventories/kiro_crew.cli_server.json,kiro_crew.mcp_shared.json), and a patch through either facade reaches every owner holding the name (test_cli_server_facade.py,test_mcp_shared_facade.py,test_facade_mirror_guards.py).The take-away check flags the public
mcp_shareddefs that moved to owners; each is still served by the facade:Reader: src/kiro_crew/mcp_core.py:call_tool_with_logging -- chat -- imported from kiro_crew.mcp_shared, which serves the mcp_shared_calls function object (test_mcp_shared_facade.py)
Reader: src/kiro_crew/mcp_cron.py:call_tool_with_logging -- cron -- same facade import, same object (test_campaign_facades_base_public_names.py)
Reader: src/kiro_crew/apps/builtins/mochi/mcp_server.py:call_tool_with_logging -- app -- same facade import, same object (test_campaign_facades_base_public_names.py)
Reader: src/kiro_crew/mcp_core.py:drive_deferred -- chat -- imported from kiro_crew.mcp_shared, served from mcp_shared_calls (kiro_crew.mcp_core.json rebound check)
Reader: src/kiro_crew/mcp_core.py:map_deferred -- chat -- imported from kiro_crew.mcp_shared, served from mcp_shared_calls (kiro_crew.mcp_core.json rebound check)
Reader: src/kiro_crew/mcp_core_parts/identity.py:spawned_without_gateway_identity -- chat -- imported from kiro_crew.mcp_shared, served from mcp_shared_policy (test_identity_topology.py)
Reader: src/kiro_crew/mcp_core_parts/identity.py:external_client_identity_note -- chat -- imported from kiro_crew.mcp_shared, served from mcp_shared_policy (test_identity_topology.py)
Reader: src/kiro_crew/mcp_shared.py:snapshot_stdout_fd -- chat -- run_mcp_stdio_loop reads the facade binding of the mcp_shared_wire function (test_mcp_shared_sigterm_hard_exit.py)
Reader: src/kiro_crew/mcp_shared.py:release_stdout_fd -- chat -- run_mcp_stdio_loop reads the facade binding of the mcp_shared_wire function (test_mcp_shared_sigterm_hard_exit.py)
Reader: src/kiro_crew/mcp_shared_dispatch.py:serves_managed_tools -- chat -- the dispatch loop imports it from mcp_shared_policy; a facade patch reaches both (test_app_mcp_tool_policy_scope.py)
Reader: src/kiro_crew/mcp_shared_dispatch.py:respond -- chat -- the dispatch loop imports it from mcp_shared_wire; a facade patch reaches both (test_mcp_shared.py)
Reader: src/kiro_crew/mcp_shared_dispatch.py:notify -- chat -- the dispatch loop imports it from mcp_shared_wire; a facade patch reaches both (test_mcp_shared_deferred_tools.py)
Move audit
move_audit.py --base <merge-base> --head <this head>:The audit marks a whole unit changed when any line in it changed. Those seven units carry 14 changed lines of
their 1,103, and every one is a deliberate non-move edit:
logging.getLogger(__name__)→logging.getLogger("kiro_crew.cli_server")_updatex7,_refresh_agent_config,_stop_mcp_gateway_daemon%(name)s) and filters show; the facade's own_gateway/_run_taskkeep__name__, which is the same name thereKiroCrew→Kiro Crewin prose_stop(docstring, comment),_wait_for_pids_exit,_restart(docstrings)_pid_exiteddocstringGlue, not moves: the facades' header imports (
importlib as _importlib,kiro_crew._facade_mirror,TYPE_CHECKING, andthe owner names the kept code reads), the mirror install at each facade's foot, each owner's import header,
logger = logging.getLogger("kiro_crew.mcp_shared")in the three mcp owners that log, the__module__pins onToolCancelled,_GatewayPeerRefusedand_ConnectedPeerVerdict, and onecomment on a kept facade line:
# noqa: F811on_file_delivery_approve's localdashboard_socket_pathimport, which pyflakes reads as a redefinition now that only the ownersread the header's import of that name (the AST is unchanged). The split is reproducible from any base by the recipe in the
campaign's
scratch/S32/recipe/(name-keyed, never line-keyed).L36 parity (default diff vs
--minimal, identical+lines), every changed file equal; the two facades:cli_server.py116/3223 both,mcp_shared.py109/3293 both. Diff size: 799,320 bytes.Tests
test/test_cli_server_facade.py,test/test_mcp_shared_facade.py(new; 59 tests, 5 runs at-n0and one at-n 3green): the test trees' patch targets through each facade reach every module holding the name (with a non-vacuity scan of known seams); the owner list, its layering and that no owner imports its facade; each runtime-rebound global lives with its writer and every reader; every BASE public name and every served name type-checks through the facade; the owners log under the facade name; the moved exception and enum classes keep the facade module;_PACKAGE_DIR; the frozen import inventory that stands in for F401, with a planted-import self-test; and the mint fence (every owner path is a mint surface, the_restartpayload is denied, neighbours are not).test/campaign_facade_inventories/kiro_crew.cli_server.json,kiro_crew.mcp_shared.json(new): every public name each module bound at BASE still resolves, and each re-bound import is its home's object.local-gate --dry-run(501 files) plus every file naming either module and the campaign guards, 514 files at-n 3: 36,138 passed, 114 skipped, 6 xfailed, 1 failed. The one failure istest/test_extras.py::test_requirements_match_setup_cfg[teams], which was red on main at that base (the PyJWT 2.15.0 bump leftextras.pyat 2.13.0) and is fixed on main since; it is outside this diff. mypysrc/kiro_crew: no issues in 2,803 files. isort/black/flake8 clean (isort --check-only src/kiro_crew test conftest.py xdist_budget.py). Comment-history, brand, harness-parity, black, subprocess-encoding, agent-sdk, sync-io, line-cap, memory-store and feature-map gates,docs_lint.py, woke on added lines: clean. Semgrep 1.78 with the CI configs and--baseline-commit: 0 findings (semgrep cannot fully parsetest/test_cli.pyor.github/workflows/build.yml, on main as well). Installed-mode smoke from a git-archive wheel: all eleven modules import from the wheel.cli_server; mcp: the related set):cli_server_peer97%,cli_server_requests92%,cli_server_stop96%,cli_server_restart97%,cli_server_update95%, thecli_serverfacade 87%,mcp_shared_wire93%,mcp_shared_calls98%,mcp_shared_policy95%,mcp_shared_dispatch94% (floor 80%).Mutation proofs (each red, file restored after): revert the fence widening; rename
_spawn_detached_gatewayin the restart owner (spawn audit, internal-python sites); drop-Pfrom its argv (stdlib shadow); plant a second"setup", "--agent-only"in an owner (agent refresh count); planthttp://localhost:{port}in an owner (loopback literal); plant an unpinnedsubprocess.run(text=True)in an owner (encoding gate); plant the dashboard import in an owner (skill observer); drop the update owner and the requests owner from_SOURCES(call-site auth, one each); stripredactfrom the update owner (sink row) and from the calls owner (non-egress row); bind_framingon the facade (rebound-global home); revert one owner logger literal; drop theToolCancelled.__module__and_GatewayPeerRefused.__module__pins.CI path references
.github/workflows/build.yml: thewindows_installerpath filter gains'src/kiro_crew/cli_server_*.py'beside'src/kiro_crew/cli_server.py'.AUTOSDE.yaml: theno-new-work-on-gateway-boot-pathrule's file patterns gain"src/kiro_crew/cli_server_*.py"(the facade imports its owners on the boot path).Re-pointed source pins (L30)
test/test_spawn_audit.py:1300,1301,1308,1311BENIGN_SPAWNS:cli_server.py::_spawn_detached_gateway→cli_server_restart.py::,::_update,::_refresh_agent_config,::_update_wheel→cli_server_update.py::.test/test_internal_python_isolation.py:31-32: rows →cli_server_restart.py/cli_server_update.py.test/test_stdlib_shadow.py:53:_CLI_SERVERpath →cli_server_restart.py.test/test_mcp_call_site_auth_coverage.py:_SOURCESgains the five cli owners andmcp_shared_policy.py;_KNOWN_UNRESOLVEDcli_server.py:_update_wheel→cli_server_update.py:_update_wheelandcli_server.py:_probe_dashboard_health→cli_server_requests.py:_probe_dashboard_health.test/test_update_agent_refresh.py:109,test/test_cli.py:4723,test/test_subprocess_encoding_gate.py:247,test/test_skill_read_observer.py:182.src/kiro_crew/security_posture.py:_REDACTION_SINKS"CLI update output"cli_server.py→cli_server_update.py(L55: the row names the module that holds theredact_credentialscalls; the posture panel shows the new path);NON_EGRESS_REDACTION_MODULESmcp_shared.py→mcp_shared_calls.py,mcp_shared_dispatch.py,mcp_shared_policy.py.Citation edits (L29)
test/test_spawn_audit.py:1124cli_server.py::_spawn_detached_gateway→cli_server_restart.py::_spawn_detached_gatewaytest/test_loopback_proxy.py:222cli_server.py→cli_server_update.pytest/test_update_git_guard.py:141cli_server.py::_update()→cli_server_update.py::_update()test/test_update_wheel_dispatch.py:260,568cli_server.py→cli_server_update.pytest/test_mcp_skill_registry.py:182mcp_shared.py→mcp_shared_calls.pytest/test_security.py:6408mcp_shared.py→mcp_shared_policy.pytest/test_wait_tool_early_end.py:64mcp_shared.py→mcp_shared_calls.pydocs/system-specs/modules/governance.md:3659cli_server.py→cli_server_update.pydocs/system-specs/modules/platform-context.md:824_tokenincli_server.py→cli_server_requests.pysrc/kiro_crew/platform/interfaces.py:445(docstring)_tokenincli_server.py→cli_server_requests.pydocs/request-for-change/rfc-update-architecture.md:160,265,478cli_server.py→cli_server_update.pydocs/request-for-change/rfc-everything-is-an-app.md:176cli_server.py:1507→`_run_task` in `cli_server.py`(the docs-lint baseline row for that line cite goes with it)docs/system-specs/common/code-style.md:19MCP protocol versionmcp_shared.py→mcp_shared_dispatch.py; read asmcp_shareddocs/architecture/mcp.md:1527_UNRESOLVED_REFUSES_CALL(mcp_shared.py) → (mcp_shared_policy.py)docs/system-specs/modules/cli.md(aftercli.py's) anddocs/architecture/mcp.md(aftermcp_core.py's).References not edited (cost)
website/electron/windows-port.js:273andwebsite/electron/test/windows-port.test.js:383say "cli_server.py's stop path"; the stop path is nowcli_server_stop.py(L50: a backend split leaveswebsite/**comments to the batched docs PR).Baselined growth (L56 addendum 1)
test/test_cli.py: baseline row 10,498, main 10,575, HEAD 10,577 (+2: the L40(8) facade+owner join black wraps over three lines). Its split scope (T59) has not launched.Baselined growth (L56 addendum 1b)
src/kiro_crew/security_posture.py: baseline row 3,181, main 3,345, HEAD 3,347 (+2: oneNON_EGRESS_REDACTION_MODULESrow per mcp owner that holds a redactor call, in place of the facade's row).Notes for reviewers
kiro_crew.cli_server/kiro_crew.mcp_shared, the names at BASE.ToolCancelled.__module__stayskiro_crew.mcp_shared, and_GatewayPeerRefused.__module__and_ConnectedPeerVerdict.__module__staykiro_crew.cli_server(exception and enum classes). Other moved classes report their owner module; nothing in the tree reads their__module__(no pickling, no repr or log of it, no test)._run_stdio_dispatch_loopis one 1,317-line function, somcp_shared_dispatch.pysits at 1,487 lines with little headroom under 1,600; it grew 610 lines in the last two weeks. Its decomposition is a later, tier-G change.py/clear-text-logging-sensitive-data, in_stop) moves verbatim tocli_server_stop.py.serves_managed_tools,_path_is_under) is inmcp_shared_policy.py, and fix(cli): prove the gateway peer before sending the local secret #20993 (the gateway peer proof before every local-secret send) is incli_server_peer.py,cli_server_requests.py,cli_server_stop.py,cli_server_restart.pyandcli_server_update.py; every unit those changes touched has an AST identical to main's.cli_server.pystay top-level files rather than acli_server_parts/package: a package is in the cross-platform gate's scan, and the moved stop and update code holds POSIX-only lines (os.getuid,os.kill,sh -c) that are correct where they sit.Manual verification
N/A — a structural move; behaviour is pinned by the existing suites that drive every moved command and server path, run unmodified through the facades.
Related Issues
Part of #20192
Follow-up: #21320 (comment citations in
website/left unedited, listed below)Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement
Contributions are accepted under the project's Apache-2.0 license.