@cleocode/runtime 2026.10.4 → 2026.10.5-rc.ci.672

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 (36) hide show
  1. package/dist/{chunk-L5BLVQDA.js → chunk-4PUSKGDO.js} +2 -2
  2. package/dist/chunk-4PUSKGDO.js.map +1 -0
  3. package/dist/{chunk-KQBVXGOL.js → chunk-GULKX44R.js} +5 -3
  4. package/dist/chunk-GULKX44R.js.map +1 -0
  5. package/dist/{chunk-7Q7BEWM7.js → chunk-HXTRXEFI.js} +7 -9
  6. package/dist/chunk-HXTRXEFI.js.map +1 -0
  7. package/dist/{chunk-U2ESNIJ5.js → chunk-NOPLC5WS.js} +4 -2
  8. package/dist/chunk-NOPLC5WS.js.map +1 -0
  9. package/dist/chunk-PDZ5T4LO.js +597 -0
  10. package/dist/chunk-PDZ5T4LO.js.map +1 -0
  11. package/dist/{chunk-XJOMQIXL.js → chunk-WO6LJMDC.js} +4 -2
  12. package/dist/chunk-WO6LJMDC.js.map +1 -0
  13. package/dist/daemon/index.js +1 -1
  14. package/dist/dispatch-BWjVeeMg.d.ts +290 -0
  15. package/dist/gateway/dispatch.d.ts +5 -0
  16. package/dist/gateway/dispatch.js +53 -0
  17. package/dist/gateway/dispatch.js.map +1 -0
  18. package/dist/gateway/http/index.d.ts +897 -11
  19. package/dist/gateway/http/index.js +2 -2
  20. package/dist/gateway/index.d.ts +549 -4
  21. package/dist/gateway/index.js +26 -581
  22. package/dist/gateway/index.js.map +1 -1
  23. package/dist/gateway/mcp/index.d.ts +232 -10
  24. package/dist/gateway/mcp/index.js +2 -2
  25. package/dist/gateway/rpc/index.d.ts +5 -2036
  26. package/dist/gateway/rpc/index.js +1 -1
  27. package/dist/gateway-handler-DCU6E0a2.d.ts +80 -0
  28. package/dist/index.d.ts +4 -3
  29. package/dist/index.js +9 -6
  30. package/dist/index.js.map +1 -1
  31. package/package.json +7 -3
  32. package/dist/chunk-7Q7BEWM7.js.map +0 -1
  33. package/dist/chunk-KQBVXGOL.js.map +0 -1
  34. package/dist/chunk-L5BLVQDA.js.map +0 -1
  35. package/dist/chunk-U2ESNIJ5.js.map +0 -1
  36. package/dist/chunk-XJOMQIXL.js.map +0 -1
