@leitwerk-dev/coding 0.1.8 → 0.2.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 (50) hide show
  1. package/README.md +7 -2
  2. package/dist/auto-work-branch.js +86 -86
  3. package/dist/auto-work-branch.js.map +1 -1
  4. package/dist/{chunk-YWGLBUFT.js → chunk-73LKROYK.js} +162 -154
  5. package/dist/chunk-73LKROYK.js.map +1 -0
  6. package/dist/{chunk-RZ54IVY5.js → chunk-EP3ZC37F.js} +1 -4
  7. package/dist/chunk-EP3ZC37F.js.map +1 -0
  8. package/dist/{chunk-RWCLBBB2.js → chunk-WQEPA35Z.js} +1 -4
  9. package/dist/chunk-WQEPA35Z.js.map +1 -0
  10. package/dist/finalization-git.d.ts +6 -1
  11. package/dist/finalization-git.d.ts.map +1 -1
  12. package/dist/finalization-git.js +13 -559
  13. package/dist/finalization-git.js.map +1 -1
  14. package/dist/index.js +650 -6
  15. package/dist/index.js.map +1 -1
  16. package/dist/repository-change-launch.js +17 -182
  17. package/dist/repository-change-launch.js.map +1 -1
  18. package/dist/repository-change-process.d.ts.map +1 -1
  19. package/dist/repository-change-state.js +12 -51
  20. package/dist/repository-change-state.js.map +1 -1
  21. package/dist/turns/generate-commit-message.js +9 -38
  22. package/dist/turns/generate-commit-message.js.map +1 -1
  23. package/dist/turns/generate-plan.js +7 -19
  24. package/dist/turns/generate-plan.js.map +1 -1
  25. package/dist/turns/implement.js +7 -17
  26. package/dist/turns/implement.js.map +1 -1
  27. package/dist/turns/resolve-merge-conflict.js +7 -21
  28. package/dist/turns/resolve-merge-conflict.js.map +1 -1
  29. package/dist/turns/review-implementation.d.ts +0 -1
  30. package/dist/turns/review-implementation.d.ts.map +1 -1
  31. package/dist/turns/review-implementation.js +7 -27
  32. package/dist/turns/review-implementation.js.map +1 -1
  33. package/dist/turns/review-plan.d.ts +0 -1
  34. package/dist/turns/review-plan.d.ts.map +1 -1
  35. package/dist/turns/review-plan.js +7 -21
  36. package/dist/turns/review-plan.js.map +1 -1
  37. package/dist/turns/simplify-implementation.js +7 -7
  38. package/dist/turns/simplify-implementation.js.map +1 -1
  39. package/package.json +5 -4
  40. package/src/finalization-git.ts +209 -166
  41. package/src/repository-change-process.ts +85 -249
  42. package/src/turns/review-implementation.ts +0 -3
  43. package/src/turns/review-plan.ts +0 -3
  44. package/dist/actions.js +0 -45
  45. package/dist/actions.js.map +0 -1
  46. package/dist/chunk-RWCLBBB2.js.map +0 -1
  47. package/dist/chunk-RZ54IVY5.js.map +0 -1
  48. package/dist/chunk-YWGLBUFT.js.map +0 -1
  49. package/dist/repository-change-process.js +0 -757
  50. package/dist/repository-change-process.js.map +0 -1
