@leitwerk-dev/coding 0.3.1 → 0.4.1

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 (123) hide show
  1. package/README.md +154 -13
  2. package/dist/chunk-3WJRJ3Q7.js +220 -0
  3. package/dist/chunk-3WJRJ3Q7.js.map +1 -0
  4. package/dist/chunk-ABQH2WZT.js +36 -0
  5. package/dist/chunk-ABQH2WZT.js.map +1 -0
  6. package/dist/chunk-B3PE6DPF.js +820 -0
  7. package/dist/chunk-B3PE6DPF.js.map +1 -0
  8. package/dist/chunk-DNG7D77K.js +65 -0
  9. package/dist/chunk-DNG7D77K.js.map +1 -0
  10. package/dist/chunk-E3DB4TIZ.js +49 -0
  11. package/dist/chunk-E3DB4TIZ.js.map +1 -0
  12. package/dist/chunk-L2TFD72B.js +16320 -0
  13. package/dist/chunk-L2TFD72B.js.map +1 -0
  14. package/dist/chunk-M2VTUPFO.js +265 -0
  15. package/dist/chunk-M2VTUPFO.js.map +1 -0
  16. package/dist/{chunk-YSC5GEQJ.js → chunk-QD6FI4HR.js} +7 -3
  17. package/dist/chunk-QD6FI4HR.js.map +1 -0
  18. package/dist/chunk-SKGB4CZS.js +14 -0
  19. package/dist/chunk-SKGB4CZS.js.map +1 -0
  20. package/dist/chunk-SZ4WOGV2.js +120 -0
  21. package/dist/chunk-SZ4WOGV2.js.map +1 -0
  22. package/dist/finalization-git-internal.d.ts +9 -0
  23. package/dist/finalization-git-internal.d.ts.map +1 -1
  24. package/dist/finalization-git.d.ts +1 -1
  25. package/dist/finalization-git.d.ts.map +1 -1
  26. package/dist/finalization-git.js +6 -3
  27. package/dist/index.d.ts +1 -0
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/index.js +18 -591
  30. package/dist/index.js.map +1 -1
  31. package/dist/pull-request-publication-internal.d.ts +34 -24
  32. package/dist/pull-request-publication-internal.d.ts.map +1 -1
  33. package/dist/repository-change-launch-internal-BudnAfL7.d.ts +88 -0
  34. package/dist/repository-change-launch-internal.d.ts +32 -11
  35. package/dist/repository-change-launch-internal.d.ts.map +1 -1
  36. package/dist/repository-change-launch.d.ts +4 -3
  37. package/dist/repository-change-launch.d.ts.map +1 -1
  38. package/dist/repository-change-launch.js +162 -34
  39. package/dist/repository-change-launch.js.map +1 -1
  40. package/dist/repository-change-process-DlgF04fU.d.ts +69 -0
  41. package/dist/repository-change-process.d.ts +30 -25
  42. package/dist/repository-change-process.d.ts.map +1 -1
  43. package/dist/repository-change-publication.d.ts +76 -7
  44. package/dist/repository-change-publication.d.ts.map +1 -1
  45. package/dist/repository-change-publication.js +624 -136
  46. package/dist/repository-change-publication.js.map +1 -1
  47. package/dist/repository-change-state-internal.d.ts +18 -4
  48. package/dist/repository-change-state-internal.d.ts.map +1 -1
  49. package/dist/repository-change-ui-launcher-internal.d.ts +34 -22
  50. package/dist/repository-change-ui-launcher-internal.d.ts.map +1 -1
  51. package/dist/repository-publication-receipt.d.ts +23 -0
  52. package/dist/repository-publication-receipt.d.ts.map +1 -0
  53. package/dist/repository-rebase/git.d.ts +8 -0
  54. package/dist/repository-rebase/git.d.ts.map +1 -1
  55. package/dist/repository-reconciliation.d.ts +47 -0
  56. package/dist/repository-reconciliation.d.ts.map +1 -0
  57. package/dist/repository-record.d.ts +6 -0
  58. package/dist/repository-record.d.ts.map +1 -0
  59. package/dist/settings.d.ts +15 -0
  60. package/dist/settings.d.ts.map +1 -0
  61. package/dist/turns/commit-message-evidence.d.ts +35 -0
  62. package/dist/turns/commit-message-evidence.d.ts.map +1 -0
  63. package/dist/turns/commit-message-evidence.js +9 -0
  64. package/dist/turns/generate-commit-message.d.ts +4 -1
  65. package/dist/turns/generate-commit-message.d.ts.map +1 -1
  66. package/dist/turns/generate-commit-message.js +7 -5
  67. package/dist/turns/generate-plan.d.ts.map +1 -1
  68. package/dist/turns/generate-plan.js +1 -1
  69. package/dist/turns/git-inspection-profile.d.ts +25 -0
  70. package/dist/turns/git-inspection-profile.d.ts.map +1 -0
  71. package/dist/turns/git-inspection-profile.js +8 -0
  72. package/dist/turns/implement.d.ts +1 -1
  73. package/dist/turns/implement.d.ts.map +1 -1
  74. package/dist/turns/implement.js +1 -1
  75. package/dist/turns/simplify-implementation.d.ts +1 -1
  76. package/dist/turns/simplify-implementation.d.ts.map +1 -1
  77. package/dist/turns/simplify-implementation.js +3 -3
  78. package/package.json +5 -9
  79. package/src/finalization-git-internal.ts +186 -114
  80. package/src/finalization-git.ts +1 -1
  81. package/src/index.ts +4 -1
  82. package/src/pull-request-publication-internal.ts +158 -79
  83. package/src/repository-change-launch-internal.ts +119 -12
  84. package/src/repository-change-launch.ts +8 -4
  85. package/src/repository-change-process.ts +252 -524
  86. package/src/repository-change-publication.ts +702 -121
  87. package/src/repository-change-state-internal.ts +34 -20
  88. package/src/repository-change-ui-launcher-internal.ts +139 -56
  89. package/src/repository-publication-receipt.ts +71 -0
  90. package/src/repository-rebase/git.ts +108 -29
  91. package/src/repository-reconciliation.ts +600 -0
  92. package/src/repository-record.ts +14 -0
  93. package/src/settings.ts +79 -0
  94. package/src/turns/commit-message-evidence.ts +241 -0
  95. package/src/turns/generate-commit-message.ts +53 -23
  96. package/src/turns/generate-plan.ts +26 -12
  97. package/src/turns/git-inspection-profile.ts +134 -0
  98. package/src/turns/implement.ts +13 -3
  99. package/src/turns/simplify-implementation.ts +10 -6
  100. package/dist/chunk-34B3Q75M.js +0 -25
  101. package/dist/chunk-34B3Q75M.js.map +0 -1
  102. package/dist/chunk-F6CEEAFE.js +0 -13
  103. package/dist/chunk-F6CEEAFE.js.map +0 -1
  104. package/dist/chunk-GO44KCUS.js +0 -154
  105. package/dist/chunk-GO44KCUS.js.map +0 -1
  106. package/dist/chunk-R3UCUGY6.js +0 -31
  107. package/dist/chunk-R3UCUGY6.js.map +0 -1
  108. package/dist/chunk-W7VJT6AN.js +0 -25
  109. package/dist/chunk-W7VJT6AN.js.map +0 -1
  110. package/dist/chunk-WKHVLLKE.js +0 -45
  111. package/dist/chunk-WKHVLLKE.js.map +0 -1
  112. package/dist/chunk-YSC5GEQJ.js.map +0 -1
  113. package/dist/repository-change-launch-internal-Dd-AONUs.d.ts +0 -67
  114. package/dist/turns/review-implementation.d.ts +0 -4
  115. package/dist/turns/review-implementation.d.ts.map +0 -1
  116. package/dist/turns/review-implementation.js +0 -8
  117. package/dist/turns/review-plan.d.ts +0 -4
  118. package/dist/turns/review-plan.d.ts.map +0 -1
  119. package/dist/turns/review-plan.js +0 -8
  120. package/src/turns/review-implementation.ts +0 -30
  121. package/src/turns/review-plan.ts +0 -24
  122. /package/dist/turns/{review-implementation.js.map → commit-message-evidence.js.map} +0 -0
  123. /package/dist/turns/{review-plan.js.map → git-inspection-profile.js.map} +0 -0
