@lumenflow/cli 5.5.0 → 5.7.14

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 (229) hide show
  1. package/README.md +41 -40
  2. package/dist/db-journal-recover.js +400 -0
  3. package/dist/db-journal-recover.js.map +1 -0
  4. package/dist/docs-sync.js +8 -3
  5. package/dist/docs-sync.js.map +1 -1
  6. package/dist/doctor.js +11 -0
  7. package/dist/doctor.js.map +1 -1
  8. package/dist/gate-defaults.js +37 -0
  9. package/dist/gate-defaults.js.map +1 -1
  10. package/dist/gates/monolithic-file-contention-guard.js +167 -0
  11. package/dist/gates/monolithic-file-contention-guard.js.map +1 -0
  12. package/dist/gates/prod-migration-drift.js +207 -0
  13. package/dist/gates/prod-migration-drift.js.map +1 -0
  14. package/dist/gates/test-over-deletion-guard.js +280 -0
  15. package/dist/gates/test-over-deletion-guard.js.map +1 -0
  16. package/dist/gates-runners.js +44 -3
  17. package/dist/gates-runners.js.map +1 -1
  18. package/dist/gates.js +3 -2
  19. package/dist/gates.js.map +1 -1
  20. package/dist/hooks/config-resolver.js +16 -1
  21. package/dist/hooks/config-resolver.js.map +1 -1
  22. package/dist/hooks/dirty-guard.js +43 -2
  23. package/dist/hooks/dirty-guard.js.map +1 -1
  24. package/dist/hooks/git-status-parser.js +22 -8
  25. package/dist/hooks/git-status-parser.js.map +1 -1
  26. package/dist/init-templates.js +241 -0
  27. package/dist/init-templates.js.map +1 -1
  28. package/dist/init.js +122 -16
  29. package/dist/init.js.map +1 -1
  30. package/dist/lumenflow-setup.js +144 -0
  31. package/dist/lumenflow-setup.js.map +1 -0
  32. package/dist/lumenflow-upgrade.js +43 -1
  33. package/dist/lumenflow-upgrade.js.map +1 -1
  34. package/dist/mem-create.js +10 -1
  35. package/dist/mem-create.js.map +1 -1
  36. package/dist/mem-signal.js +21 -4
  37. package/dist/mem-signal.js.map +1 -1
  38. package/dist/orchestrate-initiative.js +28 -3
  39. package/dist/orchestrate-initiative.js.map +1 -1
  40. package/dist/public-manifest.js +17 -7
  41. package/dist/public-manifest.js.map +1 -1
  42. package/dist/release.js +53 -18
  43. package/dist/release.js.map +1 -1
  44. package/dist/wu-done-gates.js +13 -9
  45. package/dist/wu-done-gates.js.map +1 -1
  46. package/dist/wu-done.js +14 -2
  47. package/dist/wu-done.js.map +1 -1
  48. package/dist/wu-edit-operations.js +74 -0
  49. package/dist/wu-edit-operations.js.map +1 -1
  50. package/dist/wu-edit-validators.js +58 -0
  51. package/dist/wu-edit-validators.js.map +1 -1
  52. package/dist/wu-edit.js +106 -4
  53. package/dist/wu-edit.js.map +1 -1
  54. package/dist/wu-prep.js +57 -9
  55. package/dist/wu-prep.js.map +1 -1
  56. package/dist/wu-recover.js +6 -0
  57. package/dist/wu-recover.js.map +1 -1
  58. package/dist/wu-release.js +120 -2
  59. package/dist/wu-release.js.map +1 -1
  60. package/dist/wu-sizing-validation.js +47 -17
  61. package/dist/wu-sizing-validation.js.map +1 -1
  62. package/dist/wu-status.js +33 -0
  63. package/dist/wu-status.js.map +1 -1
  64. package/package.json +13 -12
  65. package/packs/agent-runtime/package.json +1 -1
  66. package/packs/sidekick/package.json +1 -1
  67. package/packs/software-delivery/package.json +1 -1
  68. package/templates/core/AGENTS.md.template +67 -3
  69. package/templates/core/LUMENFLOW.md.template +196 -47
  70. package/dist/distribution-preflight.js +0 -230
  71. package/dist/distribution-preflight.js.map +0 -1
  72. package/packs/agent-runtime/agent-heartbeat.ts +0 -163
  73. package/packs/agent-runtime/auto-session-integration.ts +0 -888
  74. package/packs/agent-runtime/capability-factory.ts +0 -104
  75. package/packs/agent-runtime/constants.ts +0 -21
  76. package/packs/agent-runtime/delegation-registry-schema.ts +0 -220
  77. package/packs/agent-runtime/delegation-registry-store.ts +0 -269
  78. package/packs/agent-runtime/delegation-tree.ts +0 -328
  79. package/packs/agent-runtime/index.ts +0 -20
  80. package/packs/agent-runtime/manifest.ts +0 -348
  81. package/packs/agent-runtime/memory-coordination-contract.ts +0 -86
  82. package/packs/agent-runtime/orchestration.ts +0 -2027
  83. package/packs/agent-runtime/pack-registration.ts +0 -110
  84. package/packs/agent-runtime/policy-factory.ts +0 -165
  85. package/packs/agent-runtime/remote-controls/index.ts +0 -7
  86. package/packs/agent-runtime/remote-controls/operations.ts +0 -405
  87. package/packs/agent-runtime/remote-controls/port.ts +0 -48
  88. package/packs/agent-runtime/remote-controls/state-store.ts +0 -258
  89. package/packs/agent-runtime/remote-controls/types.ts +0 -105
  90. package/packs/agent-runtime/session-schema.ts +0 -467
  91. package/packs/agent-runtime/tool-impl/agent-turn-tools.ts +0 -793
  92. package/packs/agent-runtime/tool-impl/index.ts +0 -6
  93. package/packs/agent-runtime/tool-impl/provider-adapters.ts +0 -1245
  94. package/packs/agent-runtime/tool-impl/remote-controls.mock.ts +0 -256
  95. package/packs/agent-runtime/tool-impl/remote-controls.ts +0 -273
  96. package/packs/agent-runtime/tools/index.ts +0 -4
  97. package/packs/agent-runtime/tools/types.ts +0 -47
  98. package/packs/agent-runtime/turn-lifecycle-events.ts +0 -590
  99. package/packs/agent-runtime/types.ts +0 -128
  100. package/packs/agent-runtime/vitest.config.ts +0 -11
  101. package/packs/sidekick/channel-ingress.ts +0 -137
  102. package/packs/sidekick/constants.ts +0 -10
  103. package/packs/sidekick/index.ts +0 -8
  104. package/packs/sidekick/manifest-schema.ts +0 -49
  105. package/packs/sidekick/manifest.ts +0 -512
  106. package/packs/sidekick/pack-registration.ts +0 -110
  107. package/packs/sidekick/policy-factory.ts +0 -38
  108. package/packs/sidekick/sidekick-events.ts +0 -694
  109. package/packs/sidekick/src/adapters/cloud-queue.ts +0 -101
  110. package/packs/sidekick/src/adapters/control-plane-bridge.adapter.ts +0 -386
  111. package/packs/sidekick/src/adapters/filesystem-bridge.adapter.ts +0 -228
  112. package/packs/sidekick/src/domain/channel.types.ts +0 -64
  113. package/packs/sidekick/src/ports/channel-bridge.port.ts +0 -92
  114. package/packs/sidekick/src/routines/commit.ts +0 -74
  115. package/packs/sidekick/tool-impl/channel-tools.ts +0 -577
  116. package/packs/sidekick/tool-impl/channel-transports.ts +0 -75
  117. package/packs/sidekick/tool-impl/index.ts +0 -29
  118. package/packs/sidekick/tool-impl/memory-tools.ts +0 -290
  119. package/packs/sidekick/tool-impl/routine-commit.ts +0 -102
  120. package/packs/sidekick/tool-impl/routine-tools.ts +0 -440
  121. package/packs/sidekick/tool-impl/runtime-context.ts +0 -28
  122. package/packs/sidekick/tool-impl/shared.ts +0 -125
  123. package/packs/sidekick/tool-impl/storage.ts +0 -325
  124. package/packs/sidekick/tool-impl/system-tools.ts +0 -160
  125. package/packs/sidekick/tool-impl/task-tools.ts +0 -506
  126. package/packs/sidekick/tools/channel-tools.ts +0 -53
  127. package/packs/sidekick/tools/index.ts +0 -9
  128. package/packs/sidekick/tools/memory-tools.ts +0 -53
  129. package/packs/sidekick/tools/routine-tools.ts +0 -53
  130. package/packs/sidekick/tools/system-tools.ts +0 -47
  131. package/packs/sidekick/tools/task-tools.ts +0 -61
  132. package/packs/sidekick/tools/types.ts +0 -57
  133. package/packs/sidekick/vitest.config.ts +0 -11
  134. package/packs/software-delivery/constants.ts +0 -10
  135. package/packs/software-delivery/extensions.ts +0 -140
  136. package/packs/software-delivery/gate-policies.ts +0 -134
  137. package/packs/software-delivery/index.ts +0 -8
  138. package/packs/software-delivery/manifest-schema.ts +0 -268
  139. package/packs/software-delivery/manifest.ts +0 -657
  140. package/packs/software-delivery/pack-registration.ts +0 -113
  141. package/packs/software-delivery/src/commands/index.ts +0 -5
  142. package/packs/software-delivery/src/config/delivery-review-contract.ts +0 -256
  143. package/packs/software-delivery/src/config/env-accessors.ts +0 -66
  144. package/packs/software-delivery/src/config/index.ts +0 -8
  145. package/packs/software-delivery/src/config/normalize-config-keys.ts +0 -9
  146. package/packs/software-delivery/src/config/schemas/lumenflow-config-schema-types.ts +0 -460
  147. package/packs/software-delivery/src/config/workspace-reader.ts +0 -375
  148. package/packs/software-delivery/src/constants/backlog-patterns.ts +0 -31
  149. package/packs/software-delivery/src/constants/client-ids.ts +0 -19
  150. package/packs/software-delivery/src/constants/config-contract.ts +0 -7
  151. package/packs/software-delivery/src/constants/docs-layout-presets.ts +0 -50
  152. package/packs/software-delivery/src/constants/duration-constants.ts +0 -20
  153. package/packs/software-delivery/src/constants/gate-constants.ts +0 -32
  154. package/packs/software-delivery/src/constants/index.ts +0 -29
  155. package/packs/software-delivery/src/constants/lock-constants.ts +0 -35
  156. package/packs/software-delivery/src/constants/object-guards.ts +0 -12
  157. package/packs/software-delivery/src/constants/section-headings.ts +0 -107
  158. package/packs/software-delivery/src/constants/wu-cli-constants.ts +0 -500
  159. package/packs/software-delivery/src/constants/wu-domain-constants.ts +0 -466
  160. package/packs/software-delivery/src/constants/wu-git-constants.ts +0 -7
  161. package/packs/software-delivery/src/constants/wu-id-format.ts +0 -327
  162. package/packs/software-delivery/src/constants/wu-paths-constants.ts +0 -384
  163. package/packs/software-delivery/src/constants/wu-statuses.ts +0 -287
  164. package/packs/software-delivery/src/constants/wu-type-helpers.ts +0 -67
  165. package/packs/software-delivery/src/constants/wu-ui-constants.ts +0 -267
  166. package/packs/software-delivery/src/constants/wu-validation-constants.ts +0 -73
  167. package/packs/software-delivery/src/domain/index.ts +0 -5
  168. package/packs/software-delivery/src/domain/orchestration.constants.ts +0 -166
  169. package/packs/software-delivery/src/domain/orchestration.schemas.ts +0 -238
  170. package/packs/software-delivery/src/domain/orchestration.types.ts +0 -176
  171. package/packs/software-delivery/src/methodology/incremental-test.ts +0 -122
  172. package/packs/software-delivery/src/methodology/index.ts +0 -6
  173. package/packs/software-delivery/src/methodology/manual-test-validator.ts +0 -292
  174. package/packs/software-delivery/src/policy/coverage-gate.ts +0 -270
  175. package/packs/software-delivery/src/policy/gates-agent-mode.ts +0 -223
  176. package/packs/software-delivery/src/policy/gates-config-internal.ts +0 -121
  177. package/packs/software-delivery/src/policy/gates-config.ts +0 -300
  178. package/packs/software-delivery/src/policy/gates-coverage.ts +0 -356
  179. package/packs/software-delivery/src/policy/gates-presets.ts +0 -134
  180. package/packs/software-delivery/src/policy/gates-schemas.ts +0 -173
  181. package/packs/software-delivery/src/policy/index.ts +0 -22
  182. package/packs/software-delivery/src/policy/package-manager-resolver.ts +0 -319
  183. package/packs/software-delivery/src/policy/resolve-policy.ts +0 -601
  184. package/packs/software-delivery/src/ports/config.ports.ts +0 -90
  185. package/packs/software-delivery/src/ports/dashboard-renderer.port.ts +0 -125
  186. package/packs/software-delivery/src/ports/index.ts +0 -10
  187. package/packs/software-delivery/src/ports/sync-validator.ports.ts +0 -59
  188. package/packs/software-delivery/src/ports/wu-helpers.ports.ts +0 -168
  189. package/packs/software-delivery/src/ports/wu-state.ports.ts +0 -241
  190. package/packs/software-delivery/src/primitives/index.ts +0 -5
  191. package/packs/software-delivery/src/runtime/index.ts +0 -6
  192. package/packs/software-delivery/src/runtime/work-classifier.ts +0 -561
  193. package/packs/software-delivery/src/sandbox/index.ts +0 -10
  194. package/packs/software-delivery/src/sandbox/sandbox-allowlist.ts +0 -118
  195. package/packs/software-delivery/src/sandbox/sandbox-backend-linux.ts +0 -88
  196. package/packs/software-delivery/src/sandbox/sandbox-backend-macos.ts +0 -154
  197. package/packs/software-delivery/src/sandbox/sandbox-backend-windows.ts +0 -47
  198. package/packs/software-delivery/src/sandbox/sandbox-profile.ts +0 -153
  199. package/packs/software-delivery/src/schemas/index.ts +0 -5
  200. package/packs/software-delivery/src/state/date-utils.ts +0 -158
  201. package/packs/software-delivery/src/state/index.ts +0 -15
  202. package/packs/software-delivery/src/state/state-machine.ts +0 -119
  203. package/packs/software-delivery/src/state/wu-doc-types.ts +0 -51
  204. package/packs/software-delivery/src/state/wu-paths.ts +0 -381
  205. package/packs/software-delivery/src/state/wu-schema.ts +0 -1139
  206. package/packs/software-delivery/src/state/wu-state-schema.ts +0 -255
  207. package/packs/software-delivery/src/state/wu-yaml.ts +0 -338
  208. package/packs/software-delivery/tool-impl/agent-tools.ts +0 -263
  209. package/packs/software-delivery/tool-impl/delegation-tools.ts +0 -66
  210. package/packs/software-delivery/tool-impl/flow-metrics-tools.ts +0 -219
  211. package/packs/software-delivery/tool-impl/git-runner.ts +0 -113
  212. package/packs/software-delivery/tool-impl/git-tools.ts +0 -316
  213. package/packs/software-delivery/tool-impl/index.ts +0 -15
  214. package/packs/software-delivery/tool-impl/initiative-orchestration-tools.ts +0 -720
  215. package/packs/software-delivery/tool-impl/lane-lock.ts +0 -246
  216. package/packs/software-delivery/tool-impl/memory-tools.ts +0 -470
  217. package/packs/software-delivery/tool-impl/pending-runtime-tools.ts +0 -21
  218. package/packs/software-delivery/tool-impl/runtime-cli-adapter.ts +0 -329
  219. package/packs/software-delivery/tool-impl/runtime-native-tools.ts +0 -687
  220. package/packs/software-delivery/tool-impl/worker-loader.ts +0 -52
  221. package/packs/software-delivery/tool-impl/worktree-tools.ts +0 -46
  222. package/packs/software-delivery/tool-impl/wu-lifecycle-tools.ts +0 -807
  223. package/packs/software-delivery/tools/delegation-tools.ts +0 -23
  224. package/packs/software-delivery/tools/git-tools.ts +0 -55
  225. package/packs/software-delivery/tools/index.ts +0 -8
  226. package/packs/software-delivery/tools/lane-lock-tool.ts +0 -37
  227. package/packs/software-delivery/tools/types.ts +0 -71
  228. package/packs/software-delivery/tools/worktree-tools.ts +0 -49
  229. package/packs/software-delivery/vitest.config.ts +0 -11
