@lumenflow/cli 2.5.0 → 2.5.1

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 (27) hide show
  1. package/README.md +11 -8
  2. package/dist/__tests__/init-scripts.test.js +111 -0
  3. package/dist/__tests__/templates-sync.test.js +219 -0
  4. package/dist/init.js +90 -0
  5. package/dist/orchestrate-init-status.js +37 -9
  6. package/dist/orchestrate-initiative.js +10 -4
  7. package/dist/sync-templates.js +137 -5
  8. package/dist/wu-prep.js +131 -8
  9. package/dist/wu-spawn.js +7 -2
  10. package/package.json +7 -7
  11. package/templates/core/.lumenflow/constraints.md.template +61 -3
  12. package/templates/core/LUMENFLOW.md.template +85 -23
  13. package/templates/core/ai/onboarding/agent-invocation-guide.md.template +157 -0
  14. package/templates/core/ai/onboarding/agent-safety-card.md.template +227 -0
  15. package/templates/core/ai/onboarding/docs-generation.md.template +277 -0
  16. package/templates/core/ai/onboarding/first-wu-mistakes.md.template +49 -7
  17. package/templates/core/ai/onboarding/quick-ref-commands.md.template +343 -110
  18. package/templates/core/ai/onboarding/release-process.md.template +8 -2
  19. package/templates/core/ai/onboarding/starting-prompt.md.template +407 -0
  20. package/templates/core/ai/onboarding/test-ratchet.md.template +131 -0
  21. package/templates/core/ai/onboarding/troubleshooting-wu-done.md.template +91 -38
  22. package/templates/core/ai/onboarding/vendor-support.md.template +219 -0
  23. package/templates/vendors/claude/.claude/skills/context-management/SKILL.md.template +13 -1
  24. package/templates/vendors/claude/.claude/skills/execution-memory/SKILL.md.template +14 -16
  25. package/templates/vendors/claude/.claude/skills/orchestration/SKILL.md.template +48 -4
  26. package/templates/vendors/claude/.claude/skills/worktree-discipline/SKILL.md.template +5 -1
  27. package/templates/vendors/claude/.claude/skills/wu-lifecycle/SKILL.md.template +19 -8
