@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
package/dist/wu-prep.js CHANGED
@@ -1,21 +1,28 @@
1
1
  #!/usr/bin/env node
2
+ /* eslint-disable no-console -- CLI command uses console for status output */
2
3
  /**
3
4
  * WU Prep Helper (WU-1223)
4
5
  *
5
6
  * Prepares a WU for completion by running gates and generating docs in the worktree.
6
7
  * After successful prep, prints copy-paste instruction to run wu:done from main.
7
8
  *
9
+ * WU-1344: When gates fail on spec:linter due to pre-existing WU validation errors
10
+ * (not caused by the current WU), prints a ready-to-copy wu:done --skip-gates
11
+ * command with reason and fix-wu placeholders.
12
+ *
8
13
  * Workflow:
9
14
  * 1. Verify we're in a worktree (error if in main checkout)
10
15
  * 2. Run gates in the worktree
11
- * 3. Generate docs (if applicable)
12
- * 4. Print copy-paste instruction for wu:done from main
16
+ * 3. If gates fail, check if failures are pre-existing on main
17
+ * 4. If pre-existing, print skip-gates command; otherwise, print fix guidance
18
+ * 5. On success, print copy-paste instruction for wu:done from main
13
19
  *
14
20
  * Usage:
15
21
  * pnpm wu:prep --id WU-XXX [--docs-only]
16
22
  *
17
23
  * @module
18
24
  */
25
+ import { spawnSync } from 'node:child_process';
19
26
  import { createWUParser, WU_OPTIONS } from '@lumenflow/core/dist/arg-parser.js';
20
27
  import { die } from '@lumenflow/core/dist/error-handler.js';
21
28
  import { resolveLocation } from '@lumenflow/core/dist/context/location-resolver.js';
@@ -39,6 +46,84 @@ const PREP_OPTIONS = {
39
46
  description: 'Run docs-only gates (format, spec-linter)',
40
47
  },
41
48
  };
49
+ /**
50
+ * WU-1344: Check if a gate name is the spec:linter gate.
51
+ * Used to identify when spec:linter fails so we can check for pre-existing failures.
52
+ *
53
+ * @param gateName - Name of the gate that failed
54
+ * @returns true if this is the spec:linter gate
55
+ */
56
+ export function isPreExistingSpecLinterFailure(gateName) {
57
+ const normalizedName = gateName.toLowerCase().replace(/[:-]/g, '');
58
+ return normalizedName === 'speclinter';
59
+ }
60
+ /**
61
+ * WU-1344: Format a skip-gates command for wu:done.
62
+ * Includes --reason and --fix-wu placeholders.
63
+ *
64
+ * @param options - Configuration options
65
+ * @param options.wuId - The WU ID being completed
66
+ * @param options.mainCheckout - Path to main checkout
67
+ * @returns Formatted command string ready to copy-paste
68
+ */
69
+ export function formatSkipGatesCommand(options) {
70
+ const { wuId, mainCheckout } = options;
71
+ return `cd ${mainCheckout} && pnpm wu:done --id ${wuId} --skip-gates --reason "pre-existing on main" --fix-wu WU-XXXX`;
72
+ }
73
+ /**
74
+ * WU-1344: Default implementation of execOnMain using spawnSync.
75
+ * Uses spawnSync with pnpm executable for safety (no shell injection risk).
76
+ */
77
+ function defaultExecOnMain(mainCheckout) {
78
+ return async (cmd) => {
79
+ // Parse command to extract pnpm script name and args
80
+ // Expected format: "pnpm spec:linter" or similar
81
+ const parts = cmd.split(/\s+/);
82
+ const executable = parts[0];
83
+ const args = parts.slice(1);
84
+ const result = spawnSync(executable, args, {
85
+ cwd: mainCheckout,
86
+ encoding: 'utf-8',
87
+ stdio: ['pipe', 'pipe', 'pipe'],
88
+ });
89
+ return {
90
+ exitCode: result.status ?? 1,
91
+ stdout: result.stdout ?? '',
92
+ stderr: result.stderr ?? '',
93
+ };
94
+ };
95
+ }
96
+ /**
97
+ * WU-1344: Check if spec:linter failures are pre-existing on main branch.
98
+ *
99
+ * Runs spec:linter on the main checkout to determine if the failures
100
+ * already exist there (i.e., not caused by the current WU).
101
+ *
102
+ * @param options - Configuration options
103
+ * @param options.mainCheckout - Path to main checkout
104
+ * @param options.execOnMain - Optional function to execute commands on main (for testing)
105
+ * @returns Result indicating whether failures are pre-existing
106
+ */
107
+ export async function checkPreExistingFailures(options) {
108
+ const { mainCheckout, execOnMain = defaultExecOnMain(mainCheckout) } = options;
109
+ try {
110
+ // Run spec:linter on main checkout
111
+ const result = await execOnMain('pnpm spec:linter');
112
+ // If spec:linter fails on main, the failures are pre-existing
113
+ if (result.exitCode !== 0) {
114
+ return { hasPreExisting: true };
115
+ }
116
+ return { hasPreExisting: false };
117
+ }
118
+ catch (error) {
119
+ // If we can't check main, assume failures are NOT pre-existing
120
+ // (safer to require fixing rather than skipping)
121
+ return {
122
+ hasPreExisting: false,
123
+ error: error.message,
124
+ };
125
+ }
126
+ }
42
127
  /**
43
128
  * Print success message with copy-paste instruction.
44
129
  */