@@ -1,328 +0,0 @@
1
- // Copyright (c) 2026 Hellmai Ltd
2
- // SPDX-License-Identifier: LicenseRef-LumenFlow-Proprietary
3
-
4
- /**
5
- * Delegation Tree Builder (ADR-014 follow-up, WU-2763)
6
- *
7
- * Builds and formats delegation trees for visualization.
8
- *
9
- * Core now re-exports this module as a compatibility shim.
10
- */
11
-
12
- import fs from 'node:fs/promises';
13
- import path from 'node:path';
14
- import { parse as parseYAML } from 'yaml';
15
- import { DelegationRegistryStore } from './delegation-registry-store.js';
16
- import {
17
- DelegationStatus,
18
- type DelegationOwnershipScope,
19
- type DelegationRoleDescriptor,
20
- type DelegationSchemaVersion,
21
- } from './delegation-registry-schema.js';
22
-
23
- interface RegistryRecord {
24
- id: string;
25
- parentWuId: string;
26
- targetWuId: string;
27
- lane: string;
28
- status: string;
29
- delegatedAt: string;
30
- completedAt: string | null;
31
- pickedUpAt?: string;
32
- pickedUpBy?: string;
33
- schemaVersion?: DelegationSchemaVersion;
34
- requested_role?: DelegationRoleDescriptor;
35
- actual_role?: DelegationRoleDescriptor;
36
- capabilities?: string[];
37
- ownership_scope?: DelegationOwnershipScope;
38
- }
39
-
40
- interface DelegationRecord {
41
- id: string;
42
- parentWuId: string;
43
- targetWuId: string;
44
- lane: string;
45
- status: string;
46
- delegatedAt: string;
47
- completedAt: string | null;
48
- pickedUpAt?: string;
49
- pickedUpBy?: string;
50
- schemaVersion?: DelegationSchemaVersion;
51
- requested_role?: DelegationRoleDescriptor;
52
- actual_role?: DelegationRoleDescriptor;
53
- capabilities?: string[];
54
- ownership_scope?: DelegationOwnershipScope;
55
- }
56
-
57
- interface DelegationTreeNode {
58
- wuId: string;
59
- delegationId: string | null;
60
- status: string | null;
61
- lane: string | null;
62
- delegatedAt: string | null;
63
- children: DelegationTreeNode[];
64
- schemaVersion?: DelegationSchemaVersion;
65
- requested_role?: DelegationRoleDescriptor;
66
- actual_role?: DelegationRoleDescriptor;
67
- capabilities?: string[];
68
- ownership_scope?: DelegationOwnershipScope;
69
- }
70
-
71
- /**
72
- * Status indicators for terminal output.
73
- */
74
- export const STATUS_INDICATORS = Object.freeze({
75
- [DelegationStatus.PENDING]: '\u25CB',
76
- [DelegationStatus.COMPLETED]: '\u2713',
77
- [DelegationStatus.TIMEOUT]: '\u23F1',
78
- [DelegationStatus.CRASHED]: '\u2717',
79
- [DelegationStatus.ESCALATED]: '!',
80
- });
81
-
82
- const TREE_CHARS = Object.freeze({
83
- VERTICAL: '\u2502',
84
- BRANCH: '\u251C',
85
- LAST_BRANCH: '\u2514',
86
- HORIZONTAL: '\u2500',
87
- });
88
-
89
- function getStatusIndicator(status: string | null): string {
90
- switch (status) {
91
- case DelegationStatus.PENDING:
92
- return STATUS_INDICATORS[DelegationStatus.PENDING];
93
- case DelegationStatus.COMPLETED:
94
- return STATUS_INDICATORS[DelegationStatus.COMPLETED];
95
- case DelegationStatus.TIMEOUT:
96
- return STATUS_INDICATORS[DelegationStatus.TIMEOUT];
97
- case DelegationStatus.CRASHED:
98
- return STATUS_INDICATORS[DelegationStatus.CRASHED];
99
- case DelegationStatus.ESCALATED:
100
- return STATUS_INDICATORS[DelegationStatus.ESCALATED];
101
- default:
102
- return '?';
103
- }
104
- }
105
-
106
- function toDelegationRecord(record: RegistryRecord): DelegationRecord {
107
- return {
108
- id: record.id,
109
- parentWuId: record.parentWuId,
110
- targetWuId: record.targetWuId,
111
- lane: record.lane,
112
- status: record.status,
113
- delegatedAt: record.delegatedAt,
114
- completedAt: record.completedAt,
115
- pickedUpAt: record.pickedUpAt,
116
- pickedUpBy: record.pickedUpBy,
117
- schemaVersion: record.schemaVersion,
118
- requested_role: record.requested_role,
119
- actual_role: record.actual_role,
120
- capabilities: record.capabilities,
121
- ownership_scope: record.ownership_scope,
122
- };
123
- }
124
-
125
- /**
126
- * Builds a delegation tree from flat delegation events.
127
- */
128
- export function buildDelegationTree(
129
- delegations: DelegationRecord[],
130
- rootWuId: string,
131
- ): DelegationTreeNode {
132
- const root: DelegationTreeNode = {
133
- wuId: rootWuId,
134
- delegationId: null,
135
- status: null,
136
- lane: null,
137
- delegatedAt: null,
138
- children: [],
139
- };
140
-
141
- if (delegations.length === 0) {
142
- return root;
143
- }
144
-
145
- const delegationsByParent = new Map<string, DelegationRecord[]>();
146
- for (const delegation of delegations) {
147
- const existing = delegationsByParent.get(delegation.parentWuId) ?? [];
148
- existing.push(delegation);
149
- delegationsByParent.set(delegation.parentWuId, existing);
150
- }
151
-
152
- const buildChildren = (parentWuId: string): DelegationTreeNode[] => {
153
- const childDelegations = delegationsByParent.get(parentWuId) ?? [];
154
- return childDelegations.map((delegation) => ({
155
- wuId: delegation.targetWuId,
156
- delegationId: delegation.id,
157
- status: delegation.status,
158
- lane: delegation.lane,
159
- delegatedAt: delegation.delegatedAt,
160
- children: buildChildren(delegation.targetWuId),
161
- schemaVersion: delegation.schemaVersion,
162
- requested_role: delegation.requested_role,
163
- actual_role: delegation.actual_role,
164
- capabilities: delegation.capabilities,
165
- ownership_scope: delegation.ownership_scope,
166
- }));
167
- };
168
-
169
- root.children = buildChildren(rootWuId);
170
- return root;
171
- }
172
-
173
- /**
174
- * Formats a delegation tree for terminal display.
175
- */
176
- export function formatDelegationTree(tree: DelegationTreeNode): string {
177
- const lines: string[] = [];
178
- lines.push(`${tree.wuId} (root)`);
179
-
180
- if (tree.children.length === 0) {
181
- lines.push(' (no delegations)');
182
- return lines.join('\n');
183
- }
184
-
185
- const formatChildren = (children: DelegationTreeNode[], prefix: string): void => {
186
- children.forEach((child, index) => {
187
- const isLast = index === children.length - 1;
188
- const branch = isLast
189
- ? `${TREE_CHARS.LAST_BRANCH}${TREE_CHARS.HORIZONTAL}${TREE_CHARS.HORIZONTAL}`
190
- : `${TREE_CHARS.BRANCH}${TREE_CHARS.HORIZONTAL}${TREE_CHARS.HORIZONTAL}`;
191
- const indicator = getStatusIndicator(child.status);
192
- const delegationInfo = child.delegationId ? ` [${child.delegationId}]` : '';
193
- const laneInfo = child.lane ? ` (${child.lane})` : '';
194
-
195
- lines.push(`${prefix}${branch} ${indicator} ${child.wuId}${delegationInfo}${laneInfo}`);
196
-
197
- const childPrefix = prefix + (isLast ? ' ' : `${TREE_CHARS.VERTICAL} `);
198
- formatChildren(child.children, childPrefix);
199
- });
200
- };
201
-
202
- formatChildren(tree.children, '');
203
- return lines.join('\n');
204
- }
205
-
206
- /**
207
- * Gets all delegations for a WU (direct + descendants).
208
- */
209
- export async function getDelegationsByWU(
210
- wuId: string,
211
- baseDir: string,
212
- ): Promise<DelegationRecord[]> {
213
- const store = new DelegationRegistryStore(baseDir);
214
-
215
- try {
216
- await store.load();
217
- } catch (error) {
218
- if ((error as NodeJS.ErrnoException).code === 'ENOENT') {
219
- return [];
220
- }
221
- throw error;
222
- }
223
-
224
- const allRecords = store.getAllDelegations();
225
- if (allRecords.length === 0) {
226
- return [];
227
- }
228
-
229
- const result: DelegationRecord[] = [];
230
- const seenDelegationIds = new Set<string>();
231
- const visitedWuIds = new Set<string>();
232
- const queue = [wuId];
233
-
234
- while (queue.length > 0) {
235
- const currentWuId = queue.shift();
236
- if (!currentWuId || visitedWuIds.has(currentWuId)) {
237
- continue;
238
- }
239
-
240
- visitedWuIds.add(currentWuId);
241
- const childRecords = store.getByParent(currentWuId) as RegistryRecord[];
242
- for (const child of childRecords) {
243
- if (!seenDelegationIds.has(child.id)) {
244
- result.push(toDelegationRecord(child));
245
- seenDelegationIds.add(child.id);
246
- }
247
- queue.push(child.targetWuId);
248
- }
249
- }
250
-
251
- return result;
252
- }
253
-
254
- /**
255
- * Gets all delegations for an initiative.
256
- */
257
- export async function getDelegationsByInitiative(
258
- initiativeId: string,
259
- registryDir: string,
260
- wuDir: string,
261
- ): Promise<DelegationRecord[]> {
262
- const initiativeWuIds = await getWUsForInitiative(initiativeId, wuDir);
263
- if (initiativeWuIds.size === 0) {
264
- return [];
265
- }
266
-
267
- const store = new DelegationRegistryStore(registryDir);
268
- try {
269
- await store.load();
270
- } catch (error) {
271
- if ((error as NodeJS.ErrnoException).code === 'ENOENT') {
272
- return [];
273
- }
274
- throw error;
275
- }
276
-
277
- return (store.getAllDelegations() as RegistryRecord[])
278
- .filter((record) => initiativeWuIds.has(record.parentWuId))
279
- .map(toDelegationRecord);
280
- }
281
-
282
- async function getWUsForInitiative(initiativeId: string, wuDir: string): Promise<Set<string>> {
283
- const wuIds = new Set<string>();
284
- let files: string[];
285
-
286
- try {
287
- files = await fs.readdir(wuDir);
288
- } catch (error) {
289
- if ((error as NodeJS.ErrnoException).code === 'ENOENT') {
290
- return wuIds;
291
- }
292
- throw error;
293
- }
294
-
295
- const wuFiles = files.filter((file) => file.startsWith('WU-') && file.endsWith('.yaml'));
296
- for (const file of wuFiles) {
297
- try {
298
- const content = await fs.readFile(path.join(wuDir, file), 'utf-8');
299
- const doc = parseYAML(content) as { initiative?: string; id?: string };
300
- if (doc.initiative === initiativeId && typeof doc.id === 'string') {
301
- wuIds.add(doc.id);
302
- }
303
- } catch {
304
- continue;
305
- }
306
- }
307
-
308
- return wuIds;
309
- }
310
-
311
- /**
312
- * Converts a delegation tree to JSON.
313
- */
314
- export function treeToJSON(tree: DelegationTreeNode): DelegationTreeNode {
315
- return {
316
- wuId: tree.wuId,
317
- delegationId: tree.delegationId,
318
- status: tree.status,
319
- lane: tree.lane,
320
- delegatedAt: tree.delegatedAt,
321
- ...(tree.schemaVersion !== undefined ? { schemaVersion: tree.schemaVersion } : {}),
322
- ...(tree.requested_role !== undefined ? { requested_role: tree.requested_role } : {}),
323
- ...(tree.actual_role !== undefined ? { actual_role: tree.actual_role } : {}),
324
- ...(tree.capabilities !== undefined ? { capabilities: tree.capabilities } : {}),
325
- ...(tree.ownership_scope !== undefined ? { ownership_scope: tree.ownership_scope } : {}),
326
- children: tree.children.map((child): DelegationTreeNode => treeToJSON(child)),
327
- };
328
- }
@@ -1,20 +0,0 @@
1
- // Copyright (c) 2026 Hellmai Ltd
2
- // SPDX-License-Identifier: LicenseRef-LumenFlow-Proprietary
3
-
4
- export * from './constants.js';
5
- export * from './capability-factory.js';
6
- export * from './agent-heartbeat.js';
7
- export * from './auto-session-integration.js';
8
- export * from './delegation-registry-schema.js';
9
- export * from './delegation-registry-store.js';
10
- export * from './delegation-tree.js';
11
- export * from './manifest.js';
12
- export * from './memory-coordination-contract.js';
13
- export * from './orchestration.js';
14
- export * from './pack-registration.js';
15
- export * from './policy-factory.js';
16
- export * from './remote-controls/index.js';
17
- export * from './session-schema.js';
18
- export * from './turn-lifecycle-events.js';
19
- export * from './types.js';
20
- export * from './tools/index.js';
@@ -1,348 +0,0 @@
1
- // Copyright (c) 2026 Hellmai Ltd
2
- // SPDX-License-Identifier: LicenseRef-LumenFlow-Proprietary
3
-
4
- import {
5
- DomainPackManifestSchema,
6
- POLICY_TRIGGERS,
7
- type DomainPackManifest,
8
- } from '@lumenflow/kernel';
9
- import {
10
- AGENT_RUNTIME_API_KEY_ENV,
11
- AGENT_RUNTIME_BASE_URL_ENV,
12
- AGENT_RUNTIME_CONFIG_KEY,
13
- AGENT_RUNTIME_CONFIG_SCHEMA_FILE,
14
- AGENT_RUNTIME_PACK_ID,
15
- AGENT_RUNTIME_PACK_VERSION,
16
- AGENT_RUNTIME_POLICY_ID_PREFIX,
17
- AGENT_RUNTIME_STATIC_PROVIDER_ALLOWLIST,
18
- AGENT_RUNTIME_STATIC_PROVIDER_URLS,
19
- AGENT_RUNTIME_STORAGE_PATTERN,
20
- } from './constants.js';
21
- import {
22
- AGENT_RUNTIME_PROVIDER_KINDS,
23
- AGENT_RUNTIME_TOOL_NAMES,
24
- AGENT_RUNTIME_TURN_STATUSES,
25
- type AgentRuntimeToolName,
26
- } from './types.js';
27
- import { AGENT_RUNTIME_EVENT_KIND_VALUES as AGENT_RUNTIME_EMITTED_EVENT_KIND_VALUES } from './turn-lifecycle-events.js';
28
- import {
29
- AGENT_RUNTIME_REMOTE_CONTROL_APPROVALS,
30
- AGENT_RUNTIME_REMOTE_CONTROL_APPROVAL_ID,
31
- AGENT_RUNTIME_REMOTE_CONTROL_TOOL_NAMES,
32
- AGENT_RUNTIME_REMOTE_CONTROL_TOOL_NAME_VALUES,
33
- type AgentRuntimeRemoteControlToolName,
34
- } from './remote-controls/types.js';
35
-
36
- const EXECUTE_TURN_TOOL_ENTRY = 'tool-impl/agent-turn-tools.ts#agentExecuteTurnTool';
37
- const CAPABILITY_FACTORY_ENTRY = 'capability-factory.ts#createAgentRuntimeCapabilityFactory';
38
- const POLICY_FACTORY_ENTRY = 'policy-factory.ts#createAgentRuntimePolicyFactory';
39
-
40
- // WU-2733 (INIT-060 Phase 3, ADR-013 §1 + §6 governance): real
41
- // kernel-side entries. The tracer-bullet mock entries from WU-2732
42
- // (previously at tool-impl/remote-controls.mock.ts) are superseded;
43
- // mock exports remain in-tree only for contract-pin unit tests. Tool
44
- // names, permissions, scopes, approvals, and input schemas stay
45
- // identical — the wire contract is frozen.
46
- const REMOTE_CONTROL_TOOL_ENTRIES = {
47
- [AGENT_RUNTIME_REMOTE_CONTROL_TOOL_NAMES.RESUME_WORKFLOW]:
48
- 'tool-impl/remote-controls.ts#resumeWorkflowTool',
49
- [AGENT_RUNTIME_REMOTE_CONTROL_TOOL_NAMES.PAUSE_TURN]:
50
- 'tool-impl/remote-controls.ts#pauseTurnTool',
51
- [AGENT_RUNTIME_REMOTE_CONTROL_TOOL_NAMES.ABORT_TURN]:
52
- 'tool-impl/remote-controls.ts#abortTurnTool',
53
- [AGENT_RUNTIME_REMOTE_CONTROL_TOOL_NAMES.ELEVATE_AUTONOMY]:
54
- 'tool-impl/remote-controls.ts#elevateAutonomyTool',
55
- [AGENT_RUNTIME_REMOTE_CONTROL_TOOL_NAMES.LOWER_AUTONOMY]:
56
- 'tool-impl/remote-controls.ts#lowerAutonomyTool',
57
- [AGENT_RUNTIME_REMOTE_CONTROL_TOOL_NAMES.APPROVE_INFLIGHT]:
58
- 'tool-impl/remote-controls.ts#approveInflightTool',
59
- } as const satisfies Record<AgentRuntimeRemoteControlToolName, string>;
60
-
61
- /**
62
- * WU-2829 (INIT-062 WU-C): per-tool input schemas for the six
63
- * remote-control tools. The previous single shared placeholder forced
64
- * every tool to accept `reason` even when its real implementation did
65
- * not read it. Cloud now gets schema-level precision: tools that do
66
- * not consume `reason` declare only `session_id`; tools that do
67
- * surface `reason` as an optional operator-supplied rationale.
68
- *
69
- * - session_id is required for every tool (ADR-013 §1 + §6 contract).
70
- * - `reason` is only declared on tools whose operations.ts impl
71
- * surfaces it on the emitted event or state store.
72
- */
73
- const REMOTE_CONTROL_SESSION_ID_PROPERTY = {
74
- session_id: { type: 'string', minLength: 1 },
75
- } as const;
76
-
77
- const REMOTE_CONTROL_REASON_PROPERTY = {
78
- reason: { type: 'string', minLength: 1 },
79
- } as const;
80
-
81
- const REMOTE_CONTROL_SESSION_ONLY_SCHEMA: Record<string, unknown> = {
82
- type: 'object',
83
- properties: { ...REMOTE_CONTROL_SESSION_ID_PROPERTY },
84
- required: ['session_id'],
85
- additionalProperties: false,
86
- };
87
-
88
- const REMOTE_CONTROL_SESSION_AND_REASON_SCHEMA: Record<string, unknown> = {
89
- type: 'object',
90
- properties: {
91
- ...REMOTE_CONTROL_SESSION_ID_PROPERTY,
92
- ...REMOTE_CONTROL_REASON_PROPERTY,
93
- },
94
- required: ['session_id'],
95
- additionalProperties: false,
96
- };
97
-
98
- const REMOTE_CONTROL_INPUT_SCHEMAS: Record<
99
- AgentRuntimeRemoteControlToolName,
100
- Record<string, unknown>
101
- > = {
102
- // resume_workflow: clears the pause marker; operations.ts does not
103
- // read `reason`.
104
- [AGENT_RUNTIME_REMOTE_CONTROL_TOOL_NAMES.RESUME_WORKFLOW]: REMOTE_CONTROL_SESSION_ONLY_SCHEMA,
105
- // pause_turn: stores `reason` on the pause marker.
106
- [AGENT_RUNTIME_REMOTE_CONTROL_TOOL_NAMES.PAUSE_TURN]: REMOTE_CONTROL_SESSION_AND_REASON_SCHEMA,
107
- // abort_turn: records `reason` on the abort state (default
108
- // "operator-requested" when omitted).
109
- [AGENT_RUNTIME_REMOTE_CONTROL_TOOL_NAMES.ABORT_TURN]: REMOTE_CONTROL_SESSION_AND_REASON_SCHEMA,
110
- // elevate_autonomy: surfaces `reason` on the autonomy_changed event.
111
- [AGENT_RUNTIME_REMOTE_CONTROL_TOOL_NAMES.ELEVATE_AUTONOMY]:
112
- REMOTE_CONTROL_SESSION_AND_REASON_SCHEMA,
113
- // lower_autonomy: surfaces `reason` on the autonomy_changed event.
114
- [AGENT_RUNTIME_REMOTE_CONTROL_TOOL_NAMES.LOWER_AUTONOMY]:
115
- REMOTE_CONTROL_SESSION_AND_REASON_SCHEMA,
116
- // approve_inflight: pops the oldest pending approval; operations.ts
117
- // does not read `reason`.
118
- [AGENT_RUNTIME_REMOTE_CONTROL_TOOL_NAMES.APPROVE_INFLIGHT]: REMOTE_CONTROL_SESSION_ONLY_SCHEMA,
119
- };
120
-
121
- const REMOTE_CONTROL_READ_SCOPE = {
122
- type: 'path',
123
- pattern: AGENT_RUNTIME_STORAGE_PATTERN,
124
- access: 'read',
125
- } as const;
126
-
127
- const REMOTE_CONTROL_WRITE_SCOPE = {
128
- type: 'path',
129
- pattern: AGENT_RUNTIME_STORAGE_PATTERN,
130
- access: 'write',
131
- } as const;
132
-
133
- const EXECUTE_TURN_INPUT_SCHEMA: Record<string, unknown> = {
134
- type: 'object',
135
- properties: {
136
- session_id: { type: 'string', minLength: 1 },
137
- model_profile: { type: 'string', minLength: 1 },
138
- url: {
139
- type: 'string',
140
- enum: [...AGENT_RUNTIME_STATIC_PROVIDER_URLS],
141
- },
142
- stream: {
143
- type: 'boolean',
144
- },
145
- messages: {
146
- type: 'array',
147
- minItems: 1,
148
- items: {
149
- type: 'object',
150
- properties: {
151
- role: {
152
- type: 'string',
153
- enum: ['system', 'user', 'assistant', 'tool'],
154
- },
155
- content: { type: 'string' },
156
- tool_name: { type: 'string' },
157
- tool_call_id: { type: 'string' },
158
- },
159
- required: ['role', 'content'],
160
- additionalProperties: false,
161
- },
162
- },
163
- tool_catalog: {
164
- type: 'array',
165
- items: {
166
- type: 'object',
167
- properties: {
168
- name: { type: 'string', minLength: 1 },
169
- description: { type: 'string', minLength: 1 },
170
- input_schema: {
171
- type: 'object',
172
- additionalProperties: true,
173
- },
174
- },
175
- required: ['name', 'description'],
176
- additionalProperties: false,
177
- },
178
- },
179
- intent_catalog: {
180
- type: 'array',
181
- items: {
182
- type: 'object',
183
- properties: {
184
- id: { type: 'string', minLength: 1 },
185
- description: { type: 'string', minLength: 1 },
186
- },
187
- required: ['id', 'description'],
188
- additionalProperties: false,
189
- },
190
- },
191
- limits: {
192
- type: 'object',
193
- properties: {
194
- max_turns_per_session: { type: 'integer', minimum: 1 },
195
- max_tool_calls_per_session: { type: 'integer', minimum: 1 },
196
- max_input_bytes: { type: 'integer', minimum: 1 },
197
- },
198
- additionalProperties: false,
199
- },
200
- },
201
- required: ['session_id', 'model_profile', 'url', 'messages'],
202
- additionalProperties: false,
203
- };
204
-
205
- const EXECUTE_TURN_OUTPUT_SCHEMA: Record<string, unknown> = {
206
- type: 'object',
207
- properties: {
208
- status: {
209
- type: 'string',
210
- enum: Object.values(AGENT_RUNTIME_TURN_STATUSES),
211
- },
212
- intent: { type: 'string', minLength: 1 },
213
- assistant_message: { type: 'string' },
214
- requested_tool: {
215
- type: 'object',
216
- properties: {
217
- name: { type: 'string', minLength: 1 },
218
- input: {
219
- type: 'object',
220
- additionalProperties: true,
221
- },
222
- },
223
- required: ['name', 'input'],
224
- additionalProperties: false,
225
- },
226
- provider: {
227
- type: 'object',
228
- properties: {
229
- kind: {
230
- type: 'string',
231
- enum: Object.values(AGENT_RUNTIME_PROVIDER_KINDS),
232
- },
233
- model: { type: 'string', minLength: 1 },
234
- },
235
- required: ['kind', 'model'],
236
- additionalProperties: false,
237
- },
238
- usage: {
239
- type: 'object',
240
- properties: {
241
- input_tokens: { type: 'integer', minimum: 0 },
242
- output_tokens: { type: 'integer', minimum: 0 },
243
- total_tokens: { type: 'integer', minimum: 0 },
244
- },
245
- additionalProperties: false,
246
- },
247
- finish_reason: { type: 'string', minLength: 1 },
248
- },
249
- required: ['status', 'intent', 'assistant_message', 'provider', 'finish_reason'],
250
- additionalProperties: false,
251
- };
252
-
253
- function buildRemoteControlToolDefinition(name: AgentRuntimeRemoteControlToolName): {
254
- name: AgentRuntimeRemoteControlToolName;
255
- entry: string;
256
- permission: 'write';
257
- required_scopes: readonly [typeof REMOTE_CONTROL_READ_SCOPE, typeof REMOTE_CONTROL_WRITE_SCOPE];
258
- required_approvals: readonly string[];
259
- input_schema: Record<string, unknown>;
260
- } {
261
- return {
262
- name,
263
- entry: REMOTE_CONTROL_TOOL_ENTRIES[name],
264
- permission: 'write',
265
- required_scopes: [REMOTE_CONTROL_READ_SCOPE, REMOTE_CONTROL_WRITE_SCOPE],
266
- required_approvals: [...AGENT_RUNTIME_REMOTE_CONTROL_APPROVALS[name]],
267
- input_schema: REMOTE_CONTROL_INPUT_SCHEMAS[name],
268
- };
269
- }
270
-
271
- const EXECUTE_TURN_TOOL_DEFINITION = {
272
- name: AGENT_RUNTIME_TOOL_NAMES.EXECUTE_TURN,
273
- entry: EXECUTE_TURN_TOOL_ENTRY,
274
- permission: 'write',
275
- required_scopes: [
276
- { type: 'path', pattern: AGENT_RUNTIME_STORAGE_PATTERN, access: 'read' },
277
- { type: 'path', pattern: AGENT_RUNTIME_STORAGE_PATTERN, access: 'write' },
278
- {
279
- type: 'network',
280
- posture: 'allowlist',
281
- allowlist_entries: [...AGENT_RUNTIME_STATIC_PROVIDER_ALLOWLIST],
282
- },
283
- ],
284
- required_env: [AGENT_RUNTIME_API_KEY_ENV, AGENT_RUNTIME_BASE_URL_ENV],
285
- input_schema: EXECUTE_TURN_INPUT_SCHEMA,
286
- output_schema: EXECUTE_TURN_OUTPUT_SCHEMA,
287
- } as const;
288
-
289
- const MANIFEST_TOOL_DEFINITIONS = [
290
- EXECUTE_TURN_TOOL_DEFINITION,
291
- ...AGENT_RUNTIME_REMOTE_CONTROL_TOOL_NAME_VALUES.map((name) =>
292
- buildRemoteControlToolDefinition(name),
293
- ),
294
- ];
295
-
296
- export const AGENT_RUNTIME_MANIFEST = DomainPackManifestSchema.parse({
297
- id: AGENT_RUNTIME_PACK_ID,
298
- version: AGENT_RUNTIME_PACK_VERSION,
299
- config_key: AGENT_RUNTIME_CONFIG_KEY,
300
- config_schema: AGENT_RUNTIME_CONFIG_SCHEMA_FILE,
301
- capability_factory: CAPABILITY_FACTORY_ENTRY,
302
- policy_factory: POLICY_FACTORY_ENTRY,
303
- task_types: ['agent-session'],
304
- tools: MANIFEST_TOOL_DEFINITIONS,
305
- policies: [
306
- {
307
- id: `${AGENT_RUNTIME_POLICY_ID_PREFIX}.default`,
308
- trigger: POLICY_TRIGGERS.ON_TOOL_REQUEST,
309
- decision: 'allow',
310
- reason: 'Pack baseline allow; dynamic intent gating is applied by the pack policy factory.',
311
- },
312
- ],
313
- evidence_types: ['agent-runtime.turn', 'agent-runtime.provider-call'],
314
- emitted_event_kinds: [...AGENT_RUNTIME_EMITTED_EVENT_KIND_VALUES],
315
- required_approvals: [AGENT_RUNTIME_REMOTE_CONTROL_APPROVAL_ID],
316
- state_aliases: {
317
- paused: 'waiting',
318
- },
319
- lane_templates: [],
320
- }) satisfies DomainPackManifest;
321
-
322
- export type AgentRuntimePackManifest = typeof AGENT_RUNTIME_MANIFEST;
323
- export type AgentRuntimeManifestTool = AgentRuntimePackManifest['tools'][number];
324
-
325
- export const AGENT_RUNTIME_MANIFEST_TOOL_NAMES = AGENT_RUNTIME_MANIFEST.tools.map(
326
- (tool) => tool.name,
327
- ) as readonly (AgentRuntimeToolName | AgentRuntimeRemoteControlToolName)[];
328
-
329
- export function getAgentRuntimeManifestToolByName(
330
- name: string,
331
- ): AgentRuntimeManifestTool | undefined {
332
- return AGENT_RUNTIME_MANIFEST.tools.find((tool) => tool.name === name);
333
- }
334
-
335
- /**
336
- * WU-2732 (INIT-060 Phase 3, ADR-013 §3 tool exposure): the 6
337
- * remote-callable remote-control tools. The HTTP tool-api surface
338
- * uses this list to build its allowlist so the set is the single
339
- * source of truth (mirrors WU-2729 software-delivery precedent —
340
- * no duplicate allowlist in surface code).
341
- */
342
- export const AGENT_RUNTIME_REMOTE_CALLABLE_TOOLS = [
343
- ...AGENT_RUNTIME_REMOTE_CONTROL_TOOL_NAME_VALUES,
344
- ] as const satisfies readonly AgentRuntimeRemoteControlToolName[];
345
-
346
- export function getAgentRuntimeRemoteCallableToolNames(): AgentRuntimeRemoteControlToolName[] {
347
- return [...AGENT_RUNTIME_REMOTE_CALLABLE_TOOLS];
348
- }