@@ -1,43 +1,59 @@
1
- import { trimString as normalizeMessage, normalizeOptionalMarkdown } from "@leitwerk-dev/domain";
1
+ import { asUnknownRecord, trimString as normalizeMessage } from "@leitwerk-dev/domain";
2
2
  import {
3
- acceptedReviewHandoffAction,
4
3
  type Codec,
5
- createEmptyStructuralProcessState,
4
+ type ExternalActionSource,
6
5
  type FlowFragmentBuilder,
7
6
  type FormDefinition,
8
7
  flow,
9
- type HumanTurnDefinition,
10
8
  humanTurn,
11
9
  type ProcessLauncherDefinition,
12
10
  type RepositoryCredentialProject,
13
11
  type RepositoryCredentialRequirement,
14
12
  revisionAction,
15
13
  } from "@leitwerk-dev/process-sdk";
14
+ import { codingActionIds, requestRevisionForm } from "./actions.js";
16
15
  import {
17
- acceptReviewForm,
18
- codingActionIds,
19
- requestReviewChangesForm,
20
- requestRevisionForm,
21
- } from "./actions.js";
22
- import {
23
- clearReviewRefs,
24
- createEmptyRepositoryChangeFinalizationState,
25
16
  type RepositoryChangeState,
26
17
  repositoryChangeStateCodec,
27
18
  } from "./repository-change-state-internal.js";
19
+ import { prepareInitialRepository, reconciliationPrompt } from "./repository-reconciliation.js";
20
+ import { codingPurposes } from "./settings.js";
21
+ import { prepareRepositoryCommitMessageEvidence } from "./turns/commit-message-evidence.js";
28
22
  import {
29
- buildGenerateCommitMessagePrompt,
30
- normalizeGeneratedCommitMessage,
23
+ buildRepositoryCommitMessagesPrompt,
24
+ parseRepositoryCommitMessages,
31
25
  } from "./turns/generate-commit-message.js";
32
26
  import { buildGeneratePlanPrompt } from "./turns/generate-plan.js";
33
27
  import { buildImplementPrompt } from "./turns/implement.js";
34
- import { buildReviewImplementationPrompt } from "./turns/review-implementation.js";
35
- import { buildReviewPlanPrompt } from "./turns/review-plan.js";
36
- import { buildSimplifyImplementationPrompt } from "./turns/simplify-implementation.js";
28
+ import { buildStreamlinedSimplificationPrompt } from "./turns/simplify-implementation.js";
37
29
 
38
30
  /** @public */
39
31
  export type RepositoryChangeParams = object;
40
32
 
33
+ /** Server-side policies evaluated at the route boundary. @public */
34
+ export interface RepositoryChangeWorkflow<TParams> {
35
+ /** @deprecated All repository changes use the streamlined graph. @public */
36
+ variant?: "streamlined";
37
+ /** @public */
38
+ multiRepository?: boolean;
39
+ /** @public */
40
+ planDecision?(params: TParams): Promise<{
41
+ /** @internal */
42
+ skip: boolean;
43
+ /** @internal */
44
+ reason: string;
45
+ }>;
46
+ /** @public */
47
+ simplification?(params: TParams): Promise<{
48
+ /** @internal */
49
+ skip: boolean;
50
+ /** @internal */
51
+ reason: string;
52
+ }>;
53
+ /** Must recheck the current revision and source before firing. @public */
54
+ planBypassSource?: ExternalActionSource<TParams, RepositoryChangeState, unknown>;
55
+ }
56
+
41
57
  /** @public */
