micode 0.6.0 → 0.7.0

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
@@ -3,33 +3,19 @@
3
3
  [![CI](https://github.com/vtemian/micode/actions/workflows/ci.yml/badge.svg)](https://github.com/vtemian/micode/actions/workflows/ci.yml)
4
4
  [![npm version](https://badge.fury.io/js/micode.svg)](https://www.npmjs.com/package/micode)
5
5
 
6
- OpenCode plugin with a structured Brainstorm → Plan → Implement workflow and session continuity.
7
-
6
+ OpenCode plugin with structured Brainstorm → Plan → Implement workflow and session continuity.
8
7
 
9
8
  https://github.com/user-attachments/assets/85236ad3-e78a-4ff7-a840-620f6ea2f512
10
9
 
11
-
12
- ## Installation
10
+ ## Quick Start
13
11
 
14
12
  Add to `~/.config/opencode/opencode.json`:
15
13
 
16
14
  ```json
17
- {
18
- "plugin": ["micode"]
19
- }
15
+ { "plugin": ["micode"] }
20
16
  ```
21
17
 
22
- **AI-assisted install:** Share [INSTALL_CLAUDE.md](./INSTALL_CLAUDE.md) with your AI assistant for guided setup.
23
-
24
- ## Getting Started
25
-
26
- **Important:** Run `/init` first to generate project documentation:
27
-
28
- ```
29
- /init
30
- ```
31
-
32
- This creates `ARCHITECTURE.md` and `CODE_STYLE.md` which agents reference during brainstorming, planning, and implementation. Without these files, agents lack context about your codebase patterns.
18
+ Then run `/init` to generate `ARCHITECTURE.md` and `CODE_STYLE.md`.
33
19
 
34
20
  ## Workflow
35
21
 
@@ -39,215 +25,42 @@ Brainstorm → Plan → Implement
39
25
  research research executor
40
26
  ```
41
27
 
42
- Research subagents (codebase-locator, codebase-analyzer, pattern-finder) are spawned within brainstorm and plan phases - not as a separate step.
43
-
44
- ### 1. Brainstorm
45
-
46
- Refine rough ideas into fully-formed designs through collaborative questioning.
47
-
48
- - One question at a time (critical rule!)
49
- - 2-3 approaches with trade-offs
50
- - Section-by-section validation
51
- - Fires research subagents in parallel via `background_task`
52
- - Auto-hands off to planner when user approves
53
- - Output: `thoughts/shared/designs/YYYY-MM-DD-{topic}-design.md`
54
-
55
- **Research subagents** (fired in parallel via background_task):
56
-
57
- | Subagent | Purpose |
58
- |----------|---------|
59
- | `codebase-locator` | Find WHERE files live (paths, no content) |
60
- | `codebase-analyzer` | Explain HOW code works (with file:line refs) |
61
- | `pattern-finder` | Find existing patterns to follow |
62
-
63
- **Auto-handoff:** When user approves the design, brainstormer automatically spawns the planner - no extra confirmation needed.
64
-
65
- ### 2. Plan
66
-
67
- Transform validated designs into comprehensive implementation plans.
68
-
69
- - Fires research subagents in parallel via `background_task`
70
- - Uses `context7` and `btca_ask` for external library documentation
71
- - Bite-sized tasks (2-5 minutes each)
72
- - Exact file paths, complete code examples
73
- - TDD workflow: failing test → verify fail → implement → verify pass → commit
74
- - Get human approval before implementing
75
- - Output: `thoughts/shared/plans/YYYY-MM-DD-{topic}.md`
76
-
77
- **Library research tools:**
78
-
79
- | Tool | Purpose |
80
- |------|---------|
81
- | `context7` | Documentation lookup for external libraries |
82
- | `btca_ask` | Source code search for library internals |
83
-
84
- ### 3. Implement
85
-
86
- Execute plan in git worktree for isolation:
87
-
88
- ```bash
89
- git worktree add ../{feature} -b feature/{feature}
90
- ```
91
-
92
- The **Executor** orchestrates task execution with intelligent parallelization:
93
-
94
- #### How It Works
95
-
96
- 1. **Parse** - Extract individual tasks from the plan
97
- 2. **Analyze** - Build dependency graph between tasks
98
- 3. **Batch** - Group independent tasks for parallel execution
99
- 4. **Execute** - Run implementer→reviewer cycle per task
100
- 5. **Aggregate** - Collect results and report status
101
-
102
- #### Dependency Analysis
103
-
104
- Tasks are grouped into batches based on their dependencies:
105
-
106
- ```
107
- Independent tasks (can parallelize):
108
- - Modify different files
109
- - Don't depend on each other's output
110
- - Don't share state
111
-
112
- Dependent tasks (must be sequential):
113
- - Task B modifies a file Task A creates
114
- - Task B imports something Task A defines
115
- - Task B's test relies on Task A's implementation
116
- ```
117
-
118
- #### Parallel Execution (Fire-and-Check Pattern)
119
-
120
- The executor uses a **fire-and-check** pattern for maximum parallelism:
121
-
122
- 1. **Fire** - Launch all implementers as `background_task` in ONE message
123
- 2. **Poll** - Check `background_list` for completions
124
- 3. **React** - Start reviewer immediately when each implementer finishes
125
- 4. **Repeat** - Continue polling until batch complete
126
-
127
- ```
128
- Plan with 6 tasks:
129
- ├── Batch 1 (parallel): Tasks 1, 2, 3 → independent, different files
130
- │ │
131
- │ │ FIRE: background_task(agent="implementer") x3
132
- │ │
133
- │ │ POLL: background_list() → task 2 completed!
134
- │ │ → background_output(task_2)
135
- │ │ → background_task(agent="reviewer", "Review task 2")
136
- │ │
137
- │ │ POLL: background_list() → tasks 1, 3 completed!
138
- │ │ → start reviewers for 1 and 3
139
- │ │
140
- │ │ [continue until all reviewed]
141
-
142
- └── Batch 2 (parallel): Tasks 4, 5, 6 → depend on batch 1
143
- └── [same pattern]
144
- ```
145
-
146
- Key: Reviewers start **immediately** when their implementer finishes - no waiting for the whole batch.
147
-
148
- #### Per-Task Cycle
149
-
150
- Each task gets its own implement→review loop:
151
-
152
- 1. Fire implementer via `background_task`
153
- 2. Implementer: make changes → run tests → **commit** if passing
154
- 3. Fire reviewer to check implementation
155
- 4. If changes requested → fire new implementer (max 3 cycles)
156
- 5. Mark as DONE or BLOCKED
157
-
158
- **Note:** Implementer commits after verification passes, using the commit message from the plan.
159
-
160
- ### 4. Session Continuity
161
-
162
- Maintain context across long sessions and context clears with structured compaction:
163
-
164
- #### Ledger System
165
-
166
- The **continuity ledger** serves as both session state and compaction summary. Based on [Factory.ai's structured compaction research](https://factory.ai/blog/context-compression), which found that structured summarization with deterministic file tracking retains more useful context.
167
-
168
- ```
169
- /ledger
170
- ```
171
-
172
- Creates/updates `thoughts/ledgers/CONTINUITY_{session-name}.md` with:
173
-
174
- ```markdown
175
- # Session: {name}
176
- Updated: {timestamp}
177
-
178
- ## Goal
179
- ## Constraints
180
- ## Progress
181
- ### Done
182
- - [x] {Completed items}
183
- ### In Progress
184
- - [ ] {Current work}
185
- ### Blocked
186
- - {Issues, if any}
187
- ## Key Decisions
188
- - **{Decision}**: {Rationale}
189
- ## Next Steps
190
- 1. {Ordered list}
191
- ## File Operations
192
- ### Read
193
- - `{paths read since last compaction}`
194
- ### Modified
195
- - `{paths written/edited since last compaction}`
196
- ## Critical Context
197
- - {Data, examples, references needed to continue}
198
- ```
199
-
200
- **Key features:**
201
-
202
- - **Iterative merging** - Updates preserve existing information, adding new progress rather than regenerating from scratch
203
- - **Deterministic file tracking** - Read/write/edit operations tracked automatically via tool call interception, not LLM extraction
204
- - **Auto-injection** - Most recent ledger injected into system prompt on session start
28
+ ### Brainstorm
29
+ Refine ideas into designs through collaborative questioning. Fires research subagents in parallel. Output: `thoughts/shared/designs/YYYY-MM-DD-{topic}-design.md`
205
30
 
206
- **Auto-clear:** At 80% context usage, the system automatically:
207
- 1. Captures file operations tracked since last clear
208
- 2. Updates ledger with current state (iterative merge with previous)
209
- 3. Clears the session
210
- 4. Injects the updated ledger into fresh context
31
+ ### Plan
32
+ Transform designs into implementation plans with bite-sized tasks (2-5 min each), exact file paths, and TDD workflow. Output: `thoughts/shared/plans/YYYY-MM-DD-{topic}.md`
211
33
 
212
- #### Artifact Search
34
+ ### Implement
35
+ Execute in git worktree for isolation. The **Executor** orchestrates implementer→reviewer cycles with parallel execution via fire-and-check pattern.
213
36
 
214
- Search past work to find relevant precedent:
215
-
216
- ```
217
- /search oauth authentication
218
- /search JWT tokens
219
- ```
220
-
221
- Searches across:
222
- - Ledgers (`thoughts/ledgers/`)
223
- - Plans (`thoughts/shared/plans/`)
224
-
225
- **Auto-indexing:** Artifacts are automatically indexed when created.
37
+ ### Session Continuity
38
+ Maintain context across sessions with structured compaction. Run `/ledger` to create/update `thoughts/ledgers/CONTINUITY_{session}.md`. Auto-clears at 60% context usage.
226
39
 
227
40
  ## Commands
228
41
 
229
42
  | Command | Description |
230
43
  |---------|-------------|
231
- | `/init` | Initialize project with ARCHITECTURE.md and CODE_STYLE.md |
232
- | `/ledger` | Create or update continuity ledger for session state |
44
+ | `/init` | Initialize project docs |
45
+ | `/ledger` | Create/update continuity ledger |
233
46
  | `/search` | Search past plans and ledgers |
234
47
 
235
48
  ## Agents
236
49
 
237
- | Agent | Mode | Model | Purpose |
238
- |-------|------|-------|---------|
239
- | commander | primary | claude-opus-4-5 | Orchestrator, delegates to specialists |
240
- | brainstormer | primary | claude-opus-4-5 | Design exploration through questioning |
241
- | project-initializer | subagent | claude-opus-4-5 | Generate ARCHITECTURE.md and CODE_STYLE.md |
242
- | codebase-locator | subagent | claude-sonnet | Find file locations |
243
- | codebase-analyzer | subagent | claude-sonnet | Deep code analysis |
244
- | pattern-finder | subagent | claude-sonnet | Find existing patterns |
245
- | planner | subagent | claude-opus-4-5 | Create detailed implementation plans |
246
- | executor | subagent | claude-opus-4-5 | Orchestrate implement review cycle |
247
- | implementer | subagent | claude-opus-4-5 | Execute implementation tasks |
248
- | reviewer | subagent | claude-opus-4-5 | Review correctness and style |
249
- | ledger-creator | subagent | claude-sonnet | Create/update continuity ledgers |
250
- | artifact-searcher | subagent | claude-sonnet | Search past work for precedent |
50
+ | Agent | Purpose |
51
+ |-------|---------|
52
+ | commander | Orchestrator |
53
+ | brainstormer | Design exploration |
54
+ | planner | Implementation plans |
55
+ | executor | Orchestrate implement→review |
56
+ | implementer | Execute tasks |
57
+ | reviewer | Check correctness |
58
+ | codebase-locator | Find file locations |
59
+ | codebase-analyzer | Deep code analysis |
60
+ | pattern-finder | Find existing patterns |
61
+ | project-initializer | Generate project docs |
62
+ | ledger-creator | Continuity ledgers |
63
+ | artifact-searcher | Search past work |
251
64
 
252
65
  ## Tools
253
66
 
@@ -255,147 +68,67 @@ Searches across:
255
68
  |------|-------------|
256
69
  | `ast_grep_search` | AST-aware code pattern search |
257
70
  | `ast_grep_replace` | AST-aware code pattern replacement |
258
- | `look_at` | Extract file structure for large files |
259
- | `artifact_search` | Search past plans and ledgers |
260
- | `btca_ask` | Query library source code (requires btca CLI) |
261
- | `background_task` | Fire subagent to run in background, returns task_id |
262
- | `background_list` | List all tasks and status (use to poll for completion) |
263
- | `background_output` | Get results from completed task |
264
- | `background_cancel` | Cancel running task(s) |
265
-
266
- ### Background Task Pattern
267
-
268
- All agents use the **fire-poll-collect** pattern for parallel work:
269
-
270
- ```
271
- # FIRE: Launch all in ONE message
272
- task_1 = background_task(agent="locator", prompt="...")
273
- task_2 = background_task(agent="analyzer", prompt="...")
274
-
275
- # POLL: Check until complete
276
- background_list() # repeat until all show "completed"
277
-
278
- # COLLECT: Get results
279
- background_output(task_id=task_1)
280
- background_output(task_id=task_2)
281
- ```
71
+ | `look_at` | Extract file structure |
72
+ | `artifact_search` | Search past plans/ledgers |
73
+ | `btca_ask` | Query library source code |
74
+ | `background_task` | Fire subagent in background |
75
+ | `background_list` | List tasks and status |
76
+ | `background_output` | Get task results |
77
+ | `background_cancel` | Cancel task(s) |
78
+ | `pty_spawn` | Start background terminal session |
79
+ | `pty_write` | Send input to PTY |
80
+ | `pty_read` | Read PTY output |
81
+ | `pty_list` | List PTY sessions |
82
+ | `pty_kill` | Terminate PTY |
83
+
84
+ ### Background Tasks vs PTY
85
+
86
+ | System | Purpose | Use Case |
87
+ |--------|---------|----------|
88
+ | `background_task` | Async AI subagents | Research, implementation, reviews |
89
+ | `pty_spawn` | Async bash processes | Dev servers, watch modes, REPLs |
282
90
 
283
91
  ## Hooks
284
92
 
285
- | Hook | Description |
286
- |------|-------------|
287
- | Think Mode | Keywords like "think hard" enable 32k token thinking budget |
288
- | Ledger Loader | Injects continuity ledger into system prompt |
289
- | Auto-Clear Ledger | At 80% context, saves ledger with file ops and clears session |
290
- | File Ops Tracker | Tracks read/write/edit tool calls for deterministic file operation logging |
291
- | Artifact Auto-Index | Indexes artifacts when written to thoughts/ directories |
292
- | Auto-Compact | Summarizes session when hitting token limits |
293
- | Context Injector | Injects ARCHITECTURE.md, CODE_STYLE.md, .cursorrules |
294
- | Token-Aware Truncation | Truncates large tool outputs |
295
- | Context Window Monitor | Tracks token usage |
296
- | Comment Checker | Validates edit tool comments |
297
- | Session Recovery | Recovers from crashes |
298
-
299
- ## Permissions
300
-
301
- All permissions are set to `allow` globally - no prompts for tool usage:
302
-
303
- ```typescript
304
- config.permission = {
305
- edit: "allow",
306
- bash: "allow",
307
- webfetch: "allow",
308
- doom_loop: "allow",
309
- external_directory: "allow",
310
- };
311
- ```
312
-
313
- This enables subagents to work autonomously without getting stuck on permission prompts.
314
-
315
- ## MCP Servers
316
-
317
- | Server | Description | Activation |
318
- |--------|-------------|------------|
319
- | context7 | Documentation lookup | Always enabled |
320
- | perplexity | Web search | Set `PERPLEXITY_API_KEY` |
321
- | firecrawl | Web crawling | Set `FIRECRAWL_API_KEY` |
322
-
323
- ## Structure
324
-
325
- ```
326
- micode/
327
- ├── src/
328
- │ ├── agents/ # Agent definitions
329
- │ ├── tools/ # ast-grep, look-at, artifact-search, background-task
330
- │ ├── hooks/ # Session management hooks
331
- │ └── index.ts # Plugin entry
332
- ├── dist/ # Built plugin
333
- └── thoughts/ # Artifacts (gitignored)
334
- ├── ledgers/ # Continuity ledgers
335
- └── shared/
336
- ├── designs/ # Brainstorm outputs
337
- └── plans/ # Implementation plans
338
- ```
93
+ - **Think Mode** - Keywords like "think hard" enable 32k token thinking budget
94
+ - **Ledger Loader** - Injects continuity ledger into system prompt
95
+ - **Auto-Clear Ledger** - At 60% context, saves ledger and clears session
96
+ - **File Ops Tracker** - Tracks read/write/edit for deterministic logging
97
+ - **Artifact Auto-Index** - Indexes artifacts in thoughts/ directories
98
+ - **Context Injector** - Injects ARCHITECTURE.md, CODE_STYLE.md
99
+ - **Token-Aware Truncation** - Truncates large tool outputs
339
100
 
340
101
  ## Development
341
102
 
342
- ### From source
343
-
344
103
  ```bash
345
104
  git clone git@github.com:vtemian/micode.git ~/.micode
346
- cd ~/.micode
347
- bun install
348
- bun run build
105
+ cd ~/.micode && bun install && bun run build
349
106
  ```
350
107
 
351
- Then use local path in config:
352
108
  ```json
353
- {
354
- "plugin": ["~/.micode"]
355
- }
356
- ```
357
-
358
- ### Commands
359
-
360
- ```bash
361
- bun install # Install dependencies
362
- bun run build # Build plugin
363
- bun run typecheck # Type check
364
- bun test # Run tests
365
- bun test --watch # Run tests in watch mode
109
+ // Use local path
110
+ { "plugin": ["~/.micode"] }
366
111
  ```
367
112
 
368
113
  ### Release
369
114
 
370
- Releases are automated via GitHub Actions. To publish a new version:
371
-
372
115
  ```bash
373
116
  npm version patch # or minor, major
374
117
  git push --follow-tags
375
118
  ```
376
119
 
377
- This triggers the release workflow which publishes to npm.
378
-
379
- **Manual publish** (first time or if needed):
380
- ```bash
381
- npm login
382
- npm publish
383
- ```
384
-
385
120
  ## Philosophy
386
121
 
387
122
  1. **Brainstorm first** - Refine ideas before coding
388
123
  2. **Research before implementing** - Understand the codebase
389
124
  3. **Plan with human buy-in** - Get approval before coding
390
- 4. **Parallel investigation** - Spawn multiple subagents for speed
391
- 5. **Isolated implementation** - Use git worktrees for features
392
- 6. **Continuous verification** - Implementer + Reviewer per phase
393
- 7. **Session continuity** - Never lose context across clears
125
+ 4. **Parallel investigation** - Spawn multiple subagents
126
+ 5. **Isolated implementation** - Use git worktrees
127
+ 6. **Continuous verification** - Implementer + Reviewer per task
128
+ 7. **Session continuity** - Never lose context
394
129
 
395
130
  ## Inspiration
396
131
 
397
- Built on techniques from:
398
-
399
- - **[oh-my-opencode](https://github.com/code-yeongyu/oh-my-opencode)** - OpenCode plugin architecture, agent orchestration patterns, and trusted publishing setup
400
- - **[HumanLayer ACE-FCA](https://github.com/humanlayer/12-factor-agents)** - Advanced Context Engineering for Coding Agents, structured workflows, and the research → plan → implement methodology
401
- - **[Factory.ai Context Compression](https://factory.ai/blog/context-compression)** - Structured compaction research showing that anchored iterative summarization with deterministic file tracking outperforms generic compression
132
+ - [oh-my-opencode](https://github.com/code-yeongyu/oh-my-opencode) - Plugin architecture
133
+ - [HumanLayer ACE-FCA](https://github.com/humanlayer/12-factor-agents) - Structured workflows
134
+ - [Factory.ai](https://factory.ai/blog/context-compression) - Structured compaction research
@@ -1,5 +1,5 @@
1
1
  import type { PluginInput } from "@opencode-ai/plugin";
2
- export declare const DEFAULT_THRESHOLD = 0.8;
2
+ export declare const DEFAULT_THRESHOLD = 0.6;
3
3
  export declare const CLEAR_COOLDOWN_MS = 60000;
4
4
  export declare function createAutoClearLedgerHook(ctx: PluginInput): {
5
5
  event: ({ event }: {