@atolis-hq/wake 0.4.107 → 0.4.108

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 (64) hide show
  1. package/dist/src/activities/agent/agent-activity.js +4 -0
  2. package/dist/src/activities/agent/agent-result.js +1 -0
  3. package/dist/src/activities/contracts/activity.d.ts +6 -0
  4. package/dist/src/activities/pr/approve.js +1 -1
  5. package/dist/src/activities/pr/merge.js +1 -1
  6. package/dist/src/activities/pr/parent-scope.d.ts +8 -2
  7. package/dist/src/activities/pr/parent-scope.js +7 -1
  8. package/dist/src/activities/pr/parent-target.d.ts +2 -2
  9. package/dist/src/activities/pr/parent-target.js +1 -0
  10. package/dist/src/bootstrap/config/root-schema.d.ts +14 -0
  11. package/dist/src/bootstrap/delivery-integration.js +7 -4
  12. package/dist/src/bootstrap/version.js +1 -1
  13. package/dist/src/control-plane/application/activation-scheduler-ports.d.ts +10 -0
  14. package/dist/src/control-plane/application/advance-once-dispatch.js +3 -5
  15. package/dist/src/control-plane/application/dispatch-resources.d.ts +10 -0
  16. package/dist/src/control-plane/application/dispatch-resources.js +9 -0
  17. package/dist/src/execution/application/change-output-workspaces.d.ts +20 -0
  18. package/dist/src/execution/application/change-output-workspaces.js +123 -0
  19. package/dist/src/execution/application/execution-service.js +15 -2
  20. package/dist/src/execution/application/maintenance-workspaces.js +20 -12
  21. package/dist/src/execution/application/run-lifecycle.d.ts +2 -0
  22. package/dist/src/execution/application/run-lifecycle.js +2 -0
  23. package/dist/src/execution/contracts/change-output.d.ts +15 -0
  24. package/dist/src/execution/contracts/change-output.js +12 -0
  25. package/dist/src/execution/contracts/commands.d.ts +5 -0
  26. package/dist/src/execution/contracts/events.d.ts +16 -0
  27. package/dist/src/execution/contracts/events.js +4 -0
  28. package/dist/src/execution/contracts/runner.d.ts +1 -0
  29. package/dist/src/execution/contracts/views.d.ts +3 -0
  30. package/dist/src/execution/contracts/workspace.d.ts +4 -0
  31. package/dist/src/execution/domain/run.js +3 -0
  32. package/dist/src/execution/index.d.ts +1 -0
  33. package/dist/src/execution/index.js +1 -0
  34. package/dist/src/execution/infrastructure/workspace/git-workspace.js +14 -3
  35. package/dist/src/integrations/application/artifact-registration-reactor.d.ts +2 -11
  36. package/dist/src/integrations/application/artifact-registration-reactor.js +9 -22
  37. package/dist/src/integrations/application/artifact-verification-source.d.ts +26 -0
  38. package/dist/src/integrations/application/artifact-verification-source.js +36 -0
  39. package/dist/src/integrations/application/delegation-outputs.js +56 -20
  40. package/dist/src/integrations/contracts/artifact-events.d.ts +1 -0
  41. package/dist/src/integrations/contracts/artifact-events.js +1 -0
  42. package/dist/src/orchestration/application/delegated-work.d.ts +18 -0
  43. package/dist/src/orchestration/application/delegated-work.js +30 -3
  44. package/dist/src/orchestration/application/delegation-commands.d.ts +16 -0
  45. package/dist/src/orchestration/application/delegation-reservation.js +33 -5
  46. package/dist/src/orchestration/application/delivery-integration-service.js +5 -18
  47. package/dist/src/orchestration/application/orchestration-service.d.ts +34 -0
  48. package/dist/src/orchestration/application/orchestration-service.js +6 -1
  49. package/dist/src/orchestration/contracts/config.d.ts +15 -0
  50. package/dist/src/orchestration/contracts/config.js +8 -1
  51. package/dist/src/orchestration/contracts/delegation.d.ts +33 -9
  52. package/dist/src/orchestration/contracts/delegation.js +11 -5
  53. package/dist/src/orchestration/contracts/vocabulary.d.ts +2 -0
  54. package/dist/src/orchestration/contracts/vocabulary.js +2 -0
  55. package/dist/src/orchestration/domain/assignment-output-requirements.d.ts +5 -0
  56. package/dist/src/orchestration/domain/assignment-output-requirements.js +23 -0
  57. package/dist/src/orchestration/domain/compiler.js +1 -0
  58. package/dist/src/orchestration/domain/delivery-facts.d.ts +9 -1
  59. package/dist/src/orchestration/domain/delivery-facts.js +4 -2
  60. package/dist/src/orchestration/domain/delivery-integration-target.d.ts +8 -0
  61. package/dist/src/orchestration/domain/delivery-integration-target.js +37 -0
  62. package/dist/src/orchestration/domain/delivery-replacement.js +11 -6
  63. package/dist/src/orchestration/domain/delivery-selection.js +2 -1
  64. package/package.json +1 -1
