@tachu/extensions 1.0.0-alpha.2 → 1.0.0-alpha.4
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/CHANGELOG.md +69 -0
- package/README.md +21 -3
- package/README_ZH.md +20 -3
- package/dist/providers/anthropic.d.ts.map +1 -1
- package/dist/providers/anthropic.js +9 -3
- package/dist/providers/anthropic.js.map +1 -1
- package/dist/providers/openai.d.ts.map +1 -1
- package/dist/providers/openai.js +13 -4
- package/dist/providers/openai.js.map +1 -1
- package/dist/tools/apply-patch/executor.d.ts.map +1 -1
- package/dist/tools/apply-patch/executor.js +47 -0
- package/dist/tools/apply-patch/executor.js.map +1 -1
- package/dist/tools/edit-file/executor.d.ts +32 -0
- package/dist/tools/edit-file/executor.d.ts.map +1 -0
- package/dist/tools/edit-file/executor.js +84 -0
- package/dist/tools/edit-file/executor.js.map +1 -0
- package/dist/tools/git-blame/executor.d.ts +24 -0
- package/dist/tools/git-blame/executor.d.ts.map +1 -0
- package/dist/tools/git-blame/executor.js +76 -0
- package/dist/tools/git-blame/executor.js.map +1 -0
- package/dist/tools/git-branch/executor.d.ts +22 -0
- package/dist/tools/git-branch/executor.d.ts.map +1 -0
- package/dist/tools/git-branch/executor.js +81 -0
- package/dist/tools/git-branch/executor.js.map +1 -0
- package/dist/tools/git-diff/executor.d.ts +37 -0
- package/dist/tools/git-diff/executor.d.ts.map +1 -0
- package/dist/tools/git-diff/executor.js +156 -0
- package/dist/tools/git-diff/executor.js.map +1 -0
- package/dist/tools/git-log/executor.d.ts +31 -0
- package/dist/tools/git-log/executor.d.ts.map +1 -0
- package/dist/tools/git-log/executor.js +65 -0
- package/dist/tools/git-log/executor.js.map +1 -0
- package/dist/tools/git-show/executor.d.ts +22 -0
- package/dist/tools/git-show/executor.d.ts.map +1 -0
- package/dist/tools/git-show/executor.js +74 -0
- package/dist/tools/git-show/executor.js.map +1 -0
- package/dist/tools/git-status/executor.d.ts +25 -0
- package/dist/tools/git-status/executor.d.ts.map +1 -0
- package/dist/tools/git-status/executor.js +120 -0
- package/dist/tools/git-status/executor.js.map +1 -0
- package/dist/tools/glob/executor.d.ts +18 -0
- package/dist/tools/glob/executor.d.ts.map +1 -0
- package/dist/tools/glob/executor.js +47 -0
- package/dist/tools/glob/executor.js.map +1 -0
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +360 -3
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/multi-edit/executor.d.ts +29 -0
- package/dist/tools/multi-edit/executor.d.ts.map +1 -0
- package/dist/tools/multi-edit/executor.js +37 -0
- package/dist/tools/multi-edit/executor.js.map +1 -0
- package/dist/tools/read-file/executor.d.ts +5 -0
- package/dist/tools/read-file/executor.d.ts.map +1 -1
- package/dist/tools/read-file/executor.js +46 -2
- package/dist/tools/read-file/executor.js.map +1 -1
- package/dist/tools/run-shell/executor.d.ts +12 -1
- package/dist/tools/run-shell/executor.d.ts.map +1 -1
- package/dist/tools/run-shell/executor.js +103 -7
- package/dist/tools/run-shell/executor.js.map +1 -1
- package/dist/tools/run-tests/executor.d.ts +28 -0
- package/dist/tools/run-tests/executor.d.ts.map +1 -0
- package/dist/tools/run-tests/executor.js +161 -0
- package/dist/tools/run-tests/executor.js.map +1 -0
- package/dist/tools/run-typecheck/executor.d.ts +25 -0
- package/dist/tools/run-typecheck/executor.d.ts.map +1 -0
- package/dist/tools/run-typecheck/executor.js +83 -0
- package/dist/tools/run-typecheck/executor.js.map +1 -0
- package/dist/tools/todo-read/executor.d.ts +20 -0
- package/dist/tools/todo-read/executor.d.ts.map +1 -0
- package/dist/tools/todo-read/executor.js +26 -0
- package/dist/tools/todo-read/executor.js.map +1 -0
- package/dist/tools/todo-write/executor.d.ts +21 -0
- package/dist/tools/todo-write/executor.d.ts.map +1 -0
- package/dist/tools/todo-write/executor.js +38 -0
- package/dist/tools/todo-write/executor.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { readFile, writeFile } from "node:fs/promises";
|
|
2
|
+
import { ValidationError } from "@tachu/core";
|
|
3
|
+
import { resolveAllowedPath } from "../../common/path";
|
|
4
|
+
import { assertNotAborted, resolveSandboxPolicy } from "../shared";
|
|
5
|
+
export const countMatches = (content, search) => {
|
|
6
|
+
if (search.length === 0)
|
|
7
|
+
return 0;
|
|
8
|
+
let count = 0;
|
|
9
|
+
let pos = 0;
|
|
10
|
+
while ((pos = content.indexOf(search, pos)) !== -1) {
|
|
11
|
+
count++;
|
|
12
|
+
pos += search.length;
|
|
13
|
+
}
|
|
14
|
+
return count;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Fuzzy: match oldString lines (trimmed) against file lines (trimmed).
|
|
18
|
+
* Returns the actual content from the file (with original indentation) if found.
|
|
19
|
+
*/
|
|
20
|
+
export const fuzzyFindActual = (content, oldString) => {
|
|
21
|
+
const oldLines = oldString.split("\n");
|
|
22
|
+
const contentLines = content.split("\n");
|
|
23
|
+
if (oldLines.length === 0)
|
|
24
|
+
return null;
|
|
25
|
+
const oldTrimmed = oldLines.map((l) => l.trim());
|
|
26
|
+
for (let i = 0; i <= contentLines.length - oldLines.length; i++) {
|
|
27
|
+
let match = true;
|
|
28
|
+
for (let j = 0; j < oldLines.length; j++) {
|
|
29
|
+
if ((contentLines[i + j] ?? "").trim() !== (oldTrimmed[j] ?? "")) {
|
|
30
|
+
match = false;
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
if (match) {
|
|
35
|
+
return contentLines.slice(i, i + oldLines.length).join("\n");
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return null;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Core replacement logic (pure, no I/O).
|
|
42
|
+
* Returns the new content and replacement stats, or throws ValidationError.
|
|
43
|
+
*/
|
|
44
|
+
export const applyEdit = (content, oldString, newString, replaceAll, fuzzy) => {
|
|
45
|
+
let effectiveOld = oldString;
|
|
46
|
+
let matchCount = countMatches(content, effectiveOld);
|
|
47
|
+
if (matchCount === 0 && fuzzy) {
|
|
48
|
+
const actual = fuzzyFindActual(content, effectiveOld);
|
|
49
|
+
if (actual !== null) {
|
|
50
|
+
effectiveOld = actual;
|
|
51
|
+
matchCount = countMatches(content, effectiveOld);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (!replaceAll && matchCount !== 1) {
|
|
55
|
+
throw new ValidationError("EDIT_FILE_NOT_UNIQUE", `oldString 在文件中出现 ${matchCount} 次,期望恰好 1 次(matchCount=${matchCount})`, { context: { matchCount } });
|
|
56
|
+
}
|
|
57
|
+
let newContent;
|
|
58
|
+
let replaced;
|
|
59
|
+
if (replaceAll) {
|
|
60
|
+
newContent = content.split(effectiveOld).join(newString);
|
|
61
|
+
replaced = matchCount;
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
const idx = content.indexOf(effectiveOld);
|
|
65
|
+
newContent =
|
|
66
|
+
content.slice(0, idx) + newString + content.slice(idx + effectiveOld.length);
|
|
67
|
+
replaced = 1;
|
|
68
|
+
}
|
|
69
|
+
return { newContent, replaced, matchCount };
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* 编辑文件 Tool 执行器:精确字符串替换。
|
|
73
|
+
*/
|
|
74
|
+
export const editFileExecutor = async (input, context) => {
|
|
75
|
+
assertNotAborted(context.abortSignal);
|
|
76
|
+
const target = resolveAllowedPath(input.path, resolveSandboxPolicy(context));
|
|
77
|
+
const content = await readFile(target, "utf8");
|
|
78
|
+
const fuzzy = input.fuzzy !== false;
|
|
79
|
+
const replaceAll = input.replaceAll === true;
|
|
80
|
+
const { newContent, replaced, matchCount } = applyEdit(content, input.oldString, input.newString, replaceAll, fuzzy);
|
|
81
|
+
await writeFile(target, newContent, "utf8");
|
|
82
|
+
return { replaced, matchCount };
|
|
83
|
+
};
|
|
84
|
+
//# sourceMappingURL=executor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
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,UAAU,EACV,KAAK,CACN,CAAC;IAEF,MAAM,SAAS,CAAC,MAAM,EAAE,UAAU,EAAE,MAAM,CAAC,CAAC;IAC5C,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,CAAC;AAClC,CAAC,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ToolExecutor } from "../shared";
|
|
2
|
+
interface GitBlameInput {
|
|
3
|
+
path: string;
|
|
4
|
+
cwd?: string;
|
|
5
|
+
startLine?: number;
|
|
6
|
+
endLine?: number;
|
|
7
|
+
}
|
|
8
|
+
interface BlameLine {
|
|
9
|
+
lineNumber: number;
|
|
10
|
+
hash: string;
|
|
11
|
+
shortHash: string;
|
|
12
|
+
author: string;
|
|
13
|
+
date: string;
|
|
14
|
+
content: string;
|
|
15
|
+
}
|
|
16
|
+
interface GitBlameOutput {
|
|
17
|
+
lines: BlameLine[];
|
|
18
|
+
path: string;
|
|
19
|
+
}
|
|
20
|
+
export declare const gitBlameExecutor: ToolExecutor<GitBlameInput, GitBlameOutput | {
|
|
21
|
+
error: string;
|
|
22
|
+
}>;
|
|
23
|
+
export {};
|
|
24
|
+
//# sourceMappingURL=executor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../../src/tools/git-blame/executor.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAI9C,UAAU,aAAa;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,UAAU,SAAS;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,UAAU,cAAc;IACtB,KAAK,EAAE,SAAS,EAAE,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;CACd;AAyDD,eAAO,MAAM,gBAAgB,EAAE,YAAY,CAAC,aAAa,EAAE,cAAc,GAAG;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CAiC1F,CAAC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { resolve } from "node:path";
|
|
2
|
+
import { assertNotAborted, resolveSandboxPolicy } from "../shared";
|
|
3
|
+
import { resolveAllowedPath } from "../../common/path";
|
|
4
|
+
const parsePorcelain = (stdout) => {
|
|
5
|
+
const lines = stdout.split("\n");
|
|
6
|
+
const result = [];
|
|
7
|
+
let i = 0;
|
|
8
|
+
let currentHash = "";
|
|
9
|
+
let currentAuthor = "";
|
|
10
|
+
let currentDate = "";
|
|
11
|
+
let currentLineNumber = 0;
|
|
12
|
+
while (i < lines.length) {
|
|
13
|
+
const line = lines[i];
|
|
14
|
+
// A line starting with 40-char hex hash followed by line info
|
|
15
|
+
const hashMatch = line.match(/^([0-9a-f]{40}) \d+ (\d+)/);
|
|
16
|
+
if (hashMatch) {
|
|
17
|
+
currentHash = hashMatch[1];
|
|
18
|
+
currentLineNumber = parseInt(hashMatch[2], 10);
|
|
19
|
+
i++;
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
if (line.startsWith("author ") && !line.startsWith("author-")) {
|
|
23
|
+
currentAuthor = line.slice("author ".length);
|
|
24
|
+
i++;
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
if (line.startsWith("author-time ")) {
|
|
28
|
+
const ts = parseInt(line.slice("author-time ".length), 10);
|
|
29
|
+
currentDate = new Date(ts * 1000).toISOString();
|
|
30
|
+
i++;
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
if (line.startsWith("\t")) {
|
|
34
|
+
const content = line.slice(1);
|
|
35
|
+
result.push({
|
|
36
|
+
lineNumber: currentLineNumber,
|
|
37
|
+
hash: currentHash,
|
|
38
|
+
shortHash: currentHash.slice(0, 7),
|
|
39
|
+
author: currentAuthor,
|
|
40
|
+
date: currentDate,
|
|
41
|
+
content,
|
|
42
|
+
});
|
|
43
|
+
i++;
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
i++;
|
|
47
|
+
}
|
|
48
|
+
return result;
|
|
49
|
+
};
|
|
50
|
+
export const gitBlameExecutor = async (input, context) => {
|
|
51
|
+
assertNotAborted(context.abortSignal);
|
|
52
|
+
const policy = resolveSandboxPolicy(context);
|
|
53
|
+
const cwd = input.cwd ? resolveAllowedPath(input.cwd, policy) : resolve(context.workspaceRoot);
|
|
54
|
+
const filePath = resolveAllowedPath(input.path, policy);
|
|
55
|
+
const startLine = input.startLine ?? 1;
|
|
56
|
+
const cmd = ["git", "blame", "--porcelain"];
|
|
57
|
+
if (input.endLine !== undefined) {
|
|
58
|
+
cmd.push("-L", `${startLine},${input.endLine}`);
|
|
59
|
+
}
|
|
60
|
+
else if (startLine > 1) {
|
|
61
|
+
cmd.push("-L", `${startLine},`);
|
|
62
|
+
}
|
|
63
|
+
cmd.push("--", filePath);
|
|
64
|
+
const proc = Bun.spawn({ cmd, cwd, stdout: "pipe", stderr: "pipe" });
|
|
65
|
+
const [stdout, stderr, exitCode] = await Promise.all([
|
|
66
|
+
new Response(proc.stdout).text(),
|
|
67
|
+
new Response(proc.stderr).text(),
|
|
68
|
+
proc.exited,
|
|
69
|
+
]);
|
|
70
|
+
assertNotAborted(context.abortSignal);
|
|
71
|
+
if (exitCode !== 0) {
|
|
72
|
+
return { error: stderr || `git blame exited with code ${exitCode}` };
|
|
73
|
+
}
|
|
74
|
+
return { lines: parsePorcelain(stdout), path: input.path };
|
|
75
|
+
};
|
|
76
|
+
//# sourceMappingURL=executor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"executor.js","sourceRoot":"","sources":["../../../src/tools/git-blame/execut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?: boolean;
|
|
5
|
+
}
|
|
6
|
+
interface BranchEntry {
|
|
7
|
+
name: string;
|
|
8
|
+
current: boolean;
|
|
9
|
+
remote: boolean;
|
|
10
|
+
upstream?: string;
|
|
11
|
+
ahead?: number;
|
|
12
|
+
behind?: number;
|
|
13
|
+
}
|
|
14
|
+
interface GitBranchOutput {
|
|
15
|
+
branches: BranchEntry[];
|
|
16
|
+
current: string;
|
|
17
|
+
}
|
|
18
|
+
export declare const gitBranchExecutor: ToolExecutor<GitBranchInput, GitBranchOutput | {
|
|
19
|
+
error: string;
|
|
20
|
+
}>;
|
|
21
|
+
export {};
|
|
22
|
+
//# sourceMappingURL=executor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../../src/tools/git-branch/executor.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAI9C,UAAU,cAAc;IACtB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,OAAO,CAAC;CACf;AAED,UAAU,WAAW;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,OAAO,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,UAAU,eAAe;IACvB,QAAQ,EAAE,WAAW,EAAE,CAAC;IACxB,OAAO,EAAE,MAAM,CAAC;CACjB;AAiDD,eAAO,MAAM,iBAAiB,EAAE,YAAY,CAAC,cAAc,EAAE,eAAe,GAAG;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CAmC7F,CAAC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { resolve } from "node:path";
|
|
2
|
+
import { assertNotAborted, resolveSandboxPolicy } from "../shared";
|
|
3
|
+
import { resolveAllowedPath } from "../../common/path";
|
|
4
|
+
// Parses lines from `git branch -vv` or `git branch -vva`
|
|
5
|
+
// Format: [* ] <name> <hash> [<upstream>[: ahead N[, behind N]]] <subject>
|
|
6
|
+
const parseBranchLine = (line) => {
|
|
7
|
+
const current = line.startsWith("* ");
|
|
8
|
+
// Strip the leading "* " or " "
|
|
9
|
+
const rest = line.slice(2);
|
|
10
|
+
// Split by whitespace: name, hash, rest...
|
|
11
|
+
const spaceIdx = rest.search(/\s/);
|
|
12
|
+
if (spaceIdx < 0)
|
|
13
|
+
return null;
|
|
14
|
+
const name = rest.slice(0, spaceIdx).trim();
|
|
15
|
+
const after = rest.slice(spaceIdx).trim();
|
|
16
|
+
// after: "<hash> [upstream info] subject"
|
|
17
|
+
const hashEnd = after.search(/\s/);
|
|
18
|
+
if (hashEnd < 0)
|
|
19
|
+
return null;
|
|
20
|
+
const remaining = after.slice(hashEnd).trim();
|
|
21
|
+
const remote = name.startsWith("remotes/");
|
|
22
|
+
let upstream;
|
|
23
|
+
let ahead;
|
|
24
|
+
let behind;
|
|
25
|
+
// Check for upstream tracking info like [origin/main] or [origin/main: ahead 2, behind 1]
|
|
26
|
+
const trackingMatch = remaining.match(/^\[([^\]]+)\]/);
|
|
27
|
+
if (trackingMatch) {
|
|
28
|
+
const trackingInfo = trackingMatch[1];
|
|
29
|
+
const colonIdx = trackingInfo.indexOf(":");
|
|
30
|
+
if (colonIdx >= 0) {
|
|
31
|
+
upstream = trackingInfo.slice(0, colonIdx).trim();
|
|
32
|
+
const stats = trackingInfo.slice(colonIdx + 1);
|
|
33
|
+
const aheadMatch = stats.match(/ahead\s+(\d+)/);
|
|
34
|
+
const behindMatch = stats.match(/behind\s+(\d+)/);
|
|
35
|
+
if (aheadMatch)
|
|
36
|
+
ahead = parseInt(aheadMatch[1], 10);
|
|
37
|
+
if (behindMatch)
|
|
38
|
+
behind = parseInt(behindMatch[1], 10);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
upstream = trackingInfo.trim();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const entry = { name, current, remote };
|
|
45
|
+
if (upstream !== undefined)
|
|
46
|
+
entry.upstream = upstream;
|
|
47
|
+
if (ahead !== undefined)
|
|
48
|
+
entry.ahead = ahead;
|
|
49
|
+
if (behind !== undefined)
|
|
50
|
+
entry.behind = behind;
|
|
51
|
+
return entry;
|
|
52
|
+
};
|
|
53
|
+
export const gitBranchExecutor = async (input, context) => {
|
|
54
|
+
assertNotAborted(context.abortSignal);
|
|
55
|
+
const policy = resolveSandboxPolicy(context);
|
|
56
|
+
const cwd = input.cwd ? resolveAllowedPath(input.cwd, policy) : resolve(context.workspaceRoot);
|
|
57
|
+
const cmd = input.all ? ["git", "branch", "-vva"] : ["git", "branch", "-vv"];
|
|
58
|
+
const proc = Bun.spawn({ cmd, cwd, stdout: "pipe", stderr: "pipe" });
|
|
59
|
+
const [stdout, stderr, exitCode] = await Promise.all([
|
|
60
|
+
new Response(proc.stdout).text(),
|
|
61
|
+
new Response(proc.stderr).text(),
|
|
62
|
+
proc.exited,
|
|
63
|
+
]);
|
|
64
|
+
assertNotAborted(context.abortSignal);
|
|
65
|
+
if (exitCode !== 0) {
|
|
66
|
+
return { error: stderr || `git branch exited with code ${exitCode}` };
|
|
67
|
+
}
|
|
68
|
+
const lines = stdout.split("\n").filter((l) => l.trim().length > 0);
|
|
69
|
+
const branches = [];
|
|
70
|
+
let current = "";
|
|
71
|
+
for (const line of lines) {
|
|
72
|
+
const entry = parseBranchLine(line);
|
|
73
|
+
if (entry) {
|
|
74
|
+
branches.push(entry);
|
|
75
|
+
if (entry.current)
|
|
76
|
+
current = entry.name;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return { branches, current };
|
|
80
|
+
};
|
|
81
|
+
//# sourceMappingURL=executor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"executor.js","sourceRoot":"","sources":["../../../src/tools/git-branch/executor.ts"],"names":[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AM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,KAAK,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC;QACpC,IAAI,KAAK,EAAE,CAAC;YACV,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACrB,IAAI,KAAK,CAAC,OAAO;gBAAE,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC;QAC1C,CAAC;IACH,CAAC;IAED,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC;AAC/B,CAAC,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { ToolExecutor } from "../shared";
|
|
2
|
+
interface GitDiffInput {
|
|
3
|
+
cwd?: string;
|
|
4
|
+
path?: string;
|
|
5
|
+
staged?: boolean;
|
|
6
|
+
ref?: string;
|
|
7
|
+
context?: number;
|
|
8
|
+
maxBytes?: number;
|
|
9
|
+
}
|
|
10
|
+
interface DiffHunk {
|
|
11
|
+
oldStart: number;
|
|
12
|
+
oldLines: number;
|
|
13
|
+
newStart: number;
|
|
14
|
+
newLines: number;
|
|
15
|
+
header: string;
|
|
16
|
+
lines: string[];
|
|
17
|
+
}
|
|
18
|
+
interface FileDiff {
|
|
19
|
+
path: string;
|
|
20
|
+
oldPath?: string;
|
|
21
|
+
status: "modified" | "added" | "deleted" | "renamed" | "copied";
|
|
22
|
+
additions: number;
|
|
23
|
+
deletions: number;
|
|
24
|
+
hunks: DiffHunk[];
|
|
25
|
+
binary: boolean;
|
|
26
|
+
}
|
|
27
|
+
interface GitDiffOutput {
|
|
28
|
+
files: FileDiff[];
|
|
29
|
+
totalAdditions: number;
|
|
30
|
+
totalDeletions: number;
|
|
31
|
+
truncated: boolean;
|
|
32
|
+
}
|
|
33
|
+
export declare const gitDiffExecutor: ToolExecutor<GitDiffInput, GitDiffOutput | {
|
|
34
|
+
error: string;
|
|
35
|
+
}>;
|
|
36
|
+
export {};
|
|
37
|
+
//# sourceMappingURL=executor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../../src/tools/git-diff/executor.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAI9C,UAAU,YAAY;IACpB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,UAAU,QAAQ;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB;AAED,UAAU,QAAQ;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,UAAU,GAAG,OAAO,GAAG,SAAS,GAAG,SAAS,GAAG,QAAQ,CAAC;IAChE,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,QAAQ,EAAE,CAAC;IAClB,MAAM,EAAE,OAAO,CAAC;CACjB;AAED,UAAU,aAAa;IACrB,KAAK,EAAE,QAAQ,EAAE,CAAC;IAClB,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,OAAO,CAAC;CACpB;AA4GD,eAAO,MAAM,eAAe,EAAE,YAAY,CAAC,YAAY,EAAE,aAAa,GAAG;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CAgDvF,CAAC"}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { resolve } from "node:path";
|
|
2
|
+
import { assertNotAborted, resolveSandboxPolicy } from "../shared";
|
|
3
|
+
import { resolveAllowedPath } from "../../common/path";
|
|
4
|
+
const HUNK_HEADER_RE = /^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@(.*)$/;
|
|
5
|
+
const parseDiff = (rawDiff) => {
|
|
6
|
+
const files = [];
|
|
7
|
+
const fileBlocks = rawDiff.split(/^diff --git /m).filter((b) => b.trim().length > 0);
|
|
8
|
+
for (const block of fileBlocks) {
|
|
9
|
+
const lines = block.split("\n");
|
|
10
|
+
let path = "";
|
|
11
|
+
let oldPath;
|
|
12
|
+
let status = "modified";
|
|
13
|
+
let binary = false;
|
|
14
|
+
let additions = 0;
|
|
15
|
+
let deletions = 0;
|
|
16
|
+
const hunks = [];
|
|
17
|
+
// Parse header lines
|
|
18
|
+
let i = 0;
|
|
19
|
+
// First line is "a/... b/..."
|
|
20
|
+
const firstLine = lines[0] ?? "";
|
|
21
|
+
const abMatch = firstLine.match(/^a\/(.+) b\/(.+)$/);
|
|
22
|
+
if (abMatch) {
|
|
23
|
+
oldPath = abMatch[1];
|
|
24
|
+
path = abMatch[2];
|
|
25
|
+
}
|
|
26
|
+
i = 1;
|
|
27
|
+
while (i < lines.length) {
|
|
28
|
+
const line = lines[i];
|
|
29
|
+
if (line.startsWith("new file mode")) {
|
|
30
|
+
status = "added";
|
|
31
|
+
}
|
|
32
|
+
else if (line.startsWith("deleted file mode")) {
|
|
33
|
+
status = "deleted";
|
|
34
|
+
}
|
|
35
|
+
else if (line.startsWith("rename from ")) {
|
|
36
|
+
oldPath = line.slice("rename from ".length);
|
|
37
|
+
status = "renamed";
|
|
38
|
+
}
|
|
39
|
+
else if (line.startsWith("rename to ")) {
|
|
40
|
+
path = line.slice("rename to ".length);
|
|
41
|
+
status = "renamed";
|
|
42
|
+
}
|
|
43
|
+
else if (line.startsWith("copy from ")) {
|
|
44
|
+
oldPath = line.slice("copy from ".length);
|
|
45
|
+
status = "copied";
|
|
46
|
+
}
|
|
47
|
+
else if (line.startsWith("copy to ")) {
|
|
48
|
+
path = line.slice("copy to ".length);
|
|
49
|
+
status = "copied";
|
|
50
|
+
}
|
|
51
|
+
else if (line.startsWith("Binary files")) {
|
|
52
|
+
binary = true;
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
else if (line.startsWith("GIT binary patch")) {
|
|
56
|
+
binary = true;
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
else if (line.startsWith("--- ")) {
|
|
60
|
+
// entering hunk section
|
|
61
|
+
i++;
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
i++;
|
|
65
|
+
}
|
|
66
|
+
if (!binary) {
|
|
67
|
+
// Skip "+++ " line if present
|
|
68
|
+
if (i < lines.length && lines[i]?.startsWith("+++ ")) {
|
|
69
|
+
i++;
|
|
70
|
+
}
|
|
71
|
+
// Parse hunks
|
|
72
|
+
while (i < lines.length) {
|
|
73
|
+
const line = lines[i];
|
|
74
|
+
const hunkMatch = line.match(HUNK_HEADER_RE);
|
|
75
|
+
if (hunkMatch) {
|
|
76
|
+
const oldStart = parseInt(hunkMatch[1], 10);
|
|
77
|
+
const oldLines = hunkMatch[2] !== undefined ? parseInt(hunkMatch[2], 10) : 1;
|
|
78
|
+
const newStart = parseInt(hunkMatch[3], 10);
|
|
79
|
+
const newLines = hunkMatch[4] !== undefined ? parseInt(hunkMatch[4], 10) : 1;
|
|
80
|
+
const hunkLines = [line];
|
|
81
|
+
i++;
|
|
82
|
+
while (i < lines.length && !lines[i].match(HUNK_HEADER_RE) && !lines[i].startsWith("diff --git ")) {
|
|
83
|
+
const dl = lines[i];
|
|
84
|
+
hunkLines.push(dl);
|
|
85
|
+
if (dl.startsWith("+"))
|
|
86
|
+
additions++;
|
|
87
|
+
else if (dl.startsWith("-"))
|
|
88
|
+
deletions++;
|
|
89
|
+
i++;
|
|
90
|
+
}
|
|
91
|
+
hunks.push({
|
|
92
|
+
oldStart,
|
|
93
|
+
oldLines,
|
|
94
|
+
newStart,
|
|
95
|
+
newLines,
|
|
96
|
+
header: line,
|
|
97
|
+
lines: hunkLines,
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
i++;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
const fileDiff = { path, status, additions, deletions, hunks, binary };
|
|
106
|
+
if (oldPath !== undefined && (status === "renamed" || status === "copied")) {
|
|
107
|
+
fileDiff.oldPath = oldPath;
|
|
108
|
+
}
|
|
109
|
+
files.push(fileDiff);
|
|
110
|
+
}
|
|
111
|
+
return files;
|
|
112
|
+
};
|
|
113
|
+
export const gitDiffExecutor = async (input, context) => {
|
|
114
|
+
assertNotAborted(context.abortSignal);
|
|
115
|
+
const policy = resolveSandboxPolicy(context);
|
|
116
|
+
const cwd = input.cwd
|
|
117
|
+
? resolveAllowedPath(input.cwd, policy)
|
|
118
|
+
: resolve(context.workspaceRoot);
|
|
119
|
+
const contextLines = input.context ?? 3;
|
|
120
|
+
const maxBytes = input.maxBytes ?? 32768;
|
|
121
|
+
const cmd = ["git", "diff", `--unified=${contextLines}`];
|
|
122
|
+
if (input.staged)
|
|
123
|
+
cmd.push("--staged");
|
|
124
|
+
if (input.ref)
|
|
125
|
+
cmd.push(input.ref);
|
|
126
|
+
if (input.path)
|
|
127
|
+
cmd.push("--", input.path);
|
|
128
|
+
const proc = Bun.spawn({ cmd, cwd, stdout: "pipe", stderr: "pipe" });
|
|
129
|
+
const [rawBytes, stderr, exitCode] = await Promise.all([
|
|
130
|
+
new Response(proc.stdout).arrayBuffer(),
|
|
131
|
+
new Response(proc.stderr).text(),
|
|
132
|
+
proc.exited,
|
|
133
|
+
]);
|
|
134
|
+
assertNotAborted(context.abortSignal);
|
|
135
|
+
if (exitCode !== 0 && exitCode !== 1) {
|
|
136
|
+
return { error: stderr || `git diff exited with code ${exitCode}` };
|
|
137
|
+
}
|
|
138
|
+
let truncated = false;
|
|
139
|
+
let rawDiff;
|
|
140
|
+
if (rawBytes.byteLength > maxBytes) {
|
|
141
|
+
truncated = true;
|
|
142
|
+
rawDiff = new TextDecoder().decode(rawBytes.slice(0, maxBytes));
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
rawDiff = new TextDecoder().decode(rawBytes);
|
|
146
|
+
}
|
|
147
|
+
const files = parseDiff(rawDiff);
|
|
148
|
+
let totalAdditions = 0;
|
|
149
|
+
let totalDeletions = 0;
|
|
150
|
+
for (const f of files) {
|
|
151
|
+
totalAdditions += f.additions;
|
|
152
|
+
totalDeletions += f.deletions;
|
|
153
|
+
}
|
|
154
|
+
return { files, totalAdditions, totalDeletions, truncated };
|
|
155
|
+
};
|
|
156
|
+
//# sourceMappingURL=executor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"executor.js","sourceRoot":"","sources":["../../../src/tools/git-diff/executor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAqCvD,MAAM,cAAc,GAAG,kDAAkD,CAAC;AAE1E,MAAM,SAAS,GAAG,CAAC,OAAe,EAAc,EAAE;IAChD,MAAM,KAAK,GAAe,EAAE,CAAC;IAC7B,MAAM,UAAU,GAAG,OAAO,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAErF,KAAK,MAAM,KAAK,IAAI,UAAU,EAAE,CAAC;QAC/B,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAChC,IAAI,IAAI,GAAG,EAAE,CAAC;QACd,IAAI,OAA2B,CAAC;QAChC,IAAI,MAAM,GAA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EAAE,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,SAAS,EAAE,CAAC;AAC9D,CAAC,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { ToolExecutor } from "../shared";
|
|
2
|
+
interface GitLogInput {
|
|
3
|
+
cwd?: string;
|
|
4
|
+
limit?: number;
|
|
5
|
+
since?: string;
|
|
6
|
+
until?: string;
|
|
7
|
+
author?: string;
|
|
8
|
+
path?: string;
|
|
9
|
+
ref?: string;
|
|
10
|
+
oneline?: boolean;
|
|
11
|
+
}
|
|
12
|
+
interface GitCommit {
|
|
13
|
+
hash: string;
|
|
14
|
+
shortHash: string;
|
|
15
|
+
author: string;
|
|
16
|
+
email: string;
|
|
17
|
+
date: string;
|
|
18
|
+
subject: string;
|
|
19
|
+
body?: string;
|
|
20
|
+
refs?: string[];
|
|
21
|
+
}
|
|
22
|
+
interface GitLogOutput {
|
|
23
|
+
commits: GitCommit[];
|
|
24
|
+
total: number;
|
|
25
|
+
hasMore: boolean;
|
|
26
|
+
}
|
|
27
|
+
export declare const gitLogExecutor: ToolExecutor<GitLogInput, GitLogOutput | {
|
|
28
|
+
error: string;
|
|
29
|
+
}>;
|
|
30
|
+
export {};
|
|
31
|
+
//# sourceMappingURL=executor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../../src/tools/git-log/executor.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAI9C,UAAU,WAAW;IACnB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,UAAU,SAAS;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;CACjB;AAED,UAAU,YAAY;IACpB,OAAO,EAAE,SAAS,EAAE,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,OAAO,CAAC;CAClB;AAkCD,eAAO,MAAM,cAAc,EAAE,YAAY,CAAC,WAAW,EAAE,YAAY,GAAG;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CAsCtF,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { resolve } from "node:path";
|
|
2
|
+
import { assertNotAborted, resolveSandboxPolicy } from "../shared";
|
|
3
|
+
import { resolveAllowedPath } from "../../common/path";
|
|
4
|
+
// Fields: hash \x1f shortHash \x1f author \x1f email \x1f date \x1f refs \x1f subject \x1f body \x1e
|
|
5
|
+
const FORMAT = "%H\x1f%h\x1f%an\x1f%ae\x1f%aI\x1f%D\x1f%s\x1f%b\x1e";
|
|
6
|
+
const parseLog = (stdout, oneline) => {
|
|
7
|
+
const records = stdout.split("\x1e").filter((r) => r.trim().length > 0);
|
|
8
|
+
return records.map((record) => {
|
|
9
|
+
const parts = record.trim().split("\x1f");
|
|
10
|
+
const hash = parts[0] ?? "";
|
|
11
|
+
const shortHash = parts[1] ?? "";
|
|
12
|
+
const author = parts[2] ?? "";
|
|
13
|
+
const email = parts[3] ?? "";
|
|
14
|
+
const date = parts[4] ?? "";
|
|
15
|
+
const refsRaw = parts[5] ?? "";
|
|
16
|
+
const subject = parts[6] ?? "";
|
|
17
|
+
const body = parts[7] ?? "";
|
|
18
|
+
const refs = refsRaw
|
|
19
|
+
.split(",")
|
|
20
|
+
.map((r) => r.trim())
|
|
21
|
+
.filter((r) => r.length > 0);
|
|
22
|
+
const commit = { hash, shortHash, author, email, date, subject };
|
|
23
|
+
if (!oneline && body.trim().length > 0) {
|
|
24
|
+
commit.body = body.trim();
|
|
25
|
+
}
|
|
26
|
+
if (refs.length > 0) {
|
|
27
|
+
commit.refs = refs;
|
|
28
|
+
}
|
|
29
|
+
return commit;
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
export const gitLogExecutor = async (input, context) => {
|
|
33
|
+
assertNotAborted(context.abortSignal);
|
|
34
|
+
const policy = resolveSandboxPolicy(context);
|
|
35
|
+
const cwd = input.cwd ? resolveAllowedPath(input.cwd, policy) : resolve(context.workspaceRoot);
|
|
36
|
+
const limit = Math.min(input.limit ?? 20, 100);
|
|
37
|
+
const ref = input.ref ?? "HEAD";
|
|
38
|
+
const oneline = input.oneline ?? false;
|
|
39
|
+
const cmd = ["git", "log", `--format=${FORMAT}`, `-n`, String(limit), ref];
|
|
40
|
+
if (input.since)
|
|
41
|
+
cmd.push(`--since=${input.since}`);
|
|
42
|
+
if (input.until)
|
|
43
|
+
cmd.push(`--until=${input.until}`);
|
|
44
|
+
if (input.author)
|
|
45
|
+
cmd.push(`--author=${input.author}`);
|
|
46
|
+
if (input.path)
|
|
47
|
+
cmd.push("--", input.path);
|
|
48
|
+
const proc = Bun.spawn({ cmd, cwd, stdout: "pipe", stderr: "pipe" });
|
|
49
|
+
const [stdout, stderr, exitCode] = await Promise.all([
|
|
50
|
+
new Response(proc.stdout).text(),
|
|
51
|
+
new Response(proc.stderr).text(),
|
|
52
|
+
proc.exited,
|
|
53
|
+
]);
|
|
54
|
+
assertNotAborted(context.abortSignal);
|
|
55
|
+
if (exitCode !== 0) {
|
|
56
|
+
return { error: stderr || `git log exited with code ${exitCode}` };
|
|
57
|
+
}
|
|
58
|
+
const commits = parseLog(stdout, oneline);
|
|
59
|
+
return {
|
|
60
|
+
commits,
|
|
61
|
+
total: commits.length,
|
|
62
|
+
hasMore: commits.length >= limit,
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
//# sourceMappingURL=executor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"executor.js","sourceRoot":"","sources":["../../../src/tools/git-log/executor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AA8BvD,qGAAqG;AACrG,MAAM,MAAM,GAAG,qDAAqD,CAAC;AAErE,MAAM,QAAQ,GAAG,CAAC,MAAc,EAAE,OAAgB,EAAe,EAAE;IACjE,MAAM,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACxE,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE;QAC5B,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QAC1C,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QAC5B,MAAM,SAAS,GAAG,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QACjC,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QAC9B,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QAC7B,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QAC5B,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;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