Repository navigation
fix: open each kirocrew chat session with the session context - #32932
Conversation
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: the CLI now builds its first message through the same Notes
[DESIGN-REVIEWED] 8070b20 Description read[DESCRIPTION-READ] 0772db09aba484c3126b4f7f76f1dea5b4ad19605d6bf4987096c900d215476b 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. Each item traces back to the reported defect: the mirrors leave out the agent's prompt and its What this change shipsInventory (8 items) — 8 justifiedIntent: running
[FIRST-PRINCIPLES-REVIEWED] 8070b20 Description read[DESCRIPTION-READ] 86ddda1ff79ed273a440d59024d4580fbbb6b209cf0ad23b3586ead028055f00 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: |
kirocrew chat sent the typed text to the provider bare. Every mirror rules a custom agent's prompt and its skill:// resources withheld on the premise that both reach the harness in the context message ContextBuilder.build_message assembles, which the dashboard, channels, cron and kirocrew run send. So on claude, codex, opencode, goose and the other mirrored harnesses, `kirocrew chat --agent X` ran the harness's own default persona with none of X's skills. On those harnesses the CLI now builds the first message of each session with build_message, as those surfaces do: the -m message, the REPL's first turn, and the next turn after a compaction restart, a typed /clear or /compact, or a changed context_incarnation, since each of those sessions holds none of it. kiro-cli and KAS load the agent themselves, so a CLI session on either still sends the typed text bare, as before. A backend process that exits between turns shows up only once the send that respawned it changed the incarnation: the process's own liveness would be a shared runtime's answer, not this session's. Later turns are sent as typed. A turn that opens with a slash command is sent as typed too, because a harness runs a command only when it opens the prompt, and the context waits for the next ordinary turn. A build that raises prints one line and sends the typed text; the next turn tries again. build_message decides per harness what the message holds. It reads the store resolve_agent_bindings resolved: a member bound to a named store gets neither memory nor lessons, since the CLI does not bind that store and Global memory is not the member's to read. The builder lives in a new cli_chat_context module, imported inside _chat so other CLI commands do not load the context stack. The provider-shutdown tests in test_cli_chat_permission.py stub the tool gate with a real _ToolGate over a default HookManager, as production always builds one: _chat hands the gate's hooks to the context builder before the backend starts.
15c1729 to
8070b20
Compare
|
[operator: bolichen97] Dispositions for head 8070b20
|
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
Approving. On this head the review confirmed four things. build_message gets every argument the CLI passes. The kiro-cli and KAS skip is a positive identity check (is_kiro_backend / is_kas_backend). A named-store member gets only the project context, so Global memory does not reach it. Every blocking step runs off the event loop. With main's cli_chat.py restored, 9 of the 11 new test_cli_chat_context.py cases fail, and mutation checks fail at least one test for each core decision line (the harness check, the compaction and /clear resets, the incarnation compare, the named-store scope).
Done well: the CLI now goes through the same ContextBuilder.build_message path as every other surface, and the tests drive the real _chat end to end with a skill outside the global skills dir, so a green run proves the skill:// mapping delivered it.
Optional:
cli_chat_context.py:64: a message that starts with a file path (-m "/tmp/x what is this") counts as a harness command and goes out without the context. Counting only command-shaped words, for examplere.fullmatch(r"/[A-Za-z][A-Za-z0-9_-]*", word), would keep the context for it.cli_chat.py:399: the three context stores are built on kiro-cli and KAS too, where they are never used. Building them only whennot _on_kiro_harness(provider)would keep that path identical to main.- A test with a user-defined quick prompt (
/myprompt text) would pin theuser_quick_promptlookup, which a mutation can currently change without any test failing.
kirocrew chat sent the typed text to the provider bare. Every mirror rules a custom agent's prompt and its skill:// resources withheld on the premise that both reach the harness in the context message ContextBuilder.build_message assembles, which the dashboard, channels, cron and kirocrew run send. So on claude, codex, opencode, goose and the other mirrored harnesses, `kirocrew chat --agent X` ran the harness's own default persona with none of X's skills. On those harnesses the CLI now builds the first message of each session with build_message, as those surfaces do: the -m message, the REPL's first turn, and the next turn after a compaction restart, a typed /clear or /compact, or a changed context_incarnation, since each of those sessions holds none of it. kiro-cli and KAS load the agent themselves, so a CLI session on either still sends the typed text bare, as before. A backend process that exits between turns shows up only once the send that respawned it changed the incarnation: the process's own liveness would be a shared runtime's answer, not this session's. Later turns are sent as typed. A turn that opens with a slash command is sent as typed too, because a harness runs a command only when it opens the prompt, and the context waits for the next ordinary turn. A build that raises prints one line and sends the typed text; the next turn tries again. build_message decides per harness what the message holds. It reads the store resolve_agent_bindings resolved: a member bound to a named store gets neither memory nor lessons, since the CLI does not bind that store and Global memory is not the member's to read. The builder lives in a new cli_chat_context module, imported inside _chat so other CLI commands do not load the context stack. The provider-shutdown tests in test_cli_chat_permission.py stub the tool gate with a real _ToolGate over a default HookManager, as production always builds one: _chat hands the gate's hooks to the context builder before the backend starts. (cherry picked from commit eba4f3b)
…rt assembly) #32932 (clean pick 5395799ab7 in hotfix/0121-base) imports quick_prompts.user_quick_prompt, which comes from feat #31463 (saved prompts as slash commands) and is not on release/0.12.0, so importing kiro_crew.cli_chat_context raised ImportError and `kirocrew chat` on a mirrored harness could not build its session context (mypy attr-defined). On release a slash word is a quick prompt only when QUICK_PROMPTS holds it, so _is_harness_command answers from that table alone, and cli.md drops the opted-in ~/.kiro/prompts file from the quick prompts it names. No code from #31463 comes in.
Problem / Motivation
Goal:
kirocrew chat --agent <name>on Claude Code, Codex and the other non-Kiro harnesses answers as that agent, with its own prompt and itsskill://skills.With
agent.acp_backendset to a harness other than Kiro's (claude, codex, opencode, goose, copilot, deepseek, strands or pi),kirocrew chat --agent pirate -m 'say hello'answers as the harness's own default persona. Thepirateagent's prompt says "Start every reply with ARRR-77.", but the reply is a plain greeting, because the harness receives exactlysay hello: no[AGENT SYSTEM PROMPT]block and no skill name.Why it matters
Anyone who runs a custom agent from the terminal on one of those harnesses gets a different assistant from the one they set up. The agent's instructions and skills are dropped with no error. The same agent works from the dashboard, a channel or cron, so the CLI looks fine while it ignores the agent.
Not a goal
ContextBuilder.build_messageputs in a message for any harness, or how kiro-cli and KAS load an agent's prompt.kirocrew chaton kiro-cli or KAS. Both load the agent's prompt and skills themselves, so a CLI session there still sends the typed text bare.cli_chatsession key.What changed (motivation → approach → change)
kirocrew chat --agent <name>now answers as that agent on Claude Code, Codex and the other non-Kiro harnesses. The first message of each session carries the agent's prompt and skills, built the same way the dashboard, channels, cron andkirocrew runbuild theirs. On kiro-cli and KAS nothing changes.The cause: the harness mirrors leave a custom agent's
promptandskill://skills out of the harness's own launch. They count onContextBuilder.build_messageto put both in the session's first message.kirocrew chatnever calledbuild_message. It sent the typed text bare.-mmessage, and the REPL's first turn/clearor/compact, or a changedcontext_incarnationcontext_incarnationSession context not builtline on stderr; the next turn tries againbuild_messageexpands, so it keeps the context.resolve_agent_bindingsresolved. A member bound to a named store gets neither memory nor lessons, and the message names both as withheld: the CLI does not bind that store, and Global memory is not the member's to read.src/kiro_crew/cli_chat_context.pyis new. It builds the message withbuild_message, off the event loop, withinteractive=Falseand the message hooks of the CLI's own gate.cli_chat.pyimports it inside_chat, so other CLI commands do not load the context stack.is_kiro_backendandis_kas_backendflags, read withgetattr(...) is Trueasdashboard/chat_turn/turn_stats.pydoes.test_pid_reader_ratchet.pyrefuses a new reader. The respawn shows incontext_incarnationafter the send, so the turn after it carries the context.docs/system-specs/modules/cli.mdgains a Session context section, and thekirocrew chatrows point to it.test/test_cli_chat_permission.pystub the tool gate with a real_ToolGate, because_chatpasses the gate's hooks to the context builder before the backend starts.Backwards compatibility
Compatible: on kiro-cli and KAS every message goes exactly as before. Elsewhere every message still reaches the backend, and the typed text is still the request at the end of a context-bearing message. A slash command reaches the backend as typed, as it always did. The CLI refuses nothing it accepted before.
Removes nothing: the change only adds context to the messages that open a session. No path, key, record or function is removed or renamed.
Tests
test/test_cli_chat_context.py(new) drivescli_chat._chatend to end against a recording provider. Thepirateagent's skill is kept outside the global skills directory, so its name can only arrive through the agent's ownskill://mapping.test_a_single_message_carries_the_agents_prompt_and_skills[claude_code]and[codex]: the-mmessage carries[AGENT SYSTEM PROMPT], the persona and the skill name, and ends withsay hello.test_the_repl_sends_context_once_per_session: turns one and three (three follows a forced compaction restart) carry the context, and turn two is sent bare.test_a_harness_command_goes_as_typed_and_leaves_the_context_owed:/contextgoes bare,/plain onecarries the context,/cleargoes bare, and the next turn carries the context again.test_a_session_the_backend_replaced_gets_the_context_again[conversation replaced]: the turn after the change carries the context and the one after it is bare.[process exited]: the turn that respawns the process is bare and the turn after it carries the context.test_a_kiro_harness_gets_the_typed_text_as_before[is_kiro_backend]and[is_kas_backend]: the-mmessage and two REPL turns all go exactly as typed.test_a_failed_build_sends_the_typed_text_and_retries_next_turn: a build that raises sendsonebare and prints the notice, and turn two carries the context.test_only_a_session_on_the_default_store_reads_global_memory[pirate-True]and[acme-False]: a seeded Global preference reaches the kiro agent's message, and a member bound to storeacmegets[CONTEXT SCOPE]instead.test/test_cli_chat_permission.py::TestChatProviderShutdown: the stub gate is a real_ToolGate(hooks=HookManager()), and the 5 tests still pin provider shutdown and the fidelity opt-in.test_cli_chat_context.py,TestChatProviderShutdownandtest_cli_chat.pyrequest theclose_skills_loadersfixture, because_chatbuilds aSkillsLoaderwhose index and catalog worker would outlive the test.first_message, bothtest_a_kiro_harness_gets_the_typed_text_as_beforecases fail; with it, they pass.Determinism (on a Linux dev host, head cceb290938a0): the 14 new and changed tests (
test/test_cli_chat_context.pyandTestChatProviderShutdown) passed 20 runs at-n0, 10 runs at-n 4 --dist loadgroup --max-worker-restart=2besidetest_cli_chat.pyandtest_cli_logging.py(175 passed each run), and all 96 tests oftest_cli_chat_context.py,test_cli_chat_permission.pyandtest_cli_chat.pyin a shuffled order (seed 6113). At head a4db882ab2 (rebased unchanged to 8070b20) the 16 tests oftest/test_cli_chat_context.pyandTestChatProviderShutdownpassed 10 runs at-n0, and the 98 tests of the three modules passed at-n 2.Proof: PROVEN test/test_cli_chat_context.py::test_a_single_message_carries_the_agents_prompt_and_skills[claude_code], test/test_cli_chat_context.py::test_a_single_message_carries_the_agents_prompt_and_skills[codex], test/test_cli_chat_context.py::test_the_repl_sends_context_once_per_session, test/test_cli_chat_context.py::test_a_harness_command_goes_as_typed_and_leaves_the_context_owed, test/test_cli_chat_context.py::test_a_session_the_backend_replaced_gets_the_context_again[process exited] (head cceb290938a0)
prove.py names at most five tests; its record lists all nine tests of
test_cli_chat_context.pyas failing with the production hunks reverted.End-to-end repro (integration tier), the defect's own steps run against the real CLI:
HOMEandKIROCREW_HOME. The script wrote~/.kiro/agents/pirate.jsonwith the prompt "Start every reply with ARRR-77." and oneskill://resource (plank-walk). That skill sits outside the global skills directory, so its name can only reach the message through the agent's own mapping. It then ran the real CLI from the tree under test:kirocrew config set agent.acp_backend claude, thenkirocrew chat --agent pirate -m 'say hello'. The provider factory,AcpProvider,ClaudeLaunchand the ACP stdio subprocess were all real. Only the adapter binary was a stand-in, set through the documentedCLAUDE_AGENT_ACP_BINoverride: a stdlib Python ACP agent that reports itself as claude-agent-acp 0.94.0, logs everysession/prompttext, and answers like a model that follows whatever instructions it gets, so its reply starts with "ARRR-77" only if the persona arrived. The check greps the CLI's stdout forARRR-77. No gateway or port was used.say hello: no[AGENT SYSTEM PROMPT]block, noARRR-77, noplank-walk. Check FAIL, bug present. A REPL run with three piped lines (/context,say hello,again) sent all three bare (8, 9 and 5 characters).[AGENT SYSTEM PROMPT]\nStart every reply with ARRR-77.\n[END AGENT SYSTEM PROMPT]\n\n[SESSION CONTEXT, containsplank-walk, and ends withsay hello. Check PASS. The same three piped lines sent/contextbare (8 characters),say hellowith the 8659-character context, andagainbare (5 characters), and only the second reply started with "ARRR-77". The stand-in keeps no memory between turns, so its plain reply toagainis a limit of the stand-in, not a regression. No stand-in adapter or chat process was left running, and nothing outside the privateHOMEwas written.Rebased: main moved in docs/system-specs/modules/cli.md since review (666f962 -> 2caa69b).
git range-diffshows the commit patch-identical (=), and on a Linux dev host the 79 tests oftest/test_cli_chat_context.pyandtest/test_cli_chat_permission.pypassed at the rebased head 15c1729.Manual verification
N/A beyond the end-to-end repro above: it ran the real
kirocrew chatCLI, provider factory and ACP subprocess, with only the adapter binary stood in. Not run: a live Claude Code or Codex account, which the repro host does not have.Related Issues
Closes #32800
Sibling sweep
Swept:
git grep -n "build_provider_factory(" -- src/kiro_crew(every surface that starts its own provider) andgit grep -nE "\.stream\(" -- src/kiro_crewoutsideproviders/Sibling: src/kiro_crew/cli_chat.py -- changed here
Sibling: src/kiro_crew/cli_server.py -- not affected --
kirocrew runsends through task_executor, which builds the first message with build_messageSibling: src/kiro_crew/cli_commands_eval.py -- not affected -- the eval runner chooses per scenario session whether its own ContextBuilder injects context, since it measures memory carry-over
Sibling: src/kiro_crew/cli_knowledge.py -- not affected -- consolidation runs Kiro Crew's own consolidator prompt, never a user's custom agent
Pattern harvest
Rule candidate: review-prompt
Pattern: a surface that opens a provider session sends its first message straight to
provider.streamwithoutContextBuilder.build_message, so a non-Kiro harness never sees the agent's prompt or skillsChecklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)