opencodekit 0.22.0 → 0.23.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.
Files changed (71) hide show
  1. package/README.md +1 -1
  2. package/dist/index.js +4 -25
  3. package/dist/template/.opencode/.template-manifest.json +115 -188
  4. package/dist/template/.opencode/AGENTS.md +18 -4
  5. package/dist/template/.opencode/README.md +1 -1
  6. package/dist/template/.opencode/agent/build.md +155 -13
  7. package/dist/template/.opencode/agent/plan.md +7 -16
  8. package/dist/template/.opencode/agent/scout.md +2 -2
  9. package/dist/template/.opencode/artifacts/.active +1 -0
  10. package/dist/template/.opencode/artifacts/example/plan.md +12 -0
  11. package/dist/template/.opencode/artifacts/example/progress.md +4 -0
  12. package/dist/template/.opencode/artifacts/example/research.md +4 -0
  13. package/dist/template/.opencode/artifacts/example/spec.md +16 -0
  14. package/dist/template/.opencode/artifacts/todo.md +5 -0
  15. package/dist/template/.opencode/artifacts/verify.log +4 -0
  16. package/dist/template/.opencode/command/clarify.md +6 -8
  17. package/dist/template/.opencode/command/create.md +29 -71
  18. package/dist/template/.opencode/command/design.md +1 -2
  19. package/dist/template/.opencode/command/explore.md +3 -4
  20. package/dist/template/.opencode/command/fix.md +0 -1
  21. package/dist/template/.opencode/command/init.md +1 -4
  22. package/dist/template/.opencode/command/plan.md +30 -60
  23. package/dist/template/.opencode/command/pr.md +10 -28
  24. package/dist/template/.opencode/command/refactor.md +0 -1
  25. package/dist/template/.opencode/command/research.md +7 -29
  26. package/dist/template/.opencode/command/review-codebase.md +6 -13
  27. package/dist/template/.opencode/command/ship.md +136 -78
  28. package/dist/template/.opencode/command/ui-review.md +2 -4
  29. package/dist/template/.opencode/command/verify.md +15 -23
  30. package/dist/template/.opencode/dcp.jsonc +96 -96
  31. package/dist/template/.opencode/memory/README.md +1 -1
  32. package/dist/template/.opencode/memory/_templates/prd.md +1 -1
  33. package/dist/template/.opencode/memory/_templates/roadmap.md +1 -1
  34. package/dist/template/.opencode/memory/_templates/state.md +1 -1
  35. package/dist/template/.opencode/memory/project/gotchas.md +3 -3
  36. package/dist/template/.opencode/memory/project/project.md +2 -2
  37. package/dist/template/.opencode/memory/project/roadmap.md +1 -1
  38. package/dist/template/.opencode/memory/project/state.md +2 -2
  39. package/dist/template/.opencode/memory/project/tech-stack.md +2 -2
  40. package/dist/template/.opencode/opencode.json +14 -152
  41. package/dist/template/.opencode/plugin/README.md +1 -1
  42. package/dist/template/.opencode/skill/brainstorming/SKILL.md +1 -1
  43. package/dist/template/.opencode/skill/context-engineering/SKILL.md +1 -1
  44. package/dist/template/.opencode/skill/development-lifecycle/SKILL.md +26 -45
  45. package/dist/template/.opencode/skill/gemini-large-context/SKILL.md +4 -4
  46. package/dist/template/.opencode/skill/opensrc/references/example-workflow.md +1 -1
  47. package/dist/template/.opencode/skill/subagent-driven-development/SKILL.md +1 -1
  48. package/dist/template/.opencode/skill/using-git-worktrees/SKILL.md +6 -6
  49. package/dist/template/.opencode/skill/verification-before-completion/SKILL.md +6 -6
  50. package/dist/template/.opencode/skill/verification-before-completion/references/VERIFICATION_PROTOCOL.md +5 -5
  51. package/package.json +76 -76
  52. package/dist/template/.opencode/plans/1768385996691-silent-wizard.md +0 -247
  53. package/dist/template/.opencode/plans/1770006237537-mighty-otter.md +0 -418
  54. package/dist/template/.opencode/plans/1770006913647-glowing-forest.md +0 -170
  55. package/dist/template/.opencode/plans/1770013678126-witty-planet.md +0 -278
  56. package/dist/template/.opencode/plans/1770112267595-shiny-rocket.md +0 -258
  57. package/dist/template/.opencode/plans/swarm-protocol.md +0 -123
  58. package/dist/template/.opencode/skill/beads/SKILL.md +0 -182
  59. package/dist/template/.opencode/skill/beads/references/BEST_PRACTICES.md +0 -27
  60. package/dist/template/.opencode/skill/beads/references/BOUNDARIES.md +0 -219
  61. package/dist/template/.opencode/skill/beads/references/DEPENDENCIES.md +0 -124
  62. package/dist/template/.opencode/skill/beads/references/EXAMPLES.md +0 -45
  63. package/dist/template/.opencode/skill/beads/references/FILE_CLAIMING.md +0 -101
  64. package/dist/template/.opencode/skill/beads/references/GIT_SYNC.md +0 -25
  65. package/dist/template/.opencode/skill/beads/references/HIERARCHY.md +0 -71
  66. package/dist/template/.opencode/skill/beads/references/MULTI_AGENT.md +0 -40
  67. package/dist/template/.opencode/skill/beads/references/RESUMABILITY.md +0 -177
  68. package/dist/template/.opencode/skill/beads/references/SESSION_PROTOCOL.md +0 -61
  69. package/dist/template/.opencode/skill/beads/references/TASK_CREATION.md +0 -38
  70. package/dist/template/.opencode/skill/beads/references/TROUBLESHOOTING.md +0 -38
  71. package/dist/template/.opencode/skill/beads/references/WORKFLOWS.md +0 -226
