@leitwerk-dev/coding 0.1.7 → 0.1.9

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.
@@ -1,4 +1,4 @@
1
- import { createReviewSubject, normalizeOptionalMarkdown } from "@leitwerk-dev/domain";
1
+ import { 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",
@@ -129,19 +126,18 @@ export function createRepositoryChangeProcess<TParams extends RepositoryChangePa
129
126
  state: RepositoryChangeState;
130
127
  }): RepositoryChangeState {
131
128
  return patchRepositoryChangeState(ctx.state, {
132
- reviewSubject: implementationReviewSubject,
133
129
  clearReviewRefs: true,
134
130
  clearProductRefs: [products.simplificationPlan],
135
131
  });
136
132
  }
137
133
 
138
134
  function buildAcceptedReviewFollowUpMessage(input: {
139
- reviewSubject: { kind: "plan" | "implementation" };
135
+ reviewedProduct: typeof products.plan | typeof products.implementationSummary;
140
136
  reviewMarkdown: string;
141
137
  adjustment?: string | null;
142
138
  }): string {
143
139
  const adjustment = normalizeMessage(input.adjustment);
144
- if (input.reviewSubject.kind === "plan") {
140
+ if (input.reviewedProduct === products.plan) {
145
141
  return [
146
142
  "Revise the plan according to this review:",
147
143
  input.reviewMarkdown,
@@ -203,7 +199,6 @@ export function createRepositoryChangeProcess<TParams extends RepositoryChangePa
203
199
  function patchRepositoryChangeState(
204
200
  state: RepositoryChangeState,
205
201
  input: {
206
- reviewSubject?: RepositoryChangeState["reviewSubject"];
207
202
  finalization?: RepositoryChangeState["finalization"];
208
203
  semanticEntryRefs?: RepositoryChangeState["semanticEntryRefs"];
209
204
  clearReviewRefs?: boolean;
@@ -212,7 +207,6 @@ export function createRepositoryChangeProcess<TParams extends RepositoryChangePa
212
207
  ): RepositoryChangeState {
213
208
  const nextState: RepositoryChangeState = {
214
209
  ...state,
215
- ...("reviewSubject" in input ? { reviewSubject: input.reviewSubject ?? null } : {}),
216
210
  ...("finalization" in input ? { finalization: input.finalization } : {}),
217
211
  ...("semanticEntryRefs" in input ? { semanticEntryRefs: input.semanticEntryRefs } : {}),
218
212
  };
@@ -238,7 +232,6 @@ export function createRepositoryChangeProcess<TParams extends RepositoryChangePa
238
232
 
239
233
  const planDecisionSpec = humanTurn<TParams, RepositoryChangeState>({
240
234
  description: "Review plan",
241
- reviewSubject: planReviewSubject,
242
235
  reviewSemanticRef: "plan",
243
236
  notesFields: [
244
237
  {
@@ -262,7 +255,6 @@ export function createRepositoryChangeProcess<TParams extends RepositoryChangePa
262
255
  }
263
256
  return {
264
257
  state: patchRepositoryChangeState(ctx.state, {
265
- reviewSubject: null,
266
258
  clearReviewRefs: true,
267
259
  clearProductRefs: [products.simplificationPlan],
268
260
  }),
@@ -290,7 +282,6 @@ export function createRepositoryChangeProcess<TParams extends RepositoryChangePa
290
282
  const message = normalizeMessage(input.message);
291
283
  return {
292
284
  state: patchRepositoryChangeState(ctx.state, {
293
- reviewSubject: null,
294
285
  clearReviewRefs: true,
295
286
  clearProductRefs: [products.simplificationPlan],
296
287
  }),
@@ -311,7 +302,6 @@ export function createRepositoryChangeProcess<TParams extends RepositoryChangePa
311
302
  }
312
303
  return {
313
304
  state: patchRepositoryChangeState(ctx.state, {
314
- reviewSubject: planReviewSubject,
315
305
  clearReviewRefs: true,
316
306
  clearProductRefs: [products.simplificationPlan],
317
307
  }),
@@ -323,7 +313,6 @@ export function createRepositoryChangeProcess<TParams extends RepositoryChangePa
323
313
 
324
314
  const planReviewFeedbackSpec = humanTurn<TParams, RepositoryChangeState>({
325
315
  description: "Review plan feedback",
326
- reviewSubject: planReviewSubject,
327
316
  reviewSemanticRef: "review",
328
317
  notesFields: [
329
318
  {
@@ -350,16 +339,11 @@ export function createRepositoryChangeProcess<TParams extends RepositoryChangePa
350
339
  throw new Error("No review output markdown is available to accept");
351
340
  }
352
341
  return buildAcceptedReviewFollowUpMessage({
353
- reviewSubject: planReviewSubject,
342
+ reviewedProduct: products.plan,
354
343
  reviewMarkdown,
355
344
  adjustment: normalizeMessage(input.message),
356
345
  });
357
346
  },
358
- effect: ({ ctx }) => ({
359
- state: patchRepositoryChangeState(ctx.state, {
360
- reviewSubject: null,
361
- }),
362
- }),
363
347
  }),
364
348
  [codingActionIds.requestReviewChanges]: revisionAction({
365
349
  label: "Request review changes",
@@ -368,29 +352,18 @@ export function createRepositoryChangeProcess<TParams extends RepositoryChangePa
368
352
  form: requestReviewChangesForm,
369
353
  to: turnIds.reviewPlan,
370
354
  queueTarget: { semanticRef: "review" },
371
- effect: ({ ctx }) => ({
372
- state: patchRepositoryChangeState(ctx.state, {
373
- reviewSubject: planReviewSubject,
374
- }),
375
- }),
376
355
  }),
377
356
  [codingActionIds.dismissReview]: {
378
357
  label: "Dismiss review",
379
358
  description: "Return to the plan decision without applying the review.",
380
359
  acceptanceState: "neutral",
381
360
  to: turnIds.planDecision,
382
- effect: ({ ctx }) => ({
383
- state: patchRepositoryChangeState(ctx.state, {
384
- reviewSubject: planReviewSubject,
385
- }),
386
- }),
387
361
  },
388
362
  },
389
363
  });
390
364
 
391
365
  const implementationDecisionSpec = humanTurn<TParams, RepositoryChangeState>({
392
366
  description: "Review implementation",
393
- reviewSubject: implementationReviewSubject,
394
367
  reviewSemanticRef: "currentPrimaryPathLeaf",
395
368
  notesFields: [
396
369
  {
@@ -411,7 +384,6 @@ export function createRepositoryChangeProcess<TParams extends RepositoryChangePa
411
384
  to: turnIds.generateCommitMessage,
412
385
  effect: ({ ctx }) => ({
413
386
  state: patchRepositoryChangeState(ctx.state, {
414
- reviewSubject: null,
415
387
  finalization: createEmptyRepositoryChangeFinalizationState(),
416
388
  clearReviewRefs: true,
417
389
  clearProductRefs: [products.simplificationPlan],
@@ -427,7 +399,6 @@ export function createRepositoryChangeProcess<TParams extends RepositoryChangePa
427
399
  queueTarget: { semanticRef: "currentPrimaryPathLeaf" },
428
400
  effect: ({ ctx }) => ({
429
401
  state: patchRepositoryChangeState(ctx.state, {
430
- reviewSubject: null,
431
402
  clearReviewRefs: true,
432
403
  clearProductRefs: [products.simplificationPlan],
433
404
  }),
@@ -459,7 +430,6 @@ export function createRepositoryChangeProcess<TParams extends RepositoryChangePa
459
430
 
460
431
  const implementationReviewFeedbackSpec = humanTurn<TParams, RepositoryChangeState>({
461
432
  description: "Review implementation feedback",
462
- reviewSubject: implementationReviewSubject,
463
433
  reviewSemanticRef: "review",
464
434
  notesFields: [
465
435
  {
@@ -487,14 +457,13 @@ export function createRepositoryChangeProcess<TParams extends RepositoryChangePa
487
457
  throw new Error("No review output markdown is available to accept");
488
458
  }
489
459
  return buildAcceptedReviewFollowUpMessage({
490
- reviewSubject: implementationReviewSubject,
460
+ reviewedProduct: products.implementationSummary,
491
461
  reviewMarkdown,
492
462
  adjustment: normalizeMessage(input.message),
493
463
  });
494
464
  },
495
465
  effect: ({ ctx }) => ({
496
466
  state: patchRepositoryChangeState(ctx.state, {
497
- reviewSubject: null,
498
467
  clearProductRefs: [products.simplificationPlan],
499
468
  }),
500
469
  }),
@@ -506,28 +475,17 @@ export function createRepositoryChangeProcess<TParams extends RepositoryChangePa
506
475
  schedulable: true,
507
476
  to: turnIds.reviewImplementation,
508
477
  queueTarget: { semanticRef: "review" },
509
- effect: ({ ctx }) => ({
510
- state: patchRepositoryChangeState(ctx.state, {
511
- reviewSubject: implementationReviewSubject,
512
- }),
513
- }),
514
478
  }),
515
479
  [codingActionIds.dismissReview]: {
516
480
  label: "Dismiss review",
517
481
  acceptanceState: "neutral",
518
482
  to: turnIds.implementationDecision,
519
- effect: ({ ctx }) => ({
520
- state: patchRepositoryChangeState(ctx.state, {
521
- reviewSubject: implementationReviewSubject,
522
- }),
523
- }),
524
483
  },
525
484
  },
526
485
  });
527
486
 
528
487
  const simplificationDecisionSpec = humanTurn<TParams, RepositoryChangeState>({
529
488
  description: "Review simplification plan",
530
- reviewSubject: implementationReviewSubject,
531
489
  reviewProduct: products.simplificationPlan,
532
490
  notesFields: [
533
491
  {
@@ -560,7 +518,6 @@ export function createRepositoryChangeProcess<TParams extends RepositoryChangePa
560
518
  },
561
519
  effect: ({ ctx }) => ({
562
520
  state: patchRepositoryChangeState(ctx.state, {
563
- reviewSubject: null,
564
521
  clearReviewRefs: true,
565
522
  }),
566
523
  }),
@@ -571,11 +528,6 @@ export function createRepositoryChangeProcess<TParams extends RepositoryChangePa
571
528
  form: requestReviewChangesForm,
572
529
  to: turnIds.simplifyImplementation,
573
530
  queueTarget: { productName: products.simplificationPlan },
574
- effect: ({ ctx }) => ({
575
- state: patchRepositoryChangeState(ctx.state, {
576
- reviewSubject: implementationReviewSubject,
577
- }),
578
- }),
579
531
  }),
580
532
  [codingActionIds.dismissReview]: {
581
533
  label: "Reject simplification plan",
@@ -585,7 +537,6 @@ export function createRepositoryChangeProcess<TParams extends RepositoryChangePa
585
537
  to: turnIds.implementationDecision,
586
538
  effect: ({ ctx }) => ({
587
539
  state: patchRepositoryChangeState(ctx.state, {
588
- reviewSubject: implementationReviewSubject,
589
540
  clearReviewRefs: true,
590
541
  clearProductRefs: [products.simplificationPlan],
591
542
  }),
@@ -610,7 +561,6 @@ export function createRepositoryChangeProcess<TParams extends RepositoryChangePa
610
561
  params: { plan: planMarkdown },
611
562
  markdown: planMarkdown,
612
563
  state: patchRepositoryChangeState(ctx.state, {
613
- reviewSubject: null,
614
564
  clearReviewRefs: true,
615
565
  clearProductRefs: [products.simplificationPlan],
616
566
  }),
@@ -653,7 +603,6 @@ export function createRepositoryChangeProcess<TParams extends RepositoryChangePa
653
603
  const planMarkdown = ctx.output?.content ?? "";
654
604
  return {
655
605
  state: patchRepositoryChangeState(ctx.state, {
656
- reviewSubject: planReviewSubject,
657
606
  clearReviewRefs: true,
658
607
  clearProductRefs: [products.simplificationPlan],
659
608
  }),
@@ -691,7 +640,6 @@ export function createRepositoryChangeProcess<TParams extends RepositoryChangePa
691
640
  .tools("read", "bash")
692
641
  .rootBranchReview()
693
642
  .startFromReviewBranch()
694
- .reviews(planReviewSubject)
695
643
  .consume(products.plan)
696
644
  .buildPrompt(buildReviewPlanPrompt)
697
645
  .outcomeTool("no_issues", (tool) =>
@@ -699,24 +647,14 @@ export function createRepositoryChangeProcess<TParams extends RepositoryChangePa
699
647
  .description(
700
648
  "Approve the plan and publish the review. Its Markdown may include Mermaid diagrams or uploaded images.",
701
649
  )
702
- .to(turnIds.planDecision)
703
- .state(({ ctx }) =>
704
- patchRepositoryChangeState(ctx.state, {
705
- reviewSubject: planReviewSubject,
706
- }),
707
- ),
650
+ .to(turnIds.planDecision),
708
651
  )
709
652
  .outcomeTool("request_changes", (tool) =>
710
653
  tool
711
654
  .description(
712
655
  "Request plan changes and publish actionable feedback. Its Markdown may include Mermaid diagrams or uploaded images.",
713
656
  )
714
- .to(turnIds.planReviewFeedback)
715
- .state(({ ctx }) =>
716
- patchRepositoryChangeState(ctx.state, {
717
- reviewSubject: planReviewSubject,
718
- }),
719
- ),
657
+ .to(turnIds.planReviewFeedback),
720
658
  )
721
659
  .publish(products.review);
722
660
 
@@ -736,7 +674,6 @@ export function createRepositoryChangeProcess<TParams extends RepositoryChangePa
736
674
  .to(turnIds.implementationDecision)
737
675
  .state(({ ctx }) =>
738
676
  patchRepositoryChangeState(ctx.state, {
739
- reviewSubject: implementationReviewSubject,
740
677
  clearReviewRefs: true,
741
678
  clearProductRefs: [products.simplificationPlan],
742
679
  }),
@@ -748,31 +685,20 @@ export function createRepositoryChangeProcess<TParams extends RepositoryChangePa
748
685
  .tools("read", "bash")
749
686
  .rootBranchReview()
750
687
  .startFromReviewBranch()
751
- .reviews(implementationReviewSubject)
752
688
  .buildPrompt(buildReviewImplementationPrompt)
753
689
  .outcomeTool("no_issues", (tool) =>
754
690
  tool
755
691
  .description(
756
692
  "Approve the implementation and publish the review. Its Markdown may include Mermaid diagrams or uploaded images.",
757
693
  )
758
- .to(turnIds.implementationDecision)
759
- .state(({ ctx }) =>
760
- patchRepositoryChangeState(ctx.state, {
761
- reviewSubject: implementationReviewSubject,
762
- }),
763
- ),
694
+ .to(turnIds.implementationDecision),
764
695
  )
765
696
  .outcomeTool("request_changes", (tool) =>
766
697
  tool
767
698
  .description(
768
699
  "Request implementation changes and publish actionable feedback. Its Markdown may include Mermaid diagrams or uploaded images.",
769
700
  )
770
- .to(turnIds.implementationReviewFeedback)
771
- .state(({ ctx }) =>
772
- patchRepositoryChangeState(ctx.state, {
773
- reviewSubject: implementationReviewSubject,
774
- }),
775
- ),
701
+ .to(turnIds.implementationReviewFeedback),
776
702
  )
777
703
  .publish(products.review);
778
704
 
@@ -784,12 +710,7 @@ export function createRepositoryChangeProcess<TParams extends RepositoryChangePa
784
710
  .startFromProductBranch(products.simplificationPlan)
785
711
  .buildPrompt(buildSimplifyImplementationPrompt)
786
712
  .publish(products.simplificationPlan)
787
- .to(turnIds.simplificationDecision)
788
- .state(({ ctx }) =>
789
- patchRepositoryChangeState(ctx.state, {
790
- reviewSubject: implementationReviewSubject,
791
- }),
792
- );
713
+ .to(turnIds.simplificationDecision);
793
714
 
794
715
  const generateCommitMessageTurn = flow
795
716
  .llm<TParams, RepositoryChangeState>(turnIds.generateCommitMessage)
@@ -837,7 +758,6 @@ export function createRepositoryChangeProcess<TParams extends RepositoryChangePa
837
758
  .complete()
838
759
  .state(({ ctx, event }) =>
839
760
  patchRepositoryChangeState(ctx.state, {
840
- reviewSubject: null,
841
761
  finalization: resetFinalizationAfterMessage(ctx.state, {
842
762
  usedConflictResolution:
843
763
  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 {
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/turns/review-implementation.ts"],"sourcesContent":["import { createReviewSubject } from \"@leitwerk-dev/domain\";\nimport type { FlowPromptContext, StructuralProcessState } from \"@leitwerk-dev/process-sdk\";\n\nexport const implementationReviewSubject = createReviewSubject(\"implementation\");\n\nexport function buildReviewImplementationPrompt(\n\tctx: FlowPromptContext<unknown, StructuralProcessState>,\n): string {\n\tconst repo = ctx.repo.get(\"repo\");\n\treturn `Repository root: . (the current working directory)\n\nReview the current implementation of this requested change:\n${ctx.prompts.initial}\n\nInspect the changes with \\`git diff --stat $(git merge-base ${repo.baseBranch} HEAD)\\`. Check for:\n- bugs and logic errors\n- security issues\n- error handling gaps\n- missing or misplaced tests\n- unnecessary abstractions, duplication, and other avoidable complexity\n\nFor each issue, give a concise fix.\n\nRules:\n- inspect code only inside the current working directory\n- treat . as the repository root for read-only inspection\n- use bash only for read-only inspection (e.g. git diff, git status, rg, tree, file listing, read-only http/CLI calls)\n- do not modify files, branches, commits, or git index state\n- do not read from or write to any original source repository path outside the process workspace\n- publish a short Markdown approval note if the implementation is ready\n- publish concise, actionable Markdown feedback if the implementation needs changes`;\n}\n"],"mappings":";AAAA,SAAS,2BAA2B;AAG7B,IAAM,8BAA8B,oBAAoB,gBAAgB;AAExE,SAAS,gCACf,KACS;AACT,QAAM,OAAO,IAAI,KAAK,IAAI,MAAM;AAChC,SAAO;AAAA;AAAA;AAAA,EAGN,IAAI,QAAQ,OAAO;AAAA;AAAA,8DAEyC,KAAK,UAAU;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAiB7E;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/turns/review-plan.ts"],"sourcesContent":["import { createReviewSubject } from \"@leitwerk-dev/domain\";\nimport type { FlowPromptContext, StructuralProcessState } from \"@leitwerk-dev/process-sdk\";\n\nexport const planReviewSubject = createReviewSubject(\"plan\");\n\nexport function buildReviewPlanPrompt(\n\tctx: FlowPromptContext<unknown, StructuralProcessState, \"plan\">,\n): string {\n\treturn `Review the plan against this requested change:\n${ctx.prompts.initial}\n\nRepository root: . (the current working directory)\n\nPlan:\n${ctx.input.plan}\n\nRules:\n- review the plan only; do not rewrite the plan\n- if you inspect repository files for context, read only inside the current working directory\n- use bash only for read-only inspection (e.g. git diff, git status, rg, tree, file listing, read-only http/CLI calls)\n- do not modify files, branches, commits, or git index state\n- do not read from or write to any original source repository path outside the process workspace\n- evaluate scope, sequencing, risks, and acceptance criteria\n- publish a short Markdown approval note when the plan is solid\n- publish concise, actionable Markdown feedback when the plan needs changes`;\n}\n"],"mappings":";AAAA,SAAS,2BAA2B;AAG7B,IAAM,oBAAoB,oBAAoB,MAAM;AAEpD,SAAS,sBACf,KACS;AACT,SAAO;AAAA,EACN,IAAI,QAAQ,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA,EAKnB,IAAI,MAAM,IAAI;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAWhB;","names":[]}