xonecas.io
64875
Mc

mini-coder / commit 6becf56

feat: surface context pruning in output and update todo

xonecas2026-03-13 6becf56fc5cdb898a24c0d3fef6ba41f76642494 parent fddb3af

6 files changed

TODO.md+14−1
@@ -1,9 +1,22 @@
11 # TODO
22
3-- Surface to the user when context prunning happens in a structured output
43 - Normalize the different models reasoning output. Trim excessive whitespace safely, ensure it renders uniquely. Should have a more structured output so it's noticeable that is reasoning and not a normal response. Enable the markdown rendering for it.
54 - Improve our autocomplete via TAB. it should work on all commands and parameters. When the user uses tab assume it's a file path autocompletion.
65 - Tool hooks output prints inline with spinner
6+- When the user uses /new reset the terminal and clear the history, print the banner again
7+- Review our markdown renderer. Let's make it render the raw markdown, but syntax highlited
8+
9+---
10+
11+# Lean and mean idea
12+
13+CLI vs MCP is the hot debate. I've testing a lot with different coding editors and I want to make feature branch that removes the subagent tool. Then simplify our read/write tools, streamline their usage based on usage history. Then update the mini-coder skill to teach how to use "subagents" by calling another mc via shell, and general tool guidelines (don't bloat context with large outputs, dont read more than needed, etc...). Also review our exa tools for improvements. Overall this allows the …
14+
15+Why this is good in my opinion:
16+
17+- Way less code, much less bug surface, faster.
18+- Less tool implementation, simpler structured output logic
19+- Raw, simple and makes mini-coder closer to it's intented coding prompt vision (as oposed to an interactive coding agent with TUI)
720
821 ---
922
src/cli/headless-reporter.ts+2−0
@@ -38,6 +38,8 @@ export class HeadlessReporter implements AgentReporter {
3838 case "reasoning-delta":
3939 reasoningText += event.delta;
4040 break;
41+ case "context-pruned":
42+ break;
4143 case "turn-complete":
4244 inputTokens = event.inputTokens;
4345 outputTokens = event.outputTokens;
src/cli/stream-render.test.ts+25−0
@@ -153,4 +153,29 @@ describe("renderTurn", () => {
153153 expect(strip(stdout)).toBe("◆ line 1\nline 2\n\n");
154154 expect(stopCalls).toBeGreaterThanOrEqual(2);
155155 });
156+
157+ test("renders a structured context-pruned line", async () => {
158+ captureStdout();
159+
160+ await renderTurn(
161+ eventsFrom([
162+ {
163+ type: "context-pruned",
164+ mode: "balanced",
165+ beforeMessageCount: 120,
166+ afterMessageCount: 90,
167+ removedMessageCount: 30,
168+ beforeTotalBytes: 40000,
169+ afterTotalBytes: 25000,
170+ removedBytes: 15000,
171+ },
172+ done(),
173+ ]),
174+ new Spinner(),
175+ );
176+
177+ expect(strip(stdout)).toContain(
178+ "context-pruned mode=balanced removed_messages=30 removed_bytes=15000 messages_before=120 messages_after=90",
179+ );
180+ });
156181 });
src/cli/stream-render.ts+9−0
@@ -127,6 +127,15 @@ export async function renderTurn(
127127 break;
128128 }
129129
130+ case "context-pruned": {
131+ flushAnyText();
132+ spinner.stop();
133+ writeln(
134+ `${G.info} ${c.dim(`context-pruned mode=${event.mode} removed_messages=${event.removedMessageCount} removed_bytes=${event.removedBytes} messages_before=${event.beforeMessageCount} messages_after=${event.afterMessageCount}`)}`,
135+ );
136+ break;
137+ }
138+
130139 case "turn-complete": {
131140 flushAnyText();
132141 spinner.stop();
src/llm-api/turn.ts+23−7
@@ -801,18 +801,34 @@ export async function* runTurn(options: {
801801 logApiEvent("openai item ids stripped from history", { modelString });
802802 }
803803
804- logApiEvent(
805- "turn context pre-prune",
806- getMessageDiagnostics(openAIItemIdsStrippedMessages),
804+ const prePruneDiagnostics = getMessageDiagnostics(
805+ openAIItemIdsStrippedMessages,
807806 );
807+ logApiEvent("turn context pre-prune", prePruneDiagnostics);
808808 const prunedMessages = applyContextPruning(
809809 openAIItemIdsStrippedMessages,
810810 pruningMode,
811811 );
812- logApiEvent(
813- "turn context post-prune",
814- getMessageDiagnostics(prunedMessages),
815- );
812+ const postPruneDiagnostics = getMessageDiagnostics(prunedMessages);
813+ logApiEvent("turn context post-prune", postPruneDiagnostics);
814+ if (
815+ (pruningMode === "balanced" || pruningMode === "aggressive") &&
816+ (postPruneDiagnostics.messageCount < prePruneDiagnostics.messageCount ||
817+ postPruneDiagnostics.totalBytes < prePruneDiagnostics.totalBytes)
818+ ) {
819+ yield {
820+ type: "context-pruned",
821+ mode: pruningMode,
822+ beforeMessageCount: prePruneDiagnostics.messageCount,
823+ afterMessageCount: postPruneDiagnostics.messageCount,
824+ removedMessageCount:
825+ prePruneDiagnostics.messageCount - postPruneDiagnostics.messageCount,
826+ beforeTotalBytes: prePruneDiagnostics.totalBytes,
827+ afterTotalBytes: postPruneDiagnostics.totalBytes,
828+ removedBytes:
829+ prePruneDiagnostics.totalBytes - postPruneDiagnostics.totalBytes,
830+ };
831+ }
816832
817833 const turnMessages = compactToolResultPayloads(
818834 prunedMessages,
src/llm-api/types.ts+12−0
@@ -27,6 +27,17 @@ export interface ToolResultEvent {
2727 isError: boolean;
2828 }
2929
30+export interface ContextPrunedEvent {
31+ type: "context-pruned";
32+ mode: "balanced" | "aggressive";
33+ beforeMessageCount: number;
34+ afterMessageCount: number;
35+ removedMessageCount: number;
36+ beforeTotalBytes: number;
37+ afterTotalBytes: number;
38+ removedBytes: number;
39+}
40+
3041 export interface TurnCompleteEvent {
3142 type: "turn-complete";
3243 inputTokens: number;
@@ -54,6 +65,7 @@ export type TurnEvent =
5465 | TextDeltaEvent
5566 | ToolCallStartEvent
5667 | ToolResultEvent
68+ | ContextPrunedEvent
5769 | TurnCompleteEvent
5870 | TurnErrorEvent;