@mcoda/codali 0.1.87 → 0.1.89
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.
- package/dist/cli/EvalCommand.d.ts +8 -0
- package/dist/cli/EvalCommand.d.ts.map +1 -1
- package/dist/cli/EvalCommand.js +93 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +1 -0
- package/dist/docdex/DocdexClient.d.ts +8 -1
- package/dist/docdex/DocdexClient.d.ts.map +1 -1
- package/dist/docdex/DocdexClient.js +126 -33
- package/dist/eval/CodaliGatewayLiveHarness.d.ts +169 -0
- package/dist/eval/CodaliGatewayLiveHarness.d.ts.map +1 -0
- package/dist/eval/CodaliGatewayLiveHarness.js +824 -0
- package/dist/eval/GatewayEvalSuite.d.ts +202 -0
- package/dist/eval/GatewayEvalSuite.d.ts.map +1 -0
- package/dist/eval/GatewayEvalSuite.js +673 -0
- package/dist/gateway/AgentTierResolver.d.ts +74 -0
- package/dist/gateway/AgentTierResolver.d.ts.map +1 -0
- package/dist/gateway/AgentTierResolver.js +576 -0
- package/dist/gateway/AppToolGatewayDispatcher.d.ts +88 -0
- package/dist/gateway/AppToolGatewayDispatcher.d.ts.map +1 -0
- package/dist/gateway/AppToolGatewayDispatcher.js +381 -0
- package/dist/gateway/CodaliGateway.d.ts +73 -0
- package/dist/gateway/CodaliGateway.d.ts.map +1 -0
- package/dist/gateway/CodaliGateway.js +824 -0
- package/dist/gateway/CodaliGatewaySchemas.d.ts +21 -0
- package/dist/gateway/CodaliGatewaySchemas.d.ts.map +1 -0
- package/dist/gateway/CodaliGatewaySchemas.js +874 -0
- package/dist/gateway/CodaliGatewayStore.d.ts +157 -0
- package/dist/gateway/CodaliGatewayStore.d.ts.map +1 -0
- package/dist/gateway/CodaliGatewayStore.js +206 -0
- package/dist/gateway/CodaliGatewayTypes.d.ts +336 -0
- package/dist/gateway/CodaliGatewayTypes.d.ts.map +1 -0
- package/dist/gateway/CodaliGatewayTypes.js +1 -0
- package/dist/gateway/ContextPackBuilder.d.ts +43 -0
- package/dist/gateway/ContextPackBuilder.d.ts.map +1 -0
- package/dist/gateway/ContextPackBuilder.js +317 -0
- package/dist/gateway/EvidenceNormalizer.d.ts +42 -0
- package/dist/gateway/EvidenceNormalizer.d.ts.map +1 -0
- package/dist/gateway/EvidenceNormalizer.js +488 -0
- package/dist/gateway/GatewayPlanner.d.ts +195 -0
- package/dist/gateway/GatewayPlanner.d.ts.map +1 -0
- package/dist/gateway/GatewayPlanner.js +379 -0
- package/dist/gateway/GatewayPolicyCompiler.d.ts +30 -0
- package/dist/gateway/GatewayPolicyCompiler.d.ts.map +1 -0
- package/dist/gateway/GatewayPolicyCompiler.js +114 -0
- package/dist/gateway/GatewaySecurityPolicy.d.ts +14 -0
- package/dist/gateway/GatewaySecurityPolicy.d.ts.map +1 -0
- package/dist/gateway/GatewaySecurityPolicy.js +350 -0
- package/dist/gateway/GatewayStateMachine.d.ts +165 -0
- package/dist/gateway/GatewayStateMachine.d.ts.map +1 -0
- package/dist/gateway/GatewayStateMachine.js +790 -0
- package/dist/gateway/GatewayTraceReplay.d.ts +120 -0
- package/dist/gateway/GatewayTraceReplay.d.ts.map +1 -0
- package/dist/gateway/GatewayTraceReplay.js +273 -0
- package/dist/gateway/ToolCapabilityCompiler.d.ts +50 -0
- package/dist/gateway/ToolCapabilityCompiler.d.ts.map +1 -0
- package/dist/gateway/ToolCapabilityCompiler.js +442 -0
- package/dist/index.d.ts +33 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -0
- package/dist/runtime/CodaliJobRuntime.d.ts +211 -0
- package/dist/runtime/CodaliJobRuntime.d.ts.map +1 -0
- package/dist/runtime/CodaliJobRuntime.js +590 -0
- package/dist/runtime/CodaliRuntime.d.ts +81 -1
- package/dist/runtime/CodaliRuntime.d.ts.map +1 -1
- package/dist/runtime/CodaliRuntime.js +619 -4
- package/dist/tools/ToolRegistry.d.ts.map +1 -1
- package/dist/tools/ToolRegistry.js +4 -0
- package/dist/tools/ToolTypes.d.ts +1 -1
- package/dist/tools/ToolTypes.d.ts.map +1 -1
- package/dist/tools/ToolTypes.js +5 -1
- package/package.json +3 -3
|
@@ -26,6 +26,14 @@ export interface ParsedEvalArgs {
|
|
|
26
26
|
workflow_profile?: string;
|
|
27
27
|
smart?: boolean;
|
|
28
28
|
no_deep_investigation?: boolean;
|
|
29
|
+
gateway_smoke?: boolean;
|
|
30
|
+
gateway_live_smoke?: boolean;
|
|
31
|
+
live_timeout_ms?: number;
|
|
32
|
+
live_mcoda_command?: string;
|
|
33
|
+
live_allow_cloud_fallback?: boolean;
|
|
34
|
+
live_no_image_worker?: boolean;
|
|
35
|
+
live_agent_run_force?: boolean;
|
|
36
|
+
live_strict?: boolean;
|
|
29
37
|
help?: boolean;
|
|
30
38
|
}
|
|
31
39
|
export declare const parseEvalArgs: (argv: string[]) => ParsedEvalArgs;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EvalCommand.d.ts","sourceRoot":"","sources":["../../src/cli/EvalCommand.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"EvalCommand.d.ts","sourceRoot":"","sources":["../../src/cli/EvalCommand.ts"],"names":[],"mappings":"AAuBA,eAAO,MAAM,eAAe;;;;;CAKlB,CAAC;AAEX,KAAK,YAAY,GAAG,CAAC,OAAO,eAAe,CAAC,CAAC,MAAM,OAAO,eAAe,CAAC,CAAC;AAE3E,qBAAa,gBAAiB,SAAQ,KAAK;IACzC,QAAQ,CAAC,QAAQ,EAAE,YAAY,CAAC;gBAEpB,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,YAAY;CAKpD;AAED,MAAM,WAAW,cAAc;IAC7B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;IACxB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,yBAAyB,CAAC,EAAE,OAAO,CAAC;IACpC,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAoDD,eAAO,MAAM,aAAa,GAAI,MAAM,MAAM,EAAE,KAAG,cAuI9C,CAAC;AA2DF,qBAAa,WAAW;IACtB,MAAM,CAAC,QAAQ,IAAI,MAAM;WAIZ,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAmMhD"}
|
package/dist/cli/EvalCommand.js
CHANGED
|
@@ -11,6 +11,8 @@ import { serializeEvalReport } from "../eval/ReportSerializer.js";
|
|
|
11
11
|
import { ReportStore } from "../eval/ReportStore.js";
|
|
12
12
|
import { loadSuiteFromFile } from "../eval/SuiteLoader.js";
|
|
13
13
|
import { SuiteValidationError } from "../eval/SuiteSchema.js";
|
|
14
|
+
import { formatCodaliGatewayLiveHarnessTextReport, runCodaliGatewayLiveHarness, } from "../eval/CodaliGatewayLiveHarness.js";
|
|
15
|
+
import { formatCodaliGatewayEvalTextReport, runCodaliGatewayEvalSuite, } from "../eval/GatewayEvalSuite.js";
|
|
14
16
|
import { resolveWorkspaceRoot } from "./RunCommand.js";
|
|
15
17
|
export const EVAL_EXIT_CODES = {
|
|
16
18
|
usage_error: 2,
|
|
@@ -25,9 +27,13 @@ export class EvalCommandError extends Error {
|
|
|
25
27
|
this.exitCode = exitCode;
|
|
26
28
|
}
|
|
27
29
|
}
|
|
28
|
-
const HELP_TEXT = "Usage: codali eval --suite <path> [options]\n
|
|
30
|
+
const HELP_TEXT = "Usage: codali eval --suite <path> [options]\n"
|
|
31
|
+
+ " or: codali eval --gateway-smoke [options]\n"
|
|
32
|
+
+ " or: codali eval --gateway-live-smoke [options]\n\n"
|
|
29
33
|
+ "Options:\n"
|
|
30
34
|
+ " --suite <path> Path to eval suite JSON (required)\n"
|
|
35
|
+
+ " --gateway-smoke Run deterministic Codali gateway eval smoke suite\n"
|
|
36
|
+
+ " --gateway-live-smoke Run Codali gateway live model smoke harness\n"
|
|
31
37
|
+ " --output <text|json> Output mode (default: text)\n"
|
|
32
38
|
+ " --baseline <path> Optional baseline report for regression diff\n"
|
|
33
39
|
+ " --report-dir <path> Override eval report output directory\n"
|
|
@@ -42,6 +48,12 @@ const HELP_TEXT = "Usage: codali eval --suite <path> [options]\n\n"
|
|
|
42
48
|
+ " --profile <name> Workflow profile override for task runs\n"
|
|
43
49
|
+ " --smart Force smart mode for task runs\n"
|
|
44
50
|
+ " --no-deep-investigation Disable deep investigation for task runs\n"
|
|
51
|
+
+ " --live-timeout-ms <n> Timeout per live smoke command (default: 120000)\n"
|
|
52
|
+
+ " --live-mcoda-command <cmd> mcoda command path for live smoke (default: mcoda)\n"
|
|
53
|
+
+ " --allow-cloud-fallback Allow cloud candidates in live tier resolution\n"
|
|
54
|
+
+ " --no-image-worker Disable image-worker requirement in live smoke\n"
|
|
55
|
+
+ " --agent-run-force Pass --force to mcoda agent-run live checks\n"
|
|
56
|
+
+ " --strict Fail live smoke on degraded status\n"
|
|
45
57
|
+ " --config <path> Config file path\n"
|
|
46
58
|
+ " --help Show help\n";
|
|
47
59
|
const expectValue = (argv, index, flag) => {
|
|
@@ -51,6 +63,13 @@ const expectValue = (argv, index, flag) => {
|
|
|
51
63
|
}
|
|
52
64
|
return value;
|
|
53
65
|
};
|
|
66
|
+
const parsePositiveIntegerFlag = (value, flag) => {
|
|
67
|
+
const parsed = Number(value);
|
|
68
|
+
if (!Number.isInteger(parsed) || parsed <= 0) {
|
|
69
|
+
throw new EvalCommandError(`Invalid ${flag} value. Expected a positive integer.`, EVAL_EXIT_CODES.usage_error);
|
|
70
|
+
}
|
|
71
|
+
return parsed;
|
|
72
|
+
};
|
|
54
73
|
export const parseEvalArgs = (argv) => {
|
|
55
74
|
const parsed = {
|
|
56
75
|
output: "text",
|
|
@@ -66,6 +85,14 @@ export const parseEvalArgs = (argv) => {
|
|
|
66
85
|
index += 1;
|
|
67
86
|
continue;
|
|
68
87
|
}
|
|
88
|
+
if (arg === "--gateway-live-smoke") {
|
|
89
|
+
parsed.gateway_live_smoke = true;
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
if (arg === "--gateway-smoke") {
|
|
93
|
+
parsed.gateway_smoke = true;
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
69
96
|
if (arg === "--output") {
|
|
70
97
|
const value = expectValue(argv, index, "--output").trim().toLowerCase();
|
|
71
98
|
if (value !== "text" && value !== "json") {
|
|
@@ -143,6 +170,32 @@ export const parseEvalArgs = (argv) => {
|
|
|
143
170
|
parsed.no_deep_investigation = true;
|
|
144
171
|
continue;
|
|
145
172
|
}
|
|
173
|
+
if (arg === "--live-timeout-ms") {
|
|
174
|
+
parsed.live_timeout_ms = parsePositiveIntegerFlag(expectValue(argv, index, "--live-timeout-ms"), "--live-timeout-ms");
|
|
175
|
+
index += 1;
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
if (arg === "--live-mcoda-command") {
|
|
179
|
+
parsed.live_mcoda_command = expectValue(argv, index, "--live-mcoda-command");
|
|
180
|
+
index += 1;
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
if (arg === "--allow-cloud-fallback") {
|
|
184
|
+
parsed.live_allow_cloud_fallback = true;
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
if (arg === "--no-image-worker") {
|
|
188
|
+
parsed.live_no_image_worker = true;
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
if (arg === "--agent-run-force") {
|
|
192
|
+
parsed.live_agent_run_force = true;
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
if (arg === "--strict") {
|
|
196
|
+
parsed.live_strict = true;
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
146
199
|
throw new EvalCommandError(`Unknown eval flag: ${arg}`, EVAL_EXIT_CODES.usage_error);
|
|
147
200
|
}
|
|
148
201
|
return parsed;
|
|
@@ -203,6 +256,45 @@ export class EvalCommand {
|
|
|
203
256
|
console.log(HELP_TEXT);
|
|
204
257
|
return;
|
|
205
258
|
}
|
|
259
|
+
if (parsed.gateway_smoke) {
|
|
260
|
+
const result = await runCodaliGatewayEvalSuite();
|
|
261
|
+
if (parsed.output === "json") {
|
|
262
|
+
// eslint-disable-next-line no-console
|
|
263
|
+
console.log(`${JSON.stringify(result, null, 2)}\n`);
|
|
264
|
+
}
|
|
265
|
+
else {
|
|
266
|
+
// eslint-disable-next-line no-console
|
|
267
|
+
console.log(formatCodaliGatewayEvalTextReport(result));
|
|
268
|
+
}
|
|
269
|
+
if (result.summary.status !== "passed" || !result.gates.passed) {
|
|
270
|
+
throw new EvalCommandError("Codali gateway smoke gates failed.", EVAL_EXIT_CODES.gate_failure);
|
|
271
|
+
}
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
if (parsed.gateway_live_smoke) {
|
|
275
|
+
const result = await runCodaliGatewayLiveHarness({
|
|
276
|
+
command: parsed.live_mcoda_command,
|
|
277
|
+
timeoutMs: parsed.live_timeout_ms,
|
|
278
|
+
allowCloudFallback: parsed.live_allow_cloud_fallback,
|
|
279
|
+
allowImageWorker: parsed.live_no_image_worker ? false : true,
|
|
280
|
+
forceAgentRun: parsed.live_agent_run_force,
|
|
281
|
+
});
|
|
282
|
+
if (parsed.output === "json") {
|
|
283
|
+
// eslint-disable-next-line no-console
|
|
284
|
+
console.log(`${JSON.stringify(result, null, 2)}\n`);
|
|
285
|
+
}
|
|
286
|
+
else {
|
|
287
|
+
// eslint-disable-next-line no-console
|
|
288
|
+
console.log(formatCodaliGatewayLiveHarnessTextReport(result));
|
|
289
|
+
}
|
|
290
|
+
if (result.summary.status === "failed") {
|
|
291
|
+
throw new EvalCommandError("Codali gateway live smoke failed.", EVAL_EXIT_CODES.run_failure);
|
|
292
|
+
}
|
|
293
|
+
if (parsed.live_strict && result.summary.status !== "passed") {
|
|
294
|
+
throw new EvalCommandError("Codali gateway live smoke did not pass strict mode.", EVAL_EXIT_CODES.gate_failure);
|
|
295
|
+
}
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
206
298
|
if (!parsed.suite_path) {
|
|
207
299
|
throw new EvalCommandError("Missing required --suite <path>.", EVAL_EXIT_CODES.usage_error);
|
|
208
300
|
}
|
package/dist/cli.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAmEA,eAAO,MAAM,MAAM,GAAU,OAAM,MAAM,EAA0B,KAAG,OAAO,CAAC,IAAI,CAoCjF,CAAC"}
|
package/dist/cli.js
CHANGED
|
@@ -9,6 +9,7 @@ const HELP_TEXT = "Usage: codali run [--workspace-root <path>] --agent <slug> [-
|
|
|
9
9
|
" or: codali run [--workspace-root <path>] --provider <name> --model <model> [--task <file>]\n" +
|
|
10
10
|
" or: codali <fix|review|explain|test> [run options] [--task <file>]\n" +
|
|
11
11
|
" or: codali eval --suite <path> [eval options]\n" +
|
|
12
|
+
" or: codali eval --gateway-live-smoke [eval options]\n" +
|
|
12
13
|
" or: codali learn --file <path/to/file> [--confirm <dedupe_key> ...]\n" +
|
|
13
14
|
" or: codali learn --confirm <dedupe_key> [--confirm <dedupe_key> ...]\n" +
|
|
14
15
|
"\n" +
|
|
@@ -9,9 +9,10 @@ export interface DocdexClientOptions {
|
|
|
9
9
|
required?: boolean;
|
|
10
10
|
allowedOperations?: readonly string[];
|
|
11
11
|
capabilities?: Record<string, boolean | undefined>;
|
|
12
|
+
immutableRuntimeContext?: boolean;
|
|
12
13
|
dagSessionId?: string;
|
|
13
14
|
}
|
|
14
|
-
export type DocdexRuntimeErrorCode = "docdex_context_missing" | "docdex_api_key_missing" | "docdex_operation_not_allowed" | "docdex_auth_failed" | "docdex_repo_access_denied" | "docdex_unavailable";
|
|
15
|
+
export type DocdexRuntimeErrorCode = "missing_credentials" | "repo_access_denied" | "scope_denied" | "encrypted_operation_disabled" | "docdex_context_missing" | "docdex_api_key_missing" | "docdex_operation_not_allowed" | "docdex_auth_failed" | "docdex_repo_access_denied" | "docdex_unavailable";
|
|
15
16
|
export type DocdexRuntimeOperation = "health" | "initialize" | "search" | "snippet" | "open" | "symbols" | "ast" | "impact_graph" | "impact_diagnostics" | "dag_export" | "tree" | "memory_save" | "memory_recall" | "profile_read" | "profile_write" | "web_research" | "chat_context" | "rerank" | "batch_search" | "capabilities" | "stats" | "files" | "repo_inspect" | "index_rebuild" | "index_ingest" | "delegate" | "hooks_validate";
|
|
16
17
|
export interface DocdexRuntimeErrorOptions {
|
|
17
18
|
status?: number;
|
|
@@ -100,6 +101,10 @@ export declare class DocdexClient {
|
|
|
100
101
|
clearCapabilityCache(): void;
|
|
101
102
|
private runtimeAllowedOperations;
|
|
102
103
|
private runtimeCapability;
|
|
104
|
+
private isImmutableRuntimeContext;
|
|
105
|
+
private missingCredentialCode;
|
|
106
|
+
private missingScopeCode;
|
|
107
|
+
private operationDisabledCode;
|
|
103
108
|
private redactSensitiveText;
|
|
104
109
|
private runtimeError;
|
|
105
110
|
private assertRuntimeContext;
|
|
@@ -117,6 +122,8 @@ export declare class DocdexClient {
|
|
|
117
122
|
private withRepoId;
|
|
118
123
|
private extractErrorCode;
|
|
119
124
|
private mapResponseErrorCode;
|
|
125
|
+
private responseRequestId;
|
|
126
|
+
private attachResponseMetadata;
|
|
120
127
|
private throwResponseError;
|
|
121
128
|
private throwResponseBodyError;
|
|
122
129
|
search(query: string, options?: DocdexSearchOptions): Promise<unknown>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DocdexClient.d.ts","sourceRoot":"","sources":["../../src/docdex/DocdexClient.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAEV,wBAAwB,EAEzB,MAAM,uBAAuB,CAAC;AAE/B,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,gBAAgB,CAAC,EAAE,yBAAyB,GAAG,MAAM,CAAC;IACtD,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,iBAAiB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACtC,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,GAAG,SAAS,CAAC,CAAC;IACnD,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,MAAM,sBAAsB,GAC9B,wBAAwB,GACxB,wBAAwB,GACxB,8BAA8B,GAC9B,oBAAoB,GACpB,2BAA2B,GAC3B,oBAAoB,CAAC;AAEzB,MAAM,MAAM,sBAAsB,GAC9B,QAA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AAO,CAAC;IAWb,eAAe,CAAC,YAAY,UAAQ,GAAG,OAAO,CAAC,wBAAwB,CAAC;CAmC/E"}
|
|
@@ -19,6 +19,10 @@ const CAPABILITY_KEYS = [
|
|
|
19
19
|
"batch_search",
|
|
20
20
|
];
|
|
21
21
|
const DOCDEX_RUNTIME_ERROR_CODES = new Set([
|
|
22
|
+
"missing_credentials",
|
|
23
|
+
"repo_access_denied",
|
|
24
|
+
"scope_denied",
|
|
25
|
+
"encrypted_operation_disabled",
|
|
22
26
|
"docdex_context_missing",
|
|
23
27
|
"docdex_api_key_missing",
|
|
24
28
|
"docdex_operation_not_allowed",
|
|
@@ -167,6 +171,21 @@ export class DocdexClient {
|
|
|
167
171
|
}
|
|
168
172
|
return undefined;
|
|
169
173
|
}
|
|
174
|
+
isImmutableRuntimeContext() {
|
|
175
|
+
return (this.options.immutableRuntimeContext === true ||
|
|
176
|
+
this.options.credentialSource === "attached_mswarm_api_key");
|
|
177
|
+
}
|
|
178
|
+
missingCredentialCode() {
|
|
179
|
+
return this.isImmutableRuntimeContext() ? "missing_credentials" : "docdex_api_key_missing";
|
|
180
|
+
}
|
|
181
|
+
missingScopeCode() {
|
|
182
|
+
return this.isImmutableRuntimeContext() ? "scope_denied" : "docdex_context_missing";
|
|
183
|
+
}
|
|
184
|
+
operationDisabledCode() {
|
|
185
|
+
return this.isImmutableRuntimeContext()
|
|
186
|
+
? "encrypted_operation_disabled"
|
|
187
|
+
: "docdex_operation_not_allowed";
|
|
188
|
+
}
|
|
170
189
|
redactSensitiveText(text) {
|
|
171
190
|
let output = text;
|
|
172
191
|
for (const secret of [this.options.apiKey, this.options.authToken]) {
|
|
@@ -185,29 +204,35 @@ export class DocdexClient {
|
|
|
185
204
|
const credentialSource = this.options.credentialSource;
|
|
186
205
|
const requiresAttachedKey = credentialSource === "attached_mswarm_api_key";
|
|
187
206
|
if (requiresAttachedKey && (!this.options.apiKey || this.options.apiKey.trim().length === 0)) {
|
|
188
|
-
throw this.runtimeError(
|
|
207
|
+
throw this.runtimeError(this.missingCredentialCode(), "Docdex attached mswarm API key is required but was not provided.", { retryable: false, details: { operation, credential_source: credentialSource } });
|
|
189
208
|
}
|
|
190
|
-
if (this.options.required && this.resolveBaseUrl().length === 0) {
|
|
191
|
-
throw this.runtimeError(
|
|
209
|
+
if ((this.options.required || this.isImmutableRuntimeContext()) && this.resolveBaseUrl().length === 0) {
|
|
210
|
+
throw this.runtimeError(this.missingScopeCode(), "Docdex base_url is required for this job.", {
|
|
192
211
|
retryable: false,
|
|
193
212
|
details: { operation },
|
|
194
213
|
});
|
|
195
214
|
}
|
|
196
|
-
if (this.options.required && requiresAttachedKey && !this.repoId) {
|
|
197
|
-
throw this.runtimeError(
|
|
215
|
+
if ((this.options.required || this.isImmutableRuntimeContext()) && requiresAttachedKey && !this.repoId) {
|
|
216
|
+
throw this.runtimeError(this.missingScopeCode(), "Docdex repo_id is required for this job.", {
|
|
198
217
|
retryable: false,
|
|
199
218
|
details: { operation },
|
|
200
219
|
});
|
|
201
220
|
}
|
|
221
|
+
if (this.isImmutableRuntimeContext() && !this.options.allowedOperations?.length) {
|
|
222
|
+
throw this.runtimeError("scope_denied", "Docdex allowedOperations are required for immutable encrypted jobs.", { retryable: false, details: { operation, missing: "allowedOperations" } });
|
|
223
|
+
}
|
|
224
|
+
if (this.isImmutableRuntimeContext() && !this.options.capabilities) {
|
|
225
|
+
throw this.runtimeError("scope_denied", "Docdex capability map is required for immutable encrypted jobs.", { retryable: false, details: { operation, missing: "capabilities" } });
|
|
226
|
+
}
|
|
202
227
|
}
|
|
203
228
|
assertOperationAllowed(operation) {
|
|
204
229
|
this.assertRuntimeContext(operation);
|
|
205
230
|
const allowedOperations = this.runtimeAllowedOperations();
|
|
206
231
|
if (allowedOperations && !allowedOperations.has(operation)) {
|
|
207
|
-
throw this.runtimeError(
|
|
232
|
+
throw this.runtimeError(this.operationDisabledCode(), `Docdex operation is not allowed by this job: ${operation}`, { retryable: false, details: { operation } });
|
|
208
233
|
}
|
|
209
234
|
if (this.runtimeCapability(operation) === false) {
|
|
210
|
-
throw this.runtimeError(
|
|
235
|
+
throw this.runtimeError(this.operationDisabledCode(), `Docdex operation is disabled by this job capability map: ${operation}`, { retryable: false, details: { operation } });
|
|
211
236
|
}
|
|
212
237
|
}
|
|
213
238
|
resolveBaseUrl() {
|
|
@@ -224,8 +249,9 @@ export class DocdexClient {
|
|
|
224
249
|
}
|
|
225
250
|
if (this.repoId)
|
|
226
251
|
headers["x-docdex-repo-id"] = this.repoId;
|
|
227
|
-
if (this.options.repoRoot)
|
|
252
|
+
if (this.options.repoRoot && !this.isImmutableRuntimeContext()) {
|
|
228
253
|
headers["x-docdex-repo-root"] = path.resolve(this.options.repoRoot);
|
|
254
|
+
}
|
|
229
255
|
const resolvedDagSessionId = dagSessionId ?? this.dagSessionId;
|
|
230
256
|
if (resolvedDagSessionId)
|
|
231
257
|
headers["x-docdex-dag-session"] = resolvedDagSessionId;
|
|
@@ -250,6 +276,9 @@ export class DocdexClient {
|
|
|
250
276
|
}
|
|
251
277
|
}
|
|
252
278
|
async healthCheck() {
|
|
279
|
+
if (this.isImmutableRuntimeContext()) {
|
|
280
|
+
this.assertRuntimeContext("health");
|
|
281
|
+
}
|
|
253
282
|
let response;
|
|
254
283
|
try {
|
|
255
284
|
response = await fetch(`${this.resolveBaseUrl()}/healthz`);
|
|
@@ -282,6 +311,8 @@ export class DocdexClient {
|
|
|
282
311
|
return { repoId, repoRoot };
|
|
283
312
|
}
|
|
284
313
|
async ensureRepoInitialized() {
|
|
314
|
+
if (this.isImmutableRuntimeContext())
|
|
315
|
+
return;
|
|
285
316
|
if (this.repoId || this.repoInitializeAttempted || !this.options.repoRoot)
|
|
286
317
|
return;
|
|
287
318
|
this.repoInitializeAttempted = true;
|
|
@@ -296,8 +327,9 @@ export class DocdexClient {
|
|
|
296
327
|
withRepoId(params) {
|
|
297
328
|
if (this.repoId)
|
|
298
329
|
params.set("repo_id", this.repoId);
|
|
299
|
-
if (this.options.repoRoot)
|
|
330
|
+
if (this.options.repoRoot && !this.isImmutableRuntimeContext()) {
|
|
300
331
|
params.set("repo_root", path.resolve(this.options.repoRoot));
|
|
332
|
+
}
|
|
301
333
|
}
|
|
302
334
|
extractErrorCode(body) {
|
|
303
335
|
const parsed = this.tryParseJson(body);
|
|
@@ -312,33 +344,88 @@ export class DocdexClient {
|
|
|
312
344
|
}
|
|
313
345
|
mapResponseErrorCode(status, body) {
|
|
314
346
|
const extracted = this.extractErrorCode(body);
|
|
315
|
-
if (isDocdexRuntimeErrorCode(extracted))
|
|
347
|
+
if (isDocdexRuntimeErrorCode(extracted)) {
|
|
348
|
+
if (this.isImmutableRuntimeContext()) {
|
|
349
|
+
if (extracted === "docdex_api_key_missing" || extracted === "docdex_auth_failed") {
|
|
350
|
+
return "missing_credentials";
|
|
351
|
+
}
|
|
352
|
+
if (extracted === "docdex_repo_access_denied") {
|
|
353
|
+
return "repo_access_denied";
|
|
354
|
+
}
|
|
355
|
+
if (extracted === "docdex_context_missing") {
|
|
356
|
+
return "scope_denied";
|
|
357
|
+
}
|
|
358
|
+
if (extracted === "docdex_operation_not_allowed") {
|
|
359
|
+
return "encrypted_operation_disabled";
|
|
360
|
+
}
|
|
361
|
+
}
|
|
316
362
|
return extracted;
|
|
363
|
+
}
|
|
317
364
|
const normalized = `${extracted ?? ""} ${body}`.toLowerCase();
|
|
318
365
|
if (/introspection_unavailable|unavailable|timeout|timed out|econnrefused|enotfound/.test(normalized)) {
|
|
319
366
|
return "docdex_unavailable";
|
|
320
367
|
}
|
|
321
368
|
if (/repo_access_denied|unknown_repo|repo.*denied|denied.*repo/.test(normalized)) {
|
|
322
|
-
return "docdex_repo_access_denied";
|
|
369
|
+
return this.isImmutableRuntimeContext() ? "repo_access_denied" : "docdex_repo_access_denied";
|
|
323
370
|
}
|
|
324
|
-
if (/scope_denied
|
|
325
|
-
return "docdex_operation_not_allowed";
|
|
371
|
+
if (/scope_denied/.test(normalized)) {
|
|
372
|
+
return this.isImmutableRuntimeContext() ? "scope_denied" : "docdex_operation_not_allowed";
|
|
373
|
+
}
|
|
374
|
+
if (/operation_not_allowed|encrypted_operation_disabled|not allowed|forbidden_operation/.test(normalized)) {
|
|
375
|
+
return this.operationDisabledCode();
|
|
326
376
|
}
|
|
327
377
|
if (status === 401 || status === 403 || /invalid_credentials|missing_credentials|ambiguous_credentials/.test(normalized)) {
|
|
328
|
-
return "docdex_auth_failed";
|
|
378
|
+
return this.isImmutableRuntimeContext() ? "missing_credentials" : "docdex_auth_failed";
|
|
329
379
|
}
|
|
330
380
|
return "docdex_unavailable";
|
|
331
381
|
}
|
|
382
|
+
responseRequestId(response) {
|
|
383
|
+
for (const key of [
|
|
384
|
+
"x-docdex-request-id",
|
|
385
|
+
"x-request-id",
|
|
386
|
+
"x-mswarm-request-id",
|
|
387
|
+
"x-correlation-id",
|
|
388
|
+
"traceparent",
|
|
389
|
+
]) {
|
|
390
|
+
const value = response.headers.get(key);
|
|
391
|
+
if (value?.trim())
|
|
392
|
+
return value.trim();
|
|
393
|
+
}
|
|
394
|
+
return undefined;
|
|
395
|
+
}
|
|
396
|
+
attachResponseMetadata(payload, response, operation) {
|
|
397
|
+
const headerRequestId = this.responseRequestId(response);
|
|
398
|
+
if (!headerRequestId || !payload || typeof payload !== "object" || Array.isArray(payload)) {
|
|
399
|
+
return payload;
|
|
400
|
+
}
|
|
401
|
+
const record = payload;
|
|
402
|
+
const existingMeta = record.meta && typeof record.meta === "object" && !Array.isArray(record.meta)
|
|
403
|
+
? record.meta
|
|
404
|
+
: {};
|
|
405
|
+
const existingRequestId = typeof existingMeta.docdex_request_id === "string"
|
|
406
|
+
? existingMeta.docdex_request_id
|
|
407
|
+
: typeof existingMeta.request_id === "string"
|
|
408
|
+
? existingMeta.request_id
|
|
409
|
+
: undefined;
|
|
410
|
+
return {
|
|
411
|
+
...record,
|
|
412
|
+
meta: {
|
|
413
|
+
...existingMeta,
|
|
414
|
+
docdex_request_id: existingRequestId ?? headerRequestId,
|
|
415
|
+
docdex_operation: operation,
|
|
416
|
+
},
|
|
417
|
+
};
|
|
418
|
+
}
|
|
332
419
|
async throwResponseError(response, operation) {
|
|
333
420
|
const body = await response.text();
|
|
334
|
-
this.throwResponseBodyError(response.status, body, operation);
|
|
421
|
+
this.throwResponseBodyError(response.status, body, operation, this.responseRequestId(response));
|
|
335
422
|
}
|
|
336
|
-
throwResponseBodyError(status, body, operation) {
|
|
423
|
+
throwResponseBodyError(status, body, operation, requestId) {
|
|
337
424
|
const code = this.mapResponseErrorCode(status, body);
|
|
338
425
|
throw this.runtimeError(code, `Docdex ${operation} failed (${status}): ${body}`, {
|
|
339
426
|
status,
|
|
340
427
|
retryable: code === "docdex_unavailable" && status >= 500,
|
|
341
|
-
details: { operation },
|
|
428
|
+
details: requestId ? { operation, docdex_request_id: requestId } : { operation },
|
|
342
429
|
});
|
|
343
430
|
}
|
|
344
431
|
async search(query, options = {}) {
|
|
@@ -366,7 +453,7 @@ export class DocdexClient {
|
|
|
366
453
|
if (retryQuery) {
|
|
367
454
|
const retryResponse = await executeSearch(retryQuery);
|
|
368
455
|
if (retryResponse.ok) {
|
|
369
|
-
const retryPayload = await retryResponse.json();
|
|
456
|
+
const retryPayload = this.attachResponseMetadata(await retryResponse.json(), retryResponse, "search");
|
|
370
457
|
if (retryPayload && typeof retryPayload === "object" && !Array.isArray(retryPayload)) {
|
|
371
458
|
const payloadRecord = retryPayload;
|
|
372
459
|
const meta = payloadRecord.meta && typeof payloadRecord.meta === "object" && !Array.isArray(payloadRecord.meta)
|
|
@@ -387,11 +474,11 @@ export class DocdexClient {
|
|
|
387
474
|
return retryPayload;
|
|
388
475
|
}
|
|
389
476
|
const retryBody = await retryResponse.text();
|
|
390
|
-
this.throwResponseBodyError(retryResponse.status, retryBody, "search");
|
|
477
|
+
this.throwResponseBodyError(retryResponse.status, retryBody, "search", this.responseRequestId(retryResponse));
|
|
391
478
|
}
|
|
392
|
-
this.throwResponseBodyError(response.status, body, "search");
|
|
479
|
+
this.throwResponseBodyError(response.status, body, "search", this.responseRequestId(response));
|
|
393
480
|
}
|
|
394
|
-
return response.json();
|
|
481
|
+
return this.attachResponseMetadata(await response.json(), response, "search");
|
|
395
482
|
}
|
|
396
483
|
async openSnippet(docId, options = {}) {
|
|
397
484
|
this.assertOperationAllowed("snippet");
|
|
@@ -411,7 +498,7 @@ export class DocdexClient {
|
|
|
411
498
|
}
|
|
412
499
|
const contentType = response.headers.get("content-type") ?? "";
|
|
413
500
|
if (contentType.includes("application/json")) {
|
|
414
|
-
return response.json();
|
|
501
|
+
return this.attachResponseMetadata(await response.json(), response, "snippet");
|
|
415
502
|
}
|
|
416
503
|
return response.text();
|
|
417
504
|
}
|
|
@@ -433,7 +520,7 @@ export class DocdexClient {
|
|
|
433
520
|
if (!response.ok) {
|
|
434
521
|
await this.throwResponseError(response, "impact graph");
|
|
435
522
|
}
|
|
436
|
-
return response.json();
|
|
523
|
+
return this.attachResponseMetadata(await response.json(), response, "impact_graph");
|
|
437
524
|
}
|
|
438
525
|
async impactDiagnostics(options = {}) {
|
|
439
526
|
this.assertOperationAllowed("impact_diagnostics");
|
|
@@ -453,7 +540,7 @@ export class DocdexClient {
|
|
|
453
540
|
if (!response.ok) {
|
|
454
541
|
await this.throwResponseError(response, "impact diagnostics");
|
|
455
542
|
}
|
|
456
|
-
return response.json();
|
|
543
|
+
return this.attachResponseMetadata(await response.json(), response, "impact_diagnostics");
|
|
457
544
|
}
|
|
458
545
|
async indexRebuild(libsSources) {
|
|
459
546
|
this.assertOperationAllowed("index_rebuild");
|
|
@@ -466,7 +553,7 @@ export class DocdexClient {
|
|
|
466
553
|
if (!response.ok) {
|
|
467
554
|
await this.throwResponseError(response, "index rebuild");
|
|
468
555
|
}
|
|
469
|
-
return response.json();
|
|
556
|
+
return this.attachResponseMetadata(await response.json(), response, "index_rebuild");
|
|
470
557
|
}
|
|
471
558
|
async indexIngest(file) {
|
|
472
559
|
this.assertOperationAllowed("index_ingest");
|
|
@@ -479,7 +566,7 @@ export class DocdexClient {
|
|
|
479
566
|
if (!response.ok) {
|
|
480
567
|
await this.throwResponseError(response, "index ingest");
|
|
481
568
|
}
|
|
482
|
-
return response.json();
|
|
569
|
+
return this.attachResponseMetadata(await response.json(), response, "index_ingest");
|
|
483
570
|
}
|
|
484
571
|
async hooksValidate(files) {
|
|
485
572
|
this.assertOperationAllowed("hooks_validate");
|
|
@@ -492,7 +579,7 @@ export class DocdexClient {
|
|
|
492
579
|
if (!response.ok) {
|
|
493
580
|
await this.throwResponseError(response, "hooks validate");
|
|
494
581
|
}
|
|
495
|
-
return response.json();
|
|
582
|
+
return this.attachResponseMetadata(await response.json(), response, "hooks_validate");
|
|
496
583
|
}
|
|
497
584
|
async delegate(payload) {
|
|
498
585
|
this.assertOperationAllowed("delegate");
|
|
@@ -505,7 +592,7 @@ export class DocdexClient {
|
|
|
505
592
|
if (!response.ok) {
|
|
506
593
|
await this.throwResponseError(response, "delegate");
|
|
507
594
|
}
|
|
508
|
-
return response.json();
|
|
595
|
+
return this.attachResponseMetadata(await response.json(), response, "delegate");
|
|
509
596
|
}
|
|
510
597
|
async chatContext(messages, options = {}) {
|
|
511
598
|
this.assertOperationAllowed("chat_context");
|
|
@@ -531,7 +618,7 @@ export class DocdexClient {
|
|
|
531
618
|
if (!response.ok) {
|
|
532
619
|
await this.throwResponseError(response, "chat context");
|
|
533
620
|
}
|
|
534
|
-
return response.json();
|
|
621
|
+
return this.attachResponseMetadata(await response.json(), response, "chat_context");
|
|
535
622
|
}
|
|
536
623
|
async dagExport(sessionId, options = {}) {
|
|
537
624
|
this.assertOperationAllowed("dag_export");
|
|
@@ -552,13 +639,16 @@ export class DocdexClient {
|
|
|
552
639
|
throw this.runtimeError(code, `Docdex dag export failed (${response.status}): ${body}`, {
|
|
553
640
|
status: response.status,
|
|
554
641
|
retryable: code === "docdex_unavailable" && response.status >= 500,
|
|
555
|
-
details: {
|
|
642
|
+
details: {
|
|
643
|
+
operation: "dag_export",
|
|
644
|
+
...(this.responseRequestId(response) ? { docdex_request_id: this.responseRequestId(response) } : {}),
|
|
645
|
+
},
|
|
556
646
|
});
|
|
557
647
|
}
|
|
558
648
|
const contentType = response.headers.get("content-type") ?? "";
|
|
559
649
|
if (contentType.includes("application/json")) {
|
|
560
650
|
try {
|
|
561
|
-
return JSON.parse(body);
|
|
651
|
+
return this.attachResponseMetadata(JSON.parse(body), response, "dag_export");
|
|
562
652
|
}
|
|
563
653
|
catch {
|
|
564
654
|
return body;
|
|
@@ -595,7 +685,7 @@ export class DocdexClient {
|
|
|
595
685
|
details: { method },
|
|
596
686
|
});
|
|
597
687
|
}
|
|
598
|
-
return this.normalizeMcpResult(raw.result);
|
|
688
|
+
return this.attachResponseMetadata(this.normalizeMcpResult(raw.result), response, operation ?? method);
|
|
599
689
|
}
|
|
600
690
|
normalizeMcpResult(payload) {
|
|
601
691
|
if (!payload || typeof payload !== "object")
|
|
@@ -637,6 +727,9 @@ export class DocdexClient {
|
|
|
637
727
|
}
|
|
638
728
|
}
|
|
639
729
|
buildProjectParams(extra) {
|
|
730
|
+
if (this.isImmutableRuntimeContext()) {
|
|
731
|
+
return { ...extra };
|
|
732
|
+
}
|
|
640
733
|
return {
|
|
641
734
|
project_root: this.options.repoRoot,
|
|
642
735
|
...extra,
|
|
@@ -786,7 +879,7 @@ export class DocdexClient {
|
|
|
786
879
|
if (!response.ok) {
|
|
787
880
|
await this.throwResponseError(response, "web research");
|
|
788
881
|
}
|
|
789
|
-
return response.json();
|
|
882
|
+
return this.attachResponseMetadata(await response.json(), response, "web_research");
|
|
790
883
|
}
|
|
791
884
|
rerank(query, candidates, limit) {
|
|
792
885
|
return this.callMcp("docdex_rerank", this.buildProjectParams({
|