@atolis-hq/wake 0.4.104 → 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 (84) 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/config/root-schema.d.ts +16 -0
  4. package/dist/src/bootstrap/delegation-authority.js +17 -0
  5. package/dist/src/bootstrap/surface-api-delivery.js +25 -0
  6. package/dist/src/bootstrap/version.js +1 -1
  7. package/dist/src/control-plane/application/activation-scheduler-ports.d.ts +3 -1
  8. package/dist/src/control-plane/application/advance-once-dispatch.js +4 -2
  9. package/dist/src/execution/application/candidate-workspaces.d.ts +13 -0
  10. package/dist/src/execution/application/candidate-workspaces.js +75 -0
  11. package/dist/src/execution/application/execution-service.js +27 -11
  12. package/dist/src/execution/application/run-lifecycle.js +1 -0
  13. package/dist/src/execution/contracts/candidate.d.ts +31 -0
  14. package/dist/src/execution/contracts/candidate.js +40 -0
  15. package/dist/src/execution/contracts/commands.d.ts +2 -0
  16. package/dist/src/execution/contracts/events.d.ts +11 -0
  17. package/dist/src/execution/contracts/events.js +2 -0
  18. package/dist/src/execution/contracts/repository-assignment.d.ts +5 -0
  19. package/dist/src/execution/contracts/repository-assignment.js +8 -0
  20. package/dist/src/execution/contracts/views.d.ts +2 -0
  21. package/dist/src/execution/contracts/vocabulary.d.ts +5 -0
  22. package/dist/src/execution/contracts/vocabulary.js +4 -0
  23. package/dist/src/execution/contracts/workspace.d.ts +6 -0
  24. package/dist/src/execution/index.d.ts +1 -0
  25. package/dist/src/execution/index.js +1 -0
  26. package/dist/src/execution/infrastructure/workspace/git-source.d.ts +2 -2
  27. package/dist/src/execution/infrastructure/workspace/git-source.js +18 -1
  28. package/dist/src/execution/infrastructure/workspace/git-workspace.d.ts +2 -4
  29. package/dist/src/execution/infrastructure/workspace/git-workspace.js +12 -1
  30. package/dist/src/orchestration/application/delegated-work.d.ts +5 -0
  31. package/dist/src/orchestration/application/delegated-work.js +10 -0
  32. package/dist/src/orchestration/application/delegation-commands.d.ts +13 -0
  33. package/dist/src/orchestration/application/delivery-coordinator.d.ts +279 -0
  34. package/dist/src/orchestration/application/delivery-coordinator.js +213 -0
  35. package/dist/src/orchestration/application/delivery-facts-reader.d.ts +9 -0
  36. package/dist/src/orchestration/application/delivery-facts-reader.js +46 -0
  37. package/dist/src/orchestration/application/delivery-preparation.d.ts +15 -0
  38. package/dist/src/orchestration/application/delivery-preparation.js +100 -0
  39. package/dist/src/orchestration/application/delivery-sources.d.ts +10 -0
  40. package/dist/src/orchestration/application/delivery-sources.js +41 -0
  41. package/dist/src/orchestration/application/orchestration-repository.d.ts +3 -1
  42. package/dist/src/orchestration/application/orchestration-repository.js +10 -1
  43. package/dist/src/orchestration/application/orchestration-service.d.ts +268 -0
  44. package/dist/src/orchestration/application/orchestration-service.js +33 -4
  45. package/dist/src/orchestration/contracts/config.d.ts +16 -0
  46. package/dist/src/orchestration/contracts/config.js +7 -1
  47. package/dist/src/orchestration/contracts/delegation-ports.d.ts +4 -0
  48. package/dist/src/orchestration/contracts/delegation.d.ts +13 -1
  49. package/dist/src/orchestration/contracts/delegation.js +5 -0
  50. package/dist/src/orchestration/contracts/delivery-ports.d.ts +9 -0
  51. package/dist/src/orchestration/contracts/delivery-ports.js +1 -0
  52. package/dist/src/orchestration/contracts/delivery.d.ts +252 -0
  53. package/dist/src/orchestration/contracts/delivery.js +134 -0
  54. package/dist/src/orchestration/contracts/event-decoder.js +13 -1
  55. package/dist/src/orchestration/contracts/event-factory.js +6 -0
  56. package/dist/src/orchestration/contracts/events.d.ts +8 -0
  57. package/dist/src/orchestration/contracts/events.js +3 -0
  58. package/dist/src/orchestration/contracts/views.d.ts +3 -0
  59. package/dist/src/orchestration/contracts/vocabulary.d.ts +47 -0
  60. package/dist/src/orchestration/contracts/vocabulary.js +43 -0
  61. package/dist/src/orchestration/domain/compiler.js +2 -0
  62. package/dist/src/orchestration/domain/delivery-candidate.d.ts +9 -0
  63. package/dist/src/orchestration/domain/delivery-candidate.js +92 -0
  64. package/dist/src/orchestration/domain/delivery-facts.d.ts +83 -0
  65. package/dist/src/orchestration/domain/delivery-facts.js +34 -0
  66. package/dist/src/orchestration/domain/delivery-qa.d.ts +32 -0
  67. package/dist/src/orchestration/domain/delivery-qa.js +77 -0
  68. package/dist/src/orchestration/domain/delivery-replacement.d.ts +9 -0
  69. package/dist/src/orchestration/domain/delivery-replacement.js +54 -0
  70. package/dist/src/orchestration/domain/delivery-selection.d.ts +17 -0
  71. package/dist/src/orchestration/domain/delivery-selection.js +132 -0
  72. package/dist/src/orchestration/domain/delivery-workflow-policy.d.ts +4 -0
  73. package/dist/src/orchestration/domain/delivery-workflow-policy.js +13 -0
  74. package/dist/src/orchestration/domain/operator-retry-policy.js +24 -13
  75. package/dist/src/orchestration/domain/workflow-instance-events.d.ts +1 -0
  76. package/dist/src/orchestration/domain/workflow-instance-events.js +11 -0
  77. package/dist/src/orchestration/index.d.ts +2 -0
  78. package/dist/src/orchestration/index.js +1 -0
  79. package/dist/src/surfaces/api/contracts/work.d.ts +16 -0
  80. package/dist/src/surfaces/mcp/delegation.js +32 -1
  81. package/dist/src/surfaces/web-assets/assets/index-BfhxlN_h.js +1192 -0
  82. package/dist/src/surfaces/web-assets/index.html +1 -1
  83. package/package.json +1 -1
  84. package/dist/src/surfaces/web-assets/assets/index-C5R-aWzH.js +0 -1192
