@atolis-hq/wake 0.4.105 → 0.4.107

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 (158) hide show
  1. package/dist/src/activities/agent/agent-activity.js +7 -0
  2. package/dist/src/activities/contracts/activity.d.ts +12 -0
  3. package/dist/src/activities/contracts/event-schema.d.ts +314 -8
  4. package/dist/src/activities/contracts/event-schema.js +20 -2
  5. package/dist/src/activities/contracts/events.d.ts +10 -0
  6. package/dist/src/activities/contracts/vocabulary.d.ts +2 -0
  7. package/dist/src/activities/contracts/vocabulary.js +2 -0
  8. package/dist/src/activities/index.d.ts +2 -0
  9. package/dist/src/activities/index.js +2 -0
  10. package/dist/src/activities/pr/activity-support.d.ts +1 -1
  11. package/dist/src/activities/pr/activity-support.js +10 -0
  12. package/dist/src/activities/pr/application.js +31 -10
  13. package/dist/src/activities/pr/approve.d.ts +2 -1
  14. package/dist/src/activities/pr/approve.js +33 -11
  15. package/dist/src/activities/pr/check-evidence.d.ts +10 -0
  16. package/dist/src/activities/pr/check-evidence.js +16 -0
  17. package/dist/src/activities/pr/contracts.d.ts +14 -0
  18. package/dist/src/activities/pr/event-data.js +5 -1
  19. package/dist/src/activities/pr/merge.d.ts +2 -1
  20. package/dist/src/activities/pr/merge.js +54 -38
  21. package/dist/src/activities/pr/parent-scope.d.ts +65 -0
  22. package/dist/src/activities/pr/parent-scope.js +24 -0
  23. package/dist/src/activities/pr/parent-target.d.ts +45 -0
  24. package/dist/src/activities/pr/parent-target.js +59 -0
  25. package/dist/src/activities/pr/projection.js +10 -2
  26. package/dist/src/activities/pr/vocabulary.d.ts +8 -0
  27. package/dist/src/activities/pr/vocabulary.js +8 -0
  28. package/dist/src/bootstrap/activity-registry.d.ts +2 -2
  29. package/dist/src/bootstrap/activity-registry.js +3 -3
  30. package/dist/src/bootstrap/composition-root.js +12 -3
  31. package/dist/src/bootstrap/config/root-schema.d.ts +6 -0
  32. package/dist/src/bootstrap/delivery-integration.d.ts +9 -0
  33. package/dist/src/bootstrap/delivery-integration.js +46 -0
  34. package/dist/src/bootstrap/surface-api-delivery.js +27 -0
  35. package/dist/src/bootstrap/version.js +1 -1
  36. package/dist/src/control-plane/application/activation-scheduler-ports.d.ts +3 -1
  37. package/dist/src/control-plane/application/advance-once-dispatch.js +10 -6
  38. package/dist/src/conversations/application/conversation-repository.d.ts +1 -1
  39. package/dist/src/conversations/application/conversation-repository.js +3 -1
  40. package/dist/src/execution/application/execution-service.js +10 -0
  41. package/dist/src/execution/application/maintenance-workspaces.d.ts +17 -0
  42. package/dist/src/execution/application/maintenance-workspaces.js +84 -0
  43. package/dist/src/execution/application/run-lifecycle.js +1 -0
  44. package/dist/src/execution/application/run-repository.js +27 -10
  45. package/dist/src/execution/contracts/commands.d.ts +2 -0
  46. package/dist/src/execution/contracts/events.d.ts +13 -0
  47. package/dist/src/execution/contracts/events.js +2 -0
  48. package/dist/src/execution/contracts/maintenance.d.ts +36 -0
  49. package/dist/src/execution/contracts/maintenance.js +44 -0
  50. package/dist/src/execution/contracts/views.d.ts +2 -0
  51. package/dist/src/execution/contracts/workspace.d.ts +2 -0
  52. package/dist/src/execution/index.d.ts +1 -0
  53. package/dist/src/execution/index.js +1 -0
  54. package/dist/src/integrations/application/artifact-registration-reactor.js +7 -14
  55. package/dist/src/integrations/application/delegation-outputs.js +1 -1
  56. package/dist/src/integrations/application/delivery-integration-verification.d.ts +13 -0
  57. package/dist/src/integrations/application/delivery-integration-verification.js +68 -0
  58. package/dist/src/integrations/application/latest-unresolved-artifacts.d.ts +3 -0
  59. package/dist/src/integrations/application/latest-unresolved-artifacts.js +16 -0
  60. package/dist/src/integrations/delivery/application/delivery-projector.js +3 -0
  61. package/dist/src/integrations/delivery/application/merged-delivery-evidence.js +9 -1
  62. package/dist/src/integrations/delivery/contracts/views.d.ts +2 -0
  63. package/dist/src/integrations/fake/external-source.d.ts +5 -2
  64. package/dist/src/integrations/fake/external-source.js +12 -2
  65. package/dist/src/integrations/fake/inbound-translator.js +7 -2
  66. package/dist/src/integrations/fake/provider.d.ts +17 -0
  67. package/dist/src/integrations/fake/provider.js +18 -2
  68. package/dist/src/integrations/github/application/comment-history-reader.d.ts +1 -1
  69. package/dist/src/integrations/github/application/comment-history-reader.js +56 -39
  70. package/dist/src/integrations/github/application/pull-request-translation.js +2 -0
  71. package/dist/src/integrations/github/contracts/events.d.ts +3 -1
  72. package/dist/src/integrations/github/contracts/events.js +3 -1
  73. package/dist/src/integrations/github/contracts/payloads.d.ts +23 -0
  74. package/dist/src/integrations/github/infrastructure/check-execution.d.ts +9 -0
  75. package/dist/src/integrations/github/infrastructure/check-execution.js +68 -0
  76. package/dist/src/integrations/github/infrastructure/checkout-revision.d.ts +2 -0
  77. package/dist/src/integrations/github/infrastructure/checkout-revision.js +23 -0
  78. package/dist/src/integrations/github/infrastructure/client.d.ts +2 -0
  79. package/dist/src/integrations/github/infrastructure/client.js +4 -0
  80. package/dist/src/integrations/github/infrastructure/pr-check-subject.d.ts +7 -0
  81. package/dist/src/integrations/github/infrastructure/pr-check-subject.js +77 -0
  82. package/dist/src/integrations/github/infrastructure/pr-evidence.d.ts +6 -3
  83. package/dist/src/integrations/github/infrastructure/pr-evidence.js +1 -1
  84. package/dist/src/integrations/github/infrastructure/pr-source.d.ts +3 -5
  85. package/dist/src/integrations/github/infrastructure/pr-source.js +11 -1
  86. package/dist/src/integrations/github/infrastructure/workflow-run-evidence.d.ts +5 -0
  87. package/dist/src/integrations/github/infrastructure/workflow-run-evidence.js +22 -0
  88. package/dist/src/integrations/index.d.ts +1 -0
  89. package/dist/src/integrations/index.js +1 -0
  90. package/dist/src/node_modules/@atolis-hq/eventing/dist/index.d.ts +1 -1
  91. package/dist/src/node_modules/@atolis-hq/eventing/dist/index.d.ts.map +1 -1
  92. package/dist/src/node_modules/@atolis-hq/eventing/dist/index.js +1 -1
  93. package/dist/src/node_modules/@atolis-hq/eventing/dist/projections/projection-processor.d.ts +14 -0
  94. package/dist/src/node_modules/@atolis-hq/eventing/dist/projections/projection-processor.d.ts.map +1 -1
  95. package/dist/src/node_modules/@atolis-hq/eventing/dist/projections/projection-processor.js +31 -1
  96. package/dist/src/node_modules/@atolis-hq/eventing/dist/runtime/journal-view.d.ts +22 -0
  97. package/dist/src/node_modules/@atolis-hq/eventing/dist/runtime/journal-view.d.ts.map +1 -0
  98. package/dist/src/node_modules/@atolis-hq/eventing/dist/runtime/journal-view.js +60 -0
  99. package/dist/src/node_modules/@atolis-hq/eventing-filesystem/dist/file-event-journal.d.ts +2 -0
  100. package/dist/src/node_modules/@atolis-hq/eventing-filesystem/dist/file-event-journal.d.ts.map +1 -1
  101. package/dist/src/node_modules/@atolis-hq/eventing-filesystem/dist/file-event-journal.js +82 -15
  102. package/dist/src/orchestration/application/advance-workflow.js +7 -2
  103. package/dist/src/orchestration/application/deferred-signals.js +2 -6
  104. package/dist/src/orchestration/application/delegation-commands.d.ts +3 -0
  105. package/dist/src/orchestration/application/delivery-coordinator.d.ts +70 -1
  106. package/dist/src/orchestration/application/delivery-coordinator.js +31 -5
  107. package/dist/src/orchestration/application/delivery-facts-reader.js +1 -0
  108. package/dist/src/orchestration/application/delivery-integration-reader.d.ts +9 -0
  109. package/dist/src/orchestration/application/delivery-integration-reader.js +23 -0
  110. package/dist/src/orchestration/application/delivery-integration-service.d.ts +50 -0
  111. package/dist/src/orchestration/application/delivery-integration-service.js +228 -0
  112. package/dist/src/orchestration/application/delivery-preparation.d.ts +1 -0
  113. package/dist/src/orchestration/application/delivery-preparation.js +7 -2
  114. package/dist/src/orchestration/application/orchestration-repository.d.ts +14 -9
  115. package/dist/src/orchestration/application/orchestration-repository.js +139 -64
  116. package/dist/src/orchestration/application/orchestration-service.d.ts +74 -3
  117. package/dist/src/orchestration/application/orchestration-service.js +55 -2
  118. package/dist/src/orchestration/contracts/config.d.ts +6 -0
  119. package/dist/src/orchestration/contracts/config.js +6 -0
  120. package/dist/src/orchestration/contracts/delivery-ports.d.ts +44 -0
  121. package/dist/src/orchestration/contracts/delivery.d.ts +58 -0
  122. package/dist/src/orchestration/contracts/delivery.js +53 -1
  123. package/dist/src/orchestration/contracts/event-decoder.js +2 -1
  124. package/dist/src/orchestration/contracts/event-factory.js +2 -0
  125. package/dist/src/orchestration/contracts/events.d.ts +3 -1
  126. package/dist/src/orchestration/contracts/events.js +1 -0
  127. package/dist/src/orchestration/contracts/vocabulary.d.ts +44 -1
  128. package/dist/src/orchestration/contracts/vocabulary.js +40 -1
  129. package/dist/src/orchestration/domain/compile-diagnostics.d.ts +1 -1
  130. package/dist/src/orchestration/domain/compile-diagnostics.js +5 -0
  131. package/dist/src/orchestration/domain/delivery-candidate.js +13 -0
  132. package/dist/src/orchestration/domain/delivery-facts.d.ts +7 -1
  133. package/dist/src/orchestration/domain/delivery-facts.js +33 -1
  134. package/dist/src/orchestration/domain/delivery-integration-policy.d.ts +7 -0
  135. package/dist/src/orchestration/domain/delivery-integration-policy.js +15 -0
  136. package/dist/src/orchestration/domain/delivery-integration.d.ts +54 -0
  137. package/dist/src/orchestration/domain/delivery-integration.js +144 -0
  138. package/dist/src/orchestration/domain/delivery-qa.d.ts +2 -1
  139. package/dist/src/orchestration/domain/delivery-qa.js +24 -4
  140. package/dist/src/orchestration/domain/delivery-workflow-policy.d.ts +3 -1
  141. package/dist/src/orchestration/domain/delivery-workflow-policy.js +19 -0
  142. package/dist/src/orchestration/domain/workflow-instance-events.js +1 -0
  143. package/dist/src/orchestration/index.d.ts +3 -2
  144. package/dist/src/orchestration/index.js +1 -1
  145. package/dist/src/resources/application/resource-lookup.d.ts +2 -1
  146. package/dist/src/resources/application/resource-lookup.js +3 -11
  147. package/dist/src/resources/application/resource-repository.js +10 -10
  148. package/dist/src/surfaces/api/contracts/transport-values.js +1 -0
  149. package/dist/src/surfaces/api/contracts/work.d.ts +26 -0
  150. package/dist/src/surfaces/api/presenters/execution.js +1 -0
  151. package/dist/src/surfaces/mcp/delegation.js +5 -1
  152. package/dist/src/surfaces/web-assets/assets/index-ih1h3dxC.js +1192 -0
  153. package/dist/src/surfaces/web-assets/index.html +1 -1
  154. package/package.json +1 -1
  155. package/dist/src/node_modules/@atolis-hq/eventing/dist/runtime/cached-journal-view.d.ts +0 -16
  156. package/dist/src/node_modules/@atolis-hq/eventing/dist/runtime/cached-journal-view.d.ts.map +0 -1
  157. package/dist/src/node_modules/@atolis-hq/eventing/dist/runtime/cached-journal-view.js +0 -79
  158. package/dist/src/surfaces/web-assets/assets/index-BfhxlN_h.js +0 -1192
