@drisp/protocol 0.6.2 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/v2.d.ts CHANGED
@@ -4,15 +4,45 @@ import { f as InstalledWorkflowSchema } from './domain-B-kg2pa_.js';
4
4
  /** Presentation of canonical fragment records; archive/cursor accounting always uses the original records. */
5
5
  declare function readableHistory(records: HistoryRecord[]): HistoryRecord[];
6
6
 
7
+ /**
8
+ * What a Build's children cost against its token budget (root ADR-0011). Tokens exclude cache reads. The forecasts
9
+ * are defaults, not measured; the caps are the per-Run ceilings the size classes declare.
10
+ */
11
+ type SizeClass = 'S' | 'M' | 'L';
12
+ /** Per-Run token cap of each size class. The largest class also bounds anything above it. */
13
+ declare const SIZE_CLASS_CAPS: Readonly<Record<SizeClass, number>>;
14
+ /** What a Run of each class is expected to use: default, not measured. */
15
+ declare const SIZE_CLASS_FORECASTS: Readonly<Record<SizeClass, number>>;
16
+ /** The smallest class whose cap is at least the declared one; above the largest cap is `L`. */
17
+ declare function classOfCap(declaredCap: number): SizeClass;
18
+ /**
19
+ * What one attempt holds against the budget: a closed attempt (finished, failed, cancelled) its forecast; a running
20
+ * or queued one still its declared cap.
21
+ */
22
+ declare function attemptCost(attempt: {
23
+ tokenCap: number;
24
+ closed: boolean;
25
+ }): number;
26
+
7
27
  declare const protocolVersion: {
8
28
  readonly major: 2;
9
- readonly minor: 1;
29
+ readonly minor: 2;
10
30
  };
11
31
  declare const conversationContinuationCapability = "conversation_continuation";
12
32
  declare const abandonedConversationContinuationCapability = "abandoned_conversation_continuation";
13
33
  declare const repositoryAccessCapability = "repository_checkout_v1";
14
34
  /** The runner can install a Workflow named by a Run's install reference before it starts. */
15
35
  declare const workflowInstallCapability = "workflow_install_v1";
36
+ /**
37
+ * The runner takes grants carrying `delegationToken` and `parent` (protocol minor 2, root ADR-0008) and hands the
38
+ * token to the agent as `DRISP_RUN_TOKEN`. A start with `delegation` is never sent to a runner without it.
39
+ */
40
+ declare const runDelegationCapability = "run_delegation_v1";
41
+ /** The prefix of every delegation token; the Hub keeps only its digest. */
42
+ declare const delegationTokenPrefix = "drisp_dlg_";
43
+ /** A `run.artifact` history record's `name`, and the most its `json` may take serialized. */
44
+ declare const runArtifactNameSchema: z.ZodString;
45
+ declare const runArtifactMaxBytes: number;
16
46
  /** Deployment-approved secret references, never secret values or process-control variables. */
17
47
  declare const secretEnvironmentSchema: z.ZodRecord<z.ZodString, z.ZodString>;
18
48
  declare const permissionAnswerSchema: z.ZodObject<{
@@ -90,6 +120,7 @@ declare const interruptionSchema: z.ZodObject<{
90
120
  question: "question";
91
121
  guidance: "guidance";
92
122
  recovery: "recovery";
123
+ waiting: "waiting";
93
124
  }>;
94
125
  message: z.ZodString;
95
126
  requestId: z.ZodOptional<z.ZodString>;
@@ -100,6 +131,40 @@ declare const workflowIdentitySchema: z.ZodObject<{
100
131
  version: z.ZodOptional<z.ZodString>;
101
132
  }, z.core.$strict>;
102
133
  type WorkflowIdentity = z.infer<typeof workflowIdentitySchema>;
134
+ /** A Runner's close reasons for a Build Run: a child refused at bootstrap, or an approval marker with no question. */
135
+ declare const buildCloseReasonSchema: z.ZodEnum<{
136
+ workflow_template_mismatch: "workflow_template_mismatch";
137
+ child_project_dir_invalid: "child_project_dir_invalid";
138
+ build_not_approved: "build_not_approved";
139
+ approval_question_missing: "approval_question_missing";
140
+ }>;
141
+ type BuildCloseReason = z.infer<typeof buildCloseReasonSchema>;
142
+ /**
143
+ * Every close reason a Hub gives a Run view's `closeReason`: its own, and the Runner's Build ones it stores from
144
+ * `run.finished.reason`. The view keeps `closeReason` an open string, so a newer Hub's reasons still decode; the app
145
+ * words each of these (apps/macos Kit `BuildStrings.closeReasons`), and a Kit test fails on one it does not word.
146
+ */
147
+ declare const runCloseReasonSchema: z.ZodEnum<{
148
+ workflow_template_mismatch: "workflow_template_mismatch";
149
+ child_project_dir_invalid: "child_project_dir_invalid";
150
+ build_not_approved: "build_not_approved";
151
+ approval_question_missing: "approval_question_missing";
152
+ execution_terminal: "execution_terminal";
153
+ cancelled_before_start: "cancelled_before_start";
154
+ admission_failed: "admission_failed";
155
+ abandoned: "abandoned";
156
+ managed_startup_timeout: "managed_startup_timeout";
157
+ runner_disconnected: "runner_disconnected";
158
+ runner_needs_owner: "runner_needs_owner";
159
+ runner_not_available: "runner_not_available";
160
+ runner_upgrade_required: "runner_upgrade_required";
161
+ legacy_succeeded: "legacy_succeeded";
162
+ legacy_failed: "legacy_failed";
163
+ legacy_cancelled: "legacy_cancelled";
164
+ legacy_timeout: "legacy_timeout";
165
+ legacy_force_failed: "legacy_force_failed";
166
+ }>;
167
+ type RunCloseReason = z.infer<typeof runCloseReasonSchema>;
103
168
  declare const controlRecordSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
104
169
  kind: z.ZodLiteral<"workflows.changed">;
105
170
  workflows: z.ZodArray<z.ZodObject<{
@@ -167,6 +232,7 @@ declare const controlRecordSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
167
232
  question: "question";
168
233
  guidance: "guidance";
169
234
  recovery: "recovery";
235
+ waiting: "waiting";
170
236
  }>;
171
237
  message: z.ZodString;
172
238
  requestId: z.ZodOptional<z.ZodString>;
@@ -201,6 +267,12 @@ declare const controlRecordSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
201
267
  }>;
