xonecas.io
64875
Mc

mini-coder / commit 742f1db

fix: Use Bun.spawn instead of bun shell

xonecas2026-04-22 742f1db9123131cd356b28b68fb1339d366d072d parent 5215d1b

1 file changed

src/headless.ts+20−12
@@ -1,7 +1,6 @@
11 import { complete, Context, stream, Tool, Type } from "@mariozechner/pi-ai";
22 import { getApiKey } from "./oauth";
33 import type { CliOptions } from "./types";
4-import { $ } from "bun";
54
65 export async function streamHeadless(
76 options: CliOptions,
@@ -11,9 +10,9 @@ export async function streamHeadless(
1110
1211 const tools: Tool[] = [
1312 {
14- name: "shell",
13+ name: "bash",
1514 description:
16- "This is your command line, and uses the installed shell in your user's environment.",
15+ "This is your command line, runs commands in your user's environment.",
1716 parameters: Type.Object({
1817 command: Type.String({
1918 description:
@@ -33,16 +32,18 @@ export async function streamHeadless(
3332 tools,
3433 };
3534
35+ console.log("mini-coder headless");
36+ console.log("-------------------");
37+
3638 while (true) {
3739 const s = stream(options.model, context, {
3840 apiKey,
3941 reasoning: options.effort,
4042 });
43+
4144 for await (const ev of s) {
4245 switch (ev.type) {
4346 case "text_start":
44- console.log("mini-coder headless");
45- console.log("-------------------");
4647 console.log("Answering...");
4748 break;
4849 case "thinking_start":
@@ -52,7 +53,9 @@ export async function streamHeadless(
5253 console.log(`Calling tool...`);
5354 break;
5455 case "toolcall_end":
55- console.log(`${ev.toolCall.name}:\n${ev.toolCall.arguments}`);
56+ console.log(
57+ `${ev.toolCall.name}:\n\t${ev.toolCall.arguments.command}`,
58+ );
5659 break;
5760 case "error":
5861 console.log(`Error ${ev.error}`);
@@ -62,13 +65,18 @@ export async function streamHeadless(
6265
6366 const finalMessage = await s.result();
6467 context.messages.push(finalMessage);
65- console.log(
66- finalMessage.content.map((m) => m.type === "text" && m.text).join("\n"),
67- );
68+ const finalContent = finalMessage.content
69+ .map((m) => m.type === "text" && m.text)
70+ .filter((m) => Boolean(m));
71+
72+ if (finalContent.length > 0) console.log(finalContent.join("\n"));
6873
6974 const toolCalls = finalMessage.content.filter((b) => b.type === "toolCall");
7075 for (const call of toolCalls) {
71- const result = (await $`${call.arguments}`).text();
76+ const proc = Bun.spawn(["bash", "-c", call.arguments.command]);
77+ await proc.exited;
78+ const result = await proc.stdout.text();
79+
7280 context.messages.push({
7381 role: "toolResult",
7482 toolCallId: call.id,
@@ -90,8 +98,8 @@ export async function streamHeadless(
9098 console.log(`Cost: $${finalMessage.usage.cost.total.toFixed(4)}`);
9199
92100 if (["stop", "error", "aborted"].includes(finalMessage.stopReason)) {
93- console.log(`Reason for stopping: "${finalMessage.stopReason}"`)
94- const dur = Date.now() - context.messages[0].timestamp
101+ console.log(`Reason for stopping: "${finalMessage.stopReason}"`);
102+ const dur = Date.now() - context.messages[0].timestamp;
95103 leave(`Done. Took ${dur / 1000}s`);
96104 }
97105 }