Skip to content

feat(slack): code-channel agent tools, commands and wrap-up - #21429

Merged
kyleseaman merged 2 commits into
mainfrom
feat/slack-code-channels-agent-surface
Nov 9, 2026
Merged

kyleseaman merged 2 commits into
mainfrom
feat/slack-code-channels-agent-surface

Conversation

@kyleseaman

@kyleseaman kyleseaman commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: In a Slack code channel, the bound Kiro Crew agent can publish views and a plan canvas, keep the context bar and the channel's name and status current, and wrap the work up, acting only on its own channel. The people in the channel get /summarize, /wrap-up and (when possible) /create-pr, plus an Archive button that archives the channel with its summary and cleans the worktree.

The parent PRs open a code channel, bind it to a dashboard session, and give it a worktree, a diff tab and a repo/branch/PR/CI context bar. Without this PR, the agent in that channel can only chat. It cannot show a report or a plan as a tab, tell the channel it is waiting on someone, or retitle the channel when the work changes direction. The people in the channel have no commands and no way to close the channel out. The owner asked for exactly this surface, quoted here from the brief: "MCP tools for the bound agent, PINNED SERVER-SIDE to the calling session's own channel … set_view (html / block_kit / canvas), publish_plan_canvas, set_context_bar (merge with B's repo/branch/PR/CI items, <=5 unique keys), rename, set_status", "/summarize (always), /wrap-up (always), /create-pr ONLY when the bound agent can actually open PRs", and "Wrap-up: post a summary message … with an Archive button; on click … archive with summary_message_ts, then call B's worktree cleanup".

Why it matters

Slack's code-channel lifecycle guidance expects all of this from the channel's agent:

  • views for diffs, HTML and canvases;
  • a context bar kept current, including items beyond repo/branch (its examples include token usage);
  • rename "if the session's focus changes", so the channel list stops naming work that has moved on;
  • suspended when the agent asked a question and needs the answer;
  • a final summary with an archive action.

Without it, a code channel runs in Slack but cannot be finished from Slack: someone has to archive it by hand and clean up the worktree on disk. And an agent tool that could address any channel would let one session write into another team's channel. That is why the tools are pinned to the caller's own channel server-side.

Not a goal

  • No tool that creates a channel, archives one, or reaches any channel but the caller's own. Archiving stays a person's click.
  • No /run-tests command. The owner's brief names /summarize, /wrap-up and /create-pr; tests are a prompt away.
  • No context-bar action items. Slack documents a code_channel_action click event, but its reference page 404s, its payload is undocumented and the manifest does not subscribe to it. The tool refuses item_type and suggests a link item.
  • No dashboard UI. The badge is a sibling PR; it reads Binding.wrapped_up_at / archived_at, which this PR stamps.

What changed (motivation → approach → change)

Pinning. The tools must not be able to name a channel, so the channel is derived from WHO calls, never from an argument.

  • mcp_tools/code_channels.py resolves the caller through require_strict_session_key. It never uses the /proc walk, so a sub-agent cannot resolve to its parent. It forwards to a new STRICT route, POST /api/slack/code-channel/tool (dashboard/handlers/slack_code_channel_tools.py).
  • The route refuses unless the transport attests X-Session-Key (session_key_is_attested).
  • slack/code_channels/tools.py maps the key to its dashboard slot (caller_slot_key). It takes the binding whose session_key is that slot AND whose Slack link still resolves to that slot, in that channel. A replaced session therefore loses its channel.
  • channel, channel_id, team_id (and the like) are refused before anything else. The only canvas tab is the channel's own plan canvas, attached by code_channel_publish_plan_canvas (comment-only).
  • Archived or Stop-silenced channels are left alone, and every Slack write first passes the channels outbound ceiling.
  • Every call writes one slack.code_channel.tool SEL row.

Tools.

  • code_channel_set_view: html with no CSP resource domains; Block Kit through a display-only allowlist with no action_id, accessories or remote media. The diff stays the workspace's and the Plan tab comes with the plan canvas.
  • code_channel_publish_plan_canvas: channel_canvas_already_exists is never retried, and a canvas this gateway did not create is never written.
  • code_channel_set_context_bar: the agent's items ride after the workspace's in WorkspaceService._publish_bar (five in all, the workspace's keys reserved), so the bar keeps one publisher. The workspace takes at most four slots, so at least one is the agent's, and more when there is no PR or no repository.
  • code_channel_rename: agents.sessions.rename.
  • code_channel_set_status: suspended holds through the turn end.
  • code_channel_wrap_up.
  • Agent text passes every redaction pass (security.redact: exfiltration URLs and credentials), a context-bar link that redaction would change is refused, and @channel / @here / user-group pings are neutralized.
  • The surface store writes before it adopts a change in memory (a failed write fails the tool), and is touched only off the event loop. Its file is routing/slack-code-channel-surface.json, beside the core's routing/slack-code-channels.json: the routing directory is already fenced as a whole (agent file tools refuse it on the read and write floors, every sandbox masks it, it is pre-created), so this PR adds no entry to sandbox_leaves, sandbox_precreate or security/paths*.
  • Tools are listed only while slack.code_channels is on.

Commands. commands.py registers the command set with agents.conversations.setCommands at turn start, off the turn's path, and only when the set changed. /create-pr is included only when the channel has a worktree, a GitHub remote this install may reach, and gh signed in for that host. Socket Mode delivers invocations to events._handle_slash, which asks commands.handle_slash first. A repeated trigger_id is dropped (the gateway's SeenCache). The channels inbound ceiling applies before any side effect. Then the sender is authorized like a message in the channel: an allowed user, and an origin that still admits the bot. Each command becomes a prompt delivered through routing.deliver_directed, and a /wrap-up that never reached the session is disarmed.

