Skip to content

refactor(context_assembly): unchain the mate-tools ternary, fix comments - #24646

Merged
bolichen97 merged 1 commit into
mainfrom
refactor/simplify-context_assembly
Oct 27, 2026
Merged

bolichen97 merged 1 commit into
mainfrom
refactor/simplify-context_assembly

Conversation

@bolichen97

@bolichen97 bolichen97 commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: Spell the crewmate's tool-identity choice in build_member_section as if/elif/else instead of a nested conditional expression, pin that choice with a test, and correct two comments in context_assembly/member.py that contradict the code, without changing what the member section says.

build_member_section builds a crewmate's member section, [MEMBER IDENTITY] first. Its tool-identity choice is hard to read, one of its branches has no test, and two comments beside the prompt constants it uses contradict the code:

  • It picks one of three sentences with (_MATE_TOOLS_IDENTITY_MANUAL if manual else _MATE_TOOLS_IDENTITY) if has_mate_tools else _NO_MATE_TOOLS_IDENTITY. The reader has to match parentheses to see that has_mate_tools is tested first.
  • No test checks the no-tools branch: with it dead, a crewmate without the kirocrew-mate tools is told to call update_self, and none of the 17 related test files notices.
  • The note above _MEMBER_BRIEFING_ITEM_NO_FILE_TOOLS says no kirocrew-mate tool writes the briefing. save_notes does: mcp_mate posts it to /api/member/self/notes, whose handler writes members/<slug>/briefing.md. A crewmate with those tools never gets this item, because briefing_writable holds for it wherever the layer is read.
  • The note above _MEMBER_DASHBOARD_ITEM opens by narrating an earlier prompt wording, and says _MEMBER_PANEL_GRANTS grants "all six verbs". The tuple holds eleven, every tool the item names among them.

Why it matters

Nothing is broken today. Without the test, a change that tells a crewmate to call tools it does not have would pass CI. The first comment tells the next person editing the no-file-tools item that the mate server has no briefing writer, which is the opposite of the code they are about to change. The second states a count that is wrong and history that is not about the code below it.

Not a goal

  • The second from kiro_crew import crewmate_dynamic_capabilities and the repeated restricted_for(member) call later in the same function. Folding them would delete an in-function import, which this sweep never does.
  • Other files in context_assembly/, which many open PRs change.
  • Any change to the prompt text a crewmate receives (crewmate_prompts.json).
  • The same stale six-verb count in a test_dashboard_manager_agent.py docstring, and a stale count in the doc above _MEMBER_PANEL_GRANTS in agent_parts/spec_grants.py. This PR edits comments only in the module it changes.

What changed (motivation → approach → change)

The identity choice reads top to bottom, a test pins which sentence each crewmate hears, and the two comments say what the code does.

Where Before After
build_member_section, the tool-identity sentence one nested conditional expression inside identity.append(...) if not has_mate_tools / elif manual / else assigning mate_tools_identity, then the same append
note above _MEMBER_BRIEFING_ITEM_NO_FILE_TOOLS "No kirocrew-mate tool writes the briefing" a crewmate with those tools keeps its briefing through save_notes, so it never gets this item (briefing_writable)
note above _MEMBER_DASHBOARD_ITEM an earlier wording, and "all six verbs" _MEMBER_PANEL_GRANTS grants every tool the item names; the rest of the note is re-wrapped, not reworded
test/test_member_mate_tools.py none one parametrized test of which sentence each tool/preview case hears

The rewrite tests has_mate_tools first and manual only when has_mate_tools is truthy, exactly as the expression did, and both names are locals, so no call moves.

Backwards compatibility

Compatible: the member section's text is the same for every input; only the spelling of one choice and two comments change, and a test is added.

Removes nothing: no name, field, file or behaviour is taken away; the three constants and their prompt keys are unchanged.

