@fern-api/fern-api-dev 4.109.0 → 5.0.0-11-g03ccf8c3d82

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 (2) hide show
  1. package/cli.cjs +789 -111
  2. package/package.json +1 -1
package/cli.cjs CHANGED
@@ -340394,9 +340394,9 @@ var require_diff3 = __commonJS({
340394
340394
  }
340395
340395
  });
340396
340396
 
340397
- // ../../../node_modules/.pnpm/@fern-api+replay@0.13.0/node_modules/@fern-api/replay/dist/index.cjs
340397
+ // ../../../node_modules/.pnpm/@fern-api+replay@0.14.0/node_modules/@fern-api/replay/dist/index.cjs
340398
340398
  var require_dist14 = __commonJS({
340399
- "../../../node_modules/.pnpm/@fern-api+replay@0.13.0/node_modules/@fern-api/replay/dist/index.cjs"(exports2, module4) {
340399
+ "../../../node_modules/.pnpm/@fern-api+replay@0.14.0/node_modules/@fern-api/replay/dist/index.cjs"(exports2, module4) {
340400
340400
  "use strict";
340401
340401
  var __defProp4 = Object.defineProperty;
340402
340402
  var __getOwnPropDesc4 = Object.getOwnPropertyDescriptor;
@@ -340439,9 +340439,9 @@ var require_dist14 = __commonJS({
340439
340439
  return this.git.raw(args);
340440
340440
  }
340441
340441
  async execWithInput(args, input3) {
340442
- const { spawn: spawn7 } = await import("child_process");
340442
+ const { spawn: spawn22 } = await import("child_process");
340443
340443
  return new Promise((resolve22, reject) => {
340444
- const proc2 = spawn7("git", args, { cwd: this.repoPath });
340444
+ const proc2 = spawn22("git", args, { cwd: this.repoPath });
340445
340445
  let stdout = "";
340446
340446
  let stderr = "";
340447
340447
  proc2.stdout.on("data", (data2) => {
@@ -341684,11 +341684,43 @@ var require_dist14 = __commonJS({
341684
341684
  }
341685
341685
  }
341686
341686
  }
341687
- return {
341687
+ const result = {
341688
341688
  content: outputLines.join("\n"),
341689
341689
  hasConflicts: conflicts2.length > 0,
341690
341690
  conflicts: conflicts2
341691
341691
  };
341692
+ if (conflicts2.length === 0) {
341693
+ const dropped = computeDroppedContextLines(baseLines, theirsLines, outputLines);
341694
+ if (dropped.length > 0) {
341695
+ result.droppedContextLines = dropped;
341696
+ }
341697
+ }
341698
+ return result;
341699
+ }
341700
+ function computeDroppedContextLines(baseLines, theirsLines, mergedLines) {
341701
+ const baseCounts = countLines2(baseLines);
341702
+ const theirsCounts = countLines2(theirsLines);
341703
+ const mergedCounts = countLines2(mergedLines);
341704
+ const dropped = [];
341705
+ const seen = /* @__PURE__ */ new Set();
341706
+ for (const line of baseLines) {
341707
+ if (seen.has(line)) continue;
341708
+ const inBase = baseCounts.get(line) ?? 0;
341709
+ const inTheirs = theirsCounts.get(line) ?? 0;
341710
+ const inMerged = mergedCounts.get(line) ?? 0;
341711
+ if (inBase > 0 && inTheirs > 0 && inMerged < Math.min(inBase, inTheirs)) {
341712
+ dropped.push(line);
341713
+ seen.add(line);
341714
+ }
341715
+ }
341716
+ return dropped;
341717
+ }
341718
+ function countLines2(lines) {
341719
+ const counts = /* @__PURE__ */ new Map();
341720
+ for (const line of lines) {
341721
+ counts.set(line, (counts.get(line) ?? 0) + 1);
341722
+ }
341723
+ return counts;
341692
341724
  }
341693
341725
  function tryResolveConflict(oursLines, baseLines, theirsLines) {
341694
341726
  if (baseLines.length === 0) {
@@ -341877,6 +341909,19 @@ var require_dist14 = __commonJS({
341877
341909
  renameCache = /* @__PURE__ */ new Map();
341878
341910
  treeExistsCache = /* @__PURE__ */ new Map();
341879
341911
  fileTheirsAccumulator = /* @__PURE__ */ new Map();
341912
+ /**
341913
+ * Apply mode for the current `applyPatches` invocation. Set at the start
341914
+ * of `applyPatches`, read by `mergeFile` to decide:
341915
+ * - whether to skip the intra-loop marker strip (kept in `applyPatches`)
341916
+ * - whether to populate the accumulator after a conflicted merge
341917
+ * (resolve mode populates so subsequent patches on the same file
341918
+ * can use patch A's THEIRS as a structurally-correct merge base
341919
+ * when their diff was authored against post-A structure)
341920
+ * - whether to retry THEIRS reconstruction against the accumulator
341921
+ * when the BASE-relative reconstruction produced markers from a
341922
+ * cross-patch context mismatch
341923
+ */
341924
+ currentApplyMode = "replay";
341880
341925
  constructor(git, lockManager, outputDir) {
341881
341926
  this.git = git;
341882
341927
  this.lockManager = lockManager;
@@ -341924,8 +341969,23 @@ var require_dist14 = __commonJS({
341924
341969
  /**
341925
341970
  * Apply all patches, returning results for each.
341926
341971
  * Skips patches that match exclude patterns in replay.yml
341927
- */
341928
- async applyPatches(patches) {
341972
+ *
341973
+ * `applyMode` controls the post-conflict marker strategy:
341974
+ * - `"replay"` (default): strip conflict markers from disk between
341975
+ * iterations whenever a later patch touches the same file. Lets the
341976
+ * follow-up patch's `git apply --3way` see clean OURS content,
341977
+ * which is what the silent-loss fix (PR #73) relies on. The replay
341978
+ * pipeline calls `revertConflictingFiles` after the loop to clean
341979
+ * any markers that survive.
341980
+ * - `"resolve"`: keep markers on disk. The resolve command needs the
341981
+ * customer to see them. Slow-path 3-way merge naturally preserves
341982
+ * A's markers and B's clean writes when their regions don't overlap;
341983
+ * when they do overlap, the customer gets nested markers and
341984
+ * resolves manually. Either way they aren't silently dropped.
341985
+ */
341986
+ async applyPatches(patches, opts) {
341987
+ const applyMode = opts?.applyMode ?? "replay";
341988
+ this.currentApplyMode = applyMode;
341929
341989
  this.resetAccumulator();
341930
341990
  const results = [];
341931
341991
  for (let i9 = 0; i9 < patches.length; i9++) {
@@ -341940,7 +342000,7 @@ var require_dist14 = __commonJS({
341940
342000
  }
341941
342001
  const result = await this.applyPatchWithFallback(patch5);
341942
342002
  results.push(result);
341943
- if (result.status === "conflict" && result.fileResults) {
342003
+ if (applyMode !== "resolve" && result.status === "conflict" && result.fileResults) {
341944
342004
  const laterFiles = /* @__PURE__ */ new Set();
341945
342005
  for (let j7 = i9 + 1; j7 < patches.length; j7++) {
341946
342006
  for (const f5 of patches[j7].files) {
@@ -341970,9 +342030,17 @@ var require_dist14 = __commonJS({
341970
342030
  }
341971
342031
  return results;
341972
342032
  }
341973
- /** Populate accumulator after git apply succeeds. */
342033
+ /**
342034
+ * Populate accumulator after git apply succeeds, AND collect per-file
342035
+ * results including any "dropped context lines" — lines that were
342036
+ * present in BASE and THEIRS (unchanged context) but absent from the
342037
+ * final on-disk state because OURS deleted them. This is the fast-path
342038
+ * counterpart to ThreeWayMerge.computeDroppedContextLines used by the
342039
+ * 3-way slow path; both must surface the same warning.
342040
+ */
341974
342041
  async populateAccumulatorForPatch(patch5, baseGen, currentTreeHash) {
341975
- if (!baseGen) return;
342042
+ const fileResults = [];
342043
+ if (!baseGen) return fileResults;
341976
342044
  const tempDir2 = await (0, import_promises192.mkdtemp)((0, import_node_path210.join)((0, import_node_os15.tmpdir)(), "replay-acc-"));
341977
342045
  const { GitClient: GitClient2 } = await Promise.resolve().then(() => (init_GitClient(), GitClient_exports));
341978
342046
  const tempGit = new GitClient2(tempDir2);
@@ -341985,18 +342053,30 @@ var require_dist14 = __commonJS({
341985
342053
  const resolvedPath = await this.resolveFilePath(filePath, baseGen.tree_hash, currentTreeHash);
341986
342054
  const base4 = await this.git.showFile(baseGen.tree_hash, filePath);
341987
342055
  const theirs = await this.applyPatchToContent(base4, patch5.patch_content, filePath, tempGit, tempDir2);
341988
- const effectiveTheirs = theirs ?? await (0, import_promises192.readFile)((0, import_node_path210.join)(this.outputDir, resolvedPath), "utf-8").catch(() => null);
342056
+ const finalOnDisk = await (0, import_promises192.readFile)((0, import_node_path210.join)(this.outputDir, resolvedPath), "utf-8").catch(() => null);
342057
+ const effectiveTheirs = theirs ?? finalOnDisk;
341989
342058
  if (effectiveTheirs != null) {
341990
342059
  this.fileTheirsAccumulator.set(resolvedPath, {
341991
342060
  content: effectiveTheirs,
341992
342061
  baseGeneration: patch5.base_generation
341993
342062
  });
341994
342063
  }
342064
+ if (base4 != null && effectiveTheirs != null && finalOnDisk != null) {
342065
+ const dropped = computeDroppedContextLinesForFile(base4, effectiveTheirs, finalOnDisk);
342066
+ if (dropped.length > 0) {
342067
+ fileResults.push({
342068
+ file: resolvedPath,
342069
+ status: "merged",
342070
+ droppedContextLines: dropped
342071
+ });
342072
+ }
342073
+ }
341995
342074
  }
341996
342075
  } finally {
341997
342076
  await (0, import_promises192.rm)(tempDir2, { recursive: true }).catch(() => {
341998
342077
  });
341999
342078
  }
342079
+ return fileResults;
342000
342080
  }
342001
342081
  async applyPatchWithFallback(patch5) {
342002
342082
  const baseGen = await this.resolveBaseGeneration(patch5.base_generation);
@@ -342027,11 +342107,12 @@ var require_dist14 = __commonJS({
342027
342107
  }
342028
342108
  try {
342029
342109
  await this.git.execWithInput(["apply", "--3way"], patch5.patch_content);
342030
- await this.populateAccumulatorForPatch(patch5, baseGen, currentTreeHash);
342110
+ const fastPathFileResults = await this.populateAccumulatorForPatch(patch5, baseGen, currentTreeHash);
342031
342111
  return {
342032
342112
  patch: patch5,
342033
342113
  status: "applied",
342034
342114
  method: "git-am",
342115
+ ...fastPathFileResults.length > 0 && { fileResults: fastPathFileResults },
342035
342116
  ...Object.keys(resolvedFiles).length > 0 && { resolvedFiles }
342036
342117
  };
342037
342118
  } catch {
@@ -342143,19 +342224,23 @@ var require_dist14 = __commonJS({
342143
342224
  renameSourcePath
342144
342225
  );
342145
342226
  }
342227
+ const accumulatorEntry = this.fileTheirsAccumulator.get(resolvedPath);
342146
342228
  if (theirs) {
342147
342229
  const theirsHasMarkers = theirs.includes("<<<<<<< Generated") || theirs.includes(">>>>>>> Your customization");
342148
342230
  const baseHasMarkers = base4 != null && (base4.includes("<<<<<<< Generated") || base4.includes(">>>>>>> Your customization"));
342149
342231
  if (theirsHasMarkers && !baseHasMarkers) {
342150
- return {
342151
- file: resolvedPath,
342152
- status: "skipped",
342153
- reason: "stale-conflict-markers"
342154
- };
342232
+ if (accumulatorEntry) {
342233
+ theirs = null;
342234
+ } else {
342235
+ return {
342236
+ file: resolvedPath,
342237
+ status: "skipped",
342238
+ reason: "stale-conflict-markers"
342239
+ };
342240
+ }
342155
342241
  }
342156
342242
  }
342157
342243
  let useAccumulatorAsMergeBase = false;
342158
- const accumulatorEntry = this.fileTheirsAccumulator.get(resolvedPath);
342159
342244
  if (accumulatorEntry && (theirs == null || base4 == null)) {
342160
342245
  theirs = await this.applyPatchToContent(
342161
342246
  accumulatorEntry.content,
@@ -342262,7 +342347,8 @@ var require_dist14 = __commonJS({
342262
342347
  const outDir = (0, import_node_path210.dirname)(oursPath);
342263
342348
  await (0, import_promises192.mkdir)(outDir, { recursive: true });
342264
342349
  await (0, import_promises192.writeFile)(oursPath, merged.content);
342265
- if (effective_theirs != null && !merged.hasConflicts) {
342350
+ const populateAccumulator = effective_theirs != null && (!merged.hasConflicts || this.currentApplyMode === "resolve");
342351
+ if (populateAccumulator) {
342266
342352
  this.fileTheirsAccumulator.set(resolvedPath, {
342267
342353
  content: effective_theirs,
342268
342354
  baseGeneration: patch5.base_generation
@@ -342277,7 +342363,11 @@ var require_dist14 = __commonJS({
342277
342363
  conflictMetadata: metadata
342278
342364
  };
342279
342365
  }
342280
- return { file: resolvedPath, status: "merged" };
342366
+ return {
342367
+ file: resolvedPath,
342368
+ status: "merged",
342369
+ ...merged.droppedContextLines && merged.droppedContextLines.length > 0 ? { droppedContextLines: merged.droppedContextLines } : {}
342370
+ };
342281
342371
  } catch (error50) {
342282
342372
  return {
342283
342373
  file: filePath,
@@ -342463,6 +342553,30 @@ var require_dist14 = __commonJS({
342463
342553
  const ext2 = (0, import_node_path210.extname)(filePath).toLowerCase();
342464
342554
  return BINARY_EXTENSIONS2.has(ext2);
342465
342555
  }
342556
+ function computeDroppedContextLinesForFile(base4, theirs, finalContent) {
342557
+ const baseLines = base4.split("\n");
342558
+ const theirsLines = theirs.split("\n");
342559
+ const finalLines = finalContent.split("\n");
342560
+ const baseCounts = /* @__PURE__ */ new Map();
342561
+ const theirsCounts = /* @__PURE__ */ new Map();
342562
+ const finalCounts = /* @__PURE__ */ new Map();
342563
+ for (const l9 of baseLines) baseCounts.set(l9, (baseCounts.get(l9) ?? 0) + 1);
342564
+ for (const l9 of theirsLines) theirsCounts.set(l9, (theirsCounts.get(l9) ?? 0) + 1);
342565
+ for (const l9 of finalLines) finalCounts.set(l9, (finalCounts.get(l9) ?? 0) + 1);
342566
+ const dropped = [];
342567
+ const seen = /* @__PURE__ */ new Set();
342568
+ for (const line of baseLines) {
342569
+ if (seen.has(line)) continue;
342570
+ const inBase = baseCounts.get(line) ?? 0;
342571
+ const inTheirs = theirsCounts.get(line) ?? 0;
342572
+ const inFinal = finalCounts.get(line) ?? 0;
342573
+ if (inBase > 0 && inTheirs > 0 && inFinal < Math.min(inBase, inTheirs)) {
342574
+ dropped.push(line);
342575
+ seen.add(line);
342576
+ }
342577
+ }
342578
+ return dropped;
342579
+ }
342466
342580
  function isDiffLineForFile(diffLine, filePath) {
342467
342581
  const match3 = diffLine.match(/^diff --git a\/.+ b\/(.+)$/);
342468
342582
  return match3 !== null && match3[1] === filePath;
@@ -342496,13 +342610,46 @@ CLI Version: ${options2.cliVersion}`;
342496
342610
  await this.git.exec(["commit", "-m", fullMessage]);
342497
342611
  return (await this.git.exec(["rev-parse", "HEAD"])).trim();
342498
342612
  }
342499
- async commitReplay(_patchCount, patches, message) {
342613
+ async commitReplay(_patchCount, patches, message, options2) {
342500
342614
  await this.stageAll();
342501
342615
  if (!await this.hasStagedChanges()) {
342502
342616
  return (await this.git.exec(["rev-parse", "HEAD"])).trim();
342503
342617
  }
342504
342618
  let fullMessage = message ?? `[fern-replay] Applied customizations`;
342505
- if (patches && patches.length > 0) {
342619
+ const buckets = options2?.buckets;
342620
+ if (buckets) {
342621
+ if (buckets.applied.length > 0) {
342622
+ fullMessage += `
342623
+
342624
+ Patches applied (${buckets.applied.length}):`;
342625
+ for (const p14 of buckets.applied) {
342626
+ fullMessage += `
342627
+ - ${p14.id}: ${p14.original_message}`;
342628
+ }
342629
+ }
342630
+ if (buckets.unresolved.length > 0) {
342631
+ fullMessage += `
342632
+
342633
+ Patches with unresolved conflicts (${buckets.unresolved.length}):`;
342634
+ for (const p14 of buckets.unresolved) {
342635
+ fullMessage += `
342636
+ - ${p14.id}: ${p14.original_message}`;
342637
+ }
342638
+ fullMessage += `
342639
+ Run \`fern-replay resolve\` to apply these customizations.`;
342640
+ }
342641
+ if (buckets.absorbed.length > 0) {
342642
+ fullMessage += `
342643
+
342644
+ Patches absorbed by generator (${buckets.absorbed.length}):`;
342645
+ for (const p14 of buckets.absorbed) {
342646
+ fullMessage += `
342647
+ - ${p14.id}: ${p14.original_message}`;
342648
+ }
342649
+ fullMessage += `
342650
+ The generator now produces these customizations natively.`;
342651
+ }
342652
+ } else if (patches && patches.length > 0) {
342506
342653
  fullMessage += "\n\nPatches replayed:";
342507
342654
  for (const patch5 of patches) {
342508
342655
  fullMessage += `
@@ -342536,9 +342683,299 @@ CLI Version: ${options2.cliVersion}`;
342536
342683
  }
342537
342684
  };
342538
342685
  var import_node_fs210 = require("fs");
342539
- var import_node_path310 = require("path");
342686
+ var import_node_path43 = require("path");
342540
342687
  var import_minimatch22 = require_commonjs3();
342541
342688
  init_GitClient();
342689
+ var import_promises210 = require("fs/promises");
342690
+ var import_node_os22 = require("os");
342691
+ var import_node_path310 = require("path");
342692
+ var import_node_child_process7 = require("child_process");
342693
+ init_HybridReconstruction();
342694
+ function normalizeHunkBody(hunk) {
342695
+ let contextC = 0;
342696
+ let removeC = 0;
342697
+ let addC = 0;
342698
+ const trimmed2 = [];
342699
+ for (const line of hunk.lines) {
342700
+ const oldUsed = contextC + removeC;
342701
+ const newUsed = contextC + addC;
342702
+ if (oldUsed >= hunk.oldCount && newUsed >= hunk.newCount) break;
342703
+ trimmed2.push(line);
342704
+ if (line.type === "context") contextC++;
342705
+ else if (line.type === "remove") removeC++;
342706
+ else if (line.type === "add") addC++;
342707
+ }
342708
+ return { ...hunk, lines: trimmed2 };
342709
+ }
342710
+ function extractFileDiffForFile(patchContent, filePath) {
342711
+ const lines = patchContent.split("\n");
342712
+ const out = [];
342713
+ let inTarget = false;
342714
+ for (const line of lines) {
342715
+ if (line.startsWith("diff --git")) {
342716
+ if (inTarget) break;
342717
+ if (isDiffLineForFile2(line, filePath)) {
342718
+ inTarget = true;
342719
+ out.push(line);
342720
+ }
342721
+ continue;
342722
+ }
342723
+ if (inTarget) out.push(line);
342724
+ }
342725
+ return out.length > 0 ? out.join("\n") + "\n" : null;
342726
+ }
342727
+ function isDiffLineForFile2(line, filePath) {
342728
+ const match3 = line.match(/^diff --git a\/(.+) b\/(.+)$/);
342729
+ return match3 !== null && (match3[2] === filePath || match3[1] === filePath);
342730
+ }
342731
+ async function computePerPatchDiff(patch5, getCurrentGenContent, getWorkingTreeContent) {
342732
+ const fragments = [];
342733
+ const unlocatableFiles = [];
342734
+ for (const file4 of patch5.files) {
342735
+ const fileDiff = extractFileDiffForFile(patch5.patch_content, file4);
342736
+ if (fileDiff == null) {
342737
+ unlocatableFiles.push(file4);
342738
+ continue;
342739
+ }
342740
+ const hunksRaw = parseHunks(fileDiff).map(normalizeHunkBody);
342741
+ const hunks = hunksRaw.filter((h4) => {
342742
+ if (h4.lines.length === 0) return false;
342743
+ let ctx = 0, rm32 = 0, add = 0;
342744
+ for (const ln10 of h4.lines) {
342745
+ if (ln10.type === "context") ctx++;
342746
+ else if (ln10.type === "remove") rm32++;
342747
+ else if (ln10.type === "add") add++;
342748
+ }
342749
+ return ctx + rm32 === h4.oldCount && ctx + add === h4.newCount;
342750
+ });
342751
+ if (hunks.length === 0) {
342752
+ if (hunksRaw.length > 0) unlocatableFiles.push(file4);
342753
+ continue;
342754
+ }
342755
+ const currentGen = await getCurrentGenContent(file4);
342756
+ const workingTree = await getWorkingTreeContent(file4);
342757
+ const isPureNewFile = hunks.every((h4) => h4.oldCount === 0);
342758
+ const isPureDelete = hunks.every((h4) => h4.newCount === 0);
342759
+ if (currentGen == null) {
342760
+ if (!isPureNewFile) {
342761
+ unlocatableFiles.push(file4);
342762
+ continue;
342763
+ }
342764
+ if (workingTree == null) continue;
342765
+ fragments.push(synthesizeNewFileDiff(file4, workingTree));
342766
+ continue;
342767
+ }
342768
+ if (isPureNewFile) {
342769
+ if (workingTree == null) {
342770
+ fragments.push(synthesizeDeleteFileDiff(file4, currentGen));
342771
+ continue;
342772
+ }
342773
+ if (workingTree === currentGen) {
342774
+ continue;
342775
+ }
342776
+ const fullDiff = await unifiedDiff(currentGen, workingTree, file4);
342777
+ if (fullDiff && fullDiff.trim()) fragments.push(fullDiff);
342778
+ continue;
342779
+ }
342780
+ if (workingTree == null) {
342781
+ if (!isPureDelete) {
342782
+ unlocatableFiles.push(file4);
342783
+ continue;
342784
+ }
342785
+ fragments.push(synthesizeDeleteFileDiff(file4, currentGen));
342786
+ continue;
342787
+ }
342788
+ const currentGenLines = splitLines(currentGen);
342789
+ const workingTreeLines = splitLines(workingTree);
342790
+ const locInCurrentGenRaw = locateHunksInOurs(hunks, currentGenLines);
342791
+ const locInWorkingTreeRaw = locateHunksInOurs(hunks, workingTreeLines);
342792
+ if (locInCurrentGenRaw == null || locInWorkingTreeRaw == null) {
342793
+ unlocatableFiles.push(file4);
342794
+ continue;
342795
+ }
342796
+ const locInCurrentGen = locInCurrentGenRaw.map(
342797
+ (l9) => resolveSpan(l9, currentGenLines, "old")
342798
+ );
342799
+ const locInWorkingTree = locInWorkingTreeRaw.map(
342800
+ (l9) => resolveSpan(l9, workingTreeLines, "new")
342801
+ );
342802
+ const overlay = overlayRegions(
342803
+ currentGenLines,
342804
+ locInCurrentGen,
342805
+ workingTreeLines,
342806
+ locInWorkingTree
342807
+ );
342808
+ if (overlay === null) {
342809
+ unlocatableFiles.push(file4);
342810
+ continue;
342811
+ }
342812
+ if (overlay === currentGen) {
342813
+ continue;
342814
+ }
342815
+ const fileUnifiedDiff = await unifiedDiff(currentGen, overlay, file4);
342816
+ if (fileUnifiedDiff && fileUnifiedDiff.trim()) {
342817
+ fragments.push(fileUnifiedDiff);
342818
+ }
342819
+ }
342820
+ return {
342821
+ diff: fragments.join(""),
342822
+ unlocatableFiles
342823
+ };
342824
+ }
342825
+ async function computePerPatchDiffWithFallback(patch5, getCurrentGenContent, getWorkingTreeContent, runCumulativeDiff) {
342826
+ const ppDiff = await computePerPatchDiff(
342827
+ patch5,
342828
+ getCurrentGenContent,
342829
+ getWorkingTreeContent
342830
+ );
342831
+ if (ppDiff.unlocatableFiles.length === 0) {
342832
+ return { diff: ppDiff.diff, hadFallback: false, fallbackFiles: [] };
342833
+ }
342834
+ const cumulative = await runCumulativeDiff(ppDiff.unlocatableFiles);
342835
+ if (cumulative === null) {
342836
+ return null;
342837
+ }
342838
+ const merged = ppDiff.diff + (cumulative.trim() ? cumulative : "");
342839
+ return { diff: merged, hadFallback: true, fallbackFiles: ppDiff.unlocatableFiles };
342840
+ }
342841
+ function splitLines(content5) {
342842
+ return content5.split("\n");
342843
+ }
342844
+ function resolveSpan(loc, oursLines, prefer) {
342845
+ const { hunk, oursOffset } = loc;
342846
+ const oldSide = [];
342847
+ const newSide = [];
342848
+ for (const line of hunk.lines) {
342849
+ if (line.type === "context") {
342850
+ oldSide.push(line.content);
342851
+ newSide.push(line.content);
342852
+ } else if (line.type === "remove") {
342853
+ oldSide.push(line.content);
342854
+ } else if (line.type === "add") {
342855
+ newSide.push(line.content);
342856
+ }
342857
+ }
342858
+ const oldFits = sequenceMatches(oldSide, oursLines, oursOffset);
342859
+ const newFits = sequenceMatches(newSide, oursLines, oursOffset);
342860
+ if (prefer === "old") {
342861
+ if (oldFits) return { ...loc, oursSpan: hunk.oldCount };
342862
+ if (newFits) return { ...loc, oursSpan: hunk.newCount };
342863
+ } else {
342864
+ if (newFits) return { ...loc, oursSpan: hunk.newCount };
342865
+ if (oldFits) return { ...loc, oursSpan: hunk.oldCount };
342866
+ }
342867
+ return loc;
342868
+ }
342869
+ function sequenceMatches(needle, haystack, offset2) {
342870
+ if (offset2 + needle.length > haystack.length) return false;
342871
+ for (let i9 = 0; i9 < needle.length; i9++) {
342872
+ if (haystack[offset2 + i9] !== needle[i9]) return false;
342873
+ }
342874
+ return true;
342875
+ }
342876
+ function overlayRegions(currentGenLines, locInCurrentGen, workingTreeLines, locInWorkingTree) {
342877
+ if (locInCurrentGen.length !== locInWorkingTree.length) {
342878
+ return null;
342879
+ }
342880
+ const out = [];
342881
+ let cursor = 0;
342882
+ for (let i9 = 0; i9 < locInCurrentGen.length; i9++) {
342883
+ const cg = locInCurrentGen[i9];
342884
+ const wt10 = locInWorkingTree[i9];
342885
+ if (cg.oursOffset > cursor) {
342886
+ out.push(...currentGenLines.slice(cursor, cg.oursOffset));
342887
+ }
342888
+ out.push(...workingTreeLines.slice(wt10.oursOffset, wt10.oursOffset + wt10.oursSpan));
342889
+ cursor = cg.oursOffset + cg.oursSpan;
342890
+ }
342891
+ if (cursor < currentGenLines.length) {
342892
+ out.push(...currentGenLines.slice(cursor));
342893
+ }
342894
+ return out.join("\n");
342895
+ }
342896
+ async function unifiedDiff(beforeContent, afterContent, filePath) {
342897
+ if (beforeContent === afterContent) return "";
342898
+ const tmp18 = await (0, import_promises210.mkdtemp)((0, import_node_path310.join)((0, import_node_os22.tmpdir)(), "fern-replay-pp-"));
342899
+ try {
342900
+ const beforePath = (0, import_node_path310.join)(tmp18, "before");
342901
+ const afterPath = (0, import_node_path310.join)(tmp18, "after");
342902
+ await (0, import_promises210.writeFile)(beforePath, beforeContent, "utf-8");
342903
+ await (0, import_promises210.writeFile)(afterPath, afterContent, "utf-8");
342904
+ const raw = await runGitDiffNoIndex(beforePath, afterPath);
342905
+ if (!raw.trim()) return "";
342906
+ return rewriteDiffHeaders(raw, filePath);
342907
+ } finally {
342908
+ await (0, import_promises210.rm)(tmp18, { recursive: true, force: true });
342909
+ }
342910
+ }
342911
+ function runGitDiffNoIndex(beforePath, afterPath) {
342912
+ return new Promise((resolve22, reject) => {
342913
+ const proc2 = (0, import_node_child_process7.spawn)("git", ["diff", "--no-index", "--", beforePath, afterPath]);
342914
+ let stdout = "";
342915
+ let stderr = "";
342916
+ proc2.stdout.on("data", (d5) => stdout += d5.toString());
342917
+ proc2.stderr.on("data", (d5) => stderr += d5.toString());
342918
+ proc2.on("close", (code5) => {
342919
+ if (code5 === 0 || code5 === 1) resolve22(stdout);
342920
+ else reject(new Error(`git diff --no-index failed (code ${code5}): ${stderr}`));
342921
+ });
342922
+ });
342923
+ }
342924
+ function rewriteDiffHeaders(raw, filePath) {
342925
+ const lines = raw.split("\n");
342926
+ const out = [];
342927
+ let seenFirstHeader = false;
342928
+ for (const line of lines) {
342929
+ if (line.startsWith("diff --git ")) {
342930
+ out.push(`diff --git a/${filePath} b/${filePath}`);
342931
+ seenFirstHeader = true;
342932
+ continue;
342933
+ }
342934
+ if (!seenFirstHeader) {
342935
+ continue;
342936
+ }
342937
+ if (line.startsWith("--- ")) {
342938
+ out.push(`--- a/${filePath}`);
342939
+ continue;
342940
+ }
342941
+ if (line.startsWith("+++ ")) {
342942
+ out.push(`+++ b/${filePath}`);
342943
+ continue;
342944
+ }
342945
+ out.push(line);
342946
+ }
342947
+ return out.join("\n");
342948
+ }
342949
+ function synthesizeNewFileDiff(file4, content5) {
342950
+ const lines = content5.split("\n");
342951
+ const hasTrailingNewline = content5.endsWith("\n");
342952
+ const bodyLines = hasTrailingNewline ? lines.slice(0, -1) : lines;
342953
+ const header = [
342954
+ `diff --git a/${file4} b/${file4}`,
342955
+ "new file mode 100644",
342956
+ "--- /dev/null",
342957
+ `+++ b/${file4}`,
342958
+ `@@ -0,0 +1,${bodyLines.length} @@`
342959
+ ].join("\n");
342960
+ const body = bodyLines.map((l9) => `+${l9}`).join("\n");
342961
+ const trailer = hasTrailingNewline ? "" : "\n\";
342962
+ return header + "\n" + body + trailer + "\n";
342963
+ }
342964
+ function synthesizeDeleteFileDiff(file4, content5) {
342965
+ const lines = content5.split("\n");
342966
+ const hasTrailingNewline = content5.endsWith("\n");
342967
+ const bodyLines = hasTrailingNewline ? lines.slice(0, -1) : lines;
342968
+ const header = [
342969
+ `diff --git a/${file4} b/${file4}`,
342970
+ "deleted file mode 100644",
342971
+ `--- a/${file4}`,
342972
+ "+++ /dev/null",
342973
+ `@@ -1,${bodyLines.length} +0,0 @@`
342974
+ ].join("\n");
342975
+ const body = bodyLines.map((l9) => `-${l9}`).join("\n");
342976
+ const trailer = hasTrailingNewline ? "" : "\n\";
342977
+ return header + "\n" + body + trailer + "\n";
342978
+ }
342542
342979
  var ReplayService = class {
342543
342980
  git;
342544
342981
  detector;
@@ -342932,6 +343369,7 @@ CLI Version: ${options2.cliVersion}`;
342932
343369
  if (newPatches.length > 0) {
342933
343370
  results = await this.applicator.applyPatches(newPatches);
342934
343371
  this._lastApplyResults = results;
343372
+ this.recordDroppedContextLineWarnings(results);
342935
343373
  this.revertConflictingFiles(results);
342936
343374
  for (const result of results) {
342937
343375
  if (result.status === "conflict") {
@@ -342950,7 +343388,8 @@ CLI Version: ${options2.cliVersion}`;
342950
343388
  if (newPatches.length > 0) {
342951
343389
  if (!options2?.stageOnly) {
342952
343390
  const appliedCount = results.filter((r5) => r5.status === "applied").length;
342953
- await this.committer.commitReplay(appliedCount, newPatches);
343391
+ const buckets = computeCommitBuckets(results, rebaseCounts.absorbedPatchIds, newPatches);
343392
+ await this.committer.commitReplay(appliedCount, newPatches, void 0, { buckets });
342954
343393
  } else {
342955
343394
  await this.committer.stageAll();
342956
343395
  }
@@ -343013,12 +343452,21 @@ CLI Version: ${options2.cliVersion}`;
343013
343452
  (p14) => preRebasePatchIds.has(p14.id) && !postRebasePatchIds.has(p14.id)
343014
343453
  );
343015
343454
  existingPatches = this.lockManager.getPatches();
343016
- const seenHashes = /* @__PURE__ */ new Set();
343455
+ const seenHashes = /* @__PURE__ */ new Map();
343017
343456
  for (const p14 of existingPatches) {
343018
- if (seenHashes.has(p14.content_hash)) {
343019
- this.lockManager.removePatch(p14.id);
343457
+ const priorOrigin = seenHashes.get(p14.content_hash);
343458
+ if (priorOrigin !== void 0) {
343459
+ const provenanceMissing = !priorOrigin || !p14.original_commit;
343460
+ const sameOrigin = priorOrigin === p14.original_commit;
343461
+ if (sameOrigin && !provenanceMissing) {
343462
+ this.lockManager.removePatch(p14.id);
343463
+ } else {
343464
+ this.warnings.push(
343465
+ `Preserving patch ${p14.id} (commit ${(p14.original_commit || "<missing>").slice(0, 7)}): shares content_hash with a prior patch ${provenanceMissing ? "(provenance missing on at least one side)" : "from a different source commit"}. Both retained to avoid silent customization loss (FER-9983).`
343466
+ );
343467
+ }
343020
343468
  } else {
343021
- seenHashes.add(p14.content_hash);
343469
+ seenHashes.set(p14.content_hash, p14.original_commit);
343022
343470
  }
343023
343471
  }
343024
343472
  existingPatches = this.lockManager.getPatches();
@@ -343079,6 +343527,7 @@ CLI Version: ${options2.cliVersion}`;
343079
343527
  const genSha = prep._prepared.genSha;
343080
343528
  const results = await this.applicator.applyPatches(allPatches);
343081
343529
  this._lastApplyResults = results;
343530
+ this.recordDroppedContextLineWarnings(results);
343082
343531
  this.revertConflictingFiles(results);
343083
343532
  for (const result of results) {
343084
343533
  if (result.status === "conflict") {
@@ -343106,7 +343555,8 @@ CLI Version: ${options2.cliVersion}`;
343106
343555
  await this.committer.stageAll();
343107
343556
  } else {
343108
343557
  const appliedCount = results.filter((r5) => r5.status === "applied").length;
343109
- await this.committer.commitReplay(appliedCount, allPatches);
343558
+ const buckets = computeCommitBuckets(results, rebaseCounts.absorbedPatchIds, allPatches);
343559
+ await this.committer.commitReplay(appliedCount, allPatches, void 0, { buckets });
343110
343560
  }
343111
343561
  const warnings = [...detectorWarnings, ...this.warnings];
343112
343562
  return this.buildReport(
@@ -343130,7 +343580,7 @@ CLI Version: ${options2.cliVersion}`;
343130
343580
  let repointed = 0;
343131
343581
  let contentRebased = 0;
343132
343582
  let keptAsUserOwned = 0;
343133
- const seenContentHashes = /* @__PURE__ */ new Set();
343583
+ const seenContentHashes = /* @__PURE__ */ new Map();
343134
343584
  const absorbedPatchIds = /* @__PURE__ */ new Set();
343135
343585
  const fernignorePatterns = this.readFernignorePatterns();
343136
343586
  for (const result of results) {
@@ -343144,6 +343594,23 @@ CLI Version: ${options2.cliVersion}`;
343144
343594
  }
343145
343595
  }
343146
343596
  }
343597
+ const conflictedFilePaths = /* @__PURE__ */ new Set();
343598
+ for (const r5 of results) {
343599
+ if (r5.status !== "conflict") continue;
343600
+ if (r5.fileResults) {
343601
+ for (const fr9 of r5.fileResults) {
343602
+ if (fr9.status !== "conflict") continue;
343603
+ conflictedFilePaths.add(fr9.file);
343604
+ if (r5.resolvedFiles) {
343605
+ for (const [orig, resolved] of Object.entries(r5.resolvedFiles)) {
343606
+ if (resolved === fr9.file) conflictedFilePaths.add(orig);
343607
+ }
343608
+ }
343609
+ }
343610
+ } else {
343611
+ for (const f5 of r5.patch.files) conflictedFilePaths.add(f5);
343612
+ }
343613
+ }
343147
343614
  for (const result of results) {
343148
343615
  if (result.status === "conflict" && result.fileResults) {
343149
343616
  await this.trimAbsorbedFiles(result, currentGenSha);
@@ -343211,6 +343678,18 @@ CLI Version: ${options2.cliVersion}`;
343211
343678
  keptAsUserOwned++;
343212
343679
  continue;
343213
343680
  }
343681
+ const overlapsConflicted = patch5.files.some((f5) => conflictedFilePaths.has(f5));
343682
+ if (overlapsConflicted) {
343683
+ patch5.status = "unresolved";
343684
+ try {
343685
+ this.lockManager.updatePatch(patch5.id, { status: "unresolved" });
343686
+ } catch {
343687
+ }
343688
+ this.warnings.push(
343689
+ `Patch ${patch5.id} (${patch5.original_message}) was preserved as unresolved because an earlier patch conflicted on the same file(s) (${patch5.files.join(", ")}). Run \`fern replay resolve\` to apply this customization manually.`
343690
+ );
343691
+ continue;
343692
+ }
343214
343693
  this.lockManager.removePatch(patch5.id);
343215
343694
  absorbedPatchIds.add(patch5.id);
343216
343695
  absorbed++;
@@ -343226,13 +343705,22 @@ CLI Version: ${options2.cliVersion}`;
343226
343705
  continue;
343227
343706
  }
343228
343707
  const newContentHash = this.detector.computeContentHash(diff2);
343229
- if (seenContentHashes.has(newContentHash)) {
343230
- this.lockManager.removePatch(patch5.id);
343231
- absorbedPatchIds.add(patch5.id);
343232
- absorbed++;
343233
- continue;
343708
+ const priorOrigin = seenContentHashes.get(newContentHash);
343709
+ if (priorOrigin !== void 0) {
343710
+ const provenanceMissing = !priorOrigin || !patch5.original_commit;
343711
+ const sameOrigin = priorOrigin === patch5.original_commit;
343712
+ if (sameOrigin && !provenanceMissing) {
343713
+ this.lockManager.removePatch(patch5.id);
343714
+ absorbedPatchIds.add(patch5.id);
343715
+ absorbed++;
343716
+ continue;
343717
+ }
343718
+ this.warnings.push(
343719
+ `Preserving patch ${patch5.id} (commit ${(patch5.original_commit || "<missing>").slice(0, 7)}): shares content_hash with a prior patch ${provenanceMissing ? "(provenance missing on at least one side)" : "from a different source commit"}. Both retained to avoid silent customization loss (FER-9983).`
343720
+ );
343721
+ } else {
343722
+ seenContentHashes.set(newContentHash, patch5.original_commit);
343234
343723
  }
343235
- seenContentHashes.add(newContentHash);
343236
343724
  patch5.base_generation = currentGenSha;
343237
343725
  patch5.patch_content = diff2;
343238
343726
  patch5.content_hash = newContentHash;
@@ -343408,8 +343896,14 @@ CLI Version: ${options2.cliVersion}`;
343408
343896
  }
343409
343897
  if (patch5.base_generation === currentGen) {
343410
343898
  try {
343411
- const diff2 = await this.git.exec(["diff", currentGen, "HEAD", "--", ...patch5.files]).catch(() => null);
343412
- if (diff2 === null) continue;
343899
+ const ppResult = await computePerPatchDiffWithFallback(
343900
+ patch5,
343901
+ (f5) => this.git.showFile(currentGen, f5),
343902
+ (f5) => this.git.showFile("HEAD", f5),
343903
+ (files) => this.git.exec(["diff", currentGen, "HEAD", "--", ...files]).catch(() => null)
343904
+ );
343905
+ if (ppResult === null) continue;
343906
+ const diff2 = ppResult.diff;
343413
343907
  if (!diff2.trim()) {
343414
343908
  if (await allPatchFilesUserOwned(patch5)) continue;
343415
343909
  this.lockManager.removePatch(patch5.id);
@@ -343451,8 +343945,14 @@ CLI Version: ${options2.cliVersion}`;
343451
343945
  try {
343452
343946
  const markerFiles = await this.git.exec(["grep", "-l", "<<<<<<< Generated", "HEAD", "--", ...patch5.files]).catch(() => "");
343453
343947
  if (markerFiles.trim()) continue;
343454
- const diff2 = await this.git.exec(["diff", currentGen, "HEAD", "--", ...patch5.files]).catch(() => null);
343455
- if (diff2 === null) continue;
343948
+ const ppResult = await computePerPatchDiffWithFallback(
343949
+ patch5,
343950
+ (f5) => this.git.showFile(currentGen, f5),
343951
+ (f5) => this.git.showFile("HEAD", f5),
343952
+ (files) => this.git.exec(["diff", currentGen, "HEAD", "--", ...files]).catch(() => null)
343953
+ );
343954
+ if (ppResult === null) continue;
343955
+ const diff2 = ppResult.diff;
343456
343956
  if (!diff2.trim()) {
343457
343957
  if (await allPatchFilesUserOwned(patch5)) {
343458
343958
  try {
@@ -343477,6 +343977,32 @@ CLI Version: ${options2.cliVersion}`;
343477
343977
  }
343478
343978
  return { conflictResolved, conflictAbsorbed, contentRefreshed };
343479
343979
  }
343980
+ /**
343981
+ * After applyPatches(), surface a warning for each (patch × file) where
343982
+ * diff3 silently dropped lines that were unchanged context in the
343983
+ * customer's THEIRS. The deletion stays on disk (correct diff3 outcome),
343984
+ * but the customer must learn so they can re-add the lines if they
343985
+ * relied on them. This is the "surface or preserve, never silently drop"
343986
+ * contract for legitimate-deletion cases.
343987
+ */
343988
+ recordDroppedContextLineWarnings(results) {
343989
+ const PREVIEW_COUNT = 5;
343990
+ for (const result of results) {
343991
+ if (!result.fileResults) continue;
343992
+ for (const fr9 of result.fileResults) {
343993
+ const dropped = fr9.droppedContextLines;
343994
+ if (!dropped || dropped.length === 0) continue;
343995
+ const preview = dropped.slice(0, PREVIEW_COUNT).map((line) => ` ${line}`).join("\n");
343996
+ const more = dropped.length > PREVIEW_COUNT ? `
343997
+ ... and ${dropped.length - PREVIEW_COUNT} more` : "";
343998
+ this.warnings.push(
343999
+ `${fr9.file}: ${dropped.length} line(s) that appeared as unchanged context in your customization were deleted by the new generator output. The merge followed the deletion. First lines deleted:
344000
+ ${preview}${more}
344001
+ If you want to keep these lines, restore them in a follow-up commit and re-run replay; otherwise this warning can be safely ignored.`
344002
+ );
344003
+ }
344004
+ }
344005
+ }
343480
344006
  /**
343481
344007
  * After applyPatches(), strip conflict markers from conflicting files
343482
344008
  * so only clean content is committed. Keeps the Generated (OURS) side.
@@ -343486,7 +344012,7 @@ CLI Version: ${options2.cliVersion}`;
343486
344012
  if (result.status !== "conflict" || !result.fileResults) continue;
343487
344013
  for (const fileResult of result.fileResults) {
343488
344014
  if (fileResult.status !== "conflict") continue;
343489
- const filePath = (0, import_node_path310.join)(this.outputDir, fileResult.file);
344015
+ const filePath = (0, import_node_path43.join)(this.outputDir, fileResult.file);
343490
344016
  try {
343491
344017
  const content5 = (0, import_node_fs210.readFileSync)(filePath, "utf-8");
343492
344018
  const stripped = stripConflictMarkers(content5);
@@ -343516,7 +344042,7 @@ CLI Version: ${options2.cliVersion}`;
343516
344042
  }
343517
344043
  }
343518
344044
  readFernignorePatterns() {
343519
- const fernignorePath = (0, import_node_path310.join)(this.outputDir, ".fernignore");
344045
+ const fernignorePath = (0, import_node_path43.join)(this.outputDir, ".fernignore");
343520
344046
  if (!(0, import_node_fs210.existsSync)(fernignorePath)) return [];
343521
344047
  return (0, import_node_fs210.readFileSync)(fernignorePath, "utf-8").split("\n").map((line) => line.trim()).filter((line) => line && !line.startsWith("#"));
343522
344048
  }
@@ -343534,6 +344060,9 @@ CLI Version: ${options2.cliVersion}`;
343534
344060
  };
343535
344061
  }).filter((d5) => d5.files.length > 0);
343536
344062
  const partialCount = conflictDetails.filter((d5) => d5.cleanFiles && d5.cleanFiles.length > 0).length;
344063
+ const unresolvedResults = results.filter(
344064
+ (r5) => r5.status === "conflict" || r5.patch.status === "unresolved"
344065
+ );
343537
344066
  return {
343538
344067
  flow: flow4,
343539
344068
  patchesDetected: patches.length,
@@ -343550,7 +344079,7 @@ CLI Version: ${options2.cliVersion}`;
343550
344079
  patchesRefreshed: preRebaseCounts && preRebaseCounts.contentRefreshed > 0 ? preRebaseCounts.contentRefreshed : void 0,
343551
344080
  conflicts: conflictResults.flatMap((r5) => r5.fileResults?.filter((f5) => f5.status === "conflict") ?? []),
343552
344081
  conflictDetails: conflictDetails.length > 0 ? conflictDetails : void 0,
343553
- unresolvedPatches: conflictResults.length > 0 ? conflictResults.map((r5) => ({
344082
+ unresolvedPatches: unresolvedResults.length > 0 ? unresolvedResults.map((r5) => ({
343554
344083
  patchId: r5.patch.id,
343555
344084
  patchMessage: r5.patch.original_message,
343556
344085
  files: r5.patch.files,
@@ -343561,9 +344090,36 @@ CLI Version: ${options2.cliVersion}`;
343561
344090
  };
343562
344091
  }
343563
344092
  };
344093
+ function computeCommitBuckets(results, absorbedPatchIds, patchesPassedToCommit) {
344094
+ const resultByPatchId = /* @__PURE__ */ new Map();
344095
+ for (const r5 of results) resultByPatchId.set(r5.patch.id, r5);
344096
+ const applied = [];
344097
+ const unresolved = [];
344098
+ const absorbed = [];
344099
+ for (const patch5 of patchesPassedToCommit) {
344100
+ if (absorbedPatchIds.has(patch5.id)) {
344101
+ absorbed.push(patch5);
344102
+ continue;
344103
+ }
344104
+ const r5 = resultByPatchId.get(patch5.id);
344105
+ if (!r5) {
344106
+ applied.push(patch5);
344107
+ continue;
344108
+ }
344109
+ if (r5.status === "conflict" || patch5.status === "unresolved") {
344110
+ unresolved.push(patch5);
344111
+ continue;
344112
+ }
344113
+ if (r5.status === "applied") {
344114
+ applied.push(patch5);
344115
+ continue;
344116
+ }
344117
+ }
344118
+ return { applied, unresolved, absorbed };
344119
+ }
343564
344120
  var import_node_crypto22 = require("crypto");
343565
344121
  var import_node_fs33 = require("fs");
343566
- var import_node_path43 = require("path");
344122
+ var import_node_path52 = require("path");
343567
344123
  var import_minimatch32 = require_commonjs3();
343568
344124
  var import_yaml22 = require_dist9();
343569
344125
  var FernignoreMigrator = class {
@@ -343576,10 +344132,10 @@ CLI Version: ${options2.cliVersion}`;
343576
344132
  this.outputDir = outputDir;
343577
344133
  }
343578
344134
  fernignoreExists() {
343579
- return (0, import_node_fs33.existsSync)((0, import_node_path43.join)(this.outputDir, ".fernignore"));
344135
+ return (0, import_node_fs33.existsSync)((0, import_node_path52.join)(this.outputDir, ".fernignore"));
343580
344136
  }
343581
344137
  readFernignorePatterns() {
343582
- const fernignorePath = (0, import_node_path43.join)(this.outputDir, ".fernignore");
344138
+ const fernignorePath = (0, import_node_path52.join)(this.outputDir, ".fernignore");
343583
344139
  if (!(0, import_node_fs33.existsSync)(fernignorePath)) {
343584
344140
  return [];
343585
344141
  }
@@ -343639,7 +344195,16 @@ CLI Version: ${options2.cliVersion}`;
343639
344195
  original_author: "Fern Replay <replay@buildwithfern.com>",
343640
344196
  base_generation: currentGen.commit_sha,
343641
344197
  files: patchFiles,
343642
- patch_content: patchContent
344198
+ patch_content: patchContent,
344199
+ // Synthetic patches captured from .fernignore-protected files
344200
+ // are user-owned by definition — the customer's content
344201
+ // diverges from the generator's pristine output, and the
344202
+ // generator never produced this divergent content. Without
344203
+ // this flag, removing the file from .fernignore later (so
344204
+ // it leaves the protection check in `isFileUserOwned`) would
344205
+ // expose the patch to absorption on the next regen,
344206
+ // silently losing the customization.
344207
+ user_owned: true
343643
344208
  });
343644
344209
  trackedByBoth.push({
343645
344210
  file: pattern,
@@ -343672,7 +344237,7 @@ CLI Version: ${options2.cliVersion}`;
343672
344237
  return results;
343673
344238
  }
343674
344239
  readFileContent(filePath) {
343675
- const fullPath = (0, import_node_path43.join)(this.outputDir, filePath);
344240
+ const fullPath = (0, import_node_path52.join)(this.outputDir, filePath);
343676
344241
  if (!(0, import_node_fs33.existsSync)(fullPath)) {
343677
344242
  return null;
343678
344243
  }
@@ -343737,7 +344302,7 @@ CLI Version: ${options2.cliVersion}`;
343737
344302
  };
343738
344303
  }
343739
344304
  movePatternsToReplayYml(patterns) {
343740
- const replayYmlPath = (0, import_node_path43.join)(this.outputDir, ".fern", "replay.yml");
344305
+ const replayYmlPath = (0, import_node_path52.join)(this.outputDir, ".fern", "replay.yml");
343741
344306
  let config5 = {};
343742
344307
  if ((0, import_node_fs33.existsSync)(replayYmlPath)) {
343743
344308
  const content5 = (0, import_node_fs33.readFileSync)(replayYmlPath, "utf-8");
@@ -343746,7 +344311,7 @@ CLI Version: ${options2.cliVersion}`;
343746
344311
  const existing = config5.exclude ?? [];
343747
344312
  const merged = [.../* @__PURE__ */ new Set([...existing, ...patterns])];
343748
344313
  config5.exclude = merged;
343749
- const dir = (0, import_node_path43.dirname)(replayYmlPath);
344314
+ const dir = (0, import_node_path52.dirname)(replayYmlPath);
343750
344315
  if (!(0, import_node_fs33.existsSync)(dir)) {
343751
344316
  (0, import_node_fs33.mkdirSync)(dir, { recursive: true });
343752
344317
  }
@@ -343755,7 +344320,7 @@ CLI Version: ${options2.cliVersion}`;
343755
344320
  };
343756
344321
  var import_node_crypto32 = require("crypto");
343757
344322
  var import_node_fs42 = require("fs");
343758
- var import_node_path52 = require("path");
344323
+ var import_node_path62 = require("path");
343759
344324
  init_GitClient();
343760
344325
  async function bootstrap(outputDir, options2) {
343761
344326
  const git = new GitClient(outputDir);
@@ -343922,7 +344487,7 @@ CLI Version: ${options2.cliVersion}`;
343922
344487
  }
343923
344488
  var REPLAY_FERNIGNORE_ENTRIES = [".fern/replay.lock", ".fern/replay.yml", ".gitattributes"];
343924
344489
  function ensureFernignoreEntries(outputDir) {
343925
- const fernignorePath = (0, import_node_path52.join)(outputDir, ".fernignore");
344490
+ const fernignorePath = (0, import_node_path62.join)(outputDir, ".fernignore");
343926
344491
  let content5 = "";
343927
344492
  if ((0, import_node_fs42.existsSync)(fernignorePath)) {
343928
344493
  content5 = (0, import_node_fs42.readFileSync)(fernignorePath, "utf-8");
@@ -343946,7 +344511,7 @@ CLI Version: ${options2.cliVersion}`;
343946
344511
  }
343947
344512
  var GITATTRIBUTES_ENTRIES = [".fern/replay.lock linguist-generated=true"];
343948
344513
  function ensureGitattributesEntries(outputDir) {
343949
- const gitattributesPath = (0, import_node_path52.join)(outputDir, ".gitattributes");
344514
+ const gitattributesPath = (0, import_node_path62.join)(outputDir, ".gitattributes");
343950
344515
  let content5 = "";
343951
344516
  if ((0, import_node_fs42.existsSync)(gitattributesPath)) {
343952
344517
  content5 = (0, import_node_fs42.readFileSync)(gitattributesPath, "utf-8");
@@ -344138,6 +344703,8 @@ CLI Version: ${options2.cliVersion}`;
344138
344703
  nothingToReset: false
344139
344704
  };
344140
344705
  }
344706
+ var import_promises310 = require("fs/promises");
344707
+ var import_node_path72 = require("path");
344141
344708
  init_GitClient();
344142
344709
  async function resolve15(outputDir, options2) {
344143
344710
  const lockManager = new LockfileManager(outputDir);
@@ -344153,7 +344720,7 @@ CLI Version: ${options2.cliVersion}`;
344153
344720
  const resolvingPatches = lockManager.getResolvingPatches();
344154
344721
  if (unresolvedPatches.length > 0) {
344155
344722
  const applicator = new ReplayApplicator(git, lockManager, outputDir);
344156
- await applicator.applyPatches(unresolvedPatches);
344723
+ await applicator.applyPatches(unresolvedPatches, { applyMode: "resolve" });
344157
344724
  const markerFiles = await findConflictMarkerFiles(git);
344158
344725
  if (markerFiles.length > 0) {
344159
344726
  for (const patch5 of unresolvedPatches) {
@@ -344179,20 +344746,38 @@ CLI Version: ${options2.cliVersion}`;
344179
344746
  if (patchesToCommit.length > 0) {
344180
344747
  const currentGen = lock.current_generation;
344181
344748
  const detector = new ReplayDetector(git, lockManager, outputDir);
344749
+ const warnings = [];
344182
344750
  let patchesResolved = 0;
344183
344751
  for (const patch5 of patchesToCommit) {
344184
- const diff2 = await git.exec(["diff", currentGen, "--", ...patch5.files]).catch(() => null);
344185
- if (!diff2 || !diff2.trim()) {
344752
+ const result = await computePerPatchDiffWithFallback(
344753
+ patch5,
344754
+ (f5) => git.showFile(currentGen, f5),
344755
+ (f5) => (0, import_promises310.readFile)((0, import_node_path72.join)(outputDir, f5), "utf-8").catch(() => null),
344756
+ (files) => git.exec(["diff", currentGen, "--", ...files]).catch(() => null)
344757
+ );
344758
+ if (result === null) {
344759
+ warnings.push(
344760
+ `Patch ${patch5.id}: cumulative-diff fallback failed for unlocatable files; preserving patch unchanged`
344761
+ );
344762
+ continue;
344763
+ }
344764
+ const diff2 = result.diff;
344765
+ if (!diff2.trim()) {
344186
344766
  lockManager.removePatch(patch5.id);
344187
344767
  continue;
344188
344768
  }
344769
+ if (result.hadFallback) {
344770
+ warnings.push(
344771
+ `Patch ${patch5.id}: ${result.fallbackFiles.join(", ")} could not be anchored; cumulative-diff fallback applied for those files`
344772
+ );
344773
+ }
344189
344774
  const newContentHash = detector.computeContentHash(diff2);
344190
- const changedFiles = await getChangedFiles(git, currentGen, patch5.files);
344775
+ const changedFiles = result.hadFallback ? await getChangedFiles(git, currentGen, patch5.files) : extractFilesFromDiff(diff2);
344191
344776
  lockManager.markPatchResolved(patch5.id, {
344192
344777
  patch_content: diff2,
344193
344778
  content_hash: newContentHash,
344194
344779
  base_generation: currentGen,
344195
- files: changedFiles
344780
+ files: changedFiles.length > 0 ? changedFiles : patch5.files
344196
344781
  });
344197
344782
  patchesResolved++;
344198
344783
  }
@@ -344208,7 +344793,8 @@ CLI Version: ${options2.cliVersion}`;
344208
344793
  success: true,
344209
344794
  commitSha: commitSha2,
344210
344795
  phase: "committed",
344211
- patchesResolved
344796
+ patchesResolved,
344797
+ warnings: warnings.length > 0 ? warnings : void 0
344212
344798
  };
344213
344799
  }
344214
344800
  const committer = new ReplayCommitter(git, outputDir);
@@ -344226,6 +344812,24 @@ CLI Version: ${options2.cliVersion}`;
344226
344812
  const changed = filesOutput.trim().split("\n").filter(Boolean).filter((f5) => !f5.startsWith(".fern/"));
344227
344813
  return changed.length > 0 ? changed : files;
344228
344814
  }
344815
+ function extractFilesFromDiff(unifiedDiff2) {
344816
+ const out = /* @__PURE__ */ new Set();
344817
+ const renameSources = /* @__PURE__ */ new Set();
344818
+ let currentTarget = null;
344819
+ for (const line of unifiedDiff2.split("\n")) {
344820
+ const headerMatch = line.match(/^diff --git a\/(.+?) b\/(.+)$/);
344821
+ if (headerMatch) {
344822
+ currentTarget = headerMatch[2];
344823
+ if (!currentTarget.startsWith(".fern/")) out.add(currentTarget);
344824
+ continue;
344825
+ }
344826
+ if (currentTarget && line.startsWith("rename from ")) {
344827
+ renameSources.add(line.slice("rename from ".length));
344828
+ }
344829
+ }
344830
+ for (const src of renameSources) out.delete(src);
344831
+ return Array.from(out);
344832
+ }
344229
344833
  function status(outputDir) {
344230
344834
  const lockManager = new LockfileManager(outputDir);
344231
344835
  if (!lockManager.exists()) {
@@ -510619,7 +511223,7 @@ var MetadataConfig = external_exports.object({
510619
511223
  "twitter:url": external_exports.string().optional(),
510620
511224
  "twitter:card": TwitterCardSetting.optional(),
510621
511225
  "og:dynamic": external_exports.boolean().optional(),
510622
- "og:background-image": external_exports.string().optional(),
511226
+ "og:dynamic:background-image": external_exports.string().optional(),
510623
511227
  "og:dynamic:text-color": external_exports.string().optional(),
510624
511228
  "og:dynamic:background-color": external_exports.string().optional(),
510625
511229
  "og:dynamic:logo-color": external_exports.enum(["dark", "light"]).optional(),
@@ -513961,7 +514565,7 @@ var MetadataConfig2 = schemas_exports6.object({
513961
514565
  twitterUrl: schemas_exports6.property("twitter:url", schemas_exports6.string().optional()),
513962
514566
  twitterCard: schemas_exports6.property("twitter:card", TwitterCardSetting3.optional()),
513963
514567
  ogDynamic: schemas_exports6.property("og:dynamic", schemas_exports6.boolean().optional()),
513964
- ogBackgroundImage: schemas_exports6.property("og:background-image", schemas_exports6.string().optional()),
514568
+ ogDynamicBackgroundImage: schemas_exports6.property("og:dynamic:background-image", schemas_exports6.string().optional()),
513965
514569
  ogDynamicTextColor: schemas_exports6.property("og:dynamic:text-color", schemas_exports6.string().optional()),
513966
514570
  ogDynamicBackgroundColor: schemas_exports6.property("og:dynamic:background-color", schemas_exports6.string().optional()),
513967
514571
  ogDynamicLogoColor: schemas_exports6.property("og:dynamic:logo-color", OgDynamicLogoColor2.optional()),
@@ -543279,7 +543883,7 @@ async function convertMetadata(metadata, absoluteFilepathToDocsConfig, context3)
543279
543883
  "twitter:url": metadata.twitterUrl,
543280
543884
  "twitter:card": metadata.twitterCard,
543281
543885
  "og:dynamic": metadata.ogDynamic,
543282
- "og:background-image": await convertFilepathOrUrl(metadata.ogBackgroundImage, absoluteFilepathToDocsConfig),
543886
+ "og:dynamic:background-image": await convertFilepathOrUrl(metadata.ogDynamicBackgroundImage, absoluteFilepathToDocsConfig),
543283
543887
  "og:dynamic:text-color": metadata.ogDynamicTextColor,
543284
543888
  "og:dynamic:background-color": metadata.ogDynamicBackgroundColor,
543285
543889
  "og:dynamic:logo-color": metadata.ogDynamicLogoColor,
@@ -543296,7 +543900,7 @@ async function convertMetadata(metadata, absoluteFilepathToDocsConfig, context3)
543296
543900
  function warnOnMetadataConflicts(metadata, context3) {
543297
543901
  const dynamicEnabled = metadata.ogDynamic === true;
543298
543902
  const dynamicSettings = [
543299
- ["og:background-image", metadata.ogBackgroundImage],
543903
+ ["og:dynamic:background-image", metadata.ogDynamicBackgroundImage],
543300
543904
  ["og:dynamic:text-color", metadata.ogDynamicTextColor],
543301
543905
  ["og:dynamic:background-color", metadata.ogDynamicBackgroundColor],
543302
543906
  ["og:dynamic:logo-color", metadata.ogDynamicLogoColor],
@@ -621386,7 +621990,7 @@ var AccessTokenPosthogManager = class {
621386
621990
  properties: {
621387
621991
  ...event,
621388
621992
  ...event.properties,
621389
- version: "4.109.0",
621993
+ version: "5.0.0-11-g03ccf8c3d82",
621390
621994
  usingAccessToken: true
621391
621995
  }
621392
621996
  });
@@ -621440,7 +622044,7 @@ var UserPosthogManager = class {
621440
622044
  distinctId: this.userId ?? await this.getPersistedDistinctId(),
621441
622045
  event: "CLI",
621442
622046
  properties: {
621443
- version: "4.109.0",
622047
+ version: "5.0.0-11-g03ccf8c3d82",
621444
622048
  ...event,
621445
622049
  ...event.properties,
621446
622050
  usingAccessToken: false,
@@ -798819,8 +799423,8 @@ async function collectFilesFromDocsConfig({ parsedDocsConfig }) {
798819
799423
  if (parsedDocsConfig.metadata?.["twitter:image"] != null && parsedDocsConfig.metadata["twitter:image"].type === "filepath") {
798820
799424
  filepaths.add(parsedDocsConfig.metadata["twitter:image"].value);
798821
799425
  }
798822
- if (parsedDocsConfig.metadata?.["og:background-image"] != null && parsedDocsConfig.metadata["og:background-image"].type === "filepath") {
798823
- filepaths.add(parsedDocsConfig.metadata["og:background-image"].value);
799426
+ if (parsedDocsConfig.metadata?.["og:dynamic:background-image"] != null && parsedDocsConfig.metadata["og:dynamic:background-image"].type === "filepath") {
799427
+ filepaths.add(parsedDocsConfig.metadata["og:dynamic:background-image"].value);
798824
799428
  }
798825
799429
  if (parsedDocsConfig.typography?.bodyFont != null) {
798826
799430
  parsedDocsConfig.typography.bodyFont.variants.forEach((variant) => {
@@ -800802,13 +801406,13 @@ https://buildwithfern.com/learn/docs/getting-started/project-structure#api-defin
800802
801406
  if (this.parsedDocsConfig.metadata == null) {
800803
801407
  return;
800804
801408
  }
800805
- const { "og:image": ogImage, "og:logo": ogLogo, "twitter:image": twitterImage, "og:background-image": ogBackgroundImage, ...rest } = this.parsedDocsConfig.metadata;
801409
+ const { "og:image": ogImage, "og:logo": ogLogo, "twitter:image": twitterImage, "og:dynamic:background-image": ogDynamicBackgroundImage, ...rest } = this.parsedDocsConfig.metadata;
800806
801410
  return {
800807
801411
  ...rest,
800808
801412
  "og:image": this.convertFileIdOrUrl(ogImage),
800809
801413
  "og:logo": this.convertFileIdOrUrl(ogLogo),
800810
801414
  "twitter:image": this.convertFileIdOrUrl(twitterImage),
800811
- "og:background-image": this.convertFileIdOrUrl(ogBackgroundImage)
801415
+ "og:dynamic:background-image": this.convertFileIdOrUrl(ogDynamicBackgroundImage)
800812
801416
  };
800813
801417
  }
800814
801418
  convertFileIdOrUrl(filepathOrUrl) {
@@ -800991,7 +801595,7 @@ async function resolveThemeFileUrls(themeConfig, tmpDir) {
800991
801595
  cfg.footer = await maybeDownload(cfg.footer);
800992
801596
  if (cfg.metadata != null && typeof cfg.metadata === "object") {
800993
801597
  const meta5 = cfg.metadata;
800994
- for (const imgKey of ["og:image", "twitter:image", "og:background-image", "og:logo"]) {
801598
+ for (const imgKey of ["og:image", "twitter:image", "og:dynamic:background-image", "og:logo"]) {
800995
801599
  meta5[imgKey] = await maybeDownload(meta5[imgKey]);
800996
801600
  }
800997
801601
  }
@@ -833175,7 +833779,7 @@ var LOCAL_STORAGE_FOLDER4 = ".fern-dev";
833175
833779
  var LOGS_FOLDER_NAME = "logs";
833176
833780
  var MAX_LOGS_DIR_SIZE_BYTES = 100 * 1024 * 1024;
833177
833781
  function getCliSource() {
833178
- const version7 = "4.109.0";
833782
+ const version7 = "5.0.0-11-g03ccf8c3d82";
833179
833783
  return `cli@${version7}`;
833180
833784
  }
833181
833785
  var DebugLogger = class {
@@ -841615,7 +842219,7 @@ var definitions6 = {
841615
842219
  }
841616
842220
  ]
841617
842221
  },
841618
- "og:background-image": {
842222
+ "og:dynamic:background-image": {
841619
842223
  oneOf: [
841620
842224
  {
841621
842225
  type: "string"
@@ -845593,7 +846197,7 @@ var LegacyDocsPublisher = class {
845593
846197
  previewId,
845594
846198
  disableTemplates: void 0,
845595
846199
  skipUpload,
845596
- cliVersion: "4.109.0",
846200
+ cliVersion: "5.0.0-11-g03ccf8c3d82",
845597
846201
  loginCommand: "fern auth login"
845598
846202
  });
845599
846203
  if (taskContext.getResult() === TaskResult.Failure) {
@@ -866286,6 +866890,15 @@ var DynamicLiteralMapper = class extends WithGeneration {
866286
866890
  }));
866287
866891
  }
866288
866892
  convertObject({ object_, value: value2, fallbackToDefault }) {
866893
+ const classReference4 = this.csharp.classReference({
866894
+ origin: object_.declaration,
866895
+ namespace: this.context.getNamespace(object_.declaration.fernFilepath)
866896
+ });
866897
+ const propertyNameByWireValue = /* @__PURE__ */ new Map();
866898
+ for (const property23 of object_.properties) {
866899
+ const actualName = this.context.resolvePropertyName(classReference4, property23.name.name);
866900
+ propertyNameByWireValue.set(property23.name.wireValue, actualName);
866901
+ }
866289
866902
  const record22 = this.context.getRecord(value2) ?? {};
866290
866903
  const properties7 = this.context.associateByWireValue({
866291
866904
  parameters: object_.properties,
@@ -866295,7 +866908,7 @@ var DynamicLiteralMapper = class extends WithGeneration {
866295
866908
  this.context.errors.scope(property23.name.wireValue);
866296
866909
  try {
866297
866910
  return {
866298
- name: this.context.getClassName(property23.name.name),
866911
+ name: propertyNameByWireValue.get(property23.name.wireValue) ?? this.context.getClassName(property23.name.name),
866299
866912
  value: this.convert(property23)
866300
866913
  };
866301
866914
  } finally {
@@ -866304,7 +866917,7 @@ var DynamicLiteralMapper = class extends WithGeneration {
866304
866917
  });
866305
866918
  const providedWireValues = new Set(Object.keys(record22));
866306
866919
  for (const property23 of object_.properties) {
866307
- const fieldName = this.context.getClassName(property23.name.name);
866920
+ const fieldName = propertyNameByWireValue.get(property23.name.wireValue) ?? this.context.getClassName(property23.name.name);
866308
866921
  if (providedWireValues.has(property23.name.wireValue)) {
866309
866922
  if (this.isRequiredProperty(property23.typeReference)) {
866310
866923
  const existing = fields.find((f5) => f5.name === fieldName);
@@ -866328,10 +866941,7 @@ var DynamicLiteralMapper = class extends WithGeneration {
866328
866941
  }
866329
866942
  }
866330
866943
  return this.csharp.Literal.class_({
866331
- reference: this.csharp.classReference({
866332
- origin: object_.declaration,
866333
- namespace: this.context.getNamespace(object_.declaration.fernFilepath)
866334
- }),
866944
+ reference: classReference4,
866335
866945
  fields
866336
866946
  });
866337
866947
  }
@@ -866382,13 +866992,17 @@ var DynamicLiteralMapper = class extends WithGeneration {
866382
866992
  return void 0;
866383
866993
  }
866384
866994
  visited.add(typeId);
866995
+ const classReference4 = this.csharp.classReference({
866996
+ origin: object_.declaration,
866997
+ namespace: this.context.getNamespace(object_.declaration.fernFilepath)
866998
+ });
866385
866999
  const fields = [];
866386
867000
  for (const property23 of object_.properties) {
866387
867001
  if (this.isRequiredProperty(property23.typeReference)) {
866388
867002
  const defaultValue = this.getDefaultLiteralForType(property23.typeReference, visited);
866389
867003
  if (defaultValue != null) {
866390
867004
  fields.push({
866391
- name: this.context.getClassName(property23.name.name),
867005
+ name: this.context.resolvePropertyName(classReference4, property23.name.name),
866392
867006
  value: defaultValue
866393
867007
  });
866394
867008
  }
@@ -866396,10 +867010,7 @@ var DynamicLiteralMapper = class extends WithGeneration {
866396
867010
  }
866397
867011
  visited.delete(typeId);
866398
867012
  return this.csharp.Literal.class_({
866399
- reference: this.csharp.classReference({
866400
- origin: object_.declaration,
866401
- namespace: this.context.getNamespace(object_.declaration.fernFilepath)
866402
- }),
867013
+ reference: classReference4,
866403
867014
  fields
866404
867015
  });
866405
867016
  }
@@ -866953,6 +867564,22 @@ var DynamicSnippetsGeneratorContext = class _DynamicSnippetsGeneratorContext ext
866953
867564
  getPropertyName(name2) {
866954
867565
  return name2.pascalCase.safeName;
866955
867566
  }
867567
+ /**
867568
+ * Returns a property name that is safe within the given class reference's scope.
867569
+ * Detects collisions where PascalCase(property) == ClassName and returns the
867570
+ * renamed identifier (e.g., "CatalogV1Id_") to avoid CS0542 / CS0117.
867571
+ */
867572
+ resolvePropertyName(classReference4, name2) {
867573
+ const expectedName = name2.pascalCase.safeName;
867574
+ const redirected = classReference4.scope.getRedirectedFieldName(expectedName);
867575
+ if (redirected) {
867576
+ return redirected;
867577
+ }
867578
+ if (classReference4.scope.isField(expectedName)) {
867579
+ return expectedName;
867580
+ }
867581
+ return classReference4.registerField(expectedName);
867582
+ }
866956
867583
  getMethodName(name2) {
866957
867584
  return `${name2.pascalCase.safeName}Async`;
866958
867585
  }
@@ -867439,13 +868066,17 @@ var EndpointSnippetGenerator2 = class extends WithGeneration {
867439
868066
  });
867440
868067
  }
867441
868068
  getInlinedRequestArg({ request: request7, snippet: snippet2, pathParameterFields, filePropertyInfo }) {
868069
+ const classReference4 = this.csharp.classReference({
868070
+ origin: request7.declaration,
868071
+ namespace: this.context.getNamespace(request7.declaration.fernFilepath)
868072
+ });
867442
868073
  this.context.errors.scope(Scope4.QueryParameters);
867443
868074
  const queryParameters = this.context.associateQueryParametersByWireValue({
867444
868075
  parameters: request7.queryParameters ?? [],
867445
868076
  values: snippet2.queryParameters ?? {}
867446
868077
  });
867447
868078
  const queryParameterFields = queryParameters.map((queryParameter) => ({
867448
- name: this.context.getPropertyName(queryParameter.name.name),
868079
+ name: this.context.resolvePropertyName(classReference4, queryParameter.name.name),
867449
868080
  value: this.context.dynamicLiteralMapper.convert(queryParameter)
867450
868081
  }));
867451
868082
  this.context.errors.unscope();
@@ -867455,7 +868086,7 @@ var EndpointSnippetGenerator2 = class extends WithGeneration {
867455
868086
  values: snippet2.headers ?? {}
867456
868087
  });
867457
868088
  const headerFields = headers2.map((header) => ({
867458
- name: this.context.getPropertyName(header.name.name),
868089
+ name: this.context.resolvePropertyName(classReference4, header.name.name),
867459
868090
  value: this.context.dynamicLiteralMapper.convert({
867460
868091
  ...header,
867461
868092
  fallbackToDefault: header.name.wireValue
@@ -867466,30 +868097,32 @@ var EndpointSnippetGenerator2 = class extends WithGeneration {
867466
868097
  const requestBodyFields = request7.body != null ? this.getInlinedRequestBodyConstructorFields({
867467
868098
  body: request7.body,
867468
868099
  value: snippet2.requestBody,
867469
- filePropertyInfo
868100
+ filePropertyInfo,
868101
+ classReference: classReference4
867470
868102
  }) : [];
867471
868103
  this.context.errors.unscope();
867472
868104
  return this.csharp.Literal.class_({
867473
- reference: this.csharp.classReference({
867474
- origin: request7.declaration,
867475
- namespace: this.context.getNamespace(request7.declaration.fernFilepath)
867476
- }),
868105
+ reference: classReference4,
867477
868106
  fields: [...pathParameterFields, ...queryParameterFields, ...headerFields, ...requestBodyFields]
867478
868107
  });
867479
868108
  }
867480
- getInlinedRequestBodyConstructorFields({ body, value: value2, filePropertyInfo }) {
868109
+ getInlinedRequestBodyConstructorFields({ body, value: value2, filePropertyInfo, classReference: classReference4 }) {
867481
868110
  switch (body.type) {
867482
868111
  case "properties":
867483
- return this.getInlinedRequestBodyPropertyConstructorFields({ parameters: body.value, value: value2 });
868112
+ return this.getInlinedRequestBodyPropertyConstructorFields({
868113
+ parameters: body.value,
868114
+ value: value2,
868115
+ classReference: classReference4
868116
+ });
867484
868117
  case "referenced":
867485
- return [this.getReferencedRequestBodyPropertyConstructorField({ body, value: value2 })];
868118
+ return [this.getReferencedRequestBodyPropertyConstructorField({ body, value: value2, classReference: classReference4 })];
867486
868119
  case "fileUpload":
867487
868120
  return this.getFileUploadRequestBodyConstructorFields({ filePropertyInfo });
867488
868121
  default:
867489
868122
  assertNever(body);
867490
868123
  }
867491
868124
  }
867492
- getInlinedRequestBodyPropertyConstructorFields({ parameters: parameters2, value: value2 }) {
868125
+ getInlinedRequestBodyPropertyConstructorFields({ parameters: parameters2, value: value2, classReference: classReference4 }) {
867493
868126
  const fields = [];
867494
868127
  const bodyProperties = this.context.associateByWireValue({
867495
868128
  parameters: parameters2,
@@ -867497,7 +868130,7 @@ var EndpointSnippetGenerator2 = class extends WithGeneration {
867497
868130
  });
867498
868131
  for (const parameter6 of bodyProperties) {
867499
868132
  fields.push({
867500
- name: this.context.getPropertyName(parameter6.name.name),
868133
+ name: this.context.resolvePropertyName(classReference4, parameter6.name.name),
867501
868134
  value: this.context.dynamicLiteralMapper.convert({
867502
868135
  ...parameter6,
867503
868136
  fallbackToDefault: parameter6.name.wireValue
@@ -867509,9 +868142,9 @@ var EndpointSnippetGenerator2 = class extends WithGeneration {
867509
868142
  getFileUploadRequestBodyConstructorFields({ filePropertyInfo }) {
867510
868143
  return [...filePropertyInfo.fileFields, ...filePropertyInfo.bodyPropertyFields];
867511
868144
  }
867512
- getReferencedRequestBodyPropertyConstructorField({ body, value: value2 }) {
868145
+ getReferencedRequestBodyPropertyConstructorField({ body, value: value2, classReference: classReference4 }) {
867513
868146
  return {
867514
- name: this.context.getPropertyName(body.bodyKey),
868147
+ name: this.context.resolvePropertyName(classReference4, body.bodyKey),
867515
868148
  value: this.getReferencedRequestBodyPropertyLiteral({ body: body.bodyType, value: value2 })
867516
868149
  };
867517
868150
  }
@@ -874445,7 +875078,7 @@ var EndpointSnippetGenerator4 = class {
874445
875078
  args.push(...pathParameterFields.map((field5) => field5.value));
874446
875079
  }
874447
875080
  if (!inlineFileProperties) {
874448
- args.push(...filePropertyInfo.fileFields.map((field5) => field5.value));
875081
+ args.push(...filePropertyInfo.fileFields.map((field5) => java_exports.TypeLiteral.isNop(field5.value) ? java_exports.TypeLiteral.raw("null") : field5.value));
874449
875082
  }
874450
875083
  args.push(this.getInlinedRequestArg({
874451
875084
  request: request7,
@@ -890569,6 +891202,40 @@ init_lib4();
890569
891202
  function escapeSwiftStringLiteral(rawValue) {
890570
891203
  return rawValue.replace(/\\u([0-9a-fA-F]{4})/g, "\\u{$1}").replace(/(?<!\\)\\f/g, "\\u{000C}").replace(/(?<!\\)\\v/g, "\\u{000B}").replace(/(?<!\\)\\0/g, "\\u{0000}").replace(/(?<!\\)"/g, '\\"');
890571
891204
  }
891205
+ function escapeSwiftStringLiteralContent(value2) {
891206
+ let result = "";
891207
+ for (const ch of value2) {
891208
+ switch (ch) {
891209
+ case "\\":
891210
+ result += "\\\\";
891211
+ break;
891212
+ case '"':
891213
+ result += '\\"';
891214
+ break;
891215
+ case "\n":
891216
+ result += "\\n";
891217
+ break;
891218
+ case "\r":
891219
+ result += "\\r";
891220
+ break;
891221
+ case " ":
891222
+ result += "\\t";
891223
+ break;
891224
+ case "\0":
891225
+ result += "\\0";
891226
+ break;
891227
+ default: {
891228
+ const code5 = ch.charCodeAt(0);
891229
+ if (code5 < 32 || code5 === 127) {
891230
+ result += `\\u{${code5.toString(16).toUpperCase()}}`;
891231
+ } else {
891232
+ result += ch;
891233
+ }
891234
+ }
891235
+ }
891236
+ }
891237
+ return result;
891238
+ }
890572
891239
 
890573
891240
  // ../../../generators/swift/codegen/lib/syntax/reserved-keywords.js
890574
891241
  var reservedKeywords = [
@@ -890761,7 +891428,7 @@ var Expression2 = class extends AstNode8 {
890761
891428
  this.internalExpression.expression.write(writer2);
890762
891429
  break;
890763
891430
  case "string-literal":
890764
- writer2.write(`"${this.internalExpression.value}"`);
891431
+ writer2.write(this.internalExpression.escape ? `"${escapeSwiftStringLiteralContent(this.internalExpression.value)}"` : `"${this.internalExpression.value}"`);
890765
891432
  break;
890766
891433
  case "number-literal":
890767
891434
  writer2.write(this.internalExpression.value.toString());
@@ -890900,6 +891567,17 @@ var Expression2 = class extends AstNode8 {
890900
891567
  static stringLiteral(value2) {
890901
891568
  return new this({ type: "string-literal", value: value2 });
890902
891569
  }
891570
+ /**
891571
+ * Like {@link Expression.stringLiteral}, but escapes characters in `value`
891572
+ * that cannot appear unescaped inside a Swift `"..."` string literal
891573
+ * (control characters, real newlines, real backslashes, real double quotes).
891574
+ * Use this when `value` is raw user data (e.g. from JSON.parse), not a
891575
+ * pre-formed Swift string literal containing intentional backslash
891576
+ * sequences such as `\(...)` interpolation.
891577
+ */
891578
+ static escapedStringLiteral(value2) {
891579
+ return new this({ type: "string-literal", value: value2, escape: true });
891580
+ }
890903
891581
  static numberLiteral(value2) {
890904
891582
  return new this({ type: "number-literal", value: value2 });
890905
891583
  }
@@ -893071,7 +893749,7 @@ var DynamicTypeLiteralMapper6 = class {
893071
893749
  methodName: "string",
893072
893750
  arguments_: [
893073
893751
  swift_exports.functionArgument({
893074
- value: swift_exports.Expression.stringLiteral(value2)
893752
+ value: swift_exports.Expression.escapedStringLiteral(value2)
893075
893753
  })
893076
893754
  ]
893077
893755
  });
@@ -893109,7 +893787,7 @@ var DynamicTypeLiteralMapper6 = class {
893109
893787
  swift_exports.functionArgument({
893110
893788
  value: swift_exports.Expression.dictionaryLiteral({
893111
893789
  entries: Object.entries(value2).map(([key2, value3]) => [
893112
- swift_exports.Expression.stringLiteral(key2),
893790
+ swift_exports.Expression.escapedStringLiteral(key2),
893113
893791
  this.convertUnknown(value3)
893114
893792
  ]),
893115
893793
  multiline: true
@@ -893148,7 +893826,7 @@ var DynamicTypeLiteralMapper6 = class {
893148
893826
  if (str3 == null) {
893149
893827
  return swift_exports.Expression.nop();
893150
893828
  }
893151
- return swift_exports.Expression.stringLiteral(str3);
893829
+ return swift_exports.Expression.escapedStringLiteral(str3);
893152
893830
  }
893153
893831
  case "DATE": {
893154
893832
  const date25 = this.context.getValueAsString({ value: value2 });
@@ -893181,7 +893859,7 @@ var DynamicTypeLiteralMapper6 = class {
893181
893859
  if (base643 == null) {
893182
893860
  return swift_exports.Expression.nop();
893183
893861
  }
893184
- return swift_exports.Expression.stringLiteral(base643);
893862
+ return swift_exports.Expression.escapedStringLiteral(base643);
893185
893863
  }
893186
893864
  case "BIG_INTEGER": {
893187
893865
  const bigInt = this.context.getValueAsString({ value: value2 });
@@ -893724,7 +894402,7 @@ var EndpointSnippetGenerator9 = class {
893724
894402
  } else {
893725
894403
  return swift_exports.functionArgument({
893726
894404
  label: "baseURL",
893727
- value: swift_exports.Expression.stringLiteral(snippet2.baseURL)
894405
+ value: swift_exports.Expression.escapedStringLiteral(snippet2.baseURL)
893728
894406
  });
893729
894407
  }
893730
894408
  }
@@ -893748,10 +894426,10 @@ var EndpointSnippetGenerator9 = class {
893748
894426
  }
893749
894427
  args.push(swift_exports.functionArgument({
893750
894428
  label: auth8.username.camelCase.unsafeName,
893751
- value: swift_exports.Expression.stringLiteral(values2.username)
894429
+ value: swift_exports.Expression.escapedStringLiteral(values2.username)
893752
894430
  }), swift_exports.functionArgument({
893753
894431
  label: auth8.password.camelCase.unsafeName,
893754
- value: swift_exports.Expression.stringLiteral(values2.password)
894432
+ value: swift_exports.Expression.escapedStringLiteral(values2.password)
893755
894433
  }));
893756
894434
  break;
893757
894435
  case "bearer":
@@ -893764,7 +894442,7 @@ var EndpointSnippetGenerator9 = class {
893764
894442
  }
893765
894443
  args.push(swift_exports.functionArgument({
893766
894444
  label: auth8.token.camelCase.unsafeName,
893767
- value: swift_exports.Expression.stringLiteral(values2.token)
894445
+ value: swift_exports.Expression.escapedStringLiteral(values2.token)
893768
894446
  }));
893769
894447
  break;
893770
894448
  case "header":
@@ -919841,7 +920519,7 @@ var CliContext = class _CliContext {
919841
920519
  if (false) {
919842
920520
  this.logger.error("CLI_VERSION is not defined");
919843
920521
  }
919844
- return "4.109.0";
920522
+ return "5.0.0-11-g03ccf8c3d82";
919845
920523
  }
919846
920524
  getCliName() {
919847
920525
  if (false) {
@@ -928829,7 +929507,7 @@ ${errors4.map((e8) => ` - ${e8}`).join("\n")}`,
928829
929507
  collect2(raw.footer);
928830
929508
  if (raw.metadata != null && typeof raw.metadata === "object") {
928831
929509
  const meta5 = raw.metadata;
928832
- for (const imgKey of ["og:image", "twitter:image", "og:background-image", "og:logo"]) {
929510
+ for (const imgKey of ["og:image", "twitter:image", "og:dynamic:background-image", "og:logo"]) {
928833
929511
  if (typeof meta5[imgKey] === "string") {
928834
929512
  collect2(meta5[imgKey]);
928835
929513
  }
@@ -928917,7 +929595,7 @@ ${errors4.map((e8) => ` - ${e8}`).join("\n")}`,
928917
929595
  cfg.footer = await field5(cfg.footer);
928918
929596
  if (cfg.metadata != null && typeof cfg.metadata === "object") {
928919
929597
  const meta5 = { ...cfg.metadata };
928920
- for (const imgKey of ["og:image", "twitter:image", "og:background-image", "og:logo"]) {
929598
+ for (const imgKey of ["og:image", "twitter:image", "og:dynamic:background-image", "og:logo"]) {
928921
929599
  if (typeof meta5[imgKey] === "string") {
928922
929600
  meta5[imgKey] = await field5(meta5[imgKey]);
928923
929601
  }