@leitwerk-dev/coding 0.3.1 → 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 (108) hide show
  1. package/README.md +86 -1
  2. package/dist/chunk-ABQH2WZT.js +36 -0
  3. package/dist/chunk-ABQH2WZT.js.map +1 -0
  4. package/dist/{chunk-YSC5GEQJ.js → chunk-BI45R2FH.js} +7 -3
  5. package/dist/chunk-BI45R2FH.js.map +1 -0
  6. package/dist/chunk-DNG7D77K.js +65 -0
  7. package/dist/chunk-DNG7D77K.js.map +1 -0
  8. package/dist/chunk-L2TFD72B.js +16320 -0
  9. package/dist/chunk-L2TFD72B.js.map +1 -0
  10. package/dist/chunk-M2VTUPFO.js +265 -0
  11. package/dist/chunk-M2VTUPFO.js.map +1 -0
  12. package/dist/chunk-OM2AMDTJ.js +347 -0
  13. package/dist/chunk-OM2AMDTJ.js.map +1 -0
  14. package/dist/chunk-Q24RPXOA.js +159 -0
  15. package/dist/chunk-Q24RPXOA.js.map +1 -0
  16. package/dist/chunk-SKGB4CZS.js +14 -0
  17. package/dist/chunk-SKGB4CZS.js.map +1 -0
  18. package/dist/chunk-SZ4WOGV2.js +120 -0
  19. package/dist/chunk-SZ4WOGV2.js.map +1 -0
  20. package/dist/finalization-git-internal.d.ts +3 -0
  21. package/dist/finalization-git-internal.d.ts.map +1 -1
  22. package/dist/finalization-git.d.ts +1 -1
  23. package/dist/finalization-git.d.ts.map +1 -1
  24. package/dist/finalization-git.js +5 -3
  25. package/dist/index.d.ts +1 -0
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js +17 -591
  28. package/dist/index.js.map +1 -1
  29. package/dist/pull-request-publication-internal.d.ts +26 -24
  30. package/dist/pull-request-publication-internal.d.ts.map +1 -1
  31. package/dist/repository-change-launch-internal-BudnAfL7.d.ts +88 -0
  32. package/dist/repository-change-launch-internal.d.ts +32 -11
  33. package/dist/repository-change-launch-internal.d.ts.map +1 -1
  34. package/dist/repository-change-launch.d.ts +4 -3
  35. package/dist/repository-change-launch.d.ts.map +1 -1
  36. package/dist/repository-change-launch.js +162 -34
  37. package/dist/repository-change-launch.js.map +1 -1
  38. package/dist/repository-change-process-DlgF04fU.d.ts +69 -0
  39. package/dist/repository-change-process.d.ts +30 -25
  40. package/dist/repository-change-process.d.ts.map +1 -1
  41. package/dist/repository-change-publication.d.ts +62 -6
  42. package/dist/repository-change-publication.d.ts.map +1 -1
  43. package/dist/repository-change-publication.js +364 -90
  44. package/dist/repository-change-publication.js.map +1 -1
  45. package/dist/repository-change-state-internal.d.ts +18 -4
  46. package/dist/repository-change-state-internal.d.ts.map +1 -1
  47. package/dist/repository-change-ui-launcher-internal.d.ts +34 -22
  48. package/dist/repository-change-ui-launcher-internal.d.ts.map +1 -1
  49. package/dist/settings.d.ts +15 -0
  50. package/dist/settings.d.ts.map +1 -0
  51. package/dist/turns/commit-message-evidence.d.ts +35 -0
  52. package/dist/turns/commit-message-evidence.d.ts.map +1 -0
  53. package/dist/turns/commit-message-evidence.js +9 -0
  54. package/dist/turns/generate-commit-message.d.ts +4 -1
  55. package/dist/turns/generate-commit-message.d.ts.map +1 -1
  56. package/dist/turns/generate-commit-message.js +7 -5
  57. package/dist/turns/generate-plan.d.ts.map +1 -1
  58. package/dist/turns/generate-plan.js +1 -1
  59. package/dist/turns/git-inspection-profile.d.ts +25 -0
  60. package/dist/turns/git-inspection-profile.d.ts.map +1 -0
  61. package/dist/turns/git-inspection-profile.js +8 -0
  62. package/dist/turns/implement.d.ts.map +1 -1
  63. package/dist/turns/implement.js +1 -1
  64. package/dist/turns/simplify-implementation.d.ts +1 -1
  65. package/dist/turns/simplify-implementation.d.ts.map +1 -1
  66. package/dist/turns/simplify-implementation.js +3 -3
  67. package/package.json +5 -9
  68. package/src/finalization-git-internal.ts +117 -114
  69. package/src/finalization-git.ts +1 -1
  70. package/src/index.ts +4 -1
  71. package/src/pull-request-publication-internal.ts +156 -78
  72. package/src/repository-change-launch-internal.ts +119 -12
  73. package/src/repository-change-launch.ts +8 -4
  74. package/src/repository-change-process.ts +234 -523
  75. package/src/repository-change-publication.ts +516 -121
  76. package/src/repository-change-state-internal.ts +34 -20
  77. package/src/repository-change-ui-launcher-internal.ts +139 -56
  78. package/src/settings.ts +79 -0
  79. package/src/turns/commit-message-evidence.ts +241 -0
  80. package/src/turns/generate-commit-message.ts +53 -23
  81. package/src/turns/generate-plan.ts +26 -12
  82. package/src/turns/git-inspection-profile.ts +134 -0
  83. package/src/turns/implement.ts +9 -2
  84. package/src/turns/simplify-implementation.ts +10 -6
  85. package/dist/chunk-34B3Q75M.js +0 -25
  86. package/dist/chunk-34B3Q75M.js.map +0 -1
  87. package/dist/chunk-F6CEEAFE.js +0 -13
  88. package/dist/chunk-F6CEEAFE.js.map +0 -1
  89. package/dist/chunk-GO44KCUS.js +0 -154
  90. package/dist/chunk-GO44KCUS.js.map +0 -1
  91. package/dist/chunk-R3UCUGY6.js +0 -31
  92. package/dist/chunk-R3UCUGY6.js.map +0 -1
  93. package/dist/chunk-W7VJT6AN.js +0 -25
  94. package/dist/chunk-W7VJT6AN.js.map +0 -1
  95. package/dist/chunk-WKHVLLKE.js +0 -45
  96. package/dist/chunk-WKHVLLKE.js.map +0 -1
  97. package/dist/chunk-YSC5GEQJ.js.map +0 -1
  98. package/dist/repository-change-launch-internal-Dd-AONUs.d.ts +0 -67
  99. package/dist/turns/review-implementation.d.ts +0 -4
  100. package/dist/turns/review-implementation.d.ts.map +0 -1
  101. package/dist/turns/review-implementation.js +0 -8
  102. package/dist/turns/review-plan.d.ts +0 -4
  103. package/dist/turns/review-plan.d.ts.map +0 -1
  104. package/dist/turns/review-plan.js +0 -8
  105. package/src/turns/review-implementation.ts +0 -30
  106. package/src/turns/review-plan.ts +0 -24
  107. /package/dist/turns/{review-implementation.js.map → commit-message-evidence.js.map} +0 -0
  108. /package/dist/turns/{review-plan.js.map → git-inspection-profile.js.map} +0 -0
