xonecas.io
64875
Mc

mini-coder / commit ce84616

feat: cache older conversation log Nodes

xonecas2026-04-29 ce84616ef1f0b7213e95c141a2ae07aa9dc4024b parent fd39041

10 files changed

TODO.md+9−0
@@ -2,6 +2,15 @@
22
33 > This file is managed by the user, only edit if asked to.
44
5+## TODO
6+
7+- [ ] `readImage` tool — embed image files in prompts (big real gap). Also update `tui-conversation.ts` `messageCacheKey` and `toolMessageNode` to handle image blocks.
8+- [ ] Session fork/undo — either tree-view forking (like pi coding agent) or undo flow, or both. Complex feature, needs UI and storage design.
9+- [ ] Path autocomplete in TUI — `Tab` on file paths opens path picker.
10+- [ ] Command autocomplete in TUI — `/` + `Tab` interactive command menu with descriptions.
11+- [ ] Prompt history in TUI — `Ctrl+R` search and persistent prompt history.
12+- [ ] Status bar richness — cumulative tokens/cost, detailed git counts (staged/modified/untracked/ahead/behind).
13+
514 ## TODO: Better prompts, tools descriptions and reminder prompt engineering.
615
716 Raw notes, references:
benchmarks/break-filter-js-from-html.sh+1−0
@@ -4,6 +4,7 @@ PYTHONPATH="$PWD" harbor run -y \
44 --dataset terminal-bench/terminal-bench-2 \
55 --include-task-name terminal-bench/break-filter-js-from-html \
66 --agent-import-path benchmarks.local-harbor-agent:LocalMiniCoderAgent \
7+ --model openai-codex/gpt-5.5 \
78 --n-attempts 4 \
89 --n-concurrent 2 \
910 --max-retries 0
benchmarks/filter-js-from-html.sh+1−0
@@ -4,6 +4,7 @@ PYTHONPATH="$PWD" harbor run -y \
44 --dataset terminal-bench/terminal-bench-2 \
55 --include-task-name terminal-bench/filter-js-from-html \
66 --agent-import-path benchmarks.local-harbor-agent:LocalMiniCoderAgent \
7+ --model openai-codex/gpt-5.5 \
78 --n-attempts 4 \
89 --n-concurrent 2 \
910 --max-retries 0
benchmarks/fix-git.sh+1−0
@@ -4,6 +4,7 @@ PYTHONPATH="$PWD" harbor run -y \
44 --dataset terminal-bench/terminal-bench-2 \
55 --include-task-name terminal-bench/fix-git \
66 --agent-import-path benchmarks.local-harbor-agent:LocalMiniCoderAgent \
7+ --model openai-codex/gpt-5.5 \
78 --n-attempts 4 \
89 --n-concurrent 2 \
910 --max-retries 0
benchmarks/local-harbor-agent.py+22−17
@@ -7,7 +7,7 @@ from pathlib import Path
77 from tempfile import TemporaryDirectory
88 from typing import Any
99
10-from harbor.agents.installed.base import BaseInstalledAgent, with_prompt_template
10+from harbor.agents.installed.base import BaseInstalledAgent
1111 from harbor.environments.base import BaseEnvironment
1212 from harbor.models.agent.context import AgentContext
1313 from harbor.models.trial.paths import EnvironmentPaths
@@ -65,7 +65,6 @@ class LocalMiniCoderAgent(BaseInstalledAgent):
6565 ),
6666 )
6767
68- @with_prompt_template
6968 async def run(
7069 self,
7170 instruction: str,
@@ -88,27 +87,33 @@ class LocalMiniCoderAgent(BaseInstalledAgent):
8887 f"{config_dir}/auth.json",
8988 required=True,
9089 )
91- await self._upload_config_file(
92- environment,
93- self.host_config_dir / "settings.json",
94- f"{config_dir}/settings.json",
95- required=False,
96- )
9790
9891 stdout_path = (EnvironmentPaths.agent_dir / self.STDOUT_LOG).as_posix()
9992 stderr_path = (EnvironmentPaths.agent_dir / self.STDERR_LOG).as_posix()
10093
101- await self.exec_as_agent(
102- environment,
103- command=(
104- f"export HOME={shlex.quote(home)}; "
105- f'export PATH="{home}/.bun/bin:$PATH"; '
106- f"bun {shlex.quote(self.CONTAINER_ROOT + '/bin/mc.ts')} "
107- f"--json -p {shlex.quote(instruction)} "
108- f"</dev/null >{shlex.quote(stdout_path)} 2>{shlex.quote(stderr_path)}"
109- ),
94+ # Build CLI flags. Harbor's -m flag sets self.model_name as
95+ # "provider/model" (e.g. "openai-codex/gpt-5.5").
96+ cmd_parts = [
97+ f"bun {shlex.quote(self.CONTAINER_ROOT + '/bin/mc.ts')}",
98+ f"--prompt {shlex.quote(instruction)}",
99+ "--effort xhigh",
100+ ]
101+
102+ if self._parsed_model_provider and self._parsed_model_name:
103+ cmd_parts.append(
104+ f"--provider {shlex.quote(self._parsed_model_provider)}"
105+ )
106+ cmd_parts.append(f"--model {shlex.quote(self._parsed_model_name)}")
107+
108+ cmd = (
109+ f"export HOME={shlex.quote(home)}; "
110+ f'export PATH="{home}/.bun/bin:$PATH"; '
111+ f"{' '.join(cmd_parts)} "
112+ f"</dev/null >{shlex.quote(stdout_path)} 2>{shlex.quote(stderr_path)}"
110113 )
111114
115+ await self.exec_as_agent(environment, command=cmd)
116+
112117 def populate_context_post_run(self, context: AgentContext) -> None:
113118 stdout_path = self.logs_dir / self.STDOUT_LOG
114119 stderr_path = self.logs_dir / self.STDERR_LOG
benchmarks/terminal-bench-suite.sh+1−0
@@ -3,6 +3,7 @@ PYTHONPATH="$PWD" harbor run -y \
33 --jobs-dir "$PWD/benchmarks/jobs" \
44 --dataset terminal-bench/terminal-bench-2 \
55 --agent-import-path benchmarks.local-harbor-agent:LocalMiniCoderAgent \
6+ --model openai-codex/gpt-5.5 \
67 --n-attempts 2 \
78 --n-concurrent 2 \
89 --max-retries 0
src/agent.ts+5−0
@@ -19,6 +19,11 @@ import type {
1919 // Published research found that **simply hiding old tool outputs** matched the quality of full LLM summarization with **zero extra compute**:
2020 // https://blog.jetbrains.com/research/2025/12/efficient-context-management/
2121 export function compactContext(messages: Message[]) {
22+ // TODO: Preserve SKILL.md contents, and exclude them from compaction.
23+ // Problem: How do we know? we need to check each message result againt it's arguments
24+ // and then find if by chance it has a read skill command... This is a mess. We we.
25+ // A better way would be to first add a read(path, lines, offset). And then we know
26+ // which files are read using it, and can match by path if it's a SKILL.md ending.
2227 const KEEP_OBSERVATIONS = 10;
2328
2429 const toolResultIndices: number[] = [];
src/tui-components.ts+9−4
@@ -105,15 +105,20 @@ export function ContextPill(state: TUIState) {
105105 text = "0%";
106106 bg = theme.bwhite;
107107 } else {
108+ // Colors show the progress in the "smart window" or how much
109+ // before the dumb zone. The user facing percentage is the model
110+ // amount. An elegant way to show both :)
108111 const max = state.options.model.contextWindow;
112+ const smartMax = 80000;
109113 const percent = Math.floor((state.contextSize / max) * 100);
110- if (percent > 80) {
114+ const smartPercent = Math.floor((state.contextSize / smartMax) * 100)
115+ if (smartPercent > 90) {
111116 bg = theme.bred;
112- } else if (percent > 60) {
117+ } else if (smartPercent > 80) {
113118 bg = theme.red;
114- } else if (percent > 40) {
119+ } else if (smartPercent > 70) {
115120 bg = theme.yellow;
116- } else if (percent > 30) {
121+ } else if (smartPercent > 50) {
117122 bg = theme.byellow;
118123 }
119124 text = `~${percent}%`;
src/tui-conversation.ts+47−4
@@ -137,18 +137,61 @@ function toolMessageNode(msg: ToolResultMessage): Node {
137137 );
138138 }
139139
140-function conversationMessageNode(msg: Message): Node {
141- const body =
140+const messageBodyCache = new WeakMap<Message, { key: number; node: Node }>();
141+
142+function messageCacheKey(msg: Message): number {
143+ if (msg.role === "assistant") {
144+ let key = 0;
145+ for (const block of msg.content) {
146+ if (block.type === "thinking") key += block.thinking.length;
147+ if (block.type === "text") key += block.text.length;
148+ if (block.type === "toolCall" && block.arguments)
149+ key += JSON.stringify(block.arguments).length;
150+ }
151+ if (msg.stopReason) key += msg.stopReason.length;
152+ if (msg.errorMessage) key += msg.errorMessage.length;
153+ return key;
154+ }
155+ if (msg.role === "user") {
156+ if (typeof msg.content === "string") return msg.content.length;
157+ return msg.content.reduce(
158+ (sum, b) => (b.type === "text" ? sum + b.text.length : sum),
159+ 0,
160+ );
161+ }
162+ if (msg.role === "toolResult") {
163+ return msg.content.reduce(
164+ (sum, b) => (b.type === "text" ? sum + b.text.length : sum),
165+ 0,
166+ );
167+ }
168+ return 0;
169+}
170+
171+function cachedMessageBody(msg: Message): Node {
172+ const key = messageCacheKey(msg);
173+ const cached = messageBodyCache.get(msg);
174+ if (cached && cached.key === key) {
175+ return cached.node;
176+ }
177+ const node =
142178 msg.role === "assistant"
143179 ? agentMessageNode(msg)
144180 : msg.role === "user"
145181 ? userMessageNode(msg)
146182 : msg.role === "toolResult"
147183 ? toolMessageNode(msg)
148- : Text("Unknown message?", { wrap: "word", fgColor: theme.bwhite });
184+ : Text("Unknown message?", {
185+ wrap: "word",
186+ fgColor: theme.bwhite,
187+ });
188+ messageBodyCache.set(msg, { key, node });
189+ return node;
190+}
149191
192+function conversationMessageNode(msg: Message): Node {
150193 return VStack({ gap: 1 }, [
151- body,
194+ cachedMessageBody(msg),
152195 HStack({ gap: 1, justifyContent: "end" }, [
153196 Text(`${relativeTime(msg.timestamp)} ago.`, {
154197 fgColor: theme.bblack,
src/tui-overlay.ts+5−1
@@ -195,7 +195,11 @@ function sessionLabel(session: Session): string {
195195 : firstUserMessage.content
196196 .map((block) => (block.type === "text" ? block.text : ""))
197197 .join(" ");
198- const snippet = text.trim().replace(/\s+/g, " ").slice(0, 80);
198+ const snippet = text
199+ .replaceAll(/<system-reminder>[\s\S]*?<\/system-reminder>/g, "")
200+ .trim()
201+ .replace(/\s+/g, " ")
202+ .slice(0, 80);
199203
200204 return snippet || session.id;
201205 }