@drisp/protocol 0.8.5 → 0.8.7

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
@@ -18,14 +18,40 @@ declare function classOfCap(declaredCap: number): SizeClass;
18
18
  /** What a Run declaring `declaredCap` is expected to use: its class's forecast. */
19
19
  declare function forecastOfCap(declaredCap: number): number;
20
20
  /**
21
- * What one attempt holds against the budget: a closed attempt (finished, failed, cancelled) its forecast, never more
22
- * than its own declared cap (so the rule stays looser than the cap sum it replaces); a running or queued one still its
23
- * declared cap. A closed attempt whose cap is no positive number counts its forecast.
21
+ * What an attempt declaring `declaredCap` is expected to use: its class's forecast, never more than its own cap (so
22
+ * the rule stays looser than the cap sum it replaces). A cap that is no positive number counts the `S` forecast.
24
23
  */
25
- declare function attemptCost(attempt: {
24
+ declare function attemptForecast(declaredCap: number): number;
25
+ /**
26
+ * One attempt of a child: its declared cap, whether it has closed, and the counted tokens (cache reads excluded) its
27
+ * Runner reported, if any. An older Runner never reports, so its attempts count their forecast.
28
+ */
29
+ type BudgetAttempt = {
26
30
  tokenCap: number;
27
31
  closed: boolean;
28
- }): number;
32
+ spent?: number;
33
+ };
34
+ /**
35
+ * What one attempt holds against the budget: a closed attempt (finished, failed, cancelled) what it reported, else its
36
+ * forecast; a running or queued one the larger of its forecast and what it reported, so a resumed attempt never counts
37
+ * the same tokens twice and an overrun counts once reported. Never more than its own positive declared cap: a Run
38
+ * reports a little past its cap before it is stopped, and the rule must stay looser than the cap sum it replaces, so
39
+ * the Hub never refuses a start the declared-cap rule accepted.
40
+ */
41
+ declare function attemptCost(attempt: BudgetAttempt): number;
42
+ /**
43
+ * The budget rule the CLI and the Hub share (root ADR-0011). `used` is the sum over every attempt of every child, a
44
+ * retry being a new attempt; the next start, forecast at `next`, fits when `used + next` is within the budget. Issues
45
+ * not yet started never enter it: the app warns of them on the plan sheet (Kit `shortfallNote`) and nothing parks.
46
+ */
47
+ declare function budgetCheck(input: {
48
+ tokenBudget: number;
49
+ attempts: readonly BudgetAttempt[];
50
+ next: number;
51
+ }): {
52
+ used: number;
53
+ fits: boolean;
54
+ };
29
55
  /** A class needs this many finished Runs of a harness before its forecast is measured (DRI-244). */
30
56
  declare const CALIBRATION_MIN_RUNS = 10;
31
57
  /** Only Runs closed within this many days count. */
@@ -81,6 +107,8 @@ declare const workflowInstallCapability = "workflow_install_v1";
81
107
  * token to the agent as `DRISP_RUN_TOKEN`. A start with `delegation` is never sent to a runner without it.
82
108
  */
83
109
  declare const runDelegationCapability = "run_delegation_v1";
110
+ /** Authenticated Orchestrator guidance retains its source in prompts and history. */
111
+ declare const orchestratorGuidanceCapability = "orchestrator_guidance_v1";
84
112
  /**
85
113
  * The runner takes grants marked `reportUsage` (protocol minor 3, root ADR-0011) and, for those only, reports the
86
114
  * Run's usage: on `run.attention` and `run.finished`, and as `run.usage` while it executes. A Hub that does not know
@@ -172,6 +200,9 @@ declare const interruptionSchema: z.ZodObject<{
172
200
  waiting: "waiting";
173
201
  }>;
174
202
  message: z.ZodString;
203
+ respondent: z.ZodOptional<z.ZodEnum<{
204
+ orchestrator: "orchestrator";
205
+ }>>;
175
206
  requestId: z.ZodOptional<z.ZodString>;
176
207
  }, z.core.$strict>;
177
208
  /** The Workflow a Run resolved on its runner: the registry name and, when the Workflow declares one, its version. */
@@ -297,6 +328,9 @@ declare const controlRecordSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
297
328
  waiting: "waiting";
298
329
  }>;
299
330
  message: z.ZodString;
331
+ respondent: z.ZodOptional<z.ZodEnum<{
332
+ orchestrator: "orchestrator";
333
+ }>>;
300
334
  requestId: z.ZodOptional<z.ZodString>;
301
335
  }, z.core.$strict>;
