@leitwerk-dev/coding 0.1.9 → 0.2.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 (113) hide show
  1. package/README.md +19 -2
  2. package/dist/actions.d.ts +14 -0
  3. package/dist/actions.d.ts.map +1 -1
  4. package/dist/auto-work-branch-internal.d.ts +20 -0
  5. package/dist/auto-work-branch-internal.d.ts.map +1 -0
  6. package/dist/auto-work-branch.d.ts +2 -12
  7. package/dist/auto-work-branch.d.ts.map +1 -1
  8. package/dist/auto-work-branch.js +84 -86
  9. package/dist/auto-work-branch.js.map +1 -1
  10. package/dist/{chunk-EP3ZC37F.js → chunk-34B3Q75M.js} +1 -1
  11. package/dist/chunk-34B3Q75M.js.map +1 -0
  12. package/dist/{chunk-OFDNIT5X.js → chunk-F6CEEAFE.js} +1 -1
  13. package/dist/chunk-F6CEEAFE.js.map +1 -0
  14. package/dist/{chunk-YIP4MP64.js → chunk-HUVXPZSF.js} +2 -2
  15. package/dist/chunk-HUVXPZSF.js.map +1 -0
  16. package/dist/{chunk-R3S5KR3J.js → chunk-MY6XFGHM.js} +146 -168
  17. package/dist/chunk-MY6XFGHM.js.map +1 -0
  18. package/dist/{chunk-5LVPKVI2.js → chunk-OERAYSVI.js} +1 -1
  19. package/dist/chunk-OERAYSVI.js.map +1 -0
  20. package/dist/{chunk-WQEPA35Z.js → chunk-R3UCUGY6.js} +1 -1
  21. package/dist/chunk-R3UCUGY6.js.map +1 -0
  22. package/dist/{chunk-67YKGZLM.js → chunk-W7VJT6AN.js} +1 -1
  23. package/dist/chunk-W7VJT6AN.js.map +1 -0
  24. package/dist/{chunk-NIJCT4VK.js → chunk-WKHVLLKE.js} +1 -1
  25. package/dist/chunk-WKHVLLKE.js.map +1 -0
  26. package/dist/{chunk-UBVLJV3V.js → chunk-YSC5GEQJ.js} +1 -1
  27. package/dist/chunk-YSC5GEQJ.js.map +1 -0
  28. package/dist/finalization-git-internal.d.ts +72 -0
  29. package/dist/finalization-git-internal.d.ts.map +1 -0
  30. package/dist/finalization-git.d.ts +2 -42
  31. package/dist/finalization-git.d.ts.map +1 -1
  32. package/dist/finalization-git.js +7 -593
  33. package/dist/finalization-git.js.map +1 -1
  34. package/dist/index.d.ts +3 -7
  35. package/dist/index.d.ts.map +1 -1
  36. package/dist/index.js +654 -6
  37. package/dist/index.js.map +1 -1
  38. package/dist/repository-change-launch-internal.d.ts +116 -0
  39. package/dist/repository-change-launch-internal.d.ts.map +1 -0
  40. package/dist/repository-change-launch.d.ts +2 -64
  41. package/dist/repository-change-launch.d.ts.map +1 -1
  42. package/dist/repository-change-launch.js +177 -174
  43. package/dist/repository-change-launch.js.map +1 -1
  44. package/dist/repository-change-process.d.ts +32 -2
  45. package/dist/repository-change-process.d.ts.map +1 -1
  46. package/dist/repository-change-state-internal.d.ts +30 -0
  47. package/dist/repository-change-state-internal.d.ts.map +1 -0
  48. package/dist/repository-change-state.d.ts +2 -17
  49. package/dist/repository-change-state.d.ts.map +1 -1
  50. package/dist/repository-change-state.js +6 -51
  51. package/dist/repository-change-state.js.map +1 -1
  52. package/dist/turns/generate-commit-message.d.ts +2 -0
  53. package/dist/turns/generate-commit-message.d.ts.map +1 -1
  54. package/dist/turns/generate-commit-message.js +9 -38
  55. package/dist/turns/generate-commit-message.js.map +1 -1
  56. package/dist/turns/generate-plan.d.ts +1 -0
  57. package/dist/turns/generate-plan.d.ts.map +1 -1
  58. package/dist/turns/generate-plan.js +7 -19
  59. package/dist/turns/generate-plan.js.map +1 -1
  60. package/dist/turns/implement.d.ts +1 -0
  61. package/dist/turns/implement.d.ts.map +1 -1
  62. package/dist/turns/implement.js +7 -17
  63. package/dist/turns/implement.js.map +1 -1
  64. package/dist/turns/resolve-merge-conflict.d.ts +1 -0
  65. package/dist/turns/resolve-merge-conflict.d.ts.map +1 -1
  66. package/dist/turns/resolve-merge-conflict.js +7 -21
  67. package/dist/turns/resolve-merge-conflict.js.map +1 -1
  68. package/dist/turns/review-implementation.d.ts +1 -0
  69. package/dist/turns/review-implementation.d.ts.map +1 -1
  70. package/dist/turns/review-implementation.js +7 -25
  71. package/dist/turns/review-implementation.js.map +1 -1
  72. package/dist/turns/review-plan.d.ts +1 -0
  73. package/dist/turns/review-plan.d.ts.map +1 -1
  74. package/dist/turns/review-plan.js +7 -19
  75. package/dist/turns/review-plan.js.map +1 -1
  76. package/dist/turns/simplify-implementation.d.ts +1 -0
  77. package/dist/turns/simplify-implementation.d.ts.map +1 -1
  78. package/dist/turns/simplify-implementation.js +7 -7
  79. package/dist/turns/simplify-implementation.js.map +1 -1
  80. package/package.json +19 -8
  81. package/src/actions.ts +17 -1
  82. package/src/auto-work-branch-internal.ts +149 -0
  83. package/src/auto-work-branch.ts +7 -140
  84. package/src/finalization-git-internal.ts +855 -0
  85. package/src/finalization-git.ts +2 -825
  86. package/src/index.ts +16 -4
  87. package/src/repository-change-launch-internal.ts +328 -0
  88. package/src/repository-change-launch.ts +15 -264
  89. package/src/repository-change-process.ts +112 -168
  90. package/src/repository-change-state-internal.ts +90 -0
  91. package/src/repository-change-state.ts +2 -78
  92. package/src/turns/generate-commit-message.ts +2 -0
  93. package/src/turns/generate-plan.ts +1 -0
  94. package/src/turns/implement.ts +1 -0
  95. package/src/turns/resolve-merge-conflict.ts +1 -0
  96. package/src/turns/review-implementation.ts +1 -0
  97. package/src/turns/review-plan.ts +1 -0
  98. package/src/turns/simplify-implementation.ts +1 -0
  99. package/dist/actions.js +0 -45
  100. package/dist/actions.js.map +0 -1
  101. package/dist/chunk-5LVPKVI2.js.map +0 -1
  102. package/dist/chunk-67YKGZLM.js.map +0 -1
  103. package/dist/chunk-EP3ZC37F.js.map +0 -1
  104. package/dist/chunk-NIJCT4VK.js.map +0 -1
  105. package/dist/chunk-OFDNIT5X.js.map +0 -1
  106. package/dist/chunk-R3S5KR3J.js.map +0 -1
  107. package/dist/chunk-UBVLJV3V.js.map +0 -1
  108. package/dist/chunk-WQEPA35Z.js.map +0 -1
  109. package/dist/chunk-Y2S6JFVO.js +0 -185
  110. package/dist/chunk-Y2S6JFVO.js.map +0 -1
  111. package/dist/chunk-YIP4MP64.js.map +0 -1
  112. package/dist/repository-change-process.js +0 -689
  113. package/dist/repository-change-process.js.map +0 -1
