@leitwerk-dev/coding 0.3.0 → 0.4.0

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 (130) hide show
  1. package/README.md +120 -2
  2. package/dist/auto-work-branch.js +3 -24
  3. package/dist/auto-work-branch.js.map +1 -1
  4. package/dist/chunk-6E5VQPC4.js +28 -0
  5. package/dist/chunk-6E5VQPC4.js.map +1 -0
  6. package/dist/chunk-ABQH2WZT.js +36 -0
  7. package/dist/chunk-ABQH2WZT.js.map +1 -0
  8. package/dist/{chunk-YSC5GEQJ.js → chunk-BI45R2FH.js} +7 -3
  9. package/dist/chunk-BI45R2FH.js.map +1 -0
  10. package/dist/chunk-DNG7D77K.js +65 -0
  11. package/dist/chunk-DNG7D77K.js.map +1 -0
  12. package/dist/chunk-KFELB7ZC.js +70 -0
  13. package/dist/chunk-KFELB7ZC.js.map +1 -0
  14. package/dist/chunk-L2TFD72B.js +16320 -0
  15. package/dist/chunk-L2TFD72B.js.map +1 -0
  16. package/dist/chunk-M2VTUPFO.js +265 -0
  17. package/dist/chunk-M2VTUPFO.js.map +1 -0
  18. package/dist/chunk-OM2AMDTJ.js +347 -0
  19. package/dist/chunk-OM2AMDTJ.js.map +1 -0
  20. package/dist/chunk-Q24RPXOA.js +159 -0
  21. package/dist/chunk-Q24RPXOA.js.map +1 -0
  22. package/dist/chunk-SKGB4CZS.js +14 -0
  23. package/dist/chunk-SKGB4CZS.js.map +1 -0
  24. package/dist/chunk-SZ4WOGV2.js +120 -0
  25. package/dist/chunk-SZ4WOGV2.js.map +1 -0
  26. package/dist/finalization-git-internal.d.ts +3 -0
  27. package/dist/finalization-git-internal.d.ts.map +1 -1
  28. package/dist/finalization-git.d.ts +1 -1
  29. package/dist/finalization-git.d.ts.map +1 -1
  30. package/dist/finalization-git.js +5 -3
  31. package/dist/index.d.ts +1 -0
  32. package/dist/index.d.ts.map +1 -1
  33. package/dist/index.js +17 -591
  34. package/dist/index.js.map +1 -1
  35. package/dist/profile-bindings-internal.d.ts +3 -0
  36. package/dist/profile-bindings-internal.d.ts.map +1 -0
  37. package/dist/pull-request-publication-internal.d.ts +75 -0
  38. package/dist/pull-request-publication-internal.d.ts.map +1 -0
  39. package/dist/repository-change-launch-internal-BudnAfL7.d.ts +88 -0
  40. package/dist/repository-change-launch-internal.d.ts +62 -11
  41. package/dist/repository-change-launch-internal.d.ts.map +1 -1
  42. package/dist/repository-change-launch.d.ts +5 -2
  43. package/dist/repository-change-launch.d.ts.map +1 -1
  44. package/dist/repository-change-launch.js +363 -6
  45. package/dist/repository-change-launch.js.map +1 -1
  46. package/dist/repository-change-process-DlgF04fU.d.ts +69 -0
  47. package/dist/repository-change-process.d.ts +30 -25
  48. package/dist/repository-change-process.d.ts.map +1 -1
  49. package/dist/repository-change-publication.d.ts +63 -7
  50. package/dist/repository-change-publication.d.ts.map +1 -1
  51. package/dist/repository-change-publication.js +732 -56
  52. package/dist/repository-change-publication.js.map +1 -1
  53. package/dist/repository-change-state-internal.d.ts +18 -4
  54. package/dist/repository-change-state-internal.d.ts.map +1 -1
  55. package/dist/repository-change-ui-launcher-internal.d.ts +65 -0
  56. package/dist/repository-change-ui-launcher-internal.d.ts.map +1 -0
  57. package/dist/repository-rebase/git.d.ts +31 -0
  58. package/dist/repository-rebase/git.d.ts.map +1 -0
  59. package/dist/repository-rebase/index.d.ts +42 -0
  60. package/dist/repository-rebase/index.d.ts.map +1 -0
  61. package/dist/repository-rebase/index.js +16 -0
  62. package/dist/repository-rebase/policy.d.ts +37 -0
  63. package/dist/repository-rebase/policy.d.ts.map +1 -0
  64. package/dist/repository-rebase/prompt.d.ts +3 -0
  65. package/dist/repository-rebase/prompt.d.ts.map +1 -0
  66. package/dist/settings.d.ts +15 -0
  67. package/dist/settings.d.ts.map +1 -0
  68. package/dist/turns/commit-message-evidence.d.ts +35 -0
  69. package/dist/turns/commit-message-evidence.d.ts.map +1 -0
  70. package/dist/turns/commit-message-evidence.js +9 -0
  71. package/dist/turns/generate-commit-message.d.ts +4 -1
  72. package/dist/turns/generate-commit-message.d.ts.map +1 -1
  73. package/dist/turns/generate-commit-message.js +7 -5
  74. package/dist/turns/generate-plan.d.ts.map +1 -1
  75. package/dist/turns/generate-plan.js +1 -1
  76. package/dist/turns/git-inspection-profile.d.ts +25 -0
  77. package/dist/turns/git-inspection-profile.d.ts.map +1 -0
  78. package/dist/turns/git-inspection-profile.js +8 -0
  79. package/dist/turns/git-inspection-profile.js.map +1 -0
  80. package/dist/turns/implement.d.ts.map +1 -1
  81. package/dist/turns/implement.js +1 -1
  82. package/dist/turns/simplify-implementation.d.ts +1 -1
  83. package/dist/turns/simplify-implementation.d.ts.map +1 -1
  84. package/dist/turns/simplify-implementation.js +3 -3
  85. package/package.json +10 -10
  86. package/src/finalization-git-internal.ts +117 -114
  87. package/src/finalization-git.ts +1 -1
  88. package/src/index.ts +4 -1
  89. package/src/profile-bindings-internal.ts +39 -0
  90. package/src/pull-request-publication-internal.ts +364 -0
  91. package/src/repository-change-launch-internal.ts +194 -11
  92. package/src/repository-change-launch.ts +13 -0
  93. package/src/repository-change-process.ts +234 -523
  94. package/src/repository-change-publication.ts +535 -156
  95. package/src/repository-change-state-internal.ts +34 -20
  96. package/src/repository-change-ui-launcher-internal.ts +308 -0
  97. package/src/repository-rebase/git.ts +219 -0
  98. package/src/repository-rebase/index.ts +144 -0
  99. package/src/repository-rebase/policy.ts +75 -0
  100. package/src/repository-rebase/prompt.ts +2 -0
  101. package/src/settings.ts +79 -0
  102. package/src/turns/commit-message-evidence.ts +241 -0
  103. package/src/turns/generate-commit-message.ts +53 -23
  104. package/src/turns/generate-plan.ts +26 -12
  105. package/src/turns/git-inspection-profile.ts +134 -0
  106. package/src/turns/implement.ts +9 -2
  107. package/src/turns/simplify-implementation.ts +10 -6
  108. package/dist/chunk-34B3Q75M.js +0 -25
  109. package/dist/chunk-34B3Q75M.js.map +0 -1
  110. package/dist/chunk-F6CEEAFE.js +0 -13
  111. package/dist/chunk-F6CEEAFE.js.map +0 -1
  112. package/dist/chunk-GO44KCUS.js +0 -154
  113. package/dist/chunk-GO44KCUS.js.map +0 -1
  114. package/dist/chunk-R3UCUGY6.js +0 -31
  115. package/dist/chunk-R3UCUGY6.js.map +0 -1
  116. package/dist/chunk-W7VJT6AN.js +0 -25
  117. package/dist/chunk-W7VJT6AN.js.map +0 -1
  118. package/dist/chunk-WKHVLLKE.js +0 -45
  119. package/dist/chunk-WKHVLLKE.js.map +0 -1
  120. package/dist/chunk-YSC5GEQJ.js.map +0 -1
  121. package/dist/turns/review-implementation.d.ts +0 -4
  122. package/dist/turns/review-implementation.d.ts.map +0 -1
  123. package/dist/turns/review-implementation.js +0 -8
  124. package/dist/turns/review-plan.d.ts +0 -4
  125. package/dist/turns/review-plan.d.ts.map +0 -1
  126. package/dist/turns/review-plan.js +0 -8
  127. package/src/turns/review-implementation.ts +0 -30
  128. package/src/turns/review-plan.ts +0 -24
  129. /package/dist/{turns/review-implementation.js.map → repository-rebase/index.js.map} +0 -0
  130. /package/dist/turns/{review-plan.js.map → commit-message-evidence.js.map} +0 -0