302
336
  occupancy: z.ZodEnum<{
@@ -452,7 +486,7 @@ declare const runSpecSchema: z.ZodObject<{
452
486
  declare const runKeySchema: z.ZodString;
453
487
  /** A member start's grant to start, limit and stop its own children (root ADR-0008). */
454
488
  declare const delegationSchema: z.ZodObject<{
455
- maxChildren: z.ZodNumber;
489
+ maxChildren: z.ZodOptional<z.ZodNumber>;
456
490
  tokenBudget: z.ZodNumber;
457
491
  }, z.core.$strict>;
458
492
  /** A child's parent and declared token cap. Required on a delegated start; the Hub refuses it without `tokenCap`. */
@@ -511,7 +545,7 @@ declare const commandSchema: z.ZodObject<{
511
545
  }, z.core.$strict>;
512
546
  key: z.ZodOptional<z.ZodString>;
513
547
  delegation: z.ZodOptional<z.ZodObject<{
514
- maxChildren: z.ZodNumber;
548
+ maxChildren: z.ZodOptional<z.ZodNumber>;
515
549
  tokenBudget: z.ZodNumber;
516
550
  }, z.core.$strict>>;
517
551
  parent: z.ZodOptional<z.ZodObject<{
@@ -535,8 +569,90 @@ declare const commandSchema: z.ZodObject<{
535
569
  kind: z.ZodLiteral<"resume">;
536
570
  interruptionId: z.ZodString;
537
571
  guidance: z.ZodOptional<z.ZodString>;
572
+ }, z.core.$strict>, z.ZodObject<{
573
+ kind: z.ZodLiteral<"setBudget">;
574
+ tokenBudget: z.ZodNumber;
575
+ resume: z.ZodOptional<z.ZodBoolean>;
538
576
  }, z.core.$strict>], "kind">;
539
577
  }, z.core.$strict>;
578
+ /** Hub-authored provenance, never accepted on a client-submitted command. */
579
+ declare const deliveredCommandSchema: z.ZodObject<{
580
+ commandId: z.ZodString;
581
+ hubEpoch: z.ZodString;
582
+ runId: z.ZodString;
583
+ expectedRecordRevision: z.ZodOptional<z.ZodNumber>;
584
+ intent: z.ZodDiscriminatedUnion<[z.ZodObject<{
585
+ kind: z.ZodLiteral<"start">;
586
+ sessionId: z.ZodString;
587
+ runnerId: z.ZodOptional<z.ZodString>;
588
+ computeProfileId: z.ZodOptional<z.ZodString>;
589
+ scope: z.ZodDiscriminatedUnion<[z.ZodObject<{
590
+ visibility: z.ZodLiteral<"organization">;
591
+ }, z.core.$strict>, z.ZodObject<{
592
+ visibility: z.ZodLiteral<"private">;
593
+ ownerUserId: z.ZodString;
594
+ }, z.core.$strict>], "visibility">;
595
+ spec: z.ZodObject<{
596
+ prompt: z.ZodString;
597
+ projectDir: z.ZodString;
598
+ harness: z.ZodEnum<{
599
+ "claude-code": "claude-code";
600
+ codex: "codex";
601
+ }>;
602
+ workflow: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
603
+ name: z.ZodString;
604
+ source: z.ZodOptional<z.ZodString>;
605
+ ref: z.ZodOptional<z.ZodString>;
606
+ version: z.ZodOptional<z.ZodString>;
607
+ }, z.core.$strict>]>>;
608
+ repository: z.ZodOptional<z.ZodObject<{
609
+ ref: z.ZodString;
610
+ commitSha: z.ZodString;
611
+ branch: z.ZodString;
612
+ workingDirectory: z.ZodString;
613
+ setupCommands: z.ZodArray<z.ZodString>;
614
+ configRevision: z.ZodNumber;
615
+ repositoryId: z.ZodNumber;
616
+ installationId: z.ZodNumber;
617
+ owner: z.ZodString;
618
+ name: z.ZodString;
619
+ bindingId: z.ZodString;
620
+ }, z.core.$strict>>;
621
+ }, z.core.$strict>;
622
+ key: z.ZodOptional<z.ZodString>;
623
+ delegation: z.ZodOptional<z.ZodObject<{
624
+ maxChildren: z.ZodOptional<z.ZodNumber>;
625
+ tokenBudget: z.ZodNumber;
626
+ }, z.core.$strict>>;
627
+ parent: z.ZodOptional<z.ZodObject<{
628
+ runId: z.ZodString;
629
+ tokenCap: z.ZodOptional<z.ZodNumber>;
630
+ }, z.core.$strict>>;
631
+ }, z.core.$strict>, z.ZodObject<{
632
+ kind: z.ZodLiteral<"cancel">;
633
+ }, z.core.$strict>, z.ZodObject<{
634
+ kind: z.ZodLiteral<"abandon">;
635
+ }, z.core.$strict>, z.ZodObject<{
636
+ kind: z.ZodLiteral<"steer">;
637
+ text: z.ZodString;
638
+ }, z.core.$strict>, z.ZodObject<{
639
+ kind: z.ZodLiteral<"answer">;
640
+ interruptionId: z.ZodString;
641
+ expectedInterruptionRevision: z.ZodNumber;
642
+ requestId: z.ZodOptional<z.ZodString>;
643
+ answer: z.ZodJSONSchema;
644
+ }, z.core.$strict>, z.ZodObject<{
645
+ kind: z.ZodLiteral<"resume">;
646
+ interruptionId: z.ZodString;
647
+ guidance: z.ZodOptional<z.ZodString>;
648
+ }, z.core.$strict>, z.ZodObject<{
649
+ kind: z.ZodLiteral<"setBudget">;
650
+ tokenBudget: z.ZodNumber;
651
+ resume: z.ZodOptional<z.ZodBoolean>;
652
+ }, z.core.$strict>], "kind">;
653
+ orchestratorRunId: z.ZodOptional<z.ZodString>;
654
+ }, z.core.$strict>;
655
+ type DeliveredCommand = z.infer<typeof deliveredCommandSchema>;
540
656
  declare const grantSchema: z.ZodObject<{
541
657
  commandId: z.ZodString;
542
658
  hubEpoch: z.ZodString;
@@ -581,6 +697,7 @@ declare const grantSchema: z.ZodObject<{
581
697
  }, z.core.$strict>>;
582
698
  }, z.core.$strict>;
583
699
  continuation: z.ZodOptional<z.ZodJSONSchema>;
700
+ orchestratorRunId: z.ZodOptional<z.ZodString>;
584
701
  previousRun: z.ZodOptional<z.ZodObject<{
585
702
  runId: z.ZodString;
586
703
  executionRevision: z.ZodNumber;
@@ -730,6 +847,9 @@ declare const runnerFrameSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
730
847
  waiting: "waiting";
731
848
  }>;