@@ -0,0 +1,277 @@
1
+ # Automatic CLI/Config Documentation Generation
2
+
3
+ **Last updated:** {{DATE}}
4
+
5
+ This document explains LumenFlow's automatic documentation generation system, which keeps Starlight docs in sync with code using a single-source-of-truth pattern.
6
+
7
+ ---
8
+
9
+ ## Overview
10
+
11
+ LumenFlow automatically generates CLI and configuration reference documentation from source code. This ensures documentation never drifts from implementation.
12
+
13
+ | Component | Source | Output |
14
+ | ---------------- | --------------------------------------------------------- | ------------------------------------------------- |
15
+ | CLI Reference | `packages/@lumenflow/cli/src/**` | `apps/docs/src/content/docs/reference/cli.mdx` |
16
+ | Config Reference | `packages/@lumenflow/core/src/lumenflow-config-schema.ts` | `apps/docs/src/content/docs/reference/config.mdx` |
17
+
18
+ ---
19
+
20
+ ## Single-Source-of-Truth Pattern
21
+
22
+ The documentation generator imports directly from built packages rather than parsing source files with regex:
23
+
24
+ ```typescript
25
+ // tools/generate-cli-docs.ts
26
+ import {
27
+ WU_OPTIONS,
28
+ DirectoriesSchema,
29
+ GatesConfigSchema,
30
+ // ... other schemas
31
+ } from '../packages/@lumenflow/core/dist/index.js';
32
+ ```
33
+
34
+ **Benefits:**
35
+
36
+ - **No regex parsing**: Uses proper TypeScript imports
37
+ - **Type safety**: Schemas validate at build time
38
+ - **Consistent**: Same definitions used by CLI and docs
39
+ - **Maintainable**: Update code once, docs follow automatically
40
+
41
+ ---
42
+
43
+ ## Trigger Files
44
+
45
+ Changes to these files trigger documentation regeneration:
46
+
47
+ | File/Directory | Description |
48
+ | --------------------------------------------------------- | ------------------------------------- |
49
+ | `tools/generate-cli-docs.ts` | The generator script itself |
50
+ | `packages/@lumenflow/core/src/arg-parser.ts` | CLI argument definitions (WU_OPTIONS) |
51
+ | `packages/@lumenflow/core/src/lumenflow-config-schema.ts` | Config schema definitions |
52
+ | `packages/@lumenflow/core/src/index.ts` | Core exports |
53
+ | `packages/@lumenflow/cli/package.json` | CLI bin entries |
54
+ | `packages/@lumenflow/cli/src/**` | All CLI command sources |
55
+
56
+ These pathspecs are defined in `DOC_SOURCE_PATHSPECS` within `packages/@lumenflow/core/src/wu-done-docs-generate.ts`.
57
+
58
+ ---
59
+
60
+ ## wu:done Auto-Detection Flow
61
+
62
+ When you run `pnpm wu:done`, the system automatically detects if docs need regeneration:
63
+
64
+ ```mermaid
65
+ flowchart TD
66
+ A[wu:done starts] --> B[Run gates in worktree]
67
+ B --> C{Gates pass?}
68
+ C -->|No| D[Fix gates first]
69
+ C -->|Yes| E[Check doc-source changes]
70
+ E --> F{Any trigger files changed?}
71
+ F -->|No| G[Skip docs:generate]
72
+ F -->|Yes| H[Run turbo docs:generate]
73
+ H --> I[Format doc outputs]
74
+ I --> J[Stage doc files]
75
+ J --> K[Continue with metadata commit]
76
+ G --> K
77
+ ```
78
+
79
+ ### Detection Logic
80
+
81
+ The detection uses efficient `git diff` with pathspecs:
82
+
83
+ ```bash
84
+ git diff main...HEAD --name-only -- <pathspecs>
85
+ ```
86
+
87
+ - **Zero overhead** when no doc-source files changed (~0ms)
88
+ - **Turbo caching** when docs:generate runs (incremental builds)
89
+
90
+ ### Integration Point
91
+
92
+ In `executeWorktreeCompletion()` (after gates pass, before metadata commit):
93
+
94
+ ```typescript
95
+ await maybeRegenerateAndStageDocs({
96
+ baseBranch: 'main',
97
+ repoRoot: repoRoot,
98
+ });
99
+ ```
100
+
101
+ This ensures regenerated docs are included in the single atomic completion commit.
102
+
103
+ ---
104
+
105
+ ## Manual Commands
106
+
107
+ ### Generate Documentation
108
+
109
+ Regenerate all CLI/config documentation:
110
+
111
+ ```bash
112
+ pnpm docs:generate
113
+ ```
114
+
115
+ This runs `tools/generate-cli-docs.ts` which:
116
+
117
+ 1. Extracts command metadata from CLI package.json bin entries
118
+ 2. Imports WU_OPTIONS from `@lumenflow/core` for option definitions
119
+ 3. Extracts config schemas using Zod 4's native `toJSONSchema()`
120
+ 4. Generates MDX files with tables and code blocks
121
+ 5. Formats output with Prettier
122
+
123
+ ### Validate Documentation
124
+
125
+ Check if documentation is in sync with code (useful for CI):
126
+
127
+ ```bash
128
+ pnpm docs:validate
129
+ ```
130
+
131
+ - **Exit 0**: Documentation is up to date
132
+ - **Exit 1**: Documentation drift detected, run `pnpm docs:generate`
133
+
134
+ ### Turbo Integration
135
+
136
+ The generator is integrated into Turbo for caching:
137
+
138
+ ```json
139
+ // turbo.json
140
+ "docs:generate": {
141
+ "dependsOn": ["@lumenflow/core#build"],
142
+ "inputs": [
143
+ "tools/generate-cli-docs.ts",
144
+ "packages/@lumenflow/core/src/arg-parser.ts",
145
+ "packages/@lumenflow/core/src/lumenflow-config-schema.ts",
146
+ "packages/@lumenflow/core/src/index.ts",
147
+ "packages/@lumenflow/cli/src/**/*.ts",
148
+ "packages/@lumenflow/cli/package.json"
149
+ ],
150
+ "outputs": [
151
+ "apps/docs/src/content/docs/reference/cli.mdx",
152
+ "apps/docs/src/content/docs/reference/config.mdx"
153
+ ]
154
+ }
155
+ ```
156
+
157
+ **Key points:**
158
+
159
+ - Depends on `@lumenflow/core#build` (requires built packages for imports)
160
+ - Inputs match `DOC_SOURCE_PATHSPECS` for consistent detection
161
+ - Outputs are cached; unchanged inputs skip regeneration
162
+
163
+ ---
164
+
165
+ ## Output Files
166
+
167
+ The generator produces two MDX files:
168
+
169
+ ### CLI Reference (`cli.mdx`)
170
+
171
+ - Generated from CLI package.json bin entries
172
+ - Options extracted from WU_OPTIONS in `@lumenflow/core`
173
+ - Grouped by category (Work Units, Memory Layer, Initiatives, etc.)
174
+ - Includes required/optional flags and descriptions
175
+
176
+ ### Config Reference (`config.mdx`)
177
+
178
+ - Generated from Zod schemas in `@lumenflow/core`
179
+ - Each config section documented with fields, types, defaults
180
+ - Environment variable overrides documented
181
+ - Validation command shown
182
+
183
+ ---
184
+
185
+ ## Adding New CLI Commands
186
+
187
+ When you add a new CLI command:
188
+
189
+ 1. **Add bin entry** to `packages/@lumenflow/cli/package.json`
190
+ 2. **Add options** to `WU_OPTIONS` in `packages/@lumenflow/core/src/arg-parser.ts`
191
+ 3. **Run** `pnpm docs:generate` to update documentation
192
+ 4. **Verify** the command appears in `cli.mdx`
193
+
194
+ The generator automatically:
195
+
196
+ - Discovers the new command from package.json
197
+ - Extracts options from WU_OPTIONS references in source
198
+ - Categorizes based on command prefix (wu-, mem-, etc.)
199
+
200
+ ---
201
+
202
+ ## Adding New Config Options
203
+
204
+ When you add new configuration options:
205
+
206
+ 1. **Add to schema** in `packages/@lumenflow/core/src/lumenflow-config-schema.ts`
207
+ 2. **Export** from `packages/@lumenflow/core/src/index.ts`
208
+ 3. **Add to SCHEMA_DEFINITIONS** in `tools/generate-cli-docs.ts`
209
+ 4. **Run** `pnpm docs:generate` to update documentation
210
+
211
+ ---
212
+
213
+ ## Troubleshooting
214
+
215
+ ### Documentation Drift in CI
216
+
217
+ If CI fails with documentation drift:
218
+
219
+ ```bash
220
+ # Regenerate and commit
221
+ pnpm docs:generate
222
+ git add apps/docs/src/content/docs/reference/
223
+ git commit -m "docs: regenerate CLI/config reference"
224
+ ```
225
+
226
+ ### Import Errors in Generator
227
+
228
+ If `tools/generate-cli-docs.ts` fails with import errors:
229
+
230
+ ```bash
231
+ # Ensure packages are built
232
+ pnpm build
233
+ # Then regenerate
234
+ pnpm docs:generate
235
+ ```
236
+
237
+ ### Turbo Cache Issues
238
+
239
+ If docs aren't regenerating when they should:
240
+
241
+ ```bash
242
+ # Clear Turbo cache and regenerate
243
+ pnpm clean
244
+ pnpm build
245
+ pnpm docs:generate
246
+ ```
247
+
248
+ ---
249
+
250
+ ## Architecture Summary
251
+
252
+ ```
253
+ Source Code Generator Output
254
+ ────────────────────────────────────────────────────────────────────────
255
+ @lumenflow/core
256
+ └── arg-parser.ts ─┐
257
+ └── lumenflow-config- ─┼── tools/generate-cli-docs.ts ──┬─► cli.mdx
258
+ schema.ts ─┤ (imports from dist/) │
259
+ @lumenflow/cli │ │
260
+ └── package.json ─┤ └─► config.mdx
261
+ └── src/**/*.ts ─┘
262
+ ```
263
+
264
+ **Key design decisions:**
265
+
266
+ - **Library imports over regex**: Reliable, type-safe extraction
267
+ - **Turbo integration**: Caching, dependency management
268
+ - **wu:done integration**: Zero-effort doc updates
269
+ - **CI validation**: Drift detection prevents stale docs
270
+
271
+ ---
272
+
273
+ ## Related Documentation
274
+
275
+ - [Release Process](./release-process.md) - Deployment workflow including docs
276
+ - [LumenFlow Complete Guide](../../lumenflow-complete.md) - Full framework reference
277
+ - [Quick Reference Commands](./quick-ref-commands.md) - Command cheat sheet
@@ -26,17 +26,20 @@ cd worktrees/core-wu-123
26
26
  vim src/feature.ts
