6262// Add to opencode.json: "plugin": ["/opt/kimaki-config/plugins/dm-context-filter.ts"]
6363// Or place in .opencode/plugins/ in the project root.
6464
65+ /**
66+ * External dependencies
67+ */
6568import type { Plugin } from "@opencode-ai/plugin" ;
6669
6770const fleetContextFilter : Plugin = async ( ) => {
@@ -108,7 +111,9 @@ const fleetContextFilter: Plugin = async () => {
108111 continue ;
109112 }
110113 const text = ( part as any ) . text as string ;
111- if ( ! text ) continue ;
114+ if ( ! text ) {
115+ continue ;
116+ }
112117
113118 // Remove MEMORY.md TOC injection.
114119 if ( text . includes ( "Project memory from MEMORY.md" ) ) {
@@ -134,22 +139,11 @@ const fleetContextFilter: Plugin = async () => {
134139} ;
135140
136141/**
137- * Remove a markdown section from a system prompt block. Matches from the
138- * heading to just before the next heading at the same or higher level, or
139- * to the end of the block.
142+ * Remove a markdown section from a system prompt block.
140143 *
141- * Supports both ## and ### headings. For ##, stops at the next ## or #.
142- * For ###, stops at the next ###, ##, or #.
143- *
144- * Fence-aware: lines that look like headings but live inside fenced code
145- * blocks (``` … ```) are NOT treated as section terminators. Bash code
146- * examples in the kimaki system prompt routinely contain `# Comment`
147- * lines, which a naive regex would mistake for a level-1 heading and
148- * stop the section early — leaving the rest of the section unstripped.
149- * The previous regex-only implementation hit this bug on every section
150- * containing a ```bash block with `#`-prefixed comments (notably
151- * "## waiting for a session to finish", which left a `--worktree`
152- * reference in the filtered prompt).
144+ * @param {string } block - System prompt block.
145+ * @param {string } heading - Section heading to remove.
146+ * @return {string } System prompt block without the requested section.
153147 */
154148function stripSection ( block : string , heading : string ) : string {
155149 const lines = block . split ( "\n" ) ;
@@ -165,7 +159,9 @@ function stripSection(block: string, heading: string): string {
165159 break ;
166160 }
167161 }
168- if ( start === - 1 ) return block ;
162+ if ( start === - 1 ) {
163+ return block ;
164+ }
169165
170166 // Walk forward looking for the next heading of the same or higher level
171167 // (i.e. fewer-or-equal `#` characters), tracking fenced-code-block state
@@ -178,7 +174,9 @@ function stripSection(block: string, heading: string): string {
178174 inFence = ! inFence ;
179175 continue ;
180176 }
181- if ( inFence ) continue ;
177+ if ( inFence ) {
178+ continue ;
179+ }
182180 const m = line . match ( / ^ ( # { 1 , 6 } ) \s + \S / ) ;
183181 if ( m && m [ 1 ] . length <= level ) {
184182 end = i ;
@@ -203,6 +201,9 @@ function stripSection(block: string, heading: string): string {
203201 * Leaving the language in causes the agent to try `kimaki send --worktree`
204202 * or treat a Kimaki worktree as its working directory instead of using the
205203 * DM Code workspace.
204+ *
205+ * @param {string } block System prompt block.
206+ * @return {string } System prompt block without worktree inline guidance.
206207 */
207208function stripWorktreeInlines ( block : string ) : string {
208209 let result = block ;
@@ -267,6 +268,9 @@ function stripWorktreeInlines(block: string): string {
267268 *
268269 * We keep `${channelId}` examples untouched — those are the intended,
269270 * session-scoped forms.
271+ *
272+ * @param {string } block System prompt block.
273+ * @return {string } System prompt block without project discovery guidance.
270274 */
271275function stripProjectDiscoveryInlines ( block : string ) : string {
272276 let result = block ;
@@ -347,6 +351,9 @@ function stripProjectDiscoveryInlines(block: string): string {
347351 * agent. Passing `--agent <current_agent>` teaches the runtime agent to turn
348352 * the synthetic reminder value (often `opencode`) into a real session routing
349353 * override, bypassing the channel-bound Franklin agent.
354+ *
355+ * @param {string } block System prompt block.
356+ * @return {string } System prompt block without agent override examples.
350357 */
351358function stripAgentOverrideInlines ( block : string ) : string {
352359 let result = block ;
@@ -382,6 +389,9 @@ function stripAgentOverrideInlines(block: string): string {
382389 * use the live site and `wp`. A tunnel is still useful when the task needs an
383390 * inbound public URL, but it is not the default path for interacting with the
384391 * site.
392+ *
393+ * @param {string } block System prompt block.
394+ * @return {string } System prompt block with WordPress runtime guidance appended.
385395 */
386396function appendWordPressSiteRuntimeInstruction ( block : string ) : string {
387397 const instruction = `
@@ -399,6 +409,9 @@ Use \`kimaki tunnel\` only when the task specifically needs an inbound public UR
399409
400410/**
401411 * Append a positive Data Machine session handoff instruction.
412+ *
413+ * @param {string } block System prompt block.
414+ * @return {string } System prompt block with Data Machine handoff guidance appended.
402415 */
403416function appendDataMachineSessionHandoffInstruction ( block : string ) : string {
404417 const instruction = `
0 commit comments