@sourcegraph/amp 0.0.1749196899-g16ba82 → 0.0.1749225700-gc8788d
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 -3
- package/dist/{client-D1Pmx669.js → client-D0gbNDFf.js} +2 -2
- package/dist/{client-D1Pmx669.js.map → client-D0gbNDFf.js.map} +1 -1
- package/dist/{console-DZmALLuA.js → console-CDi5rFHv.js} +55 -44
- package/dist/console-CDi5rFHv.js.map +1 -0
- package/dist/{create_file.node-CygrebBY.js → create_file.node-DL2WuEa4.js} +2 -2
- package/dist/{create_file.node-CygrebBY.js.map → create_file.node-DL2WuEa4.js.map} +1 -1
- package/dist/{edit_file.node-D_cMkiLI.js → edit_file.node-SSEQ1h3o.js} +3 -3
- package/dist/{edit_file.node-D_cMkiLI.js.map → edit_file.node-SSEQ1h3o.js.map} +1 -1
- package/dist/{executable-C8qYZU1W.js → executable-CxioKGk7.js} +2 -2
- package/dist/{executable-C8qYZU1W.js.map → executable-CxioKGk7.js.map} +1 -1
- package/dist/{files--h2VjD8F.js → files-BQmddBey.js} +2 -2
- package/dist/{files--h2VjD8F.js.map → files-BQmddBey.js.map} +1 -1
- package/dist/fuzzy-server.js +116 -113
- package/dist/fuzzy-server.js.map +1 -1
- package/dist/{glob.node-AB34HaNl.js → glob.node-C8xrYICA.js} +4 -4
- package/dist/{glob.node-AB34HaNl.js.map → glob.node-C8xrYICA.js.map} +1 -1
- package/dist/{index-nQBDDlvh.js → index-BY5vhogw.js} +2 -2
- package/dist/{index-nQBDDlvh.js.map → index-BY5vhogw.js.map} +1 -1
- package/dist/{list_directory.node-DZamBwOx.js → list_directory.node-p_ArdqyT.js} +2 -2
- package/dist/{list_directory.node-DZamBwOx.js.map → list_directory.node-p_ArdqyT.js.map} +1 -1
- package/dist/{load-profile-DzDzDOIq.js → load-profile-DxrviVkC.js} +2 -2
- package/dist/{load-profile-DzDzDOIq.js.map → load-profile-DxrviVkC.js.map} +1 -1
- package/dist/{main-WXbdYG4Z.js → main-DIn8dJ9L.js} +409 -398
- package/dist/{main-WXbdYG4Z.js.map → main-DIn8dJ9L.js.map} +1 -1
- package/dist/{node-CBRPqFin.js → node-C9D1REPh.js} +374 -320
- package/dist/node-C9D1REPh.js.map +1 -0
- package/dist/{node-D2Ho0W-v.js → node-CHCdepF2.js} +3 -3
- package/dist/{node-D2Ho0W-v.js.map → node-CHCdepF2.js.map} +1 -1
- package/dist/{node-B9XNCq_w.js → node-CU0lZEVr.js} +2 -2
- package/dist/{node-B9XNCq_w.js.map → node-CU0lZEVr.js.map} +1 -1
- package/dist/{node-CUCcBUhU.js → node-CrPwEb6e.js} +4 -4
- package/dist/{node-CUCcBUhU.js.map → node-CrPwEb6e.js.map} +1 -1
- package/dist/{node-Cs3K2AKs.js → node-D-xGtMhE.js} +3 -3
- package/dist/{node-Cs3K2AKs.js.map → node-D-xGtMhE.js.map} +1 -1
- package/dist/{node-SvjAOtkw.js → node-DQLcKPbG.js} +2 -2
- package/dist/{node-SvjAOtkw.js.map → node-DQLcKPbG.js.map} +1 -1
- package/dist/{read_file.node-CveQp78z.js → read_file.node-DTbjOJwN.js} +2 -2
- package/dist/{read_file.node-CveQp78z.js.map → read_file.node-DTbjOJwN.js.map} +1 -1
- package/dist/{stdio-CRvROLK4.js → stdio-DuUbi3RX.js} +3 -3
- package/dist/{stdio-CRvROLK4.js.map → stdio-DuUbi3RX.js.map} +1 -1
- package/dist/storybook.js +1 -1
- package/dist/{undo_edit.node-C3I02TEE.js → undo_edit.node-qujh3sgI.js} +2 -2
- package/dist/{undo_edit.node-C3I02TEE.js.map → undo_edit.node-qujh3sgI.js.map} +1 -1
- package/package.json +1 -1
- package/dist/console-DZmALLuA.js.map +0 -1
- package/dist/node-CBRPqFin.js.map +0 -1
@@ -1,6 +1,6 @@
|
|
1
1
|
#!/usr/bin/env node
|
2
2
|
import u from "node:path";
|
3
|
-
import { p as d, aC as f, aD as l } from "./console-
|
3
|
+
import { p as d, aC as f, aD as l } from "./console-CDi5rFHv.js";
|
4
4
|
const w = ({ args: t }, { dir: a, dirs: n, trackFileChange: c, filesystem: o }) => d(async (e) => {
|
5
5
|
if (f(a), typeof t.content != "string")
|
6
6
|
throw new Error("create_file: content must be specified");
|
@@ -19,4 +19,4 @@ const w = ({ args: t }, { dir: a, dirs: n, trackFileChange: c, filesystem: o })
|
|
19
19
|
export {
|
20
20
|
w as nodeCreateFileTool
|
21
21
|
};
|
22
|
-
//# sourceMappingURL=create_file.node-
|
22
|
+
//# sourceMappingURL=create_file.node-DL2WuEa4.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"create_file.node-
|
1
|
+
{"version":3,"file":"create_file.node-DL2WuEa4.js","sources":["../../core/src/tools/builtin/filesystem/create_file.node.ts"],"sourcesContent":["import { promiseFactoryToObservable } from '@sourcegraph/observable'\nimport path from 'path'\nimport { checkDirURIIsFile } from '../node-helpers'\nimport type { createFileToolReg } from './create_file.common'\nimport { resolveArgumentPath } from './read_file.util'\n\nexport const nodeCreateFileTool: NonNullable<typeof createFileToolReg.fn> = (\n\t{ args },\n\t{ dir, dirs, trackFileChange, filesystem },\n) => {\n\treturn promiseFactoryToObservable(async (signal) => {\n\t\tcheckDirURIIsFile(dir)\n\t\tif (typeof args.content !== 'string') {\n\t\t\tthrow new Error('create_file: content must be specified')\n\t\t}\n\n\t\tsignal.throwIfAborted()\n\n\t\tconst fullPath = await resolveArgumentPath(filesystem, dirs, args.path, signal)\n\t\tconst dirname = path.dirname(fullPath)\n\t\tawait filesystem.mkdirp(dirname, signal)\n\n\t\tconst content = args.content\n\t\tawait trackFileChange(fullPath, async (path) => {\n\t\t\tawait filesystem.writeFile(path, content, signal)\n\t\t})\n\t\treturn {\n\t\t\tstatus: 'done',\n\t\t\tresult: `Successfully created file ${args.path}`,\n\t\t\tfiles: [args.path],\n\t\t}\n\t})\n}\n"],"names":["nodeCreateFileTool","args","dir","dirs","trackFileChange","filesystem","promiseFactoryToObservable","signal","checkDirURIIsFile","fullPath","resolveArgumentPath","dirname","path","content"],"mappings":";;;AAMa,MAAAA,IAA+D,CAC3E,EAAE,MAAAC,KACF,EAAE,KAAAC,GAAK,MAAAC,GAAM,iBAAAC,GAAiB,YAAAC,QAEvBC,EAA2B,OAAOC,MAAW;AAE/C,MADJC,EAAkBN,CAAG,GACjB,OAAOD,EAAK,WAAY;AACrB,UAAA,IAAI,MAAM,wCAAwC;AAGzD,EAAAM,EAAO,eAAe;AAEtB,QAAME,IAAW,MAAMC,EAAoBL,GAAYF,GAAMF,EAAK,MAAMM,CAAM,GACxEI,IAAUC,EAAK,QAAQH,CAAQ;AAC/B,QAAAJ,EAAW,OAAOM,GAASJ,CAAM;AAEvC,QAAMM,IAAUZ,EAAK;AACf,eAAAG,EAAgBK,GAAU,OAAOG,MAAS;AAC/C,UAAMP,EAAW,UAAUO,GAAMC,GAASN,CAAM;AAAA,EAAA,CAChD,GACM;AAAA,IACN,QAAQ;AAAA,IACR,QAAQ,6BAA6BN,EAAK,IAAI;AAAA,IAC9C,OAAO,CAACA,EAAK,IAAI;AAAA,EAClB;AAAA,CACA;"}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
#!/usr/bin/env node
|
2
|
-
import { p, aC as m, aD as F, aE as v, aF as _, aG as b } from "./console-
|
3
|
-
import { recordEdit as x } from "./undo_edit.node-
|
2
|
+
import { p, aC as m, aD as F, aE as v, aF as _, aG as b } from "./console-CDi5rFHv.js";
|
3
|
+
import { recordEdit as x } from "./undo_edit.node-qujh3sgI.js";
|
4
4
|
class E {
|
5
5
|
#e = !1;
|
6
6
|
#t = [];
|
@@ -65,4 +65,4 @@ function y(e) {
|
|
65
65
|
export {
|
66
66
|
k as nodeEditFileTool
|
67
67
|
};
|
68
|
-
//# sourceMappingURL=edit_file.node-
|
68
|
+
//# sourceMappingURL=edit_file.node-SSEQ1h3o.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"edit_file.node-
|
1
|
+
{"version":3,"file":"edit_file.node-SSEQ1h3o.js","sources":["../../core/src/utils/async_mutex.ts","../../core/src/tools/builtin/filesystem/edit_file.node.ts"],"sourcesContent":["export class AsyncMutex {\n\t#locked = false\n\t#queue: (() => void)[] = []\n\n\t/**\n\t * Acquires the lock. If the lock is already held, waits until it is released.\n\t * @returns A promise that resolves when the lock is acquired.\n\t */\n\tasync acquire(): Promise<void> {\n\t\treturn new Promise<void>((resolve) => {\n\t\t\tif (!this.#locked) {\n\t\t\t\t// Lock is free, acquire it immediately\n\t\t\t\tthis.#locked = true\n\t\t\t\tresolve()\n\t\t\t} else {\n\t\t\t\t// Lock is held, add the resolver to the queue\n\t\t\t\tthis.#queue.push(resolve)\n\t\t\t}\n\t\t})\n\t}\n\n\t/**\n\t * Releases the lock. If there are waiters in the queue, the next one acquires the lock.\n\t * Otherwise, the lock becomes free.\n\t */\n\trelease(): void {\n\t\tif (this.#queue.length > 0) {\n\t\t\t// Pass the lock to the next waiter without setting #locked to false\n\t\t\tconst nextResolve = this.#queue.shift()\n\t\t\t// The next waiter's promise resolves, and *they* now hold the lock.\n\t\t\t// #locked remains true.\n\t\t\tnextResolve?.()\n\t\t} else {\n\t\t\t// No waiters, release the lock\n\t\t\tthis.#locked = false\n\t\t}\n\t}\n}\n","import { promiseFactoryToObservable } from '@sourcegraph/observable'\nimport { getFileModTime } from '../../../threads/file-tracking/common'\nimport { AsyncMutex } from '../../../utils/async_mutex'\nimport { checkDirURIIsFile } from '../node-helpers'\nimport type { EditFileToolDef, editFileToolReg } from './edit_file.common'\nimport { applyFileEdits, editFileArgsSchema } from './edit_file.common'\nimport { resolveArgumentPath } from './read_file.util'\nimport { recordEdit } from './undo_edit.node'\n\nconst runningMutex = new AsyncMutex()\n\nexport const nodeEditFileTool: NonNullable<(typeof editFileToolReg)['fn']> = (\n\t{ args },\n\t{ dir, dirs, threadID, trackFileChange, filesystem },\n) => {\n\treturn promiseFactoryToObservable(async (signal) => {\n\t\tawait runningMutex.acquire()\n\t\ttry {\n\t\t\tcheckEditArgs(args)\n\n\t\t\tcheckDirURIIsFile(dir)\n\n\t\t\tconst filePath = await resolveArgumentPath(filesystem, dirs, args.path, signal)\n\n\t\t\tif (!filesystem.exclusiveWriter) {\n\t\t\t\tconst lastReadTime = getFileModTime(filePath, threadID)\n\t\t\t\tconst currentMtime = await filesystem.getMtime(filePath)\n\t\t\t\tif (lastReadTime && currentMtime && lastReadTime !== currentMtime) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tstatus: 'error' as const,\n\t\t\t\t\t\tprogress: {},\n\t\t\t\t\t\terror: {\n\t\t\t\t\t\t\tmessage: `The file '${args.path}' has been modified since you last read it. Please use read_file to view the current version before making edits.`,\n\t\t\t\t\t\t},\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst content = await filesystem.readFile(filePath, signal)\n\t\t\tconst { modifiedContent, formattedDiff, lineRange } = await applyFileEdits(\n\t\t\t\targs.path,\n\t\t\t\tcontent,\n\t\t\t\targs.old_str,\n\t\t\t\targs.new_str,\n\t\t\t)\n\n\t\t\tawait recordEdit(args.path, content, modifiedContent)\n\n\t\t\tawait trackFileChange(filePath, async (path) => {\n\t\t\t\tawait filesystem.writeFile(path, modifiedContent, signal)\n\t\t\t})\n\n\t\t\tconst result = {\n\t\t\t\tdiff: formattedDiff,\n\t\t\t\tlineRange,\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tstatus: 'done',\n\t\t\t\tprogress: {},\n\t\t\t\tresult,\n\t\t\t\tfiles: [args.path],\n\t\t\t}\n\t\t} finally {\n\t\t\trunningMutex.release()\n\t\t}\n\t})\n}\n\nfunction checkEditArgs(args: EditFileToolDef['args']): asserts args is EditFileToolDef['args'] {\n\targs = editFileArgsSchema.parse(args)\n\tif (args.old_str === args.new_str) {\n\t\tthrow new Error('old_str and new_str must be different from each other.')\n\t}\n}\n"],"names":["AsyncMutex","#locked","#queue","resolve","runningMutex","nodeEditFileTool","args","dir","dirs","threadID","trackFileChange","filesystem","promiseFactoryToObservable","signal","checkEditArgs","checkDirURIIsFile","filePath","resolveArgumentPath","lastReadTime","getFileModTime","currentMtime","content","modifiedContent","formattedDiff","lineRange","applyFileEdits","recordEdit","path","editFileArgsSchema"],"mappings":";;;AAAO,MAAMA,EAAW;AAAA,EACvBC,KAAU;AAAA,EACVC,KAAyB,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA,EAM1B,MAAM,UAAyB;AACvB,WAAA,IAAI,QAAc,CAACC,MAAY;AACjC,MAAC,KAAKF,KAMJ,KAAAC,GAAO,KAAKC,CAAO,KAJxB,KAAKF,KAAU,IACPE,EAAA;AAAA,IAIT,CACA;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOF,UAAgB;AACX,IAAA,KAAKD,GAAO,SAAS,IAEJ,KAAKA,GAAO,MAAM,IAGxB,IAGd,KAAKD,KAAU;AAAA,EAChB;AAEF;AC5BA,MAAMG,IAAe,IAAIJ,EAAW,GAEvBK,IAAgE,CAC5E,EAAE,MAAAC,EAAK,GACP,EAAE,KAAAC,GAAK,MAAAC,GAAM,UAAAC,GAAU,iBAAAC,GAAiB,YAAAC,QAEjCC,EAA2B,OAAOC,MAAW;AACnD,QAAMT,EAAa,QAAQ;AACvB,MAAA;AACH,IAAAU,EAAcR,CAAI,GAElBS,EAAkBR,CAAG;AAErB,UAAMS,IAAW,MAAMC,EAAoBN,GAAYH,GAAMF,EAAK,MAAMO,CAAM;AAE1E,QAAA,CAACF,EAAW,iBAAiB;AAC1B,YAAAO,IAAeC,EAAeH,GAAUP,CAAQ,GAChDW,IAAe,MAAMT,EAAW,SAASK,CAAQ;AACnD,UAAAE,KAAgBE,KAAgBF,MAAiBE;AAC7C,eAAA;AAAA,UACN,QAAQ;AAAA,UACR,UAAU,CAAC;AAAA,UACX,OAAO;AAAA,YACN,SAAS,aAAad,EAAK,IAAI;AAAA,UAAA;AAAA,QAEjC;AAAA,IACD;AAGD,UAAMe,IAAU,MAAMV,EAAW,SAASK,GAAUH,CAAM,GACpD,EAAE,iBAAAS,GAAiB,eAAAC,GAAe,WAAAC,EAAA,IAAc,MAAMC;AAAA,MAC3DnB,EAAK;AAAA,MACLe;AAAA,MACAf,EAAK;AAAA,MACLA,EAAK;AAAA,IACN;AAEA,iBAAMoB,EAAWpB,EAAK,MAAMe,GAASC,CAAe,GAE9C,MAAAZ,EAAgBM,GAAU,OAAOW,MAAS;AAC/C,YAAMhB,EAAW,UAAUgB,GAAML,GAAiBT,CAAM;AAAA,IAAA,CACxD,GAOM;AAAA,MACN,QAAQ;AAAA,MACR,UAAU,CAAC;AAAA,MACX,QARc;AAAA,QACd,MAAMU;AAAA,QACN,WAAAC;AAAA,MACD;AAAA,MAMC,OAAO,CAAClB,EAAK,IAAI;AAAA,IAClB;AAAA,EAAA,UACC;AACD,IAAAF,EAAa,QAAQ;AAAA,EAAA;AACtB,CACA;AAGF,SAASU,EAAcR,GAAwE;AAE1F,MADGA,IAAAsB,EAAmB,MAAMtB,CAAI,GAChCA,EAAK,YAAYA,EAAK;AACnB,UAAA,IAAI,MAAM,wDAAwD;AAE1E;"}
|
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env node
|
2
2
|
import { existsSync as o } from "node:fs";
|
3
3
|
import { createRequire as t } from "node:module";
|
4
|
-
import { C as i } from "./console-
|
4
|
+
import { C as i } from "./console-CDi5rFHv.js";
|
5
5
|
function u() {
|
6
6
|
{
|
7
7
|
if (process.env.AMP_RIPGREP_PATH)
|
@@ -19,4 +19,4 @@ function u() {
|
|
19
19
|
export {
|
20
20
|
u as r
|
21
21
|
};
|
22
|
-
//# sourceMappingURL=executable-
|
22
|
+
//# sourceMappingURL=executable-CxioKGk7.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"executable-
|
1
|
+
{"version":3,"file":"executable-CxioKGk7.js","sources":["../../core/src/tools/builtin/grep/executable.ts"],"sourcesContent":["import { existsSync } from 'node:fs'\nimport { createRequire } from 'node:module'\nimport { homedir } from 'node:os'\nimport { join } from 'node:path'\nimport logger from '../../../common/logger'\n\nexport function ripgrepExecutable(): string {\n\tif (import.meta.env.VITE_PLATFORM === 'vscode') {\n\t\tconst possiblePaths = getVSCodeRipgrepPaths()\n\n\t\tfor (const path of possiblePaths) {\n\t\t\tif (existsSync(path)) {\n\t\t\t\treturn path\n\t\t\t}\n\t\t}\n\t} else if (import.meta.env.VITE_PLATFORM === 'node') {\n\t\tif (process.env.AMP_RIPGREP_PATH) {\n\t\t\treturn process.env.AMP_RIPGREP_PATH\n\t\t}\n\t\ttry {\n\t\t\t// Create a require function that can be used in ESM context\n\t\t\tconst require = createRequire(import.meta.url)\n\n\t\t\t// Use the created require function to load @vscode/ripgrep\n\t\t\tconst ripgrepModule = require('@vscode/ripgrep') as { rgPath: string }\n\t\t\tconst rgPath = ripgrepModule?.rgPath\n\n\t\t\tif (rgPath && existsSync(rgPath)) {\n\t\t\t\treturn rgPath\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tlogger.error('Error with ripgrep:', error)\n\t\t}\n\t}\n\n\treturn 'rg'\n}\n\nfunction getVSCodeRipgrepPaths(): string[] {\n\tconst platform = process.platform\n\tconst paths: string[] = []\n\n\ttry {\n\t\t// eslint-disable-next-line @typescript-eslint/no-require-imports\n\t\tconst vscode = require('vscode') as typeof import('vscode')\n\t\tconst binaryName = platform === 'win32' ? 'rg.exe' : 'rg'\n\t\tpaths.push(\n\t\t\tjoin(vscode.env.appRoot, 'node_modules', '@vscode', 'ripgrep', 'bin', binaryName),\n\t\t)\n\t} catch {\n\t\t// ignore\n\t}\n\n\t// This if statement should no longer be needed since vscode.env.appRoot\n\t// already handles it. However, keeping it here as a fallback just to be\n\t// sure we don't regress anything after adding appRoot support.\n\tif (platform === 'darwin') {\n\t\tpaths.push(\n\t\t\t'/Applications/Visual Studio Code.app/Contents/Resources/app/node_modules/@vscode/ripgrep/bin/rg',\n\t\t)\n\t} else if (platform === 'linux') {\n\t\tpaths.push(\n\t\t\t'/usr/share/code/resources/app/node_modules/@vscode/ripgrep/bin/rg',\n\t\t\tjoin(homedir(), '.vscode/extensions/ms-vscode.vscode-ripgrep-*/bin/rg'),\n\t\t)\n\t}\n\n\treturn paths\n}\n"],"names":["ripgrepExecutable","rgPath","createRequire","existsSync","error","logger"],"mappings":";;;;AAMO,SAASA,IAA4B;AASU;AAChD,QAAA,QAAQ,IAAI;AACf,aAAO,QAAQ,IAAI;AAEhB,QAAA;AAMH,YAAMC,IAJUC,EAAc,YAAY,GAAG,EAGf,iBAAiB,GACjB;AAE1B,UAAAD,KAAUE,EAAWF,CAAM;AACvB,eAAAA;AAAA,aAEAG,GAAO;AACR,MAAAC,EAAA,MAAM,uBAAuBD,CAAK;AAAA,IAAA;AAAA,EAC1C;AAGM,SAAA;AACR;"}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
#!/usr/bin/env node
|
2
2
|
import y from "node:path";
|
3
|
-
import { b8 as I, b9 as T, C as z, ba as B, bb as C } from "./console-
|
3
|
+
import { b8 as I, b9 as T, C as z, ba as B, bb as C } from "./console-CDi5rFHv.js";
|
4
4
|
async function L(p, h, t) {
|
5
5
|
const b = await t.listFiles(h), i = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map(), f = [], M = /\b([\w/_-]+(?:\\.|[\w/_-])*(?:\.[\w-]+)+)\b/g, F = /(\/(?:[\w-]+\/|[\w-]+\\[.\s\S])+[\w.-]+(?:\\.|[\w.-])*(?:\.[\w-]+)+)\b/g, x = /\b([A-Za-z]:[\\\\][^\s"'<>|]*(?:\.[\w-]+)+)\b/g;
|
6
6
|
await l(M, !1), await l(F, !0), await l(x, !0);
|
@@ -67,4 +67,4 @@ async function L(p, h, t) {
|
|
67
67
|
export {
|
68
68
|
L as getFileMentions
|
69
69
|
};
|
70
|
-
//# sourceMappingURL=files
|
70
|
+
//# sourceMappingURL=files-BQmddBey.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"files
|
1
|
+
{"version":3,"file":"files-BQmddBey.js","sources":["../../core/src/threads/files.ts"],"sourcesContent":["import path from 'node:path'\nimport logger from '../common/logger'\nimport type { FileSystem } from '../platform/fs/fs'\nimport { getImageFileMetadata } from '../tools/builtin/filesystem/file-type'\nimport { checkFileSizeLimit } from '../tools/builtin/filesystem/read_file.util'\nimport type { FileMention } from './file-mentions'\nimport { FileMentions } from './file-mentions'\nimport { isSupportedImageMIMEType } from './image-attachments'\n\nexport async function getFileMentions(\n\tcontent: string,\n\tworkspaceRoot: string,\n\tfilesystem: Pick<FileSystem, 'stat' | 'readFile' | 'readBinaryFile' | 'listFiles'>,\n): Promise<FileMentions> {\n\tconst files = await filesystem.listFiles(workspaceRoot)\n\tconst fileContents = new Map<string, string>()\n\tconst imageFiles = new Map<string, { mimeType: string; size: number }>() // Track image files separately\n\tconst mentions: FileMention[] = []\n\n\t// Regex patterns for file paths\n\t// Match relative paths with extension within workspace\n\tconst relativePathRegex = /\\b([\\w/_-]+(?:\\\\.|[\\w/_-])*(?:\\.[\\w-]+)+)\\b/g\n\t// Match absolute paths with extension (Unix/Linux/Mac)\n\tconst unixAbsolutePathRegex =\n\t\t/(\\/(?:[\\w-]+\\/|[\\w-]+\\\\[.\\s\\S])+[\\w.-]+(?:\\\\.|[\\w.-])*(?:\\.[\\w-]+)+)\\b/g\n\t// Match absolute paths with extension (Windows) - using a more permissive approach\n\tconst windowsAbsolutePathRegex = /\\b([A-Za-z]:[\\\\\\\\][^\\s\"'<>|]*(?:\\.[\\w-]+)+)\\b/g\n\n\t// Process matches for each regex pattern\n\tawait processMatches(relativePathRegex, false)\n\tawait processMatches(unixAbsolutePathRegex, true)\n\n\tawait processMatches(windowsAbsolutePathRegex, true)\n\n\t// Process matches from a regex pattern\n\tasync function processMatches(regex: RegExp, isAbsolutePath: boolean) {\n\t\t// Reset regex before execution to ensure we don't miss any matches\n\t\tregex.lastIndex = 0\n\n\t\tlet match\n\t\twhile ((match = regex.exec(content)) !== null) {\n\t\t\tconst [word] = match\n\t\t\t// Unescape special characters in the path\n\t\t\t// Unescape characters in file paths\n\t\t\tlet unescapedWord\n\t\t\t// Check if this is a Windows path with drive letter\n\t\t\tconst isWindowsPath = word.match(/^[A-Za-z]:[\\\\]/) !== null\n\t\t\tif (isWindowsPath) {\n\t\t\t\t// For Windows paths, preserve the backslashes as path separators but handle escaped characters\n\t\t\t\tunescapedWord = word\n\t\t\t} else {\n\t\t\t\t// For other paths, unescape everything\n\t\t\t\tunescapedWord = word.replace(/\\\\(.)/g, '$1')\n\t\t\t}\n\n\t\t\tconst isCached = fileContents.has(unescapedWord) || imageFiles.has(unescapedWord)\n\n\t\t\t// Skip if we've already processed this file path\n\t\t\tif (isCached) {\n\t\t\t\taddMention(unescapedWord, match.index)\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\t// Determine file path\n\t\t\tconst filePath = isAbsolutePath\n\t\t\t\t? unescapedWord\n\t\t\t\t: path.join(workspaceRoot, unescapedWord)\n\n\t\t\t// For relative paths, check if file exists in the workspace\n\t\t\tif (!isAbsolutePath && !files.includes(unescapedWord)) {\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\t// For absolute paths, check if file exists on disk\n\t\t\tif (isAbsolutePath) {\n\t\t\t\ttry {\n\t\t\t\t\t// Just try to stat the file to see if it exists\n\t\t\t\t\tawait filesystem.stat(filePath)\n\t\t\t\t} catch (err) {\n\t\t\t\t\t// File doesn't exist or can't be accessed\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Process the file\n\t\t\ttry {\n\t\t\t\t// Check if this is an image file\n\t\t\t\tconst imageInfo = await getImageFileMetadata(filesystem, filePath)\n\n\t\t\t\tif (imageInfo && isSupportedImageMIMEType(imageInfo.mimeType)) {\n\t\t\t\t\t// This is an image file, treat it as an attachment\n\t\t\t\t\timageFiles.set(unescapedWord, imageInfo)\n\t\t\t\t\t// Read the image file as binary and convert to base64\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst imageBuffer = await filesystem.readBinaryFile(filePath)\n\t\t\t\t\t\tconst base64Data = imageBuffer.toString('base64')\n\t\t\t\t\t\t// Store the base64 data\n\t\t\t\t\t\tfileContents.set(unescapedWord, base64Data)\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tlogger.error(\n\t\t\t\t\t\t\t'Failed to read image as binary',\n\t\t\t\t\t\t\t{ path: unescapedWord },\n\t\t\t\t\t\t\terror,\n\t\t\t\t\t\t)\n\t\t\t\t\t\t// Set a placeholder in case of error\n\t\t\t\t\t\tfileContents.set(\n\t\t\t\t\t\t\tunescapedWord,\n\t\t\t\t\t\t\t`[Image file: ${unescapedWord} (${imageInfo.mimeType}, ${Math.round(imageInfo.size / 1024)} KB)]`,\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t\taddMention(unescapedWord, match.index)\n\t\t\t\t} else {\n\t\t\t\t\t// Not an image file, handle normally\n\t\t\t\t\tconst isTooLarge = await checkFileSizeLimit(filesystem, filePath)\n\t\t\t\t\tif (isTooLarge) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\n\t\t\t\t\tconst data = await filesystem.readFile(filePath)\n\t\t\t\t\tfileContents.set(unescapedWord, data)\n\t\t\t\t\taddMention(unescapedWord, match.index)\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\t// Skip file if there's any error reading it\n\t\t\t\tcontinue\n\t\t\t}\n\t\t}\n\t}\n\n\t// Helper function to add a mention\n\tfunction addMention(path: string, startIndex: number) {\n\t\tmentions.push({\n\t\t\tpath,\n\t\t\trange: {\n\t\t\t\tstart: startIndex,\n\t\t\t\tend: startIndex + path.length - 1,\n\t\t\t},\n\t\t})\n\t}\n\n\t// Create a FileMentions instance with both text and image file contents\n\tconst fileMentions = new FileMentions(fileContents, mentions)\n\n\t// Add image file metadata to the FileMentions instance\n\tfileMentions.imageFiles = imageFiles\n\n\treturn fileMentions\n}\n"],"names":["getFileMentions","content","workspaceRoot","filesystem","files","fileContents","imageFiles","mentions","relativePathRegex","unixAbsolutePathRegex","windowsAbsolutePathRegex","processMatches","regex","isAbsolutePath","match","word","unescapedWord","addMention","filePath","path","imageInfo","getImageFileMetadata","isSupportedImageMIMEType","base64Data","error","logger","checkFileSizeLimit","data","startIndex","fileMentions","FileMentions"],"mappings":";;;AASsB,eAAAA,EACrBC,GACAC,GACAC,GACwB;AACxB,QAAMC,IAAQ,MAAMD,EAAW,UAAUD,CAAa,GAChDG,wBAAmB,IAAoB,GACvCC,wBAAiB,IAAgD,GACjEC,IAA0B,CAAC,GAI3BC,IAAoB,gDAEpBC,IACL,2EAEKC,IAA2B;AAG3B,QAAAC,EAAeH,GAAmB,EAAK,GACvC,MAAAG,EAAeF,GAAuB,EAAI,GAE1C,MAAAE,EAAeD,GAA0B,EAAI;AAGpC,iBAAAC,EAAeC,GAAeC,GAAyB;AAErE,IAAAD,EAAM,YAAY;AAEd,QAAAE;AACJ,YAAQA,IAAQF,EAAM,KAAKX,CAAO,OAAO,QAAM;AACxC,YAAA,CAACc,CAAI,IAAID;AAGX,UAAAE;AAcJ,UAZsBD,EAAK,MAAM,gBAAgB,MAAM,OAGtCC,IAAAD,IAGAC,IAAAD,EAAK,QAAQ,UAAU,IAAI,GAG3BV,EAAa,IAAIW,CAAa,KAAKV,EAAW,IAAIU,CAAa,GAGlE;AACF,QAAAC,EAAAD,GAAeF,EAAM,KAAK;AACrC;AAAA,MAAA;AAID,YAAMI,IAAWL,IACdG,IACAG,EAAK,KAAKjB,GAAec,CAAa;AAGzC,UAAI,GAACH,KAAkB,CAACT,EAAM,SAASY,CAAa,IAKpD;AAAA,YAAIH;AACC,cAAA;AAEG,kBAAAV,EAAW,KAAKe,CAAQ;AAAA,kBACjB;AAEb;AAAA,UAAA;AAKE,YAAA;AAEH,gBAAME,IAAY,MAAMC,EAAqBlB,GAAYe,CAAQ;AAEjE,cAAIE,KAAaE,EAAyBF,EAAU,QAAQ,GAAG;AAEnD,YAAAd,EAAA,IAAIU,GAAeI,CAAS;AAEnC,gBAAA;AAEG,oBAAAG,KADc,MAAMpB,EAAW,eAAee,CAAQ,GAC7B,SAAS,QAAQ;AAEnC,cAAAb,EAAA,IAAIW,GAAeO,CAAU;AAAA,qBAClCC,GAAO;AACR,cAAAC,EAAA;AAAA,gBACN;AAAA,gBACA,EAAE,MAAMT,EAAc;AAAA,gBACtBQ;AAAA,cACD,GAEanB,EAAA;AAAA,gBACZW;AAAA,gBACA,gBAAgBA,CAAa,KAAKI,EAAU,QAAQ,KAAK,KAAK,MAAMA,EAAU,OAAO,IAAI,CAAC;AAAA,cAC3F;AAAA,YAAA;AAEU,YAAAH,EAAAD,GAAeF,EAAM,KAAK;AAAA,UAAA,OAC/B;AAGN,gBADmB,MAAMY,EAAmBvB,GAAYe,CAAQ;AAE/D;AAGD,kBAAMS,IAAO,MAAMxB,EAAW,SAASe,CAAQ;AAClC,YAAAb,EAAA,IAAIW,GAAeW,CAAI,GACzBV,EAAAD,GAAeF,EAAM,KAAK;AAAA,UAAA;AAAA,gBAEvB;AAEf;AAAA,QAAA;AAAA;AAAA,IACD;AAAA,EACD;AAIQ,WAAAG,EAAWE,GAAcS,GAAoB;AACrD,IAAArB,EAAS,KAAK;AAAA,MACb,MAAAY;AAAAA,MACA,OAAO;AAAA,QACN,OAAOS;AAAA,QACP,KAAKA,IAAaT,EAAK,SAAS;AAAA,MAAA;AAAA,IACjC,CACA;AAAA,EAAA;AAIF,QAAMU,IAAe,IAAIC,EAAazB,GAAcE,CAAQ;AAG5D,SAAAsB,EAAa,aAAavB,GAEnBuB;AACR;"}
|