Tests

  • Added. test_the_desk_hears_the_identity_sentence_its_tools_and_preview_pick in test/test_member_mate_tools.py, four cases: the kirocrew-mate tools on or off, times the Dynamic capabilities preview on or off. Each builds the member section and checks that exactly the expected one of the three sentences is in it. It passes against main's member.py, so it pins existing behaviour; with the no-tools branch made dead, its two no-tools cases fail. It scopes its _override patch with monkeypatch.context(), because an autouse fixture holds that global.
  • Mutation. Of four mutants of the rewritten branches (manual swapped, tools test inverted, manual arm dead, no-tools arm dead), the first three red two test_crewmate_dynamic_capabilities.py tests and the fourth red none of the 17 related files before this test.
  • Determinism. The four new ids: 20 runs at -n0. The file: 10 runs at -n 4 --dist loadgroup --max-worker-restart=2, and its 20 ids shuffled (seed 26102) at -n0. All green. A probe plugin shows _override back at its starting value after every test in the file.
  • Related tests (Python 3.12). The 16 files that name build_member_section, the identity constants or context_assembly.member, plus test_interrupted_turn_steers.py, which imports the package: 654 passed, 2 skipped.
  • Static gates (Python 3.12). flake8, isort, mypy, black-formatting (run with the pinned black 26.10.1, as the local venv carries 26.3.1), subprocess-encoding, comment-history, brand, harness-parity, the line cap, both docs lints, per-file coverage, the flake-pattern ratchet and the vendor manifest all exit 0.
  • Pre-PR review. Seven read-only reviewers (repo rules, behaviour, imports and bindings, security, claims, and local mirrors of the Opus and GPT lanes, the GPT one on a Claude model, so weaker than the CI lane), two adjudicators on the one finding, then a verifier.
    • Code: no defect found. The behaviour lens ran base and head build_member_section over 147,456 stubbed inputs per tree: identical outputs and call logs. The security lens found no control changed shape.
    • One Low, fixed: two lenses found that the first version of the new test patched _override without a scope, so its undo re-installed the autouse fixture's value for every later test on the worker. Both adjudicators upheld it.
  • Not run locally. scripts/scrub-lint.sh is absent from the checkout, and semgrep is not installed here; CI's SAST job runs it. The frontend did not run, as nothing under website/, .github/ or scripts/ changed.

Manual verification

N/A: the change has no runtime effect, and the related tests build the member section on each of the three identity branches.

Screenshots / video

Why no screenshot: backend-only change to one function's control flow and two comments; no page, card or prompt string changes.

Related Issues

Part of #16523

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 October 26, 2026 23:28
@bolichen97
bolichen97 requested a review from CrysisDeu October 26, 2026 23:28
@bolichen97
bolichen97 enabled auto-merge (squash) October 26, 2026 23:28
@github-actions

github-actions Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision f7ea11204ca92035efc79036bcf558dc519940f0 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 added the readiness: checking Automated validation is still running label Oct 26, 2026
@github-actions

github-actions Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

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

Design-Verdict: PASS

Nothing blocks: this is a refactor with no behaviour change, the new test covers the one branch that had none, and the two comments now match the code.

[DESIGN-REVIEWED] f7ea112

Description read

[DESCRIPTION-READ] 456dc8184badfb4ea629084cff4d105fe43e1c1d6a2a345fc36da903e7d36905

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 Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of f7ea11204ca92035efc79036bcf558dc519940f0 — 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. Every item is a behaviour-preserving spelling change, a comment brought in line with the code, or a pin on a branch that had none.

What this change ships

Inventory (4 items) — 4 justified

Intent: make the crewmate tool-identity choice readable and pinned, and correct two comments that contradict the code. This is a FIX (to comments and test coverage) with no runtime change.

  1. The three-way identity sentence choice is written as if/elif/else; the output is the same for every input — justified
  2. The no-file-tools briefing note now says save_notes writes the briefing, where it used to say no kirocrew-mate tool does — justified
  3. The dashboard-item note drops the history narration and the stale "six verbs" count — justified
  4. A new parametrized test pins which identity sentence each tools/preview combination hears — justified

[FIRST-PRINCIPLES-REVIEWED] f7ea112

Description read

[DESCRIPTION-READ] 018aef3810d6f9d1b0656010bbf70eb6842e908ce7722c49962c09308ee23f08

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 Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] f7ea112

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

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

@github-actions

github-actions Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

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

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] f7ea112

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

@bolichen97

Copy link
Copy Markdown
Contributor Author

Backend Tests (Windows) (6) is red on head 3d77cad908b5 for a reason outside this diff.

