mini-coder 0.5.2 → 0.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -59,32 +59,34 @@ Plugins can add more tools, but the core stays intentionally small.
59
59
 
60
60
  ## Commands
61
61
 
62
- | Command | Description |
63
- | ------------ | ---------------------------------------------------------------------- |
64
- | `/model` | Switch models. Persists as the global default. |
65
- | `/session` | List and resume sessions scoped to the current working directory. |
66
- | `/new` | Start a fresh session and reset cumulative usage counters. |
67
- | `/fork` | Copy the conversation into a new session and continue independently. |
68
- | `/undo` | Remove the last conversational turn (does not revert file changes). |
69
- | `/reasoning` | Toggle thinking visibility. Persisted and restored on launch. |
70
- | `/verbose` | Toggle verbose shell rendering plus edit previews/errors in the log. |
71
- | `/login` | Interactive OAuth login for supported providers. |
72
- | `/logout` | Clear saved OAuth credentials for a logged-in provider. |
73
- | `/effort` | Set reasoning effort: low, medium, high, or xhigh. |
74
- | `/help` | List commands, loaded AGENTS.md files, discovered skills, and plugins. |
62
+ | Command | Description |
63
+ | ------------ | ------------------------------------------------------------------------------------------------------ |
64
+ | `/model` | Switch models and save the choice as the global default. |
65
+ | `/session` | Open the session picker for the current working directory. |
66
+ | `/new` | Start a fresh session and reset the running token and cost totals. |
67
+ | `/fork` | Fork the current chat into a new session, keep the original, and add a UI-only `Forked session.` note. |
68
+ | `/undo` | Remove the last conversational turn without touching filesystem changes. |
69
+ | `/reasoning` | Show or hide model thinking. The setting is saved and restored on launch. |
70
+ | `/verbose` | Expand shell output plus edit previews and edit errors in the conversation log. |
71
+ | `/login` | Sign in with a supported OAuth provider. |
72
+ | `/logout` | Remove saved OAuth credentials for a logged-in provider. |
73
+ | `/effort` | Choose low, medium, high, or xhigh reasoning effort. |
74
+ | `/help` | Show commands, current toggles, loaded AGENTS.md files, skills, and plugins. |
75
75
 
76
76
  ## Key bindings
77
77
 
78
- | Key | Action |
79
- | ------------- | ------------------------------------------------- |
80
- | `Enter` | Submit message |
81
- | `Shift+Enter` | Insert newline |
82
- | `Escape` | Interrupt current turn, preserve partial response |
83
- | `Tab` | File path autocomplete (or command filter on `/`) |
84
- | `Ctrl+R` | Search global raw input history |
85
- | `Ctrl+C` | Graceful exit |
86
- | `Ctrl+D` | Graceful exit (EOF, when input is empty) |
87
- | `:q` | Graceful exit |
78
+ | Key | Action |
79
+ | ------------- | ---------------------------------------------------------------------------------------------------------- |
80
+ | `Enter` | Submit message |
81
+ | `Shift+Enter` | Insert newline |
82
+ | `Escape` | Dismiss the overlay without changing the draft; otherwise interrupt the running turn; otherwise do nothing |
83
+ | `Tab` | Autocomplete a path, or open the command picker when the draft starts with `/` |
84
+ | `Ctrl+R` | Search global raw input history |
85
+ | `Ctrl+C` | Graceful exit |
86
+ | `Ctrl+D` | Graceful exit when the input is empty |
87
+ | `:q` | Graceful exit |
88
+ | `Ctrl+Z` | Suspend the process |
89
+ | Mouse wheel | Scroll conversation history |
88
90
 
89
91
  ## Headless one-shot mode
90
92
 
@@ -95,10 +97,12 @@ $ mc -p "summarize this repo"
95
97
  $ printf '%s\n' 'fix the failing tests' | mc
