@atolis-hq/wake 0.4.102 → 0.4.104

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 (48) hide show
  1. package/dist/src/activities/pr/policy.d.ts +2 -0
  2. package/dist/src/activities/pr/policy.js +9 -1
  3. package/dist/src/bootstrap/artifact-mcp.js +20 -1
  4. package/dist/src/bootstrap/surface-api-delivery.js +6 -2
  5. package/dist/src/bootstrap/version.js +1 -1
  6. package/dist/src/integrations/application/delegation-outputs.js +41 -5
  7. package/dist/src/orchestration/application/conversation-command-reactor.js +25 -0
  8. package/dist/src/orchestration/application/delegated-work.d.ts +55 -2
  9. package/dist/src/orchestration/application/delegated-work.js +170 -23
  10. package/dist/src/orchestration/application/delegation-attention-escalations.d.ts +11 -0
  11. package/dist/src/orchestration/application/delegation-attention-escalations.js +36 -0
  12. package/dist/src/orchestration/application/delegation-attention-state.d.ts +53 -0
  13. package/dist/src/orchestration/application/delegation-attention-state.js +194 -0
  14. package/dist/src/orchestration/application/delegation-attention.d.ts +58 -0
  15. package/dist/src/orchestration/application/delegation-attention.js +206 -0
  16. package/dist/src/orchestration/application/delegation-commands.d.ts +52 -1
  17. package/dist/src/orchestration/application/delegation-commands.js +22 -3
  18. package/dist/src/orchestration/application/delegation-gate.d.ts +8 -3
  19. package/dist/src/orchestration/application/delegation-gate.js +45 -11
  20. package/dist/src/orchestration/application/delegation-ledger.d.ts +2 -0
  21. package/dist/src/orchestration/application/delegation-ledger.js +8 -0
  22. package/dist/src/orchestration/application/delegation-prerequisites.d.ts +28 -0
  23. package/dist/src/orchestration/application/delegation-prerequisites.js +118 -0
  24. package/dist/src/orchestration/application/delegation-reservation.js +1 -1
  25. package/dist/src/orchestration/application/delegation-wait-graph.d.ts +7 -0
  26. package/dist/src/orchestration/application/delegation-wait-graph.js +122 -0
  27. package/dist/src/orchestration/application/orchestration-repository.d.ts +5 -0
  28. package/dist/src/orchestration/application/orchestration-repository.js +3 -0
  29. package/dist/src/orchestration/application/orchestration-service.d.ts +103 -1
  30. package/dist/src/orchestration/application/orchestration-service.js +40 -2
  31. package/dist/src/orchestration/application/prerequisite-readiness.d.ts +68 -0
  32. package/dist/src/orchestration/application/prerequisite-readiness.js +217 -0
  33. package/dist/src/orchestration/contracts/delegation-ports.d.ts +2 -1
  34. package/dist/src/orchestration/contracts/delegation.d.ts +150 -0
  35. package/dist/src/orchestration/contracts/delegation.js +84 -1
  36. package/dist/src/orchestration/contracts/event-decoder.js +11 -1
  37. package/dist/src/orchestration/contracts/event-factory.js +12 -5
  38. package/dist/src/orchestration/contracts/events.d.ts +27 -1
  39. package/dist/src/orchestration/contracts/events.js +6 -0
  40. package/dist/src/orchestration/contracts/views.d.ts +6 -0
  41. package/dist/src/orchestration/contracts/vocabulary.d.ts +45 -0
  42. package/dist/src/orchestration/contracts/vocabulary.js +41 -0
  43. package/dist/src/orchestration/domain/workflow-instance-events.d.ts +1 -0
  44. package/dist/src/orchestration/domain/workflow-instance-events.js +31 -0
  45. package/dist/src/orchestration/index.d.ts +3 -3
  46. package/dist/src/orchestration/index.js +2 -2
  47. package/dist/src/surfaces/mcp/delegation.js +37 -10
  48. package/package.json +1 -1
