xonecas.io
79113
Ma

mini-coding-agent / commit 6e334ae

fix(tui-bash): remove ansi from bash output before render

xonecas2026-10-07 6e334ae6f8b5ad44eb6db2e458eb45be43014516 parent 90f9ac3

5 files changed

AGENTS.md+41−5
@@ -1,27 +1,63 @@
11 # mini-coding-agent (`mini` for short)
22
3-A fast, transparent, config-first terminal coding agent for one user at a time.
3+A fast, transparent, config-first terminal coding agent.
44
55 The source code is the source of truth for behavior. If a fact can be learned
66 by reading the code, it does not belong here; keep this file short.
77
8+## Guardrails
9+
10+- No sandbox or permission layer. Tools run with the user's permissions;
11+ isolation is an environment concern (`nono`), not the agent's.
12+- No loop limits. No max turns, tool calls, token budgets, or agent-imposed
13+ timeouts. The user's ability to interrupt is the limit.
14+- Config-first. Every user-facing behavior that can vary comes from config with
15+ a sane default. Global config only — no project-local config, no
16+ config-override flags — and never duplicate `pi-ai`'s catalog or env vars.
17+- Minimal context. The model sees the configured system prompt plus explicitly
18+ opted-in resource files — never reminders, hidden blocks, or harness
19+ meta-text.
20+- Never invent a parallel model. Consume `pi-ai`'s `Message` and stream types
21+ directly.
22+- The agent never imports the TUI. Headless and TUI are two projections of the
23+ same agent events; the TUI owns no agent or provider semantics.
24+- Sessions are append-only JSONL, one message per line, fsynced on write. Never
25+ rewrite or delete committed lines. A persistence failure stops the turn.
26+- The loop has no compaction, no retries, and no meta-messages between steps.
27+ Provider errors surface as-is, never masked or summarized.
28+- `edit`, `read`, and `bash` only. Tool arguments are untrusted and validated
29+ once at the boundary. `read` returns image blocks only for models that declare
30+ image input.
31+- Interruption: ESC politely pauses at the next step boundary; Ctrl+C cancels
32+ the turn (abort the request, kill the tool's process group, persist the
33+ aborted message); Ctrl+D exits on an empty draft. Completed side effects are
34+ never undone.
35+- Trace the real data flow before designing; apply guards at the narrowest
36+ boundary.
37+- Validate untrusted input once at the boundary, then keep internal code
38+ plain-typed.
39+- Ask before adding a dependency.
40+- Do not add tests unless explicitly asked; verify manually.
41+- Before finishing, review the diff against the guardrails, remove anything that
42+ added scope, and report any requirement you could not satisfy.
43+
844 ## Verification
945
10-**Do not stand up mock servers, fixture
11-endpoints, replay files, or mock terminals**; they prove nothing.
46+**Do not stand up mock servers, fixture endpoints, replay files, or mock
47+terminals**; they prove nothing.
1248
1349 Use a real bash call for headless runs, and the `tools/stress.sh` script for TUI
1450 runs.
1551
1652 ### Provider
1753
18-Verify against the real provider. Use the `OPENCODE_API_KEY` environment
54+Verify against the real provider. Use the `OPENCODE_API_KEY` environment
1955 variable and a scratch `XDG_CONFIG_HOME` with a `mini-coding-agent/config.json`
2056 that declares the provider under test.
2157
2258 Use these models:
2359
24-- `openai-completions` -> `opnecode-go/deepseek-v4.1-flash`
60+- `openai-completions` -> `opencode-go/deepseek-v4.1-flash`
2561 - `openai-responses` -> `opencode-go/gpt-6-luna`
2662 - `anthropic-messages` -> `opencode-go/minimax-m3`
2763 - `google-generative-ai` -> `opencode/gemini-3.8-flash`
notes.md+2−0
@@ -7,6 +7,8 @@ These are **my** notes. Use your own file for your notes...
77
88 ## Notes
99
10+**weird rendering when deleting characters** in the editor when line wrapping/multiline is involved. Hard to repro consistently, but when a editor is multiline deleting a word across lines, breaks in weird ways.
11+
1012 `src/config.zig` - When we fixed the issue with the model specific api being at provider level for opencode in a recent commit, apparently we didn't do it for custom providers. Again, the models need to carry the metadata, the provider is just a label grouping.
1113
1214 ```jsonc
src/tui/render.zig+38−0
@@ -115,6 +115,44 @@ pub fn sanitize(a: std.mem.Allocator, text: []const u8) []const u8 {
115115 return out.items;
116116 }
117117
118+pub fn stripAnsi(a: std.mem.Allocator, text: []const u8) []const u8 {
119+ if (std.mem.indexOfScalar(u8, text, 0x1b) == null) return text;
120+ var out: std.ArrayList(u8) = .empty;
121+ var i: usize = 0;
122+ while (i < text.len) {
123+ if (text[i] != 0x1b) {
124+ out.append(a, text[i]) catch {};
125+ i += 1;
126+ continue;
127+ }
128+ i += 1;
129+ if (i >= text.len) break;
130+ if (text[i] == '[') {
131+ i += 1;
132+ while (i < text.len and (text[i] < 0x40 or text[i] > 0x7e)) i += 1;
133+ if (i < text.len) i += 1;
134+ continue;
135+ }
136+ if (text[i] == ']') {
137+ i += 1;
138+ while (i < text.len) {
139+ if (text[i] == 0x07) {
140+ i += 1;
141+ break;
142+ }
143+ if (text[i] == 0x1b and i + 1 < text.len and text[i + 1] == '\\') {
144+ i += 2;
145+ break;
146+ }
147+ i += 1;
148+ }
149+ continue;
150+ }
151+ i += 1;
152+ }
153+ return out.items;
154+}
155+
118156 pub fn expandTabs(a: std.mem.Allocator, text: []const u8, size: usize) []const u8 {
119157 if (std.mem.indexOfScalar(u8, text, '\t') == null) return text;
120158 var out: std.ArrayList(u8) = .empty;
src/tui/stream.zig+3−1
@@ -1,6 +1,7 @@
11 const std = @import("std");
22 const theme = @import("theme.zig");
33 const highlight = @import("highlight.zig");
4+const render = @import("render.zig");
45
56 pub const BodyLine = struct {
67 text: []const u8,
@@ -181,7 +182,8 @@ pub const TailStream = struct {
181182 pub fn pending(self: *TailStream) []BodyLine {
182183 var out: std.ArrayList(BodyLine) = .empty;
183184 if (self.rest.items.len > 0) {
184- out.append(self.a, .{ .text = self.rest.items, .style = .{ .fg = theme.current.comment } }) catch {};
185+ const text = render.stripAnsi(self.a, self.rest.items);
186+ out.append(self.a, .{ .text = text, .style = .{ .fg = theme.current.comment } }) catch {};
185187 }
186188 return out.items;
187189 }
src/tui/tui.zig+2−1
@@ -765,6 +765,7 @@ const Tui = struct {
765765
766766 fn commitToolResult(self: *Tui, name: []const u8, text: []const u8, is_error: bool, diffs: []const common.FileDiff, body: ?[]const u8) void {
767767 self.separator = true;
768+ const shown = render.stripAnsi(self.s, text);
768769 if (self.pending_calls.items.len > 0) {
769770 const call = self.pending_calls.orderedRemove(0);
770771 self.commitLines(&.{callBody(self.s, call.name, call.summary)});
@@ -773,7 +774,7 @@ const Tui = struct {
773774 const lines: []const stream.BodyLine = if (!is_error and body != null)
774775 &.{.{ .text = body.? }}
775776 else
776- resultLines(self.s, name, text, is_error);
777+ resultLines(self.s, name, shown, is_error);
777778 const rows = if (std.mem.eql(u8, name, "edit")) plainRows(self.s, lines) else bodyRows(self.s, lines, width);
778779 for (rows, 0..) |row, i| {
779780 const prefix = if (is_error and i == rows.len - 1) styles.red(self.s, ERROR_PREFIX) else styles.dim(self.s, BODY_PREFIX);