@@ -0,0 +1,46 @@
1
+ import { OrchestrationEventType } from '../contracts/events.js';
2
+ /**
3
+ * Journal-derived facts for one parent delivery: its cohorts and their selected results, what each
4
+ * child consumed, and the parent's own selection, candidate and QA facts.
5
+ */
6
+ export async function readDeliveryFacts(repository, parent, own) {
7
+ const all = await repository.events();
8
+ const reservations = distinctCohorts(all.flatMap(({ event }) => event.eventType === OrchestrationEventType.DelegationReserved &&
9
+ event.payload.parentWorkflowInstanceId === parent.workflowInstanceId
10
+ ? [event.payload]
11
+ : []));
12
+ const instances = new Map(reservations.flatMap((reservation) => reservation.children.map((child) => [child.workflowInstanceId, child.workItemId])));
13
+ const results = all.flatMap(({ event }) => event.eventType === OrchestrationEventType.DelegationResultSelected &&
14
+ [...instances.values()].includes(event.payload.childWorkItemId)
15
+ ? [event.payload]
16
+ : []);
17
+ const consumed = new Map();
18
+ for (const { event } of all) {
19
+ if (event.eventType !== OrchestrationEventType.DelegationInputsResolved)
20
+ continue;
21
+ // Consumption receipts belong to the parent stream and identify their child in the payload.
22
+ const child = event.payload.childWorkItemId;
23
+ if (![...instances.values()].includes(child))
24
+ continue;
25
+ consumed.set(child, [...(consumed.get(child) ?? []), ...event.payload.consumed]);
26
+ }
27
+ const mine = own.map(({ event }) => event);
28
+ return {
29
+ reservations,
30
+ results,
31
+ consumed,
32
+ selections: mine.flatMap((event) => event.eventType === OrchestrationEventType.DeliverySelectionRevised ? [event.payload] : []),
33
+ candidates: mine.flatMap((event) => event.eventType === OrchestrationEventType.DeliveryCandidateRecorded ? [event.payload] : []),
34
+ qa: mine.flatMap((event) => event.eventType === OrchestrationEventType.DeliveryQaRecorded ? [event.payload] : []),
35
+ };
36
+ }
37
+ function distinctCohorts(reservations) {
38
+ const seen = new Set();
39
+ return reservations.filter((entry) => {
40
+ const key = `${entry.parentWorkflowInstanceId}/${entry.cohortId}`;
41
+ if (seen.has(key))
42
+ return false;
43
+ seen.add(key);
44
+ return true;
45
+ });
46
+ }
@@ -0,0 +1,15 @@
1
+ import { type ExecutionCandidate } from '../../execution/index.js';
2
+ import type { DeliveryDependencies } from '../contracts/delivery-ports.js';
3
+ import type { DeliveryCompletionBlock } from '../contracts/delivery.js';
4
+ import { type DeliveryFacts } from '../domain/delivery-facts.js';
5
+ import type { OrchestrationRepository } from './orchestration-repository.js';
6
+ export declare class DeliveryPreparation {
7
+ private readonly repository;
8
+ private readonly dependencies;
9
+ constructor(repository: OrchestrationRepository, dependencies: DeliveryDependencies);
10
+ completionBlock(id: string): Promise<DeliveryCompletionBlock | undefined>;
11
+ prepare(id: string): Promise<ExecutionCandidate | undefined>;
12
+ noDescendantCapacity(facts: DeliveryFacts): Promise<boolean>;
13
+ private delegatingStage;
14
+ private facts;
15
+ }
@@ -0,0 +1,100 @@
1
+ import { WorkspaceMode } from '../../execution/index.js';
2
+ import { OrchestrationEventType } from '../contracts/events.js';
3
+ import { CandidateSourceKind, DeliveryCompletion } from '../contracts/vocabulary.js';
4
+ import { completionDecision, deliveryState } from '../domain/delivery-qa.js';
5
+ import { readDeliveryFacts } from './delivery-facts-reader.js';
6
+ import { verifyCandidateSources } from './delivery-sources.js';
7
+ export class DeliveryPreparation {
8
+ repository;
9
+ dependencies;
10
+ constructor(repository, dependencies) {
11
+ this.repository = repository;
12
+ this.dependencies = dependencies;
13
+ }
14
+ async completionBlock(id) {
15
+ const parent = (await this.repository.loadRequired(id)).view;
16
+ const definition = await this.dependencies.definitionFor(parent);
17
+ // Existing direct workflows retain their configured routes.
18
+ if (definition.delegation?.qa === undefined && definition.delegation?.completion === undefined)
19
+ return undefined;
20
+ const facts = await this.facts(parent);
21
+ if (facts.reservations.length === 0)
22
+ return undefined;
23
+ const decision = completionDecision(deliveryState(facts), definition.delegation?.completion ?? DeliveryCompletion.QaApproved);
24
+ const retryStage = await this.delegatingStage(id, facts.reservations.at(-1));
25
+ const blocked = (reason) => ({
26
+ reason,
27
+ deliveryGate: { retryStage },
28
+ });
29
+ if (!decision.complete)
30
+ return blocked(decision.reason);
31
+ try {
32
+ await verifyCandidateSources(parent, this.dependencies.repositories, facts.candidates.at(-1), facts);
33
+ return undefined;
34
+ }
35
+ catch (error) {
36
+ return blocked(error instanceof Error ? error.message : 'Operational candidate source verification failed');
37
+ }
38
+ }
39
+ async prepare(id) {
40
+ const parent = (await this.repository.loadRequired(id)).view;
41
+ const policy = (await this.dependencies.definitionFor(parent)).delegation?.qa;
42
+ if (policy === undefined || parent.pendingActivation?.stage !== policy.stage)
43
+ return undefined;
44
+ if (parent.pendingActivation.execution?.workspace !== WorkspaceMode.ReadOnly)
45
+ throw new Error('Candidate QA requires read-only workspaces');
46
+ const facts = await this.facts(parent);
47
+ const state = deliveryState(facts);
48
+ if (!state.candidateCurrent || state.candidate === null)
49
+ throw new Error('QA preparation needs a current complete candidate');
50
+ const candidate = state.candidate;
51
+ await verifyCandidateSources(parent, this.dependencies.repositories, candidate, facts);
52
+ return {
53
+ candidateId: candidate.candidateId,
54
+ selectionRevision: candidate.selectionRevision,
55
+ criteria: candidate.criteria,
56
+ inputs: facts.selections.at(-1).entries.map((entry) => ({
57
+ workItemId: entry.output.reference.workItemId,
58
+ outputName: entry.output.name,
59
+ revision: 'revisionId' in entry.output.reference
60
+ ? entry.output.reference.revisionId
61
+ : entry.output.reference.revision,
62
+ })),
63
+ ...(policy.recipe === undefined ? {} : { recipe: policy.recipe }),
64
+ repositories: candidate.repositories.map((entry) => ({
65
+ resourceId: entry.resourceId,
66
+ sourceRef: entry.source.kind === CandidateSourceKind.RetainedRef ? entry.source.ref : entry.revision,
67
+ sourceRevision: entry.revision,
68
+ pullRequestBase: entry.pullRequestBase,
69
+ ...(entry.source.kind === CandidateSourceKind.RetainedRef
70
+ ? { requiredSourceRef: entry.source.ref }
71
+ : {}),
72
+ })),
73
+ };
74
+ }
75
+ async noDescendantCapacity(facts) {
76
+ const root = facts.reservations[0];
77
+ if (root === undefined)
78
+ return false;
79
+ const reservations = new Map();
80
+ for (const { event } of await this.repository.events()) {
81
+ if (event.eventType !== OrchestrationEventType.DelegationReserved ||
82
+ event.payload.rootWorkItemId !== root.rootWorkItemId)
83
+ continue;
84
+ const reservation = event.payload;
85
+ reservations.set(reservation.parentWorkflowInstanceId + '/' + reservation.cohortId, reservation.children.length);
86
+ }
87
+ return [...reservations.values()].reduce((sum, count) => sum + count, 0) >= root.maxDescendants;
88
+ }
89
+ async delegatingStage(id, reservation) {
90
+ const original = (await this.repository.history(id)).events.find(({ event }) => event.eventType === OrchestrationEventType.ActivityRequested &&
91
+ event.payload.activationId === reservation.activationId);
92
+ if (original?.event.eventType !== OrchestrationEventType.ActivityRequested ||
93
+ original.event.payload.stage === undefined)
94
+ throw new Error('Missing delegating activation stage');
95
+ return original.event.payload.stage;
96
+ }
97
+ async facts(parent) {
98
+ return readDeliveryFacts(this.repository, parent, (await this.repository.history(parent.workflowInstanceId)).events);
99
+ }
100
+ }
@@ -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
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,6 +18,7 @@ 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;
21
23
  private readonly resumeClarification;