42
58
  export interface RepositoryChangeProcessConfig<TParams extends RepositoryChangeParams> {
43
59
  /** @public */
@@ -45,13 +61,15 @@ export interface RepositoryChangeProcessConfig<TParams extends RepositoryChangeP
45
61
  /** @public */
46
62
  displayName: string;
47
63
  /** @public */
64
+ workflow?: RepositoryChangeWorkflow<TParams>;
65
+ /** @public */
48
66
  paramsCodec: Codec<TParams>;
49
67
  /** @public */
50
68
  launcher?: ProcessLauncherDefinition<TParams>;
51
- /** @public */
52
- finalizeLabel: string;
53
- /** @public */
54
- finalizeForm: FormDefinition;
69
+ /** @deprecated Publication follows implementation automatically. @public */
70
+ finalizeLabel?: string;
71
+ /** @deprecated Publication follows implementation automatically. @public */
72
+ finalizeForm?: FormDefinition;
55
73
  /** @public */
56
74
  repositoryCredentials?(input: {
57
75
  /** @public */
@@ -74,124 +92,8 @@ export interface RepositoryChangeProcessConfig<TParams extends RepositoryChangeP
74
92
  export function createRepositoryChangeProcess<TParams extends RepositoryChangeParams>(
75
93
  config: RepositoryChangeProcessConfig<TParams>,
76
94
  ) {
77
- const turnIds = {
78
- generatePlan: "generate_plan",
79
- planDecision: "plan_decision",
80
- reviewPlan: "review_plan",
81
- planReviewFeedback: "plan_review_feedback",
82
- implement: "implement",
83
- implementationDecision: "implementation_decision",
84
- reviewImplementation: "review_implementation",
85
- implementationReviewFeedback: "implementation_review_feedback",
86
- simplifyImplementation: "simplify_implementation",
87
- simplificationDecision: "simplification_decision",
88
- generateCommitMessage: "generate_commit_message",
89
- } as const;
90
-
91
- const products = {
92
- plan: "plan",
93
- review: "review",
94
- simplificationPlan: "simplification-plan",
95
- implementationSummary: "implementation-summary",
96
- commitMessage: "commit-message",
97
- } as const;
98
-
99
- const implementationTurnAvailableTools = ["read", "bash", "edit", "write"] as const;
100
-
101
- function hasResolvedTurnRecordRef(
102
- ref: RepositoryChangeState["semanticEntryRefs"][keyof RepositoryChangeState["semanticEntryRefs"]],
103
- ): ref is { entryId: string; turnRecordId: string } {
104
- return typeof ref?.turnRecordId === "string" && ref.turnRecordId.trim() !== "";
105
- }
106
-
107
- function requireResolvedPlanRef(
108
- plan: RepositoryChangeState["semanticEntryRefs"][keyof RepositoryChangeState["semanticEntryRefs"]],
109
- usage: "approval" | "review" | "simplification review" | "implementation review",
110
- ): asserts plan is { entryId: string; turnRecordId: string } {
111
- if (!hasResolvedTurnRecordRef(plan)) {
112
- throw new Error(`No plan is available for ${usage}`);
113
- }
114
- }
115
-
116
- function clearReviewState(state: RepositoryChangeState): RepositoryChangeState {
117
- return patchRepositoryChangeState(state, {
118
- clearReviewRefs: true,
119
- clearProductRefs: [products.simplificationPlan],
120
- });
121
- }
122
-
123
- function buildAcceptedFollowUpMessage(input: {
124
- kind: "plan_review" | "implementation_review" | "simplification";
125
- markdown: unknown;
126
- adjustment: unknown;
127
- }): string {
128
- const markdown = normalizeOptionalMarkdown(input.markdown);
129
- if (!markdown) {
130
- throw new Error(
131
- input.kind === "simplification"
132
- ? "No simplification plan markdown is available to accept"
133
- : "No review output markdown is available to accept",
134
- );
135
- }
136
- const adjustment = normalizeMessage(input.adjustment);
137
- const subject = input.kind === "simplification" ? "simplification plan" : "review";
138
- const introduction =
139
- input.kind === "plan_review"
140
- ? "Revise the plan according to this review:"
141
- : `Implement according to this ${subject}:`;
142
- const sections = [introduction, markdown];
143
- if (adjustment) {
144
- sections.push(
145
- `Also follow this adjustment where it conflicts with the ${subject}:`,
146
- adjustment,
147
- );
148
- }
149
- if (input.kind !== "plan_review") {
150
- sections.push(
151
- [
152
- "This is now an implementation turn. Ignore earlier review-only or read-only instructions.",
153
- "You may change files in the repository workspace.",
154
- `Use the available tools (${implementationTurnAvailableTools.join(", ")}) to inspect, edit, build, and test the change.`,
155
- "When finished, return an implementation summary.",
156
- ].join("\n"),
157
- );
158
- }
159
- return sections.join("\n\n");
160
- }
161
-
162
- function patchRepositoryChangeState(
163
- state: RepositoryChangeState,
164
- input: {
165
- finalization?: RepositoryChangeState["finalization"];
166
- clearReviewRefs?: boolean;
167
- clearProductRefs?: readonly string[];
168
- },
169
- ): RepositoryChangeState {
170
- const nextState: RepositoryChangeState = {
171
- ...state,
172
- ...("finalization" in input ? { finalization: input.finalization } : {}),
173
- };
174
- const productRefsToClear = new Set(input.clearProductRefs ?? []);
175
- if (input.clearReviewRefs) {
176
- productRefsToClear.add(products.review);
177
- }
178
- if (!input.clearReviewRefs && productRefsToClear.size === 0) {
179
- return nextState;
180
- }
181
- const productRefs = { ...nextState.productRefs };
182
- for (const productName of productRefsToClear) {
183
- delete productRefs[productName];
184
- }
185
- return {
186
- ...nextState,
187
- semanticEntryRefs: input.clearReviewRefs
188
- ? clearReviewRefs(nextState.semanticEntryRefs)
189
- : nextState.semanticEntryRefs,
190
- productRefs,
191
- };
192
- }
193
-
194
- const planDecisionSpec = humanTurn<TParams, RepositoryChangeState>({
95
+ const tools = ["read", "bash", "edit", "write"] as const;
96
+ const planDecision = humanTurn<TParams, RepositoryChangeState>({
195
97
  description: "Review Plan",
196
98
  reviewSemanticRef: "plan",
197
99
  notesFields: [
@@ -202,17 +104,17 @@ export function createRepositoryChangeProcess<TParams extends RepositoryChangePa
202
104
  required: true,
203
105
  },
204
106
  ],
205
- commentary: "Approve this plan, request a revision, or run an automated review.",
107
+ commentary: "Approve this plan or request a revision with comments.",
206
108
  actions: {
207
109
  [codingActionIds.approvePlan]: {
208
110
  label: "Approve plan",
209
111
  description: "Accept the current plan and continue into implementation.",
210
112
  acceptanceState: "accepted",
211
- to: turnIds.implement,
113
+ to: "implement",
212
114
  effect: ({ ctx }) => {
213
- requireResolvedPlanRef(ctx.state.semanticEntryRefs.plan, "approval");
115
+ if (!ctx.state.semanticEntryRefs.plan?.turnRecordId?.trim())
116
+ throw new Error("No plan is available for approval");
214
117
  return {
215
- state: clearReviewState(ctx.state),
216
118
  emit: [
217
119
  {
218
120
  type: "plan_approved",
@@ -231,243 +133,54 @@ export function createRepositoryChangeProcess<TParams extends RepositoryChangePa
231
133
  acceptanceState: "requires_changes",
232
134
  form: requestRevisionForm,
233
135
  schedulable: true,
234
- to: turnIds.generatePlan,
235
- queueTarget: { semanticRef: "currentPrimaryPathLeaf" },
236
- effect: ({ ctx, input }) => {
237
- const message = normalizeMessage(input.message);
238
- return {
239
- state: clearReviewState(ctx.state),
240
- emit: [{ type: "plan_revision_requested", data: { message } }],
241
- };
242
- },
243
- }),
244
- [codingActionIds.runReview]: {
245
- label: "Run automated review",
246
- description: "Send the current plan to the LLM reviewer.",
247
- acceptanceState: "neutral",
248
- schedulable: true,
249
- to: turnIds.reviewPlan,
250
- effect: ({ ctx }) => {
251
- requireResolvedPlanRef(ctx.state.semanticEntryRefs.plan, "review");
252
- return {
253
- state: clearReviewState(ctx.state),
254
- };
255
- },
256
- },
257
- },
258
- });
259
-
260
- const planReviewFeedbackSpec = humanTurn<TParams, RepositoryChangeState>({
261
- description: "Review Plan Feedback",
262
- reviewSemanticRef: "review",
263
- notesFields: [
264
- {
265
- id: "message",
266
- label: "Review notes",
267
- placeholder: "Describe how the next review pass should change",
268
- required: true,
269
- },
270
- ],
271
- commentary:
272
- "Apply this feedback to the next plan revision, request a revised review, or dismiss it.",
273
- actions: {
274
- [codingActionIds.acceptReview]: acceptedReviewHandoffAction({
275
- label: "Accept review",
276
- description: "Apply the current review outcome and continue with the plan flow.",
277
- acceptanceState: "accepted",
278
- form: acceptReviewForm,
279
- to: turnIds.generatePlan,
280
- resolveBodyMarkdown: ({ ctx, input }) =>
281
- buildAcceptedFollowUpMessage({
282
- kind: "plan_review",
283
- markdown: ctx.readSemanticTurnResultMarkdown("review"),
284
- adjustment: input.message,
285
- }),
286
- }),
287
- [codingActionIds.requestReviewChanges]: revisionAction({
288
- label: "Request review changes",
289
- description: "Ask the LLM reviewer to revise its plan review.",
290
- acceptanceState: "requires_changes",
291
- form: requestReviewChangesForm,
292
- to: turnIds.reviewPlan,
293
- queueTarget: { semanticRef: "review" },
294
- }),
295
- [codingActionIds.dismissReview]: {
296
- label: "Dismiss review",
297
- description: "Return to the plan decision without applying the review.",
298
- acceptanceState: "neutral",
299
- to: turnIds.planDecision,
300
- },
301
- },
302
- });
303
-
304
- const implementationDecisionSpec = humanTurn<TParams, RepositoryChangeState>({
305
- description: "Review",
306
- reviewSemanticRef: "currentPrimaryPathLeaf",
307
- notesFields: [
308
- {
309
- id: "message",
310
- label: "Revision notes",
311
- placeholder: "Describe what the next implementation turn should improve",
312
- required: true,
313
- },
314
- ],
315
- commentary:
316
- "Publish this implementation, request another pass, simplify it, or run an automated review.",
317
- actions: {
318
- [codingActionIds.finalizeChange]: {
319
- label: config.finalizeLabel,
320
- acceptanceState: "accepted",
321
- form: config.finalizeForm,
322
- schedulable: true,
323
- to: turnIds.generateCommitMessage,
324
- effect: ({ ctx }) => ({
325
- state: patchRepositoryChangeState(ctx.state, {
326
- finalization: createEmptyRepositoryChangeFinalizationState(),
327
- clearReviewRefs: true,
328
- clearProductRefs: [products.simplificationPlan],
329
- }),
330
- }),
331
- },
332
- [codingActionIds.requestRevision]: revisionAction({
333
- label: "Request revision",
334
- acceptanceState: "requires_changes",
335
- form: requestRevisionForm,
336
- schedulable: true,
337
- to: turnIds.implement,
136
+ to: "generate_plan",
338
137
  queueTarget: { semanticRef: "currentPrimaryPathLeaf" },
339
- effect: ({ ctx }) => ({
340
- state: clearReviewState(ctx.state),
341
- }),
342
- }),
343
- [codingActionIds.simplify]: {
344
- label: "Simplify",
345
- description: "Ask for a focused simplification review before another implementation pass.",
346
- acceptanceState: "neutral",
347
- schedulable: true,
348
- to: turnIds.simplifyImplementation,
349
- effect: ({ ctx }) => {
350
- requireResolvedPlanRef(ctx.state.semanticEntryRefs.plan, "simplification review");
351
- return { state: clearReviewState(ctx.state) };
352
- },
353
- },
354
- [codingActionIds.runReview]: {
355
- label: "Run automated review",
356
- acceptanceState: "neutral",
357
- schedulable: true,
358
- to: turnIds.reviewImplementation,
359
- effect: ({ ctx }) => {
360
- requireResolvedPlanRef(ctx.state.semanticEntryRefs.plan, "implementation review");
361
- return { state: clearReviewState(ctx.state) };
362
- },
363
- },
364
- },
365
- });
366
-
367
- const implementationReviewFeedbackSpec = humanTurn<TParams, RepositoryChangeState>({
368
- description: "Review implementation feedback",
369
- reviewSemanticRef: "review",
370
- notesFields: [
371
- {
372
- id: "message",
373
- label: "Review notes",
374
- placeholder: "Describe how the next implementation review pass should change",
375
- required: true,
376
- },
377
- ],
378
- commentary:
379
- "Apply this feedback to the next implementation pass, request a revised review, or dismiss it.",
380
- actions: {
381
- [codingActionIds.acceptReview]: acceptedReviewHandoffAction({
382
- label: "Accept review",
383
- acceptanceState: "accepted",
384
- form: acceptReviewForm,
385
- schedulable: true,
386
- to: turnIds.implement,
387
- queueTarget: { semanticRef: "review" },
388
- resolveBodyMarkdown: ({ ctx, input }) =>
389
- buildAcceptedFollowUpMessage({
390
- kind: "implementation_review",
391
- markdown: ctx.readSemanticTurnResultMarkdown("review"),
392
- adjustment: input.message,
393
- }),
394
- effect: ({ ctx }) => ({
395
- state: patchRepositoryChangeState(ctx.state, {
396
- clearProductRefs: [products.simplificationPlan],
397
- }),
138
+ effect: ({ input }) => ({
139
+ emit: [
140
+ { type: "plan_revision_requested", data: { message: normalizeMessage(input.message) } },
141
+ ],
398
142
  }),
399
143
  }),
400
- [codingActionIds.requestReviewChanges]: revisionAction({
401
- label: "Request review changes",
402
- acceptanceState: "requires_changes",
403
- form: requestReviewChangesForm,
404
- schedulable: true,
405
- to: turnIds.reviewImplementation,
406
- queueTarget: { semanticRef: "review" },
407
- }),
408
- [codingActionIds.dismissReview]: {
409
- label: "Dismiss review",
410
- acceptanceState: "neutral",
411
- to: turnIds.implementationDecision,
412
- },
413
144
  },
414
145
  });
415
-
416
- const simplificationDecisionSpec = humanTurn<TParams, RepositoryChangeState>({
417
- description: "Review simplification plan",
418
- reviewProduct: products.simplificationPlan,
419
- notesFields: [
420
- {
421
- id: "message",
422
- label: "Simplification notes",
423
- placeholder: "Describe how the simplification plan should change",
424
- required: true,
425
- },
426
- ],
427
- commentary: "Apply this simplification plan, request changes to it, or reject it.",
428
- actions: {
429
- [codingActionIds.acceptReview]: acceptedReviewHandoffAction({
430
- label: "Accept simplification plan",
431
- acceptanceState: "accepted",
432
- form: acceptReviewForm,
433
- schedulable: true,
434
- to: turnIds.implement,
435
- queueTarget: { productName: products.simplificationPlan },
436
- resolveBodyMarkdown: ({ ctx, input }) =>
437
- buildAcceptedFollowUpMessage({
438
- kind: "simplification",
439
- markdown: ctx.readProductTurnResultMarkdown(products.simplificationPlan),
440
- adjustment: input.message,
441
- }),
442
- effect: ({ ctx }) => ({
443
- state: patchRepositoryChangeState(ctx.state, {
444
- clearReviewRefs: true,
445
- }),
446
- }),
447
- }),
448
- [codingActionIds.requestReviewChanges]: revisionAction({
449
- label: "Request simplification changes",
450
- acceptanceState: "requires_changes",
451
- form: requestReviewChangesForm,
452
- to: turnIds.simplifyImplementation,
453
- queueTarget: { productName: products.simplificationPlan },
454
- }),
455
- [codingActionIds.dismissReview]: {
456
- label: "Reject simplification plan",
457
- description:
458
- "Return to the implementation decision without applying the simplification plan.",
459
- acceptanceState: "neutral",
460
- to: turnIds.implementationDecision,
461
- effect: ({ ctx }) => ({
462
- state: clearReviewState(ctx.state),
463
- }),
146
+ if (config.workflow?.planBypassSource)
147
+ planDecision.externalActions = {
148
+ bypass_plan: {
149
+ id: "bypass_plan",
150
+ label: "Skip plan approval",
151
+ source: config.workflow.planBypassSource,
152
+ to: "implement",
153
+ effect: ({ state, process, event }) => {
154
+ if ((event as { planRevision?: number }).planRevision !== process.planRevision)
155
+ throw new Error("Stale plan bypass event");
156
+ return {
157
+ state: {
158
+ ...state,
159
+ routing: {
160
+ ...state.routing,
161
+ plan: { planRevision: process.planRevision, skip: true, reason: "Jira label" },
162
+ },
163
+ },
164
+ emit: [
165
+ {
166
+ type: "plan_approved" as const,
167
+ data: {
168
+ planRevision: process.planRevision,
169
+ actor: "system",
170
+ bypassed: true,
171
+ reason: "Jira label",
172
+ },
173
+ },
174
+ ],
175
+ };
176
+ },
464
177
  },
465
- },
466
- });
178
+ };
467
179
 
468
- const generatePlanTurn = flow
469
- .llm<TParams, RepositoryChangeState>(turnIds.generatePlan)
180
+ const generatePlan = flow
181
+ .llm<TParams, RepositoryChangeState>("generate_plan")
470
182
  .description("Plan")
183
+ .executionPurpose(codingPurposes.planning)
471
184
  .tools("read", "bash")
472
185
  .askQuestions()
473
186
  .freshPrimary()
@@ -475,44 +188,81 @@ export function createRepositoryChangeProcess<TParams extends RepositoryChangePa
475
188
  .outcomeTool("plan_saved", (tool) =>
476
189
  tool
477
190
  .description(
478
- "Save the finished plan for review. Its Markdown may include Mermaid diagrams or uploaded images.",
191
+ "Save a finished, implementable plan after resolving design-critical questions. Required investigation and access must be complete. If blocked, use abort_turn. Use ask_questions for operator decisions when available; otherwise decide within the requested scope and document assumptions.",
479
192
  )
480
- .requiredString("summary", "Short summary of the proposed plan")
193
+ .requiredString("summary", "One concise sentence summarizing the proposed plan")
481
194
  .requiredStringArray(
482
195
  "acceptanceCriteria",
483
- "Acceptance criteria for the requested repository change",
196
+ "Requested outcomes for the repository change, without expanding scope",
484
197
  )
485
- .to(turnIds.planDecision)
486
- .effect(({ ctx, event }) => {
198
+ .routeByState(
199
+ {
200
+ approval: {
201
+ to: "plan_decision",
202
+ label: "Approval required",
203
+ description:
204
+ "When the process policy requires an operator to approve the saved plan.",
205
+ },
206
+ bypass: {
207
+ to: "implement",
208
+ label: "Skip plan approval",
209
+ description:
210
+ "When the process policy skips plan approval, for example through the Skip plan approval launcher option.",
211
+ },
212
+ },
213
+ ({ ctx }) => (ctx.state.routing?.plan?.skip ? "bypass" : "approval"),
214
+ )
215
+ .effect(async ({ ctx, event }) => {
487
216
  const planRevision = ctx.process.planRevision + 1;
217
+ const policy = (await config.workflow
218
+ ?.planDecision?.(ctx.params)
219
+ .catch(() => ({ skip: false, reason: "Source unavailable; approval required" }))) ?? {
220
+ skip: false,
221
+ reason: "Human approval required",
222
+ };
488
223
  const summary = normalizeMessage(event.params.summary);
489
224
  const acceptanceCriteria = Array.isArray(event.params.acceptanceCriteria)
490
225
  ? event.params.acceptanceCriteria.filter(
491
226
  (entry): entry is string => typeof entry === "string" && entry.trim() !== "",
492
227
  )
493
228
  : [];
494
- const planMarkdown = ctx.output?.content ?? "";
495
229
  return {
496
- state: clearReviewState(ctx.state),
230
+ state: {
231
+ ...ctx.state,
232
+ routing: { ...ctx.state.routing, plan: { ...policy, planRevision } },
233
+ },
497
234
  processPatch: { planRevision },
498
235
  broadcasts: [
499
236
  {
500
237
  type: "plan.updated",
501
238
  payload: {
502
239
  planRevision,
503
- reviewState: "awaiting_approval",
504
- approved: false,
240
+ reviewState: policy.skip ? "accepted" : "awaiting_approval",
241
+ approved: policy.skip,
505
242
  summary,
506
243
  },
507
244
  },
508
245
  ],
509
246
  emit: [
247
+ ...(policy.skip
248
+ ? [
249
+ {
250
+ type: "plan_approved" as const,
251
+ data: {
252
+ planRevision,
253
+ actor: "system",
254
+ bypassed: true,
255
+ reason: policy.reason,
256
+ },
257
+ },
258
+ ]
259
+ : []),
510
260
  {
511
261
  type: "plan_saved",
512
262
  data: {
513
263
  planRevision,
514
264
  summary,
515
- planMarkdown,
265
+ planMarkdown: ctx.output?.content ?? "",
516
266
  acceptanceCriteria,
517
267
  },
518
268
  },
@@ -520,170 +270,148 @@ export function createRepositoryChangeProcess<TParams extends RepositoryChangePa
520
270
  };
521
271
  }),
522
272
  )
523
- .publish(products.plan);
524
-
525
- const reviewPlanTurn = flow
526
- .llm<TParams, RepositoryChangeState>(turnIds.reviewPlan)
527
- .description("Assess Plan")
528
- .tools("read", "bash")
529
- .rootBranchReview()
530
- .startFromReviewBranch()
531
- .consume(products.plan)
532
- .buildPrompt(buildReviewPlanPrompt)
533
- .outcomeTool("no_issues", (tool) =>
534
- tool
535
- .description(
536
- "Approve the plan and publish the review. Its Markdown may include Mermaid diagrams or uploaded images.",
537
- )
538
- .to(turnIds.planDecision),
539
- )
540
- .outcomeTool("request_changes", (tool) =>
541
- tool
542
- .description(
543
- "Request plan changes and publish actionable feedback. Its Markdown may include Mermaid diagrams or uploaded images.",
544
- )
545
- .to(turnIds.planReviewFeedback),
546
- )
547
- .publish(products.review);
548
-
549
- const implementTurn = flow
550
- .llm<TParams, RepositoryChangeState>(turnIds.implement)
273
+ .publish("plan");
274
+ const implement = flow
275
+ .llm<TParams, RepositoryChangeState>("implement")
551
276
  .description("Implement")
552
- .tools(...implementationTurnAvailableTools)
277
+ .waitFor(({ state }) => !!state.productRefs.plan)
278
+ .executionPurpose(codingPurposes.implementation)
279
+ .tools(...tools)
553
280
  .freshSeededPrimary()
554
- .continueFromProductBranch(products.simplificationPlan, {
555
- kind: "semantic_ref",
556
- ref: "review",
557
- fallback: { kind: "session_root" },
558
- })
559
- .consume(products.plan)
560
- .buildPrompt(buildImplementPrompt)
561
- .publish(products.implementationSummary)
562
- .to(turnIds.implementationDecision)
563
- .state(({ ctx }) => clearReviewState(ctx.state));
564
-
565
- const reviewImplementationTurn = flow
566
- .llm<TParams, RepositoryChangeState>(turnIds.reviewImplementation)
567
- .description("Assess Implementation")
568
- .tools("read", "bash")
569
- .rootBranchReview()
570
- .startFromReviewBranch()
571
- .buildPrompt(buildReviewImplementationPrompt)
572
- .outcomeTool("no_issues", (tool) =>
573
- tool
574
- .description(
575
- "Approve the implementation and publish the review. Its Markdown may include Mermaid diagrams or uploaded images.",
576
- )
577
- .to(turnIds.implementationDecision),
578
- )
579
- .outcomeTool("request_changes", (tool) =>
281
+ .startFromRoot()
282
+ .consume("plan")
283
+ .prepare((ctx) => ({
284
+ reconciliation: ctx.repo.all().map((repo) => {
285
+ const identity = asUnknownRecord(
286
+ ctx.projects.find((p) => p.key === repo.key)?.metadata?.["leitwerk.gitIdentity"],
287
+ );
288
+ return prepareInitialRepository({
289
+ projectKey: repo.key,
290
+ repoPath: repo.fsPath,
291
+ workBranch: repo.workBranch,
292
+ gitIdentity:
293
+ typeof identity?.name === "string" && typeof identity.email === "string"
294
+ ? { name: identity.name, email: identity.email }
295
+ : undefined,
296
+ });
297
+ }),
298
+ }))
299
+ .buildPrompt((ctx) => `${buildImplementPrompt(ctx)}\n\n${reconciliationPrompt}`)
300
+ .outcomeTool("implementation_ready", (tool) =>
580
301
  tool
581
- .description(
582
- "Request implementation changes and publish actionable feedback. Its Markdown may include Mermaid diagrams or uploaded images.",
302
+ .description("Implementation and checks are complete; continue to delivery")
303
+ .routeByState(
304
+ {
305
+ simplify: {
306
+ to: "simplify_implementation",
307
+ label: "Simplification enabled",
308
+ description:
309
+ "When the process policy enables simplification. This is the default unless a launcher option or source policy skips it.",
310
+ },
311
+ skip: {
312
+ to: "generate_commit_message",
313
+ label: "Skip simplification",
314
+ description:
315
+ "When simplification is skipped, for example through the Skip simplification launcher option or the leitwerk-skip-simplification source label.",
316
+ },
317
+ },
318
+ ({ ctx }) => (ctx.state.routing?.simplification?.skip ? "skip" : "simplify"),
583
319
  )
584
- .to(turnIds.implementationReviewFeedback),
320
+ .effect(async ({ ctx }) => ({
321
+ state: {
322
+ ...ctx.state,
323
+ routing: {
324
+ ...ctx.state.routing,
325
+ simplification: ctx.state.routing?.simplification ??
326
+ (await config.workflow?.simplification?.(ctx.params)) ?? {
327
+ skip: false,
328
+ reason: "Simplification enabled by default",
329
+ },
330
+ },
331
+ },
332
+ })),
585
333
  )
586
- .publish(products.review);
587
-
588
- const simplifyImplementationTurn = flow
589
- .llm<TParams, RepositoryChangeState>(turnIds.simplifyImplementation)
334
+ .publish("implementation-summary");
335
+ const simplify = flow
336
+ .llm<TParams, RepositoryChangeState>("simplify_implementation")
590
337
  .description("Simplify")
338
+ .executionPurpose(codingPurposes.review)
591
339
  .tools("read", "bash")
592
340
  .rootBranchReview()
593
- .startFromProductBranch(products.simplificationPlan)
594
- .buildPrompt(buildSimplifyImplementationPrompt)
595
- .publish(products.simplificationPlan)
596
- .to(turnIds.simplificationDecision);
341
+ .startFromProductBranch("simplification-plan")
342
+ .buildPrompt(buildStreamlinedSimplificationPrompt)
343
+ .publish("simplification-plan")
344
+ .to("apply_simplification");
345
+ const applySimplification = flow
346
+ .llm<TParams, RepositoryChangeState>("apply_simplification")
347
+ .description("Apply simplification")
348
+ .executionPurpose(codingPurposes.implementation)
349
+ .tools(...tools)
350
+ .freshSeededPrimary()
351
+ .consume("plan")
352
+ .consume("simplification-plan")
353
+ .buildPrompt(
354
+ (
355
+ ctx,
356
+ ) => `Apply justified simplifications to each repository, preserving the accepted plan and behavior. Rerun the required checks. Empty findings require no edits. Leave changes uncommitted for delivery.
357
+
358
+ Accepted plan:
359
+ ${ctx.input.plan}
597
360
 
598
- const generateCommitMessageTurn = flow
599
- .llm<TParams, RepositoryChangeState>(turnIds.generateCommitMessage)
361
+ Findings by repository:
362
+ ${ctx.input["simplification-plan"]}`,
363
+ )
364
+ .publish("implementation-summary")
365
+ .to("generate_commit_message");
366
+ const generateCommitMessage = flow
367
+ .llm<TParams, RepositoryChangeState>("generate_commit_message")
600
368
  .description("Write Commit Message")
601
- .modelPurpose("process_title_generation")
369
+ .executionPurpose(codingPurposes.implementation)
370
+ .tools("read", "grep", "find", "ls")
602
371
  .rootBranchReview()
603
372
  .startFromRoot()
604
- .consume(products.plan)
605
- .buildPrompt(buildGenerateCommitMessagePrompt)
606
- .publish(products.commitMessage)
373
+ .consume("plan")
374
+ .consume("implementation-summary")
375
+ .prepare(prepareRepositoryCommitMessageEvidence)
376
+ .buildPrompt(buildRepositoryCommitMessagesPrompt)
377
+ .publish("commit-message")
607
378
  .to(config.publication.entryTurnId)
608
- .state(({ ctx }) =>
609
- patchRepositoryChangeState(ctx.state, {
610
- finalization: {
611
- ...ctx.state.finalization,
612
- generatedCommitMessage: normalizeGeneratedCommitMessage(ctx.output?.content),
613
- },
614
- }),
615
- );
616
-
617
- const planFlow = flow
618
- .fragment<TParams, RepositoryChangeState>("plan")
619
- .turn(generatePlanTurn)
620
- .turn({ id: turnIds.planDecision, definition: planDecisionSpec })
621
- .turn(reviewPlanTurn)
622
- .turn({ id: turnIds.planReviewFeedback, definition: planReviewFeedbackSpec });
623
-
624
- const implementationFlow = flow
625
- .fragment<TParams, RepositoryChangeState>("implementation")
626
- .turn(implementTurn)
627
- .turn({ id: turnIds.implementationDecision, definition: implementationDecisionSpec })
628
- .turn(reviewImplementationTurn)
629
- .turn({
630
- id: turnIds.implementationReviewFeedback,
631
- definition: implementationReviewFeedbackSpec,
632
- })
633
- .turn(simplifyImplementationTurn)
634
- .turn({ id: turnIds.simplificationDecision, definition: simplificationDecisionSpec });
635
-
636
- const finalizationFlow = flow
637
- .fragment<TParams, RepositoryChangeState>("finalization")
638
- .turn(generateCommitMessageTurn);
639
-
379
+ .state(({ ctx }) => ({
380
+ ...ctx.state,
381
+ finalization: {
382
+ ...ctx.state.finalization,
383
+ commitMessages: parseRepositoryCommitMessages(
384
+ ctx.output?.content,
385
+ ctx.projects.map((p) => p.key),
386
+ ),
387
+ },
388
+ }));
640
389
  const builder = flow
641
390
  .process<TParams, RepositoryChangeState>(config.processId)
642
391
  .displayName(config.displayName)
643
- .entry(turnIds.generatePlan)
392
+ .entry("generate_plan")
644
393
  .happyPath(
645
- turnIds.generatePlan,
646
- turnIds.implement,
647
- turnIds.generateCommitMessage,
394
+ "generate_plan",
395
+ "implement",
396
+ "simplify_implementation",
397
+ "apply_simplification",
398
+ "generate_commit_message",
648
399
  ...(config.publication.happyPath ?? [config.publication.entryTurnId]),
649
400
  )
650
- .piConfig({ sessionCwdTemplate: "{{{projectKey}}}" })
651
- .codecs({
652
- params: config.paramsCodec,
653
- state: repositoryChangeStateCodec,
654
- })
655
- .initialState(() => ({
656
- ...createEmptyStructuralProcessState(),
657
- finalization: createEmptyRepositoryChangeFinalizationState(),
658
- extensionState: {},
659
- }))
660
- .use(planFlow)
661
- .use(implementationFlow)
662
- .use(finalizationFlow);
663
- builder.use(config.publication.fragment);
401
+ .piConfig(config.workflow?.multiRepository ? {} : { sessionCwdTemplate: "{{{projectKey}}}" })
402
+ .codecs({ params: config.paramsCodec, state: repositoryChangeStateCodec })
403
+ .initialState(() => repositoryChangeStateCodec.parse({}))
404
+ .turn(generatePlan)
405
+ .turn({ id: "plan_decision", definition: planDecision })
406
+ .turn(implement)
407
+ .turn(simplify)
408
+ .turn(applySimplification)
409
+ .turn(generateCommitMessage)
410
+ .use(config.publication.fragment);
664
411
  if (config.repositoryCredentials) builder.repositoryCredentials(config.repositoryCredentials);
665
412
  if (config.launcher) builder.launcher(config.launcher);
666
- const process = builder.define();
667
- const decision = (id: string) =>
668
- ({
669
- /** @public */
670
- id,
671
- ...(process.turns.get(id)?.definition as HumanTurnDefinition),
672
- }) as HumanTurnDefinition & {
673
- /** @public */ id: string;
674
- };
675
413
  return {
676
414
  /** @public */
677
- process,
678
- /** @internal */
679
- planDecision: decision(turnIds.planDecision),
680
- /** @internal */
681
- planReviewFeedback: decision(turnIds.planReviewFeedback),
682
- /** @internal */
683
- implementationDecision: decision(turnIds.implementationDecision),
684
- /** @internal */
685
- implementationReviewFeedback: decision(turnIds.implementationReviewFeedback),
686
- /** @internal */
687
- simplificationDecision: decision(turnIds.simplificationDecision),
415
+ process: builder.define(),
688
416
  };
689
417
  }