@leitwerk-dev/coding 0.5.6 → 0.5.8

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 (31) hide show
  1. package/README.md +13 -0
  2. package/dist/{chunk-B3PE6DPF.js → chunk-JL53OV5M.js} +74 -67
  3. package/dist/chunk-JL53OV5M.js.map +1 -0
  4. package/dist/{chunk-QD6FI4HR.js → chunk-PISZZXK4.js} +3 -4
  5. package/dist/chunk-PISZZXK4.js.map +1 -0
  6. package/dist/{chunk-3WJRJ3Q7.js → chunk-VG6XF3OK.js} +2 -6
  7. package/dist/chunk-VG6XF3OK.js.map +1 -0
  8. package/dist/finalization-git-internal.d.ts.map +1 -1
  9. package/dist/finalization-git.js +1 -1
  10. package/dist/index.js +2 -2
  11. package/dist/{repository-change-launch-internal-BudnAfL7.d.ts → repository-change-launch-internal-CP2jJJCR.d.ts} +1 -1
  12. package/dist/{repository-change-process-DlgF04fU.d.ts → repository-change-process-DbcnkzLw.d.ts} +2 -0
  13. package/dist/repository-change-process.d.ts +2 -0
  14. package/dist/repository-change-process.d.ts.map +1 -1
  15. package/dist/repository-change-publication.d.ts.map +1 -1
  16. package/dist/repository-change-publication.js +14 -26
  17. package/dist/repository-change-publication.js.map +1 -1
  18. package/dist/repository-reconciliation.d.ts +9 -15
  19. package/dist/repository-reconciliation.d.ts.map +1 -1
  20. package/dist/turns/implement.d.ts +1 -1
  21. package/dist/turns/implement.d.ts.map +1 -1
  22. package/dist/turns/implement.js +1 -1
  23. package/package.json +5 -5
  24. package/src/finalization-git-internal.ts +1 -5
  25. package/src/repository-change-process.ts +5 -1
  26. package/src/repository-change-publication.ts +13 -27
  27. package/src/repository-reconciliation.ts +97 -84
  28. package/src/turns/implement.ts +2 -2
  29. package/dist/chunk-3WJRJ3Q7.js.map +0 -1
  30. package/dist/chunk-B3PE6DPF.js.map +0 -1
  31. package/dist/chunk-QD6FI4HR.js.map +0 -1
package/README.md CHANGED
@@ -115,6 +115,19 @@ lease and publishes any retained unpublished work before acknowledging feedback.
115
115
  An unchanged checkout creates no commit or push. A watcher may observe an active
116
116
  worker's new remote head, but never mutates its checkout or captured baseline.
117
117
 
118
+ ## Target-branch refresh
119
+
120
+ With `refreshTargetBeforeImplementation`, preparation fast-forwards a clean,
121
+ unpublished branch to the target and stops if ignored files become publishable.
122
+ Checkouts with local work are preserved for reconciliation.
123
+
124
+ Before the first push of an unpublished work branch, shared delivery fetches the
125
+ target. If it advanced, delivery uses the same checkpoint and adjustment flow to
126
+ reapply local work and require validation before pushing. A rewritten target that
127
+ no longer contains the captured baseline stops without discarding local changes.
128
+ After a work branch is published, target conflicts use the normal pull-request
129
+ maintenance flow.
130
+
118
131
  ## Git rebase repair
119
132
 
120
133
  Provider adapters import conflict evidence and reporting helpers from
@@ -7,7 +7,7 @@ import {
7
7
  } from "./chunk-ABQH2WZT.js";
8
8
  import {
9
9
  buildImplementPrompt
10
- } from "./chunk-QD6FI4HR.js";
10
+ } from "./chunk-PISZZXK4.js";
11
11
  import {
12
12
  buildStreamlinedSimplificationPrompt
13
13
  } from "./chunk-SKGB4CZS.js";
@@ -194,7 +194,7 @@ function withLock(directory, run) {
194
194
  rmSync(lock, { recursive: true });
195
195
  }
196
196
  }