202
268
  historyThrough: z.ZodNumber;
203
269
  workspaceUnavailable: z.ZodOptional<z.ZodLiteral<true>>;
270
+ reason: z.ZodOptional<z.ZodEnum<{
271
+ workflow_template_mismatch: "workflow_template_mismatch";
272
+ child_project_dir_invalid: "child_project_dir_invalid";
273
+ build_not_approved: "build_not_approved";
274
+ approval_question_missing: "approval_question_missing";
275
+ }>>;
204
276
  runId: z.ZodString;
205
277
  attemptId: z.ZodString;
206
278
  executionRevision: z.ZodNumber;
@@ -304,6 +376,24 @@ declare const runSpecSchema: z.ZodObject<{
304
376
  bindingId: z.ZodString;
305
377
  }, z.core.$strict>>;
306
378
  }, z.core.$strict>;
379
+ /** What a Run is for, e.g. `plan:<linearProjectId>`; at most one non-closed Run holds a key (`key_busy`). */
380
+ declare const runKeySchema: z.ZodString;
381
+ /** A member start's grant to start, limit and stop its own children (root ADR-0008). */
382
+ declare const delegationSchema: z.ZodObject<{
383
+ maxChildren: z.ZodNumber;
384
+ tokenBudget: z.ZodNumber;
385
+ }, z.core.$strict>;
386
+ /** A child's parent and declared token cap. Required on a delegated start; the Hub refuses it without `tokenCap`. */
387
+ declare const runParentIntentSchema: z.ZodObject<{
388
+ runId: z.ZodString;
389
+ tokenCap: z.ZodOptional<z.ZodNumber>;
390
+ }, z.core.$strict>;
391
+ declare const runParentSchema: z.ZodObject<{
392
+ runId: z.ZodString;
393
+ tokenCap: z.ZodNumber;
394
+ }, z.core.$strict>;
395
+ type Delegation = z.infer<typeof delegationSchema>;
396
+ type RunParent = z.infer<typeof runParentSchema>;
307
397
  declare const commandSchema: z.ZodObject<{
308
398
  commandId: z.ZodString;
309
399
  hubEpoch: z.ZodString;
@@ -347,6 +437,15 @@ declare const commandSchema: z.ZodObject<{
347
437
  bindingId: z.ZodString;
348
438
  }, z.core.$strict>>;
349
439
  }, z.core.$strict>;
440
+ key: z.ZodOptional<z.ZodString>;
441
+ delegation: z.ZodOptional<z.ZodObject<{
442
+ maxChildren: z.ZodNumber;
443
+ tokenBudget: z.ZodNumber;
444
+ }, z.core.$strict>>;
445
+ parent: z.ZodOptional<z.ZodObject<{
446
+ runId: z.ZodString;
447
+ tokenCap: z.ZodOptional<z.ZodNumber>;
448
+ }, z.core.$strict>>;
350
449
  }, z.core.$strict>, z.ZodObject<{
351
450
  kind: z.ZodLiteral<"cancel">;
352
451
  }, z.core.$strict>, z.ZodObject<{
@@ -424,6 +523,11 @@ declare const grantSchema: z.ZodObject<{
424
523
  checkpointId: z.ZodString;
425
524
  checksum: z.ZodString;
426
525
  }, z.core.$strict>>;
526
+ delegationToken: z.ZodOptional<z.ZodString>;
527
+ parent: z.ZodOptional<z.ZodObject<{
528
+ runId: z.ZodString;
529
+ tokenCap: z.ZodNumber;
530
+ }, z.core.$strict>>;
427
531
  }, z.core.$strict>;
