@lumenflow/cli 3.16.0 → 3.17.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 (167) hide show
  1. package/README.md +1 -3
  2. package/dist/config-get.js +3 -3
  3. package/dist/config-get.js.map +1 -1
  4. package/dist/config-set.js +3 -3
  5. package/dist/config-set.js.map +1 -1
  6. package/dist/docs-sync.js +302 -57
  7. package/dist/docs-sync.js.map +1 -1
  8. package/dist/doctor.js +3 -3
  9. package/dist/doctor.js.map +1 -1
  10. package/dist/gate-defaults.js +3 -0
  11. package/dist/gate-defaults.js.map +1 -1
  12. package/dist/gates-plan-resolvers.js +3 -4
  13. package/dist/gates-plan-resolvers.js.map +1 -1
  14. package/dist/gates-runners.js +48 -0
  15. package/dist/gates-runners.js.map +1 -1
  16. package/dist/gates-utils.js +64 -3
  17. package/dist/gates-utils.js.map +1 -1
  18. package/dist/gates.js +2 -1
  19. package/dist/gates.js.map +1 -1
  20. package/dist/init-scaffolding.js +28 -1
  21. package/dist/init-scaffolding.js.map +1 -1
  22. package/dist/init-templates.js +6 -2
  23. package/dist/init-templates.js.map +1 -1
  24. package/dist/init.js +22 -25
  25. package/dist/init.js.map +1 -1
  26. package/dist/lane-create.js +2 -2
  27. package/dist/lane-create.js.map +1 -1
  28. package/dist/lane-edit.js +2 -2
  29. package/dist/lane-edit.js.map +1 -1
  30. package/dist/lane-lock.js +8 -6
  31. package/dist/lane-lock.js.map +1 -1
  32. package/dist/lane-setup.js +7 -5
  33. package/dist/lane-setup.js.map +1 -1
  34. package/dist/lane-status.js +7 -5
  35. package/dist/lane-status.js.map +1 -1
  36. package/dist/lane-validate.js +8 -6
  37. package/dist/lane-validate.js.map +1 -1
  38. package/dist/lumenflow-upgrade.js +22 -13
  39. package/dist/lumenflow-upgrade.js.map +1 -1
  40. package/dist/onboard.js +15 -16
  41. package/dist/onboard.js.map +1 -1
  42. package/dist/orchestrate-initiative.js +29 -8
  43. package/dist/orchestrate-initiative.js.map +1 -1
  44. package/dist/state-doctor.js +3 -4
  45. package/dist/state-doctor.js.map +1 -1
  46. package/dist/wu-done-policies.js +38 -0
  47. package/dist/wu-done-policies.js.map +1 -1
  48. package/dist/wu-edit-operations.js +27 -24
  49. package/dist/wu-edit-operations.js.map +1 -1
  50. package/dist/wu-edit-validators.js +68 -0
  51. package/dist/wu-edit-validators.js.map +1 -1
  52. package/dist/wu-edit.js +11 -3
  53. package/dist/wu-edit.js.map +1 -1
  54. package/package.json +8 -8
  55. package/packs/sidekick/.turbo/turbo-build.log +1 -1
  56. package/packs/sidekick/package.json +1 -1
  57. package/packs/software-delivery/.turbo/turbo-build.log +1 -1
  58. package/packs/software-delivery/package.json +1 -1
  59. package/templates/core/AGENTS.md.template +2 -1
  60. package/templates/core/LUMENFLOW.md.template +5 -1
  61. package/templates/core/UPGRADING.md.template +14 -10
  62. package/templates/core/ai/onboarding/initiative-orchestration.md.template +1 -1
  63. package/templates/core/ai/onboarding/quick-ref-commands.md.template +11 -10
  64. package/templates/core/ai/onboarding/starting-prompt.md.template +3 -3
  65. package/templates/vendors/claude/.claude/CLAUDE.md.template +2 -1
  66. package/templates/vendors/cursor/.cursor/rules/lumenflow.md.template +2 -1
  67. package/templates/vendors/windsurf/.windsurf/rules/lumenflow.md.template +2 -1
  68. package/dist/chunk-2D2VOCA4.js +0 -37
  69. package/dist/chunk-2D5KFYGX.js +0 -284
  70. package/dist/chunk-2GXVIN57.js +0 -14072
  71. package/dist/chunk-2MQ7HZWZ.js +0 -26
  72. package/dist/chunk-2UFQ3A3C.js +0 -643
  73. package/dist/chunk-3RG5ZIWI.js +0 -10
  74. package/dist/chunk-4N74J3UT.js +0 -15
  75. package/dist/chunk-5GTOXFYR.js +0 -392
  76. package/dist/chunk-5VY6MQMC.js +0 -240
  77. package/dist/chunk-67XVPMRY.js +0 -1297
  78. package/dist/chunk-6HO4GWJE.js +0 -164
  79. package/dist/chunk-6W5XHWYV.js +0 -1890
  80. package/dist/chunk-6X4EMYJQ.js +0 -64
  81. package/dist/chunk-6XYXI2NQ.js +0 -772
  82. package/dist/chunk-7ANSOV6Q.js +0 -285
  83. package/dist/chunk-A624LFLB.js +0 -1380
  84. package/dist/chunk-ADN5NHG4.js +0 -126
  85. package/dist/chunk-B7YJYJKG.js +0 -33
  86. package/dist/chunk-CCLHCPKG.js +0 -210
  87. package/dist/chunk-CK36VROC.js +0 -1584
  88. package/dist/chunk-D3UOFRSB.js +0 -81
  89. package/dist/chunk-DFR4DJBM.js +0 -230
  90. package/dist/chunk-DSYBDHYH.js +0 -79
  91. package/dist/chunk-DWMLTXKQ.js +0 -1176
  92. package/dist/chunk-E3REJTAJ.js +0 -28
  93. package/dist/chunk-EA3IVO64.js +0 -633
  94. package/dist/chunk-EK2AKZKD.js +0 -55
  95. package/dist/chunk-ELD7JTTT.js +0 -343
  96. package/dist/chunk-EX6TT2XI.js +0 -195
  97. package/dist/chunk-EXINSFZE.js +0 -82
  98. package/dist/chunk-EZ6ZBYBM.js +0 -510
  99. package/dist/chunk-FBKAPTJ2.js +0 -16
  100. package/dist/chunk-FVLV5RYH.js +0 -1118
  101. package/dist/chunk-GDNSBQVK.js +0 -2485
  102. package/dist/chunk-GPQHMBNN.js +0 -278
  103. package/dist/chunk-GTFJB67L.js +0 -68
  104. package/dist/chunk-HANJXVKW.js +0 -1127
  105. package/dist/chunk-HEVS5YLD.js +0 -269
  106. package/dist/chunk-HMEVZKPQ.js +0 -9
  107. package/dist/chunk-HRGSYNLM.js +0 -3511
  108. package/dist/chunk-ISZR5N4K.js +0 -60
  109. package/dist/chunk-J6SUPR2C.js +0 -226
  110. package/dist/chunk-JERYVEIZ.js +0 -244
  111. package/dist/chunk-JHHWGL2N.js +0 -87
  112. package/dist/chunk-JONWQUB5.js +0 -775
  113. package/dist/chunk-K2DIWWDM.js +0 -1766
  114. package/dist/chunk-KY4PGL5V.js +0 -969
  115. package/dist/chunk-L737LQ4C.js +0 -1285
  116. package/dist/chunk-LFTWYIB2.js +0 -497
  117. package/dist/chunk-LV47RFNJ.js +0 -41
  118. package/dist/chunk-MKSAITI7.js +0 -15
  119. package/dist/chunk-MZ7RKIX4.js +0 -212
  120. package/dist/chunk-NAP6CFSO.js +0 -84
  121. package/dist/chunk-ND6MY37M.js +0 -16
  122. package/dist/chunk-NMG736UR.js +0 -683
  123. package/dist/chunk-NRAXROED.js +0 -32
  124. package/dist/chunk-NRIZR3A7.js +0 -690
  125. package/dist/chunk-NX43BG3M.js +0 -233
  126. package/dist/chunk-O645XLSI.js +0 -297
  127. package/dist/chunk-OMJD6A3S.js +0 -235
  128. package/dist/chunk-QB6SJD4T.js +0 -430
  129. package/dist/chunk-QFSTL4J3.js +0 -276
  130. package/dist/chunk-QLGDFMFX.js +0 -212
  131. package/dist/chunk-RIAAGL2E.js +0 -13
  132. package/dist/chunk-RWO5XMZ6.js +0 -86
  133. package/dist/chunk-RXRKBBSM.js +0 -149
  134. package/dist/chunk-RZOZMML6.js +0 -363
  135. package/dist/chunk-U7I7FS7T.js +0 -113
  136. package/dist/chunk-UI42RODY.js +0 -717
  137. package/dist/chunk-UTVMVSCO.js +0 -519
  138. package/dist/chunk-V6OJGLBA.js +0 -1746
  139. package/dist/chunk-W2JHVH7D.js +0 -152
  140. package/dist/chunk-WD3Y7VQN.js +0 -280
  141. package/dist/chunk-WOCTQ5MS.js +0 -303
  142. package/dist/chunk-WZR3ZUNN.js +0 -696
  143. package/dist/chunk-XGI665H7.js +0 -150
  144. package/dist/chunk-XKY65P2T.js +0 -304
  145. package/dist/chunk-Y4CQZY65.js +0 -57
  146. package/dist/chunk-YFEXKLVE.js +0 -194
  147. package/dist/chunk-YHO3HS5X.js +0 -287
  148. package/dist/chunk-YLS7AZSX.js +0 -738
  149. package/dist/chunk-ZE473AO6.js +0 -49
  150. package/dist/chunk-ZF747T3O.js +0 -644
  151. package/dist/chunk-ZHCZHZH3.js +0 -43
  152. package/dist/chunk-ZZNZX2XY.js +0 -87
  153. package/dist/constants-7QAP3VQ4.js +0 -23
  154. package/dist/dist-IY3UUMWK.js +0 -33
  155. package/dist/invariants-runner-W5RGHCSU.js +0 -27
  156. package/dist/lane-lock-6J36HD5O.js +0 -35
  157. package/dist/mem-checkpoint-core-EANG2GVN.js +0 -14
  158. package/dist/mem-signal-core-2LZ2WYHW.js +0 -19
  159. package/dist/memory-store-OLB5FO7K.js +0 -18
  160. package/dist/service-6BYCOCO5.js +0 -13
  161. package/dist/spawn-policy-resolver-NTSZYQ6R.js +0 -17
  162. package/dist/spawn-task-builder-R4E2BHSW.js +0 -22
  163. package/dist/wu-done-pr-WLFFFEPJ.js +0 -25
  164. package/dist/wu-done-validation-3J5E36FE.js +0 -30
  165. package/dist/wu-duplicate-id-detector-5S7JHELK.js +0 -232
  166. package/packs/sidekick/.turbo/turbo-typecheck.log +0 -4
  167. package/packs/software-delivery/.turbo/turbo-typecheck.log +0 -4