@@ -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
  }
@@ -1,10 +1,11 @@
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
+ import type { DeliveryIntegration } from '../contracts/delivery-ports.js';
4
+ import type { DeliveryCandidateCommand, DeliveryMaintenanceCommand, DeliveryQaCommand, DeliverySelectionCommand } from '../contracts/delivery.js';
4
5
  import type { ResourceTransitionEvidence } from './resource-transition-evidence.js';
5
6
  import type { CommandContext, EventJournal, ProjectionStore } from '@atolis-hq/eventing';
6
- import { type ActivationId, type ActivityOutcome } from '../../activities/index.js';
7
- import type { ExecutionFailureCode } from '../../execution/index.js';
7
+ import { type ActivationId, type ActivityOutcome, type ParentActionRequest } from '../../activities/index.js';
8
+ import type { ExecutionFailureCode, ExecutionMaintenance } from '../../execution/index.js';
8
9
  import { type WorkItemId, type WorkItemView, type WorkService } from '../../work/index.js';
9
10
  import type { StartWorkflowInstance } from '../contracts/commands.js';
10
11
  import type { CompiledWorkflow, TransitionTarget } from '../contracts/config.js';
@@ -37,6 +38,32 @@ export declare class OrchestrationService {
37
38
  private readonly work;
38
39
  constructor(journal: EventJournal, work: WorkService, definitions: Readonly<Record<string, CompiledWorkflow>>, projections?: ProjectionStore, isAgentActivity?: AgentActivityClassifier, delegation?: DelegationDependenciesFactory);
39
40
  deliveryStateFor(workflowInstanceId: string): Promise<{
41
+ integration: import("../domain/delivery-integration.js").IntegrationAssessment | null;
42
+ maintenance: readonly {
43
+ maintenanceId: string;
44
+ target: {
45
+ childWorkItemId: WorkItemId;
46
+ outputName: string;
47
+ };
48
+ kind: "rebase" | "retarget" | "resolve-conflicts";
49
+ resourceId: string;
50
+ repositoryResourceId: string;
51
+ previous: {
52
+ revision: string;
53
+ pullRequestBase: string;
54
+ baseRevision?: string | undefined;
55
+ };
56
+ current: {
57
+ revision: string;
58
+ pullRequestBase: string;
59
+ baseRevision?: string | undefined;
60
+ };
61
+ producer: {
62
+ runId: string;
63
+ activationId: string;
64
+ };
65
+ recordedAt?: string | undefined;
66
+ }[];
40
67
  required: {
41
68
  cohortId: string;
42
69
  assignmentId: string;
@@ -249,6 +276,13 @@ export declare class OrchestrationService {
249
276
  outputName: string;
250
277
  }[];
251
278
  criteria: string[];
279
+ subjects?: {
280
+ childWorkItemId: WorkItemId;
281
+ outputName: string;
282
+ revision: string;
283
+ pullRequestBase: string;
284
+ baseRevision?: string | undefined;
285
+ }[] | undefined;
252
286
  recipe?: string | undefined;
253
287
  };
254
288
  replay: boolean;
@@ -277,8 +311,41 @@ export declare class OrchestrationService {
277
311
  };
278
312
  replay: boolean;
279
313
  }>;
314
+ recordDeliveryMaintenance(caller: DelegationCaller, input: DeliveryMaintenanceCommand, context: CommandContext): Promise<{
315
+ readonly maintenance: import("../contracts/delivery.js").DeliveryMaintenance;
316
+ readonly replay: boolean;
317
+ }>;
318
+ authorizeParentAction(request: ParentActionRequest): Promise<import("../../activities/index.js").ParentActionDecision>;
319
+ /** The branch leases Execution must hold for the configured maintenance stage's activation. */
320
+ deliveryMaintenancePreparation(workflowInstanceId: string): Promise<ExecutionMaintenance | undefined>;
280
321
  inspectDelegation(caller: DelegationCaller, context: CommandContext): Promise<{
281
322
  delivery: {
323
+ integration: import("../domain/delivery-integration.js").IntegrationAssessment | null;
324
+ maintenance: readonly {
325
+ maintenanceId: string;
326
+ target: {
327
+ childWorkItemId: WorkItemId;
328
+ outputName: string;
329
+ };
330
+ kind: "rebase" | "retarget" | "resolve-conflicts";
331
+ resourceId: string;
332
+ repositoryResourceId: string;
333
+ previous: {
334
+ revision: string;
335
+ pullRequestBase: string;
336
+ baseRevision?: string | undefined;
337
+ };
338
+ current: {
339
+ revision: string;
340
+ pullRequestBase: string;
341
+ baseRevision?: string | undefined;
342
+ };
343
+ producer: {
344
+ runId: string;
345
+ activationId: string;
346
+ };
347
+ recordedAt?: string | undefined;
348
+ }[];
282
349
  required: {
283
350
  cohortId: string;
284
351
  assignmentId: string;
@@ -360,6 +427,9 @@ export declare class OrchestrationService {
360
427
  stage: string;
361
428
  recipe?: string | undefined;
362
429
  } | undefined;
430
+ maintenance?: {
431
+ stage: string;
432
+ } | undefined;
363
433
  } | null;
364
434
  repositories: string[];
365
435
  planRevision: number;
@@ -657,6 +727,7 @@ type DelegationDependenciesFactory = (queries: {
657
727
  artifacts: DelegationArtifacts;
658
728
  authority?: DelegationAuthority;
659
729
  repositories?: DelegationRepositories;
730
+ integration?: DeliveryIntegration;
660
731
  runHasEnded: (runId: string) => Promise<boolean>;
661
732
  };
662
733
  export {};
@@ -71,7 +71,7 @@ export class OrchestrationService {
71
71
  resumeChild: this.resumeClarification,
72
72
  });
73
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)));
74
+ this.delivery = new DeliveryCoordinator(repository, deliveryDependencies(dependencies, async (parent) => this.startWorkflow.definitionFor(parent), work));
75
75
  this.advanceWorkflow = new AdvanceWorkflow(repository, this.startWorkflow, (command, context) => this.acceptOutcome(command, context), isAgentActivity);
