@self-review/core 1.44.0 → 2.0.2
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.
- package/dist/chunk-4YO2MI6B.js +269 -0
- package/dist/chunk-4YO2MI6B.js.map +1 -0
- package/dist/chunk-QHS36X6T.js +450 -0
- package/dist/chunk-QHS36X6T.js.map +1 -0
- package/dist/diff-parser-B6S3KG5T.js +9 -0
- package/dist/git-N5HVNPKQ.js +24 -0
- package/dist/index.cjs +3493 -1108
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +948 -142
- package/dist/index.d.ts +948 -142
- package/dist/index.js +3023 -986
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/dist/chunk-A7A5ZFT3.js +0 -233
- package/dist/chunk-A7A5ZFT3.js.map +0 -1
- package/dist/chunk-OQRS7NDT.js +0 -200
- package/dist/chunk-OQRS7NDT.js.map +0 -1
- package/dist/diff-parser-2JM4CZR3.js +0 -7
- package/dist/git-E7WZPKRC.js +0 -23
- /package/dist/{diff-parser-2JM4CZR3.js.map → diff-parser-B6S3KG5T.js.map} +0 -0
- /package/dist/{git-E7WZPKRC.js.map → git-N5HVNPKQ.js.map} +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@self-review/core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "Core library for self-review: diff parsing, git operations, review session orchestration, remote PR/MR handling, XML serialization, CLI argument parsing, and configuration",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@self-review/types": "*",
|
|
34
|
-
"fast-xml-parser": "^5.
|
|
34
|
+
"fast-xml-parser": "^5.11.2",
|
|
35
35
|
"ignore": "^7.0.5",
|
|
36
36
|
"xmllint-wasm": "^5.1.0",
|
|
37
37
|
"yaml": "^2.8.2"
|
package/dist/chunk-A7A5ZFT3.js
DELETED
|
@@ -1,233 +0,0 @@
|
|
|
1
|
-
// src/git.ts
|
|
2
|
-
import { execSync, execFile, execFileSync } from "child_process";
|
|
3
|
-
import { promisify } from "util";
|
|
4
|
-
|
|
5
|
-
// src/synthetic-diff.ts
|
|
6
|
-
import { readFileSync } from "fs";
|
|
7
|
-
import { join } from "path";
|
|
8
|
-
var C_STYLE_ESCAPES = {
|
|
9
|
-
7: "\\a",
|
|
10
|
-
8: "\\b",
|
|
11
|
-
9: "\\t",
|
|
12
|
-
10: "\\n",
|
|
13
|
-
11: "\\v",
|
|
14
|
-
12: "\\f",
|
|
15
|
-
13: "\\r",
|
|
16
|
-
34: '\\"',
|
|
17
|
-
92: "\\\\"
|
|
18
|
-
};
|
|
19
|
-
function needsQuoting(byte) {
|
|
20
|
-
return byte < 32 || byte >= 127 || byte === 34 || byte === 92;
|
|
21
|
-
}
|
|
22
|
-
function quoteGitPath(path) {
|
|
23
|
-
const bytes = Buffer.from(path, "utf-8");
|
|
24
|
-
if (!bytes.some(needsQuoting)) return path;
|
|
25
|
-
let quoted = '"';
|
|
26
|
-
for (const byte of bytes) {
|
|
27
|
-
const escape = C_STYLE_ESCAPES[byte];
|
|
28
|
-
if (escape) {
|
|
29
|
-
quoted += escape;
|
|
30
|
-
} else if (byte < 32 || byte >= 127) {
|
|
31
|
-
quoted += `\\${byte.toString(8).padStart(3, "0")}`;
|
|
32
|
-
} else {
|
|
33
|
-
quoted += String.fromCharCode(byte);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return `${quoted}"`;
|
|
37
|
-
}
|
|
38
|
-
function generateSyntheticDiffs(paths, rootDir) {
|
|
39
|
-
const diffs = [];
|
|
40
|
-
for (const filePath of paths) {
|
|
41
|
-
const fullPath = join(rootDir, filePath);
|
|
42
|
-
let content;
|
|
43
|
-
try {
|
|
44
|
-
content = readFileSync(fullPath);
|
|
45
|
-
} catch {
|
|
46
|
-
continue;
|
|
47
|
-
}
|
|
48
|
-
const oldHeaderPath = quoteGitPath(`a/${filePath}`);
|
|
49
|
-
const newHeaderPath = quoteGitPath(`b/${filePath}`);
|
|
50
|
-
const sample = content.subarray(0, 8192);
|
|
51
|
-
const isBinary = sample.includes(0);
|
|
52
|
-
if (isBinary) {
|
|
53
|
-
diffs.push(
|
|
54
|
-
`diff --git ${oldHeaderPath} ${newHeaderPath}
|
|
55
|
-
new file mode 100644
|
|
56
|
-
Binary files /dev/null and ${newHeaderPath} differ`
|
|
57
|
-
);
|
|
58
|
-
continue;
|
|
59
|
-
}
|
|
60
|
-
const text = content.toString("utf-8");
|
|
61
|
-
const lines = text.split("\n");
|
|
62
|
-
if (lines.length > 0 && lines[lines.length - 1] === "") {
|
|
63
|
-
lines.pop();
|
|
64
|
-
}
|
|
65
|
-
const lineCount = lines.length;
|
|
66
|
-
const addedLines = lines.map((line) => `+${line}`).join("\n");
|
|
67
|
-
let diff = `diff --git ${oldHeaderPath} ${newHeaderPath}
|
|
68
|
-
new file mode 100644
|
|
69
|
-
--- /dev/null
|
|
70
|
-
+++ ${newHeaderPath}
|
|
71
|
-
@@ -0,0 +1,${lineCount} @@
|
|
72
|
-
` + addedLines;
|
|
73
|
-
if (text.length > 0 && !text.endsWith("\n")) {
|
|
74
|
-
diff += "\n\";
|
|
75
|
-
}
|
|
76
|
-
diffs.push(diff);
|
|
77
|
-
}
|
|
78
|
-
return diffs.join("\n");
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// src/git.ts
|
|
82
|
-
var execFileAsync = promisify(execFile);
|
|
83
|
-
function stripTrailingNewline(text) {
|
|
84
|
-
return text.replace(/\r?\n$/, "");
|
|
85
|
-
}
|
|
86
|
-
function runGitDiff(args) {
|
|
87
|
-
try {
|
|
88
|
-
try {
|
|
89
|
-
execSync("git --version", { stdio: "ignore" });
|
|
90
|
-
} catch {
|
|
91
|
-
console.error("Error: git is not installed or not in PATH");
|
|
92
|
-
process.exit(1);
|
|
93
|
-
}
|
|
94
|
-
try {
|
|
95
|
-
execSync("git rev-parse --git-dir", { stdio: "ignore" });
|
|
96
|
-
} catch {
|
|
97
|
-
console.error("Error: not a git repository (or any parent up to mount point)");
|
|
98
|
-
process.exit(1);
|
|
99
|
-
}
|
|
100
|
-
const result = execFileSync("git", ["diff", ...args], {
|
|
101
|
-
encoding: "utf-8",
|
|
102
|
-
maxBuffer: 50 * 1024 * 1024
|
|
103
|
-
// 50MB buffer for large diffs
|
|
104
|
-
});
|
|
105
|
-
return result;
|
|
106
|
-
} catch (error) {
|
|
107
|
-
if (error instanceof Error) {
|
|
108
|
-
console.error(`Error running git diff: ${error.message}`);
|
|
109
|
-
} else {
|
|
110
|
-
console.error("Error running git diff: unknown error");
|
|
111
|
-
}
|
|
112
|
-
process.exit(1);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
function getRepoRoot() {
|
|
116
|
-
try {
|
|
117
|
-
const result = execSync("git rev-parse --show-toplevel", {
|
|
118
|
-
encoding: "utf-8"
|
|
119
|
-
});
|
|
120
|
-
return stripTrailingNewline(result);
|
|
121
|
-
} catch (error) {
|
|
122
|
-
if (error instanceof Error) {
|
|
123
|
-
console.error(`Error getting repository root: ${error.message}`);
|
|
124
|
-
} else {
|
|
125
|
-
console.error("Error getting repository root: unknown error");
|
|
126
|
-
}
|
|
127
|
-
process.exit(1);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
function validateGitAvailable() {
|
|
131
|
-
try {
|
|
132
|
-
execSync("git --version", { stdio: "ignore" });
|
|
133
|
-
} catch {
|
|
134
|
-
console.error("Error: git is not installed or not in PATH");
|
|
135
|
-
process.exit(1);
|
|
136
|
-
}
|
|
137
|
-
try {
|
|
138
|
-
execSync("git rev-parse --git-dir", { stdio: "ignore" });
|
|
139
|
-
} catch {
|
|
140
|
-
console.error("Error: not a git repository (or any parent up to mount point)");
|
|
141
|
-
process.exit(1);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
async function getRepoRootAsync(cwd) {
|
|
145
|
-
try {
|
|
146
|
-
const { stdout } = await execFileAsync("git", ["rev-parse", "--show-toplevel"], {
|
|
147
|
-
timeout: 1e4,
|
|
148
|
-
// 10 second timeout
|
|
149
|
-
cwd
|
|
150
|
-
});
|
|
151
|
-
return stripTrailingNewline(stdout);
|
|
152
|
-
} catch (error) {
|
|
153
|
-
if (error instanceof Error) {
|
|
154
|
-
console.error(`Error getting repository root: ${error.message}`);
|
|
155
|
-
} else {
|
|
156
|
-
console.error("Error getting repository root: unknown error");
|
|
157
|
-
}
|
|
158
|
-
throw error;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
async function runGitDiffAsync(args, cwd) {
|
|
162
|
-
try {
|
|
163
|
-
const { stdout } = await execFileAsync("git", ["diff", ...args], {
|
|
164
|
-
maxBuffer: 50 * 1024 * 1024,
|
|
165
|
-
// 50MB buffer
|
|
166
|
-
timeout: 3e4,
|
|
167
|
-
// 30 second timeout
|
|
168
|
-
cwd
|
|
169
|
-
});
|
|
170
|
-
return stdout;
|
|
171
|
-
} catch (error) {
|
|
172
|
-
if (error instanceof Error) {
|
|
173
|
-
console.error(`Error running git diff: ${error.message}`);
|
|
174
|
-
} else {
|
|
175
|
-
console.error("Error running git diff: unknown error");
|
|
176
|
-
}
|
|
177
|
-
throw error;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
async function readGitBlobAsync(repoPath, spec) {
|
|
181
|
-
return await new Promise((resolve, reject) => {
|
|
182
|
-
execFile(
|
|
183
|
-
"git",
|
|
184
|
-
["-C", repoPath, "show", spec],
|
|
185
|
-
{ encoding: "buffer", maxBuffer: 50 * 1024 * 1024, timeout: 3e4 },
|
|
186
|
-
(error, stdout) => {
|
|
187
|
-
if (error) {
|
|
188
|
-
reject(error);
|
|
189
|
-
} else {
|
|
190
|
-
resolve(stdout);
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
);
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
async function getUntrackedFilesAsync(repoRoot) {
|
|
197
|
-
try {
|
|
198
|
-
const { stdout } = await execFileAsync(
|
|
199
|
-
"git",
|
|
200
|
-
["ls-files", "--others", "--exclude-standard", "-z"],
|
|
201
|
-
{
|
|
202
|
-
maxBuffer: 10 * 1024 * 1024,
|
|
203
|
-
timeout: 1e4,
|
|
204
|
-
cwd: repoRoot
|
|
205
|
-
}
|
|
206
|
-
);
|
|
207
|
-
return stdout.split("\0").filter((name) => name.length > 0);
|
|
208
|
-
} catch (error) {
|
|
209
|
-
if (error instanceof Error) {
|
|
210
|
-
console.error(`Warning: Failed to list untracked files: ${error.message}`);
|
|
211
|
-
} else {
|
|
212
|
-
console.error("Warning: Failed to list untracked files: unknown error");
|
|
213
|
-
}
|
|
214
|
-
return [];
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
function generateUntrackedDiffs(paths, repoRoot) {
|
|
218
|
-
return generateSyntheticDiffs(paths, repoRoot);
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
export {
|
|
222
|
-
generateSyntheticDiffs,
|
|
223
|
-
stripTrailingNewline,
|
|
224
|
-
runGitDiff,
|
|
225
|
-
getRepoRoot,
|
|
226
|
-
validateGitAvailable,
|
|
227
|
-
getRepoRootAsync,
|
|
228
|
-
runGitDiffAsync,
|
|
229
|
-
readGitBlobAsync,
|
|
230
|
-
getUntrackedFilesAsync,
|
|
231
|
-
generateUntrackedDiffs
|
|
232
|
-
};
|
|
233
|
-
//# sourceMappingURL=chunk-A7A5ZFT3.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/git.ts","../src/synthetic-diff.ts"],"sourcesContent":["// src/main/git.ts\n// Git command execution\n\nimport { execSync, execFile, execFileSync } from 'child_process';\nimport { promisify } from 'util';\nimport { generateSyntheticDiffs } from './synthetic-diff';\n\nconst execFileAsync = promisify(execFile);\n\n/**\n * Strip only the single trailing newline git appends to command output.\n * A plain `.trim()` also eats leading/trailing whitespace that is part of\n * the actual path (e.g. a repository root with a trailing space), reporting\n * a path that does not exist on disk.\n */\nexport function stripTrailingNewline(text: string): string {\n return text.replace(/\\r?\\n$/, '');\n}\n\nexport function runGitDiff(args: string[]): string {\n try {\n // Check if git is available\n try {\n execSync('git --version', { stdio: 'ignore' });\n } catch {\n console.error('Error: git is not installed or not in PATH');\n process.exit(1);\n }\n\n // Check if we're in a git repository\n try {\n execSync('git rev-parse --git-dir', { stdio: 'ignore' });\n } catch {\n console.error('Error: not a git repository (or any parent up to mount point)');\n process.exit(1);\n }\n\n // Run git diff with the provided arguments\n const result = execFileSync('git', ['diff', ...args], {\n encoding: 'utf-8',\n maxBuffer: 50 * 1024 * 1024, // 50MB buffer for large diffs\n });\n\n return result;\n } catch (error) {\n if (error instanceof Error) {\n console.error(`Error running git diff: ${error.message}`);\n } else {\n console.error('Error running git diff: unknown error');\n }\n process.exit(1);\n }\n}\n\nexport function getRepoRoot(): string {\n try {\n const result = execSync('git rev-parse --show-toplevel', {\n encoding: 'utf-8',\n });\n return stripTrailingNewline(result);\n } catch (error) {\n if (error instanceof Error) {\n console.error(`Error getting repository root: ${error.message}`);\n } else {\n console.error('Error getting repository root: unknown error');\n }\n process.exit(1);\n }\n}\n\n/**\n * Lightweight sync validation - checks if git is available and we're in a repo.\n * Called BEFORE Electron initialization for early exit path.\n */\nexport function validateGitAvailable(): void {\n try {\n execSync('git --version', { stdio: 'ignore' });\n } catch {\n console.error('Error: git is not installed or not in PATH');\n process.exit(1);\n }\n\n try {\n execSync('git rev-parse --git-dir', { stdio: 'ignore' });\n } catch {\n console.error('Error: not a git repository (or any parent up to mount point)');\n process.exit(1);\n }\n}\n\n/**\n * Async version of getRepoRoot - called AFTER app.whenReady().\n */\nexport async function getRepoRootAsync(cwd?: string): Promise<string> {\n try {\n const { stdout } = await execFileAsync('git', ['rev-parse', '--show-toplevel'], {\n timeout: 10000, // 10 second timeout\n cwd,\n });\n return stripTrailingNewline(stdout);\n } catch (error) {\n if (error instanceof Error) {\n console.error(`Error getting repository root: ${error.message}`);\n } else {\n console.error('Error getting repository root: unknown error');\n }\n throw error;\n }\n}\n\n/**\n * Async version of runGitDiff - called AFTER app.whenReady().\n * Uses timeout to prevent hanging in CI environments.\n */\nexport async function runGitDiffAsync(args: string[], cwd?: string): Promise<string> {\n try {\n const { stdout } = await execFileAsync('git', ['diff', ...args], {\n maxBuffer: 50 * 1024 * 1024, // 50MB buffer\n timeout: 30000, // 30 second timeout\n cwd,\n });\n return stdout;\n } catch (error) {\n if (error instanceof Error) {\n console.error(`Error running git diff: ${error.message}`);\n } else {\n console.error('Error running git diff: unknown error');\n }\n throw error;\n }\n}\n\n/**\n * Read a blob from a git object spec (`<sha>:<path>`) as raw bytes.\n * Remote mode reads reviewed content at the fetched head SHA — a temporary\n * clone's working tree stays on the default branch and never reflects the\n * PR/MR head.\n */\nexport async function readGitBlobAsync(repoPath: string, spec: string): Promise<Buffer> {\n return await new Promise<Buffer>((resolve, reject) => {\n execFile(\n 'git',\n ['-C', repoPath, 'show', spec],\n { encoding: 'buffer', maxBuffer: 50 * 1024 * 1024, timeout: 30000 },\n (error, stdout) => {\n if (error) {\n reject(error);\n } else {\n resolve(stdout);\n }\n }\n );\n });\n}\n\n/**\n * Get list of untracked files (respects .gitignore).\n *\n * Pass the repository root. `git ls-files` reports paths relative to the\n * directory it runs in and lists that subtree only, while `git diff` reports\n * root-relative paths for the whole repository from anywhere inside it. Run\n * anywhere else and the names match neither the diff nor the root the files\n * are read from.\n *\n * `-z` keeps the names literal. NUL termination survives newlines in\n * filenames, and it turns off the C-style quoting git otherwise applies to\n * control characters and non-ASCII bytes.\n */\nexport async function getUntrackedFilesAsync(repoRoot?: string): Promise<string[]> {\n try {\n const { stdout } = await execFileAsync(\n 'git',\n ['ls-files', '--others', '--exclude-standard', '-z'],\n {\n maxBuffer: 10 * 1024 * 1024,\n timeout: 10000,\n cwd: repoRoot,\n }\n );\n return stdout.split('\\0').filter(name => name.length > 0);\n } catch (error) {\n if (error instanceof Error) {\n console.error(`Warning: Failed to list untracked files: ${error.message}`);\n } else {\n console.error('Warning: Failed to list untracked files: unknown error');\n }\n return [];\n }\n}\n\n/**\n * Generate synthetic unified diffs for untracked files so they can be\n * parsed by the existing diff parser.\n *\n * Delegates to the reusable generateSyntheticDiffs module.\n */\nexport function generateUntrackedDiffs(paths: string[], repoRoot: string): string {\n return generateSyntheticDiffs(paths, repoRoot);\n}\n","// packages/core/src/synthetic-diff.ts\n// Generates synthetic unified diffs for files that aren't tracked by git.\n// Reusable by both git untracked file handling and directory-based scanning.\n\nimport { readFileSync } from 'fs';\nimport { join } from 'path';\n\n// C-style escapes git emits for the characters that have one.\nconst C_STYLE_ESCAPES: Record<number, string> = {\n 0x07: '\\\\a',\n 0x08: '\\\\b',\n 0x09: '\\\\t',\n 0x0a: '\\\\n',\n 0x0b: '\\\\v',\n 0x0c: '\\\\f',\n 0x0d: '\\\\r',\n 0x22: '\\\\\"',\n 0x5c: '\\\\\\\\',\n};\n\nfunction needsQuoting(byte: number): boolean {\n return byte < 0x20 || byte >= 0x7f || byte === 0x22 || byte === 0x5c;\n}\n\n/**\n * Encode a path the way git writes it in diff headers. A plain path goes out\n * verbatim. Anything else becomes a double-quoted C-style token with control\n * characters, quotes, backslashes and non-ASCII UTF-8 bytes escaped.\n *\n * This inverts `decodeGitPath` in diff-parser.ts. Without it, a filename\n * containing a newline ends the header line mid-name and the parser recovers\n * a name no file on disk answers to.\n */\nexport function quoteGitPath(path: string): string {\n const bytes = Buffer.from(path, 'utf-8');\n if (!bytes.some(needsQuoting)) return path;\n\n let quoted = '\"';\n for (const byte of bytes) {\n const escape = C_STYLE_ESCAPES[byte];\n if (escape) {\n quoted += escape;\n } else if (byte < 0x20 || byte >= 0x7f) {\n quoted += `\\\\${byte.toString(8).padStart(3, '0')}`;\n } else {\n quoted += String.fromCharCode(byte);\n }\n }\n return `${quoted}\"`;\n}\n\n/**\n * Generate synthetic unified diffs for a list of file paths so they can be\n * parsed by the existing diff parser. Each file is treated as a new addition.\n *\n * @param paths - Literal relative file paths (e.g. \"src/foo.ts\"), resolved\n * against rootDir and never git-quoted on the way in\n * @param rootDir - Absolute path to the root directory the paths are relative to\n * @returns A unified diff string covering all provided files\n */\nexport function generateSyntheticDiffs(paths: string[], rootDir: string): string {\n const diffs: string[] = [];\n\n for (const filePath of paths) {\n const fullPath = join(rootDir, filePath);\n let content: Buffer;\n try {\n content = readFileSync(fullPath);\n } catch {\n // File may have been deleted between listing and reading\n continue;\n }\n\n // Git quotes the prefixed path as a whole (\"a/name\"), not the name alone.\n const oldHeaderPath = quoteGitPath(`a/${filePath}`);\n const newHeaderPath = quoteGitPath(`b/${filePath}`);\n\n // Detect binary files by checking for null bytes in the first 8KB\n const sample = content.subarray(0, 8192);\n const isBinary = sample.includes(0);\n\n if (isBinary) {\n diffs.push(\n `diff --git ${oldHeaderPath} ${newHeaderPath}\\n` +\n `new file mode 100644\\n` +\n `Binary files /dev/null and ${newHeaderPath} differ`\n );\n continue;\n }\n\n const text = content.toString('utf-8');\n const lines = text.split('\\n');\n\n // Remove trailing empty string from split if file ends with newline\n if (lines.length > 0 && lines[lines.length - 1] === '') {\n lines.pop();\n }\n\n const lineCount = lines.length;\n const addedLines = lines.map(line => `+${line}`).join('\\n');\n\n let diff =\n `diff --git ${oldHeaderPath} ${newHeaderPath}\\n` +\n `new file mode 100644\\n` +\n `--- /dev/null\\n` +\n `+++ ${newHeaderPath}\\n` +\n `@@ -0,0 +1,${lineCount} @@\\n` +\n addedLines;\n\n // Indicate missing newline at end of file\n if (text.length > 0 && !text.endsWith('\\n')) {\n diff += '\\n\\\';\n }\n\n diffs.push(diff);\n }\n\n return diffs.join('\\n');\n}\n"],"mappings":";AAGA,SAAS,UAAU,UAAU,oBAAoB;AACjD,SAAS,iBAAiB;;;ACA1B,SAAS,oBAAoB;AAC7B,SAAS,YAAY;AAGrB,IAAM,kBAA0C;AAAA,EAC9C,GAAM;AAAA,EACN,GAAM;AAAA,EACN,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
-
return [];
|
|
5
|
-
}
|
|
6
|
-
const lines = rawDiff.split("\n");
|
|
7
|
-
const files = [];
|
|
8
|
-
let currentFile = null;
|
|
9
|
-
let currentHunk = null;
|
|
10
|
-
let oldLineNumber = 0;
|
|
11
|
-
let newLineNumber = 0;
|
|
12
|
-
let hasModeChange = false;
|
|
13
|
-
function flushFile() {
|
|
14
|
-
if (currentFile && (currentFile.oldPath || currentFile.newPath) && (currentFile.isBinary || currentFile.hunks.length > 0 || currentFile.changeType !== "modified" || hasModeChange)) {
|
|
15
|
-
files.push(currentFile);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
for (let i = 0; i < lines.length; i++) {
|
|
19
|
-
const line = lines[i];
|
|
20
|
-
if (line.startsWith("diff --git ")) {
|
|
21
|
-
if (currentHunk && currentHunk.header && currentFile) {
|
|
22
|
-
currentFile.hunks.push(currentHunk);
|
|
23
|
-
currentHunk = null;
|
|
24
|
-
}
|
|
25
|
-
flushFile();
|
|
26
|
-
const gitPaths = parseGitDiffHeader(line);
|
|
27
|
-
currentFile = {
|
|
28
|
-
oldPath: gitPaths.oldPath,
|
|
29
|
-
newPath: gitPaths.newPath,
|
|
30
|
-
changeType: "modified",
|
|
31
|
-
isBinary: false,
|
|
32
|
-
hunks: []
|
|
33
|
-
};
|
|
34
|
-
currentHunk = null;
|
|
35
|
-
hasModeChange = false;
|
|
36
|
-
continue;
|
|
37
|
-
}
|
|
38
|
-
if (!currentFile) continue;
|
|
39
|
-
if (line.startsWith("new file mode")) {
|
|
40
|
-
currentFile.changeType = "added";
|
|
41
|
-
currentFile.oldPath = "";
|
|
42
|
-
continue;
|
|
43
|
-
}
|
|
44
|
-
if (line.startsWith("deleted file mode")) {
|
|
45
|
-
currentFile.changeType = "deleted";
|
|
46
|
-
currentFile.newPath = "";
|
|
47
|
-
continue;
|
|
48
|
-
}
|
|
49
|
-
if (line.startsWith("new mode ")) {
|
|
50
|
-
hasModeChange = true;
|
|
51
|
-
continue;
|
|
52
|
-
}
|
|
53
|
-
if (line.startsWith("rename from ")) {
|
|
54
|
-
currentFile.changeType = "renamed";
|
|
55
|
-
currentFile.oldPath = decodeGitPath(line.substring("rename from ".length));
|
|
56
|
-
continue;
|
|
57
|
-
}
|
|
58
|
-
if (line.startsWith("rename to ")) {
|
|
59
|
-
currentFile.newPath = decodeGitPath(line.substring("rename to ".length));
|
|
60
|
-
continue;
|
|
61
|
-
}
|
|
62
|
-
if (!currentHunk && line.startsWith("--- ")) {
|
|
63
|
-
const path = decodeGitPath(line.substring(4).split(" ")[0]);
|
|
64
|
-
currentFile.oldPath = path === "/dev/null" ? "" : stripPrefix(path);
|
|
65
|
-
continue;
|
|
66
|
-
}
|
|
67
|
-
if (!currentHunk && line.startsWith("+++ ")) {
|
|
68
|
-
const path = decodeGitPath(line.substring(4).split(" ")[0]);
|
|
69
|
-
currentFile.newPath = path === "/dev/null" ? "" : stripPrefix(path);
|
|
70
|
-
continue;
|
|
71
|
-
}
|
|
72
|
-
if (line.startsWith("Binary files ")) {
|
|
73
|
-
currentFile.isBinary = true;
|
|
74
|
-
continue;
|
|
75
|
-
}
|
|
76
|
-
if (line.startsWith("@@")) {
|
|
77
|
-
if (currentHunk && currentHunk.header) {
|
|
78
|
-
currentFile.hunks.push(currentHunk);
|
|
79
|
-
}
|
|
80
|
-
const match = line.match(/@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@(.*)$/);
|
|
81
|
-
if (match) {
|
|
82
|
-
const oldStart = parseInt(match[1], 10);
|
|
83
|
-
const oldLines = match[2] ? parseInt(match[2], 10) : 1;
|
|
84
|
-
const newStart = parseInt(match[3], 10);
|
|
85
|
-
const newLines = match[4] ? parseInt(match[4], 10) : 1;
|
|
86
|
-
const _context = match[5];
|
|
87
|
-
currentHunk = {
|
|
88
|
-
header: line,
|
|
89
|
-
oldStart,
|
|
90
|
-
oldLines,
|
|
91
|
-
newStart,
|
|
92
|
-
newLines,
|
|
93
|
-
lines: []
|
|
94
|
-
};
|
|
95
|
-
oldLineNumber = oldStart;
|
|
96
|
-
newLineNumber = newStart;
|
|
97
|
-
}
|
|
98
|
-
continue;
|
|
99
|
-
}
|
|
100
|
-
if (currentHunk && currentHunk.lines) {
|
|
101
|
-
if (line.startsWith("+")) {
|
|
102
|
-
currentHunk.lines.push({
|
|
103
|
-
type: "addition",
|
|
104
|
-
oldLineNumber: null,
|
|
105
|
-
newLineNumber,
|
|
106
|
-
content: line.substring(1)
|
|
107
|
-
});
|
|
108
|
-
newLineNumber++;
|
|
109
|
-
} else if (line.startsWith("-")) {
|
|
110
|
-
currentHunk.lines.push({
|
|
111
|
-
type: "deletion",
|
|
112
|
-
oldLineNumber,
|
|
113
|
-
newLineNumber: null,
|
|
114
|
-
content: line.substring(1)
|
|
115
|
-
});
|
|
116
|
-
oldLineNumber++;
|
|
117
|
-
} else if (line.startsWith(" ")) {
|
|
118
|
-
currentHunk.lines.push({
|
|
119
|
-
type: "context",
|
|
120
|
-
oldLineNumber,
|
|
121
|
-
newLineNumber,
|
|
122
|
-
content: line.substring(1)
|
|
123
|
-
});
|
|
124
|
-
oldLineNumber++;
|
|
125
|
-
newLineNumber++;
|
|
126
|
-
} else if (line.startsWith("\\")) {
|
|
127
|
-
continue;
|
|
128
|
-
} else {
|
|
129
|
-
if (currentHunk.lines.length > 0) {
|
|
130
|
-
currentHunk.lines.push({
|
|
131
|
-
type: "context",
|
|
132
|
-
oldLineNumber,
|
|
133
|
-
newLineNumber,
|
|
134
|
-
content: line
|
|
135
|
-
});
|
|
136
|
-
oldLineNumber++;
|
|
137
|
-
newLineNumber++;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
if (currentHunk && currentHunk.header && currentFile) {
|
|
143
|
-
currentFile.hunks.push(currentHunk);
|
|
144
|
-
}
|
|
145
|
-
flushFile();
|
|
146
|
-
return files;
|
|
147
|
-
}
|
|
148
|
-
function stripPrefix(path) {
|
|
149
|
-
if (path.length > 2 && path[1] === "/") {
|
|
150
|
-
return path.substring(2);
|
|
151
|
-
}
|
|
152
|
-
return path;
|
|
153
|
-
}
|
|
154
|
-
function decodeGitPath(path) {
|
|
155
|
-
if (!path.startsWith('"') || !path.endsWith('"')) return path;
|
|
156
|
-
const escapes = {
|
|
157
|
-
a: "\x07",
|
|
158
|
-
b: "\b",
|
|
159
|
-
f: "\f",
|
|
160
|
-
n: "\n",
|
|
161
|
-
r: "\r",
|
|
162
|
-
t: " ",
|
|
163
|
-
v: "\v",
|
|
164
|
-
'"': '"',
|
|
165
|
-
"\\": "\\"
|
|
166
|
-
};
|
|
167
|
-
return path.slice(1, -1).replace(/(?:\\[0-7]{1,3})+|\\[abfnrtv"\\]/g, (escape) => {
|
|
168
|
-
if (/^\\[0-7]/.test(escape)) {
|
|
169
|
-
const bytes = escape.slice(1).split("\\").map((byte) => parseInt(byte, 8));
|
|
170
|
-
return Buffer.from(bytes).toString("utf8");
|
|
171
|
-
}
|
|
172
|
-
return escapes[escape[1]];
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
function parseGitDiffHeader(line) {
|
|
176
|
-
const paths = line.substring("diff --git ".length);
|
|
177
|
-
const quotedOld = paths.match(/^("(?:\\.|[^"\\])*") (.+)$/);
|
|
178
|
-
const quotedNew = paths.match(/^(.+) ("(?:\\.|[^"\\])*")$/);
|
|
179
|
-
const quoted = quotedOld || quotedNew;
|
|
180
|
-
if (quoted) {
|
|
181
|
-
return {
|
|
182
|
-
oldPath: stripPrefix(decodeGitPath(quoted[1])),
|
|
183
|
-
newPath: stripPrefix(decodeGitPath(quoted[2]))
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
const separators = [...paths.matchAll(/ [bwico]\//g)];
|
|
187
|
-
const boundary = separators.find(
|
|
188
|
-
(match) => stripPrefix(paths.substring(0, match.index)) === stripPrefix(paths.substring(match.index + 1))
|
|
189
|
-
) || separators[0];
|
|
190
|
-
if (!boundary) return { oldPath: "", newPath: "" };
|
|
191
|
-
return {
|
|
192
|
-
oldPath: stripPrefix(paths.substring(0, boundary.index)),
|
|
193
|
-
newPath: stripPrefix(paths.substring(boundary.index + 1))
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
export {
|
|
198
|
-
parseDiff
|
|
199
|
-
};
|
|
200
|
-
//# sourceMappingURL=chunk-OQRS7NDT.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/diff-parser.ts"],"sourcesContent":["// src/main/diff-parser.ts\n// Parse unified diff output into DiffFile[]\n\nimport { DiffFile, DiffHunk, ChangeType } from './types';\n\nexport function parseDiff(rawDiff: string): DiffFile[] {\n if (!rawDiff.trim()) {\n return [];\n }\n\n const lines = rawDiff.split('\\n');\n const files: DiffFile[] = [];\n let currentFile: Partial<DiffFile> | null = null;\n let currentHunk: Partial<DiffHunk> | null = null;\n let oldLineNumber = 0;\n let newLineNumber = 0;\n let hasModeChange = false;\n\n function flushFile(): void {\n if (\n currentFile &&\n (currentFile.oldPath || currentFile.newPath) &&\n (currentFile.isBinary ||\n currentFile.hunks!.length > 0 ||\n currentFile.changeType !== 'modified' ||\n hasModeChange)\n ) {\n files.push(currentFile as DiffFile);\n }\n }\n\n for (let i = 0; i < lines.length; i++) {\n const line = lines[i];\n\n // Start of a new file\n if (line.startsWith('diff --git ')) {\n // Flush the pending hunk into the current file before saving\n if (currentHunk && currentHunk.header && currentFile) {\n currentFile.hunks!.push(currentHunk as DiffHunk);\n currentHunk = null;\n }\n\n flushFile();\n\n // Extract paths from \"diff --git a/<old> b/<new>\" as fallback\n // for binary files that lack --- / +++ lines\n const gitPaths = parseGitDiffHeader(line);\n\n // Initialize new file\n currentFile = {\n oldPath: gitPaths.oldPath,\n newPath: gitPaths.newPath,\n changeType: 'modified' as ChangeType,\n isBinary: false,\n hunks: [],\n };\n currentHunk = null;\n hasModeChange = false;\n continue;\n }\n\n if (!currentFile) continue;\n\n // Detect file mode changes\n if (line.startsWith('new file mode')) {\n currentFile.changeType = 'added';\n currentFile.oldPath = '';\n continue;\n }\n\n if (line.startsWith('deleted file mode')) {\n currentFile.changeType = 'deleted';\n currentFile.newPath = '';\n continue;\n }\n\n if (line.startsWith('new mode ')) {\n hasModeChange = true;\n continue;\n }\n\n if (line.startsWith('rename from ')) {\n currentFile.changeType = 'renamed';\n currentFile.oldPath = decodeGitPath(line.substring('rename from '.length));\n continue;\n }\n\n if (line.startsWith('rename to ')) {\n currentFile.newPath = decodeGitPath(line.substring('rename to '.length));\n continue;\n }\n\n // Parse old file path\n if (!currentHunk && line.startsWith('--- ')) {\n const path = decodeGitPath(line.substring(4).split('\\t')[0]);\n currentFile.oldPath = path === '/dev/null' ? '' : stripPrefix(path);\n continue;\n }\n\n // Parse new file path\n if (!currentHunk && line.startsWith('+++ ')) {\n const path = decodeGitPath(line.substring(4).split('\\t')[0]);\n currentFile.newPath = path === '/dev/null' ? '' : stripPrefix(path);\n continue;\n }\n\n // Detect binary files\n if (line.startsWith('Binary files ')) {\n currentFile.isBinary = true;\n continue;\n }\n\n // Parse hunk header\n if (line.startsWith('@@')) {\n // Save previous hunk if exists\n if (currentHunk && currentHunk.header) {\n currentFile.hunks!.push(currentHunk as DiffHunk);\n }\n\n // Parse hunk header: @@ -oldStart,oldLines +newStart,newLines @@ context\n const match = line.match(/@@ -(\\d+)(?:,(\\d+))? \\+(\\d+)(?:,(\\d+))? @@(.*)$/);\n if (match) {\n const oldStart = parseInt(match[1], 10);\n const oldLines = match[2] ? parseInt(match[2], 10) : 1;\n const newStart = parseInt(match[3], 10);\n const newLines = match[4] ? parseInt(match[4], 10) : 1;\n const _context = match[5];\n\n currentHunk = {\n header: line,\n oldStart,\n oldLines,\n newStart,\n newLines,\n lines: [],\n };\n\n oldLineNumber = oldStart;\n newLineNumber = newStart;\n }\n continue;\n }\n\n // Parse diff lines (must have a current hunk)\n if (currentHunk && currentHunk.lines) {\n if (line.startsWith('+')) {\n // Addition\n currentHunk.lines.push({\n type: 'addition',\n oldLineNumber: null,\n newLineNumber: newLineNumber,\n content: line.substring(1),\n });\n newLineNumber++;\n } else if (line.startsWith('-')) {\n // Deletion\n currentHunk.lines.push({\n type: 'deletion',\n oldLineNumber: oldLineNumber,\n newLineNumber: null,\n content: line.substring(1),\n });\n oldLineNumber++;\n } else if (line.startsWith(' ')) {\n // Context line\n currentHunk.lines.push({\n type: 'context',\n oldLineNumber: oldLineNumber,\n newLineNumber: newLineNumber,\n content: line.substring(1),\n });\n oldLineNumber++;\n newLineNumber++;\n } else if (line.startsWith('\\\\')) {\n // \"\\" - ignore\n continue;\n } else {\n // Some other line (could be empty or malformed), treat as context\n if (currentHunk.lines.length > 0) {\n currentHunk.lines.push({\n type: 'context',\n oldLineNumber: oldLineNumber,\n newLineNumber: newLineNumber,\n content: line,\n });\n oldLineNumber++;\n newLineNumber++;\n }\n }\n }\n }\n\n // Save the last hunk and file\n if (currentHunk && currentHunk.header && currentFile) {\n currentFile.hunks!.push(currentHunk as DiffHunk);\n }\n flushFile();\n\n return files;\n}\n\nfunction stripPrefix(path: string): string {\n // Remove single-character prefix (a/, b/, c/, i/, w/, etc.)\n // Git uses a/b by default, but mnemonicPrefix uses c/i/w/o\n if (path.length > 2 && path[1] === '/') {\n return path.substring(2);\n }\n return path;\n}\n\nfunction decodeGitPath(path: string): string {\n if (!path.startsWith('\"') || !path.endsWith('\"')) return path;\n\n const escapes: Record<string, string> = {\n a: '\\x07',\n b: '\\b',\n f: '\\f',\n n: '\\n',\n r: '\\r',\n t: '\\t',\n v: '\\v',\n '\"': '\"',\n '\\\\': '\\\\',\n };\n return path.slice(1, -1).replace(/(?:\\\\[0-7]{1,3})+|\\\\[abfnrtv\"\\\\]/g, escape => {\n if (/^\\\\[0-7]/.test(escape)) {\n // Git quotes UTF-8 bytes as octal, so decode each run together.\n const bytes = escape\n .slice(1)\n .split('\\\\')\n .map(byte => parseInt(byte, 8));\n return Buffer.from(bytes).toString('utf8');\n }\n return escapes[escape[1]];\n });\n}\n\nfunction parseGitDiffHeader(line: string): {\n oldPath: string;\n newPath: string;\n} {\n const paths = line.substring('diff --git '.length);\n // Quoted paths are single C-style tokens, even when they contain spaces.\n const quotedOld = paths.match(/^(\"(?:\\\\.|[^\"\\\\])*\") (.+)$/);\n const quotedNew = paths.match(/^(.+) (\"(?:\\\\.|[^\"\\\\])*\")$/);\n const quoted = quotedOld || quotedNew;\n if (quoted) {\n return {\n oldPath: stripPrefix(decodeGitPath(quoted[1])),\n newPath: stripPrefix(decodeGitPath(quoted[2])),\n };\n }\n\n // Unquoted names can contain spaces. Prefer a boundary whose two paths\n // agree; rename headers supply the exact paths when they differ.\n const separators = [...paths.matchAll(/ [bwico]\\//g)];\n const boundary =\n separators.find(\n match =>\n stripPrefix(paths.substring(0, match.index)) ===\n stripPrefix(paths.substring(match.index! + 1))\n ) || separators[0];\n if (!boundary) return { oldPath: '', newPath: '' };\n\n return {\n oldPath: stripPrefix(paths.substring(0, boundary.index)),\n newPath: stripPrefix(paths.substring(boundary.index! + 1)),\n };\n}\n"],"mappings":";AAKO,SAAS,UAAU,SAA6B;AACrD,MAAI,CAAC,QAAQ,KAAK,GAAG;AACnB,WAAO,CAAC;AAAA,EACV;AAEA,QAAM,QAAQ,QAAQ,MAAM,IAAI;AAChC,QAAM,QAAoB,CAAC;AAC3B,MAAI,cAAwC;AAC5C,MAAI,cAAwC;AAC5C,MAAI,gBAAgB;AACpB,MAAI,gBAAgB;AACpB,MAAI,gBAAgB;AAEpB,WAAS,YAAkB;AACzB,QACE,gBACC,YAAY,WAAW,YAAY,aACnC,YAAY,YACX,YAAY,MAAO,SAAS,KAC5B,YAAY,eAAe,cAC3B,gBACF;AACA,YAAM,KAAK,WAAuB;AAAA,IACpC;AAAA,EACF;AAEA,WAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;AACrC,UAAM,OAAO,MAAM,CAAC;AAGpB,QAAI,KAAK,WAAW,aAAa,GAAG;AAElC,UAAI,eAAe,YAAY,UAAU,aAAa;AACpD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;AACV,WAAO;AAAA,MACL,SAAS,YAAY,cAAc,OAAO,CAAC,CAAC,CAAC;AAAA,MAC7C,SAAS,YAAY,cAAc,OAAO,CAAC,CAAC,CAAC;AAAA,IAC/C;AAAA,EACF;AAIA,QAAM,aAAa,CAAC,GAAG,MAAM,SAAS,aAAa,CAAC;AACpD,QAAM,WACJ,WAAW;AAAA,IACT,WACE,YAAY,MAAM,UAAU,GAAG,MAAM,KAAK,CAAC,MAC3C,YAAY,MAAM,UAAU,MAAM,QAAS,CAAC,CAAC;AAAA,EACjD,KAAK,WAAW,CAAC;AACnB,MAAI,CAAC,SAAU,QAAO,EAAE,SAAS,IAAI,SAAS,GAAG;AAEjD,SAAO;AAAA,IACL,SAAS,YAAY,MAAM,UAAU,GAAG,SAAS,KAAK,CAAC;AAAA,IACvD,SAAS,YAAY,MAAM,UAAU,SAAS,QAAS,CAAC,CAAC;AAAA,EAC3D;AACF;","names":[]}
|
package/dist/git-E7WZPKRC.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
generateUntrackedDiffs,
|
|
3
|
-
getRepoRoot,
|
|
4
|
-
getRepoRootAsync,
|
|
5
|
-
getUntrackedFilesAsync,
|
|
6
|
-
readGitBlobAsync,
|
|
7
|
-
runGitDiff,
|
|
8
|
-
runGitDiffAsync,
|
|
9
|
-
stripTrailingNewline,
|
|
10
|
-
validateGitAvailable
|
|
11
|
-
} from "./chunk-A7A5ZFT3.js";
|
|
12
|
-
export {
|
|
13
|
-
generateUntrackedDiffs,
|
|
14
|
-
getRepoRoot,
|
|
15
|
-
getRepoRootAsync,
|
|
16
|
-
getUntrackedFilesAsync,
|
|
17
|
-
readGitBlobAsync,
|
|
18
|
-
runGitDiff,
|
|
19
|
-
runGitDiffAsync,
|
|
20
|
-
stripTrailingNewline,
|
|
21
|
-
validateGitAvailable
|
|
22
|
-
};
|
|
23
|
-
//# sourceMappingURL=git-E7WZPKRC.js.map
|
|
File without changes
|
|
File without changes
|