@bike4mind/cli 4.0.0 → 4.6.0
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/README.md +86 -4
- package/bin/bike4mind-cli.mjs +249 -40
- package/bin/envFlags.d.mts +17 -0
- package/bin/envFlags.mjs +89 -0
- package/dist/{AgentHistoryStore-DgqmcVLN.mjs → AgentHistoryStore--J3sgO_-.mjs} +3794 -1368
- package/dist/{ApiClient-_JrM_xWw.mjs → ApiClient-CdO4Gamg.mjs} +22 -3
- package/dist/BubblewrapRuntime-3jAbC60G.mjs +157 -0
- package/dist/ConfigStore-CausUCzY.mjs +2 -0
- package/dist/ConfigStore-Dusy6glb.mjs +3364 -0
- package/dist/{ConfigStore-BwqsQ0U9.mjs → Logger-C1Wj6xla.mjs} +32672 -21643
- package/dist/{ProxyManager-B0-RuR2w.mjs → ProxyManager-TxEKlgdO.mjs} +88 -3
- package/dist/{SandboxOrchestrator-BcUv9fQ3.mjs → SandboxOrchestrator-CQwYq_uy.mjs} +26 -7
- package/dist/SandboxRuntimeAdapter-BsT2iLky.mjs +190 -0
- package/dist/SandboxRuntimeAdapter-Zg_0th7V.mjs +2 -0
- package/dist/SeatbeltRuntime-C2DEkrjy.mjs +194 -0
- package/dist/{WorkItemsClient-CERTDrhT.mjs → WorkItemsClient-CxNZaOmc.mjs} +1 -1
- package/dist/agents/defaults/review.md +8 -1
- package/dist/agents/defaults/test.md +8 -1
- package/dist/buildToolSearch-DOb7mx6F.mjs +417 -0
- package/dist/commands/acpCommand.mjs +25 -19
- package/dist/commands/apiCommand.mjs +3 -5
- package/dist/commands/doctorCommand.mjs +2 -2
- package/dist/commands/envCommand.mjs +1 -1
- package/dist/commands/headlessCommand.mjs +117 -36
- package/dist/commands/hostCommand.mjs +2344 -0
- package/dist/commands/mcpCommand.mjs +45 -30
- package/dist/commands/mirrorCommand.mjs +279 -0
- package/dist/commands/modelsCommand.mjs +1117 -0
- package/dist/commands/pluginCommand.mjs +9 -9
- package/dist/commands/skillsCommand.mjs +174 -29
- package/dist/commands/updateCommand.mjs +2 -2
- package/dist/curated-build.json +1 -0
- package/dist/dist-CbViwiS9.mjs +4739 -0
- package/dist/dist-Citbv0y0.mjs +7864 -0
- package/dist/fit-CVWDiavv.mjs +200 -0
- package/dist/index.mjs +853 -417
- package/dist/modelHub-BSB6qRFP.mjs +1963 -0
- package/dist/modelServers-BaegigV-.mjs +2465 -0
- package/dist/{package-CQaam4Dq.mjs → package-C9pfAdGF.mjs} +1 -1
- package/dist/{serve-CFxUhjml.mjs → serve-8wyGb8of.mjs} +595 -26
- package/dist/types-BFIvwByC.mjs +2 -0
- package/dist/{types-F61_hxmG.mjs → types-CxrzVXel.mjs} +9 -5
- package/dist/{updateChecker-CCLVVdH0.mjs → updateChecker-BAKb8KWP.mjs} +7 -29
- package/package.json +16 -13
- package/dist/BubblewrapRuntime-5bLPTwEC.mjs +0 -72
- package/dist/SandboxRuntimeAdapter-BgLUVTJL.mjs +0 -57
- package/dist/SandboxRuntimeAdapter-Bt1wPpld.mjs +0 -2
- package/dist/SeatbeltRuntime-C_Y8q8Mr.mjs +0 -124
- package/dist/buildToolSearch-D9GEK91u.mjs +0 -2351
- package/dist/dist-Ul2qwn5x.mjs +0 -624
- package/dist/types-I45lMh7Q.mjs +0 -2
|
@@ -6,11 +6,7 @@ const DEFAULT_SANDBOX_CONFIG = {
|
|
|
6
6
|
mode: "disabled",
|
|
7
7
|
filesystem: {
|
|
8
8
|
writeOnlyToWorkingDir: true,
|
|
9
|
-
allowedReadPaths: [
|
|
10
|
-
"$HOME/.gitconfig",
|
|
11
|
-
"$HOME/.npmrc",
|
|
12
|
-
"$HOME/.node_modules"
|
|
13
|
-
],
|
|
9
|
+
allowedReadPaths: ["$HOME/.gitconfig", "$HOME/.node_modules"],
|
|
14
10
|
deniedPaths: [
|
|
15
11
|
"$HOME/.ssh",
|
|
16
12
|
"$HOME/.aws",
|
|
@@ -18,6 +14,13 @@ const DEFAULT_SANDBOX_CONFIG = {
|
|
|
18
14
|
"$HOME/.env",
|
|
19
15
|
"$HOME/.claude",
|
|
20
16
|
"$HOME/.bike4mind",
|
|
17
|
+
"$HOME/.npmrc",
|
|
18
|
+
"$HOME/.netrc",
|
|
19
|
+
"$HOME/.config/gh",
|
|
20
|
+
"$HOME/.docker",
|
|
21
|
+
"$HOME/.kube",
|
|
22
|
+
"$HOME/.config/gcloud",
|
|
23
|
+
"$HOME/.azure",
|
|
21
24
|
"/etc/shadow",
|
|
22
25
|
"/etc/passwd"
|
|
23
26
|
]
|
|
@@ -49,6 +52,7 @@ const DEFAULT_SANDBOX_CONFIG = {
|
|
|
49
52
|
"podman"
|
|
50
53
|
],
|
|
51
54
|
allowUnsandboxedCommands: true,
|
|
55
|
+
allowContainerSockets: false,
|
|
52
56
|
platform: {
|
|
53
57
|
linux: { runtime: "bubblewrap" },
|
|
54
58
|
macos: {
|
|
@@ -81,37 +81,15 @@ async function getAutoUpdatePreference() {
|
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
83
|
/**
|
|
84
|
-
* Persist the user's `autoUpdate` choice (`true` = always, `false` = never)
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
* `ConfigStore.save()`. `ConfigStore.load()` merges global -> project -> local,
|
|
89
|
-
* and `ConfigStore.save()` writes that merged result back to the global path;
|
|
90
|
-
* answering "Always"/"Never" inside a project would therefore bake the
|
|
91
|
-
* project's other overrides (model, theme, temperature, ...) into the user's
|
|
92
|
-
* global config as a silent side effect. This call fires during the bin
|
|
93
|
-
* bootstrap any time an update is available, so that blast radius is
|
|
94
|
-
* unacceptable. A direct read-merge-write of only `preferences.autoUpdate`
|
|
95
|
-
* avoids it. If the on-disk file is schema-incomplete, the next
|
|
96
|
-
* `ConfigStore.load()` backfills defaults harmlessly - exactly as
|
|
97
|
-
* `getAutoUpdatePreference` already tolerates a partial file. Best-effort:
|
|
98
|
-
* a failure is swallowed (we simply ask again next launch rather than blocking).
|
|
84
|
+
* Persist the user's `autoUpdate` choice (`true` = always, `false` = never) through
|
|
85
|
+
* ConfigStore.saveAutoUpdatePreference, which sets only that key in the global file under the config write lock,
|
|
86
|
+
* and rejects rather than writing over a file it could not read. Best-effort: a failure is swallowed (we simply ask
|
|
87
|
+
* again next launch rather than blocking). ConfigStore is imported lazily to keep the bin bootstrap light.
|
|
99
88
|
*/
|
|
100
|
-
async function setAutoUpdatePreference(value) {
|
|
89
|
+
async function setAutoUpdatePreference(value, configPath) {
|
|
101
90
|
try {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
const parsed = JSON.parse(await promises.readFile(CONFIG_FILE, "utf-8"));
|
|
105
|
-
if (parsed && typeof parsed === "object") raw = parsed;
|
|
106
|
-
} catch {}
|
|
107
|
-
const prefs = raw.preferences && typeof raw.preferences === "object" ? raw.preferences : {};
|
|
108
|
-
raw.preferences = {
|
|
109
|
-
...prefs,
|
|
110
|
-
autoUpdate: value
|
|
111
|
-
};
|
|
112
|
-
await promises.mkdir(path.dirname(CONFIG_FILE), { recursive: true });
|
|
113
|
-
await promises.writeFile(CONFIG_FILE, JSON.stringify(raw, null, 2), "utf-8");
|
|
114
|
-
await promises.chmod(CONFIG_FILE, 384);
|
|
91
|
+
const { ConfigStore } = await import("./ConfigStore-CausUCzY.mjs");
|
|
92
|
+
await new ConfigStore(configPath).saveAutoUpdatePreference(value);
|
|
115
93
|
} catch {}
|
|
116
94
|
}
|
|
117
95
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bike4mind/cli",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.6.0",
|
|
4
4
|
"mcpName": "io.github.Bike4Mind/bike4mind",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Interactive CLI tool for Bike4Mind with ReAct agents",
|
|
@@ -43,6 +43,7 @@
|
|
|
43
43
|
"@aws-sdk/client-lambda": "^3.1150.0",
|
|
44
44
|
"@aws-sdk/client-s3": "^3.1150.0",
|
|
45
45
|
"@aws-sdk/client-sqs": "^3.1150.0",
|
|
46
|
+
"@aws-sdk/client-sts": "^3.1150.0",
|
|
46
47
|
"@aws-sdk/client-transcribe": "^3.1150.0",
|
|
47
48
|
"@aws-sdk/credential-provider-node": "^3.972.86",
|
|
48
49
|
"@aws-sdk/s3-request-presigner": "^3.1150.0",
|
|
@@ -82,7 +83,7 @@
|
|
|
82
83
|
"marked": "^15.0.11",
|
|
83
84
|
"mathjs": "^15.2.0",
|
|
84
85
|
"mime-types": "^3.0.2",
|
|
85
|
-
"mongoose": "^8.24.
|
|
86
|
+
"mongoose": "^8.24.7",
|
|
86
87
|
"ollama": "^0.6.3",
|
|
87
88
|
"open": "^11.0.4",
|
|
88
89
|
"openai": "^6.46.0",
|
|
@@ -124,18 +125,20 @@
|
|
|
124
125
|
"tsdown": "^0.22.3",
|
|
125
126
|
"tsx": "^4.23.0",
|
|
126
127
|
"typescript": "^5.9.3",
|
|
127
|
-
"vitest": "^4.1.
|
|
128
|
-
"@bike4mind/agents": "1.
|
|
129
|
-
"@bike4mind/client-auth": "0.
|
|
130
|
-
"@bike4mind/common": "
|
|
131
|
-
"@bike4mind/fab-pipeline": "2.
|
|
128
|
+
"vitest": "^4.1.12",
|
|
129
|
+
"@bike4mind/agents": "1.8.1",
|
|
130
|
+
"@bike4mind/client-auth": "0.4.0",
|
|
131
|
+
"@bike4mind/common": "26.0.0",
|
|
132
|
+
"@bike4mind/fab-pipeline": "3.2.0",
|
|
132
133
|
"@bike4mind/hearth": "0.3.1",
|
|
133
|
-
"@bike4mind/llm-adapters": "2.
|
|
134
|
-
"@bike4mind/
|
|
135
|
-
"@bike4mind/
|
|
136
|
-
"@bike4mind/
|
|
137
|
-
"@bike4mind/
|
|
138
|
-
"@bike4mind/
|
|
134
|
+
"@bike4mind/llm-adapters": "2.5.1",
|
|
135
|
+
"@bike4mind/local-models": "0.1.5",
|
|
136
|
+
"@bike4mind/mcp": "2.2.4",
|
|
137
|
+
"@bike4mind/model-host": "0.1.0",
|
|
138
|
+
"@bike4mind/observability": "1.1.0",
|
|
139
|
+
"@bike4mind/sdk": "2.2.0",
|
|
140
|
+
"@bike4mind/services": "27.0.0",
|
|
141
|
+
"@bike4mind/utils": "11.2.0"
|
|
139
142
|
},
|
|
140
143
|
"optionalDependencies": {
|
|
141
144
|
"@vscode/ripgrep": "^1.18.0"
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { i as isBinaryAvailable, r as expandPath } from "./SandboxRuntimeAdapter-BgLUVTJL.mjs";
|
|
3
|
-
import os from "os";
|
|
4
|
-
//#region src/sandbox/runtime/BubblewrapRuntime.ts
|
|
5
|
-
/**
|
|
6
|
-
* Linux Bubblewrap (bwrap) runtime implementation.
|
|
7
|
-
*
|
|
8
|
-
* Uses bubblewrap to create a sandboxed environment with:
|
|
9
|
-
* - Read-only system paths (/usr, /lib, /bin, etc.)
|
|
10
|
-
* - Read-write access only to the working directory
|
|
11
|
-
* - Denied paths mounted as empty tmpfs
|
|
12
|
-
* - Process namespace isolation
|
|
13
|
-
*/
|
|
14
|
-
/** System paths to bind read-only into the sandbox */
|
|
15
|
-
const SYSTEM_RO_BINDS = [
|
|
16
|
-
"/usr",
|
|
17
|
-
"/bin",
|
|
18
|
-
"/lib",
|
|
19
|
-
"/lib64",
|
|
20
|
-
"/sbin",
|
|
21
|
-
"/etc"
|
|
22
|
-
];
|
|
23
|
-
/** Paths that need special handling (dev, proc, tmp) */
|
|
24
|
-
const SPECIAL_MOUNTS = {
|
|
25
|
-
dev: "/dev",
|
|
26
|
-
proc: "/proc",
|
|
27
|
-
tmp: "/tmp"
|
|
28
|
-
};
|
|
29
|
-
var BubblewrapRuntime = class {
|
|
30
|
-
constructor() {
|
|
31
|
-
this.platform = "linux";
|
|
32
|
-
this.name = "bubblewrap";
|
|
33
|
-
}
|
|
34
|
-
isAvailable() {
|
|
35
|
-
return isBinaryAvailable("bwrap");
|
|
36
|
-
}
|
|
37
|
-
wrapCommand(options) {
|
|
38
|
-
const { command, cwd, filesystemConfig, env } = options;
|
|
39
|
-
const expandedDenied = filesystemConfig.deniedPaths.map(expandPath);
|
|
40
|
-
const expandedAllowed = filesystemConfig.allowedReadPaths.map(expandPath);
|
|
41
|
-
const args = [];
|
|
42
|
-
for (const sysPath of SYSTEM_RO_BINDS) args.push("--ro-bind-try", sysPath, sysPath);
|
|
43
|
-
args.push("--dev", SPECIAL_MOUNTS.dev);
|
|
44
|
-
args.push("--proc", SPECIAL_MOUNTS.proc);
|
|
45
|
-
args.push("--tmpfs", SPECIAL_MOUNTS.tmp);
|
|
46
|
-
args.push("--bind", cwd, cwd);
|
|
47
|
-
const homeDir = os.homedir();
|
|
48
|
-
args.push("--ro-bind", homeDir, homeDir);
|
|
49
|
-
for (const allowedPath of expandedAllowed) if (!allowedPath.startsWith(homeDir)) args.push("--ro-bind-try", allowedPath, allowedPath);
|
|
50
|
-
for (const deniedPath of expandedDenied) args.push("--tmpfs", deniedPath);
|
|
51
|
-
args.push("--unshare-all");
|
|
52
|
-
args.push(options.networkEnabled ? "--share-net" : "--unshare-net");
|
|
53
|
-
args.push("--die-with-parent");
|
|
54
|
-
if (options.seccompProfile) args.push("--seccomp", options.seccompProfile);
|
|
55
|
-
for (const [key, value] of Object.entries(env ?? {})) args.push("--setenv", key, value);
|
|
56
|
-
args.push("--chdir", cwd);
|
|
57
|
-
args.push("bash", "-c", command);
|
|
58
|
-
const commandString = ["bwrap", ...args.map(shellEscape)].join(" ");
|
|
59
|
-
return {
|
|
60
|
-
executable: "bwrap",
|
|
61
|
-
args,
|
|
62
|
-
env: env ?? {},
|
|
63
|
-
commandString
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
function shellEscape(str) {
|
|
68
|
-
if (/^[a-zA-Z0-9._/=:-]+$/.test(str)) return str;
|
|
69
|
-
return `'${str.replace(/'/g, "'\\''")}'`;
|
|
70
|
-
}
|
|
71
|
-
//#endregion
|
|
72
|
-
export { BubblewrapRuntime };
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { accessSync, constants } from "fs";
|
|
3
|
-
import os from "os";
|
|
4
|
-
import path from "path";
|
|
5
|
-
//#region src/sandbox/runtime/SandboxRuntimeAdapter.ts
|
|
6
|
-
/**
|
|
7
|
-
* Abstract sandbox runtime adapter with platform detection and factory.
|
|
8
|
-
*/
|
|
9
|
-
/**
|
|
10
|
-
* Detect the current platform.
|
|
11
|
-
* Returns null if the platform is not supported for sandboxing.
|
|
12
|
-
*/
|
|
13
|
-
function detectPlatform() {
|
|
14
|
-
const platform = os.platform();
|
|
15
|
-
if (platform === "darwin") return "darwin";
|
|
16
|
-
if (platform === "linux") return "linux";
|
|
17
|
-
return null;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Check if a binary exists on the system PATH.
|
|
21
|
-
* Uses pure filesystem checks instead of shell execution to avoid command injection.
|
|
22
|
-
*/
|
|
23
|
-
function isBinaryAvailable(binary) {
|
|
24
|
-
const pathDirs = (process.env.PATH || "").split(path.delimiter);
|
|
25
|
-
for (const dir of pathDirs) try {
|
|
26
|
-
accessSync(path.join(dir, binary), constants.X_OK);
|
|
27
|
-
return true;
|
|
28
|
-
} catch {}
|
|
29
|
-
return false;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Expand environment variables ($HOME, $USER) in a path string.
|
|
33
|
-
*/
|
|
34
|
-
function expandPath(pathStr) {
|
|
35
|
-
return pathStr.replace(/\$HOME/g, os.homedir()).replace(/\$USER/g, os.userInfo().username).replace(/~\//g, `${os.homedir()}/`);
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Factory function to create the appropriate sandbox runtime for the current platform.
|
|
39
|
-
* Returns null if the platform is unsupported or the runtime binary is not available.
|
|
40
|
-
*/
|
|
41
|
-
async function createSandboxRuntime() {
|
|
42
|
-
const platform = detectPlatform();
|
|
43
|
-
if (!platform) return null;
|
|
44
|
-
if (platform === "darwin") {
|
|
45
|
-
const { SeatbeltRuntime } = await import("./SeatbeltRuntime-C_Y8q8Mr.mjs");
|
|
46
|
-
const runtime = new SeatbeltRuntime();
|
|
47
|
-
return runtime.isAvailable() ? runtime : null;
|
|
48
|
-
}
|
|
49
|
-
if (platform === "linux") {
|
|
50
|
-
const { BubblewrapRuntime } = await import("./BubblewrapRuntime-5bLPTwEC.mjs");
|
|
51
|
-
const runtime = new BubblewrapRuntime();
|
|
52
|
-
return runtime.isAvailable() ? runtime : null;
|
|
53
|
-
}
|
|
54
|
-
return null;
|
|
55
|
-
}
|
|
56
|
-
//#endregion
|
|
57
|
-
export { isBinaryAvailable as i, detectPlatform as n, expandPath as r, createSandboxRuntime as t };
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { i as isBinaryAvailable, r as expandPath } from "./SandboxRuntimeAdapter-BgLUVTJL.mjs";
|
|
3
|
-
import { mkdtempSync, writeFileSync } from "fs";
|
|
4
|
-
import os from "os";
|
|
5
|
-
import path from "path";
|
|
6
|
-
//#region src/sandbox/runtime/SeatbeltRuntime.ts
|
|
7
|
-
/**
|
|
8
|
-
* macOS Seatbelt (sandbox-exec) runtime implementation.
|
|
9
|
-
*
|
|
10
|
-
* Generates dynamic Seatbelt profiles to restrict filesystem access.
|
|
11
|
-
* Uses Apple's Sandbox framework via the `sandbox-exec` CLI tool.
|
|
12
|
-
*/
|
|
13
|
-
/**
|
|
14
|
-
* Escape a path for use in a Seatbelt profile.
|
|
15
|
-
*
|
|
16
|
-
* Seatbelt profiles use S-expression (Scheme-like) syntax where paths are
|
|
17
|
-
* enclosed in quoted strings. Only two characters need escaping:
|
|
18
|
-
* - Backslash (\): Must be doubled to prevent interpreting the next char as special.
|
|
19
|
-
* - Double quote ("): Must be escaped to prevent closing the string prematurely.
|
|
20
|
-
*
|
|
21
|
-
* Scheme syntax characters like (, ), and ; do NOT need escaping because they
|
|
22
|
-
* are only special at the expression parsing level. Inside a quoted string,
|
|
23
|
-
* they are treated as literal characters and cannot inject directives.
|
|
24
|
-
*/
|
|
25
|
-
function escapeSeatbeltPath(p) {
|
|
26
|
-
return p.replace(/\\/g, "\\\\").replace(/"/g, "\\\"");
|
|
27
|
-
}
|
|
28
|
-
var SeatbeltRuntime = class {
|
|
29
|
-
constructor() {
|
|
30
|
-
this.platform = "darwin";
|
|
31
|
-
this.name = "seatbelt";
|
|
32
|
-
}
|
|
33
|
-
isAvailable() {
|
|
34
|
-
return isBinaryAvailable("sandbox-exec");
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Generate a Seatbelt profile string from the filesystem config.
|
|
38
|
-
*
|
|
39
|
-
* Strategy:
|
|
40
|
-
* - Start with (allow default) to permit most operations
|
|
41
|
-
* - Deny all file writes globally
|
|
42
|
-
* - Allow file writes only to the working directory
|
|
43
|
-
* - Deny all access to explicitly denied paths
|
|
44
|
-
* - Allow read access to explicitly allowed paths
|
|
45
|
-
*/
|
|
46
|
-
generateProfile(options) {
|
|
47
|
-
const { cwd, filesystemConfig } = options;
|
|
48
|
-
const expandedDenied = filesystemConfig.deniedPaths.map(expandPath);
|
|
49
|
-
const expandedAllowed = filesystemConfig.allowedReadPaths.map(expandPath);
|
|
50
|
-
const lines = [
|
|
51
|
-
"(version 1)",
|
|
52
|
-
"",
|
|
53
|
-
"; Start with permissive defaults (process exec, network, sysctl, etc.)",
|
|
54
|
-
"(allow default)",
|
|
55
|
-
""
|
|
56
|
-
];
|
|
57
|
-
if (!options.networkEnabled) {
|
|
58
|
-
lines.push("; Deny all network, then re-allow local unix sockets (net: IP-only denial)");
|
|
59
|
-
lines.push("(deny network*)");
|
|
60
|
-
lines.push("(allow network-outbound (remote unix-socket))");
|
|
61
|
-
lines.push("(allow network-inbound (local unix-socket))");
|
|
62
|
-
lines.push("(allow network-bind (local unix-socket))");
|
|
63
|
-
lines.push("");
|
|
64
|
-
}
|
|
65
|
-
if (filesystemConfig.writeOnlyToWorkingDir) {
|
|
66
|
-
lines.push("; Deny all file writes globally");
|
|
67
|
-
lines.push("(deny file-write*)");
|
|
68
|
-
lines.push("");
|
|
69
|
-
lines.push("; Allow writes to working directory");
|
|
70
|
-
lines.push(`(allow file-write* (subpath "${escapeSeatbeltPath(cwd)}"))`);
|
|
71
|
-
lines.push("");
|
|
72
|
-
lines.push("; Allow writes to temp directories");
|
|
73
|
-
lines.push(`(allow file-write* (subpath "/tmp"))`);
|
|
74
|
-
lines.push(`(allow file-write* (subpath "/private/tmp"))`);
|
|
75
|
-
lines.push(`(allow file-write* (subpath "${escapeSeatbeltPath(os.tmpdir())}"))`);
|
|
76
|
-
lines.push("");
|
|
77
|
-
}
|
|
78
|
-
if (expandedDenied.length > 0) {
|
|
79
|
-
lines.push("; Deny access to sensitive paths");
|
|
80
|
-
for (const deniedPath of expandedDenied) lines.push(`(deny file-read* file-write* (subpath "${escapeSeatbeltPath(deniedPath)}"))`);
|
|
81
|
-
lines.push("");
|
|
82
|
-
}
|
|
83
|
-
if (expandedAllowed.length > 0) {
|
|
84
|
-
lines.push("; Explicitly allowed read paths");
|
|
85
|
-
for (const allowedPath of expandedAllowed) lines.push(`(allow file-read* (subpath "${escapeSeatbeltPath(allowedPath)}"))`);
|
|
86
|
-
lines.push("");
|
|
87
|
-
}
|
|
88
|
-
return lines.join("\n");
|
|
89
|
-
}
|
|
90
|
-
wrapCommand(options) {
|
|
91
|
-
try {
|
|
92
|
-
const profile = this.generateProfile(options);
|
|
93
|
-
const tmpDir = mkdtempSync(path.join(os.tmpdir(), "b4m-sandbox-"));
|
|
94
|
-
const profilePath = path.join(tmpDir, "sandbox.sb");
|
|
95
|
-
writeFileSync(profilePath, profile, "utf-8");
|
|
96
|
-
const args = [
|
|
97
|
-
"-f",
|
|
98
|
-
profilePath,
|
|
99
|
-
"bash",
|
|
100
|
-
"-c",
|
|
101
|
-
options.command
|
|
102
|
-
];
|
|
103
|
-
const envEntries = Object.entries(options.env ?? {});
|
|
104
|
-
const envPrefix = envEntries.length > 0 ? envEntries.map(([k, v]) => `${k}=${shellEscape(v)}`).join(" ") + " " : "";
|
|
105
|
-
return {
|
|
106
|
-
executable: "sandbox-exec",
|
|
107
|
-
args,
|
|
108
|
-
env: options.env ?? {},
|
|
109
|
-
commandString: `${envPrefix}sandbox-exec -f ${profilePath} bash -c ${shellEscape(options.command)}`,
|
|
110
|
-
cleanupPaths: [profilePath, tmpDir]
|
|
111
|
-
};
|
|
112
|
-
} catch (err) {
|
|
113
|
-
throw new Error(`Failed to create sandbox profile: ${err instanceof Error ? err.message : String(err)}`);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
};
|
|
117
|
-
/**
|
|
118
|
-
* Shell-escape a string for safe embedding in a command.
|
|
119
|
-
*/
|
|
120
|
-
function shellEscape(str) {
|
|
121
|
-
return `'${str.replace(/'/g, "'\\''")}'`;
|
|
122
|
-
}
|
|
123
|
-
//#endregion
|
|
124
|
-
export { SeatbeltRuntime };
|