@leitwerk-dev/coding 0.1.2 → 0.1.4

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 (57) hide show
  1. package/dist/actions.d.ts +18 -0
  2. package/dist/actions.d.ts.map +1 -0
  3. package/dist/actions.js +45 -0
  4. package/dist/actions.js.map +1 -0
  5. package/dist/auto-work-branch.d.ts +10 -11
  6. package/dist/auto-work-branch.d.ts.map +1 -0
  7. package/dist/auto-work-branch.js +90 -90
  8. package/dist/auto-work-branch.js.map +1 -1
  9. package/dist/finalization-git.d.ts +9 -11
  10. package/dist/finalization-git.d.ts.map +1 -0
  11. package/dist/finalization-git.js +532 -11
  12. package/dist/finalization-git.js.map +1 -1
  13. package/dist/index.d.ts +7 -61
  14. package/dist/index.d.ts.map +1 -0
  15. package/dist/index.js +6 -785
  16. package/dist/index.js.map +1 -1
  17. package/dist/repository-change-launch.d.ts +15 -17
  18. package/dist/repository-change-launch.d.ts.map +1 -0
  19. package/dist/repository-change-launch.js +182 -17
  20. package/dist/repository-change-launch.js.map +1 -1
  21. package/dist/repository-change-process.d.ts +38 -0
  22. package/dist/repository-change-process.d.ts.map +1 -0
  23. package/dist/repository-change-process.js +751 -0
  24. package/dist/repository-change-process.js.map +1 -0
  25. package/dist/repository-change-state.d.ts +8 -10
  26. package/dist/repository-change-state.d.ts.map +1 -0
  27. package/dist/repository-change-state.js +50 -12
  28. package/dist/repository-change-state.js.map +1 -1
  29. package/dist/turns/generate-commit-message.d.ts +4 -6
  30. package/dist/turns/generate-commit-message.d.ts.map +1 -0
  31. package/dist/turns/generate-commit-message.js +38 -9
  32. package/dist/turns/generate-commit-message.js.map +1 -1
  33. package/dist/turns/generate-plan.d.ts +3 -5
  34. package/dist/turns/generate-plan.d.ts.map +1 -0
  35. package/dist/turns/generate-plan.js +19 -7
  36. package/dist/turns/generate-plan.js.map +1 -1
  37. package/dist/turns/implement.d.ts +3 -5
  38. package/dist/turns/implement.d.ts.map +1 -0
  39. package/dist/turns/implement.js +17 -7
  40. package/dist/turns/implement.js.map +1 -1
  41. package/dist/turns/resolve-merge-conflict.d.ts +3 -5
  42. package/dist/turns/resolve-merge-conflict.d.ts.map +1 -0
  43. package/dist/turns/resolve-merge-conflict.js +21 -7
  44. package/dist/turns/resolve-merge-conflict.js.map +1 -1
  45. package/dist/turns/review-implementation.d.ts +4 -7
  46. package/dist/turns/review-implementation.d.ts.map +1 -0
  47. package/dist/turns/review-implementation.js +27 -9
  48. package/dist/turns/review-implementation.js.map +1 -1
  49. package/dist/turns/review-plan.d.ts +4 -7
  50. package/dist/turns/review-plan.d.ts.map +1 -0
  51. package/dist/turns/review-plan.js +21 -9
  52. package/dist/turns/review-plan.js.map +1 -1
  53. package/dist/turns/simplify-implementation.d.ts +3 -5
  54. package/dist/turns/simplify-implementation.d.ts.map +1 -0
  55. package/dist/turns/simplify-implementation.js +7 -7
  56. package/dist/turns/simplify-implementation.js.map +1 -1
  57. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -1,786 +1,7 @@
