alineo-cli 0.2.0 → 0.3.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/dist/{add-CmdLjuq_.mjs → add-B6Xmz48s.mjs} +1 -1
- package/dist/{agents-CEVMF8rH.mjs → agents-T17zA9p-.mjs} +1 -1
- package/dist/{fork-CAtxcuwS.mjs → fork-Bl-31vNc.mjs} +1 -1
- package/dist/index.mjs +408 -23
- package/dist/init-Caryb0xG.mjs +18 -0
- package/dist/{kill-D1vvRxxn.mjs → kill-01oM3F4x.mjs} +1 -1
- package/dist/{list-DKxmgyNL.mjs → list-F4RrPUBT.mjs} +1 -1
- package/dist/{logs-D-DUd5Ux.mjs → logs-CaLt2Ya0.mjs} +1 -1
- package/dist/{package-DREgdB9C.mjs → package-oshZF9Gd.mjs} +1 -1
- package/dist/{prompt-CSu1QDCA.mjs → prompt-DoeWivoE.mjs} +1 -1
- package/dist/{remove-Dsp071zF.mjs → remove-B_721tl2.mjs} +1 -1
- package/dist/{sessions-data-SEZBa4Uk.mjs → sessions-data-C8XZge-w.mjs} +1 -1
- package/dist/{spawn-Dd8Y0OXB.mjs → spawn-BRFkN-5J.mjs} +1 -1
- package/dist/{steer-BdQ_-sf2.mjs → steer-B15HpNnn.mjs} +1 -1
- package/dist/{tui-C7Vonahr.mjs → tui-CFEiWbe1.mjs} +3 -3
- package/package.json +7 -5
- package/dist/init-D6RgxqQQ.mjs +0 -265
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as getSessions, t as formatAge } from "./sessions-data-
|
|
1
|
+
import { n as getSessions, t as formatAge } from "./sessions-data-C8XZge-w.mjs";
|
|
2
2
|
//#region src/commands/agents.ts
|
|
3
3
|
async function agents(opts = {}) {
|
|
4
4
|
const { tracked, untracked } = await getSessions();
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
|
+
import { installLoggerFromEnv } from "@alineo-labs/logger";
|
|
2
3
|
import { join } from "node:path";
|
|
3
4
|
import { join as join$1 } from "path";
|
|
4
5
|
import { homedir } from "os";
|
|
@@ -28,7 +29,7 @@ const commands = [
|
|
|
28
29
|
usage: "alineo init",
|
|
29
30
|
summary: "Start OpenSandbox locally via Docker"
|
|
30
31
|
}],
|
|
31
|
-
run: async (argv) => (await import("./init-
|
|
32
|
+
run: async (argv) => (await import("./init-Caryb0xG.mjs")).initCommand.run(argv)
|
|
32
33
|
},
|
|
33
34
|
{
|
|
34
35
|
name: "add",
|
|
@@ -37,7 +38,7 @@ const commands = [
|
|
|
37
38
|
usage: "alineo add <url> [--name <n>]",
|
|
38
39
|
summary: "Fetch and save an agent spec locally"
|
|
39
40
|
}],
|
|
40
|
-
run: async (argv) => (await import("./add-
|
|
41
|
+
run: async (argv) => (await import("./add-B6Xmz48s.mjs")).addCommand.run(argv)
|
|
41
42
|
},
|
|
42
43
|
{
|
|
43
44
|
name: "list",
|
|
@@ -46,7 +47,7 @@ const commands = [
|
|
|
46
47
|
usage: "alineo list",
|
|
47
48
|
summary: "List saved agent specs"
|
|
48
49
|
}],
|
|
49
|
-
run: async (argv) => (await import("./list-
|
|
50
|
+
run: async (argv) => (await import("./list-F4RrPUBT.mjs")).listCommand.run(argv)
|
|
50
51
|
},
|
|
51
52
|
{
|
|
52
53
|
name: "remove",
|
|
@@ -55,7 +56,7 @@ const commands = [
|
|
|
55
56
|
usage: "alineo remove <name>",
|
|
56
57
|
summary: "Remove a saved agent spec"
|
|
57
58
|
}],
|
|
58
|
-
run: async (argv) => (await import("./remove-
|
|
59
|
+
run: async (argv) => (await import("./remove-B_721tl2.mjs")).removeCommand.run(argv)
|
|
59
60
|
},
|
|
60
61
|
{
|
|
61
62
|
name: "spawn",
|
|
@@ -67,7 +68,7 @@ const commands = [
|
|
|
67
68
|
usage: "alineo spawn <spec> --prompt <msg>",
|
|
68
69
|
summary: "Start it, send one prompt, print the reply, exit"
|
|
69
70
|
}],
|
|
70
|
-
run: async (argv) => (await import("./spawn-
|
|
71
|
+
run: async (argv) => (await import("./spawn-BRFkN-5J.mjs")).spawnCommand.run(argv)
|
|
71
72
|
},
|
|
72
73
|
{
|
|
73
74
|
name: "prompt",
|
|
@@ -76,7 +77,7 @@ const commands = [
|
|
|
76
77
|
usage: "alineo prompt <sandbox-id> <msg>",
|
|
77
78
|
summary: "Send one prompt to a running sandbox, print the reply"
|
|
78
79
|
}],
|
|
79
|
-
run: async (argv) => (await import("./prompt-
|
|
80
|
+
run: async (argv) => (await import("./prompt-DoeWivoE.mjs")).promptCommand.run(argv)
|
|
80
81
|
},
|
|
81
82
|
{
|
|
82
83
|
name: "fork",
|
|
@@ -85,7 +86,7 @@ const commands = [
|
|
|
85
86
|
usage: "alineo fork <name> <child-spec>",
|
|
86
87
|
summary: "Fork a running session's own live sandbox into a new child"
|
|
87
88
|
}],
|
|
88
|
-
run: async (argv) => (await import("./fork-
|
|
89
|
+
run: async (argv) => (await import("./fork-Bl-31vNc.mjs")).forkCommand.run(argv)
|
|
89
90
|
},
|
|
90
91
|
{
|
|
91
92
|
name: "steer",
|
|
@@ -94,7 +95,7 @@ const commands = [
|
|
|
94
95
|
usage: "alineo steer <sandbox-id> <message>",
|
|
95
96
|
summary: "Redirect a running session — lands at its next turn boundary, not instantly"
|
|
96
97
|
}],
|
|
97
|
-
run: async (argv) => (await import("./steer-
|
|
98
|
+
run: async (argv) => (await import("./steer-B15HpNnn.mjs")).steerCommand.run(argv)
|
|
98
99
|
},
|
|
99
100
|
{
|
|
100
101
|
name: "agents",
|
|
@@ -103,7 +104,7 @@ const commands = [
|
|
|
103
104
|
usage: "alineo agents [--json]",
|
|
104
105
|
summary: "List running agent sessions"
|
|
105
106
|
}],
|
|
106
|
-
run: async (argv) => (await import("./agents-
|
|
107
|
+
run: async (argv) => (await import("./agents-T17zA9p-.mjs")).agentsCommand.run(argv)
|
|
107
108
|
},
|
|
108
109
|
{
|
|
109
110
|
name: "kill",
|
|
@@ -112,7 +113,7 @@ const commands = [
|
|
|
112
113
|
usage: "alineo kill <sandbox-id>",
|
|
113
114
|
summary: "Stop a sandbox"
|
|
114
115
|
}],
|
|
115
|
-
run: async (argv) => (await import("./kill-
|
|
116
|
+
run: async (argv) => (await import("./kill-01oM3F4x.mjs")).killCommand.run(argv)
|
|
116
117
|
},
|
|
117
118
|
{
|
|
118
119
|
name: "logs",
|
|
@@ -121,7 +122,7 @@ const commands = [
|
|
|
121
122
|
usage: "alineo logs <name> [--json]",
|
|
122
123
|
summary: "Print ledger events for a session"
|
|
123
124
|
}],
|
|
124
|
-
run: async (argv) => (await import("./logs-
|
|
125
|
+
run: async (argv) => (await import("./logs-CaLt2Ya0.mjs")).logsCommand.run(argv)
|
|
125
126
|
},
|
|
126
127
|
{
|
|
127
128
|
name: "telemetry",
|
|
@@ -144,7 +145,116 @@ const commands = [
|
|
|
144
145
|
}
|
|
145
146
|
];
|
|
146
147
|
//#endregion
|
|
147
|
-
//#region
|
|
148
|
+
//#region ../cli-shared/dist/index.mjs
|
|
149
|
+
async function spawn(cmd) {
|
|
150
|
+
let proc;
|
|
151
|
+
try {
|
|
152
|
+
proc = Bun.spawn(cmd, {
|
|
153
|
+
stdout: "pipe",
|
|
154
|
+
stderr: "pipe"
|
|
155
|
+
});
|
|
156
|
+
} catch {
|
|
157
|
+
throw new Error(`'${cmd[0]}' not found — is Docker installed?`);
|
|
158
|
+
}
|
|
159
|
+
const [stdout, stderr, exitCode] = await Promise.all([
|
|
160
|
+
new Response(proc.stdout).text(),
|
|
161
|
+
new Response(proc.stderr).text(),
|
|
162
|
+
proc.exited
|
|
163
|
+
]);
|
|
164
|
+
return {
|
|
165
|
+
ok: exitCode === 0,
|
|
166
|
+
stdout,
|
|
167
|
+
stderr
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
async function checkDocker() {
|
|
171
|
+
const { ok, stderr } = await spawn(["docker", "info"]);
|
|
172
|
+
if (!ok) {
|
|
173
|
+
if (stderr.includes("Cannot connect") || stderr.includes("daemon") || stderr.includes("socket")) throw new Error("Docker daemon is not running. Start Docker and try again.");
|
|
174
|
+
throw new Error("Docker is not available. Install Docker and try again.");
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
async function getContainerState(name) {
|
|
178
|
+
const { ok, stdout } = await spawn([
|
|
179
|
+
"docker",
|
|
180
|
+
"inspect",
|
|
181
|
+
name,
|
|
182
|
+
"--format",
|
|
183
|
+
"{{.State.Status}}"
|
|
184
|
+
]);
|
|
185
|
+
if (!ok) return "missing";
|
|
186
|
+
return stdout.trim() === "running" ? "running" : "stopped";
|
|
187
|
+
}
|
|
188
|
+
async function startContainer(name) {
|
|
189
|
+
const { ok, stderr } = await spawn([
|
|
190
|
+
"docker",
|
|
191
|
+
"start",
|
|
192
|
+
name
|
|
193
|
+
]);
|
|
194
|
+
if (!ok) throw new Error(`Failed to start container '${name}': ${stderr.trim()}`);
|
|
195
|
+
}
|
|
196
|
+
async function restartContainer(name) {
|
|
197
|
+
const { ok, stderr } = await spawn([
|
|
198
|
+
"docker",
|
|
199
|
+
"restart",
|
|
200
|
+
name
|
|
201
|
+
]);
|
|
202
|
+
if (!ok) throw new Error(`Failed to restart container '${name}': ${stderr.trim()}`);
|
|
203
|
+
}
|
|
204
|
+
/** Force-removes a container regardless of running/stopped state — used to recreate one whose
|
|
205
|
+
* config (network mode, env) needs to change, since `docker run` args can't be applied in place. */
|
|
206
|
+
async function removeContainer(name) {
|
|
207
|
+
const { ok, stderr } = await spawn([
|
|
208
|
+
"docker",
|
|
209
|
+
"rm",
|
|
210
|
+
"-f",
|
|
211
|
+
name
|
|
212
|
+
]);
|
|
213
|
+
if (!ok) throw new Error(`Failed to remove container '${name}': ${stderr.trim()}`);
|
|
214
|
+
}
|
|
215
|
+
async function runContainer(args, label = "container") {
|
|
216
|
+
const { ok, stderr } = await spawn([
|
|
217
|
+
"docker",
|
|
218
|
+
"run",
|
|
219
|
+
...args
|
|
220
|
+
]);
|
|
221
|
+
if (!ok) throw new Error(`Failed to start ${label}: ${stderr.trim()}`);
|
|
222
|
+
}
|
|
223
|
+
async function pullImage(image) {
|
|
224
|
+
const { ok, stderr } = await spawn([
|
|
225
|
+
"docker",
|
|
226
|
+
"pull",
|
|
227
|
+
image
|
|
228
|
+
]);
|
|
229
|
+
if (!ok) throw new Error(`Failed to pull '${image}': ${stderr.trim()}`);
|
|
230
|
+
}
|
|
231
|
+
/** Default health predicate: OpenSandbox's `/health` returns `{ status: "healthy" }`. */
|
|
232
|
+
const isOpenSandboxHealthy = (body) => body?.status === "healthy";
|
|
233
|
+
async function pollHealth(url, timeoutMs = 6e4, isHealthy = isOpenSandboxHealthy) {
|
|
234
|
+
const deadline = Date.now() + timeoutMs;
|
|
235
|
+
while (Date.now() < deadline) {
|
|
236
|
+
try {
|
|
237
|
+
const res = await fetch(url);
|
|
238
|
+
if (res.ok && isHealthy(await res.json())) return;
|
|
239
|
+
} catch {}
|
|
240
|
+
await new Promise((r) => setTimeout(r, 1e3));
|
|
241
|
+
}
|
|
242
|
+
throw new Error(`${url} did not become healthy within ${timeoutMs / 1e3}s`);
|
|
243
|
+
}
|
|
244
|
+
/** A quick one-shot version of `pollHealth` for deciding whether an already-`running`
|
|
245
|
+
* container is actually reachable, not just started — a container can report "running" to
|
|
246
|
+
* Docker while its service is unreachable (wrong network mode, crashed process, stale config).
|
|
247
|
+
* 10s (not 3s) so a slow-but-healthy service (host under load, cold Bun startup after reboot,
|
|
248
|
+
* bridge networking still settling) doesn't get misread as unreachable and trigger a destructive
|
|
249
|
+
* `docker rm -f` of an otherwise-fine container. */
|
|
250
|
+
async function isReachable(url, isHealthy, timeoutMs = 1e4) {
|
|
251
|
+
try {
|
|
252
|
+
await pollHealth(url, timeoutMs, isHealthy);
|
|
253
|
+
return true;
|
|
254
|
+
} catch {
|
|
255
|
+
return false;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
148
258
|
const CONFIG_DIR = ".alineo";
|
|
149
259
|
const CONFIG_FILE = "alineo.config.json";
|
|
150
260
|
function configPath() {
|
|
@@ -161,8 +271,8 @@ function fillDefaults(data) {
|
|
|
161
271
|
adapterPath: data.adapterPath ?? "./.alineo/ledger.db",
|
|
162
272
|
agentsDir: data.agentsDir ?? "./agents",
|
|
163
273
|
defaults: { resources: {
|
|
164
|
-
cpu: data.defaults?.resources
|
|
165
|
-
memory: data.defaults?.resources
|
|
274
|
+
cpu: data.defaults?.resources?.cpu ?? "1000m",
|
|
275
|
+
memory: data.defaults?.resources?.memory ?? "1Gi"
|
|
166
276
|
} }
|
|
167
277
|
};
|
|
168
278
|
}
|
|
@@ -205,8 +315,8 @@ function serverConfigPath() {
|
|
|
205
315
|
return join$1(serverConfigDir(), "server.toml");
|
|
206
316
|
}
|
|
207
317
|
/**
|
|
208
|
-
* Host directory bind-mounted into the OpenSandbox container at `/data` (see
|
|
209
|
-
*
|
|
318
|
+
* Host directory bind-mounted into the OpenSandbox container at `/data` (see `init.ts`),
|
|
319
|
+
* backing the `[store].path` set below. OpenSandbox itself persists
|
|
210
320
|
* snapshot metadata durably (a SQLite db, meant to survive the server process restarting —
|
|
211
321
|
* see opensandbox-group/OpenSandbox's `PersistedSnapshotService`), but that guarantee is
|
|
212
322
|
* only as good as where the db file actually lives: without this mount, it sits in the
|
|
@@ -238,11 +348,11 @@ function serverDataDir() {
|
|
|
238
348
|
* plans/credential-injection.md Phase 4). `dns+nft` (rather than `dns`) is required for
|
|
239
349
|
* `credentialProxy`'s Credential Vault to activate at all.
|
|
240
350
|
*/
|
|
241
|
-
function serverConfigContent() {
|
|
351
|
+
function serverConfigContent(eip) {
|
|
242
352
|
return `[server]
|
|
243
353
|
host = "0.0.0.0"
|
|
244
354
|
port = 8080
|
|
245
|
-
eip = "
|
|
355
|
+
eip = "${eip}"
|
|
246
356
|
|
|
247
357
|
[runtime]
|
|
248
358
|
type = "docker"
|
|
@@ -260,6 +370,280 @@ image = "opensandbox/egress:v1.1.7"
|
|
|
260
370
|
mode = "dns+nft"
|
|
261
371
|
`;
|
|
262
372
|
}
|
|
373
|
+
/**
|
|
374
|
+
* Model API key env vars Pi's coding-agent runtime resolves providers from — mirrors the
|
|
375
|
+
* `envMap` in earendil-works/pi's `packages/ai/src/env-api-keys.ts` (plus Anthropic's three,
|
|
376
|
+
* handled separately there). An `AgentSpec`'s env map (`{ NVIDIA_API_KEY: "${NVIDIA_API_KEY}" }`,
|
|
377
|
+
* see `packages/agent/src/schema.ts`) is resolved from `process.env` inside whatever process
|
|
378
|
+
* calls `Alineo.load()`/`.spawn()` — for a swarm run through alineod, that's alineod's own
|
|
379
|
+
* container. `alineo init` forwards whichever of these are set in the operator's shell into
|
|
380
|
+
* that container so any Pi-supported model works, not just NVIDIA's free tier.
|
|
381
|
+
*
|
|
382
|
+
* Deliberately excludes ambient/file-based credential mechanisms (AWS IAM role chains,
|
|
383
|
+
* `AWS_PROFILE`, Google Application Default Credentials) — those need a mounted file or
|
|
384
|
+
* assumed-role wiring, not just a passed-through env var. Amazon Bedrock and Google Vertex
|
|
385
|
+
* are not yet supported by `init`'s auto-start for that reason.
|
|
386
|
+
*
|
|
387
|
+
* Keep in sync with pi's `env-api-keys.ts` `envMap` as it adds providers.
|
|
388
|
+
*/
|
|
389
|
+
const PI_MODEL_API_KEY_ENV_VARS = [
|
|
390
|
+
"ANTHROPIC_API_KEY",
|
|
391
|
+
"ANTHROPIC_OAUTH_TOKEN",
|
|
392
|
+
"ANTHROPIC_AUTH_TOKEN",
|
|
393
|
+
"OPENAI_API_KEY",
|
|
394
|
+
"AZURE_OPENAI_API_KEY",
|
|
395
|
+
"GEMINI_API_KEY",
|
|
396
|
+
"NVIDIA_API_KEY",
|
|
397
|
+
"DEEPSEEK_API_KEY",
|
|
398
|
+
"MISTRAL_API_KEY",
|
|
399
|
+
"GROQ_API_KEY",
|
|
400
|
+
"CEREBRAS_API_KEY",
|
|
401
|
+
"XAI_API_KEY",
|
|
402
|
+
"OPENROUTER_API_KEY",
|
|
403
|
+
"AI_GATEWAY_API_KEY",
|
|
404
|
+
"CLOUDFLARE_API_KEY",
|
|
405
|
+
"CLOUDFLARE_ACCOUNT_ID",
|
|
406
|
+
"CLOUDFLARE_GATEWAY_ID",
|
|
407
|
+
"RADIUS_API_KEY",
|
|
408
|
+
"OPENCODE_API_KEY",
|
|
409
|
+
"QWEN_TOKEN_PLAN_API_KEY",
|
|
410
|
+
"QWEN_TOKEN_PLAN_CN_API_KEY",
|
|
411
|
+
"MOONSHOT_API_KEY",
|
|
412
|
+
"KIMI_API_KEY",
|
|
413
|
+
"ZAI_API_KEY",
|
|
414
|
+
"ZAI_CODING_CN_API_KEY",
|
|
415
|
+
"MINIMAX_API_KEY",
|
|
416
|
+
"MINIMAX_CN_API_KEY",
|
|
417
|
+
"XIAOMI_API_KEY",
|
|
418
|
+
"XIAOMI_TOKEN_PLAN_CN_API_KEY",
|
|
419
|
+
"XIAOMI_TOKEN_PLAN_AMS_API_KEY",
|
|
420
|
+
"XIAOMI_TOKEN_PLAN_SGP_API_KEY",
|
|
421
|
+
"ANT_LING_API_KEY",
|
|
422
|
+
"HF_TOKEN",
|
|
423
|
+
"FIREWORKS_API_KEY",
|
|
424
|
+
"TOGETHER_API_KEY",
|
|
425
|
+
"BASETEN_API_KEY",
|
|
426
|
+
"COPILOT_GITHUB_TOKEN"
|
|
427
|
+
];
|
|
428
|
+
/**
|
|
429
|
+
* `alineo init` / `alineo_init` — starts OpenSandbox + alineod locally via Docker and writes
|
|
430
|
+
* `alineo.config.json`. Shared verbatim by `alineo-cli` (`packages/cli/src/commands/init.ts`,
|
|
431
|
+
* which logs to stdout) and `alineo-mcp` (`packages/mcp/src/init.ts`, which collects a log array
|
|
432
|
+
* instead — an MCP stdio server's stdout is the JSON-RPC channel, so tool handlers must never
|
|
433
|
+
* `console.log`) via the injectable `log` callback, so the two can never drift apart the way two
|
|
434
|
+
* hand-copied files did before.
|
|
435
|
+
*/
|
|
436
|
+
const OPENSANDBOX_CONTAINER_NAME = "alineo-opensandbox";
|
|
437
|
+
const SERVER_URL = "http://127.0.0.1:8080";
|
|
438
|
+
const ALINEOD_CONTAINER_NAME = "alineo-alineod";
|
|
439
|
+
const ALINEOD_IMAGE = "ghcr.io/drejt/alineod:latest";
|
|
440
|
+
const ALINEOD_URL = "http://127.0.0.1:4600";
|
|
441
|
+
const isAlineodHealthy = (body) => body?.ok === true;
|
|
442
|
+
const HOST_DOCKER_INTERNAL_SERVER_URL = "http://host.docker.internal:8080";
|
|
443
|
+
/**
|
|
444
|
+
* `--network host` (which makes alineod see `127.0.0.1` exactly as the host does, matching
|
|
445
|
+
* OpenSandbox's configured `eip` — see `ensureAlineod`'s doc comment) only works out of the box
|
|
446
|
+
* on native Linux Docker. Docker Desktop for Windows/Mac ships it behind an opt-in "Enable host
|
|
447
|
+
* networking" setting nothing here can safely toggle (no stable, documented way to flip it and
|
|
448
|
+
* restart Docker Desktop from a CLI); without it, `--network host` containers report "running"
|
|
449
|
+
* but publish no ports the host can reach at all (see the `isReachable` probe below, which is
|
|
450
|
+
* exactly what catches this class of failure). Keying off `process.platform` instead of probing
|
|
451
|
+
* Docker's own networking capabilities is a heuristic, not a guarantee (e.g. Docker Desktop for
|
|
452
|
+
* Linux may behave like Windows/Mac here too) — but it matches how the overwhelming majority of
|
|
453
|
+
* each platform's users actually run Docker. `ensureAlineod` backs this guess with a live
|
|
454
|
+
* reachability probe and falls back to bridge networking on the spot if it's wrong, so a bad
|
|
455
|
+
* guess self-heals instead of leaving alineod permanently unreachable.
|
|
456
|
+
*/
|
|
457
|
+
const usesHostNetworking = process.platform !== "win32" && process.platform !== "darwin";
|
|
458
|
+
async function runInit(log) {
|
|
459
|
+
log("Checking Docker...");
|
|
460
|
+
await checkDocker();
|
|
461
|
+
const openSandboxConfigChanged = await ensureServerConfig();
|
|
462
|
+
await ensureServerDataDir();
|
|
463
|
+
const state = await getContainerState(OPENSANDBOX_CONTAINER_NAME);
|
|
464
|
+
if (state === "running") {
|
|
465
|
+
if (openSandboxConfigChanged) {
|
|
466
|
+
log("OpenSandbox networking config changed — restarting to apply it...");
|
|
467
|
+
await restartContainer(OPENSANDBOX_CONTAINER_NAME);
|
|
468
|
+
log("Waiting for OpenSandbox to be ready...");
|
|
469
|
+
await pollHealth(`${SERVER_URL}/health`);
|
|
470
|
+
} else log(`OpenSandbox already running at ${SERVER_URL}`);
|
|
471
|
+
} else if (state === "stopped") {
|
|
472
|
+
log("Restarting OpenSandbox container...");
|
|
473
|
+
await startContainer(OPENSANDBOX_CONTAINER_NAME);
|
|
474
|
+
log("Waiting for OpenSandbox to be ready...");
|
|
475
|
+
await pollHealth(`${SERVER_URL}/health`);
|
|
476
|
+
} else {
|
|
477
|
+
log("Starting OpenSandbox in Docker...");
|
|
478
|
+
await runContainer([
|
|
479
|
+
"-d",
|
|
480
|
+
"--name",
|
|
481
|
+
OPENSANDBOX_CONTAINER_NAME,
|
|
482
|
+
"-p",
|
|
483
|
+
"8080:8080",
|
|
484
|
+
"-v",
|
|
485
|
+
"/var/run/docker.sock:/var/run/docker.sock",
|
|
486
|
+
"-v",
|
|
487
|
+
`${serverConfigPath()}:/etc/opensandbox/config.toml:ro`,
|
|
488
|
+
"-v",
|
|
489
|
+
`${serverDataDir()}:/data`,
|
|
490
|
+
"-e",
|
|
491
|
+
"SANDBOX_CONFIG_PATH=/etc/opensandbox/config.toml",
|
|
492
|
+
"-e",
|
|
493
|
+
"OPENSANDBOX_INSECURE_SERVER=YES",
|
|
494
|
+
"opensandbox/server:latest"
|
|
495
|
+
], "OpenSandbox container");
|
|
496
|
+
log("Waiting for OpenSandbox to be ready...");
|
|
497
|
+
await pollHealth(`${SERVER_URL}/health`);
|
|
498
|
+
}
|
|
499
|
+
await ensureAlineod(log, openSandboxConfigChanged);
|
|
500
|
+
await ensureProjectConfig(log);
|
|
501
|
+
log(`OpenSandbox running at ${SERVER_URL}, alineod running at ${ALINEOD_URL} — ready.`);
|
|
502
|
+
return {
|
|
503
|
+
serverUrl: SERVER_URL,
|
|
504
|
+
alineodUrl: ALINEOD_URL
|
|
505
|
+
};
|
|
506
|
+
}
|
|
507
|
+
/**
|
|
508
|
+
* alineod needs to reach OpenSandbox at the same address OpenSandbox's own configured `eip`
|
|
509
|
+
* uses — that's what it hands back in every sandbox proxy URL (`{eip}/sandboxes/{id}/proxy/{port}`,
|
|
510
|
+
* see `apps/alineod/README.md`'s "Networking caveat"), and alineod follows those literally.
|
|
511
|
+
*
|
|
512
|
+
* - **Linux**: `--network host` puts alineod's `127.0.0.1` in the same namespace as the host's,
|
|
513
|
+
* matching `eip` (`SERVER_URL`, `ensureServerConfig` below) exactly — same as a bare `bun run
|
|
514
|
+
* start` would see. No extra port publishing needed; alineod's own port is already the host's.
|
|
515
|
+
* - **Windows/Mac (Docker Desktop)**: `--network host` doesn't publish container ports to the
|
|
516
|
+
* host at all without a setting this can't safely flip (see `usesHostNetworking`'s doc
|
|
517
|
+
* comment) — every ALINEOD_URL health check would time out, exactly what motivated this split.
|
|
518
|
+
* Instead alineod stays on the default bridge network with an explicit `-p 4600:4600` (so the
|
|
519
|
+
* host can reach *it*) and reaches OpenSandbox via `host.docker.internal`, which Docker
|
|
520
|
+
* Desktop resolves to the host on every container regardless of network mode — no host
|
|
521
|
+
* networking feature required. `ensureServerConfig` sets OpenSandbox's `eip` to the same
|
|
522
|
+
* `host.docker.internal` address so alineod can also follow the proxy URLs it hands back.
|
|
523
|
+
* Trade-off: a host-based client talking to *this same* OpenSandbox instance directly (not
|
|
524
|
+
* through alineod) can no longer follow those proxy URLs either, since the host itself can't
|
|
525
|
+
* reliably resolve `host.docker.internal` back to itself (Windows routes it via the LAN
|
|
526
|
+
* interface, which most local networks don't hairpin NAT back to the same machine) — use `uvx
|
|
527
|
+
* opensandbox-server` instead for that case (see the root CLAUDE.md's "Local OpenSandbox
|
|
528
|
+
* setup").
|
|
529
|
+
*/
|
|
530
|
+
async function ensureAlineod(log, openSandboxConfigChanged) {
|
|
531
|
+
const state = await getContainerState(ALINEOD_CONTAINER_NAME);
|
|
532
|
+
if (state !== "missing" && openSandboxConfigChanged) {
|
|
533
|
+
log("OpenSandbox networking config changed — recreating alineod to match...");
|
|
534
|
+
await removeContainer(ALINEOD_CONTAINER_NAME);
|
|
535
|
+
} else if (state === "running") {
|
|
536
|
+
if (await isReachable(`http://127.0.0.1:4600/health`, isAlineodHealthy)) {
|
|
537
|
+
log(`alineod already running at ${ALINEOD_URL}`);
|
|
538
|
+
return;
|
|
539
|
+
}
|
|
540
|
+
log("alineod is running but not reachable — recreating it...");
|
|
541
|
+
await removeContainer(ALINEOD_CONTAINER_NAME);
|
|
542
|
+
} else if (state === "stopped") {
|
|
543
|
+
log("Restarting alineod container...");
|
|
544
|
+
await startContainer(ALINEOD_CONTAINER_NAME);
|
|
545
|
+
log("Waiting for alineod to be ready...");
|
|
546
|
+
await pollHealth(`${ALINEOD_URL}/health`, 6e4, isAlineodHealthy);
|
|
547
|
+
return;
|
|
548
|
+
}
|
|
549
|
+
log(`Pulling ${ALINEOD_IMAGE}...`);
|
|
550
|
+
await pullImage(ALINEOD_IMAGE);
|
|
551
|
+
const foundModelKeys = PI_MODEL_API_KEY_ENV_VARS.filter((name) => process.env[name]);
|
|
552
|
+
const modelKeyArgs = foundModelKeys.flatMap((name) => ["-e", `${name}=${process.env[name]}`]);
|
|
553
|
+
if (foundModelKeys.length > 0) log(`Forwarding model key(s): ${foundModelKeys.join(", ")}`);
|
|
554
|
+
else log("No known model API key found in the environment — alineod will start, but agent specs referencing a provider key will fail until one is set (see any of the env vars in pi-model-keys.ts).");
|
|
555
|
+
log("Starting alineod in Docker...");
|
|
556
|
+
await startAlineodContainer(usesHostNetworking, modelKeyArgs);
|
|
557
|
+
log("Waiting for alineod to be ready...");
|
|
558
|
+
if (usesHostNetworking && !await isReachable(`http://127.0.0.1:4600/health`, isAlineodHealthy)) {
|
|
559
|
+
log("alineod isn't reachable over host networking on this Docker install — falling back to bridge networking + host.docker.internal...");
|
|
560
|
+
await removeContainer(ALINEOD_CONTAINER_NAME);
|
|
561
|
+
if (await ensureServerEip("http://host.docker.internal:8080")) {
|
|
562
|
+
log("OpenSandbox eip changed to match — restarting to apply it...");
|
|
563
|
+
await restartContainer(OPENSANDBOX_CONTAINER_NAME);
|
|
564
|
+
await pollHealth(`${SERVER_URL}/health`);
|
|
565
|
+
}
|
|
566
|
+
await startAlineodContainer(false, modelKeyArgs);
|
|
567
|
+
}
|
|
568
|
+
await pollHealth(`${ALINEOD_URL}/health`, 6e4, isAlineodHealthy);
|
|
569
|
+
}
|
|
570
|
+
function startAlineodContainer(useHostNetworking, modelKeyArgs) {
|
|
571
|
+
const networkArgs = useHostNetworking ? ["--network", "host"] : [
|
|
572
|
+
"-p",
|
|
573
|
+
"4600:4600",
|
|
574
|
+
"--add-host",
|
|
575
|
+
"host.docker.internal:host-gateway"
|
|
576
|
+
];
|
|
577
|
+
const alineodServerUrl = useHostNetworking ? SERVER_URL : HOST_DOCKER_INTERNAL_SERVER_URL;
|
|
578
|
+
return runContainer([
|
|
579
|
+
"-d",
|
|
580
|
+
"--name",
|
|
581
|
+
ALINEOD_CONTAINER_NAME,
|
|
582
|
+
...networkArgs,
|
|
583
|
+
"-e",
|
|
584
|
+
`ALINEO_SERVER_URL=${alineodServerUrl}`,
|
|
585
|
+
"-e",
|
|
586
|
+
"ALINEO_USE_SERVER_PROXY=true",
|
|
587
|
+
...modelKeyArgs,
|
|
588
|
+
"-v",
|
|
589
|
+
"alineod-data:/data",
|
|
590
|
+
ALINEOD_IMAGE
|
|
591
|
+
], "alineod container");
|
|
592
|
+
}
|
|
593
|
+
/** Ensures `server.toml`'s `eip` matches what this platform needs (see `ensureAlineod`'s doc
|
|
594
|
+
* comment) — returns whether it changed, so callers can restart whatever already-running
|
|
595
|
+
* containers depend on it. */
|
|
596
|
+
async function ensureServerConfig() {
|
|
597
|
+
const dir = serverConfigDir();
|
|
598
|
+
if (!existsSync(dir)) await mkdir(dir, { recursive: true });
|
|
599
|
+
return ensureServerEip(usesHostNetworking ? SERVER_URL : HOST_DOCKER_INTERNAL_SERVER_URL);
|
|
600
|
+
}
|
|
601
|
+
/**
|
|
602
|
+
* Creates `server.toml` from the default template if it doesn't exist yet, or otherwise patches
|
|
603
|
+
* only its `eip = "..."` line in place — the rest of an existing file is left untouched, since
|
|
604
|
+
* its own header comments invite hand-editing it for `networkPolicy`/`credentialProxy`/egress
|
|
605
|
+
* tuning, and clobbering that on every `init` would silently discard it. Returns whether the eip
|
|
606
|
+
* actually changed.
|
|
607
|
+
*/
|
|
608
|
+
async function ensureServerEip(eip) {
|
|
609
|
+
const path = serverConfigPath();
|
|
610
|
+
if (!existsSync(path)) {
|
|
611
|
+
await Bun.write(path, serverConfigContent(eip));
|
|
612
|
+
return true;
|
|
613
|
+
}
|
|
614
|
+
const existing = await Bun.file(path).text();
|
|
615
|
+
const eipLine = /^eip\s*=\s*"([^"]*)"/m;
|
|
616
|
+
if (existing.match(eipLine)?.[1] === eip) return false;
|
|
617
|
+
const updated = eipLine.test(existing) ? existing.replace(eipLine, `eip = "${eip}"`) : existing.replace(/^\[server\]/m, `[server]\neip = "${eip}"`);
|
|
618
|
+
await Bun.write(path, updated);
|
|
619
|
+
return true;
|
|
620
|
+
}
|
|
621
|
+
/**
|
|
622
|
+
* Host-side half of the `serverDataDir()` bind mount. `docker run -v` would auto-create
|
|
623
|
+
* a missing host path anyway, but doing it explicitly here matches `ensureServerConfig()`'s
|
|
624
|
+
* pattern and keeps directory creation in one place rather than relying on Docker's
|
|
625
|
+
* legacy-`-v`-specific behavior (unlike `--mount`, which requires the source to pre-exist).
|
|
626
|
+
*/
|
|
627
|
+
async function ensureServerDataDir() {
|
|
628
|
+
const dir = serverDataDir();
|
|
629
|
+
if (!existsSync(dir)) await mkdir(dir, { recursive: true });
|
|
630
|
+
}
|
|
631
|
+
async function ensureProjectConfig(log) {
|
|
632
|
+
if (!existsSync(configPath())) {
|
|
633
|
+
await writeConfig({
|
|
634
|
+
serverUrl: SERVER_URL,
|
|
635
|
+
useServerProxy: true,
|
|
636
|
+
apiKey: "",
|
|
637
|
+
adapterPath: "./.alineo/ledger.db",
|
|
638
|
+
agentsDir: "./agents",
|
|
639
|
+
defaults: { resources: {
|
|
640
|
+
cpu: "1000m",
|
|
641
|
+
memory: "1Gi"
|
|
642
|
+
} }
|
|
643
|
+
});
|
|
644
|
+
log("Created alineo.config.json");
|
|
645
|
+
}
|
|
646
|
+
}
|
|
263
647
|
//#endregion
|
|
264
648
|
//#region src/telemetry.ts
|
|
265
649
|
/**
|
|
@@ -425,7 +809,7 @@ async function withTelemetry(commandName, argv, run) {
|
|
|
425
809
|
errorClass = errorClassOf(err);
|
|
426
810
|
throw err;
|
|
427
811
|
} finally {
|
|
428
|
-
const { version } = await import("./package-
|
|
812
|
+
const { version } = await import("./package-oshZF9Gd.mjs");
|
|
429
813
|
await sendTelemetryEvent({
|
|
430
814
|
command: commandName,
|
|
431
815
|
flags,
|
|
@@ -450,7 +834,7 @@ async function recordTuiLaunch() {
|
|
|
450
834
|
const config = await readTelemetryConfig();
|
|
451
835
|
if (!config.enabled) return;
|
|
452
836
|
await maybePrintFirstRunNotice(config);
|
|
453
|
-
const { version } = await import("./package-
|
|
837
|
+
const { version } = await import("./package-oshZF9Gd.mjs");
|
|
454
838
|
await sendTelemetryEvent({
|
|
455
839
|
command: "tui",
|
|
456
840
|
flags: {},
|
|
@@ -498,17 +882,18 @@ function printHelp() {
|
|
|
498
882
|
async function main() {
|
|
499
883
|
if (!cmd && process.stdout.isTTY) {
|
|
500
884
|
await recordTuiLaunch();
|
|
501
|
-
const { launchTui } = await import("./tui-
|
|
885
|
+
const { launchTui } = await import("./tui-CFEiWbe1.mjs");
|
|
502
886
|
await launchTui();
|
|
503
887
|
return;
|
|
504
888
|
}
|
|
505
889
|
if (cmd === "--version" || cmd === "-v" || cmd === "version") {
|
|
506
|
-
const { version } = await import("./package-
|
|
890
|
+
const { version } = await import("./package-oshZF9Gd.mjs");
|
|
507
891
|
console.log(version);
|
|
508
892
|
return;
|
|
509
893
|
}
|
|
510
894
|
const found = commands.find((c) => c.name === cmd);
|
|
511
895
|
if (found) {
|
|
896
|
+
installLoggerFromEnv({ defaultLevel: "info" });
|
|
512
897
|
await withTelemetry(found.name, argv, () => found.run(argv));
|
|
513
898
|
process.exit(0);
|
|
514
899
|
}
|
|
@@ -520,4 +905,4 @@ main().catch((err) => {
|
|
|
520
905
|
process.exit(1);
|
|
521
906
|
});
|
|
522
907
|
//#endregion
|
|
523
|
-
export {
|
|
908
|
+
export { runInit as a, readConfig as i, readTelemetryConfig as n, writeTelemetryConfig as r, envDisabled as t };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { a as runInit } from "./index.mjs";
|
|
2
|
+
//#region src/commands/init.ts
|
|
3
|
+
async function init() {
|
|
4
|
+
await runInit(console.log);
|
|
5
|
+
}
|
|
6
|
+
const initCommand = {
|
|
7
|
+
name: "init",
|
|
8
|
+
group: "sdk",
|
|
9
|
+
variants: [{
|
|
10
|
+
usage: "alineo init",
|
|
11
|
+
summary: "Start OpenSandbox and alineod locally via Docker"
|
|
12
|
+
}],
|
|
13
|
+
run: async () => {
|
|
14
|
+
await init();
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
//#endregion
|
|
18
|
+
export { initCommand };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { i as readConfig } from "./index.mjs";
|
|
2
2
|
import { Sandbox, SandboxStatus } from "@alineo-labs/sandbox";
|
|
3
3
|
import { SQLiteAdapter } from "@alineo-labs/sqlite";
|
|
4
4
|
import { ControlClient, SandboxState } from "@alineo-labs/opensandbox";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { n as getSessions, t as formatAge } from "./sessions-data-
|
|
1
|
+
import { i as readConfig } from "./index.mjs";
|
|
2
|
+
import { n as getSessions, t as formatAge } from "./sessions-data-C8XZge-w.mjs";
|
|
3
3
|
import { join } from "path";
|
|
4
4
|
import { existsSync, readdirSync } from "fs";
|
|
5
5
|
import { Alineo } from "alineo";
|
|
@@ -276,7 +276,7 @@ function createNewSessionView(renderer, onLaunch, onCancel) {
|
|
|
276
276
|
try {
|
|
277
277
|
let specPath = entry.specPath;
|
|
278
278
|
if (!specPath && entry.registryUrl) {
|
|
279
|
-
const { add } = await import("./add-
|
|
279
|
+
const { add } = await import("./add-B6Xmz48s.mjs");
|
|
280
280
|
await add(entry.registryUrl, { log: (msg) => status.content = msg });
|
|
281
281
|
const config = await readConfig();
|
|
282
282
|
specPath = join(config.agentsDir, `${entry.name}.json`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "alineo-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -29,13 +29,15 @@
|
|
|
29
29
|
"test": "bun test"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@alineo-labs/
|
|
33
|
-
"@alineo-labs/
|
|
34
|
-
"@alineo-labs/
|
|
32
|
+
"@alineo-labs/logger": "0.1.0",
|
|
33
|
+
"@alineo-labs/opensandbox": "0.3.1",
|
|
34
|
+
"@alineo-labs/sandbox": "0.4.3",
|
|
35
|
+
"@alineo-labs/sqlite": "0.2.3",
|
|
35
36
|
"@opentui/core": "^0.4.3",
|
|
36
|
-
"alineo": "0.
|
|
37
|
+
"alineo": "0.6.0"
|
|
37
38
|
},
|
|
38
39
|
"devDependencies": {
|
|
40
|
+
"@alineo-labs/cli-shared": "0.0.1",
|
|
39
41
|
"@earendil-works/pi-coding-agent": "^0.85.1",
|
|
40
42
|
"bun-types": "1.4.2",
|
|
41
43
|
"tsdown": "0.23.0",
|
package/dist/init-D6RgxqQQ.mjs
DELETED
|
@@ -1,265 +0,0 @@
|
|
|
1
|
-
import { c as serverConfigPath, i as configPath, l as serverDataDir, o as serverConfigContent, s as serverConfigDir, u as writeConfig } from "./index.mjs";
|
|
2
|
-
import { existsSync } from "fs";
|
|
3
|
-
import { mkdir } from "fs/promises";
|
|
4
|
-
//#region src/docker.ts
|
|
5
|
-
async function spawn(cmd) {
|
|
6
|
-
let proc;
|
|
7
|
-
try {
|
|
8
|
-
proc = Bun.spawn(cmd, {
|
|
9
|
-
stdout: "pipe",
|
|
10
|
-
stderr: "pipe"
|
|
11
|
-
});
|
|
12
|
-
} catch {
|
|
13
|
-
throw new Error(`'${cmd[0]}' not found — is Docker installed?`);
|
|
14
|
-
}
|
|
15
|
-
const [stdout, stderr, exitCode] = await Promise.all([
|
|
16
|
-
new Response(proc.stdout).text(),
|
|
17
|
-
new Response(proc.stderr).text(),
|
|
18
|
-
proc.exited
|
|
19
|
-
]);
|
|
20
|
-
return {
|
|
21
|
-
ok: exitCode === 0,
|
|
22
|
-
stdout,
|
|
23
|
-
stderr
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
async function checkDocker() {
|
|
27
|
-
const { ok, stderr } = await spawn(["docker", "info"]);
|
|
28
|
-
if (!ok) {
|
|
29
|
-
if (stderr.includes("Cannot connect") || stderr.includes("daemon") || stderr.includes("socket")) throw new Error("Docker daemon is not running. Start Docker and try again.");
|
|
30
|
-
throw new Error("Docker is not available. Install Docker and try again.");
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
async function getContainerState(name) {
|
|
34
|
-
const { ok, stdout } = await spawn([
|
|
35
|
-
"docker",
|
|
36
|
-
"inspect",
|
|
37
|
-
name,
|
|
38
|
-
"--format",
|
|
39
|
-
"{{.State.Status}}"
|
|
40
|
-
]);
|
|
41
|
-
if (!ok) return "missing";
|
|
42
|
-
return stdout.trim() === "running" ? "running" : "stopped";
|
|
43
|
-
}
|
|
44
|
-
async function startContainer(name) {
|
|
45
|
-
const { ok, stderr } = await spawn([
|
|
46
|
-
"docker",
|
|
47
|
-
"start",
|
|
48
|
-
name
|
|
49
|
-
]);
|
|
50
|
-
if (!ok) throw new Error(`Failed to start container '${name}': ${stderr.trim()}`);
|
|
51
|
-
}
|
|
52
|
-
async function runContainer(args, label = "container") {
|
|
53
|
-
const { ok, stderr } = await spawn([
|
|
54
|
-
"docker",
|
|
55
|
-
"run",
|
|
56
|
-
...args
|
|
57
|
-
]);
|
|
58
|
-
if (!ok) throw new Error(`Failed to start ${label}: ${stderr.trim()}`);
|
|
59
|
-
}
|
|
60
|
-
async function pullImage(image) {
|
|
61
|
-
const { ok, stderr } = await spawn([
|
|
62
|
-
"docker",
|
|
63
|
-
"pull",
|
|
64
|
-
image
|
|
65
|
-
]);
|
|
66
|
-
if (!ok) throw new Error(`Failed to pull '${image}': ${stderr.trim()}`);
|
|
67
|
-
}
|
|
68
|
-
/** Default health predicate: OpenSandbox's `/health` returns `{ status: "healthy" }`. */
|
|
69
|
-
const isOpenSandboxHealthy = (body) => body?.status === "healthy";
|
|
70
|
-
async function pollHealth(url, timeoutMs = 6e4, isHealthy = isOpenSandboxHealthy) {
|
|
71
|
-
const deadline = Date.now() + timeoutMs;
|
|
72
|
-
while (Date.now() < deadline) {
|
|
73
|
-
try {
|
|
74
|
-
const res = await fetch(url);
|
|
75
|
-
if (res.ok && isHealthy(await res.json())) return;
|
|
76
|
-
} catch {}
|
|
77
|
-
await new Promise((r) => setTimeout(r, 1e3));
|
|
78
|
-
}
|
|
79
|
-
throw new Error(`${url} did not become healthy within ${timeoutMs / 1e3}s`);
|
|
80
|
-
}
|
|
81
|
-
//#endregion
|
|
82
|
-
//#region src/pi-model-keys.ts
|
|
83
|
-
/**
|
|
84
|
-
* Model API key env vars Pi's coding-agent runtime resolves providers from — mirrors the
|
|
85
|
-
* `envMap` in earendil-works/pi's `packages/ai/src/env-api-keys.ts` (plus Anthropic's three,
|
|
86
|
-
* handled separately there). An `AgentSpec`'s env map (`{ NVIDIA_API_KEY: "${NVIDIA_API_KEY}" }`,
|
|
87
|
-
* see `packages/agent/src/schema.ts`) is resolved from `process.env` inside whatever process
|
|
88
|
-
* calls `Alineo.load()`/`.spawn()` — for a swarm run through alineod, that's alineod's own
|
|
89
|
-
* container. `alineo init` forwards whichever of these are set in the operator's shell into
|
|
90
|
-
* that container so any Pi-supported model works, not just NVIDIA's free tier.
|
|
91
|
-
*
|
|
92
|
-
* Deliberately excludes ambient/file-based credential mechanisms (AWS IAM role chains,
|
|
93
|
-
* `AWS_PROFILE`, Google Application Default Credentials) — those need a mounted file or
|
|
94
|
-
* assumed-role wiring, not just a passed-through env var. Amazon Bedrock and Google Vertex
|
|
95
|
-
* are not yet supported by `init`'s auto-start for that reason.
|
|
96
|
-
*
|
|
97
|
-
* Keep in sync with pi's `env-api-keys.ts` `envMap` as it adds providers.
|
|
98
|
-
*/
|
|
99
|
-
const PI_MODEL_API_KEY_ENV_VARS = [
|
|
100
|
-
"ANTHROPIC_API_KEY",
|
|
101
|
-
"ANTHROPIC_OAUTH_TOKEN",
|
|
102
|
-
"ANTHROPIC_AUTH_TOKEN",
|
|
103
|
-
"OPENAI_API_KEY",
|
|
104
|
-
"AZURE_OPENAI_API_KEY",
|
|
105
|
-
"GEMINI_API_KEY",
|
|
106
|
-
"NVIDIA_API_KEY",
|
|
107
|
-
"DEEPSEEK_API_KEY",
|
|
108
|
-
"MISTRAL_API_KEY",
|
|
109
|
-
"GROQ_API_KEY",
|
|
110
|
-
"CEREBRAS_API_KEY",
|
|
111
|
-
"XAI_API_KEY",
|
|
112
|
-
"OPENROUTER_API_KEY",
|
|
113
|
-
"AI_GATEWAY_API_KEY",
|
|
114
|
-
"CLOUDFLARE_API_KEY",
|
|
115
|
-
"CLOUDFLARE_ACCOUNT_ID",
|
|
116
|
-
"CLOUDFLARE_GATEWAY_ID",
|
|
117
|
-
"RADIUS_API_KEY",
|
|
118
|
-
"OPENCODE_API_KEY",
|
|
119
|
-
"QWEN_TOKEN_PLAN_API_KEY",
|
|
120
|
-
"QWEN_TOKEN_PLAN_CN_API_KEY",
|
|
121
|
-
"MOONSHOT_API_KEY",
|
|
122
|
-
"KIMI_API_KEY",
|
|
123
|
-
"ZAI_API_KEY",
|
|
124
|
-
"ZAI_CODING_CN_API_KEY",
|
|
125
|
-
"MINIMAX_API_KEY",
|
|
126
|
-
"MINIMAX_CN_API_KEY",
|
|
127
|
-
"XIAOMI_API_KEY",
|
|
128
|
-
"XIAOMI_TOKEN_PLAN_CN_API_KEY",
|
|
129
|
-
"XIAOMI_TOKEN_PLAN_AMS_API_KEY",
|
|
130
|
-
"XIAOMI_TOKEN_PLAN_SGP_API_KEY",
|
|
131
|
-
"ANT_LING_API_KEY",
|
|
132
|
-
"HF_TOKEN",
|
|
133
|
-
"FIREWORKS_API_KEY",
|
|
134
|
-
"TOGETHER_API_KEY",
|
|
135
|
-
"BASETEN_API_KEY",
|
|
136
|
-
"COPILOT_GITHUB_TOKEN"
|
|
137
|
-
];
|
|
138
|
-
//#endregion
|
|
139
|
-
//#region src/commands/init.ts
|
|
140
|
-
const OPENSANDBOX_CONTAINER_NAME = "alineo-opensandbox";
|
|
141
|
-
const SERVER_URL = "http://127.0.0.1:8080";
|
|
142
|
-
const ALINEOD_CONTAINER_NAME = "alineo-alineod";
|
|
143
|
-
const ALINEOD_IMAGE = "ghcr.io/drejt/alineod:latest";
|
|
144
|
-
const ALINEOD_URL = "http://127.0.0.1:4600";
|
|
145
|
-
const isAlineodHealthy = (body) => body?.ok === true;
|
|
146
|
-
async function init() {
|
|
147
|
-
console.log("Checking Docker...");
|
|
148
|
-
await checkDocker();
|
|
149
|
-
const state = await getContainerState(OPENSANDBOX_CONTAINER_NAME);
|
|
150
|
-
if (state === "running") console.log(`OpenSandbox already running at ${SERVER_URL}`);
|
|
151
|
-
else if (state === "stopped") {
|
|
152
|
-
console.log("Restarting OpenSandbox container...");
|
|
153
|
-
await startContainer(OPENSANDBOX_CONTAINER_NAME);
|
|
154
|
-
console.log("Waiting for OpenSandbox to be ready...");
|
|
155
|
-
await pollHealth(`${SERVER_URL}/health`);
|
|
156
|
-
} else {
|
|
157
|
-
await ensureServerConfig();
|
|
158
|
-
await ensureServerDataDir();
|
|
159
|
-
console.log("Starting OpenSandbox in Docker...");
|
|
160
|
-
await runContainer([
|
|
161
|
-
"-d",
|
|
162
|
-
"--name",
|
|
163
|
-
OPENSANDBOX_CONTAINER_NAME,
|
|
164
|
-
"-p",
|
|
165
|
-
"8080:8080",
|
|
166
|
-
"-v",
|
|
167
|
-
"/var/run/docker.sock:/var/run/docker.sock",
|
|
168
|
-
"-v",
|
|
169
|
-
`${serverConfigPath()}:/etc/opensandbox/config.toml:ro`,
|
|
170
|
-
"-v",
|
|
171
|
-
`${serverDataDir()}:/data`,
|
|
172
|
-
"-e",
|
|
173
|
-
"SANDBOX_CONFIG_PATH=/etc/opensandbox/config.toml",
|
|
174
|
-
"-e",
|
|
175
|
-
"OPENSANDBOX_INSECURE_SERVER=YES",
|
|
176
|
-
"opensandbox/server:latest"
|
|
177
|
-
], "OpenSandbox container");
|
|
178
|
-
console.log("Waiting for OpenSandbox to be ready...");
|
|
179
|
-
await pollHealth(`${SERVER_URL}/health`);
|
|
180
|
-
}
|
|
181
|
-
await ensureAlineod();
|
|
182
|
-
await ensureProjectConfig();
|
|
183
|
-
console.log(`OpenSandbox running at ${SERVER_URL}, alineod running at ${ALINEOD_URL} — ready.`);
|
|
184
|
-
}
|
|
185
|
-
async function ensureAlineod() {
|
|
186
|
-
const state = await getContainerState(ALINEOD_CONTAINER_NAME);
|
|
187
|
-
if (state === "running") {
|
|
188
|
-
console.log(`alineod already running at ${ALINEOD_URL}`);
|
|
189
|
-
return;
|
|
190
|
-
}
|
|
191
|
-
if (state === "stopped") {
|
|
192
|
-
console.log("Restarting alineod container...");
|
|
193
|
-
await startContainer(ALINEOD_CONTAINER_NAME);
|
|
194
|
-
} else {
|
|
195
|
-
console.log(`Pulling ${ALINEOD_IMAGE}...`);
|
|
196
|
-
await pullImage(ALINEOD_IMAGE);
|
|
197
|
-
console.log("Starting alineod in Docker...");
|
|
198
|
-
const foundModelKeys = PI_MODEL_API_KEY_ENV_VARS.filter((name) => process.env[name]);
|
|
199
|
-
const modelKeyArgs = foundModelKeys.flatMap((name) => ["-e", `${name}=${process.env[name]}`]);
|
|
200
|
-
if (foundModelKeys.length > 0) console.log(`Forwarding model key(s): ${foundModelKeys.join(", ")}`);
|
|
201
|
-
else console.log("No known model API key found in the environment — alineod will start, but agent specs referencing a provider key will fail until one is set (see any of the env vars in packages/cli/src/pi-model-keys.ts).");
|
|
202
|
-
await runContainer([
|
|
203
|
-
"-d",
|
|
204
|
-
"--name",
|
|
205
|
-
ALINEOD_CONTAINER_NAME,
|
|
206
|
-
"--network",
|
|
207
|
-
"host",
|
|
208
|
-
"-e",
|
|
209
|
-
`ALINEO_SERVER_URL=${SERVER_URL}`,
|
|
210
|
-
"-e",
|
|
211
|
-
"ALINEO_USE_SERVER_PROXY=true",
|
|
212
|
-
...modelKeyArgs,
|
|
213
|
-
"-v",
|
|
214
|
-
"alineod-data:/data",
|
|
215
|
-
ALINEOD_IMAGE
|
|
216
|
-
], "alineod container");
|
|
217
|
-
}
|
|
218
|
-
console.log("Waiting for alineod to be ready...");
|
|
219
|
-
await pollHealth(`${ALINEOD_URL}/health`, 6e4, isAlineodHealthy);
|
|
220
|
-
}
|
|
221
|
-
async function ensureServerConfig() {
|
|
222
|
-
const dir = serverConfigDir();
|
|
223
|
-
if (!existsSync(dir)) await mkdir(dir, { recursive: true });
|
|
224
|
-
const path = serverConfigPath();
|
|
225
|
-
if (!existsSync(path)) await Bun.write(path, serverConfigContent());
|
|
226
|
-
}
|
|
227
|
-
/**
|
|
228
|
-
* Host-side half of the `serverDataDir()` bind mount. `docker run -v` would auto-create
|
|
229
|
-
* a missing host path anyway, but doing it explicitly here matches `ensureServerConfig()`'s
|
|
230
|
-
* pattern and keeps directory creation in one place rather than relying on Docker's
|
|
231
|
-
* legacy-`-v`-specific behavior (unlike `--mount`, which requires the source to pre-exist).
|
|
232
|
-
*/
|
|
233
|
-
async function ensureServerDataDir() {
|
|
234
|
-
const dir = serverDataDir();
|
|
235
|
-
if (!existsSync(dir)) await mkdir(dir, { recursive: true });
|
|
236
|
-
}
|
|
237
|
-
async function ensureProjectConfig() {
|
|
238
|
-
if (!existsSync(configPath())) {
|
|
239
|
-
await writeConfig({
|
|
240
|
-
serverUrl: SERVER_URL,
|
|
241
|
-
useServerProxy: true,
|
|
242
|
-
apiKey: "",
|
|
243
|
-
adapterPath: "./.alineo/ledger.db",
|
|
244
|
-
agentsDir: "./agents",
|
|
245
|
-
defaults: { resources: {
|
|
246
|
-
cpu: "1000m",
|
|
247
|
-
memory: "1Gi"
|
|
248
|
-
} }
|
|
249
|
-
});
|
|
250
|
-
console.log("Created alineo.config.json");
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
const initCommand = {
|
|
254
|
-
name: "init",
|
|
255
|
-
group: "sdk",
|
|
256
|
-
variants: [{
|
|
257
|
-
usage: "alineo init",
|
|
258
|
-
summary: "Start OpenSandbox and alineod locally via Docker"
|
|
259
|
-
}],
|
|
260
|
-
run: async () => {
|
|
261
|
-
await init();
|
|
262
|
-
}
|
|
263
|
-
};
|
|
264
|
-
//#endregion
|
|
265
|
-
export { initCommand };
|