@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,590 +0,0 @@
1
- // Copyright (c) 2026 Hellmai Ltd
2
- // SPDX-License-Identifier: LicenseRef-LumenFlow-Proprietary
3
-
4
- import { createHash, randomUUID } from 'node:crypto';
5
-
6
- const SCHEMA_VERSION_V2 = 2 as const;
7
- const CONTENT_HASH_ALGORITHM = 'sha256';
8
- const CONTENT_HASH_ENCODING = 'hex';
9
- const CONTENT_HASH_PREFIX_LENGTH = 32;
10
-
11
- export const AGENT_RUNTIME_CHANNEL_ID = 'agent-runtime' as const;
12
-
13
- export const AGENT_RUNTIME_EVENT_KINDS = {
14
- TURN_STARTED: 'agent-runtime:turn_started',
15
- TURN_COMPLETED: 'agent-runtime:turn_completed',
16
- TURN_ABORTED: 'agent-runtime:turn_aborted',
17
- TOOL_CALLED: 'agent-runtime:tool_called',
18
- APPROVAL_REQUIRED: 'agent-runtime:approval_required',
19
- WORKFLOW_NODE_STARTED: 'agent-runtime:workflow_node_started',
20
- WORKFLOW_NODE_COMPLETED: 'agent-runtime:workflow_node_completed',
21
- WORKFLOW_NODE_FAILED: 'agent-runtime:workflow_node_failed',
22
- WORKFLOW_PAUSED: 'agent-runtime:workflow_paused',
23
- SCHEDULED_WAKEUP_SET: 'agent-runtime:scheduled_wakeup_set',
24
- BUDGET_THRESHOLD: 'agent-runtime:budget_threshold',
25
- AGENT_SESSION_ENROLLED: 'agent-runtime:agent_session_enrolled',
26
- AGENT_SESSION_ENDED: 'agent-runtime:agent_session_ended',
27
- AGENT_SESSION_STALLED: 'agent-runtime:agent_session_stalled',
28
- // WU-2733 (INIT-060 Phase 3, ADR-013 §6 governance):
29
- // autonomy_changed emitted by elevate_autonomy / lower_autonomy real
30
- // remote-control impls. Cloud conductor subscribes to render the new
31
- // autonomy band in the session UI.
32
- AUTONOMY_CHANGED: 'agent-runtime:autonomy_changed',
33
- } as const;
34
-
35
- export const AGENT_RUNTIME_EVENT_KIND_VALUES = [
36
- AGENT_RUNTIME_EVENT_KINDS.TURN_STARTED,
37
- AGENT_RUNTIME_EVENT_KINDS.TURN_COMPLETED,
38
- AGENT_RUNTIME_EVENT_KINDS.TURN_ABORTED,
39
- AGENT_RUNTIME_EVENT_KINDS.TOOL_CALLED,
40
- AGENT_RUNTIME_EVENT_KINDS.APPROVAL_REQUIRED,
41
- AGENT_RUNTIME_EVENT_KINDS.WORKFLOW_NODE_STARTED,
42
- AGENT_RUNTIME_EVENT_KINDS.WORKFLOW_NODE_COMPLETED,
43
- AGENT_RUNTIME_EVENT_KINDS.WORKFLOW_NODE_FAILED,
44
- AGENT_RUNTIME_EVENT_KINDS.WORKFLOW_PAUSED,
45
- AGENT_RUNTIME_EVENT_KINDS.SCHEDULED_WAKEUP_SET,
46
- AGENT_RUNTIME_EVENT_KINDS.BUDGET_THRESHOLD,
47
- AGENT_RUNTIME_EVENT_KINDS.AGENT_SESSION_ENROLLED,
48
- AGENT_RUNTIME_EVENT_KINDS.AGENT_SESSION_ENDED,
49
- AGENT_RUNTIME_EVENT_KINDS.AGENT_SESSION_STALLED,
50
- AGENT_RUNTIME_EVENT_KINDS.AUTONOMY_CHANGED,
51
- ] as const;
52
-
53
- export type AgentRuntimeEventKind = (typeof AGENT_RUNTIME_EVENT_KIND_VALUES)[number];
54
-
55
- interface AgentRuntimeEventEnvelope {
56
- schema_version: typeof SCHEMA_VERSION_V2;
57
- timestamp: string;
58
- event_id: string;
59
- channel_id: typeof AGENT_RUNTIME_CHANNEL_ID;
60
- seq: number;
61
- }
62
-
63
- export interface AgentRuntimeTurnCostBreakdown {
64
- input_tokens_usd: number;
65
- output_tokens_usd: number;
66
- tool_calls_usd: number;
67
- total_usd: number;
68
- }
69
-
70
- export type AgentRuntimeCleanupStatus = 'clean' | 'partial' | 'needs_recovery';
71
-
72
- /**
73
- * WU-2829 (INIT-062 WU-C): narrowed TurnCompletedEvent.status so cloud
74
- * can resolve the turn discriminant without runtime string checks. The
75
- * four values describe the lifecycle outcome of a turn; the internal
76
- * per-turn semantic status (`reply | tool_request | complete | escalate`)
77
- * remains on AgentRuntimeExecuteTurnOutput — it is NOT the same concept.
78
- */
79
- export const AGENT_RUNTIME_TURN_COMPLETED_STATUSES = {
80
- SUCCESS: 'success',
81
- ERROR: 'error',
82
- ABORTED: 'aborted',
83
- PAUSED: 'paused',
84
- } as const;
85
-
86
- export const AGENT_RUNTIME_TURN_COMPLETED_STATUS_VALUES = [
87
- AGENT_RUNTIME_TURN_COMPLETED_STATUSES.SUCCESS,
88
- AGENT_RUNTIME_TURN_COMPLETED_STATUSES.ERROR,
89
- AGENT_RUNTIME_TURN_COMPLETED_STATUSES.ABORTED,
90
- AGENT_RUNTIME_TURN_COMPLETED_STATUSES.PAUSED,
91
- ] as const;
92
-
93
- export type AgentRuntimeTurnCompletedStatus =
94
- (typeof AGENT_RUNTIME_TURN_COMPLETED_STATUS_VALUES)[number];
95
-
96
- /**
97
- * WU-2829 (INIT-062 WU-C): budget threshold enrichment. Cloud previously
98
- * had to reconstruct `level` from `threshold`/`observed_value`; we now
99
- * supply the discriminant directly alongside `remaining_usd`, `scope`,
100
- * and `scope_id` so dashboards render without post-hoc inference.
101
- */
102
- export const AGENT_RUNTIME_BUDGET_LEVELS = {
103
- WARNING: 'warning',
104
- EXCEEDED: 'exceeded',
105
- } as const;
106
-
107
- export const AGENT_RUNTIME_BUDGET_LEVEL_VALUES = [
108
- AGENT_RUNTIME_BUDGET_LEVELS.WARNING,
109
- AGENT_RUNTIME_BUDGET_LEVELS.EXCEEDED,
110
- ] as const;
111
-
112
- export type AgentRuntimeBudgetLevel = (typeof AGENT_RUNTIME_BUDGET_LEVEL_VALUES)[number];
113
-
114
- export const AGENT_RUNTIME_BUDGET_SCOPES = {
115
- SESSION: 'session',
116
- WORKSPACE: 'workspace',
117
- ORG: 'org',
118
- } as const;
119
-
120
- export const AGENT_RUNTIME_BUDGET_SCOPE_VALUES = [
121
- AGENT_RUNTIME_BUDGET_SCOPES.SESSION,
122
- AGENT_RUNTIME_BUDGET_SCOPES.WORKSPACE,
123
- AGENT_RUNTIME_BUDGET_SCOPES.ORG,
124
- ] as const;
125
-
126
- export type AgentRuntimeBudgetScope = (typeof AGENT_RUNTIME_BUDGET_SCOPE_VALUES)[number];
127
-
128
- export interface TurnStartedEvent extends AgentRuntimeEventEnvelope {
129
- kind: typeof AGENT_RUNTIME_EVENT_KINDS.TURN_STARTED;
130
- session_id: string;
131
- turn_index: number;
132
- model_profile: string;
133
- }
134
-
135
- export interface TurnCompletedEvent extends AgentRuntimeEventEnvelope {
136
- kind: typeof AGENT_RUNTIME_EVENT_KINDS.TURN_COMPLETED;
137
- session_id: string;
138
- turn_index: number;
139
- // WU-2829: narrowed from `string` to the four lifecycle outcomes so
140
- // cloud gets TS exhaustiveness on the discriminated union.
141
- status: AgentRuntimeTurnCompletedStatus;
142
- cost_breakdown: AgentRuntimeTurnCostBreakdown;
143
- }
144
-
145
- export interface TurnAbortedEvent extends AgentRuntimeEventEnvelope {
146
- kind: typeof AGENT_RUNTIME_EVENT_KINDS.TURN_ABORTED;
147
- session_id: string;
148
- turn_index: number;
149
- cleanup_status: AgentRuntimeCleanupStatus;
150
- recovery_action: string | null;
151
- reason: string;
152
- }
153
-
154
- export interface ToolCalledEvent extends AgentRuntimeEventEnvelope {
155
- kind: typeof AGENT_RUNTIME_EVENT_KINDS.TOOL_CALLED;
156
- session_id: string;
157
- turn_index: number;
158
- tool_name: string;
159
- tool_call_id: string;
160
- /**
161
- * WU-2829 (INIT-062 WU-C): approval discriminant so cloud no longer
162
- * has to cross-reference APPROVAL_REQUIRED events to tell which tool
163
- * calls were gated. `true` = call proceeded (either no approval
164
- * required, or approval was satisfied); `false` = call blocked
165
- * pending an approval (paired with a subsequent APPROVAL_REQUIRED
166
- * event carrying the request_id).
167
- */
168
- approved: boolean;
169
- }
170
-
171
- export interface ApprovalRequiredEvent extends AgentRuntimeEventEnvelope {
172
- kind: typeof AGENT_RUNTIME_EVENT_KINDS.APPROVAL_REQUIRED;
173
- session_id: string;
174
- turn_index: number;
175
- tool_name: string;
176
- request_id: string;
177
- }
178
-
179
- export interface WorkflowNodeStartedEvent extends AgentRuntimeEventEnvelope {
180
- kind: typeof AGENT_RUNTIME_EVENT_KINDS.WORKFLOW_NODE_STARTED;
181
- session_id: string;
182
- node_id: string;
183
- }
184
-
185
- export interface WorkflowNodeCompletedEvent extends AgentRuntimeEventEnvelope {
186
- kind: typeof AGENT_RUNTIME_EVENT_KINDS.WORKFLOW_NODE_COMPLETED;
187
- session_id: string;
188
- node_id: string;
189
- }
190
-
191
- export interface WorkflowNodeFailedEvent extends AgentRuntimeEventEnvelope {
192
- kind: typeof AGENT_RUNTIME_EVENT_KINDS.WORKFLOW_NODE_FAILED;
193
- session_id: string;
194
- node_id: string;
195
- error_code: string;
196
- error_message: string;
197
- }
198
-
199
- export interface WorkflowPausedEvent extends AgentRuntimeEventEnvelope {
200
- kind: typeof AGENT_RUNTIME_EVENT_KINDS.WORKFLOW_PAUSED;
201
- session_id: string;
202
- node_id: string;
203
- reason: string;
204
- }
205
-
206
- export interface ScheduledWakeupSetEvent extends AgentRuntimeEventEnvelope {
207
- kind: typeof AGENT_RUNTIME_EVENT_KINDS.SCHEDULED_WAKEUP_SET;
208
- session_id: string;
209
- node_id: string;
210
- wake_at: string;
211
- }
212
-
213
- export interface BudgetThresholdEvent extends AgentRuntimeEventEnvelope {
214
- kind: typeof AGENT_RUNTIME_EVENT_KINDS.BUDGET_THRESHOLD;
215
- session_id: string;
216
- budget_name: string;
217
- threshold: number;
218
- observed_value: number;
219
- /**
220
- * WU-2829 (INIT-062 WU-C): discriminant for cloud dashboards so the
221
- * level is no longer inferred from threshold/observed_value.
222
- */
223
- level: AgentRuntimeBudgetLevel;
224
- /**
225
- * WU-2829 (INIT-062 WU-C): remaining USD headroom for the budget at
226
- * emission time. Negative values are permitted when the budget is
227
- * already exceeded.
228
- */
229
- remaining_usd: number;
230
- /**
231
- * WU-2829 (INIT-062 WU-C): budget scope so cloud can route the signal
232
- * to the correct dashboard (session / workspace / org).
233
- */
234
- scope: AgentRuntimeBudgetScope;
235
- /**
236
- * WU-2829 (INIT-062 WU-C): identifier of the scope object (session id,
237
- * workspace id, or org id) — paired with `scope` to pin the emission
238
- * to a specific subject.
239
- */
240
- scope_id: string;
241
- }
242
-
243
- export interface AgentSessionEnrolledEvent extends AgentRuntimeEventEnvelope {
244
- kind: typeof AGENT_RUNTIME_EVENT_KINDS.AGENT_SESSION_ENROLLED;
245
- session_id: string;
246
- wu_id: string;
247
- lane: string;
248
- client_type: string;
249
- }
250
-
251
- export interface AgentSessionEndedEvent extends AgentRuntimeEventEnvelope {
252
- kind: typeof AGENT_RUNTIME_EVENT_KINDS.AGENT_SESSION_ENDED;
253
- session_id: string;
254
- wu_id: string;
255
- lane: string;
256
- incidents_logged: number;
257
- incidents_major: number;
258
- }
259
-
260
- export interface AgentSessionStalledEvent extends AgentRuntimeEventEnvelope {
261
- kind: typeof AGENT_RUNTIME_EVENT_KINDS.AGENT_SESSION_STALLED;
262
- session_id: string;
263
- wu_id: string;
264
- lane: string;
265
- stage: string;
266
- reason: string;
267
- }
268
-
269
- /**
270
- * WU-2733 (INIT-060 Phase 3, ADR-013 §6 governance): autonomy_changed
271
- * carries the transition between autonomy bands ("manual" ↔ "assisted"
272
- * ↔ "auto") so cloud renders the shift and operators see the change
273
- * reflected in the evidence feed. `reason` surfaces the operator-supplied
274
- * rationale when provided.
275
- */
276
- export interface AutonomyChangedEvent extends AgentRuntimeEventEnvelope {
277
- kind: typeof AGENT_RUNTIME_EVENT_KINDS.AUTONOMY_CHANGED;
278
- session_id: string;
279
- previous_level: string;
280
- new_level: string;
281
- direction: 'elevate' | 'lower';
282
- reason: string | null;
283
- }
284
-
285
- export type AgentRuntimeEvent =
286
- | TurnStartedEvent
287
- | TurnCompletedEvent
288
- | TurnAbortedEvent
289
- | ToolCalledEvent
290
- | ApprovalRequiredEvent
291
- | WorkflowNodeStartedEvent
292
- | WorkflowNodeCompletedEvent
293
- | WorkflowNodeFailedEvent
294
- | WorkflowPausedEvent
295
- | ScheduledWakeupSetEvent
296
- | BudgetThresholdEvent
297
- | AgentSessionEnrolledEvent
298
- | AgentSessionEndedEvent
299
- | AgentSessionStalledEvent
300
- | AutonomyChangedEvent;
301
-
302
- export type AgentRuntimeEventSink = (event: AgentRuntimeEvent) => void;
303
-
304
- export interface AgentRuntimeEventBuildOptions {
305
- timestamp?: string;
306
- idempotencyKey?: string;
307
- }
308
-
309
- export function resetAgentRuntimeSeqCounter(): void {
310
- channelSeqCounters.clear();
311
- }
312
-
313
- export function createZeroTurnCostBreakdown(): AgentRuntimeTurnCostBreakdown {
314
- return {
315
- input_tokens_usd: 0,
316
- output_tokens_usd: 0,
317
- tool_calls_usd: 0,
318
- total_usd: 0,
319
- };
320
- }
321
-
322
- export function buildTurnStartedEvent(
323
- input: Omit<TurnStartedEvent, keyof AgentRuntimeEventEnvelope | 'kind'>,
324
- options?: AgentRuntimeEventBuildOptions,
325
- ): TurnStartedEvent {
326
- return buildAgentRuntimeEvent(
327
- {
328
- kind: AGENT_RUNTIME_EVENT_KINDS.TURN_STARTED,
329
- ...input,
330
- },
331
- options,
332
- );
333
- }
334
-
335
- export function buildTurnCompletedEvent(
336
- input: Omit<TurnCompletedEvent, keyof AgentRuntimeEventEnvelope | 'kind'>,
337
- options?: AgentRuntimeEventBuildOptions,
338
- ): TurnCompletedEvent {
339
- return buildAgentRuntimeEvent(
340
- {
341
- kind: AGENT_RUNTIME_EVENT_KINDS.TURN_COMPLETED,
342
- ...input,
343
- },
344
- options,
345
- );
346
- }
347
-
348
- export function buildTurnAbortedEvent(
349
- input: Omit<TurnAbortedEvent, keyof AgentRuntimeEventEnvelope | 'kind' | 'recovery_action'> & {
350
- recovery_action?: string | null;
351
- },
352
- options?: AgentRuntimeEventBuildOptions,
353
- ): TurnAbortedEvent {
354
- return buildAgentRuntimeEvent(
355
- {
356
- kind: AGENT_RUNTIME_EVENT_KINDS.TURN_ABORTED,
357
- ...input,
358
- recovery_action: resolveRecoveryAction(input.cleanup_status, input.recovery_action),
359
- },
360
- options,
361
- );
362
- }
363
-
364
- export function buildToolCalledEvent(
365
- input: Omit<ToolCalledEvent, keyof AgentRuntimeEventEnvelope | 'kind'>,
366
- options?: AgentRuntimeEventBuildOptions,
367
- ): ToolCalledEvent {
368
- return buildAgentRuntimeEvent(
369
- {
370
- kind: AGENT_RUNTIME_EVENT_KINDS.TOOL_CALLED,
371
- ...input,
372
- },
373
- options,
374
- );
375
- }
376
-
377
- export function buildApprovalRequiredEvent(
378
- input: Omit<ApprovalRequiredEvent, keyof AgentRuntimeEventEnvelope | 'kind'>,
379
- options?: AgentRuntimeEventBuildOptions,
380
- ): ApprovalRequiredEvent {
381
- return buildAgentRuntimeEvent(
382
- {
383
- kind: AGENT_RUNTIME_EVENT_KINDS.APPROVAL_REQUIRED,
384
- ...input,
385
- },
386
- options,
387
- );
388
- }
389
-
390
- export function buildWorkflowNodeStartedEvent(
391
- input: Omit<WorkflowNodeStartedEvent, keyof AgentRuntimeEventEnvelope | 'kind'>,
392
- options?: AgentRuntimeEventBuildOptions,
393
- ): WorkflowNodeStartedEvent {
394
- return buildAgentRuntimeEvent(
395
- {
396
- kind: AGENT_RUNTIME_EVENT_KINDS.WORKFLOW_NODE_STARTED,
397
- ...input,
398
- },
399
- options,
400
- );
401
- }
402
-
403
- export function buildWorkflowNodeCompletedEvent(
404
- input: Omit<WorkflowNodeCompletedEvent, keyof AgentRuntimeEventEnvelope | 'kind'>,
405
- options?: AgentRuntimeEventBuildOptions,
406
- ): WorkflowNodeCompletedEvent {
407
- return buildAgentRuntimeEvent(
408
- {
409
- kind: AGENT_RUNTIME_EVENT_KINDS.WORKFLOW_NODE_COMPLETED,
410
- ...input,
411
- },
412
- options,
413
- );
414
- }
415
-
416
- export function buildWorkflowNodeFailedEvent(
417
- input: Omit<WorkflowNodeFailedEvent, keyof AgentRuntimeEventEnvelope | 'kind'>,
418
- options?: AgentRuntimeEventBuildOptions,
419
- ): WorkflowNodeFailedEvent {
420
- return buildAgentRuntimeEvent(
421
- {
422
- kind: AGENT_RUNTIME_EVENT_KINDS.WORKFLOW_NODE_FAILED,
423
- ...input,
424
- },
425
- options,
426
- );
427
- }
428
-
429
- export function buildWorkflowPausedEvent(
430
- input: Omit<WorkflowPausedEvent, keyof AgentRuntimeEventEnvelope | 'kind'>,
431
- options?: AgentRuntimeEventBuildOptions,
432
- ): WorkflowPausedEvent {
433
- return buildAgentRuntimeEvent(
434
- {
435
- kind: AGENT_RUNTIME_EVENT_KINDS.WORKFLOW_PAUSED,
436
- ...input,
437
- },
438
- options,
439
- );
440
- }
441
-
442
- export function buildScheduledWakeupSetEvent(
443
- input: Omit<ScheduledWakeupSetEvent, keyof AgentRuntimeEventEnvelope | 'kind'>,
444
- options?: AgentRuntimeEventBuildOptions,
445
- ): ScheduledWakeupSetEvent {
446
- return buildAgentRuntimeEvent(
447
- {
448
- kind: AGENT_RUNTIME_EVENT_KINDS.SCHEDULED_WAKEUP_SET,
449
- ...input,
450
- },
451
- options,
452
- );
453
- }
454
-
455
- export function buildBudgetThresholdEvent(
456
- input: Omit<BudgetThresholdEvent, keyof AgentRuntimeEventEnvelope | 'kind'>,
457
- options?: AgentRuntimeEventBuildOptions,
458
- ): BudgetThresholdEvent {
459
- return buildAgentRuntimeEvent(
460
- {
461
- kind: AGENT_RUNTIME_EVENT_KINDS.BUDGET_THRESHOLD,
462
- ...input,
463
- },
464
- options,
465
- );
466
- }
467
-
468
- export function buildAgentSessionEnrolledEvent(
469
- input: Omit<AgentSessionEnrolledEvent, keyof AgentRuntimeEventEnvelope | 'kind'>,
470
- options?: AgentRuntimeEventBuildOptions,
471
- ): AgentSessionEnrolledEvent {
472
- return buildAgentRuntimeEvent(
473
- {
474
- kind: AGENT_RUNTIME_EVENT_KINDS.AGENT_SESSION_ENROLLED,
475
- ...input,
476
- },
477
- options,
478
- );
479
- }
480
-
481
- export function buildAgentSessionEndedEvent(
482
- input: Omit<AgentSessionEndedEvent, keyof AgentRuntimeEventEnvelope | 'kind'>,
483
- options?: AgentRuntimeEventBuildOptions,
484
- ): AgentSessionEndedEvent {
485
- return buildAgentRuntimeEvent(
486
- {
487
- kind: AGENT_RUNTIME_EVENT_KINDS.AGENT_SESSION_ENDED,
488
- ...input,
489
- },
490
- options,
491
- );
492
- }
493
-
494
- export function buildAgentSessionStalledEvent(
495
- input: Omit<AgentSessionStalledEvent, keyof AgentRuntimeEventEnvelope | 'kind'>,
496
- options?: AgentRuntimeEventBuildOptions,
497
- ): AgentSessionStalledEvent {
498
- return buildAgentRuntimeEvent(
499
- {
500
- kind: AGENT_RUNTIME_EVENT_KINDS.AGENT_SESSION_STALLED,
501
- ...input,
502
- },
503
- options,
504
- );
505
- }
506
-
507
- export function buildAutonomyChangedEvent(
508
- input: Omit<AutonomyChangedEvent, keyof AgentRuntimeEventEnvelope | 'kind'>,
509
- options?: AgentRuntimeEventBuildOptions,
510
- ): AutonomyChangedEvent {
511
- return buildAgentRuntimeEvent(
512
- {
513
- kind: AGENT_RUNTIME_EVENT_KINDS.AUTONOMY_CHANGED,
514
- ...input,
515
- },
516
- options,
517
- );
518
- }
519
-
520
- export function emitAgentRuntimeEvent(
521
- sink: AgentRuntimeEventSink | undefined,
522
- event: AgentRuntimeEvent,
523
- ): void {
524
- if (!sink) {
525
- return;
526
- }
527
- try {
528
- sink(event);
529
- } catch {
530
- // Ephemeral telemetry must never break the host/session workflow.
531
- }
532
- }
533
-
534
- const channelSeqCounters = new Map<string, number>();
535
-
536
- function buildAgentRuntimeEvent<T extends { kind: AgentRuntimeEventKind }>(
537
- payload: T,
538
- options?: AgentRuntimeEventBuildOptions,
539
- ): T & AgentRuntimeEventEnvelope {
540
- const timestamp = options?.timestamp ?? new Date().toISOString();
541
- const payloadRecord = payload as unknown as Record<string, unknown>;
542
- return {
543
- ...payload,
544
- schema_version: SCHEMA_VERSION_V2,
545
- timestamp,
546
- event_id: resolveEventId(payload.kind, payloadRecord, timestamp, options),
547
- channel_id: AGENT_RUNTIME_CHANNEL_ID,
548
- seq: nextSeq(AGENT_RUNTIME_CHANNEL_ID),
549
- };
550
- }
551
-
552
- function resolveEventId(
553
- kind: string,
554
- payload: Record<string, unknown>,
555
- timestamp: string,
556
- options?: AgentRuntimeEventBuildOptions,
557
- ): string {
558
- const key = options?.idempotencyKey;
559
- if (!key) {
560
- return randomUUID();
561
- }
562
- const canonicalPayload = JSON.stringify(payload, Object.keys(payload).sort());
563
- return createHash(CONTENT_HASH_ALGORITHM)
564
- .update(`${key}|${kind}|${timestamp}|${canonicalPayload}`)
565
- .digest(CONTENT_HASH_ENCODING)
566
- .slice(0, CONTENT_HASH_PREFIX_LENGTH);
567
- }
568
-
569
- function nextSeq(channelId: string): number {
570
- const current = channelSeqCounters.get(channelId) ?? 0;
571
- const next = current + 1;
572
- channelSeqCounters.set(channelId, next);
573
- return next;
574
- }
575
-
576
- function resolveRecoveryAction(
577
- cleanupStatus: AgentRuntimeCleanupStatus,
578
- recoveryAction?: string | null,
579
- ): string | null {
580
- if (cleanupStatus === 'clean') {
581
- return null;
582
- }
583
- if (recoveryAction && recoveryAction.trim().length > 0) {
584
- return recoveryAction.trim();
585
- }
586
- if (cleanupStatus === 'partial') {
587
- return 'Review the partially applied state and re-run wu:prep before resuming.';
588
- }
589
- return 'Run wu:recover after reviewing the current session state.';
590
- }
@@ -1,128 +0,0 @@
1
- // Copyright (c) 2026 Hellmai Ltd
2
- // SPDX-License-Identifier: LicenseRef-LumenFlow-Proprietary
3
-
4
- import {
5
- AGENT_RUNTIME_API_KEY_ENV,
6
- AGENT_RUNTIME_BASE_URL_ENV,
7
- AGENT_RUNTIME_PACK_ID,
8
- } from './constants.js';
9
-
10
- export const AGENT_RUNTIME_PROVIDER_KINDS = {
11
- OPENAI_COMPATIBLE: 'openai_compatible',
12
- MESSAGES_COMPATIBLE: 'messages_compatible',
13
- } as const;
14
-
15
- export const AGENT_RUNTIME_TURN_STATUSES = {
16
- REPLY: 'reply',
17
- TOOL_REQUEST: 'tool_request',
18
- COMPLETE: 'complete',
19
- ESCALATE: 'escalate',
20
- } as const;
21
-
22
- export const AGENT_RUNTIME_TOOL_NAMES = {
23
- EXECUTE_TURN: 'agent:execute-turn',
24
- } as const;
25
-
26
- export type AgentRuntimePackId = typeof AGENT_RUNTIME_PACK_ID;
27
- export type AgentRuntimeProviderKind =
28
- (typeof AGENT_RUNTIME_PROVIDER_KINDS)[keyof typeof AGENT_RUNTIME_PROVIDER_KINDS];
29
- export type AgentRuntimeTurnStatus =
30
- (typeof AGENT_RUNTIME_TURN_STATUSES)[keyof typeof AGENT_RUNTIME_TURN_STATUSES];
31
- export type AgentRuntimeToolName =
32
- (typeof AGENT_RUNTIME_TOOL_NAMES)[keyof typeof AGENT_RUNTIME_TOOL_NAMES];
33
-
34
- export interface AgentRuntimeModelProfileConfig {
35
- provider: AgentRuntimeProviderKind;
36
- model: string;
37
- api_key_env: string;
38
- base_url?: string;
39
- base_url_env?: string;
40
- }
41
-
42
- export interface AgentRuntimeIntentConfig {
43
- description: string;
44
- allow_tools: string[];
45
- approval_required_tools?: string[];
46
- }
47
-
48
- export interface AgentRuntimeLimitsConfig {
49
- max_turns_per_session?: number;
50
- max_tool_calls_per_session?: number;
51
- max_input_bytes?: number;
52
- }
53
-
54
- export interface AgentRuntimePackConfig {
55
- default_model: string;
56
- models: Record<string, AgentRuntimeModelProfileConfig>;
57
- intents?: Record<string, AgentRuntimeIntentConfig>;
58
- limits?: AgentRuntimeLimitsConfig;
59
- }
60
-
61
- export interface AgentRuntimeMessage {
62
- role: 'system' | 'user' | 'assistant' | 'tool';
63
- content: string;
64
- tool_name?: string;
65
- tool_call_id?: string;
66
- }
67
-
68
- export interface AgentRuntimeToolCatalogEntry {
69
- name: string;
70
- description: string;
71
- input_schema?: Record<string, unknown>;
72
- }
73
-
74
- export interface AgentRuntimeIntentCatalogEntry {
75
- id: string;
76
- description: string;
77
- }
78
-
79
- export interface AgentRuntimeExecuteTurnInput {
80
- session_id: string;
81
- messages: AgentRuntimeMessage[];
82
- model_profile: string;
83
- url: string;
84
- stream?: boolean;
85
- tool_catalog?: AgentRuntimeToolCatalogEntry[];
86
- intent_catalog?: AgentRuntimeIntentCatalogEntry[];
87
- limits?: AgentRuntimeLimitsConfig;
88
- }
89
-
90
- export interface AgentRuntimeStreamSnapshot {
91
- sequence: number;
92
- state: 'partial' | 'final';
93
- data: Record<string, unknown>;
94
- }
95
-
96
- export interface AgentRuntimeRequestedTool {
97
- name: string;
98
- input: Record<string, unknown>;
99
- }
100
-
101
- export interface AgentRuntimeUsage {
102
- input_tokens?: number;
103
- output_tokens?: number;
104
- total_tokens?: number;
105
- }
106
-
107
- export interface AgentRuntimeProviderDescriptor {
108
- kind: AgentRuntimeProviderKind;
109
- model: string;
110
- }
111
-
112
- export interface AgentRuntimeExecuteTurnOutput {
113
- status: AgentRuntimeTurnStatus;
114
- intent: string;
115
- assistant_message: string;
116
- requested_tool?: AgentRuntimeRequestedTool;
117
- provider: AgentRuntimeProviderDescriptor;
118
- usage?: AgentRuntimeUsage;
119
- finish_reason: string;
120
- }
121
-
122
- export const AGENT_RUNTIME_DECLARED_ENVIRONMENT_VARIABLES = [
123
- AGENT_RUNTIME_API_KEY_ENV,
124
- AGENT_RUNTIME_BASE_URL_ENV,
125
- ] as const;
126
-
127
- export type AgentRuntimeDeclaredEnvironmentVariable =
128
- (typeof AGENT_RUNTIME_DECLARED_ENVIRONMENT_VARIABLES)[number];