1
- import {
2
- buildImplementPrompt
3
- } from "./chunk-UBVLJV3V.js";
4
- import {
5
- buildResolveMergeConflictPrompt
6
- } from "./chunk-5LVPKVI2.js";
7
- import {
8
- buildReviewImplementationPrompt
9
- } from "./chunk-RWCLBBB2.js";
10
- import {
11
- buildReviewPlanPrompt
12
- } from "./chunk-RZ54IVY5.js";
13
- import {
14
- buildSimplifyImplementationPrompt
15
- } from "./chunk-OFDNIT5X.js";
16
- import {
17
- runDeterministicFinalization
18
- } from "./chunk-JZU3UVR6.js";
19
- import {
20
- createRepositoryChangeLaunchPlanner,
21
- createRepositoryChangeParamsCodec,
22
- createRepositoryChangeUiLauncher,
23
- formatRepositoryChangeLaunchErrors,
24
- normalizeRepositoryChangeParamsInput,
25
- repositoryChangeParamsRecord
26
- } from "./chunk-Y2S6JFVO.js";
27
- import {
28
- clearReviewRefs,
29
- createEmptyRepositoryChangeFinalizationState,
30
- repositoryChangeStateCodec,
31
- resetRepositoryChangeFinalizationState
32
- } from "./chunk-DSQX3ZHJ.js";
33
- import {
34
- buildGenerateCommitMessagePrompt,
35
- normalizeGeneratedCommitMessage
36
- } from "./chunk-NIJCT4VK.js";
37
- import {
38
- buildGeneratePlanPrompt
39
- } from "./chunk-67YKGZLM.js";
40
- import "./chunk-PX6F3LHL.js";
41
-
42
- // src/actions.ts
43
- var codingActionIds = {
44
- approvePlan: "approve_plan",
45
- requestRevision: "request_revision",
46
- runReview: "run_review",
47
- simplify: "simplify",
48
- acceptReview: "accept_review",
49
- requestReviewChanges: "request_review_changes",
50
- dismissReview: "dismiss_review",
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 { createReviewSubject, 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 planReviewSubject = createReviewSubject("plan");
109
- const implementationReviewSubject = createReviewSubject("implementation");
110
- const turnIds = {
111
- importPlan: "import_plan",
112
- generatePlan: "generate_plan",
113
- planDecision: "plan_decision",
114
- reviewPlan: "review_plan",
115
- planReviewFeedback: "plan_review_feedback",
116
- implement: "implement",
117
- implementationDecision: "implementation_decision",
118
- reviewImplementation: "review_implementation",
119
- implementationReviewFeedback: "implementation_review_feedback",
120
- simplifyImplementation: "simplify_implementation",
121
- simplificationDecision: "simplification_decision",
122
- generateCommitMessage: "generate_commit_message",
123
- commitAndMerge: "commit_and_merge",
124
- resolveMergeConflict: "resolve_merge_conflict"
125
- };
126
- const products = {
127
- plan: "plan",
128
- review: "review",
129
- simplificationPlan: "simplification-plan",
130
- implementationSummary: "implementation-summary",
131
- mergeResolutionSummary: "merge-resolution-summary",
132
- commitMessage: "commit-message"
133
- };
134
- const implementationTurnAvailableTools = ["read", "bash", "edit", "write"];
135
- function normalizeMessage(value) {
136
- return typeof value === "string" ? value.trim() : "";
137
- }
138
- function resetFinalizationAfterMessage(state, overrides = {}) {
139
- return resetRepositoryChangeFinalizationState({
140
- generatedCommitMessage: state.finalization.generatedCommitMessage,
141
- ...overrides
142
- });
143
- }
144
- function hasResolvedTurnRecordRef(ref) {
145
- return typeof ref?.turnRecordId === "string" && ref.turnRecordId.trim() !== "";
146
- }
147
- function requireResolvedPlanRef(plan, usage) {
148
- if (!hasResolvedTurnRecordRef(plan)) {
149
- throw new Error(`No plan is available for ${usage}`);
150
- }
151
- }
152
- function buildImplementationReviewTurnState(ctx) {
153
- return patchRepositoryChangeState(ctx.state, {
154
- reviewSubject: implementationReviewSubject,
155
- clearReviewRefs: true,
156
- clearProductRefs: [products.simplificationPlan]
157
- });
158
- }
159
- function buildAcceptedReviewFollowUpMessage(input) {
160
- const adjustment = normalizeMessage(input.adjustment);
161
- if (input.reviewSubject.kind === "plan") {
162
- return [
163
- "Revise the plan according to this review:",
164
- input.reviewMarkdown,
165
- adjustment ? ["Also follow this adjustment where it conflicts with the review:", adjustment].join(
166
- "\n\n"
167
- ) : null
168
- ].filter((section) => typeof section === "string" && section !== "").join("\n\n");
169
- }
170
- return buildAcceptedImplementationFollowUpMessage({
171
- kind: "review",
172
- implementationMarkdown: input.reviewMarkdown,
173
- adjustment
174
- });
175
- }
176
- function buildAcceptedImplementationFollowUpMessage(input) {
177
- const adjustment = normalizeMessage(input.adjustment);
178
- const isSimplification = input.kind === "simplification";
179
- const subject = isSimplification ? "simplification plan" : "review";
180
- return [
181
- `Implement according to this ${subject}:`,
182
- input.implementationMarkdown,
183
- adjustment ? [`Also follow this adjustment where it conflicts with the ${subject}:`, adjustment].join(
184
- "\n\n"
185
- ) : null,
186
- [
187
- "This is now an implementation turn. Ignore earlier review-only or read-only instructions.",
188
- "You may change files in the repository workspace.",
189
- `Use the available tools (${implementationTurnAvailableTools.join(", ")}) to inspect, edit, build, and test the change.`,
190
- "When finished, return an implementation summary."
191
- ].join("\n")
192
- ].filter((section) => typeof section === "string" && section !== "").join("\n\n");
193
- }
194
- function buildAcceptedSimplificationFollowUpMessage(input) {
195
- return buildAcceptedImplementationFollowUpMessage({
196
- kind: "simplification",
197
- implementationMarkdown: input.simplificationMarkdown,
198
- adjustment: input.adjustment
199
- });
200
- }
201
- function patchRepositoryChangeState(state, input) {
202
- const nextState = {
203
- ...state,
204
- ..."reviewSubject" in input ? { reviewSubject: input.reviewSubject ?? null } : {},
205
- ..."finalization" in input ? { finalization: input.finalization } : {},
206
- ..."semanticEntryRefs" in input ? { semanticEntryRefs: input.semanticEntryRefs } : {}
207
- };
208
- const productRefsToClear = new Set(input.clearProductRefs ?? []);
209
- if (input.clearReviewRefs) {
210
- productRefsToClear.add(products.review);
211
- }
212
- if (!input.clearReviewRefs && productRefsToClear.size === 0) {
213
- return nextState;
214
- }
215
- const productRefs = { ...nextState.productRefs };
216
- for (const productName of productRefsToClear) {
217
- delete productRefs[productName];
218
- }
219
- return {
220
- ...nextState,
221
- semanticEntryRefs: input.clearReviewRefs ? clearReviewRefs(nextState.semanticEntryRefs) : nextState.semanticEntryRefs,
222
- productRefs
223
- };
224
- }
225
- const planDecisionSpec = humanTurn({
226
- description: "Review plan",
227
- reviewSubject: planReviewSubject,
228
- reviewSemanticRef: "plan",
229
- notesFields: [
230
- {
231
- id: "message",
232
- label: "Revision notes",
233
- placeholder: "Describe what the next plan revision should improve",
234
- required: true
235
- }
236
- ],
237
- commentary: "Approve this plan, request a revision, or run an automated review.",
238
- actions: {
239
- [codingActionIds.approvePlan]: {
240
- label: "Approve plan",
241
- description: "Accept the current plan and continue into implementation.",
242
- acceptanceState: "accepted",
243
- to: turnIds.implement,
244
- effect: ({ ctx }) => {
245
- const plan = ctx.state.semanticEntryRefs.plan;
246
- if (!hasResolvedTurnRecordRef(plan)) {
247
- throw new Error("No plan is available for approval");
248
- }
249
- return {
250
- state: patchRepositoryChangeState(ctx.state, {
251
- reviewSubject: null,
252
- clearReviewRefs: true,
253
- clearProductRefs: [products.simplificationPlan]
254
- }),
255
- emit: [
256
- {
257
- type: "plan_approved",
258
- data: {
259
- externalId: ctx.process.externalId,
260
- planRevision: ctx.process.planRevision
261
- }
262
- }
263
- ]
264
- };
265
- }
266
- },
267
- [codingActionIds.requestRevision]: revisionAction({
268
- label: "Request revision",
269
- description: "Send the plan back for another draft revision.",
270
- acceptanceState: "requires_changes",
271
- form: requestRevisionForm,
272
- schedulable: true,
273
- to: turnIds.generatePlan,
274
- queueTarget: { semanticRef: "currentPrimaryPathLeaf" },
275
- effect: ({ ctx, input }) => {
276
- const message = normalizeMessage(input.message);
277
- return {
278
- state: patchRepositoryChangeState(ctx.state, {
279
- reviewSubject: null,
280
- clearReviewRefs: true,
281
- clearProductRefs: [products.simplificationPlan]
282
- }),
283
- emit: [{ type: "plan_revision_requested", data: { message } }]
284
- };
285
- }
286
- }),
287
- [codingActionIds.runReview]: {
288
- label: "Run automated review",
289
- description: "Send the current plan to the LLM reviewer.",
290
- acceptanceState: "neutral",
291
- schedulable: true,
292
- to: turnIds.reviewPlan,
293
- effect: ({ ctx }) => {
294
- const plan = ctx.state.semanticEntryRefs.plan;
295
- if (!hasResolvedTurnRecordRef(plan)) {
296
- throw new Error("No plan is available for review");
297
- }
298
- return {
299
- state: patchRepositoryChangeState(ctx.state, {
300
- reviewSubject: planReviewSubject,
301
- clearReviewRefs: true,
302
- clearProductRefs: [products.simplificationPlan]
303
- })
304
- };
305
- }
306
- }
307
- }
308
- });
309
- const planReviewFeedbackSpec = humanTurn({
310
- description: "Review plan feedback",
311
- reviewSubject: planReviewSubject,
312
- reviewSemanticRef: "review",
313
- notesFields: [
314
- {
315
- id: "message",
316
- label: "Review notes",
317
- placeholder: "Describe how the next review pass should change",
318
- required: true
319
- }
320
- ],
321
- commentary: "Apply this feedback to the next plan revision, request a revised review, or dismiss it.",
322
- actions: {
323
- [codingActionIds.acceptReview]: acceptedReviewHandoffAction({
324
- label: "Accept review",
325
- description: "Apply the current review outcome and continue with the plan flow.",
326
- acceptanceState: "accepted",
327
- form: acceptReviewForm,
328
- to: turnIds.generatePlan,
329
- resolveBodyMarkdown: ({ ctx, input }) => {
330
- const reviewMarkdown = normalizeOptionalMarkdown(
331
- ctx.readSemanticTurnResultMarkdown("review")
332
- );
333
- if (!reviewMarkdown) {
334
- throw new Error("No review output markdown is available to accept");
335
- }
336
- return buildAcceptedReviewFollowUpMessage({
337
- reviewSubject: planReviewSubject,
338
- reviewMarkdown,
339
- adjustment: normalizeMessage(input.message)
340
- });
341
- },
342
- effect: ({ ctx }) => ({
343
- state: patchRepositoryChangeState(ctx.state, {
344
- reviewSubject: null
345
- })
346
- })
347
- }),
348
- [codingActionIds.requestReviewChanges]: revisionAction({
349
- label: "Request review changes",
350
- description: "Ask the LLM reviewer to revise its plan review.",
351
- acceptanceState: "requires_changes",
352
- form: requestReviewChangesForm,
353
- to: turnIds.reviewPlan,
354
- queueTarget: { semanticRef: "review" },
355
- effect: ({ ctx }) => ({
356
- state: patchRepositoryChangeState(ctx.state, {
357
- reviewSubject: planReviewSubject
358
- })
359
- })
360
- }),
361
- [codingActionIds.dismissReview]: {
362
- label: "Dismiss review",
363
- description: "Return to the plan decision without applying the review.",
364
- acceptanceState: "neutral",
365
- to: turnIds.planDecision,
366
- effect: ({ ctx }) => ({
367
- state: patchRepositoryChangeState(ctx.state, {
368
- reviewSubject: planReviewSubject
369
- })
370
- })
371
- }
372
- }
373
- });
374
- const implementationDecisionSpec = humanTurn({
375
- description: "Review implementation",
376
- reviewSubject: implementationReviewSubject,
377
- reviewSemanticRef: "currentPrimaryPathLeaf",
378
- notesFields: [
379
- {
380
- id: "message",
381
- label: "Revision notes",
382
- placeholder: "Describe what the next implementation turn should improve",
383
- required: true
384
- }
385
- ],
386
- commentary: "Merge this implementation, request another pass, simplify it, or run an automated review.",
387
- actions: {
388
- [codingActionIds.finalizeChange]: {
389
- label: config.finalizeLabel,
390
- acceptanceState: "accepted",
391
- form: config.finalizeForm,
392
- schedulable: true,
393
- to: turnIds.generateCommitMessage,
394
- effect: ({ ctx }) => ({
395
- state: patchRepositoryChangeState(ctx.state, {
396
- reviewSubject: null,
397
- finalization: createEmptyRepositoryChangeFinalizationState(),
398
- clearReviewRefs: true,
399
- clearProductRefs: [products.simplificationPlan]
400
- })
401
- })
402
- },
403
- [codingActionIds.requestRevision]: revisionAction({
404
- label: "Request revision",
405
- acceptanceState: "requires_changes",
406
- form: requestRevisionForm,
407
- schedulable: true,
408
- to: turnIds.implement,
409
- queueTarget: { semanticRef: "currentPrimaryPathLeaf" },
410
- effect: ({ ctx }) => ({
411
- state: patchRepositoryChangeState(ctx.state, {
412
- reviewSubject: null,
413
- clearReviewRefs: true,
414
- clearProductRefs: [products.simplificationPlan]
415
- })
416
- })
417
- }),
418
- [codingActionIds.simplify]: {
419
- label: "Simplify",
420
- description: "Ask for a focused simplification review before another implementation pass.",
421
- acceptanceState: "neutral",
422
- schedulable: true,
423
- to: turnIds.simplifyImplementation,
424
- effect: ({ ctx }) => {
425
- requireResolvedPlanRef(ctx.state.semanticEntryRefs.plan, "simplification review");
426
- return { state: buildImplementationReviewTurnState(ctx) };
427
- }
428
- },
429
- [codingActionIds.runReview]: {
430
- label: "Run automated review",
431
- acceptanceState: "neutral",
432
- schedulable: true,
433
- to: turnIds.reviewImplementation,
434
- effect: ({ ctx }) => {
435
- requireResolvedPlanRef(ctx.state.semanticEntryRefs.plan, "implementation review");
436
- return { state: buildImplementationReviewTurnState(ctx) };
437
- }
438
- }
439
- }
440
- });
441
- const implementationReviewFeedbackSpec = humanTurn({
442
- description: "Review implementation feedback",
443
- reviewSubject: implementationReviewSubject,
444
- reviewSemanticRef: "review",
445
- notesFields: [
446
- {
447
- id: "message",
448
- label: "Review notes",
449
- placeholder: "Describe how the next implementation review pass should change",
450
- required: true
451
- }
452
- ],
453
- commentary: "Apply this feedback to the next implementation pass, request a revised review, or dismiss it.",
454
- actions: {
455
- [codingActionIds.acceptReview]: acceptedReviewHandoffAction({
456
- label: "Accept review",
457
- acceptanceState: "accepted",
458
- form: acceptReviewForm,
459
- schedulable: true,
460
- to: turnIds.implement,
461
- queueTarget: { semanticRef: "review" },
462
- resolveBodyMarkdown: ({ ctx, input }) => {
463
- const reviewMarkdown = normalizeOptionalMarkdown(
464
- ctx.readSemanticTurnResultMarkdown("review")
465
- );
466
- if (!reviewMarkdown) {
467
- throw new Error("No review output markdown is available to accept");
468
- }
469
- return buildAcceptedReviewFollowUpMessage({
470
- reviewSubject: implementationReviewSubject,
471
- reviewMarkdown,
472
- adjustment: normalizeMessage(input.message)
473
- });
474
- },
475
- effect: ({ ctx }) => ({
476
- state: patchRepositoryChangeState(ctx.state, {
477
- reviewSubject: null,
478
- clearProductRefs: [products.simplificationPlan]
479
- })
480
- })
481
- }),
482
- [codingActionIds.requestReviewChanges]: revisionAction({
483
- label: "Request review changes",
484
- acceptanceState: "requires_changes",
485
- form: requestReviewChangesForm,
486
- schedulable: true,
487
- to: turnIds.reviewImplementation,
488
- queueTarget: { semanticRef: "review" },
489
- effect: ({ ctx }) => ({
490
- state: patchRepositoryChangeState(ctx.state, {
491
- reviewSubject: implementationReviewSubject
492
- })
493
- })
494
- }),
495
- [codingActionIds.dismissReview]: {
496
- label: "Dismiss review",
497
- acceptanceState: "neutral",
498
- to: turnIds.implementationDecision,
499
- effect: ({ ctx }) => ({
500
- state: patchRepositoryChangeState(ctx.state, {
501
- reviewSubject: implementationReviewSubject
502
- })
503
- })
504
- }
505
- }
506
- });
507
- const simplificationDecisionSpec = humanTurn({
508
- description: "Review simplification plan",
509
- reviewSubject: implementationReviewSubject,
510
- reviewProduct: products.simplificationPlan,
511
- notesFields: [
512
- {
513
- id: "message",
514
- label: "Simplification notes",
515
- placeholder: "Describe how the simplification plan should change",
516
- required: true
517
- }
518
- ],
519
- commentary: "Apply this simplification plan, request changes to it, or reject it.",
520
- actions: {
521
- [codingActionIds.acceptReview]: acceptedReviewHandoffAction({
522
- label: "Accept simplification plan",
523
- acceptanceState: "accepted",
524
- form: acceptReviewForm,
525
- schedulable: true,
526
- to: turnIds.implement,
527
- queueTarget: { productName: products.simplificationPlan },
528
- resolveBodyMarkdown: ({ ctx, input }) => {
529
- const simplificationMarkdown = normalizeOptionalMarkdown(
530
- ctx.readProductTurnResultMarkdown(products.simplificationPlan)
531
- );
532
- if (!simplificationMarkdown) {
533
- throw new Error("No simplification plan markdown is available to accept");
534
- }
535
- return buildAcceptedSimplificationFollowUpMessage({
536
- simplificationMarkdown,
537
- adjustment: normalizeMessage(input.message)
538
- });
539
- },
540
- effect: ({ ctx }) => ({
541
- state: patchRepositoryChangeState(ctx.state, {
542
- reviewSubject: null,
543
- clearReviewRefs: true
544
- })
545
- })
546
- }),
547
- [codingActionIds.requestReviewChanges]: revisionAction({
548
- label: "Request simplification changes",
549
- acceptanceState: "requires_changes",
550
- form: requestReviewChangesForm,
551
- to: turnIds.simplifyImplementation,
552
- queueTarget: { productName: products.simplificationPlan },
553
- effect: ({ ctx }) => ({
554
- state: patchRepositoryChangeState(ctx.state, {
555
- reviewSubject: implementationReviewSubject
556
- })
557
- })
558
- }),
559
- [codingActionIds.dismissReview]: {
560
- label: "Reject simplification plan",
561
- description: "Return to the implementation decision without applying the simplification plan.",
562
- acceptanceState: "neutral",
563
- to: turnIds.implementationDecision,
564
- effect: ({ ctx }) => ({
565
- state: patchRepositoryChangeState(ctx.state, {
566
- reviewSubject: implementationReviewSubject,
567
- clearReviewRefs: true,
568
- clearProductRefs: [products.simplificationPlan]
569
- })
570
- })
571
- }
572
- }
573
- });
574
- const importPlanTurn = flow.serverAutomatic(turnIds.importPlan).description("Import handoff plan").run((ctx) => {
575
- const planMarkdown = ctx.params.launchKind === "imported_plan" ? normalizeOptionalMarkdown(ctx.params.importedPlanMarkdown) : null;
576
- if (!planMarkdown) {
577
- throw new Error("No importedPlanMarkdown is available to import");
578
- }
579
- return {
580
- outcome: "imported",
581
- params: { plan: planMarkdown },
582
- markdown: planMarkdown,
583
- state: patchRepositoryChangeState(ctx.state, {
584
- reviewSubject: null,
585
- clearReviewRefs: true,
586
- clearProductRefs: [products.simplificationPlan]
587
- })
588
- };
589
- }).outcome(
590
- "imported",
591
- (outcome) => outcome.description("Imported a handoff plan and skipped replanning").markdown("plan", { description: "Imported handoff plan", publish: true }).to(turnIds.implement).effect(({ ctx }) => ({ processPatch: { planRevision: ctx.process.planRevision + 1 } }))
592
- );
593
- const generatePlanTurn = flow.llm(turnIds.generatePlan).description("Draft plan").tools("read", "bash").askQuestions().freshPrimary().buildPrompt(buildGeneratePlanPrompt).outcomeTool(
594
- "plan_saved",
595
- (tool) => tool.description(
596
- "Save the finished plan for review. Its Markdown may include Mermaid diagrams or uploaded images."
597
- ).requiredString("summary", "Short summary of the proposed plan").requiredStringArray(
598
- "acceptanceCriteria",
599
- "Acceptance criteria for the requested repository change"
600
- ).to(turnIds.planDecision).effect(({ ctx, event }) => {
601
- const planRevision = ctx.process.planRevision + 1;
602
- const summary = normalizeMessage(event.params.summary);
603
- const acceptanceCriteria = Array.isArray(event.params.acceptanceCriteria) ? event.params.acceptanceCriteria.filter(
604
- (entry) => typeof entry === "string" && entry.trim() !== ""
605
- ) : [];
606
- const planMarkdown = ctx.output?.content ?? "";
607
- return {
608
- state: patchRepositoryChangeState(ctx.state, {
609
- reviewSubject: planReviewSubject,
610
- clearReviewRefs: true,
611
- clearProductRefs: [products.simplificationPlan]
612
- }),
613
- processPatch: { planRevision },
614
- broadcasts: [
615
- {
616
- type: "plan.updated",
617
- payload: {
618
- planRevision,
619
- reviewState: "awaiting_approval",
620
- approved: false,
621
- summary
622
- }
623
- }
624
- ],
625
- emit: [
626
- {
627
- type: "plan_saved",
628
- data: {
629
- planRevision,
630
- summary,
631
- planMarkdown,
632
- acceptanceCriteria
633
- }
634
- }
635
- ]
636
- };
637
- })
638
- ).publish(products.plan);
639
- const reviewPlanTurn = flow.llm(turnIds.reviewPlan).description("Review plan").tools("read", "bash").rootBranchReview().startFromReviewBranch().reviews(planReviewSubject).consume(products.plan).buildPrompt(buildReviewPlanPrompt).outcomeTool(
640
- "no_issues",
641
- (tool) => tool.description(
642
- "Approve the plan and publish the review. Its Markdown may include Mermaid diagrams or uploaded images."
643
- ).to(turnIds.planDecision).state(
644
- ({ ctx }) => patchRepositoryChangeState(ctx.state, {
645
- reviewSubject: planReviewSubject
646
- })
647
- )
648
- ).outcomeTool(
649
- "request_changes",
650
- (tool) => tool.description(
651
- "Request plan changes and publish actionable feedback. Its Markdown may include Mermaid diagrams or uploaded images."
652
- ).to(turnIds.planReviewFeedback).state(
653
- ({ ctx }) => patchRepositoryChangeState(ctx.state, {
654
- reviewSubject: planReviewSubject
655
- })
656
- )
657
- ).publish(products.review);
658
- const implementTurn = flow.llm(turnIds.implement).description("Implement change").tools(...implementationTurnAvailableTools).freshSeededPrimary().continueFromProductBranch(products.simplificationPlan, {
659
- kind: "semantic_ref",
660
- ref: "review",
661
- fallback: { kind: "session_root" }
662
- }).consume(products.plan).buildPrompt(buildImplementPrompt).publish(products.implementationSummary).to(turnIds.implementationDecision).state(
663
- ({ ctx }) => patchRepositoryChangeState(ctx.state, {
664
- reviewSubject: implementationReviewSubject,
665
- clearReviewRefs: true,
666
- clearProductRefs: [products.simplificationPlan]
667
- })
668
- );
669
- const reviewImplementationTurn = flow.llm(turnIds.reviewImplementation).description("Review implementation").tools("read", "bash").rootBranchReview().startFromReviewBranch().reviews(implementationReviewSubject).buildPrompt(buildReviewImplementationPrompt).outcomeTool(
670
- "no_issues",
671
- (tool) => tool.description(
672
- "Approve the implementation and publish the review. Its Markdown may include Mermaid diagrams or uploaded images."
673
- ).to(turnIds.implementationDecision).state(
674
- ({ ctx }) => patchRepositoryChangeState(ctx.state, {
675
- reviewSubject: implementationReviewSubject
676
- })
677
- )
678
- ).outcomeTool(
679
- "request_changes",
680
- (tool) => tool.description(
681
- "Request implementation changes and publish actionable feedback. Its Markdown may include Mermaid diagrams or uploaded images."
682
- ).to(turnIds.implementationReviewFeedback).state(
683
- ({ ctx }) => patchRepositoryChangeState(ctx.state, {
684
- reviewSubject: implementationReviewSubject
685
- })
686
- )
687
- ).publish(products.review);
688
- const simplifyImplementationTurn = flow.llm(turnIds.simplifyImplementation).description("Simplify implementation").tools("read", "bash").rootBranchReview().startFromProductBranch(products.simplificationPlan).buildPrompt(buildSimplifyImplementationPrompt).publish(products.simplificationPlan).to(turnIds.simplificationDecision).state(
689
- ({ ctx }) => patchRepositoryChangeState(ctx.state, {
690
- reviewSubject: implementationReviewSubject
691
- })
692
- );
693
- const generateCommitMessageTurn = flow.llm(turnIds.generateCommitMessage).description("Generate commit message").modelPurpose("process_title_generation").rootBranchReview().startFromRoot().consume(products.plan).buildPrompt(buildGenerateCommitMessagePrompt).publish(products.commitMessage).to(turnIds.commitAndMerge).state(
694
- ({ ctx }) => patchRepositoryChangeState(ctx.state, {
695
- finalization: {
696
- ...ctx.state.finalization,
697
- generatedCommitMessage: normalizeGeneratedCommitMessage(ctx.output?.content)
698
- }
699
- })
700
- );
701
- const commitAndMergeTurn = flow.automatic(turnIds.commitAndMerge).description(config.finalizationDescription).run(runDeterministicFinalization).outcome(
702
- "merge_conflict",
703
- (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(
704
- ({ ctx }) => patchRepositoryChangeState(ctx.state, {
705
- finalization: resetFinalizationAfterMessage(ctx.state)
706
- })
707
- )
708
- ).outcome(
709
- "finalized",
710
- (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(
711
- ({ ctx, event }) => patchRepositoryChangeState(ctx.state, {
712
- reviewSubject: null,
713
- finalization: resetFinalizationAfterMessage(ctx.state, {
714
- usedConflictResolution: event.params.usedConflictResolution === true || ctx.state.finalization.usedConflictResolution,
715
- finalizationSummaryMarkdown: normalizeOptionalMarkdown(ctx.output?.content),
716
- finalizedHeadSha: normalizeMessage(event.params.headSha)
717
- })
718
- })
719
- )
720
- );
721
- const resolveMergeConflictTurn = flow.llm(turnIds.resolveMergeConflict).description("Resolve merge conflict").tools("read", "bash", "edit", "write").fullPrimary().startFromRoot().buildPrompt(buildResolveMergeConflictPrompt).outcomeTool(
722
- "clean",
723
- (tool) => tool.description("The merge conflict was resolved and the repository is clean").requiredString("headSha", "The post-resolution HEAD sha").to(turnIds.commitAndMerge).state(
724
- ({ ctx, event }) => patchRepositoryChangeState(ctx.state, {
725
- finalization: resetFinalizationAfterMessage(ctx.state, {
726
- expectedPostConflictHeadSha: normalizeMessage(event.params.headSha),
727
- usedConflictResolution: true
728
- })
729
- })
730
- )
731
- ).publish(products.mergeResolutionSummary);
732
- const planFlow = flow.fragment("plan").turn(importPlanTurn).turn(generatePlanTurn).turn({ id: turnIds.planDecision, definition: planDecisionSpec }).turn(reviewPlanTurn).turn({ id: turnIds.planReviewFeedback, definition: planReviewFeedbackSpec });
733
- const implementationFlow = flow.fragment("implementation").turn(implementTurn).turn({ id: turnIds.implementationDecision, definition: implementationDecisionSpec }).turn(reviewImplementationTurn).turn({
734
- id: turnIds.implementationReviewFeedback,
735
- definition: implementationReviewFeedbackSpec
736
- }).turn(simplifyImplementationTurn).turn({ id: turnIds.simplificationDecision, definition: simplificationDecisionSpec });
737
- const finalizationFlow = flow.fragment("finalization").turn(generateCommitMessageTurn).turn(commitAndMergeTurn).turn(resolveMergeConflictTurn);
738
- const builder = flow.process(config.processId).displayName(config.displayName).entry(turnIds.generatePlan).alternateEntry(turnIds.importPlan).happyPath(
739
- turnIds.generatePlan,
740
- turnIds.implement,
741
- turnIds.generateCommitMessage,
742
- turnIds.commitAndMerge
743
- ).piConfig({ sessionCwdTemplate: "{{{projectKey}}}" }).codecs({
744
- params: config.paramsCodec,
745
- state: repositoryChangeStateCodec
746
- }).initialState(() => ({
747
- ...createEmptyStructuralProcessState(),
748
- finalization: createEmptyRepositoryChangeFinalizationState()
749
- })).use(planFlow).use(implementationFlow).use(finalizationFlow);
750
- if (config.repositoryCredentials) builder.repositoryCredentials(config.repositoryCredentials);
751
- const process = builder.launcher(config.launcher).define();
752
- const decision = (id) => ({
753
- id,
754
- ...process.turns.get(id)?.definition
755
- });
756
- return {
757
- process,
758
- planDecision: decision(turnIds.planDecision),
759
- planReviewFeedback: decision(turnIds.planReviewFeedback),
760
- implementationDecision: decision(turnIds.implementationDecision),
761
- implementationReviewFeedback: decision(turnIds.implementationReviewFeedback),
762
- simplificationDecision: decision(turnIds.simplificationDecision)
763
- };
764
- }
765
-
766
- // src/index.ts
767
- var manifest = { id: "coding", version: "0.1.0" };
768
- var extension = { manifest };
769
- var index_default = extension;
770
- export {
771
- acceptReviewForm,
772
- codingActionIds,
773
- createFinalizeChangeForm,
774
- createRepositoryChangeLaunchPlanner,
775
- createRepositoryChangeParamsCodec,
776
- createRepositoryChangeProcess,
777
- createRepositoryChangeUiLauncher,
778
- index_default as default,
779
- formatRepositoryChangeLaunchErrors,
780
- manifest,
781
- normalizeRepositoryChangeParamsInput,
782
- repositoryChangeParamsRecord,
783
- requestReviewChangesForm,
784
- requestRevisionForm
785
- };
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";
786
7
  //# sourceMappingURL=index.js.map