96
98
  ```
97
99
 
98
- - Enabled when `-p/--prompt` is provided or when stdin/stdout is not a TTY.
99
- - Reuses the same input parsing rules as the interactive UI for plain text, `/skill:name`, and standalone image paths.
100
- - Streams newline-delimited JSON events to stdout.
101
- - Interactive slash commands such as `/model` and `/help` are not available in headless mode.
100
+ - Starts when `-p/--prompt` is provided or when stdin or stdout is not a TTY.
101
+ - If stdout is redirected but stdin is still interactive, pass `-p`; headless mode will not fall back to an interactive prompt.
102
+ - Uses the same parser as the TUI for plain text, `/skill:name`, and standalone image paths.
103
+ - Writes raw NDJSON events to stdout for text deltas, tool activity, final messages, and `done` / `error` / `aborted` outcomes.
104
+ - Headless runs still persist like normal sessions and show up in `/session` history for that working directory.
105
+ - Interactive slash commands such as `/model`, `/session`, and `/help` are not available in headless mode.
102
106
 
103
107
  ## Docs
104
108
 
package/bun.lock CHANGED
@@ -5,9 +5,9 @@
5
5
  "": {
6
6
  "name": "mini-coder",
7
7
  "dependencies": {
8
- "@cel-tui/components": "^0.6.2",
9
- "@cel-tui/core": "^0.6.2",
10
- "@cel-tui/types": "^0.6.2",
8
+ "@cel-tui/components": "0.7.2",
9
+ "@cel-tui/core": "0.7.2",
10
+ "@cel-tui/types": "0.7.2",
11
11
  "@mariozechner/pi-ai": "^0.66.1",
12
12
  },
13
13
  "devDependencies": {
@@ -108,11 +108,11 @@
108
108
 
109
109
  "@biomejs/cli-win32-x64": ["@biomejs/cli-win32-x64@2.4.11", "", { "os": "win32", "cpu": "x64" }, "sha512-A8D3JM/00C2KQgUV3oj8Ba15EHEYwebAGCy5Sf9GAjr5Y3+kJIYOiESoqRDeuRZueuMdCsbLZIUqmPhpYXJE9A=="],
110
110
 
111
- "@cel-tui/components": ["@cel-tui/components@0.6.2", "", { "dependencies": { "@cel-tui/core": "0.6.2", "@cel-tui/types": "0.6.2", "lextide": "^0.1.0", "yoctomarkdown": "^0.1.0" }, "peerDependencies": { "typescript": ">=5.0.0" } }, "sha512-FYR7lX3/gPAyEkfMuyVapdxfO0e9OIw4lmdIUF2Tw7QszkpV4MAkEoB3G2oUY6UZyxJCSCKLBPvLzwu5uxaDgw=="],
111
+ "@cel-tui/components": ["@cel-tui/components@0.7.2", "", { "dependencies": { "@cel-tui/core": "0.7.2", "@cel-tui/types": "0.7.2", "lextide": "^0.2.1", "yoctomarkdown": "^0.1.0" }, "peerDependencies": { "typescript": ">=5.0.0" } }, "sha512-RHq7G/lS6A733l534cSStQp+cJECkxZZWrLghbPHwGBsSeDdJ2MkrQm+02roh6EH/N40ZAYjQqplq8acRrnFFQ=="],
112
112
 
113
- "@cel-tui/core": ["@cel-tui/core@0.6.2", "", { "dependencies": { "@cel-tui/types": "0.6.2", "get-east-asian-width": "^1.5.0" }, "peerDependencies": { "typescript": ">=5.0.0" } }, "sha512-KJQdDMPbwLE211Hvn75jUKEvHiKTtQ7iVGJiiOpG+s4DjhnpySBXWO0hReMxe5NR2NPls7wmze1dBZ8/MXqVXA=="],
113
+ "@cel-tui/core": ["@cel-tui/core@0.7.2", "", { "dependencies": { "@cel-tui/types": "0.7.2", "get-east-asian-width": "^1.5.0" }, "peerDependencies": { "typescript": ">=5.0.0" } }, "sha512-Y5qdI9Zoa77Olq/LD+vqf3j0hyCRJYkkTkIdUfQplSDSUJS5NM+VSnxcQ8RCUNmrIsHeLmmAPHYsBsS1WMWk1w=="],
114
114
 
115
- "@cel-tui/types": ["@cel-tui/types@0.6.2", "", { "peerDependencies": { "typescript": ">=5.0.0" } }, "sha512-JsJdo20KmgtC67QlG/ZrZyGi0xNJBKd3G6kM/yN/6/hk8a86P+1k1jqtSUjcZ4E9x1v9IXqPk6QelU7kLyOV1A=="],
115
+ "@cel-tui/types": ["@cel-tui/types@0.7.2", "", { "peerDependencies": { "typescript": ">=5.0.0" } }, "sha512-XEmYkGqtBMOXI/DKLopv5OL7d5/8ybkj1OpJO4weWPyx4Y6VY9pYFaj8zYhVaFSQZcB23/yoA+DPYi0kOgoZhQ=="],
116
116
 
117
117
  "@google/genai": ["@google/genai@1.48.0", "", { "dependencies": { "google-auth-library": "^10.3.0", "p-retry": "^4.6.2", "protobufjs": "^7.5.4", "ws": "^8.18.0" }, "peerDependencies": { "@modelcontextprotocol/sdk": "^1.25.2" }, "optionalPeers": ["@modelcontextprotocol/sdk"] }, "sha512-plonYK4ML2PrxsRD9SeqmFt76eREWkQdPCglOA6aYDzL1AAbE+7PUnT54SvpWGfws13L0AZEqGSpL7+1IPnTxQ=="],
118
118
 
@@ -342,7 +342,7 @@
342
342
 
343
343
  "lefthook-windows-x64": ["lefthook-windows-x64@2.1.5", "", { "os": "win32", "cpu": "x64" }, "sha512-yiAh8qxml6uqy10jDxOdN9fOQpyLxBFY1fgCEAhn7sVJYmJKRhjqSBwZX6LG5MQjzr29KStrIdw7TR3lf3rT7Q=="],
344
344
 
345
- "lextide": ["lextide@0.1.0", "", {}, "sha512-i1fx9SzultDOIgVtFt/vBOeyFaGYCNLT6OcdqOLRfWL9p6aTQsq8JQ+8LpJ4T7znWNjfjLqUU6dK5g2kXhSq3A=="],
345
+ "lextide": ["lextide@0.2.1", "", {}, "sha512-fP7liS0LoNJz2EF6G7+K21yvB58bJEjaTrsDcPi4Qv7xZynB9NzjY44N6tFK6SJaECHIUqF2kcWbWQ84hPfmlg=="],
346
346
 
347
347
  "long": ["long@5.3.2", "", {}, "sha512-mNAgZ1GmyNhD7AuqnTG3/VQ26o760+ZYBPKjPvugO8+nLbYfX6TVpJPseBvopbdY+qpZ/lKUnmEc1LeZYS3QAA=="],
348
348
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mini-coder",
3
- "version": "0.5.2",
3
+ "version": "0.5.4",
4
4
  "description": "A small, fast CLI coding agent",
5
5
  "module": "src/index.ts",
6
6
  "type": "module",
@@ -18,9 +18,9 @@
18
18
  "test": "bun test"
19
19
  },
20
20
  "dependencies": {
21
- "@cel-tui/components": "^0.6.2",
22
- "@cel-tui/core": "^0.6.2",
23
- "@cel-tui/types": "^0.6.2",
21
+ "@cel-tui/components": "^0.7.2",
22
+ "@cel-tui/core": "^0.7.2",
23
+ "@cel-tui/types": "^0.7.2",
24
24
  "@mariozechner/pi-ai": "^0.66.1"
25
25
  },
26
26
  "devDependencies": {
package/src/agent.ts CHANGED
@@ -525,19 +525,26 @@ async function executeToolCall(
525
525
 
526
526
  let result: ToolExecResult;
527
527
  try {
528
- result = await handler(
529
- toolCall.arguments,
530
- opts.cwd,
531
- opts.signal,
532
- (partial) => {
533
- opts.onEvent?.({
534
- type: "tool_delta",
535
- toolCallId: toolCall.id,
536
- name: toolCall.name,
537
- result: partial,
538
- });
539
- },
540
- );
528
+ if (opts.signal?.aborted) {
529
+ result = toolErrorResult(
530
+ toolCall.name,
531
+ new Error("This operation was aborted"),
532
+ );
533
+ } else {
534
+ result = await handler(
535
+ toolCall.arguments,
536
+ opts.cwd,
537
+ opts.signal,
538
+ (partial) => {
539
+ opts.onEvent?.({
540
+ type: "tool_delta",
541
+ toolCallId: toolCall.id,
542
+ name: toolCall.name,
543
+ result: partial,
544
+ });
545
+ },
546
+ );
547
+ }
541
548
  } catch (error) {
542
549
  result = toolErrorResult(toolCall.name, error);
543
550
  }
@@ -592,8 +599,17 @@ function appendToolResultMessage(
592
599
  export async function runAgentLoop(
593
600
  opts: RunAgentOpts,
594
601
  ): Promise<AgentLoopResult> {
595
- const { db, sessionId, turn, messages, signal, onEvent, toolHandlers, cwd } =
596
- opts;
602
+ const {
603
+ db,
604
+ sessionId,
605
+ turn,
606
+ model,
607
+ messages,
608
+ signal,
609
+ onEvent,
610
+ toolHandlers,
611
+ cwd,
612
+ } = opts;
597
613
 
598
614
  while (true) {
599
615
  const assistantMessage = await streamAssistantMessage(opts);
@@ -633,6 +649,13 @@ export async function runAgentLoop(
633
649
  );
634
650
 
635
651
  if (signal?.aborted) {
652
+ onEvent?.({
653
+ type: "aborted",
654
+ message: buildIncompleteAssistantMessage(
655
+ { model, signal },
656
+ assistantMessage,
657
+ ),
658
+ });
636
659
  return { messages, stopReason: "aborted" };
637
660
  }
638
661
  }
package/src/git.ts CHANGED
@@ -61,6 +61,51 @@ async function run(
61
61
  return trim ? out.trim() : out;
62
62
  }
63
63
 
64
+ function getErrorStringProperty(
65
+ error: unknown,
66
+ key: string,
67
+ ): string | undefined {
68
+ if (typeof error !== "object" || error === null) {
69
+ return undefined;
70
+ }
71
+
72
+ const value = Reflect.get(error, key);
73
+ return typeof value === "string" ? value : undefined;
74
+ }
75
+
76
+ function isMissingGitError(error: unknown): boolean {
77
+ const code = getErrorStringProperty(error, "code");
78
+ if (code !== "ENOENT") {
79
+ return false;
80
+ }
81
+
82
+ const message = getErrorStringProperty(error, "message");
83
+ return (
84
+ typeof message === "string" &&
85
+ message.includes('Executable not found in $PATH: "git"')
86
+ );
87
+ }
88
+
89
+ async function safeRun(
90
+ runGit: (
91
+ args: string[],
92
+ cwd: string,
93
+ trim?: boolean,
94
+ ) => Promise<string | null>,
95
+ args: string[],
96
+ cwd: string,
97
+ trim = true,
98
+ ): Promise<string | null> {
99
+ try {
100
+ return await runGit(args, cwd, trim);
101
+ } catch (error) {
102
+ if (isMissingGitError(error)) {
103
+ return null;
104
+ }
105
+ throw error;
106
+ }
107
+ }
108
+
64
109
  function isUntrackedStatus(
65
110
  indexStatus: string,
66
111
  workingTreeStatus: string,
@@ -145,8 +190,8 @@ export function parseGitAheadBehind(output: string): {
145
190
  * Gather the current git state for a directory.
146
191
  *
147
192
  * Runs several fast git commands in parallel to collect branch, working
148
- * tree status, and ahead/behind counts. Returns `null` if the directory
149
- * is not inside a git repository.
193
+ * tree status, and ahead/behind counts. Returns `null` if git is not
194
+ * installed or the directory is not inside a git repository.
150
195
  *
151
196
  * @param cwd - The directory to query (can be a subdirectory of the repo).
152
197
  * @param opts - Optional runtime overrides used by tests.
@@ -165,18 +210,23 @@ export async function getGitState(
165
210
  const exec = opts?.run ?? run;
166
211
 
167
212
  // Check if we're in a repo and get the root
168
- const root = await exec(["rev-parse", "--show-toplevel"], cwd);
213
+ const root = await safeRun(exec, ["rev-parse", "--show-toplevel"], cwd);
169
214
  if (root === null) return null;
170
215
 
171
216
  // Run remaining commands in parallel
172
217
  const [branch, upstream, status, revList] = await Promise.all([
173
- exec(["branch", "--show-current"], cwd),
174
- exec(
218
+ safeRun(exec, ["branch", "--show-current"], cwd),
219
+ safeRun(
220
+ exec,
175
221
  ["rev-parse", "--abbrev-ref", "--symbolic-full-name", "@{upstream}"],
176
222
  cwd,
177
223
  ),
178
- exec(["status", "--porcelain"], cwd, false),
179
- exec(["rev-list", "--left-right", "--count", "HEAD...@{upstream}"], cwd),
224
+ safeRun(exec, ["status", "--porcelain"], cwd, false),
225
+ safeRun(
226
+ exec,
227
+ ["rev-list", "--left-right", "--count", "HEAD...@{upstream}"],
228
+ cwd,
229
+ ),
180
230
  ]);
181
231
 
182
232
  const { staged, modified, untracked } = parseGitStatus(status ?? "");
package/src/prompt.ts CHANGED
@@ -225,6 +225,7 @@ Workflow: **inspect with shell → mutate with edit → verify with shell**.
225
225
 
226
226
  - Think first: before any tool call, decide all files and information you need.
227
227
  - Early in the task, look for acceptance criteria in tests, verifier scripts, eval scripts, examples, and expected-output files. Do not rely on the task text alone when machine-checkable criteria are available.
228
+ - Before relying on a binary, interpreter, or CLI helper you have not yet confirmed, probe availability with focused checks such as \`command -v <tool>\`, \`<tool> --version\`, or \`python3 -m pip --version\`, then adapt to what is actually installed.
228
229
  - Batch reads: if you need multiple files, read them together in parallel rather than one at a time.
229
230
  - Only make sequential calls when a later call genuinely depends on an earlier result.
230
231
 
@@ -233,13 +234,15 @@ Workflow: **inspect with shell → mutate with edit → verify with shell**.
233
234
  - Be concise. Friendly coding teammate tone.
234
235
  - After making changes: lead with a quick explanation of what changed and why, then suggest logical next steps if any.
235
236
  - Don't dump large file contents you've written — reference file paths.
236
- - When suggesting multiple options, use numbered lists so the user can reply with a number.
237
+ - When discussing multiple options, use numbered lists so the user can reply with a number without turning it into a questionnaire.
237
238
  - If asked for a review, focus on bugs, risks, regressions, and missing tests. Findings first, ordered by severity.
238
239
 
239
240
  # Persistence
240
241
 
241
242
  - Carry work through to completion within the current turn. Don't stop at analysis or partial fixes.
242
243
  - Once the contract is clear, create the required artifact early, then iterate and improve it. Do not spend most of the turn exploring.
244
+ - Run the narrowest verifier or test as soon as there is a plausible first implementation or artifact. Do not delay the first verification run until the end.
245
+ - When verification is down to a small number of failures, stop broad exploration and focus only on the remaining failing assertions or exact contract gaps until the last detail passes.
243
246
  - If you encounter an error, diagnose and fix it rather than reporting it and stopping.
244
247
  - Before concluding, run the smallest targeted verification that checks the exact contract: required files exist, names and signatures match, outputs are in the required format, and no forbidden extra artifacts were left behind.
245
248
  - Avoid excessive looping: if you're re-reading or re-editing the same files without progress, stop and ask the user.`;