@@ -1,6 +1,25 @@
1
1
  import {
2
2
  defineSubsystem
3
- } from "../chunk-7Q7BEWM7.js";
3
+ } from "../chunk-HXTRXEFI.js";
4
+ import {
5
+ BRAIN_DB_FILENAME,
6
+ CLEO_DIR_NAME,
7
+ Dispatcher,
8
+ STRING_TO_EXIT,
9
+ WORKFLOWS_SUBDIR,
10
+ buildNexusMetaExtensions,
11
+ cleoErrorToEngineError,
12
+ compose,
13
+ createDispatchMeta,
14
+ createGatewayHandler,
15
+ engineError,
16
+ engineSuccess,
17
+ formatSuggestedNext,
18
+ mapNumericExitCodeToString,
19
+ pickDecoratorMetaExtensions,
20
+ stampNexusMeta,
21
+ validateSuggestedNext
22
+ } from "../chunk-PDZ5T4LO.js";
4
23
  import {
5
24
  MCP_TOOL_PREFIX,
6
25
  buildToolsList,
@@ -10,7 +29,7 @@ import {
10
29
  operationToToolName,
11
30
  startMcpServer,
12
31
  toolNameToOperationKey
13
- } from "../chunk-XJOMQIXL.js";
32
+ } from "../chunk-WO6LJMDC.js";
14
33
  import {
15
34
  LineBuffer,
16
35
  buildErrorFrame,
@@ -18,7 +37,7 @@ import {
18
37
  encodeFrame,
19
38
  routeFrame,
20
39
  startRpcServer
21
- } from "../chunk-KQBVXGOL.js";
40
+ } from "../chunk-GULKX44R.js";
22
41
  import {
23
42
  SSE_HEADERS,
24
43
  STUDIO_PREFIX,
@@ -38,7 +57,7 @@ import {
38
57
  statusForResponse,
39
58
  tickStreamSource,
40
59
  writeBundleAbsentError
41
- } from "../chunk-U2ESNIJ5.js";
60
+ } from "../chunk-NOPLC5WS.js";
42
61
  import {
43
62
  OPERATIONS,
44
63
  deriveGatewayMatrix,
@@ -52,219 +71,7 @@ import {
52
71
  resolve,
53
72
  resolveStreamRoute,
54
73
  validateRequiredParams
55
- } from "../chunk-L5BLVQDA.js";
56
-
57
- // src/gateway/dispatcher.ts
58
- import { randomUUID as randomUUID2 } from "crypto";
59
- import { getLogger, getProjectRoot } from "@cleocode/core";
60
- import { registerTeardownAbort } from "@cleocode/core/teardown-signal";
61
-
62
- // src/gateway/meta.ts
63
- import { randomUUID } from "crypto";
64
- function createDispatchMeta(gateway, domain, operation, startTime, source = "cli", requestId, sessionId, originSessionId, executionSessionId) {
65
- return {
66
- gateway,
67
- domain,
68
- operation,
69
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
70
- duration_ms: Date.now() - startTime,
71
- source,
72
- requestId: requestId ?? randomUUID(),
73
- ...sessionId != null && { sessionId },
74
- ...originSessionId != null && { originSessionId },
75
- ...executionSessionId != null && { executionSessionId }
76
- };
77
- }
78
-
79
- // src/gateway/pipeline.ts
80
- function compose(middlewares) {
81
- if (middlewares.length === 0) {
82
- return async (_req, next) => next();
83
- }
84
- return async (request, next) => {
85
- let index = -1;
86
- async function dispatch(i) {
87
- if (i <= index) {
88
- throw new Error("next() called multiple times in middleware");
89
- }
90
- index = i;
91
- let fn = middlewares[i];
92
- if (i === middlewares.length) {
93
- fn = async (_req, nxt) => nxt();
94
- }
95
- if (!fn) {
96
- return next();
97
- }
98
- return fn(request, async () => {
99
- if (i === middlewares.length) {
100
- return next();
101
- }
102
- return dispatch(i + 1);
103
- });
104
- }
105
- return dispatch(0);
106
- };
107
- }
108
-
109
- // src/gateway/dispatcher.ts
110
- var DIALECTIC_RATE_LIMIT_MS = 1e4;
111
- var DIALECTIC_DEADLINE_MS = 1e4;
112
- var _dialecticLastEvalMs = /* @__PURE__ */ new Map();
113
- function ensureRequestSessionLineage(request) {
114
- request.executionSessionId ??= process.env.CLEO_EXECUTION_SESSION_ID ?? process.env.CLEO_SESSION_EXECUTION_ID ?? randomUUID2();
115
- request.originSessionId ??= process.env.CLEO_ORIGIN_SESSION_ID ?? process.env.CLEO_SESSION_ORIGIN_ID ?? request.sessionId ?? request.executionSessionId;
116
- }
117
- function isDialecticEvalAllowed(sessionId) {
118
- const last = _dialecticLastEvalMs.get(sessionId) ?? 0;
119
- const now = Date.now();
120
- if (now - last < DIALECTIC_RATE_LIMIT_MS) {
121
- return false;
122
- }
123
- _dialecticLastEvalMs.set(sessionId, now);
124
- return true;
125
- }
126
- var Dispatcher = class {
127
- handlers;
128
- pipeline;
129
- constructor(config) {
130
- this.handlers = config.handlers;
131
- this.pipeline = config.middlewares?.length ? compose(config.middlewares) : (_req, next) => next();
132
- }
133
- async dispatch(request) {
134
- const startTime = Date.now();
135
- ensureRequestSessionLineage(request);
136
- const resolved = resolve(request.gateway, request.domain, request.operation);
137
- if (!resolved) {
138
- return {
139
- meta: createDispatchMeta(
140
- request.gateway,
141
- request.domain,
142
- request.operation,
143
- startTime,
144
- request.source,
145
- request.requestId,
146
- request.sessionId,
147
- request.originSessionId,
148
- request.executionSessionId
149
- ),
150
- success: false,
151
- error: {
152
- code: "E_INVALID_OPERATION",
153
- message: `Unknown operation: ${request.gateway}:${request.domain}.${request.operation}`
154
- }
155
- };
156
- }
157
- const missing = validateRequiredParams(resolved.def, request.params);
158
- if (missing.length > 0) {
159
- return {
160
- meta: createDispatchMeta(
161
- request.gateway,
162
- resolved.domain,
163
- resolved.operation,
164
- startTime,
165
- request.source,
166
- request.requestId,
167
- request.sessionId,
168
- request.originSessionId,
169
- request.executionSessionId
170
- ),
171
- success: false,
172
- error: {
173
- code: "E_MISSING_PARAMS",
174
- message: `Missing required parameters: ${missing.join(", ")}`,
175
- details: { missing }
176
- }
177
- };
178
- }
179
- const handler = this.handlers.get(resolved.domain);
180
- if (!handler) {
181
- return {
182
- meta: createDispatchMeta(
183
- request.gateway,
184
- resolved.domain,
185
- resolved.operation,
186
- startTime,
187
- request.source,
188
- request.requestId,
189
- request.sessionId,
190
- request.originSessionId,
191
- request.executionSessionId
192
- ),
193
- success: false,
194
- error: {
195
- code: "E_NO_HANDLER",
196
- message: `No handler for domain: ${resolved.domain}`
197
- }
198
- };
199
- }
200
- const terminal = async () => {
201
- if (request.gateway === "query") {
202
- return handler.query(resolved.operation, request.params);
203
- } else {
204
- return handler.mutate(resolved.operation, request.params);
205
- }
206
- };
207
- const response = await this.pipeline(request, terminal);
208
- response.meta.duration_ms = Date.now() - startTime;
209
- response.meta.requestId = request.requestId;
210
- response.meta.source = request.source;
211
- if (request.sessionId) {
212
- response.meta.sessionId = request.sessionId;
213
- }
214
- if (request.originSessionId) {
215
- response.meta.originSessionId = request.originSessionId;
216
- }
217
- if (request.executionSessionId) {
218
- response.meta.executionSessionId = request.executionSessionId;
219
- }
220
- if (response.success && request.gateway === "mutate" && request.sessionId && isDialecticEvalAllowed(request.sessionId)) {
221
- const capturedRequest = request;
222
- const capturedSessionId = request.sessionId;
223
- setImmediate(() => {
224
- const controller = new AbortController();
225
- const deadline = setTimeout(
226
- () => controller.abort(new DOMException("DIALECTIC_DEADLINE", "AbortError")),
227
- DIALECTIC_DEADLINE_MS
228
- );
229
- deadline.unref();
230
- const unregisterAbort = registerTeardownAbort(controller);
231
- Promise.all([
232
- import("@cleocode/core/memory/dialectic-evaluator.js"),
233
- import("@cleocode/core/store/nexus-sqlite.js"),
234
- import("@cleocode/core/store/memory-sqlite.js")
235
- ]).then(async ([{ evaluateDialectic, applyInsights }, { getNexusDb }, { getBrainDb }]) => {
236
- const projectRoot = getProjectRoot();
237
- const turn = {
238
- userMessage: `cleo ${capturedRequest.domain} ${capturedRequest.operation} ${JSON.stringify(capturedRequest.params ?? {})}`,
239
- systemResponse: `Operation succeeded in domain "${capturedRequest.domain}".`,
240
- activePeerId: capturedRequest.params?.["peerId"] ?? "global",
241
- sessionId: capturedSessionId,
242
- // T12543: this turn is an operation and its result envelope,
243
- // not a user utterance — the evaluator must never mint user
244
- // traits from it.
245
- origin: "operation-envelope"
246
- };
247
- const insights = await evaluateDialectic(turn, {
248
- abortSignal: controller.signal
249
- });
250
- const [nexusDb, brainDb] = await Promise.all([getNexusDb(), getBrainDb()]);
251
- await applyInsights(insights, nexusDb, brainDb, {
252
- sessionId: capturedSessionId,
253
- activePeerId: turn.activePeerId,
254
- projectRoot
255
- });
256
- }).catch((err) => {
257
- const log = getLogger("dialectic-hook");
258
- log.warn({ err }, "dialectic-evaluator failed");
259
- }).finally(() => {
260
- clearTimeout(deadline);
261
- unregisterAbort();
262
- });
263
- });
264
- }
265
- return response;
266
- }
267
- };
74
+ } from "../chunk-4PUSKGDO.js";
268
75
 
