@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,88 @@
1
+ // Copyright (c) 2026 Hellmai Ltd
2
+ // SPDX-License-Identifier: AGPL-3.0-only
3
+
4
+ import { spawnSync } from 'node:child_process';
5
+ import {
6
+ SANDBOX_BACKEND_IDS,
7
+ type SandboxBackend,
8
+ type SandboxExecutionPlan,
9
+ type SandboxExecutionRequest,
10
+ } from './sandbox-profile.js';
11
+
12
+ export interface LinuxSandboxBackendOptions {
13
+ commandExists?: (binary: string) => boolean;
14
+ }
15
+
16
+ const LINUX_SANDBOX_BINARY = 'bwrap';
17
+
18
+ function defaultCommandExists(binary: string): boolean {
19
+ const probe = spawnSync(binary, ['--help'], { stdio: 'ignore' });
20
+ return !probe.error;
21
+ }
22
+
23
+ function buildUnavailablePlan(request: SandboxExecutionRequest): SandboxExecutionPlan {
24
+ if (request.allowUnsandboxedFallback) {
25
+ return {
26
+ backendId: SANDBOX_BACKEND_IDS.LINUX,
27
+ enforced: false,
28
+ failClosed: false,
29
+ warning:
30
+ 'Running unsandboxed because bwrap is unavailable and fallback was explicitly enabled.',
31
+ };
32
+ }
33
+
34
+ return {
35
+ backendId: SANDBOX_BACKEND_IDS.LINUX,
36
+ enforced: false,
37
+ failClosed: true,
38
+ reason: 'Linux sandbox backend unavailable: required binary "bwrap" was not found.',
39
+ };
40
+ }
41
+
42
+ function buildInvocation(request: SandboxExecutionRequest) {
43
+ const writableBinds = request.profile.allowlist.writableRoots.flatMap((entry) => [
44
+ '--bind',
45
+ entry.normalizedPath,
46
+ entry.normalizedPath,
47
+ ]);
48
+
49
+ return {
50
+ command: LINUX_SANDBOX_BINARY,
51
+ args: [
52
+ '--die-with-parent',
53
+ '--new-session',
54
+ '--ro-bind',
55
+ '/',
56
+ '/',
57
+ ...writableBinds,
58
+ '--proc',
59
+ '/proc',
60
+ '--dev',
61
+ '/dev',
62
+ '--',
63
+ ...request.command,
64
+ ],
65
+ };
66
+ }
67
+
68
+ export function createLinuxSandboxBackend(
69
+ options: LinuxSandboxBackendOptions = {},
70
+ ): SandboxBackend {
71
+ const commandExists = options.commandExists || defaultCommandExists;
72
+
73
+ return {
74
+ id: SANDBOX_BACKEND_IDS.LINUX,
75
+ resolveExecution(request: SandboxExecutionRequest): SandboxExecutionPlan {
76
+ if (!commandExists(LINUX_SANDBOX_BINARY)) {
77
+ return buildUnavailablePlan(request);
78
+ }
79
+
80
+ return {
81
+ backendId: SANDBOX_BACKEND_IDS.LINUX,
82
+ enforced: true,
83
+ failClosed: false,
84
+ invocation: buildInvocation(request),
85
+ };
86
+ },
87
+ };
88
+ }
@@ -0,0 +1,154 @@
1
+ // Copyright (c) 2026 Hellmai Ltd
2
+ // SPDX-License-Identifier: AGPL-3.0-only
3
+
4
+ import { spawnSync } from 'node:child_process';
5
+ import os from 'node:os';
6
+ import {
7
+ SANDBOX_BACKEND_IDS,
8
+ type SandboxBackend,
9
+ type SandboxExecutionPlan,
10
+ type SandboxExecutionRequest,
11
+ } from './sandbox-profile.js';
12
+
13
+ export interface MacosSandboxBackendOptions {
14
+ commandExists?: (binary: string) => boolean;
15
+ }
16
+
17
+ const MACOS_SANDBOX_BINARY = 'sandbox-exec';
18
+
19
+ function defaultCommandExists(binary: string): boolean {
20
+ const probe = spawnSync(binary, ['-h'], { stdio: 'ignore' });
21
+ return !probe.error;
22
+ }
23
+
24
+ function escapePolicyPath(targetPath: string): string {
25
+ return targetPath.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
26
+ }
27
+
28
+ function buildNetworkRules(profile: SandboxExecutionRequest['profile']): string[] {
29
+ const posture = profile.networkPosture ?? 'full';
30
+
31
+ if (posture === 'off') {
32
+ return ['(deny network*)'];
33
+ }
34
+
35
+ if (posture === 'allowlist') {
36
+ const rules: string[] = ['(deny network*)'];
37
+ for (const host of profile.networkAllowlist) {
38
+ rules.push(`(allow network-outbound (remote ip "${host}"))`);
39
+ }
40
+ return rules;
41
+ }
42
+
43
+ // posture === 'full'
44
+ return ['(allow network*)'];
45
+ }
46
+
47
+ /** macOS system paths required for process execution (parity with bwrap --ro-bind /) */
48
+ const MACOS_SYSTEM_READ_PATHS = [
49
+ '/usr',
50
+ '/System',
51
+ '/Library',
52
+ '/bin',
53
+ '/sbin',
54
+ '/private',
55
+ '/dev',
56
+ '/tmp',
57
+ ];
58
+
59
+ /** Sensitive paths denied from read access (parity with bwrap deny overlays) */
60
+ const SENSITIVE_DENY_PATHS = ['.ssh', '.aws', '.gnupg'];
61
+
62
+ function buildReadRules(profile: SandboxExecutionRequest['profile']): string[] {
63
+ const readPaths = new Set<string>();
64
+
65
+ // Workspace root (covers worktree, state, WU YAML)
66
+ readPaths.add(profile.projectRoot);
67
+
68
+ // System paths required for process execution
69
+ for (const systemPath of MACOS_SYSTEM_READ_PATHS) {
70
+ readPaths.add(systemPath);
71
+ }
72
+
73
+ // Temp path from profile
74
+ readPaths.add(profile.tempPath);
75
+
76
+ return [...readPaths].map(
77
+ (readPath) => `(allow file-read* (subpath "${escapePolicyPath(readPath)}"))`,
78
+ );
79
+ }
80
+
81
+ function buildDenyOverlays(): string[] {
82
+ const homeDir = os.homedir();
83
+ return SENSITIVE_DENY_PATHS.map(
84
+ (sensitivePath) =>
85
+ `(deny file-read* (subpath "${escapePolicyPath(homeDir)}/${sensitivePath}"))`,
86
+ );
87
+ }
88
+
89
+ function buildPolicy(profile: SandboxExecutionRequest['profile']): string {
90
+ const writableRules = profile.allowlist.writableRoots.map(
91
+ (entry) => `(allow file-write* (subpath "${escapePolicyPath(entry.normalizedPath)}"))`,
92
+ );
93
+
94
+ return [
95
+ '(version 1)',
96
+ '(deny default)',
97
+ '(allow process*)',
98
+ ...buildReadRules(profile),
99
+ ...buildDenyOverlays(),
100
+ '(allow sysctl-read)',
101
+ '(allow mach-lookup)',
102
+ ...buildNetworkRules(profile),
103
+ '(allow signal)',
104
+ ...writableRules,
105
+ ].join(' ');
106
+ }
107
+
108
+ function buildUnavailablePlan(request: SandboxExecutionRequest): SandboxExecutionPlan {
109
+ if (request.allowUnsandboxedFallback) {
110
+ return {
111
+ backendId: SANDBOX_BACKEND_IDS.MACOS,
112
+ enforced: false,
113
+ failClosed: false,
114
+ warning:
115
+ 'Running unsandboxed because sandbox-exec is unavailable and fallback was explicitly enabled.',
116
+ };
117
+ }
118
+
119
+ return {
120
+ backendId: SANDBOX_BACKEND_IDS.MACOS,
121
+ enforced: false,
122
+ failClosed: true,
123
+ reason: 'macOS sandbox backend unavailable: required binary "sandbox-exec" was not found.',
124
+ };
125
+ }
126
+
127
+ function buildInvocation(request: SandboxExecutionRequest) {
128
+ return {
129
+ command: MACOS_SANDBOX_BINARY,
130
+ args: ['-p', buildPolicy(request.profile), ...request.command],
131
+ };
132
+ }
133
+
134
+ export function createMacosSandboxBackend(
135
+ options: MacosSandboxBackendOptions = {},
136
+ ): SandboxBackend {
137
+ const commandExists = options.commandExists || defaultCommandExists;
138
+
139
+ return {
140
+ id: SANDBOX_BACKEND_IDS.MACOS,
141
+ resolveExecution(request: SandboxExecutionRequest): SandboxExecutionPlan {
142
+ if (!commandExists(MACOS_SANDBOX_BINARY)) {
143
+ return buildUnavailablePlan(request);
144
+ }
145
+
146
+ return {
147
+ backendId: SANDBOX_BACKEND_IDS.MACOS,
148
+ enforced: true,
149
+ failClosed: false,
150
+ invocation: buildInvocation(request),
151
+ };
152
+ },
153
+ };
154
+ }
@@ -0,0 +1,47 @@
1
+ // Copyright (c) 2026 Hellmai Ltd
2
+ // SPDX-License-Identifier: AGPL-3.0-only
3
+
4
+ import {
5
+ SANDBOX_BACKEND_IDS,
6
+ type SandboxBackend,
7
+ type SandboxExecutionPlan,
8
+ type SandboxExecutionRequest,
9
+ } from './sandbox-profile.js';
10
+
11
+ export interface WindowsSandboxBackendOptions {
12
+ commandExists?: (binary: string) => boolean;
13
+ }
14
+
15
+ const WINDOWS_ENFORCEMENT_UNAVAILABLE_REASON =
16
+ 'Windows sandbox backend unavailable: write enforcement is not yet available on Windows.';
17
+ const WINDOWS_ENFORCEMENT_UNAVAILABLE_WARNING =
18
+ 'Running unsandboxed because write enforcement is not yet available on Windows and fallback was explicitly enabled.';
19
+
20
+ function buildNotImplementedPlan(request: SandboxExecutionRequest): SandboxExecutionPlan {
21
+ if (request.allowUnsandboxedFallback) {
22
+ return {
23
+ backendId: SANDBOX_BACKEND_IDS.WINDOWS,
24
+ enforced: false,
25
+ failClosed: false,
26
+ warning: WINDOWS_ENFORCEMENT_UNAVAILABLE_WARNING,
27
+ };
28
+ }
29
+
30
+ return {
31
+ backendId: SANDBOX_BACKEND_IDS.WINDOWS,
32
+ enforced: false,
33
+ failClosed: true,
34
+ reason: WINDOWS_ENFORCEMENT_UNAVAILABLE_REASON,
35
+ };
36
+ }
37
+
38
+ export function createWindowsSandboxBackend(
39
+ _options: WindowsSandboxBackendOptions = {},
40
+ ): SandboxBackend {
41
+ return {
42
+ id: SANDBOX_BACKEND_IDS.WINDOWS,
43
+ resolveExecution(request: SandboxExecutionRequest): SandboxExecutionPlan {
44
+ return buildNotImplementedPlan(request);
45
+ },
46
+ };
47
+ }
@@ -0,0 +1,153 @@
1
+ // Copyright (c) 2026 Hellmai Ltd
2
+ // SPDX-License-Identifier: AGPL-3.0-only
3
+
4
+ import os from 'node:os';
5
+ import path from 'node:path';
6
+ import {
7
+ buildSandboxAllowlist,
8
+ type SandboxAllowlist,
9
+ type BuildSandboxAllowlistInput,
10
+ } from './sandbox-allowlist.js';
11
+ import { LUMENFLOW_PATHS } from '../constants/wu-paths-constants.js';
12
+ import { createWuPaths } from '../state/wu-paths.js';
13
+
14
+ export const SANDBOX_BACKEND_IDS = {
15
+ LINUX: 'linux',
16
+ MACOS: 'macos',
17
+ WINDOWS: 'windows',
18
+ UNSUPPORTED: 'unsupported',
19
+ } as const;
20
+
21
+ export type SandboxBackendId = (typeof SANDBOX_BACKEND_IDS)[keyof typeof SANDBOX_BACKEND_IDS];
22
+
23
+ export type SandboxNetworkPosture = 'off' | 'allowlist' | 'full';
24
+
25
+ export interface SandboxProfile {
26
+ projectRoot: string;
27
+ worktreePath: string;
28
+ wuId: string;
29
+ wuYamlPath: string;
30
+ statePath: string;
31
+ tempPath: string;
32
+ allowlist: SandboxAllowlist;
33
+ networkPosture: SandboxNetworkPosture;
34
+ networkAllowlist: string[];
35
+ }
36
+
37
+ export interface BuildSandboxProfileInput {
38
+ projectRoot: string;
39
+ worktreePath: string;
40
+ wuId: string;
41
+ tempPath?: string;
42
+ extraWritableRoots?: string[];
43
+ networkPosture?: SandboxNetworkPosture;
44
+ networkAllowlist?: string[];
45
+ }
46
+
47
+ export interface SandboxBackendResolution {
48
+ id: SandboxBackendId;
49
+ platform: NodeJS.Platform | string;
50
+ supported: boolean;
51
+ }
52
+
53
+ export interface SandboxInvocation {
54
+ command: string;
55
+ args: string[];
56
+ }
57
+
58
+ export interface SandboxExecutionRequest {
59
+ profile: SandboxProfile;
60
+ command: string[];
61
+ allowUnsandboxedFallback: boolean;
62
+ }
63
+
64
+ export interface SandboxExecutionPlan {
65
+ backendId: SandboxBackendId;
66
+ enforced: boolean;
67
+ failClosed: boolean;
68
+ invocation?: SandboxInvocation;
69
+ reason?: string;
70
+ warning?: string;
71
+ }
72
+
73
+ export interface SandboxBackend {
74
+ id: SandboxBackendId;
75
+ resolveExecution: (request: SandboxExecutionRequest) => SandboxExecutionPlan;
76
+ }
77
+
78
+ function resolveWorktreePath(projectRoot: string, worktreePath: string): string {
79
+ if (path.isAbsolute(worktreePath)) {
80
+ return path.resolve(worktreePath);
81
+ }
82
+
83
+ return path.resolve(projectRoot, worktreePath);
84
+ }
85
+
86
+ function buildDefaultWritableRoots(profile: {
87
+ worktreePath: string;
88
+ statePath: string;
89
+ wuYamlPath: string;
90
+ tempPath: string;
91
+ }): string[] {
92
+ return [profile.worktreePath, profile.statePath, profile.wuYamlPath, profile.tempPath];
93
+ }
94
+
95
+ export function buildSandboxProfile(input: BuildSandboxProfileInput): SandboxProfile {
96
+ const projectRoot = path.resolve(input.projectRoot);
97
+ const worktreePath = resolveWorktreePath(projectRoot, input.worktreePath);
98
+ const wuYamlPath = path.resolve(projectRoot, createWuPaths({ projectRoot }).WU(input.wuId));
99
+ const statePath = path.resolve(projectRoot, LUMENFLOW_PATHS.STATE_DIR);
100
+ const tempPath = path.resolve(input.tempPath || os.tmpdir());
101
+
102
+ const writableRoots = buildDefaultWritableRoots({
103
+ worktreePath,
104
+ statePath,
105
+ wuYamlPath,
106
+ tempPath,
107
+ });
108
+
109
+ if (input.extraWritableRoots && input.extraWritableRoots.length > 0) {
110
+ writableRoots.push(...input.extraWritableRoots);
111
+ }
112
+
113
+ const allowlistInput: BuildSandboxAllowlistInput = {
114
+ projectRoot,
115
+ writableRoots,
116
+ };
117
+
118
+ const allowlist = buildSandboxAllowlist(allowlistInput);
119
+
120
+ const networkPosture: SandboxNetworkPosture = input.networkPosture ?? 'full';
121
+ const networkAllowlist: string[] =
122
+ networkPosture === 'allowlist' && input.networkAllowlist ? [...input.networkAllowlist] : [];
123
+
124
+ return {
125
+ projectRoot,
126
+ worktreePath,
127
+ wuId: input.wuId,
128
+ wuYamlPath,
129
+ statePath,
130
+ tempPath,
131
+ allowlist,
132
+ networkPosture,
133
+ networkAllowlist,
134
+ };
135
+ }
136
+
137
+ export function resolveSandboxBackendForPlatform(
138
+ platform: NodeJS.Platform | string = process.platform,
139
+ ): SandboxBackendResolution {
140
+ if (platform === 'linux') {
141
+ return { id: SANDBOX_BACKEND_IDS.LINUX, platform, supported: true };
142
+ }
143
+
144
+ if (platform === 'darwin') {
145
+ return { id: SANDBOX_BACKEND_IDS.MACOS, platform, supported: true };
146
+ }
147
+
148
+ if (platform === 'win32') {
149
+ return { id: SANDBOX_BACKEND_IDS.WINDOWS, platform, supported: true };
150
+ }
151
+
152
+ return { id: SANDBOX_BACKEND_IDS.UNSUPPORTED, platform, supported: false };
153
+ }
@@ -0,0 +1,5 @@
1
+ // Copyright (c) 2026 Hellmai Ltd
2
+ // SPDX-License-Identifier: AGPL-3.0-only
3
+
4
+ // Barrel for pack-static-data schemas. Populated by Layer 2 of INIT-058.
5
+ export {};
@@ -0,0 +1,158 @@
1
+ // Copyright (c) 2026 Hellmai Ltd
2
+ // SPDX-License-Identifier: AGPL-3.0-only
3
+
4
+ /**
5
+ * @file date-utils.ts
6
+ * @description Date formatting utilities using date-fns library
7
+ * WU-1082: Extract shared utilities (eliminate date formatting duplication)
8
+ *
9
+ * Replaces manual date formatting in:
10
+ * - tools/wu-block.ts (todayISO)
11
+ * - tools/wu-unblock.ts (todayISO)
12
+ * - tools/wu-done.ts (todayISO - already uses date-fns)
13
+ */
14
+
15
+ import { format } from 'date-fns';
16
+
17
+ /**
18
+ * Get current date in ISO format (YYYY-MM-DD)
19
+ * @returns {string} Current date in YYYY-MM-DD format
20
+ * @example
21
+ * todayISO(); // "2025-11-12"
22
+ */
23
+ export function todayISO() {
24
+ return format(new Date(), 'yyyy-MM-dd');
25
+ }
26
+
27
+ /**
28
+ * Format a date with a custom format string
29
+ * @param {Date|string|number} date - Date to format
30
+ * @param {string} formatString - date-fns format string
31
+ * @returns {string} Formatted date string
32
+ * @example
33
+ * formatDate(new Date(), 'yyyy-MM-dd HH:mm:ss');
34
+ * formatDate('2025-11-12', 'MMMM d, yyyy'); // "November 12, 2025"
35
+ */
36
+ export function formatDate(date: Date | string | number, formatString: string) {
37
+ return format(new Date(date), formatString);
38
+ }
39
+
40
+ /**
41
+ * Date format constant for YYYY-MM-DD
42
+ * @constant {string}
43
+ */
44
+ const DATE_FORMAT_ISO = 'yyyy-MM-dd';
45
+
46
+ /**
47
+ * Normalize a Date object or ISO timestamp string to YYYY-MM-DD format
48
+ *
49
+ * WU-1442: Fix date corruption when js-yaml parses YYYY-MM-DD as Date objects
50
+ * Library-First: Uses date-fns for date formatting (no manual parsing)
51
+ *
52
+ * Use case: js-yaml parses `created: 2025-12-04` (unquoted) as a Date object.
53
+ * When yaml.dump() serializes it back, it outputs `2025-12-04T00:00:00.000Z`.
54
+ * This function normalizes Date objects back to YYYY-MM-DD string format.
55
+ *
56
+ * Handles:
57
+ * - Date objects → YYYY-MM-DD string
58
+ * - ISO timestamp strings → YYYY-MM-DD string (date portion)
59
+ * - YYYY-MM-DD strings → preserved as-is
60
+ * - undefined/null → preserved as undefined
61
+ *
62
+ * @param {Date|string|undefined|null} value - Date value to normalize
63
+ * @returns {string|undefined} Date in YYYY-MM-DD format or undefined
64
+ *
65
+ * @example
66
+ * normalizeToDateString(new Date('2025-12-04')); // '2025-12-04'
67
+ * normalizeToDateString('2025-12-04T00:00:00.000Z'); // '2025-12-04'
68
+ * normalizeToDateString('2025-12-04'); // '2025-12-04'
69
+ * normalizeToDateString(undefined); // undefined
70
+ */
71
+ export function normalizeToDateString(value: unknown) {
72
+ // Preserve undefined/null
73
+ if (value == null) {
74
+ return undefined;
75
+ }
76
+
77
+ // If already a YYYY-MM-DD string, return as-is
78
+ if (typeof value === 'string' && /^\d{4}-\d{2}-\d{2}$/.test(value)) {
79
+ return value;
80
+ }
81
+
82
+ // Convert Date objects or timestamp strings to YYYY-MM-DD
83
+ if (value instanceof Date) {
84
+ return format(value, DATE_FORMAT_ISO);
85
+ }
86
+
87
+ // Handle ISO timestamp strings (e.g., '2025-12-04T00:00:00.000Z')
88
+ if (typeof value === 'string' && /^\d{4}-\d{2}-\d{2}T/.test(value)) {
89
+ return format(new Date(value), DATE_FORMAT_ISO);
90
+ }
91
+
92
+ // Fallback: try to parse and format (coerce to string for Date constructor)
93
+ try {
94
+ const date = new Date(String(value));
95
+ if (!isNaN(date.getTime())) {
96
+ return format(date, DATE_FORMAT_ISO);
97
+ }
98
+ } catch {
99
+ // Invalid date - return undefined
100
+ }
101
+
102
+ return undefined;
103
+ }
104
+
105
+ /**
106
+ * Normalize various date formats to ISO 8601 datetime (YYYY-MM-DDTHH:mm:ss.sssZ)
107
+ *
108
+ * WU-1337: Auto-repair date fields in WU YAML to consistent format
109
+ * Library-First: Uses date-fns for date handling (no manual parsing)
110
+ *
111
+ * Handles:
112
+ * - ISO date strings (YYYY-MM-DD) → midnight UTC
113
+ * - ISO datetime strings (already valid) → preserved
114
+ * - Unix timestamps (milliseconds) → converted
115
+ * - undefined/null → preserved as undefined
116
+ *
117
+ * @param {string|number|undefined|null} value - Date value to normalize
118
+ * @returns {string|undefined} ISO datetime string or undefined
119
+ *
120
+ * @example
121
+ * normalizeISODateTime('2025-11-29'); // '2025-11-29T00:00:00.000Z'
122
+ * normalizeISODateTime('2025-11-29T14:30:00.000Z'); // '2025-11-29T14:30:00.000Z'
123
+ * normalizeISODateTime(1732896000000); // '2024-11-29T16:00:00.000Z'
124
+ * normalizeISODateTime(undefined); // undefined
125
+ */
126
+ export function normalizeISODateTime(value: string | number | null | undefined) {
127
+ // Preserve undefined/null (optional fields)
128
+ if (value == null) {
129
+ return undefined;
130
+ }
131
+
132
+ // If already a valid ISO datetime format, preserve it
133
+ // Pattern: YYYY-MM-DDTHH:mm:ss.sssZ
134
+ if (typeof value === 'string' && /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/.test(value)) {
135
+ return value;
136
+ }
137
+
138
+ // Handle Unix timestamps as strings (convert to number first)
139
+ let dateInput = value;
140
+ if (typeof value === 'string' && /^\d+$/.test(value)) {
141
+ // Numeric string - treat as Unix timestamp in milliseconds
142
+ dateInput = Number(value);
143
+ }
144
+
145
+ // Parse and convert to ISO datetime
146
+ // date-fns/Date handles: ISO dates, ISO datetimes, Unix timestamps
147
+ const date = new Date(dateInput);
148
+
149
+ // Check for invalid date
150
+ if (isNaN(date.getTime())) {
151
+ // Fallback: return undefined for unparseable dates
152
+ // Zod schema will catch invalid dates separately
153
+ return undefined;
154
+ }
155
+
156
+ // Convert to ISO 8601 datetime format
157
+ return date.toISOString();
158
+ }
@@ -0,0 +1,15 @@
1
+ // Copyright (c) 2026 Hellmai Ltd
2
+ // SPDX-License-Identifier: AGPL-3.0-only
3
+
4
+ // Barrel for pack-local WU state modules. Populated by Layer 4 of INIT-058.
5
+ // WU-2687 (narrowed): moved wu-state-schema, wu-doc-types from @lumenflow/core.
6
+ // WU-2689 (L4 cascade): moved wu-paths, wu-yaml, wu-schema, date-utils from @lumenflow/core
7
+ // after WU-2690 added getDirectories/getStatePaths to the pack workspace-reader.
8
+ export * from './wu-state-schema.js';
9
+ export * from './wu-doc-types.js';
10
+ export * from './date-utils.js';
11
+ export * from './wu-paths.js';
12
+ export * from './wu-schema.js';
13
+ export * from './wu-yaml.js';
14
+ // WU-2699 (L4): moved state-machine (SDLC residue) from @lumenflow/core.
15
+ export * from './state-machine.js';