428
532
  declare const historyRecordSchema: z.ZodObject<{
429
533
  eventId: z.ZodString;
@@ -546,6 +650,7 @@ declare const runnerFrameSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
546
650
  question: "question";
547
651
  guidance: "guidance";
548
652
  recovery: "recovery";
653
+ waiting: "waiting";
549
654
  }>;
550
655
  message: z.ZodString;
551
656
  requestId: z.ZodOptional<z.ZodString>;
@@ -580,6 +685,12 @@ declare const runnerFrameSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
580
685
  }>;
581
686
  historyThrough: z.ZodNumber;
582
687
  workspaceUnavailable: z.ZodOptional<z.ZodLiteral<true>>;
688
+ reason: z.ZodOptional<z.ZodEnum<{
689
+ workflow_template_mismatch: "workflow_template_mismatch";
690
+ child_project_dir_invalid: "child_project_dir_invalid";
691
+ build_not_approved: "build_not_approved";
692
+ approval_question_missing: "approval_question_missing";
693
+ }>>;
583
694
  runId: z.ZodString;
584
695
  attemptId: z.ZodString;
585
696
  executionRevision: z.ZodNumber;
@@ -657,6 +768,15 @@ declare const runViewSchema: z.ZodObject<{
657
768
  }, z.core.$strict>], "visibility">;
658
769
  recordRevision: z.ZodNumber;
659
770
  label: z.ZodOptional<z.ZodString>;
771
+ key: z.ZodOptional<z.ZodString>;
772
+ parent: z.ZodOptional<z.ZodObject<{
773
+ runId: z.ZodString;
774
+ tokenCap: z.ZodNumber;
775
+ }, z.core.$strict>>;
776
+ delegation: z.ZodOptional<z.ZodObject<{
777
+ maxChildren: z.ZodNumber;
778
+ tokenBudget: z.ZodNumber;
779
+ }, z.core.$strict>>;
660
780
  workflow: z.ZodOptional<z.ZodObject<{
661
781
  name: z.ZodString;
662
782
  version: z.ZodOptional<z.ZodString>;
@@ -685,6 +805,7 @@ declare const runViewSchema: z.ZodObject<{
685
805
  question: "question";
686
806
  guidance: "guidance";
687
807
  recovery: "recovery";
808
+ waiting: "waiting";
688
809
  }>;
689
810
  message: z.ZodString;
690
811
  requestId: z.ZodOptional<z.ZodString>;
@@ -737,6 +858,15 @@ declare const runViewSchema: z.ZodObject<{
737
858
  bindingId: z.ZodString;
738
859
  }, z.core.$strict>>;
739
860
  }, z.core.$strict>;
861
+ key: z.ZodOptional<z.ZodString>;
862
+ delegation: z.ZodOptional<z.ZodObject<{
863
+ maxChildren: z.ZodNumber;
864
+ tokenBudget: z.ZodNumber;
865
+ }, z.core.$strict>>;
866
+ parent: z.ZodOptional<z.ZodObject<{
867
+ runId: z.ZodString;
868
+ tokenCap: z.ZodOptional<z.ZodNumber>;
869
+ }, z.core.$strict>>;
740
870
  }, z.core.$strict>, z.ZodObject<{
741
871
  kind: z.ZodLiteral<"cancel">;
742
872
  }, z.core.$strict>, z.ZodObject<{
@@ -823,6 +953,15 @@ declare const clientFrameSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
823
953
  bindingId: z.ZodString;
824
954
  }, z.core.$strict>>;
825
955
  }, z.core.$strict>;
956
+ key: z.ZodOptional<z.ZodString>;
957
+ delegation: z.ZodOptional<z.ZodObject<{
958
+ maxChildren: z.ZodNumber;
959
+ tokenBudget: z.ZodNumber;
960
+ }, z.core.$strict>>;
961
+ parent: z.ZodOptional<z.ZodObject<{
962
+ runId: z.ZodString;
963
+ tokenCap: z.ZodOptional<z.ZodNumber>;
964
+ }, z.core.$strict>>;
826
965
  }, z.core.$strict>, z.ZodObject<{
827
966
  kind: z.ZodLiteral<"cancel">;
828
967
  }, z.core.$strict>, z.ZodObject<{
@@ -921,6 +1060,11 @@ declare const checkpointSchema: z.ZodObject<{
921
1060
  checkpointId: z.ZodString;
922
1061
  checksum: z.ZodString;
923
1062
  }, z.core.$strict>>;
1063
+ delegationToken: z.ZodOptional<z.ZodString>;
1064
+ parent: z.ZodOptional<z.ZodObject<{
1065
+ runId: z.ZodString;
1066
+ tokenCap: z.ZodNumber;
1067
+ }, z.core.$strict>>;
924
1068
  }, z.core.$strict>;
925
1069
  gitHead: z.ZodString;
926
1070
  gitBase: z.ZodOptional<z.ZodString>;