@@ -11,11 +11,13 @@ export function buildReservation(parent, caller, cohortId, assignments, limits)
11
11
  if (new Set(parsed.map((assignment) => assignment.assignmentId)).size !== parsed.length)
12
12
  throw new Error('Duplicate assignment identity');
13
13
  for (const assignment of parsed) {
14
- if (assignment.outputs.filter((output) => 'kind' in output && output.kind === DelegationOutputKind.Change).length > 1)
15
- throw new Error('One change output per child is currently supported');
16
14
  if (assignment.outputs.some((output) => 'kind' in output && output.kind === DelegationOutputKind.Change) &&
17
15
  assignment.repository === undefined)
18
16
  throw new Error('Change outputs require an explicit repository assignment');
17
+ if (assignment.outputs.some((output) => 'kind' in output &&
18
+ output.repository !== undefined &&
19
+ output.repository.resourceId !== assignment.repository?.resourceId))
20
+ throw new Error('Change outputs must use the assigned repository');
19
21
  if (new Set(assignment.outputs.map((output) => output.name)).size !== assignment.outputs.length)
20
22
  throw new Error('Duplicate named output');
21
23
  }
@@ -49,12 +51,38 @@ export function assertWithinRootLimits(existing, reservation, limits) {
49
51
  }
50
52
  /** A replay of a branch request retains the originally resolved commit. */
