pi-readseek 0.13.9 → 0.13.11

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/dist/index.ts +27 -18
  2. package/package.json +3 -3
package/dist/index.ts CHANGED
@@ -155,11 +155,14 @@ function generateCompactOrFullDiff(oldContent, newContent, anchors = new Map, co
155
155
  const lineNum = changedIndex + 1;
156
156
  const oldLine = oldLines[changedIndex] ?? "";
157
157
  const newLine = newLines[changedIndex] ?? "";
158
- const newHash = anchors.get(lineNum);
159
- return {
158
+ const formatReplacement = (newHash) => ({
160
159
  diff: `${lineNum}|${oldLine} → ${newHash === undefined ? lineNum : `${lineNum}:${newHash}`}|${newLine}`,
161
160
  firstChangedLine: lineNum
162
- };
161
+ });
162
+ if (typeof anchors === "function") {
163
+ return anchors(lineNum).then(formatReplacement);
164
+ }
165
+ return formatReplacement(anchors.get(lineNum));
163
166
  }
164
167
  }
165
168
  if (oldLines.length === newLines.length + 1) {
@@ -770,11 +773,14 @@ function dedupeSortLines(diagnostics) {
770
773
  }
771
774
  var EMPTY = { errorCount: 0, missingCount: 0, diagnostics: [] };
772
775
  async function validateSyntaxRegression(input, options = {}) {
776
+ const syntaxOptions = { stdinName: input.filePath, language: input.language, signal: options.signal };
773
777
  let before;
774
778
  let after;
775
779
  try {
776
- before = input.before === undefined ? EMPTY : await readSeekClient.syntax("-", { stdinName: input.filePath, stdin: input.before, signal: options.signal });
777
- after = await readSeekClient.syntax("-", { stdinName: input.filePath, stdin: input.after, signal: options.signal });
780
+ [before, after] = await Promise.all([
781
+ input.before === undefined ? Promise.resolve(EMPTY) : readSeekClient.syntax("-", { ...syntaxOptions, stdin: input.before }),
782
+ readSeekClient.syntax("-", { ...syntaxOptions, stdin: input.after })
783
+ ]);
778
784
  } catch {
779
785
  return null;
780
786
  }
@@ -853,23 +859,24 @@ function parseFullDiffEntries(diff) {
853
859
  return entries;
854
860
  }
855
861
  function parseCompactDiffEntries(diff, oldContent, newContent) {
862
+ const compactPrefix = /^(\d+)(?::[0-9a-f]+)?\|/.exec(diff);
863
+ if (!compactPrefix)
864
+ return;
865
+ const oldLine = Number(compactPrefix[1]);
866
+ const oldTextStart = compactPrefix[0].length;
856
867
  const oldLines = oldContent.split(`
857
868
  `);
858
869
  const newLines = newContent.split(`
859
870
  `);
860
- const compactDelete = diff.match(/^(\d+):[0-9a-f]{6}\|(.*) → \[deleted\]$/);
861
- if (compactDelete) {
862
- const oldLine = Number(compactDelete[1]);
863
- const text = compactDelete[2] ?? "";
871
+ const deletedSuffix = " → [deleted]";
872
+ if (oldLines.length === newLines.length + 1 && diff.endsWith(deletedSuffix)) {
873
+ const text = diff.slice(oldTextStart, diff.length - deletedSuffix.length);
864
874
  if (oldLines[oldLine - 1] === text)
865
875
  return [{ kind: "remove", oldLine, text }];
866
876
  }
867
- const compactPrefix = diff.match(/^(\d+):[0-9a-f]{6}\|/);
868
- if (!compactPrefix)
877
+ if (oldLines.length !== newLines.length)
869
878
  return;
870
- const oldLine = Number(compactPrefix[1]);
871
- const oldTextStart = compactPrefix[0].length;
872
- const separatorPattern = / → (\d+):[0-9a-f]{6}\|/g;
879
+ const separatorPattern = / → (\d+)(?::[0-9a-f]+)?\|/g;
873
880
  let separator;
874
881
  while ((separator = separatorPattern.exec(diff)) !== null) {
875
882
  const newLine = Number(separator[1]);
@@ -1417,7 +1424,8 @@ async function executeEdit(opts) {
1417
1424
  const regression = await validateSyntaxRegression({
1418
1425
  filePath: absolutePath,
1419
1426
  before: originalForSyntax,
1420
- after: resultForSyntax
1427
+ after: resultForSyntax,
1428
+ language: parsed.language
1421
1429
  }, { signal });
1422
1430
  if (regression) {
1423
1431
  const message = `syntax-regression: lines ${regression.errorLines.join(", ")}`;
@@ -1449,9 +1457,10 @@ async function executeEdit(opts) {
1449
1457
  return buildEditError(absolutePath, "post-edit-verification-mismatch", `Edit write completed but post-edit verification did not confirm the intended content for ${path}. Re-read the file before making follow-up edits.`, undefined, { expectedLength: result.length, actualLength: verifiedContent.length });
1450
1458
  }
1451
1459
  }
1452
- const changedLine = generateCompactOrFullDiff(original, result).firstChangedLine;
1453
- const anchors = changedLine === undefined ? [] : await readAnchors(absolutePath, { at: `line:${changedLine}`, limit: 1 }).catch(() => []);
1454
- const diffResult = generateCompactOrFullDiff(original, result, new Map(anchors.map((line) => [line.line, line.hash])));
1460
+ const diffResult = await generateCompactOrFullDiff(original, result, async (line) => {
1461
+ const [anchor] = await readAnchors(absolutePath, { at: `line:${line}`, limit: 1 }).catch(() => []);
1462
+ return anchor?.line === line ? anchor.hash : undefined;
1463
+ });
1455
1464
  const patch = createPatch(path, original, result);
1456
1465
  const diffData = buildDiffData({
1457
1466
  path: absolutePath,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-readseek",
3
- "version": "0.13.9",
3
+ "version": "0.13.11",
4
4
  "description": "Pi extension for LINE:HASH-anchored file operations and structural code navigation",
5
5
  "type": "module",
6
6
  "exports": {
@@ -39,8 +39,8 @@
39
39
  "node": ">=20.0.0"
40
40
  },
41
41
  "dependencies": {
42
- "@jarkkojs/readseek": "^0.13.9",
43
- "@jarkkojs/readseek-api": "^0.13.9",
42
+ "@jarkkojs/readseek": "^0.13.11",
43
+ "@jarkkojs/readseek-api": "^0.13.11",
44
44
  "diff": "^9.0.0"
45
45
  },
46
46
  "peerDependencies": {