@lumenflow/cli 4.24.0 → 5.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 (294) hide show
  1. package/README.md +54 -52
  2. package/dist/agent-issues-query.js +10 -2
  3. package/dist/agent-issues-query.js.map +1 -1
  4. package/dist/agent-runtime-enrollment-events.js +44 -0
  5. package/dist/agent-runtime-enrollment-events.js.map +1 -0
  6. package/dist/agent-session-end.js +47 -0
  7. package/dist/agent-session-end.js.map +1 -1
  8. package/dist/agent-session-heartbeat.js +250 -0
  9. package/dist/agent-session-heartbeat.js.map +1 -0
  10. package/dist/agent-session.js +299 -5
  11. package/dist/agent-session.js.map +1 -1
  12. package/dist/capacity-snapshot-emitter.js +73 -0
  13. package/dist/capacity-snapshot-emitter.js.map +1 -0
  14. package/dist/claim-queue.js +276 -0
  15. package/dist/claim-queue.js.map +1 -0
  16. package/dist/config-set.js +22 -3
  17. package/dist/config-set.js.map +1 -1
  18. package/dist/control-plane-sidecar-runner.js +145 -0
  19. package/dist/control-plane-sidecar-runner.js.map +1 -0
  20. package/dist/delegation-list.js +160 -1
  21. package/dist/delegation-list.js.map +1 -1
  22. package/dist/delegation-role-resolver.js +69 -0
  23. package/dist/delegation-role-resolver.js.map +1 -0
  24. package/dist/docs-generate-pack-reference.js +500 -0
  25. package/dist/docs-generate-pack-reference.js.map +1 -0
  26. package/dist/docs-sync.js +116 -1
  27. package/dist/docs-sync.js.map +1 -1
  28. package/dist/file-edit.js +28 -8
  29. package/dist/file-edit.js.map +1 -1
  30. package/dist/file-write.js +29 -5
  31. package/dist/file-write.js.map +1 -1
  32. package/dist/gate-co-change.js +25 -7
  33. package/dist/gate-co-change.js.map +1 -1
  34. package/dist/gate-conditional.js +19 -7
  35. package/dist/gate-conditional.js.map +1 -1
  36. package/dist/gates-runners.js +42 -33
  37. package/dist/gates-runners.js.map +1 -1
  38. package/dist/gates-utils.js +34 -20
  39. package/dist/gates-utils.js.map +1 -1
  40. package/dist/gates.js +79 -7
  41. package/dist/gates.js.map +1 -1
  42. package/dist/hooks/config-resolver.js +10 -1
  43. package/dist/hooks/config-resolver.js.map +1 -1
  44. package/dist/init-package-config.js +1 -1
  45. package/dist/init-package-config.js.map +1 -1
  46. package/dist/init-scaffolding.js +5 -1
  47. package/dist/init-scaffolding.js.map +1 -1
  48. package/dist/init-templates.js +10 -0
  49. package/dist/init-templates.js.map +1 -1
  50. package/dist/init.js +1 -1
  51. package/dist/init.js.map +1 -1
  52. package/dist/initiative-create.js +17 -0
  53. package/dist/initiative-create.js.map +1 -1
  54. package/dist/initiative-remove-wu.js +17 -3
  55. package/dist/initiative-remove-wu.js.map +1 -1
  56. package/dist/kernel-event-sync/emitters.js +104 -0
  57. package/dist/kernel-event-sync/emitters.js.map +1 -0
  58. package/dist/kernel-event-sync/index.js +13 -0
  59. package/dist/kernel-event-sync/index.js.map +1 -0
  60. package/dist/kernel-event-sync/lifecycle-emitters.js +160 -0
  61. package/dist/kernel-event-sync/lifecycle-emitters.js.map +1 -0
  62. package/dist/kernel-event-sync/narrow-emissions.js +89 -0
  63. package/dist/kernel-event-sync/narrow-emissions.js.map +1 -0
  64. package/dist/kernel-event-sync/software-delivery-emitters.js +297 -0
  65. package/dist/kernel-event-sync/software-delivery-emitters.js.map +1 -0
  66. package/dist/lane-lock.js +14 -1
  67. package/dist/lane-lock.js.map +1 -1
  68. package/dist/lane-suggest.js +21 -0
  69. package/dist/lane-suggest.js.map +1 -1
  70. package/dist/lumenflow-upgrade.js +7 -5
  71. package/dist/lumenflow-upgrade.js.map +1 -1
  72. package/dist/mem-context.js +145 -0
  73. package/dist/mem-context.js.map +1 -1
  74. package/dist/mem-create.js +39 -6
  75. package/dist/mem-create.js.map +1 -1
  76. package/dist/mem-inbox.js +16 -0
  77. package/dist/mem-inbox.js.map +1 -1
  78. package/dist/mem-roster.js +95 -0
  79. package/dist/mem-roster.js.map +1 -0
  80. package/dist/mem-signal.js +97 -2
  81. package/dist/mem-signal.js.map +1 -1
  82. package/dist/metrics-snapshot.js +3 -2
  83. package/dist/metrics-snapshot.js.map +1 -1
  84. package/dist/orchestrate-init-status.js +117 -2
  85. package/dist/orchestrate-init-status.js.map +1 -1
  86. package/dist/orchestrate-initiative.js +83 -10
  87. package/dist/orchestrate-initiative.js.map +1 -1
  88. package/dist/orchestrate-monitor-quality.js +289 -0
  89. package/dist/orchestrate-monitor-quality.js.map +1 -0
  90. package/dist/orchestrate-monitor.js +85 -0
  91. package/dist/orchestrate-monitor.js.map +1 -1
  92. package/dist/pack-validate.js +127 -2
  93. package/dist/pack-validate.js.map +1 -1
  94. package/dist/plan-create.js +18 -0
  95. package/dist/plan-create.js.map +1 -1
  96. package/dist/plan-link.js +13 -0
  97. package/dist/plan-link.js.map +1 -1
  98. package/dist/plan-promote.js +14 -0
  99. package/dist/plan-promote.js.map +1 -1
  100. package/dist/pre-commit-check.js +4 -3
  101. package/dist/pre-commit-check.js.map +1 -1
  102. package/dist/public-manifest.js +17 -3
  103. package/dist/public-manifest.js.map +1 -1
  104. package/dist/release.js +10 -10
  105. package/dist/release.js.map +1 -1
  106. package/dist/session-cross-link.js +139 -0
  107. package/dist/session-cross-link.js.map +1 -0
  108. package/dist/sidecar-manager.js +208 -0
  109. package/dist/sidecar-manager.js.map +1 -0
  110. package/dist/state-path-resolvers.js +18 -0
  111. package/dist/state-path-resolvers.js.map +1 -1
  112. package/dist/stream-heartbeat.js +151 -0
  113. package/dist/stream-heartbeat.js.map +1 -0
  114. package/dist/sync-templates.js +56 -2
  115. package/dist/sync-templates.js.map +1 -1
  116. package/dist/wu-block.js +47 -5
  117. package/dist/wu-block.js.map +1 -1
  118. package/dist/wu-claim-branch.js +8 -4
  119. package/dist/wu-claim-branch.js.map +1 -1
  120. package/dist/wu-claim-state.js +5 -3
  121. package/dist/wu-claim-state.js.map +1 -1
  122. package/dist/wu-claim-worktree.js +5 -3
  123. package/dist/wu-claim-worktree.js.map +1 -1
  124. package/dist/wu-claim.js +261 -9
  125. package/dist/wu-claim.js.map +1 -1
  126. package/dist/wu-done-auto-cleanup.js +3 -2
  127. package/dist/wu-done-auto-cleanup.js.map +1 -1
  128. package/dist/wu-done-git-ops.js +12 -8
  129. package/dist/wu-done-git-ops.js.map +1 -1
  130. package/dist/wu-done-preflight.js +3 -3
  131. package/dist/wu-done-preflight.js.map +1 -1
  132. package/dist/wu-done.js +46 -10
  133. package/dist/wu-done.js.map +1 -1
  134. package/dist/wu-lifecycle-sync/gate-scope-resolver.js +16 -0
  135. package/dist/wu-lifecycle-sync/gate-scope-resolver.js.map +1 -0
  136. package/dist/wu-lifecycle-sync/kernel-event-sync-shim.js +10 -0
  137. package/dist/wu-lifecycle-sync/kernel-event-sync-shim.js.map +1 -0
  138. package/dist/wu-prep.js +363 -22
  139. package/dist/wu-prep.js.map +1 -1
  140. package/dist/wu-prune.js +68 -27
  141. package/dist/wu-prune.js.map +1 -1
  142. package/dist/wu-release.js +34 -3
  143. package/dist/wu-release.js.map +1 -1
  144. package/dist/wu-review.js +167 -0
  145. package/dist/wu-review.js.map +1 -0
  146. package/dist/wu-spawn-prompt-builders.js +296 -40
  147. package/dist/wu-spawn-prompt-builders.js.map +1 -1
  148. package/dist/wu-spawn-strategy-resolver.js +126 -14
  149. package/dist/wu-spawn-strategy-resolver.js.map +1 -1
  150. package/dist/wu-unblock.js +52 -22
  151. package/dist/wu-unblock.js.map +1 -1
  152. package/package.json +13 -8
  153. package/packs/agent-runtime/.turbo/turbo-build.log +1 -1
  154. package/packs/agent-runtime/.turbo/turbo-test.log +25 -0
  155. package/packs/agent-runtime/.turbo/turbo-typecheck.log +4 -0
  156. package/packs/agent-runtime/agent-heartbeat.ts +163 -0
  157. package/packs/agent-runtime/auto-session-integration.ts +874 -0
  158. package/packs/agent-runtime/delegation-registry-schema.ts +220 -0
  159. package/packs/agent-runtime/delegation-registry-store.ts +269 -0
  160. package/packs/agent-runtime/delegation-tree.ts +328 -0
  161. package/packs/agent-runtime/index.ts +9 -0
  162. package/packs/agent-runtime/manifest.ts +103 -19
  163. package/packs/agent-runtime/manifest.yaml +132 -0
  164. package/packs/agent-runtime/memory-coordination-contract.ts +86 -0
  165. package/packs/agent-runtime/memory.d.ts +19 -0
  166. package/packs/agent-runtime/orchestration.ts +238 -23
  167. package/packs/agent-runtime/package.json +11 -2
  168. package/packs/agent-runtime/remote-controls/index.ts +7 -0
  169. package/packs/agent-runtime/remote-controls/operations.ts +399 -0
  170. package/packs/agent-runtime/remote-controls/port.ts +48 -0
  171. package/packs/agent-runtime/remote-controls/state-store.ts +258 -0
  172. package/packs/agent-runtime/remote-controls/types.ts +105 -0
  173. package/packs/agent-runtime/session-schema.ts +423 -0
  174. package/packs/agent-runtime/tool-impl/index.ts +1 -0
  175. package/packs/agent-runtime/tool-impl/remote-controls.mock.ts +252 -0
  176. package/packs/agent-runtime/tool-impl/remote-controls.ts +273 -0
  177. package/packs/agent-runtime/tsconfig.json +1 -1
  178. package/packs/agent-runtime/turn-lifecycle-events.ts +501 -0
  179. package/packs/sidekick/.lumenflow/state/conductor/outbox/sidekick-events.jsonl +213 -0
  180. package/packs/sidekick/.turbo/turbo-build.log +1 -1
  181. package/packs/sidekick/.turbo/turbo-test.log +25 -0
  182. package/packs/sidekick/.turbo/turbo-typecheck.log +4 -0
  183. package/packs/sidekick/channel-ingress.ts +137 -0
  184. package/packs/sidekick/manifest.ts +74 -0
  185. package/packs/sidekick/manifest.yaml +88 -0
  186. package/packs/sidekick/package.json +3 -1
  187. package/packs/sidekick/sidekick-events.ts +517 -0
  188. package/packs/sidekick/src/adapters/cloud-queue.ts +101 -0
  189. package/packs/sidekick/src/adapters/control-plane-bridge.adapter.ts +378 -0
  190. package/packs/sidekick/src/adapters/filesystem-bridge.adapter.ts +224 -0
  191. package/packs/sidekick/src/domain/channel.types.ts +84 -0
  192. package/packs/sidekick/src/ports/channel-bridge.port.ts +75 -0
  193. package/packs/sidekick/src/routines/commit.ts +74 -0
  194. package/packs/sidekick/tool-impl/channel-tools.ts +47 -0
  195. package/packs/sidekick/tool-impl/memory-tools.ts +17 -0
  196. package/packs/sidekick/tool-impl/routine-commit.ts +102 -0
  197. package/packs/sidekick/tool-impl/routine-tools.ts +67 -7
  198. package/packs/sidekick/tool-impl/runtime-context.ts +4 -0
  199. package/packs/sidekick/tool-impl/storage.ts +3 -0
  200. package/packs/sidekick/tool-impl/system-tools.ts +7 -0
  201. package/packs/sidekick/tool-impl/task-tools.ts +46 -0
  202. package/packs/sidekick/tsconfig.json +1 -1
  203. package/packs/software-delivery/.turbo/turbo-build.log +1 -1
  204. package/packs/software-delivery/.turbo/turbo-test.log +63 -0
  205. package/packs/software-delivery/.turbo/turbo-typecheck.log +4 -0
  206. package/packs/software-delivery/manifest-schema.ts +30 -0
  207. package/packs/software-delivery/manifest.ts +99 -1
  208. package/packs/software-delivery/manifest.yaml +46 -0
  209. package/packs/software-delivery/package.json +88 -3
  210. package/packs/software-delivery/src/commands/index.ts +5 -0
  211. package/packs/software-delivery/src/config/delivery-review-contract.ts +20 -0
  212. package/packs/software-delivery/src/config/env-accessors.ts +19 -0
  213. package/packs/software-delivery/src/config/index.ts +8 -0
  214. package/packs/software-delivery/src/config/normalize-config-keys.ts +19 -0
  215. package/packs/software-delivery/src/config/schemas/lumenflow-config-schema-types.ts +436 -0
  216. package/packs/software-delivery/src/config/workspace-reader.ts +310 -0
  217. package/packs/software-delivery/src/constants/backlog-patterns.ts +31 -0
  218. package/packs/software-delivery/src/constants/client-ids.ts +19 -0
  219. package/packs/software-delivery/src/constants/config-contract.ts +7 -0
  220. package/packs/software-delivery/src/constants/docs-layout-presets.ts +50 -0
  221. package/packs/software-delivery/src/constants/duration-constants.ts +20 -0
  222. package/packs/software-delivery/src/constants/gate-constants.ts +32 -0
  223. package/packs/software-delivery/src/constants/index.ts +29 -0
  224. package/packs/software-delivery/src/constants/lock-constants.ts +35 -0
  225. package/packs/software-delivery/src/constants/object-guards.ts +12 -0
  226. package/packs/software-delivery/src/constants/section-headings.ts +107 -0
  227. package/packs/software-delivery/src/constants/wu-cli-constants.ts +485 -0
  228. package/packs/software-delivery/src/constants/wu-domain-constants.ts +466 -0
  229. package/packs/software-delivery/src/constants/wu-git-constants.ts +7 -0
  230. package/packs/software-delivery/src/constants/wu-id-format.ts +327 -0
  231. package/packs/software-delivery/src/constants/wu-paths-constants.ts +358 -0
  232. package/packs/software-delivery/src/constants/wu-statuses.ts +287 -0
  233. package/packs/software-delivery/src/constants/wu-type-helpers.ts +67 -0
  234. package/packs/software-delivery/src/constants/wu-ui-constants.ts +267 -0
  235. package/packs/software-delivery/src/constants/wu-validation-constants.ts +73 -0
  236. package/packs/software-delivery/src/domain/index.ts +5 -0
  237. package/packs/software-delivery/src/domain/orchestration.constants.ts +168 -0
  238. package/packs/software-delivery/src/domain/orchestration.schemas.ts +239 -0
  239. package/packs/software-delivery/src/domain/orchestration.types.ts +178 -0
  240. package/packs/software-delivery/src/methodology/incremental-test.ts +90 -0
  241. package/packs/software-delivery/src/methodology/index.ts +6 -0
  242. package/packs/software-delivery/src/methodology/manual-test-validator.ts +292 -0
  243. package/packs/software-delivery/src/policy/coverage-gate.ts +270 -0
  244. package/packs/software-delivery/src/policy/gates-agent-mode.ts +223 -0
  245. package/packs/software-delivery/src/policy/gates-config-internal.ts +121 -0
  246. package/packs/software-delivery/src/policy/gates-config.ts +293 -0
  247. package/packs/software-delivery/src/policy/gates-coverage.ts +247 -0
  248. package/packs/software-delivery/src/policy/gates-presets.ts +134 -0
  249. package/packs/software-delivery/src/policy/gates-schemas.ts +173 -0
  250. package/packs/software-delivery/src/policy/index.ts +22 -0
  251. package/packs/software-delivery/src/policy/package-manager-resolver.ts +319 -0
  252. package/packs/software-delivery/src/policy/resolve-policy.ts +518 -0
  253. package/packs/software-delivery/src/ports/config.ports.ts +90 -0
  254. package/packs/software-delivery/src/ports/dashboard-renderer.port.ts +125 -0
  255. package/packs/software-delivery/src/ports/index.ts +10 -0
  256. package/packs/software-delivery/src/ports/sync-validator.ports.ts +59 -0
  257. package/packs/software-delivery/src/ports/wu-helpers.ports.ts +168 -0
  258. package/packs/software-delivery/src/ports/wu-state.ports.ts +241 -0
  259. package/packs/software-delivery/src/primitives/index.ts +5 -0
  260. package/packs/software-delivery/src/runtime/index.ts +6 -0
  261. package/packs/software-delivery/src/runtime/work-classifier.ts +561 -0
  262. package/packs/software-delivery/src/sandbox/index.ts +10 -0
  263. package/packs/software-delivery/src/sandbox/sandbox-allowlist.ts +118 -0
  264. package/packs/software-delivery/src/sandbox/sandbox-backend-linux.ts +88 -0
  265. package/packs/software-delivery/src/sandbox/sandbox-backend-macos.ts +154 -0
  266. package/packs/software-delivery/src/sandbox/sandbox-backend-windows.ts +47 -0
  267. package/packs/software-delivery/src/sandbox/sandbox-profile.ts +153 -0
  268. package/packs/software-delivery/src/schemas/index.ts +5 -0
  269. package/packs/software-delivery/src/state/date-utils.ts +158 -0
  270. package/packs/software-delivery/src/state/index.ts +15 -0
  271. package/packs/software-delivery/src/state/state-machine.ts +119 -0
  272. package/packs/software-delivery/src/state/wu-doc-types.ts +51 -0
  273. package/packs/software-delivery/src/state/wu-paths.ts +381 -0
  274. package/packs/software-delivery/src/state/wu-schema.ts +1139 -0
  275. package/packs/software-delivery/src/state/wu-state-schema.ts +255 -0
  276. package/packs/software-delivery/src/state/wu-yaml.ts +338 -0
  277. package/packs/software-delivery/src/types.d.ts +16 -0
  278. package/packs/software-delivery/tool-impl/wu-lifecycle-tools.ts +18 -0
  279. package/packs/software-delivery/tsconfig.json +28 -2
  280. package/templates/core/AGENTS.md.template +76 -17
  281. package/templates/core/LUMENFLOW.md.template +265 -66
  282. package/templates/core/_frameworks/lumenflow/wu-sizing-guide.md.template +180 -116
  283. package/templates/core/ai/onboarding/agent-invocation-guide.md.template +26 -8
  284. package/templates/core/ai/onboarding/existing-project-bootstrap.md.template +171 -0
  285. package/templates/core/ai/onboarding/first-15-mins.md.template +3 -1
  286. package/templates/core/ai/onboarding/first-wu-mistakes.md.template +1 -1
  287. package/templates/core/ai/onboarding/initiative-orchestration.md.template +46 -30
  288. package/templates/core/ai/onboarding/quick-ref-commands.md.template +36 -33
  289. package/templates/core/ai/onboarding/release-process.md.template +8 -7
  290. package/templates/core/ai/onboarding/starting-prompt.md.template +2 -0
  291. package/templates/core/ai/onboarding/troubleshooting-wu-done.md.template +62 -0
  292. package/templates/vendors/claude/.claude/CLAUDE.md.template +29 -54
  293. package/templates/vendors/cursor/.cursor/rules/lumenflow.md.template +24 -52
  294. package/templates/vendors/windsurf/.windsurf/rules/lumenflow.md.template +24 -52