197
- function reconcileRepository(input) {
197
+ function reconcile(input, preparing) {
198
198
  const { git, directory, read, save, binding: readBinding } = repository(input);
199
199
  return withLock(directory, () => {
200
200
  git(["check-ref-format", `refs/heads/${input.workBranch}`]);
@@ -202,6 +202,32 @@ function reconcileRepository(input) {
202
202
  let record = read();
203
203
  if (!repositoryBindingMatches(record, binding))
204
204
  throw new Error("Repository reconciliation binding changed");
205
+ const receipt = readPublicationReceipt(directory);
206
+ if (!repositoryBindingMatches(receipt, binding))
207
+ throw new Error("Repository publication receipt binding changed");
208
+ const sourceExists = git(["ls-remote", "--heads", "origin", `refs/heads/${input.workBranch}`]);
209
+ const unpublished = !sourceExists && !input.baselineSha && !record?.remoteSeen && (!receipt || receipt.status === "rejected" && receipt.expectedHead === null);
210
+ const target = unpublished ? input.baseBranch : void 0;
211
+ if (!sourceExists && (!unpublished || record?.operation && !target))
212
+ throw new Error(
213
+ "Remote source branch is missing or its publication is uncertain; local work was retained and the branch will not be recreated automatically"
214
+ );
215
+ if (record?.operation && record.operation.targetBranch !== target)
216
+ throw new Error("Repository reconciliation target changed; local work was retained");
217
+ assertIgnoredProtection(git, record?.protectedIgnored);
218
+ if (target) git(["check-ref-format", `refs/heads/${target}`]);
219
+ const captureBaseline = !record && (preparing || target);
220
+ const capturedHead = captureBaseline ? git(["rev-parse", "HEAD"]) : void 0;
221
+ const capturedIgnored = captureBaseline ? ignoredPaths(git) : void 0;
222
+ if (capturedHead && capturedIgnored) {
223
+ const baseline = target ? git(["merge-base", capturedHead, `refs/remotes/origin/${target}`]) : capturedHead;
224
+ record = { ...binding, baseline, protectedIgnored: capturedIgnored };
225
+ save(record);
226
+ }
227
+ if (unpublished && !target) {
228
+ const headSha = capturedHead ?? git(["rev-parse", "HEAD"]);
229
+ return { status: "unchanged", remoteHead: null, headSha };
230
+ }
205
231
  if (record?.sourceIntegration) {
206
232
  if (git(["branch", "--show-current"]) !== input.workBranch)
207
233
  throw new Error("Source integration checkout branch changed; local work was retained");
@@ -222,33 +248,38 @@ function reconcileRepository(input) {
222
248
  if (!rebaseActive() && git(["branch", "--show-current"]) !== input.workBranch)
223
249
  throw new Error(`Expected checkout on '${input.workBranch}'; local work was retained`);
224
250
  if (!record?.operation) {
225
- assertIgnoredProtection(git, record?.protectedIgnored);
226
- const ignored = ignoredPaths(git);
251
+ const ignored = capturedIgnored ?? ignoredPaths(git);
252
+ const head = capturedHead ?? git(["rev-parse", "HEAD"]);
253
+ let baseline = record?.baseline ?? input.baselineSha ?? receipt?.expectedHead ?? (receipt?.status === "attempting" ? receipt.candidate : void 0);
254
+ const cleanOnly = target && preparing;
255
+ if (cleanOnly && (head !== baseline || git(["status", "--porcelain"])))
256
+ return { status: "unchanged", remoteHead: null, headSha: head };
257
+ const ref = target ? `refs/remotes/origin/${target}` : "refs/leitwerk/reconcile-remote";
227
258
  git([
228
259
  "fetch",
229
260
  "--no-tags",
261
+ ...target ? ["--refmap="] : [],
230
262
  "origin",
231
- `+refs/heads/${input.workBranch}:refs/leitwerk/reconcile-remote`
263
+ `+refs/heads/${target ?? input.workBranch}:${ref}`
232
264
  ]);
233
- const remote = git(["rev-parse", "refs/leitwerk/reconcile-remote"]);
234
- const head = git(["rev-parse", "HEAD"]);
235
- let baseline = record?.baseline ?? input.baselineSha;
236
- const receipt = readPublicationReceipt(directory);
237
- if (!repositoryBindingMatches(receipt, binding))
238
- throw new Error("Repository publication receipt binding changed");
239
- if (receipt?.status === "attempting") {
240
- if (remote === receipt.candidate || ancestor(git, receipt.candidate, remote)) {
265
+ const remote = git(["rev-parse", ref]);
266
+ if (!target) {
267
+ if (receipt?.status === "attempting") {
268
+ if (!ancestor(git, receipt.candidate, remote))
269
+ throw new Error(
270
+ "Prior publication outcome is uncertain; local work was retained for operator reconciliation"
271
+ );
241
272
  receipt.status = "accepted";
242
273
  savePublicationReceipt(directory, receipt);
243
- } else {
244
- throw new Error(
245
- "Prior publication outcome is uncertain; local work was retained for operator reconciliation"
246
- );
247
274
  }
275
+ if (receipt?.status === "accepted" && record?.publicationReceiptSha !== receipt.candidate)
276
+ baseline = receipt.candidate;
248
277
  }
249
- if (receipt?.status === "accepted" && record?.publicationReceiptSha !== receipt.candidate)
250
- baseline = receipt.candidate;
278
+ if (!baseline)
279
+ throw new Error("Cannot establish the retained work baseline; local work was retained");
251
280
  git(["cat-file", "-e", `${baseline}^{commit}`]);
281
+ if (target && !ancestor(git, baseline, remote))
282
+ throw new Error("The target branch was rewritten; local work was retained");
252
283
  if (!ancestor(git, baseline, head))
253
284
  throw new Error(
254
285
  "Cannot establish unpublished work from the retained baseline; local work was retained"
@@ -257,21 +288,28 @@ function reconcileRepository(input) {
257
288
  ...record,
258
289
  ...binding,
259
290
  baseline,
260
- remoteSeen: true,
291
+ remoteSeen: !target,
261
292
  protectedIgnored: [.../* @__PURE__ */ new Set([...record?.protectedIgnored ?? [], ...ignored])],
262
293
  publicationReceiptSha: receipt?.status === "accepted" ? receipt.candidate : record?.publicationReceiptSha
263
294
  };
264
- if ((remote === baseline || remote === head) && !record.joinParent) {
295
+ const upToDate = target ? ancestor(git, remote, head) : remote === baseline || remote === head;
296
+ if ((!upToDate || record.joinParent) && ignoredPathsCollide(git, ignored, remote, `${baseline}..${head}`))
297
+ throw new Error("Remote changes collide with ignored files; local files were retained");
298
+ if (upToDate && !record.joinParent || cleanOnly) {
299
+ if (!upToDate) git(["merge", "--ff-only", "--no-overwrite-ignore", remote]);
265
300
  record.baseline = remote;
266
301
  save(record);
267
- return { status: "ready", remoteHead: remote, headSha: head, changed: false };
302
+ if (!upToDate) assertIgnoredProtection(git, record.protectedIgnored);
303
+ return {
304
+ status: upToDate ? "unchanged" : "reconciled",
305
+ remoteHead: target ? null : remote,
306
+ headSha: upToDate ? head : remote
307
+ };
268
308
  }
269
309
  if (git(["diff", "--name-only", "--diff-filter=U"]))
270
310
  throw new Error("Unresolved local conflicts must be repaired before reconciliation");
271
311
  if (git(["submodule", "foreach", "--quiet", "git status --porcelain"]))
272
312
  throw new Error("Commit or preserve dirty submodule work before reconciliation");
273
- if (ignoredPathsCollide(git, ignored, remote, `${record.baseline}..${head}`))
274
- throw new Error("Remote changes collide with ignored files; local files were retained");
275
313
  if (ancestor(git, head, remote)) record.baseline = head;
276
314
  const id = randomUUID();
277
315
  const temporaryIndex = join(directory, `leitwerk-index-${id}`);
@@ -303,6 +341,7 @@ function reconcileRepository(input) {
303
341
  index,
304
342
  work,
305
343
  remote,
344
+ targetBranch: target,
306
345
  phase: "captured",
307
346
  identity: replayIdentity
308
347
  };
@@ -334,17 +373,14 @@ function reconcileRepository(input) {
334
373
  if (operation.phase === "rebasing") {
335
374
  const conflicts = () => ({
336
375
  status: "conflicts",
337
- remoteHead: operation.remote,
338
- headSha: git(["rev-parse", "HEAD"]),
339
- changed: true
376
+ remoteHead: target ? null : operation.remote,
377
+ headSha: git(["rev-parse", "HEAD"])
340
378
  });
341
379
  if (rebaseActive()) return conflicts();
342
380
  if (git(["rev-parse", "HEAD"]) === operation.work) {
343
381
  try {
344
382
  git(
345
383
  [
346
- "-c",
347
- "core.hooksPath=/dev/null",
348
384
  "-c",
349
385
  "commit.gpgSign=false",
350
386
  "rebase",
@@ -414,10 +450,9 @@ function reconcileRepository(input) {
414
450
  save(record);
415
451
  assertIgnoredProtection(git, record.protectedIgnored);
416
452
  return {
417
- status: "ready",
418
- remoteHead: operation.remote,
419
- headSha: operation.resultHead,
420
- changed: true
453
+ status: "reconciled",
454
+ remoteHead: target ? null : operation.remote,
455
+ headSha: operation.resultHead
421
456
  };
422
457
  });
423
458
  }
@@ -471,40 +506,10 @@ function repositoryWorktreeIsDirty(input) {
471
506
  return Boolean(repository(input).git(["status", "--porcelain"]));
472
507
  }
473
508
  function prepareInitialRepository(input) {
474
- const { git, read, save, directory, binding } = repository(input);
475
- withLock(directory, () => {
476
- if (!read())
477
- save({
478
- ...binding(input.workBranch),
479
- baseline: git(["rev-parse", "HEAD"]),
480
- protectedIgnored: ignoredPaths(git)
481
- });
482
- });
483
- return reconcilePublicationRepository(input);
509
+ return reconcile(input, true);
484
510
  }
485
511
  function reconcilePublicationRepository(input) {
486
- const { git, read, directory } = repository(input);
487
- const record = read();
488
- const receipt = readPublicationReceipt(directory);
489
- const baselineSha = record?.baseline ?? input.baselineSha ?? (receipt?.status === "accepted" ? receipt.candidate : receipt?.expectedHead ?? (receipt?.status === "attempting" ? receipt.candidate : void 0));
490
- assertIgnoredProtection(git, record?.protectedIgnored);
491
- const remote = git(["ls-remote", "--heads", "origin", `refs/heads/${input.workBranch}`]).split(
492
- /\s+/
493
- )[0];
494
- if (!remote && !input.baselineSha && !record?.remoteSeen && !record?.operation && (!receipt || receipt.status === "rejected" && receipt.expectedHead === null))
495
- return {
496
- status: "ready",
497
- remoteHead: null,
498
- headSha: git(["rev-parse", "HEAD"]),
499
- changed: false
500
- };
501
- if (!remote)
502
- throw new Error(
503
- "Remote source branch is missing or its publication is uncertain; local work was retained and the branch will not be recreated automatically"
504
- );
505
- if (!baselineSha)
506
- throw new Error("Cannot establish the retained work baseline; local work was retained");
507
- return reconcileRepository({ ...input, baselineSha });
512
+ return reconcile(input, false);
508
513
  }
509
514
  function recordRepositoryPublication(input, headSha) {
510
515
  const { directory, read, save, binding: readBinding } = repository(input);
@@ -725,6 +730,7 @@ function createRepositoryChangeProcess(config) {
725
730
  };
726
731
  })
727
732
  ).publish("plan");
733
+ const refreshTarget = config.workflow?.refreshTargetBeforeImplementation;
728
734
  const implement = flow.llm("implement").description("Implement").waitFor(({ state }) => !!state.productRefs.plan).executionPurpose(codingPurposes.implementation).tools(...tools).freshSeededPrimary().startFromRoot().consume("plan").prepare((ctx) => ({
729
735
  reconciliation: ctx.repo.all().map((repo) => {
730
736
  const identity = asUnknownRecord(
@@ -734,10 +740,11 @@ function createRepositoryChangeProcess(config) {
734
740
  projectKey: repo.key,
735
741
  repoPath: repo.fsPath,
736
742
  workBranch: repo.workBranch,
743
+ baseBranch: refreshTarget ? repo.baseBranch : void 0,
737
744
  gitIdentity: typeof identity?.name === "string" && typeof identity.email === "string" ? { name: identity.name, email: identity.email } : void 0
738
745
  });
739
746
  })
740
- })).buildPrompt((ctx) => `${buildImplementPrompt(ctx)}
747
+ })).buildPrompt((ctx) => `${buildImplementPrompt(ctx, refreshTarget)}
741
748
 
742
749
  ${reconciliationPrompt}`).outcomeTool(
743
750
  "implementation_ready",
@@ -817,4 +824,4 @@ export {
817
824
  reconciliationPrompt,
818
825
  createRepositoryChangeProcess
819
826
  };
820
- //# sourceMappingURL=chunk-B3PE6DPF.js.map
827
+ //# sourceMappingURL=chunk-JL53OV5M.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/actions.ts","../src/repository-reconciliation.ts","../src/repository-change-process.ts","../src/repository-change-state-internal.ts"],"sourcesContent":["import type { FormDefinition } from \"@leitwerk-dev/process-sdk\";\n\n/** @public */\nexport const codingActionIds = {\n\t/** @public */\n\tapprovePlan: \"approve_plan\",\n\t/** @internal */\n\trequestRevision: \"request_revision\",\n\t/** @internal */\n\trunReview: \"run_review\",\n\t/** @internal */\n\tsimplify: \"simplify\",\n\t/** @internal */\n\tacceptReview: \"accept_review\",\n\t/** @internal */\n\trequestReviewChanges: \"request_review_changes\",\n\t/** @internal */\n\tdismissReview: \"dismiss_review\",\n\t/** @public */\n\tfinalizeChange: \"finalize_change\",\n} as const;\n\nfunction notesForm(id: string, title: string, label: string, description: string): FormDefinition {\n\treturn {\n\t\tid,\n\t\ttitle,\n\t\tfields: [\n\t\t\t{ id: \"message\", label, kind: \"textarea\", primaryPrompt: true, required: true, description },\n\t\t],\n\t\tsubmitLabel: title,\n\t};\n}\n\n/** @internal */\nexport const requestRevisionForm = notesForm(\n\tcodingActionIds.requestRevision,\n\t\"Request revision\",\n\t\"Revision notes\",\n\t\"Instructions for the next implementation pass.\",\n);\n/** @internal */\nexport const requestReviewChangesForm = notesForm(\n\tcodingActionIds.requestReviewChanges,\n\t\"Request review changes\",\n\t\"Review notes\",\n\t\"Instructions for the next review pass.\",\n);\n/** @internal */\nexport const acceptReviewForm: FormDefinition = {\n\tid: codingActionIds.acceptReview,\n\ttitle: \"Accept review\",\n\tfields: [\n\t\t{\n\t\t\tid: \"message\",\n\t\t\tlabel: \"Review adjustment\",\n\t\t\tkind: \"textarea\",\n\t\t\tprimaryPrompt: true,\n\t\t\tdescription:\n\t\t\t\t\"Optional instructions to apply with the accepted review, such as dropping one finding.\",\n\t\t},\n\t],\n\tsubmitLabel: \"Accept review\",\n};\n","import { execFileSync } from \"node:child_process\";\nimport { randomUUID } from \"node:crypto\";\nimport { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from \"node:fs\";\nimport { hostname } from \"node:os\";\nimport { join } from \"node:path\";\nimport { repositoryGitArgs, repositoryGitSubprocessEnv } from \"@leitwerk-dev/process-sdk\";\nimport { resolveGitBinary } from \"@leitwerk-dev/process-sdk/git-binary\";\nimport type { GitIdentity } from \"./finalization-git.js\";\nimport {\n\ttype RepositoryBinding,\n\treadPublicationReceipt,\n\treadRepositoryBinding,\n\trepositoryBindingMatches,\n\tsavePublicationReceipt,\n} from \"./repository-publication-receipt.js\";\nimport { repositoryRecord } from \"./repository-record.js\";\n\n/** @internal */\nexport interface ReconciliationInput {\n\tprojectKey: string;\n\trepoPath: string;\n\tworkBranch: string;\n\t/** Last remote baseline, not the latest observation. */\n\tbaselineSha: string;\n\t/** Trusted project identity for replaying unpublished commits. */\n\tgitIdentity?: GitIdentity;\n}\n\ntype WorkBranchInput = Omit<ReconciliationInput, \"baselineSha\"> & {\n\tbaselineSha?: string;\n\tbaseBranch?: string;\n};\n\n/** @internal */\nexport interface ReconciliationResult {\n\tstatus: \"unchanged\" | \"reconciled\" | \"conflicts\";\n\tremoteHead: string | null;\n\theadSha: string;\n}\n\ninterface RecordState extends RepositoryBinding {\n\tbaseline: string;\n\tremoteSeen?: boolean;\n\tprotectedIgnored?: string[];\n\tpublicationReceiptSha?: string;\n\tjoinParent?: string;\n\tjoinIdentity?: GitIdentity;\n\tsourceIntegration?: { previous: string; replacement: string };\n\toperation?: {\n\t\tid: string;\n\t\thead: string;\n\t\tindex: string;\n\t\twork: string;\n\t\tremote: string;\n\t\ttargetBranch?: string;\n\t\tphase: \"captured\" | \"rebasing\" | \"restoring\";\n\t\tresultHead?: string;\n\t\tresultIndex?: string;\n\t\tidentity?: GitIdentity;\n\t};\n}\n\nfunction repository(input: Pick<ReconciliationInput, \"projectKey\" | \"repoPath\">) {\n\tfunction git(args: string[], extra: NodeJS.ProcessEnv = {}): string {\n\t\tconst output = execFileSync(resolveGitBinary(), repositoryGitArgs(args), {\n\t\t\tcwd: input.repoPath,\n\t\t\tencoding: \"utf8\",\n\t\t\tenv: repositoryGitSubprocessEnv(input.projectKey, {\n\t\t\t\tGIT_TERMINAL_PROMPT: \"0\",\n\t\t\t\tGIT_EDITOR: \"true\",\n\t\t\t\tGIT_SEQUENCE_EDITOR: \"true\",\n\t\t\t\t...extra,\n\t\t\t}),\n\t\t\tstdio: [\"ignore\", \"pipe\", \"pipe\"],\n\t\t\tmaxBuffer: 16 * 1024 * 1024,\n\t\t});\n\t\treturn output.endsWith(\"\\0\") ? output : output.replace(/\\r?\\n$/, \"\");\n\t}\n\tconst directory = git([\"rev-parse\", \"--absolute-git-dir\"]);\n\tif (\n\t\tgit([\"remote\", \"get-url\", \"--push\", \"--all\", \"origin\"]) !== git([\"remote\", \"get-url\", \"origin\"])\n\t)\n\t\tthrow new Error(\n\t\t\t\"Repository reconciliation binding changed: fetch and push endpoints must match\",\n\t\t);\n\tconst { read, save } = repositoryRecord<RecordState>(directory, \"reconciliation\");\n\tconst binding = (branch: string) => readRepositoryBinding((...args) => git(args), branch);\n\treturn { git, directory, read, save, binding };\n}\n\nfunction integrationIdentityEnv(identity: GitIdentity | undefined): NodeJS.ProcessEnv {\n\tif (\n\t\t!identity?.name.trim() ||\n\t\t!identity.email.trim() ||\n\t\t/[\\r\\n\\0]/.test(identity.name + identity.email)\n\t)\n\t\tthrow new Error(\n\t\t\t\"A trusted Git identity is required for source integration; local work was retained\",\n\t\t);\n\treturn {\n\t\tGIT_AUTHOR_NAME: identity.name,\n\t\tGIT_AUTHOR_EMAIL: identity.email,\n\t\tGIT_COMMITTER_NAME: identity.name,\n\t\tGIT_COMMITTER_EMAIL: identity.email,\n\t};\n}\n\nfunction ignoredPaths(git: ReturnType<typeof repository>[\"git\"]): string[] {\n\treturn git([\n\t\t\"ls-files\",\n\t\t\"--others\",\n\t\t\"--ignored\",\n\t\t\"--exclude-standard\",\n\t\t\"--directory\",\n\t\t\"--no-empty-directory\",\n\t\t\"-z\",\n\t])\n\t\t.split(\"\\0\")\n\t\t.filter(Boolean)\n\t\t.map((file) => file.replace(/\\/$/, \"\"));\n}\n\nfunction assertIgnoredProtection(\n\tgit: ReturnType<typeof repository>[\"git\"],\n\tprotectedPaths: string[] = [],\n): void {\n\tif (!protectedPaths.length) return;\n\tconst visible = git([\"ls-files\", \"--cached\", \"--others\", \"--exclude-standard\", \"-z\"]).split(\"\\0\");\n\tif (\n\t\tprotectedPaths.some((ignored) =>\n\t\t\tvisible.some((file) => file === ignored || file.startsWith(`${ignored}/`)),\n\t\t)\n\t)\n\t\tthrow new Error(\n\t\t\t\"Previously ignored local files became publishable; review ignore rules before continuing. Local files were retained\",\n\t\t);\n}\n\nfunction ignoredPathsCollide(\n\tgit: ReturnType<typeof repository>[\"git\"],\n\tignored: string[],\n\ttarget: string,\n\treplayRange: string,\n): boolean {\n\tconst paths = [\n\t\t...git([\"ls-tree\", \"-r\", \"--name-only\", \"-z\", target]).split(\"\\0\"),\n\t\t...git([\"log\", \"--format=\", \"--full-history\", \"-m\", \"--name-only\", \"-z\", replayRange]).split(\n\t\t\t\"\\0\",\n\t\t),\n\t];\n\treturn ignored.some((file) =>\n\t\tpaths.some((p) => p === file || p.startsWith(`${file}/`) || file.startsWith(`${p}/`)),\n\t);\n}\n\nfunction ancestor(git: ReturnType<typeof repository>[\"git\"], a: string, b: string): boolean {\n\ttry {\n\t\tgit([\"merge-base\", \"--is-ancestor\", a, b]);\n\t\treturn true;\n\t} catch (error) {\n\t\tif ((error as { status?: number }).status === 1) return false;\n\t\tthrow error;\n\t}\n}\n\nfunction withLock<T>(directory: string, run: () => T): T {\n\tconst lock = join(directory, \"leitwerk-reconciliation.lock\");\n\ttry {\n\t\tmkdirSync(lock);\n\t} catch (error) {\n\t\tif ((error as NodeJS.ErrnoException).code !== \"EEXIST\") throw error;\n\t\t// Never steal a lock from another node or a living process.\n\t\tconst owner = JSON.parse(readFileSync(join(lock, \"owner.json\"), \"utf8\"));\n\t\tif (owner.host !== hostname())\n\t\t\tthrow new Error(\"Repository reconciliation is owned by another worker\");\n\t\ttry {\n\t\t\tprocess.kill(owner.pid, 0);\n\t\t} catch (failure) {\n\t\t\tif ((failure as NodeJS.ErrnoException).code !== \"ESRCH\") throw failure;\n\t\t\trmSync(lock, { recursive: true });\n\t\t\treturn withLock(directory, run);\n\t\t}\n\t\tthrow new Error(\"Repository reconciliation is already running\");\n\t}\n\ttry {\n\t\twriteFileSync(\n\t\t\tjoin(lock, \"owner.json\"),\n\t\t\tJSON.stringify({ host: hostname(), pid: process.pid }),\n\t\t\t{ mode: 0o600 },\n\t\t);\n\t\treturn run();\n\t} finally {\n\t\trmSync(lock, { recursive: true });\n\t}\n}\n\n/**\n * Reconcile unpublished work onto the fetched source or target branch. Checkpoint commits\n * retain the index and working tree separately, including non-ignored untracked files.\n * They are retained under private refs and removed from HEAD before publication.\n * A conflicted rebase is deliberately left in place for the existing adjustment turn.\n */\nfunction reconcile(input: WorkBranchInput, preparing: boolean): ReconciliationResult {\n\tconst { git, directory, read, save, binding: readBinding } = repository(input);\n\treturn withLock(directory, () => {\n\t\tgit([\"check-ref-format\", `refs/heads/${input.workBranch}`]);\n\t\tconst binding = readBinding(input.workBranch);\n\t\tlet record = read();\n\t\tif (!repositoryBindingMatches(record, binding))\n\t\t\tthrow new Error(\"Repository reconciliation binding changed\");\n\t\tconst receipt = readPublicationReceipt(directory);\n\t\tif (!repositoryBindingMatches(receipt, binding))\n\t\t\tthrow new Error(\"Repository publication receipt binding changed\");\n\t\tconst sourceExists = git([\"ls-remote\", \"--heads\", \"origin\", `refs/heads/${input.workBranch}`]);\n\t\tconst unpublished =\n\t\t\t!sourceExists &&\n\t\t\t!input.baselineSha &&\n\t\t\t!record?.remoteSeen &&\n\t\t\t(!receipt || (receipt.status === \"rejected\" && receipt.expectedHead === null));\n\t\tconst target = unpublished ? input.baseBranch : undefined;\n\t\tif (!sourceExists && (!unpublished || (record?.operation && !target)))\n\t\t\tthrow new Error(\n\t\t\t\t\"Remote source branch is missing or its publication is uncertain; local work was retained and the branch will not be recreated automatically\",\n\t\t\t);\n\t\tif (record?.operation && record.operation.targetBranch !== target)\n\t\t\tthrow new Error(\"Repository reconciliation target changed; local work was retained\");\n\t\tassertIgnoredProtection(git, record?.protectedIgnored);\n\t\tif (target) git([\"check-ref-format\", `refs/heads/${target}`]);\n\t\tconst captureBaseline = !record && (preparing || target);\n\t\tconst capturedHead = captureBaseline ? git([\"rev-parse\", \"HEAD\"]) : undefined;\n\t\tconst capturedIgnored = captureBaseline ? ignoredPaths(git) : undefined;\n\t\tif (capturedHead && capturedIgnored) {\n\t\t\tconst baseline = target\n\t\t\t\t? git([\"merge-base\", capturedHead, `refs/remotes/origin/${target}`])\n\t\t\t\t: capturedHead;\n\t\t\trecord = { ...binding, baseline, protectedIgnored: capturedIgnored };\n\t\t\tsave(record);\n\t\t}\n\t\tif (unpublished && !target) {\n\t\t\tconst headSha = capturedHead ?? git([\"rev-parse\", \"HEAD\"]);\n\t\t\treturn { status: \"unchanged\", remoteHead: null, headSha };\n\t\t}\n\t\tif (record?.sourceIntegration) {\n\t\t\tif (git([\"branch\", \"--show-current\"]) !== input.workBranch)\n\t\t\t\tthrow new Error(\"Source integration checkout branch changed; local work was retained\");\n\t\t\tconst { previous, replacement } = record.sourceIntegration;\n\t\t\tconst current = git([\"rev-parse\", \"HEAD\"]);\n\t\t\tif (current === previous)\n\t\t\t\tgit([\"update-ref\", `refs/heads/${input.workBranch}`, replacement, previous]);\n\t\t\telse if (current !== replacement)\n\t\t\t\tthrow new Error(\"Checkout changed during source integration; recovery refs were retained\");\n\t\t\tdelete record.sourceIntegration;\n\t\t\tsave(record);\n\t\t}\n\t\tconst rebaseActive = () =>\n\t\t\t[\"rebase-merge\", \"rebase-apply\"].some((name) => existsSync(join(directory, name)));\n\t\tif (rebaseActive() && !record?.operation)\n\t\t\tthrow new Error(\"An unrelated rebase is already in progress; local work was retained\");\n\t\tif (\n\t\t\texistsSync(join(directory, \"MERGE_HEAD\")) ||\n\t\t\texistsSync(join(directory, \"CHERRY_PICK_HEAD\"))\n\t\t)\n\t\t\tthrow new Error(\"An unrelated Git operation is in progress; local work was retained\");\n\t\tif (!rebaseActive() && git([\"branch\", \"--show-current\"]) !== input.workBranch)\n\t\t\tthrow new Error(`Expected checkout on '${input.workBranch}'; local work was retained`);\n\n\t\tif (!record?.operation) {\n\t\t\tconst ignored = capturedIgnored ?? ignoredPaths(git);\n\t\t\tconst head = capturedHead ?? git([\"rev-parse\", \"HEAD\"]);\n\t\t\tlet baseline =\n\t\t\t\trecord?.baseline ??\n\t\t\t\tinput.baselineSha ??\n\t\t\t\treceipt?.expectedHead ??\n\t\t\t\t(receipt?.status === \"attempting\" ? receipt.candidate : undefined);\n\t\t\tconst cleanOnly = target && preparing;\n\t\t\tif (cleanOnly && (head !== baseline || git([\"status\", \"--porcelain\"])))\n\t\t\t\treturn { status: \"unchanged\", remoteHead: null, headSha: head };\n\t\t\t// A source lease comes from the explicit fetch, not a remote-tracking ref.\n\t\t\tconst ref = target ? `refs/remotes/origin/${target}` : \"refs/leitwerk/reconcile-remote\";\n\t\t\tgit([\n\t\t\t\t\"fetch\",\n\t\t\t\t\"--no-tags\",\n\t\t\t\t...(target ? [\"--refmap=\"] : []),\n\t\t\t\t\"origin\",\n\t\t\t\t`+refs/heads/${target ?? input.workBranch}:${ref}`,\n\t\t\t]);\n\t\t\tconst remote = git([\"rev-parse\", ref]);\n\t\t\tif (!target) {\n\t\t\t\tif (receipt?.status === \"attempting\") {\n\t\t\t\t\tif (!ancestor(git, receipt.candidate, remote))\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\"Prior publication outcome is uncertain; local work was retained for operator reconciliation\",\n\t\t\t\t\t\t);\n\t\t\t\t\treceipt.status = \"accepted\";\n\t\t\t\t\tsavePublicationReceipt(directory, receipt);\n\t\t\t\t}\n\t\t\t\tif (receipt?.status === \"accepted\" && record?.publicationReceiptSha !== receipt.candidate)\n\t\t\t\t\tbaseline = receipt.candidate;\n\t\t\t}\n\t\t\tif (!baseline)\n\t\t\t\tthrow new Error(\"Cannot establish the retained work baseline; local work was retained\");\n\t\t\tgit([\"cat-file\", \"-e\", `${baseline}^{commit}`]);\n\t\t\tif (target && !ancestor(git, baseline, remote))\n\t\t\t\tthrow new Error(\"The target branch was rewritten; local work was retained\");\n\t\t\tif (!ancestor(git, baseline, head))\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"Cannot establish unpublished work from the retained baseline; local work was retained\",\n\t\t\t\t);\n\t\t\trecord = {\n\t\t\t\t...record,\n\t\t\t\t...binding,\n\t\t\t\tbaseline,\n\t\t\t\tremoteSeen: !target,\n\t\t\t\tprotectedIgnored: [...new Set([...(record?.protectedIgnored ?? []), ...ignored])],\n\t\t\t\tpublicationReceiptSha:\n\t\t\t\t\treceipt?.status === \"accepted\" ? receipt.candidate : record?.publicationReceiptSha,\n\t\t\t};\n\t\t\tconst upToDate = target\n\t\t\t\t? ancestor(git, remote, head)\n\t\t\t\t: remote === baseline || remote === head;\n\t\t\tif (\n\t\t\t\t(!upToDate || record.joinParent) &&\n\t\t\t\tignoredPathsCollide(git, ignored, remote, `${baseline}..${head}`)\n\t\t\t)\n\t\t\t\tthrow new Error(\"Remote changes collide with ignored files; local files were retained\");\n\t\t\tif ((upToDate && !record.joinParent) || cleanOnly) {\n\t\t\t\tif (!upToDate) git([\"merge\", \"--ff-only\", \"--no-overwrite-ignore\", remote]);\n\t\t\t\trecord.baseline = remote;\n\t\t\t\tsave(record);\n\t\t\t\tif (!upToDate) assertIgnoredProtection(git, record.protectedIgnored);\n\t\t\t\treturn {\n\t\t\t\t\tstatus: upToDate ? \"unchanged\" : \"reconciled\",\n\t\t\t\t\tremoteHead: target ? null : remote,\n\t\t\t\t\theadSha: upToDate ? head : remote,\n\t\t\t\t};\n\t\t\t}\n\t\t\tif (git([\"diff\", \"--name-only\", \"--diff-filter=U\"]))\n\t\t\t\tthrow new Error(\"Unresolved local conflicts must be repaired before reconciliation\");\n\t\t\t// Dirty submodule work cannot be represented by the parent's tree checkpoint.\n\t\t\tif (git([\"submodule\", \"foreach\", \"--quiet\", \"git status --porcelain\"]))\n\t\t\t\tthrow new Error(\"Commit or preserve dirty submodule work before reconciliation\");\n\t\t\t// A verified remote descendant already contains these local commits, including\n\t\t\t// publication that succeeded before its receipt reached the server.\n\t\t\tif (ancestor(git, head, remote)) record.baseline = head;\n\t\t\tconst id = randomUUID();\n\t\t\tconst temporaryIndex = join(directory, `leitwerk-index-${id}`);\n\t\t\tconst identity = {\n\t\t\t\tGIT_AUTHOR_NAME: \"Leitwerk checkpoint\",\n\t\t\t\tGIT_AUTHOR_EMAIL: \"checkpoint@leitwerk.invalid\",\n\t\t\t\tGIT_COMMITTER_NAME: \"Leitwerk checkpoint\",\n\t\t\t\tGIT_COMMITTER_EMAIL: \"checkpoint@leitwerk.invalid\",\n\t\t\t};\n\t\t\ttry {\n\t\t\t\tconst stagedTree = git([\"write-tree\"]);\n\t\t\t\tconst index = git(\n\t\t\t\t\t[\"commit-tree\", stagedTree, \"-p\", head, \"-m\", `Leitwerk index checkpoint ${id}`],\n\t\t\t\t\tidentity,\n\t\t\t\t);\n\t\t\t\tgit([\"read-tree\", stagedTree], { GIT_INDEX_FILE: temporaryIndex });\n\t\t\t\tgit([\"add\", \"--all\"], { GIT_INDEX_FILE: temporaryIndex });\n\t\t\t\tconst workTree = git([\"write-tree\"], { GIT_INDEX_FILE: temporaryIndex });\n\t\t\t\tconst work = git(\n\t\t\t\t\t[\"commit-tree\", workTree, \"-p\", index, \"-m\", `Leitwerk worktree checkpoint ${id}`],\n\t\t\t\t\tidentity,\n\t\t\t\t);\n\t\t\t\t// Reachability and journal precede every change to the checkout.\n\t\t\t\tgit([\"update-ref\", `refs/leitwerk/checkpoints/${id}`, work]);\n\t\t\t\tconst replayIdentity = record.joinIdentity ?? input.gitIdentity;\n\t\t\t\tif (replayIdentity || record.baseline !== head) integrationIdentityEnv(replayIdentity);\n\t\t\t\trecord.operation = {\n\t\t\t\t\tid,\n\t\t\t\t\thead,\n\t\t\t\t\tindex,\n\t\t\t\t\twork,\n\t\t\t\t\tremote,\n\t\t\t\t\ttargetBranch: target,\n\t\t\t\t\tphase: \"captured\",\n\t\t\t\t\tidentity: replayIdentity,\n\t\t\t\t};\n\t\t\t\tsave(record);\n\t\t\t} finally {\n\t\t\t\trmSync(temporaryIndex, { force: true });\n\t\t\t}\n\t\t}\n\t\tconst operation = record.operation;\n\t\tif (!operation) throw new Error(\"Missing reconciliation checkpoint\");\n\t\tif (operation.phase === \"captured\") {\n\t\t\tif (operation.identity || record.baseline !== operation.head)\n\t\t\t\tintegrationIdentityEnv(operation.identity);\n\t\t\tconst current = git([\"rev-parse\", \"HEAD\"]);\n\t\t\tconst indexTree = git([\"write-tree\"]);\n\t\t\tif (\n\t\t\t\t![operation.head, operation.work].includes(current) ||\n\t\t\t\t![\n\t\t\t\t\tgit([\"rev-parse\", `${operation.index}^{tree}`]),\n\t\t\t\t\tgit([\"rev-parse\", `${operation.work}^{tree}`]),\n\t\t\t\t].includes(indexTree)\n\t\t\t)\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"Checkout changed after its checkpoint; new local work and recovery refs were retained\",\n\t\t\t\t);\n\t\t\t// read-tree changes only the index; the worktree already has this exact tree.\n\t\t\tgit([\"read-tree\", operation.work]);\n\t\t\tif (current !== operation.work)\n\t\t\t\tgit([\"update-ref\", `refs/heads/${input.workBranch}`, operation.work, operation.head]);\n\t\t\toperation.phase = \"rebasing\";\n\t\t\tsave(record);\n\t\t}\n\t\tif (operation.phase === \"rebasing\") {\n\t\t\tconst conflicts = (): ReconciliationResult => ({\n\t\t\t\tstatus: \"conflicts\",\n\t\t\t\tremoteHead: target ? null : operation.remote,\n\t\t\t\theadSha: git([\"rev-parse\", \"HEAD\"]),\n\t\t\t});\n\t\t\tif (rebaseActive()) return conflicts();\n\t\t\t// Retry after Git completed the rebase but before the result was journaled.\n\t\t\tif (git([\"rev-parse\", \"HEAD\"]) === operation.work) {\n\t\t\t\ttry {\n\t\t\t\t\tgit(\n\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\"-c\",\n\t\t\t\t\t\t\t\"commit.gpgSign=false\",\n\t\t\t\t\t\t\t\"rebase\",\n\t\t\t\t\t\t\t\"--rebase-merges\",\n\t\t\t\t\t\t\t\"--reapply-cherry-picks\",\n\t\t\t\t\t\t\t\"--empty=keep\",\n\t\t\t\t\t\t\t\"--onto\",\n\t\t\t\t\t\t\toperation.remote,\n\t\t\t\t\t\t\trecord.baseline,\n\t\t\t\t\t\t],\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tGIT_COMMITTER_NAME: operation.identity?.name ?? \"Leitwerk checkpoint\",\n\t\t\t\t\t\t\tGIT_COMMITTER_EMAIL: operation.identity?.email ?? \"checkpoint@leitwerk.invalid\",\n\t\t\t\t\t\t},\n\t\t\t\t\t);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (!rebaseActive()) throw error;\n\t\t\t\t\treturn conflicts();\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (\n\t\t\t\tgit([\"log\", \"-1\", \"--format=%s\"]) !== `Leitwerk worktree checkpoint ${operation.id}` ||\n\t\t\t\tgit([\"log\", \"-1\", \"--format=%s\", \"HEAD^\"]) !== `Leitwerk index checkpoint ${operation.id}`\n\t\t\t)\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"Reconciliation checkpoint commits were changed or skipped; recovery refs were retained\",\n\t\t\t\t);\n\t\t\toperation.resultHead = git([\"rev-parse\", \"HEAD~2\"]);\n\t\t\toperation.resultIndex = git([\"rev-parse\", \"HEAD~1^{tree}\"]);\n\t\t\t// Preserve the integrated working tree/index before removing checkpoint commits.\n\t\t\tgit([\"update-ref\", `refs/leitwerk/reconciled/${operation.id}`, git([\"rev-parse\", \"HEAD\"])]);\n\t\t\toperation.phase = \"restoring\";\n\t\t\tsave(record);\n\t\t}\n\t\tif (!operation.resultHead || !operation.resultIndex)\n\t\t\tthrow new Error(\"Incomplete reconciliation result\");\n\t\tif (record.joinParent && !ancestor(git, record.joinParent, operation.resultHead)) {\n\t\t\t// The net repair was replayed against the current source. Retain the target\n\t\t\t// ancestry without re-merging (and thereby losing the replayed resolution).\n\t\t\toperation.resultHead = git(\n\t\t\t\t[\n\t\t\t\t\t\"commit-tree\",\n\t\t\t\t\tgit([\"rev-parse\", `${operation.resultHead}^{tree}`]),\n\t\t\t\t\t\"-p\",\n\t\t\t\t\toperation.resultHead,\n\t\t\t\t\t\"-p\",\n\t\t\t\t\trecord.joinParent,\n\t\t\t\t\t\"-m\",\n\t\t\t\t\t\"Integrate target branch with concurrent source changes\",\n\t\t\t\t],\n\t\t\t\tintegrationIdentityEnv(record.joinIdentity),\n\t\t\t);\n\t\t\tgit([\n\t\t\t\t\"update-ref\",\n\t\t\t\t`refs/leitwerk/target-integrations/${operation.id}`,\n\t\t\t\toperation.resultHead,\n\t\t\t]);\n\t\t\tsave(record);\n\t\t}\n\t\tconst integrated = git([\"rev-parse\", `refs/leitwerk/reconciled/${operation.id}`]);\n\t\tconst currentHead = git([\"rev-parse\", \"HEAD\"]);\n\t\tconst currentIndex = git([\"write-tree\"]);\n\t\tif (\n\t\t\t![operation.resultHead, integrated].includes(currentHead) ||\n\t\t\t![operation.resultIndex, git([\"rev-parse\", `${integrated}^{tree}`])].includes(currentIndex)\n\t\t)\n\t\t\tthrow new Error(\n\t\t\t\t\"Checkout changed during interrupted restoration; local work and recovery refs were retained\",\n\t\t\t);\n\t\tgit([\"update-ref\", `refs/heads/${input.workBranch}`, operation.resultHead, currentHead]);\n\t\tgit([\"read-tree\", operation.resultIndex]);\n\t\trecord.baseline = operation.remote;\n\t\tdelete record.operation;\n\t\tdelete record.joinParent;\n\t\tdelete record.joinIdentity;\n\t\tsave(record);\n\t\tassertIgnoredProtection(git, record.protectedIgnored);\n\t\treturn {\n\t\t\tstatus: \"reconciled\",\n\t\t\tremoteHead: target ? null : operation.remote,\n\t\t\theadSha: operation.resultHead,\n\t\t};\n\t});\n}\n\n/** Reject ignored-file collisions before a target checkout/rebase can overwrite them. @internal */\nexport function assertReconciliationTargetSafe(\n\tinput: Pick<ReconciliationInput, \"repoPath\" | \"projectKey\">,\n\ttargetSha: string,\n): void {\n\tconst { git, read } = repository(input);\n\tassertIgnoredProtection(git, read()?.protectedIgnored);\n\tif (ignoredPathsCollide(git, ignoredPaths(git), targetSha, `${targetSha}..HEAD`))\n\t\tthrow new Error(\"Target changes collide with ignored files; local files were retained\");\n}\n\n/** Preserve a target rebase as a net local delta when its source lease changes. @internal */\nexport function retainConcurrentRebase(\n\tinput: ReconciliationInput & {\n\t\trebasedHead: string;\n\t\ttargetBase: string;\n\t\tgitIdentity: GitIdentity;\n\t},\n): void {\n\tconst { git, directory, read, save, binding: readBinding } = repository(input);\n\twithLock(directory, () => {\n\t\tconst old = read();\n\t\tif (old?.operation || old?.sourceIntegration)\n\t\t\tthrow new Error(\"Source reconciliation is already in progress\");\n\t\tif (\n\t\t\tgit([\"branch\", \"--show-current\"]) !== input.workBranch ||\n\t\t\tgit([\"rev-parse\", \"HEAD\"]) !== input.rebasedHead ||\n\t\t\tgit([\"status\", \"--porcelain\"])\n\t\t)\n\t\t\tthrow new Error(\n\t\t\t\t\"Target rebase changed before source reconciliation; local work was retained\",\n\t\t\t);\n\t\tconst binding = readBinding(input.workBranch);\n\t\tif (!repositoryBindingMatches(old, binding))\n\t\t\tthrow new Error(\"Repository reconciliation binding changed\");\n\t\tconst identity = integrationIdentityEnv(input.gitIdentity);\n\t\tconst id = randomUUID();\n\t\tgit([\"update-ref\", `refs/leitwerk/target-repairs/${id}`, input.rebasedHead]);\n\t\tconst replacement = git(\n\t\t\t[\n\t\t\t\t\"commit-tree\",\n\t\t\t\tgit([\"rev-parse\", `${input.rebasedHead}^{tree}`]),\n\t\t\t\t\"-p\",\n\t\t\t\tinput.baselineSha,\n\t\t\t\t\"-m\",\n\t\t\t\t\"Reconcile target-branch repair\",\n\t\t\t],\n\t\t\tidentity,\n\t\t);\n\t\tgit([\"update-ref\", `refs/leitwerk/target-deltas/${id}`, replacement]);\n\t\t// The original source tree is the merge baseline, not the old target branch.\n\t\t// This preserves developer deletions as well as the agent's conflict resolution.\n\t\tsave({\n\t\t\t...binding,\n\t\t\tbaseline: input.baselineSha,\n\t\t\tremoteSeen: true,\n\t\t\tjoinParent: input.targetBase,\n\t\t\tjoinIdentity: input.gitIdentity,\n\t\t\tprotectedIgnored: old?.protectedIgnored,\n\t\t\tpublicationReceiptSha: old?.publicationReceiptSha,\n\t\t\tsourceIntegration: { previous: input.rebasedHead, replacement },\n\t\t});\n\t});\n}\n\n/** @internal */\nexport function repositoryWorktreeIsDirty(\n\tinput: Pick<ReconciliationInput, \"repoPath\" | \"projectKey\">,\n): boolean {\n\treturn Boolean(repository(input).git([\"status\", \"--porcelain\"]));\n}\n\n/** Capture the baseline before the first implementation, including an unpublished branch. @internal */\nexport function prepareInitialRepository(\n\tinput: Omit<WorkBranchInput, \"baselineSha\">,\n): ReconciliationResult {\n\treturn reconcile(input, true);\n}\n\n/** Missing branches are allowed only before first publication. @internal */\nexport function reconcilePublicationRepository(input: WorkBranchInput): ReconciliationResult {\n\treturn reconcile(input, false);\n}\n\n/** Record only a remotely verified publication, including recovery after a lost reply. @internal */\nexport function recordRepositoryPublication(\n\tinput: Omit<ReconciliationInput, \"baselineSha\" | \"gitIdentity\">,\n\theadSha: string,\n): void {\n\tconst { directory, read, save, binding: readBinding } = repository(input);\n\twithLock(directory, () => {\n\t\tconst old = read();\n\t\tif (old?.operation) throw new Error(\"Cannot acknowledge publication during reconciliation\");\n\t\tconst binding = readBinding(input.workBranch);\n\t\tif (!repositoryBindingMatches(old, binding))\n\t\t\tthrow new Error(\"Repository reconciliation binding changed\");\n\t\tsave({\n\t\t\t...binding,\n\t\t\tbaseline: headSha,\n\t\t\tpublicationReceiptSha: headSha,\n\t\t\tremoteSeen: true,\n\t\t\tprotectedIgnored: old?.protectedIgnored,\n\t\t});\n\t});\n}\n\n/** @internal */\nexport const reconciliationPrompt = `Repository synchronization preserves the current remote source branch and unpublished local work. If preparation left a rebase in progress, inspect git status and .git/leitwerk-reconciliation.json. Resolve conflicts preserving both intended changes and the original authors/sign-offs, then git add and GIT_EDITOR=true git rebase --continue until complete. Use the captured operation.identity for the committer when continuing, if present. Do not skip commits, remove the two Leitwerk checkpoint commits, reset, abort, or push. Checkpoint commits will be removed automatically by delivery; do not amend them. After resolving, finish with the turn's required success outcome so delivery can restore the ordinary checkout and request validation. If blocked, use cannot_repair when available or abort_turn otherwise, and retain the checkout. When no rebase is active, perform the requested adjustment and validate the combined result against the current repository instructions before the required success outcome. Never publish without validation after reconciliation.`;\n","import { asUnknownRecord, trimString as normalizeMessage } from \"@leitwerk-dev/domain\";\nimport {\n\ttype Codec,\n\ttype ExternalActionSource,\n\ttype FlowFragmentBuilder,\n\ttype FormDefinition,\n\tflow,\n\thumanTurn,\n\ttype ProcessLauncherDefinition,\n\ttype RepositoryCredentialProject,\n\ttype RepositoryCredentialRequirement,\n\trevisionAction,\n} from \"@leitwerk-dev/process-sdk\";\nimport { codingActionIds, requestRevisionForm } from \"./actions.js\";\nimport {\n\ttype RepositoryChangeState,\n\trepositoryChangeStateCodec,\n} from \"./repository-change-state-internal.js\";\nimport { prepareInitialRepository, reconciliationPrompt } from \"./repository-reconciliation.js\";\nimport { codingPurposes } from \"./settings.js\";\nimport { prepareRepositoryCommitMessageEvidence } from \"./turns/commit-message-evidence.js\";\nimport {\n\tbuildRepositoryCommitMessagesPrompt,\n\tparseRepositoryCommitMessages,\n} from \"./turns/generate-commit-message.js\";\nimport { buildGeneratePlanPrompt } from \"./turns/generate-plan.js\";\nimport { buildImplementPrompt } from \"./turns/implement.js\";\nimport { buildStreamlinedSimplificationPrompt } from \"./turns/simplify-implementation.js\";\n\n/** @public */\nexport type RepositoryChangeParams = object;\n\n/** Server-side policies evaluated at the route boundary. @public */\nexport interface RepositoryChangeWorkflow<TParams> {\n\t/** @deprecated All repository changes use the streamlined graph. @public */\n\tvariant?: \"streamlined\";\n\t/** @public */\n\tmultiRepository?: boolean;\n\t/** Refresh a clean, unpublished checkout against its target before implementation. @public */\n\trefreshTargetBeforeImplementation?: boolean;\n\t/** @public */\n\tplanDecision?(params: TParams): Promise<{\n\t\t/** @internal */\n\t\tskip: boolean;\n\t\t/** @internal */\n\t\treason: string;\n\t}>;\n\t/** @public */\n\tsimplification?(params: TParams): Promise<{\n\t\t/** @internal */\n\t\tskip: boolean;\n\t\t/** @internal */\n\t\treason: string;\n\t}>;\n\t/** Must recheck the current revision and source before firing. @public */\n\tplanBypassSource?: ExternalActionSource<TParams, RepositoryChangeState, unknown>;\n}\n\n/** @public */\nexport interface RepositoryChangeProcessConfig<TParams extends RepositoryChangeParams> {\n\t/** @public */\n\tprocessId: string;\n\t/** @public */\n\tdisplayName: string;\n\t/** @public */\n\tworkflow?: RepositoryChangeWorkflow<TParams>;\n\t/** @public */\n\tparamsCodec: Codec<TParams>;\n\t/** @public */\n\tlauncher?: ProcessLauncherDefinition<TParams>;\n\t/** @deprecated Publication follows implementation automatically. @public */\n\tfinalizeLabel?: string;\n\t/** @deprecated Publication follows implementation automatically. @public */\n\tfinalizeForm?: FormDefinition;\n\t/** @public */\n\trepositoryCredentials?(input: {\n\t\t/** @public */\n\t\tparams: TParams;\n\t\t/** @internal */\n\t\tprojects: readonly RepositoryCredentialProject[];\n\t}): readonly RepositoryCredentialRequirement[];\n\t/** @public */\n\tpublication: {\n\t\t/** @public */\n\t\tentryTurnId: string;\n\t\t/** @public */\n\t\tfragment: FlowFragmentBuilder<TParams, RepositoryChangeState>;\n\t\t/** @public */\n\t\thappyPath?: readonly string[];\n\t};\n}\n\n/** @public */\nexport function createRepositoryChangeProcess<TParams extends RepositoryChangeParams>(\n\tconfig: RepositoryChangeProcessConfig<TParams>,\n) {\n\tconst tools = [\"read\", \"bash\", \"edit\", \"write\"] as const;\n\tconst planDecision = humanTurn<TParams, RepositoryChangeState>({\n\t\tdescription: \"Review Plan\",\n\t\treviewSemanticRef: \"plan\",\n\t\tnotesFields: [\n\t\t\t{\n\t\t\t\tid: \"message\",\n\t\t\t\tlabel: \"Revision notes\",\n\t\t\t\tplaceholder: \"Describe what the next plan revision should improve\",\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t],\n\t\tcommentary: \"Approve this plan or request a revision with comments.\",\n\t\tactions: {\n\t\t\t[codingActionIds.approvePlan]: {\n\t\t\t\tlabel: \"Approve plan\",\n\t\t\t\tdescription: \"Accept the current plan and continue into implementation.\",\n\t\t\t\tacceptanceState: \"accepted\",\n\t\t\t\tto: \"implement\",\n\t\t\t\teffect: ({ ctx }) => {\n\t\t\t\t\tif (!ctx.state.semanticEntryRefs.plan?.turnRecordId?.trim())\n\t\t\t\t\t\tthrow new Error(\"No plan is available for approval\");\n\t\t\t\t\treturn {\n\t\t\t\t\t\temit: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\ttype: \"plan_approved\",\n\t\t\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\t\t\texternalId: ctx.process.externalId,\n\t\t\t\t\t\t\t\t\tplanRevision: ctx.process.planRevision,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t};\n\t\t\t\t},\n\t\t\t},\n\t\t\t[codingActionIds.requestRevision]: revisionAction({\n\t\t\t\tlabel: \"Request revision\",\n\t\t\t\tdescription: \"Send the plan back for another draft revision.\",\n\t\t\t\tacceptanceState: \"requires_changes\",\n\t\t\t\tform: requestRevisionForm,\n\t\t\t\tschedulable: true,\n\t\t\t\tto: \"generate_plan\",\n\t\t\t\tqueueTarget: { semanticRef: \"currentPrimaryPathLeaf\" },\n\t\t\t\teffect: ({ input }) => ({\n\t\t\t\t\temit: [\n\t\t\t\t\t\t{ type: \"plan_revision_requested\", data: { message: normalizeMessage(input.message) } },\n\t\t\t\t\t],\n\t\t\t\t}),\n\t\t\t}),\n\t\t},\n\t});\n\tif (config.workflow?.planBypassSource)\n\t\tplanDecision.externalActions = {\n\t\t\tbypass_plan: {\n\t\t\t\tid: \"bypass_plan\",\n\t\t\t\tlabel: \"Skip plan approval\",\n\t\t\t\tsource: config.workflow.planBypassSource,\n\t\t\t\tto: \"implement\",\n\t\t\t\teffect: ({ state, process, event }) => {\n\t\t\t\t\tif ((event as { planRevision?: number }).planRevision !== process.planRevision)\n\t\t\t\t\t\tthrow new Error(\"Stale plan bypass event\");\n\t\t\t\t\treturn {\n\t\t\t\t\t\tstate: {\n\t\t\t\t\t\t\t...state,\n\t\t\t\t\t\t\trouting: {\n\t\t\t\t\t\t\t\t...state.routing,\n\t\t\t\t\t\t\t\tplan: { planRevision: process.planRevision, skip: true, reason: \"Jira label\" },\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\temit: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\ttype: \"plan_approved\" as const,\n\t\t\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\t\t\tplanRevision: process.planRevision,\n\t\t\t\t\t\t\t\t\tactor: \"system\",\n\t\t\t\t\t\t\t\t\tbypassed: true,\n\t\t\t\t\t\t\t\t\treason: \"Jira label\",\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t};\n\t\t\t\t},\n\t\t\t},\n\t\t};\n\n\tconst generatePlan = flow\n\t\t.llm<TParams, RepositoryChangeState>(\"generate_plan\")\n\t\t.description(\"Plan\")\n\t\t.executionPurpose(codingPurposes.planning)\n\t\t.tools(\"read\", \"bash\")\n\t\t.askQuestions()\n\t\t.freshPrimary()\n\t\t.buildPrompt(buildGeneratePlanPrompt)\n\t\t.outcomeTool(\"plan_saved\", (tool) =>\n\t\t\ttool\n\t\t\t\t.description(\n\t\t\t\t\t\"Save a finished, implementable plan after resolving design-critical questions. Required investigation and access must be complete. If blocked, use abort_turn. Use ask_questions for operator decisions when available; otherwise decide within the requested scope and document assumptions.\",\n\t\t\t\t)\n\t\t\t\t.requiredString(\"summary\", \"One concise sentence summarizing the proposed plan\")\n\t\t\t\t.requiredStringArray(\n\t\t\t\t\t\"acceptanceCriteria\",\n\t\t\t\t\t\"Requested outcomes for the repository change, without expanding scope\",\n\t\t\t\t)\n\t\t\t\t.routeByState(\n\t\t\t\t\t{\n\t\t\t\t\t\tapproval: {\n\t\t\t\t\t\t\tto: \"plan_decision\",\n\t\t\t\t\t\t\tlabel: \"Approval required\",\n\t\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\t\"When the process policy requires an operator to approve the saved plan.\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\tbypass: {\n\t\t\t\t\t\t\tto: \"implement\",\n\t\t\t\t\t\t\tlabel: \"Skip plan approval\",\n\t\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\t\"When the process policy skips plan approval, for example through the Skip plan approval launcher option.\",\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t({ ctx }) => (ctx.state.routing?.plan?.skip ? \"bypass\" : \"approval\"),\n\t\t\t\t)\n\t\t\t\t.effect(async ({ ctx, event }) => {\n\t\t\t\t\tconst planRevision = ctx.process.planRevision + 1;\n\t\t\t\t\tconst policy = (await config.workflow\n\t\t\t\t\t\t?.planDecision?.(ctx.params)\n\t\t\t\t\t\t.catch(() => ({ skip: false, reason: \"Source unavailable; approval required\" }))) ?? {\n\t\t\t\t\t\tskip: false,\n\t\t\t\t\t\treason: \"Human approval required\",\n\t\t\t\t\t};\n\t\t\t\t\tconst summary = normalizeMessage(event.params.summary);\n\t\t\t\t\tconst acceptanceCriteria = Array.isArray(event.params.acceptanceCriteria)\n\t\t\t\t\t\t? event.params.acceptanceCriteria.filter(\n\t\t\t\t\t\t\t\t(entry): entry is string => typeof entry === \"string\" && entry.trim() !== \"\",\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t: [];\n\t\t\t\t\treturn {\n\t\t\t\t\t\tstate: {\n\t\t\t\t\t\t\t...ctx.state,\n\t\t\t\t\t\t\trouting: { ...ctx.state.routing, plan: { ...policy, planRevision } },\n\t\t\t\t\t\t},\n\t\t\t\t\t\tprocessPatch: { planRevision },\n\t\t\t\t\t\tbroadcasts: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\ttype: \"plan.updated\",\n\t\t\t\t\t\t\t\tpayload: {\n\t\t\t\t\t\t\t\t\tplanRevision,\n\t\t\t\t\t\t\t\t\treviewState: policy.skip ? \"accepted\" : \"awaiting_approval\",\n\t\t\t\t\t\t\t\t\tapproved: policy.skip,\n\t\t\t\t\t\t\t\t\tsummary,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t\temit: [\n\t\t\t\t\t\t\t...(policy.skip\n\t\t\t\t\t\t\t\t? [\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\ttype: \"plan_approved\" as const,\n\t\t\t\t\t\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\t\t\t\t\t\tplanRevision,\n\t\t\t\t\t\t\t\t\t\t\t\tactor: \"system\",\n\t\t\t\t\t\t\t\t\t\t\t\tbypassed: true,\n\t\t\t\t\t\t\t\t\t\t\t\treason: policy.reason,\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t]\n\t\t\t\t\t\t\t\t: []),\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\ttype: \"plan_saved\",\n\t\t\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\t\t\tplanRevision,\n\t\t\t\t\t\t\t\t\tsummary,\n\t\t\t\t\t\t\t\t\tplanMarkdown: ctx.output?.content ?? \"\",\n\t\t\t\t\t\t\t\t\tacceptanceCriteria,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t};\n\t\t\t\t}),\n\t\t)\n\t\t.publish(\"plan\");\n\tconst refreshTarget = config.workflow?.refreshTargetBeforeImplementation;\n\tconst implement = flow\n\t\t.llm<TParams, RepositoryChangeState>(\"implement\")\n\t\t.description(\"Implement\")\n\t\t.waitFor(({ state }) => !!state.productRefs.plan)\n\t\t.executionPurpose(codingPurposes.implementation)\n\t\t.tools(...tools)\n\t\t.freshSeededPrimary()\n\t\t.startFromRoot()\n\t\t.consume(\"plan\")\n\t\t.prepare((ctx) => ({\n\t\t\treconciliation: ctx.repo.all().map((repo) => {\n\t\t\t\tconst identity = asUnknownRecord(\n\t\t\t\t\tctx.projects.find((p) => p.key === repo.key)?.metadata?.[\"leitwerk.gitIdentity\"],\n\t\t\t\t);\n\t\t\t\treturn prepareInitialRepository({\n\t\t\t\t\tprojectKey: repo.key,\n\t\t\t\t\trepoPath: repo.fsPath,\n\t\t\t\t\tworkBranch: repo.workBranch,\n\t\t\t\t\tbaseBranch: refreshTarget ? repo.baseBranch : undefined,\n\t\t\t\t\tgitIdentity:\n\t\t\t\t\t\ttypeof identity?.name === \"string\" && typeof identity.email === \"string\"\n\t\t\t\t\t\t\t? { name: identity.name, email: identity.email }\n\t\t\t\t\t\t\t: undefined,\n\t\t\t\t});\n\t\t\t}),\n\t\t}))\n\t\t.buildPrompt((ctx) => `${buildImplementPrompt(ctx, refreshTarget)}\\n\\n${reconciliationPrompt}`)\n\t\t.outcomeTool(\"implementation_ready\", (tool) =>\n\t\t\ttool\n\t\t\t\t.description(\"Implementation and checks are complete; continue to delivery\")\n\t\t\t\t.routeByState(\n\t\t\t\t\t{\n\t\t\t\t\t\tsimplify: {\n\t\t\t\t\t\t\tto: \"simplify_implementation\",\n\t\t\t\t\t\t\tlabel: \"Simplification enabled\",\n\t\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\t\"When the process policy enables simplification. This is the default unless a launcher option or source policy skips it.\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\tskip: {\n\t\t\t\t\t\t\tto: \"generate_commit_message\",\n\t\t\t\t\t\t\tlabel: \"Skip simplification\",\n\t\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\t\"When simplification is skipped, for example through the Skip simplification launcher option or the leitwerk-skip-simplification source label.\",\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t({ ctx }) => (ctx.state.routing?.simplification?.skip ? \"skip\" : \"simplify\"),\n\t\t\t\t)\n\t\t\t\t.effect(async ({ ctx }) => ({\n\t\t\t\t\tstate: {\n\t\t\t\t\t\t...ctx.state,\n\t\t\t\t\t\trouting: {\n\t\t\t\t\t\t\t...ctx.state.routing,\n\t\t\t\t\t\t\tsimplification: ctx.state.routing?.simplification ??\n\t\t\t\t\t\t\t\t(await config.workflow?.simplification?.(ctx.params)) ?? {\n\t\t\t\t\t\t\t\t\tskip: false,\n\t\t\t\t\t\t\t\t\treason: \"Simplification enabled by default\",\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t})),\n\t\t)\n\t\t.publish(\"implementation-summary\");\n\tconst simplify = flow\n\t\t.llm<TParams, RepositoryChangeState>(\"simplify_implementation\")\n\t\t.description(\"Simplify\")\n\t\t.executionPurpose(codingPurposes.review)\n\t\t.tools(\"read\", \"bash\")\n\t\t.rootBranchReview()\n\t\t.startFromProductBranch(\"simplification-plan\")\n\t\t.buildPrompt(buildStreamlinedSimplificationPrompt)\n\t\t.publish(\"simplification-plan\")\n\t\t.to(\"apply_simplification\");\n\tconst applySimplification = flow\n\t\t.llm<TParams, RepositoryChangeState>(\"apply_simplification\")\n\t\t.description(\"Apply simplification\")\n\t\t.executionPurpose(codingPurposes.implementation)\n\t\t.tools(...tools)\n\t\t.freshSeededPrimary()\n\t\t.consume(\"plan\")\n\t\t.consume(\"simplification-plan\")\n\t\t.buildPrompt(\n\t\t\t(\n\t\t\t\tctx,\n\t\t\t) => `Apply justified simplifications to each repository, preserving the accepted plan and behavior. Rerun the required checks. Empty findings require no edits. Leave changes uncommitted for delivery.\n\nAccepted plan:\n${ctx.input.plan}\n\nFindings by repository:\n${ctx.input[\"simplification-plan\"]}`,\n\t\t)\n\t\t.publish(\"implementation-summary\")\n\t\t.to(\"generate_commit_message\");\n\tconst generateCommitMessage = flow\n\t\t.llm<TParams, RepositoryChangeState>(\"generate_commit_message\")\n\t\t.description(\"Write Commit Message\")\n\t\t.executionPurpose(codingPurposes.implementation)\n\t\t.tools(\"read\", \"grep\", \"find\", \"ls\")\n\t\t.rootBranchReview()\n\t\t.startFromRoot()\n\t\t.consume(\"plan\")\n\t\t.consume(\"implementation-summary\")\n\t\t.prepare(prepareRepositoryCommitMessageEvidence)\n\t\t.buildPrompt(buildRepositoryCommitMessagesPrompt)\n\t\t.publish(\"commit-message\")\n\t\t.to(config.publication.entryTurnId)\n\t\t.state(({ ctx }) => ({\n\t\t\t...ctx.state,\n\t\t\tfinalization: {\n\t\t\t\t...ctx.state.finalization,\n\t\t\t\tcommitMessages: parseRepositoryCommitMessages(\n\t\t\t\t\tctx.output?.content,\n\t\t\t\t\tctx.projects.map((p) => p.key),\n\t\t\t\t),\n\t\t\t},\n\t\t}));\n\tconst builder = flow\n\t\t.process<TParams, RepositoryChangeState>(config.processId)\n\t\t.displayName(config.displayName)\n\t\t.entry(\"generate_plan\")\n\t\t.happyPath(\n\t\t\t\"generate_plan\",\n\t\t\t\"implement\",\n\t\t\t\"simplify_implementation\",\n\t\t\t\"apply_simplification\",\n\t\t\t\"generate_commit_message\",\n\t\t\t...(config.publication.happyPath ?? [config.publication.entryTurnId]),\n\t\t)\n\t\t.piConfig(config.workflow?.multiRepository ? {} : { sessionCwdTemplate: \"{{{projectKey}}}\" })\n\t\t.codecs({ params: config.paramsCodec, state: repositoryChangeStateCodec })\n\t\t.initialState(() => repositoryChangeStateCodec.parse({}))\n\t\t.turn(generatePlan)\n\t\t.turn({ id: \"plan_decision\", definition: planDecision })\n\t\t.turn(implement)\n\t\t.turn(simplify)\n\t\t.turn(applySimplification)\n\t\t.turn(generateCommitMessage)\n\t\t.use(config.publication.fragment);\n\tif (config.repositoryCredentials) builder.repositoryCredentials(config.repositoryCredentials);\n\tif (config.launcher) builder.launcher(config.launcher);\n\treturn {\n\t\t/** @public */\n\t\tprocess: builder.define(),\n\t};\n}\n","import type { Codec, StructuralProcessState } from \"@leitwerk-dev/process-sdk\";\nimport { parseStructuralProcessState } from \"@leitwerk-dev/process-sdk\";\n\n/** @public */\nexport interface RepositoryChangeFinalizationState {\n\t/** @public */\n\tgeneratedCommitMessage: string | null;\n\t/** Messages keyed by process project key. @public */\n\tcommitMessages?: Record<string, string>;\n}\n\n/** @public */\nexport interface RepositoryChangeState extends StructuralProcessState {\n\t/** @public */\n\tfinalization: RepositoryChangeFinalizationState;\n\t/** Completed routing decisions survive recovery. @public */\n\trouting?: {\n\t\t/** @public */\n\t\tplan?: {\n\t\t\t/** @internal */\n\t\t\tplanRevision: number;\n\t\t\t/** @internal */ skip: boolean;\n\t\t\t/** @internal */ reason: string;\n\t\t};\n\n\t\t/** @public */\n\t\tsimplification?: {\n\t\t\t/** @internal */\n\t\t\tskip: boolean;\n\t\t\t/** @internal */ reason: string;\n\t\t};\n\t};\n\t/** Namespaced state owned by a caller-supplied publication workflow. */\n\n\t/** @public */\n\textensionState?: Record<string, unknown>;\n}\n\nfunction toRecord(value: unknown): Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null ? (value as Record<string, unknown>) : {};\n}\n\nfunction parseFinalizationState(value: unknown): RepositoryChangeFinalizationState {\n\tconst record = toRecord(value);\n\treturn {\n\t\tgeneratedCommitMessage:\n\t\t\ttypeof record.generatedCommitMessage === \"string\" ? record.generatedCommitMessage : null,\n\t\t...(record.commitMessages\n\t\t\t? {\n\t\t\t\t\tcommitMessages: Object.fromEntries(\n\t\t\t\t\t\tObject.entries(toRecord(record.commitMessages)).filter(\n\t\t\t\t\t\t\t(entry): entry is [string, string] => typeof entry[1] === \"string\",\n\t\t\t\t\t\t),\n\t\t\t\t\t),\n\t\t\t\t}\n\t\t\t: {}),\n\t};\n}\n\n/** @internal */\nexport const repositoryChangeStateCodec: Codec<RepositoryChangeState> = {\n\tparse(value) {\n\t\tconst record = toRecord(value);\n\t\treturn {\n\t\t\t...parseStructuralProcessState(record),\n\t\t\tfinalization: parseFinalizationState(record.finalization),\n\t\t\textensionState: toRecord(record.extensionState),\n\t\t\trouting: toRecord(record.routing) as RepositoryChangeState[\"routing\"],\n\t\t};\n\t},\n\tserialize(value) {\n\t\treturn value;\n\t},\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAGO,IAAM,kBAAkB;AAAA;AAAA,EAE9B,aAAa;AAAA;AAAA,EAEb,iBAAiB;AAAA;AAAA,EAEjB,WAAW;AAAA;AAAA,EAEX,UAAU;AAAA;AAAA,EAEV,cAAc;AAAA;AAAA,EAEd,sBAAsB;AAAA;AAAA,EAEtB,eAAe;AAAA;AAAA,EAEf,gBAAgB;AACjB;AAEA,SAAS,UAAU,IAAY,OAAe,OAAe,aAAqC;AACjG,SAAO;AAAA,IACN;AAAA,IACA;AAAA,IACA,QAAQ;AAAA,MACP,EAAE,IAAI,WAAW,OAAO,MAAM,YAAY,eAAe,MAAM,UAAU,MAAM,YAAY;AAAA,IAC5F;AAAA,IACA,aAAa;AAAA,EACd;AACD;AAGO,IAAM,sBAAsB;AAAA,EAClC,gBAAgB;AAAA,EAChB;AAAA,EACA;AAAA,EACA;AACD;AAEO,IAAM,2BAA2B;AAAA,EACvC,gBAAgB;AAAA,EAChB;AAAA,EACA;AAAA,EACA;AACD;AAEO,IAAM,mBAAmC;AAAA,EAC/C,IAAI,gBAAgB;AAAA,EACpB,OAAO;AAAA,EACP,QAAQ;AAAA,IACP;AAAA,MACC,IAAI;AAAA,MACJ,OAAO;AAAA,MACP,MAAM;AAAA,MACN,eAAe;AAAA,MACf,aACC;AAAA,IACF;AAAA,EACD;AAAA,EACA,aAAa;AACd;;;AC9DA,SAAS,oBAAoB;AAC7B,SAAS,kBAAkB;AAC3B,SAAS,YAAY,WAAW,cAAc,QAAQ,qBAAqB;AAC3E,SAAS,gBAAgB;AACzB,SAAS,YAAY;AACrB,SAAS,mBAAmB,kCAAkC;AAC9D,SAAS,wBAAwB;AA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AAA,EACpE,EACC,SAAS,OAAO,UAAU,kBAAkB,CAAC,IAAI,EAAE,oBAAoB,mBAAmB,CAAC,EAC3F,OAAO,EAAE,QAAQ,OAAO,aAAa,OAAO,2BAA2B,CAAC,EACxE,aAAa,MAAM,2BAA2B,MAAM,CAAC,CAAC,CAAC,EACvD,KAAK,YAAY,EACjB,KAAK,EAAE,IAAI,iBAAiB,YAAY,aAAa,CAAC,EACtD,KAAK,SAAS,EACd,KAAK,QAAQ,EACb,KAAK,mBAAmB,EACxB,KAAK,qBAAqB,EAC1B,IAAI,OAAO,YAAY,QAAQ;AACjC,MAAI,OAAO,sBAAuB,SAAQ,sBAAsB,OAAO,qBAAqB;AAC5F,MAAI,OAAO,SAAU,SAAQ,SAAS,OAAO,QAAQ;AACrD,SAAO;AAAA;AAAA,IAEN,SAAS,QAAQ,OAAO;AAAA,EACzB;AACD;","names":["process"]}
@@ -1,5 +1,5 @@
1
1
  // src/turns/implement.ts
2
- function buildImplementPrompt(ctx) {
2
+ function buildImplementPrompt(ctx, checkPlanFit = false) {
3
3
  return `Implement this requested change:
4
4
  ${ctx.prompts.initial}
5
5
 
@@ -9,13 +9,12 @@ Follow this plan:
9
9
  ${ctx.input.plan}
10
10
 
11
11
  Rules:
12
- - keep going until the change is complete; do any necessary additional passes without asking
12
+ - ${checkPlanFit ? "Before editing, check the plan against the current checkout. Adapt without expanding the approved scope, or stop and explain why if the plan no longer fits. If it fits, " : ""}keep going until the change is complete; do any necessary additional passes without asking
13
13
  - make repository changes only inside the current working directory
14
14
  - run file edits, Git commands, and checks in the appropriate checkout
15
15
  - follow each repository\u2019s instructions and validate every affected repository
16
16
  - leave changes uncommitted; delivery owns commits and pushes
17
17
  - do not read from or write to any original source repository path outside the process workspace
18
- - keep the implementation coherent and complete
19
18
  - keep the number of changed files small
20
19
  - when documenting, be sparse. Do not narrate the implementation or maintain a prose inventory of tests, helpers, internal environment variables, or cleanup mechanics.
21
20
  - publish the implementation summary when done`;
@@ -24,4 +23,4 @@ Rules:
24
23
  export {
25
24
  buildImplementPrompt
26
25
  };
27
- //# sourceMappingURL=chunk-QD6FI4HR.js.map
26
+ //# sourceMappingURL=chunk-PISZZXK4.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/turns/implement.ts"],"sourcesContent":["import type { FlowPromptContext, StructuralProcessState } from \"@leitwerk-dev/process-sdk\";\n\n/** @internal */\nexport function buildImplementPrompt(\n\tctx: Pick<\n\t\tFlowPromptContext<unknown, StructuralProcessState, \"plan\">,\n\t\t\"prompts\" | \"input\" | \"repo\"\n\t>,\n\tcheckPlanFit = false,\n): string {\n\treturn `Implement this requested change:\n${ctx.prompts.initial}\n\nRepository checkouts: ${ctx.repo\n\t\t.all()\n\t\t.map((repo) => `${repo.key}: ${repo.fsPath}`)\n\t\t.join(\"; \")}\n\nFollow this plan:\n${ctx.input.plan}\n\nRules:\n- ${checkPlanFit ? \"Before editing, check the plan against the current checkout. Adapt without expanding the approved scope, or stop and explain why if the plan no longer fits. If it fits, \" : \"\"}keep going until the change is complete; do any necessary additional passes without asking\n- make repository changes only inside the current working directory\n- run file edits, Git commands, and checks in the appropriate checkout\n- follow each repository’s instructions and validate every affected repository\n- leave changes uncommitted; delivery owns commits and pushes\n- do not read from or write to any original source repository path outside the process workspace\n- keep the number of changed files small\n- when documenting, be sparse. Do not narrate the implementation or maintain a prose inventory of tests, helpers, internal environment variables, or cleanup mechanics.\n- publish the implementation summary when done`;\n}\n"],"mappings":";AAGO,SAAS,qBACf,KAIA,eAAe,OACN;AACT,SAAO;AAAA,EACN,IAAI,QAAQ,OAAO;AAAA;AAAA,wBAEG,IAAI,KACzB,IAAI,EACJ,IAAI,CAAC,SAAS,GAAG,KAAK,GAAG,KAAK,KAAK,MAAM,EAAE,EAC3C,KAAK,IAAI,CAAC;AAAA;AAAA;AAAA,EAGX,IAAI,MAAM,IAAI;AAAA;AAAA;AAAA,IAGZ,eAAe,8KAA8K,EAAE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASnM;","names":[]}
@@ -102,11 +102,7 @@ function repositoryGit(projectKey, repoPath) {
102
102
  if (workingTreeStatus().length === 0) return git("rev-parse", "HEAD");
103
103
  assertGitIdentity(identity);
104
104
  checkedGit(["add", "--all"], "Failed to stage the completed change");
105
- checkedGit(
106
- ["-c", "core.hooksPath=/dev/null", "commit", "--no-gpg-sign", "-m", commitMessage],
107
- "Failed to commit the completed change",
108
- identity
109
- );
105
+ checkedGit(["commit", "--no-gpg-sign", "-m", commitMessage], "Commit failed", identity);
110
106
  const remaining = workingTreeStatus();
111
107
  if (remaining.length > 0) {
112
108
  throw new DeterministicGitError(`Commit left uncommitted changes: ${remaining.join(", ")}`);
@@ -217,4 +213,4 @@ export {
217
213
  repositoryHasChanges,
218
214
  commitAndPushWorkBranch
219
215
  };
220
- //# sourceMappingURL=chunk-3WJRJ3Q7.js.map
216
+ //# sourceMappingURL=chunk-VG6XF3OK.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/finalization-git-internal.ts"],"sourcesContent":["import { execFileSync } from \"node:child_process\";\nimport { existsSync } from \"node:fs\";\nimport path from \"node:path\";\nimport { trimToNull, type WorkerErrorClass } from \"@leitwerk-dev/domain\";\nimport { repositoryGitArgs, repositoryGitSubprocessEnv } from \"@leitwerk-dev/process-sdk\";\nimport { resolveGitBinary } from \"@leitwerk-dev/process-sdk/git-binary\";\nimport {\n\tpushWasRejected,\n\ttype RepositoryPublicationReceipt,\n\treadPublicationReceipt,\n\treadRepositoryBinding,\n\trepositoryBindingMatches,\n\tsavePublicationReceipt,\n} from \"./repository-publication-receipt.js\";\n\n/** @public */\nexport interface GitIdentity {\n\t/** @public */\n\tname: string;\n\t/** @public */\n\temail: string;\n}\n\n/** @internal */\nexport class DeterministicGitError extends Error {\n\t/** @internal */\n\treadonly errorClass: WorkerErrorClass = \"git_error\";\n\n\t/** @internal */\n\tconstructor(message: string) {\n\t\tsuper(message);\n\t\tthis.name = \"DeterministicGitError\";\n\t}\n}\n\n/** @internal */\nexport class RemoteBranchChangedError extends DeterministicGitError {\n\tconstructor() {\n\t\tsuper(\"The remote source branch changed before publication; reconcile and validate again\");\n\t}\n}\n\ninterface GitExecResult {\n\tok: boolean;\n\tstdout: string;\n\tstderr: string;\n}\n\nfunction gitConfigIdentityEnv(projectKey: string): NodeJS.ProcessEnv {\n\tconst env = repositoryGitSubprocessEnv(projectKey, { GIT_TERMINAL_PROMPT: \"0\" });\n\tfor (const key of [\n\t\t\"GIT_AUTHOR_NAME\",\n\t\t\"GIT_AUTHOR_EMAIL\",\n\t\t\"GIT_AUTHOR_DATE\",\n\t\t\"GIT_COMMITTER_NAME\",\n\t\t\"GIT_COMMITTER_EMAIL\",\n\t\t\"GIT_COMMITTER_DATE\",\n\t])\n\t\tdelete env[key];\n\treturn env;\n}\n\nfunction gitIdentityArgs(identity: GitIdentity): string[] {\n\tconst name = trimToNull(identity.name);\n\tconst email = trimToNull(identity.email);\n\tif (!name || !email || /[\\r\\n\\0]/.test(name) || /[\\r\\n\\0]/.test(email)) {\n\t\tthrow new DeterministicGitError(\"Git identity requires a valid name and email\");\n\t}\n\treturn [\"-c\", `user.name=${name}`, \"-c\", `user.email=${email}`];\n}\n\nfunction repositoryGit(projectKey: string, repoPath: string) {\n\tfunction runGit(args: readonly string[], identity?: GitIdentity): GitExecResult {\n\t\tconst trustedArgs = identity ? [...gitIdentityArgs(identity), ...args] : args;\n\t\ttry {\n\t\t\tconst stdout = execFileSync(resolveGitBinary(), repositoryGitArgs(trustedArgs), {\n\t\t\t\tcwd: repoPath,\n\t\t\t\tencoding: \"utf8\",\n\t\t\t\tenv: gitConfigIdentityEnv(projectKey),\n\t\t\t\tstdio: [\"ignore\", \"pipe\", \"pipe\"],\n\t\t\t});\n\t\t\treturn { ok: true, stdout, stderr: \"\" };\n\t\t} catch (error) {\n\t\t\tconst execError = error as {\n\t\t\t\tstdout?: string | Buffer;\n\t\t\t\tstderr?: string | Buffer;\n\t\t\t\tmessage?: string;\n\t\t\t};\n\t\t\treturn {\n\t\t\t\tok: false,\n\t\t\t\tstdout: execError.stdout?.toString() ?? \"\",\n\t\t\t\tstderr: execError.stderr?.toString() ?? trimToNull(execError.message) ?? \"\",\n\t\t\t};\n\t\t}\n\t}\n\n\tfunction checkedGit(\n\t\targs: readonly string[],\n\t\tfailureMessage: string,\n\t\tidentity?: GitIdentity,\n\t): string {\n\t\tconst result = runGit(args, identity);\n\t\tif (!result.ok) {\n\t\t\tconst detail = trimToNull(result.stderr) ?? trimToNull(result.stdout) ?? \"unknown git error\";\n\t\t\tthrow new DeterministicGitError(`${failureMessage}: ${detail}`);\n\t\t}\n\t\treturn result.stdout.trim();\n\t}\n\n\tfunction git(...args: string[]): string {\n\t\treturn checkedGit(args, `git ${args.join(\" \")} failed in '${repoPath}'`);\n\t}\n\n\tfunction gitOrNull(...args: string[]): string | null {\n\t\tconst result = runGit(args);\n\t\treturn result.ok ? trimToNull(result.stdout) : null;\n\t}\n\n\tfunction workingTreeStatus(): string[] {\n\t\treturn (gitOrNull(\"status\", \"--porcelain\") ?? \"\")\n\t\t\t.split(/\\r?\\n/)\n\t\t\t.map((line) => line.replace(/\\s+$/, \"\"))\n\t\t\t.filter(Boolean)\n\t\t\t.map((line) => line.slice(2).trim())\n\t\t\t.filter(Boolean);\n\t}\n\n\tfunction conflictedFiles(): string[] {\n\t\treturn (gitOrNull(\"diff\", \"--name-only\", \"--diff-filter=U\") ?? \"\")\n\t\t\t.split(/\\r?\\n/)\n\t\t\t.map((line) => line.trim())\n\t\t\t.filter(Boolean);\n\t}\n\n\tfunction mergeInProgress(): boolean {\n\t\tconst gitDir = git(\"rev-parse\", \"--git-dir\");\n\t\treturn existsSync(path.resolve(repoPath, gitDir, \"MERGE_HEAD\"));\n\t}\n\n\tfunction assertGitIdentity(identity: GitIdentity): void {\n\t\tif (\n\t\t\t!runGit([\"var\", \"GIT_AUTHOR_IDENT\"], identity).ok ||\n\t\t\t!runGit([\"var\", \"GIT_COMMITTER_IDENT\"], identity).ok\n\t\t) {\n\t\t\tthrow new DeterministicGitError(\"Git author/committer identity is not configured\");\n\t\t}\n\t}\n\n\tfunction commitIfDirty(commitMessage: string, identity: GitIdentity): string {\n\t\tif (workingTreeStatus().length === 0) return git(\"rev-parse\", \"HEAD\");\n\t\tassertGitIdentity(identity);\n\t\tcheckedGit([\"add\", \"--all\"], \"Failed to stage the completed change\");\n\t\tcheckedGit([\"commit\", \"--no-gpg-sign\", \"-m\", commitMessage], \"Commit failed\", identity);\n\t\tconst remaining = workingTreeStatus();\n\t\tif (remaining.length > 0) {\n\t\t\tthrow new DeterministicGitError(`Commit left uncommitted changes: ${remaining.join(\", \")}`);\n\t\t}\n\t\treturn git(\"rev-parse\", \"HEAD\");\n\t}\n\n\tfunction pushAndVerify(\n\t\tbranch: string,\n\t\texpectedHeadSha: string,\n\t\texpectedRemoteHead?: string | null,\n\t): string {\n\t\tconst ref = `refs/heads/${branch}`;\n\t\tconst pushTarget = `origin/${branch}`;\n\t\tconst observed = git(\"ls-remote\", \"--heads\", \"origin\", ref).split(/\\s+/)[0] || null;\n\t\tconst lease = expectedRemoteHead === undefined ? observed : expectedRemoteHead;\n\t\tconst directory = git(\"rev-parse\", \"--absolute-git-dir\");\n\t\tconst binding = readRepositoryBinding(git, branch);\n\t\tif (binding.origin !== binding.pushOrigin)\n\t\t\tthrow new DeterministicGitError(\"Fetch and push endpoints must match for publication\");\n\t\tconst previous = readPublicationReceipt(directory);\n\t\tif (!repositoryBindingMatches(previous, binding))\n\t\t\tthrow new DeterministicGitError(\"Repository publication receipt binding changed\");\n\t\tconst receipt: RepositoryPublicationReceipt = {\n\t\t\t...binding,\n\t\t\texpectedHead: lease,\n\t\t\tcandidate: expectedHeadSha,\n\t\t\tstatus: \"attempting\",\n\t\t};\n\t\t// Recover a successful push whose acknowledgement was lost.\n\t\tif (observed === expectedHeadSha) {\n\t\t\tsavePublicationReceipt(directory, { ...receipt, status: \"accepted\" });\n\t\t\treturn pushTarget;\n\t\t}\n\t\tif (previous?.status === \"attempting\")\n\t\t\tthrow new DeterministicGitError(\n\t\t\t\t\"A prior publication is unresolved; retain local work and reconcile its exact candidate first\",\n\t\t\t);\n\t\tif (previous?.status === \"accepted\" && previous.candidate === expectedHeadSha)\n\t\t\tthrow new RemoteBranchChangedError();\n\t\tif (observed !== lease) throw new RemoteBranchChangedError();\n\t\tif (lease && !runGit([\"merge-base\", \"--is-ancestor\", lease, expectedHeadSha]).ok)\n\t\t\tthrow new DeterministicGitError(\n\t\t\t\t\"Ordinary publication must preserve the captured remote head\",\n\t\t\t);\n\t\tsavePublicationReceipt(directory, receipt);\n\t\tconst pushed = runGit([\n\t\t\t\"push\",\n\t\t\t\"--porcelain\",\n\t\t\t\"--no-follow-tags\",\n\t\t\t\"--recurse-submodules=no\",\n\t\t\t`--force-with-lease=${ref}:${lease ?? \"\"}`,\n\t\t\t\"origin\",\n\t\t\t`${expectedHeadSha}:${ref}`,\n\t\t]);\n\t\tif (!pushed.ok) {\n\t\t\tif (pushWasRejected(pushed.stdout))\n\t\t\t\tsavePublicationReceipt(directory, { ...receipt, status: \"rejected\" });\n\t\t\tconst latest = git(\"ls-remote\", \"--heads\", \"origin\", ref).split(/\\s+/)[0] || null;\n\t\t\tif (latest === expectedHeadSha) {\n\t\t\t\tsavePublicationReceipt(directory, { ...receipt, status: \"accepted\" });\n\t\t\t\treturn pushTarget;\n\t\t\t}\n\t\t\tif (latest !== lease) throw new RemoteBranchChangedError();\n\t\t\tthrow new DeterministicGitError(`Failed to push HEAD to '${pushTarget}': ${pushed.stderr}`);\n\t\t}\n\t\tsavePublicationReceipt(directory, { ...receipt, status: \"accepted\" });\n\t\tconst remoteHead = gitOrNull(\"ls-remote\", \"--heads\", \"origin\", ref)?.split(/\\s+/)[0]?.trim();\n\t\tif (remoteHead !== expectedHeadSha) throw new RemoteBranchChangedError();\n\t\treturn pushTarget;\n\t}\n\n\treturn { runGit, git, conflictedFiles, mergeInProgress, commitIfDirty, pushAndVerify };\n}\n\n/** Inspect staged, unstaged, untracked, and already committed unpublished changes. @public */\nexport function repositoryHasChanges(\n\trepoPath: string,\n\tbaseBranch: string,\n\tprojectKey = \"repo\",\n): boolean {\n\tconst { git } = repositoryGit(projectKey, repoPath);\n\treturn Boolean(\n\t\tgit(\"status\", \"--porcelain\") || git(\"diff\", \"--name-only\", `origin/${baseBranch}...HEAD`),\n\t);\n}\n\n/** Commit the current workspace change and non-force push only the feature branch. */\n/** @public */\nexport function commitAndPushWorkBranch(input: {\n\t/** @public */ projectKey?: string;\n\t/** @public */\n\trepoPath: string;\n\t/** @public */\n\tworkBranch: string;\n\t/** @public */\n\tcommitMessage: string;\n\t/** @public */\n\tgitIdentity: GitIdentity;\n\t/** Captured remote head; null requires branch creation. @internal */\n\texpectedRemoteHead?: string | null;\n}) {\n\tconst repoPath = path.resolve(input.repoPath);\n\tconst { runGit, git, conflictedFiles, mergeInProgress, commitIfDirty, pushAndVerify } =\n\t\trepositoryGit(input.projectKey ?? \"repo\", repoPath);\n\tif (!existsSync(repoPath) || !runGit([\"rev-parse\", \"--git-dir\"]).ok) {\n\t\tthrow new DeterministicGitError(\n\t\t\t`Repository workspace '${repoPath}' does not exist or is not a git repository`,\n\t\t);\n\t}\n\tconst branch = git(\"branch\", \"--show-current\");\n\tif (branch !== input.workBranch) {\n\t\tthrow new DeterministicGitError(\n\t\t\t`Expected '${repoPath}' to be checked out on '${input.workBranch}', but found '${branch || \"detached HEAD\"}'`,\n\t\t);\n\t}\n\tif (!trimToNull(input.commitMessage)) {\n\t\tthrow new DeterministicGitError(\"A generated commit message is required before publication\");\n\t}\n\tconst conflicts = conflictedFiles();\n\tif (mergeInProgress() || conflicts.length > 0) {\n\t\tthrow new DeterministicGitError(\n\t\t\t`Cannot publish a work branch with unresolved conflicts: ${conflicts.join(\", \") || \"merge in progress\"}`,\n\t\t);\n\t}\n\tconst headSha = commitIfDirty(input.commitMessage, input.gitIdentity);\n\treturn {\n\t\t/** @public */\n\t\thead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N;AAAA;AAAA,IAEA,YAAY,cAAc,MAAM,YAAY,SAAS,MAAM,kBAAkB;AAAA,EAC9E;AACD;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"finalization-git-internal.d.ts","sourceRoot":"","sources":["../src/finalization-git-internal.ts"],"names":[],"mappings":"AAGA,OAAO,EAAc,KAAK,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAYzE,cAAc;AACd,MAAM,WAAW,WAAW;IAC3B,cAAc;IACd,IAAI,EAAE,MAAM,CAAC;IACb,cAAc;IACd,KAAK,EAAE,MAAM,CAAC;CACd;AAED,gBAAgB;AAChB,qBAAa,qBAAsB,SAAQ,KAAK;IAC/C,gBAAgB;IAChB,QAAQ,CAAC,UAAU,EAAE,gBAAgB,CAAe;IAEpD,gBAAgB;gBACJ,OAAO,EAAE,MAAM;CAI3B;AAED,gBAAgB;AAChB,qBAAa,wBAAyB,SAAQ,qBAAqB;;CAIlE;AAgMD,8FAA8F;AAC9F,wBAAgB,oBAAoB,CACnC,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,EAClB,UAAU,SAAS,GACjB,OAAO,CAKT;AAED,sFAAsF;AACtF,cAAc;AACd,wBAAgB,uBAAuB,CAAC,KAAK,EAAE;IAC9C,cAAc,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IACnC,cAAc;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc;IACd,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc;IACd,WAAW,EAAE,WAAW,CAAC;IACzB,qEAAqE;IACrE,kBAAkB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACnC;IA0BC,cAAc;;IAEd,gBAAgB;;EAGjB"}
1
+ {"version":3,"file":"finalization-git-internal.d.ts","sourceRoot":"","sources":["../src/finalization-git-internal.ts"],"names":[],"mappings":"AAGA,OAAO,EAAc,KAAK,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAYzE,cAAc;AACd,MAAM,WAAW,WAAW;IAC3B,cAAc;IACd,IAAI,EAAE,MAAM,CAAC;IACb,cAAc;IACd,KAAK,EAAE,MAAM,CAAC;CACd;AAED,gBAAgB;AAChB,qBAAa,qBAAsB,SAAQ,KAAK;IAC/C,gBAAgB;IAChB,QAAQ,CAAC,UAAU,EAAE,gBAAgB,CAAe;IAEpD,gBAAgB;gBACJ,OAAO,EAAE,MAAM;CAI3B;AAED,gBAAgB;AAChB,qBAAa,wBAAyB,SAAQ,qBAAqB;;CAIlE;AA4LD,8FAA8F;AAC9F,wBAAgB,oBAAoB,CACnC,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,EAClB,UAAU,SAAS,GACjB,OAAO,CAKT;AAED,sFAAsF;AACtF,cAAc;AACd,wBAAgB,uBAAuB,CAAC,KAAK,EAAE;IAC9C,cAAc,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IACnC,cAAc;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc;IACd,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc;IACd,WAAW,EAAE,WAAW,CAAC;IACzB,qEAAqE;IACrE,kBAAkB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACnC;IA0BC,cAAc;;IAEd,gBAAgB;;EAGjB"}
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  commitAndPushWorkBranch,
3
3
  repositoryHasChanges
4
- } from "./chunk-3WJRJ3Q7.js";
4
+ } from "./chunk-VG6XF3OK.js";
5
5
  import "./chunk-E3DB4TIZ.js";
6
6
  import "./chunk-PX6F3LHL.js";
7
7
  export {
package/dist/index.js CHANGED
@@ -4,10 +4,10 @@ import {
4
4
  createRepositoryChangeProcess,
5
5
  requestReviewChangesForm,
6
6
  requestRevisionForm
7
- } from "./chunk-B3PE6DPF.js";
7
+ } from "./chunk-JL53OV5M.js";
8
8
  import "./chunk-DNG7D77K.js";
9
9
  import "./chunk-ABQH2WZT.js";
10
- import "./chunk-QD6FI4HR.js";
10
+ import "./chunk-PISZZXK4.js";
11
11
  import "./chunk-SKGB4CZS.js";
12
12
  import "./chunk-E3DB4TIZ.js";
13
13
  import {
@@ -1,5 +1,5 @@
1
1
  import { Codec, FormDefinition, ProcessLaunchConfig } from '@leitwerk-dev/process-sdk';
2
- import { R as RepositoryChangeWorkflow } from './repository-change-process-DlgF04fU.js';
2
+ import { R as RepositoryChangeWorkflow } from './repository-change-process-DbcnkzLw.js';
3
3
 
4
4
  /** @public */
5
5
  interface RepositoryChangeOptions {
@@ -10,6 +10,8 @@ interface RepositoryChangeWorkflow<TParams> {
10
10
  variant?: "streamlined";
11
11
  /** @public */
12
12
  multiRepository?: boolean;
13
+ /** Refresh a clean, unpublished checkout against its target before implementation. @public */
14
+ refreshTargetBeforeImplementation?: boolean;
13
15
  /** @public */
14
16
  planDecision?(params: TParams): Promise<{
15
17
  /** @internal */
@@ -8,6 +8,8 @@ export interface RepositoryChangeWorkflow<TParams> {
8
8
  variant?: "streamlined";
9
9
  /** @public */
10
10
  multiRepository?: boolean;
11
+ /** Refresh a clean, unpublished checkout against its target before implementation. @public */
12
+ refreshTargetBeforeImplementation?: boolean;
11
13
  /** @public */
12
14
  planDecision?(params: TParams): Promise<{
13
15
  /** @internal */
@@ -1 +1 @@
1
- {"version":3,"file":"repository-change-process.d.ts","sourceRoot":"","sources":["../src/repository-change-process.ts"],"names":[],"mappings":"AACA,OAAO,EACN,KAAK,KAAK,EACV,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,EACxB,KAAK,cAAc,EAGnB,KAAK,yBAAyB,EAC9B,KAAK,2BAA2B,EAChC,KAAK,+BAA+B,EAEpC,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EACN,KAAK,qBAAqB,EAE1B,MAAM,uCAAuC,CAAC;AAY/C,cAAc;AACd,MAAM,MAAM,sBAAsB,GAAG,MAAM,CAAC;AAE5C,oEAAoE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C;IAC/C,cAAc;IACd,WAAW,EAAE;QACZ,cAAc;QACd,WAAW,EAAE,MAAM,CAAC;QACpB,cAAc;QACd,QAAQ,EAAE,mBAAmB,CAAC,OAAO,EAAE,qBAAqB,CAAC,CAAC;QAC9D,cAAc;QACd,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;KAC9B,CAAC;CACF;AAED,cAAc;AACd,wBAAgB,6BAA6B,CAAC,OAAO,SAAS,sBAAsB,EACnF,MAAM,EAAE,6BAA6B,CAAC,OAAO,CAAC;IAiU7C,cAAc;;EAGf"}
1
+ {"version":3,"file":"repository-change-process.d.ts","sourceRoot":"","sources":["../src/repository-change-process.ts"],"names":[],"mappings":"AACA,OAAO,EACN,KAAK,KAAK,EACV,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,EACxB,KAAK,cAAc,EAGnB,KAAK,yBAAyB,EAC9B,KAAK,2BAA2B,EAChC,KAAK,+BAA+B,EAEpC,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EACN,KAAK,qBAAqB,EAE1B,MAAM,uCAAuC,CAAC;AAY/C,cAAc;AACd,MAAM,MAAM,sBAAsB,GAAG,MAAM,CAAC;AAE5C,oEAAoE;AACpE,MAAM,WAAW,wBAAwB,CAAC,OAAO;IAChD,4EAA4E;IAC5E,OAAO,CAAC,EAAE,aAAa,CAAC;IACxB,cAAc;IACd,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,8FAA8F;IAC9F,iCAAiC,CAAC,EAAE,OAAO,CAAC;IAC5C,cAAc;IACd,YAAY,CAAC,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC;QACvC,gBAAgB;QAChB,IAAI,EAAE,OAAO,CAAC;QACd,gBAAgB;QAChB,MAAM,EAAE,MAAM,CAAC;KACf,CAAC,CAAC;IACH,cAAc;IACd,cAAc,CAAC,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC;QACzC,gBAAgB;QAChB,IAAI,EAAE,OAAO,CAAC;QACd,g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