@lumenflow/cli 2.5.0 → 2.6.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 (29) hide show
  1. package/README.md +11 -8
  2. package/dist/__tests__/gates-config.test.js +304 -0
  3. package/dist/__tests__/init-scripts.test.js +111 -0
  4. package/dist/__tests__/templates-sync.test.js +219 -0
  5. package/dist/gates.js +64 -15
  6. package/dist/init.js +90 -0
  7. package/dist/orchestrate-init-status.js +37 -9
  8. package/dist/orchestrate-initiative.js +10 -4
  9. package/dist/sync-templates.js +137 -5
  10. package/dist/wu-prep.js +131 -8
  11. package/dist/wu-spawn.js +7 -2
  12. package/package.json +7 -7
  13. package/templates/core/.lumenflow/constraints.md.template +61 -3
  14. package/templates/core/LUMENFLOW.md.template +85 -23
  15. package/templates/core/ai/onboarding/agent-invocation-guide.md.template +157 -0
  16. package/templates/core/ai/onboarding/agent-safety-card.md.template +227 -0
  17. package/templates/core/ai/onboarding/docs-generation.md.template +277 -0
  18. package/templates/core/ai/onboarding/first-wu-mistakes.md.template +49 -7
  19. package/templates/core/ai/onboarding/quick-ref-commands.md.template +343 -110
  20. package/templates/core/ai/onboarding/release-process.md.template +8 -2
  21. package/templates/core/ai/onboarding/starting-prompt.md.template +407 -0
  22. package/templates/core/ai/onboarding/test-ratchet.md.template +131 -0
  23. package/templates/core/ai/onboarding/troubleshooting-wu-done.md.template +91 -38
  24. package/templates/core/ai/onboarding/vendor-support.md.template +219 -0
  25. package/templates/vendors/claude/.claude/skills/context-management/SKILL.md.template +13 -1
  26. package/templates/vendors/claude/.claude/skills/execution-memory/SKILL.md.template +14 -16
  27. package/templates/vendors/claude/.claude/skills/orchestration/SKILL.md.template +48 -4
  28. package/templates/vendors/claude/.claude/skills/worktree-discipline/SKILL.md.template +5 -1
  29. package/templates/vendors/claude/.claude/skills/wu-lifecycle/SKILL.md.template +19 -8