@@ -0,0 +1,223 @@
1
+ // Copyright (c) 2026 Hellmai Ltd
2
+ // SPDX-License-Identifier: AGPL-3.0-only
3
+
4
+ import path from 'node:path';
5
+ import { existsSync, unlinkSync, symlinkSync } from 'node:fs';
6
+
7
+ /**
8
+ * Options for agent mode detection
9
+ */
10
+ interface GatesAgentModeOptions {
11
+ /** Command line arguments */
12
+ argv?: string[];
13
+ /** Environment variables */
14
+ env?: Record<string, string | undefined>;
15
+ /** stdout stream */
16
+ stdout?: { isTTY?: boolean };
17
+ }
18
+
19
+ /**
20
+ * Options for log path functions
21
+ */
22
+ interface GatesLogOptions {
23
+ /** Working directory */
24
+ cwd: string;
25
+ /** Environment variables */
26
+ env?: Record<string, string | undefined>;
27
+ }
28
+
29
+ /**
30
+ * Options for building gate log path
31
+ */
32
+ interface BuildGatesLogPathOptions extends GatesLogOptions {
33
+ /** WU ID */
34
+ wuId?: string;
35
+ /** Lane name */
36
+ lane?: string;
37
+ /** Current timestamp */
38
+ now?: Date;
39
+ }
40
+
41
+ /**
42
+ * Options for updating symlink
43
+ */
44
+ interface UpdateGatesLatestSymlinkOptions extends GatesLogOptions {
45
+ /** Path to the actual gate log file */
46
+ logPath: string;
47
+ }
48
+
49
+ /**
50
+ * Determine whether gates should run in low-noise "agent mode".
51
+ *
52
+ * Agent mode is intended for Claude Code sessions, where tool output is injected into the
53
+ * conversation context and can trigger "prompt too long".
54
+ *
55
+ * Detection strategy (WU-1827):
56
+ * 1. --verbose flag always forces full output (returns false)
57
+ * 2. CLAUDE_PROJECT_DIR env var is a strong hint (returns true if set)
58
+ * 3. TTY check: non-TTY + non-CI = likely agent mode (returns true)
59
+ * 4. Interactive TTY = human user (returns false)
60
+ *
61
+ * @param {GatesAgentModeOptions} options
62
+ * @returns {boolean} True if gates should run in agent mode
63
+ */
64
+ export function shouldUseGatesAgentMode({ argv, env, stdout }: GatesAgentModeOptions = {}) {
65
+ // --verbose flag always forces full output
66
+ const isVerbose = Array.isArray(argv) && argv.includes('--verbose');
67
+ if (isVerbose) {
68
+ return false;
69
+ }
70
+
71
+ // CLAUDE_PROJECT_DIR is a strong hint that we're in Claude Code
72
+ const hasClaudeProjectDir = Boolean(env?.CLAUDE_PROJECT_DIR);
73
+ if (hasClaudeProjectDir) {
74
+ return true;
75
+ }
76
+
77
+ // CI environments should get full output for debugging
78
+ const isCI = Boolean(env?.CI);
79
+ if (isCI) {
80
+ return false;
81
+ }
82
+
83
+ // Use provided stdout or fall back to process.stdout
84
+ const stdoutStream = stdout ?? process.stdout;
85
+
86
+ // TTY check: non-TTY = likely agent mode (Claude Code Bash tool doesn't have TTY)
87
+ // If stdout is undefined or isTTY is falsy, assume agent mode (safer default)
88
+ const isTTY = stdoutStream?.isTTY ?? false;
89
+
90
+ // Non-TTY + non-CI = likely agent mode
91
+ return !isTTY;
92
+ }
93
+
94
+ export function getGatesLogDir({ cwd, env }: GatesLogOptions) {
95
+ const configured = env?.LUMENFLOW_LOG_DIR;
96
+ return path.resolve(cwd, configured || '.logs');
97
+ }
98
+
99
+ export function buildGatesLogPath({
100
+ cwd,
101
+ env,
102
+ wuId,
103
+ lane,
104
+ now = new Date(),
105
+ }: BuildGatesLogPathOptions) {
106
+ const logDir = getGatesLogDir({ cwd, env });
107
+ const safeLane = (lane || 'unknown').toLowerCase().replace(/[^a-z0-9]+/g, '-');
108
+ const safeWu = (wuId || 'unknown').toLowerCase().replace(/[^a-z0-9]+/g, '-');
109
+ const stamp = now.toISOString().replace(/[:.]/g, '-');
110
+ return path.join(logDir, `gates-${safeLane}-${safeWu}-${stamp}.log`);
111
+ }
112
+
113
+ /**
114
+ * Get the path to the gates-latest.log symlink (WU-2064)
115
+ *
116
+ * @param {Object} options
117
+ * @param {string} options.cwd - Working directory
118
+ * @param {Object} [options.env] - Environment variables
119
+ * @returns {string} Path to the symlink
120
+ */
121
+ export function getGatesLatestSymlinkPath({ cwd, env }: GatesLogOptions) {
122
+ const logDir = getGatesLogDir({ cwd, env });
123
+ return path.join(logDir, 'gates-latest.log');
124
+ }
125
+
126
+ /**
127
+ * Create or update the gates-latest.log symlink to point to the most recent gate run (WU-2064)
128
+ *
129
+ * This provides a stable path for agents to access the most recent gate log
130
+ * without needing to know the timestamp-based filename.
131
+ *
132
+ * @param {Object} options
133
+ * @param {string} options.logPath - Path to the actual gate log file
134
+ * @param {string} options.cwd - Working directory
135
+ * @param {Object} [options.env] - Environment variables
136
+ * @returns {boolean} True if symlink was created/updated successfully
137
+ */
138
+ export function updateGatesLatestSymlink({ logPath, cwd, env }: UpdateGatesLatestSymlinkOptions) {
139
+ const symlinkPath = getGatesLatestSymlinkPath({ cwd, env });
140
+
141
+ try {
142
+ // Remove existing symlink if present
143
+ if (existsSync(symlinkPath)) {
144
+ unlinkSync(symlinkPath);
145
+ }
146
+
147
+ // Create relative symlink (so it works regardless of absolute path)
148
+ const logDir = path.dirname(symlinkPath);
149
+ const relativePath = path.relative(logDir, logPath);
150
+ symlinkSync(relativePath, symlinkPath);
151
+
152
+ return true;
153
+ } catch {
154
+ // Symlink creation is best-effort, don't fail gates
155
+ return false;
156
+ }
157
+ }
158
+
159
+ export const WU_DONE_PRE_COMMIT_GATE_DECISION_REASONS = {
160
+ SKIP_GATES_FLAG: 'skip-gates-flag',
161
+ REUSE_STEP_ZERO: 'reuse-step-zero',
162
+ REUSE_CHECKPOINT: 'reuse-checkpoint',
163
+ RUN_REQUIRED: 'run-required',
164
+ } as const;
165
+
166
+ export type WuDonePreCommitGateDecisionReason =
167
+ (typeof WU_DONE_PRE_COMMIT_GATE_DECISION_REASONS)[keyof typeof WU_DONE_PRE_COMMIT_GATE_DECISION_REASONS];
168
+
169
+ export interface WuDonePreCommitGateDecisionInput {
170
+ skipGates: boolean;
171
+ fullGatesRanInCurrentRun: boolean;
172
+ skippedByCheckpoint: boolean;
173
+ checkpointId?: string | null;
174
+ }
175
+
176
+ export interface WuDonePreCommitGateDecision {
177
+ runPreCommitFullSuite: boolean;
178
+ reason: WuDonePreCommitGateDecisionReason;
179
+ message: string;
180
+ }
181
+
182
+ /**
183
+ * Decide whether wu:done pre-flight hook validation should rerun full gates.
184
+ *
185
+ * WU-1659: Avoid duplicate full-suite execution when Step 0 already ran gates
186
+ * (or reused a valid checkpoint), while keeping operator-visible reasoning.
187
+ */
188
+ export function resolveWuDonePreCommitGateDecision(
189
+ input: WuDonePreCommitGateDecisionInput,
190
+ ): WuDonePreCommitGateDecision {
191
+ if (input.skipGates) {
192
+ return {
193
+ runPreCommitFullSuite: false,
194
+ reason: WU_DONE_PRE_COMMIT_GATE_DECISION_REASONS.SKIP_GATES_FLAG,
195
+ message: 'Pre-flight hook validation skipped because --skip-gates is active.',
196
+ };
197
+ }
198
+
199
+ if (input.fullGatesRanInCurrentRun) {
200
+ return {
201
+ runPreCommitFullSuite: false,
202
+ reason: WU_DONE_PRE_COMMIT_GATE_DECISION_REASONS.REUSE_STEP_ZERO,
203
+ message:
204
+ 'Pre-flight hook validation reuses Step 0 gate results; duplicate full-suite run skipped.',
205
+ };
206
+ }
207
+
208
+ if (input.skippedByCheckpoint) {
209
+ const checkpointSuffix = input.checkpointId ? ` (${input.checkpointId})` : '';
210
+ return {
211
+ runPreCommitFullSuite: false,
212
+ reason: WU_DONE_PRE_COMMIT_GATE_DECISION_REASONS.REUSE_CHECKPOINT,
213
+ message: `Pre-flight hook validation reuses checkpoint gate attestation${checkpointSuffix}; duplicate full-suite run skipped.`,
214
+ };
215
+ }
216
+
217
+ return {
218
+ runPreCommitFullSuite: true,
219
+ reason: WU_DONE_PRE_COMMIT_GATE_DECISION_REASONS.RUN_REQUIRED,
220
+ message:
221
+ 'No gate attestation found for this wu:done run; executing pre-flight hook gate suite.',
222
+ };
223
+ }
@@ -0,0 +1,121 @@
1
+ // Copyright (c) 2026 Hellmai Ltd
2
+ // SPDX-License-Identifier: AGPL-3.0-only
3
+
4
+ /**
5
+ * Gates Configuration Internals
6
+ *
7
+ * WU-2037: Shared infrastructure for gates modules
8
+ *
9
+ * Contains runtime defaults, field-name constants, and config-loading helpers
10
+ * used by gates-config.ts, gates-coverage.ts, and package-manager-resolver.ts.
11
+ *
12
+ * This module exists to break circular imports between the facade (gates-config.ts)
13
+ * and its extracted sub-modules.
14
+ *
15
+ * @module gates-config-internal
16
+ */
17
+
18
+ import * as fs from 'node:fs';
19
+ import * as path from 'node:path';
20
+ import * as yaml from 'yaml';
21
+ import { WORKSPACE_CONFIG_FILE_NAME, WORKSPACE_V2_KEYS } from '../constants/config-contract.js';
22
+ import { asRecord } from '../constants/object-guards.js';
23
+ import { getDefaultPolicy } from './resolve-policy.js';
24
+
25
+ // ---------------------------------------------------------------------------
26
+ // Runtime defaults
27
+ // ---------------------------------------------------------------------------
28
+
29
+ const DEFAULT_POLICY = getDefaultPolicy();
30
+
31
+ export const GATES_RUNTIME_DEFAULTS = {
32
+ COMMAND_TIMEOUT_MS: 120000,
33
+ MAX_ESLINT_WARNINGS: 100,
34
+ DEFAULT_MIN_COVERAGE: DEFAULT_POLICY.coverage_threshold,
35
+ DEFAULT_ENABLE_COVERAGE: true,
36
+ DEFAULT_PACKAGE_MANAGER: 'pnpm',
37
+ DEFAULT_TEST_RUNNER: 'vitest',
38
+ } as const;
39
+
40
+ // ---------------------------------------------------------------------------
41
+ // Field-name constants (avoid magic strings across modules)
42
+ // ---------------------------------------------------------------------------
43
+
44
+ const SOFTWARE_DELIVERY_KEY = WORKSPACE_V2_KEYS.SOFTWARE_DELIVERY;
45
+
46
+ export const SOFTWARE_DELIVERY_FIELDS = {
47
+ GATES: 'gates',
48
+ METHODOLOGY: 'methodology',
49
+ PACKAGE_MANAGER: 'package_manager',
50
+ PACKAGE_MANAGER_CAMEL: 'packageManager',
51
+ TEST_RUNNER: 'test_runner',
52
+ TEST_RUNNER_CAMEL: 'testRunner',
53
+ BUILD_COMMAND: 'build_command',
54
+ BUILD_COMMAND_CAMEL: 'buildCommand',
55
+ } as const;
56
+
57
+ export const GATES_FIELDS = {
58
+ EXECUTION: 'execution',
59
+ LANE_HEALTH: 'lane_health',
60
+ LANE_HEALTH_CAMEL: 'laneHealth',
61
+ TDD_DIFF_EVIDENCE: 'tdd_diff_evidence',
62
+ TDD_ORDERING: 'tdd_ordering',
63
+ MIN_COVERAGE: 'minCoverage',
64
+ MIN_COVERAGE_SNAKE: 'min_coverage',
65
+ ENABLE_COVERAGE: 'enableCoverage',
66
+ ENABLE_COVERAGE_SNAKE: 'enable_coverage',
67
+ COMMANDS: 'commands',
68
+ } as const;
69
+
70
+ export const GATES_COMMAND_FIELDS = {
71
+ TEST_FULL: 'test_full',
72
+ TEST_DOCS_ONLY: 'test_docs_only',
73
+ TEST_INCREMENTAL: 'test_incremental',
74
+ LINT: 'lint',
75
+ TYPECHECK: 'typecheck',
76
+ FORMAT: 'format',
77
+ MIGRATION_VERIFY: 'migration_verify',
78
+ } as const;
79
+
80
+ // ---------------------------------------------------------------------------
81
+ // Config loading helpers
82
+ // ---------------------------------------------------------------------------
83
+
84
+ /**
85
+ * Load the software_delivery section from workspace.yaml
86
+ *
87
+ * @param projectRoot - Project root directory
88
+ * @returns Parsed software_delivery record, or null
89
+ */
90
+ export function loadSoftwareDeliveryConfig(projectRoot: string): Record<string, unknown> | null {
91
+ const configPath = path.join(projectRoot, WORKSPACE_CONFIG_FILE_NAME);
92
+
93
+ if (!fs.existsSync(configPath)) {
94
+ return null;
95
+ }
96
+
97
+ try {
98
+ const content = fs.readFileSync(configPath, 'utf8');
99
+ const data = asRecord(yaml.parse(content));
100
+ if (!data) {
101
+ return null;
102
+ }
103
+ return asRecord(data[SOFTWARE_DELIVERY_KEY]);
104
+ } catch {
105
+ return null;
106
+ }
107
+ }
108
+
109
+ /**
110
+ * Load the gates sub-section from workspace.yaml software_delivery
111
+ *
112
+ * @param projectRoot - Project root directory
113
+ * @returns Parsed gates record, or null
114
+ */
115
+ export function getGatesSection(projectRoot: string): Record<string, unknown> | null {
116
+ const softwareDelivery = loadSoftwareDeliveryConfig(projectRoot);
117
+ if (!softwareDelivery) {
118
+ return null;
119
+ }
120
+ return asRecord(softwareDelivery[SOFTWARE_DELIVERY_FIELDS.GATES]);
121
+ }
@@ -0,0 +1,293 @@
1
+ // Copyright (c) 2026 Hellmai Ltd
2
+ // SPDX-License-Identifier: AGPL-3.0-only
3
+
4
+ /**
5
+ * Gates Configuration Facade
6
+ *
7
+ * WU-1067: Config-driven gates execution
8
+ * WU-2037: Decomposed into focused sub-modules
9
+ *
10
+ * This module is the public entry point for gates configuration.
11
+ * It re-exports from the extracted sub-modules and retains the
12
+ * config-loading, parsing, and lane-health functions that depend
13
+ * on the shared infrastructure.
14
+ *
15
+ * Sub-modules:
16
+ * - gates-schemas.ts Zod schemas, types, interfaces
17
+ * - gates-presets.ts Preset definitions and expansion
18
+ * - gates-coverage.ts Coverage and test policy resolution
19
+ * - package-manager-resolver.ts PM, TR, build, commands, ignore
20
+ * - gates-config-internal.ts Shared helpers and constants
21
+ *
22
+ * @module gates-config
23
+ */
24
+
25
+ import { isString } from '../constants/object-guards.js';
26
+ import { WORKSPACE_CONFIG_FILE_NAME, WORKSPACE_V2_KEYS } from '../constants/config-contract.js';
27
+ import {
28
+ GatesExecutionConfigSchema,
29
+ LaneHealthModeSchema,
30
+ DEFAULT_LANE_HEALTH_MODE,
31
+ } from './gates-schemas.js';
32
+ import type {
33
+ GateCommandConfig,
34
+ GatesExecutionConfig,
35
+ ParsedGateCommand,
36
+ LaneHealthMode,
37
+ } from './gates-schemas.js';
38
+ import { expandPreset } from './gates-presets.js';
39
+ import { GATES_RUNTIME_DEFAULTS, GATES_FIELDS, getGatesSection } from './gates-config-internal.js';
40
+
41
+ // ---------------------------------------------------------------------------
42
+ // Re-exports: schemas, types, and interfaces
43
+ // ---------------------------------------------------------------------------
44
+
45
+ export type {
46
+ GateCommandConfig,
47
+ GatesExecutionConfig,
48
+ ParsedGateCommand,
49
+ LaneHealthMode,
50
+ CoverageConfig,
51
+ CoveragePolicy,
52
+ TestRunnerPolicy,
53
+ TestPolicy,
54
+ GatesCommands,
55
+ } from './gates-schemas.js';
56
+ export type { TddDiffEvidencePolicy, TddOrderingPolicy } from './resolve-policy.js';
57
+
58
+ export type { ScopedUnitTestExecutionPlan } from './package-manager-resolver.js';
59
+
60
+ export {
61
+ GateCommandConfigSchema,
62
+ GatesExecutionConfigSchema,
63
+ LaneHealthModeSchema,
64
+ DEFAULT_LANE_HEALTH_MODE,
65
+ } from './gates-schemas.js';
66
+
67
+ // Re-export presets
68
+ // WU-2547: PRESET_FIX_COMMANDS and getFormatFixCommand added for preset-aware
69
+ // onboarding template rendering in @lumenflow/cli/src/init.ts.
70
+ export {
71
+ GATE_PRESETS,
72
+ expandPreset,
73
+ PRESET_FIX_COMMANDS,
74
+ getFormatFixCommand,
75
+ } from './gates-presets.js';
76
+
77
+ // Re-export coverage/test policy resolution
78
+ export {
79
+ resolveCoverageConfig,
80
+ resolveTestPolicy,
81
+ resolveTddDiffEvidencePolicy,
82
+ resolveTddOrderingPolicy,
83
+ } from './gates-coverage.js';
84
+
85
+ // Re-export package manager / test runner resolution
86
+ export {
87
+ resolvePackageManager,
88
+ resolveTestRunner,
89
+ resolveBuildCommand,
90
+ resolveGatesCommands,
91
+ getIgnorePatterns,
92
+ resolveGatePreset,
93
+ resolveScopedUnitTestExecutionPlan,
94
+ formatScopedUnitTestFallbackMessage,
95
+ } from './package-manager-resolver.js';
96
+
97
+ // Re-export shared infrastructure (consumed by child modules and external callers)
98
+ export {
99
+ GATES_RUNTIME_DEFAULTS,
100
+ SOFTWARE_DELIVERY_FIELDS,
101
+ GATES_FIELDS,
102
+ GATES_COMMAND_FIELDS,
103
+ loadSoftwareDeliveryConfig,
104
+ getGatesSection,
105
+ } from './gates-config-internal.js';
106
+
107
+ // ---------------------------------------------------------------------------
108
+ // Config loading / gate parsing / lane health (facade-owned)
109
+ // ---------------------------------------------------------------------------
110
+
111
+ const SOFTWARE_DELIVERY_KEY = WORKSPACE_V2_KEYS.SOFTWARE_DELIVERY;
112
+
113
+ /**
114
+ * Parse a gate command configuration into executable form
115
+ *
116
+ * @param config - Gate command configuration (string or object)
117
+ * @returns Parsed command with defaults applied, or null if undefined
118
+ */
119
+ export function parseGateCommand(config: GateCommandConfig | undefined): ParsedGateCommand | null {
120
+ if (config === undefined) {
121
+ return null;
122
+ }
123
+
124
+ if (isString(config)) {
125
+ return {
126
+ command: config,
127
+ continueOnError: false,
128
+ timeout: GATES_RUNTIME_DEFAULTS.COMMAND_TIMEOUT_MS,
129
+ };
130
+ }
131
+
132
+ return {
133
+ command: config.command,
134
+ continueOnError: config.continueOnError ?? false,
135
+ timeout: config.timeout ?? GATES_RUNTIME_DEFAULTS.COMMAND_TIMEOUT_MS,
136
+ };
137
+ }
138
+
139
+ /**
140
+ * Load gates configuration from workspace.yaml software_delivery.gates.execution
141
+ *
142
+ * @param projectRoot - Project root directory
143
+ * @returns Gates execution config, or null if not configured
144
+ */
145
+ export function loadGatesConfig(projectRoot: string): GatesExecutionConfig | null {
146
+ const gates = getGatesSection(projectRoot);
147
+ if (!gates) {
148
+ return null;
149
+ }
150
+
151
+ try {
152
+ // Check if gates.execution section exists
153
+ const executionConfig = gates[GATES_FIELDS.EXECUTION];
154
+ if (!executionConfig) {
155
+ return null;
156
+ }
157
+
158
+ // Validate the config
159
+ const result = GatesExecutionConfigSchema.safeParse(executionConfig);
160
+ if (!result.success) {
161
+ console.warn('Warning: Invalid gates.execution config:', result.error.message);
162
+ return null;
163
+ }
164
+
165
+ // Expand preset and merge with explicit config (explicit wins)
166
+ const presetDefaults = expandPreset(result.data.preset);
167
+ const merged: GatesExecutionConfig = {
168
+ ...presetDefaults,
169
+ ...result.data,
170
+ };
171
+
172
+ return merged;
173
+ } catch (error) {
174
+ console.warn(
175
+ `Warning: Failed to parse ${WORKSPACE_CONFIG_FILE_NAME} ${SOFTWARE_DELIVERY_KEY}.gates.execution:`,
176
+ error instanceof Error ? error.message : String(error),
177
+ );
178
+ return null;
179
+ }
180
+ }
181
+
182
+ /**
183
+ * Get default gates configuration for auto-detection fallback
184
+ *
185
+ * Used when no gates config is present in workspace.yaml software_delivery.
186
+ * These are generic commands that work across common setups.
187
+ *
188
+ * @returns Default gates configuration
189
+ */
190
+ export function getDefaultGatesConfig(): GatesExecutionConfig {
191
+ return {
192
+ format:
193
+ 'npm run format:check 2>/dev/null || npx prettier --check . 2>/dev/null || echo "No formatter configured"',
194
+ lint: 'npm run lint 2>/dev/null || npx eslint . 2>/dev/null || echo "No linter configured"',
195
+ typecheck:
196
+ 'npm run typecheck 2>/dev/null || npx tsc --noEmit 2>/dev/null || echo "No type checker configured"',
197
+ test: 'npm test 2>/dev/null || echo "No test command configured"',
198
+ };
199
+ }
200
+
201
+ /**
202
+ * Resolve the effective gates configuration
203
+ *
204
+ * Priority order:
205
+ * 1. Explicit config from workspace.yaml software_delivery
206
+ * 2. Preset defaults (if preset specified)
207
+ * 3. Auto-detection defaults
208
+ *
209
+ * @param projectRoot - Project root directory
210
+ * @returns Resolved gates configuration
211
+ */
212
+ export function resolveGatesConfig(projectRoot: string): GatesExecutionConfig {
213
+ const config = loadGatesConfig(projectRoot);
214
+
215
+ if (config) {
216
+ return config;
217
+ }
218
+
219
+ // Fall back to defaults for auto-detection
220
+ return getDefaultGatesConfig();
221
+ }
222
+
223
+ /**
224
+ * Check if a specific gate should be skipped
225
+ *
226
+ * @param gateName - Name of the gate (format, lint, typecheck, test)
227
+ * @param config - Gates execution configuration
228
+ * @param skipFlags - Map of skip flags from CLI/Action inputs
229
+ * @returns True if the gate should be skipped
230
+ */
231
+ export function shouldSkipGate(
232
+ gateName: keyof Omit<GatesExecutionConfig, 'preset' | 'coverage'>,
233
+ config: GatesExecutionConfig,
234
+ skipFlags: Record<string, boolean>,
235
+ ): boolean {
236
+ // Check if skip flag is set
237
+ const skipFlagName = `skip-${gateName}`;
238
+ if (skipFlags[skipFlagName] || skipFlags[gateName]) {
239
+ return true;
240
+ }
241
+
242
+ // Check if gate is configured (undefined means skip)
243
+ if (config[gateName] === undefined) {
244
+ return true;
245
+ }
246
+
247
+ return false;
248
+ }
249
+
250
+ /**
251
+ * WU-1191: Load lane health configuration from workspace.yaml software_delivery
252
+ *
253
+ * Configuration format:
254
+ * ```yaml
255
+ * gates:
256
+ * lane_health: warn|error|off
257
+ * ```
258
+ *
259
+ * @param projectRoot - Project root directory
260
+ * @returns Lane health mode ('warn', 'error', or 'off'), defaults to 'warn'
261
+ */
262
+ export function loadLaneHealthConfig(projectRoot: string): LaneHealthMode {
263
+ const gates = getGatesSection(projectRoot);
264
+ if (!gates) {
265
+ return DEFAULT_LANE_HEALTH_MODE;
266
+ }
267
+
268
+ try {
269
+ // Check if gates.lane_health is configured
270
+ const laneHealthConfig =
271
+ gates[GATES_FIELDS.LANE_HEALTH] ?? gates[GATES_FIELDS.LANE_HEALTH_CAMEL];
272
+ if (laneHealthConfig === undefined) {
273
+ return DEFAULT_LANE_HEALTH_MODE;
274
+ }
275
+
276
+ // Validate the config value
277
+ const result = LaneHealthModeSchema.safeParse(laneHealthConfig);
278
+ if (!result.success) {
279
+ console.warn(
280
+ `Warning: Invalid gates.lane_health value '${laneHealthConfig}', expected 'warn', 'error', or 'off'. Using default 'warn'.`,
281
+ );
282
+ return DEFAULT_LANE_HEALTH_MODE;
283
+ }
284
+
285
+ return result.data;
286
+ } catch (error) {
287
+ console.warn(
288
+ `Warning: Failed to parse ${WORKSPACE_CONFIG_FILE_NAME} ${SOFTWARE_DELIVERY_KEY}.gates.lane_health:`,
289
+ error instanceof Error ? error.message : String(error),
290
+ );
291
+ return DEFAULT_LANE_HEALTH_MODE;
292
+ }
293
+ }