package/dist/index.js CHANGED
@@ -1,7 +1,655 @@
1
- export const manifest = { id: "coding", version: "0.1.0" };
2
- const extension = { manifest };
3
- export default extension;
4
- export * from "./actions.js";
5
- export * from "./repository-change-launch.js";
6
- export * from "./repository-change-process.js";
1
+ import {
2
+ buildImplementPrompt
3
+ } from "./chunk-YSC5GEQJ.js";
4
+ import {
5
+ buildResolveMergeConflictPrompt
6
+ } from "./chunk-OERAYSVI.js";
7
+ import {
8
+ buildReviewImplementationPrompt
9
+ } from "./chunk-R3UCUGY6.js";
10
+ import {
11
+ buildReviewPlanPrompt
12
+ } from "./chunk-34B3Q75M.js";
13
+ import {
14
+ buildSimplifyImplementationPrompt
15
+ } from "./chunk-F6CEEAFE.js";
16
+ import {
17
+ runDeterministicFinalization
18
+ } from "./chunk-MY6XFGHM.js";
19
+ import {
20
+ clearReviewRefs,
21
+ createEmptyRepositoryChangeFinalizationState,
22
+ repositoryChangeStateCodec,
23
+ resetRepositoryChangeFinalizationState
24
+ } from "./chunk-HUVXPZSF.js";
25
+ import {
26
+ buildGenerateCommitMessagePrompt,
27
+ normalizeGeneratedCommitMessage
28
+ } from "./chunk-WKHVLLKE.js";
29
+ import {
30
+ buildGeneratePlanPrompt
31
+ } from "./chunk-W7VJT6AN.js";
32
+ import "./chunk-PX6F3LHL.js";
33
+
34
+ // src/actions.ts
35
+ var codingActionIds = {
36
+ /** @public */
37
+ approvePlan: "approve_plan",
38
+ /** @internal */
39
+ requestRevision: "request_revision",
40
+ /** @internal */
41
+ runReview: "run_review",
42
+ /** @internal */
43
+ simplify: "simplify",
44
+ /** @internal */
45
+ acceptReview: "accept_review",
46
+ /** @internal */
47
+ requestReviewChanges: "request_review_changes",
48
+ /** @internal */
49
+ dismissReview: "dismiss_review",
50
+ /** @public */
51
+ finalizeChange: "finalize_change"
52
+ };
53
+ function notesForm(id, title, label, description) {
54
+ return {
55
+ id,
56
+ title,
57
+ fields: [
58
+ { id: "message", label, kind: "textarea", primaryPrompt: true, required: true, description }
59
+ ],
60
+ submitLabel: title
61
+ };
62
+ }
63
+ var requestRevisionForm = notesForm(
64
+ codingActionIds.requestRevision,
65
+ "Request revision",
66
+ "Revision notes",
67
+ "Instructions for the next implementation pass."
68
+ );
69
+ var requestReviewChangesForm = notesForm(
70
+ codingActionIds.requestReviewChanges,
71
+ "Request review changes",
72
+ "Review notes",
73
+ "Instructions for the next review pass."
74
+ );
75
+ var acceptReviewForm = {
76
+ id: codingActionIds.acceptReview,
77
+ title: "Accept review",
78
+ fields: [
79
+ {
80
+ id: "message",
81
+ label: "Review adjustment",
82
+ kind: "textarea",
83
+ primaryPrompt: true,
84
+ description: "Optional instructions to apply with the accepted review, such as dropping one finding."
85
+ }
86
+ ],
87
+ submitLabel: "Accept review"
88
+ };
89
+ function createFinalizeChangeForm(copy) {
90
+ return {
91
+ id: codingActionIds.finalizeChange,
92
+ title: copy.title,
93
+ fields: [],
94
+ submitLabel: copy.title
95
+ };
96
+ }
97
+
98
+ // src/repository-change-process.ts
99
+ import { trimString as normalizeMessage, normalizeOptionalMarkdown } from "@leitwerk-dev/domain";
100
+ import {
101
+ acceptedReviewHandoffAction,
102
+ createEmptyStructuralProcessState,
103
+ flow,
104
+ humanTurn,
105
+ revisionAction
106
+ } from "@leitwerk-dev/process-sdk";
107
+ function createRepositoryChangeProcess(config) {
108
+ const turnIds = {
109
+ importPlan: "import_plan",
110
+ generatePlan: "generate_plan",
111
+ planDecision: "plan_decision",
112
+ reviewPlan: "review_plan",
113
+ planReviewFeedback: "plan_review_feedback",
114
+ implement: "implement",
115
+ implementationDecision: "implementation_decision",
116
+ reviewImplementation: "review_implementation",
117
+ implementationReviewFeedback: "implementation_review_feedback",
118
+ simplifyImplementation: "simplify_implementation",
119
+ simplificationDecision: "simplification_decision",
120
+ generateCommitMessage: "generate_commit_message",
121
+ commitAndMerge: "commit_and_merge",
122
+ resolveMergeConflict: "resolve_merge_conflict"
123
+ };
124
+ const products = {
125
+ plan: "plan",
126
+ review: "review",
127
+ simplificationPlan: "simplification-plan",
128
+ implementationSummary: "implementation-summary",
129
+ mergeResolutionSummary: "merge-resolution-summary",
130
+ commitMessage: "commit-message"
131
+ };
132
+ const implementationTurnAvailableTools = ["read", "bash", "edit", "write"];
133
+ function resetFinalizationAfterMessage(state, overrides = {}) {
134
+ return resetRepositoryChangeFinalizationState({
135
+ generatedCommitMessage: state.finalization.generatedCommitMessage,
136
+ ...overrides
137
+ });
138
+ }
139
+ function hasResolvedTurnRecordRef(ref) {
140
+ return typeof ref?.turnRecordId === "string" && ref.turnRecordId.trim() !== "";
141
+ }
142
+ function requireResolvedPlanRef(plan, usage) {
143
+ if (!hasResolvedTurnRecordRef(plan)) {
144
+ throw new Error(`No plan is available for ${usage}`);
145
+ }
146
+ }
147
+ function clearReviewState(state) {
148
+ return patchRepositoryChangeState(state, {
149
+ clearReviewRefs: true,
150
+ clearProductRefs: [products.simplificationPlan]
151
+ });
152
+ }
153
+ function buildAcceptedFollowUpMessage(input) {
154
+ const markdown = normalizeOptionalMarkdown(input.markdown);
155
+ if (!markdown) {
156
+ throw new Error(
157
+ input.kind === "simplification" ? "No simplification plan markdown is available to accept" : "No review output markdown is available to accept"
158
+ );
159
+ }
160
+ const adjustment = normalizeMessage(input.adjustment);
161
+ const subject = input.kind === "simplification" ? "simplification plan" : "review";
162
+ const introduction = input.kind === "plan_review" ? "Revise the plan according to this review:" : `Implement according to this ${subject}:`;
163
+ const sections = [introduction, markdown];
164
+ if (adjustment) {
165
+ sections.push(
166
+ `Also follow this adjustment where it conflicts with the ${subject}:`,
167
+ adjustment
168
+ );
169
+ }
170
+ if (input.kind !== "plan_review") {
171
+ sections.push(
172
+ [
173
+ "This is now an implementation turn. Ignore earlier review-only or read-only instructions.",
174
+ "You may change files in the repository workspace.",
175
+ `Use the available tools (${implementationTurnAvailableTools.join(", ")}) to inspect, edit, build, and test the change.`,
176
+ "When finished, return an implementation summary."
177
+ ].join("\n")
178
+ );
179
+ }
180
+ return sections.join("\n\n");
181
+ }
182
+ function patchRepositoryChangeState(state, input) {
183
+ const nextState = {
184
+ ...state,
185
+ ..."finalization" in input ? { finalization: input.finalization } : {}
186
+ };
187
+ const productRefsToClear = new Set(input.clearProductRefs ?? []);
188
+ if (input.clearReviewRefs) {
189
+ productRefsToClear.add(products.review);
190
+ }
191
+ if (!input.clearReviewRefs && productRefsToClear.size === 0) {
192
+ return nextState;
193
+ }
194
+ const productRefs = { ...nextState.productRefs };
195
+ for (const productName of productRefsToClear) {
196
+ delete productRefs[productName];
197
+ }
198
+ return {
199
+ ...nextState,
200
+ semanticEntryRefs: input.clearReviewRefs ? clearReviewRefs(nextState.semanticEntryRefs) : nextState.semanticEntryRefs,
201
+ productRefs
202
+ };
203
+ }
204
+ const planDecisionSpec = humanTurn({
205
+ description: "Review Plan",
206
+ reviewSemanticRef: "plan",
207
+ notesFields: [
208
+ {
209
+ id: "message",
210
+ label: "Revision notes",
211
+ placeholder: "Describe what the next plan revision should improve",
212
+ required: true
213
+ }
214
+ ],
215
+ commentary: "Approve this plan, request a revision, or run an automated review.",
216
+ actions: {
217
+ [codingActionIds.approvePlan]: {
218
+ label: "Approve plan",
219
+ description: "Accept the current plan and continue into implementation.",
220
+ acceptanceState: "accepted",
221
+ to: turnIds.implement,
222
+ effect: ({ ctx }) => {
223
+ requireResolvedPlanRef(ctx.state.semanticEntryRefs.plan, "approval");
224
+ return {
225
+ state: clearReviewState(ctx.state),
226
+ emit: [
227
+ {
228
+ type: "plan_approved",
229
+ data: {
230
+ externalId: ctx.process.externalId,
231
+ planRevision: ctx.process.planRevision
232
+ }
233
+ }
234
+ ]
235
+ };
236
+ }
237
+ },
238
+ [codingActionIds.requestRevision]: revisionAction({
239
+ label: "Request revision",
240
+ description: "Send the plan back for another draft revision.",
241
+ acceptanceState: "requires_changes",
242
+ form: requestRevisionForm,
243
+ schedulable: true,
244
+ to: turnIds.generatePlan,
245
+ queueTarget: { semanticRef: "currentPrimaryPathLeaf" },
246
+ effect: ({ ctx, input }) => {
247
+ const message = normalizeMessage(input.message);
248
+ return {
249
+ state: clearReviewState(ctx.state),
250
+ emit: [{ type: "plan_revision_requested", data: { message } }]
251
+ };
252
+ }
253
+ }),
254
+ [codingActionIds.runReview]: {
255
+ label: "Run automated review",
256
+ description: "Send the current plan to the LLM reviewer.",
257
+ acceptanceState: "neutral",
258
+ schedulable: true,
259
+ to: turnIds.reviewPlan,
260
+ effect: ({ ctx }) => {
261
+ requireResolvedPlanRef(ctx.state.semanticEntryRefs.plan, "review");
262
+ return {
263
+ state: clearReviewState(ctx.state)
264
+ };
265
+ }
266
+ }
267
+ }
268
+ });
269
+ const planReviewFeedbackSpec = humanTurn({
270
+ description: "Review Plan Feedback",
271
+ reviewSemanticRef: "review",
272
+ notesFields: [
273
+ {
274
+ id: "message",
275
+ label: "Review notes",
276
+ placeholder: "Describe how the next review pass should change",
277
+ required: true
278
+ }
279
+ ],
280
+ commentary: "Apply this feedback to the next plan revision, request a revised review, or dismiss it.",
281
+ actions: {
282
+ [codingActionIds.acceptReview]: acceptedReviewHandoffAction({
283
+ label: "Accept review",
284
+ description: "Apply the current review outcome and continue with the plan flow.",
285
+ acceptanceState: "accepted",
286
+ form: acceptReviewForm,
287
+ to: turnIds.generatePlan,
288
+ resolveBodyMarkdown: ({ ctx, input }) => buildAcceptedFollowUpMessage({
289
+ kind: "plan_review",
290
+ markdown: ctx.readSemanticTurnResultMarkdown("review"),
291
+ adjustment: input.message
292
+ })
293
+ }),
294
+ [codingActionIds.requestReviewChanges]: revisionAction({
295
+ label: "Request review changes",
296
+ description: "Ask the LLM reviewer to revise its plan review.",
297
+ acceptanceState: "requires_changes",
298
+ form: requestReviewChangesForm,
299
+ to: turnIds.reviewPlan,
300
+ queueTarget: { semanticRef: "review" }
301
+ }),
302
+ [codingActionIds.dismissReview]: {
303
+ label: "Dismiss review",
304
+ description: "Return to the plan decision without applying the review.",
305
+ acceptanceState: "neutral",
306
+ to: turnIds.planDecision
307
+ }
308
+ }
309
+ });
310
+ const implementationDecisionSpec = humanTurn({
311
+ description: "Review",
312
+ reviewSemanticRef: "currentPrimaryPathLeaf",
313
+ notesFields: [
314
+ {
315
+ id: "message",
316
+ label: "Revision notes",
317
+ placeholder: "Describe what the next implementation turn should improve",
318
+ required: true
319
+ }
320
+ ],
321
+ commentary: "Merge this implementation, request another pass, simplify it, or run an automated review.",
322
+ actions: {
323
+ [codingActionIds.finalizeChange]: {
324
+ label: config.finalizeLabel,
325
+ acceptanceState: "accepted",
326
+ form: config.finalizeForm,
327
+ schedulable: true,
328
+ to: turnIds.generateCommitMessage,
329
+ effect: ({ ctx }) => ({
330
+ state: patchRepositoryChangeState(ctx.state, {
331
+ finalization: createEmptyRepositoryChangeFinalizationState(),
332
+ clearReviewRefs: true,
333
+ clearProductRefs: [products.simplificationPlan]
334
+ })
335
+ })
336
+ },
337
+ [codingActionIds.requestRevision]: revisionAction({
338
+ label: "Request revision",
339
+ acceptanceState: "requires_changes",
340
+ form: requestRevisionForm,
341
+ schedulable: true,
342
+ to: turnIds.implement,
343
+ queueTarget: { semanticRef: "currentPrimaryPathLeaf" },
344
+ effect: ({ ctx }) => ({
345
+ state: clearReviewState(ctx.state)
346
+ })
347
+ }),
348
+ [codingActionIds.simplify]: {
349
+ label: "Simplify",
350
+ description: "Ask for a focused simplification review before another implementation pass.",
351
+ acceptanceState: "neutral",
352
+ schedulable: true,
353
+ to: turnIds.simplifyImplementation,
354
+ effect: ({ ctx }) => {
355
+ requireResolvedPlanRef(ctx.state.semanticEntryRefs.plan, "simplification review");
356
+ return { state: clearReviewState(ctx.state) };
357
+ }
358
+ },
359
+ [codingActionIds.runReview]: {
360
+ label: "Run automated review",
361
+ acceptanceState: "neutral",
362
+ schedulable: true,
363
+ to: turnIds.reviewImplementation,
364
+ effect: ({ ctx }) => {
365
+ requireResolvedPlanRef(ctx.state.semanticEntryRefs.plan, "implementation review");
366
+ return { state: clearReviewState(ctx.state) };
367
+ }
368
+ }
369
+ }
370
+ });
371
+ const implementationReviewFeedbackSpec = humanTurn({
372
+ description: "Review implementation feedback",
373
+ reviewSemanticRef: "review",
374
+ notesFields: [
375
+ {
376
+ id: "message",
377
+ label: "Review notes",
378
+ placeholder: "Describe how the next implementation review pass should change",
379
+ required: true
380
+ }
381
+ ],
382
+ commentary: "Apply this feedback to the next implementation pass, request a revised review, or dismiss it.",
383
+ actions: {
384
+ [codingActionIds.acceptReview]: acceptedReviewHandoffAction({
385
+ label: "Accept review",
386
+ acceptanceState: "accepted",
387
+ form: acceptReviewForm,
388
+ schedulable: true,
389
+ to: turnIds.implement,
390
+ queueTarget: { semanticRef: "review" },
391
+ resolveBodyMarkdown: ({ ctx, input }) => buildAcceptedFollowUpMessage({
392
+ kind: "implementation_review",
393
+ markdown: ctx.readSemanticTurnResultMarkdown("review"),
394
+ adjustment: input.message
395
+ }),
396
+ effect: ({ ctx }) => ({
397
+ state: patchRepositoryChangeState(ctx.state, {
398
+ clearProductRefs: [products.simplificationPlan]
399
+ })
400
+ })
401
+ }),
402
+ [codingActionIds.requestReviewChanges]: revisionAction({
403
+ label: "Request review changes",
404
+ acceptanceState: "requires_changes",
405
+ form: requestReviewChangesForm,
406
+ schedulable: true,
407
+ to: turnIds.reviewImplementation,
408
+ queueTarget: { semanticRef: "review" }
409
+ }),
410
+ [codingActionIds.dismissReview]: {
411
+ label: "Dismiss review",
412
+ acceptanceState: "neutral",
413
+ to: turnIds.implementationDecision
414
+ }
415
+ }
416
+ });
417
+ const simplificationDecisionSpec = humanTurn({
418
+ description: "Review simplification plan",
419
+ reviewProduct: products.simplificationPlan,
420
+ notesFields: [
421
+ {
422
+ id: "message",
423
+ label: "Simplification notes",
424
+ placeholder: "Describe how the simplification plan should change",
425
+ required: true
426
+ }
427
+ ],
428
+ commentary: "Apply this simplification plan, request changes to it, or reject it.",
429
+ actions: {
430
+ [codingActionIds.acceptReview]: acceptedReviewHandoffAction({
431
+ label: "Accept simplification plan",
432
+ acceptanceState: "accepted",
433
+ form: acceptReviewForm,
434
+ schedulable: true,
435
+ to: turnIds.implement,
436
+ queueTarget: { productName: products.simplificationPlan },
437
+ resolveBodyMarkdown: ({ ctx, input }) => 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: "Return to the implementation decision without applying the simplification plan.",
458
+ acceptanceState: "neutral",
459
+ to: turnIds.implementationDecision,
460
+ effect: ({ ctx }) => ({
461
+ state: clearReviewState(ctx.state)
462
+ })
463
+ }
464
+ }
465
+ });
466
+ const importPlanTurn = flow.automatic(turnIds.importPlan).description("Import handoff plan").run((ctx) => {
467
+ const planMarkdown = ctx.params.launchKind === "imported_plan" ? normalizeOptionalMarkdown(ctx.params.importedPlanMarkdown) : null;
468
+ if (!planMarkdown) {
469
+ throw new Error("No importedPlanMarkdown is available to import");
470
+ }
471
+ return {
472
+ outcome: "imported",
473
+ params: { plan: planMarkdown },
474
+ markdown: planMarkdown
475
+ };
476
+ }).outcome(
477
+ "imported",
478
+ (outcome) => outcome.description("Imported a handoff plan and skipped replanning").markdown("plan", { description: "Imported handoff plan", publish: true }).to(turnIds.implement).effect(({ ctx }) => ({
479
+ processPatch: { planRevision: ctx.process.planRevision + 1 },
480
+ state: clearReviewState(ctx.state)
481
+ }))
482
+ );
483
+ const generatePlanTurn = flow.llm(turnIds.generatePlan).description("Plan").tools("read", "bash").askQuestions().freshPrimary().buildPrompt(buildGeneratePlanPrompt).outcomeTool(
484
+ "plan_saved",
485
+ (tool) => tool.description(
486
+ "Save the finished plan for review. Its Markdown may include Mermaid diagrams or uploaded images."
487
+ ).requiredString("summary", "Short summary of the proposed plan").requiredStringArray(
488
+ "acceptanceCriteria",
489
+ "Acceptance criteria for the requested repository change"
490
+ ).to(turnIds.planDecision).effect(({ ctx, event }) => {
491
+ const planRevision = ctx.process.planRevision + 1;
492
+ const summary = normalizeMessage(event.params.summary);
493
+ const acceptanceCriteria = Array.isArray(event.params.acceptanceCriteria) ? event.params.acceptanceCriteria.filter(
494
+ (entry) => typeof entry === "string" && entry.trim() !== ""
495
+ ) : [];
496
+ const planMarkdown = ctx.output?.content ?? "";
497
+ return {
498
+ state: clearReviewState(ctx.state),
499
+ processPatch: { planRevision },
500
+ broadcasts: [
501
+ {
502
+ type: "plan.updated",
503
+ payload: {
504
+ planRevision,
505
+ reviewState: "awaiting_approval",
506
+ approved: false,
507
+ summary
508
+ }
509
+ }
510
+ ],
511
+ emit: [
512
+ {
513
+ type: "plan_saved",
514
+ data: {
515
+ planRevision,
516
+ summary,
517
+ planMarkdown,
518
+ acceptanceCriteria
519
+ }
520
+ }
521
+ ]
522
+ };
523
+ })
524
+ ).publish(products.plan);
525
+ const reviewPlanTurn = flow.llm(turnIds.reviewPlan).description("Assess Plan").tools("read", "bash").rootBranchReview().startFromReviewBranch().consume(products.plan).buildPrompt(buildReviewPlanPrompt).outcomeTool(
526
+ "no_issues",
527
+ (tool) => tool.description(
528
+ "Approve the plan and publish the review. Its Markdown may include Mermaid diagrams or uploaded images."
529
+ ).to(turnIds.planDecision)
530
+ ).outcomeTool(
531
+ "request_changes",
532
+ (tool) => tool.description(
533
+ "Request plan changes and publish actionable feedback. Its Markdown may include Mermaid diagrams or uploaded images."
534
+ ).to(turnIds.planReviewFeedback)
535
+ ).publish(products.review);
536
+ const implementTurn = flow.llm(turnIds.implement).description("Implement").tools(...implementationTurnAvailableTools).freshSeededPrimary().continueFromProductBranch(products.simplificationPlan, {
537
+ kind: "semantic_ref",
538
+ ref: "review",
539
+ fallback: { kind: "session_root" }
540
+ }).consume(products.plan).buildPrompt(buildImplementPrompt).publish(products.implementationSummary).to(turnIds.implementationDecision).state(({ ctx }) => clearReviewState(ctx.state));
541
+ const reviewImplementationTurn = flow.llm(turnIds.reviewImplementation).description("Assess Implementation").tools("read", "bash").rootBranchReview().startFromReviewBranch().buildPrompt(buildReviewImplementationPrompt).outcomeTool(
542
+ "no_issues",
543
+ (tool) => tool.description(
544
+ "Approve the implementation and publish the review. Its Markdown may include Mermaid diagrams or uploaded images."
545
+ ).to(turnIds.implementationDecision)
546
+ ).outcomeTool(
547
+ "request_changes",
548
+ (tool) => tool.description(
549
+ "Request implementation changes and publish actionable feedback. Its Markdown may include Mermaid diagrams or uploaded images."
550
+ ).to(turnIds.implementationReviewFeedback)
551
+ ).publish(products.review);
552
+ const simplifyImplementationTurn = flow.llm(turnIds.simplifyImplementation).description("Simplify").tools("read", "bash").rootBranchReview().startFromProductBranch(products.simplificationPlan).buildPrompt(buildSimplifyImplementationPrompt).publish(products.simplificationPlan).to(turnIds.simplificationDecision);
553
+ const generateCommitMessageTurn = flow.llm(turnIds.generateCommitMessage).description("Write Commit Message").modelPurpose("process_title_generation").rootBranchReview().startFromRoot().consume(products.plan).buildPrompt(buildGenerateCommitMessagePrompt).publish(products.commitMessage).to(config.publication?.entryTurnId ?? turnIds.commitAndMerge).state(
554
+ ({ ctx }) => patchRepositoryChangeState(ctx.state, {
555
+ finalization: {
556
+ ...ctx.state.finalization,
557
+ generatedCommitMessage: normalizeGeneratedCommitMessage(ctx.output?.content)
558
+ }
559
+ })
560
+ );
561
+ const commitAndMergeTurn = flow.automatic(turnIds.commitAndMerge).description(config.finalizationDescription).run(runDeterministicFinalization).outcome(
562
+ "merge_conflict",
563
+ (outcome) => outcome.description("Deterministic merge hit conflicts and needs conflict resolution").requiredString("headSha", "The current HEAD sha while the merge conflict is active").stringArray("conflictedFiles", "Conflicted files that need resolution").string("fetchedBaseSha", "The fetched origin/<baseBranch> sha when available").to(turnIds.resolveMergeConflict).state(
564
+ ({ ctx }) => patchRepositoryChangeState(ctx.state, {
565
+ finalization: resetFinalizationAfterMessage(ctx.state)
566
+ })
567
+ )
568
+ ).outcome(
569
+ "finalized",
570
+ (outcome) => outcome.description("Deterministic finalization succeeded").requiredString("headSha", "The final HEAD sha").requiredString("mergeMode", "How origin/<baseBranch> was integrated").requiredString("pushTarget", "The final base-branch publish target").requiredBoolean("usedConflictResolution", "Whether the merge required conflict resolution").complete().state(
571
+ ({ ctx, event }) => patchRepositoryChangeState(ctx.state, {
572
+ finalization: resetFinalizationAfterMessage(ctx.state, {
573
+ usedConflictResolution: event.params.usedConflictResolution === true || ctx.state.finalization.usedConflictResolution,
574
+ finalizationSummaryMarkdown: normalizeOptionalMarkdown(ctx.output?.content),
575
+ finalizedHeadSha: normalizeMessage(event.params.headSha)
576
+ })
577
+ })
578
+ )
579
+ );
580
+ const resolveMergeConflictTurn = flow.llm(turnIds.resolveMergeConflict).description("Resolve merge conflict").tools("read", "bash", "edit", "write").fullPrimary().startFromRoot().buildPrompt(buildResolveMergeConflictPrompt).outcomeTool(
581
+ "clean",
582
+ (tool) => tool.description("The merge conflict was resolved and the repository is clean").requiredString("headSha", "The post-resolution HEAD sha").to(turnIds.commitAndMerge).state(
583
+ ({ ctx, event }) => patchRepositoryChangeState(ctx.state, {
584
+ finalization: resetFinalizationAfterMessage(ctx.state, {
585
+ expectedPostConflictHeadSha: normalizeMessage(event.params.headSha),
586
+ usedConflictResolution: true
587
+ })
588
+ })
589
+ )
590
+ ).publish(products.mergeResolutionSummary);
591
+ const planFlow = flow.fragment("plan").turn(importPlanTurn).turn(generatePlanTurn).turn({ id: turnIds.planDecision, definition: planDecisionSpec }).turn(reviewPlanTurn).turn({ id: turnIds.planReviewFeedback, definition: planReviewFeedbackSpec });
592
+ const implementationFlow = flow.fragment("implementation").turn(implementTurn).turn({ id: turnIds.implementationDecision, definition: implementationDecisionSpec }).turn(reviewImplementationTurn).turn({
593
+ id: turnIds.implementationReviewFeedback,
594
+ definition: implementationReviewFeedbackSpec
595
+ }).turn(simplifyImplementationTurn).turn({ id: turnIds.simplificationDecision, definition: simplificationDecisionSpec });
596
+ const finalizationFlow = flow.fragment("finalization").turn(generateCommitMessageTurn);
597
+ if (!config.publication) {
598
+ finalizationFlow.turn(commitAndMergeTurn).turn(resolveMergeConflictTurn);
599
+ }
600
+ const builder = flow.process(config.processId).displayName(config.displayName).entry(turnIds.generatePlan).alternateEntry(turnIds.importPlan).happyPath(
601
+ turnIds.generatePlan,
602
+ turnIds.implement,
603
+ turnIds.generateCommitMessage,
604
+ ...config.publication?.happyPath ?? [turnIds.commitAndMerge]
605
+ ).piConfig({ sessionCwdTemplate: "{{{projectKey}}}" }).codecs({
606
+ params: config.paramsCodec,
607
+ state: repositoryChangeStateCodec
608
+ }).initialState(() => ({
609
+ ...createEmptyStructuralProcessState(),
610
+ finalization: createEmptyRepositoryChangeFinalizationState(),
611
+ extensionState: {}
612
+ })).use(planFlow).use(implementationFlow).use(finalizationFlow);
613
+ if (config.publication) builder.use(config.publication.fragment);
614
+ if (config.repositoryCredentials) builder.repositoryCredentials(config.repositoryCredentials);
615
+ if (config.launcher) builder.launcher(config.launcher);
616
+ const process = builder.define();
617
+ const decision = (id) => ({
618
+ id,
619
+ ...process.turns.get(id)?.definition
620
+ });
621
+ return {
622
+ /** @public */
623
+ process,
624
+ /** @internal */
625
+ planDecision: decision(turnIds.planDecision),
626
+ /** @internal */
627
+ planReviewFeedback: decision(turnIds.planReviewFeedback),
628
+ /** @internal */
629
+ implementationDecision: decision(turnIds.implementationDecision),
630
+ /** @internal */
631
+ implementationReviewFeedback: decision(turnIds.implementationReviewFeedback),
632
+ /** @internal */
633
+ simplificationDecision: decision(turnIds.simplificationDecision)
634
+ };
635
+ }
636
+
637
+ // src/index.ts
638
+ var manifest = {
639
+ /** @internal */
640
+ id: "coding",
641
+ /** @internal */
642
+ version: "0.1.0"
643
+ };
644
+ var extension = { manifest };
645
+ var index_default = extension;
646
+ export {
647
+ acceptReviewForm,
648
+ codingActionIds,
649
+ createFinalizeChangeForm,
650
+ createRepositoryChangeProcess,
651
+ index_default as default,
652
+ requestReviewChangesForm,
653
+ requestRevisionForm
654
+ };
7
655
  //# sourceMappingURL=index.js.map