@@ -0,0 +1,217 @@
1
+ import { isDeepStrictEqual } from 'node:util';
2
+ import { WorkStatus } from '../../work/index.js';
3
+ import { OrchestrationEventType } from '../contracts/events.js';
4
+ import { PrerequisiteBlockCode as Code, DelegationPrerequisiteCondition as Condition, WorkflowStatus, } from '../contracts/vocabulary.js';
5
+ import { isSuccessfulWorkflowCompletion } from '../domain/workflow-completion.js';
6
+ import { reservationsOf } from './delegation-ledger.js';
7
+ /** A bounded read pass: one journal/Work snapshot and one lookup per declared input. */
8
+ export class PrerequisiteReadiness {
9
+ work;
10
+ artifacts;
11
+ repositories;
12
+ failedChildren = new Set();
13
+ children = new Map();
14
+ owners = new Map();
15
+ receipts = new Map();
16
+ workflows = new Map();
17
+ blockers = new Map();
18
+ evaluated = new Map();
19
+ selected = new Map();
20
+ bases = new Map();
21
+ constructor(snapshot, work, artifacts, repositories) {
22
+ this.work = work;
23
+ this.artifacts = artifacts;
24
+ this.repositories = repositories;
25
+ const failures = new Set(snapshot.events.flatMap(({ event, stream }) => event.eventType === OrchestrationEventType.DelegationFailed
26
+ ? [JSON.stringify([stream.id, event.payload.cohortId])]
27
+ : []));
28
+ for (const reservation of reservationsOf(snapshot.events))
29
+ for (const child of reservation.children) {
30
+ if (reservation.children.some((entry) => (entry.prerequisites?.length ?? 0) > 0) &&
31
+ failures.has(JSON.stringify([reservation.parentWorkflowInstanceId, reservation.cohortId])))
32
+ this.failedChildren.add(child.workItemId);
33
+ this.children.set(child.workItemId, child);
34
+ this.owners.set(child.workItemId, reservation);
35
+ }
36
+ for (const { view } of snapshot.instances)
37
+ if (view !== null)
38
+ this.workflows.set(view.workflowInstanceId, view);
39
+ for (const { event } of snapshot.events) {
40
+ if (event.eventType === OrchestrationEventType.DelegationInputsResolved)
41
+ this.receipts.set(event.payload.childWorkItemId, event.payload);
42
+ if (event.eventType === OrchestrationEventType.DelegationChildBlocked)
43
+ this.blockers.set(event.payload.childWorkItemId, {
44
+ code: Code.Failed,
45
+ reason: event.payload.reason,
46
+ });
47
+ }
48
+ }
49
+ abandoned(id) {
50
+ return this.failedChildren.has(id);
51
+ }
52
+ inputs(id) {
53
+ return this.receipts.get(id);
54
+ }
55
+ workflow(id) {
56
+ return this.workflows.get(id);
57
+ }
58
+ async reason(id) {
59
+ return (await this.block(id))?.reason;
60
+ }
61
+ block(id, seen = new Set()) {
62
+ if (seen.has(id))
63
+ return Promise.resolve({ code: Code.Cycle, reason: 'Prerequisite wait cycle' });
64
+ let evaluated = this.evaluated.get(id);
65
+ if (evaluated === undefined) {
66
+ evaluated = this.evaluate(id, new Set([...seen, id])).catch((error) => ({
67
+ code: Code.Unavailable,
68
+ reason: 'Prerequisite verification unavailable: ' +
69
+ (error instanceof Error ? error.message : 'unknown error'),
70
+ }));
71
+ this.evaluated.set(id, evaluated);
72
+ }
73
+ return evaluated;
74
+ }
75
+ async evaluate(id, seen) {
76
+ const blocked = this.blockers.get(id);
77
+ if (blocked !== undefined)
78
+ return blocked;
79
+ const child = this.children.get(id);
80
+ if (child === undefined || (child.prerequisites?.length ?? 0) === 0)
81
+ return undefined;
82
+ for (const upstream of child.prerequisiteWorkItemIds ?? []) {
83
+ const block = await this.block(upstream, seen);
84
+ if (block !== undefined)
85
+ return block;
86
+ }
87
+ const current = await this.select(child, seen);
88
+ if (!Array.isArray(current))
89
+ return current;
90
+ const stored = this.inputs(id);
91
+ if (stored === undefined)
92
+ return { code: Code.Waiting, reason: 'Prerequisite inputs have not been pinned' };
93
+ if (!isDeepStrictEqual(freshness(stored.consumed), freshness(current)))
94
+ return {
95
+ code: Code.Changed,
96
+ reason: 'Consumed upstream output or base changed; agent assessment required',
97
+ };
98
+ return undefined;
99
+ }
100
+ async select(child, seen) {
101
+ const outputs = [];
102
+ for (const [index, edge] of (child.prerequisites ?? []).entries()) {
103
+ const upstream = this.children.get(child.prerequisiteWorkItemIds?.[index] ?? '');
104
+ if (upstream === undefined)
105
+ return { code: Code.Unavailable, reason: 'Prerequisite target unavailable' };
106
+ const key = JSON.stringify([upstream.workItemId, edge.output, edge.condition]);
107
+ let pending = this.selected.get(key);
108
+ if (pending === undefined) {
109
+ pending = this.selectOne(upstream, edge, seen);
110
+ this.selected.set(key, pending);
111
+ }
112
+ const selected = await pending;
113
+ if ('code' in selected)
114
+ return selected;
115
+ if (edge.useAsBase) {
116
+ const reason = await this.baseReason(child, selected.reference);
117
+ if (reason !== undefined)
118
+ return reason;
119
+ }
120
+ outputs.push(selected);
121
+ }
122
+ return outputs;
123
+ }
124
+ baseReason(child, reference) {
125
+ if ('revision' in reference && reference.merged === true && this.receipts.has(child.workItemId))
126
+ return undefined;
127
+ const key = JSON.stringify([
128
+ this.owners.get(child.workItemId)?.parentWorkflowInstanceId,
129
+ reference,
130
+ ]);
131
+ let pending = this.bases.get(key);
132
+ if (pending === undefined) {
133
+ pending = this.verifyBase(child, reference);
134
+ this.bases.set(key, pending);
135
+ }
136
+ return pending;
137
+ }
138
+ async selectOne(upstream, edge, seen) {
139
+ const blocked = await this.block(upstream.workItemId, new Set(seen));
140
+ if (blocked !== undefined)
141
+ return blocked;
142
+ const workflow = this.workflows.get(upstream.workflowInstanceId);
143
+ if (workflow === undefined)
144
+ return { code: Code.Waiting, reason: `Waiting for upstream ${upstream.assignmentId}` };
145
+ const availability = await this.upstreamAvailability(workflow);
146
+ if (availability !== undefined)
147
+ return { code: Code.Waiting, reason: `Upstream ${upstream.assignmentId}: ${availability}` };
148
+ const statusReason = workflowReason(workflow, edge);
149
+ if (statusReason !== undefined)
150
+ return {
151
+ code: workflow.status === WorkflowStatus.Completed ||
152
+ workflow.status === WorkflowStatus.Superseded
153
+ ? Code.Failed
154
+ : Code.Waiting,
155
+ reason: statusReason,
156
+ };
157
+ const output = upstream.outputs.find((entry) => entry.name === edge.output);
158
+ const selected = await this.artifacts.prerequisiteOutput?.(workflow, output, edge.condition);
159
+ if (selected == null ||
160
+ selected.name !== edge.output ||
161
+ selected.reference.workItemId !== upstream.workItemId)
162
+ return {
163
+ code: Code.Waiting,
164
+ reason: `Waiting for ${edge.condition} output ${upstream.assignmentId}/${edge.output}`,
165
+ };
166
+ return selected;
167
+ }
168
+ async upstreamAvailability(workflow) {
169
+ const snapshot = this.work;
170
+ const item = snapshot.get(workflow.workItemId);
171
+ if (isSuccessfulWorkflowCompletion(workflow) &&
172
+ item?.state === WorkStatus.Closed &&
173
+ !item.frozen &&
174
+ !item.deleted) {
175
+ for (const ancestor of item.delegation?.ancestors ?? []) {
176
+ const reason = snapshot.availability(ancestor).reason;
177
+ if (reason !== undefined)
178
+ return reason;
179
+ }
180
+ return undefined;
181
+ }
182
+ return snapshot.availability(workflow.workItemId).reason;
183
+ }
184
+ async verifyBase(child, reference) {
185
+ const owner = this.owners.get(child.workItemId);
186
+ if (!('revision' in reference) || owner === undefined || this.repositories === undefined)
187
+ return { code: Code.Unavailable, reason: 'Upstream Git base resolver unavailable' };
188
+ const parent = this.workflows.get(owner.parentWorkflowInstanceId);
189
+ if (parent === undefined)
190
+ return { code: Code.Unavailable, reason: 'Upstream parent unavailable' };
191
+ const resolved = await this.repositories.resolve(parent, {
192
+ resourceId: reference.repositoryResourceId,
193
+ sourceRef: reference.branch,
194
+ pullRequestBase: reference.branch,
195
+ });
196
+ if (resolved.sourceRevision !== reference.revision)
197
+ return { code: Code.Changed, reason: 'Upstream branch moved; agent assessment required' };
198
+ return undefined;
199
+ }
200
+ }
201
+ function workflowReason(workflow, edge) {
202
+ if (workflow.status === WorkflowStatus.Completed && !isSuccessfulWorkflowCompletion(workflow))
203
+ return 'Upstream workflow failed';
204
+ if (edge.condition === Condition.DeliveryReady && !isSuccessfulWorkflowCompletion(workflow))
205
+ return 'Waiting for delivery-ready upstream';
206
+ if (workflow.status === WorkflowStatus.Superseded)
207
+ return 'Upstream workflow was superseded';
208
+ return undefined;
209
+ }
210
+ function freshness(outputs) {
211
+ return outputs.map(({ name, reference }) => {
212
+ if (!('runId' in reference))
213
+ return { name, reference };
214
+ const { runId: _run, baseRevision: _base, merged: _merged, pullRequestBase: _baseBranch, ...revision } = reference;
215
+ return { name, reference: revision };
216
+ });
217
+ }
@@ -1,9 +1,10 @@
1
1
  import type { CommandContext } from '@atolis-hq/eventing';
