alineo-cli 0.2.1 → 0.4.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 +16 -16
- package/dist/{add-CmdLjuq_.mjs → add-BdM-DRC1.mjs} +2 -2
- package/dist/{agents-CEVMF8rH.mjs → agents-CC5ZirAu.mjs} +2 -2
- package/dist/index.mjs +1739 -76
- package/dist/init-Caryb0xG.mjs +18 -0
- package/dist/{list-DKxmgyNL.mjs → list-D0m4Llsl.mjs} +4 -4
- package/dist/{logs-D-DUd5Ux.mjs → logs-CaLt2Ya0.mjs} +1 -1
- package/dist/{package-OB-YNuQk.mjs → package-Bp80ZVLp.mjs} +1 -1
- package/dist/{prompt-CSu1QDCA.mjs → prompt-DBQLJudG.mjs} +3 -3
- package/dist/{remove-Dsp071zF.mjs → remove-B_721tl2.mjs} +1 -1
- package/dist/{sessions-data-SEZBa4Uk.mjs → sessions-data-CceSi5Jz.mjs} +2 -2
- package/dist/{fork-CAtxcuwS.mjs → spawn-_Q1KNp_T.mjs} +22 -22
- package/dist/{spawn-Dd8Y0OXB.mjs → start-Ba4NiDWn.mjs} +15 -15
- package/dist/{steer-BdQ_-sf2.mjs → steer-NAX3xw09.mjs} +5 -5
- package/dist/{kill-D1vvRxxn.mjs → stop-CvyZQHIf.mjs} +11 -11
- package/dist/{tui-C7Vonahr.mjs → tui-sV-uyFWI.mjs} +10 -10
- package/package.json +9 -6
- package/pi-extension/alineo.ts +41 -40
- package/dist/init-D6RgxqQQ.mjs +0 -265
package/dist/index.mjs
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
|
-
import {
|
|
2
|
+
import { installLoggerFromEnv } from "@alineo-labs/logger";
|
|
3
|
+
import { dirname, join, resolve } from "node:path";
|
|
3
4
|
import { join as join$1 } from "path";
|
|
4
5
|
import { homedir } from "os";
|
|
5
6
|
import { existsSync } from "fs";
|
|
6
7
|
import { mkdir } from "fs/promises";
|
|
8
|
+
import { existsSync as existsSync$1, readFileSync } from "node:fs";
|
|
9
|
+
import { homedir as homedir$1 } from "node:os";
|
|
10
|
+
import * as z$1 from "zod";
|
|
11
|
+
import { z } from "zod";
|
|
7
12
|
//#region src/commands/registry.ts
|
|
8
13
|
/**
|
|
9
14
|
* Every alineo subcommand's name/group/usage/summary, plus a `run` that dynamically
|
|
@@ -18,7 +23,10 @@ import { mkdir } from "fs/promises";
|
|
|
18
23
|
* the switch statement's actual behavior with no visual signal at all.
|
|
19
24
|
*
|
|
20
25
|
* 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.
|
|
26
|
+
* types.ts), then add one entry here whose `variants` matches it. The name has to
|
|
27
|
+
* be a verb from `@alineo-labs/schema`'s `VERBS`, or one of the nouns
|
|
28
|
+
* `scripts/check-vocabulary.ts` allowlists — that check is what keeps this list
|
|
29
|
+
* and the rest of alineo's surfaces speaking the same language.
|
|
22
30
|
*/
|
|
23
31
|
const commands = [
|
|
24
32
|
{
|
|
@@ -28,7 +36,7 @@ const commands = [
|
|
|
28
36
|
usage: "alineo init",
|
|
29
37
|
summary: "Start OpenSandbox locally via Docker"
|
|
30
38
|
}],
|
|
31
|
-
run: async (argv) => (await import("./init-
|
|
39
|
+
run: async (argv) => (await import("./init-Caryb0xG.mjs")).initCommand.run(argv)
|
|
32
40
|
},
|
|
33
41
|
{
|
|
34
42
|
name: "add",
|
|
@@ -37,7 +45,7 @@ const commands = [
|
|
|
37
45
|
usage: "alineo add <url> [--name <n>]",
|
|
38
46
|
summary: "Fetch and save an agent spec locally"
|
|
39
47
|
}],
|
|
40
|
-
run: async (argv) => (await import("./add-
|
|
48
|
+
run: async (argv) => (await import("./add-BdM-DRC1.mjs")).addCommand.run(argv)
|
|
41
49
|
},
|
|
42
50
|
{
|
|
43
51
|
name: "list",
|
|
@@ -46,7 +54,7 @@ const commands = [
|
|
|
46
54
|
usage: "alineo list",
|
|
47
55
|
summary: "List saved agent specs"
|
|
48
56
|
}],
|
|
49
|
-
run: async (argv) => (await import("./list-
|
|
57
|
+
run: async (argv) => (await import("./list-D0m4Llsl.mjs")).listCommand.run(argv)
|
|
50
58
|
},
|
|
51
59
|
{
|
|
52
60
|
name: "remove",
|
|
@@ -55,19 +63,19 @@ const commands = [
|
|
|
55
63
|
usage: "alineo remove <name>",
|
|
56
64
|
summary: "Remove a saved agent spec"
|
|
57
65
|
}],
|
|
58
|
-
run: async (argv) => (await import("./remove-
|
|
66
|
+
run: async (argv) => (await import("./remove-B_721tl2.mjs")).removeCommand.run(argv)
|
|
59
67
|
},
|
|
60
68
|
{
|
|
61
|
-
name: "
|
|
69
|
+
name: "start",
|
|
62
70
|
group: "agent",
|
|
63
71
|
variants: [{
|
|
64
|
-
usage: "alineo
|
|
72
|
+
usage: "alineo start <spec>",
|
|
65
73
|
summary: "Start a fresh agent sandbox, print its name, exit"
|
|
66
74
|
}, {
|
|
67
|
-
usage: "alineo
|
|
75
|
+
usage: "alineo start <spec> --prompt <msg>",
|
|
68
76
|
summary: "Start it, send one prompt, print the reply, exit"
|
|
69
77
|
}],
|
|
70
|
-
run: async (argv) => (await import("./
|
|
78
|
+
run: async (argv) => (await import("./start-Ba4NiDWn.mjs")).startCommand.run(argv)
|
|
71
79
|
},
|
|
72
80
|
{
|
|
73
81
|
name: "prompt",
|
|
@@ -76,16 +84,16 @@ const commands = [
|
|
|
76
84
|
usage: "alineo prompt <sandbox-id> <msg>",
|
|
77
85
|
summary: "Send one prompt to a running sandbox, print the reply"
|
|
78
86
|
}],
|
|
79
|
-
run: async (argv) => (await import("./prompt-
|
|
87
|
+
run: async (argv) => (await import("./prompt-DBQLJudG.mjs")).promptCommand.run(argv)
|
|
80
88
|
},
|
|
81
89
|
{
|
|
82
|
-
name: "
|
|
90
|
+
name: "spawn",
|
|
83
91
|
group: "agent",
|
|
84
92
|
variants: [{
|
|
85
|
-
usage: "alineo
|
|
86
|
-
summary: "
|
|
93
|
+
usage: "alineo spawn <parent> <child-spec>",
|
|
94
|
+
summary: "Spawn a child from a running session's own live sandbox"
|
|
87
95
|
}],
|
|
88
|
-
run: async (argv) => (await import("./
|
|
96
|
+
run: async (argv) => (await import("./spawn-_Q1KNp_T.mjs")).spawnCommand.run(argv)
|
|
89
97
|
},
|
|
90
98
|
{
|
|
91
99
|
name: "steer",
|
|
@@ -94,7 +102,7 @@ const commands = [
|
|
|
94
102
|
usage: "alineo steer <sandbox-id> <message>",
|
|
95
103
|
summary: "Redirect a running session — lands at its next turn boundary, not instantly"
|
|
96
104
|
}],
|
|
97
|
-
run: async (argv) => (await import("./steer-
|
|
105
|
+
run: async (argv) => (await import("./steer-NAX3xw09.mjs")).steerCommand.run(argv)
|
|
98
106
|
},
|
|
99
107
|
{
|
|
100
108
|
name: "agents",
|
|
@@ -103,16 +111,16 @@ const commands = [
|
|
|
103
111
|
usage: "alineo agents [--json]",
|
|
104
112
|
summary: "List running agent sessions"
|
|
105
113
|
}],
|
|
106
|
-
run: async (argv) => (await import("./agents-
|
|
114
|
+
run: async (argv) => (await import("./agents-CC5ZirAu.mjs")).agentsCommand.run(argv)
|
|
107
115
|
},
|
|
108
116
|
{
|
|
109
|
-
name: "
|
|
117
|
+
name: "stop",
|
|
110
118
|
group: "agent",
|
|
111
119
|
variants: [{
|
|
112
|
-
usage: "alineo
|
|
120
|
+
usage: "alineo stop <sandbox-id>",
|
|
113
121
|
summary: "Stop a sandbox"
|
|
114
122
|
}],
|
|
115
|
-
run: async (argv) => (await import("./
|
|
123
|
+
run: async (argv) => (await import("./stop-CvyZQHIf.mjs")).stopCommand.run(argv)
|
|
116
124
|
},
|
|
117
125
|
{
|
|
118
126
|
name: "logs",
|
|
@@ -121,7 +129,7 @@ const commands = [
|
|
|
121
129
|
usage: "alineo logs <name> [--json]",
|
|
122
130
|
summary: "Print ledger events for a session"
|
|
123
131
|
}],
|
|
124
|
-
run: async (argv) => (await import("./logs-
|
|
132
|
+
run: async (argv) => (await import("./logs-CaLt2Ya0.mjs")).logsCommand.run(argv)
|
|
125
133
|
},
|
|
126
134
|
{
|
|
127
135
|
name: "telemetry",
|
|
@@ -144,55 +152,1381 @@ const commands = [
|
|
|
144
152
|
}
|
|
145
153
|
];
|
|
146
154
|
//#endregion
|
|
147
|
-
//#region
|
|
155
|
+
//#region ../schema/dist/agent-spec-iZ9p1pjI.mjs
|
|
156
|
+
/**
|
|
157
|
+
* The two lists every alineo surface derives its names from.
|
|
158
|
+
*
|
|
159
|
+
* One user meets the CLI, the SDK, the daemon's HTTP API, the MCP tools and the event
|
|
160
|
+
* stream. Each of those is free to pick its own spelling, and historically each did — which
|
|
161
|
+
* is how `spawn` came to mean "create a root agent" in the CLI and "create a child" in the
|
|
162
|
+
* SDK, and how `fork` came to mean three different operations.
|
|
163
|
+
*
|
|
164
|
+
* Making the vocabulary *data* is what lets CI fail a name rather than a reviewer catch it.
|
|
165
|
+
* The checks that consume these lists land with the surfaces they police (CLI and help
|
|
166
|
+
* strings, MCP tools and HTTP routes, event types); this module is only the source of truth.
|
|
167
|
+
*/
|
|
168
|
+
/**
|
|
169
|
+
* The things alineo acts on. A name's first segment is one of these.
|
|
170
|
+
*
|
|
171
|
+
* Ordered by layer rather than alphabetically — control plane, then the agent loop, then the
|
|
172
|
+
* substrate, then the operator-facing objects — because that is how the surfaces group.
|
|
173
|
+
*
|
|
174
|
+
* `event`, `result` and `transcript` are the records a run leaves behind. They joined the list
|
|
175
|
+
* when the HTTP and MCP checks landed and found them already on the wire
|
|
176
|
+
* (`GET /agents/:id/transcript`, `GET /runs/:id/events`): they were vocabulary in use, just not
|
|
177
|
+
* written down.
|
|
178
|
+
*
|
|
179
|
+
* `memory` and `fact` joined with alineod's memory routes (`GET /agents/:id/memory`,
|
|
180
|
+
* `POST /agents/:id/facts`): `memory` is an agent's durable working memory, `fact` one item of
|
|
181
|
+
* its semantic memory.
|
|
182
|
+
*/
|
|
183
|
+
const SUBJECTS = [
|
|
184
|
+
"run",
|
|
185
|
+
"agent",
|
|
186
|
+
"sandbox",
|
|
187
|
+
"session",
|
|
188
|
+
"turn",
|
|
189
|
+
"message",
|
|
190
|
+
"tool",
|
|
191
|
+
"handle",
|
|
192
|
+
"wait",
|
|
193
|
+
"inbox",
|
|
194
|
+
"notify",
|
|
195
|
+
"budget",
|
|
196
|
+
"exec",
|
|
197
|
+
"egress",
|
|
198
|
+
"credential",
|
|
199
|
+
"permission",
|
|
200
|
+
"workflow",
|
|
201
|
+
"step",
|
|
202
|
+
"compaction",
|
|
203
|
+
"retry",
|
|
204
|
+
"extension",
|
|
205
|
+
"queue",
|
|
206
|
+
"spec",
|
|
207
|
+
"environment",
|
|
208
|
+
"event",
|
|
209
|
+
"result",
|
|
210
|
+
"transcript",
|
|
211
|
+
"memory",
|
|
212
|
+
"fact"
|
|
213
|
+
];
|
|
214
|
+
/**
|
|
215
|
+
* What alineo does to a subject. A name's second segment is one of these — in the imperative
|
|
216
|
+
* for a command, method, route or tool, and in the past tense for an event (`agent.spawned`).
|
|
217
|
+
*
|
|
218
|
+
* `branchSession` and `duplicateSession` are camelCase because they exist only as SDK
|
|
219
|
+
* methods; no route, tool or event uses them. They carry `Session` in the name on purpose:
|
|
220
|
+
* unqualified `branch`/`duplicate` read like sandbox operations, and they are not — both stay
|
|
221
|
+
* inside one container and only touch the harness conversation.
|
|
222
|
+
*/
|
|
223
|
+
const VERBS = [
|
|
224
|
+
"start",
|
|
225
|
+
"spawn",
|
|
226
|
+
"stop",
|
|
227
|
+
"pause",
|
|
228
|
+
"resume",
|
|
229
|
+
"reattach",
|
|
230
|
+
"attach",
|
|
231
|
+
"prompt",
|
|
232
|
+
"steer",
|
|
233
|
+
"await",
|
|
234
|
+
"checkpoint",
|
|
235
|
+
"fork",
|
|
236
|
+
"branchSession",
|
|
237
|
+
"duplicateSession",
|
|
238
|
+
"add",
|
|
239
|
+
"list",
|
|
240
|
+
"remove",
|
|
241
|
+
"get",
|
|
242
|
+
"watch",
|
|
243
|
+
"init",
|
|
244
|
+
"deliver"
|
|
245
|
+
];
|
|
246
|
+
const SUBJECT_SET = new Set(SUBJECTS);
|
|
247
|
+
new Set(VERBS);
|
|
248
|
+
function isSubject(value) {
|
|
249
|
+
return SUBJECT_SET.has(value);
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Every definition, by type. Populated as a side effect of `defineEvent`, which is why the
|
|
253
|
+
* event files must be imported for the registry to be complete — `index.ts` imports all five.
|
|
254
|
+
*/
|
|
255
|
+
const registry = /* @__PURE__ */ new Map();
|
|
256
|
+
/** A `type` that is well-formed but whose subject is not in `SUBJECTS`. */
|
|
257
|
+
const TYPE_SHAPE = /^([a-z]+)\.([a-z][a-z_]*)$/;
|
|
258
|
+
function defineEvent(definition) {
|
|
259
|
+
const match = TYPE_SHAPE.exec(definition.type);
|
|
260
|
+
if (!match) throw new Error(`Event type "${definition.type}" is not "<subject>.<past_tense_verb>" in lower snake case.`);
|
|
261
|
+
if (!isSubject(match[1])) throw new Error(`Event type "${definition.type}" has subject "${match[1]}", which is not in SUBJECTS. Add it to @alineo-labs/schema's vocabulary, or name the event after a subject that is already there.`);
|
|
262
|
+
const existing = registry.get(definition.type);
|
|
263
|
+
if (existing && existing !== definition) throw new Error(`Event type "${definition.type}" is defined twice.`);
|
|
264
|
+
registry.set(definition.type, definition);
|
|
265
|
+
return definition;
|
|
266
|
+
}
|
|
267
|
+
defineEvent({
|
|
268
|
+
type: "sandbox.created",
|
|
269
|
+
durable: true,
|
|
270
|
+
version: 1,
|
|
271
|
+
description: "A sandbox reached Running state.",
|
|
272
|
+
schema: z.object({
|
|
273
|
+
sandboxId: z.string(),
|
|
274
|
+
name: z.string(),
|
|
275
|
+
runId: z.string(),
|
|
276
|
+
resourceId: z.string().optional(),
|
|
277
|
+
teamId: z.string().optional(),
|
|
278
|
+
/** Set when this session came from `sb.fork()`; absent for a top-level `client.sandbox()`. */
|
|
279
|
+
parentSandboxId: z.string().optional()
|
|
280
|
+
})
|
|
281
|
+
});
|
|
282
|
+
defineEvent({
|
|
283
|
+
type: "sandbox.closed",
|
|
284
|
+
durable: true,
|
|
285
|
+
version: 1,
|
|
286
|
+
description: "A sandbox was closed and its container released.",
|
|
287
|
+
schema: z.object({ sandboxId: z.string() })
|
|
288
|
+
});
|
|
289
|
+
defineEvent({
|
|
290
|
+
type: "sandbox.paused",
|
|
291
|
+
durable: true,
|
|
292
|
+
version: 1,
|
|
293
|
+
description: "pause() froze the container.",
|
|
294
|
+
schema: z.object({ sandboxId: z.string() })
|
|
295
|
+
});
|
|
296
|
+
defineEvent({
|
|
297
|
+
type: "sandbox.resumed",
|
|
298
|
+
durable: true,
|
|
299
|
+
version: 1,
|
|
300
|
+
description: "resume() restored a frozen container to Running.",
|
|
301
|
+
schema: z.object({ sandboxId: z.string() })
|
|
302
|
+
});
|
|
303
|
+
defineEvent({
|
|
304
|
+
type: "sandbox.checkpoint_created",
|
|
305
|
+
durable: true,
|
|
306
|
+
version: 1,
|
|
307
|
+
description: "checkpoint() captured a snapshot.",
|
|
308
|
+
schema: z.object({
|
|
309
|
+
snapshotId: z.string(),
|
|
310
|
+
tag: z.string().optional()
|
|
311
|
+
})
|
|
312
|
+
});
|
|
313
|
+
defineEvent({
|
|
314
|
+
type: "exec.started",
|
|
315
|
+
durable: true,
|
|
316
|
+
version: 1,
|
|
317
|
+
description: "An exec() or execCode() call began.",
|
|
318
|
+
schema: z.object({
|
|
319
|
+
command: z.string().optional(),
|
|
320
|
+
code: z.string().optional()
|
|
321
|
+
})
|
|
322
|
+
});
|
|
323
|
+
defineEvent({
|
|
324
|
+
type: "exec.output",
|
|
325
|
+
durable: false,
|
|
326
|
+
version: 1,
|
|
327
|
+
description: "A streaming output chunk from a running exec.",
|
|
328
|
+
schema: z.object({
|
|
329
|
+
stream: z.enum(["stdout", "stderr"]).optional(),
|
|
330
|
+
text: z.string()
|
|
331
|
+
})
|
|
332
|
+
});
|
|
333
|
+
defineEvent({
|
|
334
|
+
type: "exec.completed",
|
|
335
|
+
durable: true,
|
|
336
|
+
version: 1,
|
|
337
|
+
description: "An exec() or execCode() call finished.",
|
|
338
|
+
schema: z.object({
|
|
339
|
+
exitCode: z.number().int().optional(),
|
|
340
|
+
stdout: z.string().optional(),
|
|
341
|
+
stderr: z.string().optional()
|
|
342
|
+
})
|
|
343
|
+
});
|
|
344
|
+
defineEvent({
|
|
345
|
+
type: "egress.rule_added",
|
|
346
|
+
durable: true,
|
|
347
|
+
version: 1,
|
|
348
|
+
description: "sb.egress.patch() — the exact rules handed to the sidecar, so a resume can fold a still-wanted allowance back into the new boot policy.",
|
|
349
|
+
schema: z.object({ rules: z.array(z.unknown()) })
|
|
350
|
+
});
|
|
351
|
+
defineEvent({
|
|
352
|
+
type: "egress.rule_removed",
|
|
353
|
+
durable: true,
|
|
354
|
+
version: 1,
|
|
355
|
+
description: "sb.egress.delete().",
|
|
356
|
+
schema: z.object({ targets: z.array(z.string()) })
|
|
357
|
+
});
|
|
358
|
+
defineEvent({
|
|
359
|
+
type: "credential.bound",
|
|
360
|
+
durable: true,
|
|
361
|
+
version: 1,
|
|
362
|
+
description: "sb.credentials.set()/.patch(). Binding metadata only — the credential value is never written to the ledger.",
|
|
363
|
+
schema: z.object({
|
|
364
|
+
name: z.string(),
|
|
365
|
+
host: z.string().optional(),
|
|
366
|
+
injection: z.string().optional()
|
|
367
|
+
})
|
|
368
|
+
});
|
|
369
|
+
defineEvent({
|
|
370
|
+
type: "credential.revoked",
|
|
371
|
+
durable: true,
|
|
372
|
+
version: 1,
|
|
373
|
+
description: "sb.credentials.remove().",
|
|
374
|
+
schema: z.object({ name: z.string() })
|
|
375
|
+
});
|
|
376
|
+
defineEvent({
|
|
377
|
+
type: "permission.requested",
|
|
378
|
+
durable: true,
|
|
379
|
+
version: 1,
|
|
380
|
+
description: "The permission gate paused a tool call for human approval. Metadata only — raw tool arguments can carry secrets in a bash command or a file write, and are never recorded.",
|
|
381
|
+
schema: z.object({
|
|
382
|
+
requestId: z.string(),
|
|
383
|
+
tool: z.string(),
|
|
384
|
+
target: z.string(),
|
|
385
|
+
title: z.string().optional()
|
|
386
|
+
})
|
|
387
|
+
});
|
|
388
|
+
defineEvent({
|
|
389
|
+
type: "permission.resolved",
|
|
390
|
+
durable: true,
|
|
391
|
+
version: 1,
|
|
392
|
+
description: "A permission request was answered — by a caller, a batched always/reject decision, a timeout, or a session resume dropping it.",
|
|
393
|
+
schema: z.object({
|
|
394
|
+
requestId: z.string(),
|
|
395
|
+
decision: z.string()
|
|
396
|
+
})
|
|
397
|
+
});
|
|
398
|
+
defineEvent({
|
|
399
|
+
type: "agent.checkpointed",
|
|
400
|
+
durable: true,
|
|
401
|
+
version: 1,
|
|
402
|
+
description: "A turn-level checkpoint (workspace + session-file tarball) was captured and durably stored, after the tarball itself was confirmed written — a snapshot with no event pointing at it is unreachable garbage.",
|
|
403
|
+
schema: z.object({
|
|
404
|
+
turn: z.number(),
|
|
405
|
+
snapshotRef: z.string()
|
|
406
|
+
})
|
|
407
|
+
});
|
|
408
|
+
defineEvent({
|
|
409
|
+
type: "session.started",
|
|
410
|
+
durable: true,
|
|
411
|
+
version: 1,
|
|
412
|
+
description: "The harness began a session. Was `agent_start`.",
|
|
413
|
+
schema: z.object({})
|
|
414
|
+
});
|
|
415
|
+
defineEvent({
|
|
416
|
+
type: "session.ended",
|
|
417
|
+
durable: true,
|
|
418
|
+
version: 1,
|
|
419
|
+
description: "The harness session finished. Was `agent_end`.",
|
|
420
|
+
schema: z.object({ messages: z.array(z.unknown()).optional() })
|
|
421
|
+
});
|
|
422
|
+
defineEvent({
|
|
423
|
+
type: "turn.started",
|
|
424
|
+
durable: true,
|
|
425
|
+
version: 1,
|
|
426
|
+
schema: z.object({
|
|
427
|
+
turnIndex: z.number().int(),
|
|
428
|
+
timestamp: z.number()
|
|
429
|
+
})
|
|
430
|
+
});
|
|
431
|
+
defineEvent({
|
|
432
|
+
type: "turn.ended",
|
|
433
|
+
durable: true,
|
|
434
|
+
version: 1,
|
|
435
|
+
schema: z.object({
|
|
436
|
+
turnIndex: z.number().int(),
|
|
437
|
+
message: z.unknown().optional(),
|
|
438
|
+
toolResults: z.array(z.unknown()).optional()
|
|
439
|
+
})
|
|
440
|
+
});
|
|
441
|
+
defineEvent({
|
|
442
|
+
type: "tool.started",
|
|
443
|
+
durable: true,
|
|
444
|
+
version: 1,
|
|
445
|
+
schema: z.object({
|
|
446
|
+
toolCallId: z.string(),
|
|
447
|
+
toolName: z.string(),
|
|
448
|
+
args: z.unknown()
|
|
449
|
+
})
|
|
450
|
+
});
|
|
451
|
+
defineEvent({
|
|
452
|
+
type: "tool.updated",
|
|
453
|
+
durable: false,
|
|
454
|
+
version: 1,
|
|
455
|
+
description: "A partial tool result. Superseded by `tool.ended`.",
|
|
456
|
+
schema: z.object({
|
|
457
|
+
toolCallId: z.string(),
|
|
458
|
+
toolName: z.string(),
|
|
459
|
+
partialResult: z.unknown()
|
|
460
|
+
})
|
|
461
|
+
});
|
|
462
|
+
defineEvent({
|
|
463
|
+
type: "tool.ended",
|
|
464
|
+
durable: true,
|
|
465
|
+
version: 1,
|
|
466
|
+
schema: z.object({
|
|
467
|
+
toolCallId: z.string(),
|
|
468
|
+
toolName: z.string(),
|
|
469
|
+
result: z.unknown(),
|
|
470
|
+
isError: z.boolean()
|
|
471
|
+
})
|
|
472
|
+
});
|
|
473
|
+
defineEvent({
|
|
474
|
+
type: "message.started",
|
|
475
|
+
durable: false,
|
|
476
|
+
version: 1,
|
|
477
|
+
schema: z.object({ message: z.unknown() })
|
|
478
|
+
});
|
|
479
|
+
defineEvent({
|
|
480
|
+
type: "message.updated",
|
|
481
|
+
durable: false,
|
|
482
|
+
version: 1,
|
|
483
|
+
description: "A delta on the message being written — including a plain text chunk, which was its own `text` event before. Superseded by `message.ended`.",
|
|
484
|
+
schema: z.object({
|
|
485
|
+
message: z.unknown().optional(),
|
|
486
|
+
delta: z.unknown().optional(),
|
|
487
|
+
/** Set when the delta is plain text and nothing else. */
|
|
488
|
+
text: z.string().optional()
|
|
489
|
+
})
|
|
490
|
+
});
|
|
491
|
+
defineEvent({
|
|
492
|
+
type: "message.ended",
|
|
493
|
+
durable: false,
|
|
494
|
+
version: 1,
|
|
495
|
+
schema: z.object({ message: z.unknown() })
|
|
496
|
+
});
|
|
497
|
+
defineEvent({
|
|
498
|
+
type: "compaction.started",
|
|
499
|
+
durable: true,
|
|
500
|
+
version: 1,
|
|
501
|
+
schema: z.object({ reason: z.enum([
|
|
502
|
+
"manual",
|
|
503
|
+
"threshold",
|
|
504
|
+
"overflow"
|
|
505
|
+
]) })
|
|
506
|
+
});
|
|
507
|
+
defineEvent({
|
|
508
|
+
type: "compaction.ended",
|
|
509
|
+
durable: true,
|
|
510
|
+
version: 1,
|
|
511
|
+
schema: z.object({
|
|
512
|
+
reason: z.enum([
|
|
513
|
+
"manual",
|
|
514
|
+
"threshold",
|
|
515
|
+
"overflow"
|
|
516
|
+
]),
|
|
517
|
+
result: z.object({
|
|
518
|
+
summary: z.string(),
|
|
519
|
+
firstKeptEntryId: z.string(),
|
|
520
|
+
tokensBefore: z.number(),
|
|
521
|
+
estimatedTokensAfter: z.number(),
|
|
522
|
+
details: z.unknown()
|
|
523
|
+
}).nullable(),
|
|
524
|
+
aborted: z.boolean(),
|
|
525
|
+
willRetry: z.boolean()
|
|
526
|
+
})
|
|
527
|
+
});
|
|
528
|
+
defineEvent({
|
|
529
|
+
type: "retry.started",
|
|
530
|
+
durable: true,
|
|
531
|
+
version: 1,
|
|
532
|
+
description: "The harness is retrying a failed model call. Was `auto_retry_start`.",
|
|
533
|
+
schema: z.object({
|
|
534
|
+
attempt: z.number().int(),
|
|
535
|
+
maxAttempts: z.number().int(),
|
|
536
|
+
delayMs: z.number(),
|
|
537
|
+
errorMessage: z.string()
|
|
538
|
+
})
|
|
539
|
+
});
|
|
540
|
+
defineEvent({
|
|
541
|
+
type: "retry.ended",
|
|
542
|
+
durable: true,
|
|
543
|
+
version: 1,
|
|
544
|
+
schema: z.object({
|
|
545
|
+
success: z.boolean(),
|
|
546
|
+
attempt: z.number().int(),
|
|
547
|
+
finalError: z.string().optional()
|
|
548
|
+
})
|
|
549
|
+
});
|
|
550
|
+
defineEvent({
|
|
551
|
+
type: "queue.updated",
|
|
552
|
+
durable: false,
|
|
553
|
+
version: 1,
|
|
554
|
+
description: "The steering and follow-up queues changed. A view of current state, not a fact.",
|
|
555
|
+
schema: z.object({
|
|
556
|
+
steering: z.array(z.string()),
|
|
557
|
+
followUp: z.array(z.string())
|
|
558
|
+
})
|
|
559
|
+
});
|
|
560
|
+
defineEvent({
|
|
561
|
+
type: "extension.ui",
|
|
562
|
+
durable: false,
|
|
563
|
+
version: 1,
|
|
564
|
+
description: "An extension asked the host to show something.",
|
|
565
|
+
schema: z.object({
|
|
566
|
+
method: z.string(),
|
|
567
|
+
params: z.unknown(),
|
|
568
|
+
isDialog: z.boolean(),
|
|
569
|
+
requestId: z.string().optional()
|
|
570
|
+
})
|
|
571
|
+
});
|
|
572
|
+
defineEvent({
|
|
573
|
+
type: "extension.error",
|
|
574
|
+
durable: true,
|
|
575
|
+
version: 1,
|
|
576
|
+
schema: z.object({
|
|
577
|
+
extensionPath: z.string(),
|
|
578
|
+
event: z.string(),
|
|
579
|
+
error: z.string()
|
|
580
|
+
})
|
|
581
|
+
});
|
|
582
|
+
defineEvent({
|
|
583
|
+
type: "workflow.started",
|
|
584
|
+
durable: true,
|
|
585
|
+
version: 1,
|
|
586
|
+
description: "A workflow run began, before any step executed. Was `run_started`.",
|
|
587
|
+
schema: z.object({ runId: z.string().optional() })
|
|
588
|
+
});
|
|
589
|
+
defineEvent({
|
|
590
|
+
type: "workflow.completed",
|
|
591
|
+
durable: true,
|
|
592
|
+
version: 1,
|
|
593
|
+
description: "Every step finished without error.",
|
|
594
|
+
schema: z.object({})
|
|
595
|
+
});
|
|
596
|
+
defineEvent({
|
|
597
|
+
type: "workflow.failed",
|
|
598
|
+
durable: true,
|
|
599
|
+
version: 1,
|
|
600
|
+
description: "Rollback completed after a step failure.",
|
|
601
|
+
schema: z.object({ error: z.string().optional() })
|
|
602
|
+
});
|
|
603
|
+
defineEvent({
|
|
604
|
+
type: "step.started",
|
|
605
|
+
durable: true,
|
|
606
|
+
version: 1,
|
|
607
|
+
schema: z.object({ name: z.string().optional() })
|
|
608
|
+
});
|
|
609
|
+
defineEvent({
|
|
610
|
+
type: "step.completed",
|
|
611
|
+
durable: true,
|
|
612
|
+
version: 1,
|
|
613
|
+
schema: z.object({ output: z.unknown().optional() })
|
|
614
|
+
});
|
|
615
|
+
defineEvent({
|
|
616
|
+
type: "step.failed",
|
|
617
|
+
durable: true,
|
|
618
|
+
version: 1,
|
|
619
|
+
schema: z.object({ error: z.string().optional() })
|
|
620
|
+
});
|
|
621
|
+
defineEvent({
|
|
622
|
+
type: "step.rolled_back",
|
|
623
|
+
durable: true,
|
|
624
|
+
version: 1,
|
|
625
|
+
description: "A step's rollback handler completed during saga compensation.",
|
|
626
|
+
schema: z.object({})
|
|
627
|
+
});
|
|
628
|
+
const WaitMode = z.enum([
|
|
629
|
+
"all",
|
|
630
|
+
"any",
|
|
631
|
+
"quorum"
|
|
632
|
+
]);
|
|
633
|
+
defineEvent({
|
|
634
|
+
type: "run.started",
|
|
635
|
+
durable: true,
|
|
636
|
+
version: 1,
|
|
637
|
+
description: "A swarm run was created. Was `run_started` — the name workflow also used.",
|
|
638
|
+
schema: z.object({
|
|
639
|
+
runId: z.string(),
|
|
640
|
+
closeWhen: z.enum(["explicit", "quiescent"]).default("explicit")
|
|
641
|
+
})
|
|
642
|
+
});
|
|
643
|
+
defineEvent({
|
|
644
|
+
type: "run.closed",
|
|
645
|
+
durable: true,
|
|
646
|
+
version: 1,
|
|
647
|
+
description: "The run finalized — a client deleted it (`explicit`), or it reached quiescence on its own under closeWhen: \"quiescent\". Resources are released; the ledger is kept.",
|
|
648
|
+
schema: z.object({
|
|
649
|
+
agentId: z.string().nullable(),
|
|
650
|
+
reason: z.enum(["explicit", "quiescent"])
|
|
651
|
+
})
|
|
652
|
+
});
|
|
653
|
+
defineEvent({
|
|
654
|
+
type: "run.quiescent",
|
|
655
|
+
durable: true,
|
|
656
|
+
version: 1,
|
|
657
|
+
description: "The subtree rooted at this agent went quiescent. Only tracked while someone is awaiting it. Was `subtree_quiescent`.",
|
|
658
|
+
schema: z.object({
|
|
659
|
+
agentId: z.string().nullable(),
|
|
660
|
+
memberCount: z.number().int(),
|
|
661
|
+
asOf: z.number()
|
|
662
|
+
})
|
|
663
|
+
});
|
|
664
|
+
defineEvent({
|
|
665
|
+
type: "agent.spawned",
|
|
666
|
+
durable: true,
|
|
667
|
+
version: 1,
|
|
668
|
+
schema: z.object({
|
|
669
|
+
agentId: z.string().nullable(),
|
|
670
|
+
parentAgentId: z.string().nullable(),
|
|
671
|
+
runId: z.string(),
|
|
672
|
+
specName: z.string(),
|
|
673
|
+
depth: z.number().int(),
|
|
674
|
+
spawnIndex: z.number().int(),
|
|
675
|
+
sandboxId: z.string().nullable(),
|
|
676
|
+
waitFor: z.array(z.string()).nullable().optional().describe("Persisted rather than left in the spec, so rehydrate() can retry a still-pending spawn instead of losing it."),
|
|
677
|
+
prompt: z.string().nullable().optional()
|
|
678
|
+
})
|
|
679
|
+
});
|
|
680
|
+
defineEvent({
|
|
681
|
+
type: "agent.provisioned",
|
|
682
|
+
durable: true,
|
|
683
|
+
version: 1,
|
|
684
|
+
description: "The sandbox exists and the bridge is up — backfills what `agent.spawned` could not know yet.",
|
|
685
|
+
schema: z.object({
|
|
686
|
+
agentId: z.string().nullable(),
|
|
687
|
+
sandboxId: z.string()
|
|
688
|
+
})
|
|
689
|
+
});
|
|
690
|
+
defineEvent({
|
|
691
|
+
type: "agent.state_changed",
|
|
692
|
+
durable: true,
|
|
693
|
+
version: 1,
|
|
694
|
+
schema: z.object({
|
|
695
|
+
agentId: z.string().nullable(),
|
|
696
|
+
from: z.string(),
|
|
697
|
+
to: z.string(),
|
|
698
|
+
reason: z.string().optional(),
|
|
699
|
+
pausedBy: z.enum(["operator", "cascade"]).optional().describe("On a transition to paused: whether this agent was the target, or was reached by a subtree pause.")
|
|
700
|
+
})
|
|
701
|
+
});
|
|
702
|
+
defineEvent({
|
|
703
|
+
type: "agent.steered",
|
|
704
|
+
durable: true,
|
|
705
|
+
version: 1,
|
|
706
|
+
schema: z.object({
|
|
707
|
+
agentId: z.string().nullable(),
|
|
708
|
+
message: z.string(),
|
|
709
|
+
scope: z.enum(["agent", "subtree"]).optional(),
|
|
710
|
+
roster: z.array(z.string()).optional(),
|
|
711
|
+
deliveredAs: z.enum([
|
|
712
|
+
"steer",
|
|
713
|
+
"turn",
|
|
714
|
+
"queued"
|
|
715
|
+
]).optional()
|
|
716
|
+
})
|
|
717
|
+
});
|
|
718
|
+
defineEvent({
|
|
719
|
+
type: "agent.released",
|
|
720
|
+
durable: true,
|
|
721
|
+
version: 1,
|
|
722
|
+
description: "A finished agent's still-open sandbox was closed, or a fork landed after its spawn was stopped. The recorded outcome is unchanged.",
|
|
723
|
+
schema: z.object({
|
|
724
|
+
agentId: z.string().nullable(),
|
|
725
|
+
reason: z.string()
|
|
726
|
+
})
|
|
727
|
+
});
|
|
728
|
+
defineEvent({
|
|
729
|
+
type: "agent.ended",
|
|
730
|
+
durable: true,
|
|
731
|
+
version: 1,
|
|
732
|
+
schema: z.object({
|
|
733
|
+
agentId: z.string().nullable(),
|
|
734
|
+
outcome: z.string(),
|
|
735
|
+
endedAt: z.number(),
|
|
736
|
+
error: z.string().optional()
|
|
737
|
+
})
|
|
738
|
+
});
|
|
739
|
+
defineEvent({
|
|
740
|
+
type: "handle.settled",
|
|
741
|
+
durable: true,
|
|
742
|
+
version: 1,
|
|
743
|
+
schema: z.object({
|
|
744
|
+
agentId: z.string().nullable(),
|
|
745
|
+
outcome: z.string(),
|
|
746
|
+
resultRef: z.string().nullable()
|
|
747
|
+
})
|
|
748
|
+
});
|
|
749
|
+
defineEvent({
|
|
750
|
+
type: "wait.resolved",
|
|
751
|
+
durable: true,
|
|
752
|
+
version: 1,
|
|
753
|
+
description: "A held spawn's waitFor resolved. A depfail or deadline outcome ends the child failed, without ever forking it.",
|
|
754
|
+
schema: z.object({
|
|
755
|
+
agentId: z.string().nullable(),
|
|
756
|
+
mode: WaitMode,
|
|
757
|
+
outcome: z.enum([
|
|
758
|
+
"satisfied",
|
|
759
|
+
"partial",
|
|
760
|
+
"deadline",
|
|
761
|
+
"depfail"
|
|
762
|
+
]),
|
|
763
|
+
selected: z.array(z.string()),
|
|
764
|
+
settled: z.array(z.object({
|
|
765
|
+
agentId: z.string(),
|
|
766
|
+
outcome: z.string().nullable()
|
|
767
|
+
})),
|
|
768
|
+
pending: z.array(z.string())
|
|
769
|
+
})
|
|
770
|
+
});
|
|
771
|
+
defineEvent({
|
|
772
|
+
type: "wait.blocked",
|
|
773
|
+
durable: true,
|
|
774
|
+
version: 1,
|
|
775
|
+
description: "A held spawn is waiting on a paused dependency — one event per dependency. Was `wait_blocked_on_paused`.",
|
|
776
|
+
schema: z.object({
|
|
777
|
+
agentId: z.string().nullable(),
|
|
778
|
+
blockedOn: z.string()
|
|
779
|
+
})
|
|
780
|
+
});
|
|
781
|
+
defineEvent({
|
|
782
|
+
type: "notify.registered",
|
|
783
|
+
durable: true,
|
|
784
|
+
version: 1,
|
|
785
|
+
description: "This agent asked to be told when each agent in `on` finishes.",
|
|
786
|
+
schema: z.object({
|
|
787
|
+
agentId: z.string().nullable(),
|
|
788
|
+
on: z.array(z.string()),
|
|
789
|
+
wake: z.boolean()
|
|
790
|
+
})
|
|
791
|
+
});
|
|
792
|
+
defineEvent({
|
|
793
|
+
type: "inbox.queued",
|
|
794
|
+
durable: true,
|
|
795
|
+
version: 1,
|
|
796
|
+
description: "Something for this agent to be told — a notification, a steer waiting for it to resume, or a child needing a supervision decision.",
|
|
797
|
+
schema: z.object({
|
|
798
|
+
agentId: z.string().nullable(),
|
|
799
|
+
kind: z.enum([
|
|
800
|
+
"notification",
|
|
801
|
+
"steer",
|
|
802
|
+
"supervision"
|
|
803
|
+
]),
|
|
804
|
+
aboutAgentId: z.string().nullable().optional(),
|
|
805
|
+
aboutSpec: z.string().nullable().optional(),
|
|
806
|
+
outcome: z.string().nullable().optional(),
|
|
807
|
+
resultRef: z.string().nullable().optional(),
|
|
808
|
+
excerpt: z.string().nullable().optional(),
|
|
809
|
+
again: z.boolean().optional(),
|
|
810
|
+
text: z.string().optional()
|
|
811
|
+
})
|
|
812
|
+
});
|
|
813
|
+
defineEvent({
|
|
814
|
+
type: "inbox.delivered",
|
|
815
|
+
durable: true,
|
|
816
|
+
version: 1,
|
|
817
|
+
schema: z.object({
|
|
818
|
+
agentId: z.string().nullable(),
|
|
819
|
+
seqs: z.array(z.number().int()),
|
|
820
|
+
as: z.enum([
|
|
821
|
+
"steer",
|
|
822
|
+
"turn",
|
|
823
|
+
"prompt"
|
|
824
|
+
])
|
|
825
|
+
})
|
|
826
|
+
});
|
|
827
|
+
defineEvent({
|
|
828
|
+
type: "inbox.dropped",
|
|
829
|
+
durable: true,
|
|
830
|
+
version: 1,
|
|
831
|
+
schema: z.object({
|
|
832
|
+
agentId: z.string().nullable(),
|
|
833
|
+
seqs: z.array(z.number().int()),
|
|
834
|
+
reason: z.string()
|
|
835
|
+
})
|
|
836
|
+
});
|
|
837
|
+
defineEvent({
|
|
838
|
+
type: "budget.denied",
|
|
839
|
+
durable: true,
|
|
840
|
+
version: 1,
|
|
841
|
+
schema: z.object({
|
|
842
|
+
agentId: z.string().nullable(),
|
|
843
|
+
dimension: z.enum(["spawnDepth", "maxAgents"]),
|
|
844
|
+
remaining: z.number().int()
|
|
845
|
+
})
|
|
846
|
+
});
|
|
847
|
+
defineEvent({
|
|
848
|
+
type: "agent.admission_queued",
|
|
849
|
+
durable: true,
|
|
850
|
+
version: 1,
|
|
851
|
+
description: "No free provisioning slot was available, so the fork is held instead of run immediately. Only emitted when a real wait happens — the common uncontended case emits nothing, to keep this a signal for genuinely stuck spawns, not noise on every spawn.",
|
|
852
|
+
schema: z.object({
|
|
853
|
+
agentId: z.string().nullable(),
|
|
854
|
+
capacity: z.number().int()
|
|
855
|
+
})
|
|
856
|
+
});
|
|
857
|
+
defineEvent({
|
|
858
|
+
type: "agent.admission_granted",
|
|
859
|
+
durable: true,
|
|
860
|
+
version: 1,
|
|
861
|
+
description: "A held provisioning request got its slot and is proceeding.",
|
|
862
|
+
schema: z.object({ agentId: z.string().nullable() })
|
|
863
|
+
});
|
|
864
|
+
defineEvent({
|
|
865
|
+
type: "agent.admission_timeout",
|
|
866
|
+
durable: true,
|
|
867
|
+
version: 1,
|
|
868
|
+
description: "A held provisioning request never got a slot within the bound and failed loudly instead of hanging silently.",
|
|
869
|
+
schema: z.object({
|
|
870
|
+
agentId: z.string().nullable(),
|
|
871
|
+
waitedMs: z.number().int()
|
|
872
|
+
})
|
|
873
|
+
});
|
|
874
|
+
defineEvent({
|
|
875
|
+
type: "agent.turn_failed",
|
|
876
|
+
durable: true,
|
|
877
|
+
version: 1,
|
|
878
|
+
description: "A turn concluded in failure -- recorded before the failure-policy decision (settle, auto-retry, or hold) is made, so the circuit breaker's consecutive-failure count is accurate regardless of what's decided next.",
|
|
879
|
+
schema: z.object({
|
|
880
|
+
agentId: z.string().nullable(),
|
|
881
|
+
error: z.string(),
|
|
882
|
+
consecutiveFailures: z.number().int()
|
|
883
|
+
})
|
|
884
|
+
});
|
|
885
|
+
defineEvent({
|
|
886
|
+
type: "agent.turn_interrupted",
|
|
887
|
+
durable: true,
|
|
888
|
+
version: 1,
|
|
889
|
+
description: "alineod found this agent still `running` on boot — its turn died with the previous process, mid-stream, with no SDK around to report it. Recorded before the catch-up poll that follows (`rehydrate.ts`'s `wasRunning` checks), so a turn a crash interrupted carries an audit trail distinct from one that ran straight through, whatever catch-up later finds. Named under `agent`, not `turn`: `turn.*` is reserved for events the harness itself reports, and the harness has nothing to report here — the same reasoning that renamed `turn.failed` to `agent.turn_failed`.",
|
|
890
|
+
schema: z.object({ agentId: z.string().nullable() })
|
|
891
|
+
});
|
|
892
|
+
defineEvent({
|
|
893
|
+
type: "agent.supervision_needed",
|
|
894
|
+
durable: true,
|
|
895
|
+
version: 1,
|
|
896
|
+
description: "The agent is held (state: blocked) awaiting an operator decision: POST .../prompt to retry (optionally with corrective text), POST .../stop to give up.",
|
|
897
|
+
schema: z.object({
|
|
898
|
+
agentId: z.string().nullable(),
|
|
899
|
+
reason: z.enum([
|
|
900
|
+
"ask",
|
|
901
|
+
"retries-exhausted",
|
|
902
|
+
"circuit-tripped"
|
|
903
|
+
]),
|
|
904
|
+
error: z.string()
|
|
905
|
+
})
|
|
906
|
+
});
|
|
907
|
+
/**
|
|
908
|
+
* `AgentSpec` — the JSON an agent is defined by.
|
|
909
|
+
*
|
|
910
|
+
* Both the documented `interface` and the `AgentSpecSchema` that validates it are kept by
|
|
911
|
+
* hand, deliberately: the interface carries doc comments that `z.infer<>` would erase, and
|
|
912
|
+
* they are what a reader sees on hover. `agent-spec.test.ts` asserts at the type level that
|
|
913
|
+
* the two cannot drift apart, which buys the safety of a single source without the DX loss.
|
|
914
|
+
*
|
|
915
|
+
* `validateAgentSpec()` and `AgentSpecValidationError` stay in `@alineo-labs/agent` — they
|
|
916
|
+
* are behaviour, and this package has none.
|
|
917
|
+
*
|
|
918
|
+
* Moved here from `@alineo-labs/agent` so that `apps/alineod` can stop modelling it as
|
|
919
|
+
* `z.record(z.unknown())` and emit a real `AgentSpec` into its OpenAPI spec.
|
|
920
|
+
*/
|
|
921
|
+
/** Renders an arbitrary invalid field value for an error message without risking "[object Object]". */
|
|
922
|
+
function describeValue(value) {
|
|
923
|
+
if (typeof value === "string") return value;
|
|
924
|
+
try {
|
|
925
|
+
const json = JSON.stringify(value);
|
|
926
|
+
if (json !== void 0) return json;
|
|
927
|
+
} catch {}
|
|
928
|
+
return typeof value === "object" && value !== null ? Object.prototype.toString.call(value) : String(value);
|
|
929
|
+
}
|
|
930
|
+
/**
|
|
931
|
+
* Runtime schema for `SetupStep`/`AgentSpec` above. Kept as a separate Zod schema rather than
|
|
932
|
+
* generating the interfaces from it (`z.infer<>`) so the hand-written interfaces above can carry
|
|
933
|
+
* full field-level JSDoc — TypeScript doesn't propagate comments through generic type inference,
|
|
934
|
+
* and that documentation is load-bearing (it's what IDE hover/autocomplete shows spec authors).
|
|
935
|
+
* If you add/change/remove a field on `AgentSpec`/`SetupStep`, update the matching schema field
|
|
936
|
+
* here too — `packages/agent/test/schema.test.ts` is the drift check.
|
|
937
|
+
*/
|
|
938
|
+
const CredentialEnvBindingSchema = z$1.object({
|
|
939
|
+
credential: z$1.string({ error: "Each credential env binding must have a 'credential' string" }),
|
|
940
|
+
host: z$1.string({ error: "Each credential env binding must have a 'host' string" }),
|
|
941
|
+
pathPrefix: z$1.string().optional(),
|
|
942
|
+
injection: z$1.union([z$1.object({
|
|
943
|
+
type: z$1.literal("header"),
|
|
944
|
+
name: z$1.string()
|
|
945
|
+
}), z$1.object({
|
|
946
|
+
type: z$1.literal("substitution"),
|
|
947
|
+
placeholder: z$1.string(),
|
|
948
|
+
in: z$1.array(z$1.enum([
|
|
949
|
+
"path",
|
|
950
|
+
"query",
|
|
951
|
+
"header",
|
|
952
|
+
"body"
|
|
953
|
+
])).min(1)
|
|
954
|
+
})]),
|
|
955
|
+
approval: z$1.literal("hold").optional()
|
|
956
|
+
}).loose();
|
|
957
|
+
const SetupStepSchema = z$1.object({
|
|
958
|
+
name: z$1.string({ error: "Each setup step must have a 'name' string" }),
|
|
959
|
+
run: z$1.string({ error: "Each setup step must have a 'run' string" }),
|
|
960
|
+
cwd: z$1.string().optional()
|
|
961
|
+
}).loose();
|
|
962
|
+
const PermissionActionSchema = z$1.enum([
|
|
963
|
+
"allow",
|
|
964
|
+
"ask",
|
|
965
|
+
"deny",
|
|
966
|
+
"rate_limit",
|
|
967
|
+
"classify"
|
|
968
|
+
]);
|
|
969
|
+
const PermissionRuleSchema = z$1.object({
|
|
970
|
+
tool: z$1.string({ error: "Each permission rule must have a 'tool' string" }),
|
|
971
|
+
pattern: z$1.string().optional(),
|
|
972
|
+
action: PermissionActionSchema,
|
|
973
|
+
limit: z$1.object({
|
|
974
|
+
count: z$1.number().int().positive(),
|
|
975
|
+
windowMs: z$1.number().int().positive()
|
|
976
|
+
}).optional()
|
|
977
|
+
}).loose();
|
|
978
|
+
const PermissionPolicySchema = z$1.object({
|
|
979
|
+
default: PermissionActionSchema.optional(),
|
|
980
|
+
rules: z$1.array(PermissionRuleSchema).optional(),
|
|
981
|
+
disabledTools: z$1.array(z$1.string()).optional(),
|
|
982
|
+
restrictToTools: z$1.array(z$1.string()).optional()
|
|
983
|
+
}).loose();
|
|
984
|
+
const PermissionsSchema = z$1.union([z$1.enum([
|
|
985
|
+
"auto",
|
|
986
|
+
"ask",
|
|
987
|
+
"readonly"
|
|
988
|
+
]), PermissionPolicySchema]);
|
|
989
|
+
const nonNegativeIntSpecField = (fieldName) => z$1.number({ error: `Agent spec '${fieldName}' must be a non-negative integer if set` }).int(`Agent spec '${fieldName}' must be a non-negative integer if set`).nonnegative(`Agent spec '${fieldName}' must be a non-negative integer if set`).optional();
|
|
990
|
+
z$1.object({
|
|
991
|
+
$schema: z$1.string().optional(),
|
|
992
|
+
name: z$1.string({ error: (issue) => issue.input === void 0 ? "Agent spec must have a 'name' string" : "Agent spec 'name' must be a string" }).min(1, "Agent spec must have a 'name' string"),
|
|
993
|
+
title: z$1.string().optional(),
|
|
994
|
+
description: z$1.string().optional(),
|
|
995
|
+
author: z$1.string().optional(),
|
|
996
|
+
categories: z$1.array(z$1.string()).optional(),
|
|
997
|
+
harness: z$1.literal("pi", { error: (issue) => issue.input === void 0 ? "Agent spec must have a 'harness' field. Supported values: pi" : `Unsupported harness: '${describeValue(issue.input)}'. Supported values: pi` }),
|
|
998
|
+
harnessVersion: z$1.string().optional(),
|
|
999
|
+
provider: z$1.string().optional(),
|
|
1000
|
+
model: z$1.string({ error: (issue) => issue.input === void 0 ? "Agent spec must have a 'model' string — name the model this agent runs on" : "Agent spec 'model' must be a string" }).min(1, "Agent spec must have a 'model' string — name the model this agent runs on"),
|
|
1001
|
+
packages: z$1.array(z$1.string()).optional(),
|
|
1002
|
+
env: z$1.record(z$1.string(), z$1.union([z$1.string(), CredentialEnvBindingSchema])).optional(),
|
|
1003
|
+
resources: z$1.object({
|
|
1004
|
+
cpu: z$1.string(),
|
|
1005
|
+
memory: z$1.string(),
|
|
1006
|
+
gpu: z$1.string().optional()
|
|
1007
|
+
}).optional(),
|
|
1008
|
+
metadata: z$1.record(z$1.string(), z$1.string()).optional(),
|
|
1009
|
+
registryDependencies: z$1.array(z$1.string()).optional(),
|
|
1010
|
+
setup: z$1.array(SetupStepSchema).optional(),
|
|
1011
|
+
spawnDepth: nonNegativeIntSpecField("spawnDepth"),
|
|
1012
|
+
maxAgents: nonNegativeIntSpecField("maxAgents"),
|
|
1013
|
+
teamId: z$1.string().optional(),
|
|
1014
|
+
resourceId: z$1.string().optional(),
|
|
1015
|
+
permissions: PermissionsSchema.optional(),
|
|
1016
|
+
onFailure: z$1.enum([
|
|
1017
|
+
"ask",
|
|
1018
|
+
"retry",
|
|
1019
|
+
"fail"
|
|
1020
|
+
]).optional(),
|
|
1021
|
+
maxRetries: nonNegativeIntSpecField("maxRetries"),
|
|
1022
|
+
maxConsecutiveFailures: nonNegativeIntSpecField("maxConsecutiveFailures"),
|
|
1023
|
+
checkpoint: z$1.boolean().optional()
|
|
1024
|
+
}).loose();
|
|
1025
|
+
//#endregion
|
|
1026
|
+
//#region ../schema/dist/index.mjs
|
|
1027
|
+
/**
|
|
1028
|
+
* The shape of `alineo.config.json`.
|
|
1029
|
+
*
|
|
1030
|
+
* Three consumers read the same file — `packages/agent`, `packages/cli-shared` and (through
|
|
1031
|
+
* the Docker entrypoint) `apps/alineod` — so it cannot live in any one of them without forcing
|
|
1032
|
+
* the other two to depend on a package for a file none of them owns. It lived in
|
|
1033
|
+
* `config-shared` for that reason, which was the neutral home available at the time.
|
|
1034
|
+
*
|
|
1035
|
+
* Here now because this is the neutral home: shapes, no behaviour, and published, so a user
|
|
1036
|
+
* writing an `alineo.config.json` by hand can get the type from the same place the tooling
|
|
1037
|
+
* does. The mechanism — discovery, precedence, env overlay — stays in `config-shared`.
|
|
1038
|
+
*
|
|
1039
|
+
* Settings specific to a single consumer, such as alineod's timeouts, stay with that consumer
|
|
1040
|
+
* and use `defineEnv`/`loadConfig` directly.
|
|
1041
|
+
*/
|
|
1042
|
+
const ProjectConfigObject = z.object({
|
|
1043
|
+
/**
|
|
1044
|
+
* 127.0.0.1, not "localhost" — some hosts resolve "localhost" to ::1 first, and OpenSandbox
|
|
1045
|
+
* typically only listens on IPv4.
|
|
1046
|
+
*/
|
|
1047
|
+
serverUrl: z.string().min(1).default("http://127.0.0.1:8080"),
|
|
1048
|
+
/** OpenSandbox API key. Empty string for local dev with no auth. */
|
|
1049
|
+
apiKey: z.string().default(""),
|
|
1050
|
+
/**
|
|
1051
|
+
* Route execd and proxy traffic through the OpenSandbox server. Required when the server runs
|
|
1052
|
+
* in Docker (e.g. started by `alineo init`).
|
|
1053
|
+
*/
|
|
1054
|
+
useServerProxy: z.boolean().default(true),
|
|
1055
|
+
/**
|
|
1056
|
+
* Anchor path used to derive the agent snapshot store location (`agent-snapshots.json` is
|
|
1057
|
+
* written next to it). Does not select the ledger storage adapter.
|
|
1058
|
+
*/
|
|
1059
|
+
adapterPath: z.string().min(1).default("./.alineo/ledger.db"),
|
|
1060
|
+
/** Directory holding agent spec files. */
|
|
1061
|
+
agentsDir: z.string().min(1).default("./agents"),
|
|
1062
|
+
/**
|
|
1063
|
+
* Applied when an agent spec omits the field.
|
|
1064
|
+
*
|
|
1065
|
+
* `.prefault({})` rather than `.default({})`: Zod 4 uses a `default` value as-is, so
|
|
1066
|
+
* `.default({})` on a nested object would yield a literal `{}` and leave `cpu`/`memory`
|
|
1067
|
+
* undefined. `prefault` parses the value through the schema, which fills the inner defaults.
|
|
1068
|
+
*/
|
|
1069
|
+
defaults: z.object({ resources: z.object({
|
|
1070
|
+
cpu: z.string().min(1).default("1000m"),
|
|
1071
|
+
memory: z.string().min(1).default("1Gi")
|
|
1072
|
+
}).prefault({}) }).prefault({})
|
|
1073
|
+
});
|
|
1074
|
+
/**
|
|
1075
|
+
* In this file `null` means "not set", exactly as the hand-written reader's `??` chain used to
|
|
1076
|
+
* treat it. The file is hand-editable, an interrupted write can leave `{"defaults": {"resources":
|
|
1077
|
+
* null}}` behind, and no field here has a meaningful null value — so a stray null falls back to
|
|
1078
|
+
* the built-in default instead of failing validation and taking the CLI or the daemon down.
|
|
1079
|
+
*/
|
|
1080
|
+
function dropNulls(value) {
|
|
1081
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) return value;
|
|
1082
|
+
const out = {};
|
|
1083
|
+
for (const [key, inner] of Object.entries(value)) {
|
|
1084
|
+
if (inner === null) continue;
|
|
1085
|
+
out[key] = dropNulls(inner);
|
|
1086
|
+
}
|
|
1087
|
+
return out;
|
|
1088
|
+
}
|
|
1089
|
+
/** The project config schema, with nulls treated as absent. */
|
|
1090
|
+
const ProjectConfigSchema = z.preprocess(dropNulls, ProjectConfigObject);
|
|
1091
|
+
Object.freeze({
|
|
1092
|
+
sandbox_created: "sandbox.created",
|
|
1093
|
+
sandbox_closed: "sandbox.closed",
|
|
1094
|
+
sandbox_paused: "sandbox.paused",
|
|
1095
|
+
sandbox_resumed: "sandbox.resumed",
|
|
1096
|
+
checkpoint_created: "sandbox.checkpoint_created",
|
|
1097
|
+
exec_start: "exec.started",
|
|
1098
|
+
exec_event: "exec.output",
|
|
1099
|
+
exec_complete: "exec.completed",
|
|
1100
|
+
egress_rule_added: "egress.rule_added",
|
|
1101
|
+
egress_rule_removed: "egress.rule_removed",
|
|
1102
|
+
credential_bound: "credential.bound",
|
|
1103
|
+
credential_revoked: "credential.revoked",
|
|
1104
|
+
permission_requested: "permission.requested",
|
|
1105
|
+
permission_resolved: "permission.resolved",
|
|
1106
|
+
permission_request: "permission.requested",
|
|
1107
|
+
workflow_complete: "workflow.completed",
|
|
1108
|
+
workflow_failed: "workflow.failed",
|
|
1109
|
+
step_start: "step.started",
|
|
1110
|
+
step_complete: "step.completed",
|
|
1111
|
+
step_failed: "step.failed",
|
|
1112
|
+
step_rolled_back: "step.rolled_back",
|
|
1113
|
+
snapshot: "sandbox.checkpoint_created",
|
|
1114
|
+
agent_spawned: "agent.spawned",
|
|
1115
|
+
agent_provisioned: "agent.provisioned",
|
|
1116
|
+
agent_state_changed: "agent.state_changed",
|
|
1117
|
+
agent_steered: "agent.steered",
|
|
1118
|
+
agent_released: "agent.released",
|
|
1119
|
+
agent_ended: "agent.ended",
|
|
1120
|
+
handle_settled: "handle.settled",
|
|
1121
|
+
wait_resolved: "wait.resolved",
|
|
1122
|
+
wait_blocked_on_paused: "wait.blocked",
|
|
1123
|
+
inbox_queued: "inbox.queued",
|
|
1124
|
+
inbox_delivered: "inbox.delivered",
|
|
1125
|
+
inbox_dropped: "inbox.dropped",
|
|
1126
|
+
notify_registered: "notify.registered",
|
|
1127
|
+
budget_denied: "budget.denied",
|
|
1128
|
+
subtree_quiescent: "run.quiescent",
|
|
1129
|
+
agent_start: "session.started",
|
|
1130
|
+
agent_end: "session.ended",
|
|
1131
|
+
turn_start: "turn.started",
|
|
1132
|
+
turn_end: "turn.ended",
|
|
1133
|
+
tool_start: "tool.started",
|
|
1134
|
+
tool_update: "tool.updated",
|
|
1135
|
+
tool_end: "tool.ended",
|
|
1136
|
+
message_start: "message.started",
|
|
1137
|
+
message_update: "message.updated",
|
|
1138
|
+
message_end: "message.ended",
|
|
1139
|
+
text: "message.updated",
|
|
1140
|
+
compaction_start: "compaction.started",
|
|
1141
|
+
compaction_end: "compaction.ended",
|
|
1142
|
+
auto_retry_start: "retry.started",
|
|
1143
|
+
auto_retry_end: "retry.ended",
|
|
1144
|
+
queue_update: "queue.updated",
|
|
1145
|
+
extension_ui: "extension.ui",
|
|
1146
|
+
extension_error: "extension.error"
|
|
1147
|
+
});
|
|
1148
|
+
//#endregion
|
|
1149
|
+
//#region ../config-shared/dist/index.mjs
|
|
1150
|
+
/** The file name every alineo project config uses. */
|
|
1151
|
+
const PROJECT_CONFIG_FILE = "alineo.config.json";
|
|
1152
|
+
/**
|
|
1153
|
+
* Walk up from `startDir` looking for `alineo.config.json`.
|
|
1154
|
+
*
|
|
1155
|
+
* Before this existed, `packages/agent` only ever checked `process.cwd()`, so running a script
|
|
1156
|
+
* from a subdirectory silently fell back to built-in defaults — a wrong `serverUrl` looked
|
|
1157
|
+
* exactly like no config at all.
|
|
1158
|
+
*
|
|
1159
|
+
* The walk is **bounded**, which matters as much as the walk itself: an unbounded search would
|
|
1160
|
+
* let an unrelated `alineo.config.json` several levels up configure a run. It stops after
|
|
1161
|
+
* examining:
|
|
1162
|
+
*
|
|
1163
|
+
* - a directory containing `.git` (the project boundary),
|
|
1164
|
+
* - the user's home directory (global config is a separate, explicit source), or
|
|
1165
|
+
* - the filesystem root.
|
|
1166
|
+
*
|
|
1167
|
+
* The stop directory is itself checked before the walk ends, so a config file sitting next to
|
|
1168
|
+
* `.git` is still found.
|
|
1169
|
+
*/
|
|
1170
|
+
function findProjectConfig(startDir = process.cwd()) {
|
|
1171
|
+
const home = resolve(homedir$1());
|
|
1172
|
+
let dir = resolve(startDir);
|
|
1173
|
+
for (;;) {
|
|
1174
|
+
const candidate = join(dir, PROJECT_CONFIG_FILE);
|
|
1175
|
+
if (existsSync$1(candidate)) return candidate;
|
|
1176
|
+
if (existsSync$1(join(dir, ".git"))) return null;
|
|
1177
|
+
if (dir === home) return null;
|
|
1178
|
+
const parent = dirname(dir);
|
|
1179
|
+
if (parent === dir) return null;
|
|
1180
|
+
dir = parent;
|
|
1181
|
+
}
|
|
1182
|
+
}
|
|
1183
|
+
/** Absolute path of the user-level config, `~/.config/alineo/config.json`. */
|
|
1184
|
+
function globalConfigPath$1() {
|
|
1185
|
+
return join(homedir$1(), ".config", "alineo", "config.json");
|
|
1186
|
+
}
|
|
1187
|
+
/**
|
|
1188
|
+
* Read and JSON-parse a config file, or return `null` when it isn't there.
|
|
1189
|
+
* A file that exists but is malformed throws — a typo in config should be loud, not silently
|
|
1190
|
+
* ignored in favour of defaults.
|
|
1191
|
+
*/
|
|
1192
|
+
function readJsonFile(path) {
|
|
1193
|
+
if (!existsSync$1(path)) return null;
|
|
1194
|
+
const raw = readFileSync(path, "utf8");
|
|
1195
|
+
try {
|
|
1196
|
+
return JSON.parse(raw);
|
|
1197
|
+
} catch (err) {
|
|
1198
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
1199
|
+
throw new Error(`${path} is not valid JSON: ${message}`);
|
|
1200
|
+
}
|
|
1201
|
+
}
|
|
1202
|
+
function isPlainObject(value) {
|
|
1203
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) return false;
|
|
1204
|
+
const proto = Object.getPrototypeOf(value);
|
|
1205
|
+
return proto === Object.prototype || proto === null;
|
|
1206
|
+
}
|
|
1207
|
+
/**
|
|
1208
|
+
* Merge config sources, lowest precedence first. Plain objects merge key by key; everything
|
|
1209
|
+
* else (arrays, strings, numbers) is replaced wholesale by the later source.
|
|
1210
|
+
*
|
|
1211
|
+
* `undefined` never overwrites — an absent key in a higher-precedence source leaves the lower
|
|
1212
|
+
* one intact, which is what makes "env var not set" mean "don't override" rather than "clear".
|
|
1213
|
+
* An explicit `null` *does* overwrite, so a config file can blank a value on purpose.
|
|
1214
|
+
*/
|
|
1215
|
+
function mergeDeep(...sources) {
|
|
1216
|
+
let result = void 0;
|
|
1217
|
+
for (const source of sources) {
|
|
1218
|
+
if (source === void 0) continue;
|
|
1219
|
+
if (isPlainObject(source) && isPlainObject(result)) {
|
|
1220
|
+
const merged = { ...result };
|
|
1221
|
+
for (const [key, value] of Object.entries(source)) {
|
|
1222
|
+
if (value === void 0) continue;
|
|
1223
|
+
merged[key] = key in merged ? mergeDeep(merged[key], value) : value;
|
|
1224
|
+
}
|
|
1225
|
+
result = merged;
|
|
1226
|
+
} else result = source;
|
|
1227
|
+
}
|
|
1228
|
+
return result;
|
|
1229
|
+
}
|
|
1230
|
+
/**
|
|
1231
|
+
* Freeze an object and everything reachable from it, so a resolved config can't be mutated
|
|
1232
|
+
* after validation. Cycles are impossible in JSON-derived data, so no seen-set is needed.
|
|
1233
|
+
*/
|
|
1234
|
+
function deepFreeze(value) {
|
|
1235
|
+
if (value === null || typeof value !== "object") return value;
|
|
1236
|
+
if (Object.isFrozen(value)) return value;
|
|
1237
|
+
Object.freeze(value);
|
|
1238
|
+
for (const key of Object.getOwnPropertyNames(value)) deepFreeze(value[key]);
|
|
1239
|
+
return value;
|
|
1240
|
+
}
|
|
1241
|
+
/** Env var holding a whole config document inline, as JSON. */
|
|
1242
|
+
const CONFIG_CONTENT_ENV = "ALINEO_CONFIG_CONTENT";
|
|
1243
|
+
/**
|
|
1244
|
+
* Resolve configuration from every source, lowest precedence first:
|
|
1245
|
+
*
|
|
1246
|
+
* ```
|
|
1247
|
+
* schema defaults
|
|
1248
|
+
* < ~/.config/alineo/config.json (user)
|
|
1249
|
+
* < alineo.config.json (project — found by bounded walk-up)
|
|
1250
|
+
* < ALINEO_CONFIG_CONTENT (inline JSON)
|
|
1251
|
+
* < ALINEO_* env vars (ops)
|
|
1252
|
+
* < overrides (flags / explicit call-site object)
|
|
1253
|
+
* ```
|
|
1254
|
+
*
|
|
1255
|
+
* Validated once, then deep-frozen. **This function is pure with respect to module state** —
|
|
1256
|
+
* nothing is cached here and there is no installed singleton, so two bundled copies of this
|
|
1257
|
+
* package cannot drift apart. Callers hold the result for as long as they need it.
|
|
1258
|
+
*/
|
|
1259
|
+
function loadConfigWithSources(options) {
|
|
1260
|
+
const { schema, cwd = process.cwd(), env = process.env, fromEnv, overrides, globalPath = globalConfigPath$1(), discover = true, label = "config" } = options;
|
|
1261
|
+
const sources = {
|
|
1262
|
+
globalFile: null,
|
|
1263
|
+
projectFile: null,
|
|
1264
|
+
inlineEnv: false,
|
|
1265
|
+
envVars: false,
|
|
1266
|
+
overrides: overrides !== void 0
|
|
1267
|
+
};
|
|
1268
|
+
const layers = [];
|
|
1269
|
+
if (discover) {
|
|
1270
|
+
if (globalPath) {
|
|
1271
|
+
const globalData = readJsonFile(globalPath);
|
|
1272
|
+
if (globalData !== null) {
|
|
1273
|
+
layers.push(globalData);
|
|
1274
|
+
sources.globalFile = globalPath;
|
|
1275
|
+
}
|
|
1276
|
+
}
|
|
1277
|
+
const projectFile = findProjectConfig(cwd);
|
|
1278
|
+
if (projectFile) {
|
|
1279
|
+
const projectData = readJsonFile(projectFile);
|
|
1280
|
+
if (projectData !== null) {
|
|
1281
|
+
layers.push(projectData);
|
|
1282
|
+
sources.projectFile = projectFile;
|
|
1283
|
+
}
|
|
1284
|
+
}
|
|
1285
|
+
const inline = env[CONFIG_CONTENT_ENV];
|
|
1286
|
+
if (inline !== void 0 && inline.trim() !== "") {
|
|
1287
|
+
try {
|
|
1288
|
+
layers.push(JSON.parse(inline));
|
|
1289
|
+
} catch (err) {
|
|
1290
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
1291
|
+
throw new Error(`${CONFIG_CONTENT_ENV} is not valid JSON: ${message}`);
|
|
1292
|
+
}
|
|
1293
|
+
sources.inlineEnv = true;
|
|
1294
|
+
}
|
|
1295
|
+
if (fromEnv) {
|
|
1296
|
+
const fromEnvData = fromEnv(env);
|
|
1297
|
+
if (fromEnvData !== void 0) {
|
|
1298
|
+
layers.push(fromEnvData);
|
|
1299
|
+
sources.envVars = true;
|
|
1300
|
+
}
|
|
1301
|
+
}
|
|
1302
|
+
}
|
|
1303
|
+
if (overrides !== void 0) layers.push(overrides);
|
|
1304
|
+
const merged = layers.length > 0 ? mergeDeep(...layers) : {};
|
|
1305
|
+
const parsed = schema.safeParse(merged ?? {});
|
|
1306
|
+
if (!parsed.success) {
|
|
1307
|
+
const details = parsed.error.issues.map((issue) => {
|
|
1308
|
+
return ` ${issue.path.length > 0 ? issue.path.join(".") : "(root)"}: ${issue.message}`;
|
|
1309
|
+
}).join("\n");
|
|
1310
|
+
const from = describeSources(sources);
|
|
1311
|
+
throw new Error(`Invalid ${label}${from}:\n${details}`);
|
|
1312
|
+
}
|
|
1313
|
+
return {
|
|
1314
|
+
config: deepFreeze(parsed.data),
|
|
1315
|
+
sources
|
|
1316
|
+
};
|
|
1317
|
+
}
|
|
1318
|
+
/** `loadConfigWithSources` without the provenance — the common case. */
|
|
1319
|
+
function loadConfig(options) {
|
|
1320
|
+
return loadConfigWithSources(options).config;
|
|
1321
|
+
}
|
|
1322
|
+
function describeSources(sources) {
|
|
1323
|
+
const parts = [];
|
|
1324
|
+
if (sources.globalFile) parts.push(sources.globalFile);
|
|
1325
|
+
if (sources.projectFile) parts.push(sources.projectFile);
|
|
1326
|
+
if (sources.inlineEnv) parts.push(CONFIG_CONTENT_ENV);
|
|
1327
|
+
if (sources.envVars) parts.push("environment");
|
|
1328
|
+
if (sources.overrides) parts.push("explicit options");
|
|
1329
|
+
return parts.length > 0 ? ` (from ${parts.join(", ")})` : "";
|
|
1330
|
+
}
|
|
1331
|
+
function parseBoolean(raw, name) {
|
|
1332
|
+
const value = raw.trim().toLowerCase();
|
|
1333
|
+
if ([
|
|
1334
|
+
"true",
|
|
1335
|
+
"1",
|
|
1336
|
+
"yes",
|
|
1337
|
+
"on"
|
|
1338
|
+
].includes(value)) return true;
|
|
1339
|
+
if ([
|
|
1340
|
+
"false",
|
|
1341
|
+
"0",
|
|
1342
|
+
"no",
|
|
1343
|
+
"off"
|
|
1344
|
+
].includes(value)) return false;
|
|
1345
|
+
throw new Error(`${name}=${JSON.stringify(raw)} is not a boolean (use true or false)`);
|
|
1346
|
+
}
|
|
1347
|
+
/**
|
|
1348
|
+
* Project-config fields settable from the environment. These are what
|
|
1349
|
+
* `apps/alineod/docker-entrypoint.sh` writes into a generated config file before starting the
|
|
1350
|
+
* server; reading them directly means the container no longer has to write a file at all.
|
|
1351
|
+
*/
|
|
1352
|
+
function projectConfigFromEnv(env) {
|
|
1353
|
+
const out = {};
|
|
1354
|
+
if (env.ALINEO_SERVER_URL !== void 0) out.serverUrl = env.ALINEO_SERVER_URL;
|
|
1355
|
+
if (env.ALINEO_API_KEY !== void 0) out.apiKey = env.ALINEO_API_KEY;
|
|
1356
|
+
if (env.ALINEO_USE_SERVER_PROXY !== void 0) out.useServerProxy = parseBoolean(env.ALINEO_USE_SERVER_PROXY, "ALINEO_USE_SERVER_PROXY");
|
|
1357
|
+
return Object.keys(out).length > 0 ? out : void 0;
|
|
1358
|
+
}
|
|
1359
|
+
/** Resolve `alineo.config.json` from every source. Validated once, then frozen. */
|
|
1360
|
+
function loadProjectConfig(options = {}) {
|
|
1361
|
+
return loadConfig({
|
|
1362
|
+
schema: ProjectConfigSchema,
|
|
1363
|
+
fromEnv: projectConfigFromEnv,
|
|
1364
|
+
label: "alineo config",
|
|
1365
|
+
...options
|
|
1366
|
+
});
|
|
1367
|
+
}
|
|
1368
|
+
//#endregion
|
|
1369
|
+
//#region ../cli-shared/dist/index.mjs
|
|
1370
|
+
async function spawn(cmd) {
|
|
1371
|
+
let proc;
|
|
1372
|
+
try {
|
|
1373
|
+
proc = Bun.spawn(cmd, {
|
|
1374
|
+
stdout: "pipe",
|
|
1375
|
+
stderr: "pipe"
|
|
1376
|
+
});
|
|
1377
|
+
} catch {
|
|
1378
|
+
throw new Error(`'${cmd[0]}' not found — is Docker installed?`);
|
|
1379
|
+
}
|
|
1380
|
+
const [stdout, stderr, exitCode] = await Promise.all([
|
|
1381
|
+
new Response(proc.stdout).text(),
|
|
1382
|
+
new Response(proc.stderr).text(),
|
|
1383
|
+
proc.exited
|
|
1384
|
+
]);
|
|
1385
|
+
return {
|
|
1386
|
+
ok: exitCode === 0,
|
|
1387
|
+
stdout,
|
|
1388
|
+
stderr
|
|
1389
|
+
};
|
|
1390
|
+
}
|
|
1391
|
+
async function checkDocker() {
|
|
1392
|
+
const { ok, stderr } = await spawn(["docker", "info"]);
|
|
1393
|
+
if (!ok) {
|
|
1394
|
+
if (stderr.includes("Cannot connect") || stderr.includes("daemon") || stderr.includes("socket")) throw new Error("Docker daemon is not running. Start Docker and try again.");
|
|
1395
|
+
throw new Error("Docker is not available. Install Docker and try again.");
|
|
1396
|
+
}
|
|
1397
|
+
}
|
|
1398
|
+
async function getContainerState(name) {
|
|
1399
|
+
const { ok, stdout } = await spawn([
|
|
1400
|
+
"docker",
|
|
1401
|
+
"inspect",
|
|
1402
|
+
name,
|
|
1403
|
+
"--format",
|
|
1404
|
+
"{{.State.Status}}"
|
|
1405
|
+
]);
|
|
1406
|
+
if (!ok) return "missing";
|
|
1407
|
+
return stdout.trim() === "running" ? "running" : "stopped";
|
|
1408
|
+
}
|
|
1409
|
+
async function startContainer(name) {
|
|
1410
|
+
const { ok, stderr } = await spawn([
|
|
1411
|
+
"docker",
|
|
1412
|
+
"start",
|
|
1413
|
+
name
|
|
1414
|
+
]);
|
|
1415
|
+
if (!ok) throw new Error(`Failed to start container '${name}': ${stderr.trim()}`);
|
|
1416
|
+
}
|
|
1417
|
+
async function restartContainer(name) {
|
|
1418
|
+
const { ok, stderr } = await spawn([
|
|
1419
|
+
"docker",
|
|
1420
|
+
"restart",
|
|
1421
|
+
name
|
|
1422
|
+
]);
|
|
1423
|
+
if (!ok) throw new Error(`Failed to restart container '${name}': ${stderr.trim()}`);
|
|
1424
|
+
}
|
|
1425
|
+
/** Force-removes a container regardless of running/stopped state — used to recreate one whose
|
|
1426
|
+
* config (network mode, env) needs to change, since `docker run` args can't be applied in place. */
|
|
1427
|
+
async function removeContainer(name) {
|
|
1428
|
+
const { ok, stderr } = await spawn([
|
|
1429
|
+
"docker",
|
|
1430
|
+
"rm",
|
|
1431
|
+
"-f",
|
|
1432
|
+
name
|
|
1433
|
+
]);
|
|
1434
|
+
if (!ok) throw new Error(`Failed to remove container '${name}': ${stderr.trim()}`);
|
|
1435
|
+
}
|
|
1436
|
+
/**
|
|
1437
|
+
* Set a container's restart policy in place (`docker update`, no recreate). Used so containers
|
|
1438
|
+
* created before `init` started passing `--restart` still come back after a reboot.
|
|
1439
|
+
*/
|
|
1440
|
+
async function setRestartPolicy(name, policy) {
|
|
1441
|
+
const { ok, stderr } = await spawn([
|
|
1442
|
+
"docker",
|
|
1443
|
+
"update",
|
|
1444
|
+
"--restart",
|
|
1445
|
+
policy,
|
|
1446
|
+
name
|
|
1447
|
+
]);
|
|
1448
|
+
if (!ok) throw new Error(`Failed to set restart policy on '${name}': ${stderr.trim()}`);
|
|
1449
|
+
}
|
|
1450
|
+
async function runContainer(args, label = "container") {
|
|
1451
|
+
const { ok, stderr } = await spawn([
|
|
1452
|
+
"docker",
|
|
1453
|
+
"run",
|
|
1454
|
+
...args
|
|
1455
|
+
]);
|
|
1456
|
+
if (!ok) throw new Error(`Failed to start ${label}: ${stderr.trim()}`);
|
|
1457
|
+
}
|
|
1458
|
+
async function pullImage(image) {
|
|
1459
|
+
const { ok, stderr } = await spawn([
|
|
1460
|
+
"docker",
|
|
1461
|
+
"pull",
|
|
1462
|
+
image
|
|
1463
|
+
]);
|
|
1464
|
+
if (!ok) throw new Error(`Failed to pull '${image}': ${stderr.trim()}`);
|
|
1465
|
+
}
|
|
1466
|
+
/** Default health predicate: OpenSandbox's `/health` returns `{ status: "healthy" }`. */
|
|
1467
|
+
const isOpenSandboxHealthy = (body) => body?.status === "healthy";
|
|
1468
|
+
async function pollHealth(url, timeoutMs = 6e4, isHealthy = isOpenSandboxHealthy) {
|
|
1469
|
+
const deadline = Date.now() + timeoutMs;
|
|
1470
|
+
while (Date.now() < deadline) {
|
|
1471
|
+
try {
|
|
1472
|
+
const res = await fetch(url);
|
|
1473
|
+
if (res.ok && isHealthy(await res.json())) return;
|
|
1474
|
+
} catch {}
|
|
1475
|
+
await new Promise((r) => setTimeout(r, 1e3));
|
|
1476
|
+
}
|
|
1477
|
+
throw new Error(`${url} did not become healthy within ${timeoutMs / 1e3}s`);
|
|
1478
|
+
}
|
|
1479
|
+
/** A quick one-shot version of `pollHealth` for deciding whether an already-`running`
|
|
1480
|
+
* container is actually reachable, not just started — a container can report "running" to
|
|
1481
|
+
* Docker while its service is unreachable (wrong network mode, crashed process, stale config).
|
|
1482
|
+
* 10s (not 3s) so a slow-but-healthy service (host under load, cold Bun startup after reboot,
|
|
1483
|
+
* bridge networking still settling) doesn't get misread as unreachable and trigger a destructive
|
|
1484
|
+
* `docker rm -f` of an otherwise-fine container. */
|
|
1485
|
+
async function isReachable(url, isHealthy, timeoutMs = 1e4) {
|
|
1486
|
+
try {
|
|
1487
|
+
await pollHealth(url, timeoutMs, isHealthy);
|
|
1488
|
+
return true;
|
|
1489
|
+
} catch {
|
|
1490
|
+
return false;
|
|
1491
|
+
}
|
|
1492
|
+
}
|
|
148
1493
|
const CONFIG_DIR = ".alineo";
|
|
149
|
-
const CONFIG_FILE = "alineo.config.json";
|
|
150
1494
|
function configPath() {
|
|
151
|
-
return
|
|
1495
|
+
return PROJECT_CONFIG_FILE;
|
|
152
1496
|
}
|
|
153
1497
|
function globalConfigPath() {
|
|
154
1498
|
return join$1(serverConfigDir(), "config.json");
|
|
155
1499
|
}
|
|
156
|
-
function fillDefaults(data) {
|
|
157
|
-
return {
|
|
158
|
-
serverUrl: data.serverUrl ?? "http://127.0.0.1:8080",
|
|
159
|
-
useServerProxy: data.useServerProxy ?? true,
|
|
160
|
-
apiKey: data.apiKey ?? "",
|
|
161
|
-
adapterPath: data.adapterPath ?? "./.alineo/ledger.db",
|
|
162
|
-
agentsDir: data.agentsDir ?? "./agents",
|
|
163
|
-
defaults: { resources: {
|
|
164
|
-
cpu: data.defaults?.resources.cpu ?? "1000m",
|
|
165
|
-
memory: data.defaults?.resources.memory ?? "1Gi"
|
|
166
|
-
} }
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
1500
|
/**
|
|
170
|
-
*
|
|
171
|
-
*
|
|
172
|
-
* `~/.config/alineo/config.json
|
|
173
|
-
*
|
|
1501
|
+
* Resolve the CLI's configuration.
|
|
1502
|
+
*
|
|
1503
|
+
* Sources are merged lowest-first — `~/.config/alineo/config.json`, then the nearest
|
|
1504
|
+
* `alineo.config.json` (found by walking up from the working directory), then `ALINEO_*`
|
|
1505
|
+
* environment variables. Two things changed when this moved onto `@alineo-labs/config-shared`:
|
|
1506
|
+
* a project config is now found from a subdirectory rather than only from the exact working
|
|
1507
|
+
* directory, and a global config no longer disappears entirely just because a project config
|
|
1508
|
+
* exists — the project file overrides key by key.
|
|
1509
|
+
*
|
|
1510
|
+
* When neither file exists, the global one is bootstrapped so a fresh `bunx alineo-cli` works
|
|
1511
|
+
* without an `init` in every directory.
|
|
174
1512
|
*/
|
|
175
1513
|
async function readConfig() {
|
|
176
|
-
const
|
|
177
|
-
if (await localFile.exists()) return fillDefaults(await localFile.json());
|
|
1514
|
+
const hasProject = findProjectConfig() !== null;
|
|
178
1515
|
const globalPath = globalConfigPath();
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
};
|
|
194
|
-
await Bun.write(globalPath, JSON.stringify(config, null, 2) + "\n");
|
|
195
|
-
return config;
|
|
1516
|
+
if (!hasProject && !existsSync(globalPath)) {
|
|
1517
|
+
const dir = serverConfigDir();
|
|
1518
|
+
if (!existsSync(dir)) await mkdir(dir, { recursive: true });
|
|
1519
|
+
const bootstrapped = loadProjectConfig({
|
|
1520
|
+
discover: false,
|
|
1521
|
+
overrides: {
|
|
1522
|
+
adapterPath: join$1(dir, "ledger.db"),
|
|
1523
|
+
agentsDir: join$1(dir, "agents")
|
|
1524
|
+
}
|
|
1525
|
+
});
|
|
1526
|
+
await Bun.write(globalPath, JSON.stringify(bootstrapped, null, 2) + "\n");
|
|
1527
|
+
return bootstrapped;
|
|
1528
|
+
}
|
|
1529
|
+
return loadProjectConfig({ globalPath });
|
|
196
1530
|
}
|
|
197
1531
|
async function writeConfig(config) {
|
|
198
1532
|
if (!existsSync(CONFIG_DIR)) await mkdir(CONFIG_DIR, { recursive: true });
|
|
@@ -205,14 +1539,14 @@ function serverConfigPath() {
|
|
|
205
1539
|
return join$1(serverConfigDir(), "server.toml");
|
|
206
1540
|
}
|
|
207
1541
|
/**
|
|
208
|
-
* Host directory bind-mounted into the OpenSandbox container at `/data` (see
|
|
209
|
-
*
|
|
1542
|
+
* Host directory bind-mounted into the OpenSandbox container at `/data` (see `init.ts`),
|
|
1543
|
+
* backing the `[store].path` set below. OpenSandbox itself persists
|
|
210
1544
|
* snapshot metadata durably (a SQLite db, meant to survive the server process restarting —
|
|
211
1545
|
* see opensandbox-group/OpenSandbox's `PersistedSnapshotService`), but that guarantee is
|
|
212
1546
|
* only as good as where the db file actually lives: without this mount, it sits in the
|
|
213
1547
|
* `alineo-opensandbox` container's own writable layer, so restart is fine but any time the
|
|
214
1548
|
* container itself is recreated (host reboot with no restart policy, `docker system prune`,
|
|
215
|
-
* a stray `docker rm`) silently loses every cached snapshot record — every `Alineo.
|
|
1549
|
+
* a stray `docker rm`) silently loses every cached snapshot record — every `Alineo.start()`
|
|
216
1550
|
* snapshot fast path pays a full cold rebuild next time, indistinguishable from a genuinely
|
|
217
1551
|
* changed spec (see issue #20). Bind-mounting this directory makes that data outlive the
|
|
218
1552
|
* container's own lifecycle, matching OpenSandbox's own intent.
|
|
@@ -229,6 +1563,26 @@ function serverDataDir() {
|
|
|
229
1563
|
* message itself suggests does not exist as a published tag. v1.0.22 is the latest.
|
|
230
1564
|
*/
|
|
231
1565
|
/**
|
|
1566
|
+
* Where the OpenSandbox server, running in its own container, reaches the ports it publishes on
|
|
1567
|
+
* the host (`[docker].host_ip`). Without it the server falls back to `127.0.0.1` — its own
|
|
1568
|
+
* loopback — so the readiness probe for an egress sidecar gets "connection refused" from a
|
|
1569
|
+
* sidecar that is healthy, and every sandbox with a `networkPolicy` fails to start
|
|
1570
|
+
* ("Egress sidecar did not become ready within 30s"). `init` adds
|
|
1571
|
+
* `--add-host host.docker.internal:host-gateway` to the container so the name resolves on native
|
|
1572
|
+
* Linux Docker as well as Docker Desktop.
|
|
1573
|
+
*/
|
|
1574
|
+
const DOCKER_HOST_IP = "host.docker.internal";
|
|
1575
|
+
/**
|
|
1576
|
+
* Adds `host_ip` to an existing `server.toml` that has none, leaving everything else (including
|
|
1577
|
+
* hand edits) alone. Returns `null` when nothing needs to change: a `host_ip` is already set, or
|
|
1578
|
+
* there is no `[docker]` table to put it in.
|
|
1579
|
+
*/
|
|
1580
|
+
function withDockerHostIp(toml) {
|
|
1581
|
+
if (/^host_ip\s*=/m.test(toml)) return null;
|
|
1582
|
+
if (!/^\[docker\]/m.test(toml)) return null;
|
|
1583
|
+
return toml.replace(/^\[docker\][^\n]*\n/m, (header) => `${header}host_ip = "${DOCKER_HOST_IP}"\n`);
|
|
1584
|
+
}
|
|
1585
|
+
/**
|
|
232
1586
|
* `egress.image`/`egress.mode` are configured unconditionally, not opt-in. Per OpenSandbox's
|
|
233
1587
|
* own control flow, a configured `egress.image` is inert for any sandbox created without a
|
|
234
1588
|
* `networkPolicy` — no sidecar is attached, no behavior changes for anyone not touching
|
|
@@ -238,11 +1592,11 @@ function serverDataDir() {
|
|
|
238
1592
|
* plans/credential-injection.md Phase 4). `dns+nft` (rather than `dns`) is required for
|
|
239
1593
|
* `credentialProxy`'s Credential Vault to activate at all.
|
|
240
1594
|
*/
|
|
241
|
-
function serverConfigContent() {
|
|
1595
|
+
function serverConfigContent(eip) {
|
|
242
1596
|
return `[server]
|
|
243
1597
|
host = "0.0.0.0"
|
|
244
1598
|
port = 8080
|
|
245
|
-
eip = "
|
|
1599
|
+
eip = "${eip}"
|
|
246
1600
|
|
|
247
1601
|
[runtime]
|
|
248
1602
|
type = "docker"
|
|
@@ -250,6 +1604,7 @@ execd_image = "opensandbox/execd:v1.0.22"
|
|
|
250
1604
|
|
|
251
1605
|
[docker]
|
|
252
1606
|
network_mode = "bridge"
|
|
1607
|
+
host_ip = "${DOCKER_HOST_IP}"
|
|
253
1608
|
|
|
254
1609
|
[store]
|
|
255
1610
|
type = "sqlite"
|
|
@@ -260,6 +1615,313 @@ image = "opensandbox/egress:v1.1.7"
|
|
|
260
1615
|
mode = "dns+nft"
|
|
261
1616
|
`;
|
|
262
1617
|
}
|
|
1618
|
+
/**
|
|
1619
|
+
* Model API key env vars Pi's coding-agent runtime resolves providers from — mirrors the
|
|
1620
|
+
* `envMap` in earendil-works/pi's `packages/ai/src/env-api-keys.ts` (plus Anthropic's three,
|
|
1621
|
+
* handled separately there). An `AgentSpec`'s env map (`{ NVIDIA_API_KEY: "${NVIDIA_API_KEY}" }`,
|
|
1622
|
+
* see `packages/agent/src/schema.ts`) is resolved from `process.env` inside whatever process
|
|
1623
|
+
* calls `Alineo.start()`/`.spawn()` — for a swarm run through alineod, that's alineod's own
|
|
1624
|
+
* container. `alineo init` forwards whichever of these are set in the operator's shell into
|
|
1625
|
+
* that container so any Pi-supported model works, not just NVIDIA's free tier.
|
|
1626
|
+
*
|
|
1627
|
+
* Deliberately excludes ambient/file-based credential mechanisms (AWS IAM role chains,
|
|
1628
|
+
* `AWS_PROFILE`, Google Application Default Credentials) — those need a mounted file or
|
|
1629
|
+
* assumed-role wiring, not just a passed-through env var. Amazon Bedrock and Google Vertex
|
|
1630
|
+
* are not yet supported by `init`'s auto-start for that reason.
|
|
1631
|
+
*
|
|
1632
|
+
* Keep in sync with pi's `env-api-keys.ts` `envMap` as it adds providers.
|
|
1633
|
+
*/
|
|
1634
|
+
const PI_MODEL_API_KEY_ENV_VARS = [
|
|
1635
|
+
"ANTHROPIC_API_KEY",
|
|
1636
|
+
"ANTHROPIC_OAUTH_TOKEN",
|
|
1637
|
+
"ANTHROPIC_AUTH_TOKEN",
|
|
1638
|
+
"OPENAI_API_KEY",
|
|
1639
|
+
"AZURE_OPENAI_API_KEY",
|
|
1640
|
+
"GEMINI_API_KEY",
|
|
1641
|
+
"NVIDIA_API_KEY",
|
|
1642
|
+
"DEEPSEEK_API_KEY",
|
|
1643
|
+
"MISTRAL_API_KEY",
|
|
1644
|
+
"GROQ_API_KEY",
|
|
1645
|
+
"CEREBRAS_API_KEY",
|
|
1646
|
+
"XAI_API_KEY",
|
|
1647
|
+
"OPENROUTER_API_KEY",
|
|
1648
|
+
"AI_GATEWAY_API_KEY",
|
|
1649
|
+
"CLOUDFLARE_API_KEY",
|
|
1650
|
+
"CLOUDFLARE_ACCOUNT_ID",
|
|
1651
|
+
"CLOUDFLARE_GATEWAY_ID",
|
|
1652
|
+
"RADIUS_API_KEY",
|
|
1653
|
+
"OPENCODE_API_KEY",
|
|
1654
|
+
"QWEN_TOKEN_PLAN_API_KEY",
|
|
1655
|
+
"QWEN_TOKEN_PLAN_CN_API_KEY",
|
|
1656
|
+
"MOONSHOT_API_KEY",
|
|
1657
|
+
"KIMI_API_KEY",
|
|
1658
|
+
"ZAI_API_KEY",
|
|
1659
|
+
"ZAI_CODING_CN_API_KEY",
|
|
1660
|
+
"MINIMAX_API_KEY",
|
|
1661
|
+
"MINIMAX_CN_API_KEY",
|
|
1662
|
+
"XIAOMI_API_KEY",
|
|
1663
|
+
"XIAOMI_TOKEN_PLAN_CN_API_KEY",
|
|
1664
|
+
"XIAOMI_TOKEN_PLAN_AMS_API_KEY",
|
|
1665
|
+
"XIAOMI_TOKEN_PLAN_SGP_API_KEY",
|
|
1666
|
+
"ANT_LING_API_KEY",
|
|
1667
|
+
"HF_TOKEN",
|
|
1668
|
+
"FIREWORKS_API_KEY",
|
|
1669
|
+
"TOGETHER_API_KEY",
|
|
1670
|
+
"BASETEN_API_KEY",
|
|
1671
|
+
"COPILOT_GITHUB_TOKEN"
|
|
1672
|
+
];
|
|
1673
|
+
/**
|
|
1674
|
+
* `alineo init` / `init` — starts OpenSandbox + alineod locally via Docker and writes
|
|
1675
|
+
* `alineo.config.json`. Shared verbatim by `alineo-cli` (`packages/cli/src/commands/init.ts`,
|
|
1676
|
+
* which logs to stdout) and `alineo-mcp` (`packages/mcp/src/init.ts`, which collects a log array
|
|
1677
|
+
* instead — an MCP stdio server's stdout is the JSON-RPC channel, so tool handlers must never
|
|
1678
|
+
* `console.log`) via the injectable `log` callback, so the two can never drift apart the way two
|
|
1679
|
+
* hand-copied files did before.
|
|
1680
|
+
*/
|
|
1681
|
+
const OPENSANDBOX_CONTAINER_NAME = "alineo-opensandbox";
|
|
1682
|
+
const OPENSANDBOX_IMAGE = "opensandbox/server:latest";
|
|
1683
|
+
const SERVER_URL = "http://127.0.0.1:8080";
|
|
1684
|
+
const ALINEOD_CONTAINER_NAME = "alineo-alineod";
|
|
1685
|
+
const ALINEOD_IMAGE = "ghcr.io/drejt/alineod:latest";
|
|
1686
|
+
const ALINEOD_URL = "http://127.0.0.1:4600";
|
|
1687
|
+
const isAlineodHealthy = (body) => body?.ok === true;
|
|
1688
|
+
const HOST_DOCKER_INTERNAL_SERVER_URL = "http://host.docker.internal:8080";
|
|
1689
|
+
/**
|
|
1690
|
+
* Both containers come back after a reboot or a Docker daemon restart. Without this, a host
|
|
1691
|
+
* reboot left OpenSandbox down, so nothing worked until someone ran `init` again — and alineod's
|
|
1692
|
+
* crash recovery only helps if something restarts alineod. `unless-stopped` rather than
|
|
1693
|
+
* `always`, so a deliberate `docker stop` sticks.
|
|
1694
|
+
*/
|
|
1695
|
+
const RESTART_ARGS = ["--restart", "unless-stopped"];
|
|
1696
|
+
/**
|
|
1697
|
+
* `--network host` (which makes alineod see `127.0.0.1` exactly as the host does, matching
|
|
1698
|
+
* OpenSandbox's configured `eip` — see `ensureAlineod`'s doc comment) only works out of the box
|
|
1699
|
+
* on native Linux Docker. Docker Desktop for Windows/Mac ships it behind an opt-in "Enable host
|
|
1700
|
+
* networking" setting nothing here can safely toggle (no stable, documented way to flip it and
|
|
1701
|
+
* restart Docker Desktop from a CLI); without it, `--network host` containers report "running"
|
|
1702
|
+
* but publish no ports the host can reach at all (see the `isReachable` probe below, which is
|
|
1703
|
+
* exactly what catches this class of failure). Keying off `process.platform` instead of probing
|
|
1704
|
+
* Docker's own networking capabilities is a heuristic, not a guarantee (e.g. Docker Desktop for
|
|
1705
|
+
* Linux may behave like Windows/Mac here too) — but it matches how the overwhelming majority of
|
|
1706
|
+
* each platform's users actually run Docker. `ensureAlineod` backs this guess with a live
|
|
1707
|
+
* reachability probe and falls back to bridge networking on the spot if it's wrong, so a bad
|
|
1708
|
+
* guess self-heals instead of leaving alineod permanently unreachable.
|
|
1709
|
+
*/
|
|
1710
|
+
const usesHostNetworking = process.platform !== "win32" && process.platform !== "darwin";
|
|
1711
|
+
async function runInit(log) {
|
|
1712
|
+
log("Checking Docker...");
|
|
1713
|
+
await checkDocker();
|
|
1714
|
+
const openSandboxConfigChanged = await ensureServerConfig();
|
|
1715
|
+
const hostIpAdded = await ensureServerHostIp();
|
|
1716
|
+
await ensureServerDataDir();
|
|
1717
|
+
let state = await getContainerState(OPENSANDBOX_CONTAINER_NAME);
|
|
1718
|
+
if (hostIpAdded && state !== "missing") {
|
|
1719
|
+
log("OpenSandbox config gained host_ip — recreating the container to match...");
|
|
1720
|
+
await removeContainer(OPENSANDBOX_CONTAINER_NAME);
|
|
1721
|
+
state = "missing";
|
|
1722
|
+
}
|
|
1723
|
+
if (state === "running") {
|
|
1724
|
+
if (openSandboxConfigChanged) {
|
|
1725
|
+
log("OpenSandbox networking config changed — restarting to apply it...");
|
|
1726
|
+
await restartContainer(OPENSANDBOX_CONTAINER_NAME);
|
|
1727
|
+
log("Waiting for OpenSandbox to be ready...");
|
|
1728
|
+
await pollHealth(`${SERVER_URL}/health`);
|
|
1729
|
+
} else log(`OpenSandbox already running at ${SERVER_URL}`);
|
|
1730
|
+
} else if (state === "stopped") {
|
|
1731
|
+
log("Restarting OpenSandbox container...");
|
|
1732
|
+
await startContainer(OPENSANDBOX_CONTAINER_NAME);
|
|
1733
|
+
log("Waiting for OpenSandbox to be ready...");
|
|
1734
|
+
await pollHealth(`${SERVER_URL}/health`);
|
|
1735
|
+
} else {
|
|
1736
|
+
log(`Pulling ${OPENSANDBOX_IMAGE}...`);
|
|
1737
|
+
await pullImage(OPENSANDBOX_IMAGE);
|
|
1738
|
+
log("Starting OpenSandbox in Docker...");
|
|
1739
|
+
await runContainer([
|
|
1740
|
+
"-d",
|
|
1741
|
+
"--name",
|
|
1742
|
+
OPENSANDBOX_CONTAINER_NAME,
|
|
1743
|
+
...RESTART_ARGS,
|
|
1744
|
+
"-p",
|
|
1745
|
+
"8080:8080",
|
|
1746
|
+
"--add-host",
|
|
1747
|
+
"host.docker.internal:host-gateway",
|
|
1748
|
+
"-v",
|
|
1749
|
+
"/var/run/docker.sock:/var/run/docker.sock",
|
|
1750
|
+
"-v",
|
|
1751
|
+
`${serverConfigPath()}:/etc/opensandbox/config.toml:ro`,
|
|
1752
|
+
"-v",
|
|
1753
|
+
`${serverDataDir()}:/data`,
|
|
1754
|
+
"-e",
|
|
1755
|
+
"SANDBOX_CONFIG_PATH=/etc/opensandbox/config.toml",
|
|
1756
|
+
"-e",
|
|
1757
|
+
"OPENSANDBOX_INSECURE_SERVER=YES",
|
|
1758
|
+
OPENSANDBOX_IMAGE
|
|
1759
|
+
], "OpenSandbox container");
|
|
1760
|
+
log("Waiting for OpenSandbox to be ready...");
|
|
1761
|
+
await pollHealth(`${SERVER_URL}/health`);
|
|
1762
|
+
}
|
|
1763
|
+
await ensureAlineod(log, openSandboxConfigChanged);
|
|
1764
|
+
await setRestartPolicy(OPENSANDBOX_CONTAINER_NAME, "unless-stopped");
|
|
1765
|
+
await setRestartPolicy(ALINEOD_CONTAINER_NAME, "unless-stopped");
|
|
1766
|
+
await ensureProjectConfig(log);
|
|
1767
|
+
log(`OpenSandbox running at ${SERVER_URL}, alineod running at ${ALINEOD_URL} — ready.`);
|
|
1768
|
+
return {
|
|
1769
|
+
serverUrl: SERVER_URL,
|
|
1770
|
+
alineodUrl: ALINEOD_URL
|
|
1771
|
+
};
|
|
1772
|
+
}
|
|
1773
|
+
/**
|
|
1774
|
+
* alineod needs to reach OpenSandbox at the same address OpenSandbox's own configured `eip`
|
|
1775
|
+
* uses — that's what it hands back in every sandbox proxy URL (`{eip}/sandboxes/{id}/proxy/{port}`,
|
|
1776
|
+
* see `apps/alineod/README.md`'s "Networking caveat"), and alineod follows those literally.
|
|
1777
|
+
*
|
|
1778
|
+
* - **Linux**: `--network host` puts alineod's `127.0.0.1` in the same namespace as the host's,
|
|
1779
|
+
* matching `eip` (`SERVER_URL`, `ensureServerConfig` below) exactly — same as a bare `bun run
|
|
1780
|
+
* start` would see. No extra port publishing needed; alineod's own port is already the host's.
|
|
1781
|
+
* - **Windows/Mac (Docker Desktop)**: `--network host` doesn't publish container ports to the
|
|
1782
|
+
* host at all without a setting this can't safely flip (see `usesHostNetworking`'s doc
|
|
1783
|
+
* comment) — every ALINEOD_URL health check would time out, exactly what motivated this split.
|
|
1784
|
+
* Instead alineod stays on the default bridge network with an explicit `-p 4600:4600` (so the
|
|
1785
|
+
* host can reach *it*) and reaches OpenSandbox via `host.docker.internal`, which Docker
|
|
1786
|
+
* Desktop resolves to the host on every container regardless of network mode — no host
|
|
1787
|
+
* networking feature required. `ensureServerConfig` sets OpenSandbox's `eip` to the same
|
|
1788
|
+
* `host.docker.internal` address so alineod can also follow the proxy URLs it hands back.
|
|
1789
|
+
* Trade-off: a host-based client talking to *this same* OpenSandbox instance directly (not
|
|
1790
|
+
* through alineod) can no longer follow those proxy URLs either, since the host itself can't
|
|
1791
|
+
* reliably resolve `host.docker.internal` back to itself (Windows routes it via the LAN
|
|
1792
|
+
* interface, which most local networks don't hairpin NAT back to the same machine) — use `uvx
|
|
1793
|
+
* opensandbox-server` instead for that case (see the root CLAUDE.md's "Local OpenSandbox
|
|
1794
|
+
* setup").
|
|
1795
|
+
*/
|
|
1796
|
+
async function ensureAlineod(log, openSandboxConfigChanged) {
|
|
1797
|
+
const state = await getContainerState(ALINEOD_CONTAINER_NAME);
|
|
1798
|
+
if (state !== "missing" && openSandboxConfigChanged) {
|
|
1799
|
+
log("OpenSandbox networking config changed — recreating alineod to match...");
|
|
1800
|
+
await removeContainer(ALINEOD_CONTAINER_NAME);
|
|
1801
|
+
} else if (state === "running") {
|
|
1802
|
+
if (await isReachable(`http://127.0.0.1:4600/health`, isAlineodHealthy)) {
|
|
1803
|
+
log(`alineod already running at ${ALINEOD_URL}`);
|
|
1804
|
+
return;
|
|
1805
|
+
}
|
|
1806
|
+
log("alineod is running but not reachable — recreating it...");
|
|
1807
|
+
await removeContainer(ALINEOD_CONTAINER_NAME);
|
|
1808
|
+
} else if (state === "stopped") {
|
|
1809
|
+
log("Restarting alineod container...");
|
|
1810
|
+
await startContainer(ALINEOD_CONTAINER_NAME);
|
|
1811
|
+
log("Waiting for alineod to be ready...");
|
|
1812
|
+
await pollHealth(`${ALINEOD_URL}/health`, 6e4, isAlineodHealthy);
|
|
1813
|
+
return;
|
|
1814
|
+
}
|
|
1815
|
+
log(`Pulling ${ALINEOD_IMAGE}...`);
|
|
1816
|
+
await pullImage(ALINEOD_IMAGE);
|
|
1817
|
+
const foundModelKeys = PI_MODEL_API_KEY_ENV_VARS.filter((name) => process.env[name]);
|
|
1818
|
+
const modelKeyArgs = foundModelKeys.flatMap((name) => ["-e", `${name}=${process.env[name]}`]);
|
|
1819
|
+
if (foundModelKeys.length > 0) log(`Forwarding model key(s): ${foundModelKeys.join(", ")}`);
|
|
1820
|
+
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).");
|
|
1821
|
+
log("Starting alineod in Docker...");
|
|
1822
|
+
await startAlineodContainer(usesHostNetworking, modelKeyArgs);
|
|
1823
|
+
log("Waiting for alineod to be ready...");
|
|
1824
|
+
if (usesHostNetworking && !await isReachable(`http://127.0.0.1:4600/health`, isAlineodHealthy)) {
|
|
1825
|
+
log("alineod isn't reachable over host networking on this Docker install — falling back to bridge networking + host.docker.internal...");
|
|
1826
|
+
await removeContainer(ALINEOD_CONTAINER_NAME);
|
|
1827
|
+
if (await ensureServerEip("http://host.docker.internal:8080")) {
|
|
1828
|
+
log("OpenSandbox eip changed to match — restarting to apply it...");
|
|
1829
|
+
await restartContainer(OPENSANDBOX_CONTAINER_NAME);
|
|
1830
|
+
await pollHealth(`${SERVER_URL}/health`);
|
|
1831
|
+
}
|
|
1832
|
+
await startAlineodContainer(false, modelKeyArgs);
|
|
1833
|
+
}
|
|
1834
|
+
await pollHealth(`${ALINEOD_URL}/health`, 6e4, isAlineodHealthy);
|
|
1835
|
+
}
|
|
1836
|
+
function startAlineodContainer(useHostNetworking, modelKeyArgs) {
|
|
1837
|
+
const networkArgs = useHostNetworking ? ["--network", "host"] : [
|
|
1838
|
+
"-p",
|
|
1839
|
+
"4600:4600",
|
|
1840
|
+
"--add-host",
|
|
1841
|
+
"host.docker.internal:host-gateway"
|
|
1842
|
+
];
|
|
1843
|
+
const alineodServerUrl = useHostNetworking ? SERVER_URL : HOST_DOCKER_INTERNAL_SERVER_URL;
|
|
1844
|
+
return runContainer([
|
|
1845
|
+
"-d",
|
|
1846
|
+
"--name",
|
|
1847
|
+
ALINEOD_CONTAINER_NAME,
|
|
1848
|
+
...RESTART_ARGS,
|
|
1849
|
+
...networkArgs,
|
|
1850
|
+
"-e",
|
|
1851
|
+
`ALINEO_SERVER_URL=${alineodServerUrl}`,
|
|
1852
|
+
"-e",
|
|
1853
|
+
"ALINEO_USE_SERVER_PROXY=true",
|
|
1854
|
+
...modelKeyArgs,
|
|
1855
|
+
"-v",
|
|
1856
|
+
"alineod-data:/data",
|
|
1857
|
+
ALINEOD_IMAGE
|
|
1858
|
+
], "alineod container");
|
|
1859
|
+
}
|
|
1860
|
+
/** Ensures `server.toml`'s `eip` matches what this platform needs (see `ensureAlineod`'s doc
|
|
1861
|
+
* comment) — returns whether it changed, so callers can restart whatever already-running
|
|
1862
|
+
* containers depend on it. */
|
|
1863
|
+
async function ensureServerConfig() {
|
|
1864
|
+
const dir = serverConfigDir();
|
|
1865
|
+
if (!existsSync(dir)) await mkdir(dir, { recursive: true });
|
|
1866
|
+
return ensureServerEip(usesHostNetworking ? SERVER_URL : HOST_DOCKER_INTERNAL_SERVER_URL);
|
|
1867
|
+
}
|
|
1868
|
+
/**
|
|
1869
|
+
* Creates `server.toml` from the default template if it doesn't exist yet, or otherwise patches
|
|
1870
|
+
* only its `eip = "..."` line in place — the rest of an existing file is left untouched, since
|
|
1871
|
+
* its own header comments invite hand-editing it for `networkPolicy`/`credentialProxy`/egress
|
|
1872
|
+
* tuning, and clobbering that on every `init` would silently discard it. Returns whether the eip
|
|
1873
|
+
* actually changed.
|
|
1874
|
+
*/
|
|
1875
|
+
async function ensureServerEip(eip) {
|
|
1876
|
+
const path = serverConfigPath();
|
|
1877
|
+
if (!existsSync(path)) {
|
|
1878
|
+
await Bun.write(path, serverConfigContent(eip));
|
|
1879
|
+
return true;
|
|
1880
|
+
}
|
|
1881
|
+
const existing = await Bun.file(path).text();
|
|
1882
|
+
const eipLine = /^eip\s*=\s*"([^"]*)"/m;
|
|
1883
|
+
if (existing.match(eipLine)?.[1] === eip) return false;
|
|
1884
|
+
const updated = eipLine.test(existing) ? existing.replace(eipLine, `eip = "${eip}"`) : existing.replace(/^\[server\]/m, `[server]\neip = "${eip}"`);
|
|
1885
|
+
await Bun.write(path, updated);
|
|
1886
|
+
return true;
|
|
1887
|
+
}
|
|
1888
|
+
/**
|
|
1889
|
+
* Adds `[docker].host_ip` to a `server.toml` written before `init` set it (see `DOCKER_HOST_IP`).
|
|
1890
|
+
* A fresh file already has it from `serverConfigContent`. Returns whether the file changed.
|
|
1891
|
+
*/
|
|
1892
|
+
async function ensureServerHostIp() {
|
|
1893
|
+
const path = serverConfigPath();
|
|
1894
|
+
const updated = withDockerHostIp(await Bun.file(path).text());
|
|
1895
|
+
if (updated === null) return false;
|
|
1896
|
+
await Bun.write(path, updated);
|
|
1897
|
+
return true;
|
|
1898
|
+
}
|
|
1899
|
+
/**
|
|
1900
|
+
* Host-side half of the `serverDataDir()` bind mount. `docker run -v` would auto-create
|
|
1901
|
+
* a missing host path anyway, but doing it explicitly here matches `ensureServerConfig()`'s
|
|
1902
|
+
* pattern and keeps directory creation in one place rather than relying on Docker's
|
|
1903
|
+
* legacy-`-v`-specific behavior (unlike `--mount`, which requires the source to pre-exist).
|
|
1904
|
+
*/
|
|
1905
|
+
async function ensureServerDataDir() {
|
|
1906
|
+
const dir = serverDataDir();
|
|
1907
|
+
if (!existsSync(dir)) await mkdir(dir, { recursive: true });
|
|
1908
|
+
}
|
|
1909
|
+
async function ensureProjectConfig(log) {
|
|
1910
|
+
if (!existsSync(configPath())) {
|
|
1911
|
+
await writeConfig({
|
|
1912
|
+
serverUrl: SERVER_URL,
|
|
1913
|
+
useServerProxy: true,
|
|
1914
|
+
apiKey: "",
|
|
1915
|
+
adapterPath: "./.alineo/ledger.db",
|
|
1916
|
+
agentsDir: "./agents",
|
|
1917
|
+
defaults: { resources: {
|
|
1918
|
+
cpu: "1000m",
|
|
1919
|
+
memory: "1Gi"
|
|
1920
|
+
} }
|
|
1921
|
+
});
|
|
1922
|
+
log("Created alineo.config.json");
|
|
1923
|
+
}
|
|
1924
|
+
}
|
|
263
1925
|
//#endregion
|
|
264
1926
|
//#region src/telemetry.ts
|
|
265
1927
|
/**
|
|
@@ -337,7 +1999,7 @@ async function sendTelemetryEvent(event, endpointUrl = process.env.ALINEO_TELEME
|
|
|
337
1999
|
/** Per-command allowlist of flags safe to record *presence of* -- never their values, never raw
|
|
338
2000
|
* argv. A flag not listed here is invisible to telemetry until someone deliberately adds it;
|
|
339
2001
|
* under-collecting is the only failure mode. Keys match each command's own `flag(argv, "--x")`/
|
|
340
|
-
* `argv.includes("--x")` calls (see commands/
|
|
2002
|
+
* `argv.includes("--x")` calls (see commands/start.ts, spawn.ts, prompt.ts, agents.ts, logs.ts). */
|
|
341
2003
|
const FLAG_ALLOWLIST = {
|
|
342
2004
|
spawn: [
|
|
343
2005
|
"--prompt",
|
|
@@ -425,7 +2087,7 @@ async function withTelemetry(commandName, argv, run) {
|
|
|
425
2087
|
errorClass = errorClassOf(err);
|
|
426
2088
|
throw err;
|
|
427
2089
|
} finally {
|
|
428
|
-
const { version } = await import("./package-
|
|
2090
|
+
const { version } = await import("./package-Bp80ZVLp.mjs");
|
|
429
2091
|
await sendTelemetryEvent({
|
|
430
2092
|
command: commandName,
|
|
431
2093
|
flags,
|
|
@@ -450,7 +2112,7 @@ async function recordTuiLaunch() {
|
|
|
450
2112
|
const config = await readTelemetryConfig();
|
|
451
2113
|
if (!config.enabled) return;
|
|
452
2114
|
await maybePrintFirstRunNotice(config);
|
|
453
|
-
const { version } = await import("./package-
|
|
2115
|
+
const { version } = await import("./package-Bp80ZVLp.mjs");
|
|
454
2116
|
await sendTelemetryEvent({
|
|
455
2117
|
command: "tui",
|
|
456
2118
|
flags: {},
|
|
@@ -467,15 +2129,15 @@ async function recordTuiLaunch() {
|
|
|
467
2129
|
//#endregion
|
|
468
2130
|
//#region src/index.ts
|
|
469
2131
|
const [, , cmd, ...argv] = process.argv;
|
|
470
|
-
const HELP_NOTES = ` Add --json to
|
|
471
|
-
Add --depth <n> to spawn
|
|
472
|
-
nesting-depth budget for further
|
|
473
|
-
Add --max <n> to spawn
|
|
2132
|
+
const HELP_NOTES = ` Add --json to start/prompt/spawn/agents/logs for machine-readable output.
|
|
2133
|
+
Add --depth <n> to start/spawn to override the spec's "spawnDepth" — the
|
|
2134
|
+
nesting-depth budget for further spawns.
|
|
2135
|
+
Add --max <n> to start/spawn to override the spec's "maxAgents" — a separate,
|
|
474
2136
|
optional ceiling on total descendants for this lineage (not coordinated
|
|
475
2137
|
across sibling branches spawned in parallel).
|
|
476
2138
|
Add --spec <path> to prompt to skip the ledger lookup for the spec file
|
|
477
2139
|
(needed when the sandbox's own creation event lives in a different ledger,
|
|
478
|
-
e.g. a child spawned via 'alineo
|
|
2140
|
+
e.g. a child spawned via 'alineo spawn' from inside another sandbox).`;
|
|
479
2141
|
const GROUPS = [{
|
|
480
2142
|
key: "sdk",
|
|
481
2143
|
label: "SDK — OpenSandbox config and the local spec cache:"
|
|
@@ -498,17 +2160,18 @@ function printHelp() {
|
|
|
498
2160
|
async function main() {
|
|
499
2161
|
if (!cmd && process.stdout.isTTY) {
|
|
500
2162
|
await recordTuiLaunch();
|
|
501
|
-
const { launchTui } = await import("./tui-
|
|
2163
|
+
const { launchTui } = await import("./tui-sV-uyFWI.mjs");
|
|
502
2164
|
await launchTui();
|
|
503
2165
|
return;
|
|
504
2166
|
}
|
|
505
2167
|
if (cmd === "--version" || cmd === "-v" || cmd === "version") {
|
|
506
|
-
const { version } = await import("./package-
|
|
2168
|
+
const { version } = await import("./package-Bp80ZVLp.mjs");
|
|
507
2169
|
console.log(version);
|
|
508
2170
|
return;
|
|
509
2171
|
}
|
|
510
2172
|
const found = commands.find((c) => c.name === cmd);
|
|
511
2173
|
if (found) {
|
|
2174
|
+
installLoggerFromEnv({ defaultLevel: "info" });
|
|
512
2175
|
await withTelemetry(found.name, argv, () => found.run(argv));
|
|
513
2176
|
process.exit(0);
|
|
514
2177
|
}
|
|
@@ -520,4 +2183,4 @@ main().catch((err) => {
|
|
|
520
2183
|
process.exit(1);
|
|
521
2184
|
});
|
|
522
2185
|
//#endregion
|
|
523
|
-
export {
|
|
2186
|
+
export { runInit as a, readConfig as i, readTelemetryConfig as n, writeTelemetryConfig as r, envDisabled as t };
|