732
849
  message: z.ZodString;
850
+ respondent: z.ZodOptional<z.ZodEnum<{
851
+ orchestrator: "orchestrator";
852
+ }>>;
733
853
  requestId: z.ZodOptional<z.ZodString>;
734
854
  }, z.core.$strict>;
735
855
  occupancy: z.ZodEnum<{
@@ -861,7 +981,7 @@ declare const runViewSchema: z.ZodObject<{
861
981
  tokenCap: z.ZodNumber;
862
982
  }, z.core.$strict>>;
863
983
  delegation: z.ZodOptional<z.ZodObject<{
864
- maxChildren: z.ZodNumber;
984
+ maxChildren: z.ZodOptional<z.ZodNumber>;
865
985
  tokenBudget: z.ZodNumber;
866
986
  }, z.core.$strip>>;
867
987
  usage: z.ZodOptional<z.ZodObject<{
@@ -899,6 +1019,9 @@ declare const runViewSchema: z.ZodObject<{
899
1019
  waiting: "waiting";
900
1020
  }>;
901
1021
  message: z.ZodString;
1022
+ respondent: z.ZodOptional<z.ZodEnum<{
1023
+ orchestrator: "orchestrator";
1024
+ }>>;
902
1025
  requestId: z.ZodOptional<z.ZodString>;
903
1026
  }, z.core.$strict>>;
904
1027
  }, z.core.$strip>>;
@@ -951,7 +1074,7 @@ declare const runViewSchema: z.ZodObject<{
951
1074
  }, z.core.$strict>;
952
1075
  key: z.ZodOptional<z.ZodString>;
953
1076
  delegation: z.ZodOptional<z.ZodObject<{
954
- maxChildren: z.ZodNumber;
1077
+ maxChildren: z.ZodOptional<z.ZodNumber>;
955
1078
  tokenBudget: z.ZodNumber;
956
1079
  }, z.core.$strict>>;
957
1080
  parent: z.ZodOptional<z.ZodObject<{
@@ -975,6 +1098,10 @@ declare const runViewSchema: z.ZodObject<{
975
1098
  kind: z.ZodLiteral<"resume">;
976
1099
  interruptionId: z.ZodString;
977
1100
  guidance: z.ZodOptional<z.ZodString>;
1101
+ }, z.core.$strict>, z.ZodObject<{
1102
+ kind: z.ZodLiteral<"setBudget">;
1103
+ tokenBudget: z.ZodNumber;
1104
+ resume: z.ZodOptional<z.ZodBoolean>;
978
1105
  }, z.core.$strict>], "kind">>;
979
1106
  runnerStopped: z.ZodOptional<z.ZodBoolean>;
980
1107
  canAbandon: z.ZodOptional<z.ZodBoolean>;
@@ -1046,7 +1173,7 @@ declare const clientFrameSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
1046
1173
  }, z.core.$strict>;
1047
1174
  key: z.ZodOptional<z.ZodString>;
1048
1175
  delegation: z.ZodOptional<z.ZodObject<{
1049
- maxChildren: z.ZodNumber;
1176
+ maxChildren: z.ZodOptional<z.ZodNumber>;
1050
1177
  tokenBudget: z.ZodNumber;
1051
1178
  }, z.core.$strict>>;
1052
1179
  parent: z.ZodOptional<z.ZodObject<{
@@ -1070,6 +1197,10 @@ declare const clientFrameSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
1070
1197
  kind: z.ZodLiteral<"resume">;
1071
1198
  interruptionId: z.ZodString;
1072
1199
  guidance: z.ZodOptional<z.ZodString>;
1200
+ }, z.core.$strict>, z.ZodObject<{
1201
+ kind: z.ZodLiteral<"setBudget">;
1202
+ tokenBudget: z.ZodNumber;
1203
+ resume: z.ZodOptional<z.ZodBoolean>;
1073
1204
  }, z.core.$strict>], "kind">;
1074
1205
  }, z.core.$strict>;
1075
1206
  }, z.core.$strict>, z.ZodObject<{
@@ -1137,6 +1268,7 @@ declare const checkpointSchema: z.ZodObject<{
1137
1268
  }, z.core.$strict>>;
1138
1269
  }, z.core.$strict>;
1139
1270
  continuation: z.ZodOptional<z.ZodJSONSchema>;
