xonecas.io
64875
Mc

mini-coder / commit e3055c5

chore: benchmark prep, `--json` param, and folders

xonecas2026-04-24 e3055c5a6849bb4aab980570dcdebe29ac1e4e9f parent 4390963

14 files changed

AGENTS.md+6−6
@@ -1,13 +1,13 @@
11 # Mini coder next
22
33 A new version of mini-coder, written from the ground up as library first, plugins.
4-Version `mini-coder@0.5.x` is currently stable and mostly complete, thats our reference implementation.
4+Version `mini-coder@0.5.x` is currently stable and mostly complete, that's our reference implementation.
55 Benchmarking from the start, keep the agent dumb, build the plugin-library-first architecture, then
6-run a an automated benchmarking loop to shape/hone the harness.
6+run an automated benchmarking loop to shape/hone the harness.
77
88 ## Dog-fooding
99
10-Be aware that your are mini-coder, running the dev version of this repository while editing it.
10+Be aware that you are mini-coder, running the dev version of this repository while editing it.
1111 We are dog-fooding the code: changes to prompts, tools, context building, streaming, or runtime behavior may affect the agent we are actively using during the same development session.
1212
1313 ## Core dependencies
@@ -16,7 +16,7 @@ We are dog-fooding the code: changes to prompts, tools, context building, stream
1616
1717 Plain text readme file: https://raw.githubusercontent.com/badlogic/pi-mono/refs/heads/main/packages/ai/README.md
1818
19-- Provider nomrmalized api, supports oauth logins.
19+- Provider normalized API, supports oauth logins.
2020
2121 **https://github.com/sacenox/cel-tui**
2222
@@ -24,7 +24,7 @@ Plain text readme file: https://raw.githubusercontent.com/badlogic/pi-mono/refs/
2424
2525 **Bun.js**
2626
27-- `bun` and `bunx` are prefered over their node/npm/yarn/pnpm counter-parts.
27+- `bun` and `bunx` are preferred over their node/npm/yarn/pnpm counterparts.
2828
2929 **Typescript**
3030
@@ -37,7 +37,7 @@ Plain text readme file: https://raw.githubusercontent.com/badlogic/pi-mono/refs/
3737 - Please see `BENCHMARK.md` for Terminal Bench benchmark info, and how to run it.
3838 - Never run more than 2 concurrent evals.
3939
40-## Formating and linting
40+## Formatting and linting
4141
4242 **Always format before linting**
4343
BENCHMARK.md+2−2
@@ -2,7 +2,7 @@
22
33 Harbor is installed in this system with `pipx harbor`.
44 You will need to create a custom agent for your implementation.
5-keep the benchmark jobs in `benchmark-jobs/*` folder at the root of the repo.
5+keep the benchmark jobs in `benchmarks/jobs/*` folder at the root of the repo.
66 Never run harbor evals with more than 2 concurrent evals, be aware of rate limits.
77
88 ---
@@ -30,7 +30,7 @@ harbor run \
3030
3131 ## Testing your own agent
3232
33-See our docs on [agents](/docs/agents) (pasted bellow) for more information on how to test your own agent on Terminal-Bench.
33+See our docs on [agents](/docs/agents) (pasted below) for more information on how to test your own agent on Terminal-Bench.
3434
3535 ## Submitting to the Terminal-Bench leaderboard
3636
benchmarks/local-harbor-agent.py+2−0
@@ -0,0 +1,2 @@
1+# TODO: Implement the harbor agent that runs the local checkout of mini-coder
2+# Use the current environments auth from `~/.config/mini-coder/auth.json`
bun.lock+3−0
@@ -8,6 +8,7 @@
88 "@cel-tui/components": "^0.8.1",
99 "@cel-tui/core": "^0.8.1",
1010 "@mariozechner/pi-ai": "^0.70.0",
11+ "diff": "^9.0.0",
1112 "yaml": "^2.8.3",
1213 },
1314 "devDependencies": {
@@ -269,6 +270,8 @@
269270
270271 "degenerator": ["degenerator@5.0.1", "", { "dependencies": { "ast-types": "^0.13.4", "escodegen": "^2.1.0", "esprima": "^4.0.1" } }, "sha512-TllpMR/t0M5sqCXfj85i4XaAzxmS5tVA16dqvdkMwGmzI+dXLXnw3J+3Vdv7VKw+ThlTMboK6i9rnZ6Nntj5CQ=="],
271272
273+ "diff": ["diff@9.0.0", "", {}, "sha512-svtcdpS8CgJyqAjEQIXdb3OjhFVVYjzGAPO8WGCmRbrml64SPw/jJD4GoE98aR7r25A0XcgrK3F02yw9R/vhQw=="],
274+
272275 "ecdsa-sig-formatter": ["ecdsa-sig-formatter@1.0.11", "", { "dependencies": { "safe-buffer": "^5.0.1" } }, "sha512-nagl3RYrbNv6kQkeJIpt6NJZy8twLB/2vtz6yN9Z4vRKHN4/QZJIEbqohALSgwKdnksuY3k5Addp5lg8sVoVcQ=="],
273276
274277 "escodegen": ["escodegen@2.1.0", "", { "dependencies": { "esprima": "^4.0.1", "estraverse": "^5.2.0", "esutils": "^2.0.2" }, "optionalDependencies": { "source-map": "~0.6.1" }, "bin": { "esgenerate": "bin/esgenerate.js", "escodegen": "bin/escodegen.js" } }, "sha512-2NlIDTwUWJN0mRPQOdtQBzbUHvdGY2P1VXSyU83Q3xKxM7WHX2Ql8dKq782Q9TgQUNOLEzEYu9bzLNj1q88I5w=="],
package.json+2−1
@@ -11,7 +11,7 @@
1111 "check": "bun run lint && bun run typecheck",
1212 "lint": "bun run biome check --write .",
1313 "typecheck": "bun run tsc -p tsconfig.json --noEmit",
14- "format": "bun run prettier --write *.md && bun run biome format --write ."
14+ "format": "bun run prettier --write *.md && bun run biome format --write . && bun run biome check --write ."
1515 },
1616 "devDependencies": {
1717 "@biomejs/biome": "^2.4.12",
@@ -23,6 +23,7 @@
2323 "@cel-tui/components": "^0.8.1",
2424 "@cel-tui/core": "^0.8.1",
2525 "@mariozechner/pi-ai": "^0.70.0",
26+ "diff": "^9.0.0",
2627 "yaml": "^2.8.3"
2728 }
2829 }
src/agent.ts+7−5
@@ -17,14 +17,16 @@ export const TASK_PROMPT = `# You are "mini-coder", an elite coding agent.
1717
1818 Behaviour guidelines:
1919
20-- Answer all user questions without guessing, or assuming. Use recent online information and your training data combined for a complete answer.
21-- Once you've gathered enough information to complete the request, stop exploring.
20+- Answer all user questions without guessing, or assuming.
21+- Use recent online information, the current environment, and your training data combined for a complete answer.
22+- Once you've gathered enough information to complete the request, stop exploring and complete the task.
2223 - When completing a task, ensure that you fulfill the contract **exactly**.
23-- Use temp directory for temp files, scripts or anything that doesn't match the requested ouput.
24+- Use temp directory for temp files, scripts or anything that doesn't match the requested output.
25+- Be careful with existing changes and destructive commands, they could be your user's changes.
2426 - Tone: use a jovial but motivated colleague persona. Be less verbose and more concise. You are working with software engineers, act appropriate, no fluff, only direct talk.
2527 `;
2628
27-// `AGENTS.md` support: find it in current folder (.AGENTS.md) and a global one. (`.agents/AGENTS.md`)
29+// `AGENTS.md` support: find it in current folder (./AGENTS.md) and a global one. (`.agents/AGENTS.md`)
2830 export async function getAGENTSFiles() {
2931 const content: string[] = [];
3032
@@ -45,7 +47,7 @@ export async function getAGENTSFiles() {
4547 return content.join("\n\n").trim();
4648 }
4749
48-// `SKILLS.md` discovery from [~.]/agents/skills/*/SKILL.md
50+// `SKILLS.md` discovery from [~|.]/agents/skills/*/SKILL.md
4951 export async function getSkills(): Promise<string> {
5052 let skillsBlock: string = "";
5153 const skillRoots = [
src/args.ts+6−2
@@ -16,10 +16,10 @@ function getModelConfig(modelName: string, provider: KnownProvider) {
1616 return model;
1717 }
1818
19-// TODO: For when the user set's thinking value.
19+// TODO: For when the user sets thinking value.
2020 // function _isThinkingLevel(value: string): value is ThinkingLevel {
2121 // const THINKING_LEVELS = ["low", "medium", "minimal", "high", "xhigh"]
22-// return (THINKING_LEVELS as readkonly string[]).includes(value);
22+// return (THINKING_LEVELS as readonly string[]).includes(value);
2323 // }
2424
2525 export async function handleArgv(argv: string[]): Promise<CliOptions> {
@@ -36,6 +36,10 @@ export async function handleArgv(argv: string[]): Promise<CliOptions> {
3636 options = { ...options, prompt: argv[i + 1] };
3737 }
3838
39+ if (flag === "--json" || flag === "-j") {
40+ options = { ...options, jsonOutput: true };
41+ }
42+
3943 if (flag === "--login" || flag === "-l") {
4044 await loginOAuth(argv[i + 1]);
4145 }
src/headless.ts+27−17
@@ -7,7 +7,7 @@ import type { CliOptions, ToolAndRunner } from "./types";
77
88 export async function streamHeadless(
99 options: CliOptions,
10- leave: (s: string) => void,
10+ leave: (s?: string) => void,
1111 ) {
1212 const lastTs = Date.now();
1313 const apiKey = await getApiKey(options);
@@ -19,8 +19,13 @@ export async function streamHeadless(
1919 { role: "user", content: options.prompt || "", timestamp: Date.now() },
2020 ];
2121
22- console.log("mini-coder headless");
23- console.log("-------------------");
22+ function log(msg: string) {
23+ if (options.jsonOutput) return;
24+ console.log(msg);
25+ }
26+
27+ log("mini-coder headless");
28+ log("-------------------");
2429
2530 await streamAgent(
2631 apiKey,
@@ -31,21 +36,19 @@ export async function streamHeadless(
3136 (ev) => {
3237 switch (ev.type) {
3338 case "text_start":
34- console.log("> Answering...");
39+ log("> Answering...");
3540 break;
3641 case "thinking_start":
37- console.log("> Thinking...");
42+ log("> Thinking...");
3843 break;
3944 case "toolcall_start":
40- console.log(`> Calling tool...`);
45+ log(`> Calling tool...`);
4146 break;
4247 case "toolcall_end":
43- console.log(
44- `> ${ev.toolCall.name}: ${ev.toolCall.arguments.command}`,
45- );
48+ log(`> ${ev.toolCall.name}: ${ev.toolCall.arguments.command}`);
4649 break;
4750 case "error":
48- console.log(`Error ${ev.reason}\n${ev.error.content}`);
51+ log(`Error ${ev.reason}\n${ev.error.content}`);
4952 break;
5053 }
5154 },
@@ -55,15 +58,22 @@ export async function streamHeadless(
5558 .filter((c) => c.type === "text")
5659 .map((c) => c.text)
5760 .join("\n");
58- console.log(`\n${text}`);
59- console.log(
60- `\nTotal tokens: ${msg.usage.input} in, ${msg.usage.output} out`,
61- );
62- console.log(`Cost: $${msg.usage.cost.total.toFixed(4)}`);
61+
62+ log(`\n${text}`);
63+ log(`\nTotal tokens: ${msg.usage.input} in, ${msg.usage.output} out`);
64+ log(`Cost: $${msg.usage.cost.total.toFixed(4)}`);
65+
66+ if (options.jsonOutput) {
67+ console.log(JSON.stringify(msg, null, 4));
68+ }
6369
6470 if (["stop", "error", "aborted"].includes(msg.stopReason)) {
65- console.log(`Reason for stopping: "${msg.stopReason}"`);
66- leave(`Done. Took ${(Date.now() - lastTs) / 1000}s`);
71+ log(`Reason for stopping: "${msg.stopReason}"`);
72+ leave(
73+ !options.jsonOutput
74+ ? `Done. Took ${(Date.now() - lastTs) / 1000}s`
75+ : undefined,
76+ );
6777 }
6878 },
6979 );
src/index.ts+5−5
@@ -3,14 +3,14 @@ import { streamHeadless } from "./headless.ts";
33 import { initTUI } from "./tui.ts";
44 import type { TUIActiveState, TUIState } from "./types.ts";
55
6-function leave(msg: string) {
7- console.log(msg);
8- process.exit(0);
9-}
10-
116 export async function main(): Promise<void> {
127 const options = await handleArgv(process.argv.slice(2));
138
9+ function leave(msg?: string) {
10+ if (msg) console.log(msg);
11+ process.exit(0);
12+ }
13+
1414 if (options.prompt) {
1515 await streamHeadless(options, leave);
1616 process.exit(0);
src/shared.ts+2−2
@@ -2,7 +2,7 @@ import { homedir } from "node:os";
22 import { join } from "node:path";
33 import { parseDocument } from "yaml";
44
5-// Mixed bag of helpers that can be shared accross the codebase
5+// Mixed bag of helpers that can be shared across the codebase
66
77 export const DATA_DIR = join(homedir(), ".config", "mini-coder");
88 export const AUTH_PATH = join(DATA_DIR, "auth.json");
@@ -77,7 +77,7 @@ export function takeTail<T>(arr: T[], x: number): T[] {
7777 return x <= 0 ? [] : arr.slice(-x);
7878 }
7979
80-export function extimateTokens(text: string): number {
80+export function estimateTokens(text: string): number {
8181 return Math.ceil(text.length / 4);
8282 }
8383
src/tool-bash.ts+4−4
@@ -1,7 +1,7 @@
11 import { type Tool, Type } from "@mariozechner/pi-ai";
22 import { secureRandomString } from "./shared";
33
4-const OUTPUT_TRESHOLD = 10000;
4+const OUTPUT_THRESHOLD = 10000;
55 const description = `## Bash CLI tool
66
77 Best practices using this tool:
@@ -63,13 +63,13 @@ ${stdout}`;
6363 // And add that to the truncation label for the agent to be able
6464 // to continue the read with scans. This is to protect context,
6565 // not a general read guard. The hint is for the agent, not the TUI
66- if (out.length > OUTPUT_TRESHOLD) {
66+ if (out.length > OUTPUT_THRESHOLD) {
6767 const key = `${Date.now()}-${secureRandomString(4)}`;
6868 const pathname = `/tmp/bash_result_${key}.txt`;
6969 await Bun.write(pathname, out);
70- out = `${out.substring(0, OUTPUT_TRESHOLD)}
70+ out = `${out.substring(0, OUTPUT_THRESHOLD)}
7171
72-Truncated at ${OUTPUT_TRESHOLD}. Full ouput at ${pathname}`;
72+Truncated at ${OUTPUT_THRESHOLD}. Full output at ${pathname}`;
7373 }
7474
7575 return out;
src/tool-edit.ts+7−4
@@ -1,10 +1,11 @@
11 import { isAbsolute, join } from "node:path";
22 import { type Tool, Type } from "@mariozechner/pi-ai";
3+import { createPatch } from "diff";
34
45 export const edit: Tool = {
56 name: `edit`,
67 description:
7- "This is your edit tool, use it to create or edit files safely. Always prefer this tool over bash editting methods.",
8+ "This is your edit tool, use it to create or edit files safely. Always prefer this tool over bash editing methods.",
89 parameters: Type.Object({
910 path: Type.String({
1011 description: "File path (absolute or relative to cwd)",
@@ -47,7 +48,7 @@ export async function runEditTool(args: Record<string, any>) {
4748 }
4849
4950 await Bun.write(file, args.newText);
50- return `File written: ${filePath}`;
51+ return `File written: ${filePath}\n\n${args.newText}`;
5152 }
5253
5354 if (!exists) {
@@ -62,7 +63,7 @@ export async function runEditTool(args: Record<string, any>) {
6263 }
6364
6465 if (matches.length > 1) {
65- return `Multiple matches found in ${filePath}: ${matches.length} matches`;
66+ return `Multiple matches found in ${filePath}: ${matches.length} matches, be more specific and try again`;
6667 }
6768
6869 const idx = matches[0];
@@ -72,5 +73,7 @@ export async function runEditTool(args: Record<string, any>) {
7273 content.slice(idx + args.oldText.length);
7374
7475 await file.write(updated);
75- return `Edited: ${filePath}`;
76+ const patch = createPatch(filePath, content, updated);
77+
78+ return `File edited: ${filePath}\n\n${patch}`;
7679 }
src/tui-state.ts+5−5
@@ -1,5 +1,5 @@
11 import type { ToolCall, ToolResultMessage } from "@mariozechner/pi-ai";
2-import { extimateTokens, secureRandomString, takeTail } from "./shared";
2+import { estimateTokens, secureRandomString, takeTail } from "./shared";
33 import type { TUIMessage } from "./types";
44
55 // Create the TUIState message for context tool call and result.
@@ -32,8 +32,8 @@ export function createTUIToolMessage(
3232
3333 // Now the similar cut is needed in arguments, but here we care about
3434 // seeing the start of the command, like `cd bla/ && cat ...`
35- const argsMaxLength = 100 * showLines; // estimaded by 100 char line width times X lines.
36- let args = existing?.header ?? "Writting...";
35+ const argsMaxLength = 100 * showLines; // estimated by 100 char line width times X lines.
36+ let args = existing?.header ?? "Writing...";
3737
3838 // Shell tool call
3939 if ("arguments" in source && "command" in source.arguments) {
@@ -47,10 +47,10 @@ export function createTUIToolMessage(
4747 if ("arguments" in source && "path" in source.arguments) {
4848 const before = source.arguments.oldText;
4949 const after = source.arguments.newText;
50- const tokensWritten = extimateTokens(
50+ const tokensWritten = estimateTokens(
5151 [source.arguments.path, before, after].join(""),
5252 );
53- args = `Wrote ~${tokensWritten}t`;
53+ args = `Wrote ~${tokensWritten} tokens.`;
5454 }
5555
5656 const msg: TUIMessage = {
src/types.ts+2−1
@@ -2,9 +2,10 @@ import type { Context, Model, ThinkingLevel, Tool } from "@mariozechner/pi-ai";
22 import type { OAuthCredentials } from "@mariozechner/pi-ai/oauth";
33
44 export type CliOptions = {
5- prompt?: string;
65 model: Model<never>;
76 effort: ThinkingLevel;
7+ prompt?: string;
8+ jsonOutput?: boolean;
89 };
910
1011 export type TUIActiveState = "idle" | "thinking" | "answering" | "calling_tool";