@lumenflow/core 1.0.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 (263) hide show
  1. package/LICENSE +190 -0
  2. package/README.md +119 -0
  3. package/dist/active-wu-detector.d.ts +33 -0
  4. package/dist/active-wu-detector.js +106 -0
  5. package/dist/adapters/filesystem-metrics.adapter.d.ts +108 -0
  6. package/dist/adapters/filesystem-metrics.adapter.js +519 -0
  7. package/dist/adapters/terminal-renderer.adapter.d.ts +106 -0
  8. package/dist/adapters/terminal-renderer.adapter.js +337 -0
  9. package/dist/arg-parser.d.ts +63 -0
  10. package/dist/arg-parser.js +560 -0
  11. package/dist/backlog-editor.d.ts +98 -0
  12. package/dist/backlog-editor.js +179 -0
  13. package/dist/backlog-generator.d.ts +111 -0
  14. package/dist/backlog-generator.js +381 -0
  15. package/dist/backlog-parser.d.ts +45 -0
  16. package/dist/backlog-parser.js +102 -0
  17. package/dist/backlog-sync-validator.d.ts +78 -0
  18. package/dist/backlog-sync-validator.js +294 -0
  19. package/dist/branch-drift.d.ts +34 -0
  20. package/dist/branch-drift.js +51 -0
  21. package/dist/cleanup-install-config.d.ts +33 -0
  22. package/dist/cleanup-install-config.js +37 -0
  23. package/dist/cleanup-lock.d.ts +139 -0
  24. package/dist/cleanup-lock.js +313 -0
  25. package/dist/code-path-validator.d.ts +146 -0
  26. package/dist/code-path-validator.js +537 -0
  27. package/dist/code-paths-overlap.d.ts +55 -0
  28. package/dist/code-paths-overlap.js +245 -0
  29. package/dist/commands-logger.d.ts +77 -0
  30. package/dist/commands-logger.js +254 -0
  31. package/dist/commit-message-utils.d.ts +25 -0
  32. package/dist/commit-message-utils.js +41 -0
  33. package/dist/compliance-parser.d.ts +150 -0
  34. package/dist/compliance-parser.js +507 -0
  35. package/dist/constants/backlog-patterns.d.ts +20 -0
  36. package/dist/constants/backlog-patterns.js +23 -0
  37. package/dist/constants/dora-constants.d.ts +49 -0
  38. package/dist/constants/dora-constants.js +53 -0
  39. package/dist/constants/gate-constants.d.ts +15 -0
  40. package/dist/constants/gate-constants.js +15 -0
  41. package/dist/constants/linter-constants.d.ts +16 -0
  42. package/dist/constants/linter-constants.js +16 -0
  43. package/dist/constants/tokenizer-constants.d.ts +15 -0
  44. package/dist/constants/tokenizer-constants.js +15 -0
  45. package/dist/core/scope-checker.d.ts +97 -0
  46. package/dist/core/scope-checker.js +163 -0
  47. package/dist/core/tool-runner.d.ts +161 -0
  48. package/dist/core/tool-runner.js +393 -0
  49. package/dist/core/tool.constants.d.ts +105 -0
  50. package/dist/core/tool.constants.js +101 -0
  51. package/dist/core/tool.schemas.d.ts +226 -0
  52. package/dist/core/tool.schemas.js +226 -0
  53. package/dist/core/worktree-guard.d.ts +130 -0
  54. package/dist/core/worktree-guard.js +242 -0
  55. package/dist/coverage-gate.d.ts +108 -0
  56. package/dist/coverage-gate.js +196 -0
  57. package/dist/date-utils.d.ts +75 -0
  58. package/dist/date-utils.js +140 -0
  59. package/dist/dependency-graph.d.ts +142 -0
  60. package/dist/dependency-graph.js +550 -0
  61. package/dist/dependency-guard.d.ts +54 -0
  62. package/dist/dependency-guard.js +142 -0
  63. package/dist/dependency-validator.d.ts +105 -0
  64. package/dist/dependency-validator.js +154 -0
  65. package/dist/docs-path-validator.d.ts +36 -0
  66. package/dist/docs-path-validator.js +95 -0
  67. package/dist/domain/orchestration.constants.d.ts +99 -0
  68. package/dist/domain/orchestration.constants.js +97 -0
  69. package/dist/domain/orchestration.schemas.d.ts +280 -0
  70. package/dist/domain/orchestration.schemas.js +211 -0
  71. package/dist/domain/orchestration.types.d.ts +133 -0
  72. package/dist/domain/orchestration.types.js +12 -0
  73. package/dist/error-handler.d.ts +116 -0
  74. package/dist/error-handler.js +136 -0
  75. package/dist/file-classifiers.d.ts +62 -0
  76. package/dist/file-classifiers.js +108 -0
  77. package/dist/gates-agent-mode.d.ts +81 -0
  78. package/dist/gates-agent-mode.js +94 -0
  79. package/dist/generate-traceability.d.ts +107 -0
  80. package/dist/generate-traceability.js +411 -0
  81. package/dist/git-adapter.d.ts +395 -0
  82. package/dist/git-adapter.js +649 -0
  83. package/dist/git-staged-validator.d.ts +32 -0
  84. package/dist/git-staged-validator.js +48 -0
  85. package/dist/hardcoded-strings.d.ts +61 -0
  86. package/dist/hardcoded-strings.js +270 -0
  87. package/dist/incremental-lint.d.ts +78 -0
  88. package/dist/incremental-lint.js +129 -0
  89. package/dist/incremental-test.d.ts +39 -0
  90. package/dist/incremental-test.js +61 -0
  91. package/dist/index.d.ts +42 -0
  92. package/dist/index.js +61 -0
  93. package/dist/invariants/check-automated-tests.d.ts +50 -0
  94. package/dist/invariants/check-automated-tests.js +166 -0
  95. package/dist/invariants-runner.d.ts +103 -0
  96. package/dist/invariants-runner.js +527 -0
  97. package/dist/lane-checker.d.ts +50 -0
  98. package/dist/lane-checker.js +319 -0
  99. package/dist/lane-inference.d.ts +39 -0
  100. package/dist/lane-inference.js +195 -0
  101. package/dist/lane-lock.d.ts +211 -0
  102. package/dist/lane-lock.js +474 -0
  103. package/dist/lane-validator.d.ts +48 -0
  104. package/dist/lane-validator.js +114 -0
  105. package/dist/logs-lib.d.ts +104 -0
  106. package/dist/logs-lib.js +207 -0
  107. package/dist/lumenflow-config-schema.d.ts +272 -0
  108. package/dist/lumenflow-config-schema.js +207 -0
  109. package/dist/lumenflow-config.d.ts +95 -0
  110. package/dist/lumenflow-config.js +236 -0
  111. package/dist/manual-test-validator.d.ts +80 -0
  112. package/dist/manual-test-validator.js +200 -0
  113. package/dist/merge-lock.d.ts +115 -0
  114. package/dist/merge-lock.js +251 -0
  115. package/dist/micro-worktree.d.ts +159 -0
  116. package/dist/micro-worktree.js +427 -0
  117. package/dist/migration-deployer.d.ts +69 -0
  118. package/dist/migration-deployer.js +151 -0
  119. package/dist/orchestration-advisory-loader.d.ts +28 -0
  120. package/dist/orchestration-advisory-loader.js +87 -0
  121. package/dist/orchestration-advisory.d.ts +58 -0
  122. package/dist/orchestration-advisory.js +94 -0
  123. package/dist/orchestration-di.d.ts +48 -0
  124. package/dist/orchestration-di.js +57 -0
  125. package/dist/orchestration-rules.d.ts +57 -0
  126. package/dist/orchestration-rules.js +201 -0
  127. package/dist/orphan-detector.d.ts +131 -0
  128. package/dist/orphan-detector.js +226 -0
  129. package/dist/path-classifiers.d.ts +57 -0
  130. package/dist/path-classifiers.js +93 -0
  131. package/dist/piped-command-detector.d.ts +34 -0
  132. package/dist/piped-command-detector.js +64 -0
  133. package/dist/ports/dashboard-renderer.port.d.ts +112 -0
  134. package/dist/ports/dashboard-renderer.port.js +25 -0
  135. package/dist/ports/metrics-collector.port.d.ts +132 -0
  136. package/dist/ports/metrics-collector.port.js +26 -0
  137. package/dist/process-detector.d.ts +84 -0
  138. package/dist/process-detector.js +172 -0
  139. package/dist/prompt-linter.d.ts +72 -0
  140. package/dist/prompt-linter.js +312 -0
  141. package/dist/prompt-monitor.d.ts +15 -0
  142. package/dist/prompt-monitor.js +205 -0
  143. package/dist/rebase-artifact-cleanup.d.ts +145 -0
  144. package/dist/rebase-artifact-cleanup.js +433 -0
  145. package/dist/retry-strategy.d.ts +189 -0
  146. package/dist/retry-strategy.js +283 -0
  147. package/dist/risk-detector.d.ts +108 -0
  148. package/dist/risk-detector.js +252 -0
  149. package/dist/rollback-utils.d.ts +76 -0
  150. package/dist/rollback-utils.js +104 -0
  151. package/dist/section-headings.d.ts +43 -0
  152. package/dist/section-headings.js +49 -0
  153. package/dist/spawn-escalation.d.ts +90 -0
  154. package/dist/spawn-escalation.js +253 -0
  155. package/dist/spawn-monitor.d.ts +229 -0
  156. package/dist/spawn-monitor.js +672 -0
  157. package/dist/spawn-recovery.d.ts +82 -0
  158. package/dist/spawn-recovery.js +298 -0
  159. package/dist/spawn-registry-schema.d.ts +98 -0
  160. package/dist/spawn-registry-schema.js +108 -0
  161. package/dist/spawn-registry-store.d.ts +146 -0
  162. package/dist/spawn-registry-store.js +273 -0
  163. package/dist/spawn-tree.d.ts +121 -0
  164. package/dist/spawn-tree.js +285 -0
  165. package/dist/stamp-status-validator.d.ts +84 -0
  166. package/dist/stamp-status-validator.js +134 -0
  167. package/dist/stamp-utils.d.ts +100 -0
  168. package/dist/stamp-utils.js +229 -0
  169. package/dist/state-machine.d.ts +26 -0
  170. package/dist/state-machine.js +83 -0
  171. package/dist/system-map-validator.d.ts +80 -0
  172. package/dist/system-map-validator.js +272 -0
  173. package/dist/telemetry.d.ts +80 -0
  174. package/dist/telemetry.js +213 -0
  175. package/dist/token-counter.d.ts +51 -0
  176. package/dist/token-counter.js +145 -0
  177. package/dist/usecases/get-dashboard-data.usecase.d.ts +52 -0
  178. package/dist/usecases/get-dashboard-data.usecase.js +61 -0
  179. package/dist/usecases/get-suggestions.usecase.d.ts +100 -0
  180. package/dist/usecases/get-suggestions.usecase.js +153 -0
  181. package/dist/user-normalizer.d.ts +41 -0
  182. package/dist/user-normalizer.js +141 -0
  183. package/dist/validators/phi-constants.d.ts +97 -0
  184. package/dist/validators/phi-constants.js +152 -0
  185. package/dist/validators/phi-scanner.d.ts +58 -0
  186. package/dist/validators/phi-scanner.js +215 -0
  187. package/dist/worktree-ownership.d.ts +50 -0
  188. package/dist/worktree-ownership.js +74 -0
  189. package/dist/worktree-scanner.d.ts +103 -0
  190. package/dist/worktree-scanner.js +168 -0
  191. package/dist/worktree-symlink.d.ts +99 -0
  192. package/dist/worktree-symlink.js +359 -0
  193. package/dist/wu-backlog-updater.d.ts +17 -0
  194. package/dist/wu-backlog-updater.js +37 -0
  195. package/dist/wu-checkpoint.d.ts +124 -0
  196. package/dist/wu-checkpoint.js +233 -0
  197. package/dist/wu-claim-helpers.d.ts +26 -0
  198. package/dist/wu-claim-helpers.js +63 -0
  199. package/dist/wu-claim-resume.d.ts +106 -0
  200. package/dist/wu-claim-resume.js +276 -0
  201. package/dist/wu-consistency-checker.d.ts +95 -0
  202. package/dist/wu-consistency-checker.js +567 -0
  203. package/dist/wu-constants.d.ts +1275 -0
  204. package/dist/wu-constants.js +1382 -0
  205. package/dist/wu-create-validators.d.ts +42 -0
  206. package/dist/wu-create-validators.js +93 -0
  207. package/dist/wu-done-branch-only.d.ts +63 -0
  208. package/dist/wu-done-branch-only.js +191 -0
  209. package/dist/wu-done-messages.d.ts +119 -0
  210. package/dist/wu-done-messages.js +185 -0
  211. package/dist/wu-done-pr.d.ts +72 -0
  212. package/dist/wu-done-pr.js +174 -0
  213. package/dist/wu-done-retry-helpers.d.ts +85 -0
  214. package/dist/wu-done-retry-helpers.js +172 -0
  215. package/dist/wu-done-ui.d.ts +37 -0
  216. package/dist/wu-done-ui.js +69 -0
  217. package/dist/wu-done-validators.d.ts +411 -0
  218. package/dist/wu-done-validators.js +1229 -0
  219. package/dist/wu-done-worktree.d.ts +182 -0
  220. package/dist/wu-done-worktree.js +1097 -0
  221. package/dist/wu-helpers.d.ts +128 -0
  222. package/dist/wu-helpers.js +248 -0
  223. package/dist/wu-lint.d.ts +70 -0
  224. package/dist/wu-lint.js +234 -0
  225. package/dist/wu-paths.d.ts +171 -0
  226. package/dist/wu-paths.js +178 -0
  227. package/dist/wu-preflight-validators.d.ts +86 -0
  228. package/dist/wu-preflight-validators.js +251 -0
  229. package/dist/wu-recovery.d.ts +138 -0
  230. package/dist/wu-recovery.js +341 -0
  231. package/dist/wu-repair-core.d.ts +131 -0
  232. package/dist/wu-repair-core.js +669 -0
  233. package/dist/wu-schema-normalization.d.ts +17 -0
  234. package/dist/wu-schema-normalization.js +82 -0
  235. package/dist/wu-schema.d.ts +793 -0
  236. package/dist/wu-schema.js +881 -0
  237. package/dist/wu-spawn-helpers.d.ts +121 -0
  238. package/dist/wu-spawn-helpers.js +271 -0
  239. package/dist/wu-spawn.d.ts +158 -0
  240. package/dist/wu-spawn.js +1306 -0
  241. package/dist/wu-state-schema.d.ts +213 -0
  242. package/dist/wu-state-schema.js +156 -0
  243. package/dist/wu-state-store.d.ts +264 -0
  244. package/dist/wu-state-store.js +691 -0
  245. package/dist/wu-status-transition.d.ts +63 -0
  246. package/dist/wu-status-transition.js +382 -0
  247. package/dist/wu-status-updater.d.ts +25 -0
  248. package/dist/wu-status-updater.js +116 -0
  249. package/dist/wu-transaction-collectors.d.ts +116 -0
  250. package/dist/wu-transaction-collectors.js +272 -0
  251. package/dist/wu-transaction.d.ts +170 -0
  252. package/dist/wu-transaction.js +273 -0
  253. package/dist/wu-validation-constants.d.ts +60 -0
  254. package/dist/wu-validation-constants.js +66 -0
  255. package/dist/wu-validation.d.ts +118 -0
  256. package/dist/wu-validation.js +243 -0
  257. package/dist/wu-validator.d.ts +62 -0
  258. package/dist/wu-validator.js +325 -0
  259. package/dist/wu-yaml-fixer.d.ts +97 -0
  260. package/dist/wu-yaml-fixer.js +264 -0
  261. package/dist/wu-yaml.d.ts +86 -0
  262. package/dist/wu-yaml.js +222 -0
  263. package/package.json +114 -0