@@ -1,738 +0,0 @@
1
- // ../control-plane-sdk/dist/sync-port.js
2
- var CONTROL_PLANE_POLICY_MODES = {
3
- AUTHORITATIVE: "authoritative",
4
- TIGHTEN_ONLY: "tighten-only",
5
- DEV_OVERRIDE: "dev-override"
6
- };
7
- var CONTROL_PLANE_POLICY_MODE_VALUES = [
8
- CONTROL_PLANE_POLICY_MODES.AUTHORITATIVE,
9
- CONTROL_PLANE_POLICY_MODES.TIGHTEN_ONLY,
10
- CONTROL_PLANE_POLICY_MODES.DEV_OVERRIDE
11
- ];
12
- var DEFAULT_CONTROL_PLANE_AUTH_TOKEN_ENV = "LUMENFLOW_CONTROL_PLANE_TOKEN";
13
- var CONTROL_PLANE_AUTH_TOKEN_ENV_PATTERN = /^[A-Z][A-Z0-9_]*$/;
14
-
15
- // ../control-plane-sdk/dist/workspace-config.js
16
- var CONTROL_PLANE_POLICY_MODE_SET = new Set(CONTROL_PLANE_POLICY_MODE_VALUES);
17
- var CONTROL_PLANE_REQUIRED_FIELDS = [
18
- "endpoint",
19
- "org_id",
20
- "project_id",
21
- "sync_interval",
22
- "policy_mode"
23
- ];
24
- function isObject(input) {
25
- return typeof input === "object" && input !== null;
26
- }
27
- function asPositiveInt(value, field) {
28
- if (typeof value !== "number" || !Number.isInteger(value) || value <= 0) {
29
- throw new Error(`Invalid ${field}: expected a positive integer`);
30
- }
31
- return value;
32
- }
33
- function asNonEmptyString(value, field) {
34
- if (typeof value !== "string" || value.trim().length === 0) {
35
- throw new Error(`Invalid ${field}: expected a non-empty string`);
36
- }
37
- return value;
38
- }
39
- function asUrlString(value, field) {
40
- const parsed = asNonEmptyString(value, field);
41
- try {
42
- void new URL(parsed);
43
- } catch {
44
- throw new Error(`Invalid ${field}: expected a valid URL`);
45
- }
46
- return parsed;
47
- }
48
- function asPolicyMode(value) {
49
- if (typeof value === "string" && CONTROL_PLANE_POLICY_MODE_SET.has(value)) {
50
- return value;
51
- }
52
- throw new Error("Invalid control_plane.policy_mode");
53
- }
54
- function asEnvVarName(value, field) {
55
- const parsed = asNonEmptyString(value, field);
56
- if (!CONTROL_PLANE_AUTH_TOKEN_ENV_PATTERN.test(parsed)) {
57
- throw new Error(`Invalid ${field}: expected an uppercase env var name`);
58
- }
59
- return parsed;
60
- }
61
- function parseAuthConfig(input) {
62
- if (!isObject(input)) {
63
- throw new Error("Invalid control_plane.auth: expected an object");
64
- }
65
- return {
66
- token_env: asEnvVarName(input.token_env, "control_plane.auth.token_env")
67
- };
68
- }
69
- function parseControlPlaneConfig(input) {
70
- if (!isObject(input)) {
71
- throw new Error("Invalid control_plane config: expected an object");
72
- }
73
- for (const field of CONTROL_PLANE_REQUIRED_FIELDS) {
74
- if (!(field in input)) {
75
- throw new Error(`Invalid control_plane config: missing required field control_plane.${field}`);
76
- }
77
- }
78
- return {
79
- endpoint: asUrlString(input.endpoint, "control_plane.endpoint"),
80
- org_id: asNonEmptyString(input.org_id, "control_plane.org_id"),
81
- project_id: asNonEmptyString(input.project_id, "control_plane.project_id"),
82
- sync_interval: asPositiveInt(input.sync_interval, "control_plane.sync_interval"),
83
- policy_mode: asPolicyMode(input.policy_mode),
84
- auth: parseAuthConfig(input.auth)
85
- };
86
- }
87
- var ControlPlaneConfigSchema = {
88
- parse: parseControlPlaneConfig
89
- };
90
- var WorkspaceControlPlaneSchema = {
91
- parse(input) {
92
- if (!isObject(input)) {
93
- throw new Error("Invalid workspace config: expected an object");
94
- }
95
- const idRaw = input.id;
96
- const id = idRaw === void 0 ? void 0 : typeof idRaw === "string" && idRaw.trim().length > 0 ? idRaw : (() => {
97
- throw new Error("Invalid id: expected a non-empty string when provided");
98
- })();
99
- return {
100
- id,
101
- control_plane: parseControlPlaneConfig(input.control_plane)
102
- };
103
- }
104
- };
105
- function parseWorkspaceControlPlaneConfig(input) {
106
- return WorkspaceControlPlaneSchema.parse(input);
107
- }
108
-
109
- // ../control-plane-sdk/dist/policy-mode.js
110
- function clonePolicySet(input) {
111
- return {
112
- default_decision: input.default_decision,
113
- rules: input.rules.map((rule) => ({ ...rule }))
114
- };
115
- }
116
- function isLoosening(remoteDecision, localDecision) {
117
- return remoteDecision === "deny" && localDecision === "allow";
118
- }
119
- function createWarningEvent(message, timestamp) {
120
- return {
121
- schema_version: 1,
122
- kind: "workspace_warning",
123
- timestamp,
124
- message
125
- };
126
- }
127
- function applyPolicyMode(input) {
128
- const timestamp = input.timestamp ?? (/* @__PURE__ */ new Date()).toISOString();
129
- const remote = clonePolicySet(input.remote);
130
- const local = input.local;
131
- if (input.mode === "authoritative" || !local) {
132
- return {
133
- effective: remote,
134
- events: []
135
- };
136
- }
137
- const events = [];
138
- const localDefault = local.default_decision;
139
- if (isLoosening(remote.default_decision, localDefault)) {
140
- if (input.mode === "tighten-only") {
141
- throw new Error(`tighten-only mode rejected local policy loosening for default_decision in workspace ${input.workspace_id}`);
142
- }
143
- events.push(createWarningEvent(`dev-override allowed local policy loosening for default_decision in workspace ${input.workspace_id}`, timestamp));
144
- }
145
- const mergedRules = new Map(remote.rules.map((rule) => [rule.id, { ...rule }]));
146
- for (const localRule of local.rules) {
147
- const remoteRule = mergedRules.get(localRule.id);
148
- const remoteDecision = remoteRule?.decision ?? remote.default_decision;
149
- if (isLoosening(remoteDecision, localRule.decision)) {
150
- if (input.mode === "tighten-only") {
151
- throw new Error(`tighten-only mode rejected local policy loosening for rule ${localRule.id} in workspace ${input.workspace_id}`);
152
- }
153
- events.push(createWarningEvent(`dev-override allowed local policy loosening for rule ${localRule.id} in workspace ${input.workspace_id}`, timestamp));
154
- }
155
- mergedRules.set(localRule.id, { ...localRule });
156
- }
157
- return {
158
- effective: {
159
- default_decision: localDefault,
160
- rules: Array.from(mergedRules.values())
161
- },
162
- events
163
- };
164
- }
165
-
166
- // ../control-plane-sdk/dist/http/http-control-plane-sync-port.js
167
- var API_PATH = {
168
- AUTHENTICATE: "/api/v1/authenticate",
169
- HEARTBEAT: "/api/v1/heartbeat",
170
- APPROVAL_REQUEST: "/api/v1/approvals/request",
171
- APPROVAL_RESOLVE: "/api/v1/approvals/resolve",
172
- APPROVAL_LIST: "/api/v1/approvals/list",
173
- EVENTS: "/api/v1/events",
174
- EVIDENCE: "/api/v1/evidence",
175
- TELEMETRY: "/api/v1/telemetry",
176
- POLICIES: "/api/v1/policies",
177
- CONFIG: "/api/v1/config"
178
- };
179
- var HTTP = {
180
- METHOD_POST: "POST",
181
- HEADER_AUTHORIZATION: "authorization",
182
- HEADER_CONTENT_TYPE: "content-type",
183
- CONTENT_TYPE_JSON: "application/json"
184
- };
185
- var DEFAULT_TIMEOUT_MS = 1e4;
186
- var TIMEOUT_ERROR_PREFIX = "request timed out after";
187
- var ERROR_NAME = {
188
- ABORT: "AbortError"
189
- };
190
- function normalizeEndpoint(endpoint) {
191
- return endpoint.endsWith("/") ? endpoint.slice(0, endpoint.length - 1) : endpoint;
192
- }
193
- function asError(error) {
194
- if (error instanceof Error) {
195
- return error;
196
- }
197
- return new Error(String(error));
198
- }
199
- function describeError(error) {
200
- return asError(error).message;
201
- }
202
- function asFiniteNumber(value) {
203
- return typeof value === "number" && Number.isFinite(value) ? value : void 0;
204
- }
205
- function asNonEmptyString2(value) {
206
- return typeof value === "string" && value.trim().length > 0 ? value.trim() : void 0;
207
- }
208
- function cloneControlPlaneConfig(config) {
209
- return {
210
- ...config,
211
- auth: {
212
- ...config.auth
213
- }
214
- };
215
- }
216
- async function safeResponseText(response) {
217
- try {
218
- return await response.text();
219
- } catch {
220
- return "";
221
- }
222
- }
223
- var HttpControlPlaneSyncPort = class {
224
- config;
225
- endpoint;
226
- token;
227
- timeoutMs;
228
- fetchFn;
229
- logger;
230
- constructor(config, options = {}) {
231
- this.config = cloneControlPlaneConfig(config);
232
- this.endpoint = normalizeEndpoint(config.endpoint);
233
- this.fetchFn = options.fetchFn ?? fetch;
234
- this.logger = options.logger;
235
- this.timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
236
- const environment = options.environment ?? process.env;
237
- const rawToken = environment[config.auth.token_env];
238
- this.token = typeof rawToken === "string" ? rawToken.trim() : "";
239
- if (this.token.length === 0) {
240
- this.warn(`Missing auth token in env "${config.auth.token_env}". Requests may fail.`);
241
- }
242
- }
243
- async pullPolicies(input) {
244
- try {
245
- return await this.postJson(API_PATH.POLICIES, input);
246
- } catch (error) {
247
- this.warnFailure("pullPolicies", error);
248
- throw error;
249
- }
250
- }
251
- async pullConfig(input) {
252
- try {
253
- return await this.postJson(API_PATH.CONFIG, input);
254
- } catch (error) {
255
- this.warnFailure("pullConfig", error);
256
- return {
257
- id: input.workspace_id,
258
- control_plane: cloneControlPlaneConfig(this.config)
259
- };
260
- }
261
- }
262
- async pushTelemetry(input) {
263
- try {
264
- return await this.postJson(API_PATH.TELEMETRY, input);
265
- } catch (error) {
266
- this.warnFailure("pushTelemetry", error);
267
- return { accepted: 0 };
268
- }
269
- }
270
- async pushEvidence(input) {
271
- try {
272
- return await this.postJson(API_PATH.EVIDENCE, input);
273
- } catch (error) {
274
- this.warnFailure("pushEvidence", error);
275
- return { accepted: 0 };
276
- }
277
- }
278
- async pushKernelEvents(input) {
279
- try {
280
- return await this.postJson(API_PATH.EVENTS, input);
281
- } catch (error) {
282
- this.warnFailure("pushKernelEvents", error);
283
- throw error;
284
- }
285
- }
286
- async authenticate(input) {
287
- try {
288
- return await this.postJson(API_PATH.AUTHENTICATE, input);
289
- } catch (error) {
290
- this.warnFailure("authenticate", error);
291
- return {
292
- workspace_id: input.workspace_id,
293
- org_id: input.org_id,
294
- agent_id: input.agent_id,
295
- token: ""
296
- };
297
- }
298
- }
299
- async heartbeat(input) {
300
- try {
301
- const response = await this.postJson(API_PATH.HEARTBEAT, input);
302
- const normalized = {
303
- status: response.status ?? "ok",
304
- server_time: asNonEmptyString2(response.server_time) ?? (/* @__PURE__ */ new Date()).toISOString()
305
- };
306
- const nextHeartbeatMs = asFiniteNumber(response.next_heartbeat_ms);
307
- if (nextHeartbeatMs !== void 0) {
308
- normalized.next_heartbeat_ms = nextHeartbeatMs;
309
- }
310
- if (response.assignment) {
311
- normalized.assignment = response.assignment;
312
- }
313
- const budgetRemainingUsd = asFiniteNumber(response.budget_remaining_usd);
314
- if (budgetRemainingUsd !== void 0) {
315
- normalized.budget_remaining_usd = budgetRemainingUsd;
316
- }
317
- const coalescedSignals = asFiniteNumber(response.coalesced_signals);
318
- if (coalescedSignals !== void 0) {
319
- normalized.coalesced_signals = coalescedSignals;
320
- }
321
- return normalized;
322
- } catch (error) {
323
- this.warnFailure("heartbeat", error);
324
- throw error;
325
- }
326
- }
327
- async requestApproval(input) {
328
- try {
329
- return await this.postJson(API_PATH.APPROVAL_REQUEST, input);
330
- } catch (error) {
331
- this.warnFailure("requestApproval", error);
332
- throw error;
333
- }
334
- }
335
- async resolveApproval(input) {
336
- try {
337
- return await this.postJson(API_PATH.APPROVAL_RESOLVE, input);
338
- } catch (error) {
339
- this.warnFailure("resolveApproval", error);
340
- throw error;
341
- }
342
- }
343
- async listApprovals(input) {
344
- try {
345
- return await this.postJson(API_PATH.APPROVAL_LIST, input);
346
- } catch (error) {
347
- this.warnFailure("listApprovals", error);
348
- throw error;
349
- }
350
- }
351
- warn(message) {
352
- this.logger?.warn?.(`[control-plane] ${message}`);
353
- }
354
- warnFailure(operation, error) {
355
- this.warn(`${operation} failed: ${describeError(error)}`);
356
- }
357
- getHeaders() {
358
- return {
359
- [HTTP.HEADER_AUTHORIZATION]: `Bearer ${this.token}`,
360
- [HTTP.HEADER_CONTENT_TYPE]: HTTP.CONTENT_TYPE_JSON
361
- };
362
- }
363
- async postJson(apiPath, payload) {
364
- const controller = new AbortController();
365
- const timeout = setTimeout(() => controller.abort(), this.timeoutMs);
366
- try {
367
- const response = await this.fetchFn(`${this.endpoint}${apiPath}`, {
368
- method: HTTP.METHOD_POST,
369
- headers: this.getHeaders(),
370
- body: JSON.stringify(payload),
371
- signal: controller.signal
372
- });
373
- if (!response.ok) {
374
- const responseText = await safeResponseText(response);
375
- const suffix = responseText.length > 0 ? `: ${responseText}` : "";
376
- throw new Error(`HTTP ${response.status}${suffix}`);
377
- }
378
- return await response.json();
379
- } catch (error) {
380
- const parsedError = asError(error);
381
- if (parsedError.name === ERROR_NAME.ABORT) {
382
- throw new Error(`${TIMEOUT_ERROR_PREFIX} ${this.timeoutMs}ms`, { cause: error });
383
- }
384
- throw parsedError;
385
- } finally {
386
- clearTimeout(timeout);
387
- }
388
- }
389
- };
390
- function createHttpControlPlaneSyncPort(config, logger, options = {}) {
391
- return new HttpControlPlaneSyncPort(config, {
392
- ...options,
393
- logger: options.logger ?? logger
394
- });
395
- }
396
-
397
- // ../control-plane-sdk/dist/mock/mock-control-plane-sync-port.js
398
- var DEFAULT_REMOTE_POLICIES = {
399
- default_decision: "deny",
400
- rules: []
401
- };
402
- var DEFAULT_LOCAL_POLICIES = {
403
- default_decision: "deny",
404
- rules: []
405
- };
406
- var DEFAULT_SYNC_INTERVAL_SECONDS = 30;
407
- var DEFAULT_LOCAL_OVERRIDE = false;
408
- var MockControlPlaneSyncPort = class {
409
- options;
410
- telemetryByEndpoint = /* @__PURE__ */ new Map();
411
- evidenceByWorkspace = /* @__PURE__ */ new Map();
412
- kernelEventsByWorkspace = /* @__PURE__ */ new Map();
413
- constructor(options) {
414
- this.options = {
415
- ...options,
416
- local_override: options.local_override ?? DEFAULT_LOCAL_OVERRIDE,
417
- auth_token_env: options.auth_token_env ?? DEFAULT_CONTROL_PLANE_AUTH_TOKEN_ENV,
418
- remote_policies: options.remote_policies ?? DEFAULT_REMOTE_POLICIES,
419
- local_policies: options.local_policies ?? DEFAULT_LOCAL_POLICIES
420
- };
421
- }
422
- async pullPolicies(input) {
423
- const merged = applyPolicyMode({
424
- mode: this.options.policy_mode,
425
- workspace_id: input.workspace_id,
426
- remote: this.options.remote_policies ?? DEFAULT_REMOTE_POLICIES,
427
- local: this.options.local_override ? this.options.local_policies : void 0
428
- });
429
- if (merged.events.length > 0) {
430
- const events = this.kernelEventsByWorkspace.get(input.workspace_id) ?? [];
431
- this.kernelEventsByWorkspace.set(input.workspace_id, events.concat(merged.events));
432
- }
433
- return merged.effective;
434
- }
435
- async pullConfig(input) {
436
- return {
437
- id: input.workspace_id,
438
- control_plane: {
439
- endpoint: this.options.endpoint,
440
- org_id: this.options.org_id,
441
- project_id: this.options.project_id,
442
- sync_interval: DEFAULT_SYNC_INTERVAL_SECONDS,
443
- policy_mode: this.options.policy_mode,
444
- auth: {
445
- token_env: this.options.auth_token_env ?? DEFAULT_CONTROL_PLANE_AUTH_TOKEN_ENV
446
- }
447
- }
448
- };
449
- }
450
- async pushTelemetry(input) {
451
- const entries = this.telemetryByEndpoint.get(this.options.endpoint) ?? [];
452
- this.telemetryByEndpoint.set(this.options.endpoint, entries.concat(input.records));
453
- return { accepted: input.records.length };
454
- }
455
- async pushEvidence(input) {
456
- const entries = this.evidenceByWorkspace.get(input.workspace_id) ?? [];
457
- this.evidenceByWorkspace.set(input.workspace_id, entries.concat(input.evidence_refs));
458
- return { accepted: input.evidence_refs.length };
459
- }
460
- async pushKernelEvents(input) {
461
- const entries = this.kernelEventsByWorkspace.get(input.workspace_id) ?? [];
462
- this.kernelEventsByWorkspace.set(input.workspace_id, entries.concat(input.events));
463
- return { accepted: input.events.length };
464
- }
465
- async authenticate(input) {
466
- return {
467
- workspace_id: input.workspace_id,
468
- org_id: input.org_id,
469
- agent_id: input.agent_id,
470
- token: `mock-token:${input.workspace_id}:${input.agent_id}`
471
- };
472
- }
473
- async heartbeat(input) {
474
- let assignment;
475
- if (input.health?.stalled && input.wu_id) {
476
- assignment = {
477
- wu_id: input.wu_id,
478
- action: "abort",
479
- hint: "agent reported stalled heartbeat"
480
- };
481
- } else if (input.health?.busy === false && !input.wu_id) {
482
- assignment = {
483
- wu_id: "mock-wu-assignment",
484
- action: "claim",
485
- hint: "mock assignment for idle agent"
486
- };
487
- }
488
- return {
489
- status: "ok",
490
- server_time: (/* @__PURE__ */ new Date()).toISOString(),
491
- next_heartbeat_ms: DEFAULT_SYNC_INTERVAL_SECONDS * 1e3,
492
- ...assignment ? { assignment } : {},
493
- coalesced_signals: 0
494
- };
495
- }
496
- readTelemetryEndpoint(endpoint) {
497
- return (this.telemetryByEndpoint.get(endpoint) ?? []).map((record) => ({ ...record }));
498
- }
499
- readEvidence(workspaceId) {
500
- return [...this.evidenceByWorkspace.get(workspaceId) ?? []];
501
- }
502
- readKernelEvents(workspaceId) {
503
- return [...this.kernelEventsByWorkspace.get(workspaceId) ?? []];
504
- }
505
- };
506
- function createMockControlPlaneSyncPort(options) {
507
- return new MockControlPlaneSyncPort(options);
508
- }
509
-
510
- // ../control-plane-sdk/dist/mock/mock-signal-sync-port.js
511
- var DEFAULT_PAGE_LIMIT = 50;
512
- var CURSOR_BASE = 10;
513
- function memoryKey(record) {
514
- return `${record.namespace}:${record.key}`;
515
- }
516
- function cloneSignal(signal) {
517
- return {
518
- ...signal,
519
- payload: { ...signal.payload }
520
- };
521
- }
522
- function cloneMemoryRecord(record) {
523
- return {
524
- ...record,
525
- value: record.value
526
- };
527
- }
528
- function parseCursor(cursor) {
529
- if (!cursor) {
530
- return 0;
531
- }
532
- const parsed = Number.parseInt(cursor, CURSOR_BASE);
533
- if (!Number.isFinite(parsed) || parsed < 0) {
534
- return 0;
535
- }
536
- return parsed;
537
- }
538
- function sortMemoryRecords(records) {
539
- return [...records].sort((a, b) => {
540
- if (a.updated_at === b.updated_at) {
541
- return memoryKey(a).localeCompare(memoryKey(b));
542
- }
543
- return a.updated_at.localeCompare(b.updated_at);
544
- });
545
- }
546
- function isStringArray(value) {
547
- return Array.isArray(value) && value.every((entry) => typeof entry === "string");
548
- }
549
- function normalizeSessionMetadata(input) {
550
- const metadata = {
551
- ...input.metadata ?? {}
552
- };
553
- if (typeof input.client_type === "string") {
554
- metadata.client_type = input.client_type;
555
- }
556
- if (Array.isArray(input.capabilities)) {
557
- metadata.capabilities = [...input.capabilities];
558
- }
559
- if (typeof input.agent_version === "string") {
560
- metadata.agent_version = input.agent_version;
561
- }
562
- if (typeof input.host_id === "string") {
563
- metadata.host_id = input.host_id;
564
- }
565
- const clientType = typeof metadata.client_type === "string" && metadata.client_type.length > 0 ? metadata.client_type : void 0;
566
- const capabilities = isStringArray(metadata.capabilities) ? [...metadata.capabilities] : void 0;
567
- const agentVersion = typeof metadata.agent_version === "string" && metadata.agent_version.length > 0 ? metadata.agent_version : void 0;
568
- const hostId = typeof metadata.host_id === "string" && metadata.host_id.length > 0 ? metadata.host_id : void 0;
569
- if (clientType) {
570
- metadata.client_type = clientType;
571
- }
572
- if (capabilities) {
573
- metadata.capabilities = capabilities;
574
- }
575
- if (agentVersion) {
576
- metadata.agent_version = agentVersion;
577
- }
578
- if (hostId) {
579
- metadata.host_id = hostId;
580
- }
581
- return {
582
- client_type: clientType,
583
- capabilities,
584
- agent_version: agentVersion,
585
- host_id: hostId,
586
- metadata: Object.keys(metadata).length > 0 ? metadata : void 0
587
- };
588
- }
589
- var MockSignalSyncPort = class {
590
- conflictKeys;
591
- now;
592
- signalsByWorkspace = /* @__PURE__ */ new Map();
593
- sessionsByWorkspace = /* @__PURE__ */ new Map();
594
- memoryByWorkspace = /* @__PURE__ */ new Map();
595
- constructor(options = {}) {
596
- this.conflictKeys = new Set(options.conflict_keys ?? []);
597
- this.now = options.now ?? (() => (/* @__PURE__ */ new Date()).toISOString());
598
- }
599
- async pushSignals(input) {
600
- const existing = this.signalsByWorkspace.get(input.workspace_id) ?? [];
601
- const next = existing.concat(input.signals.map((signal) => cloneSignal({
602
- ...signal,
603
- origin: signal.origin ?? "local"
604
- })));
605
- this.signalsByWorkspace.set(input.workspace_id, next);
606
- return { accepted: input.signals.length };
607
- }
608
- async pullSignals(input) {
609
- const existing = this.signalsByWorkspace.get(input.workspace_id) ?? [];
610
- const start = parseCursor(input.cursor);
611
- const limit = input.limit ?? DEFAULT_PAGE_LIMIT;
612
- const slice = existing.slice(start, start + limit).map(cloneSignal);
613
- const nextIndex = start + slice.length;
614
- return {
615
- signals: slice,
616
- next_cursor: nextIndex < existing.length ? String(nextIndex) : void 0
617
- };
618
- }
619
- async registerSession(input) {
620
- const workspaceSessions = this.sessionsByWorkspace.get(input.workspace_id) ?? /* @__PURE__ */ new Map();
621
- const normalizedMetadata = normalizeSessionMetadata(input);
622
- const session = {
623
- workspace_id: input.workspace_id,
624
- session_id: input.session_id,
625
- agent_id: input.agent_id,
626
- started_at: input.started_at,
627
- lane: input.lane,
628
- wu_id: input.wu_id,
629
- client_type: normalizedMetadata.client_type,
630
- capabilities: normalizedMetadata.capabilities,
631
- agent_version: normalizedMetadata.agent_version,
632
- host_id: normalizedMetadata.host_id,
633
- metadata: normalizedMetadata.metadata,
634
- active: true,
635
- last_heartbeat_at: this.now()
636
- };
637
- workspaceSessions.set(input.session_id, session);
638
- this.sessionsByWorkspace.set(input.workspace_id, workspaceSessions);
639
- return { ...session };
640
- }
641
- async deregisterSession(input) {
642
- const workspaceSessions = this.sessionsByWorkspace.get(input.workspace_id);
643
- if (!workspaceSessions) {
644
- return { accepted: 0 };
645
- }
646
- const session = workspaceSessions.get(input.session_id);
647
- if (!session) {
648
- return { accepted: 0 };
649
- }
650
- workspaceSessions.set(input.session_id, {
651
- ...session,
652
- active: false,
653
- last_heartbeat_at: input.ended_at ?? this.now()
654
- });
655
- return { accepted: 1 };
656
- }
657
- async listSessions(input) {
658
- const workspaceSessions = this.sessionsByWorkspace.get(input.workspace_id);
659
- if (!workspaceSessions) {
660
- return { sessions: [] };
661
- }
662
- const includeInactive = input.include_inactive ?? false;
663
- const sessions = Array.from(workspaceSessions.values()).filter((session) => includeInactive ? true : session.active).filter((session) => input.lane ? session.lane === input.lane : true).map((session) => ({ ...session }));
664
- return { sessions };
665
- }
666
- async syncMemory(input) {
667
- const workspaceMemory = this.memoryByWorkspace.get(input.workspace_id) ?? /* @__PURE__ */ new Map();
668
- const conflicts = [];
669
- let pushed = 0;
670
- if (input.direction === "push" || input.direction === "bidirectional") {
671
- for (const localRecord of input.local_records) {
672
- const key = memoryKey(localRecord);
673
- const existing = workspaceMemory.get(key);
674
- const hasRevisionConflict = Boolean(existing?.revision) && Boolean(localRecord.revision) && existing?.revision !== localRecord.revision;
675
- const forcedConflict = this.conflictKeys.has(key) && Boolean(existing);
676
- if (hasRevisionConflict || forcedConflict) {
677
- conflicts.push({
678
- namespace: localRecord.namespace,
679
- key: localRecord.key,
680
- local_revision: localRecord.revision,
681
- remote_revision: existing?.revision,
682
- resolution: "manual"
683
- });
684
- continue;
685
- }
686
- workspaceMemory.set(key, cloneMemoryRecord({
687
- ...localRecord,
688
- origin: localRecord.origin ?? "local"
689
- }));
690
- pushed += 1;
691
- }
692
- }
693
- this.memoryByWorkspace.set(input.workspace_id, workspaceMemory);
694
- const allRemoteRecords = sortMemoryRecords(Array.from(workspaceMemory.values()).map(cloneMemoryRecord));
695
- const start = parseCursor(input.cursor);
696
- const limit = input.limit ?? DEFAULT_PAGE_LIMIT;
697
- const remoteRecords = input.direction === "pull" || input.direction === "bidirectional" ? allRemoteRecords.slice(start, start + limit) : [];
698
- const nextIndex = start + remoteRecords.length;
699
- return {
700
- pushed,
701
- pulled: remoteRecords.length,
702
- conflicts,
703
- remote_records: remoteRecords,
704
- next_cursor: (input.direction === "pull" || input.direction === "bidirectional") && nextIndex < allRemoteRecords.length ? String(nextIndex) : void 0
705
- };
706
- }
707
- readSignals(workspaceId) {
708
- return (this.signalsByWorkspace.get(workspaceId) ?? []).map(cloneSignal);
709
- }
710
- readSessions(workspaceId) {
711
- return Array.from(this.sessionsByWorkspace.get(workspaceId)?.values() ?? []).map((session) => ({
712
- ...session
713
- }));
714
- }
715
- readMemory(workspaceId) {
716
- return Array.from(this.memoryByWorkspace.get(workspaceId)?.values() ?? []).map(cloneMemoryRecord);
717
- }
718
- };
719
- function createMockSignalSyncPort(options = {}) {
720
- return new MockSignalSyncPort(options);
721
- }
722
-
723
- export {
724
- CONTROL_PLANE_POLICY_MODES,
725
- CONTROL_PLANE_POLICY_MODE_VALUES,
726
- DEFAULT_CONTROL_PLANE_AUTH_TOKEN_ENV,
727
- CONTROL_PLANE_AUTH_TOKEN_ENV_PATTERN,
728
- ControlPlaneConfigSchema,
729
- WorkspaceControlPlaneSchema,
730
- parseWorkspaceControlPlaneConfig,
731
- applyPolicyMode,
732
- HttpControlPlaneSyncPort,
733
- createHttpControlPlaneSyncPort,
734
- MockControlPlaneSyncPort,
735
- createMockControlPlaneSyncPort,
736
- MockSignalSyncPort,
737
- createMockSignalSyncPort
738
- };