@atolis-hq/wake 0.4.103 → 0.4.105

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 +3 -0
  2. package/dist/src/activities/contracts/activity.d.ts +16 -0
  3. package/dist/src/bootstrap/artifact-mcp.js +20 -1
  4. package/dist/src/bootstrap/config/root-schema.d.ts +16 -0
  5. package/dist/src/bootstrap/delegation-authority.js +17 -0
  6. package/dist/src/bootstrap/surface-api-delivery.js +25 -0
  7. package/dist/src/bootstrap/version.js +1 -1
  8. package/dist/src/control-plane/application/activation-scheduler-ports.d.ts +3 -1
  9. package/dist/src/control-plane/application/advance-once-dispatch.js +4 -2
  10. package/dist/src/execution/application/candidate-workspaces.d.ts +13 -0
  11. package/dist/src/execution/application/candidate-workspaces.js +75 -0
  12. package/dist/src/execution/application/execution-service.js +27 -11
  13. package/dist/src/execution/application/run-lifecycle.js +1 -0
  14. package/dist/src/execution/contracts/candidate.d.ts +31 -0
  15. package/dist/src/execution/contracts/candidate.js +40 -0
  16. package/dist/src/execution/contracts/commands.d.ts +2 -0
  17. package/dist/src/execution/contracts/events.d.ts +11 -0
  18. package/dist/src/execution/contracts/events.js +2 -0
  19. package/dist/src/execution/contracts/repository-assignment.d.ts +5 -0
  20. package/dist/src/execution/contracts/repository-assignment.js +8 -0
  21. package/dist/src/execution/contracts/views.d.ts +2 -0
  22. package/dist/src/execution/contracts/vocabulary.d.ts +5 -0
  23. package/dist/src/execution/contracts/vocabulary.js +4 -0
  24. package/dist/src/execution/contracts/workspace.d.ts +6 -0
  25. package/dist/src/execution/index.d.ts +1 -0
  26. package/dist/src/execution/index.js +1 -0
  27. package/dist/src/execution/infrastructure/workspace/git-source.d.ts +2 -2
  28. package/dist/src/execution/infrastructure/workspace/git-source.js +18 -1
  29. package/dist/src/execution/infrastructure/workspace/git-workspace.d.ts +2 -4
  30. package/dist/src/execution/infrastructure/workspace/git-workspace.js +12 -1
  31. package/dist/src/orchestration/application/conversation-command-reactor.js +25 -0
  32. package/dist/src/orchestration/application/delegated-work.d.ts +14 -0
  33. package/dist/src/orchestration/application/delegated-work.js +63 -20
  34. package/dist/src/orchestration/application/delegation-attention-escalations.d.ts +11 -0
  35. package/dist/src/orchestration/application/delegation-attention-escalations.js +36 -0
  36. package/dist/src/orchestration/application/delegation-attention-state.d.ts +53 -0
  37. package/dist/src/orchestration/application/delegation-attention-state.js +194 -0
  38. package/dist/src/orchestration/application/delegation-attention.d.ts +58 -0
  39. package/dist/src/orchestration/application/delegation-attention.js +206 -0
  40. package/dist/src/orchestration/application/delegation-commands.d.ts +18 -1
  41. package/dist/src/orchestration/application/delegation-commands.js +18 -1
  42. package/dist/src/orchestration/application/delegation-gate.d.ts +4 -1
  43. package/dist/src/orchestration/application/delegation-gate.js +15 -3
  44. package/dist/src/orchestration/application/delivery-coordinator.d.ts +279 -0
  45. package/dist/src/orchestration/application/delivery-coordinator.js +213 -0
  46. package/dist/src/orchestration/application/delivery-facts-reader.d.ts +9 -0
  47. package/dist/src/orchestration/application/delivery-facts-reader.js +46 -0
  48. package/dist/src/orchestration/application/delivery-preparation.d.ts +15 -0
  49. package/dist/src/orchestration/application/delivery-preparation.js +100 -0
  50. package/dist/src/orchestration/application/delivery-sources.d.ts +10 -0
  51. package/dist/src/orchestration/application/delivery-sources.js +41 -0
  52. package/dist/src/orchestration/application/orchestration-repository.d.ts +3 -1
  53. package/dist/src/orchestration/application/orchestration-repository.js +10 -1
  54. package/dist/src/orchestration/application/orchestration-service.d.ts +284 -1
  55. package/dist/src/orchestration/application/orchestration-service.js +71 -5
  56. package/dist/src/orchestration/contracts/config.d.ts +16 -0
  57. package/dist/src/orchestration/contracts/config.js +7 -1
  58. package/dist/src/orchestration/contracts/delegation-ports.d.ts +4 -0
  59. package/dist/src/orchestration/contracts/delegation.d.ts +76 -2
  60. package/dist/src/orchestration/contracts/delegation.js +54 -1
  61. package/dist/src/orchestration/contracts/delivery-ports.d.ts +9 -0
  62. package/dist/src/orchestration/contracts/delivery-ports.js +1 -0
  63. package/dist/src/orchestration/contracts/delivery.d.ts +252 -0
  64. package/dist/src/orchestration/contracts/delivery.js +134 -0
  65. package/dist/src/orchestration/contracts/event-decoder.js +17 -2
  66. package/dist/src/orchestration/contracts/event-factory.js +13 -1
  67. package/dist/src/orchestration/contracts/events.d.ts +23 -1
  68. package/dist/src/orchestration/contracts/events.js +6 -0
  69. package/dist/src/orchestration/contracts/views.d.ts +9 -0
  70. package/dist/src/orchestration/contracts/vocabulary.d.ts +65 -0
  71. package/dist/src/orchestration/contracts/vocabulary.js +59 -0
  72. package/dist/src/orchestration/domain/compiler.js +2 -0
  73. package/dist/src/orchestration/domain/delivery-candidate.d.ts +9 -0
  74. package/dist/src/orchestration/domain/delivery-candidate.js +92 -0
  75. package/dist/src/orchestration/domain/delivery-facts.d.ts +83 -0
  76. package/dist/src/orchestration/domain/delivery-facts.js +34 -0
  77. package/dist/src/orchestration/domain/delivery-qa.d.ts +32 -0
  78. package/dist/src/orchestration/domain/delivery-qa.js +77 -0
  79. package/dist/src/orchestration/domain/delivery-replacement.d.ts +9 -0
  80. package/dist/src/orchestration/domain/delivery-replacement.js +54 -0
  81. package/dist/src/orchestration/domain/delivery-selection.d.ts +17 -0
  82. package/dist/src/orchestration/domain/delivery-selection.js +132 -0
  83. package/dist/src/orchestration/domain/delivery-workflow-policy.d.ts +4 -0
  84. package/dist/src/orchestration/domain/delivery-workflow-policy.js +13 -0
  85. package/dist/src/orchestration/domain/operator-retry-policy.js +24 -13
  86. package/dist/src/orchestration/domain/workflow-instance-events.d.ts +2 -0
  87. package/dist/src/orchestration/domain/workflow-instance-events.js +39 -0
  88. package/dist/src/orchestration/index.d.ts +5 -3
  89. package/dist/src/orchestration/index.js +3 -2
  90. package/dist/src/surfaces/api/contracts/work.d.ts +16 -0
  91. package/dist/src/surfaces/mcp/delegation.js +51 -1
  92. package/dist/src/surfaces/web-assets/assets/index-BfhxlN_h.js +1192 -0
  93. package/dist/src/surfaces/web-assets/index.html +1 -1
  94. package/package.json +1 -1
  95. package/dist/src/surfaces/web-assets/assets/index-C5R-aWzH.js +0 -1192