@@ -106,6 +191,34 @@ async function main() {
106
191
  console.log(`${PREP_PREFIX} Location: ${location.cwd}`);
107
192
  console.log(`${PREP_PREFIX} Main checkout: ${location.mainCheckout}`);
108
193
  console.log('');
194
+ // WU-1344: Check for pre-existing spec:linter failures on main BEFORE running gates.
195
+ // We do this first because runGates() calls die() on failure, which exits the process
196
+ // before we can check. By checking first, we can set up an exit handler to show
197
+ // the skip-gates command if gates fail.
198
+ console.log(`${PREP_PREFIX} Checking for pre-existing spec:linter failures on main...`);
199
+ const preExistingCheck = await checkPreExistingFailures({
200
+ mainCheckout: location.mainCheckout,
201
+ });
202
+ if (preExistingCheck.hasPreExisting) {
203
+ console.log(`${PREP_PREFIX} ${EMOJI.WARNING} Pre-existing failures detected on main.`);
204
+ // Set up an exit handler to print the skip-gates command when gates fail
205
+ // This runs before process.exit() fully terminates the process
206
+ process.on('exit', (code) => {
207
+ if (code !== EXIT_CODES.SUCCESS) {
208
+ console.log('');
209
+ console.log(`${PREP_PREFIX} ${EMOJI.WARNING} Since failures are pre-existing on main, you can skip gates:`);
210
+ console.log('');
211
+ console.log(` ${formatSkipGatesCommand({ wuId: id, mainCheckout: location.mainCheckout })}`);
212
+ console.log('');
213
+ console.log(`${PREP_PREFIX} Replace WU-XXXX with the WU that will fix these spec issues.`);
214
+ console.log('');
215
+ }
216
+ });
217
+ }
218
+ else {
219
+ console.log(`${PREP_PREFIX} No pre-existing failures on main.`);
220
+ }
221
+ console.log('');
109
222
  // Run gates in the worktree
110
223
  console.log(`${PREP_PREFIX} Running gates in worktree...`);
111
224
  const gatesResult = await runGates({
@@ -113,13 +226,23 @@ async function main() {
113
226
  docsOnly: args.docsOnly,
114
227
  });
115
228
  if (!gatesResult) {
116
- die(`${EMOJI.FAILURE} Gates failed in worktree.\n\n` +
117
- `Fix the gate failures and run wu:prep again.`);
229
+ // Gates failed - if pre-existing check was already done and showed failures,
230
+ // the exit handler above will print the skip-gates command.
231
+ // Otherwise, tell the user to fix the failures.
232
+ if (!preExistingCheck.hasPreExisting) {
233
+ die(`${EMOJI.FAILURE} Gates failed in worktree.\n\n` +
234
+ `Fix the gate failures and run wu:prep again.`);
235
+ }
236
+ // Pre-existing failures - exit with error, handler will print skip-gates command
237
+ process.exit(EXIT_CODES.ERROR);
118
238
  }
119
239
  // Success - print copy-paste instruction
120
240
  printSuccessMessage(id, location.mainCheckout);
121
241
  }
122
- main().catch((e) => {
123
- console.error(e.message);
124
- process.exit(EXIT_CODES.ERROR);
125
- });
242
+ // WU-1181: Use import.meta.main instead of process.argv[1] comparison
243
+ // The old pattern fails with pnpm symlinks because process.argv[1] is the symlink
244
+ // path but import.meta.url resolves to the real path - they never match
245
+ import { runCLI } from './cli-entry-point.js';
246
+ if (import.meta.main) {
247
+ void runCLI(main);
248
+ }
package/dist/wu-spawn.js CHANGED
@@ -38,11 +38,12 @@ import { WU_STATUS, PATTERNS, FILE_SYSTEM, EMOJI } from '@lumenflow/core/dist/wu
38
38
  // WU-1603: Check lane lock status before spawning
39
39
  // WU-1325: Import lock policy getter for lane availability check
40
40
  import { checkLaneLock } from '@lumenflow/core/dist/lane-lock.js';
41
- import { getLockPolicyForLane } from '@lumenflow/core/dist/lane-checker.js';
41
+ import { getLockPolicyForLane, getWipLimitForLane } from '@lumenflow/core/dist/lane-checker.js';
42
42
  import { minimatch } from 'minimatch';
43
43
  // WU-2252: Import invariants loader for spawn output injection
44
44
  import { loadInvariants, INVARIANT_TYPES } from '@lumenflow/core/dist/invariants-runner.js';
45
45
  import { validateSpawnArgs, generateExecutionModeSection, generateThinkToolGuidance, recordSpawnToRegistry, formatSpawnRecordedMessage, } from '@lumenflow/core/dist/wu-spawn-helpers.js';
46
+ // eslint-disable-next-line sonarjs/deprecation -- legacy factory used by CLI spawns
46
47
  import { SpawnStrategyFactory } from '@lumenflow/core/dist/spawn-strategy.js';
47
48
  import { getConfig } from '@lumenflow/core/dist/lumenflow-config.js';
48
49
  import { generateClientSkillsGuidance, generateSkillsSelectionSection, resolveClientConfig, } from '@lumenflow/core/dist/wu-spawn-skills.js';
@@ -1168,7 +1169,10 @@ export function checkLaneOccupation(lane) {
1168
1169
  export function generateLaneOccupationWarning(lockMetadata, targetWuId, options = {}) {
1169
1170
  const { isStale = false } = options;
1170
1171
  let warning = `⚠️ Lane "${lockMetadata.lane}" is occupied by ${lockMetadata.wuId}\n`;
1171
- warning += ` This violates WIP=1 (Work In Progress limit of 1 per lane).\n\n`;
1172
+ // WU-1346: Use injected values if provided, otherwise look up from config
1173
+ const lockPolicy = options.lockPolicy ?? getLockPolicyForLane(lockMetadata.lane);
1174
+ const wipLimit = options.wipLimit ?? getWipLimitForLane(lockMetadata.lane);
1175
+ warning += ` This violates WIP=${wipLimit} (lock_policy=${lockPolicy}).\n\n`;
1172
1176
  if (isStale) {
1173
1177
  warning += ` ⏰ This lock is STALE (>24 hours old) - the WU may be abandoned.\n`;
1174
1178
  warning += ` Consider using pnpm wu:block --id ${lockMetadata.wuId} if work is stalled.\n\n`;
@@ -1327,6 +1331,7 @@ async function main() {
1327
1331
  }
1328
1332
  }
1329
1333
  // Create strategy
1334
+ // eslint-disable-next-line sonarjs/deprecation -- legacy factory used by CLI spawns
1330
1335
  const strategy = SpawnStrategyFactory.create(clientName);
1331
1336
  const clientContext = { name: clientName, config: resolveClientConfig(config, clientName) };
1332
1337
  if (clientName === 'codex-cli' || args.codex) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lumenflow/cli",
3
- "version": "2.5.0",
3
+ "version": "2.6.0",
4
4
  "description": "Command-line interface for LumenFlow workflow framework",
5
5
  "keywords": [
6
6
  "lumenflow",
@@ -74,7 +74,7 @@
74
74
  "initiative-status": "./dist/initiative-status.js",
75
75
  "initiative-add-wu": "./dist/initiative-add-wu.js",
76
76
  "initiative-plan": "./dist/initiative-plan.js",
77
- "init-plan": "./dist/init-plan.js",
77
+ "init-plan": "./dist/initiative-plan.js",
78
78
  "plan-create": "./dist/plan-create.js",
79
79
  "plan-link": "./dist/plan-link.js",
80
80
  "plan-edit": "./dist/plan-edit.js",
@@ -148,11 +148,11 @@
148
148
  "pretty-ms": "^9.2.0",
149
149
  "simple-git": "^3.30.0",
150
150
  "yaml": "^2.8.2",
151
- "@lumenflow/core": "2.5.0",
152
- "@lumenflow/initiatives": "2.5.0",
153
- "@lumenflow/memory": "2.5.0",
154
- "@lumenflow/agent": "2.5.0",
155
- "@lumenflow/metrics": "2.5.0"
151
+ "@lumenflow/core": "2.6.0",
152
+ "@lumenflow/initiatives": "2.6.0",
153
+ "@lumenflow/metrics": "2.6.0",
154
+ "@lumenflow/agent": "2.6.0",
155
+ "@lumenflow/memory": "2.6.0"
156
156
  },
157
157
  "devDependencies": {
158
158
  "@vitest/coverage-v8": "^4.0.17",
@@ -1,13 +1,13 @@
1
1
  # LumenFlow Constraints Capsule
2
2
 
3
- **Version:** 1.0
3
+ **Version:** 1.1
4
4
  **Last updated:** {{DATE}}
5
5
 
6
- This document contains the 6 non-negotiable constraints that every agent must keep "in working memory" from first plan through `wu:done`.
6
+ This document contains the 7 non-negotiable constraints that every agent must keep "in working memory" from first plan through `wu:done`.
7
7
 
8
8
  ---
9
9
 
10
- ## The 6 Non-Negotiable Constraints
10
+ ## The 7 Non-Negotiable Constraints
11
11
 
12
12
  ### 1. Worktree Discipline and Git Safety
13
13
 
@@ -19,8 +19,40 @@ This document contains the 6 non-negotiable constraints that every agent must ke
19
19
  - Hooks block WU commits from main checkout
20
20
  - Forbidden commands on main: `git reset --hard`, `git stash`, `git clean -fd`, `git push --force`
21
21
 
22
+ **MANDATORY PRE-WRITE CHECK**
23
+
24
+ Before ANY Write/Edit/Read operation:
25
+
26
+ 1. **Verify worktree location**:
27
+
28
+ ```bash
29
+ pwd
30
+ # Must show: .../worktrees/<lane>-wu-xxx
31
+ ```
32
+
33
+ 2. **Verify relative paths only**:
34
+ - ✅ `docs/...`, `packages/...`, `apps/...`, `./...`
35
+ - ❌ `/home/...`, `/Users/...`, or full repo paths
36
+
37
+ 3. **Docs-only exception (documentation WUs)**:
38
+ - You may run **read-only** commands from main (e.g., `pnpm gates --docs-only`).
39
+ - **All file writes still require a worktree**. If no worktree exists, claim one first.
40
+
22
41
  **Why:** Worktree isolation prevents cross-contamination between parallel WUs and protects the main branch.
23
42
 
43
+ **NEVER "QUICK FIX" ON MAIN**
44
+
45
+ If you see something broken on main (failing gates, format issues, typos, lint errors):
46
+
47
+ - ❌ **Don't** fix it directly, even if it seems small or helpful
48
+ - ❌ **Don't** run `prettier --write`, `pnpm lint --fix`, or any command that modifies files
49
+ - ✅ **Do** report the issue to the user
50
+ - ✅ **Do** create a WU if a fix is needed
51
+
52
+ **Why this matters:** The "helpful fix" instinct causes agents to modify files on main without a worktree. While commits are blocked by hooks, the files are still modified, requiring manual cleanup. Every change—no matter how small—needs a worktree.
53
+
54
+ **If you're on main and want to change something: STOP. Create a WU first.**
55
+
24
56
  ---
25
57
 
26
58
  ### 2. WUs Are Specs, Not Code
@@ -94,6 +126,32 @@ This document contains the 6 non-negotiable constraints that every agent must ke
94
126
 
95
127
  ---
96
128
 
129
+ ### 7. Test Ratchet Pattern (WU-1253)
130
+
131
+ **Rule:** NEW test failures block gates; pre-existing failures (in baseline) warn but do not block.
132
+
133
+ **Baseline File:** `.lumenflow/test-baseline.json`
134
+
135
+ **Enforcement:**
136
+
137
+ - Gates compare current test results against baseline
138
+ - NEW failures (not in baseline) = **BLOCK** (must fix or add to baseline)
139
+ - Pre-existing failures (in baseline) = **WARNING** (continue, do not block WU)
140
+ - Fixed tests auto-removed from baseline (ratchet forward)
141
+
142
+ **When gates fail due to tests:**
143
+
144
+ 1. Check baseline: `cat .lumenflow/test-baseline.json`
145
+ 2. If failure is pre-existing: warning shown, WU proceeds
146
+ 3. If failure is NEW: fix the test or add to baseline with:
147
+ ```bash
148
+ pnpm baseline:add --test "<test_name>" --reason "<why>" --fix-wu WU-XXXX
149
+ ```
150
+
151
+ **Why:** Agents should not be blocked by unrelated failures. The ratchet ensures quality improves over time (failures can only be removed, never added without justification).
152
+
153
+ ---
154
+
97
155
  ## Mini Audit Checklist
98
156
 
99
157
  Before running `wu:done`, verify:
@@ -8,17 +8,18 @@ LumenFlow is a vendor-agnostic workflow framework for AI-native software develop
8
8
 
9
9
  ---
10
10
 
11
- ## Critical Rule: ALWAYS Run wu:done
11
+ ## Critical Rule: Use wu:prep Then wu:done
12
12
 
13
- **After completing work on a WU, you MUST run `pnpm wu:done --id WU-XXXX` from the main checkout.**
13
+ **WU-1223 NEW WORKFLOW:**
14
14
 
15
- This is the single most forgotten step. Do NOT:
15
+ 1. From worktree: `pnpm wu:prep --id WU-XXXX` (runs gates, prints copy-paste instruction)
16
+ 2. From main: `pnpm wu:done --id WU-XXXX` (merge + cleanup only)
16
17
 
17
- - Write "To Complete: pnpm wu:done" and stop
18
- - Ask if you should run wu:done
19
- - Forget to run wu:done
18
+ **DO NOT:**
20
19
 
21
- **DO**: Run `pnpm wu:done --id WU-XXXX` immediately after gates pass.
20
+ - Run `wu:done` from a worktree (it will error)
21
+ - Forget to run `wu:done` after `wu:prep`
22
+ - Skip `wu:prep` and go directly to `wu:done` (gates won't run in worktree)
22
23
 
23
24
  See: [docs/04-operations/\_frameworks/lumenflow/agent/onboarding/troubleshooting-wu-done.md](docs/04-operations/_frameworks/lumenflow/agent/onboarding/troubleshooting-wu-done.md)
24
25
 
@@ -30,8 +31,8 @@ See: [docs/04-operations/\_frameworks/lumenflow/agent/onboarding/troubleshooting
30
31
  # 1. Setup (first time only)
31
32
  pnpm setup
32
33
 
33
- # 2. Create a WU (default: creates spec/wu-xxxx branch, never writes to main)
34
- pnpm wu:create --id WU-XXXX --lane <Lane> --title "Title" \
34
+ # 2. Create a WU (--id is optional, auto-generates next sequential ID if omitted)
35
+ pnpm wu:create --lane <Lane> --title "Title" \
35
36
  --description "..." --acceptance "..." --code-paths "..." \
36
37
  --test-paths-unit "..." --exposure backend-only \
37
38
  --spec-refs "lumenflow://plans/WU-XXXX-plan.md"
@@ -42,15 +43,49 @@ cd worktrees/<lane>-wu-xxxx
42
43
 
43
44
  # 4. Implement in worktree
44
45
 
45
- # 5. Run gates
46
- pnpm gates --docs-only # for docs changes
47
- pnpm gates # for code changes
46
+ # 5. Prepare (runs gates in worktree) - WU-1223 NEW
47
+ pnpm wu:prep --id WU-XXXX
48
+ # This prints a copy-paste instruction for the next step
48
49
 
49
- # 6. Complete (from main checkout)
50
- cd /path/to/main
51
- pnpm wu:done --id WU-XXXX
50
+ # 6. Complete (from main checkout - copy-paste from wu:prep output)
51
+ cd /path/to/main && pnpm wu:done --id WU-XXXX
52
+ ```
53
+
54
+ ---
55
+
56
+ ## Setup Notes (Common First-Run Failures)
57
+
58
+ ### Lane inference (sub-lanes)
59
+
60
+ If you use sub-lanes like `Experience: UI`, you must have a lane taxonomy:
61
+
62
+ - Ensure `.lumenflow.lane-inference.yaml` exists, or
63
+ - Generate it with `pnpm lane:suggest --output .lumenflow.lane-inference.yaml`
64
+
65
+ Without this file, sub-lane validation will fail.
66
+
67
+ ### Local-only / no remote
68
+
69
+ By default, `wu:create` expects an `origin` remote and will fetch `origin/main`.
70
+
71
+ For local-only or offline development, add this to `.lumenflow.config.yaml`:
72
+
73
+ ```yaml
74
+ git:
75
+ requireRemote: false
52
76
  ```
53
77
 
78
+ When `requireRemote: false`:
79
+
80
+ - `wu:create` skips remote fetch operations
81
+ - `wu:claim` works without pushing to origin
82
+ - Useful for air-gapped environments, testing/evaluation, or pre-remote development
83
+
84
+ When `requireRemote: true` (default):
85
+
86
+ - Operations fail with a clear error if no `origin` remote exists
87
+ - Ensures team visibility via remote branches
88
+
54
89
  ---
55
90
 
56
91
  ## Core Principles
@@ -66,6 +101,18 @@ pnpm wu:done --id WU-XXXX
66
101
 
67
102
  ---
68
103
 
104
+ ## Universal Agent Safety (WU-1170)
105
+
106
+ LumenFlow enforces safety at the repository level so protections apply to all agents and humans.
107
+
108
+ - **Git wrapper**: `scripts/safe-git` blocks destructive operations (e.g. `worktree remove`, `reset --hard`, `clean -fd`, `push --force`).
109
+ - **Husky hooks**: staged secret scanning, absolute-path scanning, lockfile sync, and worktree discipline.
110
+ - **Audit logs**:
111
+ - `.beacon/safety-blocks.log`
112
+ - `.beacon/force-bypasses.log`
113
+
114
+ ---
115
+
69
116
  ## Global State
70
117
 
71
118
  Canonical global state is defined by:
@@ -83,17 +130,31 @@ air-gapped/offline work; it creates a local-only claim and warns explicitly.
83
130
 
84
131
  ### Core (Vendor-Agnostic)
85
132
 
86
- - **LUMENFLOW.md** - This file, main entry point
133
+ - **AGENTS.md** - Universal entry point for AI agents (Codex, Cursor, Windsurf)
134
+ - **LUMENFLOW.md** - This file, main workflow documentation
87
135
  - **.lumenflow/constraints.md** - Non-negotiable workflow constraints
88
136
  - **.lumenflow/rules/** - Workflow rules (git-safety.md, wu-workflow.md, etc.)
89
137
  - **docs/04-operations/\_frameworks/lumenflow/agent/onboarding/** - Agent onboarding documentation
90
138
 
91
- ### Vendor Integrations
139
+ ### Client/Vendor Overlays
140
+
141
+ - **CLAUDE.md** - Claude Code overlay (single file at root)
142
+ - **.claude/** - Claude Code settings, hooks, skills, agents
143
+ - **.cursor/rules/lumenflow.md** - Cursor rules overlay
144
+ - **.windsurf/rules/lumenflow.md** - Windsurf rules overlay
145
+
146
+ Use `lumenflow init --client <type>` to generate client-specific files:
147
+
148
+ ```bash
149
+ lumenflow init # Creates AGENTS.md + LUMENFLOW.md (universal)
150
+ lumenflow init --client claude # + CLAUDE.md, .claude/
151
+ lumenflow init --client cursor # + .cursor/rules/lumenflow.md
152
+ lumenflow init --client windsurf # + .windsurf/rules/lumenflow.md
153
+ lumenflow init --client all # All of the above
154
+ lumenflow init --merge # Safe merge into existing files
155
+ ```
92
156
 
93
- - **.claude/** - Claude Code (settings.json, hooks, .claude/CLAUDE.md)
94
- - **.cursor/** - Cursor (rules, settings)
95
- - **.aider.conf.yml** - Aider configuration
96
- - **.continue/** - Continue configuration
157
+ The `--merge` flag uses bounded markers (`LUMENFLOW:START`/`END`) to safely insert or update LumenFlow config in existing files without overwriting user content.
97
158
 
98
159
  ---
99
160
 
@@ -131,7 +192,7 @@ Main checkout becomes read-only after claim. Hooks will block WU commits from ma
131
192
 
132
193
  ## Core Commands
133
194
 
134
- > **Complete CLI reference (60+ commands):** See [quick-ref-commands.md](ai/onboarding/quick-ref-commands.md)
195
+ > **Complete CLI reference (60+ commands):** See [quick-ref-commands.md](docs/04-operations/_frameworks/lumenflow/agent/onboarding/quick-ref-commands.md)
135
196
 
136
197
  | Command | Description |
137
198
  | ------------------------------- | ------------------------------------------------------ |
@@ -161,7 +222,7 @@ When validation fails, commands provide copy-paste ready fix commands:
161
222
  ERROR: WRONG_LOCATION - wu:done must be run from main checkout
162
223
 
163
224
  FIX: Run this command:
164
- cd {{PROJECT_ROOT}} && pnpm wu:done --id WU-1090
225
+ cd <repo-root> && pnpm wu:done --id WU-1090
165
226
  ```
166
227
 
167
228
  Configure validation behavior in `.lumenflow.config.yaml`:
@@ -210,6 +271,7 @@ If you're an AI agent, read the onboarding docs:
210
271
  2. [docs/04-operations/\_frameworks/lumenflow/agent/onboarding/first-wu-mistakes.md](docs/04-operations/_frameworks/lumenflow/agent/onboarding/first-wu-mistakes.md) - First WU pitfalls
211
272
  3. [docs/04-operations/\_frameworks/lumenflow/agent/onboarding/agent-safety-card.md](docs/04-operations/_frameworks/lumenflow/agent/onboarding/agent-safety-card.md) - Safety guardrails
212
273
  4. [docs/04-operations/\_frameworks/lumenflow/agent/onboarding/quick-ref-commands.md](docs/04-operations/_frameworks/lumenflow/agent/onboarding/quick-ref-commands.md) - Command reference
274
+ 5. [docs/04-operations/\_frameworks/lumenflow/agent/onboarding/test-ratchet.md](docs/04-operations/_frameworks/lumenflow/agent/onboarding/test-ratchet.md) - Test baseline ratchet pattern
213
275
 
214
276
  ---
215
277
 
@@ -0,0 +1,157 @@
1
+ # Agent Invocation Guide (LumenFlow)
2
+
3
+ **Last updated:** {{DATE}}
4
+
5
+ This guide defines how to spawn and brief sub-agents so they start with the right context,
6
+ follow LumenFlow constraints, and leave durable artifacts for handoff.
7
+
8
+ Use this document when:
9
+
10
+ - Spawning sub-agents or parallel WUs
11
+ - Writing orchestrator prompts
12
+ - Starting a new session after `/clear`
13
+ - Coordinating multi-wave initiatives
14
+
15
+ ---
16
+
17
+ ## 1) Context Tiers (Load Order)
18
+
19
+ Load context in this order to reduce "lost in the middle" failures:
20
+
21
+ 1. `LUMENFLOW.md` — workflow fundamentals
22
+ 2. `README.md` — repo structure / commands
23
+ 3. `lumenflow-complete.md` §§1-7 — constraints + governance
24
+ 4. WU YAML — current task spec
25
+ 5. Task instructions — what to do
26
+ 6. **Critical Constraints block** — append at the end (see below)
27
+
28
+ **Tier guidance:**
29
+
30
+ - **Tier 1 (minimal):** `LUMENFLOW.md`, `README.md`, WU YAML
31
+ - **Tier 2 (standard):** Tier 1 + `lumenflow-complete.md` §§1-7
32
+ - **Tier 3 (full):** Tier 2 + relevant framework/agent docs
33
+
34
+ Use Tier 1 after `/clear` to stay lean, then load more only if needed.
35
+
36
+ ---
37
+
38
+ ## 2) Session Management (Spawn Fresh)
39
+
40
+ When approaching context limits, **spawn a fresh agent instead of compaction**.
41
+ The spawn prompt is the bridge between sessions.
42
+
43
+ **Mandatory triggers:**
44
+
45
+ - Context usage >80%
46
+ - 50+ tool calls
47
+ - Performance degradation (forgotten context, redundant queries)
48
+ - About to run `/compact` or `/clear`
49
+
50
+ **Spawn fresh protocol:**
51
+
52
+ ```bash
53
+ pnpm mem:checkpoint "Progress: completed X, next: Y" --wu WU-XXX
54
+ git add -A && git commit -m "checkpoint: progress on X"
55
+ git push origin lane/<lane>/wu-xxx
56
+ pnpm wu:spawn --id WU-XXX
57
+ # Exit current session; start fresh with the generated prompt.
58
+ ```
59
+
60
+ **Optional safety net:** If your client supports hooks, add a pre-clear checkpoint hook:
61
+
62
+ ```bash
63
+ pnpm mem:checkpoint "Pre-clear: <summary>" --wu WU-XXX --trigger pre-clear
64
+ ```
65
+
66
+ ---
67
+
68
+ ## 2a) Memory Context Injection (Automatic)
69
+
70
+ When the memory layer is initialized (`memory.jsonl` exists), `wu:spawn` automatically
71
+ injects relevant memory context into the spawn prompt under a `## Memory Context` section.
72
+
73
+ **What gets included:**
74
+
75
+ - WU-specific checkpoints and notes
76
+ - Project-level architectural decisions
77
+ - Recent context relevant to the lane
78
+
79
+ **Configuration:**
80
+
81
+ Configure max context size in `.lumenflow.config.yaml`:
82
+
83
+ ```yaml
84
+ memory:
85
+ spawn_context_max_size: 4096 # Default: 4KB
86
+ ```
87
+
88
+ **Skip context injection:**
89
+
90
+ Use `--no-context` when you want a clean spawn without memory context:
91
+
92
+ ```bash
93
+ pnpm wu:spawn --id WU-XXX --no-context
94
+ ```
95
+
96
+ This is useful when:
97
+
98
+ - Starting completely fresh without prior context
99
+ - Debugging context-related issues
100
+ - Memory layer contains stale or irrelevant data
101
+
102
+ ---
103
+
104
+ ## 3) Spawn Prompt Structure (Recommended)
105
+
106
+ Use this structure for sub-agent prompts:
107
+
108
+ 1. **Objective** — clear, single outcome
109
+ 2. **Scope** — what is in/out of scope
110
+ 3. **Code Paths** — allowed paths (from WU `code_paths`)
111
+ 4. **Tests/Gates** — required checks
112
+ 5. **Progress Artifacts** — checkpoints, commits, signals
113
+ 6. **Recovery** — what to do if blocked
114
+ 7. **Critical Constraints** — append at the end
115
+
116
+ ---
117
+
118
+ ## 4) Append These Constraints at the End (Mandatory)
119
+
120
+ Paste this block at the end of every multi-agent prompt:
121
+
122
+ ```
123
+ CRITICAL CONSTRAINTS (append at end, do not omit):
124
+ 1) Work only in worktrees after wu:claim; main is read-only for WU work.
125
+ 2) Never bypass hooks (--no-verify, HUSKY=0). Fix root causes instead.
126
+ 3) WUs are specs, not code; stay within code_paths.
127
+ 4) Run correct gates before wu:done (docs-only vs full).
128
+ 5) Use LLM-first inference; avoid brittle regex/keyword shortcuts.
129
+ 6) If uncertain about safety, stop and ask.
130
+ ```
131
+
132
+ For full details, see `.lumenflow/constraints.md`.
133
+
134
+ ---
135
+
136
+ ## 5) Coordination Checklist (Orchestrators)
137
+
138
+ Before spawning:
139
+
140
+ - Confirm WU status and lane availability
141
+ - Ensure worktree exists (or claim first)
142
+ - Provide explicit code_paths and tests
143
+ - Require `mem:checkpoint` at 50+ tool calls
144
+ - Require `mem:signal` for milestones
145
+
146
+ After spawning:
147
+
148
+ - Monitor with `pnpm mem:inbox --since 30m`
149
+ - Use `pnpm mem:ready --wu WU-XXX` for handoff status
150
+
151
+ ---
152
+
153
+ ## 6) Related Skills
154
+
155
+ - `.claude/skills/context-management/SKILL.md`
156
+ - `.claude/skills/multi-agent-coordination/SKILL.md`
157
+ - `.claude/skills/execution-memory/SKILL.md`