All six failures are test/test_slack_team_id_env.py::TestSpawnEnv, each raising FileNotFoundError: [WinError 2] (job log). That file came from #22380 and already fails Windows shard 6 on PRs that touch no Python. It is tracked as #24612, and its test-only fix is #24613, which is open with auto-merge armed. This PR touches neither that test nor the spawn path it mocks; the shard's other 28,063 tests passed.

This PR will not be re-run for that shard. Once #24613 lands, it gets rebased onto main and CI re-runs.

@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 Oct 27, 2026
@bolichen97
bolichen97 force-pushed the refactor/simplify-context_assembly branch from 3d77cad to 5223465 Compare October 27, 2026 07:37
@bolichen97

Copy link
Copy Markdown
Contributor Author

Rebased: main moved in src/kiro_crew/context_assembly/member.py, context_assembly/replay.py, context_assembly/turn_message.py, src/kiro_crew/context.py and two importing tests since this head went green (96c4fef -> aeb5c02); CI re-running.

The new base also carries #24609, the fix for the test/test_slack_team_id_env.py::TestSpawnEnv WinError 2 failures (#24612, closed) that turned Backend Tests (Windows) (6) red on the previous head. #24613, named in the comment above, was closed in favour of it. The diff is unchanged across the rebase (same two files, same hunks). Locally on 3.12: the static gates and the 17 related test files (654 passed, 2 skipped) are green.

@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Oct 27, 2026
@bolichen97

Copy link
Copy Markdown
Contributor Author

Backend Tests (3.12, 2) and Backend Tests (Windows) (2) are red on head 5223465a22a0 for a reason outside this diff.

Both shards fail the same single test, test/test_crew_log_fullscan_guard.py::test_a_warm_session_read_that_earns_a_savepoint_reads_only_the_gap, as [XPASS(strict)]. #24276 (now on main) fixed the warm-session refold that the strict xfail marks, so the marker reds every PR whose base carries it. Main tracks this as #24765, and the fix that drops the marker is #24774, open with auto-merge armed. This PR touches neither crew_log/ nor that test.

This PR will not be re-run or overridden for that red. Once #24774 lands, it gets rebased onto main and CI re-runs.

@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 Oct 27, 2026
build_member_section picks the crewmate's tool-identity sentence with a
nested conditional expression; spell it as if/elif/else in the same
order, so each of the three sentences sits on its own branch. No test
checked that a crewmate without the kirocrew-mate tools hears the page
sentence, so a parametrized test now pins all four tool/preview cases;
it passes against the previous expression too.

Two comments beside the prompt constants were false. The no-file-tools
item's note said no kirocrew-mate tool writes the briefing, but
save_notes does, and a crewmate with those tools never gets that item.
The dashboard item's note narrated an earlier wording and counted six
panel verbs; _MEMBER_PANEL_GRANTS holds eleven, every tool the item
names among them.
@bolichen97
bolichen97 force-pushed the refactor/simplify-context_assembly branch from 5223465 to f7ea112 Compare October 27, 2026 12:53
@bolichen97

Copy link
Copy Markdown
Contributor Author

Rebased onto d0695966 (#24774), which drops the strict xfail that made test_crew_log_fullscan_guard.py::test_a_warm_session_read_that_earns_a_savepoint_reads_only_the_gap red both shard-2 jobs and the Coverage Gate on the previous head. The diff is unchanged and main did not move in its files; on the new head flake8, isort, mypy, the black (26.10.1), brand, harness-parity, comment-history, docs, per-file coverage, line-cap, flake-ratchet and vendor gates exit 0, and the 16 related test files pass (638 passed, 2 skipped). CI re-running on f7ea11204c.

@github-actions github-actions Bot added readiness: checking Automated validation is still running 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 Oct 27, 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.

Tier 1 auto-approve: refactor (2 files). Criteria: no conflict, no requested changes, security path denylist clean, design-doc gate clean, security checklist all-NO, no reviewer-lane findings, readiness signal fresh for this head SHA, declared category matches the diff. Category: replaces a chained ternary with an if/elif and corrects comments in context_assembly/member.py, no behaviour change; with a test.

@bolichen97
bolichen97 merged commit cd89e05 into main Oct 27, 2026
108 checks passed
@bolichen97
bolichen97 deleted the refactor/simplify-context_assembly branch October 27, 2026 15:12
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 27, 2026
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.

2 participants