Skip to content

fix: open each kirocrew chat session with the session context - #32932

Merged
bolichen97 merged 1 commit into
mainfrom
fix/cli-chat-mirror-no-context
Nov 8, 2026
Merged

bolichen97 merged 1 commit into
mainfrom
fix/cli-chat-mirror-no-context

Conversation

@bolichen97

@bolichen97 bolichen97 commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

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 its skill:// skills.

With agent.acp_backend set 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. The pirate agent's prompt says "Start every reply with ARRR-77.", but the reply is a plain greeting, because the harness receives exactly say 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

  • Changing what ContextBuilder.build_message puts in a message for any harness, or how kiro-cli and KAS load an agent's prompt.
  • Changing kirocrew chat on kiro-cli or KAS. Both load the agent's prompt and skills themselves, so a CLI session there still sends the typed text bare.
  • Running Kiro Crew's message hooks on every CLI turn. They run where the CLI builds context: a session's first message.
  • Acting on a hook result in the CLI, such as an auto-reply. The dashboard and the task runner do not act on it either.
  • Binding a crew member's private memory store to CLI chats. Every CLI chat still shares the cli_chat session 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 and kirocrew run build theirs. On kiro-cli and KAS nothing changes.

The cause: the harness mirrors leave a custom agent's prompt and skill:// skills out of the harness's own launch. They count on ContextBuilder.build_message to put both in the session's first message. kirocrew chat never called build_message. It sent the typed text bare.