22
24
  private readonly repository;
@@ -34,6 +36,95 @@ export declare class OrchestrationService {
34
36
  private readonly definitions;
35
37
  private readonly work;
36
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>;
37
128
  repositoryAuthority(workItemId: string): Promise<string[] | undefined>;
38
129
  repositoryAssignment(workItemId: string): Promise<{
39
130
  resourceId: string;
@@ -82,6 +173,10 @@ export declare class OrchestrationService {
82
173
  cohortId?: string | undefined;
83
174
  useAsBase?: boolean | undefined;
84
175
  }[] | undefined;
176
+ replaces?: {
177
+ cohortId: string;
178
+ assignmentId: string;
179
+ } | undefined;
85
180
  repository?: {
86
181
  resourceId: string;
87
182
  sourceRef: string;
@@ -93,13 +188,178 @@ export declare class OrchestrationService {
93
188
  planRevision?: number | undefined;
94
189
  maxConcurrentRuns?: number | undefined;
95
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
+ }>;
96
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
+ };
97
352
  policy: {
98
353
  workflows: string[];
99
354
  maxDepth: number;
100
355
  maxDescendants: number;
101
356
  maxConcurrentRuns: number;
102
357
  repositories?: string[] | undefined;
358
+ completion?: "qa-approved" | "merge-required" | undefined;
359
+ qa?: {
360
+ stage: string;
361
+ recipe?: string | undefined;
362
+ } | undefined;
103
363
  } | null;
104
364
  repositories: string[];
105
365
  planRevision: number;
@@ -166,6 +426,10 @@ export declare class OrchestrationService {
166
426
  cohortId?: string | undefined;
167
427
  useAsBase?: boolean | undefined;
168
428
  }[] | undefined;
429
+ replaces?: {
430
+ cohortId: string;
431
+ assignmentId: string;
432
+ } | undefined;
169
433
  repository?: {
170
434
  resourceId: string;
171
435
  sourceRef: string;
@@ -249,6 +513,10 @@ export declare class OrchestrationService {
249
513
  cohortId?: string | undefined;
250
514
  useAsBase?: boolean | undefined;
251
515
  }[] | undefined;
516
+ replaces?: {
517
+ cohortId: string;
518
+ assignmentId: string;
519
+ } | undefined;
252
520
  repository?: {
253
521
  resourceId: string;
254
522
  sourceRef: string;
@@ -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';
@@ -29,6 +30,7 @@ export class OrchestrationService {
29
30
  delegationCommands;
30
31
  delegationGate;
31
32
  delegatedWork;
33
+ delivery;
32
34
  prerequisiteReasons = (ids, snapshot) => this.delegatedWork.prerequisites.reasons(ids, snapshot);
33
35
  resumeClarification = (id, context) => this.advanceWorkflow.resumeNeedsClarificationStage(id, context);
34
36
  repository;
@@ -51,7 +53,7 @@ export class OrchestrationService {
51
53
  this.projections = projections;
52
54
  this.journal = journal;
53
55
  this.work = work;
54
- const repository = new OrchestrationRepository(journal);
56
+ const repository = new OrchestrationRepository(journal, (id) => this.delivery.completionBlock(id));
55
57
  this.repository = repository;
56
58
  this.delegationGate = new DelegationGate(repository, work, delegation === undefined ? undefined : this.prerequisiteReasons);
57
59
  const dependencies = delegation?.({
@@ -69,6 +71,7 @@ export class OrchestrationService {
69
71
  resumeChild: this.resumeClarification,
70
72
  });
71
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)));
72
75
  this.advanceWorkflow = new AdvanceWorkflow(repository, this.startWorkflow, (command, context) => this.acceptOutcome(command, context), isAgentActivity);
73
76
  this.acceptWorkflowSignal = new AcceptSignal(repository, this.startWorkflow, work);
74
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));
@@ -79,6 +82,12 @@ export class OrchestrationService {
79
82
  await this.deferredSignals.reconcile(context);
80
83
  });
81
84
  }