@@ -1,170 +0,0 @@
1
- # Plan: Implement `/create` Command for Bead Artifacts
2
-
3
- ## Summary
4
-
5
- Implement a new CLI command `ock create <bead-id>` that creates structured artifacts for beads using templates. This command will set up the artifact directory structure and copy appropriate templates (spec.md, prd.md, or proposal.md) based on flags.
6
-
7
- ## Phases
8
-
9
- ### Phase 1: Create Command Implementation
10
-
11
- **Owner**: @build
12
- **Deliverable**: `src/commands/create.ts` file
13
- **Files to Create**:
14
-
15
- - `src/commands/create.ts` - Main command implementation
16
-
17
- **Implementation Details**:
18
-
19
- The command follows the established pattern from `skill.ts` and `command.ts`:
20
-
21
- 1. **Argument Parsing**:
22
- - `<bead-id>` (required) - The bead to create artifacts for
23
- - `--prd` flag - Use PRD template (combined format)
24
- - `--proposal` flag - Create proposal.md first (for epics)
25
-
26
- 2. **Validation**:
27
- - Check if `.opencode/` exists (project initialized)
28
- - Check if `.beads/` exists (beads initialized)
29
- - Validate bead-id format (lowercase, alphanumeric, hyphens)
30
- - Check if artifact directory already exists
31
-
32
- 3. **Directory Structure**:
33
- - Create `.beads/artifacts/<bead-id>/` directory
34
- - Copy templates from `.opencode/memory/_templates/`
35
-
36
- 4. **Template Selection Logic**:
37
- | Flag | Template(s) Created |
38
- |------|---------------------|
39
- | (none) | spec.md |
40
- | `--prd` | prd.md |
41
- | `--proposal` | proposal.md + spec.md |
42
-
43
- 5. **Template Variable Substitution**:
44
- - Replace `[bead-id]` with actual bead ID
45
- - Replace `[date]` with current date (YYYY-MM-DD)
46
- - Replace `[YYYY-MM-DD]` with current date
47
-
48
- 6. **Interactive Prompts** (when no flags):
49
- - Ask for bead title/description if not provided
50
- - Ask for template type preference
51
-
52
- **Validation Steps**:
53
-
54
- - Run `npm run typecheck` - TypeScript compiles without errors
55
- - Run `npm run lint` - No linting errors
56
-
57
- ### Phase 2: Register Command in CLI
58
-
59
- **Owner**: @build
60
- **Deliverable**: Updated `src/index.ts`
61
- **Files to Modify**:
62
-
63
- - `src/index.ts` - Add command registration
64
-
65
- **Changes**:
66
-
67
- 1. Import `createCommand` from `./commands/create.js`
68
- 2. Register CLI command:
69
- ```typescript
70
- cli
71
- .command("create <bead-id>", "Create structured artifacts for a bead")
72
- .option("--prd", "Use PRD template (combined format)")
73
- .option("--proposal", "Create proposal.md first (for epics)")
74
- .action(createCommand);
75
- ```
76
-
77
- **Validation Steps**:
78
-
79
- - Run `tsx src/index.ts create --help` - Shows help text
80
- - Run `npm run typecheck` - No type errors
81
-
82
- ### Phase 3: Testing
83
-
84
- **Owner**: @build
85
- **Deliverable**: Verified command works end-to-end
86
-
87
- **Test Cases**:
88
-
89
- 1. **Basic spec creation**:
90
-
91
- ```bash
92
- ock create test-bead-123
93
- # Expected: Creates .beads/artifacts/test-bead-123/spec.md
94
- ```
95
-
96
- 2. **PRD template**:
97
-
98
- ```bash
99
- ock create test-bead-456 --prd
100
- # Expected: Creates .beads/artifacts/test-bead-456/prd.md
101
- ```
102
-
103
- 3. **Proposal template**:
104
-
105
- ```bash
106
- ock create test-epic-789 --proposal
107
- # Expected: Creates .beads/artifacts/test-epic-789/proposal.md AND spec.md
108
- ```
109
-
110
- 4. **Error cases**:
111
- - Missing bead-id: Shows usage help
112
- - Invalid bead-id format: Shows validation error
113
- - Project not initialized: Shows "Run: ock init" error
114
- - Beads not initialized: Shows warning
115
- - Artifact already exists: Shows confirmation prompt
116
-
117
- **Validation Steps**:
118
-
119
- - Run `vitest src/commands/create.test.ts` (if test file created)
120
- - Manual testing of all scenarios above
121
-
122
- ## Dependencies
123
-
124
- - Phase 2 depends on Phase 1 completion
125
- - Phase 3 depends on Phase 2 completion
126
-
127
- ## Risks
128
-
129
- | Risk | Likelihood | Impact | Mitigation |
130
- | ------------------------------ | ---------- | ------ | -------------------------------------------------------------- |
131
- | Template files not found | Low | High | Check template existence, show clear error with fix suggestion |
132
- | Bead ID validation too strict | Medium | Low | Allow common formats, provide clear validation messages |
133
- | Overwriting existing artifacts | Low | High | Check before creating, prompt for confirmation |
134
-
135
- ## Acceptance Criteria
136
-
137
- - [ ] `ock create <bead-id>` creates `.beads/artifacts/<bead-id>/spec.md` from template
138
- - [ ] `ock create <bead-id> --prd` creates `prd.md` instead
139
- - [ ] `ock create <bead-id> --proposal` creates both `proposal.md` and `spec.md`
140
- - [ ] Template variables (bead-id, date) are substituted correctly
141
- - [ ] Validates project is initialized (`.opencode/` exists)
142
- - [ ] Validates beads is initialized (`.beads/` exists) or warns
143
- - [ ] Shows clear error for invalid bead-id format
144
- - [ ] Prompts for confirmation if artifacts already exist
145
- - [ ] TypeScript compiles without errors (`npm run typecheck`)
146
- - [ ] No linting errors (`npm run lint`)
147
- - [ ] Command appears in `ock --help` output
148
-
149
- ## Critical Files to Modify
150
-
151
- | File | Purpose |
152
- | ------------------------ | -------------------------- |
153
- | `src/commands/create.ts` | New command implementation |
154
- | `src/index.ts` | CLI registration |
155
-
156
- ## Templates Used
157
-
158
- | Template | Path |
159
- | ----------- | ----------------------------------------- |
160
- | spec.md | `.opencode/memory/_templates/spec.md` |
161
- | prd.md | `.opencode/memory/_templates/prd.md` |
162
- | proposal.md | `.opencode/memory/_templates/proposal.md` |
163
-
164
- ## Notes
165
-
166
- - Follow existing command patterns from `skill.ts` and `command.ts`
167
- - Use `@clack/prompts` for interactive elements
168
- - Use `picocolors` for styling
169
- - Reuse error utilities from `src/utils/errors.ts`
170
- - Bead ID validation: lowercase letters, numbers, hyphens (start with letter)
@@ -1,278 +0,0 @@
1
- # Plan: Implement `/init` Command for OpenCodeKit
2
-
3
- ## Summary
4
-
5
- Implement the `/init` slash command that provides one-command project onboarding. This command creates project-root `AGENTS.md` and populates memory files with detected project information. The command is defined in `.opencode/command/init.md` and executed by the `@plan` agent.
6
-
7
- ## Current State
8
-
9
- - **CLI `ock init`**: Already exists in `src/commands/init.ts` - bootstraps `.opencode/` directory
10
- - **Slash `/init`**: Defined in `.opencode/command/init.md` - AI-assisted project analysis workflow
11
- - **Templates**: Exist in `.opencode/memory/_templates/` (user.md, tech-stack.md)
12
- - **Memory system**: SQLite-based with tools in `.opencode/tool/`
13
-
14
- ## Phases
15
-
16
- ### Phase 1: Verify Command Registration
17
-
18
- **Owner**: @build
19
- **Deliverable**: Ensure `/init` command is properly registered and accessible
20
- **Files**:
21
-
22
- - `.opencode/command/init.md` (exists, verify content)
23
- - `.opencode/opencode.json` (verify command registration)
24
-
25
- **Validation**:
26
-
27
- - [ ] Command appears in `ock command list`
28
- - [ ] Command has correct frontmatter (agent: plan, subtask: true)
29
- - [ ] Command description is accurate
30
-
31
- ### Phase 2: Enhance Project Detection Logic
32
-
33
- **Owner**: @build
34
- **Deliverable**: Robust project detection with comprehensive tech stack identification
35
- **Files**:
36
-
37
- - `.opencode/command/init.md` (enhance Phase 2 section)
38
- - Create utility functions for detection if needed
39
-
40
- **Implementation Details**:
41
-
42
- 1. Detect tech stack from:
43
- - `package.json` → Node.js/Bun/JavaScript projects
44
- - `go.mod` → Go projects
45
- - `pyproject.toml`, `requirements.txt` → Python projects
46
- - `Cargo.toml` → Rust projects
47
- - `composer.json` → PHP projects
48
- - `Gemfile` → Ruby projects
49
- - `pom.xml`, `build.gradle` → Java projects
50
-
51
- 2. Extract key information:
52
- - Language & version
53
- - Framework & version
54
- - Build tool
55
- - Test command
56
- - Lint command
57
- - Key dependencies
58
-
59
- 3. Validate commands by attempting to run them
60
-
61
- **Validation**:
62
-
63
- - [ ] Correctly detects this project's stack (Bun, TypeScript)
64
- - [ ] Correctly detects various project types in test scenarios
65
- - [ ] Command validation works (build, test, lint)
66
-
67
- ### Phase 3: Implement AGENTS.md Generation
68
-
69
- **Owner**: @build
70
- **Deliverable**: Template-based AGENTS.md generation with project-specific content
71
- **Files**:
72
-
73
- - `.opencode/command/init.md` (enhance Phase 3 section)
74
- - Potentially create template files
75
-
76
- **Implementation Details**:
77
-
78
- 1. Create AGENTS.md template structure:
79
- - Project name (from package.json or directory name)
80
- - Tech stack section (from Phase 2 detection)
81
- - File structure section
82
- - Commands section (validated commands)
83
- - Code examples section (extract from actual codebase)
84
- - Testing section
85
- - Boundaries section (Always/Ask First/Never rules)
86
- - Gotchas section
87
-
88
- 2. Target: <60 lines (max 150 lines)
89
-
90
- 3. If AGENTS.md exists:
91
- - Read existing content
92
- - Merge/improve rather than overwrite
93
- - Preserve user-added sections
94
-
95
- **Validation**:
96
-
97
- - [ ] Generated AGENTS.md is <60 lines
98
- - [ ] Contains accurate tech stack
99
- - [ ] Commands are validated and working
100
- - [ ] Includes at least one code example from codebase
101
- - [ ] Has proper Boundaries section with Never rules
102
-
103
- ### Phase 4: Implement Memory File Population
104
-
105
- **Owner**: @build
106
- **Deliverable**: Populate `.opencode/memory/project/user.md` and `tech-stack.md`
107
- **Files**:
108
-
109
- - `.opencode/command/init.md` (enhance Phase 5 section)
110
- - `.opencode/memory/_templates/user.md`
111
- - `.opencode/memory/_templates/tech-stack.md`
112
-
113
- **Implementation Details**:
114
-
115
- 1. Load templates from `_templates/`
116
-
117
- 2. Populate `user.md` from Phase 1 answers:
118
- - Identity (name, git contributor)
119
- - Communication preferences (terse/detailed)
120
- - Workflow preferences (auto-commit/ask-first)
121
- - Custom rules
122
-
123
- 3. Populate `tech-stack.md` from Phase 2 detection:
124
- - Framework & version
125
- - Language & runtime
126
- - Key dependencies with versions
127
- - Key constraints
128
- - Active integrations
129
-
130
- **Validation**:
131
-
132
- - [ ] user.md created with accurate information
133
- - [ ] tech-stack.md created with detected stack
134
- - [ ] Templates are properly used as base
135
-
136
- ### Phase 5: Implement Optional Beads Initialization
137
-
138
- **Owner**: @build
139
- **Deliverable**: Initialize `.beads/` directory when user opts in
140
- **Files**:
141
-
142
- - `.opencode/command/init.md` (enhance Phase 6 section)
143
-
144
- **Implementation Details**:
145
-
146
- 1. If user says yes to beads:
147
- - Run `br init` if available
148
- - Or create basic structure manually:
149
- - `.beads/config.yaml`
150
- - `.beads/issues.jsonl`
151
- - `.beads/metadata.json`
152
-
153
- **Validation**:
154
-
155
- - [ ] Beads initializes correctly when requested
156
- - [ ] No errors if beads already exists
157
-
158
- ### Phase 6: Add --deep Mode Support
159
-
160
- **Owner**: @build
161
- **Deliverable**: Comprehensive research mode with subsystem detection
162
- **Files**:
163
-
164
- - `.opencode/command/init.md` (enhance Phase 4 section)
165
-
166
- **Implementation Details**:
167
-
168
- 1. When `--deep` flag is passed:
169
- - Git history analysis (contributors, commit conventions)
170
- - Branching strategy detection
171
- - Source file pattern analysis
172
- - Subsystem identification for nested AGENTS.md
173
-
174
- 2. Suggest nested AGENTS.md for:
175
- - `packages/*/` in monorepos
176
- - `src/` vs `tests/` if patterns differ
177
- - `frontend/` vs `backend/` directories
178
-
179
- **Validation**:
180
-
181
- - [ ] --deep flag triggers additional research
182
- - [ ] Subsystem detection works for monorepos
183
- - [ ] Suggestions are relevant and actionable
184
-
185
- ### Phase 7: Testing & Validation
186
-
187
- **Owner**: @build
188
- **Deliverable**: End-to-end testing of the `/init` command
189
- **Files**:
190
-
191
- - Test in a fresh project directory
192
- - Test in existing project with AGENTS.md
193
- - Test with --deep flag
194
-
195
- **Test Scenarios**:
196
-
197
- 1. Fresh project (no AGENTS.md):
198
- - [ ] Asks upfront questions
199
- - [ ] Detects tech stack correctly
200
- - [ ] Creates AGENTS.md
201
- - [ ] Populates memory files
202
- - [ ] Shows completion summary
203
-
204
- 2. Existing project (with AGENTS.md):
205
- - [ ] Reads existing AGENTS.md
206
- - [ ] Merges/improves rather than overwriting
207
- - [ ] Preserves user content
208
-
209
- 3. With --deep flag:
210
- - [ ] Performs git analysis
211
- - [ ] Detects subsystems
212
- - [ ] Suggests nested AGENTS.md
213
-
214
- 4. With --skip-questions:
215
- - [ ] Skips upfront questions
216
- - [ ] Infers identity from git config
217
-
218
- **Validation**:
219
-
220
- - [ ] All test scenarios pass
221
- - [ ] Generated files are valid and useful
222
- - [ ] Command completes without errors
223
-
224
- ## Dependencies
225
-
226
- - Phase 2 depends on Phase 1 (command registration verification)
227
- - Phase 3 depends on Phase 2 (tech stack detection)
228
- - Phase 4 depends on Phase 1 (templates exist) and Phase 2 (detection data)
229
- - Phase 5 is independent but uses Phase 1 answers
230
- - Phase 6 is optional enhancement
231
- - Phase 7 depends on all previous phases
232
-
233
- ## Risks
234
-
235
- | Risk | Likelihood | Impact | Mitigation |
236
- | ------------------------------------------------- | ---------- | ------ | ---------------------------------------------------- |
237
- | Command detection fails for exotic project types | Medium | Medium | Fallback to generic templates, allow manual override |
238
- | AGENTS.md generation produces stale code examples | Low | Medium | Use pointers instead of inline code where possible |
239
- | Memory file templates change structure | Low | Low | Version templates, update command accordingly |
240
- | User preferences not captured correctly | Low | Medium | Validate with user before writing files |
241
- | --deep mode takes too long | Medium | Low | Add progress indicators, allow cancellation |
242
-
243
- ## Acceptance Criteria
244
-
245
- - [ ] `/init` command is accessible and runs without errors
246
- - [ ] Creates `./AGENTS.md` with project-specific information (<60 lines target)
247
- - [ ] Populates `.opencode/memory/project/user.md` with user preferences
248
- - [ ] Populates `.opencode/memory/project/tech-stack.md` with detected stack
249
- - [ ] Validates commands (build, test, lint) actually work
250
- - [ ] Handles existing AGENTS.md gracefully (merges/improves)
251
- - [ ] Supports `--deep` flag for comprehensive analysis
252
- - [ ] Supports `--skip-questions` flag for non-interactive use
253
- - [ ] Optional beads initialization works
254
- - [ ] Shows clear completion summary with next steps
255
-
256
- ## Questions
257
-
258
- 1. Should we add a `--dry-run` flag to preview what would be created without writing files?
259
- 2. Should we support importing from existing `.cursorrules` or `.github/copilot-instructions.md` files?
260
- 3. Should the command suggest running `/review-codebase` after initialization?
261
-
262
- ## Implementation Notes
263
-
264
- The `/init` command is already defined in `.opencode/command/init.md`. The implementation involves:
265
-
266
- 1. **Verifying** the command definition is complete and accurate
267
- 2. **Enhancing** the command instructions with robust detection logic
268
- 3. **Testing** the command end-to-end in various scenarios
269
-
270
- The command uses the `@plan` agent (subtask: true) which means it runs as a separate planning task. The instructions in the markdown file guide the AI through the 8-phase process.
271
-
272
- Key files to verify/modify:
273
-
274
- - `.opencode/command/init.md` - Main command definition
275
- - `.opencode/memory/_templates/user.md` - User profile template
276
- - `.opencode/memory/_templates/tech-stack.md` - Tech stack template
277
-
278
- No new CLI commands needed - this is a slash command enhancement.
@@ -1,258 +0,0 @@
1
- # Plan: Patch-Package Style Feature for Template File Modifications
2
-
3
- ## Summary
4
-
5
- Add a patch system that preserves user modifications to template files across upgrades. When users edit built-in skills, commands, agents, or tools, their changes are saved as patches and automatically reapplied after template updates.
6
-
7
- ## Problem
8
-
9
- ```
10
- User edits .opencode/skill/beads/skill.md (built-in template file)
11
- User runs `ock upgrade`
12
- → Current behavior: Template file overwrites OR user version preserved forever (never gets template updates)
13
- → User loses customizations OR misses template improvements
14
- ```
15
-
16
- ## Solution
17
-
18
- Save user modifications as unified diff patches. On upgrade:
19
-
20
- 1. Apply new template files
21
- 2. Automatically reapply user patches
22
- 3. Handle conflicts gracefully
23
-
24
- ---
25
-
26
- ## File Structure
27
-
28
- ```
29
- .opencode/
30
- ├── patches/
31
- │ ├── .patches.json # Metadata index (hashes, versions)
32
- │ ├── skill-beads-skill.md.patch # Unified diff patches
33
- │ ├── command-ship.md.patch
34
- │ └── *.patch.rej # Failed patches (conflicts)
35
- ├── .version # Already exists
36
- └── ... (other template files)
37
- ```
38
-
39
- ---
40
-
41
- ## New Commands
42
-
43
- ### `ock patch save <file>`
44
-
45
- Save current modifications as a patch.
46
-
47
- ```bash
48
- $ ock patch save .opencode/skill/beads/skill.md
49
-
50
- ✓ Saved patch: .opencode/patches/skill-beads-skill.md.patch
51
- Original: a1b2c3d4 → Current: e5f6g7h8
52
- ```
53
-
54
- ### `ock patch list`
55
-
56
- List all saved patches with status.
57
-
58
- ```bash
59
- $ ock patch list
60
-
61
- Active Patches (3):
62
- skill/beads/skill.md ✓ Clean
63
- command/ship.md ⚠ Stale (template changed)
64
- agent/build.md ✗ Conflict
65
- ```
66
-
67
- ### `ock patch apply` (automatic during upgrade)
68
-
69
- Reapply patches after template update.
70
-
71
- ### `ock patch remove <file>`
72
-
73
- Remove a saved patch.
74
-
75
- ---
76
-
77
- ## `.patches.json` Schema
78
-
79
- ```json
80
- {
81
- "version": "1.0.0",
82
- "patches": {
83
- "skill/beads/skill.md": {
84
- "originalHash": "sha256:a1b2c3d4...",
85
- "currentHash": "sha256:e5f6g7h8...",
86
- "patchFile": "skill-beads-skill.md.patch",
87
- "createdAt": "2026-02-03T10:00:00Z",
88
- "templateVersion": "1.2.3"
89
- }
90
- }
91
- }
92
- ```
93
-
94
- ---
95
-
96
- ## Upgrade Flow (Modified)
97
-
98
- ```
99
- 1. User runs: ock upgrade
100
- 2. Check version (existing logic)
101
- 3. For PRESERVE_DIRS files that exist in template:
102
- - Copy template file (overwrite user's version)
103
- - Check if patch exists in .patches.json
104
- - If patch exists, apply it
105
- - If patch fails, save conflict to .patch.rej
106
- 4. Report: "✓ Updated X files, reapplied Y patches, Z conflicts"
107
- ```
108
-
109
- ---
110
-
111
- ## Conflict Resolution
112
-
113
- | Scenario | Action |
114
- | ------------------------------- | ----------------------------------------- |
115
- | Template unchanged | Auto-apply patch |
116
- | Template changed, patch applies | Auto-apply with info message |
117
- | Template changed, patch fails | Save `.patch.rej`, skip file, notify user |
118
-
119
- **Conflict UI:**
120
-
121
- ```
122
- ⚠ CONFLICT: skill/beads/skill.md
123
-
124
- Template changed in v1.3.0 and your patch no longer applies.
125
-
126
- Options:
127
- [1] View diff between versions
128
- [2] Keep new template (discard patch)
129
- [3] Keep your version (skip update)
130
- [4] Manually merge (edit patch.rej)
131
-
132
- Saved: .opencode/patches/skill-beads-skill.md.patch.rej
133
- ```
134
-
135
- ---
136
-
137
- ## Implementation Phases
138
-
139
- ### Phase 1: Core Patch Infrastructure
140
-
141
- **Files to create:**
142
-
143
- - `src/commands/patch.ts` - Patch save/list/apply/remove commands
144
- - `src/utils/patch.ts` - Diff generation, hash calculation, patch application
145
-
146
- **Files to modify:**
147
-
148
- - `src/index.ts` - Register `patch` command
149
-
150
- **Key functions:**
151
-
152
- ```typescript
153
- // src/utils/patch.ts
154
- export function generatePatch(templatePath: string, userPath: string): string;
155
- export function applyPatch(filePath: string, patchContent: string): boolean;
156
- export function calculateHash(content: string): string;
157
- export function loadPatchMetadata(opencodeDir: string): PatchMetadata;
158
- export function savePatchMetadata(opencodeDir: string, metadata: PatchMetadata): void;
159
- ```
160
-
161
- ### Phase 2: Upgrade Integration
162
-
163
- **Files to modify:**
164
-
165
- - `src/commands/upgrade.ts` - Integrate patch apply after template copy
166
-
167
- **Changes:**
168
-
169
- 1. After `copyDirWithPreserve()`, call `applyPatches()`
170
- 2. Modify `PRESERVE_DIRS` logic: still preserve, but ALSO check for patches
171
- 3. Add patch status to upgrade summary
172
-
173
- ### Phase 3: CLI Polish
174
-
175
- - Interactive conflict resolution
176
- - `--dry-run` flag for patch apply
177
- - Pretty diff viewer for conflicts
178
-
179
- ---
180
-
181
- ## Dependencies
182
-
183
- Use existing Node.js capabilities:
184
-
185
- - `crypto.createHash('sha256')` - Hash calculation
186
- - **diff** library (`npm:diff`) - Generate unified diffs
187
- - **patch-package** or custom parser - Apply patches
188
-
189
- Alternative: Shell out to `git diff` and `git apply` (simpler, but requires git).
190
-
191
- ---
192
-
193
- ## Critical Files
194
-
195
- | File | Purpose |
196
- | ------------------------- | -------------------------- |
197
- | `src/commands/patch.ts` | New - Patch commands |
198
- | `src/utils/patch.ts` | New - Patch utilities |
199
- | `src/commands/upgrade.ts` | Modify - Integrate patches |
200
- | `src/index.ts` | Modify - Register command |
201
-
202
- ---
203
-
204
- ## Verification
205
-
206
- 1. **Unit tests**: `src/commands/patch.test.ts`
207
- - Test patch generation from diff
208
- - Test patch application
209
- - Test conflict detection
210
-
211
- 2. **Integration test**:
212
-
213
- ```bash
214
- # Setup
215
- ock init
216
- echo "# Custom section" >> .opencode/skill/beads/skill.md
217
- ock patch save .opencode/skill/beads/skill.md
218
-
219
- # Simulate upgrade
220
- ock upgrade --force
221
-
222
- # Verify
223
- grep "Custom section" .opencode/skill/beads/skill.md # Should exist
224
- ```
225
-
226
- 3. **Conflict test**:
227
- - Modify template file in dist/template
228
- - Run upgrade
229
- - Verify conflict detection and `.patch.rej` creation
230
-
231
- ---
232
-
233
- ## Complexity Estimate
234
-
235
- | Component | Effort | Notes |
236
- | ------------------- | ------ | ------------------------------ |
237
- | Hash/diff utilities | 2h | Use `diff` library |
238
- | Patch save command | 2h | Generate + store patch |
239
- | Patch list command | 1h | Read metadata, show status |
240
- | Patch apply logic | 3h | Apply patches, handle failures |
241
- | Upgrade integration | 2h | Hook into existing flow |
242
- | Conflict UI | 2h | Interactive resolution |
243
- | Tests | 2h | Unit + integration |
244
-
245
- **Total: ~14 hours (2 days)**
246
-
247
- ---
248
-
249
- ## Open Questions
250
-
251
- 1. **Git dependency?** Should we require git for `git diff`/`git apply` or use pure JS?
252
- - Recommendation: Pure JS (`diff` library) for portability
253
-
254
- 2. **Auto-save patches?** Should we auto-detect modifications on upgrade?
255
- - Recommendation: Manual `ock patch save` for now (explicit is better)
256
-
257
- 3. **Nested directories?** How to handle `skill/beads/skill.md` path → filename conversion?
258
- - Recommendation: Replace `/` with `-` → `skill-beads-skill.md.patch`