Skip to content

fix: strip project discovery from system prompt to prevent wrong-channel minion routing#61

Merged
chubes4 merged 1 commit intomainfrom
fix/minion-routing-pollution
Apr 23, 2026
Merged

fix: strip project discovery from system prompt to prevent wrong-channel minion routing#61
chubes4 merged 1 commit intomainfrom
fix/minion-routing-pollution

Conversation

@chubes4
Copy link
Copy Markdown
Member

@chubes4 chubes4 commented Apr 23, 2026

Summary

Agents running under the dm-context-filter plugin could still discover other Discord channel IDs and spawn minion sessions there, violating the "one agent per Discord channel" boundary. Refs Extra-Chill/data-machine-code#49.

The existing filter stripped the ## cross-project commands section, but three residual vectors let channel IDs leak back into the system prompt:

  1. ## reading other sessions — documented kimaki session list --project /path/to/project and kimaki session search --channel <channel_id>. Direct project-and-channel discovery surface.
  2. Project-discovery inlines — stray kimaki project list|add|create, kimaki send --project, and bare kimaki send --channel <channel_id> examples scattered across surviving sections (scheduled sends, opencode commands, handoff instructions).
  3. No positive counter-instruction — once the agent learned a channel ID some other way (training data, kimaki --help, another agent mentioning it), nothing told it not to use that ID.

What this PR changes

kimaki/plugins/dm-context-filter.ts:

  • Strip ## reading other sessions as a whole section. On a single-project fleet server the agent only ever needs kimaki session list (no flags) for the current project — the flag-heavy documentation is pure leakage.
  • Add stripProjectDiscoveryInlines() to catch surviving lines that reference kimaki project list|add|create, kimaki send --project <dir>, or kimaki send --channel <channel_id> (literal placeholder — the current-channel \${channelId} form is substituted to a concrete numeric ID before the plugin runs, so it never matches and stays intact).
  • Inject ## Minion Session Routing at the end of the system prompt. Positive defense-in-depth instruction: all minion sessions stay in the current channel; cross-repo work uses kimaki send --cwd /path/to/repo (same channel, different checkout) or Data Machine Code's workspace worktrees.

Updated the header comment block to document items 10 and 11 (reading-other-sessions + project-discovery inlines) and the new positive-injection behavior.

Verification

  • Regex patterns targeted against the exact strings in kimaki/cli/src/system-message.ts (line 635 for session search --channel <channel_id>, lines 652-670 for the ## cross-project commands block, line 667 for kimaki send --channel <channel_id>).
  • The \${channelId} template variable is substituted before experimental.chat.system.transform runs, so the current session's baked-in channel ID (numeric, e.g. 1493345787894038649) does not match the <channel_id> placeholder regex — current-channel examples in ## starting new sessions from CLI are preserved.
  • Conservative line-level regexes — each pattern anchors on a full line starting with kimaki <verb> to avoid mangling prose that happens to mention --project or --channel.

AI assistance

  • AI assistance: Yes
  • Tool(s): Claude Code (Sonnet 4.5)
  • Used for: Drafted the two new helper functions (stripProjectDiscoveryInlines, appendMinionRoutingInstruction), updated the header-comment block, and composed this PR body. Chris reviewed the regex patterns against the actual system-prompt source in kimaki/cli/src/system-message.ts and verified the existing filter coverage before adding the new strips.

Agents running under the dm-context-filter plugin could still discover
other Discord channel IDs and route minion sessions there, even with the
existing '## cross-project commands' section stripped. The section
stripper missed three residual vectors:

- '## reading other sessions' documented 'kimaki session list --project'
  and 'kimaki session search --channel <channel_id>'.
- Stray 'kimaki project list|add|create' / 'kimaki send --project' /
  bare 'kimaki send --channel <channel_id>' examples in surviving
  sections (scheduled sends, opencode commands, etc.).
- No positive instruction steering the agent back to the current channel
  once it learned a channel ID some other way (--help, training data,
  another agent's mention).

This fix:

1. Strips '## reading other sessions' as a whole section.
2. Adds stripProjectDiscoveryInlines() to remove surviving
   kimaki project / --project / --channel <channel_id> lines.
3. Appends '## Minion Session Routing' with a positive instruction:
   all minion sessions stay in the current channel; --cwd targets a
   different repo directory without changing channels.

Refs Extra-Chill/data-machine-code#49.
@chubes4 chubes4 merged commit 2268406 into main Apr 23, 2026
2 checks passed
@chubes4 chubes4 deleted the fix/minion-routing-pollution branch April 23, 2026 20:28
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.

1 participant