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

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 (49) hide show
  1. package/README.md +7 -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 +15 -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/git/diff-flags.js +26 -12
  34. package/src/git/worktree.js +21 -43
  35. package/src/github/client.js +0 -88
  36. package/src/github/impl/graphql/pending-review-comments.js +5 -1
  37. package/src/github/submit-pr-context.js +56 -0
  38. package/src/local-review.js +34 -17
  39. package/src/main.js +80 -106
  40. package/src/routes/executable-analysis.js +14 -15
  41. package/src/routes/local.js +3 -5
  42. package/src/routes/pr.js +18 -105
  43. package/src/setup/pr-setup.js +1 -1
  44. package/src/setup/stack-setup.js +1 -1
  45. package/src/utils/diff-annotator.js +175 -25
  46. package/src/utils/diff-file-content.js +4 -26
  47. package/src/utils/diff-file-list.js +178 -42
  48. package/src/utils/git-paths.js +77 -0
  49. package/src/utils/paths.js +1 -25
@@ -29,21 +29,35 @@ const GIT_DIFF_FLAGS_ARRAY = [
29
29
  ];
30
30
 
31
31
  /**
32
- * Array form for simple-git .diffSummary() calls.
33
- * Use --numstat so simple-git parses machine-readable output with exact file paths.
34
- * The default --stat output is display-oriented and may abbreviate long paths,
35
- * which breaks downstream matching for generated route files and similar cases.
36
- * Omits --src-prefix/--dst-prefix since diffSummary doesn't output file content with prefixes.
32
+ * Git config that makes path-producing commands print names verbatim.
33
+ *
34
+ * With git's default core.quotePath=true, any path with a byte >= 0x80 is
35
+ * C-quoted with octal escapes (`"caf\303\251.js"`) in diff headers,
36
+ * --name-only, --numstat and ls-files output. Pinning it off keeps non-ASCII
37
+ * names readable everywhere. `-c` must precede the subcommand, so exec calls
38
+ * spell commands as `git ${GIT_PATH_CONFIG} diff ...`.
39
+ *
40
+ * Git still quotes paths containing control characters, `"` or `\` in diff
41
+ * headers; src/utils/git-paths.js decodes those. Path LISTS are read with -z,
42
+ * which is never quoted.
37
43
  */
38
- const GIT_DIFF_SUMMARY_FLAGS_ARRAY = [
39
- '--no-color',
40
- '--no-ext-diff',
41
- '--no-relative',
42
- '--numstat'
43
- ];
44
+ const GIT_PATH_CONFIG = '-c core.quotePath=false';
45
+
46
+ /**
47
+ * Array form of GIT_PATH_CONFIG for execFile / spawn argument lists.
48
+ */
49
+ const GIT_PATH_CONFIG_ARRAY = ['-c', 'core.quotePath=false'];
50
+
51
+ /**
52
+ * simple-git constructor options carrying the same config, for every
53
+ * simple-git instance that runs diff: `simpleGit(dir, SIMPLE_GIT_PATH_OPTIONS)`.
54
+ */
55
+ const SIMPLE_GIT_PATH_OPTIONS = Object.freeze({ config: ['core.quotePath=false'] });
44
56
 
45
57
  module.exports = {
46
58
  GIT_DIFF_FLAGS,
47
59
  GIT_DIFF_FLAGS_ARRAY,
48
- GIT_DIFF_SUMMARY_FLAGS_ARRAY
60
+ GIT_PATH_CONFIG,
61
+ GIT_PATH_CONFIG_ARRAY,
62
+ SIMPLE_GIT_PATH_OPTIONS
49
63
  };
@@ -6,8 +6,10 @@ const os = require('os');
6
6
  const { getConfigDir, DEFAULT_CHECKOUT_TIMEOUT_MS } = require('../config');
7
7
  const { WorktreeRepository, generateWorktreeId } = require('../database');
8
8
  const { getGeneratedFilePatterns } = require('./gitattributes');
9
- const { normalizeRepository, resolveRenamedFile, resolveRenamedFileOld } = require('../utils/paths');
10
- const { GIT_DIFF_FLAGS_ARRAY, GIT_DIFF_SUMMARY_FLAGS_ARRAY } = require('./diff-flags');
9
+ const { normalizeRepository } = require('../utils/paths');
10
+ const { buildChangedFileEntries } = require('../utils/diff-file-list');
11
+ const { decodeGitPath } = require('../utils/git-paths');
12
+ const { GIT_DIFF_FLAGS_ARRAY, SIMPLE_GIT_PATH_OPTIONS } = require('./diff-flags');
11
13
  const { rawFetchNoTags, fetchWithPruneRecovery } = require('./fetch-helpers');