Wrap-up and archive (wrapup.py).

  • The wrap-up posts the agent's summary, the facts the gateway knows (branch, PR, CI, changes, uncommitted work) and an Archive channel button. It is recorded as summary_message and stamps Binding.wrapped_up_at. An older wrap-up's button goes stale; its message is not edited. If the /wrap-up turn ends without the tool call, the facts alone are posted.

  • A click (interactions.dispatch → handle_archive_click) is authorized like a message (allowed user, and both the origin and the code channel itself admit the bot: channel_and_origin_permit, as on the message path) and must be the current session's current wrap-up. Under a per-channel lock the code:

    1. retires the button;

    2. calls agents.conversations.archive(summary_message_ts);

    3. fences the channel in-process at once, then stamps Binding.archived_at (retried once); if the stamp cannot be written, nothing is cleaned up and the dashboard is told;

    4. runs this PR's cleanup.release_channel_workspace. The workspace PR no longer ships a cleanup, so this PR owns it. It runs under the workspace's channel lock with no bind in flight (WorkspaceService.channel_quiet), and checks before it removes anything:

      • the workspace record (a data-home file) is checked against the gateway's own facts: git_ops.is_channel_worktree (a channel-derived branch whose registered worktree is the recorded one), the sealed binding's repository (or, when the binding names no project, the one its bind resolved), and no sensitive path. The record is read once, under the service's own store lock, and that same snapshot is acted on;
      • the tree is kept when it has uncommitted, untracked or ignored files, or is off its channel branch;
      • the removal is a non-forced git worktree remove;
      • the branch is deleted, compare-and-delete at the very sha that was checked, only when its tip is already on the repository's default branch, resolved from the repository and never from the record, so commits always stay reachable.

      A kept tree is reported to the dashboard.

    An archived channel's turns fire no hooks afterwards (binding.notify_turn_start).

  • A second click archives nothing.

Minimal hunks in the parents' files:

  • client.py is unchanged: the surface's own agents.* writes live in surface_client.SurfaceClient, a subclass of the core's client that inherits its validation, ok check, no-retry and latch rules.

  • status.py: hold_after_turn.

  • hooks.py: on_turn_start(..., first=True), so the wrap-up's turn counter observes a start before any other hook awaits.

  • __init__.py: surface.install.

  • workspace/service.py: the merge in _publish_bar (off the loop), plus republish_bar and channel_quiet.

  • binding.py: notify_turn_start skips an archived channel.

  • routing.py: _dispatch_directed split into a delivery-reporting deliver_directed (unchanged for existing callers).

  • events_slash.py (where the base moved _handle_slash) / interactions.py: one pass-through seam each.

  • Registration (mcp_tools/__init__.py, REFLEXIVE_TOOL_MODULES, tool titles, strict path, deferred route).

  • security_posture.py (cross-owned, additive only): a _REDACTION_SINKS row "Slack code-channel posts" for slack/code_channels/wrapup.py, whose _redact (the dual-pass redact() plus a ping defang) every surface post goes through, and a NON_EGRESS_REDACTION_MODULES entry for slack/code_channels/tools.py, which posts only through that redactor. No other entry moved; test_every_redactor_call_site_is_a_registered_sink_or_allowlisted passes on this head.

  • Docs: slack-gateway.md § Code-channel agent surface, and a feature-map row.

Sensitive change review

Drafted for the human reviewer to check and post; the agent does not post this as a comment.

  • Head commit: 349ce1c
  • Watched files changed (base main...head): src/kiro_crew/security_posture_sinks_delivery.py +7 / -0 (the "Slack code-channel posts" sink row, right before "Slack cron / notification posts") and src/kiro_crew/security_posture.py +5 / -0 (the NON_EGRESS_REDACTION_MODULES entry incl. its required reason comment). These are the same 12 lines, byte for byte, as the earlier single-file hunk; the base split the sink table into security_posture_sinks_delivery.py, so the sink row moved there. No other file matches SENSITIVE_GLOBS; security/paths*.py, sandbox_leaves.py, sandbox_precreate.py are untouched.
  • What rule changed: no floor, gate or path rule changed. Two additive classification rows: slack/code_channels/wrapup.py registered as the "Slack code-channel posts" redaction sink, and slack/code_channels/tools.py allowlisted as a non-egress redactor caller.
  • Before -> after (what was allowed/blocked, now): before, the security panel did not know the code-channel surface's posts and test_every_redactor_call_site_is_a_registered_sink_or_allowlisted refused both new modules; after, the panel counts wrapup.py's posts as a redacted output boundary and tools.py is recorded as posting only through it. Nothing is newly allowed or blocked at runtime. The surface record lives in the existing protected routing/ directory, so no new protection entry was added.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): the panel shows a wrong sink count, or tools.py gets an egress path later that skips the shared redactor and the allowlist hides it from the omission test. No redaction is removed by these rows; they only describe calls the code already makes.
  • Evidence checked (which sandbox result proves it): no sandbox rule changed, so no sandbox result applies. Removing each row in turn makes the omission test fail and name exactly that module (slack/code_channels/wrapup.py, then slack/code_channels/tools.py); with both rows in, every test in test/test_security_posture.py passes. A fresh-context review confirmed the relocated record keeps at least its old file-tool and sandbox protection under both data-home prefixes and a KIROCREW_HOME override.
  • No regression:
    • Tools still work (which tools/commands were run, result): the rows are data read by the security panel and the posture tests only; all 1626 focused code-channel, posture, facade, composition-contract and MCP-title and channel-gate ratchet tests pass on this head, as do the 223 posture, composition-contract, source-pin and inbound-gate tests.
    • Backward compatible (old config / old data / old callers still work, how checked): no existing row moved or changed; the diff is two additions, and with slack.code_channels off neither module runs.
    • Existing tests (which suites passed on this head): test/test_security_posture.py and test/test_security_posture_facade.py plus the focused code-channel suites, flake8, isort and mypy, all on 349ce1c.
  • How to undo: delete the sink row from src/kiro_crew/security_posture_sinks_delivery.py and the allowlist entry from src/kiro_crew/security_posture.py (the omission test will then name both modules until they are re-classified).