85
+ deliveryStateFor(workflowInstanceId) {
86
+ return this.delivery.inspect(workflowInstanceId);
87
+ }
88
+ deliveryQaPreparation(workflowInstanceId) {
89
+ return this.delivery.prepare(workflowInstanceId);
90
+ }
82
91
  repositoryAuthority(workItemId) {
83
92
  return this.delegatedWork.repositoryScope(workItemId);
84
93
  }
@@ -90,11 +99,24 @@ export class OrchestrationService {
90
99
  (item === undefined || view.workItemId === item) &&
91
100
  view.acceptedOutcomes.some((accepted) => accepted === id));
92
101
  }
93
- submitDelegation(caller, input, context) {
102
+ async submitDelegation(caller, input, context) {
103
+ await this.delivery.assertReplacements(caller, input);
94
104
  return this.delegationCommands.submit(caller, input, context);
95
105
  }
96
- inspectDelegation(caller, context) {
97
- 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
+ };
98
120
  }
99
121
  deliveryTree(id) {
100
122
  return this.delegatedWork.inspect(id);
@@ -444,6 +466,13 @@ function isReviewConversationCommand(command) {
444
466
  async function unavailableRunCompletion() {
445
467
  throw new Error('Delegation adapters unavailable');
446
468
  }
469
+ function deliveryDependencies(dependencies, definitionFor) {
470
+ return {
471
+ authority: dependencies?.authority ?? unavailableDelegationAuthority,
472
+ repositories: dependencies?.repositories,
473
+ definitionFor,
474
+ };
475
+ }
447
476
  const unavailableArtifacts = {
448
477
  validateInputs: unavailableRunCompletion,
449
478
  registerChild: unavailableRunCompletion,