alineo-cli 0.3.0 → 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-B6Xmz48s.mjs → add-BdM-DRC1.mjs} +1 -1
- package/dist/{agents-T17zA9p-.mjs → agents-CC5ZirAu.mjs} +2 -2
- package/dist/index.mjs +1349 -71
- package/dist/{list-F4RrPUBT.mjs → list-D0m4Llsl.mjs} +3 -3
- package/dist/{package-oshZF9Gd.mjs → package-Bp80ZVLp.mjs} +1 -1
- package/dist/{prompt-DoeWivoE.mjs → prompt-DBQLJudG.mjs} +2 -2
- package/dist/{sessions-data-C8XZge-w.mjs → sessions-data-CceSi5Jz.mjs} +1 -1
- package/dist/{fork-Bl-31vNc.mjs → spawn-_Q1KNp_T.mjs} +21 -21
- package/dist/{spawn-BRFkN-5J.mjs → start-Ba4NiDWn.mjs} +14 -14
- package/dist/{steer-B15HpNnn.mjs → steer-NAX3xw09.mjs} +4 -4
- package/dist/{kill-01oM3F4x.mjs → stop-CvyZQHIf.mjs} +10 -10
- package/dist/{tui-CFEiWbe1.mjs → tui-sV-uyFWI.mjs} +9 -9
- package/package.json +7 -6
- package/pi-extension/alineo.ts +41 -40
package/dist/index.mjs
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
import { installLoggerFromEnv } from "@alineo-labs/logger";
|
|
3
|
-
import { join } from "node:path";
|
|
3
|
+
import { dirname, join, resolve } from "node:path";
|
|
4
4
|
import { join as join$1 } from "path";
|
|
5
5
|
import { homedir } from "os";
|
|
6
6
|
import { existsSync } from "fs";
|
|
7
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";
|
|
8
12
|
//#region src/commands/registry.ts
|
|
9
13
|
/**
|
|
10
14
|
* Every alineo subcommand's name/group/usage/summary, plus a `run` that dynamically
|
|
@@ -19,7 +23,10 @@ import { mkdir } from "fs/promises";
|
|
|
19
23
|
* the switch statement's actual behavior with no visual signal at all.
|
|
20
24
|
*
|
|
21
25
|
* Adding a command: create the command file with its own `xCommand` export (see
|
|
22
|
-
* 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.
|
|
23
30
|
*/
|
|
24
31
|
const commands = [
|
|
25
32
|
{
|
|
@@ -38,7 +45,7 @@ const commands = [
|
|
|
38
45
|
usage: "alineo add <url> [--name <n>]",
|
|
39
46
|
summary: "Fetch and save an agent spec locally"
|
|
40
47
|
}],
|
|
41
|
-
run: async (argv) => (await import("./add-
|
|
48
|
+
run: async (argv) => (await import("./add-BdM-DRC1.mjs")).addCommand.run(argv)
|
|
42
49
|
},
|
|
43
50
|
{
|
|
44
51
|
name: "list",
|
|
@@ -47,7 +54,7 @@ const commands = [
|
|
|
47
54
|
usage: "alineo list",
|
|
48
55
|
summary: "List saved agent specs"
|
|
49
56
|
}],
|
|
50
|
-
run: async (argv) => (await import("./list-
|
|
57
|
+
run: async (argv) => (await import("./list-D0m4Llsl.mjs")).listCommand.run(argv)
|
|
51
58
|
},
|
|
52
59
|
{
|
|
53
60
|
name: "remove",
|
|
@@ -59,16 +66,16 @@ const commands = [
|
|
|
59
66
|
run: async (argv) => (await import("./remove-B_721tl2.mjs")).removeCommand.run(argv)
|
|
60
67
|
},
|
|
61
68
|
{
|
|
62
|
-
name: "
|
|
69
|
+
name: "start",
|
|
63
70
|
group: "agent",
|
|
64
71
|
variants: [{
|
|
65
|
-
usage: "alineo
|
|
72
|
+
usage: "alineo start <spec>",
|
|
66
73
|
summary: "Start a fresh agent sandbox, print its name, exit"
|
|
67
74
|
}, {
|
|
68
|
-
usage: "alineo
|
|
75
|
+
usage: "alineo start <spec> --prompt <msg>",
|
|
69
76
|
summary: "Start it, send one prompt, print the reply, exit"
|
|
70
77
|
}],
|
|
71
|
-
run: async (argv) => (await import("./
|
|
78
|
+
run: async (argv) => (await import("./start-Ba4NiDWn.mjs")).startCommand.run(argv)
|
|
72
79
|
},
|
|
73
80
|
{
|
|
74
81
|
name: "prompt",
|
|
@@ -77,16 +84,16 @@ const commands = [
|
|
|
77
84
|
usage: "alineo prompt <sandbox-id> <msg>",
|
|
78
85
|
summary: "Send one prompt to a running sandbox, print the reply"
|
|
79
86
|
}],
|
|
80
|
-
run: async (argv) => (await import("./prompt-
|
|
87
|
+
run: async (argv) => (await import("./prompt-DBQLJudG.mjs")).promptCommand.run(argv)
|
|
81
88
|
},
|
|
82
89
|
{
|
|
83
|
-
name: "
|
|
90
|
+
name: "spawn",
|
|
84
91
|
group: "agent",
|
|
85
92
|
variants: [{
|
|
86
|
-
usage: "alineo
|
|
87
|
-
summary: "
|
|
93
|
+
usage: "alineo spawn <parent> <child-spec>",
|
|
94
|
+
summary: "Spawn a child from a running session's own live sandbox"
|
|
88
95
|
}],
|
|
89
|
-
run: async (argv) => (await import("./
|
|
96
|
+
run: async (argv) => (await import("./spawn-_Q1KNp_T.mjs")).spawnCommand.run(argv)
|
|
90
97
|
},
|
|
91
98
|
{
|
|
92
99
|
name: "steer",
|
|
@@ -95,7 +102,7 @@ const commands = [
|
|
|
95
102
|
usage: "alineo steer <sandbox-id> <message>",
|
|
96
103
|
summary: "Redirect a running session — lands at its next turn boundary, not instantly"
|
|
97
104
|
}],
|
|
98
|
-
run: async (argv) => (await import("./steer-
|
|
105
|
+
run: async (argv) => (await import("./steer-NAX3xw09.mjs")).steerCommand.run(argv)
|
|
99
106
|
},
|
|
100
107
|
{
|
|
101
108
|
name: "agents",
|
|
@@ -104,16 +111,16 @@ const commands = [
|
|
|
104
111
|
usage: "alineo agents [--json]",
|
|
105
112
|
summary: "List running agent sessions"
|
|
106
113
|
}],
|
|
107
|
-
run: async (argv) => (await import("./agents-
|
|
114
|
+
run: async (argv) => (await import("./agents-CC5ZirAu.mjs")).agentsCommand.run(argv)
|
|
108
115
|
},
|
|
109
116
|
{
|
|
110
|
-
name: "
|
|
117
|
+
name: "stop",
|
|
111
118
|
group: "agent",
|
|
112
119
|
variants: [{
|
|
113
|
-
usage: "alineo
|
|
120
|
+
usage: "alineo stop <sandbox-id>",
|
|
114
121
|
summary: "Stop a sandbox"
|
|
115
122
|
}],
|
|
116
|
-
run: async (argv) => (await import("./
|
|
123
|
+
run: async (argv) => (await import("./stop-CvyZQHIf.mjs")).stopCommand.run(argv)
|
|
117
124
|
},
|
|
118
125
|
{
|
|
119
126
|
name: "logs",
|
|
@@ -145,6 +152,1220 @@ const commands = [
|
|
|
145
152
|
}
|
|
146
153
|
];
|
|
147
154
|
//#endregion
|
|
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
|
|
148
1369
|
//#region ../cli-shared/dist/index.mjs
|
|
149
1370
|
async function spawn(cmd) {
|
|
150
1371
|
let proc;
|
|
@@ -212,6 +1433,20 @@ async function removeContainer(name) {
|
|
|
212
1433
|
]);
|
|
213
1434
|
if (!ok) throw new Error(`Failed to remove container '${name}': ${stderr.trim()}`);
|
|
214
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
|
+
}
|
|
215
1450
|
async function runContainer(args, label = "container") {
|
|
216
1451
|
const { ok, stderr } = await spawn([
|
|
217
1452
|
"docker",
|
|
@@ -256,53 +1491,42 @@ async function isReachable(url, isHealthy, timeoutMs = 1e4) {
|
|
|
256
1491
|
}
|
|
257
1492
|
}
|
|
258
1493
|
const CONFIG_DIR = ".alineo";
|
|
259
|
-
const CONFIG_FILE = "alineo.config.json";
|
|
260
1494
|
function configPath() {
|
|
261
|
-
return
|
|
1495
|
+
return PROJECT_CONFIG_FILE;
|
|
262
1496
|
}
|
|
263
1497
|
function globalConfigPath() {
|
|
264
1498
|
return join$1(serverConfigDir(), "config.json");
|
|
265
1499
|
}
|
|
266
|
-
function fillDefaults(data) {
|
|
267
|
-
return {
|
|
268
|
-
serverUrl: data.serverUrl ?? "http://127.0.0.1:8080",
|
|
269
|
-
useServerProxy: data.useServerProxy ?? true,
|
|
270
|
-
apiKey: data.apiKey ?? "",
|
|
271
|
-
adapterPath: data.adapterPath ?? "./.alineo/ledger.db",
|
|
272
|
-
agentsDir: data.agentsDir ?? "./agents",
|
|
273
|
-
defaults: { resources: {
|
|
274
|
-
cpu: data.defaults?.resources?.cpu ?? "1000m",
|
|
275
|
-
memory: data.defaults?.resources?.memory ?? "1Gi"
|
|
276
|
-
} }
|
|
277
|
-
};
|
|
278
|
-
}
|
|
279
1500
|
/**
|
|
280
|
-
*
|
|
281
|
-
*
|
|
282
|
-
* `~/.config/alineo/config.json
|
|
283
|
-
*
|
|
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.
|
|
284
1512
|
*/
|
|
285
1513
|
async function readConfig() {
|
|
286
|
-
const
|
|
287
|
-
if (await localFile.exists()) return fillDefaults(await localFile.json());
|
|
1514
|
+
const hasProject = findProjectConfig() !== null;
|
|
288
1515
|
const globalPath = globalConfigPath();
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
};
|
|
304
|
-
await Bun.write(globalPath, JSON.stringify(config, null, 2) + "\n");
|
|
305
|
-
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 });
|
|
306
1530
|
}
|
|
307
1531
|
async function writeConfig(config) {
|
|
308
1532
|
if (!existsSync(CONFIG_DIR)) await mkdir(CONFIG_DIR, { recursive: true });
|
|
@@ -322,7 +1546,7 @@ function serverConfigPath() {
|
|
|
322
1546
|
* only as good as where the db file actually lives: without this mount, it sits in the
|
|
323
1547
|
* `alineo-opensandbox` container's own writable layer, so restart is fine but any time the
|
|
324
1548
|
* container itself is recreated (host reboot with no restart policy, `docker system prune`,
|
|
325
|
-
* 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()`
|
|
326
1550
|
* snapshot fast path pays a full cold rebuild next time, indistinguishable from a genuinely
|
|
327
1551
|
* changed spec (see issue #20). Bind-mounting this directory makes that data outlive the
|
|
328
1552
|
* container's own lifecycle, matching OpenSandbox's own intent.
|
|
@@ -339,6 +1563,26 @@ function serverDataDir() {
|
|
|
339
1563
|
* message itself suggests does not exist as a published tag. v1.0.22 is the latest.
|
|
340
1564
|
*/
|
|
341
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
|
+
/**
|
|
342
1586
|
* `egress.image`/`egress.mode` are configured unconditionally, not opt-in. Per OpenSandbox's
|
|
343
1587
|
* own control flow, a configured `egress.image` is inert for any sandbox created without a
|
|
344
1588
|
* `networkPolicy` — no sidecar is attached, no behavior changes for anyone not touching
|
|
@@ -360,6 +1604,7 @@ execd_image = "opensandbox/execd:v1.0.22"
|
|
|
360
1604
|
|
|
361
1605
|
[docker]
|
|
362
1606
|
network_mode = "bridge"
|
|
1607
|
+
host_ip = "${DOCKER_HOST_IP}"
|
|
363
1608
|
|
|
364
1609
|
[store]
|
|
365
1610
|
type = "sqlite"
|
|
@@ -375,7 +1620,7 @@ mode = "dns+nft"
|
|
|
375
1620
|
* `envMap` in earendil-works/pi's `packages/ai/src/env-api-keys.ts` (plus Anthropic's three,
|
|
376
1621
|
* handled separately there). An `AgentSpec`'s env map (`{ NVIDIA_API_KEY: "${NVIDIA_API_KEY}" }`,
|
|
377
1622
|
* see `packages/agent/src/schema.ts`) is resolved from `process.env` inside whatever process
|
|
378
|
-
* calls `Alineo.
|
|
1623
|
+
* calls `Alineo.start()`/`.spawn()` — for a swarm run through alineod, that's alineod's own
|
|
379
1624
|
* container. `alineo init` forwards whichever of these are set in the operator's shell into
|
|
380
1625
|
* that container so any Pi-supported model works, not just NVIDIA's free tier.
|
|
381
1626
|
*
|
|
@@ -426,7 +1671,7 @@ const PI_MODEL_API_KEY_ENV_VARS = [
|
|
|
426
1671
|
"COPILOT_GITHUB_TOKEN"
|
|
427
1672
|
];
|
|
428
1673
|
/**
|
|
429
|
-
* `alineo init` / `
|
|
1674
|
+
* `alineo init` / `init` — starts OpenSandbox + alineod locally via Docker and writes
|
|
430
1675
|
* `alineo.config.json`. Shared verbatim by `alineo-cli` (`packages/cli/src/commands/init.ts`,
|
|
431
1676
|
* which logs to stdout) and `alineo-mcp` (`packages/mcp/src/init.ts`, which collects a log array
|
|
432
1677
|
* instead — an MCP stdio server's stdout is the JSON-RPC channel, so tool handlers must never
|
|
@@ -434,6 +1679,7 @@ const PI_MODEL_API_KEY_ENV_VARS = [
|
|
|
434
1679
|
* hand-copied files did before.
|
|
435
1680
|
*/
|
|
436
1681
|
const OPENSANDBOX_CONTAINER_NAME = "alineo-opensandbox";
|
|
1682
|
+
const OPENSANDBOX_IMAGE = "opensandbox/server:latest";
|
|
437
1683
|
const SERVER_URL = "http://127.0.0.1:8080";
|
|
438
1684
|
const ALINEOD_CONTAINER_NAME = "alineo-alineod";
|
|
439
1685
|
const ALINEOD_IMAGE = "ghcr.io/drejt/alineod:latest";
|
|
@@ -441,6 +1687,13 @@ const ALINEOD_URL = "http://127.0.0.1:4600";
|
|
|
441
1687
|
const isAlineodHealthy = (body) => body?.ok === true;
|
|
442
1688
|
const HOST_DOCKER_INTERNAL_SERVER_URL = "http://host.docker.internal:8080";
|
|
443
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
|
+
/**
|
|
444
1697
|
* `--network host` (which makes alineod see `127.0.0.1` exactly as the host does, matching
|
|
445
1698
|
* OpenSandbox's configured `eip` — see `ensureAlineod`'s doc comment) only works out of the box
|
|
446
1699
|
* on native Linux Docker. Docker Desktop for Windows/Mac ships it behind an opt-in "Enable host
|
|
@@ -459,8 +1712,14 @@ async function runInit(log) {
|
|
|
459
1712
|
log("Checking Docker...");
|
|
460
1713
|
await checkDocker();
|
|
461
1714
|
const openSandboxConfigChanged = await ensureServerConfig();
|
|
1715
|
+
const hostIpAdded = await ensureServerHostIp();
|
|
462
1716
|
await ensureServerDataDir();
|
|
463
|
-
|
|
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
|
+
}
|
|
464
1723
|
if (state === "running") {
|
|
465
1724
|
if (openSandboxConfigChanged) {
|
|
466
1725
|
log("OpenSandbox networking config changed — restarting to apply it...");
|
|
@@ -474,13 +1733,18 @@ async function runInit(log) {
|
|
|
474
1733
|
log("Waiting for OpenSandbox to be ready...");
|
|
475
1734
|
await pollHealth(`${SERVER_URL}/health`);
|
|
476
1735
|
} else {
|
|
1736
|
+
log(`Pulling ${OPENSANDBOX_IMAGE}...`);
|
|
1737
|
+
await pullImage(OPENSANDBOX_IMAGE);
|
|
477
1738
|
log("Starting OpenSandbox in Docker...");
|
|
478
1739
|
await runContainer([
|
|
479
1740
|
"-d",
|
|
480
1741
|
"--name",
|
|
481
1742
|
OPENSANDBOX_CONTAINER_NAME,
|
|
1743
|
+
...RESTART_ARGS,
|
|
482
1744
|
"-p",
|
|
483
1745
|
"8080:8080",
|
|
1746
|
+
"--add-host",
|
|
1747
|
+
"host.docker.internal:host-gateway",
|
|
484
1748
|
"-v",
|
|
485
1749
|
"/var/run/docker.sock:/var/run/docker.sock",
|
|
486
1750
|
"-v",
|
|
@@ -491,12 +1755,14 @@ async function runInit(log) {
|
|
|
491
1755
|
"SANDBOX_CONFIG_PATH=/etc/opensandbox/config.toml",
|
|
492
1756
|
"-e",
|
|
493
1757
|
"OPENSANDBOX_INSECURE_SERVER=YES",
|
|
494
|
-
|
|
1758
|
+
OPENSANDBOX_IMAGE
|
|
495
1759
|
], "OpenSandbox container");
|
|
496
1760
|
log("Waiting for OpenSandbox to be ready...");
|
|
497
1761
|
await pollHealth(`${SERVER_URL}/health`);
|
|
498
1762
|
}
|
|
499
1763
|
await ensureAlineod(log, openSandboxConfigChanged);
|
|
1764
|
+
await setRestartPolicy(OPENSANDBOX_CONTAINER_NAME, "unless-stopped");
|
|
1765
|
+
await setRestartPolicy(ALINEOD_CONTAINER_NAME, "unless-stopped");
|
|
500
1766
|
await ensureProjectConfig(log);
|
|
501
1767
|
log(`OpenSandbox running at ${SERVER_URL}, alineod running at ${ALINEOD_URL} — ready.`);
|
|
502
1768
|
return {
|
|
@@ -579,6 +1845,7 @@ function startAlineodContainer(useHostNetworking, modelKeyArgs) {
|
|
|
579
1845
|
"-d",
|
|
580
1846
|
"--name",
|
|
581
1847
|
ALINEOD_CONTAINER_NAME,
|
|
1848
|
+
...RESTART_ARGS,
|
|
582
1849
|
...networkArgs,
|
|
583
1850
|
"-e",
|
|
584
1851
|
`ALINEO_SERVER_URL=${alineodServerUrl}`,
|
|
@@ -619,6 +1886,17 @@ async function ensureServerEip(eip) {
|
|
|
619
1886
|
return true;
|
|
620
1887
|
}
|
|
621
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
|
+
/**
|
|
622
1900
|
* Host-side half of the `serverDataDir()` bind mount. `docker run -v` would auto-create
|
|
623
1901
|
* a missing host path anyway, but doing it explicitly here matches `ensureServerConfig()`'s
|
|
624
1902
|
* pattern and keeps directory creation in one place rather than relying on Docker's
|
|
@@ -721,7 +1999,7 @@ async function sendTelemetryEvent(event, endpointUrl = process.env.ALINEO_TELEME
|
|
|
721
1999
|
/** Per-command allowlist of flags safe to record *presence of* -- never their values, never raw
|
|
722
2000
|
* argv. A flag not listed here is invisible to telemetry until someone deliberately adds it;
|
|
723
2001
|
* under-collecting is the only failure mode. Keys match each command's own `flag(argv, "--x")`/
|
|
724
|
-
* `argv.includes("--x")` calls (see commands/
|
|
2002
|
+
* `argv.includes("--x")` calls (see commands/start.ts, spawn.ts, prompt.ts, agents.ts, logs.ts). */
|
|
725
2003
|
const FLAG_ALLOWLIST = {
|
|
726
2004
|
spawn: [
|
|
727
2005
|
"--prompt",
|
|
@@ -809,7 +2087,7 @@ async function withTelemetry(commandName, argv, run) {
|
|
|
809
2087
|
errorClass = errorClassOf(err);
|
|
810
2088
|
throw err;
|
|
811
2089
|
} finally {
|
|
812
|
-
const { version } = await import("./package-
|
|
2090
|
+
const { version } = await import("./package-Bp80ZVLp.mjs");
|
|
813
2091
|
await sendTelemetryEvent({
|
|
814
2092
|
command: commandName,
|
|
815
2093
|
flags,
|
|
@@ -834,7 +2112,7 @@ async function recordTuiLaunch() {
|
|
|
834
2112
|
const config = await readTelemetryConfig();
|
|
835
2113
|
if (!config.enabled) return;
|
|
836
2114
|
await maybePrintFirstRunNotice(config);
|
|
837
|
-
const { version } = await import("./package-
|
|
2115
|
+
const { version } = await import("./package-Bp80ZVLp.mjs");
|
|
838
2116
|
await sendTelemetryEvent({
|
|
839
2117
|
command: "tui",
|
|
840
2118
|
flags: {},
|
|
@@ -851,15 +2129,15 @@ async function recordTuiLaunch() {
|
|
|
851
2129
|
//#endregion
|
|
852
2130
|
//#region src/index.ts
|
|
853
2131
|
const [, , cmd, ...argv] = process.argv;
|
|
854
|
-
const HELP_NOTES = ` Add --json to
|
|
855
|
-
Add --depth <n> to spawn
|
|
856
|
-
nesting-depth budget for further
|
|
857
|
-
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,
|
|
858
2136
|
optional ceiling on total descendants for this lineage (not coordinated
|
|
859
2137
|
across sibling branches spawned in parallel).
|
|
860
2138
|
Add --spec <path> to prompt to skip the ledger lookup for the spec file
|
|
861
2139
|
(needed when the sandbox's own creation event lives in a different ledger,
|
|
862
|
-
e.g. a child spawned via 'alineo
|
|
2140
|
+
e.g. a child spawned via 'alineo spawn' from inside another sandbox).`;
|
|
863
2141
|
const GROUPS = [{
|
|
864
2142
|
key: "sdk",
|
|
865
2143
|
label: "SDK — OpenSandbox config and the local spec cache:"
|
|
@@ -882,12 +2160,12 @@ function printHelp() {
|
|
|
882
2160
|
async function main() {
|
|
883
2161
|
if (!cmd && process.stdout.isTTY) {
|
|
884
2162
|
await recordTuiLaunch();
|
|
885
|
-
const { launchTui } = await import("./tui-
|
|
2163
|
+
const { launchTui } = await import("./tui-sV-uyFWI.mjs");
|
|
886
2164
|
await launchTui();
|
|
887
2165
|
return;
|
|
888
2166
|
}
|
|
889
2167
|
if (cmd === "--version" || cmd === "-v" || cmd === "version") {
|
|
890
|
-
const { version } = await import("./package-
|
|
2168
|
+
const { version } = await import("./package-Bp80ZVLp.mjs");
|
|
891
2169
|
console.log(version);
|
|
892
2170
|
return;
|
|
893
2171
|
}
|