1271
+ orchestratorRunId: z.ZodOptional<z.ZodString>;
1140
1272
  previousRun: z.ZodOptional<z.ZodObject<{
1141
1273
  runId: z.ZodString;
1142
1274
  executionRevision: z.ZodNumber;
@@ -1516,4 +1648,4 @@ type ConnectPendingResponse = z.infer<typeof connectPendingResponseSchema>;
1516
1648
  type TeamDefault = z.infer<typeof teamDefaultSchema>;
1517
1649
  type RunsGoTo = z.infer<typeof runsGoToSchema>;
1518
1650
 
1519
- export { type Audience, type BuildCloseReason, CALIBRATION_MIN_RUNS, CALIBRATION_WINDOW_DAYS, type Calibration, type CalibrationSample, type Checkpoint, type ClassCalibration, 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 RunUsage, 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, calibrate, calibrationSchema, canonicalJson, checkpointPathSchema, checkpointSchema, classOfCap, clientFrameSchema, commandSchema, connectAlreadyConnectedSchema, connectApproveRequestSchema, connectCodeAlphabet, connectCodeRequestSchema, connectCodeResponseSchema, connectCodeSchema, connectDenyRequestSchema, connectPendingResponseSchema, connectPollRequestSchema, connectRedeemRequestSchema, connectRedeemResponseSchema, connectStartRequestSchema, connectStartResponseSchema, controlRecordSchema, conversationContinuationCapability, delegationSchema, delegationTokenPrefix, forecastOfCap, forecastOfClass, 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, runUsageCapability, runUsageSchema, runViewSchema, runnerAdoptRequestSchema, runnerDisconnectPreviewSchema, runnerDisconnectRequestSchema, runnerDisconnectResponseSchema, runnerFrameSchema, runnerListEntrySchema, runnerListSchema, runnerReadinessSchema, runnerUpdateCommand, runnerUpdateRequestSchema, runsGoToSchema, sameWorkflow, scopeSchema, secretEnvironmentSchema, sequence, teamDefaultRequestSchema, teamDefaultSchema, workflowIdentitySchema, workflowInstallCapability, workflowName, workflowReferenceSchema, workflowSourceSchema };
1651
+ export { type Audience, type BudgetAttempt, type BuildCloseReason, CALIBRATION_MIN_RUNS, CALIBRATION_WINDOW_DAYS, type Calibration, type CalibrationSample, type Checkpoint, type ClassCalibration, type Command, type ConnectAlreadyConnected, type ConnectPendingResponse, type ConnectRedeemRequest, type ConnectRedeemResponse, type ConnectStartRequest, type ConnectStartResponse, type ControlRecord, type Delegation, type DeliveredCommand, type ExecutionFact, type Grant, type Harness, type HarnessReadiness, type HistoryRecord, type InstalledWorkflow, type RepositoryBinding, type RepositorySource, type RunCloseReason, type RunParent, type RunUsage, 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, attemptForecast, audienceSchema, budgetCheck, buildCloseReasonSchema, calibrate, calibrationSchema, canonicalJson, checkpointPathSchema, checkpointSchema, classOfCap, clientFrameSchema, commandSchema, connectAlreadyConnectedSchema, connectApproveRequestSchema, connectCodeAlphabet, connectCodeRequestSchema, connectCodeResponseSchema, connectCodeSchema, connectDenyRequestSchema, connectPendingResponseSchema, connectPollRequestSchema, connectRedeemRequestSchema, connectRedeemResponseSchema, connectStartRequestSchema, connectStartResponseSchema, controlRecordSchema, conversationContinuationCapability, delegationSchema, delegationTokenPrefix, deliveredCommandSchema, forecastOfCap, forecastOfClass, grantSchema, harnessReadinessSchema, harnessSchema, historyRecordSchema, hubEpochRequestSchema, installReference, installedWorkflowsSchema, interruptionSchema, orchestratorGuidanceCapability, permissionAnswerSchema, protocolVersion, readableHistory, readinessFixCommand, repositoryAccessCapability, repositoryBindingSchema, repositoryRefSchema, repositorySourceSchema, repositoryWorkingDirectorySchema, runArtifactMaxBytes, runArtifactNameSchema, runCloseReasonSchema, runDelegationCapability, runKeySchema, runParentIntentSchema, runParentSchema, runSpecSchema, runUsageCapability, runUsageSchema, 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
@@ -67,10 +67,18 @@ function classOfCap(declaredCap) {
67
67
  function forecastOfCap(declaredCap) {
68
68
  return SIZE_CLASS_FORECASTS[classOfCap(declaredCap)];
69
69
  }
70
+ function attemptForecast(declaredCap) {
71
+ const forecast = forecastOfCap(declaredCap);
72
+ return declaredCap > 0 ? Math.min(declaredCap, forecast) : forecast;
73
+ }
70
74
  function attemptCost(attempt) {
71
- if (!attempt.closed) return attempt.tokenCap;
72
- const forecast = forecastOfCap(attempt.tokenCap);
73
- return attempt.tokenCap > 0 ? Math.min(attempt.tokenCap, forecast) : forecast;
75
+ const forecast = attemptForecast(attempt.tokenCap);
76
+ const cost = attempt.closed ? attempt.spent ?? forecast : Math.max(forecast, attempt.spent ?? 0);
77
+ return attempt.tokenCap > 0 ? Math.min(attempt.tokenCap, cost) : cost;
78
+ }
79
+ function budgetCheck(input) {
80
+ const used = input.attempts.reduce((sum, attempt) => sum + attemptCost(attempt), 0);
81
+ return { used, fits: used + input.next <= input.tokenBudget };
74
82
  }
75
83
  var CALIBRATION_MIN_RUNS = 10;
76
84
  var CALIBRATION_WINDOW_DAYS = 90;
@@ -109,6 +117,7 @@ var abandonedConversationContinuationCapability = "abandoned_conversation_contin
109
117
  var repositoryAccessCapability = "repository_checkout_v1";
110
118
  var workflowInstallCapability = "workflow_install_v1";
111
119
  var runDelegationCapability = "run_delegation_v1";
120
+ var orchestratorGuidanceCapability = "orchestrator_guidance_v1";
112
121
  var runUsageCapability = "run_usage_v1";
113
122
  var delegationTokenPrefix = "drisp_dlg_";
114
123
  var runArtifactNameSchema = z2.string().regex(/^[a-z][a-z0-9_]{0,63}$/);
@@ -154,6 +163,8 @@ var interruptionSchema = z2.strictObject({
154
163
  /** `waiting` (root ADR-0008) is non-human: a Run parked until one of its children closes or parks. */
155
164
  kind: z2.enum(["permission", "question", "guidance", "recovery", "waiting"]),
156
165
  message: z2.string().max(16384),
166
+ /** Explicit technical question for a parent; absent always reserves the answer to a member. */
167
+ respondent: z2.enum(["orchestrator"]).optional(),
157
168
  requestId: id.optional()
158
169
  });
159
170
  var workflowIdentitySchema = z2.strictObject({
@@ -307,7 +318,8 @@ var runSpecSchema = z2.strictObject({
307
318
  });
308
319
  var runKeySchema = z2.string().min(1).max(160);
309
320
  var delegationSchema = z2.strictObject({
310
- maxChildren: z2.number().int().min(1).max(8),
321
+ // Omitted: follow the Runner capacity. An explicit value is a per-Build ceiling.
322
+ maxChildren: z2.number().int().min(1).max(64).optional(),
311
323
  tokenBudget: z2.number().int().positive().max(Number.MAX_SAFE_INTEGER)
312
324
  });
313
325
  var tokenCapSchema = z2.number().int().positive().max(Number.MAX_SAFE_INTEGER);
@@ -350,9 +362,20 @@ var commandSchema = z2.strictObject({
350
362
  kind: z2.literal("resume"),
351
363
  interruptionId: id,
352
364
  guidance: z2.string().max(131072).optional()
365
+ }),
366
+ /**
367
+ * A member rewrites an Orchestrator's `delegation.tokenBudget` (root ADR-0011), never below what its children
368
+ * used. With `resume`, a parked Orchestrator with no live child is resumed when the value is strictly greater.
369
+ * Hub-only: never delivered to a Runner.
370
+ */
371
+ z2.strictObject({
372
+ kind: z2.literal("setBudget"),
373
+ tokenBudget: delegationSchema.shape.tokenBudget,
374
+ resume: z2.boolean().optional()
353
375
  })
354
376
  ])
355
377
  });
378
+ var deliveredCommandSchema = commandSchema.extend({ orchestratorRunId: id.optional() });
356
379
  var grantSchema = z2.strictObject({
357
380
  commandId: id,
358
381
  hubEpoch: id,
@@ -368,6 +391,8 @@ var grantSchema = z2.strictObject({
368
391
  purpose: z2.enum(["start", "resume"]),
369
392
  spec: runSpecSchema,
370
393
  continuation: z2.json().optional(),
394
+ /** Authenticated source of a delegated continuation; absence retains member semantics. */
395
+ orchestratorRunId: id.optional(),
371
396
  /** A new Run in a durable conversation; never resumes the predecessor's lifecycle. */
372
397
  previousRun: z2.strictObject({
373
398
  runId: id,
@@ -448,7 +473,11 @@ var runViewSchema = z2.object({
448
473
  * Not strict, unlike the start intent's: a Hub keeps more on the Run's delegation (`initialTokenBudget`) than it
449
474
  * shows, and a client never refuses a view for a field it does not read.
450
475
  */
451
- delegation: z2.object(delegationSchema.shape).optional(),
476
+ delegation: z2.object({
477
+ ...delegationSchema.shape,
478
+ // A resolved Runner default may exceed the explicit settings ceiling on configured Runners.
479
+ maxChildren: z2.number().int().positive().max(Number.MAX_SAFE_INTEGER).optional()
480
+ }).optional(),
452
481
  /** The largest cumulative usage the Run's Runner reported; absent until one does (an older Runner never does). */
453
482
  usage: runUsageSchema.optional(),
454
483
  /** Resolved by the runner at start; absent until the Run starts and for runners that predate reporting. */
@@ -678,7 +707,9 @@ export {
678
707
  SIZE_CLASS_FORECASTS,
679
708
  abandonedConversationContinuationCapability,
680
709
  attemptCost,
710
+ attemptForecast,
681
711
  audienceSchema,
712
+ budgetCheck,
682
713
  buildCloseReasonSchema,
683
714
  calibrate,
684
715
  calibrationSchema,
@@ -705,6 +736,7 @@ export {
705
736
  conversationContinuationCapability,
706
737
  delegationSchema,
707
738
  delegationTokenPrefix,
739
+ deliveredCommandSchema,
708
740
  forecastOfCap,
709
741
  forecastOfClass,
710
742
  grantSchema,
@@ -715,6 +747,7 @@ export {
715
747
  installReference,
716
748
  installedWorkflowsSchema,
717
749
  interruptionSchema,
750
+ orchestratorGuidanceCapability,
718
751
  permissionAnswerSchema,
719
752
  protocolVersion,
720
753
  readableHistory,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drisp/protocol",
3
- "version": "0.8.5",
3
+ "version": "0.8.7",
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",
@@ -265,6 +265,11 @@
265
265
  "continuation": {
266
266
  "$ref": "#/$defs/__schema0"
267
267
  },
268
+ "orchestratorRunId": {
269
+ "type": "string",
270
+ "minLength": 1,
271
+ "maxLength": 160
272
+ },
268
273
  "previousRun": {
269
274
  "type": "object",
270
275
  "properties": {
@@ -305,7 +305,7 @@
305
305
  "maxChildren": {
306
306
  "type": "integer",
307
307
  "minimum": 1,
308
- "maximum": 8
308
+ "maximum": 64
309
309
  },
310
310
  "tokenBudget": {
311
311
  "type": "integer",
@@ -314,7 +314,6 @@
314
314
  }
315
315
  },
316
316
  "required": [
317
- "maxChildren",
318
317
  "tokenBudget"
319
318
  ],
320
319
  "additionalProperties": false
@@ -448,6 +447,28 @@
448
447
  "interruptionId"
449
448
  ],
450
449
  "additionalProperties": false
450
+ },
451
+ {
452
+ "type": "object",
453
+ "properties": {
454
+ "kind": {
455
+ "type": "string",
456
+ "const": "setBudget"
457
+ },
458
+ "tokenBudget": {
459
+ "type": "integer",
460
+ "exclusiveMinimum": 0,
461
+ "maximum": 9007199254740991
462
+ },
463
+ "resume": {
464
+ "type": "boolean"
465
+ }
466
+ },
467
+ "required": [
468
+ "kind",
469
+ "tokenBudget"
470
+ ],
471
+ "additionalProperties": false
451
472
  }
452
473
  ]
453
474
  }
@@ -242,7 +242,7 @@
242
242
  "maxChildren": {
243
243
  "type": "integer",
244
244
  "minimum": 1,
245
- "maximum": 8
245
+ "maximum": 64
246
246
  },
247
247
  "tokenBudget": {
248
248
  "type": "integer",
@@ -251,7 +251,6 @@
251
251
  }
252
252
  },
253
253
  "required": [
254
- "maxChildren",
255
254
  "tokenBudget"
256
255
  ],
257
256
  "additionalProperties": false
@@ -385,6 +384,28 @@
385
384
  "interruptionId"
386
385
  ],
387
386
  "additionalProperties": false
387
+ },
388
+ {
389
+ "type": "object",
390
+ "properties": {
391
+ "kind": {
392
+ "type": "string",
393
+ "const": "setBudget"
394
+ },
395
+ "tokenBudget": {
396
+ "type": "integer",
397
+ "exclusiveMinimum": 0,
398
+ "maximum": 9007199254740991
399
+ },
400
+ "resume": {
401
+ "type": "boolean"
402
+ }
403
+ },
404
+ "required": [
405
+ "kind",
406
+ "tokenBudget"
407
+ ],
408
+ "additionalProperties": false
388
409
  }
389
410
  ]
390
411
  }
@@ -0,0 +1,458 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "type": "object",
4
+ "properties": {
5
+ "commandId": {
6
+ "type": "string",
7
+ "minLength": 1,
8
+ "maxLength": 160
9
+ },
10
+ "hubEpoch": {
11
+ "type": "string",
12
+ "minLength": 1,
13
+ "maxLength": 160
14
+ },
15
+ "runId": {
16
+ "type": "string",
17
+ "minLength": 1,
18
+ "maxLength": 160
19
+ },
20
+ "expectedRecordRevision": {
21
+ "type": "integer",
22
+ "minimum": 0,
23
+ "maximum": 9007199254740991
24
+ },
25
+ "intent": {
26
+ "oneOf": [
27
+ {
28
+ "type": "object",
29
+ "properties": {
30
+ "kind": {
31
+ "type": "string",
32
+ "const": "start"
33
+ },
34
+ "sessionId": {
35
+ "type": "string",
36
+ "minLength": 1,
37
+ "maxLength": 160
38
+ },
39
+ "runnerId": {
40
+ "type": "string",
41
+ "minLength": 1,
42
+ "maxLength": 160
43
+ },
44
+ "computeProfileId": {
45
+ "type": "string",
46
+ "minLength": 1,
47
+ "maxLength": 160
48
+ },
49
+ "scope": {
50
+ "oneOf": [
51
+ {
52
+ "type": "object",
53
+ "properties": {
54
+ "visibility": {
55
+ "type": "string",
56
+ "const": "organization"
57
+ }
58
+ },
59
+ "required": [
60
+ "visibility"
61
+ ],
62
+ "additionalProperties": false
63
+ },
64
+ {
65
+ "type": "object",
66
+ "properties": {
67
+ "visibility": {
68
+ "type": "string",
69
+ "const": "private"
70
+ },
71
+ "ownerUserId": {
72
+ "type": "string",
73
+ "minLength": 1,
74
+ "maxLength": 160
75
+ }
76
+ },
77
+ "required": [
78
+ "visibility",
79
+ "ownerUserId"
80
+ ],
81
+ "additionalProperties": false
82
+ }
83
+ ]
84
+ },
85
+ "spec": {
86
+ "type": "object",
87
+ "properties": {
88
+ "prompt": {
89
+ "type": "string",
90
+ "minLength": 1,
91
+ "maxLength": 131072
92
+ },
93
+ "projectDir": {
94
+ "type": "string",
95
+ "minLength": 1,
96
+ "maxLength": 4096
97
+ },
98
+ "harness": {
99
+ "type": "string",
100
+ "enum": [
101
+ "claude-code",
102
+ "codex"
103
+ ]
104
+ },
105
+ "workflow": {
106
+ "anyOf": [
107
+ {
108
+ "type": "string",
109
+ "maxLength": 512
110
+ },
111
+ {
112
+ "type": "object",
113
+ "properties": {
114
+ "name": {
115
+ "type": "string",
116
+ "minLength": 1,
117
+ "maxLength": 128,
118
+ "pattern": "^[A-Za-z0-9][A-Za-z0-9_-]*$"
119
+ },
120
+ "source": {
121
+ "type": "string",
122
+ "maxLength": 201,
123
+ "pattern": "^[A-Za-z0-9][A-Za-z0-9_.-]*\\/[A-Za-z0-9][A-Za-z0-9_.-]*$"
124
+ },
125
+ "ref": {
126
+ "type": "string",
127
+ "minLength": 1,
128
+ "maxLength": 512
129
+ },
130
+ "version": {
131
+ "type": "string",
132
+ "minLength": 1,
133
+ "maxLength": 128,
134
+ "pattern": "^\\d[A-Za-z0-9_.+-]*$"
135
+ }
136
+ },
137
+ "required": [
138
+ "name"
139
+ ],
140
+ "additionalProperties": false
141
+ }
142
+ ]
143
+ },
144
+ "repository": {
145
+ "type": "object",
146
+ "properties": {
147
+ "bindingId": {
148
+ "type": "string",
149
+ "minLength": 1,
150
+ "maxLength": 160
151
+ },
152
+ "repositoryId": {
153
+ "type": "integer",
154
+ "exclusiveMinimum": 0,
155
+ "maximum": 9007199254740991
156
+ },
157
+ "installationId": {
158
+ "type": "integer",
159
+ "exclusiveMinimum": 0,
160
+ "maximum": 9007199254740991
161
+ },
162
+ "owner": {
163
+ "type": "string",
164
+ "minLength": 1,
165
+ "maxLength": 100,
166
+ "pattern": "^[a-zA-Z0-9][a-zA-Z0-9-]*$"
167
+ },
168
+ "name": {
169
+ "type": "string",
170
+ "minLength": 1,
171
+ "maxLength": 100,
172
+ "pattern": "^(?!\\.{1,2}$)[a-zA-Z0-9_.-]+$"
173
+ },
174
+ "ref": {
175
+ "type": "string",
176
+ "minLength": 1,
177
+ "maxLength": 512,
178
+ "pattern": "^(?![-/])(?!.*\\.\\.)(?!.*@\\{)(?!.*(?:^|\\/)\\.)(?!.*\\.lock(?:\\/|$))(?!.*\\/\\/)[^\\x00-\\x20\\x7f~^:?*\\[\\\\]+(?<![/.])$"
179
+ },
180
+ "commitSha": {
181
+ "type": "string",
182
+ "pattern": "^[0-9a-f]{40}$"
183
+ },
184
+ "branch": {
185
+ "type": "string",
186
+ "minLength": 1,
187
+ "maxLength": 512,
188
+ "pattern": "^(?![-/])(?!.*\\.\\.)(?!.*@\\{)(?!.*(?:^|\\/)\\.)(?!.*\\.lock(?:\\/|$))(?!.*\\/\\/)[^\\x00-\\x20\\x7f~^:?*\\[\\\\]+(?<![/.])$"
189
+ },
190
+ "workingDirectory": {
191
+ "type": "string",
192
+ "minLength": 1,
193
+ "maxLength": 1024,
194
+ "pattern": "^(?:\\.|(?!\\/)(?!.*(?:^|\\/)\\.\\.?(?:\\/|$))(?!.*(?:^|\\/)\\.git(?:\\/|$))[^\\x00-\\x1f\\x7f\\\\:]+(?<!\\/))$"
195
+ },
196
+ "setupCommands": {
197
+ "maxItems": 16,
198
+ "type": "array",
199
+ "items": {
200
+ "type": "string",
201
+ "minLength": 1,
202
+ "maxLength": 8192
203
+ }
204
+ },
205
+ "configRevision": {
206
+ "type": "integer",
207
+ "minimum": 0,
208
+ "maximum": 9007199254740991
209
+ }
210
+ },
211
+ "required": [
212
+ "bindingId",
213
+ "repositoryId",
214
+ "installationId",
215
+ "owner",
216
+ "name",
217
+ "ref",
218
+ "commitSha",
219
+ "branch",
220
+ "workingDirectory",
221
+ "setupCommands",
222
+ "configRevision"
223
+ ],
224
+ "additionalProperties": false
225
+ }
226
+ },
227
+ "required": [
228
+ "prompt",
229
+ "projectDir",
230
+ "harness"
231
+ ],
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": 64
246
+ },
247
+ "tokenBudget": {
248
+ "type": "integer",
249
+ "exclusiveMinimum": 0,
250
+ "maximum": 9007199254740991
251
+ }
252
+ },
253
+ "required": [
254
+ "tokenBudget"
255
+ ],
256
+ "additionalProperties": false
257
+ },
258
+ "parent": {
259
+ "type": "object",
260
+ "properties": {
261
+ "runId": {
262
+ "type": "string",
263
+ "minLength": 1,
264
+ "maxLength": 160
265
+ },
266
+ "tokenCap": {
267
+ "type": "integer",
268
+ "exclusiveMinimum": 0,
269
+ "maximum": 9007199254740991
270
+ }
271
+ },
272
+ "required": [
273
+ "runId"
274
+ ],
275
+ "additionalProperties": false
276
+ }
277
+ },
278
+ "required": [
279
+ "kind",
280
+ "sessionId",
281
+ "scope",
282
+ "spec"
283
+ ],
284
+ "additionalProperties": false
285
+ },
286
+ {
287
+ "type": "object",
288
+ "properties": {
289
+ "kind": {
290
+ "type": "string",
291
+ "const": "cancel"
292
+ }
293
+ },
294
+ "required": [
295
+ "kind"
296
+ ],
297
+ "additionalProperties": false
298
+ },
299
+ {
300
+ "type": "object",
301
+ "properties": {
302
+ "kind": {
303
+ "type": "string",
304
+ "const": "abandon"
305
+ }
306
+ },
307
+ "required": [
308
+ "kind"
309
+ ],
310
+ "additionalProperties": false
311
+ },
312
+ {
313
+ "type": "object",
314
+ "properties": {
315
+ "kind": {
316
+ "type": "string",
317
+ "const": "steer"
318
+ },
319
+ "text": {
320
+ "type": "string",
321
+ "minLength": 1,
322
+ "maxLength": 131072
323
+ }
324
+ },
325
+ "required": [
326
+ "kind",
327
+ "text"
328
+ ],
329
+ "additionalProperties": false
330
+ },
331
+ {
332
+ "type": "object",
333
+ "properties": {
334
+ "kind": {
335
+ "type": "string",
336
+ "const": "answer"
337
+ },
338
+ "interruptionId": {
339
+ "type": "string",
340
+ "minLength": 1,
341
+ "maxLength": 160
342
+ },
343
+ "expectedInterruptionRevision": {
344
+ "type": "integer",
345
+ "minimum": 0,
346
+ "maximum": 9007199254740991
347
+ },
348
+ "requestId": {
349
+ "type": "string",
350
+ "minLength": 1,
351
+ "maxLength": 160
352
+ },
353
+ "answer": {
354
+ "$ref": "#/$defs/__schema0"
355
+ }
356
+ },
357
+ "required": [
358
+ "kind",
359
+ "interruptionId",
360
+ "expectedInterruptionRevision",
361
+ "answer"
362
+ ],
363
+ "additionalProperties": false
364
+ },
365
+ {
366
+ "type": "object",
367
+ "properties": {
368
+ "kind": {
369
+ "type": "string",
370
+ "const": "resume"
371
+ },
372
+ "interruptionId": {
373
+ "type": "string",
374
+ "minLength": 1,
375
+ "maxLength": 160
376
+ },
377
+ "guidance": {
378
+ "type": "string",
379
+ "maxLength": 131072
380
+ }
381
+ },
382
+ "required": [
383
+ "kind",
384
+ "interruptionId"
385
+ ],
386
+ "additionalProperties": false
387
+ },
388
+ {
389
+ "type": "object",
390
+ "properties": {
391
+ "kind": {
392
+ "type": "string",
393
+ "const": "setBudget"
394
+ },
395
+ "tokenBudget": {
396
+ "type": "integer",
397
+ "exclusiveMinimum": 0,
398
+ "maximum": 9007199254740991
399
+ },
400
+ "resume": {
401
+ "type": "boolean"
402
+ }
403
+ },
404
+ "required": [
405
+ "kind",
406
+ "tokenBudget"
407
+ ],
408
+ "additionalProperties": false
409
+ }
410
+ ]
411
+ },
412
+ "orchestratorRunId": {
413
+ "type": "string",
414
+ "minLength": 1,
415
+ "maxLength": 160
416
+ }
417
+ },
418
+ "required": [
419
+ "commandId",
420
+ "hubEpoch",
421
+ "runId",
422
+ "intent"
423
+ ],
424
+ "additionalProperties": false,
425
+ "$defs": {
426
+ "__schema0": {
427
+ "anyOf": [
428
+ {
429
+ "type": "string"
430
+ },
431
+ {
432
+ "type": "number"
433
+ },
434
+ {
435
+ "type": "boolean"
436
+ },
437
+ {
438
+ "type": "null"
439
+ },
440
+ {
441
+ "type": "array",
442
+ "items": {
443
+ "$ref": "#/$defs/__schema0"
444
+ }
445
+ },
446
+ {
447
+ "type": "object",
448
+ "propertyNames": {
449
+ "type": "string"
450
+ },
451
+ "additionalProperties": {
452
+ "$ref": "#/$defs/__schema0"
453
+ }
454
+ }
455
+ ]
456
+ }
457
+ }
458
+ }
@@ -216,6 +216,11 @@
216
216
  "continuation": {
217
217
  "$ref": "#/$defs/__schema0"
218
218
  },
219
+ "orchestratorRunId": {
220
+ "type": "string",
221
+ "minLength": 1,
222
+ "maxLength": 160
223
+ },
219
224
  "previousRun": {
220
225
  "type": "object",
221
226
  "properties": {
@@ -97,8 +97,8 @@
97
97
  "properties": {
98
98
  "maxChildren": {
99
99
  "type": "integer",
100
- "minimum": 1,
101
- "maximum": 8
100
+ "exclusiveMinimum": 0,
101
+ "maximum": 9007199254740991
102
102
  },
103
103
  "tokenBudget": {
104
104
  "type": "integer",
@@ -107,7 +107,6 @@
107
107
  }
108
108
  },
109
109
  "required": [
110
- "maxChildren",
111
110
  "tokenBudget"
112
111
  ],
113
112
  "additionalProperties": false
@@ -220,6 +219,12 @@
220
219
  "type": "string",
221
220
  "maxLength": 16384
222
221
  },
222
+ "respondent": {
223
+ "type": "string",
224
+ "enum": [
225
+ "orchestrator"
226
+ ]
227
+ },
223
228
  "requestId": {
224
229
  "type": "string",
225
230
  "minLength": 1,
@@ -488,7 +493,7 @@
488
493
  "maxChildren": {
489
494
  "type": "integer",
490
495
  "minimum": 1,
491
- "maximum": 8
496
+ "maximum": 64
492
497
  },
493
498
  "tokenBudget": {
494
499
  "type": "integer",
@@ -497,7 +502,6 @@
497
502
  }
498
503
  },
499
504
  "required": [
500
- "maxChildren",
501
505
  "tokenBudget"
502
506
  ],
503
507
  "additionalProperties": false
@@ -631,6 +635,28 @@
631
635
  "interruptionId"
632
636
  ],
633
637
  "additionalProperties": false
638
+ },
639
+ {
640
+ "type": "object",
641
+ "properties": {
642
+ "kind": {
643
+ "type": "string",
644
+ "const": "setBudget"
645
+ },
646
+ "tokenBudget": {
647
+ "type": "integer",
648
+ "exclusiveMinimum": 0,
649
+ "maximum": 9007199254740991
650
+ },
651
+ "resume": {
652
+ "type": "boolean"
653
+ }
654
+ },
655
+ "required": [
656
+ "kind",
657
+ "tokenBudget"
658
+ ],
659
+ "additionalProperties": false
634
660
  }
635
661
  ]
636
662
  },
@@ -622,6 +622,12 @@
622
622
  "type": "string",
623
623
  "maxLength": 16384
624
624
  },
625
+ "respondent": {
626
+ "type": "string",
627
+ "enum": [
628
+ "orchestrator"
629
+ ]
630
+ },
625
631
  "requestId": {
626
632
  "type": "string",
627
633
  "minLength": 1,