@in-the-loop-labs/pair-review 5.3.4 → 5.3.6

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 (59) hide show
  1. package/README.md +13 -1
  2. package/bin/git-diff-lines +2 -1
  3. package/package.json +1 -1
  4. package/plugin/.claude-plugin/plugin.json +1 -1
  5. package/plugin-code-critic/.claude-plugin/plugin.json +1 -1
  6. package/plugin-code-critic/skills/analyze/scripts/git-diff-lines +104 -25
  7. package/plugin-pair-loop/.claude-plugin/plugin.json +1 -1
  8. package/public/css/pr.css +162 -46
  9. package/public/css/styles.css +0 -12
  10. package/public/js/components/AIPanel.js +3 -2
  11. package/public/js/components/AnalysisConfigModal.js +4 -1
  12. package/public/js/components/ChatPanel.js +39 -8
  13. package/public/js/components/PanelGroup.js +115 -21
  14. package/public/js/components/SuggestionNavigator.js +16 -3
  15. package/public/js/local.js +7 -12
  16. package/public/js/modules/diff-renderer.js +13 -0
  17. package/public/js/modules/file-comment-manager.js +19 -10
  18. package/public/js/modules/hunk-parser.js +39 -2
  19. package/public/js/modules/panel-resizer.js +41 -3
  20. package/public/js/modules/pierre-bridge.js +11 -2
  21. package/public/js/modules/suggestion-manager.js +128 -33
  22. package/public/js/pr.js +132 -29
  23. package/public/js/repo-settings.js +35 -19
  24. package/public/js/utils/git-paths.js +140 -0
  25. package/public/js/utils/smart-truncate.js +88 -0
  26. package/public/local.html +6 -0
  27. package/public/pr.html +6 -0
  28. package/src/ai/analyzer.js +15 -13
  29. package/src/ai/antigravity-provider.js +44 -24
  30. package/src/ai/cursor-agent-provider.js +4 -4
  31. package/src/ai/muse-provider.js +68 -3
  32. package/src/ai/summary-generator.js +8 -5
  33. package/src/chat/acp-bridge.js +26 -1
  34. package/src/chat/claude-code-bridge.js +10 -0
  35. package/src/chat/codex-bridge.js +10 -0
  36. package/src/chat/pi-bridge.js +10 -0
  37. package/src/chat/session-manager.js +333 -19
  38. package/src/config.js +40 -26
  39. package/src/git/diff-flags.js +26 -12
  40. package/src/git/worktree.js +21 -43
  41. package/src/github/client.js +0 -88
  42. package/src/github/impl/graphql/pending-review-comments.js +5 -1
  43. package/src/github/impl/host/pending-review-comments.js +75 -11
  44. package/src/github/submit-pr-context.js +56 -0
  45. package/src/local-review.js +34 -17
  46. package/src/main.js +80 -106
  47. package/src/routes/chat.js +44 -1
  48. package/src/routes/executable-analysis.js +14 -15
  49. package/src/routes/local.js +3 -5
  50. package/src/routes/pr.js +18 -105
  51. package/src/server.js +5 -3
  52. package/src/settings/registry.js +10 -0
  53. package/src/setup/pr-setup.js +1 -1
  54. package/src/setup/stack-setup.js +1 -1
  55. package/src/utils/diff-annotator.js +175 -25
  56. package/src/utils/diff-file-content.js +4 -26
  57. package/src/utils/diff-file-list.js +178 -42
  58. package/src/utils/git-paths.js +77 -0
  59. package/src/utils/paths.js +1 -25
@@ -2,68 +2,219 @@
2
2
  const { promisify } = require('util');
3
3
  const { exec } = require('child_process');
4
4
  const { queryOne } = require('../database');
5
- const { GIT_DIFF_FLAGS } = require('../git/diff-flags');
5
+ const { GIT_DIFF_FLAGS, GIT_PATH_CONFIG } = require('../git/diff-flags');
6
6
  const { normalizePath, resolveRenamedFile } = require('./paths');