@@ -1,81 +1,119 @@
1
1
  import { asUnknownRecord } from "@leitwerk-dev/domain";
2
2
  import {
3
+ type AutomaticOutcomeBuilder,
4
+ type ExtensionProcessDefinition,
3
5
  type ExternalActionSource,
4
6
  type FlowAutomaticRunContext,
5
7
  flow,
8
+ type ServerExtensionAPI,
6
9
  } from "@leitwerk-dev/process-sdk";
7
10
  import {
8
- type ConflictEvidence,
9
- conflictKey,
10
- validateConflict,
11
- } from "@leitwerk-dev/repository-rebase";
12
- import { publishRebase, startRebase } from "@leitwerk-dev/repository-rebase/git";
13
- import { rebasePrompt } from "@leitwerk-dev/repository-rebase/prompt";
14
- import { commitAndPushWorkBranch, type GitIdentity } from "./finalization-git.js";
11
+ commitAndPushWorkBranch,
12
+ type GitIdentity,
13
+ repositoryHasChanges,
14
+ } from "./finalization-git.js";
15
15
  import type { RepositoryChangeState } from "./repository-change-state.js";
16
+ import { publishRebase, startRebase } from "./repository-rebase/git.js";
17
+ import { type ConflictEvidence, conflictKey, validateConflict } from "./repository-rebase/index.js";
18
+ import { rebasePrompt } from "./repository-rebase/prompt.js";
19
+ import { codingPurposes } from "./settings.js";
20
+
21
+ export {
22
+ createPullRequestChangeProcess,
23
+ pullRequestPublicationDefaults,
24
+ resolvePullRequestGitIdentity,
25
+ } from "./pull-request-publication-internal.js";
16
26
 
17
27
  /** @public */
18
28
  export interface PublicationRequest {
19
29
  /** @public */
20
30
  number: number;
31
+
21
32
  /** @public */
22
33
  html_url: string;
34
+
23
35
  /** @public */
24
36
  merged: boolean;
37
+
25
38
  /** @public */
26
39
  merge_commit_sha?: string | null;
27
40
  }
41
+
28
42
  /** @public */
29
43
  export interface PublicationPipeline {
30
44
  /** @public */
31
45
  number: number;
46
+
32
47
  /** @public */
33
48
  status: string;
49
+
34
50
  /** @public */
35
51
  [key: string]: unknown;
36
52
  }
53
+
37
54
  /** @public */
38
55
  export interface PublicationParams {
39
56
  /** @public */
40
57
  owner: string;
58
+
41
59
  /** @public */
42
60
  repo: string;
61
+
43
62
  /** @public */
44
63
  workBranch: string;
64
+
45
65
  /** @public */
46
66
  baseBranch: string;
47
67
  }
68
+
69
+ /** Narrow process params to a resolved repository before publication. @public */
70
+ export function requirePublicationParams<P>(params: P): P & PublicationParams {
71
+ const value = asUnknownRecord(params);
72
+ for (const key of ["owner", "repo", "workBranch", "baseBranch"])
73
+ if (typeof value?.[key] !== "string" || !value[key])
74
+ throw new Error("Repository binding is not resolved");
75
+ return params as P & PublicationParams;
76
+ }
77
+
48
78
  /** @public */
49
79
  export type PublicationContext<P> = FlowAutomaticRunContext<P, RepositoryChangeState>;
80
+
50
81
  /** @public */