27
27
  git commit -m "feat: add feature"
28
28
  git push origin lane/core/wu-123
29
- cd /path/to/main
30
- pnpm wu:done --id WU-123
29
+ pnpm wu:prep --id WU-123 # WU-1223: runs gates, prints copy-paste instruction
30
+ cd /path/to/main && pnpm wu:done --id WU-123 # Copy-paste from wu:prep output
31
31
  ```
32
32
 
33
33
  ---
34
34
 
35
- ## Mistake 2: Forgetting to Run wu:done
35
+ ## Mistake 2: Forgetting to Run wu:prep and wu:done
36
36
 
37
37
  See [troubleshooting-wu-done.md](troubleshooting-wu-done.md) for the full explanation.
38
38
 
39
- **TL;DR:** After gates pass, ALWAYS run `pnpm wu:done --id WU-XXX`.
39
+ **TL;DR (WU-1223):**
40
+
41
+ 1. From worktree: `pnpm wu:prep --id WU-XXX` (runs gates)
42
+ 2. From main: `pnpm wu:done --id WU-XXX` (copy-paste from wu:prep output)
40
43
 
41
44
  ---
42
45
 
@@ -159,7 +162,8 @@ Start coding immediately based on the title.
159
162
  2. Understand acceptance criteria
160
163
  3. Review code_paths
161
164
  4. Check dependencies
162
- 5. Then start
165
+ 5. Check spec_refs for linked plans (if present, read the plan document)
166
+ 6. Then start
163
167
 
164
168
  ---
165
169
 
@@ -183,16 +187,54 @@ vim src/feature.ts # Now it's safe
183
187
 
184
188
  ---
185
189
 
190
+ ## Mistake 11: "Quick Fixing" on Main
191
+
192
+ ### Wrong
193
+
194
+ ```bash
195
+ # On main, see failing format check
196
+ pnpm gates
197
+ # Output: format:check failed
198
+
199
+ # Instinct: "I should help fix this!"
200
+ pnpm prettier --write apps/docs/src/content/docs/concepts/lanes.mdx
201
+ # Files modified on main - BAD!
202
+ ```
203
+
204
+ ### Right
205
+
206
+ ```bash
207
+ # On main, see failing format check
208
+ pnpm gates
209
+ # Output: format:check failed
210
+
211
+ # Report to user or create a WU
212
+ # "Format check is failing on main. Should I create a WU to fix it?"
213
+
214
+ # If yes:
215
+ pnpm wu:create --lane "Content: Documentation" --title "Fix format issues" ...
216
+ pnpm wu:claim --id WU-XXX --lane "Content: Documentation"
217
+ cd worktrees/content-documentation-wu-xxx
218
+ pnpm prettier --write <files> # Safe in worktree
219
+ ```
220
+
221
+ **Why:** The "helpful fix" instinct is dangerous. Even small fixes (format, typos, lint) must go through a worktree. Commits are blocked by hooks, but files are still modified, requiring cleanup with `git checkout -- <files>`.
222
+
223
+ **Rule:** If you're on main and want to change something—STOP. Create a WU first.
224
+
225
+ ---
226
+
186
227
  ## Quick Checklist
187
228
 
188
229
  Before starting any WU:
189
230
 
190
231
  - [ ] Read the full WU spec
191
232
  - [ ] Understand acceptance criteria
233
+ - [ ] Check spec_refs for plans (read linked plans if present)
192
234
  - [ ] Claim the WU with `pnpm wu:claim`
193
235
  - [ ] cd to the worktree IMMEDIATELY
194
236
  - [ ] Work only in the worktree
195
237
  - [ ] Stay within code_paths
196
238
  - [ ] Follow TDD
197
- - [ ] Run gates before wu:done
198
- - [ ] ALWAYS run wu:done
239
+ - [ ] Run wu:prep from worktree (runs gates)
240
+ - [ ] Run wu:done from main (copy-paste from wu:prep output)