@humain/humain-code-contracts 0.3.2

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.
Files changed (51) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/README.md +92 -0
  3. package/dist/index.d.ts +224 -0
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.js +218 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/orchestration.d.ts +327 -0
  8. package/dist/orchestration.d.ts.map +1 -0
  9. package/dist/orchestration.js +307 -0
  10. package/dist/orchestration.js.map +1 -0
  11. package/dist/rpc.d.ts +63 -0
  12. package/dist/rpc.d.ts.map +1 -0
  13. package/dist/rpc.js +147 -0
  14. package/dist/rpc.js.map +1 -0
  15. package/dist/subagent-progress.d.ts +106 -0
  16. package/dist/subagent-progress.d.ts.map +1 -0
  17. package/dist/subagent-progress.js +440 -0
  18. package/dist/subagent-progress.js.map +1 -0
  19. package/dist/testing.d.ts +390 -0
  20. package/dist/testing.d.ts.map +1 -0
  21. package/dist/testing.js +431 -0
  22. package/dist/testing.js.map +1 -0
  23. package/dist/trace-api.d.ts +293 -0
  24. package/dist/trace-api.d.ts.map +1 -0
  25. package/dist/trace-api.js +202 -0
  26. package/dist/trace-api.js.map +1 -0
  27. package/dist/trace-artifact.d.ts +94 -0
  28. package/dist/trace-artifact.d.ts.map +1 -0
  29. package/dist/trace-artifact.js +168 -0
  30. package/dist/trace-artifact.js.map +1 -0
  31. package/dist/trace-canonical.d.ts +23 -0
  32. package/dist/trace-canonical.d.ts.map +1 -0
  33. package/dist/trace-canonical.js +240 -0
  34. package/dist/trace-canonical.js.map +1 -0
  35. package/dist/trace-export.d.ts +94 -0
  36. package/dist/trace-export.d.ts.map +1 -0
  37. package/dist/trace-export.js +374 -0
  38. package/dist/trace-export.js.map +1 -0
  39. package/dist/trace-http.d.ts +1294 -0
  40. package/dist/trace-http.d.ts.map +1 -0
  41. package/dist/trace-http.js +1481 -0
  42. package/dist/trace-http.js.map +1 -0
  43. package/dist/trace-payload.d.ts +425 -0
  44. package/dist/trace-payload.d.ts.map +1 -0
  45. package/dist/trace-payload.js +1519 -0
  46. package/dist/trace-payload.js.map +1 -0
  47. package/dist/trace.d.ts +257 -0
  48. package/dist/trace.d.ts.map +1 -0
  49. package/dist/trace.js +1014 -0
  50. package/dist/trace.js.map +1 -0
  51. package/package.json +64 -0