@@ -0,0 +1,10 @@
1
+ import type { DelegationRepositories } from '../contracts/delegation-ports.js';
2
+ import { type DeliveryCandidate } from '../contracts/delivery.js';
3
+ import type { WorkflowInstanceView } from '../contracts/views.js';
4
+ import { type DeliveryFacts } from '../domain/delivery-facts.js';
5
+ /**
6
+ * Proves every candidate commit is fetchable from its authorized repository at the recorded
7
+ * revision. A retained ref is resolved by name, so a moved or deleted ref fails; a selected
8
+ * output is fetched by its exact commit. A local SHA alone is never a durable source.
9
+ */
10
+ export declare function verifyCandidateSources(parent: WorkflowInstanceView, repositories: DelegationRepositories | undefined, candidate: DeliveryCandidate, facts: DeliveryFacts): Promise<void>;
@@ -0,0 +1,41 @@
1
+ import { RepositorySourceError, RepositorySourceFailure } from '../../execution/index.js';
2
+ import { DeliveryRejectionError } from '../contracts/delivery.js';
3
+ import { CandidateSourceKind, DeliveryRejection } from '../contracts/vocabulary.js';
4
+ import { currentSelection, isChange } from '../domain/delivery-facts.js';
5
+ /**
6
+ * Proves every candidate commit is fetchable from its authorized repository at the recorded
7
+ * revision. A retained ref is resolved by name, so a moved or deleted ref fails; a selected
8
+ * output is fetched by its exact commit. A local SHA alone is never a durable source.
9
+ */
10
+ export async function verifyCandidateSources(parent, repositories, candidate, facts) {
11
+ for (const entry of candidate.repositories) {
12
+ const source = entry.source.kind === CandidateSourceKind.RetainedRef
13
+ ? { sourceRef: entry.source.ref }
14
+ : { sourceRef: branchOf(facts, entry.contributions[0]), sourceRevision: entry.revision };
15
+ const unavailable = (detail) => new DeliveryRejectionError(DeliveryRejection.SourceUnavailable, `Candidate source ${source.sourceRef} in ${entry.resourceId} is unavailable: ${detail}`);
16
+ if (repositories === undefined)
17
+ throw unavailable('source verification is not configured');
18
+ let resolved;
19
+ try {
20
+ resolved = await repositories.resolve(parent, {
21
+ resourceId: entry.resourceId,
22
+ pullRequestBase: entry.pullRequestBase,
23
+ ...source,
24
+ });
25
+ }
26
+ catch (error) {
27
+ const detail = error instanceof Error ? error.message : 'unknown source verification failure';
28
+ if (error instanceof RepositorySourceError &&
29
+ error.kind === RepositorySourceFailure.RefUnavailable)
30
+ throw unavailable(detail);
31
+ throw unavailable('operational fetch/check failed; candidate not verified: ' + detail);
32
+ }
33
+ if (resolved.sourceRevision.toLowerCase() !== entry.revision.toLowerCase())
34
+ throw unavailable(`it now points at ${resolved.sourceRevision}, not ${entry.revision}`);
35
+ }
36
+ }
37
+ function branchOf(facts, contribution) {
38
+ const output = currentSelection(facts)?.entries.find((entry) => entry.childWorkItemId === contribution?.childWorkItemId &&
39
+ entry.output.name === contribution.outputName)?.output;
40
+ return output !== undefined && isChange(output) ? output.reference.branch : 'HEAD';
41
+ }
@@ -1,4 +1,5 @@
1
1
  import { type EventJournal } from '@atolis-hq/eventing';
