fix: filter /threads output from model context and strip command footer
2 unmodified lines3456789101188 unmodified lines10010110210310310410510610791 unmodified lines19920020120220320420520620720820921021121221321477 unmodified lines2 unmodified linesimport type { AgentEndEvent, BeforeAgentStartEvent, BeforeAgentStartEventResult, ContextEvent, ExtensionAPI, ExtensionCommandContext, ExtensionContext, InputEvent,88 unmodified lines if (closed.length > 0) sections.push(`Closed threads:\n${closed.map(formatThread).join("\n")}`); if (registry.unreconciled.length > 0) { sections.push(`Unreconciled user messages: ${registry.unreconciled.length}`); } sections.push("Commands: /threads done|dismiss|reopen|drop <id>, /threads edit <id> <text>"); return sections.join("\n\n");}
export function createCommitmentObserverExtension(env: NodeJS.ProcessEnv = process.env) {91 unmodified lines if (event.reason === "reload") return; 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 ( _event: BeforeAgentStartEvent,77 unmodified lines59 unmodified lines6061626364646566676868697071721 unmodified line59 unmodified lines return estimateTokens(block) > tokenCap ? undefined : block; }
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; }
return [HEADER, ...lines, FOOTER].join("\n");1 unmodified line