@@ -1092,8 +1236,8 @@ declare const runsGoToSchema: z.ZodUnion<readonly [z.ZodObject<{
1092
1236
  }, z.core.$strict>, z.ZodObject<{
1093
1237
  via: z.ZodLiteral<"none">;
1094
1238
  reason: z.ZodEnum<{
1095
- no_runner_available: "no_runner_available";
1096
1239
  runner_needs_owner: "runner_needs_owner";
1240
+ no_runner_available: "no_runner_available";
1097
1241
  }>;
1098
1242
  }, z.core.$strict>]>;
1099
1243
  declare const runnerListSchema: z.ZodObject<{
@@ -1122,8 +1266,8 @@ declare const runnerListSchema: z.ZodObject<{
1122
1266
  }, z.core.$strict>, z.ZodObject<{
1123
1267
  via: z.ZodLiteral<"none">;
1124
1268
  reason: z.ZodEnum<{
1125
- no_runner_available: "no_runner_available";
1126
1269
  runner_needs_owner: "runner_needs_owner";
1270
+ no_runner_available: "no_runner_available";
1127
1271
  }>;
1128
1272
  }, z.core.$strict>]>>;
1129
1273
  minimumRunnerVersion: z.ZodOptional<z.ZodString>;
@@ -1280,4 +1424,4 @@ type ConnectPendingResponse = z.infer<typeof connectPendingResponseSchema>;
1280
1424
  type TeamDefault = z.infer<typeof teamDefaultSchema>;
1281
1425
  type RunsGoTo = z.infer<typeof runsGoToSchema>;
1282
1426
 
1283
- export { type Audience, type Checkpoint, type Command, type ConnectAlreadyConnected, type ConnectPendingResponse, type ConnectRedeemRequest, type ConnectRedeemResponse, type ConnectStartRequest, type ConnectStartResponse, type ControlRecord, type ExecutionFact, type Grant, type Harness, type HarnessReadiness, type HistoryRecord, type InstalledWorkflow, type RepositoryBinding, type RepositorySource, type RunView, type RunnerAdoptRequest, type RunnerDisconnectPreview, type RunnerDisconnectResponse, type RunnerFrame, type RunnerList, type RunnerListEntry, type RunnerReadiness, type RunsGoTo, type Scope, type TeamDefault, type WorkflowIdentity, type WorkflowInstallReference, type WorkflowReference, abandonedConversationContinuationCapability, audienceSchema, canonicalJson, checkpointPathSchema, checkpointSchema, clientFrameSchema, commandSchema, connectAlreadyConnectedSchema, connectApproveRequestSchema, connectCodeAlphabet, connectCodeRequestSchema, connectCodeResponseSchema, connectCodeSchema, connectDenyRequestSchema, connectPendingResponseSchema, connectPollRequestSchema, connectRedeemRequestSchema, connectRedeemResponseSchema, connectStartRequestSchema, connectStartResponseSchema, controlRecordSchema, conversationContinuationCapability, grantSchema, harnessReadinessSchema, harnessSchema, historyRecordSchema, hubEpochRequestSchema, installReference, installedWorkflowsSchema, interruptionSchema, permissionAnswerSchema, protocolVersion, readableHistory, readinessFixCommand, repositoryAccessCapability, repositoryBindingSchema, repositoryRefSchema, repositorySourceSchema, repositoryWorkingDirectorySchema, runSpecSchema, runViewSchema, runnerAdoptRequestSchema, runnerDisconnectPreviewSchema, runnerDisconnectRequestSchema, runnerDisconnectResponseSchema, runnerFrameSchema, runnerListEntrySchema, runnerListSchema, runnerReadinessSchema, runnerUpdateCommand, runnerUpdateRequestSchema, runsGoToSchema, sameWorkflow, scopeSchema, secretEnvironmentSchema, sequence, teamDefaultRequestSchema, teamDefaultSchema, workflowIdentitySchema, workflowInstallCapability, workflowName, workflowReferenceSchema, workflowSourceSchema };
1427
+ export { type Audience, type BuildCloseReason, type Checkpoint, type Command, type ConnectAlreadyConnected, type ConnectPendingResponse, type ConnectRedeemRequest, type ConnectRedeemResponse, type ConnectStartRequest, type ConnectStartResponse, type ControlRecord, type Delegation, type ExecutionFact, type Grant, type Harness, type HarnessReadiness, type HistoryRecord, type InstalledWorkflow, type RepositoryBinding, type RepositorySource, type RunCloseReason, type RunParent, type RunView, type RunnerAdoptRequest, type RunnerDisconnectPreview, type RunnerDisconnectResponse, type RunnerFrame, type RunnerList, type RunnerListEntry, type RunnerReadiness, type RunsGoTo, SIZE_CLASS_CAPS, SIZE_CLASS_FORECASTS, type Scope, type SizeClass, type TeamDefault, type WorkflowIdentity, type WorkflowInstallReference, type WorkflowReference, abandonedConversationContinuationCapability, attemptCost, audienceSchema, buildCloseReasonSchema, canonicalJson, checkpointPathSchema, checkpointSchema, classOfCap, clientFrameSchema, commandSchema, connectAlreadyConnectedSchema, connectApproveRequestSchema, connectCodeAlphabet, connectCodeRequestSchema, connectCodeResponseSchema, connectCodeSchema, connectDenyRequestSchema, connectPendingResponseSchema, connectPollRequestSchema, connectRedeemRequestSchema, connectRedeemResponseSchema, connectStartRequestSchema, connectStartResponseSchema, controlRecordSchema, conversationContinuationCapability, delegationSchema, delegationTokenPrefix, grantSchema, harnessReadinessSchema, harnessSchema, historyRecordSchema, hubEpochRequestSchema, installReference, installedWorkflowsSchema, interruptionSchema, permissionAnswerSchema, protocolVersion, readableHistory, readinessFixCommand, repositoryAccessCapability, repositoryBindingSchema, repositoryRefSchema, repositorySourceSchema, repositoryWorkingDirectorySchema, runArtifactMaxBytes, runArtifactNameSchema, runCloseReasonSchema, runDelegationCapability, runKeySchema, runParentIntentSchema, runParentSchema, runSpecSchema, runViewSchema, runnerAdoptRequestSchema, runnerDisconnectPreviewSchema, runnerDisconnectRequestSchema, runnerDisconnectResponseSchema, runnerFrameSchema, runnerListEntrySchema, runnerListSchema, runnerReadinessSchema, runnerUpdateCommand, runnerUpdateRequestSchema, runsGoToSchema, sameWorkflow, scopeSchema, secretEnvironmentSchema, sequence, teamDefaultRequestSchema, teamDefaultSchema, workflowIdentitySchema, workflowInstallCapability, workflowName, workflowReferenceSchema, workflowSourceSchema };
package/dist/v2.js CHANGED
@@ -47,12 +47,36 @@ function readableHistory(records) {
47
47
  return result;
48
48
  }