Backwards compatibility

Compatible: everything is new and behind slack.code_channels. With the toggle off, or the install unable to run code channels, the tools are not listed and refuse, the slash and button seams return "not mine" so the existing handlers run unchanged, and no hook fires.

Removes nothing: the diff only adds tools, a route, a store file and pass-through seams; no existing key, record, path or validator is removed or tightened.

Tests

test/test_slack_code_channel_agent_surface.py (91 tests; recorded Slack payloads and fakes, real git for the worktree cleanup). It covers the nearby inputs:

  • Unbound or unidentified callers: a session not bound to a code channel, and a cron or unknown key, get not_bound; the refusal is audited and nothing reaches Slack.
  • Other channels: a call naming another channel (channel, channel_id, team_id) is refused before Slack, as is a foreign canvas_id. Two bound sessions each reach only their own channel, and a replaced session loses its channel.
  • Commands: a retried slash delivery is routed once. A code channel itself set to off or review refuses /summarize, /wrap-up and /create-pr while its origin stays active. /create-pr on a non-git project explains instead of running, and the command set offers /create-pr only when possible.
  • Archive refusals: an unauthorized user, an origin with the bot off, the code channel itself off or in review, a stale or superseded wrap-up, a replaced session's old button, a forged value and an unbound channel all archive nothing, and each is audited.
  • Archive clicks: a double click archives once. A failed archive restores the button.
  • Worktrees: a worktree with uncommitted changes is kept intact and the dashboard is notified; a clean worktree is removed.
  • Slack refusals: feature_disabled / missing_scope degrade, and feature_disabled latches the feature off.
  • Gate: toggle off behaves identically to main (nothing listed, seams fall through), and toggle on with the scope missing behaves the same. A channels policy denying Slack inbound refuses a command; denying outbound refuses tools, wrap-up and archive.
  • Content: HTML is redacted with no CSP, the Block Kit allowlist holds (including a card container), and group pings are neutralized.
  • Canvas: never retried, never adopted.
  • Context bar: the merge keeps one publisher.
  • Status: suspended outlasts the turn.
  • Record guards: the file-tool write fence refuses the record under both home prefixes but not a .bak, a lookalike name or the same basename in a project; a pre-created {} reads as no records and the gateway's first write replaces it.
  • Wrap-up: the facts-only fallback posts, and nothing is posted into an archived channel.
  • Robustness: a binding update never rewrites a replaced binding; an unexpected failure is audited instead of raised; a failed store write changes nothing and fails the tool; an undelivered /wrap-up posts no fallback; exfiltration URLs in views are redacted and such links are refused on the bar; wrap-up facts (branch, git output), view keys, bar keys and Block Kit keys pass the same redaction; a forged workspace record (base at the tip of unpushed commits, a foreign worktree, a foreign branch) never drives the cleanup.
  • Transport: the MCP forwarder sends the strict key and no channel, and the route refuses an unattested caller.

Manual verification

There is no live pilot workspace, so the Slack side is verified only against fakes and recorded payloads. A fresh-context adversarial review of the diff attempted to break the channel pinning and found no cross-channel path. Its state findings are fixed with regression tests above: plan-canvas adoption, a binding lost-update, unguarded archive bookkeeping, wrap-up racing the archive, a replaced session's old button, the Block Kit denylist and group pings.

Local gates run against this PR's base: flake8, mypy, black (diff-scoped), subprocess-encoding, comment-history, sync-io-in-async, file-line-cap, brand, harness-parity, feature-map, loop-bound-locks, docs-lint, and the related suites.

Related Issues

Part of #15175

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

Contribution License Agreement

Contributed under the project's Apache-2.0 license.

@kyleseaman
kyleseaman requested review from a team and KiroCrewCaptain as code owners October 16, 2026 23:40
@kyleseaman
kyleseaman requested review from chenmingwei23 and removed request for a team October 16, 2026 23:40
@github-actions

github-actions Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 349ce1c118fc5a22e324193f063a292853ec2ca2 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 16, 2026
@github-actions

github-actions Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

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

Design-Verdict: PASS

No design blocker: the channel comes from who calls, not from an argument; the patch removes nothing that readers depend on; and nothing under website/ changes, so no rendered evidence is needed.

Notes

  • slack/code_channels/routing.py was already 1,713 lines on the base and this PR takes it to 1,806. Move the slash-command delivery and wrap-up-disarm logic it adds into commands.py or wrapup.py before the file nears the 2,000-line cap.

[DESIGN-REVIEWED] 349ce1c

Description read

[DESCRIPTION-READ] 989432fa6774c2525797562fc6d091648c54f824b2c4b5c0887ba998c9beb464

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 16, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 349ce1c118fc5a22e324193f063a292853ec2ca2 — 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

