xonecas.io
64875
Mc

mini-coder / commit 2986a05

feat: more error handling, and a compaction experiment

xonecas2026-06-16 2986a058457fab04812769aa4a0715cd997bcd83 parent 2e83492

3 files changed

src/agent.ts+6−7
@@ -78,10 +78,6 @@ export async function* streamAgent(
7878
7979 // Main agent loop, continues until llm sends a response other than toolCall or has no tool calls.
8080 while (true) {
81- let estimate = estimateTokens(JSON.stringify(llmCtx));
82- // 80k is the agreed uppon threshold to the DUMB ZONE
83- if (estimate > 80000) compactContext(llmCtx.messages);
84-
8581 const s = streamSimple(agentCtx.options.model, llmCtx, {
8682 reasoning: agentCtx.options.effort,
8783 signal: agentCtx.signal,
@@ -115,9 +111,6 @@ export async function* streamAgent(
115111 yield { type: "message_update", partial };
116112 }
117113
118- estimate = estimateTokens(JSON.stringify(llmCtx));
119- // 80k is the agreed uppon threshold to the DUMB ZONE
120- if (estimate > 80000) compactContext(llmCtx.messages);
121114 break;
122115 }
123116
@@ -134,6 +127,12 @@ export async function* streamAgent(
134127 return;
135128 }
136129 }
130+
131+ // Experiment: use this inside the inner loop for "running" compaction
132+ // after we are in the dumb zone.
133+ const estimate = estimateTokens(JSON.stringify(llmCtx));
134+ // 80k is the agreed uppon threshold to the DUMB ZONE
135+ if (estimate > 80000) compactContext(llmCtx.messages);
137136 }
138137
139138 const message = await s.result();
src/headless.ts+1−0
@@ -39,6 +39,7 @@ export async function streamHeadless(
3939 };
4040
4141 const agent = streamAgent(ctx);
42+
4243 for await (const ev of agent) {
4344 switch (ev.type) {
4445 case "message_end":
src/tui.ts+7−0
@@ -357,6 +357,13 @@ async function streamAgentTUI(state: TUIState) {
357357 }
358358 }
359359 }
360+ } catch (error) {
361+ const text = error instanceof Error ? error.message : String(error);
362+ state.tuiMessages.push({
363+ timestamp: formatTimestamp(Date.now()),
364+ role: "assistant",
365+ text,
366+ });
360367 } finally {
361368 state.streaming = false;
362369 if (!state.sessionId) {