49
49
 
50
+ // src/budget.ts
51
+ var SIZE_CLASS_CAPS = {
52
+ S: 3e6,
53
+ M: 6e6,
54
+ L: 12e6
55
+ };
56
+ var SIZE_CLASS_FORECASTS = {
57
+ S: 15e4,
58
+ M: 4e5,
59
+ L: 12e5
60
+ };
61
+ function classOfCap(declaredCap) {
62
+ if (declaredCap <= SIZE_CLASS_CAPS.S) return "S";
63
+ if (declaredCap <= SIZE_CLASS_CAPS.M) return "M";
64
+ return "L";
65
+ }
66
+ function attemptCost(attempt) {
67
+ return attempt.closed ? SIZE_CLASS_FORECASTS[classOfCap(attempt.tokenCap)] : attempt.tokenCap;
68
+ }
69
+
50
70
  // src/v2.ts
51
- var protocolVersion = { major: 2, minor: 1 };
71
+ var protocolVersion = { major: 2, minor: 2 };
52
72
  var conversationContinuationCapability = "conversation_continuation";
53
73
  var abandonedConversationContinuationCapability = "abandoned_conversation_continuation";
54
74
  var repositoryAccessCapability = "repository_checkout_v1";
55
75
  var workflowInstallCapability = "workflow_install_v1";
