@drisp/protocol 0.8.5 → 0.8.6

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,38 @@ 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 it reported, if any. No
27
+ * caller passes `spent` yet: the CLI and the Hub count forecasts until reported usage feeds the rule (DRI-246).
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.
38
+ */
39
+ declare function attemptCost(attempt: BudgetAttempt): number;
40
+ /**
41
+ * The budget rule the CLI and the Hub share (root ADR-0011). `used` is the sum over every attempt of every child, a
42
+ * retry being a new attempt; the next start, forecast at `next`, fits when `used + next` is within the budget. Issues
43
+ * not yet started never enter it: the app warns of them on the plan sheet (Kit `shortfallNote`) and nothing parks.
44
+ */
45
+ declare function budgetCheck(input: {
46
+ tokenBudget: number;
47
+ attempts: readonly BudgetAttempt[];
48
+ next: number;
49
+ }): {
50
+ used: number;
51
+ fits: boolean;
52
+ };
29
53
  /** A class needs this many finished Runs of a harness before its forecast is measured (DRI-244). */
30
54
  declare const CALIBRATION_MIN_RUNS = 10;
31
55
  /** Only Runs closed within this many days count. */
@@ -535,6 +559,10 @@ declare const commandSchema: z.ZodObject<{
535
559
  kind: z.ZodLiteral<"resume">;
536
560
  interruptionId: z.ZodString;
537
561
  guidance: z.ZodOptional<z.ZodString>;
562
+ }, z.core.$strict>, z.ZodObject<{
563
+ kind: z.ZodLiteral<"setBudget">;
564
+ tokenBudget: z.ZodNumber;
565
+ resume: z.ZodOptional<z.ZodBoolean>;
538
566
  }, z.core.$strict>], "kind">;
539
567
  }, z.core.$strict>;
540
568
  declare const grantSchema: z.ZodObject<{
@@ -975,6 +1003,10 @@ declare const runViewSchema: z.ZodObject<{
975
1003
  kind: z.ZodLiteral<"resume">;
976
1004
  interruptionId: z.ZodString;
977
1005
  guidance: z.ZodOptional<z.ZodString>;
1006
+ }, z.core.$strict>, z.ZodObject<{
1007
+ kind: z.ZodLiteral<"setBudget">;
1008
+ tokenBudget: z.ZodNumber;
1009
+ resume: z.ZodOptional<z.ZodBoolean>;
978
1010
  }, z.core.$strict>], "kind">>;
979
1011
  runnerStopped: z.ZodOptional<z.ZodBoolean>;
980
1012
  canAbandon: z.ZodOptional<z.ZodBoolean>;
@@ -1070,6 +1102,10 @@ declare const clientFrameSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
1070
1102
  kind: z.ZodLiteral<"resume">;
1071
1103
  interruptionId: z.ZodString;
1072
1104
  guidance: z.ZodOptional<z.ZodString>;
1105
+ }, z.core.$strict>, z.ZodObject<{
1106
+ kind: z.ZodLiteral<"setBudget">;
1107
+ tokenBudget: z.ZodNumber;
1108
+ resume: z.ZodOptional<z.ZodBoolean>;
1073
1109
  }, z.core.$strict>], "kind">;
1074
1110
  }, z.core.$strict>;
1075
1111
  }, z.core.$strict>, z.ZodObject<{
@@ -1516,4 +1552,4 @@ type ConnectPendingResponse = z.infer<typeof connectPendingResponseSchema>;
1516
1552
  type TeamDefault = z.infer<typeof teamDefaultSchema>;
1517
1553
  type RunsGoTo = z.infer<typeof runsGoToSchema>;
1518
1554
 
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 };
1555
+ 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 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, 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 };
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
+ if (attempt.closed) return attempt.spent ?? forecast;
77
+ return Math.max(forecast, attempt.spent ?? 0);
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;
@@ -350,6 +358,16 @@ var commandSchema = z2.strictObject({
350
358
  kind: z2.literal("resume"),
351
359
  interruptionId: id,
352
360
  guidance: z2.string().max(131072).optional()
361
+ }),
362
+ /**
363
+ * A member rewrites an Orchestrator's `delegation.tokenBudget` (root ADR-0011), never below what its children
364
+ * used. With `resume`, a parked Orchestrator with no live child is resumed when the value is strictly greater.
365
+ * Hub-only: never delivered to a Runner.
366
+ */
367
+ z2.strictObject({
368
+ kind: z2.literal("setBudget"),
369
+ tokenBudget: delegationSchema.shape.tokenBudget,
370
+ resume: z2.boolean().optional()
353
371
  })
354
372
  ])
355
373
  });
@@ -678,7 +696,9 @@ export {
678
696
  SIZE_CLASS_FORECASTS,
679
697
  abandonedConversationContinuationCapability,
680
698
  attemptCost,
699
+ attemptForecast,
681
700
  audienceSchema,
701
+ budgetCheck,
682
702
  buildCloseReasonSchema,
683
703
  calibrate,
684
704
  calibrationSchema,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drisp/protocol",
3
- "version": "0.8.5",
3
+ "version": "0.8.6",
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",
@@ -448,6 +448,28 @@
448
448
  "interruptionId"
449
449
  ],
450
450
  "additionalProperties": false
451
+ },
452
+ {
453
+ "type": "object",
454
+ "properties": {
455
+ "kind": {
456
+ "type": "string",
457
+ "const": "setBudget"
458
+ },
459
+ "tokenBudget": {
460
+ "type": "integer",
461
+ "exclusiveMinimum": 0,
462
+ "maximum": 9007199254740991
463
+ },
464
+ "resume": {
465
+ "type": "boolean"
466
+ }
467
+ },
468
+ "required": [
469
+ "kind",
470
+ "tokenBudget"
471
+ ],
472
+ "additionalProperties": false
451
473
  }
452
474
  ]
453
475
  }
@@ -385,6 +385,28 @@
385
385
  "interruptionId"
386
386
  ],
387
387
  "additionalProperties": false
388
+ },
389
+ {
390
+ "type": "object",
391
+ "properties": {
392
+ "kind": {
393
+ "type": "string",
394
+ "const": "setBudget"
395
+ },
396
+ "tokenBudget": {
397
+ "type": "integer",
398
+ "exclusiveMinimum": 0,
399
+ "maximum": 9007199254740991
400
+ },
401
+ "resume": {
402
+ "type": "boolean"
403
+ }
404
+ },
405
+ "required": [
406
+ "kind",
407
+ "tokenBudget"
408
+ ],
409
+ "additionalProperties": false
388
410
  }
389
411
  ]
390
412
  }
@@ -631,6 +631,28 @@
631
631
  "interruptionId"
632
632
  ],
633
633
  "additionalProperties": false
634
+ },
635
+ {
636
+ "type": "object",
637
+ "properties": {
638
+ "kind": {
639
+ "type": "string",
640
+ "const": "setBudget"
641
+ },
642
+ "tokenBudget": {
643
+ "type": "integer",
644
+ "exclusiveMinimum": 0,
645
+ "maximum": 9007199254740991
646
+ },
647
+ "resume": {
648
+ "type": "boolean"
649
+ }
650
+ },
651
+ "required": [
652
+ "kind",
653
+ "tokenBudget"
654
+ ],
655
+ "additionalProperties": false
634
656
  }
635
657
  ]
636
658
  },