Every item sits behind slack.code_channels, which is off by default, and the in-progress rfc-slack-code-channels.md covers the shape. One redundant enum value.

Notes

  • Item 5 — oversized: "enum": ["processing", "suspended", "active"]. The tool's own description says "Kiro Crew already shows processing while you work and active when your turn ends". An agent can only call the tool mid-turn, when the status already reads processing, so that value does nothing. Subtraction: delete "processing" from the code_channel_set_status enum and from _STATUSES, keeping suspended and active.

What this change ships

Inventory (10 items) — 9 justified

Intent: let a Slack code channel's agent publish its work, keep the channel current, and let people finish and archive the channel from Slack. ADDITION.

  1. The agent can publish html or Block Kit tabs in its own channel — justified
  2. The agent can publish and update a comment-only plan canvas as the Plan tab — justified
  3. The agent can add its own items to the context bar after the workspace's repo/branch/PR/CI items — justified
  4. The agent can rename its channel and session — justified
  5. The agent can set the channel's status, and suspended stays after the turn ends — oversized: the processing value does nothing
  6. The agent can post a wrap-up summary with an Archive button — justified
  7. People in the channel get /summarize, /wrap-up and, when possible, /create-pr — justified
  8. Pressing Archive archives the channel with its summary, stamps archived_at and removes the worktree — justified
  9. An archived channel takes no further turns — justified
  10. A new strict internal route, /api/slack/code-channel/tool, plus a new delivery sink and a new surface-store file under routing/ — justified

[FIRST-PRINCIPLES-REVIEWED] 349ce1c

Description read

[DESCRIPTION-READ] f63bcdf1b76748d7d09afe2845017e8501ff2aca6eafb4beef36bd21394c67ed

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 16, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

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

Review details

No findings.

Notes:

  • docs/system-specs/modules/slack-gateway.md:2206 says a canvas create answered channel_canvas_already_exists is "never adopted". _publish_canvas_locked does adopt one: a canvas this bot made after one of its own creates lost its answer. The spec sentence could say so.

[OPUS-REVIEWED] 349ce1c

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

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

@github-actions

github-actions Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

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

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 349ce1c

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

@kyleseaman
kyleseaman force-pushed the feat/slack-code-channels-agent-surface branch 2 times, most recently from cc54755 to 84f04ad Compare October 17, 2026 00:17
@kyleseaman

Copy link
Copy Markdown
Contributor Author

Dispositions for the review of cc54755ada. Each finding below is fixed in 84f04adca9.

Opus 5.5

  • BLOCKING commands.py:308 (channels governance): fixed. handle_slash checks channel_inbound_permitted("slack") before any side effect and audits the denial. Test: test_a_command_is_refused_when_the_channels_policy_denies_slack_inbound.
  • BLOCKING wrapup.py:164 / tools.py:493 (exfiltration URLs): fixed. Agent text now goes through security.redact, which applies both the exfiltration-URL and credential passes. A context-bar URL that redaction would change is refused. Test: test_exfiltration_urls_are_redacted_and_bad_links_refused.
  • FINDING commands.py:305 (a /wrap-up stays armed when it is not delivered): fixed. routing._dispatch_directed now delegates to a delivery-reporting deliver_directed, and an undelivered /wrap-up is disarmed. Test: test_a_wrap_up_that_never_reached_the_session_is_disarmed.

GPT 6.1

  • F1 (governance): fixed as above. Tools, wrap-up, archive and command registration also check channel_outbound_permitted("slack"). Test: test_tools_wrap_up_and_archive_respect_the_outbound_ceiling.
  • F2 (URL redaction): fixed as above.
  • F3 (surface_store persist-before-publish): fixed. The store commits a staged snapshot and adopts it only after atomic_write succeeds. A failed write raises, and the tool reports the failure. Test: test_a_failed_store_write_changes_nothing_and_fails_the_tool.
  • F4 (synchronous store calls on the event loop): fixed. Every surface-store and binding-store read or write in the new coroutines goes through asyncio.to_thread, including the agent-bar read inside _publish_bar.
  • F5 (retiring the old wrap-up erased its summary): fixed by removal. The older wrap-up's message is no longer edited. Its button is refused as stale on click. Test: test_a_newer_wrap_up_makes_the_older_button_stale_without_editing_it.
  • F6 (the test depended on clock ticks): fixed. Turn starts are ordered by a counter instead of the wall clock, so the fallback guard and its test are deterministic.

@kyleseaman
kyleseaman force-pushed the feat/slack-code-channels-agent-surface branch from 84f04ad to d48919d Compare October 17, 2026 00:41
@kyleseaman

Copy link
Copy Markdown
Contributor Author

Dispositions for the review of 84f04adca9. Each finding below is fixed in d48919dc16.

  • Opus BLOCKING wrapup.py:143 (branch facts were not redacted): fixed. Every fact line (the branch and the git --shortstat output) goes through the same _redact as the summary: every redaction pass, plus the broadcast and user-group filter.
  • Opus FINDING surface.py:48 (start-hook order): fixed. hooks.on_turn_start gains first=True, and wrapup.on_turn_start registers first, so a turn is numbered before any other start hook awaits. Test: test_the_wrap_up_start_hook_runs_before_every_other.
  • GPT F1 (identifiers and facts bypassed redaction): fixed. A view_key or context-bar key that redaction would change is refused. _redact_tree now redacts Block Kit dictionary keys as well as values. Wrap-up facts are redacted as above. Test: test_wrap_up_facts_and_identifiers_pass_the_redaction.