76
+ var runDelegationCapability = "run_delegation_v1";
77
+ var delegationTokenPrefix = "drisp_dlg_";
78
+ var runArtifactNameSchema = z.string().regex(/^[a-z][a-z0-9_]{0,63}$/);
79
+ var runArtifactMaxBytes = 64 * 1024;
56
80
  var secretEnvironmentSchema = z.record(
57
81
  z.string().regex(/^(?:OPENAI_API_KEY|ANTHROPIC_API_KEY|CLAUDE_CODE_OAUTH_TOKEN|NPM_TOKEN|NODE_AUTH_TOKEN|PIP_INDEX_URL|PIP_EXTRA_INDEX_URL|UV_INDEX_URL|DRISP_TEST_[A-Z0-9_]+)$/),
58
82
  z.string().regex(/^projects\/[a-zA-Z0-9-]+\/secrets\/[a-zA-Z0-9_-]+\/versions\/(?:latest|[0-9]+)$/)
@@ -91,7 +115,8 @@ var runnerUpdateCommand = "npm i -g @drisp/cli";
91
115
  var interruptionSchema = z.strictObject({
92
116
  interruptionId: id,
93
117
  revision: positive,
94
- kind: z.enum(["permission", "question", "guidance", "recovery"]),
118
+ /** `waiting` (root ADR-0008) is non-human: a Run parked until one of its children closes or parks. */
119
+ kind: z.enum(["permission", "question", "guidance", "recovery", "waiting"]),
95
120
  message: z.string().max(16384),
96
121
  requestId: id.optional()
97
122
  });
@@ -99,6 +124,29 @@ var workflowIdentitySchema = z.strictObject({
99
124
  name: z.string().min(1).max(128),
100
125
  version: z.string().min(1).max(128).optional()
101
126
  });
127
+ var buildCloseReasonSchema = z.enum([
128
+ "workflow_template_mismatch",
129
+ "child_project_dir_invalid",
130
+ "build_not_approved",
131
+ "approval_question_missing"
132
+ ]);
133
+ var runCloseReasonSchema = z.enum([
134
+ "execution_terminal",
135
+ "cancelled_before_start",
136
+ "admission_failed",
137
+ "abandoned",
138
+ "managed_startup_timeout",
139
+ "runner_disconnected",
140
+ "runner_needs_owner",
141
+ "runner_not_available",
142
+ "runner_upgrade_required",
143
+ "legacy_succeeded",
144
+ "legacy_failed",
145
+ "legacy_cancelled",
146
+ "legacy_timeout",
147
+ "legacy_force_failed",
148
+ ...buildCloseReasonSchema.options
149
+ ]);
102
150
  var factIdentity = {
103
151
  runId: id,
104
152
  attemptId: id,
@@ -143,7 +191,12 @@ var controlRecordSchema = z.discriminatedUnion("kind", [
143
191
  status: z.enum(["completed", "failed", "cancelled"]),
144
192
  historyThrough: sequence,
145
193
  /** No setup/harness executed and no workspace was produced; safe to retire without export. */
146
- workspaceUnavailable: z.literal(true).optional()
194
+ workspaceUnavailable: z.literal(true).optional(),
195
+ /**
196
+ * Why a Build Run failed, as its close reason (docs/specs/build-orchestrator.md). Sent only for a grant with
197
+ * `parent` or `delegationToken`, which only a Hub that knows this field issues.
198
+ */
199
+ reason: buildCloseReasonSchema.optional()
147
200
  }),
148
201
  z.strictObject({ kind: z.literal("command.applied"), runId: id, attemptId: id, commandId: id }),
149
202
  z.strictObject({
@@ -207,6 +260,14 @@ var runSpecSchema = z.strictObject({
207
260
  workflow: workflowReferenceSchema.optional(),
208
261
  repository: repositorySourceSchema.optional()
209
262
  });
263
+ var runKeySchema = z.string().min(1).max(160);
264
+ var delegationSchema = z.strictObject({
265
+ maxChildren: z.number().int().min(1).max(8),
266
+ tokenBudget: z.number().int().positive().max(Number.MAX_SAFE_INTEGER)
267
+ });
268
+ var tokenCapSchema = z.number().int().positive().max(Number.MAX_SAFE_INTEGER);
269
+ var runParentIntentSchema = z.strictObject({ runId: id, tokenCap: tokenCapSchema.optional() });
270
+ var runParentSchema = z.strictObject({ runId: id, tokenCap: tokenCapSchema });
210
271
  var commandSchema = z.strictObject({
211
272
  commandId: id,
212
273
  hubEpoch: id,
@@ -223,7 +284,12 @@ var commandSchema = z.strictObject({
223
284
  runnerId: id.optional(),
224
285
  computeProfileId: id.optional(),
225
286
  scope: scopeSchema,
226
- spec: runSpecSchema
287
+ spec: runSpecSchema,
288
+ key: runKeySchema.optional(),
289
+ /** Member starts only. */
290
+ delegation: delegationSchema.optional(),
291
+ /** Delegated starts only, and required on them. */
292
+ parent: runParentIntentSchema.optional()
227
293
  }),
228
294
  z.strictObject({ kind: z.literal("cancel") }),
229
295
  z.strictObject({ kind: z.literal("abandon") }),
@@ -266,7 +332,11 @@ var grantSchema = z.strictObject({
266
332
  closeReason: z.literal("abandoned").optional(),
267
333
  checkpoint: z.strictObject({ checkpointId: id, checksum: z.string().regex(/^[a-f0-9]{64}$/) }).optional()
268
334
  }).optional(),
269
- checkpoint: z.strictObject({ checkpointId: id, checksum: z.string().regex(/^[a-f0-9]{64}$/) }).optional()
335
+ checkpoint: z.strictObject({ checkpointId: id, checksum: z.string().regex(/^[a-f0-9]{64}$/) }).optional(),
336
+ /** This attempt's delegation token: only for a Run started with `delegation`, only to a `run_delegation_v1` Runner. */
337
+ delegationToken: z.string().min(32).max(256).optional(),
338
+ /** Copied from the start intent of a delegated child. */
339
+ parent: runParentSchema.optional()
270
340
  });
271
341
  var historyRecordSchema = z.strictObject({
272
342
  eventId: id,
@@ -325,6 +395,9 @@ var runViewSchema = z.object({
325
395
  scope: scopeSchema,
326
396
  recordRevision: positive,
327
397
  label: z.string().max(160).optional(),
398
+ key: runKeySchema.optional(),
399
+ parent: runParentSchema.optional(),
400
+ delegation: delegationSchema.optional(),
328
401
  /** Resolved by the runner at start; absent until the Run starts and for runners that predate reporting. */
329
402
  workflow: workflowIdentitySchema.optional(),
330
403
  execution: z.object({
@@ -546,11 +619,16 @@ var connectApproveRequestSchema = z.strictObject({
546
619
  });
547
620
  var connectDenyRequestSchema = z.strictObject({ code: z.string().min(8).max(16) });
548
621
  export {
622
+ SIZE_CLASS_CAPS,
623
+ SIZE_CLASS_FORECASTS,
549
624
  abandonedConversationContinuationCapability,
625
+ attemptCost,
550
626
  audienceSchema,
627
+ buildCloseReasonSchema,
551
628
  canonicalJson,
552
629
  checkpointPathSchema,
553
630
  checkpointSchema,
631
+ classOfCap,
554
632
  clientFrameSchema,
555
633
  commandSchema,
556
634
  connectAlreadyConnectedSchema,
@@ -568,6 +646,8 @@ export {
568
646
  connectStartResponseSchema,
569
647
  controlRecordSchema,
570
648
  conversationContinuationCapability,
649
+ delegationSchema,
650
+ delegationTokenPrefix,
571
651
  grantSchema,
572
652
  harnessReadinessSchema,
573
653
  harnessSchema,
@@ -585,6 +665,13 @@ export {
585
665
  repositoryRefSchema,
586
666
  repositorySourceSchema,
587
667
  repositoryWorkingDirectorySchema,
668
+ runArtifactMaxBytes,
669
+ runArtifactNameSchema,
670
+ runCloseReasonSchema,
671
+ runDelegationCapability,
672
+ runKeySchema,
673
+ runParentIntentSchema,
674
+ runParentSchema,
588
675
  runSpecSchema,
589
676
  runViewSchema,
590
677
  runnerAdoptRequestSchema,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drisp/protocol",
3
- "version": "0.6.2",
3
+ "version": "0.8.1",
4
4
  "description": "Wire contract between a drisp runner and the hub: zod schemas, inferred types, and JSON Schema for the instance-socket frames, Run, Turn, Interruption, and the event stream",
5
5
  "repository": {
6
6
  "type": "git",
@@ -332,6 +332,31 @@
332
332
  "checksum"
333
333
  ],
334
334
  "additionalProperties": false
335
+ },
336
+ "delegationToken": {
337
+ "type": "string",
338
+ "minLength": 32,
339
+ "maxLength": 256
340
+ },
341
+ "parent": {
342
+ "type": "object",
343
+ "properties": {
344
+ "runId": {
345
+ "type": "string",
346
+ "minLength": 1,
347
+ "maxLength": 160
348
+ },
349
+ "tokenCap": {
350
+ "type": "integer",
351
+ "exclusiveMinimum": 0,
352
+ "maximum": 9007199254740991
353
+ }
354
+ },
355
+ "required": [
356
+ "runId",
357
+ "tokenCap"
358
+ ],
359
+ "additionalProperties": false
335
360
  }
336
361
  },
337
362
  "required": [
@@ -293,6 +293,50 @@
293
293
  "harness"
294
294
  ],
295
295
  "additionalProperties": false
296
+ },
297
+ "key": {
298
+ "type": "string",
299
+ "minLength": 1,
300
+ "maxLength": 160
301
+ },
302
+ "delegation": {
303
+ "type": "object",
304
+ "properties": {
305
+ "maxChildren": {
306
+ "type": "integer",
307
+ "minimum": 1,
308
+ "maximum": 8
309
+ },
310
+ "tokenBudget": {
311
+ "type": "integer",
312
+ "exclusiveMinimum": 0,
313
+ "maximum": 9007199254740991
314
+ }
315
+ },
316
+ "required": [
317
+ "maxChildren",
318
+ "tokenBudget"
319
+ ],
320
+ "additionalProperties": false
321
+ },
322
+ "parent": {
323
+ "type": "object",
324
+ "properties": {
325
+ "runId": {
326
+ "type": "string",
327
+ "minLength": 1,
328
+ "maxLength": 160
329
+ },
330
+ "tokenCap": {
331
+ "type": "integer",
332
+ "exclusiveMinimum": 0,
333
+ "maximum": 9007199254740991
334
+ }
335
+ },
336
+ "required": [
337
+ "runId"
338
+ ],
339
+ "additionalProperties": false
296
340
  }
297
341
  },
298
342
  "required": [
@@ -230,6 +230,50 @@
230
230
  "harness"
231
231
  ],
232
232
  "additionalProperties": false
233
+ },
234
+ "key": {
235
+ "type": "string",
236
+ "minLength": 1,
237
+ "maxLength": 160
238
+ },
239
+ "delegation": {
240
+ "type": "object",
241
+ "properties": {
242
+ "maxChildren": {
243
+ "type": "integer",
244
+ "minimum": 1,
245
+ "maximum": 8
246
+ },
247
+ "tokenBudget": {
248
+ "type": "integer",
249
+ "exclusiveMinimum": 0,
250
+ "maximum": 9007199254740991
251
+ }
252
+ },
253
+ "required": [
254
+ "maxChildren",
255
+ "tokenBudget"
256
+ ],
257
+ "additionalProperties": false
258
+ },
259
+ "parent": {
260
+ "type": "object",
261
+ "properties": {
262
+ "runId": {
263
+ "type": "string",
264
+ "minLength": 1,
265
+ "maxLength": 160
266
+ },
267
+ "tokenCap": {
268
+ "type": "integer",
269
+ "exclusiveMinimum": 0,
270
+ "maximum": 9007199254740991
271
+ }
272
+ },
273
+ "required": [
274
+ "runId"
275
+ ],
276
+ "additionalProperties": false
233
277
  }
234
278
  },
235
279
  "required": [
@@ -283,6 +283,31 @@
283
283
  "checksum"
284
284
  ],
285
285
  "additionalProperties": false
286
+ },
287
+ "delegationToken": {
288
+ "type": "string",
289
+ "minLength": 32,
290
+ "maxLength": 256
291
+ },
292
+ "parent": {
293
+ "type": "object",
294
+ "properties": {
295
+ "runId": {
296
+ "type": "string",
297
+ "minLength": 1,
298
+ "maxLength": 160
299
+ },
300
+ "tokenCap": {
301
+ "type": "integer",
302
+ "exclusiveMinimum": 0,
303
+ "maximum": 9007199254740991
304
+ }
305
+ },
306
+ "required": [
307
+ "runId",
308
+ "tokenCap"
309
+ ],
310
+ "additionalProperties": false
286
311
  }
287
312
  },
288
313
  "required": [
@@ -67,6 +67,51 @@
67
67
  "type": "string",
68
68
  "maxLength": 160
69
69
  },
70
+ "key": {
71
+ "type": "string",
72
+ "minLength": 1,
73
+ "maxLength": 160
74
+ },
75
+ "parent": {
76
+ "type": "object",
77
+ "properties": {
78
+ "runId": {
79
+ "type": "string",
80
+ "minLength": 1,
81
+ "maxLength": 160
82
+ },
83
+ "tokenCap": {
84
+ "type": "integer",
85
+ "exclusiveMinimum": 0,
86
+ "maximum": 9007199254740991
87
+ }
88
+ },
89
+ "required": [
90
+ "runId",
91
+ "tokenCap"
92
+ ],
93
+ "additionalProperties": false
94
+ },
95
+ "delegation": {
96
+ "type": "object",
97
+ "properties": {
98
+ "maxChildren": {
99
+ "type": "integer",
100
+ "minimum": 1,
101
+ "maximum": 8
102
+ },
103
+ "tokenBudget": {
104
+ "type": "integer",
105
+ "exclusiveMinimum": 0,
106
+ "maximum": 9007199254740991
107
+ }
108
+ },
109
+ "required": [
110
+ "maxChildren",
111
+ "tokenBudget"
112
+ ],
113
+ "additionalProperties": false
114
+ },
70
115
  "workflow": {
71
116
  "type": "object",
72
117
  "properties": {
@@ -147,7 +192,8 @@
147
192
  "permission",
148
193
  "question",
149
194
  "guidance",
150
- "recovery"
195
+ "recovery",
196
+ "waiting"
151
197
  ]
152
198
  },
153
199
  "message": {
@@ -410,6 +456,50 @@
410
456
  "harness"
411
457
  ],
412
458
  "additionalProperties": false
459
+ },
460
+ "key": {
461
+ "type": "string",
462
+ "minLength": 1,
463
+ "maxLength": 160
464
+ },
465
+ "delegation": {
466
+ "type": "object",
467
+ "properties": {
468
+ "maxChildren": {
469
+ "type": "integer",
470
+ "minimum": 1,
471
+ "maximum": 8
472
+ },
473
+ "tokenBudget": {
474
+ "type": "integer",
475
+ "exclusiveMinimum": 0,
476
+ "maximum": 9007199254740991
477
+ }
478
+ },
479
+ "required": [
480
+ "maxChildren",
481
+ "tokenBudget"
482
+ ],
483
+ "additionalProperties": false
484
+ },
485
+ "parent": {
486
+ "type": "object",
487
+ "properties": {
488
+ "runId": {
489
+ "type": "string",
490
+ "minLength": 1,
491
+ "maxLength": 160
492
+ },
493
+ "tokenCap": {
494
+ "type": "integer",
495
+ "exclusiveMinimum": 0,
496
+ "maximum": 9007199254740991
497
+ }
498
+ },
499
+ "required": [
500
+ "runId"
501
+ ],
502
+ "additionalProperties": false
413
503
  }
414
504
  },
415
505
  "required": [
@@ -614,7 +614,8 @@
614
614
  "permission",
615
615
  "question",
616
616
  "guidance",
617
- "recovery"
617
+ "recovery",
618
+ "waiting"
618
619
  ]
619
620
  },
620
621
  "message": {
@@ -777,6 +778,15 @@
777
778
  "workspaceUnavailable": {
778
779
  "type": "boolean",
779
780
  "const": true
781
+ },
782
+ "reason": {
783
+ "type": "string",
784
+ "enum": [
785
+ "workflow_template_mismatch",
786
+ "child_project_dir_invalid",
787
+ "build_not_approved",
788
+ "approval_question_missing"
789
+ ]
780
790
  }
781
791
  },
782
792
  "required": [