@alineo-labs/schema 0.0.0-stage → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1190 @@
1
+ import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
2
+ import * as z$1 from "zod";
3
+ import { z } from "zod";
4
+ //#region src/vocabulary.ts
5
+ /**
6
+ * The two lists every alineo surface derives its names from.
7
+ *
8
+ * One user meets the CLI, the SDK, the daemon's HTTP API, the MCP tools and the event
9
+ * stream. Each of those is free to pick its own spelling, and historically each did — which
10
+ * is how `spawn` came to mean "create a root agent" in the CLI and "create a child" in the
11
+ * SDK, and how `fork` came to mean three different operations.
12
+ *
13
+ * Making the vocabulary *data* is what lets CI fail a name rather than a reviewer catch it.
14
+ * The checks that consume these lists land with the surfaces they police (CLI and help
15
+ * strings, MCP tools and HTTP routes, event types); this module is only the source of truth.
16
+ */
17
+ /**
18
+ * The things alineo acts on. A name's first segment is one of these.
19
+ *
20
+ * Ordered by layer rather than alphabetically — control plane, then the agent loop, then the
21
+ * substrate, then the operator-facing objects — because that is how the surfaces group.
22
+ *
23
+ * `event`, `result` and `transcript` are the records a run leaves behind. They joined the list
24
+ * when the HTTP and MCP checks landed and found them already on the wire
25
+ * (`GET /agents/:id/transcript`, `GET /runs/:id/events`): they were vocabulary in use, just not
26
+ * written down.
27
+ *
28
+ * `provider` joined with the `SandboxProvider` interface: the thing a sandbox runs on and is
29
+ * owned by (`sandbox.created` records which one). No event or route is named after it yet; it
30
+ * is registered so the first one is not a surprise.
31
+ *
32
+ * `memory` and `fact` joined with alineod's memory routes (`GET /agents/:id/memory`,
33
+ * `POST /agents/:id/facts`): `memory` is an agent's durable working memory, `fact` one item of
34
+ * its semantic memory.
35
+ */
36
+ const SUBJECTS = [
37
+ "run",
38
+ "agent",
39
+ "sandbox",
40
+ "provider",
41
+ "session",
42
+ "turn",
43
+ "message",
44
+ "tool",
45
+ "handle",
46
+ "wait",
47
+ "inbox",
48
+ "notify",
49
+ "budget",
50
+ "exec",
51
+ "egress",
52
+ "credential",
53
+ "permission",
54
+ "workflow",
55
+ "step",
56
+ "compaction",
57
+ "retry",
58
+ "extension",
59
+ "queue",
60
+ "spec",
61
+ "environment",
62
+ "event",
63
+ "result",
64
+ "transcript",
65
+ "memory",
66
+ "fact"
67
+ ];
68
+ /**
69
+ * What alineo does to a subject. A name's second segment is one of these — in the imperative
70
+ * for a command, method, route or tool, and in the past tense for an event (`agent.spawned`).
71
+ *
72
+ * `branchSession` and `duplicateSession` are camelCase because they exist only as SDK
73
+ * methods; no route, tool or event uses them. They carry `Session` in the name on purpose:
74
+ * unqualified `branch`/`duplicate` read like sandbox operations, and they are not — both stay
75
+ * inside one container and only touch the harness conversation.
76
+ */
77
+ const VERBS = [
78
+ "start",
79
+ "spawn",
80
+ "stop",
81
+ "pause",
82
+ "resume",
83
+ "reattach",
84
+ "attach",
85
+ "prompt",
86
+ "steer",
87
+ "await",
88
+ "checkpoint",
89
+ "fork",
90
+ "branchSession",
91
+ "duplicateSession",
92
+ "add",
93
+ "list",
94
+ "remove",
95
+ "get",
96
+ "watch",
97
+ "init",
98
+ "deliver"
99
+ ];
100
+ const SUBJECT_SET = new Set(SUBJECTS);
101
+ const VERB_SET = new Set(VERBS);
102
+ function isSubject(value) {
103
+ return SUBJECT_SET.has(value);
104
+ }
105
+ function isVerb(value) {
106
+ return VERB_SET.has(value);
107
+ }
108
+ /**
109
+ * Split a two-segment name into its subject and verb, or return `null` if either half is not
110
+ * in the lists above.
111
+ *
112
+ * The separator is what distinguishes the surfaces: `_` for an MCP tool (`agent_spawn`), `.`
113
+ * for an event type (`agent.spawned`). Only the first separator splits, so a multi-word verb
114
+ * stays intact.
115
+ *
116
+ * Note for the event check (Track 1): event verbs are past tense and so will not be in
117
+ * `VERBS` literally — `agent.spawned`, not `agent.spawn`. That check needs its own tense
118
+ * rule on top of `isSubject`; this helper is exact-match only.
119
+ */
120
+ function parseName(name, separator) {
121
+ const at = name.indexOf(separator);
122
+ if (at <= 0) return null;
123
+ const subject = name.slice(0, at);
124
+ const verb = name.slice(at + separator.length);
125
+ if (!isSubject(subject) || !isVerb(verb)) return null;
126
+ return {
127
+ subject,
128
+ verb
129
+ };
130
+ }
131
+ //#endregion
132
+ //#region src/define.ts
133
+ /**
134
+ * Every definition, by type. Populated as a side effect of `defineEvent`, which is why the
135
+ * event files must be imported for the registry to be complete — `index.ts` imports all five.
136
+ */
137
+ const registry = /* @__PURE__ */ new Map();
138
+ /** A `type` that is well-formed but whose subject is not in `SUBJECTS`. */
139
+ const TYPE_SHAPE = /^([a-z]+)\.([a-z][a-z_]*)$/;
140
+ function defineEvent(definition) {
141
+ const match = TYPE_SHAPE.exec(definition.type);
142
+ if (!match) throw new Error(`Event type "${definition.type}" is not "<subject>.<past_tense_verb>" in lower snake case.`);
143
+ 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.`);
144
+ const existing = registry.get(definition.type);
145
+ if (existing && existing !== definition) throw new Error(`Event type "${definition.type}" is defined twice.`);
146
+ registry.set(definition.type, definition);
147
+ return definition;
148
+ }
149
+ /** Every registered definition. Order is definition order, which is file order. */
150
+ function allEvents() {
151
+ return [...registry.values()];
152
+ }
153
+ function getEvent(type) {
154
+ return registry.get(type);
155
+ }
156
+ /** The subset that earns a ledger row. */
157
+ function durableEvents() {
158
+ return allEvents().filter((d) => d.durable);
159
+ }
160
+ //#endregion
161
+ //#region src/events/sandbox.ts
162
+ /**
163
+ * Substrate events — the sandbox itself, and what runs inside it.
164
+ *
165
+ * Owned by `@alineo-labs/core`, which emits every one of them through the single funnel at
166
+ * `sandbox/core.ts`'s `emit()` plus five `SandboxCreated` sites in the SDK client.
167
+ *
168
+ * These were declared in `packages/core/src/ledger.ts`, in one enum alongside the agent and
169
+ * workflow layers' events — the bottom layer defining the vocabulary of two layers above it.
170
+ * That is the coupling this package exists to break.
171
+ */
172
+ var sandbox_exports = /* @__PURE__ */ __exportAll({
173
+ CredentialBound: () => CredentialBound,
174
+ CredentialRevoked: () => CredentialRevoked,
175
+ EgressRuleAdded: () => EgressRuleAdded,
176
+ EgressRuleRemoved: () => EgressRuleRemoved,
177
+ ExecCompleted: () => ExecCompleted,
178
+ ExecOutput: () => ExecOutput,
179
+ ExecStarted: () => ExecStarted,
180
+ SandboxCheckpointCreated: () => SandboxCheckpointCreated,
181
+ SandboxClosed: () => SandboxClosed,
182
+ SandboxCreated: () => SandboxCreated,
183
+ SandboxPaused: () => SandboxPaused,
184
+ SandboxResumed: () => SandboxResumed
185
+ });
186
+ const SandboxCreated = defineEvent({
187
+ type: "sandbox.created",
188
+ durable: true,
189
+ version: 1,
190
+ description: "A sandbox reached Running state.",
191
+ schema: z.object({
192
+ sandboxId: z.string(),
193
+ name: z.string(),
194
+ runId: z.string(),
195
+ resourceId: z.string().optional(),
196
+ teamId: z.string().optional(),
197
+ /** Set when this session came from `sb.fork()`; absent for a top-level `client.sandbox()`. */
198
+ parentSandboxId: z.string().optional(),
199
+ /**
200
+ * The sandbox provider that owns `sandboxId`. Absent on rows written before this field
201
+ * existed, and an absent value means `"opensandbox"` (the only provider there was). Readers
202
+ * apply that default; there is no migration.
203
+ */
204
+ provider: z.string().optional()
205
+ })
206
+ });
207
+ const SandboxClosed = defineEvent({
208
+ type: "sandbox.closed",
209
+ durable: true,
210
+ version: 1,
211
+ description: "A sandbox was closed and its container released.",
212
+ schema: z.object({ sandboxId: z.string() })
213
+ });
214
+ const SandboxPaused = defineEvent({
215
+ type: "sandbox.paused",
216
+ durable: true,
217
+ version: 1,
218
+ description: "pause() froze the container.",
219
+ schema: z.object({ sandboxId: z.string() })
220
+ });
221
+ const SandboxResumed = defineEvent({
222
+ type: "sandbox.resumed",
223
+ durable: true,
224
+ version: 1,
225
+ description: "resume() restored a frozen container to Running.",
226
+ schema: z.object({ sandboxId: z.string() })
227
+ });
228
+ const SandboxCheckpointCreated = defineEvent({
229
+ type: "sandbox.checkpoint_created",
230
+ durable: true,
231
+ version: 1,
232
+ description: "checkpoint() captured a snapshot.",
233
+ schema: z.object({
234
+ snapshotId: z.string(),
235
+ tag: z.string().optional()
236
+ })
237
+ });
238
+ const ExecStarted = defineEvent({
239
+ type: "exec.started",
240
+ durable: true,
241
+ version: 1,
242
+ description: "An exec() or execCode() call began.",
243
+ schema: z.object({
244
+ command: z.string().optional(),
245
+ code: z.string().optional()
246
+ })
247
+ });
248
+ const ExecOutput = defineEvent({
249
+ type: "exec.output",
250
+ durable: false,
251
+ version: 1,
252
+ description: "A streaming output chunk from a running exec.",
253
+ schema: z.object({
254
+ stream: z.enum(["stdout", "stderr"]).optional(),
255
+ text: z.string()
256
+ })
257
+ });
258
+ const ExecCompleted = defineEvent({
259
+ type: "exec.completed",
260
+ durable: true,
261
+ version: 1,
262
+ description: "An exec() or execCode() call finished.",
263
+ schema: z.object({
264
+ exitCode: z.number().int().optional(),
265
+ stdout: z.string().optional(),
266
+ stderr: z.string().optional(),
267
+ /** How long the command ran, in milliseconds, as the client measured it. */
268
+ durationMs: z.number().int().optional(),
269
+ /** Present and true when a signal ended the command. */
270
+ killed: z.boolean().optional(),
271
+ /** The signal, as the server reported it. Set with `killed`. */
272
+ signal: z.string().optional(),
273
+ /** Present and true when the command was killed after running for `timeoutMs`. */
274
+ timedOut: z.boolean().optional()
275
+ })
276
+ });
277
+ const EgressRuleAdded = defineEvent({
278
+ type: "egress.rule_added",
279
+ durable: true,
280
+ version: 1,
281
+ 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.",
282
+ schema: z.object({ rules: z.array(z.unknown()) })
283
+ });
284
+ const EgressRuleRemoved = defineEvent({
285
+ type: "egress.rule_removed",
286
+ durable: true,
287
+ version: 1,
288
+ description: "sb.egress.delete().",
289
+ schema: z.object({ targets: z.array(z.string()) })
290
+ });
291
+ const CredentialBound = defineEvent({
292
+ type: "credential.bound",
293
+ durable: true,
294
+ version: 1,
295
+ description: "sb.credentials.set()/.patch(). Binding metadata only — the credential value is never written to the ledger.",
296
+ schema: z.object({
297
+ name: z.string(),
298
+ host: z.string().optional(),
299
+ injection: z.string().optional()
300
+ })
301
+ });
302
+ const CredentialRevoked = defineEvent({
303
+ type: "credential.revoked",
304
+ durable: true,
305
+ version: 1,
306
+ description: "sb.credentials.remove().",
307
+ schema: z.object({ name: z.string() })
308
+ });
309
+ //#endregion
310
+ //#region src/events/agent.ts
311
+ /**
312
+ * The agent SDK's own events — what `alineo` adds on top of a sandbox.
313
+ *
314
+ * Started as two, both from the human-in-the-loop permission gate; `AgentCheckpointed`
315
+ * (durability-roadmap M3, 3.2) is the third. All three live in `packages/core`'s ledger enum
316
+ * too, under a "used by the `alineo` agent SDK" heading, which is exactly the layering
317
+ * inversion this package fixes: `core` knows nothing about agents. Not resolved here —
318
+ * `sb.emit()` is typed to `packages/core`'s `LedgerEvent` enum, so a new agent-SDK event still
319
+ * needs a member there to be emittable at all; this file is the vocabulary-check and
320
+ * documentation registry for the same type string, not a replacement for it yet.
321
+ */
322
+ var agent_exports = /* @__PURE__ */ __exportAll({
323
+ AgentCheckpointed: () => AgentCheckpointed,
324
+ PermissionRequested: () => PermissionRequested,
325
+ PermissionResolved: () => PermissionResolved
326
+ });
327
+ const PermissionRequested = defineEvent({
328
+ type: "permission.requested",
329
+ durable: true,
330
+ version: 1,
331
+ 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.",
332
+ schema: z.object({
333
+ requestId: z.string(),
334
+ tool: z.string(),
335
+ target: z.string(),
336
+ title: z.string().optional()
337
+ })
338
+ });
339
+ const PermissionResolved = defineEvent({
340
+ type: "permission.resolved",
341
+ durable: true,
342
+ version: 1,
343
+ description: "A permission request was answered — by a caller, a batched always/reject decision, a timeout, or a session resume dropping it.",
344
+ schema: z.object({
345
+ requestId: z.string(),
346
+ decision: z.string()
347
+ })
348
+ });
349
+ const AgentCheckpointed = defineEvent({
350
+ type: "agent.checkpointed",
351
+ durable: true,
352
+ version: 1,
353
+ 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. `snapshotRef` is the file on the host. `remoteRef` is the same tarball in object storage and is absent when no store is configured or the upload failed (`uploadError` says why). A checkpoint without `remoteRef` does not survive the loss of the host's disk.",
354
+ schema: z.object({
355
+ turn: z.number(),
356
+ snapshotRef: z.string(),
357
+ remoteRef: z.string().optional(),
358
+ uploadError: z.string().optional()
359
+ })
360
+ });
361
+ //#endregion
362
+ //#region src/events/harness.ts
363
+ /**
364
+ * The harness stream — what the agent-loop driver reports while a turn runs.
365
+ *
366
+ * These are the highest-volume events in the system and most of them are stream-only: a
367
+ * `message.updated` delta is superseded by the `message.ended` that follows it, so persisting
368
+ * every one would bloat the ledger to record something the next event already says.
369
+ *
370
+ * Two collisions the subject namespacing settles: `agent_start`/`agent_end` were a *harness
371
+ * session* beginning and ending, not an alineod agent's lifecycle, so they become
372
+ * `session.*`; and `text` was a delta of exactly one message, so it becomes
373
+ * `message.updated` rather than keeping a name that hides what it is about.
374
+ */
375
+ var harness_exports = /* @__PURE__ */ __exportAll({
376
+ CompactionEnded: () => CompactionEnded,
377
+ CompactionStarted: () => CompactionStarted,
378
+ ExtensionError: () => ExtensionError,
379
+ ExtensionUi: () => ExtensionUi,
380
+ MessageEnded: () => MessageEnded,
381
+ MessageStarted: () => MessageStarted,
382
+ MessageUpdated: () => MessageUpdated,
383
+ QueueUpdated: () => QueueUpdated,
384
+ RetryEnded: () => RetryEnded,
385
+ RetryStarted: () => RetryStarted,
386
+ SessionEnded: () => SessionEnded,
387
+ SessionStarted: () => SessionStarted,
388
+ ToolEnded: () => ToolEnded,
389
+ ToolStarted: () => ToolStarted,
390
+ ToolUpdated: () => ToolUpdated,
391
+ TurnEnded: () => TurnEnded,
392
+ TurnStarted: () => TurnStarted
393
+ });
394
+ const SessionStarted = defineEvent({
395
+ type: "session.started",
396
+ durable: true,
397
+ version: 1,
398
+ description: "The harness began a session. Was `agent_start`.",
399
+ schema: z.object({})
400
+ });
401
+ const SessionEnded = defineEvent({
402
+ type: "session.ended",
403
+ durable: true,
404
+ version: 1,
405
+ description: "The harness session finished. Was `agent_end`.",
406
+ schema: z.object({ messages: z.array(z.unknown()).optional() })
407
+ });
408
+ const TurnStarted = defineEvent({
409
+ type: "turn.started",
410
+ durable: true,
411
+ version: 1,
412
+ schema: z.object({
413
+ turnIndex: z.number().int(),
414
+ timestamp: z.number()
415
+ })
416
+ });
417
+ const TurnEnded = defineEvent({
418
+ type: "turn.ended",
419
+ durable: true,
420
+ version: 1,
421
+ schema: z.object({
422
+ turnIndex: z.number().int(),
423
+ message: z.unknown().optional(),
424
+ toolResults: z.array(z.unknown()).optional()
425
+ })
426
+ });
427
+ const ToolStarted = defineEvent({
428
+ type: "tool.started",
429
+ durable: true,
430
+ version: 1,
431
+ schema: z.object({
432
+ toolCallId: z.string(),
433
+ toolName: z.string(),
434
+ args: z.unknown()
435
+ })
436
+ });
437
+ const ToolUpdated = defineEvent({
438
+ type: "tool.updated",
439
+ durable: false,
440
+ version: 1,
441
+ description: "A partial tool result. Superseded by `tool.ended`.",
442
+ schema: z.object({
443
+ toolCallId: z.string(),
444
+ toolName: z.string(),
445
+ partialResult: z.unknown()
446
+ })
447
+ });
448
+ const ToolEnded = defineEvent({
449
+ type: "tool.ended",
450
+ durable: true,
451
+ version: 1,
452
+ schema: z.object({
453
+ toolCallId: z.string(),
454
+ toolName: z.string(),
455
+ result: z.unknown(),
456
+ isError: z.boolean()
457
+ })
458
+ });
459
+ const MessageStarted = defineEvent({
460
+ type: "message.started",
461
+ durable: false,
462
+ version: 1,
463
+ schema: z.object({ message: z.unknown() })
464
+ });
465
+ const MessageUpdated = defineEvent({
466
+ type: "message.updated",
467
+ durable: false,
468
+ version: 1,
469
+ description: "A delta on the message being written — including a plain text chunk, which was its own `text` event before. Superseded by `message.ended`.",
470
+ schema: z.object({
471
+ message: z.unknown().optional(),
472
+ delta: z.unknown().optional(),
473
+ /** Set when the delta is plain text and nothing else. */
474
+ text: z.string().optional()
475
+ })
476
+ });
477
+ const MessageEnded = defineEvent({
478
+ type: "message.ended",
479
+ durable: false,
480
+ version: 1,
481
+ schema: z.object({ message: z.unknown() })
482
+ });
483
+ const CompactionStarted = defineEvent({
484
+ type: "compaction.started",
485
+ durable: true,
486
+ version: 1,
487
+ schema: z.object({ reason: z.enum([
488
+ "manual",
489
+ "threshold",
490
+ "overflow"
491
+ ]) })
492
+ });
493
+ const CompactionEnded = defineEvent({
494
+ type: "compaction.ended",
495
+ durable: true,
496
+ version: 1,
497
+ schema: z.object({
498
+ reason: z.enum([
499
+ "manual",
500
+ "threshold",
501
+ "overflow"
502
+ ]),
503
+ result: z.object({
504
+ summary: z.string(),
505
+ firstKeptEntryId: z.string(),
506
+ tokensBefore: z.number(),
507
+ estimatedTokensAfter: z.number(),
508
+ details: z.unknown()
509
+ }).nullable(),
510
+ aborted: z.boolean(),
511
+ willRetry: z.boolean()
512
+ })
513
+ });
514
+ const RetryStarted = defineEvent({
515
+ type: "retry.started",
516
+ durable: true,
517
+ version: 1,
518
+ description: "The harness is retrying a failed model call. Was `auto_retry_start`.",
519
+ schema: z.object({
520
+ attempt: z.number().int(),
521
+ maxAttempts: z.number().int(),
522
+ delayMs: z.number(),
523
+ errorMessage: z.string()
524
+ })
525
+ });
526
+ const RetryEnded = defineEvent({
527
+ type: "retry.ended",
528
+ durable: true,
529
+ version: 1,
530
+ schema: z.object({
531
+ success: z.boolean(),
532
+ attempt: z.number().int(),
533
+ finalError: z.string().optional()
534
+ })
535
+ });
536
+ const QueueUpdated = defineEvent({
537
+ type: "queue.updated",
538
+ durable: false,
539
+ version: 1,
540
+ description: "The steering and follow-up queues changed. A view of current state, not a fact.",
541
+ schema: z.object({
542
+ steering: z.array(z.string()),
543
+ followUp: z.array(z.string())
544
+ })
545
+ });
546
+ const ExtensionUi = defineEvent({
547
+ type: "extension.ui",
548
+ durable: false,
549
+ version: 1,
550
+ description: "An extension asked the host to show something.",
551
+ schema: z.object({
552
+ method: z.string(),
553
+ params: z.unknown(),
554
+ isDialog: z.boolean(),
555
+ requestId: z.string().optional()
556
+ })
557
+ });
558
+ const ExtensionError = defineEvent({
559
+ type: "extension.error",
560
+ durable: true,
561
+ version: 1,
562
+ schema: z.object({
563
+ extensionPath: z.string(),
564
+ event: z.string(),
565
+ error: z.string()
566
+ })
567
+ });
568
+ //#endregion
569
+ //#region src/events/workflow.ts
570
+ /**
571
+ * Workflow-engine events — `@alineo-labs/workflow`'s steps and saga compensation.
572
+ *
573
+ * Moved out of `packages/core`'s enum now rather than later. Leaving them there is the exact
574
+ * defect this package exists to fix, and moving them costs nothing while everything else moves.
575
+ *
576
+ * Two names change meaning rather than spelling:
577
+ *
578
+ * - `run_started` meant a workflow run here and a *swarm* run in alineod. The two are
579
+ * `workflow.started` and `run.started` now, and nothing has to guess from context.
580
+ * - `snapshot` is **dropped**. It recorded a sandbox checkpoint that the workflow engine
581
+ * happened to take — so it emits `sandbox.checkpoint_created`, the event that already
582
+ * describes it. `checkpoint` (the workflow's own resumption point) is **dropped** too: an early
583
+ * version wrote it, nothing has for a long time, and nothing reads it.
584
+ */
585
+ var workflow_exports = /* @__PURE__ */ __exportAll({
586
+ StepCompleted: () => StepCompleted,
587
+ StepFailed: () => StepFailed,
588
+ StepRolledBack: () => StepRolledBack,
589
+ StepStarted: () => StepStarted,
590
+ WorkflowCompleted: () => WorkflowCompleted,
591
+ WorkflowFailed: () => WorkflowFailed,
592
+ WorkflowStarted: () => WorkflowStarted
593
+ });
594
+ const WorkflowStarted = defineEvent({
595
+ type: "workflow.started",
596
+ durable: true,
597
+ version: 1,
598
+ description: "A workflow run began, before any step executed. Was `run_started`.",
599
+ schema: z.object({ runId: z.string().optional() })
600
+ });
601
+ const WorkflowCompleted = defineEvent({
602
+ type: "workflow.completed",
603
+ durable: true,
604
+ version: 1,
605
+ description: "Every step finished without error.",
606
+ schema: z.object({})
607
+ });
608
+ const WorkflowFailed = defineEvent({
609
+ type: "workflow.failed",
610
+ durable: true,
611
+ version: 1,
612
+ description: "Rollback completed after a step failure.",
613
+ schema: z.object({ error: z.string().optional() })
614
+ });
615
+ const StepStarted = defineEvent({
616
+ type: "step.started",
617
+ durable: true,
618
+ version: 1,
619
+ schema: z.object({ name: z.string().optional() })
620
+ });
621
+ const StepCompleted = defineEvent({
622
+ type: "step.completed",
623
+ durable: true,
624
+ version: 1,
625
+ schema: z.object({ output: z.unknown().optional() })
626
+ });
627
+ const StepFailed = defineEvent({
628
+ type: "step.failed",
629
+ durable: true,
630
+ version: 1,
631
+ schema: z.object({ error: z.string().optional() })
632
+ });
633
+ const StepRolledBack = defineEvent({
634
+ type: "step.rolled_back",
635
+ durable: true,
636
+ version: 1,
637
+ description: "A step's rollback handler completed during saga compensation.",
638
+ schema: z.object({})
639
+ });
640
+ //#endregion
641
+ //#region src/events/alineod.ts
642
+ /**
643
+ * Swarm control-plane events — the run tree, its budgets, and how agents coordinate.
644
+ *
645
+ * Every one of these is durable. alineod's projections are rebuilt by folding them
646
+ * (`state/projection.ts`'s `rebuild()`), so an event that is not written is state that does
647
+ * not survive a restart — which is the whole basis of the daemon's crash-only design.
648
+ *
649
+ * Namespaced by subject rather than by the daemon that emits them: a user reads one mixed
650
+ * stream and needs to know what an event is *about*. `agent.spawned`, not
651
+ * `alineod.agent_spawned`.
652
+ */
653
+ var alineod_exports = /* @__PURE__ */ __exportAll({
654
+ AgentAdmissionGranted: () => AgentAdmissionGranted,
655
+ AgentAdmissionQueued: () => AgentAdmissionQueued,
656
+ AgentAdmissionTimeout: () => AgentAdmissionTimeout,
657
+ AgentEnded: () => AgentEnded,
658
+ AgentProvisioned: () => AgentProvisioned,
659
+ AgentReleased: () => AgentReleased,
660
+ AgentRestored: () => AgentRestored,
661
+ AgentSpawned: () => AgentSpawned,
662
+ AgentStateChanged: () => AgentStateChanged,
663
+ AgentSteered: () => AgentSteered,
664
+ AgentSupervisionNeeded: () => AgentSupervisionNeeded,
665
+ AgentTurnFailed: () => AgentTurnFailed,
666
+ AgentTurnInterrupted: () => AgentTurnInterrupted,
667
+ AgentTurnRetried: () => AgentTurnRetried,
668
+ BudgetDenied: () => BudgetDenied,
669
+ HandleSettled: () => HandleSettled,
670
+ InboxDelivered: () => InboxDelivered,
671
+ InboxDropped: () => InboxDropped,
672
+ InboxQueued: () => InboxQueued,
673
+ NotifyRegistered: () => NotifyRegistered,
674
+ RunClosed: () => RunClosed,
675
+ RunQuiescent: () => RunQuiescent,
676
+ RunStarted: () => RunStarted,
677
+ WaitBlocked: () => WaitBlocked,
678
+ WaitResolved: () => WaitResolved
679
+ });
680
+ const WaitMode = z.enum([
681
+ "all",
682
+ "any",
683
+ "quorum"
684
+ ]);
685
+ const RunStarted = defineEvent({
686
+ type: "run.started",
687
+ durable: true,
688
+ version: 1,
689
+ description: "A swarm run was created. Was `run_started` — the name workflow also used.",
690
+ schema: z.object({
691
+ runId: z.string(),
692
+ closeWhen: z.enum(["explicit", "quiescent"]).default("explicit")
693
+ })
694
+ });
695
+ const RunClosed = defineEvent({
696
+ type: "run.closed",
697
+ durable: true,
698
+ version: 1,
699
+ 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.",
700
+ schema: z.object({
701
+ agentId: z.string().nullable(),
702
+ reason: z.enum(["explicit", "quiescent"])
703
+ })
704
+ });
705
+ const RunQuiescent = defineEvent({
706
+ type: "run.quiescent",
707
+ durable: true,
708
+ version: 1,
709
+ description: "The subtree rooted at this agent went quiescent. Only tracked while someone is awaiting it. Was `subtree_quiescent`.",
710
+ schema: z.object({
711
+ agentId: z.string().nullable(),
712
+ memberCount: z.number().int(),
713
+ asOf: z.number()
714
+ })
715
+ });
716
+ const AgentSpawned = defineEvent({
717
+ type: "agent.spawned",
718
+ durable: true,
719
+ version: 1,
720
+ schema: z.object({
721
+ agentId: z.string().nullable(),
722
+ parentAgentId: z.string().nullable(),
723
+ runId: z.string(),
724
+ specName: z.string(),
725
+ depth: z.number().int(),
726
+ spawnIndex: z.number().int(),
727
+ sandboxId: z.string().nullable(),
728
+ 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."),
729
+ prompt: z.string().nullable().optional()
730
+ })
731
+ });
732
+ const AgentProvisioned = defineEvent({
733
+ type: "agent.provisioned",
734
+ durable: true,
735
+ version: 1,
736
+ description: "The sandbox exists and the bridge is up — backfills what `agent.spawned` could not know yet.",
737
+ schema: z.object({
738
+ agentId: z.string().nullable(),
739
+ sandboxId: z.string(),
740
+ /**
741
+ * The sandbox provider that owns `sandboxId`. Absent on events written before this field
742
+ * existed, which all came from OpenSandbox.
743
+ */
744
+ provider: z.string().optional()
745
+ })
746
+ });
747
+ const AgentRestored = defineEvent({
748
+ type: "agent.restored",
749
+ durable: true,
750
+ version: 1,
751
+ description: "The agent's sandbox was gone, so a fresh one replaced it. `checkpointTurn` is the turn its workspace and session were restored from, or `null` when it had no checkpoint and came back blank. Follows `agent.provisioned`, which carries the new `sandboxId`.",
752
+ schema: z.object({
753
+ agentId: z.string().nullable(),
754
+ oldSandboxId: z.string(),
755
+ checkpointTurn: z.number().int().nullable()
756
+ })
757
+ });
758
+ const AgentStateChanged = defineEvent({
759
+ type: "agent.state_changed",
760
+ durable: true,
761
+ version: 1,
762
+ schema: z.object({
763
+ agentId: z.string().nullable(),
764
+ from: z.string(),
765
+ to: z.string(),
766
+ reason: z.string().optional(),
767
+ 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.")
768
+ })
769
+ });
770
+ const AgentSteered = defineEvent({
771
+ type: "agent.steered",
772
+ durable: true,
773
+ version: 1,
774
+ schema: z.object({
775
+ agentId: z.string().nullable(),
776
+ message: z.string(),
777
+ scope: z.enum(["agent", "subtree"]).optional(),
778
+ roster: z.array(z.string()).optional(),
779
+ deliveredAs: z.enum([
780
+ "steer",
781
+ "turn",
782
+ "queued"
783
+ ]).optional()
784
+ })
785
+ });
786
+ const AgentReleased = defineEvent({
787
+ type: "agent.released",
788
+ durable: true,
789
+ version: 1,
790
+ description: "A finished agent's still-open sandbox was closed, or a fork landed after its spawn was stopped. The recorded outcome is unchanged.",
791
+ schema: z.object({
792
+ agentId: z.string().nullable(),
793
+ reason: z.string()
794
+ })
795
+ });
796
+ const AgentEnded = defineEvent({
797
+ type: "agent.ended",
798
+ durable: true,
799
+ version: 1,
800
+ schema: z.object({
801
+ agentId: z.string().nullable(),
802
+ outcome: z.string(),
803
+ endedAt: z.number(),
804
+ error: z.string().optional(),
805
+ /** A stable `ErrorCode` for `error`, when one is known. See `@alineo-labs/errors`. */
806
+ errorCode: z.string().optional()
807
+ })
808
+ });
809
+ const HandleSettled = defineEvent({
810
+ type: "handle.settled",
811
+ durable: true,
812
+ version: 1,
813
+ schema: z.object({
814
+ agentId: z.string().nullable(),
815
+ outcome: z.string(),
816
+ resultRef: z.string().nullable()
817
+ })
818
+ });
819
+ const WaitResolved = defineEvent({
820
+ type: "wait.resolved",
821
+ durable: true,
822
+ version: 1,
823
+ description: "A held spawn's waitFor resolved. A depfail or deadline outcome ends the child failed, without ever forking it.",
824
+ schema: z.object({
825
+ agentId: z.string().nullable(),
826
+ mode: WaitMode,
827
+ outcome: z.enum([
828
+ "satisfied",
829
+ "partial",
830
+ "deadline",
831
+ "depfail"
832
+ ]),
833
+ selected: z.array(z.string()),
834
+ settled: z.array(z.object({
835
+ agentId: z.string(),
836
+ outcome: z.string().nullable()
837
+ })),
838
+ pending: z.array(z.string())
839
+ })
840
+ });
841
+ const WaitBlocked = defineEvent({
842
+ type: "wait.blocked",
843
+ durable: true,
844
+ version: 1,
845
+ description: "A held spawn is waiting on a paused dependency — one event per dependency. Was `wait_blocked_on_paused`.",
846
+ schema: z.object({
847
+ agentId: z.string().nullable(),
848
+ blockedOn: z.string()
849
+ })
850
+ });
851
+ const NotifyRegistered = defineEvent({
852
+ type: "notify.registered",
853
+ durable: true,
854
+ version: 1,
855
+ description: "This agent asked to be told when each agent in `on` finishes.",
856
+ schema: z.object({
857
+ agentId: z.string().nullable(),
858
+ on: z.array(z.string()),
859
+ wake: z.boolean()
860
+ })
861
+ });
862
+ const InboxQueued = defineEvent({
863
+ type: "inbox.queued",
864
+ durable: true,
865
+ version: 1,
866
+ description: "Something for this agent to be told — a notification, a steer waiting for it to resume, or a child needing a supervision decision.",
867
+ schema: z.object({
868
+ agentId: z.string().nullable(),
869
+ kind: z.enum([
870
+ "notification",
871
+ "steer",
872
+ "supervision"
873
+ ]),
874
+ aboutAgentId: z.string().nullable().optional(),
875
+ aboutSpec: z.string().nullable().optional(),
876
+ outcome: z.string().nullable().optional(),
877
+ resultRef: z.string().nullable().optional(),
878
+ excerpt: z.string().nullable().optional(),
879
+ again: z.boolean().optional(),
880
+ text: z.string().optional()
881
+ })
882
+ });
883
+ const InboxDelivered = defineEvent({
884
+ type: "inbox.delivered",
885
+ durable: true,
886
+ version: 1,
887
+ schema: z.object({
888
+ agentId: z.string().nullable(),
889
+ seqs: z.array(z.number().int()),
890
+ as: z.enum([
891
+ "steer",
892
+ "turn",
893
+ "prompt"
894
+ ])
895
+ })
896
+ });
897
+ const InboxDropped = defineEvent({
898
+ type: "inbox.dropped",
899
+ durable: true,
900
+ version: 1,
901
+ schema: z.object({
902
+ agentId: z.string().nullable(),
903
+ seqs: z.array(z.number().int()),
904
+ reason: z.string()
905
+ })
906
+ });
907
+ const BudgetDenied = defineEvent({
908
+ type: "budget.denied",
909
+ durable: true,
910
+ version: 1,
911
+ schema: z.object({
912
+ agentId: z.string().nullable(),
913
+ dimension: z.enum(["spawnDepth", "maxAgents"]),
914
+ remaining: z.number().int()
915
+ })
916
+ });
917
+ const AgentAdmissionQueued = defineEvent({
918
+ type: "agent.admission_queued",
919
+ durable: true,
920
+ version: 1,
921
+ 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.",
922
+ schema: z.object({
923
+ agentId: z.string().nullable(),
924
+ capacity: z.number().int()
925
+ })
926
+ });
927
+ const AgentAdmissionGranted = defineEvent({
928
+ type: "agent.admission_granted",
929
+ durable: true,
930
+ version: 1,
931
+ description: "A held provisioning request got its slot and is proceeding.",
932
+ schema: z.object({ agentId: z.string().nullable() })
933
+ });
934
+ const AgentAdmissionTimeout = defineEvent({
935
+ type: "agent.admission_timeout",
936
+ durable: true,
937
+ version: 1,
938
+ description: "A held provisioning request never got a slot within the bound and failed loudly instead of hanging silently.",
939
+ schema: z.object({
940
+ agentId: z.string().nullable(),
941
+ waitedMs: z.number().int()
942
+ })
943
+ });
944
+ const AgentTurnFailed = defineEvent({
945
+ type: "agent.turn_failed",
946
+ durable: true,
947
+ version: 1,
948
+ 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.",
949
+ schema: z.object({
950
+ agentId: z.string().nullable(),
951
+ error: z.string(),
952
+ /** A stable `ErrorCode` for `error`, when one is known. See `@alineo-labs/errors`. */
953
+ errorCode: z.string().optional(),
954
+ consecutiveFailures: z.number().int()
955
+ })
956
+ });
957
+ const AgentTurnRetried = defineEvent({
958
+ type: "agent.turn_retried",
959
+ durable: true,
960
+ version: 1,
961
+ description: "A turn failed with a transient model-provider error (a 429 or a 5xx) and alineod is re-sending it after a backoff. This is not a supervision failure: it does not count toward the circuit breaker. After `maxAttempts` the failure is recorded as `agent.turn_failed`.",
962
+ schema: z.object({
963
+ agentId: z.string().nullable(),
964
+ error: z.string(),
965
+ errorCode: z.string(),
966
+ /** 1-based number of this retry. */
967
+ attempt: z.number().int(),
968
+ maxAttempts: z.number().int(),
969
+ /** The wait before the turn is re-sent, in milliseconds. */
970
+ delayMs: z.number().int()
971
+ })
972
+ });
973
+ const AgentTurnInterrupted = defineEvent({
974
+ type: "agent.turn_interrupted",
975
+ durable: true,
976
+ version: 1,
977
+ 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`.",
978
+ schema: z.object({ agentId: z.string().nullable() })
979
+ });
980
+ const AgentSupervisionNeeded = defineEvent({
981
+ type: "agent.supervision_needed",
982
+ durable: true,
983
+ version: 1,
984
+ description: "The agent is held (state: blocked) awaiting an operator decision: POST .../prompt to retry (optionally with corrective text), POST .../stop to give up.",
985
+ schema: z.object({
986
+ agentId: z.string().nullable(),
987
+ reason: z.enum([
988
+ "ask",
989
+ "retries-exhausted",
990
+ "circuit-tripped"
991
+ ]),
992
+ error: z.string(),
993
+ /** A stable `ErrorCode` for `error`, when one is known. See `@alineo-labs/errors`. */
994
+ errorCode: z.string().optional()
995
+ })
996
+ });
997
+ //#endregion
998
+ //#region src/agent-spec.ts
999
+ /**
1000
+ * `AgentSpec` — the JSON an agent is defined by.
1001
+ *
1002
+ * Both the documented `interface` and the `AgentSpecSchema` that validates it are kept by
1003
+ * hand, deliberately: the interface carries doc comments that `z.infer<>` would erase, and
1004
+ * they are what a reader sees on hover. `agent-spec.test.ts` asserts at the type level that
1005
+ * the two cannot drift apart, which buys the safety of a single source without the DX loss.
1006
+ *
1007
+ * `validateAgentSpec()` and `AgentSpecValidationError` stay in `@alineo-labs/agent` — they
1008
+ * are behaviour, and this package has none.
1009
+ *
1010
+ * Moved here from `@alineo-labs/agent` so that `apps/alineod` can stop modelling it as
1011
+ * `z.record(z.unknown())` and emit a real `AgentSpec` into its OpenAPI spec.
1012
+ */
1013
+ /** Renders an arbitrary invalid field value for an error message without risking "[object Object]". */
1014
+ function describeValue(value) {
1015
+ if (typeof value === "string") return value;
1016
+ try {
1017
+ const json = JSON.stringify(value);
1018
+ if (json !== void 0) return json;
1019
+ } catch {}
1020
+ return typeof value === "object" && value !== null ? Object.prototype.toString.call(value) : String(value);
1021
+ }
1022
+ /**
1023
+ * Runtime schema for `SetupStep`/`AgentSpec` above. Kept as a separate Zod schema rather than
1024
+ * generating the interfaces from it (`z.infer<>`) so the hand-written interfaces above can carry
1025
+ * full field-level JSDoc — TypeScript doesn't propagate comments through generic type inference,
1026
+ * and that documentation is load-bearing (it's what IDE hover/autocomplete shows spec authors).
1027
+ * If you add/change/remove a field on `AgentSpec`/`SetupStep`, update the matching schema field
1028
+ * here too — `packages/agent/test/schema.test.ts` is the drift check.
1029
+ */
1030
+ const CredentialEnvBindingSchema = z$1.object({
1031
+ credential: z$1.string({ error: "Each credential env binding must have a 'credential' string" }),
1032
+ host: z$1.string({ error: "Each credential env binding must have a 'host' string" }),
1033
+ pathPrefix: z$1.string().optional(),
1034
+ injection: z$1.union([z$1.object({
1035
+ type: z$1.literal("header"),
1036
+ name: z$1.string()
1037
+ }), z$1.object({
1038
+ type: z$1.literal("substitution"),
1039
+ placeholder: z$1.string(),
1040
+ in: z$1.array(z$1.enum([
1041
+ "path",
1042
+ "query",
1043
+ "header",
1044
+ "body"
1045
+ ])).min(1)
1046
+ })]),
1047
+ approval: z$1.literal("hold").optional()
1048
+ }).loose();
1049
+ const SetupStepSchema = z$1.object({
1050
+ name: z$1.string({ error: "Each setup step must have a 'name' string" }),
1051
+ run: z$1.string({ error: "Each setup step must have a 'run' string" }),
1052
+ cwd: z$1.string().optional()
1053
+ }).loose();
1054
+ const PermissionActionSchema = z$1.enum([
1055
+ "allow",
1056
+ "ask",
1057
+ "deny",
1058
+ "rate_limit",
1059
+ "classify"
1060
+ ]);
1061
+ const PermissionRuleSchema = z$1.object({
1062
+ tool: z$1.string({ error: "Each permission rule must have a 'tool' string" }),
1063
+ pattern: z$1.string().optional(),
1064
+ action: PermissionActionSchema,
1065
+ limit: z$1.object({
1066
+ count: z$1.number().int().positive(),
1067
+ windowMs: z$1.number().int().positive()
1068
+ }).optional()
1069
+ }).loose();
1070
+ const PermissionPolicySchema = z$1.object({
1071
+ default: PermissionActionSchema.optional(),
1072
+ rules: z$1.array(PermissionRuleSchema).optional(),
1073
+ disabledTools: z$1.array(z$1.string()).optional(),
1074
+ restrictToTools: z$1.array(z$1.string()).optional()
1075
+ }).loose();
1076
+ const PermissionsSchema = z$1.union([z$1.enum([
1077
+ "auto",
1078
+ "ask",
1079
+ "readonly"
1080
+ ]), PermissionPolicySchema]);
1081
+ /** The provider a non-Pi harness runs on. A spec that names another one is wrong. */
1082
+ const NATIVE_PROVIDER = {
1083
+ "claude-code": "anthropic",
1084
+ codex: "openai"
1085
+ };
1086
+ /** Turn an authored spec into the flat shape the runtime reads. Run it on a validated spec. */
1087
+ function normalizeAgentSpec(input) {
1088
+ const { harness, model, ...rest } = input;
1089
+ const harnessId = typeof harness === "string" ? harness : harness.id;
1090
+ const harnessVersion = (typeof harness === "string" ? void 0 : harness.version) ?? input.harnessVersion;
1091
+ const modelId = typeof model === "string" ? model : model.id;
1092
+ const provider = (typeof model === "string" ? void 0 : model.provider) ?? input.provider;
1093
+ const out = {
1094
+ ...rest,
1095
+ harness: harnessId,
1096
+ model: modelId
1097
+ };
1098
+ if (harnessVersion !== void 0) out.harnessVersion = harnessVersion;
1099
+ else delete out.harnessVersion;
1100
+ if (provider !== void 0) out.provider = provider;
1101
+ else delete out.provider;
1102
+ return out;
1103
+ }
1104
+ /** The deprecated top-level fields a spec still uses, and what replaces each. */
1105
+ function deprecatedSpecFields(input) {
1106
+ const out = [];
1107
+ if (input.provider !== void 0) out.push({
1108
+ field: "provider",
1109
+ use: "model.provider"
1110
+ });
1111
+ if (input.harnessVersion !== void 0) out.push({
1112
+ field: "harnessVersion",
1113
+ use: "harness.version"
1114
+ });
1115
+ return out;
1116
+ }
1117
+ /** The harness id inside `{ id }`, so an error names `cursor` and not `{"id":"cursor"}`. */
1118
+ function harnessIdOf(input) {
1119
+ return typeof input === "object" && input !== null && "id" in input ? input.id : input;
1120
+ }
1121
+ const HarnessIdSchema = z$1.enum([
1122
+ "pi",
1123
+ "claude-code",
1124
+ "codex"
1125
+ ], { error: (issue) => issue.input === void 0 ? "Agent spec must have a 'harness' field. Supported values: pi, claude-code, codex" : `Unsupported harness: '${describeValue(harnessIdOf(issue.input))}'. Supported values: pi, claude-code, codex` });
1126
+ 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();
1127
+ const AgentSpecSchema = z$1.object({
1128
+ $schema: z$1.string().optional(),
1129
+ 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"),
1130
+ title: z$1.string().optional(),
1131
+ description: z$1.string().optional(),
1132
+ author: z$1.string().optional(),
1133
+ categories: z$1.array(z$1.string()).optional(),
1134
+ harness: z$1.union([HarnessIdSchema, z$1.object({
1135
+ id: HarnessIdSchema,
1136
+ version: z$1.string().optional()
1137
+ })], { error: (issue) => issue.input === void 0 ? "Agent spec must have a 'harness' field. Supported values: pi, claude-code, codex" : `Unsupported harness: '${describeValue(harnessIdOf(issue.input))}'. Supported values: pi, claude-code, codex` }),
1138
+ harnessVersion: z$1.string().optional(),
1139
+ provider: z$1.string().optional(),
1140
+ model: z$1.union([z$1.string().min(1, "Agent spec must have a 'model' string — name the model this agent runs on"), z$1.object({
1141
+ provider: z$1.string().optional(),
1142
+ id: z$1.string().min(1, "Agent spec 'model.id' must name the model this agent runs on")
1143
+ })], { 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, or an object with an 'id'" }),
1144
+ packages: z$1.array(z$1.string()).optional(),
1145
+ env: z$1.record(z$1.string(), z$1.union([z$1.string(), CredentialEnvBindingSchema])).optional(),
1146
+ resources: z$1.object({
1147
+ cpu: z$1.string(),
1148
+ memory: z$1.string(),
1149
+ gpu: z$1.string().optional()
1150
+ }).optional(),
1151
+ metadata: z$1.record(z$1.string(), z$1.string()).optional(),
1152
+ registryDependencies: z$1.array(z$1.string()).optional(),
1153
+ setup: z$1.array(SetupStepSchema).optional(),
1154
+ spawnDepth: nonNegativeIntSpecField("spawnDepth"),
1155
+ maxAgents: nonNegativeIntSpecField("maxAgents"),
1156
+ teamId: z$1.string().optional(),
1157
+ resourceId: z$1.string().optional(),
1158
+ permissions: PermissionsSchema.optional(),
1159
+ onFailure: z$1.enum([
1160
+ "ask",
1161
+ "retry",
1162
+ "fail"
1163
+ ]).optional(),
1164
+ maxRetries: nonNegativeIntSpecField("maxRetries"),
1165
+ maxConsecutiveFailures: nonNegativeIntSpecField("maxConsecutiveFailures"),
1166
+ checkpoint: z$1.boolean().optional()
1167
+ }).loose().superRefine((spec, ctx) => {
1168
+ const harnessId = typeof spec.harness === "string" ? spec.harness : spec.harness.id;
1169
+ const nested = typeof spec.harness === "string" ? void 0 : spec.harness.version;
1170
+ if (nested !== void 0 && spec.harnessVersion !== void 0 && nested !== spec.harnessVersion) ctx.addIssue({
1171
+ code: "custom",
1172
+ path: ["harnessVersion"],
1173
+ message: `'harnessVersion' (${spec.harnessVersion}) conflicts with 'harness.version' (${nested}). Set only 'harness.version'.`
1174
+ });
1175
+ const modelProvider = typeof spec.model === "string" ? void 0 : spec.model.provider;
1176
+ if (modelProvider !== void 0 && spec.provider !== void 0 && modelProvider !== spec.provider) ctx.addIssue({
1177
+ code: "custom",
1178
+ path: ["provider"],
1179
+ message: `'provider' (${spec.provider}) conflicts with 'model.provider' (${modelProvider}). Set only 'model.provider'.`
1180
+ });
1181
+ const provider = modelProvider ?? spec.provider;
1182
+ const native = NATIVE_PROVIDER[harnessId];
1183
+ if (native !== void 0 && provider !== void 0 && provider !== native) ctx.addIssue({
1184
+ code: "custom",
1185
+ path: ["model", "provider"],
1186
+ message: `The ${harnessId} harness runs on ${native} models, but the provider is '${provider}'. Remove the provider, or use the pi harness.`
1187
+ });
1188
+ });
1189
+ //#endregion
1190
+ export { parseName as _, workflow_exports as a, sandbox_exports as c, durableEvents as d, getEvent as f, isVerb as g, isSubject as h, alineod_exports as i, allEvents as l, VERBS as m, deprecatedSpecFields as n, harness_exports as o, SUBJECTS as p, normalizeAgentSpec as r, agent_exports as s, AgentSpecSchema as t, defineEvent as u };