@@ -1,43 +1,58 @@
1
- import { trimString as normalizeMessage, normalizeOptionalMarkdown } from "@leitwerk-dev/domain";
1
+ import { 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 { codingPurposes } from "./settings.js";
20
+ import { prepareRepositoryCommitMessageEvidence } from "./turns/commit-message-evidence.js";
28
21
  import {
29
- buildGenerateCommitMessagePrompt,
30
- normalizeGeneratedCommitMessage,
22
+ buildRepositoryCommitMessagesPrompt,
23
+ parseRepositoryCommitMessages,
31
24
  } from "./turns/generate-commit-message.js";
32
25
  import { buildGeneratePlanPrompt } from "./turns/generate-plan.js";
33
26
  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";
27
+ import { buildStreamlinedSimplificationPrompt } from "./turns/simplify-implementation.js";
37
28
 
38
29
  /** @public */
39
30
  export type RepositoryChangeParams = object;
40
31
 
32
+ /** Server-side policies evaluated at the route boundary. @public */
33
+ export interface RepositoryChangeWorkflow<TParams> {
34
+ /** @deprecated All repository changes use the streamlined graph. @public */
35
+ variant?: "streamlined";
36
+ /** @public */
37
+ multiRepository?: boolean;
38
+ /** @public */
39
+ planDecision?(params: TParams): Promise<{
40
+ /** @internal */
41
+ skip: boolean;
42
+ /** @internal */
43
+ reason: string;
44
+ }>;
45
+ /** @public */
46
+ simplification?(params: TParams): Promise<{
47
+ /** @internal */
48
+ skip: boolean;
49
+ /** @internal */
50
+ reason: string;
51
+ }>;
52
+ /** Must recheck the current revision and source before firing. @public */
53
+ planBypassSource?: ExternalActionSource<TParams, RepositoryChangeState, unknown>;
54
+ }
55
+
41
56
  /** @public */
42
57
  export interface RepositoryChangeProcessConfig<TParams extends RepositoryChangeParams> {
43
58
  /** @public */
@@ -45,13 +60,15 @@ export interface RepositoryChangeProcessConfig<TParams extends RepositoryChangeP
45
60
  /** @public */
46
61
  displayName: string;
47
62
  /** @public */
63
+ workflow?: RepositoryChangeWorkflow<TParams>;
64
+ /** @public */
48
65
  paramsCodec: Codec<TParams>;
49
66
  /** @public */
50
67
  launcher?: ProcessLauncherDefinition<TParams>;
51
- /** @public */
52
- finalizeLabel: string;
53
- /** @public */
54
- finalizeForm: FormDefinition;
68
+ /** @deprecated Publication follows implementation automatically. @public */
69
+ finalizeLabel?: string;
70
+ /** @deprecated Publication follows implementation automatically. @public */
71
+ finalizeForm?: FormDefinition;
55
72
  /** @public */
56
73
  repositoryCredentials?(input: {
57
74
  /** @public */
@@ -74,124 +91,8 @@ export interface RepositoryChangeProcessConfig<TParams extends RepositoryChangeP
74
91
  export function createRepositoryChangeProcess<TParams extends RepositoryChangeParams>(
75
92
  config: RepositoryChangeProcessConfig<TParams>,
76
93
  ) {
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>({
94
+ const tools = ["read", "bash", "edit", "write"] as const;
95
+ const planDecision = humanTurn<TParams, RepositoryChangeState>({
195
96
  description: "Review Plan",
196
97
  reviewSemanticRef: "plan",
197
98
  notesFields: [
@@ -202,17 +103,17 @@ export function createRepositoryChangeProcess<TParams extends RepositoryChangePa
202
103
  required: true,
203
104
  },
204
105
  ],
205
- commentary: "Approve this plan, request a revision, or run an automated review.",
106
+ commentary: "Approve this plan or request a revision with comments.",
206
107
  actions: {
207
108
  [codingActionIds.approvePlan]: {
208
109
  label: "Approve plan",
209
110
  description: "Accept the current plan and continue into implementation.",
210
111
  acceptanceState: "accepted",
211
- to: turnIds.implement,
112
+ to: "implement",
212
113
  effect: ({ ctx }) => {
213
- requireResolvedPlanRef(ctx.state.semanticEntryRefs.plan, "approval");
114
+ if (!ctx.state.semanticEntryRefs.plan?.turnRecordId?.trim())
115
+ throw new Error("No plan is available for approval");
214
116
  return {
215
- state: clearReviewState(ctx.state),
216
117
  emit: [
217
118
  {
218
119
  type: "plan_approved",
@@ -231,243 +132,54 @@ export function createRepositoryChangeProcess<TParams extends RepositoryChangePa
231
132
  acceptanceState: "requires_changes",
232
133
  form: requestRevisionForm,
233
134
  schedulable: true,
234
- to: turnIds.generatePlan,
135
+ to: "generate_plan",
235
136
  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,
338
- queueTarget: { semanticRef: "currentPrimaryPathLeaf" },
339
- effect: ({ ctx }) => ({
340
- state: clearReviewState(ctx.state),
137
+ effect: ({ input }) => ({
138
+ emit: [
139
+ { type: "plan_revision_requested", data: { message: normalizeMessage(input.message) } },
140
+ ],
341
141
  }),
342
142
  }),
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
143
  },
365
144
  });
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
- }),
398
- }),
399
- }),
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
- },
414
- });
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
- }),
145
+ if (config.workflow?.planBypassSource)
146
+ planDecision.externalActions = {
147
+ bypass_plan: {
148
+ id: "bypass_plan",
149
+ label: "Skip plan approval",
150
+ source: config.workflow.planBypassSource,
151
+ to: "implement",
152
+ effect: ({ state, process, event }) => {
153
+ if ((event as { planRevision?: number }).planRevision !== process.planRevision)
154
+ throw new Error("Stale plan bypass event");
155
+ return {
156
+ state: {
157
+ ...state,
158
+ routing: {
159
+ ...state.routing,
160
+ plan: { planRevision: process.planRevision, skip: true, reason: "Jira label" },
161
+ },
162
+ },
163
+ emit: [
164
+ {
165
+ type: "plan_approved" as const,
166
+ data: {
167
+ planRevision: process.planRevision,
168
+ actor: "system",
169
+ bypassed: true,
170
+ reason: "Jira label",
171
+ },
172
+ },
173
+ ],
174
+ };
175
+ },
464
176
  },
465
- },
466
- });
177
+ };
467
178
 