@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 17, 2026
@kyleseaman
kyleseaman force-pushed the feat/slack-code-channels-agent-surface branch from d48919d to a5ed55a Compare October 17, 2026 01:13
@kyleseaman

Copy link
Copy Markdown
Contributor Author

Dispositions for the review of d48919dc16. Both findings are fixed in a5ed55abd2.

  • GPT F1 surface_store.py:70 (the surface record was not sealed): fixed. slack-code-channel-surface.json now has the same protection as the core's slack-code-channels.json:

    • the read-only seal list and the child-readable list (sandbox_leaves.py);
    • the pre-create list (sandbox_precreate.py; {} reads as an absent file, and a frozen reader publishes and archives nothing);
    • the file-edit write floor (security/paths.py).
  • GPT F2 wrapup.py:462 (the cleanup trusted a forgeable record): fixed in this PR's archive path. Before release_channel_workspace runs, _provenance_refusal checks the workspace record against facts the gateway holds:

    • the branch must carry the hash derived from THIS channel's team_id:channel_id;
    • the repository must be the git toplevel of the sealed binding's project_dir;
    • the worktree must be the path git registers for that branch;
    • a base_sha equal to the branch tip (which would allow deleting the branch) must already be an ancestor of the default branch.

    On any mismatch nothing is removed, and the refusal is audited (slack.code_channel.worktree_release denied) and reported to the dashboard. Test: test_a_forged_workspace_record_never_drives_the_cleanup[base_at_tip|foreign_worktree|foreign_branch]. Sealing the workspace record itself belongs to the parent PR (feat(slack): code-channel worktree, diff view and context bar #21412), which owns that file.

@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 17, 2026
@github-actions

github-actions Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Sensitive Change Review

Sensitive files changed:

  • src/kiro_crew/security_posture.py

  • src/kiro_crew/security_posture_sinks_delivery.py

  • @kyleseaman posted a complete reasoning template for 349ce1c.

@kyleseaman
kyleseaman force-pushed the feat/slack-code-channels-workspace branch from c7a1b15 to 517b6bd Compare October 17, 2026 01:24
@github-actions

github-actions Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Security Scope Review -- 🟡 CONCERNS

Which legitimate operations does 90250b12ad71158bcc9c507bdbc57a24241fc8a7 newly refuse? Updated in place on each push. A script-confirmed regression blocks; the model proposes candidates and never decides a refusal.

Verdict basis: the reviewer's own judgement; no confirmed regression.

Security scope review -- adjudicated candidates

  • macos-latest (platform posix): 9 classified, 0 newly refused, 9 still allowed.
  • ubuntu-latest (platform posix): 9 classified, 0 newly refused, 9 still allowed.
  • windows-latest (platform windows): 7 classified, 0 newly refused, 7 still allowed.

No candidate flipped from allowed to refused.

Scope-Verdict: CONCERNS

TIGHTENING: a crew home leaf, slack-code-channel-surface.json, is added to the file-edit write floor, the sandbox read-only seal and the precreate read-only leaves -- it refuses a sandboxed agent that rewrites the gateway's code-channel surface record (context-bar items, plan canvas id, current wrap-up pointer) to steer what the gateway publishes or archives in a channel outside the sandbox. Quoted from src/kiro_crew/security/paths.py: f"{prefix}/{leaf}" ... for leaf in ("slack-code-channels.json", "slack-code-channel-surface.json"), along with the _CREW_READONLY_LEAVES hunk in sandbox_leaves.py ("slack-code-channel-surface.json",) and the matching hunk in sandbox_precreate.py.

ADJUDICATED: 13 candidates, 0 confirmed newly-refused

PLATFORM COVERAGE: The diff hard-codes one leaf filename under each _CREW_HOME_PREFIXES prefix. Candidates cover both spellings of a read of that leaf and of its neighbour slack-code-channels.json, plus the area's test runs:

  • posix: cat, jq, ls -la, grep -rn and a gateway-log tail on ~/.kirocrew/....
  • windows: PowerShell Get-Content $env:USERPROFILE\.kirocrew\..., cmd type %USERPROFILE%\.kirocrew\..., and a .venv\Scripts\python.exe pytest run with \ separators.
  • any: the pytest runs of test/test_slack_code_channel_agent_surface.py and test/test_mcp_tool_titles.py, and a scoped git diff --stat.

I wrote no UNC-path or .cmd row. The diff assumes no executable name, and the only path assumption is the existing prefix list, which this change reuses without altering it.

UNADJUDICATED:

  • Write floor on the file-edit tools. Guard: security.paths._WRITE_PROTECTED_HOME_PATHS, reached by the agent's file-write/edit tool calls through the paths gate with _SENSITIVE_HOME_DIRS + _WRITE_PROTECTED_HOME_PATHS (paths.py ~3594). It is not in the shell deny composite: SHELL_DENY_TIERS has no path tier, so every row above classifies the same at base and head. The zero above says nothing about this guard. Legitimate inputs I would have submitted, all of which must stay allowed:
    • a file-read tool call on ~/.kirocrew/slack-code-channel-surface.json (and the Windows %USERPROFILE%\.kirocrew\... form);
    • a write to a same-prefix sibling that is not protected, such as a file under ~/.kirocrew/ whose name only shares the slack-code-channel stem;
    • the gateway's own atomic_write of the surface store, which the diff says runs outside this gate.
  • Sandbox seal. Guard: _CREW_READONLY_LEAVES, _CREW_CHILD_READABLE_LEAVES and _CREW_PRECREATE_READONLY_FILE_LEAVES, applied when the sandbox is built for a crew child. Inputs I would have submitted:
    • the gateway (unsandboxed) writing the store on its first code-channel tool call while a sandboxed child already holds the precreated {} leaf;
    • a sandboxed child's SurfaceStore read of that frozen {}, which the diff says must mean "no records".
  • New STRICT route /api/slack/code-channel/tool. It is added to _STRICT_INTERNAL_API_PATHS, and api_code_channel_tool refuses unless internal_auth/peer_verified holds and session_key_is_attested passes. It is a new route, so it refuses no existing operation. Still, I could not test the one input it must keep alive: the mcp_tools/code_channels.py MCP subprocess posting with an attested X-Session-Key, over the unix peer and over the signed per-session token transport. The token leg is the Windows one, since there is no unix peer check there.

[SCOPE-REVIEWED] 90250b1

@github-actions github-actions Bot added merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Oct 17, 2026
@kyleseaman
kyleseaman force-pushed the feat/slack-code-channels-agent-surface branch from a5ed55a to 691f9cb Compare October 17, 2026 01:48
@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 17, 2026
@kyleseaman
kyleseaman force-pushed the feat/slack-code-channels-workspace branch from b0953b3 to 98c0ea4 Compare October 19, 2026 17:39
@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Oct 19, 2026
@kyleseaman
kyleseaman force-pushed the feat/slack-code-channels-workspace branch from 98c0ea4 to eb5d873 Compare October 19, 2026 19:01
@kyleseaman
kyleseaman force-pushed the feat/slack-code-channels-agent-surface branch from 90250b1 to 98c623d Compare October 19, 2026 19:08
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision labels Oct 19, 2026

@iamwhatever iamwhatever left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

REQUEST_CHANGES at fd858de.

One defect on the archive failure path:

  • In wrapup.py#L493-L504, the channel is fenced before _stamp_archived. If both stamp attempts fail, the fence stays up for the life of the process. A later click then stops at is_archived (L446-L451) and answers already archived, so archived_at is never written and the worktree is never cleaned. The dashboard notice (L369-L383) says Slack's archive event will record it, but nothing in src/kiro_crew/slack handles that event at this head. This is the Opus lane's current-head finding, and it has no reply yet.
  • Smallest fix: when a click finds the channel fenced but archived_at unset, retry the stamp and cleanup. Or remove the retry and archive-event promises from the comment and the notice, and tell the operator what to do by hand.

Also open:

  • First Principles item 8 (a third per-channel store) needs the stack owner's ruling. If it is deferred, link a tracking issue in the description.
  • First Principles item 10 (the code_channels_toggle fallback that never runs) has no reply.
  • Sensitive Change Review is red until the author posts its reasoning template for security_posture.py.

Even after these are fixed, this PR goes to a human reviewer. It adds a STRICT route that trusts an attested session key, changes the redaction registry in security_posture.py, and deletes worktrees and branches on Archive. It also targets feat/slack-code-channels-workspace, not main, so it needs a fresh review once it is retargeted.

— crew-pr-reviewer (r116)

@iamwhatever iamwhatever left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Request changes at 66687b7.

The archive-fence defect from r116 is fixed: a click on a channel that is fenced but not recorded now starts the recovery (

if not stale and await surface.fenced_unrecorded(binding):
# Archived here but never recorded: record it now rather than
# answer "already archived" with nothing cleaned up.
if surface.channel_policy_refusal(channel, operation=operation, caller=user):
# The recovery stamps and removes the worktree: same ceiling.
await _ephemeral(channel, user, NOT_ALLOWED_TEXT)
return True
surface.audit(user, operation, "allowed", f"{resources} result=archive_retry")
_start_recovery(binding, user, time.time(), resources, await _worktree_path(binding))
await _ephemeral(channel, user, ALREADY_ARCHIVED_TEXT)
). Two defects the AI lanes raised on this head hold up in the code:

  1. Plan canvas (Opus). When the first create times out or the socket resets after Slack made the canvas, _publish_canvas_locked re-raises without recording anything (
    async def _publish_canvas_locked(call: Call, channel: str, markdown: str, title: str) -> str:
    record = await surface_get(channel)
    canvas_id = (record.plan_canvas_id if record is not None else "") or _unsaved_canvas.get(
    channel, ""
    )
    created = False
    if not canvas_id:
    try:
    canvas_id = await _create_canvas(call, channel, markdown, title)
    created = True
    except CodeChannelApiError as exc:
    if exc.code != CANVAS_ALREADY_EXISTS:
    raise
    # Never retried, and never adopted: a canvas this gateway did not
    # create may be a shared document, and writing it would edit it
    # everywhere it appears.
    raise ToolRefusal(
    "Error: this channel already has a canvas that Kiro Crew did not create, "
    "so it was left alone. Share the plan as an html view instead.",
    CANVAS_ALREADY_EXISTS,
    ) from None
    if not canvas_id:
    raise CodeChannelApiError("conversations.canvases.create", "missing_canvas_id")
    _unsaved_canvas[channel] = canvas_id
    ). The next call creates again, gets channel_canvas_already_exists, and refuses for good with "a canvas that Kiro Crew did not create". Smallest fix: on a maybe_applied create error, remember that a create may have landed for the channel; when a later create answers channel_canvas_already_exists with that record present, read the channel's canvas id and adopt it.
  2. Worktree removal (GPT, upheld by adjudication). For sessions filed under the channel's folder, _turn_running returns the folder scan's cached answer (
    def _turn_running(state: Any, key: str, filed: dict[str, tuple[bool, int]]) -> bool:
    """Whether session *key* is mid-turn (the folder scan's answer, else its slot's)."""
    if key in filed:
    return filed[key][0]
    slot = (getattr(state, "_slots", None) or {}).get(key) if state is not None else None
    return bool(getattr(slot, "turn_running", False))
    ). It is checked before the awaited setters, and git worktree remove re-checks nothing (
    removed = git_ops.run_git(["worktree", "remove", record.worktree], record.repo_root)
    ). A worker that starts a turn in that window keeps running in a deleted directory, and its output can be lost. Smallest fix: read each affected slot's live turn_running just before removal, and keep the tree if any is busy.

The GPT Stop finding was downgraded by its adjudicator and First Principles item 9 (15 commit-point policy re-checks) is a simplification note; neither blocks by itself, but please reply to each.

Even with these fixed, this PR goes to a human reviewer. It adds a strict route that trusts an attested session key, changes security_posture.py and security_posture_sinks_delivery.py (Sensitive Change Review needs the template for this head), and deletes worktrees and branches on Archive. It also targets feat/slack-code-worktree-diff, not main, so it needs a fresh review after it is retargeted.

— crew-pr-reviewer (r143)

@kyleseaman

kyleseaman commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor Author

@iamwhatever, replies to crew-pr-reviewer r143 (on 66687b7). The review has no inline threads, so all five points are answered here. Everything is checked on head b7abba1, based on main 759bb96 (#28305 has merged). The fixes are in that head's second commit, fix(slack): code-channel review fixes.... The tests named below pass there.

  1. r116 archive fence: fixed (as you noted). A click on a channel that is fenced but not recorded starts the recovery: wrapup.py#L796. Test: test_a_click_on_a_fenced_unrecorded_archive_retries_instead_of_answering_done.

  2. Plan canvas lost create: fixed. The intent to create is stored in the surface record before the create is sent, and kept until the canvas id is stored, so a lost answer, a failed id write or a restart is covered; a create whose intent can't be stored isn't sent (tools.py#L847). On a later channel_canvas_already_exists, _adopt_lost_create adopts the channel's canvas only if files.info names this gateway's bot as its creator and it was created no earlier than that lost create began. Anything else is refused and left untouched. The files.info read never trips the install-wide latch. Tests: test_a_canvas_whose_create_answer_was_lost_is_adopted_next_time, test_a_canvas_whose_id_write_failed_is_adopted_after_a_restart, test_no_canvas_is_created_when_its_intent_cannot_be_stored, test_a_foreign_canvas_is_never_adopted_or_overwritten, test_an_unverifiable_canvas_is_refused_and_code_channels_stay_on.

  3. Worktree removal re-check: fixed. _retarget records each session's (turn running, turn generation) before its first await. Right before git worktree remove starts, with no await in between, _still_idle (called at L519) reads the live slots again. The tree is kept, and the sessions moved back, if one started a turn or a new session joined the folder. Test: test_archive_keeps_the_tree_when_a_turn_starts_while_sessions_move (bound turn, worker turn, worker joined).

  4. GPT native-Stop finding (downgraded by its adjudicator): no change. The window is one agent-surface write already in flight when Stop lands (surface.py#L321). The session itself is stopped, so the turn makes no further tool calls, and the stray write is visible in the channel. Closing it needs new per-turn stop state shared by agent_sessions, routing and surface, plus a re-check at every write. The adjudicator judged that disproportionate, so it stays a known limit, not a deferral.

  5. First Principles item 9 (the commit-point policy re-checks): kept, by design. Each handler awaits (a creation wait, a bind, the worktree, a lock) before its side effect, and the per-channel ceiling can change during any of them. A check only at entry is what earlier review rounds blocked. A single shared checker can't cover them, because each check has to run right before that handler's own side effect. To keep them from drifting, every one goes through surface.channel_policy_refusal, and surface.policy_gated_handlers() lists each handler with its guard count. A test holds that list (test_every_policy_gated_handler_checks_at_entry_and_at_its_commit_point), and each re-check has its own mid-await test. First Principles passes on the current lineage.

Could you re-review at b7abba1?

@bolichen97

Copy link
Copy Markdown
Contributor

@iamwhatever, re-review ask at b7abba1. Your change request at 66687b7 named two defects. kyleseaman answered all five points on 11-03 against this head, and the code on b7abba1 looks like it addresses both:

  1. Plan canvas: tools.py now handles a maybe_applied create error, and _adopt_lost_create adopts the channel's canvas only when files.info shows this gateway's bot made it. A stored intent alone adopts nothing.
  2. Worktree removal: cleanup.py now reads each session's live (turn running, generation) from the loop just before removal, instead of the folder scan's cached answer.

Could you re-review this head, and clear your change request if you agree? Separately, the Sensitive Change Review check on this head still needs the author's reasoning template.

iamwhatever
iamwhatever previously approved these changes Nov 8, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor

Rebased onto main as 6a69939d2 (still the two commits). Conflicts: mcp_core_parts/identity.py (main swapped mcp_tools/apps.py for mcp_tools/app_tools.py; kept that and added mcp_tools/code_channels.py), mcp_tools/__init__.py (code_channels goes before app_tools, which main keeps last), and the gate patches in test_mcp_tool_titles.py / test_mcp_discovery_agent_config.py (both kept). Re-pinned the MCP route table (345 rows) and the one extra _deferred in both boot pins for /api/slack/code-channel/tool. Locally the reach, titles, discovery, identity-topology and slack code-channel suites pass. This push dropped the 19:27Z approval; it needs a fresh one once CI is green.

@iamwhatever

Copy link
Copy Markdown
Contributor

@kyleseaman @bolichen97 status at 6a69939d2f2611d000fc5eec39ca2218eb873c71 after the rebase. GPT 6.1 raised two new blocking findings (review comment):

  1. tools.py:568: a credential split by <span hidden> or display:none passes the shown-text screen, because both text projections keep the hidden separator. This is the same area as the earlier shown-text fix in b7abba1, so I am not starting another fix round on it. It needs your call on the approach: GPT suggests limiting accepted HTML attributes and CSS to a grammar the screen can project faithfully (for example, drop hidden, inline style and <style>), or the screen could treat hidden content as removed.
  2. routing.py:1724: !stop (and native Stop) installs the fence and status hold before stop_slot_turn returns; when it answers compacting=True and the turn keeps running, that turn loses its code-channel tools and a pending /wrap-up is disarmed. Suggested fix: keep the fence provisional and restore the previous fence and hold on a compaction refusal.

Opus 5.5 Review failed on infra (no discovery marker); I will rerun it. Sensitive Change Review needs the template again naming the new head 6a69939d2f2611d000fc5eec39ca2218eb873c71, since the push reset it.

A session bound to a Slack code channel gets code_channel_* MCP tools
(views, plan canvas, its own context-bar items, rename, status, wrap-up)
that act only on its own channel: the channel is derived from the
transport-attested calling session through the strict route
POST /api/slack/code-channel/tool, never from an argument.

The channel offers /summarize, /wrap-up and, when the session can open a
pull request, /create-pr (agents.conversations.setCommands over Socket
Mode, redeliveries deduplicated). The wrap-up posts a summary with an
Archive button; a click authorized against the origin conversation
archives with summary_message_ts and releases the worktree, which is
kept when it holds uncommitted work. Every decision is SEL-audited, and
with slack.code_channels off (or the install unable to run it) nothing
here runs.
…canvas creates, idle-at-removal, shown-text screen

Every code-channel handler re-checks the per-channel allowed_channel_ids refusal after its awaits, right before each side effect (surface.policy_gated_handlers() is the audit list); the slash entry gate pairs channel_inbound_permitted with channel_refusal. A plan-canvas create whose answer was lost is remembered, and on the next already-exists the channel canvas is adopted only when files.info names our bot as its creator, no earlier than that create began. The Archive cleanup keeps the worktree when a session started a turn, or joined the folder, while the sessions were being moved. A view is screened on the text Slack shows: a credential split across Block Kit elements or HTML spans, or a label held apart from its value, refuses it, through the dashboard cards' own screen (card_lifecycle.readings_hide_secret, lifted from _hides_secret); Block Kit link destinations are no longer mention-defanged.
@kyleseaman

Copy link
Copy Markdown
Contributor Author

Sensitive change review

Drafted for the human reviewer to check and post; the agent does not post this as a comment.

  • Head commit: 349ce1c
  • Watched files changed (base main...head): src/kiro_crew/security_posture_sinks_delivery.py +7 / -0 (the "Slack code-channel posts" sink row, right before "Slack cron / notification posts") and src/kiro_crew/security_posture.py +5 / -0 (the NON_EGRESS_REDACTION_MODULES entry incl. its required reason comment). These are the same 12 lines, byte for byte, as the earlier single-file hunk; the base split the sink table into security_posture_sinks_delivery.py, so the sink row moved there. No other file matches SENSITIVE_GLOBS; security/paths*.py, sandbox_leaves.py, sandbox_precreate.py are untouched.
  • What rule changed: no floor, gate or path rule changed. Two additive classification rows: slack/code_channels/wrapup.py registered as the "Slack code-channel posts" redaction sink, and slack/code_channels/tools.py allowlisted as a non-egress redactor caller.
  • Before -> after (what was allowed/blocked, now): before, the security panel did not know the code-channel surface's posts and test_every_redactor_call_site_is_a_registered_sink_or_allowlisted refused both new modules; after, the panel counts wrapup.py's posts as a redacted output boundary and tools.py is recorded as posting only through it. Nothing is newly allowed or blocked at runtime. The surface record lives in the existing protected routing/ directory, so no new protection entry was added.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): the panel shows a wrong sink count, or tools.py gets an egress path later that skips the shared redactor and the allowlist hides it from the omission test. No redaction is removed by these rows; they only describe calls the code already makes.
  • Evidence checked (which sandbox result proves it): no sandbox rule changed, so no sandbox result applies. Removing each row in turn makes the omission test fail and name exactly that module (slack/code_channels/wrapup.py, then slack/code_channels/tools.py); with both rows in, every test in test/test_security_posture.py passes. A fresh-context review confirmed the relocated record keeps at least its old file-tool and sandbox protection under both data-home prefixes and a KIROCREW_HOME override.
  • No regression:
    • Tools still work (which tools/commands were run, result): the rows are data read by the security panel and the posture tests only; all 1626 focused code-channel, posture, facade, composition-contract and MCP-title and channel-gate ratchet tests pass on this head, as do the 223 posture, composition-contract, source-pin and inbound-gate tests.
    • Backward compatible (old config / old data / old callers still work, how checked): no existing row moved or changed; the diff is two additions, and with slack.code_channels off neither module runs.
    • Existing tests (which suites passed on this head): test/test_security_posture.py and test/test_security_posture_facade.py plus the focused code-channel suites, flake8, isort and mypy, all on 349ce1c.
  • How to undo: delete the sink row from src/kiro_crew/security_posture_sinks_delivery.py and the allowlist entry from src/kiro_crew/security_posture.py (the omission test will then name both modules until they are re-classified).

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.

3 participants