51
82
  export type PublicationEvidence = (
52
83
  | {
53
84
  /** @public */
54
85
  kind: "feedback";
86
+
55
87
  /** @public */
56
88
  feedbackIds: PublicationFeedbackId[];
89
+
57
90
  /** @public */
58
91
  conversationCursor: number;
92
+
59
93
  /** @public */
60
94
  reviewCursor: number;
95
+
61
96
  /** @public */
62
97
  inlineCursor: number;
63
98
  }
64
99
  | {
65
100
  /** @public */
66
101
  kind: "failure";
102
+
67
103
  /** @public */
68
104
  pipeline: PublicationPipeline;
69
105
  }
70
106
  | {
71
107
  /** @public */
72
108
  kind: "conflict";
109
+
73
110
  /** @public */
74
111
  conflict: ConflictEvidence;
75
112
  }
76
113
  | {
77
114
  /** @public */
78
115
  kind: "terminal";
116
+
79
117
  /** @public */
80
118
  request: PublicationRequest;
81
119
  }
@@ -90,143 +128,258 @@ export type PublicationEvidence = (
90
128
  ) & {
91
129
  /** @public */
92
130
  observationKey?: string;
131
+ /** Coordinated repository key. @public */ projectKey?: string;
93
132
  };
133
+
94
134
  /** @public */
95
135
  export interface PublicationSource<P> {
96
136
  /** @public */
97
137
  id: string;
138
+
98
139
  /** @public */
99
140
  kind: "feedback" | "failure" | "conflict" | "terminal" | "cancelled" | "observation";
141
+
100
142
  /** @public */
101
143
  operatorId?: string;
144
+
102
145
  /** @public */
103
146
  label: string;
147
+
104
148
  /** @public */
105
149
  source: ExternalActionSource<P, RepositoryChangeState, unknown>;
150
+
106
151
  /** @public */
107
- enabled?(params: P): boolean;
152
+ enabled?(params: P, state: RepositoryChangeState): boolean;
153
+
108
154
  /** @public */
109
155
  read(input: {
110
156
  /** @public */
111
157
  params: P;
158
+
112
159
  /** @public */
113
160
  state: RepositoryChangeState;
161
+
114
162
  /** @public */
115
163
  event: unknown;
116
164
  }): PublicationEvidence;
117
165
  }
166
+
118
167
  /** @public */
119
- export interface RepositoryChangePublicationAdapter<P extends PublicationParams> {
168
+ export interface RepositoryChangePublicationAdapter<P> {
169
+ /** Optional server maintenance uses existing business turns and adds no worker positions. @public */
170
+ maintenance?: {
171
+ /** @public */ source: ExternalActionSource<
172
+ P,
173
+ RepositoryChangeState,
174
+ PublicationMaintenanceEvent
175
+ >;
176
+ /** @public */ ownershipTool: string;
177
+ /** @public */ register(
178
+ api: ServerExtensionAPI,
179
+ process: ExtensionProcessDefinition<P, RepositoryChangeState>,
180
+ ): void;
181
+ };
120
182
  /** @public */
121
183
  namespace: string;
184
+ /** Reconcile a single-repository no-change outcome. @public */
185
+ unchanged?(ctx: PublicationContext<P>): Promise<void>;
186
+ /** Optional coordinated repositories; each retains independent publication state. @public */
187
+ repositories?(params: P): readonly {
188
+ /** @internal */
189
+ key: string;
190
+ /** @internal */
191
+ params: P & PublicationParams;
192
+ }[];
193
+ /** Reconcile remote terminal state before new writes or source cancellation. @public */
194
+ observeTerminal?(
195
+ ctx: PublicationContext<P>,
196
+ current: PublicationState,
197
+ ): Promise<PublicationRequest | null>;
198
+
199
+ /** @public */
200
+ sourceCancelled?(ctx: PublicationContext<P>): Promise<boolean>;
201
+
202
+ /** @public */
203
+ reconcileAll?(
204
+ ctx: PublicationContext<P>,
205
+ results: readonly {
206
+ /** @internal */
207
+ key: string;
208
+ /** @internal */
209
+ current: PublicationState;
210
+ }[],
211
+ cancelled: boolean,
212
+ ): Promise<void>;
213
+
122
214
  /** @public */
123
215
  label: string;
216
+
124
217
  /** @public */
125
218
  ids: {
126
219
  /** @public */
127
220
  deliver: string;
221
+
128
222
  /** @public */
129
223
  feedback: string;
224
+
130
225
  /** @public */
131
226
  ciRepair: string;
227
+
132
228
  /** @public */
133
229
  operator: string;
134
230
  };
231
+
135
232
  /** @public */
136
233
  tools: {
137
234
  /** @public */
138
235
  delivery: readonly string[];
236
+
139
237
  /** @public */
140
238
  feedback: readonly string[];
239
+
141
240
  /** @public */
142
241
  ci: readonly string[];
143
242
  };
243
+
144
244
  /** @public */
145
245
  sources: readonly PublicationSource<P>[];
246
+
146
247
  /** @public */
147
248
  identity(ctx: PublicationContext<P>): Promise<GitIdentity>;
249
+
148
250
  /** @public */
149
251
  ensureRequest(ctx: PublicationContext<P>): Promise<PublicationRequest>;
252
+
150
253
  /** @public */
151
254
  reconcileTerminal(
152
255
  ctx: PublicationContext<P>,
153
256
  current: PublicationState,
154
257
  request: PublicationRequest,
155
258
  ): Promise<void>;
259
+
156
260
  /** @public */
157
261
  linkIssue(ctx: PublicationContext<P>, current: PublicationState): Promise<void>;
262
+
158
263
  /** @public */
159
264
  acknowledge(ctx: PublicationContext<P>, current: PublicationState): Promise<void>;
265
+
160
266
  /** @public */
161
267
  reply(ctx: PublicationContext<P>, current: PublicationState): Promise<void>;
268
+
162
269
  /** @public */
163
270
  afterRebase(ctx: PublicationContext<P>, current: PublicationState): Promise<void>;
271
+
164
272
  /** @public */
165
273
  head(ctx: PublicationContext<P>, current: PublicationState): Promise<string>;
274
+
166
275
  /** @public */
167
276
  prompt(kind: "feedback" | "ci", current: PublicationState): string;
277
+
168
278
  /** @public */
169
279
  commitMessage(kind: "feedback" | "ci"): string;
170
280
  }
281
+
282
+ /** @public */
283
+ export interface PublicationMaintenanceEvent {
284
+ /** @public */
285
+ state: RepositoryChangeState;
286
+ }
287
+
288
+ /** @public */
289
+ export interface FeedbackDeliveryResult {
290
+ /** @public */
291
+ published: boolean;
292
+ /** @public */
293
+ summary: string;
294
+ }
295
+
171
296
  /** @public */
172
297
  export type PublicationFeedbackId = {
173
298
  /** @public */
174
299
  kind: "conversation" | "review" | "inline";
300
+
175
301
  /** @public */
176
302
  id: number;
303
+
177
304
  /** @public */
178
305
  discussionId?: string;
179
306
  };
307
+
180
308
  /** @public */
181
309
  type AdjustmentInvocation = {
182
310
  /** @public */
183
311
  origin: "feedback" | "ci" | "rebase";
312
+
184
313
  /** @public */
185
314
  publishRequired: boolean;
186
315
  };
187
316
 
188
317
  /** @public */
189
318
  export interface DeliveryState {
319
+ /** Feedback delivery retained until the server acknowledges the batch. @public */
320
+ feedbackResult?: FeedbackDeliveryResult | null;
190
321
  /** @public */
191
322
  stage: "not_started" | "branch_published" | "pull_request_ready" | "awaiting";
323
+
192
324
  /** @public */
193
325
  issueLinked: boolean;
326
+
194
327
  /** @public */
195
328
  adjustment: AdjustmentInvocation | null;
329
+
196
330
  /** @public */
197
331
  terminalPullRequest: PublicationRequest | null;
198
332
  }
199
333
 
200
334
  /** @public */
201
335
  export interface PublicationState {
336
+ /** Maintenance was stopped for this MR; it remains open and contributes a partial result. @public */ stopped?: boolean;
337
+ /** Repository had no change at first publication. @public */ noChanges?: boolean;
338
+
202
339
  /** @public */
203
340
  lastConflictKey?: string | null;
341
+
204
342
  /** @public */
205
343
  conflict?: ConflictEvidence | null;
344
+
206
345
  /** @public */
207
346
  repairReason?: "feedback" | "ci" | "rebase";
347
+ /** Staged repair retained when another maintained MR interrupts the worker. @public */
348
+ repairPending?: boolean;
349
+
208
350
  /** @public */
209
351
  headSha: string | null;
352
+
210
353
  /** @public */
211
354
  prNumber: number | null;
355
+
212
356
  /** @public */
213
357
  prUrl: string | null;
358
+
214
359
  /** @public */
215
360
  conversationCursor: number;
361
+
216
362
  /** @public */
217
363
  reviewCursor: number;
364
+
218
365
  /** @public */
219
366
  inlineCursor: number;
367
+
220
368
  /** @public */
221
369
  feedbackIds: PublicationFeedbackId[];
370
+
222
371
  /** @public */
223
372
  pipeline: PublicationPipeline | null;
373
+
224
374
  /** @public */
225
375
  ciRecoveryCycles: number;
376
+
226
377
  /** @public */
227
378
  delivery: DeliveryState;
379
+
228
380
  /** @public */
229
381
  observationKey?: string;
382
+
230
383
  /** @public */
231
384
  pendingEvidence?: PublicationEvidence | null;
232
385
  }
@@ -254,6 +407,29 @@ const initialPublicationState: PublicationState = {
254
407
  /** @public */
255
408
  export const publicationObject = (value: unknown) => asUnknownRecord(value) ?? {};
256
409
 
410
+ /** Shared coordination metadata for worker publication and server maintenance. @internal */
411
+ export function createPublicationSelection(namespace: () => string) {
412
+ return {
413
+ /** @internal */
414
+ activeKey: (state: RepositoryChangeState) =>
415
+ publicationObject(state.extensionState?.[`${namespace()}.coordination`]).activeKey as
416
+ | string
417
+ | undefined,
418
+ /** @internal */
419
+ select: (state: RepositoryChangeState, key: string): RepositoryChangeState => ({
420
+ ...state,
421
+ extensionState: {
422
+ ...state.extensionState,
423
+ [`${namespace()}.coordination`]: { activeKey: key },
424
+ },
425
+ }),
426
+ };
427
+ }
428
+
429
+ /** @internal */
430
+ export const publicationFinished = (current: PublicationState): boolean =>
431
+ !!(current.stopped || current.noChanges || current.delivery.terminalPullRequest);
432
+
257
433
  /** @public */
258
434
  export function readPublicationState(
259
435
  state: RepositoryChangeState,
@@ -295,7 +471,7 @@ export function patchPublicationState(
295
471
 
296
472
  /** @public */
297
473
  export function applyPublicationEvidence(
298
- params: PublicationParams,
474
+ params: unknown,
299
475
  current: PublicationState,
300
476
  evidence: PublicationEvidence,
301
477
  countFailure = true,
@@ -315,15 +491,16 @@ export function applyPublicationEvidence(
315
491
  ciRecoveryCycles: current.ciRecoveryCycles + (countFailure ? 1 : 0),
316
492
  };
317
493
  case "conflict": {
494
+ const repository = requirePublicationParams(params);
318
495
  const conflict = validateConflict(
319
496
  evidence.conflict,
320
497
  {
321
- owner: params.owner,
322
- repo: params.repo,
498
+ owner: repository.owner,
499
+ repo: repository.repo,
323
500
  prNumber: current.prNumber ?? 0,
324
501
  headSha: current.headSha ?? "",
325
- headBranch: params.workBranch,
326
- baseBranch: params.baseBranch,
502
+ headBranch: repository.workBranch,
503
+ baseBranch: repository.baseBranch,
327
504
  },
328
505
  current.lastConflictKey,
329
506
  );
@@ -390,174 +567,302 @@ function deliveryProgress(value: PublicationState, label: string, activeStepId?:
390
567
  }
391
568
 
392
569
  /** @public */
393
- export function createRepositoryChangePublication<P extends PublicationParams>(
570
+ export function createRepositoryChangePublication<P>(
394
571
  adapter: RepositoryChangePublicationAdapter<P>,
395
572
  ) {
396
- const applyEvidence = applyPublicationEvidence;
397
573
  const ids = adapter.ids;
398
574
  const publication = flow.fragment<P, RepositoryChangeState>(`${adapter.namespace}-publication`);
399
- const remote = (state: RepositoryChangeState) => readPublicationState(state, adapter.namespace);
575
+ const { activeKey, select } = createPublicationSelection(() => adapter.namespace);
576
+ const namespace = (state: RepositoryChangeState) =>
577
+ adapter.repositories ? `${adapter.namespace}:${activeKey(state)}` : adapter.namespace;
578
+ const remote = (state: RepositoryChangeState) => readPublicationState(state, namespace(state));
579
+ const repositoryContext = (ctx: PublicationContext<P>): PublicationContext<P> => {
580
+ if (!adapter.repositories) return ctx;
581
+ const selected = adapter
582
+ .repositories(ctx.params)
583
+ .find((repo) => repo.key === activeKey(ctx.state));
584
+ if (!selected) throw new Error("Missing coordinated repository selection");
585
+ return {
586
+ ...ctx,
587
+ params: selected.params,
588
+ repo: { ...ctx.repo, get: (key) => ctx.repo.get(key === "repo" ? selected.key : key) },
589
+ callIntegrationTool: (name, args) =>
590
+ ctx.callIntegrationTool(name, { ...args, projectKey: selected.key }),
591
+ };
592
+ };
400
593
  const patchRemote = (
401
594
  state: RepositoryChangeState,
402
595
  patch: Partial<Omit<PublicationState, "delivery">> & { delivery?: Partial<DeliveryState> },
403
- ) => patchPublicationState(state, adapter.namespace, patch);
596
+ ) => patchPublicationState(state, namespace(state), patch);
404
597
  async function commitWorkBranch(ctx: PublicationContext<P>, commitMessage: string) {
405
598
  const repo = ctx.repo.get("repo");
599
+ const gitIdentity = await adapter.identity(ctx);
600
+ if (adapter.maintenance)
601
+ await ctx.callIntegrationTool(adapter.maintenance.ownershipTool, { projectKey: repo.key });
406
602
  return commitAndPushWorkBranch({
407
603
  repoPath: repo.fsPath,
604
+ projectKey: repo.key,
408
605
  workBranch: repo.workBranch,
409
606
  commitMessage,
410
- gitIdentity: await adapter.identity(ctx),
607
+ gitIdentity,
411
608
  });
412
609
  }
413
- const delivery = flow
414
- .automatic<P, RepositoryChangeState>(ids.deliver)
415
- .description("Deliver")
416
- .integrationTools(...adapter.tools.delivery)
417
- .run(async (ctx) => {
418
- let current = remote(ctx.state);
419
- const update = (patch: Parameters<typeof patchRemote>[1]) => {
420
- current = { ...current, ...patch, delivery: { ...current.delivery, ...patch.delivery } };
421
- };
422
- const result = (
423
- outcome:
424
- | "awaiting"
425
- | "feedback_ready"
426
- | "completed"
427
- | "aborted"
428
- | "ci_ready"
429
- | "conflict_ready"
430
- | "operator_action",
431
- ) => ({
432
- outcome,
433
- params: { nextState: patchRemote(ctx.state, current) },
434
- });
435
- if (current.pendingEvidence) {
436
- const evidence = current.pendingEvidence;
437
- const needsOperator = evidence.kind === "failure" && current.ciRecoveryCycles >= 3;
438
- current = applyEvidence(ctx.params, current, evidence, !needsOperator);
439
- current.pendingEvidence = null;
440
- if (evidence.kind === "cancelled") return result("aborted");
441
- if (evidence.kind === "failure")
442
- return result(needsOperator ? "operator_action" : "ci_ready");
443
- if (evidence.kind === "conflict") return result("conflict_ready");
444
- }
610
+ const runRepository = async (ctx: PublicationContext<P>) => {
611
+ let current = remote(ctx.state);
612
+ const update = (patch: Parameters<typeof patchRemote>[1]) => {
613
+ current = { ...current, ...patch, delivery: { ...current.delivery, ...patch.delivery } };
614
+ };
615
+ const result = (
616
+ outcome:
617
+ | "awaiting"
618
+ | "feedback_ready"
619
+ | "completed"
620
+ | "aborted"
621
+ | "ci_ready"
622
+ | "conflict_ready"
623
+ | "operator_action",
624
+ ) => ({
625
+ outcome,
626
+ params: { nextState: patchRemote(ctx.state, current) },
627
+ });
628
+ if (current.stopped) return result("aborted");
629
+ if (current.pendingEvidence) {
630
+ const evidence = current.pendingEvidence;
631
+ const needsOperator = evidence.kind === "failure" && current.ciRecoveryCycles >= 3;
632
+ current = applyPublicationEvidence(ctx.params, current, evidence, !needsOperator);
633
+ current.pendingEvidence = null;
634
+ if (evidence.kind === "cancelled") return result("aborted");
635
+ if (evidence.kind === "failure")
636
+ return result(needsOperator ? "operator_action" : "ci_ready");
637
+ if (evidence.kind === "conflict") return result("conflict_ready");
638
+ }
639
+ ctx.reportProgress(deliveryProgress(current, adapter.label));
640
+
641
+ if (current.delivery.terminalPullRequest) {
642
+ ctx.reportProgress(deliveryProgress(current, adapter.label, "reconcile_terminal"));
643
+ const pr = current.delivery.terminalPullRequest;
644
+ await adapter.reconcileTerminal(ctx, current, pr);
445
645
  ctx.reportProgress(deliveryProgress(current, adapter.label));
646
+ return result(pr.merged ? "completed" : "aborted");
647
+ }
446
648
 
447
- if (current.delivery.terminalPullRequest) {
448
- ctx.reportProgress(deliveryProgress(current, adapter.label, "reconcile_terminal"));
449
- const pr = current.delivery.terminalPullRequest;
450
- await adapter.reconcileTerminal(ctx, current, pr);
451
- ctx.reportProgress(deliveryProgress(current, adapter.label));
452
- return result(pr.merged ? "completed" : "aborted");
453
- }
649
+ if (
650
+ !current.headSha &&
651
+ (adapter.repositories || adapter.unchanged) &&
652
+ !repositoryHasChanges(
653
+ ctx.repo.get("repo").fsPath,
654
+ ctx.repo.get("repo").baseBranch,
655
+ ctx.repo.get("repo").key,
656
+ )
657
+ ) {
658
+ update({ noChanges: true });
659
+ await adapter.unchanged?.(ctx);
660
+ return result("completed");
661
+ }
662
+ if (!current.headSha) {
663
+ ctx.reportProgress(deliveryProgress(current, adapter.label, "publish_branch"));
664
+ const published = await commitWorkBranch(
665
+ ctx,
666
+ ctx.state.finalization.commitMessages?.[ctx.repo.get("repo").key] ??
667
+ ctx.state.finalization.generatedCommitMessage ??
668
+ "",
669
+ );
670
+ update({ headSha: published.headSha, pipeline: null });
671
+ }
454
672
 
455
- if (!current.headSha) {
456
- ctx.reportProgress(deliveryProgress(current, adapter.label, "publish_branch"));
457
- const published = await commitWorkBranch(
458
- ctx,
459
- ctx.state.finalization.generatedCommitMessage ?? "",
460
- );
673
+ if (!current.prNumber || !current.prUrl) {
674
+ ctx.reportProgress(deliveryProgress(current, adapter.label, "open_pr"));
675
+ const pr = await adapter.ensureRequest(ctx);
676
+ update({ prNumber: pr.number, prUrl: pr.html_url });
677
+ }
678
+
679
+ if (!current.delivery.issueLinked) {
680
+ ctx.reportProgress(deliveryProgress(current, adapter.label, "link_issue"));
681
+ await adapter.linkIssue(ctx, current);
682
+ update({ delivery: { issueLinked: true } });
683
+ }
684
+
685
+ if (current.delivery.adjustment) {
686
+ const adjustment = current.delivery.adjustment;
687
+ if (adjustment.publishRequired || adjustment.origin === "rebase") {
688
+ ctx.reportProgress(deliveryProgress(current, adapter.label, "publish_adjustment"));
689
+ if (adapter.maintenance)
690
+ await ctx.callIntegrationTool(adapter.maintenance.ownershipTool, {
691
+ projectKey: ctx.repo.get("repo").key,
692
+ });
693
+ const published =
694
+ adjustment.origin === "rebase"
695
+ ? publishRebase(rebaseInput(ctx))
696
+ : await commitWorkBranch(ctx, adapter.commitMessage(adjustment.origin));
697
+ if (adjustment.origin === "rebase") {
698
+ const head = await adapter.head(ctx, current);
699
+ if (head !== published.headSha)
700
+ throw new Error("Pull request head has not caught up with rebase publication");
701
+ }
461
702
  update({ headSha: published.headSha, pipeline: null });
462
703
  }
463
-
464
- if (!current.prNumber || !current.prUrl) {
465
- ctx.reportProgress(deliveryProgress(current, adapter.label, "open_pr"));
466
- const pr = await adapter.ensureRequest(ctx);
467
- update({ prNumber: pr.number, prUrl: pr.html_url });
704
+ if (adjustment.origin === "rebase") await adapter.afterRebase(ctx, current);
705
+ if (adjustment.origin === "feedback" && !adapter.maintenance) {
706
+ ctx.reportProgress(deliveryProgress(current, adapter.label, "reply_feedback"));
707
+ await adapter.reply(ctx, current);
468
708
  }
709
+ update({
710
+ ...(adjustment.origin === "feedback" && !adapter.maintenance ? { feedbackIds: [] } : {}),
711
+ ...(adjustment.origin === "rebase" ? { conflict: null } : {}),
712
+ delivery: {
713
+ adjustment: null,
714
+ ...(adjustment.origin === "feedback" && adapter.maintenance
715
+ ? {
716
+ feedbackResult: {
717
+ published: adjustment.publishRequired,
718
+ summary: "Review adjustment published",
719
+ },
720
+ }
721
+ : {}),
722
+ },
723
+ });
724
+ }
469
725
 
470
- if (!current.delivery.issueLinked) {
471
- ctx.reportProgress(deliveryProgress(current, adapter.label, "link_issue"));
472
- await adapter.linkIssue(ctx, current);
473
- update({ delivery: { issueLinked: true } });
474
- }
726
+ if (current.feedbackIds.length > 0 && !adapter.maintenance) {
727
+ ctx.reportProgress(deliveryProgress(current, adapter.label, "reply_feedback"));
728
+ await adapter.acknowledge(ctx, current);
729
+ return result("feedback_ready");
730
+ }
475
731
 
476
- if (current.delivery.adjustment) {
477
- const adjustment = current.delivery.adjustment;
478
- if (adjustment.publishRequired || adjustment.origin === "rebase") {
479
- ctx.reportProgress(deliveryProgress(current, adapter.label, "publish_adjustment"));
480
- const published =
481
- adjustment.origin === "rebase"
482
- ? publishRebase(rebaseInput(ctx))
483
- : await commitWorkBranch(ctx, adapter.commitMessage(adjustment.origin));
484
- if (adjustment.origin === "rebase") {
485
- const head = await adapter.head(ctx, current);
486
- if (head !== published.headSha)
487
- throw new Error("Pull request head has not caught up with rebase publication");
488
- }
489
- update({ headSha: published.headSha, pipeline: null });
732
+ update({ delivery: { stage: "awaiting" } });
733
+ ctx.reportProgress(deliveryProgress(current, adapter.label, "await_evidence"));
734
+ return result("awaiting");
735
+ };
736
+ const delivery = flow
737
+ .automatic<P, RepositoryChangeState>(ids.deliver)
738
+ .description("Deliver")
739
+ .waitFor(({ state, params }) => {
740
+ const states = adapter.repositories
741
+ ? adapter.repositories(params).map(({ key }) => select(state, key))
742
+ : [state];
743
+ return states.some((state) => {
744
+ const current = remote(state);
745
+ if (adapter.maintenance)
746
+ return (
747
+ !current.stopped &&
748
+ !current.noChanges &&
749
+ !current.delivery.terminalPullRequest &&
750
+ (current.delivery.stage !== "awaiting" ||
751
+ !!(
752
+ current.delivery.adjustment &&
753
+ (current.delivery.adjustment.publishRequired ||
754
+ current.delivery.adjustment.origin === "rebase")
755
+ ))
756
+ );
757
+ return (
758
+ current.delivery.stage !== "awaiting" ||
759
+ !!current.pendingEvidence ||
760
+ !!current.delivery.adjustment ||
761
+ current.feedbackIds.length > 0 ||
762
+ !!current.delivery.terminalPullRequest
763
+ );
764
+ });
765
+ })
766
+ .integrationTools(...adapter.tools.delivery)
767
+ .run(async (ctx) => {
768
+ if (!adapter.repositories) return runRepository(ctx);
769
+ let state = ctx.state;
770
+ const repositories = adapter.repositories(ctx.params);
771
+ if (!repositories.length) throw new Error("No repositories are bound");
772
+ const results = () =>
773
+ repositories.map(({ key }) => ({ key, current: remote(select(state, key)) }));
774
+ const finished = () => results().every(({ current }) => publicationFinished(current));
775
+ // Terminal facts take precedence over cancellation, including after interrupted publication.
776
+ const reconcileTerminals = async () => {
777
+ for (const { key } of repositories) {
778
+ state = select(state, key);
779
+ const current = remote(state);
780
+ if (publicationFinished(current)) continue;
781
+ const terminal = await adapter.observeTerminal?.(
782
+ repositoryContext({ ...ctx, state }),
783
+ current,
784
+ );
785
+ if (terminal)
786
+ state = patchRemote(state, {
787
+ prNumber: terminal.number,
788
+ prUrl: terminal.html_url,
789
+ delivery: { terminalPullRequest: terminal },
790
+ });
490
791
  }
491
- if (adjustment.origin === "rebase") await adapter.afterRebase(ctx, current);
492
- if (adjustment.origin === "feedback") {
493
- ctx.reportProgress(deliveryProgress(current, adapter.label, "reply_feedback"));
494
- await adapter.reply(ctx, current);
792
+ };
793
+ await reconcileTerminals();
794
+ let cancelled = false;
795
+ for (const { key } of repositories) {
796
+ state = select(state, key);
797
+ if (publicationFinished(remote(state))) continue;
798
+ if (await adapter.sourceCancelled?.({ ...ctx, state })) {
799
+ await reconcileTerminals();
800
+ cancelled = !finished();
801
+ break;
495
802
  }
496
- update({
497
- ...(adjustment.origin === "feedback" ? { feedbackIds: [] } : {}),
498
- delivery: { adjustment: null },
499
- });
803
+ const result = await runRepository(repositoryContext({ ...ctx, state }));
804
+ state = result.params.nextState;
805
+ if (!["awaiting", "completed", "aborted"].includes(result.outcome))
806
+ return { ...result, params: { nextState: state } };
500
807
  }
501
-
502
- if (current.feedbackIds.length > 0) {
503
- ctx.reportProgress(deliveryProgress(current, adapter.label, "reply_feedback"));
504
- await adapter.acknowledge(ctx, current);
505
- return result("feedback_ready");
808
+ if (cancelled || finished()) {
809
+ await adapter.reconcileAll?.({ ...ctx, state }, results(), cancelled);
810
+ const requests = results().flatMap(({ current }) =>
811
+ current.delivery.terminalPullRequest ? [current.delivery.terminalPullRequest] : [],
812
+ );
813
+ return {
814
+ outcome:
815
+ cancelled || (requests.length > 0 && requests.every((request) => !request.merged))
816
+ ? "aborted"
817
+ : "completed",
818
+ params: { nextState: state },
819
+ };
506
820
  }
507
-
508
- update({ delivery: { stage: "awaiting" } });
509
- ctx.reportProgress(deliveryProgress(current, adapter.label, "await_evidence"));
510
- return result("awaiting");
511
- })
512
- .outcome("awaiting", (outcome) =>
513
- outcome
514
- .description("Delivery is waiting for external evidence")
515
- .object("nextState")
516
- .wait()
517
- .state(({ event }) => event.params.nextState as RepositoryChangeState),
518
- )
519
- .outcome("feedback_ready", (outcome) =>
520
- outcome
521
- .description("Pull request feedback is acknowledged and ready for revision")
522
- .object("nextState")
523
- .to(ids.feedback)
524
- .state(({ event }) => event.params.nextState as RepositoryChangeState),
525
- )
526
- .outcome("completed", (outcome) =>
527
- outcome
528
- .description("Merged pull request was reconciled")
529
- .object("nextState")
530
- .complete()
531
- .state(({ event }) => event.params.nextState as RepositoryChangeState),
532
- )
533
- .outcome("aborted", (outcome) =>
534
- outcome
535
- .description("Closed pull request was reconciled")
536
- .object("nextState")
537
- .lifecycleStatus("aborted")
538
- .state(({ event }) => event.params.nextState as RepositoryChangeState),
821
+ return { outcome: "awaiting", params: { nextState: state } };
822
+ });
823
+ const outcome = (o: AutomaticOutcomeBuilder<P, RepositoryChangeState>, description: string) =>
824
+ o
825
+ .description(description)
826
+ .object("nextState")
827
+ .state(({ event }) => event.params.nextState as RepositoryChangeState);
828
+ delivery
829
+ .outcome("awaiting", (o) => outcome(o, "Delivery is waiting for external evidence").wait())
830
+ .outcome("completed", (o) => outcome(o, "Merged pull request was reconciled").complete())
831
+ .outcome("aborted", (o) =>
832
+ outcome(o, "Closed pull request was reconciled").lifecycleStatus("aborted"),
539
833
  );
540
- for (const [outcome, target] of [
541
- ["ci_ready", ids.ciRepair],
542
- ["conflict_ready", ids.feedback],
543
- ["operator_action", ids.operator],
544
- ] as const) {
545
- delivery.outcome(outcome, (o) =>
546
- o
547
- .description("Route observed delivery evidence")
548
- .object("nextState")
549
- .to(target)
550
- .state(({ event }) => event.params.nextState as RepositoryChangeState),
834
+ if (!adapter.maintenance)
835
+ delivery.outcome("feedback_ready", (o) =>
836
+ outcome(o, "Pull request feedback is acknowledged and ready for revision").to(ids.feedback),
551
837
  );
838
+ for (const [name, target] of adapter.maintenance
839
+ ? []
840
+ : ([
841
+ ["ci_ready", ids.ciRepair],
842
+ ["conflict_ready", ids.feedback],
843
+ ["operator_action", ids.operator],
844
+ ] as const)) {
845
+ delivery.outcome(name, (o) => outcome(o, "Route observed delivery evidence").to(target));
552
846
  }
553
847
  for (const source of adapter.sources) {
848
+ if (adapter.maintenance && source.kind === "observation") continue;
554
849
  const attach = (id: string, operator: boolean) =>
555
850
  delivery.externalAction(id, source.source, (external) => {
556
851
  external
557
852
  .label(source.label)
558
853
  .when(
559
854
  ({ params, state }) =>
560
- (!source.enabled || source.enabled(params)) &&
855
+ (!source.enabled || source.enabled(params, state)) &&
856
+ (source.kind === "cancelled" ||
857
+ (adapter.repositories
858
+ ? adapter.repositories(params).map(({ key }) => remote(select(state, key)))
859
+ : [remote(state)]
860
+ ).every(
861
+ (current) =>
862
+ current.noChanges ||
863
+ current.delivery.terminalPullRequest ||
864
+ !!(current.headSha && current.prNumber && current.prUrl),
865
+ )) &&
561
866
  (source.kind !== "failure" || remote(state).ciRecoveryCycles >= 3 === operator),
562
867
  );
563
868
  if (source.kind === "cancelled") return external.lifecycleStatus("aborted");
@@ -572,13 +877,17 @@ export function createRepositoryChangePublication<P extends PublicationParams>(
572
877
  );
573
878
  return external.effect((input) => {
574
879
  const evidence = source.read(input);
575
- const current = remote(input.state);
880
+ const state =
881
+ adapter.repositories && evidence.projectKey
882
+ ? select(input.state, evidence.projectKey)
883
+ : input.state;
884
+ const current = remote(state);
576
885
  return {
577
886
  state: patchRemote(
578
- input.state,
887
+ state,
579
888
  source.kind === "observation"
580
889
  ? { pendingEvidence: evidence }
581
- : applyEvidence(input.params, current, evidence, !operator),
890
+ : applyPublicationEvidence(input.params, current, evidence, !operator),
582
891
  ),
583
892
  };
584
893
  });
@@ -586,15 +895,34 @@ export function createRepositoryChangePublication<P extends PublicationParams>(
586
895
  attach(source.id, false);
587
896
  if (source.kind === "failure") attach(source.operatorId ?? `${source.id}_operator`, true);
588
897
  }
898
+ if (adapter.maintenance) {
899
+ for (const [id, target] of [
900
+ ["feedback", ids.feedback],
901
+ ["conflict", ids.feedback],
902
+ ["ci", ids.ciRepair],
903
+ ["operator", ids.operator],
904
+ ] as const)
905
+ delivery.externalAction(`maintenance_${id}`, adapter.maintenance.source, (action) =>
906
+ action
907
+ .label("Maintain MR")
908
+ .to(target)
909
+ .effect(({ event }) => ({ state: event.state })),
910
+ );
911
+ }
589
912
  publication.turn(delivery);
590
913
  function rebaseInput(ctx: {
591
914
  state: RepositoryChangeState;
592
915
  repo: { get(key: string): { fsPath: string; workBranch: string } };
593
916
  }) {
594
- const project = ctx.repo.get("repo");
917
+ const project = ctx.repo.get(activeKey(ctx.state) ?? "repo");
595
918
  const conflict = remote(ctx.state).conflict;
596
919
  if (!conflict) throw new Error("Missing conflict evidence");
597
- return { projectKey: "repo", path: project.fsPath, workBranch: project.workBranch, conflict };
920
+ return {
921
+ projectKey: activeKey(ctx.state) ?? "repo",
922
+ path: project.fsPath,
923
+ workBranch: project.workBranch,
924
+ conflict,
925
+ };
598
926
  }
599
927
  function repairReason(state: RepositoryChangeState, kind: "feedback" | "ci") {
600
928
  return kind === "feedback" && remote(state).repairReason === "rebase" ? "rebase" : kind;
@@ -605,7 +933,7 @@ export function createRepositoryChangePublication<P extends PublicationParams>(
605
933
  const current = remote(ctx.state);
606
934
  if (repairReason(ctx.state, kind) === "rebase")
607
935
  return `${rebasePrompt} Evidence: ${JSON.stringify(current.conflict)}. Call changes_ready or no_changes when verified complete, cannot_repair when blocked.`;
608
- return adapter.prompt(kind, current);
936
+ return `${adapter.repositories ? `Repository: ${activeKey(ctx.state)}. Apply changes only to this checkout. ` : ""}${adapter.prompt(kind, current)}`;
609
937
  };
610
938
  }
611
939
 
@@ -613,6 +941,17 @@ export function createRepositoryChangePublication<P extends PublicationParams>(
613
941
  const turn = flow
614
942
  .llm<P, RepositoryChangeState>(id)
615
943
  .description(kind === "feedback" ? "Address Feedback" : "Fix CI")
944
+ .waitFor(({ state }) => {
945
+ const current = remote(state);
946
+ return (
947
+ !current.stopped &&
948
+ !current.delivery.terminalPullRequest &&
949
+ (kind === "feedback"
950
+ ? current.feedbackIds.length > 0 || !!current.conflict
951
+ : current.repairReason === "ci" && current.pipeline !== null)
952
+ );
953
+ })
954
+ .executionPurpose(codingPurposes.implementation)
616
955
  .tools("read", "bash", "edit", "write")
617
956
  .resolveIntegrationTools((_params, state) =>
618
957
  repairReason(state, kind) === "rebase" ? [] : adapter.tools[kind],
@@ -631,26 +970,63 @@ export function createRepositoryChangePublication<P extends PublicationParams>(
631
970
  .resultSummary()
632
971
  .description(description)
633
972
  .to(ids.deliver)
634
- .state(({ ctx }) =>
973
+ .state(({ ctx, event }) =>
635
974
  patchRemote(ctx.state, {
636
- delivery: { adjustment: { origin: repairReason(ctx.state, kind), publishRequired } },
975
+ repairPending: false,
976
+ delivery: {
977
+ adjustment: { origin: repairReason(ctx.state, kind), publishRequired },
978
+ ...(!publishRequired &&
979
+ adapter.maintenance &&
980
+ repairReason(ctx.state, kind) !== "rebase"
981
+ ? {
982
+ feedbackResult: {
983
+ published: false,
984
+ summary: String(
985
+ event.params.resultSummary ?? "No repository change was required",
986
+ ),
987
+ },
988
+ }
989
+ : {}),
990
+ },
637
991
  }),
638
992
  ),
639
993
  );
640
994
  }
641
- return turn.outcomeTool("cannot_repair", (tool) =>
642
- tool.description("The adjustment requires operator action").to(ids.operator),
643
- );
995
+ return turn.outcomeTool("cannot_repair", (tool) => {
996
+ const outcome = tool.description("The adjustment requires operator action").to(ids.operator);
997
+ return adapter.maintenance
998
+ ? outcome.state(({ ctx }) => patchRemote(ctx.state, { repairPending: false }))
999
+ : outcome;
1000
+ });
644
1001
  }
645
1002
 
646
1003
  publication.turn(revisionTurn(ids.feedback, "feedback"));
647
1004
  publication.turn(revisionTurn(ids.ciRepair, "ci"));
1005
+ const maintenanceSource = adapter.maintenance?.source;
648
1006
  publication.turn({
649
1007
  id: ids.operator,
650
1008
  definition: {
651
1009
  kind: "human",
652
1010
  description: "Repository repair needs operator action",
653
1011
  operatorAttention: "required",
1012
+ ...(maintenanceSource
1013
+ ? {
1014
+ externalActions: Object.fromEntries(
1015
+ (["feedback", "conflict"] as const).map((id) => [
1016
+ `maintenance_${id}`,
1017
+ {
1018
+ id: `maintenance_${id}`,
1019
+ source: maintenanceSource,
1020
+ to: ids.feedback,
1021
+ label: "Maintain MR",
1022
+ effect: ({ event }: { event: unknown }) => ({
1023
+ state: (event as { state: RepositoryChangeState }).state,
1024
+ }),
1025
+ },
1026
+ ]),
1027
+ ),
1028
+ }
1029
+ : {}),
654
1030
  actions: {
655
1031
  retry_repair: {
656
1032
  label: "Retry repair",
@@ -668,6 +1044,7 @@ export function createRepositoryChangePublication<P extends PublicationParams>(
668
1044
  to: ids.deliver,
669
1045
  effect: ({ ctx }) => ({
670
1046
  state: patchRemote(ctx.state, {
1047
+ repairPending: false,
671
1048
  feedbackIds: [],
672
1049
  delivery: { adjustment: null },
673
1050
  }),
@@ -681,8 +1058,10 @@ export function createRepositoryChangePublication<P extends PublicationParams>(
681
1058
  return {
682
1059
  /** @public */
683
1060
  entryTurnId: ids.deliver,
1061
+
684
1062
  /** @public */
685
1063
  fragment: publication,
1064
+
686
1065
  /** @public */
687
1066
  happyPath: [ids.deliver],
688
1067
  };