@@ -0,0 +1,407 @@
1
+ # LumenFlow Agent Starting Prompt
2
+
3
+ **Last updated:** {{DATE}}
4
+
5
+ This is the complete onboarding document for AI agents working with LumenFlow. Read this entire document before starting any work.
6
+
7
+ ---
8
+
9
+ ## Quick Start (Copy This)
10
+
11
+ ```bash
12
+ # 1. Check your assigned WU
13
+ cat docs/04-operations/tasks/wu/WU-XXXX.yaml
14
+
15
+ # 2. Claim the WU (creates isolated worktree)
16
+ pnpm wu:claim --id WU-XXXX --lane "Lane Name"
17
+
18
+ # 3. IMMEDIATELY cd to worktree (CRITICAL!)
19
+ cd worktrees/<lane>-wu-xxxx
20
+
21
+ # 4. Do your work here (not in main!)
22
+
23
+ # 5. Run gates before completion
24
+ pnpm gates # For code changes
25
+ pnpm gates --docs-only # For documentation changes
26
+
27
+ # 6. Return to main and complete
28
+ cd /path/to/main/checkout
29
+ pnpm wu:done --id WU-XXXX
30
+ ```
31
+
32
+ ---
33
+
34
+ ## Before Creating WUs
35
+
36
+ If you plan to use sub-lanes like `Experience: UI`, make sure lane inference is configured:
37
+
38
+ - `.lumenflow.lane-inference.yaml` must exist for sub-lane validation, or
39
+ - Generate it with `pnpm lane:suggest --output .lumenflow.lane-inference.yaml`
40
+
41
+ **No remote yet?** `wu:create` expects `origin/main`. If your repo is local-only, add a remote
42
+ before running `wu:create`. `wu:claim` supports `--no-push` for local-only work.
43
+
44
+ ---
45
+
46
+ ## The 5 Rules You Must Follow
47
+
48
+ ### Rule 1: ALWAYS Work in Worktrees
49
+
50
+ After `pnpm wu:claim`, you MUST immediately `cd` to the worktree. **Never edit files in the main checkout.**
51
+
52
+ ```bash
53
+ # WRONG - editing in main
54
+ pnpm wu:claim --id WU-123 --lane "Framework: CLI"
55
+ vim packages/cli/src/index.ts # BLOCKED BY HOOKS!
56
+
57
+ # RIGHT - editing in worktree
58
+ pnpm wu:claim --id WU-123 --lane "Framework: CLI"
59
+ cd worktrees/framework-cli-wu-123 # IMMEDIATELY!
60
+ vim packages/cli/src/index.ts # Safe here
61
+ ```
62
+
63
+ **Why:** Worktrees isolate your changes. Main checkout is protected by git hooks.
64
+
65
+ ### Rule 2: ALWAYS Run wu:done
66
+
67
+ After gates pass, you MUST run `pnpm wu:done --id WU-XXXX` from the main checkout. Do not just write "To complete: run wu:done" - actually run it.
68
+
69
+ ```bash
70
+ # WRONG
71
+ "Work complete. Next step: run pnpm wu:done --id WU-123"
72
+
73
+ # RIGHT
74
+ cd /path/to/main
75
+ pnpm wu:done --id WU-123
76
+ # Then report: "WU-123 completed. Changes merged to main."
77
+ ```
78
+
79
+ **Why:** wu:done merges your changes, creates the completion stamp, and releases the lane lock.
80
+
81
+ ### Rule 3: Use Relative Paths Only
82
+
83
+ When writing or editing files, use paths relative to the worktree root.
84
+
85
+ ```bash
86
+ # WRONG - absolute paths
87
+ Write to: /home/user/project/worktrees/cli-wu-123/src/index.ts
88
+
89
+ # RIGHT - relative paths
90
+ Write to: src/index.ts
91
+ # (from within the worktree directory)
92
+ ```
93
+
94
+ **Why:** Absolute paths may accidentally write to main or wrong worktree.
95
+
96
+ ### Rule 4: Handle Gate Failures Properly
97
+
98
+ When gates fail, read the error and fix it. Common failures and fixes:
99
+
100
+ | Failure | Cause | Fix |
101
+ | -------------- | ----------------------- | -------------------------------------- |
102
+ | `format:check` | Prettier formatting | `pnpm prettier --write <file>` |
103
+ | `backlog-sync` | WU missing from backlog | Regenerate backlog or add WU reference |
104
+ | `typecheck` | TypeScript errors | Fix the type errors |
105
+ | `lint` | ESLint violations | `pnpm lint --fix` or manual fix |
106
+ | `test` | Failing tests | Fix the tests or implementation |
107
+
108
+ **Pre-existing failures:** If failures exist on main before your changes:
109
+
110
+ ```bash
111
+ pnpm wu:done --id WU-XXX --skip-gates \
112
+ --reason "Pre-existing format failures in apps/docs/*.mdx" \
113
+ --fix-wu WU-XXX
114
+ ```
115
+
116
+ ### Rule 5: Know When to Use LUMENFLOW_FORCE
117
+
118
+ `LUMENFLOW_FORCE=1` bypasses git hooks. Use it ONLY for emergency fixes when hooks are incorrectly blocking you.
119
+
120
+ ```bash
121
+ # Emergency: backlog fix when worktree hook blocks main writes
122
+ LUMENFLOW_FORCE=1 LUMENFLOW_FORCE_REASON="backlog corruption recovery" git commit -m "fix: ..."
123
+ LUMENFLOW_FORCE=1 LUMENFLOW_FORCE_REASON="backlog corruption recovery" git push
124
+ ```
125
+
126
+ **Never use for:**
127
+
128
+ - Skipping failing tests
129
+ - Avoiding gate failures
130
+ - Convenience
131
+
132
+ **Always use with:**
133
+
134
+ - `LUMENFLOW_FORCE_REASON="explanation"`
135
+
136
+ ---
137
+
138
+ ## Common Failure Scenarios and Recovery
139
+
140
+ ### Scenario 1: "BLOCKED: Direct commit to main"
141
+
142
+ **Cause:** You're trying to commit in the main checkout, not the worktree.
143
+
144
+ **Fix:**
145
+
146
+ ```bash
147
+ # Check where you are
148
+ pwd
149
+ # Should be: .../worktrees/<lane>-wu-xxx
150
+ # If in main, cd to worktree first
151
+
152
+ cd worktrees/<lane>-wu-xxx
153
+ git add . && git commit -m "your message"
154
+ ```
155
+
156
+ ### Scenario 2: "backlog-sync failed - WU not found in backlog.md"
157
+
158
+ **Cause:** The backlog.md file is missing references to some WU YAML files.
159
+
160
+ **Fix:** Regenerate the backlog or manually add the missing WU:
161
+
162
+ ```bash
163
+ # In worktree, edit docs/04-operations/tasks/backlog.md
164
+ # Add the missing WU reference in the appropriate section
165
+ ```
166
+
167
+ ### Scenario 3: "Auto-rebase failed: unstaged changes"
168
+
169
+ **Cause:** Your worktree has uncommitted changes when wu:done tries to rebase.
170
+
171
+ **Fix:**
172
+
173
+ ```bash
174
+ cd worktrees/<lane>-wu-xxx
175
+ git status # See what's uncommitted
176
+ git add . && git commit -m "wip: complete changes"
177
+ cd /path/to/main
178
+ pnpm wu:done --id WU-XXX
179
+ ```
180
+
181
+ ### Scenario 4: "Working tree is not clean" (when running wu:done)
182
+
183
+ **Cause:** Main checkout has uncommitted changes (possibly from another agent).
184
+
185
+ **Fix:**
186
+
187
+ ```bash
188
+ cd /path/to/main
189
+ git status # Check what's uncommitted
190
+ # If your changes: commit them
191
+ # If another agent's changes: DO NOT DELETE - coordinate with user
192
+ git restore <file> # Only if safe to discard
193
+ ```
194
+
195
+ ### Scenario 5: Gate fails but you didn't cause the failure
196
+
197
+ **Cause:** Pre-existing failures on main that your WU didn't introduce.
198
+
199
+ **Fix:**
200
+
201
+ ```bash
202
+ # Verify the failure exists on main before your changes
203
+ git stash
204
+ pnpm gates # If still fails, it's pre-existing
205
+ git stash pop
206
+
207
+ # Complete with skip-gates
208
+ pnpm wu:done --id WU-XXX --skip-gates \
209
+ --reason "Pre-existing failure in X" \
210
+ --fix-wu WU-XXX
211
+ ```
212
+
213
+ ---
214
+
215
+ ## Spawning Sub-Agents with wu:spawn
216
+
217
+ Use `wu:spawn` to create parallel sub-agents for complex WUs that require multiple agents working simultaneously on different aspects.
218
+
219
+ ### When to Use wu:spawn
220
+
221
+ - **Parallel work:** Multiple agents needed on the same WU simultaneously
222
+ - **Specialized expertise:** Different agents for different domains (frontend, backend, docs)
223
+ - **Context isolation:** Preventing context limit issues on large WUs
224
+ - **Wave-based execution:** Coordinating multiple phases of work
225
+
226
+ ### How to Use wu:spawn
227
+
228
+ ```bash
229
+ # Spawn a sub-agent with client-specific context
230
+ pnpm wu:spawn --id WU-XXXX --client <client-type>
231
+
232
+ # Valid client values:
233
+ # - claude-code # Claude Code CLI
234
+ # - cursor # Cursor IDE
235
+ # - windsurf # Windsurf IDE
236
+ # - gemini-cli # Gemini CLI
237
+ # - copilot # GitHub Copilot CLI
238
+ ```
239
+
240
+ **IMPORTANT:** The `--client` flag identifies your IDE/tool environment, NOT the underlying AI model. Use `--client windsurf` even if Windsurf is running a Claude agent.
241
+
242
+ ### Sub-Agent Coordination
243
+
244
+ - Sub-agents work in isolated micro-worktrees
245
+ - Use `pnpm mem:signal` for progress communication
246
+ - Main agent coordinates and integrates results
247
+ - Each sub-agent should focus on a specific aspect
248
+
249
+ ---
250
+
251
+ ## WU Lifecycle Commands
252
+
253
+ | Command | Description | When to Use |
254
+ | ----------------------------------------- | --------------------------------- | --------------------- |
255
+ | `pnpm wu:status --id WU-XXX` | Show WU state and valid commands | Check current state |
256
+ | `pnpm wu:claim --id WU-XXX --lane "Lane"` | Claim WU and create worktree | Start working |
257
+ | `pnpm wu:spawn --id WU-XXX --client X` | Spawn sub-agent for parallel work | Complex WUs |
258
+ | `pnpm gates` | Run quality gates | Before wu:done |
259
+ | `pnpm gates --docs-only` | Run docs-only gates | For documentation WUs |
260
+ | `pnpm wu:done --id WU-XXX` | Complete WU, merge, cleanup | After gates pass |
261
+ | `pnpm wu:recover --id WU-XXX` | Fix inconsistent WU state | When state is broken |
262
+
263
+ ---
264
+
265
+ ## File Structure
266
+
267
+ ```
268
+ /path/to/repo/
269
+ ├── docs/04-operations/tasks/
270
+ │ ├── backlog.md # All WUs listed here
271
+ │ └── wu/WU-XXXX.yaml # Individual WU specs
272
+ ├── worktrees/
273
+ │ └── <lane>-wu-xxxx/ # Your isolated workspace
274
+ ├── .lumenflow/
275
+ │ ├── constraints.md # Non-negotiable rules
276
+ │ ├── stamps/WU-XXXX.done # Completion stamps
277
+ │ └── state/wu-events.jsonl # Event log
278
+ └── LUMENFLOW.md # Main workflow docs
279
+ ```
280
+
281
+ ---
282
+
283
+ ## Definition of Done
284
+
285
+ Before reporting a WU complete, verify:
286
+
287
+ - [ ] All acceptance criteria in WU YAML are satisfied
288
+ - [ ] Gates pass (`pnpm gates` or `pnpm gates --docs-only`)
289
+ - [ ] `pnpm wu:done --id WU-XXX` ran successfully
290
+ - [ ] Output shows "Marked done, pushed, and cleaned up"
291
+ - [ ] Worktree was removed (check `ls worktrees/`)
292
+
293
+ ---
294
+
295
+ ## Anti-Patterns (Don't Do These)
296
+
297
+ 1. **Don't write "To complete: run wu:done"** - Actually run it
298
+ 2. **Don't edit files in main checkout** - Use the worktree
299
+ 3. **Don't use absolute paths** - Use relative paths from worktree root
300
+ 4. **Don't ignore gate failures** - Fix them or use --skip-gates with reason
301
+ 5. **Don't use LUMENFLOW_FORCE casually** - Only for genuine emergencies
302
+ 6. **Don't delete another agent's uncommitted work** - Coordinate with user
303
+ 7. **Don't work after context compaction** - Spawn fresh agent instead
304
+
305
+ ---
306
+
307
+ ## Getting Help
308
+
309
+ 1. **Check WU status:** `pnpm wu:status --id WU-XXX`
310
+ 2. **Read error messages:** They usually include fix commands
311
+ 3. **Check gate logs:** `.logs/gates-*.log` in worktree
312
+ 4. **Recovery command:** `pnpm wu:recover --id WU-XXX`
313
+
314
+ ---
315
+
316
+ ## Universal Agent Entry Points
317
+
318
+ LumenFlow uses **AGENTS.md** as the universal entry point for all AI agents. This file works with:
319
+
320
+ - **Claude Code** - Reads AGENTS.md directly
321
+ - **Cursor** - Reads AGENTS.md directly
322
+ - **Windsurf** - Reads AGENTS.md directly
323
+ - **OpenAI Codex** - Reads AGENTS.md directly
324
+
325
+ ### Client-Specific Overlays
326
+
327
+ Some clients have additional overlay files for client-specific features:
328
+
329
+ | Client | Entry Point | Overlay Location |
330
+ | -------- | ----------- | ---------------------------- |
331
+ | Claude | AGENTS.md | CLAUDE.md (root) |
332
+ | Cursor | AGENTS.md | .cursor/rules/lumenflow.md |
333
+ | Windsurf | AGENTS.md | .windsurf/rules/lumenflow.md |
334
+ | Codex | AGENTS.md | (no overlay, AGENTS.md only) |
335
+
336
+ ### Setting Up for Your Client
337
+
338
+ When initializing LumenFlow, use the `--client` flag to generate client-specific files:
339
+
340
+ ```bash
341
+ # Install the CLI first
342
+ pnpm add -D @lumenflow/cli
343
+
344
+ # Universal setup (AGENTS.md only)
345
+ pnpm exec lumenflow
346
+
347
+ # Claude-specific setup
348
+ pnpm exec lumenflow --client claude
349
+
350
+ # Cursor-specific setup
351
+ pnpm exec lumenflow --client cursor
352
+
353
+ # Windsurf-specific setup
354
+ pnpm exec lumenflow --client windsurf
355
+
356
+ # All clients
357
+ pnpm exec lumenflow --client all
358
+ ```
359
+
360
+ ### Adding LumenFlow to Existing Projects
361
+
362
+ Use `--merge` mode to safely add LumenFlow configuration to existing files without overwriting your content:
363
+
364
+ ```bash
365
+ # Install the CLI first
366
+ pnpm add -D @lumenflow/cli
367
+
368
+ # Merge into existing AGENTS.md (preserves your content)
369
+ pnpm exec lumenflow --merge
370
+
371
+ # Merge with client overlay
372
+ pnpm exec lumenflow --merge --client claude
373
+ ```
374
+
375
+ The merge mode uses bounded markers (`<!-- LUMENFLOW:START -->` and `<!-- LUMENFLOW:END -->`) to safely insert and update the LumenFlow block while preserving everything else.
376
+
377
+ ### Framework Scaffolding in Non-Empty Directories
378
+
379
+ Many framework scaffolding tools (e.g., `create-next-app`, `create-react-app`) fail in non-empty directories. Use a temp directory workaround:
380
+
381
+ ```bash
382
+ # 1. Scaffold in a temp directory
383
+ pnpm create next-app /tmp/nextjs-scaffold --typescript --tailwind --app
384
+
385
+ # 2. Copy scaffold files to your project (preserves existing files)
386
+ cp -rn /tmp/nextjs-scaffold/* .
387
+ cp -rn /tmp/nextjs-scaffold/.* . 2>/dev/null || true
388
+
389
+ # 3. Install and initialize LumenFlow
390
+ pnpm install
391
+ pnpm add -D @lumenflow/cli
392
+ pnpm exec lumenflow --client claude --full
393
+
394
+ # 4. Clean up
395
+ rm -rf /tmp/nextjs-scaffold
396
+ ```
397
+
398
+ ---
399
+
400
+ ## Reference Documents
401
+
402
+ - [LUMENFLOW.md](../../../../../LUMENFLOW.md) - Main workflow documentation
403
+ - [AGENTS.md](../../../../../AGENTS.md) - Universal agent entry point
404
+ - [.lumenflow/constraints.md](../../../../../.lumenflow/constraints.md) - The 6 non-negotiable rules
405
+ - [troubleshooting-wu-done.md](troubleshooting-wu-done.md) - Why agents forget wu:done
406
+ - [first-wu-mistakes.md](first-wu-mistakes.md) - Common mistakes to avoid
407
+ - [quick-ref-commands.md](quick-ref-commands.md) - Command reference
@@ -0,0 +1,131 @@
1
+ # Test Ratchet Pattern (WU-1253)
2
+
3
+ **Purpose:** Enable agents to work on WUs without being blocked by unrelated test failures, while preventing introduction of NEW failures.
4
+
5
+ ---
6
+
7
+ ## Overview
8
+
9
+ The test ratchet pattern tracks known test failures in a baseline file. When gates run:
10
+
11
+ - **NEW failures** (not in baseline) **BLOCK** the gate
12
+ - **Pre-existing failures** (in baseline) show **WARNING** but do not block
13
+ - When tests are **FIXED**, baseline auto-updates (ratchet forward)
14
+
15
+ This creates a "ratchet" effect: test failures can only decrease over time, never increase without explicit justification.
16
+
17
+ ---
18
+
19
+ ## Baseline File
20
+
21
+ Location: `.lumenflow/test-baseline.json`
22
+
23
+ ```json
24
+ {
25
+ "version": 1,
26
+ "updated_at": "{{DATE}}T12:00:00.000Z",
27
+ "updated_by": "WU-1253",
28
+ "known_failures": [
29
+ {
30
+ "test_name": "should handle edge case",
31
+ "file_path": "packages/@lumenflow/core/src/__tests__/foo.test.ts",
32
+ "failure_reason": "WU-1210 changed implementation without updating test",
33
+ "added_at": "{{DATE}}T10:00:00.000Z",
34
+ "added_by_wu": "WU-1239",
35
+ "expected_fix_wu": "WU-1300"
36
+ }
37
+ ],
38
+ "stats": {
39
+ "total_known_failures": 1,
40
+ "last_ratchet_forward": "{{DATE}}T15:00:00.000Z"
41
+ }
42
+ }
43
+ ```
44
+
45
+ ---
46
+
47
+ ## When Gates Fail Due to Tests
48
+
49
+ ### Step 1: Check if failure is in baseline
50
+
51
+ ```bash
52
+ cat .lumenflow/test-baseline.json | grep -i "<test_name>"
53
+ ```
54
+
55
+ ### Step 2: Determine action
56
+
57
+ | Failure Type | In Baseline? | Action |
58
+ | ------------ | ------------ | --------------------------------------- |
59
+ | Pre-existing | Yes | Continue - warning only, does not block |
60
+ | NEW | No | Must fix test OR add to baseline |
61
+
62
+ ### Step 3: If NEW failure, choose resolution
63
+
64
+ **Option A: Fix the test** (preferred)
65
+
66
+ - Debug and fix the failing test
67
+ - Ensure test passes
68
+ - Re-run gates
69
+
70
+ **Option B: Add to baseline** (for infrastructure issues only)
71
+
72
+ ```bash
73
+ pnpm baseline:add \
74
+ --test "should handle edge case" \
75
+ --file "path/to/test.ts" \
76
+ --reason "CI flakiness - infrastructure issue" \
77
+ --fix-wu WU-XXXX
78
+ ```
79
+
80
+ ---
81
+
82
+ ## Ratchet Forward (Auto-Update)
83
+
84
+ When a test that was in the baseline now passes, gates automatically:
85
+
86
+ 1. Remove the fixed test from `known_failures`
87
+ 2. Update `stats.total_known_failures`
88
+ 3. Record `stats.last_ratchet_forward` timestamp
89
+ 4. Commit the baseline update with WU reference
90
+
91
+ This ensures the baseline only shrinks over time.
92
+
93
+ ---
94
+
95
+ ## Skip-Gates Integration
96
+
97
+ The test ratchet works with skip-gates:
98
+
99
+ - Pre-existing failures (in baseline) do NOT require `--skip-gates`
100
+ - Only truly NEW failures or infrastructure issues need skip-gates
101
+ - The `expected_fix_wu` field tracks accountability
102
+
103
+ ---
104
+
105
+ ## Agent Checklist
106
+
107
+ When encountering test failures:
108
+
109
+ - [ ] Check if failure is in baseline
110
+ - [ ] If pre-existing: continue (warning is expected)
111
+ - [ ] If NEW: fix the test (preferred) or add to baseline with reason
112
+ - [ ] If adding to baseline: specify `expected_fix_wu` for accountability
113
+ - [ ] Re-run gates to verify
114
+
115
+ ---
116
+
117
+ ## Why This Matters
118
+
119
+ 1. **Unblocking agents**: Unrelated test failures shouldn't block your WU
120
+ 2. **Quality ratchet**: Failures can only decrease, never increase
121
+ 3. **Accountability**: Every baselined failure has a reason and fix-WU
122
+ 4. **TDD compliance**: You still must write tests FIRST for your changes
123
+ 5. **Visibility**: Team can track technical debt via baseline
124
+
125
+ ---
126
+
127
+ ## Related Documentation
128
+
129
+ - [constraints.md](../../../../../../.lumenflow/constraints.md) - Constraint #7: Test Ratchet
130
+ - [lumenflow-complete.md](../../lumenflow-complete.md) - Definition of Done
131
+ - [troubleshooting-wu-done.md](./troubleshooting-wu-done.md) - wu:done issues