@atolis-hq/wake 0.4.102 → 0.4.103
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/activities/pr/policy.d.ts +2 -0
- package/dist/src/activities/pr/policy.js +9 -1
- package/dist/src/bootstrap/surface-api-delivery.js +6 -2
- package/dist/src/bootstrap/version.js +1 -1
- package/dist/src/integrations/application/delegation-outputs.js +41 -5
- package/dist/src/orchestration/application/delegated-work.d.ts +46 -2
- package/dist/src/orchestration/application/delegated-work.js +135 -21
- package/dist/src/orchestration/application/delegation-commands.d.ts +47 -0
- package/dist/src/orchestration/application/delegation-commands.js +4 -2
- package/dist/src/orchestration/application/delegation-gate.d.ts +5 -3
- package/dist/src/orchestration/application/delegation-gate.js +31 -9
- package/dist/src/orchestration/application/delegation-ledger.d.ts +2 -0
- package/dist/src/orchestration/application/delegation-ledger.js +8 -0
- package/dist/src/orchestration/application/delegation-prerequisites.d.ts +28 -0
- package/dist/src/orchestration/application/delegation-prerequisites.js +118 -0
- package/dist/src/orchestration/application/delegation-reservation.js +1 -1
- package/dist/src/orchestration/application/delegation-wait-graph.d.ts +7 -0
- package/dist/src/orchestration/application/delegation-wait-graph.js +122 -0
- package/dist/src/orchestration/application/orchestration-repository.d.ts +5 -0
- package/dist/src/orchestration/application/orchestration-repository.js +3 -0
- package/dist/src/orchestration/application/orchestration-service.d.ts +87 -0
- package/dist/src/orchestration/application/orchestration-service.js +3 -2
- package/dist/src/orchestration/application/prerequisite-readiness.d.ts +68 -0
- package/dist/src/orchestration/application/prerequisite-readiness.js +217 -0
- package/dist/src/orchestration/contracts/delegation-ports.d.ts +2 -1
- package/dist/src/orchestration/contracts/delegation.d.ts +88 -0
- package/dist/src/orchestration/contracts/delegation.js +36 -1
- package/dist/src/orchestration/contracts/event-decoder.js +8 -1
- package/dist/src/orchestration/contracts/event-factory.js +5 -4
- package/dist/src/orchestration/contracts/events.d.ts +13 -1
- package/dist/src/orchestration/contracts/events.js +3 -0
- package/dist/src/orchestration/contracts/vocabulary.d.ts +27 -0
- package/dist/src/orchestration/contracts/vocabulary.js +25 -0
- package/dist/src/orchestration/domain/workflow-instance-events.js +3 -0
- package/dist/src/orchestration/index.d.ts +2 -2
- package/dist/src/orchestration/index.js +1 -1
- package/dist/src/surfaces/mcp/delegation.js +18 -10
- package/package.json +1 -1
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { DeliverySnapshot } from '../../work/index.js';
|
|
2
|
+
import type { DelegationArtifacts, DelegationRepositories } from '../contracts/delegation-ports.js';
|
|
3
|
+
import type { DelegationInputs, DelegationReservation } from '../contracts/delegation.js';
|
|
4
|
+
import type { WorkflowInstanceView } from '../contracts/views.js';
|
|
5
|
+
import { PrerequisiteBlockCode as Code } from '../contracts/vocabulary.js';
|
|
6
|
+
import type { OrchestrationRepository } from './orchestration-repository.js';
|
|
7
|
+
type Child = DelegationReservation['children'][number];
|
|
8
|
+
export interface PrerequisiteAdmission {
|
|
9
|
+
readonly reason: string | undefined;
|
|
10
|
+
readonly abandoned: boolean;
|
|
11
|
+
}
|
|
12
|
+
export interface PrerequisiteBlock {
|
|
13
|
+
readonly code: Code;
|
|
14
|
+
readonly reason: string;
|
|
15
|
+
}
|
|
16
|
+
/** A bounded read pass: one journal/Work snapshot and one lookup per declared input. */
|
|
17
|
+
export declare class PrerequisiteReadiness {
|
|
18
|
+
private readonly work;
|
|
19
|
+
private readonly artifacts;
|
|
20
|
+
private readonly repositories;
|
|
21
|
+
private readonly failedChildren;
|
|
22
|
+
private readonly children;
|
|
23
|
+
private readonly owners;
|
|
24
|
+
private readonly receipts;
|
|
25
|
+
private readonly workflows;
|
|
26
|
+
private readonly blockers;
|
|
27
|
+
private readonly evaluated;
|
|
28
|
+
private readonly selected;
|
|
29
|
+
private readonly bases;
|
|
30
|
+
constructor(snapshot: Awaited<ReturnType<OrchestrationRepository['snapshot']>>, work: DeliverySnapshot, artifacts: DelegationArtifacts, repositories: DelegationRepositories | undefined);
|
|
31
|
+
abandoned(id: string): boolean;
|
|
32
|
+
inputs(id: string): {
|
|
33
|
+
childWorkItemId: import("../../work/index.js").WorkItemId;
|
|
34
|
+
consumed: {
|
|
35
|
+
name: string;
|
|
36
|
+
reference: {
|
|
37
|
+
workItemId: import("../../work/index.js").WorkItemId;
|
|
38
|
+
revisionId: string;
|
|
39
|
+
} | {
|
|
40
|
+
workItemId: import("../../work/index.js").WorkItemId;
|
|
41
|
+
resourceId: string;
|
|
42
|
+
repositoryResourceId: string;
|
|
43
|
+
revision: string;
|
|
44
|
+
branch: string;
|
|
45
|
+
pullRequestBase: string;
|
|
46
|
+
runId: string;
|
|
47
|
+
baseRevision?: string | undefined;
|
|
48
|
+
merged?: true | undefined;
|
|
49
|
+
};
|
|
50
|
+
}[];
|
|
51
|
+
repository?: {
|
|
52
|
+
resourceId: string;
|
|
53
|
+
sourceRef: string;
|
|
54
|
+
pullRequestBase: string;
|
|
55
|
+
sourceRevision: string;
|
|
56
|
+
} | undefined;
|
|
57
|
+
} | undefined;
|
|
58
|
+
workflow(id: string): WorkflowInstanceView | undefined;
|
|
59
|
+
reason(id: string): Promise<string | undefined>;
|
|
60
|
+
block(id: string, seen?: Set<string>): Promise<PrerequisiteBlock | undefined>;
|
|
61
|
+
private evaluate;
|
|
62
|
+
select(child: Child, seen: Set<string>): Promise<DelegationInputs['consumed'] | PrerequisiteBlock>;
|
|
63
|
+
private baseReason;
|
|
64
|
+
private selectOne;
|
|
65
|
+
private upstreamAvailability;
|
|
66
|
+
private verifyBase;
|
|
67
|
+
}
|
|
68
|
+
export {};
|
|
@@ -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 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,43 @@ 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
|
+
}
|
|
137
223
|
export declare const delegationWaitSchema: z.ZodObject<{
|
|
138
224
|
cohortId: z.ZodString;
|
|
139
225
|
activationId: z.ZodPipe<z.ZodString, z.ZodTransform<import("../../activities/index.js").ActivationId, string>>;
|
|
@@ -156,6 +242,8 @@ export declare const delegationJoinSchema: z.ZodObject<{
|
|
|
156
242
|
branch: z.ZodString;
|
|
157
243
|
pullRequestBase: z.ZodString;
|
|
158
244
|
runId: z.ZodString;
|
|
245
|
+
baseRevision: z.ZodOptional<z.ZodString>;
|
|
246
|
+
merged: z.ZodOptional<z.ZodLiteral<true>>;
|
|
159
247
|
}, z.core.$strict>]>;
|
|
160
248
|
}, z.core.$strict>>;
|
|
161
249
|
}, 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 { 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,26 @@ 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
|
+
}
|
|
111
146
|
export const delegationWaitSchema = z
|
|
112
147
|
.object({ cohortId: z.string().min(1), activationId: brandedStringSchema(activationId) })
|
|
113
148
|
.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 { 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,13 @@ 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()),
|
|
219
226
|
[OrchestrationEventType.DelegationFailed]: workflowEnvelope(OrchestrationEventType.DelegationFailed, z.object({ cohortId: z.string().min(1), reason: z.string().min(1) }).strict()),
|
|
220
227
|
[OrchestrationEventType.DelegationReconciliationFailed]: workflowEnvelope(OrchestrationEventType.DelegationReconciliationFailed, z.object({ cohortId: z.string().min(1), reason: z.string().min(1) }).strict()),
|
|
221
228
|
[OrchestrationEventType.DelegationReserved]: workflowEnvelope(OrchestrationEventType.DelegationReserved, delegationReservationSchema),
|
|
@@ -4,8 +4,12 @@ import { OrchestrationEventType, } from './events.js';
|
|
|
4
4
|
// eslint-disable-next-line complexity
|
|
5
5
|
export function createOrchestrationEventData(input) {
|
|
6
6
|
switch (input.eventType) {
|
|
7
|
-
case OrchestrationEventType.
|
|
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);
|
|
11
15
|
case OrchestrationEventType.DelegationReserved:
|
|
@@ -61,11 +65,8 @@ export function createOrchestrationEventData(input) {
|
|
|
61
65
|
case OrchestrationEventType.ChildRequested:
|
|
62
66
|
return createEventData(input);
|
|
63
67
|
case OrchestrationEventType.ChildStarted:
|
|
64
|
-
return createEventData(input);
|
|
65
68
|
case OrchestrationEventType.ChildCompleted:
|
|
66
|
-
return createEventData(input);
|
|
67
69
|
case OrchestrationEventType.ChildCompletionConsumed:
|
|
68
|
-
return createEventData(input);
|
|
69
70
|
case OrchestrationEventType.CausalActivationRejected:
|
|
70
71
|
return createEventData(input);
|
|
71
72
|
case OrchestrationEventType.GroupBudgetExhausted:
|
|
@@ -3,11 +3,14 @@ import type { ActivationId, ActivityName, ActivityOutcome, ActivityOutcomeKind }
|
|
|
3
3
|
import type { WorkItemId } from '../../work/index.js';
|
|
4
4
|
import type { OrchestrationWaitingActivityOutcome } from './activity-outcome.js';
|
|
5
5
|
import type { ApprovalAuthority, CompiledResourceTransition, CompiledWorkflow, StageConfig, TransitionTarget } from './config.js';
|
|
6
|
-
import type { DelegationReservation, DelegationResult } from './delegation.js';
|
|
6
|
+
import type { DelegationInputs, DelegationReservation, DelegationResult } from './delegation.js';
|
|
7
7
|
import type { CommandName, OrchestrationGroupId, SignalName, StageName, WorkflowInstanceId, WorkflowName } from './identifiers.js';
|
|
8
8
|
import type { ChildOrchestrationGroupStreamId, ChildOrchestrationGroupStreamRef, PrimaryOrchestrationGroupStreamRef, WorkflowDefinitionsStreamRef, WorkflowInstanceStreamRef } from './streams.js';
|
|
9
9
|
export declare const OrchestrationEventType: {
|
|
10
10
|
readonly DelegationReserved: "orchestration.delegation-reserved";
|
|
11
|
+
readonly DelegationInputsResolved: "orchestration.delegation-inputs-resolved";
|
|
12
|
+
readonly DelegationChildBlocked: "orchestration.delegation-child-blocked";
|
|
13
|
+
readonly DelegationPrerequisiteBlocked: "orchestration.delegation-prerequisite-blocked";
|
|
11
14
|
readonly DelegationRegistered: "orchestration.delegation-registered";
|
|
12
15
|
readonly DelegationResultSelected: "orchestration.delegation-result-selected";
|
|
13
16
|
readonly DelegationWaitStarted: "orchestration.delegation-wait-started";
|
|
@@ -53,6 +56,15 @@ export interface DeferredWorkflowSignal {
|
|
|
53
56
|
readonly target?: TransitionTarget;
|
|
54
57
|
}
|
|
55
58
|
export interface OrchestrationEventPayloads {
|
|
59
|
+
readonly [OrchestrationEventType.DelegationChildBlocked]: {
|
|
60
|
+
readonly childWorkItemId: WorkItemId;
|
|
61
|
+
readonly reason: string;
|
|
62
|
+
};
|
|
63
|
+
readonly [OrchestrationEventType.DelegationInputsResolved]: DelegationInputs;
|
|
64
|
+
readonly [OrchestrationEventType.DelegationPrerequisiteBlocked]: {
|
|
65
|
+
readonly childWorkItemId: WorkItemId;
|
|
66
|
+
readonly reason: string;
|
|
67
|
+
};
|
|
56
68
|
readonly [OrchestrationEventType.SignalDeferred]: DeferredWorkflowSignal;
|
|
57
69
|
readonly [OrchestrationEventType.DelegationFailed]: {
|
|
58
70
|
readonly cohortId: string;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { signalName } from './identifiers.js';
|
|
2
2
|
export const OrchestrationEventType = {
|
|
3
3
|
DelegationReserved: 'orchestration.delegation-reserved',
|
|
4
|
+
DelegationInputsResolved: 'orchestration.delegation-inputs-resolved',
|
|
5
|
+
DelegationChildBlocked: 'orchestration.delegation-child-blocked',
|
|
6
|
+
DelegationPrerequisiteBlocked: 'orchestration.delegation-prerequisite-blocked',
|
|
4
7
|
DelegationRegistered: 'orchestration.delegation-registered',
|
|
5
8
|
DelegationResultSelected: 'orchestration.delegation-result-selected',
|
|
6
9
|
DelegationWaitStarted: 'orchestration.delegation-wait-started',
|
|
@@ -50,3 +50,30 @@ export type ConversationSurfaceCapability = ValueOf<typeof ConversationSurfaceCa
|
|
|
50
50
|
export declare const DelegationOutputKind: {
|
|
51
51
|
readonly Change: "change";
|
|
52
52
|
};
|
|
53
|
+
export declare const DelegationPrerequisiteCondition: {
|
|
54
|
+
readonly AcceptedOutput: "accepted-output";
|
|
55
|
+
readonly PushedChange: "pushed-change";
|
|
56
|
+
readonly DeliveryReady: "delivery-ready";
|
|
57
|
+
readonly MergedChange: "merged-change";
|
|
58
|
+
};
|
|
59
|
+
export declare const DelegationConflictCode: {
|
|
60
|
+
readonly SelfDependency: "self-dependency";
|
|
61
|
+
readonly MissingTarget: "missing-target";
|
|
62
|
+
readonly MissingOutput: "missing-output";
|
|
63
|
+
readonly OutputKind: "output-kind";
|
|
64
|
+
readonly CrossRepositoryBase: "cross-repository-base";
|
|
65
|
+
readonly CrossRepositoryChange: "cross-repository-change";
|
|
66
|
+
readonly MultipleBases: "multiple-bases";
|
|
67
|
+
readonly WaitCycle: "wait-cycle";
|
|
68
|
+
readonly StalePlan: "stale-plan";
|
|
69
|
+
};
|
|
70
|
+
export type DelegationConflictCode = ValueOf<typeof DelegationConflictCode>;
|
|
71
|
+
export declare const PrerequisiteBlockCode: {
|
|
72
|
+
readonly Waiting: "prerequisite-waiting";
|
|
73
|
+
readonly Changed: "prerequisite-changed";
|
|
74
|
+
readonly Failed: "prerequisite-failed";
|
|
75
|
+
readonly Unavailable: "prerequisite-unavailable";
|
|
76
|
+
readonly Cycle: "prerequisite-cycle";
|
|
77
|
+
readonly Blocked: "prerequisite-blocked";
|
|
78
|
+
};
|
|
79
|
+
export type PrerequisiteBlockCode = ValueOf<typeof PrerequisiteBlockCode>;
|