7
+ const { parseHunkHeader } = require('./diff-annotator');
8
+ const { decodeGitPath, parsePatchPaths, splitNulPaths } = require('./git-paths');
7
9
 
8
10
  const execPromise = promisify(exec);
9
11
 
10
12
  /**
11
- * Parse a unified diff into a map of file path -> per-file patch.
12
- * Uses the "b/" path from the diff header as the canonical file path.
13
+ * Split a unified diff into its per-file patches, in order, keyed by the
14
+ * decoded new path: the `rename to` / `copy to` line when there is one,
15
+ * otherwise the `diff --git` header's "b/" side (see parsePatchPaths in
16
+ * public/js/utils/git-paths.js).
17
+ *
18
+ * A path can appear more than once: git prints a file <-> symlink type change
19
+ * as a deletion block followed by an addition block for the same path. Every
20
+ * block is kept, so callers that need the whole change can combine them.
13
21
  *
14
22
  * @param {string} diff - Full unified diff
15
- * @returns {Map<string, string>} Map of file paths to full patch text
23
+ * @returns {Array<[string, string]>} [file path, per-file patch] pairs
16
24
  */
17
- function parseUnifiedDiffPatches(diff) {
18
- const filePatchMap = new Map();
19
- if (!diff) return filePatchMap;
25
+ function splitUnifiedDiffPatches(diff) {
26
+ const patches = [];
27
+ if (!diff) return patches;
20
28
 
21
- const parts = diff.split(/(?=^diff --git )/m);
22
-
23
- for (const part of parts) {
29
+ for (const part of diff.split(/(?=^diff --git )/m)) {
24
30
  if (!part.trim()) continue;
25
31
 
26
- const match = part.match(/^diff --git a\/(.+?) b\/(.+)$/m);
27
- if (match) {
28
- filePatchMap.set(match[2], part);
32
+ const paths = parsePatchPaths(part);
33
+ if (paths) {
34
+ patches.push([paths.newPath, part]);
29
35
  }
30
36
  }
31
37
 
32
- return filePatchMap;
38
+ return patches;
39
+ }
40
+
41
+ /**
42
+ * Parse a unified diff into a map of file path -> per-file patch, keyed like
43
+ * splitUnifiedDiffPatches. When a path has more than one block (a type
44
+ * change), the map holds the last one, matching the browser's
45
+ * parseUnifiedDiff.
46
+ *
47
+ * @param {string} diff - Full unified diff
48
+ * @returns {Map<string, string>} Map of file paths to full patch text
49
+ */
50
+ function parseUnifiedDiffPatches(diff) {
51
+ return new Map(splitUnifiedDiffPatches(diff));
52
+ }
53
+
54
+ /**
55
+ * The extended header of a per-file patch: everything before the first `@@`
56
+ * hunk header, where git prints the rename and binary markers.
57
+ *
58
+ * @param {string} patch - Per-file patch text
59
+ * @returns {string} Header text (the whole patch when it has no hunk)
60
+ */
61
+ function patchHeader(patch) {
62
+ const hunkStart = patch.search(/^@@/m);
63
+ return hunkStart === -1 ? patch : patch.slice(0, hunkStart);
33
64
  }
34
65
 
35
66
  /**
36
67
  * Count additions and deletions inside a single patch body.
37
68
  *
69
+ * Only lines inside a hunk count: after an `@@` header and within the line
70
+ * counts it declares. A prefix test cannot tell headers from content — a
71
+ * deleted `-- x` line is emitted as `--- x` and an added `++ x` as `+++ x` —
72
+ * but hunk state can: `---`/`+++` are headers only outside a hunk (the same
73
+ * rule `buildDiffLineSet` in diff-annotator.js follows). Mirrored in the
74
+ * browser by `HunkParser.countPatchStats`; both suites share
75
+ * tests/utils/diff-stat-fixtures.js.
76
+ *
38
77
  * @param {string} patch - Per-file patch text
39
78
  * @returns {{ insertions: number, deletions: number }}
40
79
  */
41
80
  function countPatchStats(patch) {
42
81
  let insertions = 0;
43
82
  let deletions = 0;
83
+ let oldRemaining = 0;
84
+ let newRemaining = 0;
44
85
 
45
- for (const line of patch.split('\n')) {
46
- if (line.startsWith('+') && !line.startsWith('+++ ')) {
86
+ for (const line of (patch || '').split('\n')) {
87
+ const hunk = parseHunkHeader(line);
88
+ if (hunk) {
89
+ oldRemaining = hunk.oldCount;
90
+ newRemaining = hunk.newCount;
91
+ } else if (line.startsWith('+') && newRemaining > 0) {
47
92
  insertions++;
48
- } else if (line.startsWith('-') && !line.startsWith('--- ')) {
93
+ newRemaining--;
94
+ } else if (line.startsWith('-') && oldRemaining > 0) {
49
95
  deletions++;
96
+ oldRemaining--;
97
+ } else if (line.startsWith(' ')) {
98
+ oldRemaining--;
99
+ newRemaining--;
50
100
  }
51
101
  }
52
102
 
53
103
  return { insertions, deletions };
54
104
  }
55
105
 
106
+ /**
107
+ * Describe one file of a unified diff as a `changed_files` entry.
108
+ *
109
+ * Renames come from the explicit `rename from` / `rename to` lines, so a
110
+ * rename is recorded whatever the two paths have in common, and a file
111
+ * literally named `a => b.md` is never mistaken for one.
112
+ *
113
+ * @param {string} filePath - Decoded new path (the parseUnifiedDiffPatches key)
114
+ * @param {string} patch - Per-file patch text
115
+ * @returns {{ file: string, insertions: number, deletions: number, changes: number,
116
+ * binary: boolean, renamed?: true, renamedFrom?: string }}
117
+ */
118
+ function buildChangedFileEntry(filePath, patch) {
119
+ const { insertions, deletions } = countPatchStats(patch);
120
+ const header = patchHeader(patch);
121
+ const entry = {
122
+ file: filePath,
123
+ insertions,
124
+ deletions,
125
+ changes: insertions + deletions,
126
+ binary: /^Binary files .* differ$/m.test(header) || /^GIT binary patch$/m.test(header)
127
+ };
128
+ if (/^rename from /m.test(header) && /^rename to /m.test(header)) {
129
+ entry.renamed = true;
130
+ entry.renamedFrom = parsePatchPaths(patch).oldPath;
131
+ }
132
+ return entry;
133
+ }
134
+
135
+ /**
136
+ * Describe every file of a unified diff as a `changed_files` entry, one per
137
+ * path. A path with more than one block (git prints a file <-> symlink type
138
+ * change as a deletion followed by an addition) gets one entry whose counts
139
+ * are the sum of its blocks, so it reads +1/-1 like `--numstat`, not as a
140
+ * new file.
141
+ *
142
+ * @param {Array<[string, string]>} patches - From splitUnifiedDiffPatches
143
+ * @returns {Map<string, object>} File path -> entry, in diff order
144
+ */
145
+ function buildMergedChangedFileEntries(patches) {
146
+ const entries = new Map();
147
+ for (const [filePath, patch] of patches) {
148
+ const entry = buildChangedFileEntry(filePath, patch);
149
+ const previous = entries.get(filePath);
150
+ if (!previous) {
151
+ entries.set(filePath, entry);
152
+ continue;
153
+ }
154
+ previous.insertions += entry.insertions;
155
+ previous.deletions += entry.deletions;
156
+ previous.changes += entry.changes;
157
+ previous.binary = previous.binary || entry.binary;
158
+ if (entry.renamed && !previous.renamed) {
159
+ previous.renamed = true;
160
+ previous.renamedFrom = entry.renamedFrom;
161
+ }
162
+ }
163
+ return entries;
164
+ }
165
+
166
+ /**
167
+ * Build PR `changed_files` from the unified diff: one entry per file, with
168
+ * path, rename, additions/deletions and binary flag read from the diff text
169
+ * and `generated` from .gitattributes.
170
+ *
171
+ * This is the only producer of PR changed_files, so every PR path (setup,
172
+ * refresh, headless, `?w=1`) spells each file exactly as the diff headers do.
173
+ *
174
+ * @param {string} diff - Full unified diff
175
+ * @param {{ isGenerated: (file: string) => boolean }|null} [gitattributes] - Generated-file matcher
176
+ * @returns {Array<object>} changed_files entries
177
+ */
178
+ function buildChangedFileEntries(diff, gitattributes = null) {
179
+ return [...buildMergedChangedFileEntries(splitUnifiedDiffPatches(diff)).values()].map(entry => ({
180
+ ...entry,
181
+ generated: gitattributes ? gitattributes.isGenerated(entry.file) : false
182
+ }));
183
+ }
184
+
185
+ /**
186
+ * Re-spell a changed_files entry cached by a version that read paths from
187
+ * git's default C-quoted output (`"caf\303\251.js"`), so it matches the
188
+ * decoded diff headers until the review is refreshed. The decoded spelling is
189
+ * adopted only when the diff confirms it, so a real name that merely looks
190
+ * quoted is never mangled.
191
+ *
192
+ * @param {object|string} entry - changed_files entry
193
+ * @param {Map<string, string>} patchMap - From parseUnifiedDiffPatches
194
+ * @returns {object|string} Entry spelled like the diff headers
195
+ */
196
+ function respellCachedEntry(entry, patchMap) {
197
+ const filePath = typeof entry === 'string' ? entry : entry.file;
198
+ if (patchMap.has(filePath)) return entry;
199
+ const decoded = decodeGitPath(filePath);
200
+ if (decoded === filePath || !patchMap.has(decoded)) return entry;
201
+ return typeof entry === 'string' ? decoded : { ...entry, file: decoded };
202
+ }
203
+
56
204
  /**
57
205
  * Merge changed_files metadata with the authoritative file list from the diff.
58
206
  * This recovers files when cached changed_files were derived from abbreviated
59
- * diff --stat output and no longer match the full patch headers.
207
+ * diff --stat output and no longer match the full patch headers, and
208
+ * re-spells entries cached in git's quoted form so they match the decoded
209
+ * diff headers until the review is refreshed.
60
210
  *
61
211
  * @param {Array<object|string>} changedFiles - Existing changed_files array
62
212
  * @param {string} diff - Full unified diff
63
213
  * @returns {Array<object|string>} Merged changed_files array
64
214
  */
65
215
  function mergeChangedFilesWithDiff(changedFiles, diff) {
66
- const patchMap = parseUnifiedDiffPatches(diff);
216
+ const patches = splitUnifiedDiffPatches(diff);
217
+ const patchMap = new Map(patches);
67
218
  if (patchMap.size === 0) {
68
219
  return Array.isArray(changedFiles) ? changedFiles : [];
69
220
  }
@@ -73,7 +224,7 @@ function mergeChangedFilesWithDiff(changedFiles, diff) {
73
224
  const existing = (Array.isArray(changedFiles) ? changedFiles : []).filter(entry => {
74
225
  const filePath = typeof entry === 'string' ? entry : entry?.file;
75
226
  return filePath && !filePath.includes('...');
76
- });
227
+ }).map(entry => respellCachedEntry(entry, patchMap));
77
228
 
78
229
  const normalizedExisting = new Set(existing.map(file => {
79
230
  const filePath = typeof file === 'string' ? file : file?.file;
@@ -82,26 +233,13 @@ function mergeChangedFilesWithDiff(changedFiles, diff) {
82
233
 
83
234
  const merged = [...existing];
84
235
 
85
- for (const [filePath, patch] of patchMap.entries()) {
236
+ for (const [filePath, entry] of buildMergedChangedFileEntries(patches)) {
86
237
  const normalizedPatchPath = normalizePath(resolveRenamedFile(filePath));
87
238
  if (normalizedExisting.has(normalizedPatchPath)) {
88
239
  continue;
89
240
  }
90
241
 
91
- const { insertions, deletions } = countPatchStats(patch);
92
- const renameFrom = patch.match(/^rename from (.+)$/m)?.[1] || null;
93
- const renameTo = patch.match(/^rename to (.+)$/m)?.[1] || null;
94
- const binary = /^Binary files .* differ$/m.test(patch) || /^GIT binary patch$/m.test(patch);
95
-
96
- merged.push({
97
- file: filePath,
98
- insertions,
99
- deletions,
100
- changes: insertions + deletions,
101
- binary,
102
- renamed: Boolean(renameFrom && renameTo),
103
- renamedFrom: renameFrom
104
- });
242
+ merged.push(entry);
105
243
  normalizedExisting.add(normalizedPatchPath);
106
244
  }
107
245
 
@@ -142,14 +280,10 @@ async function getDiffFileList(db, review) {
142
280
  try {
143
281
  const opts = { cwd: review.local_path };
144
282
  const [{ stdout: unstaged }, { stdout: untracked }] = await Promise.all([
145
- execPromise(`git diff ${GIT_DIFF_FLAGS} --name-only`, opts),
146
- execPromise('git ls-files --others --exclude-standard', opts),
283
+ execPromise(`git ${GIT_PATH_CONFIG} diff ${GIT_DIFF_FLAGS} --name-only -z`, opts),
284
+ execPromise(`git ${GIT_PATH_CONFIG} ls-files -z --others --exclude-standard`, opts),
147
285
  ]);
148
- const combined = `${unstaged}\n${untracked}`
149
- .split('\n')
150
- .map(l => l.trim())
151
- .filter(Boolean);
152
- return [...new Set(combined)];
286
+ return [...new Set([...splitNulPaths(unstaged), ...splitNulPaths(untracked)])];
153
287
  } catch {
154
288
  // git error – fall through to empty list
155
289
  }
@@ -161,7 +295,9 @@ async function getDiffFileList(db, review) {
161
295
 
162
296
  module.exports = {
163
297
  getDiffFileList,
298
+ splitUnifiedDiffPatches,
164
299
  parseUnifiedDiffPatches,
165
300
  countPatchStats,
301
+ buildChangedFileEntries,
166
302
  mergeChangedFilesWithDiff
167
303
  };
@@ -0,0 +1,77 @@
1
+ // Copyright 2026 Tim Perkins (tjwp) | SPDX-License-Identifier: Apache-2.0
2
+ /**
3
+ * Git path spelling helpers for the server.
4
+ *
5
+ * Every git command that prints paths runs with core.quotePath=false (see
6
+ * GIT_PATH_CONFIG in src/git/diff-flags.js), and path lists are read with -z,
7
+ * so names arrive verbatim. What is left to decode is the diff text itself:
8
+ * git still C-quotes a header path containing a control character, `"` or
9
+ * `\`, and diffs cached by older versions quote non-ASCII names too.
10
+ *
11
+ * The decoder is shared with the browser (public/js/utils/git-paths.js) so
12
+ * both sides spell every path the same way.
13
+ */
14
+ const { decodeGitPath, parseDiffGitPaths, parsePatchPaths } = require('../../public/js/utils/git-paths');
15
+
16
+ const QUOTE_ESCAPES = { 0x07: 'a', 0x08: 'b', 0x09: 't', 0x0a: 'n', 0x0b: 'v', 0x0c: 'f', 0x0d: 'r', 0x22: '"', 0x5c: '\\' };
17
+
18
+ /**
19
+ * Quote a path the way git does with core.quotePath=false, so a header we
20
+ * synthesize is spelled like one git would print. Only control characters,
21
+ * DEL, `"` and `\` force quoting; non-ASCII stays verbatim. Paths that need no
22
+ * quoting are returned unchanged.
23
+ * @param {string} value - Real path (may include an `a/` or `b/` prefix)
24
+ * @returns {string} Git-spelled path
25
+ */
26
+ function quoteGitPath(value) {
27
+ let needsQuote = false;
28
+ let out = '';
29
+ for (const char of value) {
30
+ const code = char.codePointAt(0);
31
+ if (QUOTE_ESCAPES[code] !== undefined) {
32
+ out += `\\${QUOTE_ESCAPES[code]}`;
33
+ needsQuote = true;
34
+ } else if (code < 0x20 || code === 0x7f) {
35
+ out += `\\${code.toString(8).padStart(3, '0')}`;
36
+ needsQuote = true;
37
+ } else {
38
+ out += char;
39
+ }
40
+ }
41
+ return needsQuote ? `"${out}"` : value;
42
+ }
43
+
44
+ /**
45
+ * Decode the path in a `--- ` / `+++ ` file line or a `rename from` /
46
+ * `rename to` extended header. Git ends a `---`/`+++` path that contains a
47
+ * space with a tab; a tab inside a real name is always C-quoted, so one
48
+ * trailing raw tab is never part of the path.
49
+ * @param {string} value - Text after `--- `, `+++ `, `rename from ` or `rename to `
50
+ * @param {string} [prefix] - Prefix to strip from the decoded path (`a/` or `b/`)
51
+ * @returns {string|null} Decoded path, or null for `/dev/null`
52
+ */
53
+ function decodeDiffLinePath(value, prefix = '') {
54
+ const raw = value.endsWith('\t') ? value.slice(0, -1) : value;
55
+ if (raw === '/dev/null') return null;
56
+ const decoded = decodeGitPath(raw);
57
+ return prefix && decoded.startsWith(prefix) ? decoded.slice(prefix.length) : decoded;
58
+ }
59
+
60
+ /**
61
+ * Split NUL-terminated git output (`--name-only -z`, `ls-files -z`) into
62
+ * paths. Paths are verbatim: no trimming, no unquoting.
63
+ * @param {string} stdout - Raw command output
64
+ * @returns {string[]} Non-empty paths
65
+ */
66
+ function splitNulPaths(stdout) {
67
+ return (stdout || '').split('\0').filter(path => path.length > 0);
68
+ }
69
+
70
+ module.exports = {
71
+ decodeGitPath,
72
+ parseDiffGitPaths,
73
+ parsePatchPaths,
74
+ quoteGitPath,
75
+ decodeDiffLinePath,
76
+ splitNulPaths
77
+ };
@@ -179,35 +179,11 @@ function resolveRenamedFile(fileName) {
179
179
  return fileName.replace(/\{[^}]*\s*=>\s*([^}]*)\}/, '$1').replace(/\/+/g, '/').replace(/^\//, '');
180
180
  }
181
181
 
182
- /**
183
- * Resolve git rename syntax to extract the OLD filename.
184
- *
185
- * Git represents renames with curly-brace syntax:
186
- * "tests/{old.js => new.js}" → "tests/old.js"
187
- * "{old-dir => new-dir}/file.js" → "old-dir/file.js"
188
- * "a/{b => c}/d.js" → "a/b/d.js"
189
- *
190
- * @param {string} fileName - File name possibly containing rename syntax
191
- * @returns {string} Resolved file name with the old path, or original if no rename syntax
192
- *
193
- * @example
194
- * resolveRenamedFileOld('tests/{old.js => new.js}') // => 'tests/old.js'
195
- * resolveRenamedFileOld('{old-dir => new-dir}/file.js') // => 'old-dir/file.js'
196
- * resolveRenamedFileOld('a/{b => c}/d.js') // => 'a/b/d.js'
197
- * resolveRenamedFileOld('src/foo.js') // => 'src/foo.js'
198
- * resolveRenamedFileOld(null) // => null
199
- */
200
- function resolveRenamedFileOld(fileName) {
201
- if (!fileName) return fileName;
202
- return fileName.replace(/\{([^}]*?)\s*=>\s*[^}]*\}/, '$1').replace(/\/+/g, '/').replace(/^\//, '');
203
- }
204
-
205
182
  module.exports = {
206
183
  normalizePath,
207
184
  pathsEqual,
208
185
  pathExistsInList,
209
186
  pathExistsInSet,
210
187
  normalizeRepository,
211
- resolveRenamedFile,
212
- resolveRenamedFileOld
188
+ resolveRenamedFile
213
189
  };