@@ -0,0 +1,327 @@
1
+ import { type Static, Type } from "typebox";
2
+ export * from "./subagent-progress.ts";
3
+ export declare const ORCHESTRATION_CONTRACT_VERSION: 1;
4
+ export declare const ORCHESTRATION_CAPABILITIES: readonly ["architect", "technical_lead", "implementation_fast", "implementation_strong", "technical_review", "security_review"];
5
+ export type OrchestrationCapability = (typeof ORCHESTRATION_CAPABILITIES)[number];
6
+ export declare const ORCHESTRATION_EFFORTS: readonly ["low", "medium", "high"];
7
+ export type OrchestrationEffort = (typeof ORCHESTRATION_EFFORTS)[number];
8
+ export declare const ORCHESTRATION_RISKS: readonly ["low", "medium", "high", "critical"];
9
+ export type OrchestrationRisk = (typeof ORCHESTRATION_RISKS)[number];
10
+ export declare const OrchestrationCapabilitySchema: Type.TUnion<[Type.TLiteral<"architect">, Type.TLiteral<"technical_lead">, Type.TLiteral<"implementation_fast">, Type.TLiteral<"implementation_strong">, Type.TLiteral<"technical_review">, Type.TLiteral<"security_review">]>;
11
+ export type OrchestrationCapabilityLiteral = Static<typeof OrchestrationCapabilitySchema>;
12
+ export declare const OrchestrationEffortSchema: Type.TUnion<[Type.TLiteral<"low">, Type.TLiteral<"medium">, Type.TLiteral<"high">]>;
13
+ export type OrchestrationEffortLiteral = Static<typeof OrchestrationEffortSchema>;
14
+ export declare const OrchestrationRiskSchema: Type.TUnion<[Type.TLiteral<"low">, Type.TLiteral<"medium">, Type.TLiteral<"high">, Type.TLiteral<"critical">]>;
15
+ export type OrchestrationRiskLiteral = Static<typeof OrchestrationRiskSchema>;
16
+ export declare const OrchestrationPackageSchema: Type.TObject<{
17
+ readonly route: Type.TString;
18
+ readonly effort: Type.TUnion<[Type.TLiteral<"low">, Type.TLiteral<"medium">, Type.TLiteral<"high">]>;
19
+ readonly contextBudget: Type.TInteger;
20
+ readonly model: Type.TString;
21
+ readonly independentFrom: Type.TOptional<Type.TArray<Type.TUnion<[Type.TLiteral<"architect">, Type.TLiteral<"technical_lead">, Type.TLiteral<"implementation_fast">, Type.TLiteral<"implementation_strong">, Type.TLiteral<"technical_review">, Type.TLiteral<"security_review">]>>>;
22
+ }>;
23
+ export type OrchestrationPackage = Static<typeof OrchestrationPackageSchema>;
24
+ export declare const OrchestrationTopologySchema: Type.TObject<{
25
+ readonly maxDepth: Type.TInteger;
26
+ readonly maxWorkers: Type.TInteger;
27
+ readonly maxConcurrent: Type.TInteger;
28
+ readonly maxWorktrees: Type.TInteger;
29
+ }>;
30
+ export type OrchestrationTopology = Static<typeof OrchestrationTopologySchema>;
31
+ export declare const OrchestrationRunClassSchema: Type.TObject<{
32
+ readonly taskClass: Type.TString;
33
+ readonly complexity: Type.TInteger;
34
+ readonly risk: Type.TUnion<[Type.TLiteral<"low">, Type.TLiteral<"medium">, Type.TLiteral<"high">, Type.TLiteral<"critical">]>;
35
+ readonly classificationSource: Type.TUnion<[Type.TLiteral<"deterministic">, Type.TLiteral<"classifier">, Type.TLiteral<"fallback">, Type.TLiteral<"architect">]>;
36
+ }>;
37
+ export type OrchestrationRunClass = Static<typeof OrchestrationRunClassSchema>;
38
+ export declare const OrchestrationFeaturesSchema: Type.TObject<{
39
+ readonly adaptiveRouting: Type.TUnion<[Type.TLiteral<"off">, Type.TLiteral<"observe">, Type.TLiteral<"recommend">, Type.TLiteral<"enforce">]>;
40
+ readonly exploration: Type.TBoolean;
41
+ readonly shadowRouting: Type.TUnion<[Type.TLiteral<"off">, Type.TLiteral<"estimate">]>;
42
+ readonly budget: Type.TUnion<[Type.TLiteral<"monitor">, Type.TLiteral<"warn">, Type.TLiteral<"enforce">]>;
43
+ readonly budgetMicrocents: Type.TInteger;
44
+ readonly timeBudgetMs: Type.TInteger;
45
+ readonly autoMerge: Type.TLiteral<false>;
46
+ readonly destructiveOps: Type.TLiteral<"deny">;
47
+ readonly dependencyChanges: Type.TUnion<[Type.TLiteral<"deny">, Type.TLiteral<"ask">]>;
48
+ }>;
49
+ export type OrchestrationFeatures = Static<typeof OrchestrationFeaturesSchema>;
50
+ export declare const OrchestrationDecisionV1Schema: Type.TObject<{
51
+ readonly defaultPackage: Type.TOptional<Type.TRecord<"^.*$", Type.TObject<{
52
+ readonly route: Type.TString;
53
+ readonly effort: Type.TUnion<[Type.TLiteral<"low">, Type.TLiteral<"medium">, Type.TLiteral<"high">]>;
54
+ readonly contextBudget: Type.TInteger;
55
+ readonly model: Type.TString;
56
+ readonly independentFrom: Type.TOptional<Type.TArray<Type.TUnion<[Type.TLiteral<"architect">, Type.TLiteral<"technical_lead">, Type.TLiteral<"implementation_fast">, Type.TLiteral<"implementation_strong">, Type.TLiteral<"technical_review">, Type.TLiteral<"security_review">]>>>;
57
+ }>>>;
58
+ readonly recommendedPackage: Type.TOptional<Type.TRecord<"^.*$", Type.TObject<{
59
+ readonly route: Type.TString;
60
+ readonly effort: Type.TUnion<[Type.TLiteral<"low">, Type.TLiteral<"medium">, Type.TLiteral<"high">]>;
61
+ readonly contextBudget: Type.TInteger;
62
+ readonly model: Type.TString;
63
+ readonly independentFrom: Type.TOptional<Type.TArray<Type.TUnion<[Type.TLiteral<"architect">, Type.TLiteral<"technical_lead">, Type.TLiteral<"implementation_fast">, Type.TLiteral<"implementation_strong">, Type.TLiteral<"technical_review">, Type.TLiteral<"security_review">]>>>;
64
+ }>>>;
65
+ readonly selected: Type.TUnion<[Type.TLiteral<"default">, Type.TLiteral<"recommended">, Type.TLiteral<"explored">, Type.TLiteral<"canary">]>;
66
+ readonly sampleCount: Type.TInteger;
67
+ readonly minSamples: Type.TInteger;
68
+ readonly explored: Type.TBoolean;
69
+ readonly canary: Type.TBoolean;
70
+ readonly shadowEstimate: Type.TOptional<Type.TObject<{
71
+ readonly costMicrocents: Type.TInteger;
72
+ readonly durationMs: Type.TInteger;
73
+ }>>;
74
+ }>;
75
+ export type OrchestrationDecisionV1 = Static<typeof OrchestrationDecisionV1Schema>;
76
+ export declare const OrchestrationPolicyV1Schema: Type.TObject<{
77
+ readonly contractVersion: Type.TLiteral<1>;
78
+ readonly policyId: Type.TString;
79
+ readonly runClass: Type.TObject<{
80
+ readonly taskClass: Type.TString;
81
+ readonly complexity: Type.TInteger;
82
+ readonly risk: Type.TUnion<[Type.TLiteral<"low">, Type.TLiteral<"medium">, Type.TLiteral<"high">, Type.TLiteral<"critical">]>;
83
+ readonly classificationSource: Type.TUnion<[Type.TLiteral<"deterministic">, Type.TLiteral<"classifier">, Type.TLiteral<"fallback">, Type.TLiteral<"architect">]>;
84
+ }>;
85
+ readonly topology: Type.TObject<{
86
+ readonly maxDepth: Type.TInteger;
87
+ readonly maxWorkers: Type.TInteger;
88
+ readonly maxConcurrent: Type.TInteger;
89
+ readonly maxWorktrees: Type.TInteger;
90
+ }>;
91
+ readonly packages: Type.TRecord<"^.*$", Type.TObject<{
92
+ readonly route: Type.TString;
93
+ readonly effort: Type.TUnion<[Type.TLiteral<"low">, Type.TLiteral<"medium">, Type.TLiteral<"high">]>;
94
+ readonly contextBudget: Type.TInteger;
95
+ readonly model: Type.TString;
96
+ readonly independentFrom: Type.TOptional<Type.TArray<Type.TUnion<[Type.TLiteral<"architect">, Type.TLiteral<"technical_lead">, Type.TLiteral<"implementation_fast">, Type.TLiteral<"implementation_strong">, Type.TLiteral<"technical_review">, Type.TLiteral<"security_review">]>>>;
97
+ }>>;
98
+ readonly agentCapabilities: Type.TRecord<"^.*$", Type.TUnion<[Type.TLiteral<"architect">, Type.TLiteral<"technical_lead">, Type.TLiteral<"implementation_fast">, Type.TLiteral<"implementation_strong">, Type.TLiteral<"technical_review">, Type.TLiteral<"security_review">]>>;
99
+ readonly escalation: Type.TArray<Type.TUnion<[Type.TLiteral<"architect">, Type.TLiteral<"technical_lead">, Type.TLiteral<"implementation_fast">, Type.TLiteral<"implementation_strong">, Type.TLiteral<"technical_review">, Type.TLiteral<"security_review">]>>;
100
+ readonly verification: Type.TObject<{
101
+ readonly depth: Type.TUnion<[Type.TLiteral<"none">, Type.TLiteral<"targeted">, Type.TLiteral<"broad">, Type.TLiteral<"full">]>;
102
+ readonly review: Type.TUnion<[Type.TLiteral<"off">, Type.TLiteral<"sampled">, Type.TLiteral<"risk_based">, Type.TLiteral<"always">]>;
103
+ readonly gate: Type.TUnion<[Type.TLiteral<"off">, Type.TLiteral<"on">]>;
104
+ }>;
105
+ readonly features: Type.TObject<{
106
+ readonly adaptiveRouting: Type.TUnion<[Type.TLiteral<"off">, Type.TLiteral<"observe">, Type.TLiteral<"recommend">, Type.TLiteral<"enforce">]>;
107
+ readonly exploration: Type.TBoolean;
108
+ readonly shadowRouting: Type.TUnion<[Type.TLiteral<"off">, Type.TLiteral<"estimate">]>;
109
+ readonly budget: Type.TUnion<[Type.TLiteral<"monitor">, Type.TLiteral<"warn">, Type.TLiteral<"enforce">]>;
110
+ readonly budgetMicrocents: Type.TInteger;
111
+ readonly timeBudgetMs: Type.TInteger;
112
+ readonly autoMerge: Type.TLiteral<false>;
113
+ readonly destructiveOps: Type.TLiteral<"deny">;
114
+ readonly dependencyChanges: Type.TUnion<[Type.TLiteral<"deny">, Type.TLiteral<"ask">]>;
115
+ }>;
116
+ readonly decision: Type.TObject<{
117
+ readonly defaultPackage: Type.TOptional<Type.TRecord<"^.*$", Type.TObject<{
118
+ readonly route: Type.TString;
119
+ readonly effort: Type.TUnion<[Type.TLiteral<"low">, Type.TLiteral<"medium">, Type.TLiteral<"high">]>;
120
+ readonly contextBudget: Type.TInteger;
121
+ readonly model: Type.TString;
122
+ readonly independentFrom: Type.TOptional<Type.TArray<Type.TUnion<[Type.TLiteral<"architect">, Type.TLiteral<"technical_lead">, Type.TLiteral<"implementation_fast">, Type.TLiteral<"implementation_strong">, Type.TLiteral<"technical_review">, Type.TLiteral<"security_review">]>>>;
123
+ }>>>;
124
+ readonly recommendedPackage: Type.TOptional<Type.TRecord<"^.*$", Type.TObject<{
125
+ readonly route: Type.TString;
126
+ readonly effort: Type.TUnion<[Type.TLiteral<"low">, Type.TLiteral<"medium">, Type.TLiteral<"high">]>;
127
+ readonly contextBudget: Type.TInteger;
128
+ readonly model: Type.TString;
129
+ readonly independentFrom: Type.TOptional<Type.TArray<Type.TUnion<[Type.TLiteral<"architect">, Type.TLiteral<"technical_lead">, Type.TLiteral<"implementation_fast">, Type.TLiteral<"implementation_strong">, Type.TLiteral<"technical_review">, Type.TLiteral<"security_review">]>>>;
130
+ }>>>;
131
+ readonly selected: Type.TUnion<[Type.TLiteral<"default">, Type.TLiteral<"recommended">, Type.TLiteral<"explored">, Type.TLiteral<"canary">]>;
132
+ readonly sampleCount: Type.TInteger;
133
+ readonly minSamples: Type.TInteger;
134
+ readonly explored: Type.TBoolean;
135
+ readonly canary: Type.TBoolean;
136
+ readonly shadowEstimate: Type.TOptional<Type.TObject<{
137
+ readonly costMicrocents: Type.TInteger;
138
+ readonly durationMs: Type.TInteger;
139
+ }>>;
140
+ }>;
141
+ readonly approvedDependencyChanges: Type.TOptional<Type.TArray<Type.TString>>;
142
+ }>;
143
+ export type OrchestrationPolicyV1 = Static<typeof OrchestrationPolicyV1Schema>;
144
+ export declare function parseOrchestrationPolicy(value: unknown): OrchestrationPolicyV1;
145
+ export declare const RunOrchestrationDecisionV1Schema: Type.TObject<{
146
+ readonly schemaVersion: Type.TLiteral<1>;
147
+ readonly policyId: Type.TUnion<[Type.TString, Type.TNull]>;
148
+ readonly contractVersion: Type.TLiteral<1>;
149
+ readonly runClass: Type.TUnion<[Type.TObject<{
150
+ readonly taskClass: Type.TString;
151
+ readonly complexity: Type.TInteger;
152
+ readonly risk: Type.TUnion<[Type.TLiteral<"low">, Type.TLiteral<"medium">, Type.TLiteral<"high">, Type.TLiteral<"critical">]>;
153
+ readonly classificationSource: Type.TUnion<[Type.TLiteral<"deterministic">, Type.TLiteral<"classifier">, Type.TLiteral<"fallback">, Type.TLiteral<"architect">]>;
154
+ }>, Type.TNull]>;
155
+ readonly topology: Type.TUnion<[Type.TObject<{
156
+ readonly maxDepth: Type.TInteger;
157
+ readonly maxWorkers: Type.TInteger;
158
+ readonly maxConcurrent: Type.TInteger;
159
+ readonly maxWorktrees: Type.TInteger;
160
+ }>, Type.TNull]>;
161
+ readonly decision: Type.TUnion<[Type.TObject<{
162
+ readonly defaultPackage: Type.TOptional<Type.TRecord<"^.*$", Type.TObject<{
163
+ readonly route: Type.TString;
164
+ readonly effort: Type.TUnion<[Type.TLiteral<"low">, Type.TLiteral<"medium">, Type.TLiteral<"high">]>;
165
+ readonly contextBudget: Type.TInteger;
166
+ readonly model: Type.TString;
167
+ readonly independentFrom: Type.TOptional<Type.TArray<Type.TUnion<[Type.TLiteral<"architect">, Type.TLiteral<"technical_lead">, Type.TLiteral<"implementation_fast">, Type.TLiteral<"implementation_strong">, Type.TLiteral<"technical_review">, Type.TLiteral<"security_review">]>>>;
168
+ }>>>;
169
+ readonly recommendedPackage: Type.TOptional<Type.TRecord<"^.*$", Type.TObject<{
170
+ readonly route: Type.TString;
171
+ readonly effort: Type.TUnion<[Type.TLiteral<"low">, Type.TLiteral<"medium">, Type.TLiteral<"high">]>;
172
+ readonly contextBudget: Type.TInteger;
173
+ readonly model: Type.TString;
174
+ readonly independentFrom: Type.TOptional<Type.TArray<Type.TUnion<[Type.TLiteral<"architect">, Type.TLiteral<"technical_lead">, Type.TLiteral<"implementation_fast">, Type.TLiteral<"implementation_strong">, Type.TLiteral<"technical_review">, Type.TLiteral<"security_review">]>>>;
175
+ }>>>;
176
+ readonly selected: Type.TUnion<[Type.TLiteral<"default">, Type.TLiteral<"recommended">, Type.TLiteral<"explored">, Type.TLiteral<"canary">]>;
177
+ readonly sampleCount: Type.TInteger;
178
+ readonly minSamples: Type.TInteger;
179
+ readonly explored: Type.TBoolean;
180
+ readonly canary: Type.TBoolean;
181
+ readonly shadowEstimate: Type.TOptional<Type.TObject<{
182
+ readonly costMicrocents: Type.TInteger;
183
+ readonly durationMs: Type.TInteger;
184
+ }>>;
185
+ }>, Type.TNull]>;
186
+ readonly degradationReason: Type.TUnion<[Type.TLiteral<"orchestration-unsupported">, Type.TLiteral<"orchestration-disabled">, Type.TNull]>;
187
+ }>;
188
+ export type RunOrchestrationDecisionV1 = Static<typeof RunOrchestrationDecisionV1Schema>;
189
+ export declare const SubagentTaskEventSchema: Type.TUnion<[Type.TObject<{
190
+ readonly type: Type.TLiteral<"schedule">;
191
+ readonly taskId: Type.TString;
192
+ readonly dependsOn: Type.TArray<Type.TString>;
193
+ readonly ownerPaths: Type.TArray<Type.TString>;
194
+ readonly baseRevision: Type.TOptional<Type.TString>;
195
+ readonly at: Type.TInteger;
196
+ }>, Type.TObject<{
197
+ readonly type: Type.TLiteral<"wait">;
198
+ readonly taskId: Type.TString;
199
+ readonly reason: Type.TLiteral<"concurrency">;
200
+ readonly at: Type.TInteger;
201
+ }>, Type.TObject<{
202
+ readonly type: Type.TLiteral<"serialize">;
203
+ readonly taskId: Type.TString;
204
+ readonly after: Type.TArray<Type.TString>;
205
+ readonly at: Type.TInteger;
206
+ }>, Type.TObject<{
207
+ readonly type: Type.TLiteral<"start">;
208
+ readonly taskId: Type.TString;
209
+ readonly attempt: Type.TInteger;
210
+ readonly at: Type.TInteger;
211
+ }>, Type.TObject<{
212
+ readonly type: Type.TLiteral<"complete">;
213
+ readonly taskId: Type.TString;
214
+ readonly attempt: Type.TInteger;
215
+ readonly at: Type.TInteger;
216
+ }>, Type.TObject<{
217
+ readonly type: Type.TLiteral<"fail">;
218
+ readonly taskId: Type.TString;
219
+ readonly attempt: Type.TInteger;
220
+ readonly reason: Type.TString;
221
+ readonly at: Type.TInteger;
222
+ }>, Type.TObject<{
223
+ readonly type: Type.TLiteral<"escalate">;
224
+ readonly taskId: Type.TString;
225
+ readonly fromAttempt: Type.TInteger;
226
+ readonly toAttempt: Type.TInteger;
227
+ readonly model: Type.TOptional<Type.TString>;
228
+ readonly thinking: Type.TOptional<Type.TString>;
229
+ readonly at: Type.TInteger;
230
+ }>, Type.TObject<{
231
+ readonly type: Type.TLiteral<"skip">;
232
+ readonly taskId: Type.TString;
233
+ readonly failedDependency: Type.TString;
234
+ readonly at: Type.TInteger;
235
+ }>]>;
236
+ export type SubagentTaskEvent = Static<typeof SubagentTaskEventSchema>;
237
+ export declare function parseSubagentTaskEvent(value: unknown): SubagentTaskEvent;
238
+ export declare const SubagentIdentityEnvelopeSchema: Type.TObject<{
239
+ readonly taskId: Type.TOptional<Type.TString>;
240
+ readonly parentTaskId: Type.TOptional<Type.TString>;
241
+ readonly depth: Type.TOptional<Type.TInteger>;
242
+ }>;
243
+ export type SubagentIdentityEnvelope = Static<typeof SubagentIdentityEnvelopeSchema>;
244
+ export declare const SubagentWorkerStatusSchema: Type.TUnion<[Type.TLiteral<"queued">, Type.TLiteral<"waiting">, Type.TLiteral<"running">, Type.TLiteral<"completed">, Type.TLiteral<"failed">, Type.TLiteral<"cancelled">, Type.TLiteral<"skipped">, Type.TLiteral<"unresolved">]>;
245
+ export declare const SubagentCancellationOutcomeSchema: Type.TUnion<[Type.TLiteral<"none">, Type.TLiteral<"not_started">, Type.TLiteral<"direct_worker_terminated">, Type.TLiteral<"unconfirmed">]>;
246
+ export declare const SubagentFailureKindSchema: Type.TUnion<[Type.TLiteral<"spawn_failed">, Type.TLiteral<"process_error">, Type.TLiteral<"model_error">, Type.TLiteral<"merge_failed">, Type.TNull]>;
247
+ export declare const SubagentRunModeSchema: Type.TUnion<[Type.TLiteral<"single">, Type.TLiteral<"parallel">, Type.TLiteral<"chain">]>;
248
+ /**
249
+ * Structural TypeBox description of the C1 worker. The hand-written parsers in `subagent-progress.ts` are
250
+ * authoritative: they also enforce lone-surrogate and edge-whitespace rules and the cross-field invariants.
251
+ */
252
+ export declare const SubagentWorkerSnapshotSchema: Type.TObject<{
253
+ readonly workerId: Type.TString;
254
+ readonly attempt: Type.TInteger;
255
+ readonly status: Type.TUnion<[Type.TLiteral<"queued">, Type.TLiteral<"waiting">, Type.TLiteral<"running">, Type.TLiteral<"completed">, Type.TLiteral<"failed">, Type.TLiteral<"cancelled">, Type.TLiteral<"skipped">, Type.TLiteral<"unresolved">]>;
256
+ readonly cancelRequested: Type.TBoolean;
257
+ readonly cancellationOutcome: Type.TUnion<[Type.TLiteral<"none">, Type.TLiteral<"not_started">, Type.TLiteral<"direct_worker_terminated">, Type.TLiteral<"unconfirmed">]>;
258
+ readonly agent: Type.TUnion<[Type.TString, Type.TNull]>;
259
+ readonly label: Type.TUnion<[Type.TString, Type.TNull]>;
260
+ readonly task: Type.TUnion<[Type.TString, Type.TNull]>;
261
+ readonly model: Type.TUnion<[Type.TString, Type.TNull]>;
262
+ readonly startedAt: Type.TUnion<[Type.TInteger, Type.TNull]>;
263
+ readonly endedAt: Type.TUnion<[Type.TInteger, Type.TNull]>;
264
+ readonly turns: Type.TInteger;
265
+ readonly toolCalls: Type.TInteger;
266
+ readonly failureKind: Type.TUnion<[Type.TLiteral<"spawn_failed">, Type.TLiteral<"process_error">, Type.TLiteral<"model_error">, Type.TLiteral<"merge_failed">, Type.TNull]>;
267
+ readonly resultPreview: Type.TUnion<[Type.TString, Type.TNull]>;
268
+ }>;
269
+ export declare const SubagentRunSnapshotSchema: Type.TObject<{
270
+ readonly runId: Type.TString;
271
+ readonly seq: Type.TInteger;
272
+ readonly final: Type.TBoolean;
273
+ readonly workers: Type.TArray<Type.TObject<{
274
+ readonly workerId: Type.TString;
275
+ readonly attempt: Type.TInteger;
276
+ readonly status: Type.TUnion<[Type.TLiteral<"queued">, Type.TLiteral<"waiting">, Type.TLiteral<"running">, Type.TLiteral<"completed">, Type.TLiteral<"failed">, Type.TLiteral<"cancelled">, Type.TLiteral<"skipped">, Type.TLiteral<"unresolved">]>;
277
+ readonly cancelRequested: Type.TBoolean;
278
+ readonly cancellationOutcome: Type.TUnion<[Type.TLiteral<"none">, Type.TLiteral<"not_started">, Type.TLiteral<"direct_worker_terminated">, Type.TLiteral<"unconfirmed">]>;
279
+ readonly agent: Type.TUnion<[Type.TString, Type.TNull]>;
280
+ readonly label: Type.TUnion<[Type.TString, Type.TNull]>;
281
+ readonly task: Type.TUnion<[Type.TString, Type.TNull]>;
282
+ readonly model: Type.TUnion<[Type.TString, Type.TNull]>;
283
+ readonly startedAt: Type.TUnion<[Type.TInteger, Type.TNull]>;
284
+ readonly endedAt: Type.TUnion<[Type.TInteger, Type.TNull]>;
285
+ readonly turns: Type.TInteger;
286
+ readonly toolCalls: Type.TInteger;
287
+ readonly failureKind: Type.TUnion<[Type.TLiteral<"spawn_failed">, Type.TLiteral<"process_error">, Type.TLiteral<"model_error">, Type.TLiteral<"merge_failed">, Type.TNull]>;
288
+ readonly resultPreview: Type.TUnion<[Type.TString, Type.TNull]>;
289
+ }>>;
290
+ readonly toolCallId: Type.TUnion<[Type.TString, Type.TNull]>;
291
+ readonly mode: Type.TUnion<[Type.TLiteral<"single">, Type.TLiteral<"parallel">, Type.TLiteral<"chain">]>;
292
+ readonly startedAt: Type.TInteger;
293
+ readonly endedAt: Type.TUnion<[Type.TInteger, Type.TNull]>;
294
+ }>;
295
+ export declare const SubagentProgressSnapshotSchema: Type.TObject<{
296
+ readonly schemaVersion: Type.TLiteral<1>;
297
+ readonly runtimeId: Type.TString;
298
+ readonly sessionEpoch: Type.TString;
299
+ readonly complete: Type.TBoolean;
300
+ readonly runs: Type.TArray<Type.TObject<{
301
+ readonly runId: Type.TString;
302
+ readonly seq: Type.TInteger;
303
+ readonly final: Type.TBoolean;
304
+ readonly workers: Type.TArray<Type.TObject<{
305
+ readonly workerId: Type.TString;
306
+ readonly attempt: Type.TInteger;
307
+ readonly status: Type.TUnion<[Type.TLiteral<"queued">, Type.TLiteral<"waiting">, Type.TLiteral<"running">, Type.TLiteral<"completed">, Type.TLiteral<"failed">, Type.TLiteral<"cancelled">, Type.TLiteral<"skipped">, Type.TLiteral<"unresolved">]>;
308
+ readonly cancelRequested: Type.TBoolean;
309
+ readonly cancellationOutcome: Type.TUnion<[Type.TLiteral<"none">, Type.TLiteral<"not_started">, Type.TLiteral<"direct_worker_terminated">, Type.TLiteral<"unconfirmed">]>;
310
+ readonly agent: Type.TUnion<[Type.TString, Type.TNull]>;
311
+ readonly label: Type.TUnion<[Type.TString, Type.TNull]>;
312
+ readonly task: Type.TUnion<[Type.TString, Type.TNull]>;
313
+ readonly model: Type.TUnion<[Type.TString, Type.TNull]>;
314
+ readonly startedAt: Type.TUnion<[Type.TInteger, Type.TNull]>;
315
+ readonly endedAt: Type.TUnion<[Type.TInteger, Type.TNull]>;
316
+ readonly turns: Type.TInteger;
317
+ readonly toolCalls: Type.TInteger;
318
+ readonly failureKind: Type.TUnion<[Type.TLiteral<"spawn_failed">, Type.TLiteral<"process_error">, Type.TLiteral<"model_error">, Type.TLiteral<"merge_failed">, Type.TNull]>;
319
+ readonly resultPreview: Type.TUnion<[Type.TString, Type.TNull]>;
320
+ }>>;
321
+ readonly toolCallId: Type.TUnion<[Type.TString, Type.TNull]>;
322
+ readonly mode: Type.TUnion<[Type.TLiteral<"single">, Type.TLiteral<"parallel">, Type.TLiteral<"chain">]>;
323
+ readonly startedAt: Type.TInteger;
324
+ readonly endedAt: Type.TUnion<[Type.TInteger, Type.TNull]>;
325
+ }>>;
326
+ }>;
327
+ //# sourceMappingURL=orchestration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"orchestration.d.ts","sourceRoot":"","sources":["../src/orchestration.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,307 @@
1
+ import { Type } from "typebox";
2
+ import { Compile } from "typebox/compile";
3
+ import { SUBAGENT_CANCELLATION_OUTCOMES, SUBAGENT_FAILURE_KINDS, SUBAGENT_PROGRESS_AGENT_MAX_CODE_UNITS, SUBAGENT_PROGRESS_IDENTIFIER_PATTERN, SUBAGENT_PROGRESS_MAX_RUNS, SUBAGENT_PROGRESS_MAX_WORKERS_PER_RUN, SUBAGENT_PROGRESS_MODEL_MAX_CODE_UNITS, SUBAGENT_PROGRESS_MODEL_PATTERN, SUBAGENT_PROGRESS_RESULT_PREVIEW_MAX_CODE_UNITS, SUBAGENT_PROGRESS_SCHEMA_VERSION, SUBAGENT_PROGRESS_TASK_MAX_CODE_UNITS, SUBAGENT_PROGRESS_TEXT_PATTERN, SUBAGENT_PROGRESS_TOOL_CALL_ID_MAX_CODE_UNITS, SUBAGENT_PROGRESS_TOOL_CALL_ID_PATTERN, SUBAGENT_PROGRESS_UUID_PATTERN, SUBAGENT_RUN_MODES, SUBAGENT_WORKER_STATUSES, } from "./subagent-progress.js";
4
+ export * from "./subagent-progress.js";
5
+ const StrictObject = (properties) => Type.Object(properties, { additionalProperties: false });
6
+ const PositiveInteger = Type.Integer({ minimum: 1, maximum: Number.MAX_SAFE_INTEGER });
7
+ const NonnegativeInteger = Type.Integer({ minimum: 0, maximum: Number.MAX_SAFE_INTEGER });
8
+ const Digest = Type.String({ pattern: "^[a-f0-9]{64}$" });
9
+ export const ORCHESTRATION_CONTRACT_VERSION = 1;
10
+ export const ORCHESTRATION_CAPABILITIES = [
11
+ "architect",
12
+ "technical_lead",
13
+ "implementation_fast",
14
+ "implementation_strong",
15
+ "technical_review",
16
+ "security_review",
17
+ ];
18
+ export const ORCHESTRATION_EFFORTS = ["low", "medium", "high"];
19
+ export const ORCHESTRATION_RISKS = ["low", "medium", "high", "critical"];
20
+ export const OrchestrationCapabilitySchema = Type.Union([
21
+ Type.Literal(ORCHESTRATION_CAPABILITIES[0]),
22
+ Type.Literal(ORCHESTRATION_CAPABILITIES[1]),
23
+ Type.Literal(ORCHESTRATION_CAPABILITIES[2]),
24
+ Type.Literal(ORCHESTRATION_CAPABILITIES[3]),
25
+ Type.Literal(ORCHESTRATION_CAPABILITIES[4]),
26
+ Type.Literal(ORCHESTRATION_CAPABILITIES[5]),
27
+ ]);
28
+ export const OrchestrationEffortSchema = Type.Union([
29
+ Type.Literal(ORCHESTRATION_EFFORTS[0]),
30
+ Type.Literal(ORCHESTRATION_EFFORTS[1]),
31
+ Type.Literal(ORCHESTRATION_EFFORTS[2]),
32
+ ]);
33
+ export const OrchestrationRiskSchema = Type.Union([
34
+ Type.Literal(ORCHESTRATION_RISKS[0]),
35
+ Type.Literal(ORCHESTRATION_RISKS[1]),
36
+ Type.Literal(ORCHESTRATION_RISKS[2]),
37
+ Type.Literal(ORCHESTRATION_RISKS[3]),
38
+ ]);
39
+ export const OrchestrationPackageSchema = StrictObject({
40
+ route: Type.String({ minLength: 1 }),
41
+ effort: OrchestrationEffortSchema,
42
+ contextBudget: PositiveInteger,
43
+ model: Type.String({ minLength: 1 }),
44
+ independentFrom: Type.Optional(Type.Array(OrchestrationCapabilitySchema)),
45
+ });
46
+ export const OrchestrationTopologySchema = StrictObject({
47
+ maxDepth: Type.Integer({ minimum: 1, maximum: 3 }),
48
+ maxWorkers: Type.Integer({ minimum: 1, maximum: 16 }),
49
+ maxConcurrent: Type.Integer({ minimum: 1, maximum: 8 }),
50
+ maxWorktrees: Type.Integer({ minimum: 0, maximum: 8 }),
51
+ });
52
+ export const OrchestrationRunClassSchema = StrictObject({
53
+ taskClass: Type.String({ minLength: 1 }),
54
+ complexity: Type.Integer({ minimum: 1, maximum: 10 }),
55
+ risk: OrchestrationRiskSchema,
56
+ classificationSource: Type.Union([
57
+ Type.Literal("deterministic"),
58
+ Type.Literal("classifier"),
59
+ Type.Literal("fallback"),
60
+ Type.Literal("architect"),
61
+ ]),
62
+ });
63
+ export const OrchestrationFeaturesSchema = StrictObject({
64
+ adaptiveRouting: Type.Union([
65
+ Type.Literal("off"),
66
+ Type.Literal("observe"),
67
+ Type.Literal("recommend"),
68
+ Type.Literal("enforce"),
69
+ ]),
70
+ exploration: Type.Boolean(),
71
+ shadowRouting: Type.Union([Type.Literal("off"), Type.Literal("estimate")]),
72
+ budget: Type.Union([Type.Literal("monitor"), Type.Literal("warn"), Type.Literal("enforce")]),
73
+ budgetMicrocents: NonnegativeInteger,
74
+ timeBudgetMs: NonnegativeInteger,
75
+ autoMerge: Type.Literal(false),
76
+ destructiveOps: Type.Literal("deny"),
77
+ dependencyChanges: Type.Union([Type.Literal("deny"), Type.Literal("ask")]),
78
+ });
79
+ export const OrchestrationDecisionV1Schema = StrictObject({
80
+ defaultPackage: Type.Optional(Type.Record(Type.String(), OrchestrationPackageSchema)),
81
+ recommendedPackage: Type.Optional(Type.Record(Type.String(), OrchestrationPackageSchema)),
82
+ selected: Type.Union([
83
+ Type.Literal("default"),
84
+ Type.Literal("recommended"),
85
+ Type.Literal("explored"),
86
+ Type.Literal("canary"),
87
+ ]),
88
+ sampleCount: NonnegativeInteger,
89
+ minSamples: PositiveInteger,
90
+ explored: Type.Boolean(),
91
+ canary: Type.Boolean(),
92
+ shadowEstimate: Type.Optional(StrictObject({ costMicrocents: NonnegativeInteger, durationMs: NonnegativeInteger })),
93
+ });
94
+ export const OrchestrationPolicyV1Schema = StrictObject({
95
+ contractVersion: Type.Literal(ORCHESTRATION_CONTRACT_VERSION),
96
+ policyId: Digest,
97
+ runClass: OrchestrationRunClassSchema,
98
+ topology: OrchestrationTopologySchema,
99
+ packages: Type.Record(Type.String(), OrchestrationPackageSchema),
100
+ agentCapabilities: Type.Record(Type.String(), OrchestrationCapabilitySchema),
101
+ escalation: Type.Array(OrchestrationCapabilitySchema),
102
+ verification: StrictObject({
103
+ depth: Type.Union([Type.Literal("none"), Type.Literal("targeted"), Type.Literal("broad"), Type.Literal("full")]),
104
+ review: Type.Union([
105
+ Type.Literal("off"),
106
+ Type.Literal("sampled"),
107
+ Type.Literal("risk_based"),
108
+ Type.Literal("always"),
109
+ ]),
110
+ gate: Type.Union([Type.Literal("off"), Type.Literal("on")]),
111
+ }),
112
+ features: OrchestrationFeaturesSchema,
113
+ decision: OrchestrationDecisionV1Schema,
114
+ approvedDependencyChanges: Type.Optional(Type.Array(Type.String({ minLength: 1 }))),
115
+ });
116
+ const OrchestrationPolicyValidator = Compile(OrchestrationPolicyV1Schema);
117
+ const ORCHESTRATION_CAPABILITY_SET = new Set(ORCHESTRATION_CAPABILITIES);
118
+ export function parseOrchestrationPolicy(value) {
119
+ if (!OrchestrationPolicyValidator.Check(value)) {
120
+ throw new Error("Invalid orchestration policy");
121
+ }
122
+ if (Object.keys(value.packages).some((capability) => !ORCHESTRATION_CAPABILITY_SET.has(capability))) {
123
+ throw new Error("Invalid orchestration policy: packages keyed by an unknown capability");
124
+ }
125
+ return deepFreeze(structuredClone(value));
126
+ }
127
+ export const RunOrchestrationDecisionV1Schema = StrictObject({
128
+ schemaVersion: Type.Literal(1),
129
+ policyId: Type.Union([Digest, Type.Null()]),
130
+ contractVersion: Type.Literal(ORCHESTRATION_CONTRACT_VERSION),
131
+ runClass: Type.Union([OrchestrationRunClassSchema, Type.Null()]),
132
+ topology: Type.Union([OrchestrationTopologySchema, Type.Null()]),
133
+ decision: Type.Union([OrchestrationDecisionV1Schema, Type.Null()]),
134
+ degradationReason: Type.Union([
135
+ Type.Literal("orchestration-unsupported"),
136
+ Type.Literal("orchestration-disabled"),
137
+ Type.Null(),
138
+ ]),
139
+ });
140
+ // Runtime -> host wire shapes, mirroring packages/coding-agent/src/core/tools/subagent.ts
141
+ // (SubagentTaskEvent) and src/modes/json-event.ts (OrchestrationEnvelope). Field names
142
+ // match the runtime exactly.
143
+ export const SubagentTaskEventSchema = Type.Union([
144
+ StrictObject({
145
+ type: Type.Literal("schedule"),
146
+ taskId: Type.String(),
147
+ dependsOn: Type.Array(Type.String()),
148
+ ownerPaths: Type.Array(Type.String()),
149
+ baseRevision: Type.Optional(Type.String()),
150
+ at: NonnegativeInteger,
151
+ }),
152
+ StrictObject({
153
+ type: Type.Literal("wait"),
154
+ taskId: Type.String(),
155
+ reason: Type.Literal("concurrency"),
156
+ at: NonnegativeInteger,
157
+ }),
158
+ StrictObject({
159
+ type: Type.Literal("serialize"),
160
+ taskId: Type.String(),
161
+ after: Type.Array(Type.String()),
162
+ at: NonnegativeInteger,
163
+ }),
164
+ StrictObject({
165
+ type: Type.Literal("start"),
166
+ taskId: Type.String(),
167
+ attempt: PositiveInteger,
168
+ at: NonnegativeInteger,
169
+ }),
170
+ StrictObject({
171
+ type: Type.Literal("complete"),
172
+ taskId: Type.String(),
173
+ attempt: PositiveInteger,
174
+ at: NonnegativeInteger,
175
+ }),
176
+ StrictObject({
177
+ type: Type.Literal("fail"),
178
+ taskId: Type.String(),
179
+ attempt: PositiveInteger,
180
+ reason: Type.String(),
181
+ at: NonnegativeInteger,
182
+ }),
183
+ StrictObject({
184
+ type: Type.Literal("escalate"),
185
+ taskId: Type.String(),
186
+ fromAttempt: PositiveInteger,
187
+ toAttempt: PositiveInteger,
188
+ model: Type.Optional(Type.String()),
189
+ thinking: Type.Optional(Type.String()),
190
+ at: NonnegativeInteger,
191
+ }),
192
+ StrictObject({
193
+ type: Type.Literal("skip"),
194
+ taskId: Type.String(),
195
+ failedDependency: Type.String(),
196
+ at: NonnegativeInteger,
197
+ }),
198
+ ]);
199
+ const SubagentTaskEventValidator = Compile(SubagentTaskEventSchema);
200
+ export function parseSubagentTaskEvent(value) {
201
+ if (!SubagentTaskEventValidator.Check(value)) {
202
+ throw new Error("Invalid subagent task event");
203
+ }
204
+ return deepFreeze(structuredClone(value));
205
+ }
206
+ export const SubagentIdentityEnvelopeSchema = StrictObject({
207
+ taskId: Type.Optional(Type.String({ minLength: 1 })),
208
+ parentTaskId: Type.Optional(Type.String({ minLength: 1 })),
209
+ depth: Type.Optional(Type.Integer({ minimum: 1, maximum: 3 })),
210
+ });
211
+ const ProgressUuid = Type.String({
212
+ pattern: SUBAGENT_PROGRESS_UUID_PATTERN,
213
+ minLength: 36,
214
+ maxLength: 36,
215
+ });
216
+ const Nullable = (schema) => Type.Union([schema, Type.Null()]);
217
+ const ProgressIdentifier = Nullable(Type.String({
218
+ pattern: SUBAGENT_PROGRESS_IDENTIFIER_PATTERN,
219
+ minLength: 1,
220
+ maxLength: SUBAGENT_PROGRESS_AGENT_MAX_CODE_UNITS,
221
+ }));
222
+ const ProgressModel = Nullable(Type.String({
223
+ pattern: SUBAGENT_PROGRESS_MODEL_PATTERN,
224
+ minLength: 1,
225
+ maxLength: SUBAGENT_PROGRESS_MODEL_MAX_CODE_UNITS,
226
+ }));
227
+ const ProgressToolCallId = Nullable(Type.String({
228
+ pattern: SUBAGENT_PROGRESS_TOOL_CALL_ID_PATTERN,
229
+ minLength: 1,
230
+ maxLength: SUBAGENT_PROGRESS_TOOL_CALL_ID_MAX_CODE_UNITS,
231
+ }));
232
+ const ProgressText = (maxLength) => Nullable(Type.String({ pattern: SUBAGENT_PROGRESS_TEXT_PATTERN, minLength: 1, maxLength }));
233
+ export const SubagentWorkerStatusSchema = Type.Union([
234
+ Type.Literal(SUBAGENT_WORKER_STATUSES[0]),
235
+ Type.Literal(SUBAGENT_WORKER_STATUSES[1]),
236
+ Type.Literal(SUBAGENT_WORKER_STATUSES[2]),
237
+ Type.Literal(SUBAGENT_WORKER_STATUSES[3]),
238
+ Type.Literal(SUBAGENT_WORKER_STATUSES[4]),
239
+ Type.Literal(SUBAGENT_WORKER_STATUSES[5]),
240
+ Type.Literal(SUBAGENT_WORKER_STATUSES[6]),
241
+ Type.Literal(SUBAGENT_WORKER_STATUSES[7]),
242
+ ]);
243
+ export const SubagentCancellationOutcomeSchema = Type.Union([
244
+ Type.Literal(SUBAGENT_CANCELLATION_OUTCOMES[0]),
245
+ Type.Literal(SUBAGENT_CANCELLATION_OUTCOMES[1]),
246
+ Type.Literal(SUBAGENT_CANCELLATION_OUTCOMES[2]),
247
+ Type.Literal(SUBAGENT_CANCELLATION_OUTCOMES[3]),
248
+ ]);
249
+ export const SubagentFailureKindSchema = Type.Union([
250
+ Type.Literal(SUBAGENT_FAILURE_KINDS[0]),
251
+ Type.Literal(SUBAGENT_FAILURE_KINDS[1]),
252
+ Type.Literal(SUBAGENT_FAILURE_KINDS[2]),
253
+ Type.Literal(SUBAGENT_FAILURE_KINDS[3]),
254
+ Type.Null(),
255
+ ]);
256
+ export const SubagentRunModeSchema = Type.Union([
257
+ Type.Literal(SUBAGENT_RUN_MODES[0]),
258
+ Type.Literal(SUBAGENT_RUN_MODES[1]),
259
+ Type.Literal(SUBAGENT_RUN_MODES[2]),
260
+ ]);
261
+ /**
262
+ * Structural TypeBox description of the C1 worker. The hand-written parsers in `subagent-progress.ts` are
263
+ * authoritative: they also enforce lone-surrogate and edge-whitespace rules and the cross-field invariants.
264
+ */
265
+ export const SubagentWorkerSnapshotSchema = StrictObject({
266
+ workerId: ProgressUuid,
267
+ attempt: NonnegativeInteger,
268
+ status: SubagentWorkerStatusSchema,
269
+ cancelRequested: Type.Boolean(),
270
+ cancellationOutcome: SubagentCancellationOutcomeSchema,
271
+ agent: ProgressIdentifier,
272
+ label: ProgressIdentifier,
273
+ task: ProgressText(SUBAGENT_PROGRESS_TASK_MAX_CODE_UNITS),
274
+ model: ProgressModel,
275
+ startedAt: Nullable(NonnegativeInteger),
276
+ endedAt: Nullable(NonnegativeInteger),
277
+ turns: NonnegativeInteger,
278
+ toolCalls: NonnegativeInteger,
279
+ failureKind: SubagentFailureKindSchema,
280
+ resultPreview: ProgressText(SUBAGENT_PROGRESS_RESULT_PREVIEW_MAX_CODE_UNITS),
281
+ });
282
+ export const SubagentRunSnapshotSchema = StrictObject({
283
+ runId: ProgressUuid,
284
+ seq: PositiveInteger,
285
+ final: Type.Boolean(),
286
+ workers: Type.Array(SubagentWorkerSnapshotSchema, { maxItems: SUBAGENT_PROGRESS_MAX_WORKERS_PER_RUN }),
287
+ toolCallId: ProgressToolCallId,
288
+ mode: SubagentRunModeSchema,
289
+ startedAt: NonnegativeInteger,
290
+ endedAt: Nullable(NonnegativeInteger),
291
+ });
292
+ export const SubagentProgressSnapshotSchema = StrictObject({
293
+ schemaVersion: Type.Literal(SUBAGENT_PROGRESS_SCHEMA_VERSION),
294
+ runtimeId: ProgressUuid,
295
+ sessionEpoch: ProgressUuid,
296
+ complete: Type.Boolean(),
297
+ runs: Type.Array(SubagentRunSnapshotSchema, { maxItems: SUBAGENT_PROGRESS_MAX_RUNS }),
298
+ });
299
+ function deepFreeze(value) {
300
+ if (value === null || typeof value !== "object" || Object.isFrozen(value))
301
+ return value;
302
+ Object.freeze(value);
303
+ for (const child of Object.values(value))
304
+ deepFreeze(child);
305
+ return value;
306
+ }
307
+ //# sourceMappingURL=orchestration.js.map