76
76
  this.acceptWorkflowSignal = new AcceptSignal(repository, this.startWorkflow, work);
77
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));
@@ -112,6 +112,38 @@ export class OrchestrationService {
112
112
  recordDeliveryQa(caller, input, context) {
113
113
  return this.delivery.recordQa(caller, input, context);
114
114
  }
115
+ recordDeliveryMaintenance(caller, input, context) {
116
+ return this.delivery.recordMaintenance(caller, input, context);
117
+ }
118
+ authorizeParentAction(request) {
119
+ return this.delivery.authorizeParentAction(request);
120
+ }
121
+ /** The branch leases Execution must hold for the configured maintenance stage's activation. */
122
+ async deliveryMaintenancePreparation(workflowInstanceId) {
123
+ const targets = await this.delivery.maintenanceTargets(workflowInstanceId);
124
+ if (targets === undefined || targets.length === 0)
125
+ return undefined;
126
+ const prepared = [];
127
+ for (const target of targets) {
128
+ // The same assignment that created the child's workspace, so its lease is reused exactly.
129
+ const repository = await this.delegatedWork.repositoryFor(target.ownerWorkItemId);
130
+ if (repository === undefined)
131
+ continue;
132
+ prepared.push({
133
+ childWorkItemId: target.ownerWorkItemId,
134
+ outputName: target.output.outputName,
135
+ resourceId: target.resourceId,
136
+ repository,
137
+ branch: target.branch,
138
+ revision: target.revision,
139
+ pullRequestBase: target.pullRequestBase,
140
+ ...(target.maintenance === undefined
141
+ ? {}
142
+ : { reason: `${target.maintenance}: ${target.detail ?? ''}`.trim() }),
143
+ });
144
+ }
145
+ return prepared.length === 0 ? undefined : { targets: prepared };
146
+ }
115
147
  async inspectDelegation(caller, context) {
116
148
  return {
117
149
  ...(await this.delegationCommands.inspect(caller, context)),
@@ -466,10 +498,31 @@ function isReviewConversationCommand(command) {
466
498
  async function unavailableRunCompletion() {
467
499
  throw new Error('Delegation adapters unavailable');
468
500
  }
469
- function deliveryDependencies(dependencies, definitionFor) {
501
+ function deliveryDependencies(dependencies, definitionFor, work) {
470
502
  return {
471
503
  authority: dependencies?.authority ?? unavailableDelegationAuthority,
472
504
  repositories: dependencies?.repositories,
505
+ integration: dependencies?.integration,
506
+ // A finished producing workflow (a Closed child) is deliberately not a hold.
507
+ unavailable: async (ids) => {
508
+ const snapshot = await work.deliverySnapshot();
509
+ const reasons = new Map();
510
+ for (const id of ids) {
511
+ const lineage = [id, ...(snapshot.get(id)?.delegation?.ancestors ?? [])];
512
+ const held = lineage.find((member) => {
513
+ const state = snapshot.get(member);
514
+ return (snapshot.invalid(member) ||
515
+ state === null ||
516
+ state.deleted === true ||
517
+ state.frozen === true ||
518
+ state.state === WorkStatus.Cancelled ||
519
+ (member !== id && state.state !== WorkStatus.Open));
520
+ });
521
+ if (held !== undefined)
522
+ reasons.set(id, `Delivery work ${held} is unavailable`);
523
+ }
524
+ return reasons;
525
+ },
473
526
  definitionFor,
474
527
  };
475
528
  }
@@ -228,6 +228,9 @@ export declare const delegationPolicySchema: z.ZodObject<{
228
228
  stage: z.ZodString;
229
229
  recipe: z.ZodOptional<z.ZodString>;
230
230
  }, z.core.$strict>>;
231
+ maintenance: z.ZodOptional<z.ZodObject<{
232
+ stage: z.ZodString;
233
+ }, z.core.$strict>>;
231
234
  }, z.core.$strict>;
232
235
  export type DelegationPolicy = z.infer<typeof delegationPolicySchema>;
233
236
  export declare const workflowDefinitionConfigSchema: z.ZodObject<{
@@ -246,6 +249,9 @@ export declare const workflowDefinitionConfigSchema: z.ZodObject<{
246
249
  stage: z.ZodString;
247
250
  recipe: z.ZodOptional<z.ZodString>;
248
251
  }, z.core.$strict>>;
252
+ maintenance: z.ZodOptional<z.ZodObject<{
253
+ stage: z.ZodString;
254
+ }, z.core.$strict>>;
249
255
  }, z.core.$strict>>;
250
256
  commands: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
251
257
  activity: z.ZodString;
@@ -164,6 +164,12 @@ export const delegationPolicySchema = z
164
164
  .object({ stage: identifier, recipe: z.string().trim().min(1).optional() })
165
165
  .strict()
166
166
  .optional(),
167
+ /**
168
+ * The agent stage that retargets, rebases or repairs selected pull requests between planned
169
+ * merges. Wake leases each target's recorded branch workspace for it; the agent chooses the
170
+ * repair.
171
+ */
172
+ maintenance: z.object({ stage: identifier }).strict().optional(),
167
173
  })
168
174
  .strict();
169
175
  export const workflowDefinitionConfigSchema = z
@@ -1,9 +1,53 @@
1
+ import type { PullRequestMergeability, PullRequestState } from '../../activities/index.js';
1
2
  import type { CompiledWorkflow } from './config.js';
2
3
  import type { DelegationAuthority, DelegationRepositories } from './delegation-ports.js';
3
4
  import type { WorkflowInstanceView } from './views.js';
5
+ export interface DeliveryPullRequest {
6
+ readonly state: PullRequestState;
7
+ readonly headRevision: string;
8
+ readonly baseRevision: string;
9
+ readonly mergeRevision?: string | undefined;
10
+ readonly mergeability?: PullRequestMergeability | undefined;
11
+ }
12
+ /** Trusted Bootstrap adapters over provider-observed facts and Execution's Run records. */
13
+ export interface DeliveryIntegration {
14
+ /** The current provider-observed pull request, or null when it has not been observed. */
15
+ observe(resourceId: string): Promise<DeliveryPullRequest | null>;
16
+ verifyTarget(request: {
17
+ readonly ownerWorkItemId: string;
18
+ readonly resourceId: string;
19
+ readonly repositoryResourceId: string;
20
+ readonly branch: string;
21
+ readonly revision: string;
22
+ readonly pullRequestBase: string;
23
+ readonly baseRevision?: string | undefined;
24
+ readonly maintenanceRecordedAt?: string | undefined;
25
+ readonly maintenanceRunId?: string | undefined;
26
+ readonly requireReview: boolean;
27
+ readonly requireChecks: boolean;
28
+ }): Promise<boolean>;
29
+ /**
30
+ * Proves the Run was durably prepared with the target's branch lease, and that no earlier
31
+ * maintenance Run of the same target is still unresolved or ambiguous.
32
+ */
33
+ assertMaintenanceWriter(request: {
34
+ readonly workflowInstanceId: string;
35
+ readonly activationId: string;
36
+ readonly runId: string;
37
+ readonly childWorkItemId: string;
38
+ readonly resourceId: string;
39
+ readonly revision: string;
40
+ }): Promise<void>;
41
+ }
4
42
  export interface DeliveryDependencies {
5
43
  readonly authority: DelegationAuthority;
6
44
  /** Resolves a repository source through the parent's own repository authority. */
7
45
  readonly repositories?: DelegationRepositories | undefined;
46
+ readonly integration?: DeliveryIntegration | undefined;
47
+ /**
48
+ * Reasons integration must not touch a child's output: the child or any ancestor is frozen,
49
+ * cancelled or deleted. A finished producing workflow is not a reason.
50
+ */
51
+ readonly unavailable?: ((childWorkItemIds: readonly string[]) => Promise<ReadonlyMap<string, string>>) | undefined;
8
52
  readonly definitionFor: (parent: WorkflowInstanceView) => Promise<CompiledWorkflow>;
9
53
  }
@@ -182,6 +182,13 @@ export declare const deliveryCandidateSchema: z.ZodObject<{
182
182
  outputName: z.ZodString;
183
183
  }, z.core.$strict>>;
184
184
  }, z.core.$strict>>;
185
+ subjects: z.ZodOptional<z.ZodArray<z.ZodObject<{
186
+ childWorkItemId: z.ZodPipe<z.ZodString, z.ZodTransform<import("../../work/index.js").WorkItemId, string>>;
187
+ outputName: z.ZodString;
188
+ revision: z.ZodString;
189
+ pullRequestBase: z.ZodString;
190
+ baseRevision: z.ZodOptional<z.ZodString>;
191
+ }, z.core.$strict>>>;
185
192
  context: z.ZodArray<z.ZodObject<{
186
193
  childWorkItemId: z.ZodPipe<z.ZodString, z.ZodTransform<import("../../work/index.js").WorkItemId, string>>;
187
194
  outputName: z.ZodString;
@@ -239,6 +246,57 @@ export declare const deliveryQaSchema: z.ZodObject<{
239
246
  activationId: z.ZodOptional<z.ZodString>;
240
247
  }, z.core.$strict>;
241
248
  export type DeliveryQa = z.infer<typeof deliveryQaSchema>;
249
+ /** Agent input: what it did to one selected change, for Wake to verify against the provider. */
250
+ export declare const deliveryMaintenanceCommandSchema: z.ZodObject<{
251
+ maintenanceId: z.ZodString;
252
+ target: z.ZodObject<{
253
+ childWorkItemId: z.ZodPipe<z.ZodString, z.ZodTransform<import("../../work/index.js").WorkItemId, string>>;
254
+ outputName: z.ZodString;
255
+ }, z.core.$strict>;
256
+ kind: z.ZodEnum<{
257
+ readonly Retarget: "retarget";
258
+ readonly Rebase: "rebase";
259
+ readonly Resolve: "resolve-conflicts";
260
+ }>;
261
+ expectedRevision: z.ZodString;
262
+ revision: z.ZodString;
263
+ pullRequestBase: z.ZodString;
264
+ }, z.core.$strict>;
265
+ export type DeliveryMaintenanceCommand = z.infer<typeof deliveryMaintenanceCommandSchema>;
266
+ /**
267
+ * An immutable new subject for a selected change. The earlier subject, its reviews, checks and
268
+ * QA stay historical; the PR keeps its original owner and the producer is the maintaining Run.
269
+ */
270
+ export declare const deliveryMaintenanceSchema: z.ZodObject<{
271
+ maintenanceId: z.ZodString;
272
+ target: z.ZodObject<{
273
+ childWorkItemId: z.ZodPipe<z.ZodString, z.ZodTransform<import("../../work/index.js").WorkItemId, string>>;
274
+ outputName: z.ZodString;
275
+ }, z.core.$strict>;
276
+ kind: z.ZodEnum<{
277
+ readonly Retarget: "retarget";
278
+ readonly Rebase: "rebase";
279
+ readonly Resolve: "resolve-conflicts";
280
+ }>;
281
+ resourceId: z.ZodString;
282
+ repositoryResourceId: z.ZodString;
283
+ previous: z.ZodObject<{
284
+ revision: z.ZodString;
285
+ pullRequestBase: z.ZodString;
286
+ baseRevision: z.ZodOptional<z.ZodString>;
287
+ }, z.core.$strict>;
288
+ current: z.ZodObject<{
289
+ revision: z.ZodString;
290
+ pullRequestBase: z.ZodString;
291
+ baseRevision: z.ZodOptional<z.ZodString>;
292
+ }, z.core.$strict>;
293
+ recordedAt: z.ZodOptional<z.ZodString>;
294
+ producer: z.ZodObject<{
295
+ runId: z.ZodString;
296
+ activationId: z.ZodString;
297
+ }, z.core.$strict>;
298
+ }, z.core.$strict>;
299
+ export type DeliveryMaintenance = z.infer<typeof deliveryMaintenanceSchema>;
242
300
  /** A final delivery gate can be reassessed through ordinary operator retry. */
243
301
  export interface DeliveryCompletionBlock {
244
302
  readonly reason: string;