package/src/session.ts CHANGED
@@ -160,6 +160,8 @@ const EMPTY_ASSISTANT_USAGE: AssistantMessage["usage"] = {
160
160
  },
161
161
  };
162
162
 
163
+ const SQLITE_BUSY_TIMEOUT_MS = 1_000;
164
+
163
165
  /** Row shape returned by `SELECT * FROM prompt_history`. */
164
166
  type PromptHistoryRow = {
165
167
  id: number;
@@ -253,6 +255,7 @@ CREATE INDEX IF NOT EXISTS idx_prompt_history_created_at ON prompt_history(creat
253
255
  export function openDatabase(path: string): Database {
254
256
  const db = new Database(path);
255
257
  db.run("PRAGMA journal_mode = WAL");
258
+ db.run(`PRAGMA busy_timeout = ${SQLITE_BUSY_TIMEOUT_MS}`);
256
259
  db.run("PRAGMA foreign_keys = ON");
257
260
  db.exec(SCHEMA);
258
261
  return db;
@@ -709,6 +712,31 @@ export function getAssistantUsage(
709
712
  };
710
713
  }
711
714
 
715
+ function runInImmediateTransaction<T>(db: Database, callback: () => T): T {
716
+ if (db.inTransaction) {
717
+ return callback();
718
+ }
719
+
720
+ db.run("BEGIN IMMEDIATE");
721
+ try {
722
+ const result = callback();
723
+ db.run("COMMIT");
724
+ return result;
725
+ } catch (error) {
726
+ if (db.inTransaction) {
727
+ try {
728
+ db.run("ROLLBACK");
729
+ } catch (rollbackError) {
730
+ throw new AggregateError(
731
+ [error, rollbackError],
732
+ "Failed to roll back SQLite transaction",
733
+ );
734
+ }
735
+ }
736
+ throw error;
737
+ }
738
+ }
739
+
712
740
  /**
713
741
  * Append a UI-only message to a session's history.
714
742
  *
@@ -790,25 +818,27 @@ export function appendMessage(
790
818
  message: PersistedMessage,
791
819
  turn?: number,
792
820
  ): number | null {
793
- const now = Date.now();
794
-
795
- let effectiveTurn: number | null;
796
- if (isUiMessage(message)) {
797
- effectiveTurn = null;
798
- } else if (turn !== undefined) {
799
- effectiveTurn = turn;
800
- } else {
801
- const row = db.query<MaxTurnRow, [string]>(SQL.maxTurn).get(sessionId);
802
- effectiveTurn = (row?.max_turn ?? 0) + 1;
803
- }
821
+ return runInImmediateTransaction(db, () => {
822
+ const now = Date.now();
823
+
824
+ let effectiveTurn: number | null;
825
+ if (isUiMessage(message)) {
826
+ effectiveTurn = null;
827
+ } else if (turn !== undefined) {
828
+ effectiveTurn = turn;
829
+ } else {
830
+ const row = db.query<MaxTurnRow, [string]>(SQL.maxTurn).get(sessionId);
831
+ effectiveTurn = (row?.max_turn ?? 0) + 1;
832
+ }
804
833
 
805
- db.run(
806
- "INSERT INTO messages (session_id, turn, data, created_at) VALUES (?, ?, ?, ?)",
807
- [sessionId, effectiveTurn, JSON.stringify(message), now],
808
- );
809
- db.run("UPDATE sessions SET updated_at = ? WHERE id = ?", [now, sessionId]);
834
+ db.run(
835
+ "INSERT INTO messages (session_id, turn, data, created_at) VALUES (?, ?, ?, ?)",
836
+ [sessionId, effectiveTurn, JSON.stringify(message), now],
837
+ );
838
+ db.run("UPDATE sessions SET updated_at = ? WHERE id = ?", [now, sessionId]);
810
839
 
811
- return effectiveTurn;
840
+ return effectiveTurn;
841
+ });
812
842
  }
813
843
 
814
844
  /**