@@ -0,0 +1,121 @@
1
+ /**
2
+ * @file wu-spawn-helpers.mjs
3
+ * Helper functions for wu:spawn thinking mode and model configuration (WU-1577)
4
+ *
5
+ * Provides:
6
+ * - CLI argument parsing for thinking mode options
7
+ * - Validation for thinking/budget options
8
+ * - Execution Mode section generation
9
+ * - Think tool guidance generation
10
+ * - Help text generation
11
+ * - Spawn registry integration (WU-1945)
12
+ */
13
+ /**
14
+ * Option definitions for thinking mode configuration.
15
+ *
16
+ * Note: Commander.js handles --no-thinking automatically as a negation of --thinking.
17
+ * When --no-thinking is used, opts.thinking is set to false.
18
+ * We detect this and convert to noThinking: true for clarity.
19
+ */
20
+ export declare const THINKING_OPTIONS: {
21
+ thinking: {
22
+ name: string;
23
+ flags: string;
24
+ description: string;
25
+ };
26
+ budget: {
27
+ name: string;
28
+ flags: string;
29
+ description: string;
30
+ };
31
+ };
32
+ /**
33
+ * Parse spawn-specific arguments from argv.
34
+ *
35
+ * @param {string[]} argv - Process arguments
36
+ * @returns {object} Parsed arguments with thinking options
37
+ */
38
+ export declare function parseSpawnArgs(argv: any): import("commander").OptionValues;
39
+ /**
40
+ * Validate spawn arguments for consistency.
41
+ *
42
+ * @param {object} args - Parsed arguments
43
+ * @throws {Error} If validation fails
44
+ */
45
+ export declare function validateSpawnArgs(args: any): void;
46
+ /**
47
+ * Generate the Execution Mode section for the task prompt.
48
+ *
49
+ * @param {object} options - Thinking mode options
50
+ * @param {boolean} [options.thinking] - Whether extended thinking is enabled
51
+ * @param {boolean} [options.noThinking] - Whether thinking is explicitly disabled
52
+ * @param {string} [options.budget] - Token budget for thinking
53
+ * @returns {string} Execution Mode section or empty string if no thinking flags
54
+ */
55
+ export declare function generateExecutionModeSection(options: any): string;
56
+ /**
57
+ * Generate think tool guidance for the task prompt.
58
+ *
59
+ * @param {object} options - Thinking mode options
60
+ * @param {boolean} [options.thinking] - Whether extended thinking is enabled
61
+ * @param {boolean} [options.noThinking] - Whether thinking is explicitly disabled
62
+ * @returns {string} Think tool guidance or empty string if not applicable
63
+ */
64
+ export declare function generateThinkToolGuidance(options: any): "" | "## Think Tool Guidance\n\nWhen extended thinking is enabled, use the think tool strategically for:\n\n1. **Complex Decision Points**: Before making architectural decisions or choosing between approaches\n2. **Multi-Step Reasoning**: When planning long tool-call chains or multi-file edits\n3. **Mid-Execution Reflection**: After gathering information, before implementing changes\n4. **Error Analysis**: When troubleshooting failures or unexpected behavior\n\n### Best Practices\n\n- Use think blocks to reason through acceptance criteria before implementation\n- Document your reasoning for complex logic decisions\n- Break down large tasks into thought-through steps\n- Reflect on test results before proceeding with fixes\n\n### When NOT to Use Think Blocks\n\n- Simple file reads or writes with clear outcomes\n- Routine git operations\n- Running predefined commands like `pnpm gates`\n- When the next action is obvious and low-risk";
65
+ /**
66
+ * Generate help text with examples for thinking mode options.
67
+ *
68
+ * @returns {string} Help text with option descriptions and examples
69
+ */
70
+ export declare function getHelpText(): string;
71
+ /**
72
+ * Records a spawn event to the spawn registry.
73
+ *
74
+ * This function is non-blocking: if the registry write fails, it returns
75
+ * a result with success=false but does NOT throw an error. This ensures
76
+ * wu:spawn succeeds even if the registry is unavailable.
77
+ *
78
+ * @param {object} options - Spawn recording options
79
+ * @param {string} options.parentWuId - Parent WU ID (orchestrator)
80
+ * @param {string} options.targetWuId - Target WU ID (spawned work)
81
+ * @param {string} options.lane - Lane for the spawned work
82
+ * @param {string} [options.baseDir] - Base directory for registry (defaults to .beacon/state)
83
+ * @returns {Promise<{success: boolean, spawnId: string|null, error?: string}>}
84
+ *
85
+ * @example
86
+ * const result = await recordSpawnToRegistry({
87
+ * parentWuId: 'WU-1000',
88
+ * targetWuId: 'WU-1001',
89
+ * lane: 'Operations: Tooling',
90
+ * });
91
+ *
92
+ * if (result.success) {
93
+ * console.log(`Recorded: ${result.spawnId}`);
94
+ * }
95
+ */
96
+ export declare function recordSpawnToRegistry(options: any): Promise<{
97
+ success: boolean;
98
+ spawnId: string;
99
+ error?: undefined;
100
+ } | {
101
+ success: boolean;
102
+ spawnId: any;
103
+ error: any;
104
+ }>;
105
+ /**
106
+ * Formats a message about spawn recording result.
107
+ *
108
+ * @param {string|null} spawnId - Spawn ID if successful, null otherwise
109
+ * @param {string} [errorMessage] - Error message if spawn recording failed
110
+ * @returns {string} Formatted message for console output
111
+ *
112
+ * @example
113
+ * // Successful recording
114
+ * formatSpawnRecordedMessage('spawn-abc1');
115
+ * // Returns: '[wu:spawn] Spawn recorded spawn-abc1'
116
+ *
117
+ * // Failed recording
118
+ * formatSpawnRecordedMessage(null, 'Registry unavailable');
119
+ * // Returns: '[wu:spawn] Warning: Registry write skipped (Registry unavailable)'
120
+ */
121
+ export declare function formatSpawnRecordedMessage(spawnId: any, errorMessage?: any): string;
@@ -0,0 +1,271 @@
1
+ /**
2
+ * @file wu-spawn-helpers.mjs
3
+ * Helper functions for wu:spawn thinking mode and model configuration (WU-1577)
4
+ *
5
+ * Provides:
6
+ * - CLI argument parsing for thinking mode options
7
+ * - Validation for thinking/budget options
8
+ * - Execution Mode section generation
9
+ * - Think tool guidance generation
10
+ * - Help text generation
11
+ * - Spawn registry integration (WU-1945)
12
+ */
13
+ import { Command } from 'commander';
14
+ import { SpawnRegistryStore } from './spawn-registry-store.js';
15
+ /**
16
+ * Option definitions for thinking mode configuration.
17
+ *
18
+ * Note: Commander.js handles --no-thinking automatically as a negation of --thinking.
19
+ * When --no-thinking is used, opts.thinking is set to false.
20
+ * We detect this and convert to noThinking: true for clarity.
21
+ */
22
+ export const THINKING_OPTIONS = {
23
+ thinking: {
24
+ name: 'thinking',
25
+ flags: '--thinking',
26
+ description: 'Enable extended thinking for complex WU execution',
27
+ },
28
+ budget: {
29
+ name: 'budget',
30
+ flags: '--budget <tokens>',
31
+ description: 'Token budget for extended thinking (requires --thinking)',
32
+ },
33
+ };
34
+ /**
35
+ * Parse spawn-specific arguments from argv.
36
+ *
37
+ * @param {string[]} argv - Process arguments
38
+ * @returns {object} Parsed arguments with thinking options
39
+ */
40
+ export function parseSpawnArgs(argv) {
41
+ const program = new Command()
42
+ .name('wu-spawn')
43
+ .description('Generate Task tool invocation for sub-agent WU execution')
44
+ .allowUnknownOption(true)
45
+ .allowExcessArguments(true) // Allow positional WU ID argument
46
+ .exitOverride();
47
+ // Core options
48
+ program.option('-i, --id <wuId>', 'Work Unit ID (e.g., WU-123)');
49
+ // Thinking mode options
50
+ // Commander automatically creates --no-thinking when --thinking is registered
51
+ program.option(THINKING_OPTIONS.thinking.flags, THINKING_OPTIONS.thinking.description);
52
+ program.option(THINKING_OPTIONS.budget.flags, THINKING_OPTIONS.budget.description);
53
+ try {
54
+ program.parse(argv);
55
+ }
56
+ catch (err) {
57
+ if (err.code === 'commander.helpDisplayed' || err.code === 'commander.version') {
58
+ process.exit(0);
59
+ }
60
+ throw err;
61
+ }
62
+ const opts = program.opts();
63
+ // Handle positional argument as WU ID fallback
64
+ if (program.args.length > 0 && !opts.id) {
65
+ opts.id = program.args[0];
66
+ }
67
+ // Handle --no-thinking explicitly
68
+ // Check the argv array directly since Commander's handling of negated booleans varies
69
+ if (argv.includes('--no-thinking')) {
70
+ opts.noThinking = true;
71
+ delete opts.thinking;
72
+ }
73
+ return opts;
74
+ }
75
+ /**
76
+ * Validate spawn arguments for consistency.
77
+ *
78
+ * @param {object} args - Parsed arguments
79
+ * @throws {Error} If validation fails
80
+ */
81
+ export function validateSpawnArgs(args) {
82
+ // Check mutually exclusive flags
83
+ if (args.thinking && args.noThinking) {
84
+ throw new Error('--thinking and --no-thinking are mutually exclusive');
85
+ }
86
+ // Budget requires thinking
87
+ if (args.budget && !args.thinking) {
88
+ throw new Error('--budget requires --thinking flag');
89
+ }
90
+ // Budget must be positive integer
91
+ if (args.budget) {
92
+ const budgetNum = parseInt(args.budget, 10);
93
+ if (isNaN(budgetNum) || budgetNum <= 0 || !Number.isInteger(budgetNum)) {
94
+ throw new Error('--budget must be a positive integer');
95
+ }
96
+ }
97
+ }
98
+ /**
99
+ * Generate the Execution Mode section for the task prompt.
100
+ *
101
+ * @param {object} options - Thinking mode options
102
+ * @param {boolean} [options.thinking] - Whether extended thinking is enabled
103
+ * @param {boolean} [options.noThinking] - Whether thinking is explicitly disabled
104
+ * @param {string} [options.budget] - Token budget for thinking
105
+ * @returns {string} Execution Mode section or empty string if no thinking flags
106
+ */
107
+ export function generateExecutionModeSection(options) {
108
+ const { thinking, noThinking, budget } = options;
109
+ // No section if no thinking flags specified (default behavior)
110
+ if (!thinking && !noThinking) {
111
+ return '';
112
+ }
113
+ const lines = ['## Execution Mode', ''];
114
+ if (thinking) {
115
+ lines.push('Extended thinking: **enabled**');
116
+ if (budget) {
117
+ lines.push(`Token budget: **${budget}**`);
118
+ }
119
+ lines.push('');
120
+ lines.push('The sub-agent will use extended thinking for complex reasoning tasks.');
121
+ }
122
+ else if (noThinking) {
123
+ lines.push('Extended thinking: **disabled**');
124
+ lines.push('');
125
+ lines.push('The sub-agent will execute without extended thinking mode.');
126
+ }
127
+ return lines.join('\n');
128
+ }
129
+ /**
130
+ * Generate think tool guidance for the task prompt.
131
+ *
132
+ * @param {object} options - Thinking mode options
133
+ * @param {boolean} [options.thinking] - Whether extended thinking is enabled
134
+ * @param {boolean} [options.noThinking] - Whether thinking is explicitly disabled
135
+ * @returns {string} Think tool guidance or empty string if not applicable
136
+ */
137
+ export function generateThinkToolGuidance(options) {
138
+ const { thinking, noThinking } = options;
139
+ // No guidance if thinking is disabled or not specified
140
+ if (!thinking || noThinking) {
141
+ return '';
142
+ }
143
+ return `## Think Tool Guidance
144
+
145
+ When extended thinking is enabled, use the think tool strategically for:
146
+
147
+ 1. **Complex Decision Points**: Before making architectural decisions or choosing between approaches
148
+ 2. **Multi-Step Reasoning**: When planning long tool-call chains or multi-file edits
149
+ 3. **Mid-Execution Reflection**: After gathering information, before implementing changes
150
+ 4. **Error Analysis**: When troubleshooting failures or unexpected behavior
151
+
152
+ ### Best Practices
153
+
154
+ - Use think blocks to reason through acceptance criteria before implementation
155
+ - Document your reasoning for complex logic decisions
156
+ - Break down large tasks into thought-through steps
157
+ - Reflect on test results before proceeding with fixes
158
+
159
+ ### When NOT to Use Think Blocks
160
+
161
+ - Simple file reads or writes with clear outcomes
162
+ - Routine git operations
163
+ - Running predefined commands like \`pnpm gates\`
164
+ - When the next action is obvious and low-risk`;
165
+ }
166
+ /**
167
+ * Generate help text with examples for thinking mode options.
168
+ *
169
+ * @returns {string} Help text with option descriptions and examples
170
+ */
171
+ export function getHelpText() {
172
+ return `
173
+ Thinking Mode Options:
174
+
175
+ --thinking Enable extended thinking for complex WU execution
176
+ --no-thinking Explicitly disable extended thinking (default behavior)
177
+ --budget <tokens> Token budget for extended thinking (requires --thinking)
178
+
179
+ Examples:
180
+
181
+ # Enable extended thinking for a complex WU
182
+ pnpm wu:spawn --id WU-123 --thinking
183
+
184
+ # Enable thinking with a specific token budget
185
+ pnpm wu:spawn --id WU-456 --thinking --budget 10000
186
+
187
+ # Explicitly disable thinking (useful for clear-spec WUs)
188
+ pnpm wu:spawn --id WU-789 --no-thinking
189
+
190
+ Notes:
191
+
192
+ - Default behavior (no flags) preserves backward compatibility
193
+ - --budget requires --thinking flag to be set
194
+ - --thinking and --no-thinking are mutually exclusive
195
+ - Token budget is passed to the sub-agent's execution configuration
196
+ `;
197
+ }
198
+ /**
199
+ * Log prefix for spawn registry messages (WU-1945)
200
+ */
201
+ const LOG_PREFIX = '[wu:spawn]';
202
+ /**
203
+ * Records a spawn event to the spawn registry.
204
+ *
205
+ * This function is non-blocking: if the registry write fails, it returns
206
+ * a result with success=false but does NOT throw an error. This ensures
207
+ * wu:spawn succeeds even if the registry is unavailable.
208
+ *
209
+ * @param {object} options - Spawn recording options
210
+ * @param {string} options.parentWuId - Parent WU ID (orchestrator)
211
+ * @param {string} options.targetWuId - Target WU ID (spawned work)
212
+ * @param {string} options.lane - Lane for the spawned work
213
+ * @param {string} [options.baseDir] - Base directory for registry (defaults to .beacon/state)
214
+ * @returns {Promise<{success: boolean, spawnId: string|null, error?: string}>}
215
+ *
216
+ * @example
217
+ * const result = await recordSpawnToRegistry({
218
+ * parentWuId: 'WU-1000',
219
+ * targetWuId: 'WU-1001',
220
+ * lane: 'Operations: Tooling',
221
+ * });
222
+ *
223
+ * if (result.success) {
224
+ * console.log(`Recorded: ${result.spawnId}`);
225
+ * }
226
+ */
227
+ export async function recordSpawnToRegistry(options) {
228
+ const { parentWuId, targetWuId, lane, baseDir = '.beacon/state' } = options;
229
+ try {
230
+ const store = new SpawnRegistryStore(baseDir);
231
+ await store.load();
232
+ const spawnId = await store.record(parentWuId, targetWuId, lane);
233
+ return {
234
+ success: true,
235
+ spawnId,
236
+ };
237
+ }
238
+ catch (error) {
239
+ // Non-blocking: return failure result instead of throwing
240
+ return {
241
+ success: false,
242
+ spawnId: null,
243
+ error: error.message,
244
+ };
245
+ }
246
+ }
247
+ /**
248
+ * Formats a message about spawn recording result.
249
+ *
250
+ * @param {string|null} spawnId - Spawn ID if successful, null otherwise
251
+ * @param {string} [errorMessage] - Error message if spawn recording failed
252
+ * @returns {string} Formatted message for console output
253
+ *
254
+ * @example
255
+ * // Successful recording
256
+ * formatSpawnRecordedMessage('spawn-abc1');
257
+ * // Returns: '[wu:spawn] Spawn recorded spawn-abc1'
258
+ *
259
+ * // Failed recording
260
+ * formatSpawnRecordedMessage(null, 'Registry unavailable');
261
+ * // Returns: '[wu:spawn] Warning: Registry write skipped (Registry unavailable)'
262
+ */
263
+ export function formatSpawnRecordedMessage(spawnId, errorMessage = undefined) {
264
+ if (spawnId) {
265
+ return `${LOG_PREFIX} Spawn recorded ${spawnId}`;
266
+ }
267
+ if (errorMessage) {
268
+ return `${LOG_PREFIX} Warning: Registry write skipped (${errorMessage})`;
269
+ }
270
+ return `${LOG_PREFIX} Warning: Registry unavailable`;
271
+ }
@@ -0,0 +1,158 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * WU Spawn Helper
4
+ *
5
+ * Generates ready-to-use Task tool invocations for sub-agent WU execution.
6
+ * Includes context loading preamble, skills selection guidance, and constraints block.
7
+ *
8
+ * Usage:
9
+ * pnpm wu:spawn --id WU-123
10
+ * pnpm wu:spawn --id WU-123 --codex
11
+ *
12
+ * Output:
13
+ * A complete Task tool invocation block with:
14
+ * - Context loading preamble (CLAUDE-core.md, README, lumenflow, WU YAML)
15
+ * - WU details and acceptance criteria
16
+ * - Skills Selection section (sub-agent reads catalogue and selects at runtime)
17
+ * - Mandatory agent advisory
18
+ * - Constraints block at end (Lost in the Middle research)
19
+ *
20
+ * Skills Selection:
21
+ * This command is AGENT-FACING. Unlike /wu-prompt (human-facing, skills selected
22
+ * at generation time), wu:spawn instructs the sub-agent to read the skill catalogue
23
+ * and select skills at execution time based on WU context.
24
+ *
25
+ * Codex Mode:
26
+ * When --codex is used, outputs a Codex/GPT-friendly Markdown prompt (no antml/XML escaping).
27
+ *
28
+ * @see {@link ai/onboarding/agent-invocation-guide.md} - Context loading templates
29
+ */
30
+ /**
31
+ * Generate effort scaling rules section (WU-1986)
32
+ *
33
+ * Based on Anthropic multi-agent research: helps agents decide when to
34
+ * spawn sub-agents vs handle inline.
35
+ *
36
+ * @returns {string} Effort scaling section
37
+ */
38
+ export declare function generateEffortScalingRules(): string;
39
+ /**
40
+ * Generate parallel tool call guidance (WU-1986)
41
+ *
42
+ * Based on Anthropic research: 3+ parallel tool calls significantly improve performance.
43
+ *
44
+ * @returns {string} Parallel tool call guidance
45
+ */
46
+ export declare function generateParallelToolCallGuidance(): string;
47
+ /**
48
+ * Generate iterative search heuristics (WU-1986)
49
+ *
50
+ * Based on Anthropic research: start broad, narrow focus.
51
+ *
52
+ * @returns {string} Search heuristics section
53
+ */
54
+ export declare function generateIterativeSearchHeuristics(): string;
55
+ /**
56
+ * Generate token budget awareness section (WU-1986)
57
+ *
58
+ * @param {string} id - WU ID
59
+ * @returns {string} Token budget section
60
+ */
61
+ export declare function generateTokenBudgetAwareness(id: any): string;
62
+ /**
63
+ * Generate structured completion format (WU-1986)
64
+ *
65
+ * @param {string} id - WU ID
66
+ * @returns {string} Completion format section
67
+ */
68
+ export declare function generateCompletionFormat(_id: any): string;
69
+ /**
70
+ * Generate agent coordination section (WU-1987)
71
+ *
72
+ * Provides guidance on mem:signal for parallel agent coordination,
73
+ * orchestrate:status for dashboard checks, and abandoned WU handling.
74
+ *
75
+ * @param {string} id - WU ID
76
+ * @returns {string} Agent coordination section
77
+ */
78
+ export declare function generateAgentCoordinationSection(id: any): string;
79
+ /**
80
+ * Generate quick fix commands section (WU-1987)
81
+ *
82
+ * Provides format/lint/typecheck commands for quick fixes before gates.
83
+ *
84
+ * @returns {string} Quick fix commands section
85
+ */
86
+ export declare function generateQuickFixCommands(): string;
87
+ /**
88
+ * Generate Lane Selection section (WU-2107)
89
+ *
90
+ * Provides guidance on lane selection when creating new WUs.
91
+ * Points agents to wu:infer-lane for automated lane suggestions.
92
+ *
93
+ * @returns {string} Lane Selection section
94
+ */
95
+ export declare function generateLaneSelectionSection(): string;
96
+ /**
97
+ * Generate Worktree Path Guidance section (WU-2362)
98
+ *
99
+ * Provides guidance for sub-agents on working within worktrees, including
100
+ * how to determine the worktree root and where to create stamps.
101
+ *
102
+ * Problem: CLAUDE_PROJECT_DIR is hook-only; sub-agents inherit parent cwd (main).
103
+ * Solution: Use git rev-parse --show-toplevel to determine actual worktree root.
104
+ *
105
+ * @param {string|undefined} worktreePath - Worktree path from WU YAML
106
+ * @returns {string} Worktree path guidance section
107
+ */
108
+ export declare function generateWorktreePathGuidance(worktreePath: any): string;
109
+ /**
110
+ * Generate the Action section based on WU claim status (WU-1745).
111
+ *
112
+ * If WU is already claimed (has claimed_at and worktree_path), tells agent
113
+ * to continue in the existing worktree.
114
+ *
115
+ * If WU is unclaimed (status: ready), tells agent to run wu:claim first.
116
+ *
117
+ * @param {object} doc - WU YAML document
118
+ * @param {string} id - WU ID
119
+ * @returns {string} Action section content
120
+ */
121
+ export declare function generateActionSection(doc: any, id: any): string;
122
+ /**
123
+ * Generate the complete Task tool invocation
124
+ *
125
+ * @param {object} doc - WU YAML document
126
+ * @param {string} id - WU ID
127
+ * @param {object} [options={}] - Thinking mode options
128
+ * @param {boolean} [options.thinking] - Whether extended thinking is enabled
129
+ * @param {boolean} [options.noThinking] - Whether thinking is explicitly disabled
130
+ * @param {string} [options.budget] - Token budget for thinking
131
+ * @returns {string} Complete Task tool invocation
132
+ */
133
+ export declare function generateTaskInvocation(doc: any, id: any, options?: {}): string;
134
+ export declare function generateCodexPrompt(doc: any, id: any, options?: {}): string;
135
+ /**
136
+ * WU-1603: Check if a lane is currently occupied by another WU
137
+ *
138
+ * @param {string} lane - Lane name (e.g., "Operations: Tooling")
139
+ * @returns {import('./lib/lane-lock.js').LockMetadata|null} Lock metadata if occupied, null otherwise
140
+ */
141
+ export declare function checkLaneOccupation(lane: any): import("./lane-lock.js").LockMetadata;
142
+ /**
143
+ * Options for lane occupation warning
144
+ */
145
+ interface LaneOccupationWarningOptions {
146
+ /** Whether the lock is stale (>24h old) */
147
+ isStale?: boolean;
148
+ }
149
+ /**
150
+ * WU-1603: Generate a warning message when lane is occupied
151
+ *
152
+ * @param {import('./lib/lane-lock.js').LockMetadata} lockMetadata - Lock metadata
153
+ * @param {string} targetWuId - WU ID being spawned
154
+ * @param {LaneOccupationWarningOptions} [options={}] - Options
155
+ * @returns {string} Warning message
156
+ */
157
+ export declare function generateLaneOccupationWarning(lockMetadata: any, targetWuId: any, options?: LaneOccupationWarningOptions): string;
158
+ export {};