alineo-cli 0.1.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 +195 -0
- package/dist/add-Dv8ui6gU.mjs +47 -0
- package/dist/agent-prompt-DeTX84DU.mjs +17 -0
- package/dist/agents-uXEMlj41.mjs +46 -0
- package/dist/args-BBPtXttx.mjs +8 -0
- package/dist/fork-BSbb54Ba.mjs +89 -0
- package/dist/index.mjs +492 -0
- package/dist/init-BI4f18xk.mjs +162 -0
- package/dist/kill-CTAbMh-H.mjs +35 -0
- package/dist/list-DKxmgyNL.mjs +53 -0
- package/dist/logs-BkVSXK9O.mjs +44 -0
- package/dist/package-DKqFeJxs.mjs +4 -0
- package/dist/prompt-DN_v5l5u.mjs +64 -0
- package/dist/remove-Dsp071zF.mjs +26 -0
- package/dist/sessions-data-BYaLq9wh.mjs +54 -0
- package/dist/spawn-CBsNRaLz.mjs +70 -0
- package/dist/telemetry-D5PF-o_p.mjs +52 -0
- package/dist/tui-mkWqwNZl.mjs +429 -0
- package/package.json +51 -0
- package/pi-extension/alineo.ts +179 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,492 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { join as join$1 } from "path";
|
|
4
|
+
import { homedir } from "os";
|
|
5
|
+
import { existsSync } from "fs";
|
|
6
|
+
import { mkdir } from "fs/promises";
|
|
7
|
+
//#region src/commands/registry.ts
|
|
8
|
+
/**
|
|
9
|
+
* Every alineo subcommand's name/group/usage/summary, plus a `run` that dynamically
|
|
10
|
+
* imports its implementation. The metadata here is intentionally duplicated from each
|
|
11
|
+
* command file's own `xCommand` export (e.g. `initCommand` in init.ts) rather than
|
|
12
|
+
* statically imported — a static import would pull in that command's full dependency
|
|
13
|
+
* graph (e.g. spawn.ts drags in `@alineo-labs/agent`, `alineo`, `@alineo-labs/sqlite`) on *every* CLI
|
|
14
|
+
* invocation just to print help text, which measured ~3x slower for something as
|
|
15
|
+
* trivial as `alineo --version`. Duplicating a couple of plain strings per command is a
|
|
16
|
+
* much smaller risk than that: a mismatch would show up immediately in the printed
|
|
17
|
+
* help output, unlike the old free-floating prose block that could silently drift from
|
|
18
|
+
* the switch statement's actual behavior with no visual signal at all.
|
|
19
|
+
*
|
|
20
|
+
* Adding a command: create the command file with its own `xCommand` export (see
|
|
21
|
+
* types.ts), then add one entry here whose `variants` matches it.
|
|
22
|
+
*/
|
|
23
|
+
const commands = [
|
|
24
|
+
{
|
|
25
|
+
name: "init",
|
|
26
|
+
group: "sdk",
|
|
27
|
+
variants: [{
|
|
28
|
+
usage: "alineo init",
|
|
29
|
+
summary: "Start OpenSandbox locally via Docker"
|
|
30
|
+
}],
|
|
31
|
+
run: async (argv) => (await import("./init-BI4f18xk.mjs")).initCommand.run(argv)
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
name: "add",
|
|
35
|
+
group: "sdk",
|
|
36
|
+
variants: [{
|
|
37
|
+
usage: "alineo add <url> [--name <n>]",
|
|
38
|
+
summary: "Fetch and save an agent spec locally"
|
|
39
|
+
}],
|
|
40
|
+
run: async (argv) => (await import("./add-Dv8ui6gU.mjs")).addCommand.run(argv)
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
name: "list",
|
|
44
|
+
group: "sdk",
|
|
45
|
+
variants: [{
|
|
46
|
+
usage: "alineo list",
|
|
47
|
+
summary: "List saved agent specs"
|
|
48
|
+
}],
|
|
49
|
+
run: async (argv) => (await import("./list-DKxmgyNL.mjs")).listCommand.run(argv)
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
name: "remove",
|
|
53
|
+
group: "sdk",
|
|
54
|
+
variants: [{
|
|
55
|
+
usage: "alineo remove <name>",
|
|
56
|
+
summary: "Remove a saved agent spec"
|
|
57
|
+
}],
|
|
58
|
+
run: async (argv) => (await import("./remove-Dsp071zF.mjs")).removeCommand.run(argv)
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
name: "spawn",
|
|
62
|
+
group: "agent",
|
|
63
|
+
variants: [{
|
|
64
|
+
usage: "alineo spawn <spec>",
|
|
65
|
+
summary: "Start a fresh agent sandbox, print its name, exit"
|
|
66
|
+
}, {
|
|
67
|
+
usage: "alineo spawn <spec> --prompt <msg>",
|
|
68
|
+
summary: "Start it, send one prompt, print the reply, exit"
|
|
69
|
+
}],
|
|
70
|
+
run: async (argv) => (await import("./spawn-CBsNRaLz.mjs")).spawnCommand.run(argv)
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
name: "prompt",
|
|
74
|
+
group: "agent",
|
|
75
|
+
variants: [{
|
|
76
|
+
usage: "alineo prompt <sandbox-id> <msg>",
|
|
77
|
+
summary: "Send one prompt to a running sandbox, print the reply"
|
|
78
|
+
}],
|
|
79
|
+
run: async (argv) => (await import("./prompt-DN_v5l5u.mjs")).promptCommand.run(argv)
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
name: "fork",
|
|
83
|
+
group: "agent",
|
|
84
|
+
variants: [{
|
|
85
|
+
usage: "alineo fork <name> <child-spec>",
|
|
86
|
+
summary: "Fork a running session's own live sandbox into a new child"
|
|
87
|
+
}],
|
|
88
|
+
run: async (argv) => (await import("./fork-BSbb54Ba.mjs")).forkCommand.run(argv)
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
name: "agents",
|
|
92
|
+
group: "agent",
|
|
93
|
+
variants: [{
|
|
94
|
+
usage: "alineo agents [--json]",
|
|
95
|
+
summary: "List running agent sessions"
|
|
96
|
+
}],
|
|
97
|
+
run: async (argv) => (await import("./agents-uXEMlj41.mjs")).agentsCommand.run(argv)
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
name: "kill",
|
|
101
|
+
group: "agent",
|
|
102
|
+
variants: [{
|
|
103
|
+
usage: "alineo kill <sandbox-id>",
|
|
104
|
+
summary: "Stop a sandbox"
|
|
105
|
+
}],
|
|
106
|
+
run: async (argv) => (await import("./kill-CTAbMh-H.mjs")).killCommand.run(argv)
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
name: "logs",
|
|
110
|
+
group: "agent",
|
|
111
|
+
variants: [{
|
|
112
|
+
usage: "alineo logs <name> [--json]",
|
|
113
|
+
summary: "Print ledger events for a session"
|
|
114
|
+
}],
|
|
115
|
+
run: async (argv) => (await import("./logs-BkVSXK9O.mjs")).logsCommand.run(argv)
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
name: "telemetry",
|
|
119
|
+
group: "sdk",
|
|
120
|
+
variants: [
|
|
121
|
+
{
|
|
122
|
+
usage: "alineo telemetry status",
|
|
123
|
+
summary: "Show whether telemetry is enabled"
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
usage: "alineo telemetry enable",
|
|
127
|
+
summary: "Enable anonymous usage telemetry"
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
usage: "alineo telemetry disable",
|
|
131
|
+
summary: "Disable anonymous usage telemetry"
|
|
132
|
+
}
|
|
133
|
+
],
|
|
134
|
+
run: async (argv) => (await import("./telemetry-D5PF-o_p.mjs")).telemetryCommand.run(argv)
|
|
135
|
+
}
|
|
136
|
+
];
|
|
137
|
+
//#endregion
|
|
138
|
+
//#region src/config.ts
|
|
139
|
+
const CONFIG_DIR = ".alineo";
|
|
140
|
+
const CONFIG_FILE = "alineo.config.json";
|
|
141
|
+
function configPath() {
|
|
142
|
+
return CONFIG_FILE;
|
|
143
|
+
}
|
|
144
|
+
function globalConfigPath() {
|
|
145
|
+
return join$1(serverConfigDir(), "config.json");
|
|
146
|
+
}
|
|
147
|
+
function fillDefaults(data) {
|
|
148
|
+
return {
|
|
149
|
+
serverUrl: data.serverUrl ?? "http://127.0.0.1:8080",
|
|
150
|
+
useServerProxy: data.useServerProxy ?? true,
|
|
151
|
+
apiKey: data.apiKey ?? "",
|
|
152
|
+
adapterPath: data.adapterPath ?? "./.alineo/ledger.db",
|
|
153
|
+
agentsDir: data.agentsDir ?? "./agents",
|
|
154
|
+
defaults: { resources: {
|
|
155
|
+
cpu: data.defaults?.resources?.cpu ?? "1000m",
|
|
156
|
+
memory: data.defaults?.resources?.memory ?? "1Gi"
|
|
157
|
+
} }
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Resolves, in order: a project-local `alineo.config.json` (written by `alineo init`
|
|
162
|
+
* for repos that want their own agents dir / ledger), then a global
|
|
163
|
+
* `~/.config/alineo/config.json`. If neither exists yet, bootstraps the global
|
|
164
|
+
* one so a fresh `bunx alineo-cli` works without requiring `init` in every directory.
|
|
165
|
+
*/
|
|
166
|
+
async function readConfig() {
|
|
167
|
+
const localFile = Bun.file(configPath());
|
|
168
|
+
if (await localFile.exists()) return fillDefaults(await localFile.json());
|
|
169
|
+
const globalPath = globalConfigPath();
|
|
170
|
+
const globalFile = Bun.file(globalPath);
|
|
171
|
+
if (await globalFile.exists()) return fillDefaults(await globalFile.json());
|
|
172
|
+
const dir = serverConfigDir();
|
|
173
|
+
if (!existsSync(dir)) await mkdir(dir, { recursive: true });
|
|
174
|
+
const config = {
|
|
175
|
+
serverUrl: "http://127.0.0.1:8080",
|
|
176
|
+
useServerProxy: true,
|
|
177
|
+
apiKey: "",
|
|
178
|
+
adapterPath: join$1(dir, "ledger.db"),
|
|
179
|
+
agentsDir: join$1(dir, "agents"),
|
|
180
|
+
defaults: { resources: {
|
|
181
|
+
cpu: "1000m",
|
|
182
|
+
memory: "1Gi"
|
|
183
|
+
} }
|
|
184
|
+
};
|
|
185
|
+
await Bun.write(globalPath, JSON.stringify(config, null, 2) + "\n");
|
|
186
|
+
return config;
|
|
187
|
+
}
|
|
188
|
+
async function writeConfig(config) {
|
|
189
|
+
if (!existsSync(CONFIG_DIR)) await mkdir(CONFIG_DIR, { recursive: true });
|
|
190
|
+
await Bun.write(configPath(), JSON.stringify(config, null, 2) + "\n");
|
|
191
|
+
}
|
|
192
|
+
function serverConfigDir() {
|
|
193
|
+
return join$1(homedir(), ".config", "alineo");
|
|
194
|
+
}
|
|
195
|
+
function serverConfigPath() {
|
|
196
|
+
return join$1(serverConfigDir(), "server.toml");
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Host directory bind-mounted into the OpenSandbox container at `/data` (see
|
|
200
|
+
* `commands/init.ts`), backing the `[store].path` set below. OpenSandbox itself persists
|
|
201
|
+
* snapshot metadata durably (a SQLite db, meant to survive the server process restarting —
|
|
202
|
+
* see opensandbox-group/OpenSandbox's `PersistedSnapshotService`), but that guarantee is
|
|
203
|
+
* only as good as where the db file actually lives: without this mount, it sits in the
|
|
204
|
+
* `alineo-opensandbox` container's own writable layer, so restart is fine but any time the
|
|
205
|
+
* container itself is recreated (host reboot with no restart policy, `docker system prune`,
|
|
206
|
+
* a stray `docker rm`) silently loses every cached snapshot record — every `Agent.load()`
|
|
207
|
+
* snapshot fast path pays a full cold rebuild next time, indistinguishable from a genuinely
|
|
208
|
+
* changed spec (see issue #20). Bind-mounting this directory makes that data outlive the
|
|
209
|
+
* container's own lifecycle, matching OpenSandbox's own intent.
|
|
210
|
+
*/
|
|
211
|
+
function serverDataDir() {
|
|
212
|
+
return join$1(serverConfigDir(), "opensandbox-data");
|
|
213
|
+
}
|
|
214
|
+
function serverConfigContent() {
|
|
215
|
+
return `[server]
|
|
216
|
+
host = "0.0.0.0"
|
|
217
|
+
port = 8080
|
|
218
|
+
eip = "http://127.0.0.1:8080"
|
|
219
|
+
|
|
220
|
+
[runtime]
|
|
221
|
+
type = "docker"
|
|
222
|
+
execd_image = "opensandbox/execd:v1.0.19"
|
|
223
|
+
|
|
224
|
+
[docker]
|
|
225
|
+
network_mode = "bridge"
|
|
226
|
+
|
|
227
|
+
[store]
|
|
228
|
+
type = "sqlite"
|
|
229
|
+
path = "/data/opensandbox.db"
|
|
230
|
+
`;
|
|
231
|
+
}
|
|
232
|
+
//#endregion
|
|
233
|
+
//#region src/telemetry.ts
|
|
234
|
+
/**
|
|
235
|
+
* `alineo` CLI usage telemetry. Anonymous, allowlisted (command name + a small per-command set
|
|
236
|
+
* of boolean flag presence, never argv/paths/spec contents), default-on with an explicit
|
|
237
|
+
* opt-out. Wired in at the single dispatch choke point in index.ts, not per-command -- every
|
|
238
|
+
* command file in commands/ stays untouched.
|
|
239
|
+
*/
|
|
240
|
+
/** The deployed ingest endpoint (see apps/telemetry). Overridable via env var, same override
|
|
241
|
+
* convention `@alineo-labs/otel`'s own collector URL uses -- useful for pointing at a local
|
|
242
|
+
* `apps/telemetry` instance during development instead. */
|
|
243
|
+
const DEFAULT_TELEMETRY_ENDPOINT = "https://telemetry.alineo.tech/v1/events";
|
|
244
|
+
const SEND_TIMEOUT_MS = 500;
|
|
245
|
+
/** `ALINEO_TELEMETRY_CONFIG_PATH` is an internal test seam, not a documented user-facing setting
|
|
246
|
+
* (`node:os`'s `homedir()` doesn't re-read `process.env.HOME` after its first call in a process,
|
|
247
|
+
* so tests can't isolate the real `serverConfigDir()` path via env mutation the way they can for
|
|
248
|
+
* plain env-var-driven config elsewhere) -- defaults to the real path for every real invocation. */
|
|
249
|
+
function telemetryConfigPath() {
|
|
250
|
+
return process.env.ALINEO_TELEMETRY_CONFIG_PATH ?? join(serverConfigDir(), "telemetry.json");
|
|
251
|
+
}
|
|
252
|
+
function newAnonymousId() {
|
|
253
|
+
return crypto.randomUUID();
|
|
254
|
+
}
|
|
255
|
+
async function readTelemetryConfig() {
|
|
256
|
+
const file = Bun.file(telemetryConfigPath());
|
|
257
|
+
if (await file.exists()) {
|
|
258
|
+
const data = await file.json();
|
|
259
|
+
return {
|
|
260
|
+
enabled: data.enabled ?? true,
|
|
261
|
+
anonymousId: data.anonymousId ?? newAnonymousId(),
|
|
262
|
+
notifiedAt: data.notifiedAt ?? null
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
return {
|
|
266
|
+
enabled: true,
|
|
267
|
+
anonymousId: newAnonymousId(),
|
|
268
|
+
notifiedAt: null
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
async function writeTelemetryConfig(config) {
|
|
272
|
+
await Bun.write(telemetryConfigPath(), JSON.stringify(config, null, 2) + "\n");
|
|
273
|
+
}
|
|
274
|
+
/** Checked before anything else -- either env var disables telemetry with no config file read at
|
|
275
|
+
* all, matching Next.js's "check the env var before any other init logic runs" ordering.
|
|
276
|
+
* `DO_NOT_TRACK` is the cross-tool convention Turborepo also honors alongside its own var.
|
|
277
|
+
* Exported so `commands/telemetry.ts`'s `status` output can explain *why* telemetry is off when
|
|
278
|
+
* an env var is the reason, not just the persisted config's own `enabled` flag. */
|
|
279
|
+
function envDisabled() {
|
|
280
|
+
return !!process.env.ALINEO_TELEMETRY_DISABLED || !!process.env.DO_NOT_TRACK;
|
|
281
|
+
}
|
|
282
|
+
const FIRST_RUN_NOTICE = `[alineo] Anonymous usage telemetry: which command ran, a few known flags,
|
|
283
|
+
success/failure, timing -- never spec contents, prompts, or file paths. Disable any time with
|
|
284
|
+
'alineo telemetry disable' or ALINEO_TELEMETRY_DISABLED=1.`;
|
|
285
|
+
async function maybePrintFirstRunNotice(config) {
|
|
286
|
+
if (config.notifiedAt !== null) return;
|
|
287
|
+
console.error(FIRST_RUN_NOTICE);
|
|
288
|
+
await writeTelemetryConfig({
|
|
289
|
+
...config,
|
|
290
|
+
notifiedAt: Date.now()
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
/** Bounded send, not fire-and-forget, not a blocking wait -- races the POST against a short
|
|
294
|
+
* timeout so an unreachable/slow endpoint never meaningfully delays a real command's exit.
|
|
295
|
+
* Never throws: a failed/slow send must not surface as a CLI error. */
|
|
296
|
+
async function sendTelemetryEvent(event, endpointUrl = process.env.ALINEO_TELEMETRY_ENDPOINT ?? DEFAULT_TELEMETRY_ENDPOINT) {
|
|
297
|
+
try {
|
|
298
|
+
await fetch(endpointUrl, {
|
|
299
|
+
method: "POST",
|
|
300
|
+
headers: { "Content-Type": "application/json" },
|
|
301
|
+
body: JSON.stringify(event),
|
|
302
|
+
signal: AbortSignal.timeout(SEND_TIMEOUT_MS)
|
|
303
|
+
});
|
|
304
|
+
} catch {}
|
|
305
|
+
}
|
|
306
|
+
/** Per-command allowlist of flags safe to record *presence of* -- never their values, never raw
|
|
307
|
+
* argv. A flag not listed here is invisible to telemetry until someone deliberately adds it;
|
|
308
|
+
* under-collecting is the only failure mode. Keys match each command's own `flag(argv, "--x")`/
|
|
309
|
+
* `argv.includes("--x")` calls (see commands/spawn.ts, fork.ts, prompt.ts, agents.ts, logs.ts). */
|
|
310
|
+
const FLAG_ALLOWLIST = {
|
|
311
|
+
spawn: [
|
|
312
|
+
"--prompt",
|
|
313
|
+
"--rebuild",
|
|
314
|
+
"--json",
|
|
315
|
+
"--depth",
|
|
316
|
+
"--max",
|
|
317
|
+
"--timeout",
|
|
318
|
+
"--run-id"
|
|
319
|
+
],
|
|
320
|
+
fork: [
|
|
321
|
+
"--prompt",
|
|
322
|
+
"--json",
|
|
323
|
+
"--depth",
|
|
324
|
+
"--max",
|
|
325
|
+
"--timeout"
|
|
326
|
+
],
|
|
327
|
+
prompt: [
|
|
328
|
+
"--json",
|
|
329
|
+
"--spec",
|
|
330
|
+
"--timeout"
|
|
331
|
+
],
|
|
332
|
+
agents: ["--json"],
|
|
333
|
+
logs: ["--json"],
|
|
334
|
+
init: [],
|
|
335
|
+
add: [],
|
|
336
|
+
list: [],
|
|
337
|
+
remove: [],
|
|
338
|
+
kill: []
|
|
339
|
+
};
|
|
340
|
+
/** Presence-only booleans for whichever flags `commandName`'s own allowlist names -- never the
|
|
341
|
+
* flag's value, never anything not on the list. */
|
|
342
|
+
function extractAllowedFlags(commandName, argv) {
|
|
343
|
+
const allowed = FLAG_ALLOWLIST[commandName] ?? [];
|
|
344
|
+
const flags = {};
|
|
345
|
+
for (const flagName of allowed) flags[flagName.replace(/^--/, "")] = argv.includes(flagName);
|
|
346
|
+
return flags;
|
|
347
|
+
}
|
|
348
|
+
/** `spawn`/`fork` take a spec file as their first non-flag argv token -- reads just its own
|
|
349
|
+
* `provider` field (a small, closed, non-identifying set like `"nvidia"`/`"google"`) to answer
|
|
350
|
+
* "which providers actually get used." Deliberately not `model` (closer to free text, not needed
|
|
351
|
+
* for that question) and nothing else from the spec. Never throws -- a missing/unreadable spec
|
|
352
|
+
* file must never surface through telemetry into the real command. */
|
|
353
|
+
async function extractSpecProvider(commandName, argv) {
|
|
354
|
+
if (commandName !== "spawn" && commandName !== "fork") return void 0;
|
|
355
|
+
const specPath = (commandName === "fork" ? argv.slice(1) : argv).find((a) => !a.startsWith("--"));
|
|
356
|
+
if (!specPath) return void 0;
|
|
357
|
+
try {
|
|
358
|
+
const spec = await Bun.file(specPath).json();
|
|
359
|
+
return typeof spec.provider === "string" ? spec.provider : void 0;
|
|
360
|
+
} catch {
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
function errorClassOf(err) {
|
|
365
|
+
return err instanceof Error ? err.constructor.name : "UnknownError";
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Wraps a single command's `run()` call: on disabled, just calls `run()` directly (zero
|
|
369
|
+
* overhead, no config read even). Otherwise times the call, records outcome/errorClass, builds
|
|
370
|
+
* and sends the event, prints the first-run notice if this is the first time, and always
|
|
371
|
+
* re-throws whatever `run()` threw, unchanged -- telemetry must never swallow or alter a real
|
|
372
|
+
* command failure.
|
|
373
|
+
*/
|
|
374
|
+
async function withTelemetry(commandName, argv, run) {
|
|
375
|
+
if (envDisabled()) {
|
|
376
|
+
await run();
|
|
377
|
+
return;
|
|
378
|
+
}
|
|
379
|
+
const config = await readTelemetryConfig();
|
|
380
|
+
if (!config.enabled) {
|
|
381
|
+
await run();
|
|
382
|
+
return;
|
|
383
|
+
}
|
|
384
|
+
await maybePrintFirstRunNotice(config);
|
|
385
|
+
const flags = extractAllowedFlags(commandName, argv);
|
|
386
|
+
const specProvider = await extractSpecProvider(commandName, argv);
|
|
387
|
+
const start = performance.now();
|
|
388
|
+
let outcome = "success";
|
|
389
|
+
let errorClass;
|
|
390
|
+
try {
|
|
391
|
+
await run();
|
|
392
|
+
} catch (err) {
|
|
393
|
+
outcome = "error";
|
|
394
|
+
errorClass = errorClassOf(err);
|
|
395
|
+
throw err;
|
|
396
|
+
} finally {
|
|
397
|
+
const { version } = await import("./package-DKqFeJxs.mjs");
|
|
398
|
+
await sendTelemetryEvent({
|
|
399
|
+
command: commandName,
|
|
400
|
+
flags,
|
|
401
|
+
specProvider,
|
|
402
|
+
outcome,
|
|
403
|
+
errorClass,
|
|
404
|
+
durationMs: Math.round(performance.now() - start),
|
|
405
|
+
cliVersion: version,
|
|
406
|
+
osPlatform: process.platform,
|
|
407
|
+
osArch: process.arch,
|
|
408
|
+
bunVersion: Bun.version,
|
|
409
|
+
isCI: !!process.env.CI,
|
|
410
|
+
anonymousId: config.anonymousId
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
/** The bare-`alineo`-launches-TUI path (index.ts) isn't a single bounded command run the way
|
|
415
|
+
* `withTelemetry()` assumes -- a TUI session's own lifetime makes "wait for this before
|
|
416
|
+
* proceeding" meaningless, so this only ever fires a launch count, never duration/outcome. */
|
|
417
|
+
async function recordTuiLaunch() {
|
|
418
|
+
if (envDisabled()) return;
|
|
419
|
+
const config = await readTelemetryConfig();
|
|
420
|
+
if (!config.enabled) return;
|
|
421
|
+
await maybePrintFirstRunNotice(config);
|
|
422
|
+
const { version } = await import("./package-DKqFeJxs.mjs");
|
|
423
|
+
await sendTelemetryEvent({
|
|
424
|
+
command: "tui",
|
|
425
|
+
flags: {},
|
|
426
|
+
outcome: "success",
|
|
427
|
+
durationMs: 0,
|
|
428
|
+
cliVersion: version,
|
|
429
|
+
osPlatform: process.platform,
|
|
430
|
+
osArch: process.arch,
|
|
431
|
+
bunVersion: Bun.version,
|
|
432
|
+
isCI: !!process.env.CI,
|
|
433
|
+
anonymousId: config.anonymousId
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
//#endregion
|
|
437
|
+
//#region src/index.ts
|
|
438
|
+
const [, , cmd, ...argv] = process.argv;
|
|
439
|
+
const HELP_NOTES = ` Add --json to spawn/prompt/fork/agents/logs for machine-readable output.
|
|
440
|
+
Add --depth <n> to spawn/fork to override the spec's "spawnDepth" — the
|
|
441
|
+
nesting-depth budget for further forks.
|
|
442
|
+
Add --max <n> to spawn/fork to override the spec's "maxAgents" — a separate,
|
|
443
|
+
optional ceiling on total descendants for this lineage (not coordinated
|
|
444
|
+
across sibling branches spawned in parallel).
|
|
445
|
+
Add --spec <path> to prompt to skip the ledger lookup for the spec file
|
|
446
|
+
(needed when the sandbox's own creation event lives in a different ledger,
|
|
447
|
+
e.g. a child spawned via 'alineo fork' from inside another sandbox).`;
|
|
448
|
+
const GROUPS = [{
|
|
449
|
+
key: "sdk",
|
|
450
|
+
label: "SDK — OpenSandbox config and the local spec cache:"
|
|
451
|
+
}, {
|
|
452
|
+
key: "agent",
|
|
453
|
+
label: "Agent — session lifecycle:"
|
|
454
|
+
}];
|
|
455
|
+
function printHelp() {
|
|
456
|
+
console.log(`alineo — alineo agent registry CLI\n`);
|
|
457
|
+
console.log(` alineo Launch the interactive TUI (in a terminal)`);
|
|
458
|
+
console.log(` alineo --version Print the installed version`);
|
|
459
|
+
for (const { key, label } of GROUPS) {
|
|
460
|
+
const groupCommands = commands.filter((c) => c.group === key);
|
|
461
|
+
const width = Math.max(...groupCommands.flatMap((c) => c.variants.map((v) => v.usage.length))) + 2;
|
|
462
|
+
console.log(`\n${label}`);
|
|
463
|
+
for (const c of groupCommands) for (const v of c.variants) console.log(` ${v.usage.padEnd(width)}${v.summary}`);
|
|
464
|
+
}
|
|
465
|
+
console.log(`\n${HELP_NOTES}`);
|
|
466
|
+
}
|
|
467
|
+
async function main() {
|
|
468
|
+
if (!cmd && process.stdout.isTTY) {
|
|
469
|
+
await recordTuiLaunch();
|
|
470
|
+
const { launchTui } = await import("./tui-mkWqwNZl.mjs");
|
|
471
|
+
await launchTui();
|
|
472
|
+
return;
|
|
473
|
+
}
|
|
474
|
+
if (cmd === "--version" || cmd === "-v" || cmd === "version") {
|
|
475
|
+
const { version } = await import("./package-DKqFeJxs.mjs");
|
|
476
|
+
console.log(version);
|
|
477
|
+
return;
|
|
478
|
+
}
|
|
479
|
+
const found = commands.find((c) => c.name === cmd);
|
|
480
|
+
if (found) {
|
|
481
|
+
await withTelemetry(found.name, argv, () => found.run(argv));
|
|
482
|
+
return;
|
|
483
|
+
}
|
|
484
|
+
printHelp();
|
|
485
|
+
if (cmd) process.exit(1);
|
|
486
|
+
}
|
|
487
|
+
main().catch((err) => {
|
|
488
|
+
console.error(`Error: ${err instanceof Error ? err.message : String(err)}`);
|
|
489
|
+
process.exit(1);
|
|
490
|
+
});
|
|
491
|
+
//#endregion
|
|
492
|
+
export { readConfig as a, serverConfigPath as c, configPath as i, serverDataDir as l, readTelemetryConfig as n, serverConfigContent as o, writeTelemetryConfig as r, serverConfigDir as s, envDisabled as t, writeConfig as u };
|
|
@@ -0,0 +1,162 @@
|
|
|
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 os from "os";
|
|
3
|
+
import { existsSync } from "fs";
|
|
4
|
+
import { mkdir } from "fs/promises";
|
|
5
|
+
//#region src/docker.ts
|
|
6
|
+
async function spawn(cmd) {
|
|
7
|
+
let proc;
|
|
8
|
+
try {
|
|
9
|
+
proc = Bun.spawn(cmd, {
|
|
10
|
+
stdout: "pipe",
|
|
11
|
+
stderr: "pipe"
|
|
12
|
+
});
|
|
13
|
+
} catch {
|
|
14
|
+
throw new Error(`'${cmd[0]}' not found — is Docker installed?`);
|
|
15
|
+
}
|
|
16
|
+
const [stdout, stderr, exitCode] = await Promise.all([
|
|
17
|
+
new Response(proc.stdout).text(),
|
|
18
|
+
new Response(proc.stderr).text(),
|
|
19
|
+
proc.exited
|
|
20
|
+
]);
|
|
21
|
+
return {
|
|
22
|
+
ok: exitCode === 0,
|
|
23
|
+
stdout,
|
|
24
|
+
stderr
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
async function checkDocker() {
|
|
28
|
+
const { ok, stderr } = await spawn(["docker", "info"]);
|
|
29
|
+
if (!ok) {
|
|
30
|
+
if (stderr.includes("Cannot connect") || stderr.includes("daemon") || stderr.includes("socket")) throw new Error("Docker daemon is not running. Start Docker and try again.");
|
|
31
|
+
throw new Error("Docker is not available. Install Docker and try again.");
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
async function getContainerState(name) {
|
|
35
|
+
const { ok, stdout } = await spawn([
|
|
36
|
+
"docker",
|
|
37
|
+
"inspect",
|
|
38
|
+
name,
|
|
39
|
+
"--format",
|
|
40
|
+
"{{.State.Status}}"
|
|
41
|
+
]);
|
|
42
|
+
if (!ok) return "missing";
|
|
43
|
+
return stdout.trim() === "running" ? "running" : "stopped";
|
|
44
|
+
}
|
|
45
|
+
async function startContainer(name) {
|
|
46
|
+
const { ok, stderr } = await spawn([
|
|
47
|
+
"docker",
|
|
48
|
+
"start",
|
|
49
|
+
name
|
|
50
|
+
]);
|
|
51
|
+
if (!ok) throw new Error(`Failed to start container '${name}': ${stderr.trim()}`);
|
|
52
|
+
}
|
|
53
|
+
async function runContainer(args) {
|
|
54
|
+
const { ok, stderr } = await spawn([
|
|
55
|
+
"docker",
|
|
56
|
+
"run",
|
|
57
|
+
...args
|
|
58
|
+
]);
|
|
59
|
+
if (!ok) throw new Error(`Failed to start OpenSandbox container: ${stderr.trim()}`);
|
|
60
|
+
}
|
|
61
|
+
async function pollHealth(url, timeoutMs = 6e4) {
|
|
62
|
+
const deadline = Date.now() + timeoutMs;
|
|
63
|
+
while (Date.now() < deadline) {
|
|
64
|
+
try {
|
|
65
|
+
const res = await fetch(url);
|
|
66
|
+
if (res.ok) {
|
|
67
|
+
if ((await res.json()).status === "healthy") return;
|
|
68
|
+
}
|
|
69
|
+
} catch {}
|
|
70
|
+
await new Promise((r) => setTimeout(r, 1e3));
|
|
71
|
+
}
|
|
72
|
+
throw new Error(`OpenSandbox did not become healthy within ${timeoutMs / 1e3}s`);
|
|
73
|
+
}
|
|
74
|
+
//#endregion
|
|
75
|
+
//#region src/commands/init.ts
|
|
76
|
+
const CONTAINER_NAME = "alineo-opensandbox";
|
|
77
|
+
const SERVER_URL = "http://127.0.0.1:8080";
|
|
78
|
+
async function init() {
|
|
79
|
+
console.log("Checking Docker...");
|
|
80
|
+
await checkDocker();
|
|
81
|
+
const state = await getContainerState(CONTAINER_NAME);
|
|
82
|
+
if (state === "running") {
|
|
83
|
+
console.log(`OpenSandbox already running at ${SERVER_URL}`);
|
|
84
|
+
await ensureProjectConfig();
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
if (state === "stopped") {
|
|
88
|
+
console.log("Restarting OpenSandbox container...");
|
|
89
|
+
await startContainer(CONTAINER_NAME);
|
|
90
|
+
} else {
|
|
91
|
+
await ensureServerConfig();
|
|
92
|
+
await ensureServerDataDir();
|
|
93
|
+
console.log("Starting OpenSandbox in Docker...");
|
|
94
|
+
await runContainer([
|
|
95
|
+
"-d",
|
|
96
|
+
"--name",
|
|
97
|
+
CONTAINER_NAME,
|
|
98
|
+
"-p",
|
|
99
|
+
"8080:8080",
|
|
100
|
+
"-v",
|
|
101
|
+
os.platform() === "win32" ? "//./pipe/docker_engine://./pipe/docker_engine" : "/var/run/docker.sock:/var/run/docker.sock",
|
|
102
|
+
"-v",
|
|
103
|
+
`${serverConfigPath()}:/etc/opensandbox/config.toml:ro`,
|
|
104
|
+
"-v",
|
|
105
|
+
`${serverDataDir()}:/data`,
|
|
106
|
+
"-e",
|
|
107
|
+
"SANDBOX_CONFIG_PATH=/etc/opensandbox/config.toml",
|
|
108
|
+
"-e",
|
|
109
|
+
"OPENSANDBOX_INSECURE_SERVER=YES",
|
|
110
|
+
"opensandbox/server:latest"
|
|
111
|
+
]);
|
|
112
|
+
}
|
|
113
|
+
console.log("Waiting for OpenSandbox to be ready...");
|
|
114
|
+
await pollHealth(`${SERVER_URL}/health`);
|
|
115
|
+
await ensureProjectConfig();
|
|
116
|
+
console.log(`OpenSandbox running at ${SERVER_URL} — ready.`);
|
|
117
|
+
}
|
|
118
|
+
async function ensureServerConfig() {
|
|
119
|
+
const dir = serverConfigDir();
|
|
120
|
+
if (!existsSync(dir)) await mkdir(dir, { recursive: true });
|
|
121
|
+
const path = serverConfigPath();
|
|
122
|
+
if (!existsSync(path)) await Bun.write(path, serverConfigContent());
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Host-side half of the `serverDataDir()` bind mount. `docker run -v` would auto-create
|
|
126
|
+
* a missing host path anyway, but doing it explicitly here matches `ensureServerConfig()`'s
|
|
127
|
+
* pattern and keeps directory creation in one place rather than relying on Docker's
|
|
128
|
+
* legacy-`-v`-specific behavior (unlike `--mount`, which requires the source to pre-exist).
|
|
129
|
+
*/
|
|
130
|
+
async function ensureServerDataDir() {
|
|
131
|
+
const dir = serverDataDir();
|
|
132
|
+
if (!existsSync(dir)) await mkdir(dir, { recursive: true });
|
|
133
|
+
}
|
|
134
|
+
async function ensureProjectConfig() {
|
|
135
|
+
if (!existsSync(configPath())) {
|
|
136
|
+
await writeConfig({
|
|
137
|
+
serverUrl: SERVER_URL,
|
|
138
|
+
useServerProxy: true,
|
|
139
|
+
apiKey: "",
|
|
140
|
+
adapterPath: "./.alineo/ledger.db",
|
|
141
|
+
agentsDir: "./agents",
|
|
142
|
+
defaults: { resources: {
|
|
143
|
+
cpu: "1000m",
|
|
144
|
+
memory: "1Gi"
|
|
145
|
+
} }
|
|
146
|
+
});
|
|
147
|
+
console.log("Created alineo.config.json");
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
const initCommand = {
|
|
151
|
+
name: "init",
|
|
152
|
+
group: "sdk",
|
|
153
|
+
variants: [{
|
|
154
|
+
usage: "alineo init",
|
|
155
|
+
summary: "Start OpenSandbox locally via Docker"
|
|
156
|
+
}],
|
|
157
|
+
run: async () => {
|
|
158
|
+
await init();
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
//#endregion
|
|
162
|
+
export { initCommand };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { a as readConfig } from "./index.mjs";
|
|
2
|
+
import { Alineo } from "alineo";
|
|
3
|
+
import { SQLiteAdapter } from "@alineo-labs/sqlite";
|
|
4
|
+
//#region src/commands/kill.ts
|
|
5
|
+
/**
|
|
6
|
+
* Addressed by sandbox ID, not session name — see prompt.ts for why: names
|
|
7
|
+
* aren't unique and a name-based ledger lookup can hand back a sandbox that
|
|
8
|
+
* already died ungracefully. `client.connect()`'s live control-plane check
|
|
9
|
+
* is the actual authority on whether it still exists to kill.
|
|
10
|
+
*/
|
|
11
|
+
async function kill(sandboxId) {
|
|
12
|
+
if (!sandboxId) throw new Error("Usage: alineo kill <sandbox-id>");
|
|
13
|
+
const config = await readConfig();
|
|
14
|
+
const adapter = new SQLiteAdapter(config.adapterPath);
|
|
15
|
+
await (await new Alineo({
|
|
16
|
+
baseUrl: config.serverUrl,
|
|
17
|
+
apiKey: config.apiKey,
|
|
18
|
+
adapter,
|
|
19
|
+
useServerProxy: config.useServerProxy
|
|
20
|
+
}).connect(sandboxId, sandboxId)).close();
|
|
21
|
+
console.log(`Killed sandbox ${sandboxId}`);
|
|
22
|
+
}
|
|
23
|
+
const killCommand = {
|
|
24
|
+
name: "kill",
|
|
25
|
+
group: "agent",
|
|
26
|
+
variants: [{
|
|
27
|
+
usage: "alineo kill <sandbox-id>",
|
|
28
|
+
summary: "Stop a sandbox"
|
|
29
|
+
}],
|
|
30
|
+
run: async (argv) => {
|
|
31
|
+
await kill(argv[0] ?? "");
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
//#endregion
|
|
35
|
+
export { killCommand };
|