468
- const generatePlanTurn = flow
469
- .llm<TParams, RepositoryChangeState>(turnIds.generatePlan)
179
+ const generatePlan = flow
180
+ .llm<TParams, RepositoryChangeState>("generate_plan")
470
181
  .description("Plan")
182
+ .executionPurpose(codingPurposes.planning)
471
183
  .tools("read", "bash")
472
184
  .askQuestions()
473
185
  .freshPrimary()
@@ -475,44 +187,81 @@ export function createRepositoryChangeProcess<TParams extends RepositoryChangePa
475
187
  .outcomeTool("plan_saved", (tool) =>
476
188
  tool
477
189
  .description(
478
- "Save the finished plan for review. Its Markdown may include Mermaid diagrams or uploaded images.",
190
+ "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
191
  )
480
- .requiredString("summary", "Short summary of the proposed plan")
192
+ .requiredString("summary", "One concise sentence summarizing the proposed plan")
481
193
  .requiredStringArray(
482
194
  "acceptanceCriteria",
483
- "Acceptance criteria for the requested repository change",
195
+ "Requested outcomes for the repository change, without expanding scope",
484
196
  )
485
- .to(turnIds.planDecision)
486
- .effect(({ ctx, event }) => {
197
+ .routeByState(
198
+ {
199
+ approval: {
200
+ to: "plan_decision",
201
+ label: "Approval required",
202
+ description:
203
+ "When the process policy requires an operator to approve the saved plan.",
204
+ },
205
+ bypass: {
206
+ to: "implement",
207
+ label: "Skip plan approval",
208
+ description:
209
+ "When the process policy skips plan approval, for example through the Skip plan approval launcher option.",
210
+ },
211
+ },
212
+ ({ ctx }) => (ctx.state.routing?.plan?.skip ? "bypass" : "approval"),
213
+ )
214
+ .effect(async ({ ctx, event }) => {
487
215
  const planRevision = ctx.process.planRevision + 1;
216
+ const policy = (await config.workflow
217
+ ?.planDecision?.(ctx.params)
218
+ .catch(() => ({ skip: false, reason: "Source unavailable; approval required" }))) ?? {
219
+ skip: false,
220
+ reason: "Human approval required",
221
+ };
488
222
  const summary = normalizeMessage(event.params.summary);
489
223
  const acceptanceCriteria = Array.isArray(event.params.acceptanceCriteria)
490
224
  ? event.params.acceptanceCriteria.filter(
491
225
  (entry): entry is string => typeof entry === "string" && entry.trim() !== "",
492
226
  )
493
227
  : [];
494
- const planMarkdown = ctx.output?.content ?? "";
495
228
  return {
496
- state: clearReviewState(ctx.state),
229
+ state: {
230
+ ...ctx.state,
231
+ routing: { ...ctx.state.routing, plan: { ...policy, planRevision } },
232
+ },
497
233
  processPatch: { planRevision },
498
234
  broadcasts: [
499
235
  {
500
236
  type: "plan.updated",
501
237
  payload: {
502
238
  planRevision,
503
- reviewState: "awaiting_approval",
504
- approved: false,
239
+ reviewState: policy.skip ? "accepted" : "awaiting_approval",
240
+ approved: policy.skip,
505
241
  summary,
506
242
  },
507
243
  },
508
244
  ],
509
245
  emit: [
246
+ ...(policy.skip
247
+ ? [
248
+ {
249
+ type: "plan_approved" as const,
250
+ data: {
251
+ planRevision,
252
+ actor: "system",
253
+ bypassed: true,
254
+ reason: policy.reason,
255
+ },
256
+ },
257
+ ]
258
+ : []),
510
259
  {
511
260
  type: "plan_saved",
512
261
  data: {
513
262
  planRevision,
514
263
  summary,
515
- planMarkdown,
264
+ planMarkdown: ctx.output?.content ?? "",
516
265
  acceptanceCriteria,
517
266
  },
518
267
  },
@@ -520,170 +269,132 @@ export function createRepositoryChangeProcess<TParams extends RepositoryChangePa
520
269
  };
521
270
  }),
522
271
  )
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)
272
+ .publish("plan");
273
+ const implement = flow
274
+ .llm<TParams, RepositoryChangeState>("implement")
551
275
  .description("Implement")
552
- .tools(...implementationTurnAvailableTools)
276
+ .waitFor(({ state }) => !!state.productRefs.plan)
277
+ .executionPurpose(codingPurposes.implementation)
278
+ .tools(...tools)
553
279
  .freshSeededPrimary()
554
- .continueFromProductBranch(products.simplificationPlan, {
555
- kind: "semantic_ref",
556
- ref: "review",
557
- fallback: { kind: "session_root" },
558
- })
559
- .consume(products.plan)
280
+ .startFromRoot()
281
+ .consume("plan")
560
282
  .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) =>
283
+ .outcomeTool("implementation_ready", (tool) =>
573
284
  tool
574
- .description(
575
- "Approve the implementation and publish the review. Its Markdown may include Mermaid diagrams or uploaded images.",
285
+ .description("Implementation and checks are complete; continue to delivery")
286
+ .routeByState(
287
+ {
288
+ simplify: {
289
+ to: "simplify_implementation",
290
+ label: "Simplification enabled",
291
+ description:
292
+ "When the process policy enables simplification. This is the default unless a launcher option or source policy skips it.",
293
+ },
294
+ skip: {
295
+ to: "generate_commit_message",
296
+ label: "Skip simplification",
297
+ description:
298
+ "When simplification is skipped, for example through the Skip simplification launcher option or the leitwerk-skip-simplification source label.",
299
+ },
300
+ },
301
+ ({ ctx }) => (ctx.state.routing?.simplification?.skip ? "skip" : "simplify"),
576
302
  )
577
- .to(turnIds.implementationDecision),
578
- )
579
- .outcomeTool("request_changes", (tool) =>
580
- tool
581
- .description(
582
- "Request implementation changes and publish actionable feedback. Its Markdown may include Mermaid diagrams or uploaded images.",
583
- )
584
- .to(turnIds.implementationReviewFeedback),
303
+ .effect(async ({ ctx }) => ({
304
+ state: {
305
+ ...ctx.state,
306
+ routing: {
307
+ ...ctx.state.routing,
308
+ simplification: ctx.state.routing?.simplification ??
309
+ (await config.workflow?.simplification?.(ctx.params)) ?? {
310
+ skip: false,
311
+ reason: "Simplification enabled by default",
312
+ },
313
+ },
314
+ },
315
+ })),
585
316
  )
586
- .publish(products.review);
587
-
588
- const simplifyImplementationTurn = flow
589
- .llm<TParams, RepositoryChangeState>(turnIds.simplifyImplementation)
317
+ .publish("implementation-summary");
318
+ const simplify = flow
319
+ .llm<TParams, RepositoryChangeState>("simplify_implementation")
590
320
  .description("Simplify")
321
+ .executionPurpose(codingPurposes.review)
591
322
  .tools("read", "bash")
592
323
  .rootBranchReview()
593
- .startFromProductBranch(products.simplificationPlan)
594
- .buildPrompt(buildSimplifyImplementationPrompt)
595
- .publish(products.simplificationPlan)
596
- .to(turnIds.simplificationDecision);
324
+ .startFromProductBranch("simplification-plan")
325
+ .buildPrompt(buildStreamlinedSimplificationPrompt)
326
+ .publish("simplification-plan")
327
+ .to("apply_simplification");
328
+ const applySimplification = flow
329
+ .llm<TParams, RepositoryChangeState>("apply_simplification")
330
+ .description("Apply simplification")
331
+ .executionPurpose(codingPurposes.implementation)
332
+ .tools(...tools)
333
+ .freshSeededPrimary()
334
+ .consume("plan")
335
+ .consume("simplification-plan")
336
+ .buildPrompt(
337
+ (
338
+ ctx,
339
+ ) => `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.
597
340
 
598
- const generateCommitMessageTurn = flow
599
- .llm<TParams, RepositoryChangeState>(turnIds.generateCommitMessage)
341
+ Accepted plan:
342
+ ${ctx.input.plan}
343
+
344
+ Findings by repository:
345
+ ${ctx.input["simplification-plan"]}`,
346
+ )
347
+ .publish("implementation-summary")
348
+ .to("generate_commit_message");
349
+ const generateCommitMessage = flow
350
+ .llm<TParams, RepositoryChangeState>("generate_commit_message")
600
351
  .description("Write Commit Message")
601
- .modelPurpose("process_title_generation")
352
+ .executionPurpose(codingPurposes.implementation)
353
+ .tools("read", "grep", "find", "ls")
602
354
  .rootBranchReview()
603
355
  .startFromRoot()
604
- .consume(products.plan)
605
- .buildPrompt(buildGenerateCommitMessagePrompt)
606
- .publish(products.commitMessage)
356
+ .consume("plan")
357
+ .consume("implementation-summary")
358
+ .prepare(prepareRepositoryCommitMessageEvidence)
359
+ .buildPrompt(buildRepositoryCommitMessagesPrompt)
360
+ .publish("commit-message")
607
361
  .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
-
362
+ .state(({ ctx }) => ({
363
+ ...ctx.state,
364
+ finalization: {
365
+ ...ctx.state.finalization,
366
+ commitMessages: parseRepositoryCommitMessages(
367
+ ctx.output?.content,
368
+ ctx.projects.map((p) => p.key),
369
+ ),
370
+ },
371
+ }));
640
372
  const builder = flow
641
373
  .process<TParams, RepositoryChangeState>(config.processId)
642
374
  .displayName(config.displayName)
643
- .entry(turnIds.generatePlan)
375
+ .entry("generate_plan")
644
376
  .happyPath(
645
- turnIds.generatePlan,
646
- turnIds.implement,
647
- turnIds.generateCommitMessage,
377
+ "generate_plan",
378
+ "implement",
379
+ "simplify_implementation",
380
+ "apply_simplification",
381
+ "generate_commit_message",
648
382
  ...(config.publication.happyPath ?? [config.publication.entryTurnId]),
649
383
  )
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);
384
+ .piConfig(config.workflow?.multiRepository ? {} : { sessionCwdTemplate: "{{{projectKey}}}" })
385
+ .codecs({ params: config.paramsCodec, state: repositoryChangeStateCodec })
386
+ .initialState(() => repositoryChangeStateCodec.parse({}))
387
+ .turn(generatePlan)
388
+ .turn({ id: "plan_decision", definition: planDecision })
389
+ .turn(implement)
390
+ .turn(simplify)
391
+ .turn(applySimplification)
392
+ .turn(generateCommitMessage)
393
+ .use(config.publication.fragment);
664
394
  if (config.repositoryCredentials) builder.repositoryCredentials(config.repositoryCredentials);
665
395
  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
396
  return {
676
397
  /** @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),
398
+ process: builder.define(),
688
399
  };
689
400
  }