From 6b8b73776732ca2663e2d21a32fdc7ce54b64686 Mon Sep 17 00:00:00 2001 From: dawn <90008@klbr.net> Date: Thu, 3 Sep 2026 17:53:54 +0900 Subject: [PATCH] fix: filter /threads output from model context and strip command footer --- index.ts | 10 +++++++++- src/inject.ts | 4 ++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/index.ts b/index.ts index 598382c..30c2d39 100644 --- a/index.ts +++ b/index.ts @@ -4,6 +4,7 @@ import type { AgentEndEvent, BeforeAgentStartEvent, BeforeAgentStartEventResult, + ContextEvent, ExtensionAPI, ExtensionCommandContext, ExtensionContext, @@ -100,7 +101,6 @@ function formatRegistry(registry: Registry): string { if (registry.unreconciled.length > 0) { sections.push(`Unreconciled user messages: ${registry.unreconciled.length}`); } - sections.push("Commands: /threads done|dismiss|reopen|drop , /threads edit "); return sections.join("\n\n"); } @@ -200,6 +200,14 @@ export function createCommitmentObserverExtension(env: NodeJS.ProcessEnv = proce scheduleReconcile(ctx, branchMessages(ctx.sessionManager.getBranch())); }); + // Ensure /threads output shown in the TUI never enters model context + pi.on("context", (event: ContextEvent): { messages?: AgentMessage[] } | void => { + const filtered = event.messages.filter( + (message) => !(message.role === "custom" && message.customType === LIST_CUSTOM_TYPE), + ); + return filtered.length === event.messages.length ? undefined : { messages: filtered }; + }); + pi.on( "before_agent_start", async ( diff --git a/src/inject.ts b/src/inject.ts index 59c3359..6cfced1 100644 --- a/src/inject.ts +++ b/src/inject.ts @@ -61,11 +61,11 @@ export function renderOpenThreads( } if (hidden > 0) { - const note = `- (${hidden} more open thread${hidden === 1 ? "" : "s"} hidden by the injection cap; run /threads)`; + const note = `- (${hidden} more open thread${hidden === 1 ? "" : "s"} hidden by the injection cap)`; const withNote = [HEADER, ...lines, note, FOOTER].join("\n"); if (estimateTokens(withNote) <= tokenCap) return withNote; const dropped = lines.slice(0, -1); - const rebuilt = [HEADER, ...dropped, `- (${hidden + 1} more open threads hidden by the injection cap; run /threads)`, FOOTER].join("\n"); + const rebuilt = [HEADER, ...dropped, `- (${hidden + 1} more open threads hidden by the injection cap)`, FOOTER].join("\n"); if (estimateTokens(rebuilt) <= tokenCap) return rebuilt; } -- 2.51.2