xonecas.io
64875
Mc

mini-coder / commit 6643abe

style: reformat codebase with prettier and clean up stale files

- Reformat all source files from tabs to spaces (prettier)
- Add .prettierignore
- Remove stale files: CLAUDE.md, cli-helpers, commands-config,
  config-conflicts, git-branch-cache, ui-audit test, runtime/script
- Minor doc updates to AGENTS.md, SHARE.md, TODO.md, mini-coder-idea.md

xonecas2026-03-20 6643abeddf23a73eb8ffa2e97848db1732183630 parent 670d7e4

142 files changed

This diff is too big to show in full. The first 1000 lines are below, and every file is listed with its counts.

.agents/skills/mini-coder/SKILL.md+1−1
@@ -204,4 +204,4 @@ mc -m zen/claude-sonnet-4-6
204204 mc --cwd ~/src/my-project
205205 ```
206206
207-If a user asks how to do something in mini-coder, answer in terms of the `mc` CLI and its interactive commands.
207+If a user asks how to do something in mini-coder, answer in terms of the `mc` CLI and its interactive commands.
.prettierignore+7−0
@@ -0,0 +1,7 @@
1+node_modules/
2+dist/
3+*.db
4+*.db-shm
5+*.db-wal
6+bun.lock
7+package-lock.json
AGENTS.md+3−1
@@ -1,7 +1,7 @@
11 # Mini Coder repo for agents:
22
33 - App data folder is in `~/.config/mini-coder/`. It includes sqlite db file and logs.
4-- Core idea is in [mini-coder-idea.md](mini-coder-idea.md). This file is managed by the user, don't edit unless asked to by the user. Treat this as the source of truth for the design/implementation.
4+- Core idea is in [mini-coder-idea.md](mini-coder-idea.md); READ IT. This file is managed by the user, don't edit unless asked to by the user. Treat this as the source of truth for the design/implementation.
55 - README.md is cosmetic for users, don't edit unless asked to.
66 - Write minimal tests, focused on our code's logic. Never test dependencies. Never use mocks or stubs.
77 - Keep the repo pristine: no failing tests, no lint, no build issues, no `ignore`-style comments. No failing hooks.
@@ -9,6 +9,8 @@
99 - Use `bun run format` to fix formatting issues.
1010 - We care about performance.
1111 - Do not inline `import` calls. Don't duplicate code. Don't leave dead code behind.
12+- Don't re-implement helpers/functionality that already exists, always consolidate.
13+- Don't add complexity for backwards compatibility, it's preferable to break compatibility and keep the code simple.
1214 - Don't make random test files, if you need to test something, write a propper unit test.
1315 - If you make temp files, clean them up when you are done.
1416 - Use Conventional Commits formatting for commit messages. When you commit, include the whole diff unless told otherwise.
CLAUDE.md+0−1
@@ -1 +0,0 @@
1-Read and follow the instructions in [AGENTS.md](AGENTS.md).
SHARE.md+1−1
@@ -18,4 +18,4 @@ mc
1818
1919 No telemetry. No cloud accounts. No bloat.
2020
21-🔗 https://github.com/sacenox/mini-coder
21+🔗 https://github.com/sacenox/mini-coder
TODO.md+2−2
@@ -1,10 +1,10 @@
11 # TODO
22
3-- When a shell tool call hits max timeout, the turn ends and the parent terminal is left in a broken state.
3+- Several truncation helpers accross the cli module files, consolidate in a cli/truncate.ts for rendering truncation.
44 - CTRL+d hangs sometimes and doesn't exit.
5+- When a shell tool call hits max timeout, the turn ends and the parent terminal is left in a broken state.
56 - **MiniMax empty lines in one-shot** — Investigate empty text deltas. May need to skip rendering deltas that are only whitespace at stream start.
67 - **Double prompt glyph after ESC** — The `turn-complete` handler writes a newline when `!renderedVisibleOutput`, then the input loop also writes its prompt. May need coordination to avoid the double prompt.
7-
88 - **No conversation summary on max context** — The idea says "Stops with a conversation summary if max context is reached." Currently shows an error and suggests `/new` without generating a summary of the conversation.
99
1010 ---
biome.json+58−58
@@ -1,60 +1,60 @@
11 {
2- "$schema": "https://biomejs.dev/schemas/2.4.6/schema.json",
3- "vcs": {
4- "enabled": true,
5- "clientKind": "git",
6- "useIgnoreFile": true
7- },
8- "formatter": {
9- "enabled": true
10- },
11- "assist": {
12- "enabled": true,
13- "actions": {
14- "source": {
15- "organizeImports": "on"
16- }
17- }
18- },
19- "linter": {
20- "enabled": true,
21- "domains": {
22- "test": "all"
23- },
24- "rules": {
25- "recommended": true,
26- "style": {
27- "noNonNullAssertion": "error",
28- "noParameterAssign": "error",
29- "noShoutyConstants": "error",
30- "noEnum": "error",
31- "noNestedTernary": "error",
32- "useConst": "error",
33- "useCollapsedIf": "error",
34- "useThrowNewError": "error",
35- "useThrowOnlyError": "error",
36- "useNumberNamespace": "error",
37- "useAtIndex": "error"
38- },
39- "complexity": {
40- "noUselessCatch": "error",
41- "noUselessStringConcat": "error",
42- "noForEach": "error"
43- },
44- "suspicious": {
45- "noDebugger": "error",
46- "noExplicitAny": "error",
47- "noConsole": "error",
48- "noEvolvingTypes": "error"
49- },
50- "correctness": {
51- "noUnusedVariables": "error",
52- "noUnusedImports": "error",
53- "noUndeclaredVariables": "error"
54- }
55- }
56- },
57- "javascript": {
58- "globals": ["Bun", "Timer"]
59- }
2+ "$schema": "https://biomejs.dev/schemas/2.4.6/schema.json",
3+ "vcs": {
4+ "enabled": true,
5+ "clientKind": "git",
6+ "useIgnoreFile": true
7+ },
8+ "formatter": {
9+ "enabled": false
10+ },
11+ "assist": {
12+ "enabled": true,
13+ "actions": {
14+ "source": {
15+ "organizeImports": "on"
16+ }
17+ }
18+ },
19+ "linter": {
20+ "enabled": true,
21+ "domains": {
22+ "test": "all"
23+ },
24+ "rules": {
25+ "recommended": true,
26+ "style": {
27+ "noNonNullAssertion": "error",
28+ "noParameterAssign": "error",
29+ "noShoutyConstants": "error",
30+ "noEnum": "error",
31+ "noNestedTernary": "error",
32+ "useConst": "error",
33+ "useCollapsedIf": "error",
34+ "useThrowNewError": "error",
35+ "useThrowOnlyError": "error",
36+ "useNumberNamespace": "error",
37+ "useAtIndex": "error"
38+ },
39+ "complexity": {
40+ "noUselessCatch": "error",
41+ "noUselessStringConcat": "error",
42+ "noForEach": "error"
43+ },
44+ "suspicious": {
45+ "noDebugger": "error",
46+ "noExplicitAny": "error",
47+ "noConsole": "error",
48+ "noEvolvingTypes": "error"
49+ },
50+ "correctness": {
51+ "noUnusedVariables": "error",
52+ "noUnusedImports": "error",
53+ "noUndeclaredVariables": "error"
54+ }
55+ }
56+ },
57+ "javascript": {
58+ "globals": ["Bun", "Timer"]
59+ }
6060 }
docs/mini-coder.1.md+15−15
@@ -6,7 +6,7 @@
66
77 ## SYNOPSIS
88
9-`mc` \[*options*\] \[*prompt*\]
9+`mc` \[_options_\] \[_prompt_\]
1010
1111 ## DESCRIPTION
1212
@@ -14,25 +14,25 @@ Developer-focused CLI coding agent. Prioritizes dev flow — no slow startup, no
1414
1515 ## OPTIONS
1616
17-`-m`, `--model` *id*
17+`-m`, `--model` _id_
1818 : Model to use (e.g. `zen/claude-sonnet-4-6`).
1919
2020 `-c`, `--continue`
2121 : Continue most recent session.
2222
23-`-r`, `--resume` *id*
23+`-r`, `--resume` _id_
2424 : Resume a specific session.
2525
2626 `-l`, `--list`
2727 : List recent sessions.
2828
29-`--cwd` *path*
29+`--cwd` _path_
3030 : Set working directory.
3131
3232 `-h`, `--help`
3333 : Display help.
3434
35-*prompt*
35+_prompt_
3636 : Optional one-shot prompt. Runs once then exits.
3737
3838 ## INTERACTIVE COMMANDS
@@ -40,13 +40,13 @@ Developer-focused CLI coding agent. Prioritizes dev flow — no slow startup, no
4040 `/model`
4141 : List all available models.
4242
43-`/model` *id*
43+`/model` _id_
4444 : Switch model.
4545
46-`/model effort` *low|medium|high|xhigh|off*
46+`/model effort` _low|medium|high|xhigh|off_
4747 : Set reasoning effort.
4848
49-`/session` \[*id*\]
49+`/session` \[_id_\]
5050 : List sessions or switch to one.
5151
5252 `/new`
@@ -55,22 +55,22 @@ Developer-focused CLI coding agent. Prioritizes dev flow — no slow startup, no
5555 `/undo`
5656 : Remove last turn (does NOT revert filesystem).
5757
58-`/reasoning` \[*on|off*\]
58+`/reasoning` \[_on|off_\]
5959 : Toggle reasoning display.
6060
61-`/verbose` \[*on|off*\]
61+`/verbose` \[_on|off_\]
6262 : Toggle output truncation.
6363
6464 `/mcp list`
6565 : List MCP servers.
6666
67-`/mcp add` *name* `http` *url*
67+`/mcp add` _name_ `http` _url_
6868 : Add HTTP MCP server.
6969
70-`/mcp add` *name* `stdio` *cmd* \[*args...*\]
70+`/mcp add` _name_ `stdio` _cmd_ \[_args..._\]
7171 : Add stdio MCP server.
7272
73-`/mcp remove` *name*
73+`/mcp remove` _name_
7474 : Remove MCP server.
7575
7676 `/review`
@@ -79,10 +79,10 @@ Developer-focused CLI coding agent. Prioritizes dev flow — no slow startup, no
7979 `/login`
8080 : Show OAuth login status.
8181
82-`/login` *provider*
82+`/login` _provider_
8383 : Login via OAuth (opens browser for device flow). Currently supports `anthropic`.
8484
85-`/logout` *provider*
85+`/logout` _provider_
8686 : Clear saved OAuth tokens.
8787
8888 `/help`
lefthook.yml+2−13
@@ -1,15 +1,4 @@
11 pre-commit:
2- parallel: true
32 commands:
4- jscpd:
5- run: bun run jscpd
6- knip:
7- run: bun run knip
8- typecheck:
9- run: bun run typecheck
10- format:
11- run: bun run format
12- lint:
13- run: bun run lint
14- test:
15- run: bun run test
3+ check:
4+ run: bun run check
mini-coder-idea.md+2−3
@@ -21,7 +21,7 @@ conventions and not introduce more specs.
2121
2222 ## Features:
2323
24-We want to do our best to support and autodiscover community config standards:
24+- We want to do our best to support and autodiscover community config standards:
2525 - AGENTS.md -> https://agents.md/
2626 - CLAUDE.md (same as AGENTS.md)
2727 - Skills -> https://agentskills.io/client-implementation/adding-skills-support (and https://agentskills.io/client-implementation/adding-skills-support.md)
@@ -59,14 +59,13 @@ We want to do our best to support and autodiscover community config standards:
5959 - Optional `webSearch` and `webContent` tools when `EXA_API_KEY` is set.
6060 - Cross model system prompt with clear descriptions of the expected dev flow and guidance as a code agent focused on shell first.
6161
62--Other Commands in CLI prompt:
62+- Other Commands in CLI prompt:
6363 - `/reasoning` toggles display of model reasoning output.
6464 - `/verbose` toggles output truncation. Tuncates large outputs keeping start and end sections and truncating the rest when verbose is off. This controls truncation for the user output, it's a visibility UI concern
6565 - `/review` reviews recent changes via a global custom skill installed at app start (`~/.agents/skills/review.md`), and can be customized or shadowed locally.
6666
6767 - Connect to MCP servers over Streamable HTTP / SSE fallback or stdio.
6868 - `/mcp` list/add/remove mcp servers. servers are stored in sqlite
69-
7069
7170 ## UI/Output
7271
package.json+49−47
@@ -1,49 +1,51 @@
11 {
2- "name": "mini-coder",
3- "version": "0.2.0",
4- "description": "A small, fast CLI coding agent",
5- "module": "src/index.ts",
6- "type": "module",
7- "bin": {
8- "mc": "dist/mc.js",
9- "mc-edit": "dist/mc-edit.js"
10- },
11- "scripts": {
12- "build": "bun run scripts/build.ts",
13- "dev": "bun run src/index.ts",
14- "typecheck": "tsc --noEmit",
15- "lint": "biome check src",
16- "format": "biome check --write src",
17- "knip": "knip",
18- "test": "bun test --only-failures",
19- "test:verbose": "bun test",
20- "jscpd": "jscpd src",
21- "prepare": "lefthook install"
22- },
23- "dependencies": {
24- "@ai-sdk/anthropic": "^3.0.60",
25- "@ai-sdk/google": "^3.0.51",
26- "@ai-sdk/openai": "^3.0.45",
27- "@ai-sdk/openai-compatible": "^2.0.36",
28- "@modelcontextprotocol/sdk": "^1.27.1",
29- "ai": "^6.0.127",
30- "diff": "^8.0.3",
31- "yoctocolors": "^2.1.2",
32- "yoctomarkdown": "^0.0.7",
33- "zod": "^4.3.6"
34- },
35- "devDependencies": {
36- "@biomejs/biome": "^2.4.6",
37- "@types/bun": "latest",
38- "jscpd": "^4.0.8",
39- "knip": "^5.86.0",
40- "lefthook": "^2.1.4",
41- "typescript": "^5.9.3"
42- },
43- "knip": {
44- "entry": [
45- "src/mc-edit.ts"
46- ]
47- },
48- "license": "MIT"
2+ "name": "mini-coder",
3+ "version": "0.2.0",
4+ "description": "A small, fast CLI coding agent",
5+ "module": "src/index.ts",
6+ "type": "module",
7+ "bin": {
8+ "mc": "dist/mc.js",
9+ "mc-edit": "dist/mc-edit.js"
10+ },
11+ "scripts": {
12+ "prepare": "lefthook install",
13+ "build": "bun run scripts/build.ts",
14+ "dev": "bun run src/index.ts",
15+ "format": "prettier --write --log-level warn .",
16+ "check": "bun run prettier -c . && bun run typecheck && bun run lint && bun run knip && bun run jscpd && bun run test",
17+ "typecheck": "tsc --noEmit",
18+ "lint": "biome check src",
19+ "knip": "knip",
20+ "test": "bun test --only-failures",
21+ "test:verbose": "bun test",
22+ "jscpd": "jscpd -s src"
23+ },
24+ "dependencies": {
25+ "@ai-sdk/anthropic": "^3.0.60",
26+ "@ai-sdk/google": "^3.0.51",
27+ "@ai-sdk/openai": "^3.0.45",
28+ "@ai-sdk/openai-compatible": "^2.0.36",
29+ "@modelcontextprotocol/sdk": "^1.27.1",
30+ "ai": "^6.0.127",
31+ "diff": "^8.0.3",
32+ "yoctocolors": "^2.1.2",
33+ "yoctomarkdown": "^0.0.7",
34+ "zod": "^4.3.6"
35+ },
36+ "devDependencies": {
37+ "@biomejs/biome": "^2.4.6",
38+ "@types/bun": "latest",
39+ "jscpd": "^4.0.8",
40+ "knip": "^5.86.0",
41+ "lefthook": "^2.1.4",
42+ "prettier": "^3.8.1",
43+ "typescript": "^5.9.3"
44+ },
45+ "knip": {
46+ "entry": [
47+ "src/mc-edit.ts"
48+ ]
49+ },
50+ "license": "MIT"
4951 }
scripts/build.ts+16−16
@@ -1,23 +1,23 @@
11 import pkg from "../package.json";
22
33 async function buildEntrypoint(entrypoint: string, outputName: string) {
4- const result = await Bun.build({
5- entrypoints: [entrypoint],
6- target: "bun",
7- outdir: "dist",
8- naming: outputName,
9- packages: "external",
10- define: {
11- __PACKAGE_VERSION__: JSON.stringify(pkg.version),
12- },
13- });
4+ const result = await Bun.build({
5+ entrypoints: [entrypoint],
6+ target: "bun",
7+ outdir: "dist",
8+ naming: outputName,
9+ packages: "external",
10+ define: {
11+ __PACKAGE_VERSION__: JSON.stringify(pkg.version),
12+ },
13+ });
1414
15- if (!result.success) {
16- for (const log of result.logs) {
17- console.error(log);
18- }
19- process.exit(1);
20- }
15+ if (!result.success) {
16+ for (const log of result.logs) {
17+ console.error(log);
18+ }
19+ process.exit(1);
20+ }
2121 }
2222
2323 await buildEntrypoint("src/index.ts", "mc.js");
src/agent/agent-helpers.ts+36−36
@@ -1,56 +1,56 @@
11 import {
2- stripOpenAIHistoryTransforms,
3- stripToolRuntimeInputFields,
2+ stripOpenAIHistoryTransforms,
3+ stripToolRuntimeInputFields,
44 } from "../llm-api/history-transforms.ts";
55 import type { CoreMessage } from "../llm-api/turn.ts";
66
77 export function makeInterruptMessage(reason: "user" | "error"): CoreMessage {
8- const text =
9- reason === "user"
10- ? "<system-message>Response was interrupted by the user.</system-message>"
11- : "<system-message>Response was interrupted due to an error.</system-message>";
12- return { role: "assistant", content: text };
8+ const text =
9+ reason === "user"
10+ ? "<system-message>Response was interrupted by the user.</system-message>"
11+ : "<system-message>Response was interrupted due to an error.</system-message>";
12+ return { role: "assistant", content: text };
1313 }
1414
1515 export function isAbortError(error: Error): boolean {
16- return (
17- error.name === "AbortError" ||
18- (error.name === "Error" && error.message.toLowerCase().includes("abort"))
19- );
16+ return (
17+ error.name === "AbortError" ||
18+ (error.name === "Error" && error.message.toLowerCase().includes("abort"))
19+ );
2020 }
2121
2222 export function buildAbortMessages(
23- partialMessages: CoreMessage[],
24- accumulatedText?: string,
23+ partialMessages: CoreMessage[],
24+ accumulatedText?: string,
2525 ): CoreMessage[] {
26- const stub = makeInterruptMessage("user");
27- const content = accumulatedText
28- ? `${accumulatedText}${stub.content}`
29- : (stub.content as string);
30- const partialMsg: CoreMessage = { role: "assistant", content };
31- return [...partialMessages, partialMsg];
26+ const stub = makeInterruptMessage("user");
27+ const content = accumulatedText
28+ ? `${accumulatedText}${stub.content}`
29+ : (stub.content as string);
30+ const partialMsg: CoreMessage = { role: "assistant", content };
31+ return [...partialMessages, partialMsg];
3232 }
3333
3434 export function sanitizeModelAuthoredMessages(
35- newMessages: CoreMessage[],
36- modelString: string,
35+ newMessages: CoreMessage[],
36+ modelString: string,
3737 ): CoreMessage[] {
38- const strippedRuntimeFields = stripToolRuntimeInputFields(newMessages);
39- return stripOpenAIHistoryTransforms(strippedRuntimeFields, modelString);
38+ const strippedRuntimeFields = stripToolRuntimeInputFields(newMessages);
39+ return stripOpenAIHistoryTransforms(strippedRuntimeFields, modelString);
4040 }
4141
4242 export function extractAssistantText(newMessages: CoreMessage[]): string {
43- const parts: string[] = [];
44- for (const msg of newMessages) {
45- if (msg.role !== "assistant") continue;
46- const content = msg.content;
47- if (typeof content === "string") {
48- parts.push(content);
49- } else if (Array.isArray(content)) {
50- for (const part of content as Array<{ type?: string; text?: string }>) {
51- if (part?.type === "text" && part.text) parts.push(part.text);
52- }
53- }
54- }
55- return parts.join("\n");
43+ const parts: string[] = [];
44+ for (const msg of newMessages) {
45+ if (msg.role !== "assistant") continue;
46+ const content = msg.content;
47+ if (typeof content === "string") {
48+ parts.push(content);
49+ } else if (Array.isArray(content)) {
50+ for (const part of content as Array<{ type?: string; text?: string }>) {
51+ if (part?.type === "text" && part.text) parts.push(part.text);
52+ }
53+ }
54+ }
55+ return parts.join("\n");
5656 }
src/agent/agent.test.ts+163−163
@@ -1,180 +1,180 @@
11 import { describe, expect, test } from "bun:test";
22 import type { CoreMessage } from "../llm-api/turn.ts";
33 import {
4- extractAssistantText,
5- makeInterruptMessage,
6- sanitizeModelAuthoredMessages,
4+ extractAssistantText,
5+ makeInterruptMessage,
6+ sanitizeModelAuthoredMessages,
77 } from "./agent-helpers.ts";
88
99 // ─── extractAssistantText ─────────────────────────────────────────────────────
1010
1111 describe("extractAssistantText", () => {
12- test("returns empty string for empty message list", () => {
13- expect(extractAssistantText([])).toBe("");
14- });
15-
16- test("returns empty string when no assistant messages present", () => {
17- const msgs: CoreMessage[] = [{ role: "user", content: "hello" }];
18- expect(extractAssistantText(msgs)).toBe("");
19- });
20-
21- test("extracts string content from an assistant message", () => {
22- const msgs: CoreMessage[] = [{ role: "assistant", content: "All done." }];
23- expect(extractAssistantText(msgs)).toBe("All done.");
24- });
25-
26- test("extracts text parts from array content", () => {
27- const msgs: CoreMessage[] = [
28- {
29- role: "assistant",
30- content: [
31- { type: "text", text: "I will run the tests." },
32- { type: "tool-call", toolCallId: "1", toolName: "shell", input: {} },
33- ],
34- },
35- ];
36- expect(extractAssistantText(msgs)).toBe("I will run the tests.");
37- });
38-
39- test("concatenates text across multiple assistant messages", () => {
40- const msgs: CoreMessage[] = [
41- { role: "user", content: "go" },
42- { role: "assistant", content: "Fixing the bug." },
43- { role: "assistant", content: "All done." },
44- ];
45- expect(extractAssistantText(msgs)).toBe("Fixing the bug.\nAll done.");
46- });
47-
48- test("returns empty string when assistant message has no text parts", () => {
49- const msgs: CoreMessage[] = [
50- {
51- role: "assistant",
52- content: [
53- { type: "tool-call", toolCallId: "1", toolName: "shell", input: {} },
54- ],
55- },
56- ];
57- expect(extractAssistantText(msgs)).toBe("");
58- });
59-
60- test("extracts text from array content when last part is a tool call", () => {
61- const msgs: CoreMessage[] = [
62- {
63- role: "assistant",
64- content: [
65- { type: "text", text: "Tests pass." },
66- { type: "tool-call", toolCallId: "1", toolName: "shell", input: {} },
67- ],
68- },
69- ];
70- expect(extractAssistantText(msgs)).toBe("Tests pass.");
71- });
12+ test("returns empty string for empty message list", () => {
13+ expect(extractAssistantText([])).toBe("");
14+ });
15+
16+ test("returns empty string when no assistant messages present", () => {
17+ const msgs: CoreMessage[] = [{ role: "user", content: "hello" }];
18+ expect(extractAssistantText(msgs)).toBe("");
19+ });
20+
21+ test("extracts string content from an assistant message", () => {
22+ const msgs: CoreMessage[] = [{ role: "assistant", content: "All done." }];
23+ expect(extractAssistantText(msgs)).toBe("All done.");
24+ });
25+
26+ test("extracts text parts from array content", () => {
27+ const msgs: CoreMessage[] = [
28+ {
29+ role: "assistant",
30+ content: [
31+ { type: "text", text: "I will run the tests." },
32+ { type: "tool-call", toolCallId: "1", toolName: "shell", input: {} },
33+ ],
34+ },
35+ ];
36+ expect(extractAssistantText(msgs)).toBe("I will run the tests.");
37+ });
38+
39+ test("concatenates text across multiple assistant messages", () => {
40+ const msgs: CoreMessage[] = [
41+ { role: "user", content: "go" },
42+ { role: "assistant", content: "Fixing the bug." },
43+ { role: "assistant", content: "All done." },
44+ ];
45+ expect(extractAssistantText(msgs)).toBe("Fixing the bug.\nAll done.");
46+ });
47+
48+ test("returns empty string when assistant message has no text parts", () => {
49+ const msgs: CoreMessage[] = [
50+ {
51+ role: "assistant",
52+ content: [
53+ { type: "tool-call", toolCallId: "1", toolName: "shell", input: {} },
54+ ],
55+ },
56+ ];
57+ expect(extractAssistantText(msgs)).toBe("");
58+ });
59+
60+ test("extracts text from array content when last part is a tool call", () => {
61+ const msgs: CoreMessage[] = [
62+ {
63+ role: "assistant",
64+ content: [
65+ { type: "text", text: "Tests pass." },
66+ { type: "tool-call", toolCallId: "1", toolName: "shell", input: {} },
67+ ],
68+ },
69+ ];
70+ expect(extractAssistantText(msgs)).toBe("Tests pass.");
71+ });
7272 });
7373
7474 describe("sanitizeModelAuthoredMessages", () => {
75- test("strips GPT commentary parts before messages are reused or persisted", () => {
76- const msgs: CoreMessage[] = [
77- {
78- role: "assistant",
79- content: [
80- { type: "reasoning", text: "plan" },
81- {
82- type: "text",
83- text: "hidden commentary",
84- providerOptions: { openai: { phase: "commentary" } },
85- },
86- {
87- type: "text",
88- text: "final answer",
89- providerOptions: { openai: { phase: "final_answer" } },
90- },
91- ],
92- } as unknown as CoreMessage,
93- ];
94-
95- expect(sanitizeModelAuthoredMessages(msgs, "openai/gpt-5.3-codex")).toEqual(
96- [
97- {
98- role: "assistant",
99- content: [
100- { type: "reasoning", text: "plan" },
101- {
102- type: "text",
103- text: "final answer",
104- providerOptions: { openai: { phase: "final_answer" } },
105- },
106- ],
107- },
108- ],
109- );
110- });
111-
112- test("strips runtime-only tool fields from persisted tool calls", () => {
113- const msgs: CoreMessage[] = [
114- {
115- role: "assistant",
116- content: [
117- {
118- type: "tool-call",
119- toolCallId: "1",
120- toolName: "read",
121- input: {
122- path: "TODO.md",
123- cwd: "/tmp/project",
124- },
125- },
126- ],
127- } as unknown as CoreMessage,
128- ];
129-
130- expect(
131- sanitizeModelAuthoredMessages(msgs, "anthropic/claude-sonnet-4-5"),
132- ).toEqual([
133- {
134- role: "assistant",
135- content: [
136- {
137- type: "tool-call",
138- toolCallId: "1",
139- toolName: "read",
140- input: { path: "TODO.md" },
141- },
142- ],
143- },
144- ]);
145- });
75+ test("strips GPT commentary parts before messages are reused or persisted", () => {
76+ const msgs: CoreMessage[] = [
77+ {
78+ role: "assistant",
79+ content: [
80+ { type: "reasoning", text: "plan" },
81+ {
82+ type: "text",
83+ text: "hidden commentary",
84+ providerOptions: { openai: { phase: "commentary" } },
85+ },
86+ {
87+ type: "text",
88+ text: "final answer",
89+ providerOptions: { openai: { phase: "final_answer" } },
90+ },
91+ ],
92+ } as unknown as CoreMessage,
93+ ];
94+
95+ expect(sanitizeModelAuthoredMessages(msgs, "openai/gpt-5.3-codex")).toEqual(
96+ [
97+ {
98+ role: "assistant",
99+ content: [
100+ { type: "reasoning", text: "plan" },
101+ {
102+ type: "text",
103+ text: "final answer",
104+ providerOptions: { openai: { phase: "final_answer" } },
105+ },
106+ ],
107+ },
108+ ],
109+ );
110+ });
111+
112+ test("strips runtime-only tool fields from persisted tool calls", () => {
113+ const msgs: CoreMessage[] = [
114+ {
115+ role: "assistant",
116+ content: [
117+ {
118+ type: "tool-call",
119+ toolCallId: "1",
120+ toolName: "read",
121+ input: {
122+ path: "TODO.md",
123+ cwd: "/tmp/project",
124+ },
125+ },
126+ ],
127+ } as unknown as CoreMessage,
128+ ];
129+
130+ expect(
131+ sanitizeModelAuthoredMessages(msgs, "anthropic/claude-sonnet-4-5"),
132+ ).toEqual([
133+ {
134+ role: "assistant",
135+ content: [
136+ {
137+ type: "tool-call",
138+ toolCallId: "1",
139+ toolName: "read",
140+ input: { path: "TODO.md" },
141+ },
142+ ],
143+ },
144+ ]);
145+ });
146146 });
147147
148148 // ─── makeInterruptMessage ─────────────────────────────────────────────────────
149149
150150 describe("makeInterruptMessage", () => {
151- test("user reason produces an assistant role message", () => {
152- const msg = makeInterruptMessage("user");
153- expect(msg.role).toBe("assistant");
154- });
155-
156- test("error reason produces an assistant role message", () => {
157- const msg = makeInterruptMessage("error");
158- expect(msg.role).toBe("assistant");
159- });
160-
161- test("user reason content contains system-message tag", () => {
162- const msg = makeInterruptMessage("user");
163- expect(msg.content).toContain("<system-message>");
164- expect(msg.content).toContain("</system-message>");
165- expect(msg.content).toContain("interrupted by the user");
166- });
167-
168- test("error reason content contains system-message tag", () => {
169- const msg = makeInterruptMessage("error");
170- expect(msg.content).toContain("<system-message>");
171- expect(msg.content).toContain("</system-message>");
172- expect(msg.content).toContain("interrupted due to an error");
173- });
174-
175- test("user and error produce different messages", () => {
176- expect(makeInterruptMessage("user").content).not.toBe(
177- makeInterruptMessage("error").content,
178- );
179- });
151+ test("user reason produces an assistant role message", () => {
152+ const msg = makeInterruptMessage("user");
153+ expect(msg.role).toBe("assistant");
154+ });
155+
156+ test("error reason produces an assistant role message", () => {
157+ const msg = makeInterruptMessage("error");
158+ expect(msg.role).toBe("assistant");
159+ });
160+
161+ test("user reason content contains system-message tag", () => {
162+ const msg = makeInterruptMessage("user");
163+ expect(msg.content).toContain("<system-message>");
164+ expect(msg.content).toContain("</system-message>");
165+ expect(msg.content).toContain("interrupted by the user");
166+ });
167+
168+ test("error reason content contains system-message tag", () => {
169+ const msg = makeInterruptMessage("error");
170+ expect(msg.content).toContain("<system-message>");
171+ expect(msg.content).toContain("</system-message>");
172+ expect(msg.content).toContain("interrupted due to an error");
173+ });
174+
175+ test("user and error produce different messages", () => {
176+ expect(makeInterruptMessage("user").content).not.toBe(
177+ makeInterruptMessage("error").content,
178+ );
179+ });
180180 });
src/agent/agent.ts+91−94
@@ -4,113 +4,110 @@ import type { ThinkingEffort } from "../llm-api/providers.ts";
44 import type { ToolDef } from "../llm-api/types.ts";
55 import { connectMcpServer } from "../mcp/client.ts";
66 import {
7- listMcpServers,
8- setPreferredModel,
9- setPreferredShowReasoning,
10- setPreferredThinkingEffort,
11- setPreferredVerboseOutput,
7+ listMcpServers,
8+ setPreferredModel,
9+ setPreferredShowReasoning,
10+ setPreferredThinkingEffort,
11+ setPreferredVerboseOutput,
1212 } from "../session/db/index.ts";
1313 import type { AgentReporter } from "./reporter.ts";
1414 import { SessionRunner } from "./session-runner.ts";
1515 import { buildToolSet } from "./tools.ts";
1616
1717 interface AgentOptions {
18- model: string;
19- cwd: string;
20- initialThinkingEffort: ThinkingEffort | null;
21- initialShowReasoning: boolean;
22- initialVerboseOutput: boolean;
23- sessionId?: string;
24- reporter: AgentReporter;
18+ model: string;
19+ cwd: string;
20+ initialThinkingEffort: ThinkingEffort | null;
21+ initialShowReasoning: boolean;
22+ initialVerboseOutput: boolean;
23+ sessionId?: string;
24+ reporter: AgentReporter;
2525 }
2626
2727 export async function initAgent(opts: AgentOptions): Promise<{
28- runner: SessionRunner;
29- cmdCtx: CommandContext;
28+ runner: SessionRunner;
29+ cmdCtx: CommandContext;
3030 }> {
31- const cwd = opts.cwd;
31+ const cwd = opts.cwd;
32+ const tools: ToolDef[] = buildToolSet({ cwd });
33+ const mcpTools: ToolDef[] = [];
3234
33- const tools: ToolDef[] = buildToolSet({ cwd });
35+ async function connectAndAddMcp(name: string): Promise<void> {
36+ const rows = listMcpServers();
37+ const row = rows.find((r) => r.name === name);
38+ if (!row) throw new Error(`MCP server "${name}" not found in DB`);
39+ const cfg: Parameters<typeof connectMcpServer>[0] = {
40+ name: row.name,
41+ transport: row.transport as "http" | "stdio",
42+ ...(row.url ? { url: row.url } : {}),
43+ ...(row.command ? { command: row.command } : {}),
44+ ...(row.args ? { args: JSON.parse(row.args) } : {}),
45+ ...(row.env ? { env: JSON.parse(row.env) } : {}),
46+ };
47+ const client = await connectMcpServer(cfg);
48+ tools.push(...client.tools);
49+ mcpTools.push(...client.tools);
50+ }
3451
35- const mcpTools: ToolDef[] = [];
52+ for (const row of listMcpServers()) {
53+ try {
54+ await connectAndAddMcp(row.name);
55+ opts.reporter.info(`MCP: connected ${c.cyan(row.name)}`);
56+ } catch (e) {
57+ opts.reporter.error(`MCP: failed to connect ${row.name}: ${String(e)}`);
58+ }
59+ }
3660
37- async function connectAndAddMcp(name: string): Promise<void> {
38- const rows = listMcpServers();
39- const row = rows.find((r) => r.name === name);
40- if (!row) throw new Error(`MCP server "${name}" not found in DB`);
41- const cfg: Parameters<typeof connectMcpServer>[0] = {
42- name: row.name,
43- transport: row.transport as "http" | "stdio",
44- ...(row.url ? { url: row.url } : {}),
45- ...(row.command ? { command: row.command } : {}),
46- ...(row.args ? { args: JSON.parse(row.args) } : {}),
47- ...(row.env ? { env: JSON.parse(row.env) } : {}),
48- };
49- const client = await connectMcpServer(cfg);
50- tools.push(...client.tools);
51- mcpTools.push(...client.tools);
52- }
61+ const runner = new SessionRunner({
62+ cwd,
63+ reporter: opts.reporter,
64+ tools,
65+ mcpTools,
66+ initialModel: opts.model,
67+ initialThinkingEffort: opts.initialThinkingEffort,
68+ initialShowReasoning: opts.initialShowReasoning,
69+ initialVerboseOutput: opts.initialVerboseOutput,
70+ sessionId: opts.sessionId,
71+ });
5372
54- for (const row of listMcpServers()) {
55- try {
56- await connectAndAddMcp(row.name);
57- opts.reporter.info(`MCP: connected ${c.cyan(row.name)}`);
58- } catch (e) {
59- opts.reporter.error(`MCP: failed to connect ${row.name}: ${String(e)}`);
60- }
61- }
73+ const cmdCtx: CommandContext = {
Cut short: this commit's diff is over 1000 lines.
src/agent/reporter.ts+27−27
Cut short: this commit's diff is over 1000 lines.
src/agent/session-runner.ts+210−210
Cut short: this commit's diff is over 1000 lines.
src/agent/system-prompt.test.ts+177−177
Cut short: this commit's diff is over 1000 lines.
src/agent/system-prompt.ts+78−76
Cut short: this commit's diff is over 1000 lines.
src/agent/tools.test.ts+34−34
Cut short: this commit's diff is over 1000 lines.
src/agent/tools.ts+25−25
Cut short: this commit's diff is over 1000 lines.
src/agent/undo-turn.ts+17−17
Cut short: this commit's diff is over 1000 lines.
src/cli/args.ts+88−88
Cut short: this commit's diff is over 1000 lines.
src/cli/bootstrap.ts+9−9
Cut short: this commit's diff is over 1000 lines.
src/cli/cli-helpers.ts+0−15
Cut short: this commit's diff is over 1000 lines.
src/cli/commands-config.test.ts+0−54
Cut short: this commit's diff is over 1000 lines.
src/cli/commands-config.ts+0−58
Cut short: this commit's diff is over 1000 lines.
src/cli/commands-help.ts+50−50
Cut short: this commit's diff is over 1000 lines.
src/cli/commands-login.ts+103−103
Cut short: this commit's diff is over 1000 lines.
src/cli/commands-mcp.ts+99−99
Cut short: this commit's diff is over 1000 lines.
src/cli/commands-model.ts+162−162
Cut short: this commit's diff is over 1000 lines.
src/cli/commands-session.ts+20−20
Cut short: this commit's diff is over 1000 lines.
src/cli/commands.ts+210−174
Cut short: this commit's diff is over 1000 lines.
src/cli/completions.test.ts+55−55
Cut short: this commit's diff is over 1000 lines.
src/cli/completions.ts+91−91
Cut short: this commit's diff is over 1000 lines.
src/cli/config-conflicts.ts+0−25
Cut short: this commit's diff is over 1000 lines.
src/cli/error-log.ts+12−39
Cut short: this commit's diff is over 1000 lines.
src/cli/error-parse.test.ts+136−136
Cut short: this commit's diff is over 1000 lines.
src/cli/error-parse.ts+130−130
Cut short: this commit's diff is over 1000 lines.
src/cli/file-refs.test.ts+28−28
Cut short: this commit's diff is over 1000 lines.
src/cli/file-refs.ts+34−38
Cut short: this commit's diff is over 1000 lines.
src/cli/frontmatter.test.ts+39−39
Cut short: this commit's diff is over 1000 lines.
src/cli/frontmatter.ts+22−22
Cut short: this commit's diff is over 1000 lines.
src/cli/git-branch-cache.test.ts+0−84
Cut short: this commit's diff is over 1000 lines.
src/cli/git-branch-cache.ts+0−49
Cut short: this commit's diff is over 1000 lines.
src/cli/image-types.test.ts+36−36
Cut short: this commit's diff is over 1000 lines.
src/cli/image-types.ts+31−31
Cut short: this commit's diff is over 1000 lines.
src/cli/input-buffer.ts+65−65
Cut short: this commit's diff is over 1000 lines.
src/cli/input-completion.ts+34−34
Cut short: this commit's diff is over 1000 lines.
src/cli/input-control.ts+6−6
Cut short: this commit's diff is over 1000 lines.
src/cli/input-editing.test.ts+26−26
Cut short: this commit's diff is over 1000 lines.
src/cli/input-editing.ts+22−22
Cut short: this commit's diff is over 1000 lines.
src/cli/input-images.test.ts+39−39
Cut short: this commit's diff is over 1000 lines.
src/cli/input-images.ts+28−28
Cut short: this commit's diff is over 1000 lines.
src/cli/input-loop.ts+114−109
Cut short: this commit's diff is over 1000 lines.
src/cli/input.test.ts+117−117
Cut short: this commit's diff is over 1000 lines.
src/cli/input.ts+464−464
Cut short: this commit's diff is over 1000 lines.
src/cli/live-reasoning.test.ts+25−25
Cut short: this commit's diff is over 1000 lines.
src/cli/live-reasoning.ts+44−44
Cut short: this commit's diff is over 1000 lines.
src/cli/log-paths.ts+29−29
Cut short: this commit's diff is over 1000 lines.
src/cli/output.test.ts+24−24
Cut short: this commit's diff is over 1000 lines.
src/cli/output.ts+145−147
Cut short: this commit's diff is over 1000 lines.
src/cli/reasoning.ts+22−22
Cut short: this commit's diff is over 1000 lines.
src/cli/skills.test.ts+204−204
Cut short: this commit's diff is over 1000 lines.
src/cli/skills.ts+274−249
Cut short: this commit's diff is over 1000 lines.
src/cli/spinner.test.ts+28−28
Cut short: this commit's diff is over 1000 lines.
src/cli/spinner.ts+32−32
Cut short: this commit's diff is over 1000 lines.
src/cli/status-bar.test.ts+96−96
Cut short: this commit's diff is over 1000 lines.
src/cli/status-bar.ts+77−77
Cut short: this commit's diff is over 1000 lines.
src/cli/stdin-prompt.test.ts+35−35
Cut short: this commit's diff is over 1000 lines.
src/cli/stdin-prompt.ts+20−20
Cut short: this commit's diff is over 1000 lines.
src/cli/stream-render-content.ts+84−84
Cut short: this commit's diff is over 1000 lines.
src/cli/stream-render.test.ts+331−331
Cut short: this commit's diff is over 1000 lines.
src/cli/stream-render.ts+151−151
Cut short: this commit's diff is over 1000 lines.
src/cli/structured-output.test.ts+43−43
Cut short: this commit's diff is over 1000 lines.
src/cli/structured-output.ts+82−82
Cut short: this commit's diff is over 1000 lines.
src/cli/terminal-io.test.ts+26−26
Cut short: this commit's diff is over 1000 lines.
src/cli/terminal-io.ts+111−111
Cut short: this commit's diff is over 1000 lines.
src/cli/test-helpers.ts+41−58
Cut short: this commit's diff is over 1000 lines.
src/cli/tool-render.test.ts+161−161
Cut short: this commit's diff is over 1000 lines.
src/cli/tool-render.ts+119−119
Cut short: this commit's diff is over 1000 lines.
src/cli/tool-result-renderers.ts+280−280
Cut short: this commit's diff is over 1000 lines.
src/cli/types.ts+15−15
Cut short: this commit's diff is over 1000 lines.
src/cli/ui-audit.test.ts+0−792
Cut short: this commit's diff is over 1000 lines.
src/index.ts+115−115
Cut short: this commit's diff is over 1000 lines.
src/internal/ansi.ts+2−2
Cut short: this commit's diff is over 1000 lines.
src/internal/file-edit/cli.test.ts+95−95
Cut short: this commit's diff is over 1000 lines.
src/internal/file-edit/cli.ts+107−107
Cut short: this commit's diff is over 1000 lines.
src/internal/file-edit/command.test.ts+37−37
Cut short: this commit's diff is over 1000 lines.
src/internal/file-edit/command.ts+49−36
Cut short: this commit's diff is over 1000 lines.
src/internal/file-edit/exact-text.test.ts+76−76
Cut short: this commit's diff is over 1000 lines.
src/internal/file-edit/exact-text.ts+78−78
Cut short: this commit's diff is over 1000 lines.
src/internal/file-edit/path.ts+22−22
Cut short: this commit's diff is over 1000 lines.
src/internal/runtime/script.ts+0−13
Cut short: this commit's diff is over 1000 lines.
src/llm-api/api-log.ts+47−47
Cut short: this commit's diff is over 1000 lines.
src/llm-api/error-utils.test.ts+22−22
Cut short: this commit's diff is over 1000 lines.
src/llm-api/error-utils.ts+36−36
Cut short: this commit's diff is over 1000 lines.
src/llm-api/history/gemini.ts+108−108
Cut short: this commit's diff is over 1000 lines.
src/llm-api/history/reasoning.ts+8−8
Cut short: this commit's diff is over 1000 lines.
src/llm-api/history/shared.ts+66−66
Cut short: this commit's diff is over 1000 lines.
src/llm-api/model-info-cache.ts+172−172
Cut short: this commit's diff is over 1000 lines.
src/llm-api/model-info-fetch.ts+197−197
Cut short: this commit's diff is over 1000 lines.
src/llm-api/model-info-normalize.ts+103−103
Cut short: this commit's diff is over 1000 lines.
src/llm-api/model-info.test.ts+236−236
Cut short: this commit's diff is over 1000 lines.
src/llm-api/model-info.ts+203−203
Cut short: this commit's diff is over 1000 lines.
src/llm-api/model-routing.test.ts+48−48
Cut short: this commit's diff is over 1000 lines.
src/llm-api/model-routing.ts+40−40
Cut short: this commit's diff is over 1000 lines.
src/llm-api/providers-resolve.test.ts+47−47
Cut short: this commit's diff is over 1000 lines.
src/llm-api/providers.test.ts+51−51
Cut short: this commit's diff is over 1000 lines.
src/llm-api/providers.ts+209−209
Cut short: this commit's diff is over 1000 lines.
src/llm-api/turn-context.ts+207−207
Cut short: this commit's diff is over 1000 lines.
src/llm-api/turn-execution.test.ts+226−226
Cut short: this commit's diff is over 1000 lines.
src/llm-api/turn-execution.ts+300−300
Cut short: this commit's diff is over 1000 lines.
src/llm-api/turn-prepare-messages.ts+111−111
Cut short: this commit's diff is over 1000 lines.
src/llm-api/turn-provider-options.ts+43−43
Cut short: this commit's diff is over 1000 lines.
src/llm-api/turn-request.test.ts+178−178
Cut short: this commit's diff is over 1000 lines.
src/llm-api/turn-request.ts+77−77
Cut short: this commit's diff is over 1000 lines.
src/llm-api/turn-stream-events.test.ts+114−114
Cut short: this commit's diff is over 1000 lines.
src/llm-api/turn-stream-events.ts+74−74
Cut short: this commit's diff is over 1000 lines.
src/llm-api/turn.ts+115−115
Cut short: this commit's diff is over 1000 lines.
src/llm-api/types.ts+48−48
Cut short: this commit's diff is over 1000 lines.
src/mcp/client.ts+78−78
Cut short: this commit's diff is over 1000 lines.
src/session/db/connection.test.ts+12−12
Cut short: this commit's diff is over 1000 lines.
src/session/db/connection.ts+74−74
Cut short: this commit's diff is over 1000 lines.
src/session/db/mcp-repo.ts+25−24
Cut short: this commit's diff is over 1000 lines.
src/session/db/message-repo.ts+78−76
Cut short: this commit's diff is over 1000 lines.
src/session/db/model-info-repo.ts+74−71
Cut short: this commit's diff is over 1000 lines.
src/session/db/session-repo.ts+40−39
Cut short: this commit's diff is over 1000 lines.
src/session/db/settings-repo.test.ts+14−14
Cut short: this commit's diff is over 1000 lines.
src/session/db/settings-repo.ts+37−36
Cut short: this commit's diff is over 1000 lines.
src/session/manager.ts+38−38
Cut short: this commit's diff is over 1000 lines.
src/session/oauth/anthropic.ts+133−133
Cut short: this commit's diff is over 1000 lines.
src/session/oauth/auth-storage.ts+64−63
Cut short: this commit's diff is over 1000 lines.
src/session/oauth/pkce.test.ts+16−16
Cut short: this commit's diff is over 1000 lines.
src/session/oauth/pkce.ts+14−14
Cut short: this commit's diff is over 1000 lines.
src/session/oauth/types.ts+9−9
Cut short: this commit's diff is over 1000 lines.
src/tools/exa.ts+48−48
Cut short: this commit's diff is over 1000 lines.
src/tools/shell.test.ts+19−48
Cut short: this commit's diff is over 1000 lines.
src/tools/shell.ts+152−152
Cut short: this commit's diff is over 1000 lines.
src/tools/skills.test.ts+32−32
Cut short: this commit's diff is over 1000 lines.
src/tools/skills.ts+49−49
Cut short: this commit's diff is over 1000 lines.
tsconfig.json+23−23
Cut short: this commit's diff is over 1000 lines.