@atolis-hq/wake 0.4.106 → 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 (95) 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/application.js +23 -9
  5. package/dist/src/activities/pr/approve.js +1 -1
  6. package/dist/src/activities/pr/merge.js +1 -1
  7. package/dist/src/activities/pr/parent-scope.d.ts +8 -2
  8. package/dist/src/activities/pr/parent-scope.js +7 -1
  9. package/dist/src/activities/pr/parent-target.d.ts +2 -2
  10. package/dist/src/activities/pr/parent-target.js +1 -0
  11. package/dist/src/bootstrap/composition-root.js +1 -1
  12. package/dist/src/bootstrap/config/root-schema.d.ts +14 -0
  13. package/dist/src/bootstrap/delivery-integration.js +7 -4
  14. package/dist/src/bootstrap/version.js +1 -1
  15. package/dist/src/control-plane/application/activation-scheduler-ports.d.ts +10 -0
  16. package/dist/src/control-plane/application/advance-once-dispatch.js +3 -5
  17. package/dist/src/control-plane/application/dispatch-resources.d.ts +10 -0
  18. package/dist/src/control-plane/application/dispatch-resources.js +9 -0
  19. package/dist/src/conversations/application/conversation-repository.d.ts +1 -1
  20. package/dist/src/conversations/application/conversation-repository.js +3 -1
  21. package/dist/src/execution/application/change-output-workspaces.d.ts +20 -0
  22. package/dist/src/execution/application/change-output-workspaces.js +123 -0
  23. package/dist/src/execution/application/execution-service.js +15 -2
  24. package/dist/src/execution/application/maintenance-workspaces.js +20 -12
  25. package/dist/src/execution/application/run-lifecycle.d.ts +2 -0
  26. package/dist/src/execution/application/run-lifecycle.js +2 -0
  27. package/dist/src/execution/application/run-repository.js +27 -10
  28. package/dist/src/execution/contracts/change-output.d.ts +15 -0
  29. package/dist/src/execution/contracts/change-output.js +12 -0
  30. package/dist/src/execution/contracts/commands.d.ts +5 -0
  31. package/dist/src/execution/contracts/events.d.ts +16 -0
  32. package/dist/src/execution/contracts/events.js +4 -0
  33. package/dist/src/execution/contracts/runner.d.ts +1 -0
  34. package/dist/src/execution/contracts/views.d.ts +3 -0
  35. package/dist/src/execution/contracts/workspace.d.ts +4 -0
  36. package/dist/src/execution/domain/run.js +3 -0
  37. package/dist/src/execution/index.d.ts +1 -0
  38. package/dist/src/execution/index.js +1 -0
  39. package/dist/src/execution/infrastructure/workspace/git-workspace.js +14 -3
  40. package/dist/src/integrations/application/artifact-registration-reactor.d.ts +2 -11
  41. package/dist/src/integrations/application/artifact-registration-reactor.js +16 -36
  42. package/dist/src/integrations/application/artifact-verification-source.d.ts +26 -0
  43. package/dist/src/integrations/application/artifact-verification-source.js +36 -0
  44. package/dist/src/integrations/application/delegation-outputs.js +56 -20
  45. package/dist/src/integrations/application/latest-unresolved-artifacts.d.ts +3 -0
  46. package/dist/src/integrations/application/latest-unresolved-artifacts.js +16 -0
  47. package/dist/src/integrations/contracts/artifact-events.d.ts +1 -0
  48. package/dist/src/integrations/contracts/artifact-events.js +1 -0
  49. package/dist/src/integrations/github/application/comment-history-reader.d.ts +1 -1
  50. package/dist/src/integrations/github/application/comment-history-reader.js +56 -39
  51. package/dist/src/node_modules/@atolis-hq/eventing/dist/index.d.ts +1 -1
  52. package/dist/src/node_modules/@atolis-hq/eventing/dist/index.d.ts.map +1 -1
  53. package/dist/src/node_modules/@atolis-hq/eventing/dist/index.js +1 -1
  54. package/dist/src/node_modules/@atolis-hq/eventing/dist/projections/projection-processor.d.ts +14 -0
  55. package/dist/src/node_modules/@atolis-hq/eventing/dist/projections/projection-processor.d.ts.map +1 -1
  56. package/dist/src/node_modules/@atolis-hq/eventing/dist/projections/projection-processor.js +31 -1
  57. package/dist/src/node_modules/@atolis-hq/eventing/dist/runtime/journal-view.d.ts +22 -0
  58. package/dist/src/node_modules/@atolis-hq/eventing/dist/runtime/journal-view.d.ts.map +1 -0
  59. package/dist/src/node_modules/@atolis-hq/eventing/dist/runtime/journal-view.js +60 -0
  60. package/dist/src/node_modules/@atolis-hq/eventing-filesystem/dist/file-event-journal.d.ts +2 -0
  61. package/dist/src/node_modules/@atolis-hq/eventing-filesystem/dist/file-event-journal.d.ts.map +1 -1
  62. package/dist/src/node_modules/@atolis-hq/eventing-filesystem/dist/file-event-journal.js +82 -15
  63. package/dist/src/orchestration/application/advance-workflow.js +7 -2
  64. package/dist/src/orchestration/application/deferred-signals.js +2 -6
  65. package/dist/src/orchestration/application/delegated-work.d.ts +18 -0
  66. package/dist/src/orchestration/application/delegated-work.js +30 -3
  67. package/dist/src/orchestration/application/delegation-commands.d.ts +16 -0
  68. package/dist/src/orchestration/application/delegation-reservation.js +33 -5
  69. package/dist/src/orchestration/application/delivery-integration-service.js +5 -18
  70. package/dist/src/orchestration/application/orchestration-repository.d.ts +14 -9
  71. package/dist/src/orchestration/application/orchestration-repository.js +139 -64
  72. package/dist/src/orchestration/application/orchestration-service.d.ts +34 -0
  73. package/dist/src/orchestration/application/orchestration-service.js +6 -1
  74. package/dist/src/orchestration/contracts/config.d.ts +15 -0
  75. package/dist/src/orchestration/contracts/config.js +8 -1
  76. package/dist/src/orchestration/contracts/delegation.d.ts +33 -9
  77. package/dist/src/orchestration/contracts/delegation.js +11 -5
  78. package/dist/src/orchestration/contracts/vocabulary.d.ts +2 -0
  79. package/dist/src/orchestration/contracts/vocabulary.js +2 -0
  80. package/dist/src/orchestration/domain/assignment-output-requirements.d.ts +5 -0
  81. package/dist/src/orchestration/domain/assignment-output-requirements.js +23 -0
  82. package/dist/src/orchestration/domain/compiler.js +1 -0
  83. package/dist/src/orchestration/domain/delivery-facts.d.ts +9 -1
  84. package/dist/src/orchestration/domain/delivery-facts.js +4 -2
  85. package/dist/src/orchestration/domain/delivery-integration-target.d.ts +8 -0
  86. package/dist/src/orchestration/domain/delivery-integration-target.js +37 -0
  87. package/dist/src/orchestration/domain/delivery-replacement.js +11 -6
  88. package/dist/src/orchestration/domain/delivery-selection.js +2 -1
  89. package/dist/src/resources/application/resource-lookup.d.ts +2 -1
  90. package/dist/src/resources/application/resource-lookup.js +3 -11
  91. package/dist/src/resources/application/resource-repository.js +10 -10
  92. package/package.json +1 -1
  93. package/dist/src/node_modules/@atolis-hq/eventing/dist/runtime/cached-journal-view.d.ts +0 -16
  94. package/dist/src/node_modules/@atolis-hq/eventing/dist/runtime/cached-journal-view.d.ts.map +0 -1
  95. package/dist/src/node_modules/@atolis-hq/eventing/dist/runtime/cached-journal-view.js +0 -79
