@lumenflow/cli 2.8.0 → 2.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/init.js CHANGED
@@ -19,6 +19,8 @@ import { GATE_PRESETS } from '@lumenflow/core/dist/gates-config.js';
19
19
  import { updateMergeBlock } from './merge-block.js';
20
20
  // WU-1362: Import worktree guard utilities for branch checking
21
21
  import { isMainBranch, isInWorktree } from '@lumenflow/core/dist/core/worktree-guard.js';
22
+ // WU-1386: Import doctor for auto-run after init
23
+ import { runDoctorForInit } from './doctor.js';
22
24
  /**
23
25
  * WU-1085: CLI option definitions for init command
24
26
  * WU-1171: Added --merge and --client options
@@ -70,9 +72,12 @@ const INIT_OPTIONS = {
70
72
  * Provides proper --help, --version, and option parsing
71
73
  */
72
74
  export function parseInitOptions() {
75
+ // WU-1378: Description includes subcommand hint
73
76
  const opts = createWUParser({
74
77
  name: 'lumenflow-init',
75
- description: 'Initialize LumenFlow in a project',
78
+ description: 'Initialize LumenFlow in a project\n\n' +
79
+ 'Subcommands:\n' +
80
+ ' lumenflow commands List all available CLI commands',
76
81
  options: Object.values(INIT_OPTIONS),
77
82
  });
78
83
  // WU-1171: --client takes precedence, --vendor is alias
@@ -321,9 +326,24 @@ const DEFAULT_LANE_DEFINITIONS = [
321
326
  * WU-1067: Supports --preset option for config-driven gates
322
327
  * WU-1307: Includes default lane definitions for onboarding
323
328
  * WU-1364: Supports git config overrides (requireRemote)
329
+ * WU-1383: Adds enforcement hooks config for Claude client by default
324
330
  */
325
- function generateLumenflowConfigYaml(gatePreset, gitConfigOverride) {
326
- const header = `# LumenFlow Configuration\n# Generated by: lumenflow init\n# Customize paths based on your project structure\n\n`;
331
+ function generateLumenflowConfigYaml(gatePreset, gitConfigOverride, client) {
332
+ // WU-1382: Add managed file header to prevent manual edits
333
+ const header = `# ============================================================================
334
+ # LUMENFLOW MANAGED FILE - DO NOT EDIT MANUALLY
335
+ # ============================================================================
336
+ # Generated by: lumenflow init
337
+ # Regenerate with: pnpm exec lumenflow init --force
338
+ #
339
+ # This file is managed by LumenFlow tooling. Manual edits may be overwritten.
340
+ # To customize, use the CLI commands or edit the appropriate source templates.
341
+ # ============================================================================
342
+
343
+ # LumenFlow Configuration
344
+ # Customize paths based on your project structure
345
+
346
+ `;
327
347
  const config = getDefaultConfig();
328
348
  config.directories.agentsDir = LUMENFLOW_AGENTS_DIR;
329
349
  // WU-1067: Add gates.execution section with preset if specified
@@ -344,6 +364,22 @@ function generateLumenflowConfigYaml(gatePreset, gitConfigOverride) {
344
364
  requireRemote: gitConfigOverride.requireRemote,
345
365
  };
346
366
  }
367
+ // WU-1383: Add enforcement hooks for Claude client by default
368
+ // This prevents agents from working on main and editing config files manually
369
+ if (client === 'claude') {
370
+ config.agents = {
371
+ clients: {
372
+ 'claude-code': {
373
+ enforcement: {
374
+ hooks: true,
375
+ block_outside_worktree: true,
376
+ require_wu_for_edits: true,
377
+ warn_on_stop_without_wu_done: true,
378
+ },
379
+ },
380
+ },
381
+ };
382
+ }
347
383
  return header + yaml.stringify(config);
348
384
  }
349
385
  /**
@@ -453,7 +489,78 @@ const LUMENFLOW_MD_TEMPLATE = `# LumenFlow Workflow Guide\n\n**Last updated:** {
453
489
  const CONSTRAINTS_MD_TEMPLATE = `# LumenFlow Constraints Capsule\n\n**Version:** 1.0\n**Last updated:** {{DATE}}\n\n## The 6 Non-Negotiable Constraints\n\n### 1. Worktree Discipline and Git Safety\nWork only in worktrees, treat main as read-only, never run destructive git commands on main.\n\n### 2. WUs Are Specs, Not Code\nRespect code_paths boundaries, no feature creep, no code blocks in WU YAML files.\n\n### 3. Docs-Only vs Code WUs\nDocumentation WUs use \`--docs-only\` gates, code WUs run full gates.\n\n### 4. LLM-First, Zero-Fallback Inference\nUse LLMs for semantic tasks, fall back to safe defaults (never regex/keywords).\n\n### 5. Gates and Skip-Gates\nComplete via \`pnpm wu:done\`; skip-gates only for pre-existing failures with \`--reason\` and \`--fix-wu\`.\n\n### 6. Safety and Governance\nRespect privacy rules, approved sources, security policies; when uncertain, choose safer path.\n\n---\n\n## Mini Audit Checklist\n\nBefore running \`wu:done\`, verify:\n\n- [ ] Working in worktree (not main)\n- [ ] Only modified files in \`code_paths\`\n- [ ] Gates pass\n- [ ] No forbidden git commands used\n- [ ] Acceptance criteria satisfied\n\n---\n\n## Escalation Triggers\n\nStop and ask a human when:\n- Same error repeats 3 times\n- Auth or permissions changes required\n- PII/PHI/safety issues discovered\n- Cloud spend or secrets involved\n`;
454
490
  // Template for root CLAUDE.md
455
491
  // WU-1309: Use <project-root> placeholder for portability
456
- const CLAUDE_MD_TEMPLATE = `# Claude Code Instructions\n\n**Last updated:** {{DATE}}\n\nThis project uses LumenFlow workflow. For workflow documentation, see [LUMENFLOW.md](LUMENFLOW.md).\n\n---\n\n## Quick Start\n\n\`\`\`bash\n# 1. Claim a WU\npnpm wu:claim --id WU-XXXX --lane <Lane>\ncd worktrees/<lane>-wu-xxxx\n\n# 2. Work in worktree, run gates\npnpm gates\n\n# 3. Complete (ALWAYS run this!)\ncd <project-root>\npnpm wu:done --id WU-XXXX\n\`\`\`\n\n---\n\n## Critical: Always wu:done\n\nAfter completing work, ALWAYS run \`pnpm wu:done --id WU-XXXX\`.\n\nSee [LUMENFLOW.md](LUMENFLOW.md) for full workflow documentation.\n`;
492
+ // WU-1382: Expanded with CLI commands table and warning about manual YAML editing
493
+ const CLAUDE_MD_TEMPLATE = `# Claude Code Instructions
494
+
495
+ **Last updated:** {{DATE}}
496
+
497
+ This project uses LumenFlow workflow. For workflow documentation, see [LUMENFLOW.md](LUMENFLOW.md).
498
+
499
+ ---
500
+
501
+ ## Quick Start
502
+
503
+ \`\`\`bash
504
+ # 1. Claim a WU
505
+ pnpm wu:claim --id WU-XXXX --lane <Lane>
506
+ cd worktrees/<lane>-wu-xxxx
507
+
508
+ # 2. Work in worktree, run gates
509
+ pnpm gates
510
+
511
+ # 3. Complete (ALWAYS run this!)
512
+ cd <project-root>
513
+ pnpm wu:done --id WU-XXXX
514
+ \`\`\`
515
+
516
+ ---
517
+
518
+ ## CLI Commands Reference
519
+
520
+ ### WU Lifecycle
521
+
522
+ | Command | Description |
523
+ | ----------------------------------------- | ---------------------------------------- |
524
+ | \`pnpm wu:status --id WU-XXX\` | Show WU status, location, valid commands |
525
+ | \`pnpm wu:claim --id WU-XXX --lane <Lane>\` | Claim WU and create worktree |
526
+ | \`pnpm wu:prep --id WU-XXX\` | Run gates in worktree, prep for wu:done |
527
+ | \`pnpm wu:done --id WU-XXX\` | Complete WU (from main checkout) |
528
+ | \`pnpm wu:block --id WU-XXX --reason "..."\`| Block WU with reason |
529
+ | \`pnpm wu:unblock --id WU-XXX\` | Unblock WU |
530
+
531
+ ### Gates & Quality
532
+
533
+ | Command | Description |
534
+ | ------------------------ | -------------------------- |
535
+ | \`pnpm gates\` | Run all quality gates |
536
+ | \`pnpm gates --docs-only\` | Run gates for docs changes |
537
+ | \`pnpm format\` | Format all files |
538
+ | \`pnpm lint\` | Run linter |
539
+ | \`pnpm typecheck\` | Run TypeScript check |
540
+ | \`pnpm test\` | Run tests |
541
+
542
+ ---
543
+
544
+ ## Critical: Always wu:done
545
+
546
+ After completing work, ALWAYS run \`pnpm wu:done --id WU-XXXX\` from the main checkout.
547
+
548
+ See [LUMENFLOW.md](LUMENFLOW.md) for full workflow documentation.
549
+
550
+ ---
551
+
552
+ ## Warning: Do Not Edit WU YAML Files Manually
553
+
554
+ **Never manually edit WU YAML files** in \`docs/.../tasks/wu/WU-XXX.yaml\`.
555
+
556
+ Use CLI commands instead:
557
+
558
+ - \`pnpm wu:create ...\` to create new WUs
559
+ - \`pnpm wu:edit --id WU-XXX ...\` to modify WU fields
560
+ - \`pnpm wu:claim\` / \`wu:block\` / \`wu:done\` for status changes
561
+
562
+ Manual edits bypass validation and can corrupt workflow state.
563
+ `;
457
564
  // Template for .claude/settings.json
458
565
  const CLAUDE_SETTINGS_TEMPLATE = `{
459
566
  "$schema": "https://json.schemastore.org/claude-code-settings.json",
@@ -1095,9 +1202,19 @@ Choose the safer path:
1095
1202
  `;
1096
1203
  // WU-1307: Lane inference configuration template (hierarchical Parent→Sublane format)
1097
1204
  // WU-1364: Added Core and Feature as parent lanes for intuitive naming
1205
+ // WU-1382: Added managed file header to prevent manual edits
1098
1206
  // This format is required by lane-inference.ts and lane-checker.ts
1099
- const LANE_INFERENCE_TEMPLATE = `# Lane Inference Configuration
1207
+ const LANE_INFERENCE_TEMPLATE = `# ============================================================================
1208
+ # LUMENFLOW MANAGED FILE - DO NOT EDIT MANUALLY
1209
+ # ============================================================================
1100
1210
  # Generated by: lumenflow init
1211
+ # Regenerate with: pnpm exec lumenflow init --force
1212
+ #
1213
+ # This file is managed by LumenFlow tooling. Manual edits may be overwritten.
1214
+ # To customize lanes, use: pnpm lane:suggest --output .lumenflow.lane-inference.yaml
1215
+ # ============================================================================
1216
+
1217
+ # Lane Inference Configuration
1101
1218
  #
1102
1219
  # Hierarchical format: Parent -> Sublane -> { code_paths, keywords }
1103
1220
  # This format is required by lane-inference.ts for proper sub-lane suggestion.
@@ -1363,6 +1480,7 @@ LumenFlow uses Work Units (WUs) to track all changes:
1363
1480
  - [quick-ref-commands.md](quick-ref-commands.md) - Complete command reference
1364
1481
  - [agent-safety-card.md](agent-safety-card.md) - Safety guidelines
1365
1482
  - [wu-create-checklist.md](wu-create-checklist.md) - WU creation guide
1483
+ - [wu-sizing-guide.md](wu-sizing-guide.md) - WU complexity and context management
1366
1484
  `;
1367
1485
  const WU_CREATE_CHECKLIST_TEMPLATE = `# WU Creation Checklist
1368
1486
 
@@ -1751,6 +1869,96 @@ This detects:
1751
1869
  - Overlapping code paths between lanes
1752
1870
  - Code files not covered by any lane
1753
1871
  `;
1872
+ // WU-1385: WU sizing guide template for agent onboarding
1873
+ const WU_SIZING_GUIDE_TEMPLATE = `# Work Unit Sizing & Strategy Guide
1874
+
1875
+ **Last updated:** {{DATE}}
1876
+
1877
+ **Purpose:** Decision framework for agents to determine execution strategy based on task complexity.
1878
+
1879
+ **Status:** Active — Thresholds are **mandatory limits**, not guidelines.
1880
+
1881
+ ---
1882
+
1883
+ ## Complexity Assessment Matrix
1884
+
1885
+ Before claiming a WU, estimate its "weight" using these heuristics.
1886
+
1887
+ | Complexity | Files | Tool Calls | Context Budget | Strategy |
1888
+ | :------------ | :---- | :--------- | :------------- | :------------------------------------------- |
1889
+ | **Simple** | <20 | <50 | <30% | **Single Session** (Tier 2 Context) |
1890
+ | **Medium** | 20-50 | 50-100 | 30-50% | **Checkpoint-Resume** (Standard Handoff) |
1891
+ | **Complex** | 50+ | 100+ | >50% | **Orchestrator-Worker** OR **Decomposition** |
1892
+ | **Oversized** | 100+ | 200+ | — | **MUST Split** (See Patterns below) |
1893
+
1894
+ **These thresholds are mandatory.** Exceeding them leads to context exhaustion and rule loss. Agents operate in context windows and tool calls, not clock time.
1895
+
1896
+ ---
1897
+
1898
+ ## Context Safety Triggers
1899
+
1900
+ If you hit ANY of these triggers during a session, you MUST checkpoint and spawn fresh:
1901
+
1902
+ - **Token Limit:** Context usage hits **50% (Warning)** or **80% (Critical)**.
1903
+ - **Tool Volume:** **50+ tool calls** in current session.
1904
+ - **File Volume:** **20+ files** modified in \`git status\`.
1905
+ - **Session Staleness:** Repeated redundant queries or forgotten context.
1906
+
1907
+ ---
1908
+
1909
+ ## Spawn Fresh, Don't Continue
1910
+
1911
+ **When approaching context limits, spawn a fresh agent instead of continuing after compaction.**
1912
+
1913
+ Context compaction causes agents to lose critical rules. The disciplined approach:
1914
+
1915
+ 1. Checkpoint your progress: \`pnpm mem:checkpoint --wu WU-XXX\`
1916
+ 2. Commit and push work
1917
+ 3. Generate fresh agent prompt: \`pnpm wu:spawn --id WU-XXX\`
1918
+ 4. EXIT current session (do NOT continue after compaction)
1919
+
1920
+ ---
1921
+
1922
+ ## Splitting Patterns
1923
+
1924
+ When a WU is Oversized or Complex, split it using approved patterns:
1925
+
1926
+ - **Tracer Bullet**: WU-1 proves skeleton works, WU-2 implements real logic
1927
+ - **Layer Split**: WU-1 for ports/application, WU-2 for infrastructure
1928
+ - **UI/Logic Split**: WU-1 for backend, WU-2 for frontend
1929
+ - **Feature Flag**: WU-1 behind flag, WU-2 removes flag
1930
+
1931
+ ---
1932
+
1933
+ ## Quick Reference
1934
+
1935
+ | Scenario | Strategy | Action |
1936
+ | :---------------------------------- | :------------------ | :------------------------------------------- |
1937
+ | Bug fix, single file, <20 calls | Simple | Claim, fix, commit, \`wu:done\` |
1938
+ | Feature 50-100 calls, clear phases | Checkpoint-Resume | Phase 1 → checkpoint → Phase 2 → done |
1939
+ | Multi-domain, must land atomically | Orchestrator-Worker | Main agent coordinates, spawns sub-agents |
1940
+ | Large refactor 100+ calls | Feature Flag Split | WU-A: New behind flag → WU-B: Remove flag |
1941
+
1942
+ ---
1943
+
1944
+ ## Documentation-Only Exception
1945
+
1946
+ Documentation WUs (\`type: documentation\`) have relaxed file count thresholds:
1947
+
1948
+ | Complexity | Files (docs) | Tool Calls | Strategy |
1949
+ | :--------- | :----------- | :--------- | :---------------- |
1950
+ | **Simple** | <40 | <50 | Single Session |
1951
+ | **Medium** | 40-80 | 50-100 | Checkpoint-Resume |
1952
+
1953
+ **Applies when ALL true:**
1954
+ - WU \`type: documentation\`
1955
+ - Only modifies: \`docs/**\`, \`*.md\`
1956
+ - Does NOT touch code paths
1957
+
1958
+ ---
1959
+
1960
+ For complete sizing guidance, see the canonical [wu-sizing-guide.md](https://lumenflow.dev/reference/wu-sizing-guide/) documentation.
1961
+ `;
1754
1962
  // WU-1083: Claude skills templates
1755
1963
  const WU_LIFECYCLE_SKILL_TEMPLATE = `---
1756
1964
  name: wu-lifecycle
@@ -2127,8 +2335,17 @@ export async function scaffoldProject(targetDir, options) {
2127
2335
  };
2128
2336
  // Create .lumenflow.config.yaml (WU-1067: includes gate preset if specified)
2129
2337
  // WU-1364: Includes git config overrides (e.g., requireRemote: false for local-only)
2338
+ // WU-1383: Includes enforcement hooks for Claude client
2130
2339
  // Note: Config files don't use merge mode (always skip or force)
2131
- await createFile(path.join(targetDir, CONFIG_FILE_NAME), generateLumenflowConfigYaml(options.gatePreset, gitConfigOverride), options.force ? 'force' : 'skip', result, targetDir);
2340
+ const configPath = path.join(targetDir, CONFIG_FILE_NAME);
2341
+ // WU-1383: Warn if config already exists to discourage manual editing
2342
+ if (fs.existsSync(configPath) && !options.force) {
2343
+ result.warnings = result.warnings ?? [];
2344
+ result.warnings.push(`${CONFIG_FILE_NAME} already exists. ` +
2345
+ 'To modify configuration, use CLI commands (e.g., pnpm lumenflow:init --force) ' +
2346
+ 'instead of manual editing.');
2347
+ }
2348
+ await createFile(configPath, generateLumenflowConfigYaml(options.gatePreset, gitConfigOverride, client), options.force ? 'force' : 'skip', result, targetDir);
2132
2349
  // WU-1171: Create AGENTS.md (universal entry point for all agents)
2133
2350
  try {
2134
2351
  const agentsTemplate = loadTemplate('core/AGENTS.md.template');
@@ -2382,6 +2599,8 @@ async function scaffoldAgentOnboardingDocs(targetDir, options, result, tokens) {
2382
2599
  await createFile(path.join(onboardingDir, 'troubleshooting-wu-done.md'), processTemplate(TROUBLESHOOTING_WU_DONE_TEMPLATE, tokens), options.force, result, targetDir);
2383
2600
  await createFile(path.join(onboardingDir, 'agent-safety-card.md'), processTemplate(AGENT_SAFETY_CARD_TEMPLATE, tokens), options.force, result, targetDir);
2384
2601
  await createFile(path.join(onboardingDir, 'wu-create-checklist.md'), processTemplate(WU_CREATE_CHECKLIST_TEMPLATE, tokens), options.force, result, targetDir);
2602
+ // WU-1385: Add wu-sizing-guide.md to onboarding docs
2603
+ await createFile(path.join(onboardingDir, 'wu-sizing-guide.md'), processTemplate(WU_SIZING_GUIDE_TEMPLATE, tokens), options.force, result, targetDir);
2385
2604
  }
2386
2605
  /**
2387
2606
  * WU-1083: Scaffold Claude skills
@@ -2559,8 +2778,19 @@ function writeNewFile(filePath, content, result, relativePath) {
2559
2778
  * CLI entry point
2560
2779
  * WU-1085: Updated to use parseInitOptions for proper --help support
2561
2780
  * WU-1171: Added --merge and --client support
2781
+ * WU-1378: Added subcommand routing for 'commands' subcommand
2562
2782
  */
2563
2783
  export async function main() {
2784
+ // WU-1378: Check for subcommands before parsing init options
2785
+ const subcommand = process.argv[2];
2786
+ if (subcommand === 'commands') {
2787
+ // Route to commands subcommand
2788
+ const { main: commandsMain } = await import('./commands.js');
2789
+ // Remove 'commands' from argv so the subcommand parser sees clean args
2790
+ process.argv.splice(2, 1);
2791
+ await commandsMain();
2792
+ return;
2793
+ }
2564
2794
  const opts = parseInitOptions();
2565
2795
  const targetDir = process.cwd();
2566
2796
  console.log('[lumenflow init] Scaffolding LumenFlow project...');
@@ -2603,6 +2833,18 @@ export async function main() {
2603
2833
  console.log('\nWarnings:');
2604
2834
  result.warnings.forEach((w) => console.log(` ⚠ ${w}`));
2605
2835
  }
2836
+ // WU-1386: Run doctor auto-check (non-blocking)
2837
+ // This provides feedback on workflow health without failing init
2838
+ try {
2839
+ const doctorResult = await runDoctorForInit(targetDir);
2840
+ if (doctorResult.output) {
2841
+ console.log('');
2842
+ console.log(doctorResult.output);
2843
+ }
2844
+ }
2845
+ catch {
2846
+ // Doctor check is non-blocking - if it fails, continue with init
2847
+ }
2606
2848
  // WU-1359: Show complete lifecycle with auto-ID (no --id flag required)
2607
2849
  // WU-1364: Added initiative-first guidance for product visions
2608
2850
  console.log('\n[lumenflow init] Done! Next steps:');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lumenflow/cli",
3
- "version": "2.8.0",
3
+ "version": "2.9.0",
4
4
  "description": "Command-line interface for LumenFlow workflow framework",
5
5
  "keywords": [
6
6
  "lumenflow",
@@ -99,6 +99,7 @@
99
99
  "lumenflow-init": "./dist/init.js",
100
100
  "lumenflow": "./dist/init.js",
101
101
  "lumenflow-doctor": "./dist/doctor.js",
102
+ "lumenflow-commands": "./dist/commands.js",
102
103
  "lumenflow-release": "./dist/release.js",
103
104
  "lumenflow-docs-sync": "./dist/docs-sync.js",
104
105
  "lumenflow-sync-templates": "./dist/sync-templates.js",
@@ -150,11 +151,11 @@
150
151
  "pretty-ms": "^9.2.0",
151
152
  "simple-git": "^3.30.0",
152
153
  "yaml": "^2.8.2",
153
- "@lumenflow/core": "2.8.0",
154
- "@lumenflow/memory": "2.8.0",
155
- "@lumenflow/metrics": "2.8.0",
156
- "@lumenflow/agent": "2.8.0",
157
- "@lumenflow/initiatives": "2.8.0"
154
+ "@lumenflow/core": "2.9.0",
155
+ "@lumenflow/metrics": "2.9.0",
156
+ "@lumenflow/memory": "2.9.0",
157
+ "@lumenflow/agent": "2.9.0",
158
+ "@lumenflow/initiatives": "2.9.0"
158
159
  },
159
160
  "devDependencies": {
160
161
  "@vitest/coverage-v8": "^4.0.17",