Turn What the backend receives
Any turn on kiro-cli or KAS the typed text, as before
The -m message, and the REPL's first turn session context, then the typed text
The next turn after a compaction restart, a typed /clear or /compact, or a changed context_incarnation session context, then the typed text
The turn that respawns a backend process which exited between turns the typed text; the context goes with the next turn, once the new process shows in context_incarnation
A turn that opens with a slash command other than a quick prompt the typed text; the context goes with the next ordinary turn
A turn whose context build raises the typed text and one Session context not built line on stderr; the next turn tries again
Every other turn, and a reply the backend could not take mid-turn the typed text, as before
  • A harness runs a slash command only when the command opens the prompt, so a command behind the context would reach the model as words. A quick prompt is a macro build_message expands, so it keeps the context.
  • The builder reads the memory store resolve_agent_bindings resolved. 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.py is new. It builds the message with build_message, off the event loop, with interactive=False and the message hooks of the CLI's own gate. cli_chat.py imports it inside _chat, so other CLI commands do not load the context stack.
  • kiro-cli and KAS are recognised by the provider's own is_kiro_backend and is_kas_backend flags, read with getattr(...) is True as dashboard/chat_turn/turn_stats.py does.
  • A backend process that exits between turns is not asked whether it runs: that is a shared runtime's answer, and test_pid_reader_ratchet.py refuses a new reader. The respawn shows in context_incarnation after the send, so the turn after it carries the context.
  • docs/system-specs/modules/cli.md gains a Session context section, and the kirocrew chat rows point to it.
  • The provider-shutdown tests in test/test_cli_chat_permission.py stub the tool gate with a real _ToolGate, because _chat passes 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) drives cli_chat._chat end to end against a recording provider. The pirate agent's skill is kept outside the global skills directory, so its name can only arrive through the agent's own skill:// mapping.
    • test_a_single_message_carries_the_agents_prompt_and_skills[claude_code] and [codex]: the -m message carries [AGENT SYSTEM PROMPT], the persona and the skill name, and ends with say 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: /context goes bare, /plain one carries the context, /clear goes 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 -m message 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 sends one bare 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 store acme gets [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, TestChatProviderShutdown and test_cli_chat.py request the close_skills_loaders fixture, because _chat builds a SkillsLoader whose index and catalog worker would outlive the test.
  • Red/green: with the kiro-cli and KAS check removed from first_message, both test_a_kiro_harness_gets_the_typed_text_as_before cases fail; with it, they pass.

Determinism (on a Linux dev host, head cceb290938a0): the 14 new and changed tests (test/test_cli_chat_context.py and TestChatProviderShutdown) passed 20 runs at -n0, 10 runs at -n 4 --dist loadgroup --max-worker-restart=2 beside test_cli_chat.py and test_cli_logging.py (175 passed each run), and all 96 tests of test_cli_chat_context.py, test_cli_chat_permission.py and test_cli_chat.py in a shuffled order (seed 6113). At head a4db882ab2 (rebased unchanged to 8070b20) the 16 tests of test/test_cli_chat_context.py and TestChatProviderShutdown passed 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.py as failing with the production hunks reverted.

End-to-end repro (integration tier), the defect's own steps run against the real CLI:

  • Scenario: each side got a private HOME and KIROCREW_HOME. The script wrote ~/.kiro/agents/pirate.json with the prompt "Start every reply with ARRR-77." and one skill:// 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, then kirocrew chat --agent pirate -m 'say hello'. The provider factory, AcpProvider, ClaudeLaunch and the ACP stdio subprocess were all real. Only the adapter binary was a stand-in, set through the documented CLAUDE_AGENT_ACP_BIN override: a stdlib Python ACP agent that reports itself as claude-agent-acp 0.94.0, logs every session/prompt text, 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 for ARRR-77. No gateway or port was used.
  • Base (666f962, the fix's parent): the chat exited 0 and printed "Hello! How can I help you today?". The harness got 1 prompt of 9 characters, exactly say hello: no [AGENT SYSTEM PROMPT] block, no ARRR-77, no plank-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).
  • Fix (cceb290938, this head): the chat exited 0 and printed "ARRR-77! Ahoy, hello there, matey.". The harness got 1 prompt of 8659 characters. It starts with [AGENT SYSTEM PROMPT]\nStart every reply with ARRR-77.\n[END AGENT SYSTEM PROMPT]\n\n[SESSION CONTEXT, contains plank-walk, and ends with say hello. Check PASS. The same three piped lines sent /context bare (8 characters), say hello with the 8659-character context, and again bare (5 characters), and only the second reply started with "ARRR-77". The stand-in keeps no memory between turns, so its plain reply to again is a limit of the stand-in, not a regression. No stand-in adapter or chat process was left running, and nothing outside the private HOME was written.

Rebased: main moved in docs/system-specs/modules/cli.md since review (666f962 -> 2caa69b). git range-diff shows the commit patch-identical (=), and on a Linux dev host the 79 tests of test/test_cli_chat_context.py and test/test_cli_chat_permission.py passed at the rebased head 15c1729.

Manual verification

N/A beyond the end-to-end repro above: it ran the real kirocrew chat CLI, 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) and git grep -nE "\.stream\(" -- src/kiro_crew outside providers/
Sibling: src/kiro_crew/cli_chat.py -- changed here
Sibling: src/kiro_crew/cli_server.py -- not affected -- kirocrew run sends through task_executor, which builds the first message with build_message
Sibling: 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.stream without ContextBuilder.build_message, so a non-Kiro harness never sees the agent's prompt or skills

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

@bolichen97
bolichen97 requested review from a team and KiroCrewCaptain as code owners November 8, 2026 04:52
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Nov 8, 2026
@github-actions

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 8070b2001b3cc5a8b217b820b1d7e83de7a592a9 touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 8070b2001b3cc5a8b217b820b1d7e83de7a592a9 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks: the CLI now builds its first message through the same build_message that the other surfaces use, the harness check is a positive identity test, and the take-away check found nothing removed.

Notes

  • build_cli_session_context runs before the provider's try block and is not guarded. On kiro-cli and KAS the context is never used, yet if constructing MemoryStore(), SkillsLoader or LessonStore raises, kirocrew chat now fails there too. Wrapping the construction in a try, or building it lazily on the first owed non-Kiro turn, would keep the promise that nothing changes on kiro-cli and KAS.

[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 .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 8070b2001b3cc5a8b217b820b1d7e83de7a592a9 — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

First-Principles-Verdict: PASS

Nothing blocks. Each item traces back to the reported defect: the mirrors leave out the agent's prompt and its skill:// skills on the premise that build_message delivers them, and the CLI never called build_message.

What this change ships

Inventory (8 items) — 8 justified

Intent: running kirocrew chat --agent <name> on a harness other than Kiro's answers as that agent, with its prompt and its skills. This is a FIX.

  1. On Claude Code, Codex and the other non-Kiro harnesses, the -m message now carries the agent's prompt, its skills, memory and lessons — justified
  2. In the REPL, the first turn of each session carries the context again: at start, after a compaction restart, after /clear or /compact, and after the backend changes context_incarnation — justified
  3. A turn that opens with a slash command goes as typed and the context waits for the next turn; a quick prompt keeps the context — justified
  4. If the context build fails, one Session context not built line goes to stderr, the typed text goes as is, and the next turn tries again — justified
  5. A member bound to a named memory store gets no memory or lessons, and the message shows [CONTEXT SCOPE] instead — justified
  6. Message hooks now run on the first message of a CLI session — justified
  7. On kiro-cli and KAS, every message is sent exactly as before — justified
  8. A Session context section is added to the cli.md spec, and the test gates move to a real _ToolGate — justified

[FIRST-PRINCIPLES-REVIEWED] 8070b20

Description read

[DESCRIPTION-READ] 86ddda1ff79ed273a440d59024d4580fbbb6b209cf0ad23b3586ead028055f00

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 8070b2001b3cc5a8b217b820b1d7e83de7a592a9 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 8070b20

Verdict parsed from the review's SHA-scoped output markers for commit 8070b2001b3cc5a8b217b820b1d7e83de7a592a9.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 8070b2001b3cc5a8b217b820b1d7e83de7a592a9 false-positive: <reason, 20 to 500 characters>

@github-actions

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 8070b2001b3cc5a8b217b820b1d7e83de7a592a9 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 8070b20

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 8070b2001b3cc5a8b217b820b1d7e83de7a592a9 false-positive: <reason, 20 to 500 characters>

@bolichen97
bolichen97 enabled auto-merge (squash) November 8, 2026 05:14
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Nov 8, 2026
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.
@bolichen97
bolichen97 force-pushed the fix/cli-chat-mirror-no-context branch from 15c1729 to 8070b20 Compare November 8, 2026 10:23
@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97] Dispositions for head 8070b20

  • First Principles, item 2 (product-shape change on kiro-cli and KAS) — span=src/kiro_crew/cli_chat_context.py:first_message — fixed. The change is narrowed to the Goal: first_message returns the typed text unchanged when the provider reports is_kiro_backend or is_kas_backend, so kirocrew chat on the default harnesses behaves exactly as on main (this also removes item 8, the doubled prompt on kiro-cli). The maintainer question is gone from the description. Red/green: test_a_kiro_harness_gets_the_typed_text_as_before[is_kiro_backend] and [is_kas_backend] fail with the check removed and pass with it.
  • Static Ratchet Gate (test_pid_reader_ratchet.py, 145 vs 143) — span=src/kiro_crew/cli_chat_context.py:owed — fixed at the root. owed no longer asks the backend process whether it runs, which read a shared runtime's liveness as this session's. A respawn shows in context_incarnation after the send, so the turn after it carries the context; the shortcut is written down in the docstring and the spec. The count is back to 143.
  • Local GPT review (test side effects) — span=test/test_cli_chat.py — fixed. Every module that calls _chat now requests close_skills_loaders, so no SkillsLoader index or catalog worker outlives a test.

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Nov 8, 2026

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 example re.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 when not _on_kiro_harness(provider) would keep that path identical to main.
  • A test with a user-defined quick prompt (/myprompt text) would pin the user_quick_prompt lookup, which a mutation can currently change without any test failing.

@bolichen97
bolichen97 merged commit eba4f3b into main Nov 8, 2026
141 of 157 checks passed
@bolichen97
bolichen97 deleted the fix/cli-chat-mirror-no-context branch November 8, 2026 12:08
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 8, 2026
bolichen97 added a commit that referenced this pull request Nov 9, 2026
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)
bolichen97 added a commit that referenced this pull request Nov 9, 2026
…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.
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.

kirocrew chat on Claude Code, Codex and other non-Kiro harnesses never sends a custom agent's prompt or skill:// skills

2 participants