2
2
  import type { RepositoryAssignment } from '../../execution/index.js';
3
- import type { DelegatedAssignment, DelegationCaller, DelegationReservation, DelegationResult, DelegationRevisionReference, RepositoryAssignmentRequest } from './delegation.js';
3
+ import type { DelegatedAssignment, DelegationCaller, DelegationPrerequisite, DelegationReservation, DelegationResult, DelegationRevisionReference, RepositoryAssignmentRequest } from './delegation.js';
4
4
  import type { WorkflowInstanceView } from './views.js';
5
5
  /** Trusted Bootstrap adapters; no provider, Run or session authority is supplied by assignments. */
6
6
  export interface DelegationArtifacts {
7
+ prerequisiteOutput?(child: WorkflowInstanceView, output: DelegatedAssignment['outputs'][number], condition: DelegationPrerequisite['condition']): Promise<DelegationResult['outputs'][number] | null>;
7
8
  validateInputs(parent: WorkflowInstanceView, references: readonly DelegationRevisionReference[]): Promise<void>;
8
9
  registerChild(grant: {
9
10
  readonly delegationId: string;
@@ -1,6 +1,20 @@
1
1
  import { z } from 'zod';
2
2
  import { activationId } from '../../activities/index.js';
3
3
  import { workflowInstanceId } from './identifiers.js';
4
+ import { type DelegationAttentionRejection, type DelegationConflictCode } from './vocabulary.js';
5
+ export declare const delegationPrerequisiteSchema: z.ZodObject<{
6
+ cohortId: z.ZodOptional<z.ZodString>;
7
+ assignmentId: z.ZodString;
8
+ output: z.ZodString;
9
+ condition: z.ZodEnum<{
10
+ readonly AcceptedOutput: "accepted-output";
11
+ readonly PushedChange: "pushed-change";
12
+ readonly DeliveryReady: "delivery-ready";
13
+ readonly MergedChange: "merged-change";
14
+ }>;
15
+ useAsBase: z.ZodOptional<z.ZodBoolean>;
16
+ }, z.core.$strict>;
17
+ export type DelegationPrerequisite = z.infer<typeof delegationPrerequisiteSchema>;
4
18
  export declare const delegationRevisionReferenceSchema: z.ZodObject<{
5
19
  workItemId: z.ZodPipe<z.ZodString, z.ZodTransform<import("../../work/index.js").WorkItemId, string>>;
6
20
  revisionId: z.ZodString;
@@ -30,6 +44,18 @@ export declare const delegatedAssignmentSchema: z.ZodObject<{
30
44
  sourceRevision: z.ZodOptional<z.ZodString>;
31
45
  pullRequestBase: z.ZodString;
32
46
  }, z.core.$strict>>;
47
+ prerequisites: z.ZodOptional<z.ZodArray<z.ZodObject<{
48
+ cohortId: z.ZodOptional<z.ZodString>;
49
+ assignmentId: z.ZodString;
50
+ output: z.ZodString;
51
+ condition: z.ZodEnum<{
52
+ readonly AcceptedOutput: "accepted-output";
53
+ readonly PushedChange: "pushed-change";
54
+ readonly DeliveryReady: "delivery-ready";
55
+ readonly MergedChange: "merged-change";
56
+ }>;
57
+ useAsBase: z.ZodOptional<z.ZodBoolean>;
58
+ }, z.core.$strict>>>;
33
59
  outputs: z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
34
60
  name: z.ZodString;
35
61
  path: z.ZodString;
@@ -42,6 +68,7 @@ export declare const delegatedAssignmentSchema: z.ZodObject<{
42
68
  }, z.core.$strict>;
43
69
  export declare const delegationSubmissionSchema: z.ZodObject<{
44
70
  cohortId: z.ZodString;
71
+ expectedPlanRevision: z.ZodOptional<z.ZodNumber>;
45
72
  assignments: z.ZodArray<z.ZodObject<{
46
73
  objective: z.ZodString;
47
74
  repository: z.ZodOptional<z.ZodObject<{
@@ -58,6 +85,18 @@ export declare const delegationSubmissionSchema: z.ZodObject<{
58
85
  criteria: z.ZodArray<z.ZodString>;
59
86
  workflowName: z.ZodPipe<z.ZodString, z.ZodTransform<import("./identifiers.js").WorkflowName, string>>;
60
87
  repositoryResourceIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
88
+ prerequisites: z.ZodOptional<z.ZodArray<z.ZodObject<{
89
+ cohortId: z.ZodOptional<z.ZodString>;
90
+ assignmentId: z.ZodString;
91
+ output: z.ZodString;
92
+ condition: z.ZodEnum<{
93
+ readonly AcceptedOutput: "accepted-output";
94
+ readonly PushedChange: "pushed-change";
95
+ readonly DeliveryReady: "delivery-ready";
96
+ readonly MergedChange: "merged-change";
97
+ }>;
98
+ useAsBase: z.ZodOptional<z.ZodBoolean>;
99
+ }, z.core.$strict>>>;
61
100
  outputs: z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
62
101
  name: z.ZodString;
63
102
  path: z.ZodString;
@@ -73,6 +112,7 @@ export type DelegationSubmission = z.infer<typeof delegationSubmissionSchema>;
73
112
  export type DelegatedAssignment = z.infer<typeof delegatedAssignmentSchema>;
74
113
  export declare const delegationReservationSchema: z.ZodObject<{
75
114
  cohortId: z.ZodString;
115
+ planRevision: z.ZodOptional<z.ZodNumber>;
76
116
  parentWorkflowInstanceId: z.ZodPipe<z.ZodString, z.ZodTransform<import("./identifiers.js").WorkflowInstanceId, string>>;
77
117
  parentWorkItemId: z.ZodPipe<z.ZodString, z.ZodTransform<import("../../work/index.js").WorkItemId, string>>;
78
118
  rootWorkItemId: z.ZodPipe<z.ZodString, z.ZodTransform<import("../../work/index.js").WorkItemId, string>>;
@@ -93,6 +133,18 @@ export declare const delegationReservationSchema: z.ZodObject<{
93
133
  workItemId: z.ZodPipe<z.ZodString, z.ZodTransform<import("../../work/index.js").WorkItemId, string>>;
94
134
  revisionId: z.ZodString;
95
135
  }, z.core.$strict>>;
136
+ prerequisites: z.ZodOptional<z.ZodArray<z.ZodObject<{
137
+ cohortId: z.ZodOptional<z.ZodString>;
138
+ assignmentId: z.ZodString;
139
+ output: z.ZodString;
140
+ condition: z.ZodEnum<{
141
+ readonly AcceptedOutput: "accepted-output";
142
+ readonly PushedChange: "pushed-change";
143
+ readonly DeliveryReady: "delivery-ready";
144
+ readonly MergedChange: "merged-change";
145
+ }>;
146
+ useAsBase: z.ZodOptional<z.ZodBoolean>;
147
+ }, z.core.$strict>>>;
96
148
  outputs: z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
97
149
  name: z.ZodString;
98
150
  path: z.ZodString;
@@ -111,6 +163,7 @@ export declare const delegationReservationSchema: z.ZodObject<{
111
163
  workItemId: z.ZodPipe<z.ZodString, z.ZodTransform<import("../../work/index.js").WorkItemId, string>>;
112
164
  workflowInstanceId: z.ZodPipe<z.ZodString, z.ZodTransform<import("./identifiers.js").WorkflowInstanceId, string>>;
113
165
  grantId: z.ZodString;
166
+ prerequisiteWorkItemIds: z.ZodOptional<z.ZodArray<z.ZodPipe<z.ZodString, z.ZodTransform<import("../../work/index.js").WorkItemId, string>>>>;
114
167
  }, z.core.$strict>>;
115
168
  }, z.core.$strict>;
116
169
  export type DelegationReservation = z.infer<typeof delegationReservationSchema>;
@@ -130,10 +183,105 @@ export declare const delegationResultSchema: z.ZodObject<{
130
183
  branch: z.ZodString;
131
184
  pullRequestBase: z.ZodString;
132
185
  runId: z.ZodString;
186
+ baseRevision: z.ZodOptional<z.ZodString>;
187
+ merged: z.ZodOptional<z.ZodLiteral<true>>;
133
188
  }, z.core.$strict>]>;
134
189
  }, z.core.$strict>>;
135
190
  }, z.core.$strict>;
136
191
  export type DelegationResult = z.infer<typeof delegationResultSchema>;
192
+ export declare const delegationInputsSchema: z.ZodObject<{
193
+ childWorkItemId: z.ZodPipe<z.ZodString, z.ZodTransform<import("../../work/index.js").WorkItemId, string>>;
194
+ consumed: z.ZodArray<z.ZodObject<{
195
+ name: z.ZodString;
196
+ reference: z.ZodUnion<readonly [z.ZodObject<{
197
+ workItemId: z.ZodPipe<z.ZodString, z.ZodTransform<import("../../work/index.js").WorkItemId, string>>;
198
+ revisionId: z.ZodString;
199
+ }, z.core.$strict>, z.ZodObject<{
200
+ workItemId: z.ZodPipe<z.ZodString, z.ZodTransform<import("../../work/index.js").WorkItemId, string>>;
201
+ resourceId: z.ZodString;
202
+ repositoryResourceId: z.ZodString;
203
+ revision: z.ZodString;
204
+ branch: z.ZodString;
205
+ pullRequestBase: z.ZodString;
206
+ runId: z.ZodString;
207
+ baseRevision: z.ZodOptional<z.ZodString>;
208
+ merged: z.ZodOptional<z.ZodLiteral<true>>;
209
+ }, z.core.$strict>]>;
210
+ }, z.core.$strict>>;
211
+ repository: z.ZodOptional<z.ZodObject<{
212
+ resourceId: z.ZodString;
213
+ sourceRef: z.ZodString;
214
+ pullRequestBase: z.ZodString;
215
+ sourceRevision: z.ZodString;
216
+ }, z.core.$strict>>;
217
+ }, z.core.$strict>;
218
+ export type DelegationInputs = z.infer<typeof delegationInputsSchema>;
219
+ export declare class DelegationConflictError extends Error {
220
+ readonly code: DelegationConflictCode;
221
+ constructor(code: DelegationConflictCode, message: string);
222
+ }
223
+ export declare const delegationAttentionBlockerSchema: z.ZodObject<{
224
+ blockerId: z.ZodString;
225
+ childWorkItemId: z.ZodPipe<z.ZodString, z.ZodTransform<import("../../work/index.js").WorkItemId, string>>;
226
+ kind: z.ZodEnum<{
227
+ readonly Failed: "failed";
228
+ readonly Context: "assignment-context";
229
+ }>;
230
+ reason: z.ZodString;
231
+ }, z.core.$strict>;
232
+ export type DelegationAttentionBlocker = z.infer<typeof delegationAttentionBlockerSchema>;
233
+ /** One coalesced assessment of the unresolved reasons, keyed by cohort revision and blockers. */
234
+ export declare const delegationAttentionRequestSchema: z.ZodObject<{
235
+ cohortId: z.ZodString;
236
+ attentionKey: z.ZodString;
237
+ activationId: z.ZodPipe<z.ZodString, z.ZodTransform<import("../../activities/index.js").ActivationId, string>>;
238
+ revision: z.ZodNumber;
239
+ blockers: z.ZodArray<z.ZodObject<{
240
+ blockerId: z.ZodString;
241
+ childWorkItemId: z.ZodPipe<z.ZodString, z.ZodTransform<import("../../work/index.js").WorkItemId, string>>;
242
+ kind: z.ZodEnum<{
243
+ readonly Failed: "failed";
244
+ readonly Context: "assignment-context";
245
+ }>;
246
+ reason: z.ZodString;
247
+ }, z.core.$strict>>;
248
+ }, z.core.$strict>;
249
+ export type DelegationAttentionRequest = z.infer<typeof delegationAttentionRequestSchema>;
250
+ /** Names the child, blocker and assignment revision; context references are exact revisions. */
251
+ export declare const delegationAttentionReplySchema: z.ZodObject<{
252
+ childWorkItemId: z.ZodPipe<z.ZodString, z.ZodTransform<import("../../work/index.js").WorkItemId, string>>;
253
+ blockerId: z.ZodString;
254
+ expectedRevision: z.ZodNumber;
255
+ references: z.ZodArray<z.ZodObject<{
256
+ workItemId: z.ZodPipe<z.ZodString, z.ZodTransform<import("../../work/index.js").WorkItemId, string>>;
257
+ revisionId: z.ZodString;
258
+ }, z.core.$strict>>;
259
+ }, z.core.$strict>;
260
+ export type DelegationAttentionReply = z.infer<typeof delegationAttentionReplySchema>;
261
+ export declare const delegationAttentionResponseSchema: z.ZodObject<{
262
+ childWorkItemId: z.ZodPipe<z.ZodString, z.ZodTransform<import("../../work/index.js").WorkItemId, string>>;
263
+ blockerId: z.ZodString;
264
+ expectedRevision: z.ZodNumber;
265
+ references: z.ZodArray<z.ZodObject<{
266
+ workItemId: z.ZodPipe<z.ZodString, z.ZodTransform<import("../../work/index.js").WorkItemId, string>>;
267
+ revisionId: z.ZodString;
268
+ }, z.core.$strict>>;
269
+ cohortId: z.ZodString;
270
+ attentionKey: z.ZodString;
271
+ }, z.core.$strict>;
272
+ export type DelegationAttentionResponse = z.infer<typeof delegationAttentionResponseSchema>;
273
+ export declare const delegationAttentionResolvedSchema: z.ZodObject<{
274
+ cohortId: z.ZodString;
275
+ attentionKey: z.ZodString;
276
+ activationId: z.ZodPipe<z.ZodString, z.ZodTransform<import("../../activities/index.js").ActivationId, string>>;
277
+ escalation: z.ZodOptional<z.ZodString>;
278
+ assessmentFailure: z.ZodOptional<z.ZodString>;
279
+ }, z.core.$strict>;
280
+ /** Rejected replies never resume work; the code names the boundary that refused them. */
281
+ export declare class DelegationAttentionError extends Error {
282
+ readonly code: DelegationAttentionRejection;
283
+ constructor(code: DelegationAttentionRejection, message: string);
284
+ }
137
285
  export declare const delegationWaitSchema: z.ZodObject<{
138
286
  cohortId: z.ZodString;
139
287
  activationId: z.ZodPipe<z.ZodString, z.ZodTransform<import("../../activities/index.js").ActivationId, string>>;
@@ -156,6 +304,8 @@ export declare const delegationJoinSchema: z.ZodObject<{
156
304
  branch: z.ZodString;
157
305
  pullRequestBase: z.ZodString;
158
306
  runId: z.ZodString;
307
+ baseRevision: z.ZodOptional<z.ZodString>;
308
+ merged: z.ZodOptional<z.ZodLiteral<true>>;
159
309
  }, z.core.$strict>]>;
160
310
  }, z.core.$strict>>;
161
311
  }, z.core.$strict>>;
@@ -3,7 +3,16 @@ import { activationId } from '../../activities/index.js';
3
3
  import { brandedStringSchema } from '../../kernel/index.js';
4
4
  import { workItemId } from '../../work/index.js';
5
5
  import { workflowInstanceId, workflowName } from './identifiers.js';
6
- import { DelegationOutputKind } from './vocabulary.js';
6
+ import { DelegationBlockerKind, DelegationOutputKind, DelegationPrerequisiteCondition, } from './vocabulary.js';
7
+ export const delegationPrerequisiteSchema = z
8
+ .object({
9
+ cohortId: z.string().min(1).optional(),
10
+ assignmentId: z.string().min(1),
11
+ output: z.string().min(1),
12
+ condition: z.enum(DelegationPrerequisiteCondition),
13
+ useAsBase: z.boolean().optional(),
14
+ })
15
+ .strict();
7
16
  export const delegationRevisionReferenceSchema = z
8
17
  .object({
9
18
  workItemId: brandedStringSchema(workItemId),
@@ -31,6 +40,7 @@ export const delegatedAssignmentSchema = z
31
40
  workflowFingerprint: z.string().min(1),
32
41
  context: z.array(delegationRevisionReferenceSchema),
33
42
  repository: repositoryAssignmentRequestSchema.optional(),
43
+ prerequisites: z.array(delegationPrerequisiteSchema).optional(),
34
44
  outputs: z
35
45
  .array(z.union([
36
46
  z.object({ name: z.string().min(1), path: z.string().min(1) }).strict(),
@@ -49,12 +59,14 @@ export const delegatedAssignmentSchema = z
49
59
  export const delegationSubmissionSchema = z
50
60
  .object({
51
61
  cohortId: z.string().min(1),
62
+ expectedPlanRevision: z.number().int().nonnegative().optional(),
52
63
  assignments: z.array(delegatedAssignmentSchema.omit({ workflowFingerprint: true })).min(1),
53
64
  })
54
65
  .strict();
55
66
  export const delegationReservationSchema = z
56
67
  .object({
57
68
  cohortId: z.string().min(1),
69
+ planRevision: z.number().int().positive().optional(),
58
70
  parentWorkflowInstanceId: brandedStringSchema(workflowInstanceId),
59
71
  parentWorkItemId: brandedStringSchema(workItemId),
60
72
  rootWorkItemId: brandedStringSchema(workItemId),
@@ -76,6 +88,7 @@ export const delegationReservationSchema = z
76
88
  workItemId: brandedStringSchema(workItemId),
77
89
  workflowInstanceId: brandedStringSchema(workflowInstanceId),
78
90
  grantId: z.string().min(1),
91
+ prerequisiteWorkItemIds: z.array(brandedStringSchema(workItemId)).optional(),
79
92
  })
80
93
  .strict())
81
94
  .min(1),
@@ -100,6 +113,8 @@ export const delegationResultSchema = z
100
113
  branch: z.string().min(1),
101
114
  pullRequestBase: z.string().min(1),
102
115
  runId: z.string().min(1),
116
+ baseRevision: z.string().min(1).optional(),
117
+ merged: z.literal(true).optional(),
103
118
  })
104
119
  .strict(),
105
120
  ]),
@@ -108,6 +123,74 @@ export const delegationResultSchema = z
108
123
  .min(1),
109
124
  })
110
125
  .strict();
126
+ export const delegationInputsSchema = z
127
+ .object({
128
+ childWorkItemId: brandedStringSchema(workItemId),
129
+ consumed: z.array(delegationResultSchema.shape.outputs.element),
130
+ repository: repositoryAssignmentRequestSchema
131
+ .extend({
132
+ sourceRevision: z.string().regex(/^(?:[a-f0-9]{40}|[a-f0-9]{64})$/i),
133
+ })
134
+ .strict()
135
+ .optional(),
136
+ })
137
+ .strict();
138
+ export class DelegationConflictError extends Error {
139
+ code;
140
+ constructor(code, message) {
141
+ super(message);
142
+ this.code = code;
143
+ this.name = 'DelegationConflictError';
144
+ }
145
+ }
146
+ export const delegationAttentionBlockerSchema = z
147
+ .object({
148
+ blockerId: z.string().min(1),
149
+ childWorkItemId: brandedStringSchema(workItemId),
150
+ kind: z.enum(DelegationBlockerKind),
151
+ reason: z.string().min(1),
152
+ })
153
+ .strict();
154
+ /** One coalesced assessment of the unresolved reasons, keyed by cohort revision and blockers. */
155
+ export const delegationAttentionRequestSchema = z
156
+ .object({
157
+ cohortId: z.string().min(1),
158
+ attentionKey: z.string().min(1),
159
+ activationId: brandedStringSchema(activationId),
160
+ revision: z.number().int().positive(),
161
+ blockers: z.array(delegationAttentionBlockerSchema).min(1),
162
+ })
163
+ .strict();
164
+ /** Names the child, blocker and assignment revision; context references are exact revisions. */
165
+ export const delegationAttentionReplySchema = z
166
+ .object({
167
+ childWorkItemId: brandedStringSchema(workItemId),
168
+ blockerId: z.string().min(1),
169
+ expectedRevision: z.number().int().positive(),
170
+ references: z.array(delegationRevisionReferenceSchema),
171
+ })
172
+ .strict();
173
+ export const delegationAttentionResponseSchema = delegationAttentionReplySchema
174
+ .extend({ cohortId: z.string().min(1), attentionKey: z.string().min(1) })
175
+ .strict();
176
+ export const delegationAttentionResolvedSchema = z
177
+ .object({
178
+ cohortId: z.string().min(1),
179
+ attentionKey: z.string().min(1),
180
+ activationId: brandedStringSchema(activationId),
181
+ escalation: z.string().min(1).optional(),
182
+ assessmentFailure: z.string().min(1).optional(),
183
+ })
184
+ .strict();
185
+ /** Rejected replies never resume work; the code names the boundary that refused them. */
186
+ export class DelegationAttentionError extends Error {
187
+ code;
188
+ constructor(code, message) {
189
+ super(message);
190
+ this.code = code;
191
+ this.name = 'DelegationAttentionError';
192
+ }
193
+ }
111
194
  export const delegationWaitSchema = z
112
195
  .object({ cohortId: z.string().min(1), activationId: brandedStringSchema(activationId) })
113
196
  .strict();
@@ -1,6 +1,6 @@
1
1
  /* eslint-disable max-lines */
2
2
  import { z } from 'zod';
3
- import { delegationJoinSchema, delegationReservationSchema, delegationResultSchema, delegationWaitSchema, } from './delegation.js';
3
+ import { delegationAttentionRequestSchema, delegationAttentionResolvedSchema, delegationAttentionResponseSchema, delegationInputsSchema, delegationJoinSchema, delegationReservationSchema, delegationResultSchema, delegationWaitSchema, } from './delegation.js';
4
4
  import { eventDataSchema, eventEnvelopeSchema } from '@atolis-hq/eventing';
5
5
  import { activationId, ActivityEventType, activityName, ActivityOutcomeKind, PullRequestCheckState, PullRequestMergeability, PullRequestState, } from '../../activities/index.js';
6
6
  import { WorkspaceMode } from '../../execution/index.js';
@@ -216,6 +216,16 @@ const groupBudgetGrantedEnvelope = childGroupEnvelope(OrchestrationEventType.Gro
216
216
  });
