@mcoda/codali 0.1.135-codali.2 → 0.1.135-codali.29
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/CHANGELOG.md +53 -0
- package/ORCHESTRATION.md +308 -2
- package/README.md +184 -7
- package/config/AGENTS.md +11 -0
- package/config/deterministic/install-python.mjs +16 -0
- package/config/deterministic/node-worker.mjs +77 -0
- package/config/deterministic/python-worker.py +222 -0
- package/config/deterministic/requirements.txt +6 -0
- package/config/docdex-tools-0.2.99.json +3977 -0
- package/config/documents/install-python.mjs +16 -0
- package/config/documents/requirements.txt +10 -0
- package/config/documents/worker.py +267 -0
- package/config/orchestration.schema.json +94 -3
- package/config/skills/planning/SKILL.md +13 -0
- package/config/terminal-long-scenarios.v1.json +3 -2
- package/dist/cli/TerminalArtifacts.d.ts +5 -0
- package/dist/cli/TerminalArtifacts.d.ts.map +1 -0
- package/dist/cli/TerminalArtifacts.js +26 -0
- package/dist/cli/TerminalCommand.d.ts.map +1 -1
- package/dist/cli/TerminalCommand.js +411 -75
- package/dist/cli/TerminalCredentials.js +2 -2
- package/dist/cli/TerminalInput.d.ts +13 -0
- package/dist/cli/TerminalInput.d.ts.map +1 -1
- package/dist/cli/TerminalInput.js +55 -7
- package/dist/cli/TerminalModels.d.ts +6 -0
- package/dist/cli/TerminalModels.d.ts.map +1 -0
- package/dist/cli/TerminalModels.js +45 -0
- package/dist/cli/TerminalPlan.d.ts +40 -0
- package/dist/cli/TerminalPlan.d.ts.map +1 -0
- package/dist/cli/TerminalPlan.js +37 -0
- package/dist/cli/ToolsCommand.d.ts.map +1 -1
- package/dist/cli/ToolsCommand.js +8 -1
- package/dist/cli/tui/TerminalCells.d.ts +6 -0
- package/dist/cli/tui/TerminalCells.d.ts.map +1 -0
- package/dist/cli/tui/TerminalCells.js +47 -0
- package/dist/cli/tui/TerminalEditor.d.ts +22 -0
- package/dist/cli/tui/TerminalEditor.d.ts.map +1 -0
- package/dist/cli/tui/TerminalEditor.js +88 -0
- package/dist/cli/tui/TerminalLogo.d.ts +6 -0
- package/dist/cli/tui/TerminalLogo.d.ts.map +1 -0
- package/dist/cli/tui/TerminalLogo.js +26 -0
- package/dist/cli/tui/TerminalMarkdown.d.ts +5 -0
- package/dist/cli/tui/TerminalMarkdown.d.ts.map +1 -0
- package/dist/cli/tui/TerminalMarkdown.js +118 -0
- package/dist/cli/tui/TerminalPresentation.d.ts +4 -0
- package/dist/cli/tui/TerminalPresentation.d.ts.map +1 -0
- package/dist/cli/tui/TerminalPresentation.js +77 -0
- package/dist/cli/tui/TerminalScreen.d.ts +50 -0
- package/dist/cli/tui/TerminalScreen.d.ts.map +1 -0
- package/dist/cli/tui/TerminalScreen.js +137 -0
- package/dist/cli/tui/TerminalSelection.d.ts +15 -0
- package/dist/cli/tui/TerminalSelection.d.ts.map +1 -0
- package/dist/cli/tui/TerminalSelection.js +38 -0
- package/dist/cli/tui/TerminalTui.d.ts +82 -0
- package/dist/cli/tui/TerminalTui.d.ts.map +1 -0
- package/dist/cli/tui/TerminalTui.js +553 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +5 -3
- package/dist/config/OrchestrationConfig.d.ts +33 -0
- package/dist/config/OrchestrationConfig.d.ts.map +1 -1
- package/dist/config/OrchestrationConfig.js +59 -1
- package/dist/connectors/media/MediaJobStore.d.ts +2 -1
- package/dist/connectors/media/MediaJobStore.d.ts.map +1 -1
- package/dist/connectors/media/MediaJobStore.js +11 -3
- package/dist/docdex/DocdexCatalog.d.ts +12 -0
- package/dist/docdex/DocdexCatalog.d.ts.map +1 -0
- package/dist/docdex/DocdexCatalog.js +30 -0
- package/dist/docdex/DocdexClient.d.ts +8 -2
- package/dist/docdex/DocdexClient.d.ts.map +1 -1
- package/dist/docdex/DocdexClient.js +86 -11
- package/dist/docdex/ManagedDocdex.d.ts +1 -0
- package/dist/docdex/ManagedDocdex.d.ts.map +1 -1
- package/dist/docdex/ManagedDocdex.js +25 -4
- package/dist/eval/TerminalWorkflowCorpus.d.ts +1 -1
- package/dist/eval/TerminalWorkflowCorpus.d.ts.map +1 -1
- package/dist/eval/TerminalWorkflowCorpus.js +9 -6
- package/dist/eval/TrustBenchmark.d.ts +94 -0
- package/dist/eval/TrustBenchmark.d.ts.map +1 -0
- package/dist/eval/TrustBenchmark.js +199 -0
- package/dist/eval/fixtures/ContractReviewProvider.d.ts +4 -0
- package/dist/eval/fixtures/ContractReviewProvider.d.ts.map +1 -0
- package/dist/eval/fixtures/ContractReviewProvider.js +10 -0
- package/dist/eval/fixtures/MixedMediaRecoveryJourney.d.ts +6 -0
- package/dist/eval/fixtures/MixedMediaRecoveryJourney.d.ts.map +1 -0
- package/dist/eval/fixtures/MixedMediaRecoveryJourney.js +145 -0
- package/dist/eval/fixtures/TerminalRecoveryJourney.d.ts.map +1 -1
- package/dist/eval/fixtures/TerminalRecoveryJourney.js +14 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/permissions/PermissionGate.d.ts +1 -1
- package/dist/permissions/PermissionGate.d.ts.map +1 -1
- package/dist/permissions/PermissionGate.js +40 -2
- package/dist/permissions/WorkspacePermissions.d.ts +11 -0
- package/dist/permissions/WorkspacePermissions.d.ts.map +1 -0
- package/dist/permissions/WorkspacePermissions.js +42 -0
- package/dist/providers/ConfiguredModelScope.d.ts +1 -0
- package/dist/providers/ConfiguredModelScope.d.ts.map +1 -1
- package/dist/providers/ConfiguredModelScope.js +17 -1
- package/dist/providers/ConfiguredProvider.d.ts +5 -0
- package/dist/providers/ConfiguredProvider.d.ts.map +1 -1
- package/dist/providers/ConfiguredProvider.js +38 -5
- package/dist/providers/ModelServiceError.d.ts +7 -2
- package/dist/providers/ModelServiceError.d.ts.map +1 -1
- package/dist/providers/ModelServiceError.js +28 -4
- package/dist/providers/OpenAiCompatibleProvider.d.ts.map +1 -1
- package/dist/providers/OpenAiCompatibleProvider.js +9 -1
- package/dist/providers/ProviderTypes.d.ts +2 -0
- package/dist/providers/ProviderTypes.d.ts.map +1 -1
- package/dist/providers/RequestUsage.d.ts +11 -0
- package/dist/providers/RequestUsage.d.ts.map +1 -0
- package/dist/providers/RequestUsage.js +33 -0
- package/dist/runtime/CodaliRuntime.d.ts +1 -0
- package/dist/runtime/CodaliRuntime.d.ts.map +1 -1
- package/dist/runtime/CodaliRuntime.js +1 -0
- package/dist/runtime/ComputedAnswer.d.ts +13 -0
- package/dist/runtime/ComputedAnswer.d.ts.map +1 -0
- package/dist/runtime/ComputedAnswer.js +75 -0
- package/dist/runtime/ContextCompression.d.ts +22 -0
- package/dist/runtime/ContextCompression.d.ts.map +1 -0
- package/dist/runtime/ContextCompression.js +53 -0
- package/dist/runtime/InspectionBudget.d.ts +8 -0
- package/dist/runtime/InspectionBudget.d.ts.map +1 -0
- package/dist/runtime/InspectionBudget.js +25 -0
- package/dist/runtime/InteractionContract.d.ts +42 -0
- package/dist/runtime/InteractionContract.d.ts.map +1 -0
- package/dist/runtime/InteractionContract.js +50 -0
- package/dist/runtime/InteractionRouter.d.ts +71 -0
- package/dist/runtime/InteractionRouter.d.ts.map +1 -0
- package/dist/runtime/InteractionRouter.js +134 -0
- package/dist/runtime/PreparedDocdex.d.ts +4 -0
- package/dist/runtime/PreparedDocdex.d.ts.map +1 -0
- package/dist/runtime/PreparedDocdex.js +55 -0
- package/dist/runtime/PreparedMemory.d.ts +3 -0
- package/dist/runtime/PreparedMemory.d.ts.map +1 -0
- package/dist/runtime/PreparedMemory.js +30 -0
- package/dist/runtime/ReviewContract.d.ts +35 -0
- package/dist/runtime/ReviewContract.d.ts.map +1 -0
- package/dist/runtime/ReviewContract.js +132 -0
- package/dist/runtime/ReviewCoordinator.d.ts +41 -0
- package/dist/runtime/ReviewCoordinator.d.ts.map +1 -0
- package/dist/runtime/ReviewCoordinator.js +132 -0
- package/dist/runtime/ReviewSource.d.ts +3 -0
- package/dist/runtime/ReviewSource.d.ts.map +1 -1
- package/dist/runtime/ReviewSource.js +17 -1
- package/dist/runtime/Runner.d.ts.map +1 -1
- package/dist/runtime/Runner.js +6 -1
- package/dist/runtime/SessionController.d.ts +51 -1
- package/dist/runtime/SessionController.d.ts.map +1 -1
- package/dist/runtime/SessionController.js +1146 -112
- package/dist/runtime/TaskReview.d.ts +25 -0
- package/dist/runtime/TaskReview.d.ts.map +1 -0
- package/dist/runtime/TaskReview.js +109 -0
- package/dist/runtime/TaskReviewContext.d.ts +37 -0
- package/dist/runtime/TaskReviewContext.d.ts.map +1 -1
- package/dist/runtime/TaskReviewContext.js +18 -2
- package/dist/runtime/UsageReconciliation.d.ts +28 -0
- package/dist/runtime/UsageReconciliation.d.ts.map +1 -0
- package/dist/runtime/UsageReconciliation.js +68 -0
- package/dist/runtime/VerificationCommand.d.ts +2 -0
- package/dist/runtime/VerificationCommand.d.ts.map +1 -1
- package/dist/runtime/VerificationCommand.js +28 -0
- package/dist/runtime/VerificationReceiptSelection.d.ts +15 -0
- package/dist/runtime/VerificationReceiptSelection.d.ts.map +1 -0
- package/dist/runtime/VerificationReceiptSelection.js +30 -0
- package/dist/session/AtomicState.d.ts.map +1 -1
- package/dist/session/AtomicState.js +15 -1
- package/dist/session/InstructionLoader.d.ts +5 -1
- package/dist/session/InstructionLoader.d.ts.map +1 -1
- package/dist/session/InstructionLoader.js +65 -19
- package/dist/session/SessionStoragePath.d.ts.map +1 -1
- package/dist/session/SessionStoragePath.js +28 -16
- package/dist/session/SessionStore.d.ts +5 -1
- package/dist/session/SessionStore.d.ts.map +1 -1
- package/dist/session/SessionStore.js +11 -2
- package/dist/session/SkillCatalog.d.ts +33 -0
- package/dist/session/SkillCatalog.d.ts.map +1 -0
- package/dist/session/SkillCatalog.js +194 -0
- package/dist/session/WorkState.d.ts +9 -0
- package/dist/session/WorkState.d.ts.map +1 -1
- package/dist/session/WorkState.js +32 -0
- package/dist/session/WorkTypes.d.ts +8 -0
- package/dist/session/WorkTypes.d.ts.map +1 -1
- package/dist/tools/SemanticToolRetrieval.d.ts +19 -0
- package/dist/tools/SemanticToolRetrieval.d.ts.map +1 -0
- package/dist/tools/SemanticToolRetrieval.js +52 -0
- package/dist/tools/ToolRetrieval.d.ts +7 -0
- package/dist/tools/ToolRetrieval.d.ts.map +1 -0
- package/dist/tools/ToolRetrieval.js +25 -0
- package/dist/tools/browser/BrowserTool.d.ts +9 -0
- package/dist/tools/browser/BrowserTool.d.ts.map +1 -0
- package/dist/tools/browser/BrowserTool.js +152 -0
- package/dist/tools/browser/BrowserWorker.d.ts +2 -0
- package/dist/tools/browser/BrowserWorker.d.ts.map +1 -0
- package/dist/tools/browser/BrowserWorker.js +51 -0
- package/dist/tools/calculation/CalculatorTool.d.ts +5 -0
- package/dist/tools/calculation/CalculatorTool.d.ts.map +1 -0
- package/dist/tools/calculation/CalculatorTool.js +137 -0
- package/dist/tools/deterministic/DeterministicRuntime.d.ts +39 -0
- package/dist/tools/deterministic/DeterministicRuntime.d.ts.map +1 -0
- package/dist/tools/deterministic/DeterministicRuntime.js +98 -0
- package/dist/tools/deterministic/DeterministicTools.d.ts +8 -0
- package/dist/tools/deterministic/DeterministicTools.d.ts.map +1 -0
- package/dist/tools/deterministic/DeterministicTools.js +86 -0
- package/dist/tools/deterministic/node-worker.cjs +38 -0
- package/dist/tools/deterministic/python-worker.py +222 -0
- package/dist/tools/docdex/DocdexCatalogTools.d.ts +4 -0
- package/dist/tools/docdex/DocdexCatalogTools.d.ts.map +1 -0
- package/dist/tools/docdex/DocdexCatalogTools.js +58 -0
- package/dist/tools/docdex/DocdexTools.d.ts +2 -0
- package/dist/tools/docdex/DocdexTools.d.ts.map +1 -1
- package/dist/tools/docdex/DocdexTools.js +72 -105
- package/dist/tools/documents/DocumentRuntime.d.ts +12 -0
- package/dist/tools/documents/DocumentRuntime.d.ts.map +1 -0
- package/dist/tools/documents/DocumentRuntime.js +59 -0
- package/dist/tools/documents/DocumentTools.d.ts +19 -0
- package/dist/tools/documents/DocumentTools.d.ts.map +1 -0
- package/dist/tools/documents/DocumentTools.js +150 -0
- package/dist/tools/documents/worker.py +267 -0
- package/dist/tools/entities/AdesTool.d.ts +7 -0
- package/dist/tools/entities/AdesTool.d.ts.map +1 -0
- package/dist/tools/entities/AdesTool.js +59 -0
- package/dist/tools/research/TnlTool.d.ts +22 -0
- package/dist/tools/research/TnlTool.d.ts.map +1 -0
- package/dist/tools/research/TnlTool.js +246 -0
- package/dist/tools/shell/AsyncProcess.d.ts +3 -0
- package/dist/tools/shell/AsyncProcess.d.ts.map +1 -1
- package/dist/tools/shell/AsyncProcess.js +1 -1
- package/dist/tools/shell/HostToolchain.d.ts.map +1 -1
- package/dist/tools/shell/HostToolchain.js +18 -4
- package/dist/tools/shell/IsolatedExecutor.d.ts +3 -2
- package/dist/tools/shell/IsolatedExecutor.d.ts.map +1 -1
- package/dist/tools/shell/IsolatedExecutor.js +39 -5
- package/dist/tools/system/TimeTool.d.ts +4 -0
- package/dist/tools/system/TimeTool.d.ts.map +1 -0
- package/dist/tools/system/TimeTool.js +22 -0
- package/dist/tools/verification/JavaScriptVerificationTool.d.ts +47 -0
- package/dist/tools/verification/JavaScriptVerificationTool.d.ts.map +1 -0
- package/dist/tools/verification/JavaScriptVerificationTool.js +71 -0
- package/dist/tools/verification/JavaScriptVerificationWorker.d.ts +2 -0
- package/dist/tools/verification/JavaScriptVerificationWorker.d.ts.map +1 -0
- package/dist/tools/verification/JavaScriptVerificationWorker.js +91 -0
- package/dist/tools/verification/VitestTool.d.ts +3 -0
- package/dist/tools/verification/VitestTool.d.ts.map +1 -0
- package/dist/tools/verification/VitestTool.js +128 -0
- package/package.json +16 -5
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// Runs only in the separate OS-isolated verification process. vm separates the
|
|
2
|
+
// observation harness from the submitted program; it is NOT the security boundary.
|
|
3
|
+
import { readFileSync } from "node:fs";
|
|
4
|
+
import vm from "node:vm";
|
|
5
|
+
const input = JSON.parse(readFileSync("input.json", "utf8"));
|
|
6
|
+
const observations = [];
|
|
7
|
+
for (const args of input.inputs) {
|
|
8
|
+
const context = vm.createContext(Object.create(null), { codeGeneration: { strings: false, wasm: false }, microtaskMode: "afterEvaluate" });
|
|
9
|
+
// Capture intrinsics before evaluating submitted code. Serialize data without
|
|
10
|
+
// calling guest toJSON methods or accessors, and reject non-JSON results.
|
|
11
|
+
const observe = vm.runInContext(`(() => {
|
|
12
|
+
const parse = JSON.parse, stringify = JSON.stringify, apply = Reflect.apply, string = String;
|
|
13
|
+
const descriptors = Object.getOwnPropertyDescriptors, prototype = Object.getPrototypeOf;
|
|
14
|
+
const objectPrototype = Object.prototype, arrayPrototype = Array.prototype;
|
|
15
|
+
const isArray = Array.isArray, finite = Number.isFinite, keys = Object.keys;
|
|
16
|
+
const hasOwn = Object.hasOwn;
|
|
17
|
+
function encode(value, depth = 0, seen = []) {
|
|
18
|
+
if (depth > 32 || seen.length > 10000) throw 'Result exceeds JSON limits';
|
|
19
|
+
if (value === null || typeof value === 'boolean' || typeof value === 'string') return stringify(value);
|
|
20
|
+
if (typeof value === 'number' && finite(value)) return stringify(value);
|
|
21
|
+
if (typeof value !== 'object') throw 'Expected finite JSON data';
|
|
22
|
+
for (let i = 0; i < seen.length; i++) if (seen[i] === value) throw 'Cyclic result';
|
|
23
|
+
seen[seen.length] = value;
|
|
24
|
+
const array = isArray(value), proto = prototype(value);
|
|
25
|
+
if (proto !== null && proto !== (array ? arrayPrototype : objectPrototype)) throw 'Expected plain JSON data';
|
|
26
|
+
const fields = descriptors(value), names = keys(fields);
|
|
27
|
+
let text = array ? '[' : '{', count = 0;
|
|
28
|
+
const length = array ? fields.length.value : names.length;
|
|
29
|
+
if (length > 10000) throw 'Result exceeds JSON limits';
|
|
30
|
+
for (let i = 0; i < length; i++) {
|
|
31
|
+
const key = array ? string(i) : names[i], field = fields[key];
|
|
32
|
+
if (!field || !hasOwn(field, 'value')) throw 'Sparse arrays and accessors are unsupported';
|
|
33
|
+
if (!array && !field.enumerable) continue;
|
|
34
|
+
if (count++) text += ',';
|
|
35
|
+
if (!array) text += stringify(key) + ':';
|
|
36
|
+
text += encode(field.value, depth + 1, seen);
|
|
37
|
+
if (text.length > 32768) throw 'Result exceeds JSON limits';
|
|
38
|
+
}
|
|
39
|
+
seen.length--;
|
|
40
|
+
return text + (array ? ']' : '}');
|
|
41
|
+
}
|
|
42
|
+
return (fn, encoded) => {
|
|
43
|
+
const args = parse(encoded), before = encode(args);
|
|
44
|
+
const result = apply(fn, undefined, args);
|
|
45
|
+
const actual = encode(result), unchanged = before === encode(args);
|
|
46
|
+
return '{"actual":' + actual + ',"inputPreserved":' + unchanged + '}';
|
|
47
|
+
};
|
|
48
|
+
})()`, context, { timeout: 250 });
|
|
49
|
+
// No buffers/native APIs are needed for this synchronous JSON-only tool.
|
|
50
|
+
vm.runInContext(`
|
|
51
|
+
for (const intrinsic of [Object, Array, Function, String, Number, Boolean, JSON, Reflect]) Object.freeze(intrinsic.prototype ?? intrinsic);
|
|
52
|
+
for (const name of ['console','ArrayBuffer','SharedArrayBuffer','WebAssembly','DataView','Int8Array','Uint8Array','Uint8ClampedArray','Int16Array','Uint16Array','Int32Array','Uint32Array','Float32Array','Float64Array','BigInt64Array','BigUint64Array']) delete globalThis[name];
|
|
53
|
+
`, context, { timeout: 250 });
|
|
54
|
+
try {
|
|
55
|
+
const module = new vm.SourceTextModule(input.source, { context, identifier: "submission.mjs" });
|
|
56
|
+
// Reject imports without passing a host Error/function into the guest realm.
|
|
57
|
+
await module.link(async () => { throw undefined; });
|
|
58
|
+
const evaluation = module.evaluate({ timeout: 250 });
|
|
59
|
+
// Node 20 can leave evaluate() awaiting the inner context's promise queue.
|
|
60
|
+
// Drain after the outer await handlers are registered, still under timeout.
|
|
61
|
+
// Keep afterEvaluate: removing it lets guest microtasks escape that timeout.
|
|
62
|
+
const drained = new Promise((resolve, reject) => {
|
|
63
|
+
// Drain before Node's end-of-turn unhandled-rejection check as well.
|
|
64
|
+
queueMicrotask(() => {
|
|
65
|
+
try {
|
|
66
|
+
vm.runInContext("", context, { timeout: 250 });
|
|
67
|
+
resolve();
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
reject(undefined);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
await Promise.all([evaluation, drained]);
|
|
75
|
+
const fn = module.namespace[input.entry];
|
|
76
|
+
if (typeof fn !== "function")
|
|
77
|
+
throw undefined;
|
|
78
|
+
context.__codaliObserve = observe;
|
|
79
|
+
context.__codaliFunction = fn;
|
|
80
|
+
context.__codaliInput = JSON.stringify(args);
|
|
81
|
+
const encoded = vm.runInContext("__codaliObserve(__codaliFunction, __codaliInput)", context, { timeout: 250 });
|
|
82
|
+
if (typeof encoded !== "string" || encoded.length > 40000)
|
|
83
|
+
throw undefined;
|
|
84
|
+
observations.push(JSON.parse(encoded));
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
// Never inspect/stringify a guest exception: its getters may execute code.
|
|
88
|
+
observations.push({ error: "Program failed, timed out, imported a module, or returned unsupported non-JSON data" });
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
process.stdout.write(JSON.stringify({ observations }));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VitestTool.d.ts","sourceRoot":"","sources":["../../../src/tools/verification/VitestTool.ts"],"names":[],"mappings":"AAMA,OAAO,EAAsB,KAAK,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAyC1E,eAAO,MAAM,gBAAgB,QAAO,cA2DlC,CAAC"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { promises as fs } from "node:fs";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import { createHash } from "node:crypto";
|
|
4
|
+
import os from "node:os";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { createIsolatedExecutor } from "../shell/IsolatedExecutor.js";
|
|
7
|
+
import { ToolExecutionError } from "../ToolTypes.js";
|
|
8
|
+
/** Resolve only the installed runner's dependency closure, never a workspace config. */
|
|
9
|
+
async function runnerRuntime() {
|
|
10
|
+
const require = createRequire(import.meta.url);
|
|
11
|
+
const entry = await fs.realpath(path.dirname(require.resolve("vitest/package.json")));
|
|
12
|
+
const seen = new Set(), mounts = new Set();
|
|
13
|
+
const visit = async (root) => {
|
|
14
|
+
if (seen.has(root))
|
|
15
|
+
return;
|
|
16
|
+
if (seen.size >= 256)
|
|
17
|
+
throw Error("Test runner dependency closure is unexpectedly large");
|
|
18
|
+
seen.add(root);
|
|
19
|
+
const manifest = JSON.parse(await fs.readFile(path.join(root, "package.json"), "utf8"));
|
|
20
|
+
const marker = `${path.sep}node_modules${path.sep}.pnpm${path.sep}`;
|
|
21
|
+
const at = root.lastIndexOf(marker);
|
|
22
|
+
if (at >= 0) {
|
|
23
|
+
const containerEnd = root.indexOf(`${path.sep}node_modules${path.sep}`, at + marker.length);
|
|
24
|
+
mounts.add(root.slice(0, containerEnd + "/node_modules".length));
|
|
25
|
+
}
|
|
26
|
+
else
|
|
27
|
+
mounts.add(root);
|
|
28
|
+
const resolver = createRequire(path.join(root, "package.json"));
|
|
29
|
+
const optional = manifest.optionalDependencies ?? {};
|
|
30
|
+
for (const dep of Object.keys({ ...manifest.dependencies, ...optional })) {
|
|
31
|
+
let resolved;
|
|
32
|
+
for (const candidate of resolver.resolve.paths(dep) ?? []) {
|
|
33
|
+
try {
|
|
34
|
+
const file = path.join(candidate, dep, "package.json");
|
|
35
|
+
const pkg = JSON.parse(await fs.readFile(file, "utf8"));
|
|
36
|
+
if (pkg.name === dep) {
|
|
37
|
+
resolved = await fs.realpath(path.dirname(file));
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
catch { /* Try the next installed module search path. */ }
|
|
42
|
+
}
|
|
43
|
+
if (resolved)
|
|
44
|
+
await visit(resolved);
|
|
45
|
+
else if (!Object.prototype.hasOwnProperty.call(optional, dep))
|
|
46
|
+
throw Error(`Missing installed runner dependency: ${dep}`);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
await visit(entry);
|
|
50
|
+
const version = JSON.parse(await fs.readFile(path.join(entry, "package.json"), "utf8")).version;
|
|
51
|
+
// This patched v3 release installs on Node 20/22's npm without the v4.1
|
|
52
|
+
// optional Vite/devtools peer cycle (npm/cli#9787). No peer checks are disabled.
|
|
53
|
+
if (version !== "3.2.7")
|
|
54
|
+
throw Error("Vitest runtime does not match the pinned version");
|
|
55
|
+
return { entry, version, mounts: [...mounts] };
|
|
56
|
+
}
|
|
57
|
+
export const createVitestTool = () => ({
|
|
58
|
+
name: "verify_tests", readOnly: true, capability: "verification",
|
|
59
|
+
description: "Run Vitest on supplied JS/TS source and *.test.js/ts files in an offline temporary sandbox. Import vitest and supplied relative modules. No workspace/config/credentials. Reports supplied-test results, not independent proof; prefer verify_javascript for simple synchronous JSON cases.",
|
|
60
|
+
inputSchema: { type: "object", properties: { files: { type: "array", minItems: 1, maxItems: 12, items: { type: "object", properties: {
|
|
61
|
+
path: { type: "string", minLength: 1, maxLength: 160 }, content: { type: "string", maxLength: 24000 },
|
|
62
|
+
}, required: ["path", "content"], additionalProperties: false } } }, required: ["files"], additionalProperties: false },
|
|
63
|
+
handler: async (raw, context) => {
|
|
64
|
+
context.signal?.throwIfAborted();
|
|
65
|
+
const args = raw;
|
|
66
|
+
const payload = JSON.stringify(args);
|
|
67
|
+
if (payload.length > 96000 || !Array.isArray(args.files) || !args.files.length || args.files.length > 12
|
|
68
|
+
|| args.files.some(file => !/^(?:[A-Za-z0-9_-]+\/)*[A-Za-z0-9_.-]+\.(?:[cm]?js|ts)$/.test(file.path)
|
|
69
|
+
|| file.path.split("/").some(segment => segment === "node_modules" || segment.startsWith(".")) || /(?:^|\/)(?:vite|vitest)\.config\./.test(file.path)
|
|
70
|
+
|| typeof file.content !== "string" || file.content.length > 24000)
|
|
71
|
+
|| new Set(args.files.map(file => file.path)).size !== args.files.length || !args.files.some(file => /\.test\.(?:[cm]?js|ts)$/.test(file.path))) {
|
|
72
|
+
throw new ToolExecutionError("tool_invalid_args", "Supply up to 12 bounded source/test files with relative paths, including a *.test.js/ts file; no configs or node_modules");
|
|
73
|
+
}
|
|
74
|
+
const runtime = await runnerRuntime();
|
|
75
|
+
const root = await fs.mkdtemp(path.join(os.tmpdir(), "codali-vitest-"));
|
|
76
|
+
const started = Date.now();
|
|
77
|
+
try {
|
|
78
|
+
await fs.chmod(root, 0o700);
|
|
79
|
+
for (const file of args.files) {
|
|
80
|
+
const target = path.join(root, file.path);
|
|
81
|
+
await fs.mkdir(path.dirname(target), { recursive: true });
|
|
82
|
+
await fs.writeFile(target, file.content);
|
|
83
|
+
}
|
|
84
|
+
await fs.writeFile(path.join(root, "package.json"), '{"type":"module"}');
|
|
85
|
+
await fs.mkdir(path.join(root, "node_modules"));
|
|
86
|
+
await fs.symlink(runtime.entry, path.join(root, "node_modules", "vitest"));
|
|
87
|
+
await fs.mkdir(path.join(root, "artifacts"));
|
|
88
|
+
const config = { cacheDir: path.join(root, "artifacts", "cache"), server: { host: "127.0.0.1", hmr: false }, test: { include: ["**/*.test.{js,ts,mjs,cjs}"], environment: "node", globals: false,
|
|
89
|
+
// macOS denies signaling separate child processes inside this sandbox.
|
|
90
|
+
// Threads retain the same OS boundary without requiring signal grants.
|
|
91
|
+
pool: "threads", maxWorkers: 1, fileParallelism: false, testTimeout: 1000, hookTimeout: 1000, passWithNoTests: false, reporters: ["json"], outputFile: path.join(root, "artifacts", "report.json") } };
|
|
92
|
+
await fs.writeFile(path.join(root, "codali.config.mjs"), `export default ${JSON.stringify(config)};`);
|
|
93
|
+
let exitCode = 0;
|
|
94
|
+
let executionFailure;
|
|
95
|
+
try {
|
|
96
|
+
await createIsolatedExecutor({ network: false, readOnlyRuntimeRoots: runtime.mounts })(process.execPath, ["--max-old-space-size=256", path.join(runtime.entry, "vitest.mjs"), "run", "--config", path.join(root, "codali.config.mjs"), "--configLoader", "native"], { workspaceRoot: root, signal: context.signal, allowedWritePaths: ["artifacts"], shellTimeoutMs: 15000, shellMaxOutputBytes: 128000 });
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
if (!(error instanceof ToolExecutionError) || error.code !== "tool_execution_failed" || error.details?.exitCode !== 1)
|
|
100
|
+
throw error;
|
|
101
|
+
exitCode = 1;
|
|
102
|
+
executionFailure = error;
|
|
103
|
+
}
|
|
104
|
+
const reportPath = path.join(root, "artifacts", "report.json");
|
|
105
|
+
let reportStat;
|
|
106
|
+
try {
|
|
107
|
+
reportStat = await fs.lstat(reportPath);
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
throw executionFailure ?? error;
|
|
111
|
+
}
|
|
112
|
+
if (reportStat.isSymbolicLink() || !reportStat.isFile() || reportStat.size > 256000)
|
|
113
|
+
throw Error("Invalid test report");
|
|
114
|
+
const report = JSON.parse(await fs.readFile(reportPath, "utf8"));
|
|
115
|
+
if (!Number.isInteger(report.numTotalTests) || report.numTotalTests < 1 || !Array.isArray(report.testResults))
|
|
116
|
+
throw Error("No complete test results were produced");
|
|
117
|
+
const result = { library: "vitest", version: runtime.version, passed: exitCode === 0 && report.success === true && report.numFailedTests === 0 && report.numPassedTests === report.numTotalTests,
|
|
118
|
+
total: report.numTotalTests, passedTests: report.numPassedTests, failedTests: report.numFailedTests, pendingTests: report.numPendingTests,
|
|
119
|
+
assertions: report.testResults.flatMap((suite) => (suite.assertionResults ?? []).map(check => ({ name: check.fullName.slice(0, 200), status: check.status, failures: check.failureMessages?.map(message => message.slice(0, 500)).slice(0, 2) }))).slice(0, 64),
|
|
120
|
+
sourceSha256: createHash("sha256").update(payload).digest("hex"), elapsedMs: Date.now() - started,
|
|
121
|
+
scope: "Results reported by the supplied tests in an offline sandbox; not independent proof or a workspace test run" };
|
|
122
|
+
return { output: JSON.stringify(result), data: result };
|
|
123
|
+
}
|
|
124
|
+
finally {
|
|
125
|
+
await fs.rm(root, { recursive: true, force: true });
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
});
|
package/package.json
CHANGED
|
@@ -8,14 +8,25 @@
|
|
|
8
8
|
"url": "https://github.com/bekirdag/mcoda/issues"
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@mcoda/db": "0.1.135-codali.
|
|
12
|
-
"@mcoda/shared": "0.1.135-codali.
|
|
11
|
+
"@mcoda/db": "0.1.135-codali.29",
|
|
12
|
+
"@mcoda/shared": "0.1.135-codali.29",
|
|
13
13
|
"@modelcontextprotocol/sdk": "1.30.0",
|
|
14
|
+
"ajv": "8.20.0",
|
|
15
|
+
"browser-use": "0.9.0",
|
|
16
|
+
"decimal.js": "10.6.0",
|
|
17
|
+
"mathjs": "15.2.0",
|
|
18
|
+
"playwright-core": "1.64.1",
|
|
19
|
+
"string-width": "8.3.0",
|
|
20
|
+
"vitest": "3.2.7",
|
|
21
|
+
"yaml": "2.9.0",
|
|
14
22
|
"zod": "4.5.2"
|
|
15
23
|
},
|
|
16
24
|
"description": "Standalone tool-runner adapter for mcoda.",
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"esbuild": "0.28.2"
|
|
27
|
+
},
|
|
17
28
|
"engines": {
|
|
18
|
-
"node": ">=
|
|
29
|
+
"node": "^20.19.0 || ^22.12.0 || >=24.0.0"
|
|
19
30
|
},
|
|
20
31
|
"files": [
|
|
21
32
|
"dist",
|
|
@@ -39,11 +50,11 @@
|
|
|
39
50
|
"url": "git+https://github.com/bekirdag/mcoda.git"
|
|
40
51
|
},
|
|
41
52
|
"scripts": {
|
|
42
|
-
"build": "tsc -p tsconfig.json",
|
|
53
|
+
"build": "tsc -p tsconfig.json && node scripts/build-deterministic.mjs",
|
|
43
54
|
"lint": "echo \"lint not configured\"",
|
|
44
55
|
"test": "pnpm run build && node ../../scripts/run-node-tests.js dist"
|
|
45
56
|
},
|
|
46
57
|
"type": "module",
|
|
47
58
|
"types": "dist/index.d.ts",
|
|
48
|
-
"version": "0.1.135-codali.
|
|
59
|
+
"version": "0.1.135-codali.29"
|
|
49
60
|
}
|