@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
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { b as
|
|
3
|
-
import { t as
|
|
2
|
+
import { b as AuthenticatedApiClient, t as ConfigStore, x as DeviceFlowClient } from "./ConfigStore-Dusy6glb.mjs";
|
|
3
|
+
import { t as logger } from "./Logger-C1Wj6xla.mjs";
|
|
4
|
+
import { t as version } from "./package-C9pfAdGF.mjs";
|
|
4
5
|
import { isAxiosError } from "axios";
|
|
5
6
|
import { Readable } from "node:stream";
|
|
6
7
|
//#region src/auth/OAuthClient.ts
|
|
@@ -51,6 +52,7 @@ function decodeBinaryBody(data) {
|
|
|
51
52
|
//#endregion
|
|
52
53
|
//#region src/auth/ApiClient.ts
|
|
53
54
|
const USER_AGENT = `b4m-cli/${version}`;
|
|
55
|
+
const SIGNED_OUT_BASE_URL = "http://signed-out.invalid";
|
|
54
56
|
/**
|
|
55
57
|
* Per-request timeout. Generous by design: a waited chat (POST /api/chat with wait:true)
|
|
56
58
|
* runs a full server-side quest, so the bound only exists to stop a hung backend from
|
|
@@ -67,7 +69,7 @@ function resolveTimeoutMs() {
|
|
|
67
69
|
/**
|
|
68
70
|
* The shared authenticated client, wired to the CLI's storage, logger and branding.
|
|
69
71
|
*/
|
|
70
|
-
var ApiClient = class extends AuthenticatedApiClient {
|
|
72
|
+
var ApiClient = class ApiClient extends AuthenticatedApiClient {
|
|
71
73
|
/**
|
|
72
74
|
* @param apiKey - When set, requests authenticate with this instance API key via
|
|
73
75
|
* the `x-api-key` header and the OAuth-JWT path (Bearer injection + refresh-on-401)
|
|
@@ -92,6 +94,7 @@ var ApiClient = class extends AuthenticatedApiClient {
|
|
|
92
94
|
},
|
|
93
95
|
isPassThrough401: isProviderKeyFailure
|
|
94
96
|
});
|
|
97
|
+
this.signedOutClient = false;
|
|
95
98
|
this.fetch = async (input, init = {}) => {
|
|
96
99
|
const headers = Object.fromEntries(new Headers(init.headers));
|
|
97
100
|
try {
|
|
@@ -110,6 +113,22 @@ var ApiClient = class extends AuthenticatedApiClient {
|
|
|
110
113
|
}
|
|
111
114
|
};
|
|
112
115
|
}
|
|
116
|
+
/** True for a client made by `ApiClient.whileSignedOut`. */
|
|
117
|
+
get signedOut() {
|
|
118
|
+
return this.signedOutClient;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* A client for a signed-out session: every request rejects before it leaves the process, so a
|
|
122
|
+
* cloud call that a signed-out path failed to skip surfaces as a sign-in message, never traffic.
|
|
123
|
+
*/
|
|
124
|
+
static whileSignedOut(configStore) {
|
|
125
|
+
const client = new ApiClient(SIGNED_OUT_BASE_URL, configStore);
|
|
126
|
+
client.signedOutClient = true;
|
|
127
|
+
client.getAxiosInstance().defaults.adapter = async (config) => {
|
|
128
|
+
throw new Error(`Not signed in, so ${config.url ?? "the request"} was not sent to Bike4Mind. Run /login to sign in.`);
|
|
129
|
+
};
|
|
130
|
+
return client;
|
|
131
|
+
}
|
|
113
132
|
get baseURL() {
|
|
114
133
|
return this.getAxiosInstance().defaults.baseURL ?? "";
|
|
115
134
|
}
|
|
@@ -0,0 +1,157 @@
|
|
|
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 { lstatSync, mkdirSync, statSync } from "fs";
|
|
5
|
+
import os from "os";
|
|
6
|
+
import path from "path";
|
|
7
|
+
//#region src/sandbox/runtime/BubblewrapRuntime.ts
|
|
8
|
+
/**
|
|
9
|
+
* Linux Bubblewrap (bwrap) runtime implementation.
|
|
10
|
+
*
|
|
11
|
+
* Uses bubblewrap to create a sandboxed environment with:
|
|
12
|
+
* - Read-only system paths (/usr, /lib, /bin, etc.)
|
|
13
|
+
* - Read-write access only to the working directory
|
|
14
|
+
* - Denied paths mounted as empty tmpfs
|
|
15
|
+
* - Process and network namespace isolation; egress only through the filtering proxy
|
|
16
|
+
*/
|
|
17
|
+
/** System paths to bind read-only into the sandbox */
|
|
18
|
+
const SYSTEM_RO_BINDS = [
|
|
19
|
+
"/usr",
|
|
20
|
+
"/bin",
|
|
21
|
+
"/lib",
|
|
22
|
+
"/lib64",
|
|
23
|
+
"/sbin",
|
|
24
|
+
"/etc"
|
|
25
|
+
];
|
|
26
|
+
/** Paths that need special handling (dev, proc, tmp) */
|
|
27
|
+
const SPECIAL_MOUNTS = {
|
|
28
|
+
dev: "/dev",
|
|
29
|
+
proc: "/proc",
|
|
30
|
+
tmp: "/tmp"
|
|
31
|
+
};
|
|
32
|
+
/** Where the proxy's host unix socket is mounted; /run is never bound from the host, so nothing shadows it. */
|
|
33
|
+
const SANDBOX_PROXY_SOCKET = "/run/b4m/proxy.sock";
|
|
34
|
+
/** Readiness probes for the in-sandbox relay, 50ms apart. */
|
|
35
|
+
const RELAY_READY_ATTEMPTS = 100;
|
|
36
|
+
/**
|
|
37
|
+
* Listen on the sandbox's own loopback at the proxy port, so the proxy env vars work unchanged, and
|
|
38
|
+
* forward to the mounted socket. The command runs as "$1" once the relay accepts connections.
|
|
39
|
+
*/
|
|
40
|
+
function relayScript(proxyPort) {
|
|
41
|
+
return [
|
|
42
|
+
`socat TCP-LISTEN:${proxyPort},bind=127.0.0.1,fork,reuseaddr UNIX-CONNECT:${SANDBOX_PROXY_SOCKET} </dev/null >/dev/null 2>&1 &`,
|
|
43
|
+
"attempts=0",
|
|
44
|
+
`until (: </dev/tcp/127.0.0.1/${proxyPort}) 2>/dev/null; do`,
|
|
45
|
+
" attempts=$((attempts + 1))",
|
|
46
|
+
` if [ "$attempts" -ge ${RELAY_READY_ATTEMPTS} ]; then echo 'sandbox: network relay failed to start' >&2; exit 1; fi`,
|
|
47
|
+
" sleep 0.05",
|
|
48
|
+
"done",
|
|
49
|
+
"exec bash -c \"$1\""
|
|
50
|
+
].join("\n");
|
|
51
|
+
}
|
|
52
|
+
var BubblewrapRuntime = class {
|
|
53
|
+
constructor() {
|
|
54
|
+
this.platform = "linux";
|
|
55
|
+
this.name = "bubblewrap";
|
|
56
|
+
}
|
|
57
|
+
isAvailable() {
|
|
58
|
+
return isBinaryAvailable("bwrap");
|
|
59
|
+
}
|
|
60
|
+
wrapCommand(options) {
|
|
61
|
+
const { command, cwd, filesystemConfig, env } = options;
|
|
62
|
+
const expandedDenied = filesystemConfig.deniedPaths.map(resolveSandboxPath);
|
|
63
|
+
const expandedAllowed = filesystemConfig.allowedReadPaths.map(resolveSandboxPath);
|
|
64
|
+
const args = [];
|
|
65
|
+
for (const sysPath of SYSTEM_RO_BINDS) args.push("--ro-bind-try", sysPath, sysPath);
|
|
66
|
+
args.push("--dev", SPECIAL_MOUNTS.dev);
|
|
67
|
+
args.push("--proc", SPECIAL_MOUNTS.proc);
|
|
68
|
+
args.push("--tmpfs", SPECIAL_MOUNTS.tmp);
|
|
69
|
+
const homeDir = os.homedir();
|
|
70
|
+
args.push("--ro-bind", homeDir, homeDir);
|
|
71
|
+
for (const allowedPath of expandedAllowed) if (allowedPath !== homeDir && !allowedPath.startsWith(`${homeDir}${path.sep}`)) args.push("--ro-bind-try", allowedPath, allowedPath);
|
|
72
|
+
args.push("--bind", cwd, cwd);
|
|
73
|
+
const protectedPaths = getProtectedWorkspacePaths(cwd);
|
|
74
|
+
const resolvedCwd = resolveSandboxPath(cwd);
|
|
75
|
+
for (const protectedPath of protectedPaths) {
|
|
76
|
+
const resolvedPath = resolveSandboxPath(protectedPath);
|
|
77
|
+
if (resolvedCwd === resolvedPath || resolvedCwd.startsWith(`${resolvedPath}${path.sep}`)) throw new Error(`Cannot use protected metadata as sandbox cwd: ${cwd}`);
|
|
78
|
+
}
|
|
79
|
+
const projectDir = path.join(cwd, ".bike4mind");
|
|
80
|
+
mkdirSync(projectDir, { recursive: true });
|
|
81
|
+
for (const protectedPath of protectedPaths) {
|
|
82
|
+
try {
|
|
83
|
+
if (lstatSync(protectedPath).isSymbolicLink()) throw new Error(`Cannot protect sandbox metadata symlink: ${protectedPath}`);
|
|
84
|
+
} catch (error) {
|
|
85
|
+
if (!(error instanceof Error && "code" in error && ["ENOENT", "ENOTDIR"].includes(String(error.code)))) throw error;
|
|
86
|
+
}
|
|
87
|
+
const resolvedPath = resolveSandboxPath(protectedPath);
|
|
88
|
+
if (protectedPath === projectDir || pathKind(resolvedPath) !== "missing") args.push("--ro-bind", resolvedPath, resolvedPath);
|
|
89
|
+
}
|
|
90
|
+
for (const deniedPath of expandedDenied) {
|
|
91
|
+
const kind = pathKind(deniedPath);
|
|
92
|
+
if (kind === "dir") args.push("--tmpfs", deniedPath);
|
|
93
|
+
else if (kind === "file") args.push("--ro-bind", "/dev/null", deniedPath);
|
|
94
|
+
}
|
|
95
|
+
if (!options.allowContainerSockets) {
|
|
96
|
+
const isDenied = (p) => expandedDenied.some((d) => p === d || p.startsWith(`${d}${path.sep}`));
|
|
97
|
+
for (const entry of getContainerSocketPaths()) {
|
|
98
|
+
let socketPath;
|
|
99
|
+
let kind;
|
|
100
|
+
try {
|
|
101
|
+
socketPath = resolveSandboxPath(entry.path);
|
|
102
|
+
kind = pathKind(socketPath);
|
|
103
|
+
} catch (error) {
|
|
104
|
+
if (error instanceof Error && "code" in error && ["EACCES", "ELOOP"].includes(String(error.code))) {
|
|
105
|
+
logger.debug(`Sandbox: skipping unreadable container socket path ${entry.path}: ${error.code}`);
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
throw error;
|
|
109
|
+
}
|
|
110
|
+
if (isDenied(socketPath)) continue;
|
|
111
|
+
if (resolvedCwd === socketPath || resolvedCwd.startsWith(`${socketPath}${path.sep}`)) {
|
|
112
|
+
logger.debug(`Sandbox: not masking container socket path ${socketPath}, it contains the working directory`);
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
if (kind === "dir") args.push("--tmpfs", socketPath);
|
|
116
|
+
else if (kind === "file") args.push("--ro-bind", "/dev/null", socketPath);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
let relayPort = null;
|
|
120
|
+
if (options.networkEnabled) {
|
|
121
|
+
if (options.proxyPort === void 0 || !options.proxySocketPath) throw new Error("Sandbox network on Linux requires a running filtering proxy with a unix socket");
|
|
122
|
+
assertProxyPort(options.proxyPort);
|
|
123
|
+
if (!isBinaryAvailable("socat")) throw new Error("Sandbox network on Linux requires socat; install it or turn sandbox network off");
|
|
124
|
+
relayPort = options.proxyPort;
|
|
125
|
+
args.push("--ro-bind", options.proxySocketPath, SANDBOX_PROXY_SOCKET);
|
|
126
|
+
}
|
|
127
|
+
args.push("--unshare-all");
|
|
128
|
+
args.push("--unshare-net");
|
|
129
|
+
args.push("--die-with-parent");
|
|
130
|
+
if (options.seccompProfile) args.push("--seccomp", options.seccompProfile);
|
|
131
|
+
for (const [key, value] of Object.entries(env ?? {})) args.push("--setenv", key, value);
|
|
132
|
+
args.push("--chdir", cwd);
|
|
133
|
+
if (relayPort === null) args.push("bash", "-c", command);
|
|
134
|
+
else args.push("bash", "-c", relayScript(relayPort), "b4m-sandbox", command);
|
|
135
|
+
const commandString = ["bwrap", ...args.map(shellEscape)].join(" ");
|
|
136
|
+
return {
|
|
137
|
+
executable: "bwrap",
|
|
138
|
+
args,
|
|
139
|
+
env: env ?? {},
|
|
140
|
+
commandString
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
function pathKind(p) {
|
|
145
|
+
try {
|
|
146
|
+
return statSync(p).isDirectory() ? "dir" : "file";
|
|
147
|
+
} catch (error) {
|
|
148
|
+
if (error instanceof Error && "code" in error && ["ENOENT", "ENOTDIR"].includes(String(error.code))) return "missing";
|
|
149
|
+
throw error;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
function shellEscape(str) {
|
|
153
|
+
if (/^[a-zA-Z0-9._/=:-]+$/.test(str)) return str;
|
|
154
|
+
return `'${str.replace(/'/g, "'\\''")}'`;
|
|
155
|
+
}
|
|
156
|
+
//#endregion
|
|
157
|
+
export { BubblewrapRuntime };
|