2
+ import type { DeliveryCompletionBlock } from '../contracts/delivery.js';
2
3
  import type { WorkflowOrchestrationEvent, WorkflowOrchestrationEventData } from '../contracts/events.js';
3
4
  import type { WorkflowInstanceView } from '../contracts/views.js';
4
5
  type ListedInstance = {
@@ -7,8 +8,9 @@ type ListedInstance = {
7
8
  };
8
9
  export declare class OrchestrationRepository {
9
10
  private readonly journal;
11
+ private readonly completionBlock?;
10
12
  private readonly listed;
11
- constructor(journal: EventJournal);
13
+ constructor(journal: EventJournal, completionBlock?: ((id: string) => Promise<DeliveryCompletionBlock | undefined>) | undefined);
12
14
  load(id: string): Promise<{
13
15
  sequence: number;
14
16
  view: WorkflowInstanceView | null;
@@ -6,9 +6,11 @@ import { isWorkflowInstanceStream, workflowInstanceStream } from '../contracts/s
6
6
  import { foldWorkflowInstance } from '../domain/workflow-instance.js';
7
7
  export class OrchestrationRepository {
8
8
  journal;
9
+ completionBlock;
9
10
  listed;
10
- constructor(journal) {
11
+ constructor(journal, completionBlock) {
11
12
  this.journal = journal;
13
+ this.completionBlock = completionBlock;
12
14
  this.listed = cachedJournalView(journal, (events) => {
13
15
  const owned = events.flatMap((entry) => {
14
16
  const decoded = selectWorkflowOrchestrationEvent(entry);
@@ -67,6 +69,13 @@ export class OrchestrationRepository {
67
69
  .filter((event) => drafts.some((draft) => draft.eventId === event.event.eventId))
68
70
  .map(decodeOrchestrationEvent)
69
71
  .filter(isWorkflowEvent);
72
+ if (drafts.some((draft) => draft.eventType === OrchestrationEventType.InstanceCompleted)) {
73
+ const block = await this.completionBlock?.(id);
74
+ if (block !== undefined)
75
+ drafts = drafts.map((draft) => draft.eventType === OrchestrationEventType.InstanceCompleted
76
+ ? { ...draft, eventType: OrchestrationEventType.InstanceBlocked, payload: block }
77
+ : draft);
78
+ }
70
79
  const events = await this.journal.appendToStream(workflowInstanceStream(workflowInstanceId(id)), sequence, drafts);
71
80
  return events.map(decodeOrchestrationEvent).filter(isWorkflowEvent);
72
81
  }
@@ -1,5 +1,6 @@
1
1
  import type { DelegationArtifacts, DelegationAuthority, DelegationRepositories } from '../contracts/delegation-ports.js';
2
- import type { DelegationCaller, DelegationSubmission } from '../contracts/delegation.js';
2
+ import type { DelegationAttentionReply, DelegationCaller, DelegationSubmission } from '../contracts/delegation.js';
3
+ import type { DeliveryCandidateCommand, DeliveryQaCommand, DeliverySelectionCommand } from '../contracts/delivery.js';
3
4
  import type { ResourceTransitionEvidence } from './resource-transition-evidence.js';
4
5
  import type { CommandContext, EventJournal, ProjectionStore } from '@atolis-hq/eventing';
5
6
  import { type ActivationId, type ActivityOutcome } from '../../activities/index.js';
@@ -17,7 +18,9 @@ export declare class OrchestrationService {
17
18
  private readonly delegationCommands;
18
19
  private readonly delegationGate;
19
20
  private readonly delegatedWork;
21
+ private readonly delivery;
20
22
  private readonly prerequisiteReasons;
23
+ private readonly resumeClarification;
21
24
  private readonly repository;
22
25
  private readonly deferredSignals;
23
26
  private readonly startWorkflow;
@@ -33,6 +36,95 @@ export declare class OrchestrationService {
33
36
  private readonly definitions;
34
37
  private readonly work;
35
38
  constructor(journal: EventJournal, work: WorkService, definitions: Readonly<Record<string, CompiledWorkflow>>, projections?: ProjectionStore, isAgentActivity?: AgentActivityClassifier, delegation?: DelegationDependenciesFactory);
39
+ deliveryStateFor(workflowInstanceId: string): Promise<{
40
+ required: {
41
+ cohortId: string;
42
+ assignmentId: string;
43
+ outputName: string;
44
+ childWorkItemId: WorkItemId;
45
+ }[];
46
+ selection: {
47
+ requestId: string;
48
+ revision: number;
49
+ entries: {
50
+ cohortId: string;
51
+ assignmentId: string;
52
+ childWorkItemId: WorkItemId;
53
+ output: {
54
+ name: string;
55
+ reference: {
56
+ workItemId: WorkItemId;
57
+ revisionId: string;
58
+ } | {
59
+ workItemId: WorkItemId;
60
+ resourceId: string;
61
+ repositoryResourceId: string;
62
+ revision: string;
63
+ branch: string;
64
+ pullRequestBase: string;
65
+ runId: string;
66
+ baseRevision?: string | undefined;
67
+ merged?: true | undefined;
68
+ };
69
+ };
70
+ replaces?: {
71
+ childWorkItemId: WorkItemId;
72
+ outputName: string;
73
+ } | undefined;
74
+ }[];
75
+ } | null;
76
+ history: readonly {
77
+ qaId: string;
78
+ candidateId: string;
79
+ verdict: "blocked" | "pass" | "fail";
80
+ revisions: {
81
+ resourceId: string;
82
+ revision: string;
83
+ }[];
84
+ environment: {
85
+ available: boolean;
86
+ recipe?: string | undefined;
87
+ };
88
+ findings: string[];
89
+ evidence?: {
90
+ workItemId: WorkItemId;
91
+ revisionId: string;
92
+ }[] | undefined;
93
+ exhausted?: boolean | undefined;
94
+ runId?: string | undefined;
95
+ activationId?: string | undefined;
96
+ }[];
97
+ completion: import("../domain/delivery-qa.js").CompletionDecision;
98
+ selectionRevision: number;
99
+ stale: readonly string[];
100
+ candidate: import("../contracts/delivery.js").DeliveryCandidate | null;
101
+ candidateCurrent: boolean;
102
+ qa: import("../contracts/delivery.js").DeliveryQa | null;
103
+ qaEffective: boolean;
104
+ repair: {
105
+ readonly failedRounds: number;
106
+ readonly exhausted: boolean;
107
+ readonly unresolvedFindings: readonly string[];
108
+ };
109
+ }>;
110
+ deliveryQaPreparation(workflowInstanceId: string): Promise<{
111
+ candidateId: string;
112
+ selectionRevision: number;
113
+ criteria: string[];
114
+ inputs: {
115
+ workItemId: string;
116
+ outputName: string;
117
+ revision: string;
118
+ }[];
119
+ repositories: {
120
+ resourceId: string;
121
+ sourceRef: string;
122
+ sourceRevision: string;
123
+ pullRequestBase: string;
124
+ requiredSourceRef?: string | undefined;
125
+ }[];
126
+ recipe?: string | undefined;
127
+ } | undefined>;
36
128
  repositoryAuthority(workItemId: string): Promise<string[] | undefined>;
37
129
  repositoryAssignment(workItemId: string): Promise<{
38
130
  resourceId: string;
@@ -81,6 +173,10 @@ export declare class OrchestrationService {
81
173
  cohortId?: string | undefined;
82
174
  useAsBase?: boolean | undefined;
83
175
  }[] | undefined;
176
+ replaces?: {
177
+ cohortId: string;
178
+ assignmentId: string;
179
+ } | undefined;
84
180
  repository?: {
85
181
  resourceId: string;
86
182
  sourceRef: string;
@@ -92,16 +188,182 @@ export declare class OrchestrationService {
92
188
  planRevision?: number | undefined;
93
189
  maxConcurrentRuns?: number | undefined;
94
190
  }>;
191
+ selectDelivery(caller: DelegationCaller, input: DeliverySelectionCommand, context: CommandContext): Promise<{
192
+ selection: {
193
+ requestId: string;
194
+ revision: number;
195
+ entries: {
196
+ cohortId: string;
197
+ assignmentId: string;
198
+ childWorkItemId: WorkItemId;
199
+ output: {
200
+ name: string;
201
+ reference: {
202
+ workItemId: WorkItemId;
203
+ revisionId: string;
204
+ } | {
205
+ workItemId: WorkItemId;
206
+ resourceId: string;
207
+ repositoryResourceId: string;
208
+ revision: string;
209
+ branch: string;
210
+ pullRequestBase: string;
211
+ runId: string;
212
+ baseRevision?: string | undefined;
213
+ merged?: true | undefined;
214
+ };
215
+ };
216
+ replaces?: {
217
+ childWorkItemId: WorkItemId;
218
+ outputName: string;
219
+ } | undefined;
220
+ }[];
221
+ };
222
+ replay: boolean;
223
+ }>;
224
+ recordDeliveryCandidate(caller: DelegationCaller, input: DeliveryCandidateCommand, context: CommandContext): Promise<{
225
+ candidate: {
226
+ candidateId: string;
227
+ selectionRevision: number;
228
+ repositories: {
229
+ resourceId: string;
230
+ revision: string;
231
+ pullRequestBase: string;
232
+ source: {
233
+ kind: "output";
234
+ tip: {
235
+ childWorkItemId: WorkItemId;
236
+ outputName: string;
237
+ };
238
+ } | {
239
+ kind: "retained-ref";
240
+ ref: string;
241
+ };
242
+ contributions: {
243
+ childWorkItemId: WorkItemId;
244
+ outputName: string;
245
+ }[];
246
+ }[];
247
+ context: {
248
+ childWorkItemId: WorkItemId;
249
+ outputName: string;
250
+ }[];
251
+ criteria: string[];
252
+ recipe?: string | undefined;
253
+ };
254
+ replay: boolean;
255
+ }>;
256
+ recordDeliveryQa(caller: DelegationCaller, input: DeliveryQaCommand, context: CommandContext): Promise<{
257
+ qa: {
258
+ qaId: string;
259
+ candidateId: string;
260
+ verdict: "blocked" | "pass" | "fail";
261
+ revisions: {
262
+ resourceId: string;
263
+ revision: string;
264
+ }[];
265
+ environment: {
266
+ available: boolean;
267
+ recipe?: string | undefined;
268
+ };
269
+ findings: string[];
270
+ evidence?: {
271
+ workItemId: WorkItemId;
272
+ revisionId: string;
273
+ }[] | undefined;
274
+ exhausted?: boolean | undefined;
275
+ runId?: string | undefined;
276
+ activationId?: string | undefined;
277
+ };
278
+ replay: boolean;
279
+ }>;
95
280
  inspectDelegation(caller: DelegationCaller, context: CommandContext): Promise<{
281
+ delivery: {
282
+ required: {
283
+ cohortId: string;
284
+ assignmentId: string;
285
+ outputName: string;
286
+ childWorkItemId: WorkItemId;
287
+ }[];
288
+ selection: {
289
+ requestId: string;
290
+ revision: number;
291
+ entries: {
292
+ cohortId: string;
293
+ assignmentId: string;
294
+ childWorkItemId: WorkItemId;
295
+ output: {
296
+ name: string;
297
+ reference: {
298
+ workItemId: WorkItemId;
299
+ revisionId: string;
300
+ } | {
301
+ workItemId: WorkItemId;
302
+ resourceId: string;
303
+ repositoryResourceId: string;
304
+ revision: string;
305
+ branch: string;
306
+ pullRequestBase: string;
307
+ runId: string;
308
+ baseRevision?: string | undefined;
309
+ merged?: true | undefined;
310
+ };
311
+ };
312
+ replaces?: {
313
+ childWorkItemId: WorkItemId;
314
+ outputName: string;
315
+ } | undefined;
316
+ }[];
317
+ } | null;
318
+ history: readonly {
319
+ qaId: string;
320
+ candidateId: string;
321
+ verdict: "blocked" | "pass" | "fail";
322
+ revisions: {
323
+ resourceId: string;
324
+ revision: string;
325
+ }[];
326
+ environment: {
327
+ available: boolean;
328
+ recipe?: string | undefined;
329
+ };
330
+ findings: string[];
331
+ evidence?: {
332
+ workItemId: WorkItemId;
333
+ revisionId: string;
334
+ }[] | undefined;
335
+ exhausted?: boolean | undefined;
336
+ runId?: string | undefined;
337
+ activationId?: string | undefined;
338
+ }[];
339
+ completion: import("../domain/delivery-qa.js").CompletionDecision;
340
+ selectionRevision: number;
341
+ stale: readonly string[];
342
+ candidate: import("../contracts/delivery.js").DeliveryCandidate | null;
343
+ candidateCurrent: boolean;
344
+ qa: import("../contracts/delivery.js").DeliveryQa | null;
345
+ qaEffective: boolean;
346
+ repair: {
347
+ readonly failedRounds: number;
348
+ readonly exhausted: boolean;
349
+ readonly unresolvedFindings: readonly string[];
350
+ };
351
+ };
96
352
  policy: {
97
353
  workflows: string[];
98
354
  maxDepth: number;
99
355
  maxDescendants: number;
100
356
  maxConcurrentRuns: number;
101
357
  repositories?: string[] | undefined;
358
+ completion?: "qa-approved" | "merge-required" | undefined;
359
+ qa?: {
360
+ stage: string;
361
+ recipe?: string | undefined;
362
+ } | undefined;
102
363
  } | null;
103
364
  repositories: string[];
104
365
  planRevision: number;
366
+ attention: import("./delegation-attention-state.js").OpenAttention | null;
105
367
  tree: {
106
368
  settled: boolean;
107
369
  failureReason: string | undefined;
@@ -164,6 +426,10 @@ export declare class OrchestrationService {
164
426
  cohortId?: string | undefined;
165
427
  useAsBase?: boolean | undefined;
166
428
  }[] | undefined;
429
+ replaces?: {
430
+ cohortId: string;
431
+ assignmentId: string;
432
+ } | undefined;
167
433
  repository?: {
168
434
  resourceId: string;
169
435
  sourceRef: string;
@@ -247,6 +513,10 @@ export declare class OrchestrationService {
247
513
  cohortId?: string | undefined;
248
514
  useAsBase?: boolean | undefined;
249
515
  }[] | undefined;
516
+ replaces?: {
517
+ cohortId: string;
518
+ assignmentId: string;
519
+ } | undefined;
250
520
  repository?: {
251
521
  resourceId: string;
252
522
  sourceRef: string;
@@ -300,6 +570,19 @@ export declare class OrchestrationService {
300
570
  activationId: ActivationId;
301
571
  outcome: ActivityOutcome;
302
572
  }, context: CommandContext): Promise<WorkflowInstanceView>;
573
+ /**
574
+ * Every ending restores the cohort wait, so independent members keep running and their
575
+ * results stay joinable (a join that completed meanwhile then proceeds). A structured
576
+ * human question is also recorded as an accepted outcome, which the ordinary publication
577
+ * route delivers to a human; a failed assessment run is recorded and re-raised a bounded
578
+ * number of times. The cohort is never settled or cancelled by the assessment itself.
579
+ */
580
+ private endAttention;
581
+ /** Delegated children still blocked on a question this work item's parent escalated to a human. */
582
+ escalatedReplyTargets(workItemId: WorkItemId): Promise<WorkItemId[]>;
583
+ /** The open attention request when `activationId` is the attention activation, else null. */
584
+ openDelegationAttention(id: WorkflowInstanceId, activationId: ActivationId): Promise<import("./delegation-attention-state.js").OpenAttention | null>;
585
+ respondToDelegationAttention(caller: DelegationCaller, reply: DelegationAttentionReply, context: CommandContext): Promise<import("./delegation-attention-state.js").OpenAttention | null>;
303
586
  waitForSignal(workflowInstanceId: WorkflowInstanceId, expectation: SignalExpectation, context: CommandContext): Promise<WorkflowInstanceView>;
304
587
  acceptSignal(workflowInstanceId: WorkflowInstanceId, signal: OrchestrationSignal, context: CommandContext): Promise<WorkflowInstanceView>;
305
588
  setAcceptSignalOperationCoordinator(coordinator: OperationCoordinator): void;
@@ -3,6 +3,7 @@ import { DeferredSignals } from './deferred-signals.js';
3
3
  import { DelegatedWork } from './delegated-work.js';
4
4
  import { DelegationCommands } from './delegation-commands.js';
5
5
  import { DelegationGate } from './delegation-gate.js';
6
+ import { DeliveryCoordinator } from './delivery-coordinator.js';
6
7
  import { expireTimedOutWaits } from './expire-timed-out-waits.js';
7
8
  import { recoverPolicyBlockedMerges } from './policy-blocked-merge-recovery.js';
8
9
  import { WorkStatus, } from '../../work/index.js';
@@ -17,6 +18,7 @@ import { AcceptSignal } from './accept-signal.js';
17
18
  import { AdvanceWorkflow } from './advance-workflow.js';
18
19
  import { applyBuiltInConversationCommand, continuationCommandRejection, conversationCommand, } from './conversation-command.js';
19
20
  import { CoordinationClaims } from './coordination-claims.js';
21
+ import { attentionVerdict } from './delegation-attention-state.js';
20
22
  import { GroupBudgetRecorder } from './group-budget-recorder.js';
21
23
  import { workflowsByWorkItemProjection } from './orchestration-projection.js';
22
24
  import { OrchestrationRepository } from './orchestration-repository.js';
@@ -28,7 +30,9 @@ export class OrchestrationService {
28
30
  delegationCommands;
29
31
  delegationGate;
30
32
  delegatedWork;
33
+ delivery;
31
34
  prerequisiteReasons = (ids, snapshot) => this.delegatedWork.prerequisites.reasons(ids, snapshot);
35
+ resumeClarification = (id, context) => this.advanceWorkflow.resumeNeedsClarificationStage(id, context);
32
36
  repository;
33
37
  deferredSignals;
34
38
  startWorkflow;
@@ -43,11 +47,13 @@ export class OrchestrationService {
43
47
  journal;
44
48
  definitions;
45
49
  work;
50
+ // Composition root for the module's services; splitting it would only scatter the wiring.
51
+ // eslint-disable-next-line max-lines-per-function
46
52
  constructor(journal, work, definitions, projections, isAgentActivity, delegation) {
47
53
  this.projections = projections;
48
54
  this.journal = journal;
49
55
  this.work = work;
50
- const repository = new OrchestrationRepository(journal);
56
+ const repository = new OrchestrationRepository(journal, (id) => this.delivery.completionBlock(id));
51
57
  this.repository = repository;
52
58
  this.delegationGate = new DelegationGate(repository, work, delegation === undefined ? undefined : this.prerequisiteReasons);
53
59
  const dependencies = delegation?.({
@@ -61,8 +67,11 @@ export class OrchestrationService {
61
67
  artifacts: dependencies?.artifacts ?? unavailableArtifacts,
62
68
  repositories: dependencies?.repositories,
63
69
  runHasEnded: dependencies?.runHasEnded ?? unavailableRunCompletion,
70
+ supportsAttention: isAgentActivity,
71
+ resumeChild: this.resumeClarification,
64
72
  });
65
73
  this.delegationCommands = new DelegationCommands(repository, work, this.startWorkflow, this.definitions, this.delegatedWork, dependencies?.authority ?? unavailableDelegationAuthority);
74
+ this.delivery = new DeliveryCoordinator(repository, deliveryDependencies(dependencies, async (parent) => this.startWorkflow.definitionFor(parent)));
66
75
  this.advanceWorkflow = new AdvanceWorkflow(repository, this.startWorkflow, (command, context) => this.acceptOutcome(command, context), isAgentActivity);
67
76
  this.acceptWorkflowSignal = new AcceptSignal(repository, this.startWorkflow, work);
68
77
  this.deferredSignals = new DeferredSignals(repository, (id, signal, context) => this.delegationGate.run(id, () => this.acceptWorkflowSignal.execute(id, signal, context)), (id, target, evidenceId, context) => this.delegationGate.run(id, () => this.advanceWorkflow.applyResourceTransition(id, target, evidenceId, context)), (ids) => this.delegationGate.fencedAmong(ids));
@@ -73,6 +82,12 @@ export class OrchestrationService {
73
82
  await this.deferredSignals.reconcile(context);
74
83
  });
75
84
  }
85
+ deliveryStateFor(workflowInstanceId) {
86
+ return this.delivery.inspect(workflowInstanceId);
87
+ }
88
+ deliveryQaPreparation(workflowInstanceId) {
89
+ return this.delivery.prepare(workflowInstanceId);
90
+ }
76
91
  repositoryAuthority(workItemId) {
77
92
  return this.delegatedWork.repositoryScope(workItemId);
78
93
  }
@@ -84,11 +99,24 @@ export class OrchestrationService {
84
99
  (item === undefined || view.workItemId === item) &&
85
100
  view.acceptedOutcomes.some((accepted) => accepted === id));
86
101
  }
87
- submitDelegation(caller, input, context) {
102
+ async submitDelegation(caller, input, context) {
103
+ await this.delivery.assertReplacements(caller, input);
88
104
  return this.delegationCommands.submit(caller, input, context);
89
105
  }
90
- inspectDelegation(caller, context) {
91
- return this.delegationCommands.inspect(caller, context);
106
+ selectDelivery(caller, input, context) {
107
+ return this.delivery.select(caller, input, context);
108
+ }
109
+ recordDeliveryCandidate(caller, input, context) {
110
+ return this.delivery.recordCandidate(caller, input, context);
111
+ }
112
+ recordDeliveryQa(caller, input, context) {
113
+ return this.delivery.recordQa(caller, input, context);
114
+ }
115
+ async inspectDelegation(caller, context) {
116
+ return {
117
+ ...(await this.delegationCommands.inspect(caller, context)),
118
+ delivery: await this.delivery.inspectFor(caller),
119
+ };
92
120
  }
93
121
  deliveryTree(id) {
94
122
  return this.delegatedWork.inspect(id);
@@ -125,7 +153,38 @@ export class OrchestrationService {
125
153
  return this.transitionWatchChildren(context, () => this.delegationGate.outcome(command.workflowInstanceId, command.activationId, () => this.acceptActivityOutcome.execute(command, context), async () => {
126
154
  await this.reconcileChildCompletions(context);
127
155
  return (await this.repository.loadRequired(command.workflowInstanceId)).view;
128
- }, async (view) => view));
156
+ }, async (view) => view, () => this.endAttention(command, context)));
157
+ }
158
+ /**
159
+ * Every ending restores the cohort wait, so independent members keep running and their
160
+ * results stay joinable (a join that completed meanwhile then proceeds). A structured
161
+ * human question is also recorded as an accepted outcome, which the ordinary publication
162
+ * route delivers to a human; a failed assessment run is recorded and re-raised a bounded
163
+ * number of times. The cohort is never settled or cancelled by the assessment itself.
164
+ */
165
+ async endAttention(command, context) {
166
+ await this.delegatedWork.attention.resolve(command.workflowInstanceId, command.activationId, context, attentionVerdict(command.outcome));
167
+ await this.delegatedWork.reconcile(context);
168
+ return (await this.repository.loadRequired(command.workflowInstanceId)).view;
169
+ }
170
+ /** Delegated children still blocked on a question this work item's parent escalated to a human. */
171
+ async escalatedReplyTargets(workItemId) {
172
+ const targets = [];
173
+ for (const parent of await this.advanceWorkflow.listAll())
174
+ if (parent.workItemId === workItemId)
175
+ for (const target of await this.delegatedWork.attention.escalatedTargets(parent))
176
+ targets.push(target.childWorkItemId);
177
+ return targets;
178
+ }
179
+ /** The open attention request when `activationId` is the attention activation, else null. */
180
+ async openDelegationAttention(id, activationId) {
181
+ const view = (await this.repository.load(id)).view;
182
+ if (view?.delegationAttention?.activationId !== activationId)
183
+ return null;
184
+ return this.delegatedWork.attention.current(view);
185
+ }
186
+ respondToDelegationAttention(caller, reply, context) {
187
+ return this.delegationCommands.respond(caller, reply, context);
129
188
  }
130
189
  waitForSignal(workflowInstanceId, expectation, context) {
131
190
  return this.transitionWatchChildren(context, async () => {
@@ -407,6 +466,13 @@ function isReviewConversationCommand(command) {
407
466
  async function unavailableRunCompletion() {
408
467
  throw new Error('Delegation adapters unavailable');
409
468
  }
469
+ function deliveryDependencies(dependencies, definitionFor) {
470
+ return {
471
+ authority: dependencies?.authority ?? unavailableDelegationAuthority,
472
+ repositories: dependencies?.repositories,
473
+ definitionFor,
474
+ };
475
+ }
410
476
  const unavailableArtifacts = {
411
477
  validateInputs: unavailableRunCompletion,
412
478
  registerChild: unavailableRunCompletion,
@@ -220,6 +220,14 @@ export declare const delegationPolicySchema: z.ZodObject<{
220
220
  maxDepth: z.ZodNumber;
221
221
  maxDescendants: z.ZodNumber;
222
222
  maxConcurrentRuns: z.ZodNumber;
223
+ completion: z.ZodOptional<z.ZodEnum<{
224
+ readonly QaApproved: "qa-approved";
225
+ readonly MergeRequired: "merge-required";
226
+ }>>;
227
+ qa: z.ZodOptional<z.ZodObject<{
228
+ stage: z.ZodString;
229
+ recipe: z.ZodOptional<z.ZodString>;
230
+ }, z.core.$strict>>;
223
231
  }, z.core.$strict>;
224
232
  export type DelegationPolicy = z.infer<typeof delegationPolicySchema>;
225
233
  export declare const workflowDefinitionConfigSchema: z.ZodObject<{
@@ -230,6 +238,14 @@ export declare const workflowDefinitionConfigSchema: z.ZodObject<{
230
238
  maxDepth: z.ZodNumber;
231
239
  maxDescendants: z.ZodNumber;
232
240
  maxConcurrentRuns: z.ZodNumber;
241
+ completion: z.ZodOptional<z.ZodEnum<{
242
+ readonly QaApproved: "qa-approved";
243
+ readonly MergeRequired: "merge-required";
244
+ }>>;
245
+ qa: z.ZodOptional<z.ZodObject<{
246
+ stage: z.ZodString;
247
+ recipe: z.ZodOptional<z.ZodString>;
248
+ }, z.core.$strict>>;
233
249
  }, z.core.$strict>>;
234
250
  commands: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
235
251
  activity: z.ZodString;
@@ -1,5 +1,5 @@
1
1
  import { z } from 'zod';
2
- import { ApprovalAuthorityKind, ConversationSurfaceCapability, WorkflowStatus, } from './vocabulary.js';
2
+ import { ApprovalAuthorityKind, ConversationSurfaceCapability, DeliveryCompletion, 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';
@@ -158,6 +158,12 @@ export const delegationPolicySchema = z
158
158
  maxDepth: z.number().int().positive(),
159
159
  maxDescendants: z.number().int().positive(),
160
160
  maxConcurrentRuns: z.number().int().positive(),
161
+ /** Final gate for the parent: QA approval alone (default) or QA plus governed integration. */
162
+ completion: z.enum(DeliveryCompletion).optional(),
163
+ qa: z
164
+ .object({ stage: identifier, recipe: z.string().trim().min(1).optional() })
165
+ .strict()
166
+ .optional(),
161
167
  })
162
168
  .strict();
163
169
  export const workflowDefinitionConfigSchema = z
@@ -15,6 +15,10 @@ export interface DelegationArtifacts {
15
15
  qualifyingOutputs(child: WorkflowInstanceView, outputs: DelegatedAssignment['outputs']): Promise<DelegationResult['outputs'] | null>;
16
16
  }
17
17
  export interface DelegationAuthority {
18
+ assertQaCaller?(caller: DelegationCaller, candidateId: string, selectionRevision: number, revisions: readonly {
19
+ resourceId: string;
20
+ revision: string;
21
+ }[]): Promise<void>;
18
22
  assertCaller(caller: DelegationCaller, parent: WorkflowInstanceView): Promise<void>;
19
23
  repositories(parent: WorkflowInstanceView): Promise<readonly string[]>;
20
24
  /**