@henryqw/pi-subagent 27.15.1 → 27.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,462 @@
1
+ import { Type, type Static } from "typebox";
2
+ import { type ChangesetTaskRequest } from "./schema.ts";
3
+ export declare const WorkspaceCheckSchema: Type.TObject<{
4
+ command: Type.TString;
5
+ args: Type.TArray<Type.TString>;
6
+ repository: Type.TString;
7
+ }>;
8
+ export declare const WorkspaceTaskSchema: Type.TObject<{
9
+ role: Type.TString;
10
+ modelClass: Type.TUnion<[Type.TLiteral<"fast">, Type.TLiteral<"balanced">, Type.TLiteral<"frontier">, Type.TLiteral<"fav">]>;
11
+ requirements: Type.TString;
12
+ deliverable: Type.TString;
13
+ dependsOn: Type.TArray<Type.TString>;
14
+ contextFrom: Type.TArray<Type.TString>;
15
+ id: Type.TString;
16
+ kind: Type.TLiteral<"changeset">;
17
+ judgment: Type.TOptional<Type.TObject<{
18
+ role: Type.TString;
19
+ modelClass: Type.TUnion<[Type.TLiteral<"fast">, Type.TLiteral<"balanced">, Type.TLiteral<"frontier">, Type.TLiteral<"fav">]>;
20
+ criterion: Type.TString;
21
+ }>>;
22
+ checks: Type.TArray<Type.TObject<{
23
+ command: Type.TString;
24
+ args: Type.TArray<Type.TString>;
25
+ repository: Type.TString;
26
+ }>>;
27
+ inputs: Type.TOptional<Type.TRecord<"^.*$", Type.TString>>;
28
+ }>;
29
+ export declare const WorkspaceRequestSchema: Type.TObject<{
30
+ mode: Type.TLiteral<"isolated">;
31
+ id: Type.TString;
32
+ goal: Type.TString;
33
+ finalJudgment: Type.TOptional<Type.TObject<{
34
+ role: Type.TString;
35
+ modelClass: Type.TUnion<[Type.TLiteral<"fast">, Type.TLiteral<"balanced">, Type.TLiteral<"frontier">, Type.TLiteral<"fav">]>;
36
+ criterion: Type.TString;
37
+ }>>;
38
+ repositories: Type.TRecord<"^.*$", Type.TString>;
39
+ tasks: Type.TArray<Type.TObject<{
40
+ role: Type.TString;
41
+ modelClass: Type.TUnion<[Type.TLiteral<"fast">, Type.TLiteral<"balanced">, Type.TLiteral<"frontier">, Type.TLiteral<"fav">]>;
42
+ requirements: Type.TString;
43
+ deliverable: Type.TString;
44
+ dependsOn: Type.TArray<Type.TString>;
45
+ contextFrom: Type.TArray<Type.TString>;
46
+ id: Type.TString;
47
+ kind: Type.TLiteral<"changeset">;
48
+ judgment: Type.TOptional<Type.TObject<{
49
+ role: Type.TString;
50
+ modelClass: Type.TUnion<[Type.TLiteral<"fast">, Type.TLiteral<"balanced">, Type.TLiteral<"frontier">, Type.TLiteral<"fav">]>;
51
+ criterion: Type.TString;
52
+ }>>;
53
+ checks: Type.TArray<Type.TObject<{
54
+ command: Type.TString;
55
+ args: Type.TArray<Type.TString>;
56
+ repository: Type.TString;
57
+ }>>;
58
+ inputs: Type.TOptional<Type.TRecord<"^.*$", Type.TString>>;
59
+ }>>;
60
+ finalChecks: Type.TArray<Type.TObject<{
61
+ command: Type.TString;
62
+ args: Type.TArray<Type.TString>;
63
+ repository: Type.TString;
64
+ }>>;
65
+ }>;
66
+ export type WorkspaceRequest = Static<typeof WorkspaceRequestSchema>;
67
+ export type WorkspaceCheck = Static<typeof WorkspaceCheckSchema>;
68
+ export declare const IdentitySetSchema: Type.TRecord<"^.*$", Type.TObject<{
69
+ branch: Type.TString;
70
+ head: Type.TString;
71
+ index: Type.TString;
72
+ tree: Type.TString;
73
+ }>>;
74
+ export type IdentitySet = Static<typeof IdentitySetSchema>;
75
+ export declare const WorkspaceActionSchema: Type.TObject<{
76
+ id: Type.TString;
77
+ action: Type.TUnsafe<"abort" | "cleanup" | "promote" | "reconcile" | "stage" | "status" | "validate">;
78
+ expected: Type.TOptional<Type.TRecord<"^.*$", Type.TObject<{
79
+ branch: Type.TString;
80
+ head: Type.TString;
81
+ index: Type.TString;
82
+ tree: Type.TString;
83
+ }>>>;
84
+ }>;
85
+ export type WorkspaceAction = Static<typeof WorkspaceActionSchema>;
86
+ export declare function parseWorkspaceRequest(value: unknown): WorkspaceRequest;
87
+ export declare function workerTask(request: WorkspaceRequest): ChangesetTaskRequest;
88
+ export declare function sameSet(left: IdentitySet, right: IdentitySet): boolean;
89
+ export declare const WorkspaceStateSchema: Type.TObject<{
90
+ version: Type.TLiteral<1>;
91
+ root: Type.TString;
92
+ request: Type.TObject<{
93
+ mode: Type.TLiteral<"isolated">;
94
+ id: Type.TString;
95
+ goal: Type.TString;
96
+ finalJudgment: Type.TOptional<Type.TObject<{
97
+ role: Type.TString;
98
+ modelClass: Type.TUnion<[Type.TLiteral<"fast">, Type.TLiteral<"balanced">, Type.TLiteral<"frontier">, Type.TLiteral<"fav">]>;
99
+ criterion: Type.TString;
100
+ }>>;
101
+ repositories: Type.TRecord<"^.*$", Type.TString>;
102
+ tasks: Type.TArray<Type.TObject<{
103
+ role: Type.TString;
104
+ modelClass: Type.TUnion<[Type.TLiteral<"fast">, Type.TLiteral<"balanced">, Type.TLiteral<"frontier">, Type.TLiteral<"fav">]>;
105
+ requirements: Type.TString;
106
+ deliverable: Type.TString;
107
+ dependsOn: Type.TArray<Type.TString>;
108
+ contextFrom: Type.TArray<Type.TString>;
109
+ id: Type.TString;
110
+ kind: Type.TLiteral<"changeset">;
111
+ judgment: Type.TOptional<Type.TObject<{
112
+ role: Type.TString;
113
+ modelClass: Type.TUnion<[Type.TLiteral<"fast">, Type.TLiteral<"balanced">, Type.TLiteral<"frontier">, Type.TLiteral<"fav">]>;
114
+ criterion: Type.TString;
115
+ }>>;
116
+ checks: Type.TArray<Type.TObject<{
117
+ command: Type.TString;
118
+ args: Type.TArray<Type.TString>;
119
+ repository: Type.TString;
120
+ }>>;
121
+ inputs: Type.TOptional<Type.TRecord<"^.*$", Type.TString>>;
122
+ }>>;
123
+ finalChecks: Type.TArray<Type.TObject<{
124
+ command: Type.TString;
125
+ args: Type.TArray<Type.TString>;
126
+ repository: Type.TString;
127
+ }>>;
128
+ }>;
129
+ status: Type.TUnsafe<"aborted" | "allocating" | "attention" | "checking" | "cleaned" | "partial" | "promoted" | "promoting" | "ready" | "staged" | "staging" | "validated" | "validating" | "working">;
130
+ policy: Type.TObject<{
131
+ maxSubagents: Type.TInteger;
132
+ maxTurns: Type.TInteger;
133
+ maxTokens: Type.TOptional<Type.TInteger>;
134
+ childIdleMs: Type.TNumber;
135
+ childMaxMs: Type.TNumber;
136
+ maxCorrections: Type.TInteger;
137
+ }>;
138
+ repositories: Type.TRecord<"^.*$", Type.TObject<{
139
+ root: Type.TString;
140
+ common: Type.TString;
141
+ base: Type.TObject<{
142
+ branch: Type.TString;
143
+ head: Type.TString;
144
+ index: Type.TString;
145
+ tree: Type.TString;
146
+ }>;
147
+ testScript: Type.TOptional<Type.TString>;
148
+ attempt: Type.TObject<{
149
+ number: Type.TInteger;
150
+ waveNumber: Type.TInteger;
151
+ waveBase: Type.TObject<{
152
+ branch: Type.TString;
153
+ head: Type.TString;
154
+ index: Type.TString;
155
+ tree: Type.TString;
156
+ }>;
157
+ correlationToken: Type.TString;
158
+ allocationGeneration: Type.TInteger;
159
+ allocations: Type.TArray<Type.TUnion<[Type.TObject<{
160
+ generation: Type.TInteger;
161
+ token: Type.TString;
162
+ status: Type.TUnion<[Type.TLiteral<"allocating">, Type.TLiteral<"owned">, Type.TLiteral<"absent">, Type.TLiteral<"unknown">]>;
163
+ possibleResources: Type.TOptional<Type.TArray<Type.TString>>;
164
+ failure: Type.TOptional<Type.TString>;
165
+ kind: Type.TLiteral<"worktree">;
166
+ worktree: Type.TOptional<Type.TObject<{
167
+ path: Type.TString;
168
+ cwd: Type.TString;
169
+ branch: Type.TString;
170
+ repoRoot: Type.TString;
171
+ baseCommit: Type.TString;
172
+ }>>;
173
+ }>, Type.TObject<{
174
+ generation: Type.TInteger;
175
+ token: Type.TString;
176
+ status: Type.TUnion<[Type.TLiteral<"allocating">, Type.TLiteral<"owned">, Type.TLiteral<"absent">, Type.TLiteral<"unknown">]>;
177
+ possibleResources: Type.TOptional<Type.TArray<Type.TString>>;
178
+ failure: Type.TOptional<Type.TString>;
179
+ kind: Type.TLiteral<"workspace">;
180
+ label: Type.TString;
181
+ worktreeCwd: Type.TString;
182
+ mainRoot: Type.TString;
183
+ repoKey: Type.TString;
184
+ herdrRepoRoot: Type.TString;
185
+ workspaceId: Type.TOptional<Type.TString>;
186
+ rootTabId: Type.TOptional<Type.TString>;
187
+ rootPaneId: Type.TOptional<Type.TString>;
188
+ }>, Type.TObject<{
189
+ generation: Type.TInteger;
190
+ token: Type.TString;
191
+ status: Type.TUnion<[Type.TLiteral<"allocating">, Type.TLiteral<"owned">, Type.TLiteral<"absent">, Type.TLiteral<"unknown">]>;
192
+ possibleResources: Type.TOptional<Type.TArray<Type.TString>>;
193
+ failure: Type.TOptional<Type.TString>;
194
+ kind: Type.TLiteral<"worker_tab">;
195
+ label: Type.TString;
196
+ workspaceId: Type.TString;
197
+ workspaceRootTabId: Type.TString;
198
+ workspaceRootPaneId: Type.TString;
199
+ worktreeCwd: Type.TString;
200
+ leasePath: Type.TString;
201
+ tabId: Type.TOptional<Type.TString>;
202
+ paneId: Type.TOptional<Type.TString>;
203
+ }>, Type.TObject<{
204
+ generation: Type.TInteger;
205
+ token: Type.TString;
206
+ status: Type.TUnion<[Type.TLiteral<"allocating">, Type.TLiteral<"owned">, Type.TLiteral<"absent">, Type.TLiteral<"unknown">]>;
207
+ possibleResources: Type.TOptional<Type.TArray<Type.TString>>;
208
+ failure: Type.TOptional<Type.TString>;
209
+ kind: Type.TLiteral<"agent">;
210
+ agentName: Type.TString;
211
+ workspaceId: Type.TString;
212
+ tabId: Type.TString;
213
+ paneId: Type.TString;
214
+ worktreeCwd: Type.TString;
215
+ leasePath: Type.TString;
216
+ }>]>>;
217
+ prompts: Type.TArray<Type.TObject<{
218
+ kind: Type.TUnion<[Type.TLiteral<"initial">, Type.TLiteral<"correction">, Type.TLiteral<"followup">]>;
219
+ status: Type.TUnion<[Type.TLiteral<"submitting">, Type.TLiteral<"not_sent">, Type.TLiteral<"settled">, Type.TLiteral<"ambiguous">]>;
220
+ preCandidate: Type.TObject<{
221
+ branch: Type.TString;
222
+ head: Type.TString;
223
+ index: Type.TString;
224
+ tree: Type.TString;
225
+ }>;
226
+ candidate: Type.TOptional<Type.TObject<{
227
+ branch: Type.TString;
228
+ head: Type.TString;
229
+ index: Type.TString;
230
+ tree: Type.TString;
231
+ }>>;
232
+ instruction: Type.TOptional<Type.TString>;
233
+ failure: Type.TOptional<Type.TString>;
234
+ at: Type.TInteger;
235
+ }>>;
236
+ candidate: Type.TOptional<Type.TObject<{
237
+ branch: Type.TString;
238
+ head: Type.TString;
239
+ index: Type.TString;
240
+ tree: Type.TString;
241
+ }>>;
242
+ candidateBase: Type.TOptional<Type.TObject<{
243
+ branch: Type.TString;
244
+ head: Type.TString;
245
+ index: Type.TString;
246
+ tree: Type.TString;
247
+ }>>;
248
+ preliminaryChecks: Type.TOptional<Type.TObject<{
249
+ phase: Type.TUnion<[Type.TLiteral<"preliminary">, Type.TLiteral<"final">]>;
250
+ candidate: Type.TObject<{
251
+ branch: Type.TString;
252
+ head: Type.TString;
253
+ index: Type.TString;
254
+ tree: Type.TString;
255
+ }>;
256
+ identityAfter: Type.TObject<{
257
+ branch: Type.TString;
258
+ head: Type.TString;
259
+ index: Type.TString;
260
+ tree: Type.TString;
261
+ }>;
262
+ results: Type.TArray<Type.TObject<{
263
+ command: Type.TString;
264
+ args: Type.TArray<Type.TString>;
265
+ code: Type.TInteger;
266
+ killed: Type.TBoolean;
267
+ stdout: Type.TString;
268
+ stderr: Type.TString;
269
+ reusedFrom: Type.TOptional<Type.TObject<{
270
+ taskId: Type.TString;
271
+ attempt: Type.TInteger;
272
+ candidate: Type.TObject<{
273
+ branch: Type.TString;
274
+ head: Type.TString;
275
+ index: Type.TString;
276
+ tree: Type.TString;
277
+ }>;
278
+ }>>;
279
+ }>>;
280
+ passed: Type.TBoolean;
281
+ at: Type.TInteger;
282
+ }>>;
283
+ readiness: Type.TOptional<Type.TObject<{
284
+ candidate: Type.TObject<{
285
+ branch: Type.TString;
286
+ head: Type.TString;
287
+ index: Type.TString;
288
+ tree: Type.TString;
289
+ }>;
290
+ base: Type.TObject<{
291
+ branch: Type.TString;
292
+ head: Type.TString;
293
+ index: Type.TString;
294
+ tree: Type.TString;
295
+ }>;
296
+ at: Type.TInteger;
297
+ }>>;
298
+ superseded: Type.TOptional<Type.TLiteral<true>>;
299
+ termination: Type.TOptional<Type.TObject<{
300
+ status: Type.TUnion<[Type.TLiteral<"terminating">, Type.TLiteral<"terminated">, Type.TLiteral<"unknown">]>;
301
+ workerId: Type.TString;
302
+ candidate: Type.TObject<{
303
+ branch: Type.TString;
304
+ head: Type.TString;
305
+ index: Type.TString;
306
+ tree: Type.TString;
307
+ }>;
308
+ at: Type.TOptional<Type.TInteger>;
309
+ failure: Type.TOptional<Type.TString>;
310
+ }>>;
311
+ preliminaryReview: Type.TOptional<Type.TObject<{
312
+ phase: Type.TUnion<[Type.TLiteral<"preliminary">, Type.TLiteral<"final">]>;
313
+ criterion: Type.TString;
314
+ base: Type.TObject<{
315
+ branch: Type.TString;
316
+ head: Type.TString;
317
+ index: Type.TString;
318
+ tree: Type.TString;
319
+ }>;
320
+ tip: Type.TObject<{
321
+ branch: Type.TString;
322
+ head: Type.TString;
323
+ index: Type.TString;
324
+ tree: Type.TString;
325
+ }>;
326
+ identityAfter: Type.TObject<{
327
+ branch: Type.TString;
328
+ head: Type.TString;
329
+ index: Type.TString;
330
+ tree: Type.TString;
331
+ }>;
332
+ verdict: Type.TString;
333
+ passed: Type.TBoolean;
334
+ at: Type.TInteger;
335
+ }>>;
336
+ cleanup: Type.TArray<Type.TObject<{
337
+ kind: Type.TUnion<[Type.TLiteral<"worker_tab">, Type.TLiteral<"workspace">, Type.TLiteral<"worktree">, Type.TLiteral<"branch">]>;
338
+ status: Type.TUnion<[Type.TLiteral<"pending">, Type.TLiteral<"running">, Type.TLiteral<"completed">]>;
339
+ failure: Type.TOptional<Type.TString>;
340
+ }>>;
341
+ }>;
342
+ integration: Type.TOptional<Type.TObject<{
343
+ path: Type.TString;
344
+ cwd: Type.TString;
345
+ branch: Type.TString;
346
+ repoRoot: Type.TString;
347
+ baseCommit: Type.TString;
348
+ }>>;
349
+ allocation: Type.TOptional<Type.TUnion<[Type.TLiteral<"allocating">, Type.TLiteral<"owned">]>>;
350
+ stage: Type.TOptional<Type.TUnion<[Type.TLiteral<"staging">, Type.TLiteral<"staged">, Type.TLiteral<"unchanged">]>>;
351
+ receipt: Type.TOptional<Type.TObject<{
352
+ previous: Type.TObject<{
353
+ branch: Type.TString;
354
+ head: Type.TString;
355
+ index: Type.TString;
356
+ tree: Type.TString;
357
+ }>;
358
+ worker: Type.TObject<{
359
+ branch: Type.TString;
360
+ head: Type.TString;
361
+ index: Type.TString;
362
+ tree: Type.TString;
363
+ }>;
364
+ tip: Type.TObject<{
365
+ branch: Type.TString;
366
+ head: Type.TString;
367
+ index: Type.TString;
368
+ tree: Type.TString;
369
+ }>;
370
+ }>>;
371
+ promotion: Type.TOptional<Type.TObject<{
372
+ status: Type.TUnion<[Type.TLiteral<"pending">, Type.TLiteral<"promoting">, Type.TLiteral<"promoted">]>;
373
+ expected: Type.TObject<{
374
+ branch: Type.TString;
375
+ head: Type.TString;
376
+ index: Type.TString;
377
+ tree: Type.TString;
378
+ }>;
379
+ tip: Type.TObject<{
380
+ branch: Type.TString;
381
+ head: Type.TString;
382
+ index: Type.TString;
383
+ tree: Type.TString;
384
+ }>;
385
+ mainAfter: Type.TOptional<Type.TObject<{
386
+ branch: Type.TString;
387
+ head: Type.TString;
388
+ index: Type.TString;
389
+ tree: Type.TString;
390
+ }>>;
391
+ }>>;
392
+ cleanup: Type.TOptional<Type.TArray<Type.TString>>;
393
+ }>>;
394
+ inputs: Type.TRecord<"^.*$", Type.TObject<{
395
+ source: Type.TString;
396
+ path: Type.TString;
397
+ digest: Type.TString;
398
+ }>>;
399
+ candidates: Type.TOptional<Type.TRecord<"^.*$", Type.TObject<{
400
+ branch: Type.TString;
401
+ head: Type.TString;
402
+ index: Type.TString;
403
+ tree: Type.TString;
404
+ }>>>;
405
+ tips: Type.TOptional<Type.TRecord<"^.*$", Type.TObject<{
406
+ branch: Type.TString;
407
+ head: Type.TString;
408
+ index: Type.TString;
409
+ tree: Type.TString;
410
+ }>>>;
411
+ preliminary: Type.TOptional<Type.TObject<{
412
+ before: Type.TRecord<"^.*$", Type.TObject<{
413
+ branch: Type.TString;
414
+ head: Type.TString;
415
+ index: Type.TString;
416
+ tree: Type.TString;
417
+ }>>;
418
+ after: Type.TRecord<"^.*$", Type.TObject<{
419
+ branch: Type.TString;
420
+ head: Type.TString;
421
+ index: Type.TString;
422
+ tree: Type.TString;
423
+ }>>;
424
+ results: Type.TArray<Type.TObject<{
425
+ command: Type.TString;
426
+ args: Type.TArray<Type.TString>;
427
+ repository: Type.TString;
428
+ code: Type.TInteger;
429
+ killed: Type.TBoolean;
430
+ stdout: Type.TString;
431
+ stderr: Type.TString;
432
+ }>>;
433
+ }>>;
434
+ final: Type.TOptional<Type.TObject<{
435
+ before: Type.TRecord<"^.*$", Type.TObject<{
436
+ branch: Type.TString;
437
+ head: Type.TString;
438
+ index: Type.TString;
439
+ tree: Type.TString;
440
+ }>>;
441
+ after: Type.TRecord<"^.*$", Type.TObject<{
442
+ branch: Type.TString;
443
+ head: Type.TString;
444
+ index: Type.TString;
445
+ tree: Type.TString;
446
+ }>>;
447
+ results: Type.TArray<Type.TObject<{
448
+ command: Type.TString;
449
+ args: Type.TArray<Type.TString>;
450
+ repository: Type.TString;
451
+ code: Type.TInteger;
452
+ killed: Type.TBoolean;
453
+ stdout: Type.TString;
454
+ stderr: Type.TString;
455
+ }>>;
456
+ }>>;
457
+ failure: Type.TOptional<Type.TString>;
458
+ }>;
459
+ export type WorkspaceState = Static<typeof WorkspaceStateSchema>;
460
+ export type WorkspaceEvidence = NonNullable<WorkspaceState["final"]>;
461
+ export declare function parseWorkspaceState(value: unknown): WorkspaceState;
462
+ export declare function setFrom(state: WorkspaceState, field: "base" | "candidate"): IdentitySet;
@@ -0,0 +1,111 @@
1
+ import { Type } from "typebox";
2
+ import { Check } from "typebox/value";
3
+ import { CheckCommandSchema, ExecutionPolicySnapshotSchema, ExecuteRequestSchema, parseExecuteRequest, TaskAttemptSchema, WorkspaceSchema, WorktreeRecordSchema, sameIdentity } from "./schema.js";
4
+ import { RepositorySelectionSchema, parseRepositorySelection } from "./workspace-scope.js";
5
+ const Name = Type.String({ pattern: "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$", maxLength: 80 });
6
+ const Text = Type.String({ minLength: 1, maxLength: 8192 });
7
+ export const WorkspaceCheckSchema = Type.Object({ ...CheckCommandSchema.properties, repository: Name }, { additionalProperties: false });
8
+ export const WorkspaceTaskSchema = Type.Object({
9
+ ...ExecuteRequestSchema.properties.tasks.items.anyOf[1].properties,
10
+ checks: Type.Array(WorkspaceCheckSchema, { minItems: 1, maxItems: 32 }),
11
+ inputs: Type.Optional(RepositorySelectionSchema),
12
+ }, { additionalProperties: false });
13
+ export const WorkspaceRequestSchema = Type.Object({
14
+ ...ExecuteRequestSchema.properties,
15
+ repositories: RepositorySelectionSchema,
16
+ tasks: Type.Array(WorkspaceTaskSchema, { minItems: 1, maxItems: 1 }),
17
+ finalChecks: Type.Array(WorkspaceCheckSchema, { minItems: 1, maxItems: 32 }),
18
+ }, { additionalProperties: false });
19
+ export const IdentitySetSchema = Type.Record(Name, WorkspaceSchema, { minProperties: 1, maxProperties: 8 });
20
+ const ACTIONS = ["status", "stage", "validate", "promote", "reconcile", "abort", "cleanup"];
21
+ const STATUSES = ["allocating", "working", "checking", "ready", "staging", "staged", "validating", "validated", "promoting", "partial", "promoted", "aborted", "attention", "cleaned"];
22
+ export const WorkspaceActionSchema = Type.Object({
23
+ id: ExecuteRequestSchema.properties.id,
24
+ action: Type.Unsafe({ type: "string", enum: [...ACTIONS] }),
25
+ expected: Type.Optional(IdentitySetSchema),
26
+ }, { additionalProperties: false });
27
+ export function parseWorkspaceRequest(value) {
28
+ if (!Check(WorkspaceRequestSchema, value))
29
+ throw new Error("Workspace requests require one changeset task, explicit repositories, and repository-tagged checks.");
30
+ parseRepositorySelection(value.repositories);
31
+ const task = value.tasks[0];
32
+ if (task.dependsOn.length || task.contextFrom.length || task.judgment || value.finalJudgment)
33
+ throw new Error("Workspace requests do not support task dependencies, text tasks, or judgment. Use a single changeset task with explicit automated checks.");
34
+ if (task.inputs)
35
+ parseRepositorySelection(task.inputs);
36
+ const strip = ({ repository: _repository, ...check }) => check;
37
+ parseExecuteRequest({ mode: value.mode, id: value.id, goal: value.goal,
38
+ tasks: [{ ...workerTask(value), checks: task.checks.map(strip) }], finalChecks: value.finalChecks.map(strip) });
39
+ for (const check of [...task.checks, ...value.finalChecks]) {
40
+ if (!Object.hasOwn(value.repositories, check.repository))
41
+ throw new Error(`Check selects unknown repository ${check.repository}.`);
42
+ }
43
+ for (const repository of Object.keys(value.repositories)) {
44
+ if (!task.checks.some((check) => check.repository === repository))
45
+ throw new Error(`Task checks are missing for repository ${repository}.`);
46
+ if (!value.finalChecks.some((check) => check.repository === repository))
47
+ throw new Error(`Final checks are missing for repository ${repository}.`);
48
+ }
49
+ return structuredClone(value);
50
+ }
51
+ export function workerTask(request) {
52
+ const { inputs: _inputs, checks, ...task } = request.tasks[0];
53
+ return { ...task, checks: checks.map(({ repository: _repository, ...check }) => check) };
54
+ }
55
+ export function sameSet(left, right) {
56
+ return Object.keys(left).length === Object.keys(right).length && Object.keys(left).every((name) => right[name] && sameIdentity(left[name], right[name]));
57
+ }
58
+ const Receipt = Type.Object({ previous: WorkspaceSchema, worker: WorkspaceSchema, tip: WorkspaceSchema }, { additionalProperties: false });
59
+ const RepoState = Type.Object({
60
+ root: Text, common: Text, base: WorkspaceSchema, testScript: Type.Optional(Text), attempt: TaskAttemptSchema,
61
+ integration: Type.Optional(WorktreeRecordSchema),
62
+ allocation: Type.Optional(Type.Union([Type.Literal("allocating"), Type.Literal("owned")])),
63
+ stage: Type.Optional(Type.Union([Type.Literal("staging"), Type.Literal("staged"), Type.Literal("unchanged")])),
64
+ receipt: Type.Optional(Receipt),
65
+ promotion: Type.Optional(Type.Object({
66
+ status: Type.Union([Type.Literal("pending"), Type.Literal("promoting"), Type.Literal("promoted")]),
67
+ expected: WorkspaceSchema, tip: WorkspaceSchema, mainAfter: Type.Optional(WorkspaceSchema),
68
+ }, { additionalProperties: false })),
69
+ cleanup: Type.Optional(Type.Array(Type.String({ enum: ["worker_tab", "workspace", "worker", "worker_branch", "integration", "integration_branch"] }), { uniqueItems: true, maxItems: 6 })),
70
+ }, { additionalProperties: false });
71
+ const CheckResult = Type.Object({ ...WorkspaceCheckSchema.properties, code: Type.Integer(), killed: Type.Boolean(), stdout: Type.String({ maxLength: 8192 }), stderr: Type.String({ maxLength: 8192 }) }, { additionalProperties: false });
72
+ const Evidence = Type.Object({ before: IdentitySetSchema, after: IdentitySetSchema, results: Type.Array(CheckResult, { maxItems: 40 }) }, { additionalProperties: false });
73
+ export const WorkspaceStateSchema = Type.Object({
74
+ version: Type.Literal(1), root: Text, request: WorkspaceRequestSchema,
75
+ status: Type.Unsafe({ type: "string", enum: [...STATUSES] }),
76
+ policy: ExecutionPolicySnapshotSchema,
77
+ repositories: Type.Record(Name, RepoState, { minProperties: 1, maxProperties: 8 }),
78
+ inputs: Type.Record(Name, Type.Object({ source: Text, path: Text, digest: Type.String({ pattern: "^[a-f0-9]{64}$" }) }, { additionalProperties: false }), { maxProperties: 8 }),
79
+ candidates: Type.Optional(IdentitySetSchema), tips: Type.Optional(IdentitySetSchema),
80
+ preliminary: Type.Optional(Evidence), final: Type.Optional(Evidence),
81
+ failure: Type.Optional(Text),
82
+ }, { additionalProperties: false });
83
+ export function parseWorkspaceState(value) {
84
+ if (!Check(WorkspaceStateSchema, value))
85
+ throw new Error("Workspace state is invalid; preserve the file and all resources.");
86
+ parseWorkspaceRequest(value.request);
87
+ const names = Object.keys(value.repositories);
88
+ const complete = (set) => names.length === Object.keys(set).length && names.every((name) => Object.hasOwn(set, name));
89
+ if (!complete(value.request.repositories) || value.candidates && !complete(value.candidates) || value.tips && !complete(value.tips))
90
+ throw new Error("Workspace state has an incomplete repository set.");
91
+ for (const [name, repo] of Object.entries(value.repositories)) {
92
+ if (repo.root !== value.request.repositories[name] || !sameIdentity(repo.base, repo.attempt.waveBase))
93
+ throw new Error("Workspace repository base or root changed.");
94
+ if (repo.promotion && (!value.tips || !sameIdentity(repo.promotion.tip, value.tips[name]) || !sameIdentity(repo.promotion.expected, repo.base)))
95
+ throw new Error("Workspace promotion intent changed.");
96
+ if (repo.promotion?.status === "promoted" && (!repo.promotion.mainAfter || !sameIdentity(repo.promotion.mainAfter, { ...repo.promotion.tip, branch: repo.base.branch })))
97
+ throw new Error("Workspace promotion receipt is invalid.");
98
+ }
99
+ for (const evidence of [value.preliminary, value.final])
100
+ if (evidence && (!complete(evidence.before) || !complete(evidence.after)))
101
+ throw new Error("Workspace checks have an incomplete input set.");
102
+ return value;
103
+ }
104
+ export function setFrom(state, field) {
105
+ return Object.fromEntries(Object.entries(state.repositories).map(([name, repo]) => {
106
+ const identity = field === "base" ? repo.base : repo.attempt.candidate;
107
+ if (!identity)
108
+ throw new Error(`Repository ${name} has no ${field}.`);
109
+ return [name, identity];
110
+ }));
111
+ }
@@ -0,0 +1,16 @@
1
+ import { Type, type Static } from "typebox";
2
+ export declare const RepositorySelectionSchema: Type.TRecord<"^.*$", Type.TString>;
3
+ export type RepositorySelection = Static<typeof RepositorySelectionSchema>;
4
+ export type SelectedRepository = {
5
+ root: string;
6
+ common: string;
7
+ };
8
+ export type WorkspaceScope = {
9
+ root: string;
10
+ repositories: Record<string, SelectedRepository>;
11
+ };
12
+ export declare function parseRepositorySelection(value: unknown): RepositorySelection;
13
+ /** Selection is explicit. Never discover repositories or infer a write scope from their names. */
14
+ export declare function resolveWorkspaceScope(cwd: string, selection: RepositorySelection, signal?: AbortSignal): Promise<WorkspaceScope>;
15
+ /** Root inputs are files, not trees or Git members. No symlink traversal is accepted. */
16
+ export declare function workspaceInputPath(scope: WorkspaceScope, path: string): Promise<string>;
@@ -0,0 +1,60 @@
1
+ import { lstat, realpath } from "node:fs/promises";
2
+ import { dirname, isAbsolute, relative, resolve } from "node:path";
3
+ import { Type } from "typebox";
4
+ import { Check } from "typebox/value";
5
+ import { runGit } from "./git-process.js";
6
+ const Name = Type.String({ pattern: "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$", maxLength: 80 });
7
+ export const RepositorySelectionSchema = Type.Record(Name, Type.String({ minLength: 1, maxLength: 4096 }), { minProperties: 1, maxProperties: 8 });
8
+ export function parseRepositorySelection(value) {
9
+ if (!Check(RepositorySelectionSchema, value))
10
+ throw new Error("repositories must map 1 to 8 unique names to absolute Git checkout paths.");
11
+ for (const path of Object.values(value)) {
12
+ if (!isAbsolute(path) || resolve(path) !== path || /[\x00-\x1f\x7f]/.test(path))
13
+ throw new Error("Selected repository paths must be absolute and normalized without control characters.");
14
+ }
15
+ return value;
16
+ }
17
+ /** Selection is explicit. Never discover repositories or infer a write scope from their names. */
18
+ export async function resolveWorkspaceScope(cwd, selection, signal) {
19
+ parseRepositorySelection(selection);
20
+ signal?.throwIfAborted();
21
+ if (process.env.GIT_DIR || process.env.GIT_WORK_TREE || process.env.GIT_INDEX_FILE)
22
+ throw new Error("Workspace selection does not support Git environment overrides.");
23
+ const root = await realpath(cwd);
24
+ const enclosing = await runGit(["rev-parse", "--show-toplevel"], root, signal);
25
+ if (enclosing.code === 0 || enclosing.code === -1 || !/not a git repository/i.test(enclosing.stderr))
26
+ throw new Error("Explicit repositories require a non-Git workspace directory.");
27
+ const repositories = {};
28
+ const commons = new Set();
29
+ for (const [name, path] of Object.entries(selection)) {
30
+ signal?.throwIfAborted();
31
+ const canonical = await realpath(path);
32
+ // One workspace owns selection. Nested layouts and symlink aliases are not inferred.
33
+ if (canonical !== path || dirname(path) !== root || !(await lstat(path)).isDirectory())
34
+ throw new Error(`Repository ${name} must be a canonical direct child of the workspace.`);
35
+ const top = await runGit(["rev-parse", "--show-toplevel"], path, signal);
36
+ const commonResult = await runGit(["rev-parse", "--path-format=absolute", "--git-common-dir"], path, signal);
37
+ if (top.code !== 0 || top.stdout.trimEnd() !== path || commonResult.code !== 0)
38
+ throw new Error(`Repository ${name} does not identify an exact Git checkout.`);
39
+ const common = await realpath(commonResult.stdout.trimEnd());
40
+ if (common !== resolve(path, ".git") || !(await lstat(common)).isDirectory() || commons.has(common))
41
+ throw new Error(`Repository ${name} must be an independent primary checkout with its own .git directory.`);
42
+ commons.add(common);
43
+ repositories[name] = { root: path, common };
44
+ }
45
+ return { root, repositories };
46
+ }
47
+ /** Root inputs are files, not trees or Git members. No symlink traversal is accepted. */
48
+ export async function workspaceInputPath(scope, path) {
49
+ if (!isAbsolute(path) || await realpath(path) !== path || !(await lstat(path)).isFile())
50
+ throw new Error("Workspace inputs must be canonical regular files.");
51
+ const within = relative(scope.root, path);
52
+ if (!within || within.startsWith("..") || isAbsolute(within) || within.split(/[\\/]/).includes(".git")
53
+ || Object.values(scope.repositories).some(({ root }) => path.startsWith(`${root}/`)))
54
+ throw new Error("Workspace inputs must be outside selected repositories and inside the workspace.");
55
+ // An unselected repository is not a workspace-root input source either.
56
+ const git = await runGit(["rev-parse", "--show-toplevel"], dirname(path));
57
+ if (git.code === 0 || git.code === -1 || !/not a git repository/i.test(git.stderr))
58
+ throw new Error("Workspace input belongs to a Git repository or its scope is uncertain.");
59
+ return path;
60
+ }