xonecas.io
79113
Ma

mini-coding-agent / commit 79078d2

fix: timeout in bash, minor improvements to the TUI

xonecas2026-10-05 79078d256f5f40db27f6158496af6d1404c5f37b parent 02d44f3

7 files changed

AGENTS.md+3−13
@@ -48,7 +48,8 @@ Hard constraints. Do not cross these without explicit direction:
4848 - **No sandbox or permission layer.** Tools run with the user's permissions;
4949 isolation is an environment concern, not the agent's.
5050 - **No loop limits.** No max turns, tool calls, token budgets, or agent-imposed
51- timeouts. The user's ability to interrupt is the limit.
51+ timeouts (except for bash tool, agents are prone to running bad commands this is
52+ guard against it). The user's ability to interrupt is the limit.
5253 - **Config-first.** Every user-facing behavior that can vary comes from config
5354 with a sane default. Global config only — no project-local config; a
5455 `-c`/`--config` file overrides the global one for a run — and never duplicate
@@ -106,18 +107,7 @@ endpoints, or replay files**; they stall and prove nothing. Use the
106107 `OPENCODE_API_KEY` environment variable and a scratch `XDG_CONFIG_HOME` with a
107108 `mini-coding-agent/config.json` that declares the provider under test.
108109
109-OpenCode Zen serves all four wire protocols. Base URLs and the working models:
110-
111-- `openai-completions` — base `https://opencode.ai/zen/go/v1`, model
112- `deepseek-v4.1-flash` (the daily path, also `opencode-go` in the config).
113-- `openai-responses` — base `https://opencode.ai/zen/go/v1`, model
114- `gpt-6-luna`.
115-- `anthropic-messages` — base `https://opencode.ai/zen`, model
116- `claude-haiku-4-5`.
117-- `google-generative-ai` — base `https://opencode.ai/zen/v1`, model
118- `gemini-3.8-flash`.
119-
120-Every Zen request needs the `x-opencode-session` header; set it via the custom
110+Every Zen/Go request needs the `x-opencode-session` header; set it via the custom
121111 provider's `headers`. Not every catalog model is enabled for the account (for
122112 example `claude-opus-5` is disabled and returns `Model access is disabled`), so
123113 use the models above. Run a real tool call, not just a text turn.
src/agent.zig+2−0
@@ -61,6 +61,8 @@ pub const Options = struct {
6161 a: std.mem.Allocator,
6262 model: ?*const types.Model,
6363 system_prompt: []const u8,
64+ /// Counts of the discovered files in the system prompt.
65+ loaded: struct { agent_files: usize = 0, skills: usize = 0 } = .{},
6466 tools_json: []const u8,
6567 supports_images: bool,
6668 session: *session.Session,
src/main.zig+3−1
@@ -153,10 +153,12 @@ fn run() !u8 {
153153 } else null;
154154
155155 const supports_images = if (model_ptr) |m| m.supports_images else false;
156+ const built = try prompt.buildSystemPrompt(a, &cfg);
156157 const opts = agent.Options{
157158 .a = a,
158159 .model = model_ptr,
159- .system_prompt = try prompt.buildSystemPrompt(a, &cfg),
160+ .system_prompt = built.prompt,
161+ .loaded = .{ .agent_files = built.loaded.agent_files, .skills = built.loaded.skills },
160162 .tools_json = tools.json(a, cfg.tools, supports_images),
161163 .supports_images = supports_images,
162164 .session = &sess,
src/prompt.zig+13−3
@@ -65,15 +65,23 @@ fn agentFiles(a: std.mem.Allocator) ![]const []const u8 {
6565 return found.items;
6666 }
6767
68+/// How many discovered files made it into the system prompt.
69+pub const Loaded = struct { agent_files: usize = 0, skills: usize = 0 };
70+
71+/// The system prompt and the counts of the files that fed it.
72+pub const Built = struct { prompt: []const u8, loaded: Loaded };
73+
6874 /// Builds the system prompt from the config. The result lives for the process.
69-pub fn buildSystemPrompt(a: std.mem.Allocator, cfg: *const config.Config) ![]const u8 {
75+pub fn buildSystemPrompt(a: std.mem.Allocator, cfg: *const config.Config) !Built {
7076 var sections: std.ArrayList([]const u8) = .empty;
77+ var loaded: Loaded = .{};
7178
7279 const configured = std.mem.trim(u8, cfg.system_prompt, " \t\r\n");
7380 if (configured.len > 0) try sections.append(a, configured);
7481
7582 if (cfg.skills_dirs.len > 0) {
7683 const skills = try discoverSkills(a, cfg.skills_dirs);
84+ loaded.skills = skills.len;
7785 if (skills.len > 0) {
7886 var out: std.ArrayList(u8) = .empty;
7987 try out.appendSlice(a, "## Skills\n");
@@ -85,7 +93,9 @@ pub fn buildSystemPrompt(a: std.mem.Allocator, cfg: *const config.Config) ![]con
8593 }
8694
8795 if (cfg.discover_agent_files) {
88- for (try agentFiles(a)) |path| {
96+ const files = try agentFiles(a);
97+ loaded.agent_files = files.len;
98+ for (files) |path| {
8999 const text = try util.readFileAlloc(a, path, 1 << 24);
90100 try sections.append(a, try std.fmt.allocPrint(a, "## {s}\n\n{s}", .{
91101 path,
@@ -99,5 +109,5 @@ pub fn buildSystemPrompt(a: std.mem.Allocator, cfg: *const config.Config) ![]con
99109 if (i > 0) try joined.appendSlice(a, "\n\n");
100110 try joined.appendSlice(a, section);
101111 }
102- return joined.items;
112+ return .{ .prompt = joined.items, .loaded = loaded };
103113 }
src/tools/bash.zig+20−4
@@ -11,7 +11,9 @@ const max_head = 10_000;
1111 const max_tail = 6_000;
1212 const truncated_marker = "\n\n... output truncated ...\n\n";
1313
14-const Args = struct { command: []const u8 };
14+const default_timeout_s = 120;
15+
16+const Args = struct { command: []const u8, timeout: ?u64 = null };
1517
1618 const Acc = struct {
1719 a: std.mem.Allocator,
@@ -90,15 +92,27 @@ pub fn run(a: std.mem.Allocator, scratch: std.mem.Allocator, args_json: []const
9092 var cancelled = false;
9193 var broken = false;
9294 var oom = false;
95+ var timed_out = false;
96+
97+ const timeout_s = args.timeout orelse default_timeout_s;
98+ const start = std.Io.Clock.awake.now(platform.io);
99+ const deadline = start.addDuration(.fromSeconds(@intCast(@min(timeout_s, std.math.maxInt(i64)))));
93100
94101 while (open[0] or open[1]) {
95102 if (ctx.cancel.load(.acquire)) {
96103 cancelled = true;
97104 break;
98105 }
106+ const now = std.Io.Clock.awake.now(platform.io);
107+ if (now.durationTo(deadline).nanoseconds <= 0) {
108+ timed_out = true;
109+ break;
110+ }
111+ const remaining = now.durationTo(deadline).toMilliseconds();
112+ const wait_ms: i32 = @intCast(@min(100, @max(1, remaining)));
99113 // A poll failure must not leave the command running: the tool returns
100114 // at once, so nothing would ever collect it or its process group.
101- const ready = std.posix.poll(&fds, 100) catch {
115+ const ready = std.posix.poll(&fds, wait_ms) catch {
102116 broken = true;
103117 break;
104118 };
@@ -129,7 +143,7 @@ pub fn run(a: std.mem.Allocator, scratch: std.mem.Allocator, args_json: []const
129143 if (oom) break;
130144 }
131145
132- if (cancelled or oom or broken) killGroup(pid);
146+ if (cancelled or timed_out or oom or broken) killGroup(pid);
133147 const term = child.wait(platform.io) catch std.process.Child.Term{ .unknown = 0 };
134148
135149 if (oom) return fail(a, "bash failed: out of memory", .{});
@@ -141,7 +155,9 @@ pub fn run(a: std.mem.Allocator, scratch: std.mem.Allocator, args_json: []const
141155 .exited => |c| c,
142156 else => null,
143157 };
144- const label: []const u8 = if (code) |c|
158+ const label: []const u8 = if (timed_out)
159+ std.fmt.allocPrint(scratch, "timed out after {d}s", .{timeout_s}) catch "timed out"
160+ else if (code) |c|
145161 std.fmt.allocPrint(scratch, "{d}", .{c}) catch "unknown"
146162 else if (cancelled)
147163 "aborted"
src/tools/index.zig+1−1
@@ -20,7 +20,7 @@ const edit_params =
2020 ;
2121
2222 const bash_params =
23- \\{"type":"object","required":["command"],"properties":{"command":{"type":"string","description":"Command to run"}},"additionalProperties":false}
23+ \\{"type":"object","required":["command"],"properties":{"command":{"type":"string","description":"Command to run"},"timeout":{"type":"integer","description":"Timeout in seconds; defaults to 120"}},"additionalProperties":false}
2424 ;
2525
2626 const read_description = "Read a file. Returns its text. Returns the whole file unless offset and range give a line window. Prefer bash for search or binary files.";
src/tui/tui.zig+7−1
@@ -485,6 +485,10 @@ const Tui = struct {
485485 std.fmt.allocPrint(self.s, "mini · {s}/{s} · {s}", .{ m.provider, m.id, m.effort }) catch "mini"
486486 else
487487 "mini · no model configured");
488+ const loaded = self.opts.loaded;
489+ self.push(std.fmt.allocPrint(self.s, "{d} agent files · {d} skills", .{
490+ loaded.agent_files, loaded.skills,
491+ }) catch "resources");
488492 self.separator = true;
489493 }
490494
@@ -798,7 +802,9 @@ const Tui = struct {
798802 .help => self.showHelp(),
799803 .new => {
800804 self.newSession();
801- self.note("new session");
805+ self.push("");
806+ self.pushBanner();
807+ self.note(styles.dim(self.s, "new session"));
802808 },
803809 .provider => self.startProviderSelect(),
804810 .model => {