@@ -1,31 +1,32 @@
1
- import { cachedJournalView } from '@atolis-hq/eventing';
1
+ import { foldedJournalView } from '@atolis-hq/eventing';
2
2
  import { decodeOrchestrationEvent, selectWorkflowOrchestrationEvent, } from '../contracts/event-decoder.js';
3
3
  import { OrchestrationEventType } from '../contracts/events.js';
4
4
  import { workflowInstanceId } from '../contracts/identifiers.js';
5
5
  import { isWorkflowInstanceStream, workflowInstanceStream } from '../contracts/streams.js';
6
6
  import { foldWorkflowInstance } from '../domain/workflow-instance.js';
7
+ const emptyState = {
8
+ failures: new Map(),
9
+ instances: [],
10
+ events: [],
11
+ inherited: new Map(),
12
+ deferredInstanceIds: new Set(),
13
+ sequences: new Map(),
14
+ own: new Map(),
15
+ grouped: new Map(),
16
+ listedById: new Map(),
17
+ };
7
18
  export class OrchestrationRepository {
8
19
  journal;
9
20
  completionBlock;
10
- listed;
21
+ state;
11
22
  constructor(journal, completionBlock) {
12
23
  this.journal = journal;
13
24
  this.completionBlock = completionBlock;
14
- this.listed = cachedJournalView(journal, (events) => {
15
- const owned = events.flatMap((entry) => {
16
- const decoded = selectWorkflowOrchestrationEvent(entry);
17
- return decoded === null ? [] : [decoded];
18
- });
19
- return {
20
- instances: deriveList(events, owned),
21
- events: owned,
22
- inherited: inheritedReservations(owned),
23
- };
24
- });
25
+ this.state = foldedJournalView(journal, { initial: emptyState, extend: extendState });
25
26
  }
26
27
  async load(id) {
27
28
  const { events: own, sequence } = await this.history(id);
28
- const inherited = ((await this.listed.get()).inherited.get(id) ?? []).filter((entry) => {
29
+ const inherited = ((await this.state.get()).inherited.get(id) ?? []).filter((entry) => {
29
30
  const fact = entry.event;
30
31
  if (entry.stream.id === id ||
31
32
  fact.eventType !== OrchestrationEventType.DelegationReserved ||
@@ -39,18 +40,27 @@ export class OrchestrationRepository {
39
40
  return { sequence, view: foldWorkflowInstance([...own, ...inherited]) };
40
41
  }
41
42
  snapshot() {
42
- return this.listed.get();
43
+ return this.healthyState();
44
+ }
45
+ async events() {
46
+ return (await this.healthyState()).events;
43
47
  }
44
- events() {
45
- return this.listed.get().then((snapshot) => snapshot.events);
48
+ /** Workflow instances that hold at least one deferred signal. */
49
+ async instancesWithDeferredSignals() {
50
+ return (await this.healthyState()).deferredInstanceIds;
46
51
  }
47
52
  async history(id) {
48
- const raw = await this.journal.readStream(workflowInstanceStream(workflowInstanceId(id)));
49
- const events = raw.flatMap((entry) => {
50
- const owned = selectWorkflowOrchestrationEvent(entry);
51
- return owned === null ? [] : [owned];
52
- });
53
- return { sequence: raw.length, events };
53
+ const state = await this.state.get();
54
+ if (state.failures.has(id))
55
+ throw state.failures.get(id);
56
+ return { sequence: state.sequences.get(id) ?? 0, events: state.own.get(id) ?? [] };
57
+ }
58
+ /** The state for reads that span every instance, which fail while any instance is malformed. */
59
+ async healthyState() {
60
+ const state = await this.state.get();
61
+ for (const failure of state.failures.values())
62
+ throw failure;
63
+ return state;
54
64
  }
55
65
  async loadRequired(id) {
56
66
  const loaded = await this.load(id);
@@ -80,57 +90,122 @@ export class OrchestrationRepository {
80
90
  return events.map(decodeOrchestrationEvent).filter(isWorkflowEvent);
81
91
  }
82
92
  async list() {
83
- return (await this.listed.get()).instances;
93
+ return (await this.healthyState()).instances;
84
94
  }
85
95
  }
86
96
  function isWorkflowEvent(event) {
87
97
  return isWorkflowInstanceStream(event.stream);
88
98
  }
89
- // `sequence` counts every event on the stream, matching readStream, while the
90
- // fold sees only owned orchestration events — exactly what load() computes.
91
- function deriveList(events, owned) {
92
- const streams = new Map();
93
- for (const event of events) {
94
- if (!isWorkflowInstanceStream(event.stream))
99
+ /** Refolds only the touched instances; a fold error fails that instance alone. */
100
+ function refoldTouched(touched, previous, sequences, grouped, failures) {
101
+ const listedById = new Map(previous);
102
+ for (const id of touched) {
103
+ // A parent named by a reservation may not have a stream of its own yet.
104
+ if (!sequences.has(id))
95
105
  continue;
96
- const existing = streams.get(event.stream.id);
97
- if (existing === undefined)
98
- streams.set(event.stream.id, [event]);
99
- else
100
- existing.push(event);
106
+ try {
107
+ listedById.set(id, {
108
+ sequence: sequences.get(id),
109
+ view: foldWorkflowInstance(grouped.get(id) ?? []),
110
+ });
111
+ }
112
+ catch (error) {
113
+ listedById.delete(id);
114
+ if (!failures.has(id))
115
+ failures.set(id, error);
116
+ }
101
117
  }
102
- const grouped = new Map();
103
- const add = (id, event) => {
104
- const group = grouped.get(id);
105
- if (group === undefined)
106
- grouped.set(id, [event]);
107
- else
108
- group.push(event);
109
- };
110
- for (const event of owned) {
111
- add(event.stream.id, event);
112
- if (event.event.eventType === OrchestrationEventType.DelegationReserved &&
113
- event.event.payload.parentWorkflowInstanceId !== event.stream.id)
114
- add(event.event.payload.parentWorkflowInstanceId, event);
118
+ return listedById;
119
+ }
120
+ /** A malformed event poisons only the instance whose stream holds it. */
121
+ function decodeIsolated(raw, instanceId, failures) {
122
+ try {
123
+ return selectWorkflowOrchestrationEvent(raw);
124
+ }
125
+ catch (error) {
126
+ if (!failures.has(instanceId))
127
+ failures.set(instanceId, error);
128
+ // A reservation recorded on a child's stream is part of its parent's view, so
129
+ // a malformed one must not leave the parent quietly missing it.
130
+ const parent = rawReservationParent(raw);
131
+ if (parent !== undefined && !failures.has(parent))
132
+ failures.set(parent, error);
133
+ return null;
115
134
  }
116
- return [...streams.values()].map((streamEvents) => ({
117
- sequence: streamEvents.length,
118
- view: foldWorkflowInstance(grouped.get(streamEvents[0].stream.id) ?? []),
119
- }));
120
135
  }
121
- function inheritedReservations(events) {
122
- const inherited = new Map();
123
- for (const entry of events) {
124
- if (entry.event.eventType !== OrchestrationEventType.DelegationReserved)
136
+ function rawReservationParent(raw) {
137
+ if (raw.event.eventType !== OrchestrationEventType.DelegationReserved)
138
+ return undefined;
139
+ const payload = raw.event.payload;
140
+ if (typeof payload !== 'object' || payload === null)
141
+ return undefined;
142
+ const parent = payload.parentWorkflowInstanceId;
143
+ return typeof parent === 'string' ? parent : undefined;
144
+ }
145
+ /** The parent instance a child-stream DelegationReserved fact is recorded for. */
146
+ function reservingParent(event) {
147
+ return event.event.eventType === OrchestrationEventType.DelegationReserved &&
148
+ event.event.payload.parentWorkflowInstanceId !== event.stream.id
149
+ ? event.event.payload.parentWorkflowInstanceId
150
+ : undefined;
151
+ }
152
+ // `sequence` counts every event on the stream, matching readStream, while the
153
+ // fold sees only owned orchestration events. A DelegationReserved fact recorded
154
+ // on a child's stream also belongs to the parent's group, in journal order.
155
+ function extendState(state, events) {
156
+ const sequences = new Map(state.sequences);
157
+ const own = new Map(state.own);
158
+ const grouped = new Map(state.grouped);
159
+ const inherited = new Map(state.inherited);
160
+ const deferred = new Set(state.deferredInstanceIds);
161
+ const failures = new Map(state.failures);
162
+ const added = [];
163
+ const touched = new Set();
164
+ // Arrays carried over from earlier states are copied on first touch, then
165
+ // extended in place for the rest of this fold.
166
+ const fresh = new Set();
167
+ const push = (map, key, event) => {
168
+ let list = map.get(key);
169
+ if (list === undefined || !fresh.has(list)) {
170
+ list = [...(list ?? [])];
171
+ fresh.add(list);
172
+ map.set(key, list);
173
+ }
174
+ list.push(event);
175
+ };
176
+ for (const raw of events) {
177
+ if (!isWorkflowInstanceStream(raw.stream))
125
178
  continue;
126
- const id = entry.event.payload.parentWorkflowInstanceId;
127
- if (entry.stream.id === id)
179
+ const id = raw.stream.id;
180
+ sequences.set(id, (sequences.get(id) ?? 0) + 1);
181
+ touched.add(id);
182
+ const event = decodeIsolated(raw, id, failures);
183
+ if (event === null)
128
184
  continue;
129
- const prior = inherited.get(id);
130
- if (prior === undefined)
131
- inherited.set(id, [entry]);
132
- else
133
- prior.push(entry);
185
+ added.push(event);
186
+ push(own, id, event);
187
+ push(grouped, id, event);
188
+ if (event.event.eventType === OrchestrationEventType.SignalDeferred)
189
+ deferred.add(id);
190
+ const parent = reservingParent(event);
191
+ if (parent !== undefined) {
192
+ push(grouped, parent, event);
193
+ push(inherited, parent, event);
194
+ touched.add(parent);
195
+ }
134
196
  }
135
- return inherited;
197
+ if (touched.size === 0)
198
+ return state;
199
+ const listedById = refoldTouched(touched, state.listedById, sequences, grouped, failures);
200
+ return {
201
+ failures,
202
+ instances: [...listedById.values()],
203
+ events: added.length === 0 ? state.events : [...state.events, ...added],
204
+ inherited,
205
+ deferredInstanceIds: deferred,
206
+ sequences,
207
+ own,
208
+ grouped,
209
+ listedById,
210
+ };
136
211
  }
@@ -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
+ };