@mcoda/codali 0.1.135-codali.32 → 0.1.135-codali.37
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 +59 -0
- package/config/skills/architecture-design/SKILL.md +2 -2
- package/dist/docdex/DocdexClient.d.ts +7 -1
- package/dist/docdex/DocdexClient.d.ts.map +1 -1
- package/dist/docdex/DocdexClient.js +34 -2
- package/dist/eval/EvaluationProcess.d.ts.map +1 -1
- package/dist/eval/EvaluationProcess.js +4 -0
- package/dist/providers/ConfiguredProvider.d.ts +4 -1
- package/dist/providers/ConfiguredProvider.d.ts.map +1 -1
- package/dist/providers/ConfiguredProvider.js +18 -5
- package/dist/providers/ProviderTypes.d.ts +3 -0
- package/dist/providers/ProviderTypes.d.ts.map +1 -1
- package/dist/runtime/CompletionReport.d.ts +6 -0
- package/dist/runtime/CompletionReport.d.ts.map +1 -1
- package/dist/runtime/CompletionReport.js +8 -0
- package/dist/runtime/ContextCompression.d.ts +3 -0
- package/dist/runtime/ContextCompression.d.ts.map +1 -1
- package/dist/runtime/ContextCompression.js +35 -6
- package/dist/runtime/InteractionRouter.d.ts +5 -5
- package/dist/runtime/InteractionRouter.d.ts.map +1 -1
- package/dist/runtime/InteractionRouter.js +7 -6
- package/dist/runtime/SessionController.d.ts +49 -0
- package/dist/runtime/SessionController.d.ts.map +1 -1
- package/dist/runtime/SessionController.js +339 -63
- package/dist/runtime/SpecialistTools.d.ts +2 -0
- package/dist/runtime/SpecialistTools.d.ts.map +1 -1
- package/dist/runtime/SpecialistTools.js +20 -4
- package/dist/runtime/TaskReview.js +1 -1
- package/dist/session/SessionStore.d.ts +1 -0
- package/dist/session/SessionStore.d.ts.map +1 -1
- package/dist/session/SessionStore.js +97 -41
- package/dist/session/WorkState.d.ts +5 -2
- package/dist/session/WorkState.d.ts.map +1 -1
- package/dist/session/WorkState.js +9 -3
- package/dist/tools/ToolTypes.d.ts +3 -0
- package/dist/tools/ToolTypes.d.ts.map +1 -1
- package/dist/tools/filesystem/FileTools.d.ts.map +1 -1
- package/dist/tools/filesystem/FileTools.js +4 -0
- package/dist/tools/shell/HostToolchain.d.ts +7 -0
- package/dist/tools/shell/HostToolchain.d.ts.map +1 -1
- package/dist/tools/shell/HostToolchain.js +33 -2
- 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 +38 -14
- package/dist/tools/shell/ShellTool.d.ts.map +1 -1
- package/dist/tools/shell/ShellTool.js +3 -2
- package/package.json +3 -3
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { existsSync, realpathSync, statSync, readdirSync, mkdtempSync, rmSync, promises as fs } from "node:fs";
|
|
1
|
+
import { existsSync, realpathSync, statSync, readdirSync, mkdirSync, mkdtempSync, rmSync, promises as fs } from "node:fs";
|
|
2
2
|
import os from "node:os";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { spawnSync } from "node:child_process";
|
|
5
5
|
import { runProcess } from "./AsyncProcess.js";
|
|
6
6
|
import { resolveShellWorkingDirectory } from "./ShellWorkingDirectory.js";
|
|
7
7
|
import { ToolExecutionError } from "../ToolTypes.js";
|
|
8
|
-
import { discoverHostToolchain, extraRuntimeMounts } from "./HostToolchain.js";
|
|
8
|
+
import { discoverHostToolchain, extraRuntimeMounts, venvInterpreter } 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 = [], protectedPaths = [], cacheRoot) => {
|
|
10
|
+
export const darwinSandboxProfile = (root, scratch, writePaths, runtimes, network = false, runtimeRoots = [], protectedPaths = [], cacheRoot, sessionScratch) => {
|
|
11
11
|
const quoted = (value) => JSON.stringify(value);
|
|
12
12
|
const ancestors = new Set();
|
|
13
|
-
for (const target of [root, scratch, ...(cacheRoot ? [cacheRoot] : []), ...runtimeRoots, ...extraRuntimeMounts(runtimes).map(runtime => runtime.readOnlyRoot)]) {
|
|
13
|
+
for (const target of [root, scratch, ...(cacheRoot ? [cacheRoot] : []), ...(sessionScratch ? [sessionScratch] : []), ...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
|
}
|
|
@@ -36,6 +36,7 @@ export const darwinSandboxProfile = (root, scratch, writePaths, runtimes, networ
|
|
|
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
38
|
...(cacheRoot ? [`(allow file-read* file-write* (subpath ${quoted(cacheRoot)}))`, `(deny file-write-unlink (literal ${quoted(cacheRoot)}))`] : []),
|
|
39
|
+
...(sessionScratch ? [`(allow file-read* file-write* (subpath ${quoted(sessionScratch)}))`, `(deny file-write-unlink (literal ${quoted(sessionScratch)}))`] : []),
|
|
39
40
|
...writePaths.map(file => `(allow file-write* (subpath ${quoted(file)}))`),
|
|
40
41
|
...[".git", ".mcoda"].map(dir => `(deny file-write* (subpath ${quoted(path.join(root, dir))}))`),
|
|
41
42
|
...protectedPaths.map(file => `(deny file-write* (subpath ${quoted(file)}))`),
|
|
@@ -62,11 +63,13 @@ const bubblewrapRoot = () => {
|
|
|
62
63
|
args.push("--ro-bind", realpathSync("/etc/fonts"), "/etc/fonts");
|
|
63
64
|
if (existsSync("/etc/alternatives"))
|
|
64
65
|
for (const name of readdirSync("/etc/alternatives")) {
|
|
65
|
-
|
|
66
|
-
|
|
66
|
+
// Commands such as awk are aliases through /etc/alternatives to a binary
|
|
67
|
+
// under /usr/bin that is already visible; without the alias the command
|
|
68
|
+
// is "not found" inside the sandbox.
|
|
69
|
+
const library = /^lib[^/]+\.so(?:\..+)?$/.test(name);
|
|
67
70
|
try {
|
|
68
71
|
const alias = path.join("/etc/alternatives", name), target = realpathSync(alias);
|
|
69
|
-
if (!["/usr/lib/", "/usr/lib64/", "/lib/", "/lib64/"].some(prefix => target.startsWith(prefix)) || !statSync(target).isFile())
|
|
72
|
+
if (!(library ? ["/usr/lib/", "/usr/lib64/", "/lib/", "/lib64/"] : ["/usr/bin/", "/bin/"]).some(prefix => target.startsWith(prefix)) || !statSync(target).isFile())
|
|
70
73
|
continue;
|
|
71
74
|
args.push("--ro-bind", target, alias);
|
|
72
75
|
}
|
|
@@ -100,17 +103,17 @@ const packageCacheEnvironment = (root) => ({
|
|
|
100
103
|
CARGO_HOME: path.join(root, "cargo"), XDG_CACHE_HOME: path.join(root, "xdg"),
|
|
101
104
|
});
|
|
102
105
|
/** Disposable, workspace-specific cache. Never mount an existing host package cache or credentials. */
|
|
103
|
-
const preparePackageCache = async (requested, workspace) => {
|
|
106
|
+
const preparePackageCache = async (requested, workspace, label = "Package cache") => {
|
|
104
107
|
const absolute = path.resolve(requested);
|
|
105
108
|
const unsafe = (value) => value === path.parse(value).root || value === realpathSync(os.homedir())
|
|
106
109
|
|| value === workspace || workspace.startsWith(`${value}${path.sep}`) || value.startsWith(`${workspace}${path.sep}`);
|
|
107
110
|
if (unsafe(absolute))
|
|
108
|
-
throw new ToolExecutionError("tool_permission_denied",
|
|
111
|
+
throw new ToolExecutionError("tool_permission_denied", `${label} must be a private dedicated directory outside the workspace`);
|
|
109
112
|
await fs.mkdir(absolute, { recursive: true, mode: 0o700 });
|
|
110
113
|
const stat = await fs.lstat(absolute), real = await fs.realpath(absolute);
|
|
111
114
|
if (stat.isSymbolicLink() || !stat.isDirectory() || unsafe(real)
|
|
112
115
|
|| (process.getuid && stat.uid !== process.getuid()) || (stat.mode & 0o077) !== 0) {
|
|
113
|
-
throw new ToolExecutionError("tool_permission_denied",
|
|
116
|
+
throw new ToolExecutionError("tool_permission_denied", `${label} must be an owned private directory, not a symlink`);
|
|
114
117
|
}
|
|
115
118
|
return real;
|
|
116
119
|
};
|
|
@@ -124,6 +127,7 @@ export const createIsolatedExecutor = (options = {}) => {
|
|
|
124
127
|
if (root === path.parse(root).root)
|
|
125
128
|
throw new ToolExecutionError("tool_permission_denied", "Filesystem root cannot be an isolated workspace");
|
|
126
129
|
const cacheRoot = options.cacheRoot ? await preparePackageCache(options.cacheRoot, root) : undefined;
|
|
130
|
+
const sessionScratch = options.scratchRoot ? await preparePackageCache(options.scratchRoot, root, "Shell scratch") : undefined;
|
|
127
131
|
const runtimes = discoverHostToolchain(root);
|
|
128
132
|
const protectedPaths = [...new Set((context.protectedPaths ?? []).flatMap(file => {
|
|
129
133
|
const requested = path.resolve(root, file);
|
|
@@ -143,10 +147,19 @@ export const createIsolatedExecutor = (options = {}) => {
|
|
|
143
147
|
throw new ToolExecutionError("tool_permission_denied", "Runtime mount must be a dedicated installed library directory");
|
|
144
148
|
return real;
|
|
145
149
|
}))];
|
|
150
|
+
for (const [index, venv] of runtimeRoots.entries()) {
|
|
151
|
+
const interpreter = venvInterpreter(venv, root);
|
|
152
|
+
if (interpreter && !runtimes.some(runtime => runtime.executable === interpreter.executable))
|
|
153
|
+
runtimes.push({ ...interpreter, name: `python-runtime-${index}` });
|
|
154
|
+
}
|
|
146
155
|
const writePaths = (context.allowedWritePaths ?? ["."]).map(file => {
|
|
147
156
|
const requested = path.resolve(root, file);
|
|
148
157
|
if (requested !== root && !requested.startsWith(`${root}${path.sep}`))
|
|
149
158
|
throw new ToolExecutionError("tool_permission_denied", "Shell write scope escapes workspace");
|
|
159
|
+
// A declared output directory that does not exist yet (dist/, data/) is
|
|
160
|
+
// created rather than refused; a missing file still has to be written first.
|
|
161
|
+
if (!existsSync(requested) && (/[\\/]$/.test(file) || !path.extname(requested)))
|
|
162
|
+
mkdirSync(requested, { recursive: true });
|
|
150
163
|
if (!existsSync(requested))
|
|
151
164
|
throw new ToolExecutionError("tool_permission_denied", "Create the scoped directory with create_directory (or file with write_file) before shell execution");
|
|
152
165
|
const real = realpathSync(requested);
|
|
@@ -176,7 +189,7 @@ export const createIsolatedExecutor = (options = {}) => {
|
|
|
176
189
|
}
|
|
177
190
|
launch.push("--dir", path.dirname(root), "--ro-bind", root, root);
|
|
178
191
|
for (const runtime of extraRuntimeMounts(runtimes))
|
|
179
|
-
launch.push("--dir", path.dirname(runtime.readOnlyRoot), "--ro-bind", runtime.readOnlyRoot, runtime.readOnlyRoot);
|
|
192
|
+
launch.push("--dir", path.dirname(runtime.readOnlyRoot), ...(runtime.linkTo ? ["--symlink", runtime.linkTo, runtime.readOnlyRoot] : ["--ro-bind", runtime.readOnlyRoot, runtime.readOnlyRoot]));
|
|
180
193
|
for (const runtime of runtimeRoots)
|
|
181
194
|
launch.push("--dir", path.dirname(runtime), "--ro-bind", runtime, runtime);
|
|
182
195
|
launch.push("--dir", "/tmp/codali-bin");
|
|
@@ -186,12 +199,23 @@ export const createIsolatedExecutor = (options = {}) => {
|
|
|
186
199
|
launch.push("--bind", file, file);
|
|
187
200
|
if (cacheRoot)
|
|
188
201
|
launch.push("--bind", cacheRoot, "/tmp/codali-cache");
|
|
189
|
-
|
|
202
|
+
// The rest of /tmp stays per-call; only $TMPDIR survives between calls.
|
|
203
|
+
if (sessionScratch)
|
|
204
|
+
launch.push("--bind", sessionScratch, "/tmp/scratch");
|
|
205
|
+
launch.push("--chdir", cwd, "--dir", "/tmp/home", "--setenv", "HOME", "/tmp/home", "--setenv", "TMPDIR", sessionScratch ? "/tmp/scratch" : "/tmp", "--setenv", "PATH", "/tmp/codali-bin:/usr/local/bin:/usr/bin:/bin");
|
|
190
206
|
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
207
|
launch.push("--setenv", key, value);
|
|
192
208
|
if (cacheRoot)
|
|
193
209
|
for (const [key, value] of Object.entries(packageCacheEnvironment("/tmp/codali-cache")))
|
|
194
210
|
launch.push("--setenv", key, value);
|
|
211
|
+
// A relocated Python (a CI tool cache, a copied installation) records the
|
|
212
|
+
// library directory it was built for, not the one it lives in, and fails
|
|
213
|
+
// with "libpython not found". Point the loader at the interpreter
|
|
214
|
+
// libraries already mounted from the same installation, and nothing else.
|
|
215
|
+
const interpreterLibraries = [...new Set(runtimes.flatMap(runtime => (runtime.support ?? [])
|
|
216
|
+
.filter(mount => !mount.directory && /^libpython3\./.test(path.basename(mount.readOnlyRoot))).map(mount => path.dirname(mount.readOnlyRoot))))];
|
|
217
|
+
if (interpreterLibraries.length)
|
|
218
|
+
launch.push("--setenv", "LD_LIBRARY_PATH", interpreterLibraries.join(":"));
|
|
195
219
|
// Git hooks/config and private session state are not part of executable workspace access.
|
|
196
220
|
for (const dir of [".git", ".mcoda"])
|
|
197
221
|
if (existsSync(path.join(root, dir)))
|
|
@@ -215,10 +239,10 @@ export const createIsolatedExecutor = (options = {}) => {
|
|
|
215
239
|
await fs.mkdir(privateBin, { mode: 0o700 });
|
|
216
240
|
for (const runtime of runtimes)
|
|
217
241
|
await fs.symlink(runtime.executable, path.join(privateBin, runtime.name));
|
|
218
|
-
const profile = darwinSandboxProfile(root, scratch, writePaths, runtimes, options.network, runtimeRoots, protectedPaths, cacheRoot);
|
|
242
|
+
const profile = darwinSandboxProfile(root, scratch, writePaths, runtimes, options.network, runtimeRoots, protectedPaths, cacheRoot, sessionScratch);
|
|
219
243
|
return await runProcess("/usr/bin/sandbox-exec", ["-p", profile, runtimes.find(runtime => runtime.name === command)?.executable ?? command, ...args], context, {
|
|
220
244
|
...runtimes.find(runtime => runtime.name === "cc")?.environment,
|
|
221
|
-
HOME: privateHome, TMPDIR: scratch, PATH: `${privateBin}:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin`,
|
|
245
|
+
HOME: privateHome, TMPDIR: sessionScratch ?? scratch, PATH: `${privateBin}:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin`,
|
|
222
246
|
CARGO_HOME: path.join(privateHome, "cargo"), XDG_CACHE_HOME: path.join(privateHome, "cache"),
|
|
223
247
|
...(cacheRoot ? packageCacheEnvironment(cacheRoot) : {}),
|
|
224
248
|
PYTHONPYCACHEPREFIX: path.join(privateHome, "pycache"), PYTHONUSERBASE: path.join(privateHome, "python"),
|
|
@@ -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;AAI5F,yEAAyE;AACzE,eAAO,MAAM,oBAAoB,
|
|
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,UAA4iB,CAAC;AA6C9kB,eAAO,MAAM,eAAe,QAAO,cA8DjC,CAAC"}
|
|
@@ -3,7 +3,7 @@ import { ToolExecutionError } from "../ToolTypes.js";
|
|
|
3
3
|
import { runProcess } from "./AsyncProcess.js";
|
|
4
4
|
import { resolveShellWorkingDirectory } from "./ShellWorkingDirectory.js";
|
|
5
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"];
|
|
6
|
+
export const DEVELOPMENT_COMMANDS = ["git", "rg", "grep", "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", "rm", "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"];
|
|
7
7
|
const resolveAllowlist = (context) => {
|
|
8
8
|
return context.shellAllowlist ?? [];
|
|
9
9
|
};
|
|
@@ -45,7 +45,7 @@ const isDestructiveShellAction = (command, args) => {
|
|
|
45
45
|
};
|
|
46
46
|
export const createShellTool = () => ({
|
|
47
47
|
name: "run_shell",
|
|
48
|
-
description: 'Run an allowlisted executable. Use $TMPDIR for
|
|
48
|
+
description: 'Run an allowlisted executable. Use $TMPDIR for scratch space: files written under $TMPDIR stay available to later calls in this session, while exports, cwd changes and other /tmp paths 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. Deleting files works only inside $TMPDIR and the writePaths of the call. 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.',
|
|
49
49
|
readOnly: false,
|
|
50
50
|
capability: "shell",
|
|
51
51
|
inputSchema: {
|
|
@@ -66,6 +66,7 @@ export const createShellTool = () => ({
|
|
|
66
66
|
}
|
|
67
67
|
const { command, args: commandArgs = [], cwd } = args;
|
|
68
68
|
if (!context.allowDestructiveOperations
|
|
69
|
+
&& !context.shellIsolated
|
|
69
70
|
&& isDestructiveShellAction(command, commandArgs)) {
|
|
70
71
|
throw new ToolExecutionError("tool_permission_denied", "Destructive operation blocked by policy", {
|
|
71
72
|
retryable: false,
|
package/package.json
CHANGED
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
"url": "https://github.com/bekirdag/mcoda/issues"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@mcoda/db": "0.1.135-codali.
|
|
13
|
-
"@mcoda/shared": "0.1.135-codali.
|
|
12
|
+
"@mcoda/db": "0.1.135-codali.37",
|
|
13
|
+
"@mcoda/shared": "0.1.135-codali.37",
|
|
14
14
|
"@modelcontextprotocol/sdk": "1.30.0",
|
|
15
15
|
"ajv": "8.20.0",
|
|
16
16
|
"browser-use": "0.9.0",
|
|
@@ -57,5 +57,5 @@
|
|
|
57
57
|
},
|
|
58
58
|
"type": "module",
|
|
59
59
|
"types": "dist/index.d.ts",
|
|
60
|
-
"version": "0.1.135-codali.
|
|
60
|
+
"version": "0.1.135-codali.37"
|
|
61
61
|
}
|