@@ -1,4 +1,4 @@
1
- import { createReviewSubject, normalizeOptionalMarkdown } from "@leitwerk-dev/domain";
1
+ import { trimString as normalizeMessage, normalizeOptionalMarkdown } from "@leitwerk-dev/domain";
2
2
  import {
3
3
  acceptedReviewHandoffAction,
4
4
  type Codec,
@@ -65,9 +65,6 @@ export interface RepositoryChangeProcessConfig<TParams extends RepositoryChangeP
65
65
  export function createRepositoryChangeProcess<TParams extends RepositoryChangeParams>(
66
66
  config: RepositoryChangeProcessConfig<TParams>,
67
67
  ) {
68
- const planReviewSubject = createReviewSubject("plan");
69
- const implementationReviewSubject = createReviewSubject("implementation");
70
-
71
68
  const turnIds = {
72
69
  importPlan: "import_plan",
73
70
  generatePlan: "generate_plan",
@@ -96,10 +93,6 @@ export function createRepositoryChangeProcess<TParams extends RepositoryChangePa
96
93
 
97
94
  const implementationTurnAvailableTools = ["read", "bash", "edit", "write"] as const;
98
95
 
99
- function normalizeMessage(value: unknown): string {
100
- return typeof value === "string" ? value.trim() : "";
101
- }
102
-
103
96
  function resetFinalizationAfterMessage(
104
97
  state: RepositoryChangeState,
105
98
  overrides: Partial<RepositoryChangeState["finalization"]> = {},
@@ -118,103 +111,70 @@ export function createRepositoryChangeProcess<TParams extends RepositoryChangePa
118
111
 
119
112
  function requireResolvedPlanRef(
120
113
  plan: RepositoryChangeState["semanticEntryRefs"][keyof RepositoryChangeState["semanticEntryRefs"]],
121
- usage: "simplification review" | "implementation review",
114
+ usage: "approval" | "review" | "simplification review" | "implementation review",
122
115
  ): asserts plan is { entryId: string; turnRecordId: string } {
123
116
  if (!hasResolvedTurnRecordRef(plan)) {
124
117
  throw new Error(`No plan is available for ${usage}`);
125
118
  }
126
119
  }
127
120
 
128
- function buildImplementationReviewTurnState(ctx: {
129
- state: RepositoryChangeState;
130
- }): RepositoryChangeState {
131
- return patchRepositoryChangeState(ctx.state, {
132
- reviewSubject: implementationReviewSubject,
121
+ function clearReviewState(state: RepositoryChangeState): RepositoryChangeState {
122
+ return patchRepositoryChangeState(state, {
133
123
  clearReviewRefs: true,
134
124
  clearProductRefs: [products.simplificationPlan],
135
125
  });
136
126
  }
137
127
 
138
- function buildAcceptedReviewFollowUpMessage(input: {
139
- reviewSubject: { kind: "plan" | "implementation" };
140
- reviewMarkdown: string;
141
- adjustment?: string | null;
128
+ function buildAcceptedFollowUpMessage(input: {
129
+ kind: "plan_review" | "implementation_review" | "simplification";
130
+ markdown: unknown;
131
+ adjustment: unknown;
142
132
  }): string {
143
- const adjustment = normalizeMessage(input.adjustment);
144
- if (input.reviewSubject.kind === "plan") {
145
- return [
146
- "Revise the plan according to this review:",
147
- input.reviewMarkdown,
148
- adjustment
149
- ? ["Also follow this adjustment where it conflicts with the review:", adjustment].join(
150
- "\n\n",
151
- )
152
- : null,
153
- ]
154
- .filter((section): section is string => typeof section === "string" && section !== "")
155
- .join("\n\n");
133
+ const markdown = normalizeOptionalMarkdown(input.markdown);
134
+ if (!markdown) {
135
+ throw new Error(
136
+ input.kind === "simplification"
137
+ ? "No simplification plan markdown is available to accept"
138
+ : "No review output markdown is available to accept",
139
+ );
156
140
  }
157
- return buildAcceptedImplementationFollowUpMessage({
158
- kind: "review",
159
- implementationMarkdown: input.reviewMarkdown,
160
- adjustment,
161
- });
162
- }
163
-
164
- function buildAcceptedImplementationFollowUpMessage(input: {
165
- kind: "review" | "simplification";
166
- implementationMarkdown: string;
167
- adjustment?: string | null;
168
- }): string {
169
141
  const adjustment = normalizeMessage(input.adjustment);
170
- const isSimplification = input.kind === "simplification";
171
- const subject = isSimplification ? "simplification plan" : "review";
172
-
173
- return [
174
- `Implement according to this ${subject}:`,
175
- input.implementationMarkdown,
176
- adjustment
177
- ? [`Also follow this adjustment where it conflicts with the ${subject}:`, adjustment].join(
178
- "\n\n",
179
- )
180
- : null,
181
- [
182
- "This is now an implementation turn. Ignore earlier review-only or read-only instructions.",
183
- "You may change files in the repository workspace.",
184
- `Use the available tools (${implementationTurnAvailableTools.join(", ")}) to inspect, edit, build, and test the change.`,
185
- "When finished, return an implementation summary.",
186
- ].join("\n"),
187
- ]
188
- .filter((section): section is string => typeof section === "string" && section !== "")
189
- .join("\n\n");
190
- }
191
-
192
- function buildAcceptedSimplificationFollowUpMessage(input: {
193
- simplificationMarkdown: string;
194
- adjustment?: string | null;
195
- }): string {
196
- return buildAcceptedImplementationFollowUpMessage({
197
- kind: "simplification",
198
- implementationMarkdown: input.simplificationMarkdown,
199
- adjustment: input.adjustment,
200
- });
142
+ const subject = input.kind === "simplification" ? "simplification plan" : "review";
143
+ const introduction =
144
+ input.kind === "plan_review"
145
+ ? "Revise the plan according to this review:"
146
+ : `Implement according to this ${subject}:`;
147
+ const sections = [introduction, markdown];
148
+ if (adjustment) {
149
+ sections.push(
150
+ `Also follow this adjustment where it conflicts with the ${subject}:`,
151
+ adjustment,
152
+ );
153
+ }
154
+ if (input.kind !== "plan_review") {
155
+ sections.push(
156
+ [
157
+ "This is now an implementation turn. Ignore earlier review-only or read-only instructions.",
158
+ "You may change files in the repository workspace.",
159
+ `Use the available tools (${implementationTurnAvailableTools.join(", ")}) to inspect, edit, build, and test the change.`,
160
+ "When finished, return an implementation summary.",
161
+ ].join("\n"),
162
+ );
163
+ }
164
+ return sections.join("\n\n");
201
165
  }
202
166
 
203
167
  function patchRepositoryChangeState(
204
168
  state: RepositoryChangeState,
205
169
  input: {
206
- reviewSubject?: RepositoryChangeState["reviewSubject"];
207
170
  finalization?: RepositoryChangeState["finalization"];
208
- semanticEntryRefs?: RepositoryChangeState["semanticEntryRefs"];
209
171
  clearReviewRefs?: boolean;
210
172
  clearProductRefs?: readonly string[];
211
173
  },
212
174
  ): RepositoryChangeState {
213
175
  const nextState: RepositoryChangeState = {
214
176
  ...state,
215
- ...("reviewSubject" in input ? { reviewSubject: input.reviewSubject ?? null } : {}),
216
177
  ...("finalization" in input ? { finalization: input.finalization } : {}),
217
- ...("semanticEntryRefs" in input ? { semanticEntryRefs: input.semanticEntryRefs } : {}),
218
178
  };
219
179
  const productRefsToClear = new Set(input.clearProductRefs ?? []);
220
180
  if (input.clearReviewRefs) {
@@ -237,8 +197,7 @@ export function createRepositoryChangeProcess<TParams extends RepositoryChangePa
237
197
  }
238
198
 
239
199
  const planDecisionSpec = humanTurn<TParams, RepositoryChangeState>({
240
- description: "Review plan",
241
- reviewSubject: planReviewSubject,
200
+ description: "Review Plan",
242
201
  reviewSemanticRef: "plan",
243
202
  notesFields: [
244
203
  {
@@ -256,16 +215,9 @@ export function createRepositoryChangeProcess<TParams extends RepositoryChangePa
256
215
  acceptanceState: "accepted",
257
216
  to: turnIds.implement,
258
217
  effect: ({ ctx }) => {
259
- const plan = ctx.state.semanticEntryRefs.plan;
260
- if (!hasResolvedTurnRecordRef(plan)) {
261
- throw new Error("No plan is available for approval");
262
- }
218
+ requireResolvedPlanRef(ctx.state.semanticEntryRefs.plan, "approval");
263
219
  return {
264
- state: patchRepositoryChangeState(ctx.state, {
265
- reviewSubject: null,
266
- clearReviewRefs: true,
267
- clearProductRefs: [products.simplificationPlan],
268
- }),
220
+ state: clearReviewState(ctx.state),
269
221
  emit: [
270
222
  {
271
223
  type: "plan_approved",
@@ -289,11 +241,7 @@ export function createRepositoryChangeProcess<TParams extends RepositoryChangePa
289
241
  effect: ({ ctx, input }) => {
290
242
  const message = normalizeMessage(input.message);
291
243
  return {
292
- state: patchRepositoryChangeState(ctx.state, {
293
- reviewSubject: null,
294
- clearReviewRefs: true,
295
- clearProductRefs: [products.simplificationPlan],
296
- }),
244
+ state: clearReviewState(ctx.state),
297
245
  emit: [{ type: "plan_revision_requested", data: { message } }],
298
246
  };
299
247
  },
@@ -305,16 +253,9 @@ export function createRepositoryChangeProcess<TParams extends RepositoryChangePa
305
253
  schedulable: true,
306
254
  to: turnIds.reviewPlan,
307
255
  effect: ({ ctx }) => {
308
- const plan = ctx.state.semanticEntryRefs.plan;
309
- if (!hasResolvedTurnRecordRef(plan)) {
310
- throw new Error("No plan is available for review");
311
- }
256
+ requireResolvedPlanRef(ctx.state.semanticEntryRefs.plan, "review");
312
257
  return {
313
- state: patchRepositoryChangeState(ctx.state, {
314
- reviewSubject: planReviewSubject,
315
- clearReviewRefs: true,
316
- clearProductRefs: [products.simplificationPlan],
317
- }),
258
+ state: clearReviewState(ctx.state),
318
259
  };
319
260
  },
320
261
  },
@@ -322,8 +263,7 @@ export function createRepositoryChangeProcess<TParams extends RepositoryChangePa
322
263
  });
323
264
 
324
265
  const planReviewFeedbackSpec = humanTurn<TParams, RepositoryChangeState>({
325
- description: "Review plan feedback",
326
- reviewSubject: planReviewSubject,
266
+ description: "Review Plan Feedback",
327
267
  reviewSemanticRef: "review",
328
268
  notesFields: [
329
269
  {
@@ -342,24 +282,12 @@ export function createRepositoryChangeProcess<TParams extends RepositoryChangePa
342
282
  acceptanceState: "accepted",
343
283
  form: acceptReviewForm,
344
284
  to: turnIds.generatePlan,
345
- resolveBodyMarkdown: ({ ctx, input }) => {
346
- const reviewMarkdown = normalizeOptionalMarkdown(
347
- ctx.readSemanticTurnResultMarkdown("review"),
348
- );
349
- if (!reviewMarkdown) {
350
- throw new Error("No review output markdown is available to accept");
351
- }
352
- return buildAcceptedReviewFollowUpMessage({
353
- reviewSubject: planReviewSubject,
354
- reviewMarkdown,
355
- adjustment: normalizeMessage(input.message),
356
- });
357
- },
358
- effect: ({ ctx }) => ({
359
- state: patchRepositoryChangeState(ctx.state, {
360
- reviewSubject: null,
285
+ resolveBodyMarkdown: ({ ctx, input }) =>
286
+ buildAcceptedFollowUpMessage({
287
+ kind: "plan_review",
288
+ markdown: ctx.readSemanticTurnResultMarkdown("review"),
289
+ adjustment: input.message,
361
290
  }),
362
- }),
363
291
  }),
364
292
  [codingActionIds.requestReviewChanges]: revisionAction({
365
293
  label: "Request review changes",
@@ -368,29 +296,18 @@ export function createRepositoryChangeProcess<TParams extends RepositoryChangePa
368
296
  form: requestReviewChangesForm,
369
297
  to: turnIds.reviewPlan,
370
298
  queueTarget: { semanticRef: "review" },
371
- effect: ({ ctx }) => ({
372
- state: patchRepositoryChangeState(ctx.state, {
373
- reviewSubject: planReviewSubject,
374
- }),
375
- }),
376
299
  }),
377
300
  [codingActionIds.dismissReview]: {
378
301
  label: "Dismiss review",
379
302
  description: "Return to the plan decision without applying the review.",
380
303
  acceptanceState: "neutral",
381
304
  to: turnIds.planDecision,
382
- effect: ({ ctx }) => ({
383
- state: patchRepositoryChangeState(ctx.state, {
384
- reviewSubject: planReviewSubject,
385
- }),
386
- }),
387
305
  },
388
306
  },
389
307
  });
390
308
 
391
309
  const implementationDecisionSpec = humanTurn<TParams, RepositoryChangeState>({
392
- description: "Review implementation",
393
- reviewSubject: implementationReviewSubject,
310
+ description: "Review",
394
311
  reviewSemanticRef: "currentPrimaryPathLeaf",
395
312
  notesFields: [
396
313
  {
@@ -411,7 +328,6 @@ export function createRepositoryChangeProcess<TParams extends RepositoryChangePa
411
328
  to: turnIds.generateCommitMessage,
412
329
  effect: ({ ctx }) => ({
413
330
  state: patchRepositoryChangeState(ctx.state, {
414
- reviewSubject: null,
415
331
  finalization: createEmptyRepositoryChangeFinalizationState(),
416
332
  clearReviewRefs: true,
417
333
  clearProductRefs: [products.simplificationPlan],
@@ -426,11 +342,7 @@ export function createRepositoryChangeProcess<TParams extends RepositoryChangePa
426
342
  to: turnIds.implement,
427
343
  queueTarget: { semanticRef: "currentPrimaryPathLeaf" },
428
344
  effect: ({ ctx }) => ({
429
- state: patchRepositoryChangeState(ctx.state, {
430
- reviewSubject: null,
431
- clearReviewRefs: true,
432
- clearProductRefs: [products.simplificationPlan],
433
- }),
345
+ state: clearReviewState(ctx.state),
434
346
  }),
435
347
  }),
436
348
  [codingActionIds.simplify]: {
@@ -441,7 +353,7 @@ export function createRepositoryChangeProcess<TParams extends RepositoryChangePa
441
353
  to: turnIds.simplifyImplementation,
442
354
  effect: ({ ctx }) => {
443
355
  requireResolvedPlanRef(ctx.state.semanticEntryRefs.plan, "simplification review");
444
- return { state: buildImplementationReviewTurnState(ctx) };
356
+ return { state: clearReviewState(ctx.state) };
445
357
  },
446
358
  },
447
359
  [codingActionIds.runReview]: {
@@ -451,7 +363,7 @@ export function createRepositoryChangeProcess<TParams extends RepositoryChangePa
451
363
  to: turnIds.reviewImplementation,
452
364
  effect: ({ ctx }) => {
453
365
  requireResolvedPlanRef(ctx.state.semanticEntryRefs.plan, "implementation review");
454
- return { state: buildImplementationReviewTurnState(ctx) };
366
+ return { state: clearReviewState(ctx.state) };
455
367
  },
456
368
  },
457
369
  },
@@ -459,7 +371,6 @@ export function createRepositoryChangeProcess<TParams extends RepositoryChangePa
459
371
 
460
372
  const implementationReviewFeedbackSpec = humanTurn<TParams, RepositoryChangeState>({
461
373
  description: "Review implementation feedback",
462
- reviewSubject: implementationReviewSubject,
463
374
  reviewSemanticRef: "review",
464
375
  notesFields: [
465
376
  {
@@ -479,22 +390,14 @@ export function createRepositoryChangeProcess<TParams extends RepositoryChangePa
479
390
  schedulable: true,
480
391
  to: turnIds.implement,
481
392
  queueTarget: { semanticRef: "review" },
482
- resolveBodyMarkdown: ({ ctx, input }) => {
483
- const reviewMarkdown = normalizeOptionalMarkdown(
484
- ctx.readSemanticTurnResultMarkdown("review"),
485
- );
486
- if (!reviewMarkdown) {
487
- throw new Error("No review output markdown is available to accept");
488
- }
489
- return buildAcceptedReviewFollowUpMessage({
490
- reviewSubject: implementationReviewSubject,
491
- reviewMarkdown,
492
- adjustment: normalizeMessage(input.message),
493
- });
494
- },
393
+ resolveBodyMarkdown: ({ ctx, input }) =>
394
+ buildAcceptedFollowUpMessage({
395
+ kind: "implementation_review",
396
+ markdown: ctx.readSemanticTurnResultMarkdown("review"),
397
+ adjustment: input.message,
398
+ }),
495
399
  effect: ({ ctx }) => ({
496
400
  state: patchRepositoryChangeState(ctx.state, {
497
- reviewSubject: null,
498
401
  clearProductRefs: [products.simplificationPlan],
499
402
  }),
500
403
  }),
@@ -506,28 +409,17 @@ export function createRepositoryChangeProcess<TParams extends RepositoryChangePa
506
409
  schedulable: true,
507
410
  to: turnIds.reviewImplementation,
508
411
  queueTarget: { semanticRef: "review" },
509
- effect: ({ ctx }) => ({
510
- state: patchRepositoryChangeState(ctx.state, {
511
- reviewSubject: implementationReviewSubject,
512
- }),
513
- }),
514
412
  }),
515
413
  [codingActionIds.dismissReview]: {
516
414
  label: "Dismiss review",
517
415
  acceptanceState: "neutral",
518
416
  to: turnIds.implementationDecision,
519
- effect: ({ ctx }) => ({
520
- state: patchRepositoryChangeState(ctx.state, {
521
- reviewSubject: implementationReviewSubject,
522
- }),
523
- }),
524
417
  },
525
418
  },
526
419
  });
527
420
 
528
421
  const simplificationDecisionSpec = humanTurn<TParams, RepositoryChangeState>({
529
422
  description: "Review simplification plan",
530
- reviewSubject: implementationReviewSubject,
531
423
  reviewProduct: products.simplificationPlan,
532
424
  notesFields: [
533
425
  {
@@ -546,21 +438,14 @@ export function createRepositoryChangeProcess<TParams extends RepositoryChangePa
546
438
  schedulable: true,
547
439
  to: turnIds.implement,
548
440
  queueTarget: { productName: products.simplificationPlan },
549
- resolveBodyMarkdown: ({ ctx, input }) => {
550
- const simplificationMarkdown = normalizeOptionalMarkdown(
551
- ctx.readProductTurnResultMarkdown(products.simplificationPlan),
552
- );
553
- if (!simplificationMarkdown) {
554
- throw new Error("No simplification plan markdown is available to accept");
555
- }
556
- return buildAcceptedSimplificationFollowUpMessage({
557
- simplificationMarkdown,
558
- adjustment: normalizeMessage(input.message),
559
- });
560
- },
441
+ resolveBodyMarkdown: ({ ctx, input }) =>
442
+ buildAcceptedFollowUpMessage({
443
+ kind: "simplification",
444
+ markdown: ctx.readProductTurnResultMarkdown(products.simplificationPlan),
445
+ adjustment: input.message,
446
+ }),
561
447
  effect: ({ ctx }) => ({
562
448
  state: patchRepositoryChangeState(ctx.state, {
563
- reviewSubject: null,
564
449
  clearReviewRefs: true,
565
450
  }),
566
451
  }),
@@ -571,11 +456,6 @@ export function createRepositoryChangeProcess<TParams extends RepositoryChangePa
571
456
  form: requestReviewChangesForm,
572
457
  to: turnIds.simplifyImplementation,
573
458
  queueTarget: { productName: products.simplificationPlan },
574
- effect: ({ ctx }) => ({
575
- state: patchRepositoryChangeState(ctx.state, {
576
- reviewSubject: implementationReviewSubject,
577
- }),
578
- }),
579
459
  }),
580
460
  [codingActionIds.dismissReview]: {
581
461
  label: "Reject simplification plan",
@@ -584,18 +464,14 @@ export function createRepositoryChangeProcess<TParams extends RepositoryChangePa
584
464
  acceptanceState: "neutral",
585
465
  to: turnIds.implementationDecision,
586
466
  effect: ({ ctx }) => ({
587
- state: patchRepositoryChangeState(ctx.state, {
588
- reviewSubject: implementationReviewSubject,
589
- clearReviewRefs: true,
590
- clearProductRefs: [products.simplificationPlan],
591
- }),
467
+ state: clearReviewState(ctx.state),
592
468
  }),
593
469
  },
594
470
  },
595
471
  });
596
472
 
597
473
  const importPlanTurn = flow
598
- .serverAutomatic<TParams, RepositoryChangeState>(turnIds.importPlan)
474
+ .automatic<TParams, RepositoryChangeState>(turnIds.importPlan)
599
475
  .description("Import handoff plan")
600
476
  .run((ctx) => {
601
477
  const planMarkdown =
@@ -609,11 +485,6 @@ export function createRepositoryChangeProcess<TParams extends RepositoryChangePa
609
485
  outcome: "imported",
610
486
  params: { plan: planMarkdown },
611
487
  markdown: planMarkdown,
612
- state: patchRepositoryChangeState(ctx.state, {
613
- reviewSubject: null,
614
- clearReviewRefs: true,
615
- clearProductRefs: [products.simplificationPlan],
616
- }),
617
488
  };
618
489
  })
619
490
  .outcome("imported", (outcome) =>
@@ -621,12 +492,15 @@ export function createRepositoryChangeProcess<TParams extends RepositoryChangePa
621
492
  .description("Imported a handoff plan and skipped replanning")
622
493
  .markdown("plan", { description: "Imported handoff plan", publish: true })
623
494
  .to(turnIds.implement)
624
- .effect(({ ctx }) => ({ processPatch: { planRevision: ctx.process.planRevision + 1 } })),
495
+ .effect(({ ctx }) => ({
496
+ processPatch: { planRevision: ctx.process.planRevision + 1 },
497
+ state: clearReviewState(ctx.state),
498
+ })),
625
499
  );
626
500
 
627
501
  const generatePlanTurn = flow
628
502
  .llm<TParams, RepositoryChangeState>(turnIds.generatePlan)
629
- .description("Draft plan")
503
+ .description("Plan")
630
504
  .tools("read", "bash")
631
505
  .askQuestions()
632
506
  .freshPrimary()
@@ -652,11 +526,7 @@ export function createRepositoryChangeProcess<TParams extends RepositoryChangePa
652
526
  : [];
653
527
  const planMarkdown = ctx.output?.content ?? "";
654
528
  return {
655
- state: patchRepositoryChangeState(ctx.state, {
656
- reviewSubject: planReviewSubject,
657
- clearReviewRefs: true,
658
- clearProductRefs: [products.simplificationPlan],
659
- }),
529
+ state: clearReviewState(ctx.state),
660
530
  processPatch: { planRevision },
661
531
  broadcasts: [
662
532
  {
@@ -687,11 +557,10 @@ export function createRepositoryChangeProcess<TParams extends RepositoryChangePa
687
557
 
688
558
  const reviewPlanTurn = flow
689
559
  .llm<TParams, RepositoryChangeState>(turnIds.reviewPlan)
690
- .description("Review plan")
560
+ .description("Assess Plan")
691
561
  .tools("read", "bash")
692
562
  .rootBranchReview()
693
563
  .startFromReviewBranch()
694
- .reviews(planReviewSubject)
695
564
  .consume(products.plan)
696
565
  .buildPrompt(buildReviewPlanPrompt)
697
566
  .outcomeTool("no_issues", (tool) =>
@@ -699,30 +568,20 @@ export function createRepositoryChangeProcess<TParams extends RepositoryChangePa
699
568
  .description(
700
569
  "Approve the plan and publish the review. Its Markdown may include Mermaid diagrams or uploaded images.",
701
570
  )
702
- .to(turnIds.planDecision)
703
- .state(({ ctx }) =>
704
- patchRepositoryChangeState(ctx.state, {
705
- reviewSubject: planReviewSubject,
706
- }),
707
- ),
571
+ .to(turnIds.planDecision),
708
572
  )
709
573
  .outcomeTool("request_changes", (tool) =>
710
574
  tool
711
575
  .description(
712
576
  "Request plan changes and publish actionable feedback. Its Markdown may include Mermaid diagrams or uploaded images.",
713
577
  )
714
- .to(turnIds.planReviewFeedback)
715
- .state(({ ctx }) =>
716
- patchRepositoryChangeState(ctx.state, {
717
- reviewSubject: planReviewSubject,
718
- }),
719
- ),
578
+ .to(turnIds.planReviewFeedback),
720
579
  )
721
580
  .publish(products.review);
722
581
 
723
582
  const implementTurn = flow
724
583
  .llm<TParams, RepositoryChangeState>(turnIds.implement)
725
- .description("Implement change")
584
+ .description("Implement")
726
585
  .tools(...implementationTurnAvailableTools)
727
586
  .freshSeededPrimary()
728
587
  .continueFromProductBranch(products.simplificationPlan, {
@@ -734,66 +593,44 @@ export function createRepositoryChangeProcess<TParams extends RepositoryChangePa
734
593
  .buildPrompt(buildImplementPrompt)
735
594
  .publish(products.implementationSummary)
736
595
  .to(turnIds.implementationDecision)
737
- .state(({ ctx }) =>
738
- patchRepositoryChangeState(ctx.state, {
739
- reviewSubject: implementationReviewSubject,
740
- clearReviewRefs: true,
741
- clearProductRefs: [products.simplificationPlan],
742
- }),
743
- );
596
+ .state(({ ctx }) => clearReviewState(ctx.state));
744
597
 
745
598
  const reviewImplementationTurn = flow
746
599
  .llm<TParams, RepositoryChangeState>(turnIds.reviewImplementation)
747
- .description("Review implementation")
600
+ .description("Assess Implementation")
748
601
  .tools("read", "bash")
749
602
  .rootBranchReview()
750
603
  .startFromReviewBranch()
751
- .reviews(implementationReviewSubject)
752
604
  .buildPrompt(buildReviewImplementationPrompt)
753
605
  .outcomeTool("no_issues", (tool) =>
754
606
  tool
755
607
  .description(
756
608
  "Approve the implementation and publish the review. Its Markdown may include Mermaid diagrams or uploaded images.",
757
609
  )
758
- .to(turnIds.implementationDecision)
759
- .state(({ ctx }) =>
760
- patchRepositoryChangeState(ctx.state, {
761
- reviewSubject: implementationReviewSubject,
762
- }),
763
- ),
610
+ .to(turnIds.implementationDecision),
764
611
  )
765
612
  .outcomeTool("request_changes", (tool) =>
766
613
  tool
767
614
  .description(
768
615
  "Request implementation changes and publish actionable feedback. Its Markdown may include Mermaid diagrams or uploaded images.",
769
616
  )
770
- .to(turnIds.implementationReviewFeedback)
771
- .state(({ ctx }) =>
772
- patchRepositoryChangeState(ctx.state, {
773
- reviewSubject: implementationReviewSubject,
774
- }),
775
- ),
617
+ .to(turnIds.implementationReviewFeedback),
776
618
  )
777
619
  .publish(products.review);
778
620
 
779
621
  const simplifyImplementationTurn = flow
780
622
  .llm<TParams, RepositoryChangeState>(turnIds.simplifyImplementation)
781
- .description("Simplify implementation")
623
+ .description("Simplify")
782
624
  .tools("read", "bash")
783
625
  .rootBranchReview()
784
626
  .startFromProductBranch(products.simplificationPlan)
785
627
  .buildPrompt(buildSimplifyImplementationPrompt)
786
628
  .publish(products.simplificationPlan)
787
- .to(turnIds.simplificationDecision)
788
- .state(({ ctx }) =>
789
- patchRepositoryChangeState(ctx.state, {
790
- reviewSubject: implementationReviewSubject,
791
- }),
792
- );
629
+ .to(turnIds.simplificationDecision);
793
630
 
794
631
  const generateCommitMessageTurn = flow
795
632
  .llm<TParams, RepositoryChangeState>(turnIds.generateCommitMessage)
796
- .description("Generate commit message")
633
+ .description("Write Commit Message")
797
634
  .modelPurpose("process_title_generation")
798
635
  .rootBranchReview()
799
636
  .startFromRoot()
@@ -837,7 +674,6 @@ export function createRepositoryChangeProcess<TParams extends RepositoryChangePa
837
674
  .complete()
838
675
  .state(({ ctx, event }) =>
839
676
  patchRepositoryChangeState(ctx.state, {
840
- reviewSubject: null,
841
677
  finalization: resetFinalizationAfterMessage(ctx.state, {
842
678
  usedConflictResolution:
843
679
  event.params.usedConflictResolution === true ||
@@ -1,8 +1,5 @@
1
- import { createReviewSubject } from "@leitwerk-dev/domain";
2
1
  import type { FlowPromptContext, StructuralProcessState } from "@leitwerk-dev/process-sdk";
3
2
 
4
- export const implementationReviewSubject = createReviewSubject("implementation");
5
-
6
3
  export function buildReviewImplementationPrompt(
7
4
  ctx: FlowPromptContext<unknown, StructuralProcessState>,
8
5
  ): string {
@@ -1,8 +1,5 @@
1
- import { createReviewSubject } from "@leitwerk-dev/domain";
2
1
  import type { FlowPromptContext, StructuralProcessState } from "@leitwerk-dev/process-sdk";
3
2
 
4
- export const planReviewSubject = createReviewSubject("plan");
5
-
6
3
  export function buildReviewPlanPrompt(
7
4
  ctx: FlowPromptContext<unknown, StructuralProcessState, "plan">,
8
5
  ): string {