12
14
  const { spawn, execSync } = require('child_process');
13
15
 
@@ -39,7 +41,7 @@ class GitWorktreeManager {
39
41
  * @returns {import('simple-git').SimpleGit}
40
42
  */
41
43
  _gitFor(dirPath) {
42
- return simpleGit(dirPath);
44
+ return simpleGit(dirPath, SIMPLE_GIT_PATH_OPTIONS);
43
45
  }
44
46
 
45
47
  /**
@@ -873,48 +875,21 @@ class GitWorktreeManager {
873
875
  }
874
876
 
875
877
  /**
876
- * Get list of changed files in the PR
877
- * @param {string} worktreePath - Path to worktree
878
- * @param {Object} prData - PR data from GitHub API
878
+ * Get list of changed files in the PR, built from its unified diff.
879
+ *
880
+ * The diff is the one source of PR paths: renames come from its explicit
881
+ * `rename from` / `rename to` lines and counts from its hunks, so
882
+ * changed_files spells every file exactly like the diff headers the
883
+ * browser keys on (see buildChangedFileEntries).
884
+ *
885
+ * @param {string} worktreePath - Path to worktree (for .gitattributes)
886
+ * @param {string} diff - Unified diff from generateUnifiedDiff
879
887
  * @returns {Promise<Array>} Array of changed file information
880
888
  */
881
- async getChangedFiles(worktreePath, prData) {
889
+ async getChangedFiles(worktreePath, diff) {
882
890
  try {
883
- const git = this._gitFor(worktreePath);
884
- const baseSha = this.getPRBaseSha(prData);
885
- const headSha = this.getPRHeadSha(prData);
886
-
887
- await this.assertCommitAvailableLocally(git, baseSha, 'Base SHA');
888
- await this.assertCommitAvailableLocally(git, headSha, 'Head SHA');
889
-
890
- // Get file changes with stats using base SHA and head SHA
891
- // This ensures we get the exact files changed in the PR, even if the base branch has moved
892
- const diffSummary = await git.diffSummary([
893
- `${baseSha}...${headSha}`,
894
- ...GIT_DIFF_SUMMARY_FLAGS_ARRAY
895
- ]);
896
-
897
- // Parse .gitattributes to identify generated files
898
891
  const gitattributes = await getGeneratedFilePatterns(worktreePath);
899
-
900
- return diffSummary.files.map(file => {
901
- const resolvedFile = resolveRenamedFile(file.file);
902
- const isRenamed = resolvedFile !== file.file;
903
- const result = {
904
- file: resolvedFile,
905
- insertions: file.insertions,
906
- deletions: file.deletions,
907
- changes: file.changes,
908
- binary: file.binary || false,
909
- generated: gitattributes.isGenerated(resolvedFile)
910
- };
911
- if (isRenamed) {
912
- result.renamed = true;
913
- result.renamedFrom = resolveRenamedFileOld(file.file);
914
- }
915
- return result;
916
- });
917
-
892
+ return buildChangedFileEntries(diff, gitattributes);
918
893
  } catch (error) {
919
894
  console.error('Error getting changed files:', error);
920
895
  throw this.wrapError('Failed to get changed files', error);
@@ -1449,9 +1424,12 @@ class GitWorktreeManager {
1449
1424
  */
1450
1425
  async getSparseCheckoutPatterns(repoPath) {
1451
1426
  try {
1452
- const git = simpleGit(repoPath);
1427
+ // `sparse-checkout list` C-quotes names like a diff header does:
1428
+ // core.quotePath=false keeps non-ASCII verbatim, and decodeGitPath
1429
+ // undoes the quoting git still applies to `"`, `\` and control chars.
1430
+ const git = this._gitFor(repoPath);
1453
1431
  const output = await git.raw(['sparse-checkout', 'list']);
1454
- return output.trim().split('\n').filter(Boolean);
1432
+ return output.split('\n').filter(Boolean).map(decodeGitPath);
1455
1433
  } catch {
1456
1434
  return [];
1457
1435
  }
@@ -986,94 +986,6 @@ class GitHubClient {
986
986
  }
987
987
  }
988
988
 
989
- /**
990
- * Calculate diff position for a given file path and line number
991
- * Position is counted from the first @@ hunk header, where position 1 = first line after @@
992
- * @param {string} diffContent - The unified diff content
993
- * @param {string} filePath - File path to find in diff
994
- * @param {number} lineNumber - Line number in the new file
995
- * @returns {number} Diff position or -1 if not found
996
- */
997
- calculateDiffPosition(diffContent, filePath, lineNumber) {
998
- if (!diffContent || !filePath || lineNumber === undefined) {
999
- console.warn('calculateDiffPosition: Missing required parameters', {
1000
- filePath,
1001
- lineNumber,
1002
- hasDiffContent: !!diffContent
1003
- });
1004
- return -1;
1005
- }
1006
-
1007
- const lines = diffContent.split('\n');
1008
- let inFile = false;
1009
- let currentFile = '';
1010
- let position = 0;
1011
- let newLineNumber = 0;
1012
- let foundHunk = false;
1013
-
1014
- for (let i = 0; i < lines.length; i++) {
1015
- const line = lines[i];
1016
-
1017
- if (line.startsWith('diff --git')) {
1018
- const match = line.match(/diff --git a\/(.+) b\/(.+)/);
1019
- if (match) {
1020
- currentFile = match[2];
1021
- inFile = currentFile === filePath;
1022
- position = 0;
1023
- newLineNumber = 0;
1024
- foundHunk = false;
1025
- }
1026
- continue;
1027
- }
1028
-
1029
- if (!inFile) continue;
1030
-
1031
- if (line.startsWith('@@')) {
1032
- const match = line.match(/@@ -\d+,?\d* \+(\d+),?\d* @@/);
1033
- if (match) {
1034
- newLineNumber = parseInt(match[1]) - 1;
1035
-
1036
- if (!foundHunk) {
1037
- position = 0;
1038
- foundHunk = true;
1039
- } else {
1040
- position++;
1041
- }
1042
- }
1043
- continue;
1044
- }
1045
-
1046
- if (!foundHunk) continue;
1047
-
1048
- const isDiffContentLine = line.startsWith('+') || line.startsWith('-') || line.startsWith(' ') || (line === '' && foundHunk);
1049
-
1050
- if (!isDiffContentLine) continue;
1051
-
1052
- position++;
1053
-
1054
- if (line.startsWith('+')) {
1055
- newLineNumber++;
1056
- if (newLineNumber === lineNumber) {
1057
- return position;
1058
- }
1059
- } else if (line.startsWith(' ') || (line === '' && foundHunk)) {
1060
- newLineNumber++;
1061
- if (newLineNumber === lineNumber) {
1062
- return position;
1063
- }
1064
- }
1065
- }
1066
-
1067
- console.warn('calculateDiffPosition: Position not found', {
1068
- filePath,
1069
- lineNumber,
1070
- inFile,
1071
- foundHunk,
1072
- finalNewLineNumber: newLineNumber
1073
- });
1074
- return -1;
1075
- }
1076
-
1077
989
  /**
1078
990
  * Handle errors specific to review submission
1079
991
  * @param {Error} error - The API error
@@ -45,7 +45,11 @@ function buildBatchMutation(batch) {
45
45
  }
46
46
 
47
47
  const side = comment.side || 'RIGHT';
48
- const startLineField = comment.start_line ? `startLine: ${comment.start_line}\n ` : '';
48
+ // A range sends its start side too: GitHub defaults startSide to RIGHT,
49
+ // which breaks a LEFT-side (deleted lines) range.
50
+ const startLineField = comment.start_line
51
+ ? `startLine: ${comment.start_line}\n startSide: ${comment.start_side || side}\n `
52
+ : '';
49
53
  return `
50
54
  comment${index}: addPullRequestReviewThread(input: {
51
55
  pullRequestId: $prId
@@ -0,0 +1,56 @@
1
+ // Copyright 2026 Tim Perkins (tjwp) | SPDX-License-Identifier: Apache-2.0
2
+ const logger = require('../utils/logger');
3
+
4
+ /**
5
+ * Build the `prContext` handed to `createReviewGraphQL` /
6
+ * `createDraftReviewGraphQL` when a review is submitted to GitHub or an
7
+ * alt-host.
8
+ *
9
+ * Shared by both submit entry points so they cannot drift apart:
10
+ * - the web submit route (`POST /api/pr/:owner/:repo/:number/submit-review`
11
+ * in src/routes/pr.js)
12
+ * - headless `--ai-draft` / `--ai-review` (`performHeadlessReview` in
13
+ * src/main.js)
14
+ *
15
+ * `headSha` (the PR head SHA) is required by the host pending-review-comments
16
+ * path: GitHub-compatible alt-hosts validate each inline comment like
17
+ * `pulls.createReviewComment`, which rejects a missing `commit_id` with a 422.
18
+ * The GraphQL path on github.com ignores it (the pending review pins the
19
+ * commit implicitly), so threading it through is harmless there.
20
+ *
21
+ * `prData.head_sha` (the parsed `pr_metadata.pr_data` JSON) is the canonical
22
+ * source; `prMetadata.head_sha` is a fallback for records that expose it at
23
+ * the top level (as `PRMetadataRepository.getByPR` does). When neither is
24
+ * present the context carries `headSha: null` and a warning is logged so the
25
+ * resulting 422 is diagnosable.
26
+ *
27
+ * @param {Object} params
28
+ * @param {string} params.owner - Repository owner
29
+ * @param {string} params.repo - Repository name
30
+ * @param {number} params.prNumber - Pull request number
31
+ * @param {Object|null} [params.existingDraft] - The user's pending review, if
32
+ * any; its numeric `databaseId` becomes `reviewId` for REST/host paths
33
+ * @param {Object|null} [params.prData] - Parsed `pr_data` JSON
34
+ * @param {Object|null} [params.prMetadata] - The `pr_metadata` record
35
+ * @returns {{ owner: string, repo: string, prNumber: number, reviewId: (number|undefined), headSha: (string|null) }}
36
+ */
37
+ function buildSubmitPrContext({ owner, repo, prNumber, existingDraft = null, prData = null, prMetadata = null }) {
38
+ const headSha = prData?.head_sha || prMetadata?.head_sha || null;
39
+ if (!headSha) {
40
+ logger.warn(
41
+ `Submit review for ${owner}/${repo}#${prNumber}: PR head SHA is missing ` +
42
+ `(prData.head_sha and prMetadata.head_sha both absent). Host inline-comment ` +
43
+ `posting will likely fail with a 422 missing commit_id error.`
44
+ );
45
+ }
46
+
47
+ return {
48
+ owner,
49
+ repo,
50
+ prNumber,
51
+ reviewId: existingDraft?.databaseId,
52
+ headSha
53
+ };
54
+ }
55
+
56
+ module.exports = { buildSubmitPrContext };
@@ -20,7 +20,8 @@ const { localReviewDiffs } = require('./routes/shared');
20
20
  const summaryGenerator = require('./ai/summary-generator');
21
21
  const tourGenerator = require('./ai/tour-generator');
22
22
  const { getShaAbbrevLength } = require('./git/sha-abbrev');
23
- const { GIT_DIFF_FLAGS, GIT_DIFF_FLAGS_ARRAY } = require('./git/diff-flags');
23
+ const { GIT_DIFF_FLAGS, GIT_DIFF_FLAGS_ARRAY, GIT_PATH_CONFIG, GIT_PATH_CONFIG_ARRAY } = require('./git/diff-flags');
24
+ const { quoteGitPath, splitNulPaths } = require('./utils/git-paths');
24
25
  // Namespace import (not destructured) so detectBaseBranch is resolved off the
25
26
  // module object at call time — this keeps it interceptable by vi.spyOn on the
26
27
  // base-branch module in tests, unlike a destructured binding captured at load.
@@ -292,13 +293,13 @@ function isBinaryFile(buffer) {
292
293
  async function getUntrackedFiles(repoPath) {
293
294
  try {
294
295
  // Get list of untracked files (excluding ignored files)
295
- const output = execSync('git ls-files --others --exclude-standard', {
296
+ const output = execSync(`git ${GIT_PATH_CONFIG} ls-files -z --others --exclude-standard`, {
296
297
  cwd: repoPath,
297
298
  encoding: 'utf8',
298
299
  stdio: ['pipe', 'pipe', 'pipe']
299
300
  });
300
301
 
301
- const files = output.trim().split('\n').filter(f => f.length > 0);
302
+ const files = splitNulPaths(output);
302
303
 
303
304
  // Process files in parallel for better performance
304
305
  // Use Promise.allSettled to process all files even if some fail
@@ -398,6 +399,24 @@ async function findMergeBase(repoPath, baseBranch) {
398
399
  }
399
400
  }
400
401
 
402
+ /**
403
+ * Rewrite the file headers of a `git diff --no-index /dev/null <abs path>`
404
+ * patch to name the repo-relative path, spelled the way git spells a header
405
+ * (C-quoted only when the name contains a control character, `"` or `\`).
406
+ * The `+++` path gets git's trailing tab when it contains a space.
407
+ * @param {string} fileDiff - Patch for one untracked file
408
+ * @param {string} file - Repo-relative path
409
+ * @returns {string} Patch with repo-relative headers
410
+ */
411
+ function respellUntrackedDiffHeaders(fileDiff, file) {
412
+ const newPath = quoteGitPath(`b/${file}`);
413
+ const header = `diff --git ${quoteGitPath(`a/${file}`)} ${newPath}`;
414
+ const plusLine = `+++ ${newPath}${file.includes(' ') ? '\t' : ''}`;
415
+ return fileDiff
416
+ .replace(/^diff --git .*$/m, () => header)
417
+ .replace(/^\+\+\+ .*$/m, () => plusLine);
418
+ }
419
+
401
420
  /**
402
421
  * Generate diff output for untracked files using git diff --no-index.
403
422
  * @param {string} repoPath - Path to the git repository
@@ -426,7 +445,7 @@ function generateUntrackedDiffs(repoPath, untrackedFiles, options = {}) {
426
445
  const filePath = path.join(repoPath, untracked.file);
427
446
  let fileDiff;
428
447
  try {
429
- fileDiff = execFileSync('git', [...diffArgs, filePath], {
448
+ fileDiff = execFileSync('git', [...GIT_PATH_CONFIG_ARRAY, ...diffArgs, filePath], {
430
449
  cwd: repoPath,
431
450
  encoding: 'utf8',
432
451
  stdio: ['pipe', 'pipe', 'pipe'],
@@ -447,9 +466,7 @@ function generateUntrackedDiffs(repoPath, untrackedFiles, options = {}) {
447
466
  }
448
467
 
449
468
  if (fileDiff && fileDiff.trim()) {
450
- const normalizedDiff = fileDiff
451
- .replace(/^diff --git a\/.+? b\/.+$/m, `diff --git a/${untracked.file} b/${untracked.file}`)
452
- .replace(/^\+\+\+ b\/.+$/m, `+++ b/${untracked.file}`);
469
+ const normalizedDiff = respellUntrackedDiffHeaders(fileDiff, untracked.file);
453
470
 
454
471
  if (diff) {
455
472
  diff += '\n';
@@ -522,19 +539,19 @@ async function generateScopedDiff(repoPath, scopeStart, scopeEnd, baseBranch, op
522
539
  try {
523
540
  if (hasBranch) {
524
541
  // Branch scope → working tree vs merge-base (includes committed + staged + unstaged)
525
- diff = execSync(`git diff ${mergeBaseSha} ${GIT_DIFF_FLAGS}${contextFlag}${extraArgsStr}${wFlag}`, {
542
+ diff = execSync(`git ${GIT_PATH_CONFIG} diff ${mergeBaseSha} ${GIT_DIFF_FLAGS}${contextFlag}${extraArgsStr}${wFlag}`, {
526
543
  cwd: repoPath, encoding: 'utf8', stdio: ['pipe', 'pipe', 'pipe'],
527
544
  maxBuffer: 50 * 1024 * 1024
528
545
  });
529
546
  } else if (hasStaged) {
530
547
  // Staged + Unstaged scope → all changes vs HEAD
531
- diff = execSync(`git diff HEAD ${GIT_DIFF_FLAGS}${contextFlag}${extraArgsStr}${wFlag}`, {
548
+ diff = execSync(`git ${GIT_PATH_CONFIG} diff HEAD ${GIT_DIFF_FLAGS}${contextFlag}${extraArgsStr}${wFlag}`, {
532
549
  cwd: repoPath, encoding: 'utf8', stdio: ['pipe', 'pipe', 'pipe'],
533
550
  maxBuffer: 50 * 1024 * 1024
534
551
  });
535
552
  } else {
536
553
  // Unstaged only (or Unstaged–Untracked) → working tree changes
537
- diff = execSync(`git diff ${GIT_DIFF_FLAGS}${contextFlag}${extraArgsStr}${wFlag}`, {
554
+ diff = execSync(`git ${GIT_PATH_CONFIG} diff ${GIT_DIFF_FLAGS}${contextFlag}${extraArgsStr}${wFlag}`, {
538
555
  cwd: repoPath, encoding: 'utf8', stdio: ['pipe', 'pipe', 'pipe'],
539
556
  maxBuffer: 50 * 1024 * 1024
540
557
  });
@@ -553,7 +570,7 @@ async function generateScopedDiff(repoPath, scopeStart, scopeEnd, baseBranch, op
553
570
  // Count staged/unstaged for stats when relevant
554
571
  if (hasStaged) {
555
572
  try {
556
- const stagedDiff = execSync(`git diff --cached --stat ${GIT_DIFF_FLAGS}`, {
573
+ const stagedDiff = execSync(`git ${GIT_PATH_CONFIG} diff --cached --stat ${GIT_DIFF_FLAGS}`, {
557
574
  cwd: repoPath, encoding: 'utf8', stdio: ['pipe', 'pipe', 'pipe']
558
575
  });
559
576
  if (stagedDiff.trim()) {
@@ -563,7 +580,7 @@ async function generateScopedDiff(repoPath, scopeStart, scopeEnd, baseBranch, op
563
580
  }
564
581
  if (hasUnstaged) {
565
582
  try {
566
- const unstagedDiff = execSync(`git diff --stat ${GIT_DIFF_FLAGS}`, {
583
+ const unstagedDiff = execSync(`git ${GIT_PATH_CONFIG} diff --stat ${GIT_DIFF_FLAGS}`, {
567
584
  cwd: repoPath, encoding: 'utf8', stdio: ['pipe', 'pipe', 'pipe']
568
585
  });
569
586
  if (unstagedDiff.trim()) {
@@ -615,7 +632,7 @@ async function computeScopedDigest(repoPath, scopeStart, scopeEnd) {
615
632
  // Staged in scope → cached diff content
616
633
  if (scopeIncludes(scopeStart, scopeEnd, 'staged')) {
617
634
  try {
618
- const result = await execAsync(`git diff --cached ${GIT_DIFF_FLAGS}`, {
635
+ const result = await execAsync(`git ${GIT_PATH_CONFIG} diff --cached ${GIT_DIFF_FLAGS}`, {
619
636
  cwd: repoPath, encoding: 'utf8', maxBuffer: 50 * 1024 * 1024
620
637
  });
621
638
  parts.push('STAGED:' + result.stdout);
@@ -627,7 +644,7 @@ async function computeScopedDigest(repoPath, scopeStart, scopeEnd) {
627
644
  // Unstaged in scope → working tree diff
628
645
  if (scopeIncludes(scopeStart, scopeEnd, 'unstaged')) {
629
646
  try {
630
- const result = await execAsync(`git diff ${GIT_DIFF_FLAGS}`, {
647
+ const result = await execAsync(`git ${GIT_PATH_CONFIG} diff ${GIT_DIFF_FLAGS}`, {
631
648
  cwd: repoPath, encoding: 'utf8', maxBuffer: 50 * 1024 * 1024
632
649
  });
633
650
  parts.push('UNSTAGED:' + result.stdout);
@@ -639,10 +656,10 @@ async function computeScopedDigest(repoPath, scopeStart, scopeEnd) {
639
656
  // Untracked in scope → file list with sizes/mtimes
640
657
  if (scopeIncludes(scopeStart, scopeEnd, 'untracked')) {
641
658
  try {
642
- const result = await execAsync('git ls-files --others --exclude-standard', {
659
+ const result = await execAsync(`git ${GIT_PATH_CONFIG} ls-files -z --others --exclude-standard`, {
643
660
  cwd: repoPath, encoding: 'utf8'
644
661
  });
645
- const files = result.stdout.trim().split('\n').filter(f => f.length > 0);
662
+ const files = splitNulPaths(result.stdout);
646
663
  let untrackedInfo = '';
647
664
  for (const file of files) {
648
665
  try {
@@ -682,7 +699,7 @@ async function generateLocalDiff(repoPath, options = {}) {
682
699
  // Always count staged changes for CLI info message, even when staged is out of scope
683
700
  if (!result.stats.stagedChanges) {
684
701
  try {
685
- const stagedStat = execSync(`git diff --cached --stat ${GIT_DIFF_FLAGS}`, {
702
+ const stagedStat = execSync(`git ${GIT_PATH_CONFIG} diff --cached --stat ${GIT_DIFF_FLAGS}`, {
686
703
  cwd: repoPath, encoding: 'utf8', stdio: ['pipe', 'pipe', 'pipe']
687
704
  });
688
705
  if (stagedStat.trim()) {