217
217
  });
218
218
  const eventSchemas = {
219
+ [OrchestrationEventType.DelegationChildBlocked]: workflowEnvelope(OrchestrationEventType.DelegationChildBlocked, z
220
+ .object({ childWorkItemId: brandedStringSchema(workItemId), reason: z.string().min(1) })
221
+ .strict()),
222
+ [OrchestrationEventType.DelegationInputsResolved]: workflowEnvelope(OrchestrationEventType.DelegationInputsResolved, delegationInputsSchema),
223
+ [OrchestrationEventType.DelegationPrerequisiteBlocked]: workflowEnvelope(OrchestrationEventType.DelegationPrerequisiteBlocked, z
224
+ .object({ childWorkItemId: brandedStringSchema(workItemId), reason: z.string().min(1) })
225
+ .strict()),
226
+ [OrchestrationEventType.DelegationAttentionRequested]: workflowEnvelope(OrchestrationEventType.DelegationAttentionRequested, delegationAttentionRequestSchema),
227
+ [OrchestrationEventType.DelegationAttentionResponded]: workflowEnvelope(OrchestrationEventType.DelegationAttentionResponded, delegationAttentionResponseSchema),
228
+ [OrchestrationEventType.DelegationAttentionResolved]: workflowEnvelope(OrchestrationEventType.DelegationAttentionResolved, delegationAttentionResolvedSchema),
219
229
  [OrchestrationEventType.DelegationFailed]: workflowEnvelope(OrchestrationEventType.DelegationFailed, z.object({ cohortId: z.string().min(1), reason: z.string().min(1) }).strict()),
220
230
  [OrchestrationEventType.DelegationReconciliationFailed]: workflowEnvelope(OrchestrationEventType.DelegationReconciliationFailed, z.object({ cohortId: z.string().min(1), reason: z.string().min(1) }).strict()),
221
231
  [OrchestrationEventType.DelegationReserved]: workflowEnvelope(OrchestrationEventType.DelegationReserved, delegationReservationSchema),
@@ -1,13 +1,23 @@
1
1
  import { createEventData } from '@atolis-hq/eventing';
2
2
  import { OrchestrationEventType, } from './events.js';
3
3
  // Exhaustive dispatch preserves the closed event-to-payload mapping.
4
- // eslint-disable-next-line complexity
4
+ // eslint-disable-next-line complexity, max-lines-per-function
5
5
  export function createOrchestrationEventData(input) {
6
6
  switch (input.eventType) {
7
- case OrchestrationEventType.DelegationFailed:
7
+ case OrchestrationEventType.DelegationInputsResolved:
8
+ return createEventData(input);
9
+ case OrchestrationEventType.DelegationPrerequisiteBlocked:
10
+ case OrchestrationEventType.DelegationChildBlocked:
8
11
  return createEventData(input);
12
+ case OrchestrationEventType.DelegationFailed:
9
13
  case OrchestrationEventType.DelegationReconciliationFailed:
10
14
  return createEventData(input);
15
+ case OrchestrationEventType.DelegationAttentionRequested:
16
+ return createEventData(input);
17
+ case OrchestrationEventType.DelegationAttentionResponded:
18
+ return createEventData(input);
19
+ case OrchestrationEventType.DelegationAttentionResolved:
20
+ return createEventData(input);
11
21
  case OrchestrationEventType.DelegationReserved:
12
22
  return createEventData(input);
13
23
  case OrchestrationEventType.DelegationRegistered:
@@ -61,11 +71,8 @@ export function createOrchestrationEventData(input) {
61
71
  case OrchestrationEventType.ChildRequested:
62
72
  return createEventData(input);
63
73
  case OrchestrationEventType.ChildStarted:
64
- return createEventData(input);
65
74
  case OrchestrationEventType.ChildCompleted:
66
- return createEventData(input);
67
75
  case OrchestrationEventType.ChildCompletionConsumed:
68
- return createEventData(input);
69
76
  case OrchestrationEventType.CausalActivationRejected:
70
77
  return createEventData(input);
71
78
  case OrchestrationEventType.GroupBudgetExhausted: