mini-coder 0.0.9 → 0.0.11

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/hanging-bug.md CHANGED
@@ -69,6 +69,7 @@ So this is now proven in your codepath:
69
69
  * When a command times out, `proc.kill("SIGTERM")` only kills the parent process (e.g., `bash`). Any child processes (e.g., `bun`) become orphaned but stay alive, holding the write end of the `stdout`/`stderr` pipes open.
70
70
  * Because the pipe never closes, `await reader.read()` inside `collectStream()` hangs indefinitely.
71
71
  * Because `collectStream()` never resolves, the tool execution never finishes, `tool-result` is never yielded, and the stream goes completely silent while the spinner stays stuck on "shell".
72
+ - **FIXED**
72
73
 
73
74
  ### Root Cause 2: Hangs spinning on `"thinking"`
74
75
  **Proof in code:** `src/llm-api/turn.ts`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mini-coder",
3
- "version": "0.0.9",
3
+ "version": "0.0.11",
4
4
  "description": "A small, fast CLI coding agent",
5
5
  "module": "src/index.ts",
6
6
  "type": "module",
package/codex-lazy-fix.md DELETED
@@ -1,76 +0,0 @@
1
- # Codex Autonomy Issues & Fix Analysis
2
-
3
- ## Behaviours
4
- When using `zen/gpt-5.3-codex` as the agent, the model consistently exhibits "lazy" or permission-seeking behaviour. Specifically:
5
- 1. **Initial Compliance**: It starts by reading files or globbing the directory.
6
- 2. **Immediate Stall**: Instead of executing edits or implementing the plan, it outputs a multi-paragraph text explaining what it *plans* to do and ends the turn.
7
- 3. **Permission Seeking**: It explicitly asks the user for permission (e.g., "Reply **'proceed'** and I'll start implementing batch 1").
8
- 4. **Ralph Mode Incompatibility**: In `/ralph` mode, the agent loops continuously. Because it restarts with a fresh context on each loop and stalls after gathering context, it never actually writes any files. It just loops through the same read-and-plan phase until it hits the max iteration limit.
9
- 5. **Model Differences**: Both Claude and Gemini models do not exhibit this behaviour. They are not subjected to the same conversational RLHF that pushes the model to ask the user to double check its work.
10
-
11
- ## Root Cause Analysis
12
- An analysis of both OpenAI's open-source `codex-rs` client and `opencode` source code reveals that Codex models (like `gpt-5.3-codex`) are highly RLHF-tuned for safety and collaborative pair-programming. By default, the model prefers to break tasks into chunks and explicitly ask for sign-off.
13
-
14
- To override this, the model requires three things which `mini-coder` was failing to provide correctly:
15
-
16
- ### 1. Dual-Anchored System Prompts (`system` + `instructions`)
17
- `mini-coder` implemented a check `useInstructions` that placed the system prompt into the `instructions` field of the `/v1/responses` API payload. However, doing so stripped the `system` role message from the conversation context (`input` array).
18
-
19
- By looking at `opencode` and `codex-rs`, they both ensure that the context array *also* contains the system prompt:
20
- - `opencode` maps its environment variables and system instructions to `role: "system"` (or `role: "developer"`) inside `input.messages`, **while also** passing behavioral instructions to the `instructions` field in the API payload.
21
- - `codex-rs` directly injects `role: "developer"` into the message list (as seen in `codex-rs/core/src/compact.rs` and their memory tracing implementations).
22
-
23
- Without the `system` / `developer` message anchored at the start of the `input` array, the AI SDK and the model deprioritized the standalone `instructions` field, allowing the model's base permission-seeking behaviors to take over.
24
-
25
- ### 2. Explicit "Do Not Ask" Directives
26
- Both `opencode` and `codex-rs` employ heavy anti-permission prompts.
27
- - **Opencode** (`session/prompt/codex_header.txt`):
28
- > "- Default: do the work without asking questions... Never ask permission questions like 'Should I proceed?' or 'Do you want me to run tests?'; proceed with the most reasonable option and mention what you did."
29
- - **Codex-RS** (`core/templates/model_instructions/gpt-5.2-codex_instructions_template.md`):
30
- > "Persist until the task is fully handled end-to-end within the current turn whenever feasible: do not stop at analysis or partial fixes; carry changes through implementation, verification, and a clear explanation of outcomes unless the user explicitly pauses or redirects you."
31
-
32
- `mini-coder` introduced `CODEX_AUTONOMY` in a previous commit, but because of Issue #1, it was never adequately anchored in the `input` array.
33
-
34
- ## Evidence & Tests
35
- We introduced a fetch wrapper interceptor in `src/llm-api/providers.ts` that logs the full outbound API requests to `~/.config/mini-coder/api.log`.
36
-
37
- A test script `test-turn.ts` running a dummy turn showed the exact payload generated by the AI SDK before our fix:
38
- ```json
39
- "body": {
40
- "model": "gpt-5.3-codex",
41
- "input": [
42
- {
43
- "role": "user",
44
- "content": [
45
- { "type": "input_text", "text": "hello" }
46
- ]
47
- }
48
- ],
49
- "store": false,
50
- "instructions": "You are a test agent.",
51
- ...
52
- ```
53
- ```json
54
- "body": {
55
- "model": "gpt-5.3-codex",
56
- "input": [
57
- {
58
- "role": "developer",
59
- "content": "You are mini-coder, a small and fast CLI coding agent... [CODEX_AUTONOMY directives]"
60
- },
61
- {
62
- "role": "user",
63
- "content": [
64
- { "type": "input_text", "text": "hello" }
65
- ]
66
- }
67
- ],
68
- "instructions": "You are mini-coder, a small and fast CLI coding agent... [CODEX_AUTONOMY directives]"
69
- }
70
- ```
71
- This perfectly mirrors the behavior seen in `opencode` and `codex-rs`.
72
-
73
- ## Actions Taken
74
- 1. Added an `api.log` request interceptor in `providers.ts` to capture and inspect the exact JSON payloads sent to the OpenAI/AI SDK endpoints.
75
- 2. Cloned and analyzed both `opencode` and `codex` repos to observe how they communicate with `gpt-5.*` codex endpoints.
76
- 3. Updated `src/llm-api/turn.ts` so `system: systemPrompt` is *always* passed to the AI SDK, guaranteeing a `developer` message anchors the `input` array, even when `instructions` is also used.
@@ -1,169 +0,0 @@
1
- # Code Health Remediation Plan
2
-
3
- ## Goal
4
- Address maintainability and reliability issues identified in `code-health.md` with low-risk, incremental refactors that keep behavior stable.
5
-
6
- ## Constraints
7
- - Keep `mini-coder-idea.md` and `README.md` unchanged.
8
- - Prefer small PR-sized changes with passing tests after each step.
9
- - Preserve current CLI behavior while improving structure.
10
-
11
- ## Workstreams
12
-
13
- ### 1) Decompose `src/agent/agent.ts` (High)
14
- **Outcome:** `runAgent` remains orchestration entrypoint; responsibilities split into focused modules.
15
-
16
- **Steps:**
17
- 1. Add `src/agent/reporter.ts` interface (narrow surface for output/status/tool events).
18
- 2. Extract session lifecycle + turn loop into `src/agent/session-runner.ts`.
19
- 3. Extract subagent execution into `src/agent/subagent-runner.ts`.
20
- 4. Extract snapshot/undo helpers into `src/agent/undo-snapshot.ts`.
21
- 5. Extract user input processing into `src/agent/input-loop.ts`.
22
- 6. Keep `agent.ts` as composition/wiring file only.
23
-
24
- **Checks:**
25
- - Add/adjust unit tests around orchestration boundaries.
26
- - Ensure no behavior regressions in interrupts, resume, and tool-call flows.
27
-
28
- ---
29
-
30
- ### 2) Decompose `src/cli/output.ts` (High)
31
- **Outcome:** Rendering responsibilities isolated and testable.
32
-
33
- **Target modules:**
34
- - `src/cli/spinner.ts`
35
- - `src/cli/tool-render.ts`
36
- - `src/cli/stream-render.ts`
37
- - `src/cli/status-bar.ts`
38
- - `src/cli/error-render.ts`
39
- - `src/cli/output.ts` as facade
40
-
41
- **Steps:**
42
- 1. Extract pure formatting helpers first (no IO).
43
- 2. Extract spinner lifecycle module.
44
- 3. Extract stream queue/tick/flush behavior.
45
- 4. Keep compatibility exports in `output.ts` to avoid broad callsite churn.
46
-
47
- **Checks:**
48
- - Add focused tests for formatting + stream behavior.
49
- - Verify terminal rendering remains stable manually.
50
-
51
- ---
52
-
53
- ### 3) Introduce `TerminalIO` abstraction (Medium)
54
- **Outcome:** Centralized process/TTY interactions and signal lifecycle.
55
-
56
- **Steps:**
57
- 1. Create `src/cli/terminal-io.ts` with methods for stdout/stderr writes, raw mode, signal subscriptions.
58
- 2. Replace direct `process.*` use in output/input stack with injected `TerminalIO`.
59
- 3. Centralize signal registration/unregistration in one lifecycle owner.
60
-
61
- **Checks:**
62
- - Add unit tests for signal registration cleanup semantics.
63
- - Confirm no stuck raw-mode edge cases.
64
-
65
- ---
66
-
67
- ### 4) Split DB layer by domain (Medium)
68
- **Outcome:** Reduced blast radius and clearer data ownership.
69
-
70
- **Target modules:**
71
- - `src/session/db/connection.ts`
72
- - `src/session/db/session-repo.ts`
73
- - `src/session/db/message-repo.ts`
74
- - `src/session/db/settings-repo.ts`
75
- - `src/session/db/mcp-repo.ts`
76
- - `src/session/db/snapshot-repo.ts`
77
- - `src/session/db/index.ts` (facade exports)
78
-
79
- **Steps:**
80
- 1. Move code without behavior changes.
81
- 2. Keep SQL and schema unchanged initially.
82
- 3. Replace direct `JSON.parse` in message loading with guarded parser:
83
- - skip malformed rows
84
- - emit diagnostic via logger/reporter
85
-
86
- **Checks:**
87
- - Add tests for malformed payload handling.
88
- - Validate existing DB tests still pass.
89
-
90
- ---
91
-
92
- ### 5) Shared markdown config loader (Medium)
93
- **Outcome:** Remove duplication across agents/skills/custom-commands.
94
-
95
- **Steps:**
96
- 1. Create `src/cli/load-markdown-configs.ts` with parameterized layout strategy.
97
- 2. Migrate:
98
- - `src/cli/agents.ts`
99
- - `src/cli/skills.ts`
100
- - `src/cli/custom-commands.ts`
101
- 3. Keep precedence rules identical (built-in/user/project).
102
- 4. Preserve existing frontmatter semantics.
103
-
104
- **Checks:**
105
- - Reuse/expand existing loader tests to cover parity.
106
-
107
- ---
108
-
109
- ### 6) Runtime/UI decoupling via reporter boundary (Medium)
110
- **Outcome:** Core runtime no longer depends directly on terminal rendering.
111
-
112
- **Steps:**
113
- 1. Define domain events or reporter interface in `src/agent/reporter.ts`.
114
- 2. Implement CLI reporter adapter in `src/cli/output-reporter.ts`.
115
- 3. Replace direct output calls in agent runtime with reporter calls.
116
-
117
- **Checks:**
118
- - Add tests using test reporter to assert emitted events.
119
-
120
- ---
121
-
122
- ### 7) Error observability and silent catches (Medium)
123
- **Outcome:** Non-fatal failures become diagnosable without crashing.
124
-
125
- **Steps:**
126
- 1. Find empty/broad catches in agent/output/loaders.
127
- 2. Add debug-level diagnostics with contextual metadata.
128
- 3. Keep user-facing behavior unchanged unless critical.
129
-
130
- **Checks:**
131
- - Validate noisy paths are still quiet at normal verbosity.
132
-
133
- ---
134
-
135
- ### 8) Startup FS sync usage (Low/Deferred)
136
- **Outcome:** Optional responsiveness improvement if startup cost grows.
137
-
138
- **Steps:**
139
- 1. Measure startup and config-loading time first.
140
- 2. If needed, move high-volume file scanning to async or cache results with invalidation.
141
-
142
- ---
143
-
144
- ### 9) Test hygiene cleanup (Low)
145
- **Outcome:** Cleaner CI output.
146
-
147
- **Steps:**
148
- 1. Remove `console.log` skip notices in `src/tools/shell.test.ts`.
149
- 2. Use test-framework-native skip annotations/helpers.
150
-
151
- ---
152
-
153
- ## Execution Order (recommended)
154
- 1. Reporter interface (foundation for later decoupling).
155
- 2. `agent.ts` decomposition.
156
- 3. `output.ts` decomposition.
157
- 4. Shared config loader extraction.
158
- 5. DB module split + safe JSON parsing.
159
- 6. TerminalIO + centralized signals.
160
- 7. Silent catch diagnostics.
161
- 8. Test hygiene and any deferred FS optimization.
162
-
163
- ## Definition of Done
164
- - `bun run typecheck && bun run format && bun run lint && bun test` passes.
165
- - No behavior regressions in interactive CLI flows.
166
- - `agent.ts` and `output.ts` materially reduced in size/responsibility.
167
- - Config loader duplication removed.
168
- - Message loading resilient to malformed JSON rows.
169
- - New abstractions documented in code comments where non-obvious.