praxis-agent 0.20.4 → 0.20.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.
@@ -28,7 +28,74 @@ export function visiblePatchLines(patch) {
28
28
  !isNewFileHeader(line) &&
29
29
  !line.startsWith('@@ '));
30
30
  }
31
+ async function hasHead(cwd) {
32
+ try {
33
+ await execFileAsync('git', ['-C', cwd, 'rev-parse', '--verify', '--quiet', 'HEAD'], { encoding: 'utf8' });
34
+ return true;
35
+ }
36
+ catch {
37
+ return false;
38
+ }
39
+ }
40
+ async function diffUnbornPath(cwd, path) {
41
+ try {
42
+ const result = await execFileAsync('git', [
43
+ '-C',
44
+ cwd,
45
+ 'diff',
46
+ '--no-index',
47
+ '--no-ext-diff',
48
+ '--no-color',
49
+ '--unified=3',
50
+ '--',
51
+ '/dev/null',
52
+ path,
53
+ ], { encoding: 'utf8', maxBuffer: 8 * 1024 * 1024 });
54
+ return result.stdout;
55
+ }
56
+ catch (error) {
57
+ const execError = error;
58
+ // `git diff --no-index` exits with code 1 when the inputs differ.
59
+ if (execError.code === 1) {
60
+ return execError.stdout ?? '';
61
+ }
62
+ throw error;
63
+ }
64
+ }
65
+ async function loadUnbornDiff(cwd) {
66
+ const stagedResult = await execFileAsync('git', ['-C', cwd, 'diff', '--cached', '--name-only', '-z', '--'], { encoding: 'utf8', maxBuffer: 8 * 1024 * 1024 });
67
+ const untrackedResult = await execFileAsync('git', ['-C', cwd, 'ls-files', '--others', '--exclude-standard', '-z'], { encoding: 'utf8', maxBuffer: 8 * 1024 * 1024 });
68
+ const stagedPaths = stagedResult.stdout.split('\0').filter(Boolean);
69
+ const untrackedPaths = untrackedResult.stdout.split('\0').filter(Boolean);
70
+ const files = [];
71
+ for (const path of stagedPaths) {
72
+ const result = await execFileAsync('git', [
73
+ '-C',
74
+ cwd,
75
+ 'diff',
76
+ '--cached',
77
+ '--no-ext-diff',
78
+ '--no-color',
79
+ '--unified=3',
80
+ '--',
81
+ path,
82
+ ], { encoding: 'utf8', maxBuffer: 8 * 1024 * 1024 });
83
+ files.push({ path, patch: result.stdout, ...changedLines(result.stdout) });
84
+ }
85
+ for (const path of untrackedPaths) {
86
+ const patch = await diffUnbornPath(cwd, path);
87
+ files.push({ path, patch, ...changedLines(patch) });
88
+ }
89
+ return {
90
+ files,
91
+ additions: files.reduce((total, file) => total + file.additions, 0),
92
+ deletions: files.reduce((total, file) => total + file.deletions, 0),
93
+ };
94
+ }
31
95
  export async function loadGitDiff(cwd) {
96
+ if (!(await hasHead(cwd))) {
97
+ return loadUnbornDiff(cwd);
98
+ }
32
99
  const names = await execFileAsync('git', ['-C', cwd, 'diff', '--name-only', '-z', 'HEAD', '--'], { encoding: 'utf8', maxBuffer: 8 * 1024 * 1024 });
33
100
  const paths = names.stdout.split('\0').filter(Boolean);
34
101
  const files = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "praxis-agent",
3
- "version": "0.20.4",
3
+ "version": "0.20.5",
4
4
  "description": "Local-first, single-user general agent for the command line.",
5
5
  "license": "MIT",
6
6
  "author": "wuqisen",