269
76
  // src/gateway/background-jobs.ts
270
77
  import {
@@ -273,7 +80,7 @@ import {
273
80
  } from "@cleocode/core/store/background-jobs.js";
274
81
 
275
82
  // src/gateway/daemon-subsystem.ts
276
- import { getLogger as getLogger2 } from "@cleocode/core";
83
+ import { getLogger } from "@cleocode/core";
277
84
  function gatewaySubsystemName(scope) {
278
85
  return `gateway-${scope}`;
279
86
  }
@@ -284,7 +91,7 @@ function defineGatewaySubsystem(opts) {
284
91
  );
285
92
  }
286
93
  const name = gatewaySubsystemName(opts.scope);
287
- const log = getLogger2(name);
94
+ const log = getLogger(name);
288
95
  let live;
289
96
  return defineSubsystem({
290
97
  name,
@@ -620,242 +427,6 @@ function validateLabels(labels, repoLabels) {
620
427
  return adaptResult(templates.validateLabels(labels, repoLabels));
621
428
  }
622
429
 
623
- // src/gateway/engine-error.ts
624
- import {
625
- engineError as coreEngineError,
626
- getLogger as getLogger3
627
- } from "@cleocode/core";
628
-
629
- // src/gateway/exit-codes.ts
630
- var _inverseCache = null;
631
- function getInverseMap() {
632
- if (_inverseCache) return _inverseCache;
633
- const map = /* @__PURE__ */ new Map();
634
- for (const [key, value] of Object.entries(STRING_TO_EXIT)) {
635
- if (!map.has(value)) {
636
- map.set(value, key);
637
- }
638
- }
639
- _inverseCache = map;
640
- return map;
641
- }
642
- function mapNumericExitCodeToString(numericCode) {
643
- if (numericCode === void 0) return void 0;
644
- return getInverseMap().get(numericCode);
645
- }
646
-
647
- // src/gateway/engine-error.ts
648
- import { engineSuccess } from "@cleocode/core";
649
- var STRING_TO_EXIT = {
650
- // General Errors (1-9)
651
- E_GENERAL: 1,
652
- E_GENERAL_ERROR: 1,
653
- E_INVALID_INPUT: 2,
654
- E_MISSING_PARAMS: 2,
655
- E_INVALID_OPERATION: 2,
656
- E_FILE_ERROR: 3,
657
- E_NOT_FOUND: 4,
658
- E_DEPENDENCY: 5,
659
- E_DEPENDENCY_ERROR: 5,
660
- E_VALIDATION: 6,
661
- E_VALIDATION_FAILED: 6,
662
- E_VALIDATION_ERROR: 6,
663
- E_RETRYABLE: 7,
664
- E_LOCK_TIMEOUT: 7,
665
- E_CONFIG_ERROR: 8,
666
- E_PROJECT_MOVED: 9,
667
- // Hierarchy Errors (10-19)
668
- E_PARENT_NOT_FOUND: 10,
669
- E_DEPTH_EXCEEDED: 11,
670
- E_SIBLING_LIMIT: 12,
671
- E_INVALID_PARENT_TYPE: 13,
672
- E_INVALID_PARENT: 13,
673
- E_CIRCULAR_DEP: 14,
674
- E_CIRCULAR_REFERENCE: 14,
675
- E_ORPHAN_DETECTED: 15,
676
- E_HAS_CHILDREN: 16,
677
- E_TASK_COMPLETED: 17,
678
- // ExitCode.TASK_COMPLETED — canonical value from @cleocode/contracts
679
- E_CASCADE_FAILED: 18,
680
- E_HAS_DEPENDENTS: 19,
681
- // Concurrency Errors (20-29)
682
- E_CHECKSUM_MISMATCH: 20,
683
- E_CONCURRENT_MODIFICATION: 21,
684
- E_ID_COLLISION: 22,
685
- E_CONFLICT: 23,
686
- E_SESSION_UNBOUND: 24,
687
- E_WORKTREE_LOCKED: 25,
688
- E_TASK_RENAMED: 26,
689
- // Session Errors (30-39)
690
- E_SESSION_EXISTS: 30,
691
- E_SESSION_CONFLICT: 30,
692
- E_SESSION_NOT_FOUND: 31,
693
- E_SCOPE_CONFLICT: 32,
694
- E_SCOPE_INVALID: 33,
695
- E_TASK_NOT_IN_SCOPE: 34,
696
- E_TASK_CLAIMED: 35,
697
- E_SESSION_REQUIRED: 36,
698
- E_SESSION_CLOSE_BLOCKED: 37,
699
- E_ACTIVE_TASK_REQUIRED: 38,
700
- E_NOTES_REQUIRED: 39,
701
- // Verification Errors (40-47)
702
- E_VERIFICATION_INIT_FAILED: 40,
703
- E_GATE_UPDATE_FAILED: 41,
704
- E_INVALID_GATE: 42,
705
- E_INVALID_AGENT: 43,
706
- E_MAX_ROUNDS_EXCEEDED: 44,
707
- E_GATE_DEPENDENCY: 45,
708
- E_VERIFICATION_LOCKED: 46,
709
- E_ROUND_MISMATCH: 47,
710
- // T1590 — Acceptance-criteria immutability after implementation stage
711
- E_AC_LOCKED: 48,
712
- // Context Safeguard (50-54)
713
- E_CONTEXT_WARNING: 50,
714
- E_CONTEXT_CAUTION: 51,
715
- E_CONTEXT_CRITICAL: 52,
716
- E_CONTEXT_EMERGENCY: 53,
717
- E_CONTEXT_STALE: 54,
718
- // Orchestrator / Protocol Errors (60-67)
719
- E_PROTOCOL_MISSING: 60,
720
- E_PROTOCOL_RESEARCH: 60,
721
- E_INVALID_RETURN_MESSAGE: 61,
722
- E_PROTOCOL_CONSENSUS: 61,
723
- E_MANIFEST_ENTRY_MISSING: 62,
724
- E_PROTOCOL_SPECIFICATION: 62,
725
- E_SPAWN_VALIDATION_FAILED: 63,
726
- E_PROTOCOL_DECOMPOSITION: 63,
727
- E_AUTONOMOUS_BOUNDARY: 64,
728
- E_PROTOCOL_IMPLEMENTATION: 64,
729
- E_HANDOFF_REQUIRED: 65,
730
- E_PROTOCOL_CONTRIBUTION: 65,
731
- E_RESUME_FAILED: 66,
732
- E_PROTOCOL_RELEASE: 66,
733
- E_CONCURRENT_SESSION: 67,
734
- E_PROTOCOL_GENERIC: 67,
735
- // Nexus Errors (70-79)
736
- E_NEXUS_NOT_INITIALIZED: 70,
737
- E_NEXUS_PROJECT_NOT_FOUND: 71,
738
- E_NEXUS_PERMISSION_DENIED: 72,
739
- E_NEXUS_INVALID_SYNTAX: 73,
740
- E_NEXUS_SYNC_FAILED: 74,
741
- E_NEXUS_REGISTRY_CORRUPT: 75,
742
- // T12512: the registry could not be read (unreadable, locked, missing table).
743
- // Shares 75 with E_NEXUS_REGISTRY_CORRUPT: both mean "registry unusable".
744
- E_NEXUS_REGISTRY_READ: 75,
745
- // T12513: a fleet `--device` filter named no known device.
746
- E_NEXUS_DEVICE_NOT_FOUND: 4,
747
- E_NEXUS_PROJECT_EXISTS: 76,
748
- E_NEXUS_QUERY_FAILED: 77,
749
- E_NEXUS_GRAPH_ERROR: 78,
750
- // Lifecycle Enforcement (80-84)
751
- E_LIFECYCLE_GATE_FAILED: 80,
752
- E_AUDIT_MISSING: 81,
753
- E_CIRCULAR_VALIDATION: 82,
754
- E_LIFECYCLE_TRANSITION_INVALID: 83,
755
- E_IVTR_INCOMPLETE: 83,
756
- E_PROVENANCE_REQUIRED: 84,
757
- // T1162: lifecycle scope guard — maps to ExitCode.TASK_NOT_IN_SCOPE (34)
758
- // because a subagent attempting to mutate a parent epic's lifecycle is
759
- // operating outside the scope granted by its session.
760
- E_LIFECYCLE_SCOPE_DENIED: 34,
761
- // Artifact Publish (85-89)
762
- E_ARTIFACT_TYPE_UNKNOWN: 85,
763
- E_ARTIFACT_VALIDATION_FAILED: 86,
764
- E_ARTIFACT_BUILD_FAILED: 87,
765
- E_ARTIFACT_PUBLISH_FAILED: 88,
766
- E_ARTIFACT_ROLLBACK_FAILED: 89,
767
- // Provenance (90-94)
768
- E_PROVENANCE_CONFIG_INVALID: 90,
769
- E_SIGNING_KEY_MISSING: 91,
770
- E_SIGNATURE_INVALID: 92,
771
- E_DIGEST_MISMATCH: 93,
772
- E_ATTESTATION_INVALID: 94,
773
- // Special Codes (100+) - NOT errors
774
- E_NO_DATA: 100,
775
- E_ALREADY_EXISTS: 101,
776
- E_NO_CHANGE: 102,
777
- E_TESTS_SKIPPED: 103,
778
- // Adapter Errors (95-99)
779
- E_ADAPTER_NOT_FOUND: 95,
780
- E_ADAPTER_INIT_FAILED: 96,
781
- E_ADAPTER_HOOK_FAILED: 97,
782
- E_ADAPTER_SPAWN_FAILED: 98,
783
- E_ADAPTER_INSTALL_FAILED: 99,
784
- // Common engine-specific aliases
785
- E_NOT_INITIALIZED: 3,
786
- E_NO_HANDLER: 1,
787
- E_INTERNAL: 1,
788
- E_LIST_FAILED: 3,
789
- E_READ_FAILED: 3,
790
- E_WRITE_FAILED: 3,
791
- E_PARSE_ERROR: 2,
792
- E_TEMPLATE_ERROR: 2
793
- };
794
- function logLevel(exitCode) {
795
- if (exitCode === 0 || exitCode >= 100) return "debug";
796
- if (exitCode === 1 || exitCode === 3) return "error";
797
- return "warn";
798
- }
799
- function engineError(code, message, options) {
800
- const resolvedExitCode = options?.exitCode ?? STRING_TO_EXIT[code] ?? 1;
801
- const level = logLevel(resolvedExitCode);
802
- const isVitest = process.env["VITEST"] === "true";
803
- if (!isVitest) {
804
- const logger = getLogger3("engine");
805
- logger[level](
806
- { code, exitCode: resolvedExitCode, ...options?.details && { details: options.details } },
807
- message
808
- );
809
- }
810
- return coreEngineError(code, message, { ...options, exitCode: resolvedExitCode });
811
- }
812
- function cleoErrorToEngineError(err, fallbackCode, fallbackMessage, meta) {
813
- if (typeof err === "string") {
814
- const exitCode2 = STRING_TO_EXIT[fallbackCode] ?? 1;
815
- return engineError(fallbackCode, err, {
816
- exitCode: exitCode2,
817
- problemDetails: {
818
- type: `https://cleocode.dev/errors/${fallbackCode}`,
819
- title: fallbackCode,
820
- status: exitCode2,
821
- detail: err,
822
- ...meta?.requestId !== void 0 ? { instance: meta.requestId } : {}
823
- }
824
- });
825
- }
826
- if (err !== null && typeof err !== "object") {
827
- const exitCode2 = STRING_TO_EXIT[fallbackCode] ?? 1;
828
- const message2 = String(err);
829
- return engineError(fallbackCode, message2, {
830
- exitCode: exitCode2,
831
- problemDetails: {
832
- type: `https://cleocode.dev/errors/${fallbackCode}`,
833
- title: fallbackCode,
834
- status: exitCode2,
835
- detail: message2,
836
- ...meta?.requestId !== void 0 ? { instance: meta.requestId } : {}
837
- }
838
- });
839
- }
840
- const e = err;
841
- const code = mapNumericExitCodeToString(e.code) ?? fallbackCode;
842
- const message = e.message ?? fallbackMessage;
843
- const exitCode = STRING_TO_EXIT[code] ?? 1;
844
- return engineError(code, message, {
845
- exitCode,
846
- ...e.fix !== void 0 && { fix: e.fix },
847
- ...e.details !== void 0 && { details: e.details },
848
- ...e.alternatives !== void 0 && { alternatives: e.alternatives },
849
- problemDetails: {
850
- type: `https://cleocode.dev/errors/${code}`,
851
- title: code,
852
- status: exitCode,
853
- detail: message,
854
- ...meta?.requestId !== void 0 ? { instance: meta.requestId } : {}
855
- }
856
- });
857
- }
858
-
859
430
  // src/gateway/job-manager-accessor.ts
860
431
  var _instance = null;
861
432
  function setJobManager(manager) {
@@ -865,126 +436,6 @@ function getJobManager() {
865
436
  return _instance;
866
437
  }
867
438
 
868
- // src/gateway/nexus-decorator.ts
869
- import { getNexusDescriptor, NEXUS_SCOPE_MAP } from "@cleocode/contracts";
870
- function resolveBindingSource(descriptor, params) {
871
- if (!descriptor.requiresProject) return "none";
872
- if (typeof params["projectId"] === "string" && params["projectId"]) {
873
- return "arg-project-id";
874
- }
875
- if (typeof params["path"] === "string" && params["path"]) {
876
- return "arg-path";
877
- }
878
- if (typeof params["_resolvedFrom"] === "string") {
879
- return params["_resolvedFrom"] === "cwd" ? "cwd" : "registry";
880
- }
881
- return "cwd";
882
- }
883
- function resolveIndexFreshness(params) {
884
- const fromParams = params["_indexFreshness"];
885
- if (fromParams === "fresh" || fromParams === "stale") return fromParams;
886
- return "unknown";
887
- }
888
- function canonicalCommandFor(op) {
889
- return `cleo nexus ${op}`;
890
- }
891
- function validateSuggestedNext(suggestions) {
892
- for (const s of suggestions) {
893
- if (!(s.op in NEXUS_SCOPE_MAP)) {
894
- throw new TypeError(
895
- `[nexus-decorator] suggestedNext.op "${s.op}" is not a known NEXUS_SCOPE_MAP entry. Add it to packages/contracts/src/operations/nexus-scope-map.ts first.`
896
- );
897
- }
898
- }
899
- }
900
- function formatSuggestedNext(s) {
901
- const argParts = Object.entries(s.args).map(([k, v]) => `--${k} ${String(v)}`).join(" ");
902
- const cmd = `cleo nexus ${s.op}${argParts ? ` ${argParts}` : ""}`;
903
- const confirm = s.requiresConfirmation ? "confirm before running" : "no confirmation needed";
904
- return `${cmd} (${s.effect}, ${confirm}) \u2014 ${s.reason}`;
905
- }
906
- function stampNexusMeta(response, operation, params, isTopLevel = true) {
907
- if (!(operation in NEXUS_SCOPE_MAP)) {
908
- return response;
909
- }
910
- const descriptor = getNexusDescriptor(operation);
911
- const bindingSource = resolveBindingSource(descriptor, params);
912
- const projectId = typeof params["projectId"] === "string" ? params["projectId"] : void 0;
913
- const projectName = typeof params["_projectName"] === "string" ? params["_projectName"] : void 0;
914
- const projectPath = typeof params["_projectPath"] === "string" ? params["_projectPath"] : void 0;
915
- const registryPath = typeof params["_registryPath"] === "string" ? params["_registryPath"] : void 0;
916
- const counterpartProjectId = descriptor.scope === "cross" || descriptor.scope === "hybrid" ? typeof params["counterpartProjectId"] === "string" ? params["counterpartProjectId"] : void 0 : void 0;
917
- const indexFreshness = descriptor.indexSensitive && isTopLevel ? resolveIndexFreshness(params) : void 0;
918
- const legacyAliasFor = typeof params["_legacyAliasFor"] === "string" ? params["_legacyAliasFor"] : void 0;
919
- const nexusMeta = {
920
- scope: descriptor.scope,
921
- effect: descriptor.effect,
922
- ...projectId !== void 0 && { projectId },
923
- ...projectName !== void 0 && { projectName },
924
- ...projectPath !== void 0 && { projectPath },
925
- ...registryPath !== void 0 && { registryPath },
926
- bindingSource,
927
- ...counterpartProjectId !== void 0 && { counterpartProjectId },
928
- ...indexFreshness !== void 0 && { indexFreshness },
929
- canonicalCommand: canonicalCommandFor(operation),
930
- ...legacyAliasFor !== void 0 && { legacyAliasFor }
931
- };
932
- return {
933
- ...response,
934
- meta: {
935
- ...response.meta,
936
- _nexus: nexusMeta,
937
- // Stamp top-level deprecated field for alias shims (T9147)
938
- ...legacyAliasFor !== void 0 && {
939
- deprecated: {
940
- since: "v2026.6.5",
941
- removeIn: "v2026.8.0",
942
- replacement: `cleo graph ${operation}`
943
- }
944
- }
945
- }
946
- };
947
- }
948
- function pickDecoratorMetaExtensions(responseMeta) {
949
- if (!responseMeta) return {};
950
- const out = {};
951
- if (responseMeta["_nexus"] !== void 0) out["_nexus"] = responseMeta["_nexus"];
952
- if (responseMeta["deprecated"] !== void 0) out["deprecated"] = responseMeta["deprecated"];
953
- if (responseMeta.sessionId !== void 0) out["sessionId"] = responseMeta.sessionId;
954
- if (responseMeta.originSessionId !== void 0) {
955
- out["originSessionId"] = responseMeta.originSessionId;
956
- }
957
- if (responseMeta.executionSessionId !== void 0) {
958
- out["executionSessionId"] = responseMeta.executionSessionId;
959
- }
960
- if (responseMeta["suggestedNext"] !== void 0) {
961
- out["suggestedNext"] = responseMeta["suggestedNext"];
962
- }
963
- return out;
964
- }
965
- function buildNexusMetaExtensions(operation, params = {}) {
966
- const synthetic = {
967
- success: true,
968
- data: void 0,
969
- meta: {
970
- gateway: "query",
971
- domain: "nexus",
972
- operation,
973
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
974
- duration_ms: 0,
975
- source: "cli",
976
- requestId: ""
977
- }
978
- };
979
- const stamped = stampNexusMeta(synthetic, operation, params);
980
- return pickDecoratorMetaExtensions(stamped.meta);
981
- }
982
-
983
- // src/gateway/paths.ts
984
- var CLEO_DIR_NAME = ".cleo";
985
- var WORKFLOWS_SUBDIR = "workflows";
986
- var BRAIN_DB_FILENAME = "brain.db";
987
-
988
439
  // src/gateway/serve.ts
989
440
  var DEFAULT_HOST = "127.0.0.1";
990
441
  async function serveGateway(opts) {
@@ -1009,12 +460,6 @@ async function serveGateway(opts) {
1009
460
  }
1010
461
  };
1011
462
  }
1012
-
1013
- // src/gateway/index.ts
1014
- function createGatewayHandler(config) {
1015
- const dispatcher = new Dispatcher(config);
1016
- return { handle: (req) => dispatcher.dispatch(req) };
1017
- }
1018
463
  export {
1019
464
  BRAIN_DB_FILENAME,
1020
465
  BackgroundJobManager,