@bike4mind/cli 3.4.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 +223 -39
- package/bin/bike4mind-cli.mjs +301 -38
- package/bin/envFlags.d.mts +17 -0
- package/bin/envFlags.mjs +89 -0
- package/bin/hearth-hook.mjs +53 -7
- package/dist/{AgentHistoryStore-ClO2zOn6.mjs → AgentHistoryStore--J3sgO_-.mjs} +9011 -6699
- package/dist/ApiClient-CdO4Gamg.mjs +152 -0
- package/dist/BubblewrapRuntime-3jAbC60G.mjs +157 -0
- package/dist/ConfigStore-CausUCzY.mjs +2 -0
- package/dist/ConfigStore-Dusy6glb.mjs +3364 -0
- package/dist/{ConfigStore-CbVFLXMH.mjs → Logger-C1Wj6xla.mjs} +32880 -20779
- package/dist/{ProxyManager-B0-RuR2w.mjs → ProxyManager-TxEKlgdO.mjs} +88 -3
- package/dist/RemoteSkillSource-qTvRkaNA.mjs +455 -0
- 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-SeNbzvEw.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 +33 -27
- 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 +118 -36
- package/dist/commands/hostCommand.mjs +2344 -0
- package/dist/commands/mcpCommand.mjs +46 -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 +404 -0
- 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 +1001 -442
- package/dist/modelHub-BSB6qRFP.mjs +1963 -0
- package/dist/modelServers-BaegigV-.mjs +2465 -0
- package/dist/{package-MoDZ9cGj.mjs → package-C9pfAdGF.mjs} +1 -1
- package/dist/{serve-zi-B2iUT.mjs → serve-8wyGb8of.mjs} +1243 -44
- package/dist/store-BYeE0shc.mjs +2 -0
- package/dist/{store-BxmPEI3v.mjs → store-BbvSi3KK.mjs} +26 -2
- 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 +17 -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/buildAgent-BeaVbpzH.mjs +0 -1992
- package/dist/dist-DlBq3wHu.mjs +0 -739
- package/dist/store-BkMur6uk.mjs +0 -2
- package/dist/types-I45lMh7Q.mjs +0 -2
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { accessSync, constants, lstatSync, readFileSync, realpathSync } 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
|
+
/** Docker, Podman, Colima, Lima, Rancher Desktop and OrbStack API sockets, or the directories holding them. */
|
|
10
|
+
function getContainerSocketPaths() {
|
|
11
|
+
const home = os.homedir();
|
|
12
|
+
const env = process.env;
|
|
13
|
+
const entries = [
|
|
14
|
+
{
|
|
15
|
+
path: "/var/run/docker.sock",
|
|
16
|
+
directory: false
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
path: "/run/docker.sock",
|
|
20
|
+
directory: false
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
path: "/run/podman",
|
|
24
|
+
directory: true
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
path: path.join(home, ".docker"),
|
|
28
|
+
directory: true
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
path: path.join(home, "Library", "Containers", "com.docker.docker", "Data"),
|
|
32
|
+
directory: true
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
path: path.join(home, ".colima"),
|
|
36
|
+
directory: true
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
path: path.join(home, ".lima"),
|
|
40
|
+
directory: true
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
path: path.join(home, ".rd"),
|
|
44
|
+
directory: true
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
path: path.join(home, ".orbstack"),
|
|
48
|
+
directory: true
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
path: path.join(home, ".local", "share", "containers"),
|
|
52
|
+
directory: true
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
path: path.join(os.tmpdir(), "podman"),
|
|
56
|
+
directory: true
|
|
57
|
+
}
|
|
58
|
+
];
|
|
59
|
+
const addIfAbsolute = (p, directory) => {
|
|
60
|
+
if (p && path.isAbsolute(p)) entries.push({
|
|
61
|
+
path: p,
|
|
62
|
+
directory
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
if (env.XDG_RUNTIME_DIR && path.isAbsolute(env.XDG_RUNTIME_DIR)) {
|
|
66
|
+
addIfAbsolute(path.join(env.XDG_RUNTIME_DIR, "docker.sock"), false);
|
|
67
|
+
addIfAbsolute(path.join(env.XDG_RUNTIME_DIR, "podman"), true);
|
|
68
|
+
}
|
|
69
|
+
for (const host of [env.DOCKER_HOST, env.CONTAINER_HOST]) if (host?.startsWith("unix://")) addIfAbsolute(host.slice(7), false);
|
|
70
|
+
addIfAbsolute(env.COLIMA_HOME, true);
|
|
71
|
+
addIfAbsolute(env.LIMA_HOME, true);
|
|
72
|
+
const configHome = env.XDG_CONFIG_HOME && path.isAbsolute(env.XDG_CONFIG_HOME) ? env.XDG_CONFIG_HOME : path.join(home, ".config");
|
|
73
|
+
addIfAbsolute(path.join(configHome, "colima"), true);
|
|
74
|
+
return entries;
|
|
75
|
+
}
|
|
76
|
+
/** Rejects anything but a TCP port number before it is written into a profile or relay script. */
|
|
77
|
+
function assertProxyPort(port) {
|
|
78
|
+
if (!Number.isInteger(port) || port < 1 || port > 65535) throw new Error(`Invalid sandbox proxy port: ${port}`);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Detect the current platform.
|
|
82
|
+
* Returns null if the platform is not supported for sandboxing.
|
|
83
|
+
*/
|
|
84
|
+
function detectPlatform() {
|
|
85
|
+
const platform = os.platform();
|
|
86
|
+
if (platform === "darwin") return "darwin";
|
|
87
|
+
if (platform === "linux") return "linux";
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Check if a binary exists on the system PATH.
|
|
92
|
+
* Uses pure filesystem checks instead of shell execution to avoid command injection.
|
|
93
|
+
*/
|
|
94
|
+
function isBinaryAvailable(binary) {
|
|
95
|
+
const pathDirs = (process.env.PATH || "").split(path.delimiter);
|
|
96
|
+
for (const dir of pathDirs) try {
|
|
97
|
+
accessSync(path.join(dir, binary), constants.X_OK);
|
|
98
|
+
return true;
|
|
99
|
+
} catch {}
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Expand environment variables ($HOME, $USER) in a path string.
|
|
104
|
+
*/
|
|
105
|
+
function expandPath(pathStr) {
|
|
106
|
+
return pathStr.replace(/\$HOME/g, os.homedir()).replace(/\$USER/g, os.userInfo().username).replace(/~\//g, `${os.homedir()}/`);
|
|
107
|
+
}
|
|
108
|
+
/** Paths under cwd that stay read-only inside the writable working directory. */
|
|
109
|
+
function getProtectedWorkspacePaths(cwd) {
|
|
110
|
+
const git = findGitEntry(cwd);
|
|
111
|
+
const repositoryRoot = path.dirname(git);
|
|
112
|
+
const protectedPaths = /* @__PURE__ */ new Set([
|
|
113
|
+
path.join(cwd, ".git"),
|
|
114
|
+
path.join(cwd, ".bike4mind"),
|
|
115
|
+
git,
|
|
116
|
+
path.join(repositoryRoot, ".bike4mind")
|
|
117
|
+
]);
|
|
118
|
+
let ancestor = cwd;
|
|
119
|
+
while (path.dirname(ancestor) !== ancestor) {
|
|
120
|
+
if ([".git", ".bike4mind"].includes(path.basename(ancestor))) protectedPaths.add(ancestor);
|
|
121
|
+
ancestor = path.dirname(ancestor);
|
|
122
|
+
}
|
|
123
|
+
const gitDirectory = readMetadataFile(git)?.match(/^gitdir:\s*(.+)\s*$/)?.[1];
|
|
124
|
+
if (gitDirectory) {
|
|
125
|
+
const metadataPath = path.resolve(repositoryRoot, gitDirectory.trim());
|
|
126
|
+
protectedPaths.add(metadataPath);
|
|
127
|
+
const commonDirectory = readMetadataFile(path.join(metadataPath, "commondir"))?.trim();
|
|
128
|
+
if (commonDirectory) protectedPaths.add(path.resolve(metadataPath, commonDirectory));
|
|
129
|
+
}
|
|
130
|
+
for (const protectedPath of [...protectedPaths]) protectedPaths.add(resolveSandboxPath(protectedPath));
|
|
131
|
+
return [...protectedPaths];
|
|
132
|
+
}
|
|
133
|
+
function findGitEntry(cwd) {
|
|
134
|
+
let directory = cwd;
|
|
135
|
+
while (true) {
|
|
136
|
+
const gitPath = path.join(directory, ".git");
|
|
137
|
+
try {
|
|
138
|
+
lstatSync(gitPath);
|
|
139
|
+
return gitPath;
|
|
140
|
+
} catch (error) {
|
|
141
|
+
if (!(error instanceof Error && "code" in error && ["ENOENT", "ENOTDIR"].includes(String(error.code)))) throw error;
|
|
142
|
+
}
|
|
143
|
+
const parentDirectory = path.dirname(directory);
|
|
144
|
+
if (parentDirectory === directory) return path.join(cwd, ".git");
|
|
145
|
+
directory = parentDirectory;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
function readMetadataFile(filePath) {
|
|
149
|
+
try {
|
|
150
|
+
return readFileSync(filePath, "utf8");
|
|
151
|
+
} catch (error) {
|
|
152
|
+
if (error instanceof Error && "code" in error && [
|
|
153
|
+
"ENOENT",
|
|
154
|
+
"ENOTDIR",
|
|
155
|
+
"EISDIR"
|
|
156
|
+
].includes(String(error.code))) return;
|
|
157
|
+
throw error;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
/** Resolve aliases so sensitive symlinks are protected at their actual target. */
|
|
161
|
+
function resolveSandboxPath(pathString) {
|
|
162
|
+
const expandedPath = path.resolve(expandPath(pathString));
|
|
163
|
+
try {
|
|
164
|
+
return realpathSync(expandedPath);
|
|
165
|
+
} catch (error) {
|
|
166
|
+
if (error instanceof Error && "code" in error && ["ENOENT", "ENOTDIR"].includes(String(error.code))) {
|
|
167
|
+
const parentPath = path.dirname(expandedPath);
|
|
168
|
+
return parentPath === expandedPath ? expandedPath : path.join(resolveSandboxPath(parentPath), path.basename(expandedPath));
|
|
169
|
+
}
|
|
170
|
+
throw error;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Factory function to create the appropriate sandbox runtime for the current platform.
|
|
175
|
+
* Returns null if the platform is unsupported or the runtime binary is not available.
|
|
176
|
+
*/
|
|
177
|
+
async function createSandboxRuntime() {
|
|
178
|
+
const platform = detectPlatform();
|
|
179
|
+
if (!platform) return null;
|
|
180
|
+
if (platform === "darwin") {
|
|
181
|
+
const { SeatbeltRuntime } = await import("./SeatbeltRuntime-C2DEkrjy.mjs");
|
|
182
|
+
const runtime = new SeatbeltRuntime();
|
|
183
|
+
return runtime.isAvailable() ? runtime : null;
|
|
184
|
+
}
|
|
185
|
+
const { BubblewrapRuntime } = await import("./BubblewrapRuntime-3jAbC60G.mjs");
|
|
186
|
+
const runtime = new BubblewrapRuntime();
|
|
187
|
+
return runtime.isAvailable() ? runtime : null;
|
|
188
|
+
}
|
|
189
|
+
//#endregion
|
|
190
|
+
export { getContainerSocketPaths as a, resolveSandboxPath as c, expandPath as i, createSandboxRuntime as n, getProtectedWorkspacePaths as o, detectPlatform as r, isBinaryAvailable as s, assertProxyPort as t };
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { t as logger } from "./Logger-C1Wj6xla.mjs";
|
|
3
|
+
import { a as getContainerSocketPaths, c as resolveSandboxPath, o as getProtectedWorkspacePaths, s as isBinaryAvailable, t as assertProxyPort } from "./SandboxRuntimeAdapter-BsT2iLky.mjs";
|
|
4
|
+
import { mkdtempSync, writeFileSync } from "fs";
|
|
5
|
+
import os from "os";
|
|
6
|
+
import path from "path";
|
|
7
|
+
//#region src/sandbox/runtime/SeatbeltRuntime.ts
|
|
8
|
+
/**
|
|
9
|
+
* macOS Seatbelt (sandbox-exec) runtime implementation.
|
|
10
|
+
*
|
|
11
|
+
* Generates dynamic Seatbelt profiles to restrict filesystem access.
|
|
12
|
+
* Uses Apple's Sandbox framework via the `sandbox-exec` CLI tool.
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Escape a path for use in a Seatbelt profile.
|
|
16
|
+
*
|
|
17
|
+
* Seatbelt profiles use S-expression (Scheme-like) syntax where paths are
|
|
18
|
+
* enclosed in quoted strings. Only two characters need escaping:
|
|
19
|
+
* - Backslash (\): Must be doubled to prevent interpreting the next char as special.
|
|
20
|
+
* - Double quote ("): Must be escaped to prevent closing the string prematurely.
|
|
21
|
+
*
|
|
22
|
+
* Scheme syntax characters like (, ), and ; do NOT need escaping because they
|
|
23
|
+
* are only special at the expression parsing level. Inside a quoted string,
|
|
24
|
+
* they are treated as literal characters and cannot inject directives.
|
|
25
|
+
*/
|
|
26
|
+
function escapeSeatbeltPath(p) {
|
|
27
|
+
return p.replace(/\\/g, "\\\\").replace(/"/g, "\\\"");
|
|
28
|
+
}
|
|
29
|
+
const MDNS_RESPONDER_SOCKET = "/private/var/run/mDNSResponder";
|
|
30
|
+
const DEVICE_WRITE_ALLOWS = [
|
|
31
|
+
"(allow file-write-data (literal \"/dev/null\"))",
|
|
32
|
+
"(allow file-write-data (literal \"/dev/zero\"))",
|
|
33
|
+
"(allow file-write-data (literal \"/dev/dtracehelper\"))",
|
|
34
|
+
"(allow file-write-data (subpath \"/dev/fd\"))"
|
|
35
|
+
];
|
|
36
|
+
/** Unresolvable paths keep their rule at the unresolved location instead of failing profile generation. */
|
|
37
|
+
function resolveProfilePath(p) {
|
|
38
|
+
try {
|
|
39
|
+
return resolveSandboxPath(p);
|
|
40
|
+
} catch (error) {
|
|
41
|
+
if (error instanceof Error && "code" in error && [
|
|
42
|
+
"EACCES",
|
|
43
|
+
"ELOOP",
|
|
44
|
+
"EPERM"
|
|
45
|
+
].includes(String(error.code))) {
|
|
46
|
+
logger.debug(`Sandbox: using unresolved profile path ${p}: ${error.code}`);
|
|
47
|
+
return p;
|
|
48
|
+
}
|
|
49
|
+
throw error;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Seatbelt matches a socket connect against the fully resolved path, so a symlink like
|
|
54
|
+
* /var/run/docker.sock is denied at its current target, resolved each time a profile is built.
|
|
55
|
+
* The write denies stop a socket in a writable directory from being renamed to an unlisted path,
|
|
56
|
+
* directly or by renaming one of its parent directories.
|
|
57
|
+
*/
|
|
58
|
+
function containerSocketDenies() {
|
|
59
|
+
const network = /* @__PURE__ */ new Set();
|
|
60
|
+
const fileWrite = /* @__PURE__ */ new Set();
|
|
61
|
+
for (const entry of getContainerSocketPaths()) {
|
|
62
|
+
const resolvedParent = path.join(resolveProfilePath(path.dirname(entry.path)), path.basename(entry.path));
|
|
63
|
+
for (const candidate of [resolvedParent, resolveProfilePath(entry.path)]) {
|
|
64
|
+
const filter = entry.directory ? "subpath" : "path-literal";
|
|
65
|
+
const escaped = escapeSeatbeltPath(candidate);
|
|
66
|
+
network.add(`(deny network-outbound (remote unix-socket (${filter} "${escaped}")))`);
|
|
67
|
+
fileWrite.add(`(deny file-write* (${filter} "${escaped}"))`);
|
|
68
|
+
for (let dir = path.dirname(candidate); dir !== path.dirname(dir); dir = path.dirname(dir)) fileWrite.add(`(deny file-write* (path-literal "${escapeSeatbeltPath(dir)}"))`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
network: [...network],
|
|
73
|
+
fileWrite: [...fileWrite]
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
var SeatbeltRuntime = class {
|
|
77
|
+
constructor() {
|
|
78
|
+
this.platform = "darwin";
|
|
79
|
+
this.name = "seatbelt";
|
|
80
|
+
}
|
|
81
|
+
isAvailable() {
|
|
82
|
+
return isBinaryAvailable("sandbox-exec");
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Generate a Seatbelt profile string from the filesystem config.
|
|
86
|
+
*
|
|
87
|
+
* Strategy:
|
|
88
|
+
* - Start with (allow default) to permit most operations
|
|
89
|
+
* - Deny all file writes globally
|
|
90
|
+
* - Allow file writes only to the working directory
|
|
91
|
+
* - Deny all access to explicitly denied paths
|
|
92
|
+
* - Allow read access to explicitly allowed paths
|
|
93
|
+
*/
|
|
94
|
+
generateProfile(options) {
|
|
95
|
+
const { cwd, filesystemConfig } = options;
|
|
96
|
+
const expandedDenied = filesystemConfig.deniedPaths.map(resolveSandboxPath);
|
|
97
|
+
const expandedAllowed = filesystemConfig.allowedReadPaths.map(resolveSandboxPath);
|
|
98
|
+
const containerDenies = options.allowContainerSockets ? null : containerSocketDenies();
|
|
99
|
+
const lines = [
|
|
100
|
+
"(version 1)",
|
|
101
|
+
"",
|
|
102
|
+
"; Start with permissive defaults (process exec, network, sysctl, etc.)",
|
|
103
|
+
"(allow default)",
|
|
104
|
+
""
|
|
105
|
+
];
|
|
106
|
+
lines.push("; Deny all network, then re-allow local unix sockets except the DNS resolver");
|
|
107
|
+
lines.push("(deny network*)");
|
|
108
|
+
lines.push("(allow network-outbound (remote unix-socket))");
|
|
109
|
+
lines.push("(allow network-inbound (local unix-socket))");
|
|
110
|
+
lines.push("(allow network-bind (local unix-socket))");
|
|
111
|
+
lines.push(`(deny network-outbound (remote unix-socket (path-literal "${MDNS_RESPONDER_SOCKET}")))`);
|
|
112
|
+
if (options.networkEnabled && options.proxyPort !== void 0) {
|
|
113
|
+
assertProxyPort(options.proxyPort);
|
|
114
|
+
lines.push("; Allow outbound loopback to the filtering proxy only");
|
|
115
|
+
lines.push("(allow network-bind (local ip \"localhost:*\"))");
|
|
116
|
+
lines.push("(allow network-inbound (local ip \"localhost:*\"))");
|
|
117
|
+
lines.push(`(allow network-outbound (remote ip "localhost:${options.proxyPort}"))`);
|
|
118
|
+
}
|
|
119
|
+
if (containerDenies) {
|
|
120
|
+
lines.push("; Keep container engine sockets out of reach");
|
|
121
|
+
lines.push(...containerDenies.network);
|
|
122
|
+
}
|
|
123
|
+
lines.push("");
|
|
124
|
+
if (filesystemConfig.writeOnlyToWorkingDir) {
|
|
125
|
+
lines.push("; Deny all file writes globally");
|
|
126
|
+
lines.push("(deny file-write*)");
|
|
127
|
+
lines.push("");
|
|
128
|
+
const writable = (p) => [.../* @__PURE__ */ new Set([p, resolveProfilePath(p)])];
|
|
129
|
+
lines.push("; Allow writes to working directory");
|
|
130
|
+
for (const p of writable(cwd)) lines.push(`(allow file-write* (subpath "${escapeSeatbeltPath(p)}"))`);
|
|
131
|
+
lines.push("");
|
|
132
|
+
lines.push("; Allow writes to temp directories");
|
|
133
|
+
lines.push(`(allow file-write* (subpath "/tmp"))`);
|
|
134
|
+
lines.push(`(allow file-write* (subpath "/private/tmp"))`);
|
|
135
|
+
for (const p of writable(os.tmpdir())) lines.push(`(allow file-write* (subpath "${escapeSeatbeltPath(p)}"))`);
|
|
136
|
+
lines.push("");
|
|
137
|
+
lines.push("; Allow writes to standard device files");
|
|
138
|
+
lines.push(...DEVICE_WRITE_ALLOWS);
|
|
139
|
+
lines.push("");
|
|
140
|
+
}
|
|
141
|
+
lines.push("; Keep protected workspace paths read-only");
|
|
142
|
+
for (const protectedPath of getProtectedWorkspacePaths(cwd)) lines.push(`(deny file-write* (subpath "${escapeSeatbeltPath(protectedPath)}"))`);
|
|
143
|
+
lines.push("");
|
|
144
|
+
if (containerDenies) {
|
|
145
|
+
lines.push("; Keep container engine sockets where they are");
|
|
146
|
+
lines.push(...containerDenies.fileWrite, "");
|
|
147
|
+
}
|
|
148
|
+
if (expandedAllowed.length > 0) {
|
|
149
|
+
lines.push("; Explicitly allowed read paths");
|
|
150
|
+
for (const allowedPath of expandedAllowed) lines.push(`(allow file-read* (subpath "${escapeSeatbeltPath(allowedPath)}"))`);
|
|
151
|
+
lines.push("");
|
|
152
|
+
}
|
|
153
|
+
if (expandedDenied.length > 0) {
|
|
154
|
+
lines.push("; Deny access to sensitive paths");
|
|
155
|
+
for (const deniedPath of expandedDenied) lines.push(`(deny file-read* file-write* (subpath "${escapeSeatbeltPath(deniedPath)}"))`);
|
|
156
|
+
lines.push("");
|
|
157
|
+
}
|
|
158
|
+
return lines.join("\n");
|
|
159
|
+
}
|
|
160
|
+
wrapCommand(options) {
|
|
161
|
+
try {
|
|
162
|
+
const profile = this.generateProfile(options);
|
|
163
|
+
const tmpDir = mkdtempSync(path.join(os.tmpdir(), "b4m-sandbox-"));
|
|
164
|
+
const profilePath = path.join(tmpDir, "sandbox.sb");
|
|
165
|
+
writeFileSync(profilePath, profile, "utf-8");
|
|
166
|
+
const args = [
|
|
167
|
+
"-f",
|
|
168
|
+
profilePath,
|
|
169
|
+
"bash",
|
|
170
|
+
"-c",
|
|
171
|
+
options.command
|
|
172
|
+
];
|
|
173
|
+
const envEntries = Object.entries(options.env ?? {});
|
|
174
|
+
const envPrefix = envEntries.length > 0 ? envEntries.map(([k, v]) => `${k}=${shellEscape(v)}`).join(" ") + " " : "";
|
|
175
|
+
return {
|
|
176
|
+
executable: "sandbox-exec",
|
|
177
|
+
args,
|
|
178
|
+
env: options.env ?? {},
|
|
179
|
+
commandString: `${envPrefix}sandbox-exec -f ${profilePath} bash -c ${shellEscape(options.command)}`,
|
|
180
|
+
cleanupPaths: [profilePath, tmpDir]
|
|
181
|
+
};
|
|
182
|
+
} catch (err) {
|
|
183
|
+
throw new Error(`Failed to create sandbox profile: ${err instanceof Error ? err.message : String(err)}`);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
/**
|
|
188
|
+
* Shell-escape a string for safe embedding in a command.
|
|
189
|
+
*/
|
|
190
|
+
function shellEscape(str) {
|
|
191
|
+
return `'${str.replace(/'/g, "'\\''")}'`;
|
|
192
|
+
}
|
|
193
|
+
//#endregion
|
|
194
|
+
export { SeatbeltRuntime };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
2
|
+
import { Bt as tokenEstimateMultiplier } from "./Logger-C1Wj6xla.mjs";
|
|
3
3
|
import { v4 } from "uuid";
|
|
4
4
|
import { get_encoding } from "tiktoken";
|
|
5
5
|
//#region ../../b4m-core/utils/dist/calibratedTokenizer.mjs
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
description: Code quality analysis and review
|
|
3
|
-
model: claude-sonnet-
|
|
3
|
+
model: claude-sonnet-5-5
|
|
4
4
|
allowed-tools:
|
|
5
5
|
- file_read
|
|
6
6
|
- grep_search
|
|
@@ -25,6 +25,7 @@ shared-context:
|
|
|
25
25
|
You are a code review specialist. Your job is to analyze code quality and identify issues.
|
|
26
26
|
|
|
27
27
|
## Focus Areas
|
|
28
|
+
|
|
28
29
|
- Code quality and best practices
|
|
29
30
|
- Potential bugs and edge cases
|
|
30
31
|
- Performance considerations
|
|
@@ -32,24 +33,30 @@ You are a code review specialist. Your job is to analyze code quality and identi
|
|
|
32
33
|
- Maintainability and readability
|
|
33
34
|
|
|
34
35
|
## Review Process
|
|
36
|
+
|
|
35
37
|
1. Understand the context and purpose of the code
|
|
36
38
|
2. Check for common issues (error handling, edge cases, null checks)
|
|
37
39
|
3. Verify consistent patterns with rest of codebase
|
|
38
40
|
4. Look for security concerns (injection, XSS, etc.)
|
|
39
41
|
|
|
40
42
|
## Output Format
|
|
43
|
+
|
|
41
44
|
Provide actionable feedback:
|
|
42
45
|
|
|
43
46
|
### Critical Issues
|
|
47
|
+
|
|
44
48
|
- [file:line] Description of issue and why it matters
|
|
45
49
|
|
|
46
50
|
### Suggestions
|
|
51
|
+
|
|
47
52
|
- [file:line] Improvement suggestion
|
|
48
53
|
|
|
49
54
|
### Positive Observations
|
|
55
|
+
|
|
50
56
|
- What's done well (optional)
|
|
51
57
|
|
|
52
58
|
## Iteration Budget
|
|
59
|
+
|
|
53
60
|
You have **$MAX_ITERATIONS iterations** for this task (thoroughness: $THOROUGHNESS). Plan your tool usage to complete within this budget. Prioritize the most impactful actions first.
|
|
54
61
|
|
|
55
62
|
Be specific with file paths and line numbers. Focus on actionable feedback.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
description: Run and analyze test suites, identify failures, suggest fixes
|
|
3
|
-
model: claude-sonnet-
|
|
3
|
+
model: claude-sonnet-5-5
|
|
4
4
|
allowed-tools:
|
|
5
5
|
- bash_execute
|
|
6
6
|
- file_read
|
|
@@ -28,19 +28,23 @@ shared-context:
|
|
|
28
28
|
You are a test execution and analysis specialist. Your job is to run tests, analyze results, and identify failures.
|
|
29
29
|
|
|
30
30
|
## Focus Areas
|
|
31
|
+
|
|
31
32
|
- Running test suites and individual test files
|
|
32
33
|
- Analyzing test output for failures and errors
|
|
33
34
|
- Identifying root causes of test failures
|
|
34
35
|
- Suggesting targeted fixes
|
|
35
36
|
|
|
36
37
|
## Tool Usage
|
|
38
|
+
|
|
37
39
|
You have read-only file access plus bash for running tests:
|
|
40
|
+
|
|
38
41
|
- `bash_execute` - Run test commands (npm test, pnpm test, jest, pytest, etc.)
|
|
39
42
|
- `file_read` - Read test files and source files to understand failures
|
|
40
43
|
- `grep_search` - Search for related test patterns or error messages
|
|
41
44
|
- `glob_files` - Find test files by pattern
|
|
42
45
|
|
|
43
46
|
## Strategy
|
|
47
|
+
|
|
44
48
|
1. Identify the test framework in use (check package.json, config files)
|
|
45
49
|
2. Run the requested tests using `bash_execute`
|
|
46
50
|
3. Parse output for failures, errors, and warnings
|
|
@@ -49,13 +53,16 @@ You have read-only file access plus bash for running tests:
|
|
|
49
53
|
6. Provide clear diagnosis and fix suggestions
|
|
50
54
|
|
|
51
55
|
## Output Format
|
|
56
|
+
|
|
52
57
|
Provide a structured summary:
|
|
58
|
+
|
|
53
59
|
1. **Test Results**: Pass/fail counts, which tests failed
|
|
54
60
|
2. **Failure Analysis**: For each failure - what failed, why, stack trace highlights
|
|
55
61
|
3. **Root Cause**: Likely cause of each failure
|
|
56
62
|
4. **Suggested Fixes**: Concrete code changes to fix failures
|
|
57
63
|
|
|
58
64
|
## Iteration Budget
|
|
65
|
+
|
|
59
66
|
You have **$MAX_ITERATIONS iterations** for this task (thoroughness: $THOROUGHNESS). Plan your tool usage to complete within this budget. Prioritize the most impactful actions first.
|
|
60
67
|
|
|
61
68
|
Be precise with file:line references. Your summary will be used by the main agent.
|