@sourcegraph/amp 0.0.1748851339-g31df22 → 0.0.1748877319-g69d2be
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/amp.js +3 -2
- package/dist/amp.js.map +1 -1
- package/dist/client-CEMYqypS.js +35 -0
- package/dist/client-CEMYqypS.js.map +1 -0
- package/dist/{console-k3nh7b4U.js → console-Dz8kjLXq.js} +38668 -17361
- package/dist/console-Dz8kjLXq.js.map +1 -0
- package/dist/{create_file.node-Dxp9NAiW.js → create_file.node-Dkg9a9qS.js} +2 -2
- package/dist/{create_file.node-Dxp9NAiW.js.map → create_file.node-Dkg9a9qS.js.map} +1 -1
- package/dist/{edit_file.node-BlCpGVR-.js → edit_file.node-BzmJeIBM.js} +10 -10
- package/dist/{edit_file.node-BlCpGVR-.js.map → edit_file.node-BzmJeIBM.js.map} +1 -1
- package/dist/{executable-DTI1_xm7.js → executable-BfvtWYTF.js} +2 -2
- package/dist/{executable-DTI1_xm7.js.map → executable-BfvtWYTF.js.map} +1 -1
- package/dist/{files-DdjDm_B8.js → files-DLJqtzT7.js} +3 -3
- package/dist/{files-DdjDm_B8.js.map → files-DLJqtzT7.js.map} +1 -1
- package/dist/glob.node-D18uhtO0.js +137 -0
- package/dist/glob.node-D18uhtO0.js.map +1 -0
- package/dist/index-DDEnF9L5.js +922 -0
- package/dist/index-DDEnF9L5.js.map +1 -0
- package/dist/{list_directory.node-DDhJZGvT.js → list_directory.node-ldHqnCmb.js} +2 -2
- package/dist/{list_directory.node-DDhJZGvT.js.map → list_directory.node-ldHqnCmb.js.map} +1 -1
- package/dist/{load-profile-CWDhvBXX.js → load-profile-2hKEWJfV.js} +2 -2
- package/dist/{load-profile-CWDhvBXX.js.map → load-profile-2hKEWJfV.js.map} +1 -1
- package/dist/main-BnHTihL6.js +19700 -0
- package/dist/main-BnHTihL6.js.map +1 -0
- package/dist/{node-B1RLuGfG.js → node-BHe5RJPs.js} +41 -41
- package/dist/{node-B1RLuGfG.js.map → node-BHe5RJPs.js.map} +1 -1
- package/dist/{node-w5kFgl6-.js → node-BMzC1GPN.js} +47 -47
- package/dist/{node-w5kFgl6-.js.map → node-BMzC1GPN.js.map} +1 -1
- package/dist/node-BRxAOe2b.js +85 -0
- package/dist/node-BRxAOe2b.js.map +1 -0
- package/dist/{node-DGc3Eu0F.js → node-CUTKGt9Y.js} +3 -3
- package/dist/{node-DGc3Eu0F.js.map → node-CUTKGt9Y.js.map} +1 -1
- package/dist/{node-BZlRkYQw.js → node-CzSXw-Xz.js} +2 -2
- package/dist/{node-BZlRkYQw.js.map → node-CzSXw-Xz.js.map} +1 -1
- package/dist/{node-DuhaU87r.js → node-DcXu8fEU.js} +1090 -833
- package/dist/node-DcXu8fEU.js.map +1 -0
- package/dist/{read_file.node-CsATnmUF.js → read_file.node-6DnwIJAn.js} +2 -2
- package/dist/{read_file.node-CsATnmUF.js.map → read_file.node-6DnwIJAn.js.map} +1 -1
- package/dist/{stdio-Egb8ZIIg.js → stdio-B_076PGB.js} +29 -29
- package/dist/{stdio-Egb8ZIIg.js.map → stdio-B_076PGB.js.map} +1 -1
- package/dist/storybook.js +1 -1
- package/dist/{undo_edit.node-CHrrMPkn.js → undo_edit.node-WsSsWWo7.js} +10 -10
- package/dist/{undo_edit.node-CHrrMPkn.js.map → undo_edit.node-WsSsWWo7.js.map} +1 -1
- package/package.json +1 -1
- package/dist/console-k3nh7b4U.js.map +0 -1
- package/dist/glob.node-BnKeKl9M.js +0 -1051
- package/dist/glob.node-BnKeKl9M.js.map +0 -1
- package/dist/main-DuPQOPga.js +0 -40843
- package/dist/main-DuPQOPga.js.map +0 -1
- package/dist/node-3m0J6gBv.js +0 -72
- package/dist/node-3m0J6gBv.js.map +0 -1
- package/dist/node-DuhaU87r.js.map +0 -1
@@ -0,0 +1,85 @@
|
|
1
|
+
#!/usr/bin/env node
|
2
|
+
import { p as f } from "./index-DDEnF9L5.js";
|
3
|
+
import { aA as m, g, m as c, aL as h, aM as d, aN as b, aO as E, c as S, O as _ } from "./console-Dz8kjLXq.js";
|
4
|
+
import { r as v } from "./executable-BfvtWYTF.js";
|
5
|
+
const O = ({ args: a }, { dirs: s }) => {
|
6
|
+
for (const e of s)
|
7
|
+
m(e);
|
8
|
+
return g(...s.map((e) => A(e.fsPath, a))).pipe(
|
9
|
+
c((e) => {
|
10
|
+
const t = [];
|
11
|
+
for (const r of e)
|
12
|
+
r.status === "in-progress" ? t.push(...r?.progress ?? []) : r.status === "done" ? t.push(...r.result) : r.status === "cancelled" ? t.push(...r.progress ?? []) : r.status === "error" && t.push(...r.progress ?? []);
|
13
|
+
const o = e.filter((r) => r.status === "error");
|
14
|
+
return o.length > 0 ? {
|
15
|
+
status: "error",
|
16
|
+
progress: t,
|
17
|
+
error: {
|
18
|
+
message: o.map((r) => r?.error?.message ?? "").join(`
|
19
|
+
`)
|
20
|
+
}
|
21
|
+
} : {
|
22
|
+
status: e.every((r) => r.status === "done") ? "done" : e.some((r) => r.status === "cancelled") ? "cancelled" : "in-progress",
|
23
|
+
progress: t,
|
24
|
+
result: t
|
25
|
+
};
|
26
|
+
})
|
27
|
+
);
|
28
|
+
};
|
29
|
+
function A(a, s) {
|
30
|
+
const e = [
|
31
|
+
"--with-filename",
|
32
|
+
"--line-number",
|
33
|
+
"--no-heading",
|
34
|
+
"--no-require-git",
|
35
|
+
"--max-columns",
|
36
|
+
h.toString(),
|
37
|
+
"--trim",
|
38
|
+
"--max-count",
|
39
|
+
d.toString()
|
40
|
+
];
|
41
|
+
s.caseSensitive || e.push("-i"), e.push("--regexp", s.pattern), s.path && (b(s.path), e.push(s.path));
|
42
|
+
const t = s?.glob ? f(s.glob, { nocase: !s.caseSensitive, dot: !0 }) : void 0;
|
43
|
+
return E(v(), e, {
|
44
|
+
cwd: a,
|
45
|
+
stdio: ["ignore", "pipe", "pipe"]
|
46
|
+
}).pipe(
|
47
|
+
c(({ stdout: o, stderr: l, exitCode: r, exited: i }) => {
|
48
|
+
const n = o.trim().split(`
|
49
|
+
`).filter((p) => {
|
50
|
+
if (p.length === 0)
|
51
|
+
return !1;
|
52
|
+
if (t) {
|
53
|
+
const [u] = p.split(":", 1);
|
54
|
+
if (u && !t(u))
|
55
|
+
return !1;
|
56
|
+
}
|
57
|
+
return !0;
|
58
|
+
});
|
59
|
+
return i ? i && r && r >= 2 ? {
|
60
|
+
status: "error",
|
61
|
+
progress: n,
|
62
|
+
error: { message: `ripgrep exited with code ${r}` }
|
63
|
+
} : {
|
64
|
+
status: "done",
|
65
|
+
progress: n,
|
66
|
+
result: n
|
67
|
+
} : {
|
68
|
+
status: "in-progress",
|
69
|
+
progress: n
|
70
|
+
};
|
71
|
+
}),
|
72
|
+
S(
|
73
|
+
(o) => _.of({
|
74
|
+
status: "error",
|
75
|
+
progress: [],
|
76
|
+
error: { message: String(o) }
|
77
|
+
})
|
78
|
+
)
|
79
|
+
);
|
80
|
+
}
|
81
|
+
export {
|
82
|
+
O as nodeGrepTool,
|
83
|
+
A as ripgrepFiles
|
84
|
+
};
|
85
|
+
//# sourceMappingURL=node-BRxAOe2b.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"node-BRxAOe2b.js","sources":["../../core/src/tools/builtin/grep/node.ts"],"sourcesContent":["import { catchError, combineLatest, map, Observable } from '@sourcegraph/observable'\nimport pm from 'picomatch'\nimport type { ToolRun } from '../../tool-service'\nimport { checkArgSafety, checkDirURIIsFile, spawnAndObserveChildProcess } from '../node-helpers'\nimport type { GrepToolArgs } from './common'\nimport {\n\tGREP_MAX_COLUMN_LENGTH,\n\tGREP_MAX_RESULTS_PER_FILE,\n\ttype GrepToolDef,\n\ttype grepToolReg,\n} from './common'\nimport { ripgrepExecutable } from './executable'\n\nexport const nodeGrepTool: NonNullable<(typeof grepToolReg)['fn']> = ({ args }, { dirs }) => {\n\tfor (const dir of dirs) {\n\t\tcheckDirURIIsFile(dir)\n\t}\n\treturn combineLatest(...dirs.map((dir) => ripgrepFiles(dir.fsPath, args))).pipe(\n\t\tmap<ToolRun<GrepToolDef>[], ToolRun<GrepToolDef>>((results) => {\n\t\t\tconst progress: string[] = []\n\t\t\tfor (const result of results) {\n\t\t\t\tif (result.status === 'in-progress') {\n\t\t\t\t\tprogress.push(...(result?.progress ?? []))\n\t\t\t\t} else if (result.status === 'done') {\n\t\t\t\t\tprogress.push(...result.result)\n\t\t\t\t} else if (result.status === 'cancelled') {\n\t\t\t\t\tprogress.push(...(result.progress ?? []))\n\t\t\t\t} else if (result.status === 'error') {\n\t\t\t\t\tprogress.push(...(result.progress ?? []))\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst errors = results.filter((result) => result.status === 'error')\n\t\t\tif (errors.length > 0) {\n\t\t\t\treturn {\n\t\t\t\t\tstatus: 'error',\n\t\t\t\t\tprogress,\n\t\t\t\t\terror: {\n\t\t\t\t\t\tmessage: errors\n\t\t\t\t\t\t\t.map<string>((error) => error?.error?.message ?? '')\n\t\t\t\t\t\t\t.join('\\n'),\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst status = results.every((result) => result.status === 'done')\n\t\t\t\t? 'done'\n\t\t\t\t: results.some((result) => result.status === 'cancelled')\n\t\t\t\t\t? 'cancelled'\n\t\t\t\t\t: 'in-progress'\n\t\t\treturn {\n\t\t\t\tstatus,\n\t\t\t\tprogress,\n\t\t\t\tresult: progress,\n\t\t\t}\n\t\t}),\n\t)\n}\n\nexport function ripgrepFiles(dir: string, args: GrepToolArgs): Observable<ToolRun<GrepToolDef>> {\n\tconst ripgrepArgs: string[] = [\n\t\t'--with-filename',\n\t\t'--line-number',\n\t\t'--no-heading',\n\t\t'--no-require-git',\n\t\t'--max-columns',\n\t\tGREP_MAX_COLUMN_LENGTH.toString(),\n\t\t'--trim',\n\t\t'--max-count',\n\t\tGREP_MAX_RESULTS_PER_FILE.toString(),\n\t]\n\tif (!args.caseSensitive) {\n\t\tripgrepArgs.push('-i')\n\t}\n\tripgrepArgs.push('--regexp', args.pattern)\n\tif (args.path) {\n\t\tcheckArgSafety(args.path)\n\t\tripgrepArgs.push(args.path)\n\t}\n\n\t// Interpret the `glob` property in TypeScript instead of using the ripgrep\n\t// option `--glob` because using `--glob` disables the built-in gitignore\n\t// feature. We do the same thing in the Glob tool.\n\tconst matchesGlobPattern = args?.glob\n\t\t? pm(args.glob, { nocase: !args.caseSensitive, dot: true })\n\t\t: undefined\n\n\treturn spawnAndObserveChildProcess(ripgrepExecutable(), ripgrepArgs, {\n\t\tcwd: dir,\n\t\tstdio: ['ignore', 'pipe', 'pipe'],\n\t}).pipe(\n\t\tmap(({ stdout, stderr: _stderr, exitCode, exited }): ToolRun<GrepToolDef> => {\n\t\t\tconst matches = stdout\n\t\t\t\t.trim()\n\t\t\t\t.split('\\n')\n\t\t\t\t.filter((line) => {\n\t\t\t\t\tif (line.length === 0) {\n\t\t\t\t\t\treturn false\n\t\t\t\t\t}\n\t\t\t\t\tif (matchesGlobPattern) {\n\t\t\t\t\t\tconst [filename] = line.split(':', 1)\n\t\t\t\t\t\tif (filename && !matchesGlobPattern(filename)) {\n\t\t\t\t\t\t\treturn false\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\treturn true\n\t\t\t\t})\n\n\t\t\tif (!exited) {\n\t\t\t\treturn {\n\t\t\t\t\tstatus: 'in-progress',\n\t\t\t\t\tprogress: matches,\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// ripgrep exit code 1 means \"no matches found\"\n\t\t\tif (exited && exitCode && exitCode >= 2) {\n\t\t\t\treturn {\n\t\t\t\t\tstatus: 'error',\n\t\t\t\t\tprogress: matches,\n\t\t\t\t\terror: { message: `ripgrep exited with code ${exitCode}` },\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tstatus: 'done',\n\t\t\t\tprogress: matches,\n\t\t\t\tresult: matches,\n\t\t\t}\n\t\t}),\n\t\tcatchError((error) =>\n\t\t\tObservable.of({\n\t\t\t\tstatus: 'error',\n\t\t\t\tprogress: [],\n\t\t\t\terror: { message: String(error) },\n\t\t\t}),\n\t\t),\n\t)\n}\n"],"names":["nodeGrepTool","args","dirs","dir","checkDirURIIsFile","combineLatest","ripgrepFiles","map","results","progress","result","errors","error","ripgrepArgs","GREP_MAX_COLUMN_LENGTH","GREP_MAX_RESULTS_PER_FILE","checkArgSafety","matchesGlobPattern","pm","spawnAndObserveChildProcess","ripgrepExecutable","stdout","_stderr","exitCode","exited","matches","line","filename","catchError","Observable"],"mappings":";;;;AAaO,MAAMA,IAAwD,CAAC,EAAE,MAAAC,KAAQ,EAAE,MAAAC,QAAW;AAC5F,aAAWC,KAAOD;AACjB,IAAAE,EAAkBD,CAAG;AAEtB,SAAOE,EAAc,GAAGH,EAAK,IAAI,CAACC,MAAQG,EAAaH,EAAI,QAAQF,CAAI,CAAC,CAAC,EAAE;AAAA,IAC1EM,EAAkD,CAACC,MAAY;AAC9D,YAAMC,IAAqB,CAAC;AAC5B,iBAAWC,KAAUF;AAChB,QAAAE,EAAO,WAAW,gBACrBD,EAAS,KAAK,GAAIC,GAAQ,YAAY,CAAA,CAAG,IAC/BA,EAAO,WAAW,SACnBD,EAAA,KAAK,GAAGC,EAAO,MAAM,IACpBA,EAAO,WAAW,cAC5BD,EAAS,KAAK,GAAIC,EAAO,YAAY,CAAA,CAAG,IAC9BA,EAAO,WAAW,WAC5BD,EAAS,KAAK,GAAIC,EAAO,YAAY,CAAA,CAAG;AAG1C,YAAMC,IAASH,EAAQ,OAAO,CAACE,MAAWA,EAAO,WAAW,OAAO;AAC/D,aAAAC,EAAO,SAAS,IACZ;AAAA,QACN,QAAQ;AAAA,QACR,UAAAF;AAAA,QACA,OAAO;AAAA,UACN,SAASE,EACP,IAAY,CAACC,MAAUA,GAAO,OAAO,WAAW,EAAE,EAClD,KAAK;AAAA,CAAI;AAAA,QAAA;AAAA,MAEb,IAOM;AAAA,QACN,QANcJ,EAAQ,MAAM,CAACE,MAAWA,EAAO,WAAW,MAAM,IAC9D,SAC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AQ,GAAG;AAAA,MAC1D,IAGM;AAAA,QACN,QAAQ;AAAA,QACR,UAAUE;AAAA,QACV,QAAQA;AAAA,MACT,IAnBQ;AAAA,QACN,QAAQ;AAAA,QACR,UAAUA;AAAA,MACX;AAAA,IAgBD,CACA;AAAA,IACDG;AAAA,MAAW,CAAChB,MACXiB,EAAW,GAAG;AAAA,QACb,QAAQ;AAAA,QACR,UAAU,CAAC;AAAA,QACX,OAAO,EAAE,SAAS,OAAOjB,CAAK,EAAE;AAAA,MAChC,CAAA;AAAA,IAAA;AAAA,EAEH;AACD;"}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
#!/usr/bin/env node
|
2
|
-
import { f as a } from "./
|
3
|
-
import { p as u,
|
2
|
+
import { f as a } from "./client-CEMYqypS.js";
|
3
|
+
import { p as u, aP as c } from "./console-Dz8kjLXq.js";
|
4
4
|
const l = ({ args: o }, { threadID: t }) => u(async (s) => {
|
5
5
|
try {
|
6
6
|
const r = `/api/web-search?query=${encodeURIComponent(o.query)}&numResults=${o.num_results || 5}`, e = await a(r, {
|
@@ -23,4 +23,4 @@ const l = ({ args: o }, { threadID: t }) => u(async (s) => {
|
|
23
23
|
export {
|
24
24
|
l as nodeWebSearchTool
|
25
25
|
};
|
26
|
-
//# sourceMappingURL=node-
|
26
|
+
//# sourceMappingURL=node-CUTKGt9Y.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"node-
|
1
|
+
{"version":3,"file":"node-CUTKGt9Y.js","sources":["../../core/src/tools/builtin/web_search/node.ts"],"sourcesContent":["import { promiseFactoryToObservable } from '@sourcegraph/observable'\nimport { fetchFromAmpServer } from '../../../server-api/client'\nimport { HEADER_KEY_THREAD_ID } from '../../../server-api/headers'\nimport type { webSearchToolReg } from './common'\n\nexport const nodeWebSearchTool: NonNullable<(typeof webSearchToolReg)['fn']> = (\n\t{ args },\n\t{ threadID },\n) => {\n\treturn promiseFactoryToObservable(async (signal) => {\n\t\ttry {\n\t\t\t// Call the server endpoint using the fetchFromAmpServer helper\n\t\t\tconst url = `/api/web-search?query=${encodeURIComponent(args.query)}&numResults=${args.num_results || 5}`\n\t\t\tconst response = await fetchFromAmpServer(url, {\n\t\t\t\tmethod: 'GET',\n\t\t\t\tsignal,\n\t\t\t\theaders: threadID ? { [HEADER_KEY_THREAD_ID]: threadID } : undefined,\n\t\t\t})\n\n\t\t\tif (!response.ok) {\n\t\t\t\tconst errorText = await response.text()\n\t\t\t\tthrow new Error(`Server returned ${response.status}: ${errorText}`)\n\t\t\t}\n\n\t\t\tconst results = await response.json()\n\t\t\treturn {\n\t\t\t\tstatus: 'done' as const,\n\t\t\t\tresult: results,\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tthrow new Error(`Failed to perform web search: ${(error as Error).message}`)\n\t\t}\n\t})\n}\n"],"names":["nodeWebSearchTool","args","threadID","promiseFactoryToObservable","signal","url","response","fetchFromAmpServer","HEADER_KEY_THREAD_ID","errorText","error"],"mappings":";;;AAKO,MAAMA,IAAkE,CAC9E,EAAE,MAAAC,KACF,EAAE,UAAAC,QAEKC,EAA2B,OAAOC,MAAW;AAC/C,MAAA;AAEG,UAAAC,IAAM,yBAAyB,mBAAmBJ,EAAK,KAAK,CAAC,eAAeA,EAAK,eAAe,CAAC,IACjGK,IAAW,MAAMC,EAAmBF,GAAK;AAAA,MAC9C,QAAQ;AAAA,MACR,QAAAD;AAAA,MACA,SAASF,IAAW,EAAE,CAACM,CAAoB,GAAGN,EAAa,IAAA;AAAA,IAAA,CAC3D;AAEG,QAAA,CAACI,EAAS,IAAI;AACX,YAAAG,IAAY,MAAMH,EAAS,KAAK;AACtC,YAAM,IAAI,MAAM,mBAAmBA,EAAS,MAAM,KAAKG,CAAS,EAAE;AAAA,IAAA;AAI5D,WAAA;AAAA,MACN,QAAQ;AAAA,MACR,QAHe,MAAMH,EAAS,KAAK;AAAA,IAIpC;AAAA,WACQI,GAAO;AACf,UAAM,IAAI,MAAM,iCAAkCA,EAAgB,OAAO,EAAE;AAAA,EAAA;AAC5E,CACA;"}
|
@@ -4,7 +4,7 @@ import * as i from "node:fs";
|
|
4
4
|
import * as o from "node:path";
|
5
5
|
import { join as f } from "node:path";
|
6
6
|
import { promisify as p } from "node:util";
|
7
|
-
import {
|
7
|
+
import { C as l, aH as n } from "./console-Dz8kjLXq.js";
|
8
8
|
import { homedir as w } from "node:os";
|
9
9
|
const d = f(w(), ".amp", "file-changes"), u = p(m);
|
10
10
|
function b(a) {
|
@@ -110,4 +110,4 @@ export {
|
|
110
110
|
y as listFilesGit,
|
111
111
|
b as nodeFileSystem
|
112
112
|
};
|
113
|
-
//# sourceMappingURL=node-
|
113
|
+
//# sourceMappingURL=node-CzSXw-Xz.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"node-
|
1
|
+
{"version":3,"file":"node-CzSXw-Xz.js","sources":["../../core/src/platform/fs/backups.node.ts","../../core/src/platform/fs/node.ts"],"sourcesContent":["import { homedir } from 'node:os'\nimport { join } from 'node:path'\n\nexport const BACKUP_DIR_NODE = join(homedir(), '.amp', 'file-changes')\n","import { execFile } from 'node:child_process'\nimport * as fs from 'node:fs'\nimport * as path from 'node:path'\nimport { promisify } from 'node:util'\nimport logger from '../../common/logger'\nimport { type FileChangeRecord } from '../../threads/file-tracking/common'\nimport type { ThreadID } from '../../threads/thread'\nimport { BACKUP_DIR_NODE } from './backups.node'\nimport { FileNotExistError, type FileSystem } from './fs'\n\nconst execFileAsync = promisify(execFile)\n\nexport function nodeFileSystem(threadID: ThreadID): FileSystem {\n\tconst backupDir = path.join(BACKUP_DIR_NODE, threadID)\n\treturn {\n\t\trelativePath: (a: string, b: string) => path.relative(a, b),\n\t\tjoinPath: (...paths: string[]) => path.join(...paths),\n\n\t\treadFile: async (path: string, signal?: AbortSignal) => {\n\t\t\ttry {\n\t\t\t\treturn await fs.promises.readFile(path, { encoding: 'utf8', signal })\n\t\t\t} catch (error) {\n\t\t\t\tif (isNodeFSNotExistError(error)) {\n\t\t\t\t\tthrow new FileNotExistError(path)\n\t\t\t\t}\n\t\t\t\tthrow error\n\t\t\t}\n\t\t},\n\t\treadBinaryFile: async (path: string, signal?: AbortSignal) => {\n\t\t\ttry {\n\t\t\t\t// Read as Buffer without encoding\n\t\t\t\treturn await fs.promises.readFile(path, { signal })\n\t\t\t} catch (error) {\n\t\t\t\tif (isNodeFSNotExistError(error)) {\n\t\t\t\t\tthrow new FileNotExistError(path)\n\t\t\t\t}\n\t\t\t\tthrow error\n\t\t\t}\n\t\t},\n\t\tgetMtime: async (path: string, signal?: AbortSignal) => {\n\t\t\ttry {\n\t\t\t\t// Node.js stat doesn't support AbortSignal directly\n\t\t\t\tconst stats = await fs.promises.stat(path)\n\t\t\t\treturn stats.mtimeMs\n\t\t\t} catch (error) {\n\t\t\t\tif (isNodeFSNotExistError(error)) {\n\t\t\t\t\tthrow new FileNotExistError(path)\n\t\t\t\t}\n\t\t\t\tthrow error\n\t\t\t}\n\t\t},\n\t\tstat: async (path: string) => {\n\t\t\ttry {\n\t\t\t\tconst stats = await fs.promises.stat(path)\n\t\t\t\treturn {\n\t\t\t\t\tsize: stats.size,\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tif (isNodeFSNotExistError(error)) {\n\t\t\t\t\tthrow new FileNotExistError(path)\n\t\t\t\t}\n\t\t\t\tthrow error\n\t\t\t}\n\t\t},\n\t\twriteFile: async (path, content, signal) => {\n\t\t\tawait fs.promises.writeFile(path, content, { encoding: 'utf-8', signal })\n\t\t},\n\t\tdeleteFile: async (path, signal?: AbortSignal) => {\n\t\t\ttry {\n\t\t\t\tawait fs.promises.unlink(path)\n\t\t\t} catch (error) {\n\t\t\t\tif (isNodeFSNotExistError(error)) {\n\t\t\t\t\tthrow new FileNotExistError(path)\n\t\t\t\t}\n\t\t\t\tthrow error\n\t\t\t}\n\t\t},\n\t\tmkdirp: async (path) => {\n\t\t\tawait fs.promises.mkdir(path, { recursive: true })\n\t\t},\n\t\tstoreFileChange: async (backupFileName: string, fileChange: FileChangeRecord) => {\n\t\t\tconst backupPath = path.join(backupDir, backupFileName)\n\t\t\tawait fs.promises.writeFile(backupPath, JSON.stringify(fileChange, null, 2), 'utf8')\n\t\t},\n\t\tlistBackupFiles: async () => {\n\t\t\ttry {\n\t\t\t\t// Ensure backup directory exists\n\t\t\t\tif (\n\t\t\t\t\t!(await fs.promises\n\t\t\t\t\t\t.stat(backupDir)\n\t\t\t\t\t\t.then((s) => s.isDirectory())\n\t\t\t\t\t\t.catch(() => false))\n\t\t\t\t) {\n\t\t\t\t\tawait fs.promises.mkdir(backupDir, { recursive: true })\n\t\t\t\t\treturn []\n\t\t\t\t}\n\t\t\t\treturn await fs.promises.readdir(backupDir)\n\t\t\t} catch (error) {\n\t\t\t\tlogger.error('Error listing backup files:', error)\n\t\t\t\treturn []\n\t\t\t}\n\t\t},\n\t\tloadFileChange: async (backupFileName: string) => {\n\t\t\ttry {\n\t\t\t\tconst backupPath = path.join(backupDir, backupFileName)\n\t\t\t\tconst content = await fs.promises.readFile(backupPath, 'utf8')\n\t\t\t\treturn JSON.parse(content) as FileChangeRecord\n\t\t\t} catch (error) {\n\t\t\t\tlogger.error(`Error loading backup file ${backupFileName}:`, error)\n\t\t\t\treturn null\n\t\t\t}\n\t\t},\n\t\tcleanupBackupFiles: async () => {\n\t\t\ttry {\n\t\t\t\tif (\n\t\t\t\t\tawait fs.promises\n\t\t\t\t\t\t.stat(backupDir)\n\t\t\t\t\t\t.then((s) => s.isDirectory())\n\t\t\t\t\t\t.catch(() => false)\n\t\t\t\t) {\n\t\t\t\t\tawait fs.promises.rm(backupDir, { recursive: true, force: true })\n\t\t\t\t\tlogger.debug(`Cleaned up backup directory: ${backupDir}`)\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tlogger.error(`Error cleaning up backup files in ${backupDir}:`, error)\n\t\t\t}\n\t\t},\n\t\tlistFiles: async (dir: string) => listFilesGit(dir),\n\t\texclusiveWriter: false,\n\t}\n}\n\nfunction isNodeFSNotExistError(error: unknown): boolean {\n\treturn (\n\t\terror !== null &&\n\t\ttypeof error === 'object' &&\n\t\t'code' in error &&\n\t\t(error as { code: string }).code === 'ENOENT'\n\t)\n}\n\n/**\n * Lists files in a directory using git ls-files.\n * Exported for reuse by other filesystem implementations.\n */\nexport async function listFilesGit(dir: string): Promise<string[]> {\n\ttry {\n\t\tconst { stdout: trackedFiles } = await execFileAsync('git', ['ls-files'], {\n\t\t\tcwd: dir,\n\t\t})\n\n\t\tconst { stdout: untrackedFiles } = await execFileAsync(\n\t\t\t'git',\n\t\t\t['ls-files', '--others', '--exclude-standard'],\n\t\t\t{\n\t\t\t\tcwd: dir,\n\t\t\t},\n\t\t)\n\n\t\treturn [...trackedFiles.split('\\n'), ...untrackedFiles.split('\\n')].filter(Boolean)\n\t} catch {\n\t\treturn []\n\t}\n}\n"],"names":["BACKUP_DIR_NODE","join","homedir","execFileAsync","promisify","execFile","nodeFileSystem","threadID","backupDir","path","a","b","paths","signal","fs","error","isNodeFSNotExistError","FileNotExistError","content","backupFileName","fileChange","backupPath","s","logger","dir","listFilesGit","trackedFiles","untrackedFiles"],"mappings":";;;;;;;;AAGO,MAAMA,IAAkBC,EAAKC,KAAW,QAAQ,cAAc,GCO/DC,IAAgBC,EAAUC,CAAQ;AAEjC,SAASC,EAAeC,GAAgC;AAC9D,QAAMC,IAAYC,EAAK,KAAKT,GAAiBO,CAAQ;AAC9C,SAAA;AAAA,IACN,cAAc,CAACG,GAAWC,MAAcF,EAAK,SAASC,GAAGC,CAAC;AAAA,IAC1D,UAAU,IAAIC,MAAoBH,EAAK,KAAK,GAAGG,CAAK;AAAA,IAEpD,UAAU,OAAOH,GAAcI,MAAyB;AACnD,UAAA;AACI,eAAA,MAAMC,EAAG,SAAS,SAASL,GAAM,EAAE,UAAU,QAAQ,QAAAI,GAAQ;AAAA,eAC5DE,GAAO;AACX,cAAAC,EAAsBD,CAAK,IACxB,IAAIE,EAAkBR,CAAI,IAE3BM;AAAA,MAAA;AAAA,I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