@mcoda/codali 0.1.135-codali.29 → 0.1.135-codali.32
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 +35 -0
- package/ORCHESTRATION.md +67 -38
- package/README.md +51 -16
- package/config/AGENTS.md +6 -0
- package/config/browser-desktop/Dockerfile +7 -0
- package/config/browser-desktop/preview.py +15 -0
- package/config/browser-desktop/start.sh +12 -0
- package/config/deterministic/python-worker.py +18 -3
- package/config/orchestration.schema.json +46 -6
- package/config/skills/architecture-design/SKILL.md +14 -0
- package/config/skills/browser-session/SKILL.md +16 -0
- package/config/skills/browser-use/SKILL.md +14 -0
- package/config/skills/code-implementation/SKILL.md +18 -0
- package/config/skills/code-review/SKILL.md +14 -0
- package/config/skills/docdex-research/SKILL.md +18 -0
- package/config/skills/docdex-research/references/catalog.md +111 -0
- package/config/skills/docdex-research/references/memory.md +22 -0
- package/config/skills/docdex-research/references/operations.md +19 -0
- package/config/skills/docdex-research/references/retrieval.md +13 -0
- package/config/skills/planning/SKILL.md +9 -8
- package/config/skills/system-diagnostics/SKILL.md +14 -0
- package/config/skills/system-services/SKILL.md +17 -0
- package/config/skills/system-services/references/docker.md +11 -0
- package/config/skills/system-services/references/linux.md +9 -0
- package/config/skills/system-services/references/macos.md +9 -0
- package/config/skills/systematic-debugging/SKILL.md +14 -0
- package/config/skills/testing-and-verification/SKILL.md +16 -0
- package/config/skills/tool-selection/SKILL.md +16 -0
- package/config/skills/ui-ux-design/SKILL.md +16 -0
- package/config/skills/ui-ux-design/references/validation.md +13 -0
- package/config/skills/webapp-testing/SKILL.md +12 -0
- package/dist/cli/TerminalCommand.d.ts +2 -1
- package/dist/cli/TerminalCommand.d.ts.map +1 -1
- package/dist/cli/TerminalCommand.js +27 -27
- package/dist/cli/tui/TerminalPresentation.d.ts +2 -0
- package/dist/cli/tui/TerminalPresentation.d.ts.map +1 -1
- package/dist/cli/tui/TerminalPresentation.js +77 -2
- package/dist/cli/tui/TerminalTui.d.ts.map +1 -1
- package/dist/cli/tui/TerminalTui.js +14 -3
- package/dist/config/OrchestrationConfig.d.ts +7 -0
- package/dist/config/OrchestrationConfig.d.ts.map +1 -1
- package/dist/config/OrchestrationConfig.js +15 -2
- package/dist/docdex/DocdexClient.d.ts +1 -0
- package/dist/docdex/DocdexClient.d.ts.map +1 -1
- package/dist/docdex/DocdexClient.js +1 -1
- package/dist/docdex/ManagedDocdex.d.ts +3 -0
- package/dist/docdex/ManagedDocdex.d.ts.map +1 -1
- package/dist/docdex/ManagedDocdex.js +17 -1
- package/dist/gateway/GroundingMode.d.ts.map +1 -1
- package/dist/gateway/GroundingMode.js +23 -3
- package/dist/permissions/PermissionGate.d.ts.map +1 -1
- package/dist/permissions/PermissionGate.js +7 -5
- package/dist/providers/ConfiguredModelScope.d.ts.map +1 -1
- package/dist/providers/ConfiguredModelScope.js +2 -1
- package/dist/providers/ConfiguredProvider.d.ts +1 -0
- package/dist/providers/ConfiguredProvider.d.ts.map +1 -1
- package/dist/providers/ConfiguredProvider.js +51 -30
- package/dist/providers/ModelCapacityWait.d.ts +21 -0
- package/dist/providers/ModelCapacityWait.d.ts.map +1 -0
- package/dist/providers/ModelCapacityWait.js +40 -0
- package/dist/providers/ModelServiceError.d.ts +11 -2
- package/dist/providers/ModelServiceError.d.ts.map +1 -1
- package/dist/providers/ModelServiceError.js +13 -5
- package/dist/providers/OpenAiCompatibleProvider.d.ts.map +1 -1
- package/dist/providers/OpenAiCompatibleProvider.js +20 -5
- package/dist/providers/ProviderTypes.d.ts +4 -0
- package/dist/providers/ProviderTypes.d.ts.map +1 -1
- package/dist/providers/RequestSize.d.ts +5 -0
- package/dist/providers/RequestSize.d.ts.map +1 -0
- package/dist/providers/RequestSize.js +10 -0
- package/dist/runtime/AnswerVerification.d.ts +17 -0
- package/dist/runtime/AnswerVerification.d.ts.map +1 -0
- package/dist/runtime/AnswerVerification.js +39 -0
- package/dist/runtime/CompletionReport.d.ts +2 -0
- package/dist/runtime/CompletionReport.d.ts.map +1 -1
- package/dist/runtime/CompletionReport.js +17 -0
- package/dist/runtime/ContextCompression.d.ts +19 -3
- package/dist/runtime/ContextCompression.d.ts.map +1 -1
- package/dist/runtime/ContextCompression.js +224 -14
- package/dist/runtime/GatewayRequest.d.ts +5 -0
- package/dist/runtime/GatewayRequest.d.ts.map +1 -0
- package/dist/runtime/GatewayRequest.js +19 -0
- package/dist/runtime/InspectionBudget.d.ts +4 -1
- package/dist/runtime/InspectionBudget.d.ts.map +1 -1
- package/dist/runtime/InspectionBudget.js +14 -16
- package/dist/runtime/InspectionConvergence.d.ts +24 -0
- package/dist/runtime/InspectionConvergence.d.ts.map +1 -0
- package/dist/runtime/InspectionConvergence.js +67 -0
- package/dist/runtime/InteractionContract.d.ts +2 -0
- package/dist/runtime/InteractionContract.d.ts.map +1 -1
- package/dist/runtime/InteractionContract.js +14 -0
- package/dist/runtime/InteractionRouter.d.ts +6 -4
- package/dist/runtime/InteractionRouter.d.ts.map +1 -1
- package/dist/runtime/InteractionRouter.js +15 -11
- package/dist/runtime/PlanCoverage.d.ts +9 -0
- package/dist/runtime/PlanCoverage.d.ts.map +1 -0
- package/dist/runtime/PlanCoverage.js +12 -0
- package/dist/runtime/ProgressTracker.d.ts +1 -0
- package/dist/runtime/ProgressTracker.d.ts.map +1 -1
- package/dist/runtime/ProgressTracker.js +25 -5
- package/dist/runtime/ResearchEvidence.d.ts +19 -0
- package/dist/runtime/ResearchEvidence.d.ts.map +1 -0
- package/dist/runtime/ResearchEvidence.js +55 -0
- package/dist/runtime/ReviewCoordinator.d.ts +2 -0
- package/dist/runtime/ReviewCoordinator.d.ts.map +1 -1
- package/dist/runtime/ReviewCoordinator.js +3 -1
- package/dist/runtime/SessionController.d.ts +20 -4
- package/dist/runtime/SessionController.d.ts.map +1 -1
- package/dist/runtime/SessionController.js +869 -213
- package/dist/runtime/SpecialistTools.d.ts +6 -0
- package/dist/runtime/SpecialistTools.d.ts.map +1 -0
- package/dist/runtime/SpecialistTools.js +69 -0
- package/dist/runtime/StructuralEvidence.d.ts +4 -2
- package/dist/runtime/StructuralEvidence.d.ts.map +1 -1
- package/dist/runtime/StructuralEvidence.js +22 -5
- package/dist/runtime/WorkspaceLedger.d.ts +2 -0
- package/dist/runtime/WorkspaceLedger.d.ts.map +1 -1
- package/dist/runtime/WorkspaceLedger.js +44 -20
- package/dist/runtime/WorkspaceLock.d.ts.map +1 -1
- package/dist/runtime/WorkspaceLock.js +9 -1
- package/dist/runtime/WorkspaceSnapshot.d.ts.map +1 -1
- package/dist/runtime/WorkspaceSnapshot.js +3 -2
- package/dist/runtime/WriteSyntaxCheck.d.ts +10 -0
- package/dist/runtime/WriteSyntaxCheck.d.ts.map +1 -0
- package/dist/runtime/WriteSyntaxCheck.js +34 -0
- package/dist/session/SessionStoragePath.d.ts.map +1 -1
- package/dist/session/SessionStoragePath.js +7 -2
- package/dist/session/SkillCatalog.d.ts.map +1 -1
- package/dist/session/SkillCatalog.js +6 -3
- package/dist/session/WorkState.d.ts +2 -0
- package/dist/session/WorkState.d.ts.map +1 -1
- package/dist/session/WorkState.js +14 -2
- package/dist/session/WorkspaceScope.d.ts +3 -0
- package/dist/session/WorkspaceScope.d.ts.map +1 -0
- package/dist/session/WorkspaceScope.js +19 -0
- package/dist/tools/ToolTypes.d.ts +2 -0
- package/dist/tools/ToolTypes.d.ts.map +1 -1
- package/dist/tools/browser/BrowserSessionTool.d.ts +16 -0
- package/dist/tools/browser/BrowserSessionTool.d.ts.map +1 -0
- package/dist/tools/browser/BrowserSessionTool.js +326 -0
- package/dist/tools/browser/BrowserTool.d.ts +8 -0
- package/dist/tools/browser/BrowserTool.d.ts.map +1 -1
- package/dist/tools/browser/BrowserTool.js +152 -13
- package/dist/tools/browser/BrowserWorker.js +74 -4
- package/dist/tools/calculation/CalculatorTool.d.ts.map +1 -1
- package/dist/tools/calculation/CalculatorTool.js +33 -7
- package/dist/tools/deterministic/DeterministicTools.d.ts.map +1 -1
- package/dist/tools/deterministic/DeterministicTools.js +17 -3
- package/dist/tools/deterministic/python-worker.py +18 -3
- package/dist/tools/docdex/DocdexCatalogTools.d.ts.map +1 -1
- package/dist/tools/docdex/DocdexCatalogTools.js +2 -1
- package/dist/tools/docdex/DocdexTools.js +10 -2
- package/dist/tools/filesystem/FileTools.d.ts.map +1 -1
- package/dist/tools/filesystem/FileTools.js +58 -11
- package/dist/tools/shell/AsyncProcess.d.ts +4 -0
- package/dist/tools/shell/AsyncProcess.d.ts.map +1 -1
- package/dist/tools/shell/AsyncProcess.js +9 -3
- package/dist/tools/shell/HostToolchain.d.ts.map +1 -1
- package/dist/tools/shell/HostToolchain.js +19 -1
- 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 +93 -28
- package/dist/tools/shell/ShellTool.d.ts +2 -0
- package/dist/tools/shell/ShellTool.d.ts.map +1 -1
- package/dist/tools/shell/ShellTool.js +18 -4
- package/dist/tools/system/CalendarTool.d.ts +15 -0
- package/dist/tools/system/CalendarTool.d.ts.map +1 -0
- package/dist/tools/system/CalendarTool.js +44 -0
- package/dist/tools/system/TextTool.d.ts +4 -0
- package/dist/tools/system/TextTool.d.ts.map +1 -0
- package/dist/tools/system/TextTool.js +39 -0
- package/dist/tools/verification/VitestTool.d.ts +3 -0
- package/dist/tools/verification/VitestTool.d.ts.map +1 -1
- package/dist/tools/verification/VitestTool.js +65 -9
- package/package.json +4 -3
|
@@ -7,10 +7,10 @@ import { resolveShellWorkingDirectory } from "./ShellWorkingDirectory.js";
|
|
|
7
7
|
import { ToolExecutionError } from "../ToolTypes.js";
|
|
8
8
|
import { discoverHostToolchain, extraRuntimeMounts } from "./HostToolchain.js";
|
|
9
9
|
/** All paths have been canonicalized by the host, before launching the sandbox. */
|
|
10
|
-
export const darwinSandboxProfile = (root, scratch, writePaths, runtimes, network = false, runtimeRoots = []) => {
|
|
10
|
+
export const darwinSandboxProfile = (root, scratch, writePaths, runtimes, network = false, runtimeRoots = [], protectedPaths = [], cacheRoot) => {
|
|
11
11
|
const quoted = (value) => JSON.stringify(value);
|
|
12
12
|
const ancestors = new Set();
|
|
13
|
-
for (const target of [root, scratch, ...runtimeRoots, ...extraRuntimeMounts(runtimes).map(runtime => runtime.readOnlyRoot)]) {
|
|
13
|
+
for (const target of [root, scratch, ...(cacheRoot ? [cacheRoot] : []), ...runtimeRoots, ...extraRuntimeMounts(runtimes).map(runtime => runtime.readOnlyRoot)]) {
|
|
14
14
|
for (let parent = path.dirname(target); parent !== path.dirname(parent); parent = path.dirname(parent))
|
|
15
15
|
ancestors.add(parent);
|
|
16
16
|
}
|
|
@@ -35,8 +35,10 @@ export const darwinSandboxProfile = (root, scratch, writePaths, runtimes, networ
|
|
|
35
35
|
...runtimeRoots.map(runtime => `(allow file-read* (subpath ${quoted(runtime)}))`),
|
|
36
36
|
...extraRuntimeMounts(runtimes).map(runtime => `(allow file-read* (${runtime.directory ? "subpath" : "literal"} ${quoted(runtime.readOnlyRoot)}))`),
|
|
37
37
|
`(allow file-read* file-write* (subpath ${quoted(scratch)}))`,
|
|
38
|
+
...(cacheRoot ? [`(allow file-read* file-write* (subpath ${quoted(cacheRoot)}))`, `(deny file-write-unlink (literal ${quoted(cacheRoot)}))`] : []),
|
|
38
39
|
...writePaths.map(file => `(allow file-write* (subpath ${quoted(file)}))`),
|
|
39
40
|
...[".git", ".mcoda"].map(dir => `(deny file-write* (subpath ${quoted(path.join(root, dir))}))`),
|
|
41
|
+
...protectedPaths.map(file => `(deny file-write* (subpath ${quoted(file)}))`),
|
|
40
42
|
network ? "(allow network*)" : "(deny network*)",
|
|
41
43
|
].join("\n");
|
|
42
44
|
};
|
|
@@ -50,6 +52,14 @@ const bubblewrapRoot = () => {
|
|
|
50
52
|
// or the other configured alternatives. ffprobe needs these on Ubuntu 22.04.
|
|
51
53
|
if (existsSync("/etc/ld.so.cache"))
|
|
52
54
|
args.push("--ro-bind", "/etc/ld.so.cache", "/etc/ld.so.cache");
|
|
55
|
+
// Toolchain installers inspect this public distribution descriptor. Do not
|
|
56
|
+
// expose all of /etc merely to identify the operating system.
|
|
57
|
+
if (existsSync("/etc/os-release"))
|
|
58
|
+
args.push("--ro-bind", realpathSync("/etc/os-release"), "/etc/os-release");
|
|
59
|
+
// Public system font selection is needed for reproducible browser rendering.
|
|
60
|
+
// User font settings/profiles and the rest of /etc remain inaccessible.
|
|
61
|
+
if (existsSync("/etc/fonts"))
|
|
62
|
+
args.push("--ro-bind", realpathSync("/etc/fonts"), "/etc/fonts");
|
|
53
63
|
if (existsSync("/etc/alternatives"))
|
|
54
64
|
for (const name of readdirSync("/etc/alternatives")) {
|
|
55
65
|
if (!/^lib[^/]+\.so(?:\..+)?$/.test(name))
|
|
@@ -84,6 +94,26 @@ export const executorStatus = () => {
|
|
|
84
94
|
}
|
|
85
95
|
return { available: false, backend: "unavailable", reason: "No supported isolation backend on this platform" };
|
|
86
96
|
};
|
|
97
|
+
const packageCacheEnvironment = (root) => ({
|
|
98
|
+
NPM_CONFIG_CACHE: path.join(root, "npm"), GRADLE_USER_HOME: path.join(root, "gradle"),
|
|
99
|
+
PIP_CACHE_DIR: path.join(root, "pip"), UV_CACHE_DIR: path.join(root, "uv"),
|
|
100
|
+
CARGO_HOME: path.join(root, "cargo"), XDG_CACHE_HOME: path.join(root, "xdg"),
|
|
101
|
+
});
|
|
102
|
+
/** Disposable, workspace-specific cache. Never mount an existing host package cache or credentials. */
|
|
103
|
+
const preparePackageCache = async (requested, workspace) => {
|
|
104
|
+
const absolute = path.resolve(requested);
|
|
105
|
+
const unsafe = (value) => value === path.parse(value).root || value === realpathSync(os.homedir())
|
|
106
|
+
|| value === workspace || workspace.startsWith(`${value}${path.sep}`) || value.startsWith(`${workspace}${path.sep}`);
|
|
107
|
+
if (unsafe(absolute))
|
|
108
|
+
throw new ToolExecutionError("tool_permission_denied", "Package cache must be a private dedicated directory outside the workspace");
|
|
109
|
+
await fs.mkdir(absolute, { recursive: true, mode: 0o700 });
|
|
110
|
+
const stat = await fs.lstat(absolute), real = await fs.realpath(absolute);
|
|
111
|
+
if (stat.isSymbolicLink() || !stat.isDirectory() || unsafe(real)
|
|
112
|
+
|| (process.getuid && stat.uid !== process.getuid()) || (stat.mode & 0o077) !== 0) {
|
|
113
|
+
throw new ToolExecutionError("tool_permission_denied", "Package cache must be an owned private directory, not a symlink");
|
|
114
|
+
}
|
|
115
|
+
return real;
|
|
116
|
+
};
|
|
87
117
|
export const createIsolatedExecutor = (options = {}) => {
|
|
88
118
|
const status = options.status ?? executorStatus();
|
|
89
119
|
return async (command, args, context) => {
|
|
@@ -93,7 +123,19 @@ export const createIsolatedExecutor = (options = {}) => {
|
|
|
93
123
|
const cwd = resolveShellWorkingDirectory(root, context.shellWorkingDirectory);
|
|
94
124
|
if (root === path.parse(root).root)
|
|
95
125
|
throw new ToolExecutionError("tool_permission_denied", "Filesystem root cannot be an isolated workspace");
|
|
126
|
+
const cacheRoot = options.cacheRoot ? await preparePackageCache(options.cacheRoot, root) : undefined;
|
|
96
127
|
const runtimes = discoverHostToolchain(root);
|
|
128
|
+
const protectedPaths = [...new Set((context.protectedPaths ?? []).flatMap(file => {
|
|
129
|
+
const requested = path.resolve(root, file);
|
|
130
|
+
if (requested === root || !requested.startsWith(`${root}${path.sep}`))
|
|
131
|
+
throw new ToolExecutionError("tool_permission_denied", "Protected input must be inside the workspace");
|
|
132
|
+
if (!existsSync(requested))
|
|
133
|
+
return [];
|
|
134
|
+
const real = realpathSync(requested);
|
|
135
|
+
if (!real.startsWith(`${root}${path.sep}`))
|
|
136
|
+
throw new ToolExecutionError("tool_permission_denied", "Protected input resolves outside the workspace");
|
|
137
|
+
return [requested, real];
|
|
138
|
+
}))];
|
|
97
139
|
const runtimeRoots = [...new Set((options.readOnlyRuntimeRoots ?? []).map(requested => {
|
|
98
140
|
const real = realpathSync(requested);
|
|
99
141
|
if (!statSync(real).isDirectory() || [path.parse(real).root, os.homedir(), context.workspaceRoot].some(forbidden => real === realpathSync(forbidden))
|
|
@@ -106,41 +148,63 @@ export const createIsolatedExecutor = (options = {}) => {
|
|
|
106
148
|
if (requested !== root && !requested.startsWith(`${root}${path.sep}`))
|
|
107
149
|
throw new ToolExecutionError("tool_permission_denied", "Shell write scope escapes workspace");
|
|
108
150
|
if (!existsSync(requested))
|
|
109
|
-
throw new ToolExecutionError("tool_permission_denied", "Create the scoped directory
|
|
151
|
+
throw new ToolExecutionError("tool_permission_denied", "Create the scoped directory with create_directory (or file with write_file) before shell execution");
|
|
110
152
|
const real = realpathSync(requested);
|
|
111
153
|
if (real !== root && !real.startsWith(`${root}${path.sep}`))
|
|
112
154
|
throw new ToolExecutionError("tool_permission_denied", "Shell write scope resolves outside workspace");
|
|
113
155
|
if ([".git", ".mcoda"].some(dir => real === path.join(root, dir) || real.startsWith(`${root}/${dir}/`)))
|
|
114
156
|
throw new ToolExecutionError("tool_permission_denied", "Repository control metadata cannot be a write scope");
|
|
157
|
+
if (protectedPaths.some(input => real === input || real.startsWith(`${input}${path.sep}`)))
|
|
158
|
+
throw new ToolExecutionError("tool_permission_denied", "Authoritative input cannot be a write scope");
|
|
115
159
|
return real;
|
|
116
160
|
});
|
|
117
161
|
if (status.backend === "bubblewrap") {
|
|
118
162
|
const launch = bubblewrapRoot();
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
163
|
+
let resolverRoot;
|
|
164
|
+
try {
|
|
165
|
+
if (!options.network) {
|
|
166
|
+
resolverRoot = await fs.mkdtemp(path.join(os.tmpdir(), "codali-resolver-"));
|
|
167
|
+
const hosts = path.join(resolverRoot, "hosts");
|
|
168
|
+
await fs.writeFile(hosts, "127.0.0.1 localhost\n::1 localhost\n", { mode: 0o600 });
|
|
169
|
+
launch.push("--ro-bind", hosts, "/etc/hosts");
|
|
170
|
+
}
|
|
171
|
+
if (options.network) {
|
|
172
|
+
launch.push("--share-net");
|
|
173
|
+
for (const file of ["/etc/resolv.conf", "/etc/hosts", "/etc/nsswitch.conf", "/etc/ssl/certs"])
|
|
174
|
+
if (existsSync(file))
|
|
175
|
+
launch.push("--ro-bind", realpathSync(file), file);
|
|
176
|
+
}
|
|
177
|
+
launch.push("--dir", path.dirname(root), "--ro-bind", root, root);
|
|
178
|
+
for (const runtime of extraRuntimeMounts(runtimes))
|
|
179
|
+
launch.push("--dir", path.dirname(runtime.readOnlyRoot), "--ro-bind", runtime.readOnlyRoot, runtime.readOnlyRoot);
|
|
180
|
+
for (const runtime of runtimeRoots)
|
|
181
|
+
launch.push("--dir", path.dirname(runtime), "--ro-bind", runtime, runtime);
|
|
182
|
+
launch.push("--dir", "/tmp/codali-bin");
|
|
183
|
+
for (const runtime of runtimes)
|
|
184
|
+
launch.push("--symlink", runtime.executable, `/tmp/codali-bin/${runtime.name}`);
|
|
185
|
+
for (const file of writePaths)
|
|
186
|
+
launch.push("--bind", file, file);
|
|
187
|
+
if (cacheRoot)
|
|
188
|
+
launch.push("--bind", cacheRoot, "/tmp/codali-cache");
|
|
189
|
+
launch.push("--chdir", cwd, "--dir", "/tmp/home", "--setenv", "HOME", "/tmp/home", "--setenv", "TMPDIR", "/tmp", "--setenv", "PATH", "/tmp/codali-bin:/usr/local/bin:/usr/bin:/bin");
|
|
190
|
+
for (const [key, value] of Object.entries({ CARGO_HOME: "/tmp/home/cargo", XDG_CACHE_HOME: "/tmp/home/cache", PYTHONPYCACHEPREFIX: "/tmp/home/pycache", PYTHONUSERBASE: "/tmp/home/python", GIT_CONFIG_NOSYSTEM: "1", GIT_CONFIG_GLOBAL: "/dev/null", GIT_ATTR_NOSYSTEM: "1" }))
|
|
191
|
+
launch.push("--setenv", key, value);
|
|
192
|
+
if (cacheRoot)
|
|
193
|
+
for (const [key, value] of Object.entries(packageCacheEnvironment("/tmp/codali-cache")))
|
|
194
|
+
launch.push("--setenv", key, value);
|
|
195
|
+
// Git hooks/config and private session state are not part of executable workspace access.
|
|
196
|
+
for (const dir of [".git", ".mcoda"])
|
|
197
|
+
if (existsSync(path.join(root, dir)))
|
|
198
|
+
launch.push("--ro-bind", path.join(root, dir), path.join(root, dir));
|
|
199
|
+
for (const file of protectedPaths)
|
|
200
|
+
launch.push("--ro-bind", realpathSync(file), file);
|
|
201
|
+
launch.push("--", command, ...args);
|
|
202
|
+
return await runProcess("/usr/bin/bwrap", launch, context);
|
|
203
|
+
}
|
|
204
|
+
finally {
|
|
205
|
+
if (resolverRoot)
|
|
206
|
+
await fs.rm(resolverRoot, { recursive: true, force: true });
|
|
124
207
|
}
|
|
125
|
-
launch.push("--dir", path.dirname(root), "--ro-bind", root, root);
|
|
126
|
-
for (const runtime of extraRuntimeMounts(runtimes))
|
|
127
|
-
launch.push("--dir", path.dirname(runtime.readOnlyRoot), "--ro-bind", runtime.readOnlyRoot, runtime.readOnlyRoot);
|
|
128
|
-
for (const runtime of runtimeRoots)
|
|
129
|
-
launch.push("--dir", path.dirname(runtime), "--ro-bind", runtime, runtime);
|
|
130
|
-
launch.push("--dir", "/tmp/codali-bin");
|
|
131
|
-
for (const runtime of runtimes)
|
|
132
|
-
launch.push("--symlink", runtime.executable, `/tmp/codali-bin/${runtime.name}`);
|
|
133
|
-
for (const file of writePaths)
|
|
134
|
-
launch.push("--bind", file, file);
|
|
135
|
-
launch.push("--chdir", cwd, "--dir", "/tmp/home", "--setenv", "HOME", "/tmp/home", "--setenv", "TMPDIR", "/tmp", "--setenv", "PATH", "/tmp/codali-bin:/usr/local/bin:/usr/bin:/bin");
|
|
136
|
-
for (const [key, value] of Object.entries({ CARGO_HOME: "/tmp/home/cargo", XDG_CACHE_HOME: "/tmp/home/cache", PYTHONPYCACHEPREFIX: "/tmp/home/pycache", PYTHONUSERBASE: "/tmp/home/python", GIT_CONFIG_NOSYSTEM: "1", GIT_CONFIG_GLOBAL: "/dev/null", GIT_ATTR_NOSYSTEM: "1" }))
|
|
137
|
-
launch.push("--setenv", key, value);
|
|
138
|
-
// Git hooks/config and private session state are not part of executable workspace access.
|
|
139
|
-
for (const dir of [".git", ".mcoda"])
|
|
140
|
-
if (existsSync(path.join(root, dir)))
|
|
141
|
-
launch.push("--ro-bind", path.join(root, dir), path.join(root, dir));
|
|
142
|
-
launch.push("--", command, ...args);
|
|
143
|
-
return runProcess("/usr/bin/bwrap", launch, context);
|
|
144
208
|
}
|
|
145
209
|
const scratch = realpathSync(await fs.mkdtemp(path.join(os.tmpdir(), "codali-shell-")));
|
|
146
210
|
try {
|
|
@@ -151,11 +215,12 @@ export const createIsolatedExecutor = (options = {}) => {
|
|
|
151
215
|
await fs.mkdir(privateBin, { mode: 0o700 });
|
|
152
216
|
for (const runtime of runtimes)
|
|
153
217
|
await fs.symlink(runtime.executable, path.join(privateBin, runtime.name));
|
|
154
|
-
const profile = darwinSandboxProfile(root, scratch, writePaths, runtimes, options.network, runtimeRoots);
|
|
218
|
+
const profile = darwinSandboxProfile(root, scratch, writePaths, runtimes, options.network, runtimeRoots, protectedPaths, cacheRoot);
|
|
155
219
|
return await runProcess("/usr/bin/sandbox-exec", ["-p", profile, runtimes.find(runtime => runtime.name === command)?.executable ?? command, ...args], context, {
|
|
156
220
|
...runtimes.find(runtime => runtime.name === "cc")?.environment,
|
|
157
221
|
HOME: privateHome, TMPDIR: scratch, PATH: `${privateBin}:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin`,
|
|
158
222
|
CARGO_HOME: path.join(privateHome, "cargo"), XDG_CACHE_HOME: path.join(privateHome, "cache"),
|
|
223
|
+
...(cacheRoot ? packageCacheEnvironment(cacheRoot) : {}),
|
|
159
224
|
PYTHONPYCACHEPREFIX: path.join(privateHome, "pycache"), PYTHONUSERBASE: path.join(privateHome, "python"),
|
|
160
225
|
// Host Git settings can invoke external helpers or read private paths.
|
|
161
226
|
GIT_CONFIG_NOSYSTEM: "1", GIT_CONFIG_GLOBAL: "/dev/null", GIT_ATTR_NOSYSTEM: "1",
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import { type ToolDefinition } from "../ToolTypes.js";
|
|
2
|
+
/** Shared by terminal execution and tool-enabled benchmark baselines. */
|
|
3
|
+
export declare const DEVELOPMENT_COMMANDS: string[];
|
|
2
4
|
export declare const createShellTool: () => ToolDefinition;
|
|
3
5
|
//# sourceMappingURL=ShellTool.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ShellTool.d.ts","sourceRoot":"","sources":["../../../src/tools/shell/ShellTool.ts"],"names":[],"mappings":"AACA,OAAO,EAAwC,KAAK,cAAc,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"ShellTool.d.ts","sourceRoot":"","sources":["../../../src/tools/shell/ShellTool.ts"],"names":[],"mappings":"AACA,OAAO,EAAwC,KAAK,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAI5F,yEAAyE;AACzE,eAAO,MAAM,oBAAoB,UAA8hB,CAAC;AA6ChkB,eAAO,MAAM,eAAe,QAAO,cA6DjC,CAAC"}
|
|
@@ -2,6 +2,8 @@ import path from "node:path";
|
|
|
2
2
|
import { ToolExecutionError } from "../ToolTypes.js";
|
|
3
3
|
import { runProcess } from "./AsyncProcess.js";
|
|
4
4
|
import { resolveShellWorkingDirectory } from "./ShellWorkingDirectory.js";
|
|
5
|
+
/** Shared by terminal execution and tool-enabled benchmark baselines. */
|
|
6
|
+
export const DEVELOPMENT_COMMANDS = ["git", "rg", "node", "npm", "pnpm", "npx", "python3", "pytest", "cargo", "rustc", "go", "make", "cmake", "tsc", "sh", "bash", "ls", "cat", "pwd", "expr", "printf", "head", "tail", "sed", "awk", "uname", "which", "env", "find", "wc", "sort", "uniq", "cut", "diff", "file", "stat", "du", "df", "mkdir", "touch", "cp", "mv", "curl", "wget", "tar", "unzip", "zip", "cc", "gcc", "g++", "clang", "clang++", "ar", "swift", "swiftc", "java", "javac", "xcrun", "xcodebuild", "google-chrome", "google-chrome-stable", "chromium", "chromium-browser"];
|
|
5
7
|
const resolveAllowlist = (context) => {
|
|
6
8
|
return context.shellAllowlist ?? [];
|
|
7
9
|
};
|
|
@@ -27,7 +29,9 @@ const DESTRUCTIVE_PATTERNS = [
|
|
|
27
29
|
/\bshred\b/,
|
|
28
30
|
/\bmkfs\b/,
|
|
29
31
|
/\bdd\b/,
|
|
30
|
-
|
|
32
|
+
// Swift's named argument and formatting methods are source syntax, not the
|
|
33
|
+
// disk-format command. Direct executable names are checked separately.
|
|
34
|
+
/(?<!\.)\bformat\b(?!\s*:)/,
|
|
31
35
|
/\bfs\.rm(?:sync)?\s*\(/,
|
|
32
36
|
/\bunlink(?:sync)?\s*\(/,
|
|
33
37
|
];
|
|
@@ -41,7 +45,7 @@ const isDestructiveShellAction = (command, args) => {
|
|
|
41
45
|
};
|
|
42
46
|
export const createShellTool = () => ({
|
|
43
47
|
name: "run_shell",
|
|
44
|
-
description: 'Run an allowlisted executable. Default cwd is the workspace root; set cwd for a module-local command, e.g. {"command":"npm","args":["test"],"cwd":"packages/app"}. In terminal mode the workspace is read-only unless writePaths names root-relative paths inside the claimed task. Existing source files in those paths require current reads and structural analysis.',
|
|
48
|
+
description: 'Run an allowlisted executable. Use $TMPDIR for transient per-call scratch space; scratch files, exports and cwd changes do not persist between calls. Save required project outputs in claimed workspace writePaths; create missing scoped files/directories with write_file/create_directory first. Package-manager cache environment variables point to persistent workspace-private caches; do not hardcode their paths. Each call is isolated and kills its background processes on return; nohup, setsid and tmux cannot keep a server alive. Use browser_session for persistent noVNC/static previews and browser_interact for official Browser Use. Default cwd is the workspace root; set cwd for a module-local command, e.g. {"command":"npm","args":["test"],"cwd":"packages/app"}. In terminal mode the workspace is read-only unless writePaths names root-relative paths inside the claimed task. Existing source files in those paths require current reads and structural analysis.',
|
|
45
49
|
readOnly: false,
|
|
46
50
|
capability: "shell",
|
|
47
51
|
inputSchema: {
|
|
@@ -75,12 +79,22 @@ export const createShellTool = () => ({
|
|
|
75
79
|
}
|
|
76
80
|
const allowlist = resolveAllowlist(context);
|
|
77
81
|
if (!allowlist.length || !allowlist.includes(command)) {
|
|
78
|
-
throw new ToolExecutionError("tool_permission_denied", `Command not allowed: ${command}`, {
|
|
82
|
+
throw new ToolExecutionError("tool_permission_denied", `Command not allowed: ${command.slice(0, 160)}. Available executables: ${allowlist.slice(0, 12).join(", ").slice(0, 700)}${allowlist.length > 12 ? " (first 12 shown)" : ""}`, {
|
|
79
83
|
retryable: false,
|
|
80
84
|
details: { command },
|
|
81
85
|
});
|
|
82
86
|
}
|
|
83
87
|
const shellWorkingDirectory = resolveShellWorkingDirectory(context.workspaceRoot, cwd);
|
|
84
|
-
|
|
88
|
+
const effectiveArgs = [...commandArgs];
|
|
89
|
+
if (command === "bash") {
|
|
90
|
+
// Bash requires long options before short options. Preserve caller flags
|
|
91
|
+
// and script parameters; only make failed pipeline stages observable.
|
|
92
|
+
let at = 0;
|
|
93
|
+
while (effectiveArgs[at]?.startsWith("--") && effectiveArgs[at] !== "--") {
|
|
94
|
+
at += ["--rcfile", "--init-file"].includes(effectiveArgs[at]) ? 2 : 1;
|
|
95
|
+
}
|
|
96
|
+
effectiveArgs.splice(at, 0, "-o", "pipefail");
|
|
97
|
+
}
|
|
98
|
+
return (context.shellExecutor ?? runProcess)(command, effectiveArgs, { ...context, shellWorkingDirectory });
|
|
85
99
|
},
|
|
86
100
|
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type ToolDefinition } from "../ToolTypes.js";
|
|
2
|
+
interface CalendarInput {
|
|
3
|
+
operation: "add_days" | "difference_days";
|
|
4
|
+
date: string;
|
|
5
|
+
days?: number;
|
|
6
|
+
otherDate?: string;
|
|
7
|
+
}
|
|
8
|
+
export declare const calendarCalculate: (input: CalendarInput) => {
|
|
9
|
+
date: string;
|
|
10
|
+
} | {
|
|
11
|
+
days: number;
|
|
12
|
+
};
|
|
13
|
+
export declare const createCalendarTool: () => ToolDefinition;
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=CalendarTool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CalendarTool.d.ts","sourceRoot":"","sources":["../../../src/tools/system/CalendarTool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,KAAK,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAE1E,UAAU,aAAa;IAAG,SAAS,EAAE,UAAU,GAAG,iBAAiB,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAAE;AASvH,eAAO,MAAM,iBAAiB,GAAI,OAAO,aAAa,KAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAazF,CAAC;AAEF,eAAO,MAAM,kBAAkB,QAAO,cAYpC,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { ToolExecutionError } from "../ToolTypes.js";
|
|
2
|
+
const DAY = 86400000;
|
|
3
|
+
const epochDay = (date) => {
|
|
4
|
+
if (typeof date !== "string" || !/^\d{4}-\d{2}-\d{2}$/.test(date) || date.startsWith("0000"))
|
|
5
|
+
throw new Error("Expected a Gregorian date YYYY-MM-DD in years 0001–9999");
|
|
6
|
+
const time = Date.parse(`${date}T00:00:00.000Z`);
|
|
7
|
+
if (!Number.isFinite(time) || new Date(time).toISOString().slice(0, 10) !== date)
|
|
8
|
+
throw new Error("Invalid calendar date");
|
|
9
|
+
return time / DAY;
|
|
10
|
+
};
|
|
11
|
+
export const calendarCalculate = (input) => {
|
|
12
|
+
const start = epochDay(input.date);
|
|
13
|
+
if (input.operation === "add_days") {
|
|
14
|
+
if (!Number.isInteger(input.days) || Math.abs(input.days) > 3652058 || input.otherDate !== undefined)
|
|
15
|
+
throw new Error("add_days requires integer days and no otherDate");
|
|
16
|
+
const date = new Date((start + input.days) * DAY).toISOString().slice(0, 10);
|
|
17
|
+
epochDay(date); // Reject results beyond the supported Gregorian year range.
|
|
18
|
+
return { date };
|
|
19
|
+
}
|
|
20
|
+
if (input.operation === "difference_days") {
|
|
21
|
+
if (input.days !== undefined || input.otherDate === undefined)
|
|
22
|
+
throw new Error("difference_days requires otherDate and no days");
|
|
23
|
+
return { days: epochDay(input.otherDate) - start };
|
|
24
|
+
}
|
|
25
|
+
throw new Error("Unknown calendar operation");
|
|
26
|
+
};
|
|
27
|
+
export const createCalendarTool = () => ({
|
|
28
|
+
name: "calendar_calculate", capability: "calculation", readOnly: true,
|
|
29
|
+
description: "Exact Gregorian calendar dates: add signed days or count otherDate minus date. ISO YYYY-MM-DD, UTC; no business-day, locale or timezone guessing.",
|
|
30
|
+
inputSchema: { type: "object", required: ["operation", "date"], additionalProperties: false, properties: {
|
|
31
|
+
operation: { type: "string", enum: ["add_days", "difference_days"] }, date: { type: "string", minLength: 10, maxLength: 10 },
|
|
32
|
+
days: { type: "integer", minimum: -3652058, maximum: 3652058 }, otherDate: { type: "string", minLength: 10, maxLength: 10 },
|
|
33
|
+
} },
|
|
34
|
+
handler: async (args, context) => {
|
|
35
|
+
context.signal?.throwIfAborted();
|
|
36
|
+
try {
|
|
37
|
+
const data = { ...calendarCalculate(args), calendar: "proleptic Gregorian UTC" };
|
|
38
|
+
return { output: JSON.stringify(data), data };
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
throw new ToolExecutionError("tool_invalid_args", error instanceof Error ? error.message : String(error), { retryable: false });
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TextTool.d.ts","sourceRoot":"","sources":["../../../src/tools/system/TextTool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,KAAK,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAE1E,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAO9D;AAED,eAAO,MAAM,cAAc,QAAO,cAsBhC,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { ToolExecutionError } from "../ToolTypes.js";
|
|
2
|
+
export function compareCodePoints(a, b) {
|
|
3
|
+
const left = Array.from(a, ch => ch.codePointAt(0));
|
|
4
|
+
const right = Array.from(b, ch => ch.codePointAt(0));
|
|
5
|
+
for (let i = 0; i < Math.min(left.length, right.length); i++) {
|
|
6
|
+
if (left[i] !== right[i])
|
|
7
|
+
return left[i] - right[i];
|
|
8
|
+
}
|
|
9
|
+
return left.length - right.length;
|
|
10
|
+
}
|
|
11
|
+
export const createTextTool = () => ({
|
|
12
|
+
name: "transform_text", capability: "deterministic", readOnly: true,
|
|
13
|
+
description: "Exact string-list operations: sort lexicographically by Unicode code points, deduplicate in source order, or normalize Unicode. No locale collation. Sorting does not normalize text.",
|
|
14
|
+
inputSchema: { type: "object", required: ["operation", "values"], additionalProperties: false, properties: {
|
|
15
|
+
operation: { type: "string", enum: ["sort_codepoints", "unique", "normalize"] },
|
|
16
|
+
values: { type: "array", maxItems: 1000, items: { type: "string", maxLength: 4096 } },
|
|
17
|
+
form: { type: "string", enum: ["NFC", "NFD", "NFKC", "NFKD"] },
|
|
18
|
+
} },
|
|
19
|
+
handler: async (args, context) => {
|
|
20
|
+
context.signal?.throwIfAborted();
|
|
21
|
+
const { operation, values, form } = args;
|
|
22
|
+
if (!Array.isArray(values) || values.length > 1000 || values.some(v => typeof v !== "string" || v.length > 4096)
|
|
23
|
+
|| values.reduce((n, v) => n + v.length, 0) > 32000)
|
|
24
|
+
throw new ToolExecutionError("tool_invalid_args", "Expected at most 1000 strings and 32000 total characters");
|
|
25
|
+
if (form !== undefined && operation !== "normalize")
|
|
26
|
+
throw new ToolExecutionError("tool_invalid_args", "Normalization form applies only to normalize; sorting preserves exact text");
|
|
27
|
+
let result;
|
|
28
|
+
if (operation === "sort_codepoints")
|
|
29
|
+
result = [...values].sort(compareCodePoints);
|
|
30
|
+
else if (operation === "unique")
|
|
31
|
+
result = [...new Set(values)];
|
|
32
|
+
else if (operation === "normalize" && ["NFC", "NFD", "NFKC", "NFKD"].includes(form ?? ""))
|
|
33
|
+
result = values.map(v => v.normalize(form));
|
|
34
|
+
else
|
|
35
|
+
throw new ToolExecutionError("tool_invalid_args", "Choose sort_codepoints, unique, or normalize with an explicit Unicode form");
|
|
36
|
+
const data = { values: result };
|
|
37
|
+
return { output: JSON.stringify(data), data };
|
|
38
|
+
},
|
|
39
|
+
});
|
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
import { type ToolDefinition } from "../ToolTypes.js";
|
|
2
|
+
/** Keep the diagnostic, not hundreds of characters of runner stack frames.
|
|
3
|
+
* Vitest can put timeout/caused-by messages after STACK_TRACE_ERROR frames. */
|
|
4
|
+
export declare const testFailureSummary: (message: string) => string;
|
|
2
5
|
export declare const createVitestTool: () => ToolDefinition;
|
|
3
6
|
//# sourceMappingURL=VitestTool.d.ts.map
|
|
@@ -1 +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;
|
|
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;AAE1E;+EAC+E;AAC/E,eAAO,MAAM,kBAAkB,GAAI,SAAS,MAAM,KAAG,MAGpD,CAAC;AAyCF,eAAO,MAAM,gBAAgB,QAAO,cAwGlC,CAAC"}
|
|
@@ -5,6 +5,12 @@ import os from "node:os";
|
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import { createIsolatedExecutor } from "../shell/IsolatedExecutor.js";
|
|
7
7
|
import { ToolExecutionError } from "../ToolTypes.js";
|
|
8
|
+
/** Keep the diagnostic, not hundreds of characters of runner stack frames.
|
|
9
|
+
* Vitest can put timeout/caused-by messages after STACK_TRACE_ERROR frames. */
|
|
10
|
+
export const testFailureSummary = (message) => {
|
|
11
|
+
const diagnostic = message.split("\n").filter(line => !/^\s+at\s/.test(line)).join("\n").trim();
|
|
12
|
+
return diagnostic.length <= 900 ? diagnostic : `${diagnostic.slice(0, 350)}\n[…]\n${diagnostic.slice(-500)}`;
|
|
13
|
+
};
|
|
8
14
|
/** Resolve only the installed runner's dependency closure, never a workspace config. */
|
|
9
15
|
async function runnerRuntime() {
|
|
10
16
|
const require = createRequire(import.meta.url);
|
|
@@ -56,22 +62,25 @@ async function runnerRuntime() {
|
|
|
56
62
|
}
|
|
57
63
|
export const createVitestTool = () => ({
|
|
58
64
|
name: "verify_tests", readOnly: true, capability: "verification",
|
|
59
|
-
description: "Run
|
|
60
|
-
inputSchema: { type: "object", properties: { files: { type: "array", minItems: 1, maxItems: 12, items: { type: "object", properties: {
|
|
65
|
+
description: "Run supplied tests offline: runner vitest (default) for JS/TS, node for node:test, python for standard-library unittest (test_*.py). Use the requested language/runner without translating tests. No workspace/config/credentials. Reports supplied-test results, not independent proof.",
|
|
66
|
+
inputSchema: { type: "object", properties: { runner: { type: "string", enum: ["vitest", "node", "python"] }, files: { type: "array", minItems: 1, maxItems: 12, items: { type: "object", properties: {
|
|
61
67
|
path: { type: "string", minLength: 1, maxLength: 160 }, content: { type: "string", maxLength: 24000 },
|
|
62
68
|
}, required: ["path", "content"], additionalProperties: false } } }, required: ["files"], additionalProperties: false },
|
|
63
69
|
handler: async (raw, context) => {
|
|
64
70
|
context.signal?.throwIfAborted();
|
|
65
71
|
const args = raw;
|
|
72
|
+
const runner = args.runner ?? "vitest";
|
|
73
|
+
const testPattern = runner === "python" ? /(?:^|\/)test_[^/]+\.py$/ : /\.test\.(?:[cm]?js|ts)$/;
|
|
66
74
|
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)
|
|
75
|
+
if (!["vitest", "node", "python"].includes(runner) || payload.length > 96000 || !Array.isArray(args.files) || !args.files.length || args.files.length > 12
|
|
76
|
+
|| args.files.some(file => !/^(?:[A-Za-z0-9_-]+\/)*[A-Za-z0-9_.-]+\.(?:[cm]?js|ts|py)$/.test(file.path)
|
|
77
|
+
|| (runner === "python" ? !file.path.endsWith(".py") : file.path.endsWith(".py") || runner === "node" && file.path.endsWith(".ts"))
|
|
69
78
|
|| file.path.split("/").some(segment => segment === "node_modules" || segment.startsWith(".")) || /(?:^|\/)(?:vite|vitest)\.config\./.test(file.path)
|
|
70
79
|
|| 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 =>
|
|
72
|
-
throw new ToolExecutionError("tool_invalid_args", "Supply up to 12 bounded source/test files
|
|
80
|
+
|| new Set(args.files.map(file => file.path)).size !== args.files.length || !args.files.some(file => testPattern.test(file.path))) {
|
|
81
|
+
throw new ToolExecutionError("tool_invalid_args", "Supply up to 12 bounded relative source/test files for the chosen runner: *.test.js/ts for Vitest, *.test.js/mjs/cjs for Node, test_*.py for Python. No configs or node_modules");
|
|
73
82
|
}
|
|
74
|
-
const runtime = await runnerRuntime();
|
|
83
|
+
const runtime = runner === "vitest" ? await runnerRuntime() : undefined;
|
|
75
84
|
const root = await fs.mkdtemp(path.join(os.tmpdir(), "codali-vitest-"));
|
|
76
85
|
const started = Date.now();
|
|
77
86
|
try {
|
|
@@ -82,9 +91,55 @@ export const createVitestTool = () => ({
|
|
|
82
91
|
await fs.writeFile(target, file.content);
|
|
83
92
|
}
|
|
84
93
|
await fs.writeFile(path.join(root, "package.json"), '{"type":"module"}');
|
|
94
|
+
await fs.mkdir(path.join(root, "artifacts"));
|
|
95
|
+
if (runner !== "vitest") {
|
|
96
|
+
const tests = args.files.filter(file => testPattern.test(file.path)).map(file => path.join(root, file.path));
|
|
97
|
+
const python = `import unittest,sys,os,json,importlib.util
|
|
98
|
+
sys.path.insert(0,os.getcwd())
|
|
99
|
+
suite=unittest.TestSuite()
|
|
100
|
+
for i,file in enumerate(sys.argv[1:]):
|
|
101
|
+
spec=importlib.util.spec_from_file_location('codali_test_'+str(i),file)
|
|
102
|
+
module=importlib.util.module_from_spec(spec);spec.loader.exec_module(module)
|
|
103
|
+
suite.addTests(unittest.defaultTestLoader.loadTestsFromModule(module))
|
|
104
|
+
result=unittest.TextTestRunner(verbosity=2).run(suite)
|
|
105
|
+
data={'total':result.testsRun,'failedTests':len(result.failures)+len(result.errors)+len(result.unexpectedSuccesses),'pendingTests':len(result.skipped)+len(result.expectedFailures)}
|
|
106
|
+
data['passedTests']=data['total']-data['failedTests']-data['pendingTests']
|
|
107
|
+
with open('artifacts/native-report.json','w') as f:json.dump(data,f)
|
|
108
|
+
sys.exit(0 if result.wasSuccessful() and data['total']>0 and data['pendingTests']==0 else 1)`;
|
|
109
|
+
let output = "", exitCode = 0;
|
|
110
|
+
try {
|
|
111
|
+
const run = await createIsolatedExecutor({ network: false })(runner === "node" ? process.execPath : "python3", runner === "node" ? ["--max-old-space-size=256", "--test", "--test-reporter=tap", ...tests] : ["-I", "-B", "-c", python, ...tests], { workspaceRoot: root, signal: context.signal, allowedWritePaths: ["artifacts"], shellTimeoutMs: 15000, shellMaxOutputBytes: 128000 });
|
|
112
|
+
output = run.output;
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
if (!(error instanceof ToolExecutionError) || error.code !== "tool_execution_failed" || error.details?.exitCode !== 1)
|
|
116
|
+
throw error;
|
|
117
|
+
exitCode = 1;
|
|
118
|
+
output = String(error.details?.output ?? error.message);
|
|
119
|
+
}
|
|
120
|
+
const count = (key) => Number([...output.matchAll(new RegExp(`^# ${key} (\\d+)$`, "gm"))].at(-1)?.[1] ?? NaN);
|
|
121
|
+
const reportPath = path.join(root, "artifacts", "native-report.json");
|
|
122
|
+
if (runner === "python") {
|
|
123
|
+
const stat = await fs.lstat(reportPath).catch(() => undefined);
|
|
124
|
+
if (!stat)
|
|
125
|
+
throw new ToolExecutionError("tool_execution_failed", `Python tests could not start. This runner loads standard-library unittest.TestCase tests; third-party packages such as pytest are not installed. Fix the reported import/syntax error or use unittest.\n${testFailureSummary(output)}`, { details: { exitCode, output } });
|
|
126
|
+
if (!stat.isFile() || stat.isSymbolicLink() || stat.size > 16000)
|
|
127
|
+
throw new Error("Invalid test report");
|
|
128
|
+
}
|
|
129
|
+
const report = runner === "node" ? { total: count("tests"), passedTests: count("pass"), failedTests: count("fail"), pendingTests: count("skipped") + count("todo") + count("cancelled") }
|
|
130
|
+
: JSON.parse(await fs.readFile(reportPath, "utf8"));
|
|
131
|
+
if (!Object.values(report).every(value => Number.isSafeInteger(value) && Number(value) >= 0) || report.total < 1)
|
|
132
|
+
throw new ToolExecutionError("tool_execution_failed", `No complete test results were produced. Python requires unittest.TestCase methods named test_*; Node requires node:test cases. Zero executed tests cannot establish correctness.\n${testFailureSummary(output)}`, { details: { exitCode, output } });
|
|
133
|
+
const result = { library: runner === "node" ? "node:test" : "unittest", ...report,
|
|
134
|
+
passed: exitCode === 0 && report.failedTests === 0 && report.pendingTests === 0 && report.passedTests === report.total,
|
|
135
|
+
diagnostic: testFailureSummary(output).slice(0, 1800), sourceSha256: createHash("sha256").update(payload).digest("hex"), elapsedMs: Date.now() - started,
|
|
136
|
+
scope: "Supplied tests executed in an offline sandbox; not independent proof or a workspace test run" };
|
|
137
|
+
return { output: JSON.stringify(result), data: result };
|
|
138
|
+
}
|
|
139
|
+
if (!runtime)
|
|
140
|
+
throw new Error("Vitest runtime unavailable");
|
|
85
141
|
await fs.mkdir(path.join(root, "node_modules"));
|
|
86
142
|
await fs.symlink(runtime.entry, path.join(root, "node_modules", "vitest"));
|
|
87
|
-
await fs.mkdir(path.join(root, "artifacts"));
|
|
88
143
|
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
144
|
// macOS denies signaling separate child processes inside this sandbox.
|
|
90
145
|
// Threads retain the same OS boundary without requiring signal grants.
|
|
@@ -116,7 +171,8 @@ export const createVitestTool = () => ({
|
|
|
116
171
|
throw Error("No complete test results were produced");
|
|
117
172
|
const result = { library: "vitest", version: runtime.version, passed: exitCode === 0 && report.success === true && report.numFailedTests === 0 && report.numPassedTests === report.numTotalTests,
|
|
118
173
|
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(
|
|
174
|
+
assertions: report.testResults.flatMap((suite) => (suite.assertionResults ?? []).map(check => ({ name: check.fullName.slice(0, 200), status: check.status, durationMs: check.duration, failures: check.failureMessages?.map(testFailureSummary).slice(0, 2) })))
|
|
175
|
+
.sort((a, b) => Number(b.status === "failed") - Number(a.status === "failed")).slice(0, 64),
|
|
120
176
|
sourceSha256: createHash("sha256").update(payload).digest("hex"), elapsedMs: Date.now() - started,
|
|
121
177
|
scope: "Results reported by the supplied tests in an offline sandbox; not independent proof or a workspace test run" };
|
|
122
178
|
return { output: JSON.stringify(result), data: result };
|
package/package.json
CHANGED
|
@@ -2,14 +2,15 @@
|
|
|
2
2
|
"author": "bekir dag",
|
|
3
3
|
"bin": {
|
|
4
4
|
"codali": "dist/cli.js",
|
|
5
|
+
"codali-cli": "dist/cli.js",
|
|
5
6
|
"dataset": "dist/dataset-cli.js"
|
|
6
7
|
},
|
|
7
8
|
"bugs": {
|
|
8
9
|
"url": "https://github.com/bekirdag/mcoda/issues"
|
|
9
10
|
},
|
|
10
11
|
"dependencies": {
|
|
11
|
-
"@mcoda/db": "0.1.135-codali.
|
|
12
|
-
"@mcoda/shared": "0.1.135-codali.
|
|
12
|
+
"@mcoda/db": "0.1.135-codali.32",
|
|
13
|
+
"@mcoda/shared": "0.1.135-codali.32",
|
|
13
14
|
"@modelcontextprotocol/sdk": "1.30.0",
|
|
14
15
|
"ajv": "8.20.0",
|
|
15
16
|
"browser-use": "0.9.0",
|
|
@@ -56,5 +57,5 @@
|
|
|
56
57
|
},
|
|
57
58
|
"type": "module",
|
|
58
59
|
"types": "dist/index.d.ts",
|
|
59
|
-
"version": "0.1.135-codali.
|
|
60
|
+
"version": "0.1.135-codali.32"
|
|
60
61
|
}
|