51
53
  export function matchesAssignments(reservation, assignments) {
52
- if (assignments.some((assignment) => assignment.repository?.sourceRevision !== undefined &&
53
- reservation.children.find((child) => child.assignmentId === assignment.assignmentId)
54
- ?.repository?.sourceRevision !== assignment.repository.sourceRevision))
54
+ if (assignments.some((assignment) => assignment.outputs.some((output) => {
55
+ if (!('kind' in output) || output.repository?.sourceRevision === undefined)
56
+ return false;
57
+ const recorded = reservation.children
58
+ .find((child) => child.assignmentId === assignment.assignmentId)
59
+ ?.outputs.find((entry) => entry.name === output.name);
60
+ return (recorded === undefined ||
61
+ !('kind' in recorded) ||
62
+ recorded.repository?.sourceRevision !== output.repository.sourceRevision);
63
+ })) ||
64
+ assignments.some((assignment) => assignment.repository?.sourceRevision !== undefined &&
65
+ reservation.children.find((child) => child.assignmentId === assignment.assignmentId)
66
+ ?.repository?.sourceRevision !== assignment.repository.sourceRevision))
55
67
  return false;
56
68
  return isDeepStrictEqual(reservation.children.map(({ workItemId: _w, workflowInstanceId: _i, grantId: _g, prerequisiteWorkItemIds: _p, ...assignment }) => ({
57
69
  ...assignment,
70
+ outputs: assignment.outputs.map((output) => {
71
+ if (!('kind' in output) || output.repository === undefined)
72
+ return output;
73
+ const requested = assignments
74
+ .find((entry) => entry.assignmentId === assignment.assignmentId)
75
+ ?.outputs.find((entry) => entry.name === output.name);
76
+ return {
77
+ ...output,
78
+ repository: {
79
+ ...output.repository,
80
+ sourceRevision: requested !== undefined && 'kind' in requested
81
+ ? requested.repository?.sourceRevision
82
+ : undefined,
83
+ },
84
+ };
85
+ }),
58
86
  ...(assignment.repository === undefined
59
87
  ? {}
60
88
  : {
@@ -5,6 +5,7 @@ import { OrchestrationEventType } from '../contracts/events.js';
5
5
  import { DeliveryCompletion, DeliveryRejection, IntegrationState, QaVerdict, } from '../contracts/vocabulary.js';
6
6
  import { currentSelection, isChange, outputKey, } from '../domain/delivery-facts.js';
7
7
  import { targetRequirements } from '../domain/delivery-integration-policy.js';
8
+ import { selectIntegrationTarget } from '../domain/delivery-integration-target.js';
8
9
  import { known, sameRevision } from '../domain/delivery-integration.js';
9
10
  import { deliveryState } from '../domain/delivery-qa.js';
10
11
  import { readDeliveryFacts } from './delivery-facts-reader.js';
@@ -47,9 +48,10 @@ export class DeliveryIntegrationService {
47
48
  const assessment = await this.reader.assess(facts);
48
49
  if (assessment.complete)
49
50
  return { kind: 'fully-integrated' };
50
- const { next, blocking } = assessment;
51
- if (next === null)
52
- return denied(blockReason(blocking));
51
+ const selected = selectIntegrationTarget(assessment, request.output);
52
+ if ('reason' in selected)
53
+ return denied(selected.reason);
54
+ const next = selected.target;
53
55
  if (!(await this.verifySelected(facts, next.output, request.action)))
54
56
  return denied(PullRequestDenialCode.DeliveryNotReady);
55
57
  const context = {
@@ -211,18 +213,3 @@ function replayPlan(recorded, command) {
211
213
  draft: undefined,
212
214
  };
213
215
  }
214
- function blockReason(blocking) {
215
- switch (blocking?.state) {
216
- case IntegrationState.Held:
217
- return PullRequestDenialCode.TargetHeld;
218
- case IntegrationState.MaintenanceRequired:
219
- case IntegrationState.AwaitingLowerLayer:
220
- return PullRequestDenialCode.MaintenanceRequired;
221
- case IntegrationState.Closed:
222
- return PullRequestDenialCode.Closed;
223
- case IntegrationState.Unobserved:
224
- return PullRequestDenialCode.MissingResource;
225
- default:
226
- return PullRequestDenialCode.DeliveryNotReady;
227
- }
228
- }
@@ -153,6 +153,16 @@ export declare class OrchestrationService {
153
153
  recipe?: string | undefined;
154
154
  } | undefined>;
155
155
  repositoryAuthority(workItemId: string): Promise<string[] | undefined>;
156
+ changeOutputAssignments(workItemId: string): Promise<{
157
+ name: string;
158
+ isolated: boolean;
159
+ repository: {
160
+ resourceId: string;
161
+ sourceRef: string;
162
+ sourceRevision: string;
163
+ pullRequestBase: string;
164
+ };
165
+ }[] | undefined>;
156
166
  repositoryAssignment(workItemId: string): Promise<{
157
167
  resourceId: string;
158
168
  sourceRef: string;
@@ -183,9 +193,17 @@ export declare class OrchestrationService {
183
193
  outputs: ({
184
194
  name: string;
185
195
  path: string;
196
+ required?: boolean | undefined;
186
197
  } | {
187
198
  name: string;
188
199
  kind: "change";
200
+ required?: boolean | undefined;
201
+ repository?: {
202
+ resourceId: string;
203
+ sourceRef: string;
204
+ pullRequestBase: string;
205
+ sourceRevision?: string | undefined;
206
+ } | undefined;
189
207
  requireReview?: boolean | undefined;
190
208
  requireChecks?: boolean | undefined;
191
209
  })[];
@@ -479,9 +497,17 @@ export declare class OrchestrationService {
479
497
  outputs: ({
480
498
  name: string;
481
499
  path: string;
500
+ required?: boolean | undefined;
482
501
  } | {
483
502
  name: string;
484
503
  kind: "change";
504
+ required?: boolean | undefined;
505
+ repository?: {
506
+ resourceId: string;
507
+ sourceRef: string;
508
+ pullRequestBase: string;
509
+ sourceRevision?: string | undefined;
510
+ } | undefined;
485
511
  requireReview?: boolean | undefined;
486
512
  requireChecks?: boolean | undefined;
487
513
  })[];
@@ -566,9 +592,17 @@ export declare class OrchestrationService {
566
592
  outputs: ({
567
593
  name: string;
568
594
  path: string;
595
+ required?: boolean | undefined;
569
596
  } | {
570
597
  name: string;
571
598
  kind: "change";
599
+ required?: boolean | undefined;
600
+ repository?: {
601
+ resourceId: string;
602
+ sourceRef: string;
603
+ pullRequestBase: string;
604
+ sourceRevision?: string | undefined;
605
+ } | undefined;
572
606
  requireReview?: boolean | undefined;
573
607
  requireChecks?: boolean | undefined;
574
608
  })[];
@@ -91,6 +91,9 @@ export class OrchestrationService {
91
91
  repositoryAuthority(workItemId) {
92
92
  return this.delegatedWork.repositoryScope(workItemId);
93
93
  }
94
+ changeOutputAssignments(workItemId) {
95
+ return this.delegatedWork.changeOutputAssignments(workItemId);
96
+ }
94
97
  repositoryAssignment(workItemId) {
95
98
  return this.delegatedWork.repositoryFor(workItemId);
96
99
  }
@@ -126,7 +129,9 @@ export class OrchestrationService {
126
129
  const prepared = [];
127
130
  for (const target of targets) {
128
131
  // The same assignment that created the child's workspace, so its lease is reused exactly.
129
- const repository = await this.delegatedWork.repositoryFor(target.ownerWorkItemId);
132
+ const outputs = await this.delegatedWork.changeOutputAssignments(target.ownerWorkItemId);
133
+ const repository = outputs?.find((output) => output.name === target.output.outputName)?.repository ??
134
+ (await this.delegatedWork.repositoryFor(target.ownerWorkItemId));
130
135
  if (repository === undefined)
131
136
  continue;
132
137
  prepared.push({
@@ -233,6 +233,13 @@ export declare const delegationPolicySchema: z.ZodObject<{
233
233
  }, z.core.$strict>>;
234
234
  }, z.core.$strict>;
235
235
  export type DelegationPolicy = z.infer<typeof delegationPolicySchema>;
236
+ export declare const workflowOutputSchema: z.ZodObject<{
237
+ kind: z.ZodEnum<{
238
+ change: "change";
239
+ artifact: "artifact";
240
+ }>;
241
+ required: z.ZodOptional<z.ZodBoolean>;
242
+ }, z.core.$strict>;
236
243
  export declare const workflowDefinitionConfigSchema: z.ZodObject<{
237
244
  entry: z.ZodOptional<z.ZodString>;
238
245
  delegation: z.ZodOptional<z.ZodObject<{
@@ -253,6 +260,13 @@ export declare const workflowDefinitionConfigSchema: z.ZodObject<{
253
260
  stage: z.ZodString;
254
261
  }, z.core.$strict>>;
255
262
  }, z.core.$strict>>;
263
+ outputs: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
264
+ kind: z.ZodEnum<{
265
+ change: "change";
266
+ artifact: "artifact";
267
+ }>;
268
+ required: z.ZodOptional<z.ZodBoolean>;
269
+ }, z.core.$strict>>>;
256
270
  commands: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
257
271
  activity: z.ZodString;
258
272
  with: z.ZodOptional<z.ZodUnknown>;
@@ -452,6 +466,7 @@ export interface CompiledWatch extends Omit<WatchConfig, 'workflow' | 'while' |
452
466
  }
453
467
  export interface CompiledWorkflow {
454
468
  readonly delegation?: DelegationPolicy;
469
+ readonly outputs?: Readonly<Record<string, z.infer<typeof workflowOutputSchema>>>;
455
470
  readonly remainingAgentSteps?: Readonly<Record<StageName, number>>;
456
471
  readonly name: WorkflowName;
457
472
  readonly entry: StageName;
@@ -1,5 +1,5 @@
1
1
  import { z } from 'zod';
2
- import { ApprovalAuthorityKind, ConversationSurfaceCapability, DeliveryCompletion, WorkflowStatus, } from './vocabulary.js';
2
+ import { ApprovalAuthorityKind, ConversationSurfaceCapability, DelegationOutputKind, DeliveryCompletion, WorkflowArtifactOutputKind, WorkflowStatus, } from './vocabulary.js';
3
3
  import { ActivityEventType, PullRequestCheckState, PullRequestDenialCode, PullRequestMergeability, PullRequestState, } from '../../activities/index.js';
4
4
  import { WorkspaceMode } from '../../execution/index.js';
5
5
  import { MatchMode } from '../../kernel/index.js';
@@ -172,10 +172,17 @@ export const delegationPolicySchema = z
172
172
  maintenance: z.object({ stage: identifier }).strict().optional(),
173
173
  })
174
174
  .strict();
175
+ export const workflowOutputSchema = z
176
+ .object({
177
+ kind: z.enum([WorkflowArtifactOutputKind, DelegationOutputKind.Change]),
178
+ required: z.boolean().optional(),
179
+ })
180
+ .strict();
175
181
  export const workflowDefinitionConfigSchema = z
176
182
  .object({
177
183
  entry: identifier.optional(),
178
184
  delegation: delegationPolicySchema.optional(),
185
+ outputs: z.record(identifier, workflowOutputSchema).optional(),
179
186
  commands: z.record(commandName, supplementalCommandConfigSchema).optional(),
180
187
  watches: z.array(watchConfigSchema).readonly().optional(),
181
188
  stages: z
@@ -63,9 +63,17 @@ export declare const delegatedAssignmentSchema: z.ZodObject<{
63
63
  outputs: z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
64
64
  name: z.ZodString;
65
65
  path: z.ZodString;
66
+ required: z.ZodOptional<z.ZodBoolean>;
66
67
  }, z.core.$strict>, z.ZodObject<{
67
68
  name: z.ZodString;
68
69
  kind: z.ZodLiteral<"change">;
70
+ required: z.ZodOptional<z.ZodBoolean>;
71
+ repository: z.ZodOptional<z.ZodObject<{
72
+ resourceId: z.ZodString;
73
+ sourceRef: z.ZodString;
74
+ sourceRevision: z.ZodOptional<z.ZodString>;
75
+ pullRequestBase: z.ZodString;
76
+ }, z.core.$strict>>;
69
77
  requireReview: z.ZodOptional<z.ZodBoolean>;
70
78
  requireChecks: z.ZodOptional<z.ZodBoolean>;
71
79
  }, z.core.$strict>]>>;
@@ -86,6 +94,23 @@ export declare const delegationSubmissionSchema: z.ZodObject<{
86
94
  revisionId: z.ZodString;
87
95
  }, z.core.$strict>>;
88
96
  criteria: z.ZodArray<z.ZodString>;
97
+ outputs: z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
98
+ name: z.ZodString;
99
+ path: z.ZodString;
100
+ required: z.ZodOptional<z.ZodBoolean>;
101
+ }, z.core.$strict>, z.ZodObject<{
102
+ name: z.ZodString;
103
+ kind: z.ZodLiteral<"change">;
104
+ required: z.ZodOptional<z.ZodBoolean>;
105
+ repository: z.ZodOptional<z.ZodObject<{
106
+ resourceId: z.ZodString;
107
+ sourceRef: z.ZodString;
108
+ sourceRevision: z.ZodOptional<z.ZodString>;
109
+ pullRequestBase: z.ZodString;
110
+ }, z.core.$strict>>;
111
+ requireReview: z.ZodOptional<z.ZodBoolean>;
112
+ requireChecks: z.ZodOptional<z.ZodBoolean>;
113
+ }, z.core.$strict>]>>;
89
114
  assignmentId: z.ZodString;
90
115
  workflowName: z.ZodPipe<z.ZodString, z.ZodTransform<import("./identifiers.js").WorkflowName, string>>;
91
116
  repositoryResourceIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
@@ -105,15 +130,6 @@ export declare const delegationSubmissionSchema: z.ZodObject<{
105
130
  cohortId: z.ZodString;
106
131
  assignmentId: z.ZodString;
107
132
  }, z.core.$strict>>;
108
- outputs: z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
109
- name: z.ZodString;
110
- path: z.ZodString;
111
- }, z.core.$strict>, z.ZodObject<{
112
- name: z.ZodString;
113
- kind: z.ZodLiteral<"change">;
114
- requireReview: z.ZodOptional<z.ZodBoolean>;
115
- requireChecks: z.ZodOptional<z.ZodBoolean>;
116
- }, z.core.$strict>]>>;
117
133
  }, z.core.$strict>>;
118
134
  }, z.core.$strict>;
119
135
  export type DelegationSubmission = z.infer<typeof delegationSubmissionSchema>;
@@ -160,9 +176,17 @@ export declare const delegationReservationSchema: z.ZodObject<{
160
176
  outputs: z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
161
177
  name: z.ZodString;
162
178
  path: z.ZodString;
179
+ required: z.ZodOptional<z.ZodBoolean>;
163
180
  }, z.core.$strict>, z.ZodObject<{
164
181
  name: z.ZodString;
165
182
  kind: z.ZodLiteral<"change">;
183
+ required: z.ZodOptional<z.ZodBoolean>;
184
+ repository: z.ZodOptional<z.ZodObject<{
185
+ resourceId: z.ZodString;
186
+ sourceRef: z.ZodString;
187
+ sourceRevision: z.ZodOptional<z.ZodString>;
188
+ pullRequestBase: z.ZodString;
189
+ }, z.core.$strict>>;
166
190
  requireReview: z.ZodOptional<z.ZodBoolean>;
167
191
  requireChecks: z.ZodOptional<z.ZodBoolean>;
168
192
  }, z.core.$strict>]>>;
@@ -48,11 +48,19 @@ export const delegatedAssignmentSchema = z
48
48
  .optional(),
49
49
  outputs: z
50
50
  .array(z.union([
51
- z.object({ name: z.string().min(1), path: z.string().min(1) }).strict(),
51
+ z
52
+ .object({
53
+ name: z.string().min(1),
54
+ path: z.string().min(1),
55
+ required: z.boolean().optional(),
56
+ })
57
+ .strict(),
52
58
  z
53
59
  .object({
54
60
  name: z.string().min(1),
55
61
  kind: z.literal(DelegationOutputKind.Change),
62
+ required: z.boolean().optional(),
63
+ repository: repositoryAssignmentRequestSchema.optional(),
56
64
  requireReview: z.boolean().optional(),
57
65
  requireChecks: z.boolean().optional(),
58
66
  })
@@ -103,8 +111,7 @@ export const delegationResultSchema = z
103
111
  .object({
104
112
  cohortId: z.string().min(1),
105
113
  childWorkItemId: brandedStringSchema(workItemId),
106
- outputs: z
107
- .array(z
114
+ outputs: z.array(z
108
115
  .object({
109
116
  name: z.string().min(1),
110
117
  reference: z.union([
@@ -124,8 +131,7 @@ export const delegationResultSchema = z
124
131
  .strict(),
125
132
  ]),
126
133
  })
127
- .strict())
128
- .min(1),
134
+ .strict()),
129
135
  })
130
136
  .strict();
131
137
  export const delegationInputsSchema = z
@@ -50,6 +50,8 @@ export type ConversationSurfaceCapability = ValueOf<typeof ConversationSurfaceCa
50
50
  export declare const DelegationOutputKind: {
51
51
  readonly Change: "change";
52
52
  };
53
+ /** Path-addressed outputs; kept outside the vocabulary so unrelated 'artifact' strings stay free. */
54
+ export declare const WorkflowArtifactOutputKind = "artifact";
53
55
  export declare const DelegationPrerequisiteCondition: {
54
56
  readonly AcceptedOutput: "accepted-output";
55
57
  readonly PushedChange: "pushed-change";
@@ -43,6 +43,8 @@ export const ConversationSurfaceCapability = defineClosedVocabulary({
43
43
  Operator: 'operator-surface',
44
44
  });
45
45
  export const DelegationOutputKind = defineClosedVocabulary({ Change: 'change' });
46
+ /** Path-addressed outputs; kept outside the vocabulary so unrelated 'artifact' strings stay free. */
47
+ export const WorkflowArtifactOutputKind = 'artifact';
46
48
  export const DelegationPrerequisiteCondition = defineClosedVocabulary({
47
49
  AcceptedOutput: 'accepted-output',
48
50
  PushedChange: 'pushed-change',
@@ -0,0 +1,5 @@
1
+ import type { CompiledWorkflow } from '../contracts/config.js';
2
+ import type { DelegatedAssignment, DelegationReservation, DelegationResult } from '../contracts/delegation.js';
3
+ /** An assignment may add obligations, but cannot remove the workflow's declared obligations. */
4
+ export declare function assertConfiguredOutputs(configured: CompiledWorkflow['outputs'], outputs: DelegatedAssignment['outputs']): void;
5
+ export declare function hasRequiredOutputs(child: DelegationReservation['children'][number], outputs: DelegationResult['outputs']): boolean;
@@ -0,0 +1,23 @@
1
+ import { WorkflowArtifactOutputKind } from '../contracts/vocabulary.js';
2
+ /** An assignment may add obligations, but cannot remove the workflow's declared obligations. */
3
+ export function assertConfiguredOutputs(configured, outputs) {
4
+ for (const [name, requirement] of Object.entries(configured ?? {})) {
5
+ const output = outputs.find((entry) => entry.name === name);
6
+ if (output === undefined) {
7
+ if (requirement.required !== false)
8
+ throw new Error('Missing configured required output: ' + name);
9
+ continue;
10
+ }
11
+ if (('kind' in output ? output.kind : WorkflowArtifactOutputKind) !== requirement.kind ||
12
+ (requirement.required !== false && output.required === false))
13
+ throw new Error('Assignment weakens configured output: ' + name);
14
+ }
15
+ }
16
+ export function hasRequiredOutputs(child, outputs) {
17
+ return (new Set(outputs.map((output) => output.name)).size === outputs.length &&
18
+ outputs.every((output) => output.reference.workItemId === child.workItemId &&
19
+ child.outputs.some((declared) => declared.name === output.name)) &&
20
+ child.outputs
21
+ .filter((output) => output.required !== false)
22
+ .every((required) => outputs.some((output) => output.name === required.name)));
23
+ }
@@ -34,6 +34,7 @@ export function compileWorkflow(name, input, activities, knownWorkflowNames = [n
34
34
  return Object.freeze({
35
35
  remainingAgentSteps: Object.freeze(remainingAgentSteps(stages, (activity) => activities.describe(activity).executionKind === ActivityExecutionKind.Agent)),
36
36
  ...(config.delegation === undefined ? {} : { delegation: config.delegation }),
37
+ ...(config.outputs === undefined ? {} : { outputs: config.outputs }),
37
38
  name: compiledName,
38
39
  entry: compiledEntry,
39
40
  commands: Object.freeze(commands),
@@ -40,7 +40,7 @@ export interface Requirement {
40
40
  readonly criteria: readonly string[];
41
41
  }
42
42
  /** Original required assignments: those not themselves declared as a replacement. */
43
- export declare function requirements(reservations: readonly DelegationReservation[]): Requirement[];
43
+ export declare function requirements(reservations: readonly DelegationReservation[], includeOptional?: boolean): Requirement[];
44
44
  export declare function childOf(reservations: readonly DelegationReservation[], id: string): {
45
45
  cohortId: string;
46
46
  child: {
@@ -56,9 +56,17 @@ export declare function childOf(reservations: readonly DelegationReservation[],
56
56
  outputs: ({
57
57
  name: string;
58
58
  path: string;
59
+ required?: boolean | undefined;
59
60
  } | {
60
61
  name: string;
61
62
  kind: "change";
63
+ required?: boolean | undefined;
64
+ repository?: {
65
+ resourceId: string;
66
+ sourceRef: string;
67
+ pullRequestBase: string;
68
+ sourceRevision?: string | undefined;
69
+ } | undefined;
62
70
  requireReview?: boolean | undefined;
63
71
  requireChecks?: boolean | undefined;
64
72
  })[];
@@ -39,10 +39,12 @@ export function currentSelection(facts) {
39
39
  };
40
40
  }
41
41
  /** Original required assignments: those not themselves declared as a replacement. */
42
- export function requirements(reservations) {
42
+ export function requirements(reservations, includeOptional = false) {
43
43
  return reservations.flatMap((reservation) => reservation.children
44
44
  .filter((child) => child.replaces === undefined)
45
- .flatMap((child) => child.outputs.map((output) => ({
45
+ .flatMap((child) => child.outputs
46
+ .filter((output) => includeOptional || output.required !== false)
47
+ .map((output) => ({
46
48
  cohortId: reservation.cohortId,
47
49
  assignmentId: child.assignmentId,
48
50
  outputName: output.name,
@@ -0,0 +1,8 @@
1
+ import { PullRequestDenialCode, type ParentOutputTarget } from '../../activities/index.js';
2
+ import type { IntegrationAssessment, IntegrationTarget } from './delivery-integration.js';
3
+ /** Multiple outputs of one child have no implicit integration order. */
4
+ export declare function selectIntegrationTarget(assessment: IntegrationAssessment, output: ParentOutputTarget | undefined): {
5
+ readonly target: IntegrationTarget;
6
+ } | {
7
+ readonly reason: PullRequestDenialCode;
8
+ };
@@ -0,0 +1,37 @@
1
+ import { PullRequestDenialCode } from '../../activities/index.js';
2
+ import { IntegrationState } from '../contracts/vocabulary.js';
3
+ /** Multiple outputs of one child have no implicit integration order. */
4
+ export function selectIntegrationTarget(assessment, output) {
5
+ if (output === undefined) {
6
+ const owners = assessment.targets.map((target) => target.output.childWorkItemId);
7
+ if (new Set(owners).size !== owners.length)
8
+ return { reason: PullRequestDenialCode.AmbiguousResource };
9
+ return assessment.next === null
10
+ ? { reason: blockReason(assessment.blocking) }
11
+ : { target: assessment.next };
12
+ }
13
+ const matches = assessment.targets.filter((entry) => (output.childWorkItemId === undefined ||
14
+ entry.output.childWorkItemId === output.childWorkItemId) &&
15
+ entry.output.outputName === output.outputName);
16
+ if (matches.length > 1)
17
+ return { reason: PullRequestDenialCode.AmbiguousResource };
18
+ const target = matches[0];
19
+ if (target === undefined)
20
+ return { reason: PullRequestDenialCode.MissingResource };
21
+ return target.state === IntegrationState.Ready ? { target } : { reason: blockReason(target) };
22
+ }
23
+ function blockReason(blocking) {
24
+ switch (blocking?.state) {
25
+ case IntegrationState.Held:
26
+ return PullRequestDenialCode.TargetHeld;
27
+ case IntegrationState.MaintenanceRequired:
28
+ case IntegrationState.AwaitingLowerLayer:
29
+ return PullRequestDenialCode.MaintenanceRequired;
30
+ case IntegrationState.Closed:
31
+ return PullRequestDenialCode.Closed;
32
+ case IntegrationState.Unobserved:
33
+ return PullRequestDenialCode.MissingResource;
34
+ default:
35
+ return PullRequestDenialCode.DeliveryNotReady;
36
+ }
37
+ }
@@ -25,22 +25,27 @@ export function assertCriteriaPreserving(facts, original, assignment) {
25
25
  const unmerged = facts.results
26
26
  .filter((entry) => entry.childWorkItemId === original.workItemId)
27
27
  .flatMap((entry) => entry.outputs.filter(isChange))
28
- .map((output) => output.reference)
29
- .filter((reference) => reference.merged !== true);
30
- for (const reference of unmerged)
31
- assertCarriesContribution(assignment, reference);
28
+ .filter((output) => output.reference.merged !== true);
29
+ for (const output of unmerged) {
30
+ const counterpart = assignment.outputs.find((entry) => entry.name === output.name);
31
+ const repository = counterpart !== undefined && 'kind' in counterpart
32
+ ? (counterpart.repository ?? assignment.repository)
33
+ : assignment.repository;
34
+ assertCarriesContribution(repository, output.reference);
35
+ }
32
36
  }
33
37
  function assertOutputsProvided(original, assignment) {
34
38
  for (const output of original.outputs) {
35
39
  const counterpart = assignment.outputs.find((entry) => entry.name === output.name);
36
40
  if (counterpart === undefined || 'kind' in output !== 'kind' in counterpart)
37
41
  throw invalid(`A replacement must provide the original output ${output.name}`);
42
+ if (output.required !== false && counterpart.required === false)
43
+ throw invalid('A replacement must preserve the original required output ' + output.name);
38
44
  if ('kind' in output && 'kind' in counterpart)
39
45
  assertChangeRequirements(output, counterpart);
40
46
  }
41
47
  }
42
- function assertCarriesContribution(assignment, reference) {
43
- const repository = assignment.repository;
48
+ function assertCarriesContribution(repository, reference) {
44
49
  if (repository?.sourceRevision !== reference.revision)
45
50
  throw invalid(`A replacement must start from the unmerged contribution ${reference.branch}@${reference.revision}`);
46
51
  if (repository.pullRequestBase !== reference.pullRequestBase)
@@ -18,9 +18,10 @@ export function reviseSelection(facts, command) {
18
18
  if (command.expectedRevision !== revision)
19
19
  throw reject(DeliveryRejection.StaleSelection, `Selection is at revision ${revision}, not ${command.expectedRevision}; inspect and retry`);
20
20
  const required = requirements(facts.reservations);
21
+ const available = requirements(facts.reservations, true);
21
22
  const seen = new Set();
22
23
  const entries = command.entries.map((entry) => {
23
- const requirement = required.find((candidate) => candidate.cohortId === entry.cohortId &&
24
+ const requirement = available.find((candidate) => candidate.cohortId === entry.cohortId &&
24
25
  candidate.assignmentId === entry.assignmentId &&
25
26
  candidate.outputName === entry.output.outputName);
26
27
  if (requirement === undefined)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atolis-hq/wake",
3
- "version": "0.4.107",
3
+ "version": "0.4.108",
4
4
  "description": "Local autonomous agent control plane for software development",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {