@sourcegraph/amp 0.0.1749211345-g16cdfc → 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-Dd8T5Ydk.js → client-D0gbNDFf.js} +2 -2
- package/dist/{client-Dd8T5Ydk.js.map → client-D0gbNDFf.js.map} +1 -1
- package/dist/{console-D_ZxbRrA.js → console-CDi5rFHv.js} +55 -44
- package/dist/console-CDi5rFHv.js.map +1 -0
- package/dist/{create_file.node-D_xwgdhJ.js → create_file.node-DL2WuEa4.js} +2 -2
- package/dist/{create_file.node-D_xwgdhJ.js.map → create_file.node-DL2WuEa4.js.map} +1 -1
- package/dist/{edit_file.node-Cv9nC-uR.js → edit_file.node-SSEQ1h3o.js} +3 -3
- package/dist/{edit_file.node-Cv9nC-uR.js.map → edit_file.node-SSEQ1h3o.js.map} +1 -1
- package/dist/{executable-BTpHtmPV.js → executable-CxioKGk7.js} +2 -2
- package/dist/{executable-BTpHtmPV.js.map → executable-CxioKGk7.js.map} +1 -1
- package/dist/{files-CNmw2a6V.js → files-BQmddBey.js} +2 -2
- package/dist/{files-CNmw2a6V.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-Dbygwo7q.js → glob.node-C8xrYICA.js} +4 -4
- package/dist/{glob.node-Dbygwo7q.js.map → glob.node-C8xrYICA.js.map} +1 -1
- package/dist/{index-DGuVA6oK.js → index-BY5vhogw.js} +2 -2
- package/dist/{index-DGuVA6oK.js.map → index-BY5vhogw.js.map} +1 -1
- package/dist/{list_directory.node-DJCJkqLg.js → list_directory.node-p_ArdqyT.js} +2 -2
- package/dist/{list_directory.node-DJCJkqLg.js.map → list_directory.node-p_ArdqyT.js.map} +1 -1
- package/dist/{load-profile-CXHBU_AI.js → load-profile-DxrviVkC.js} +2 -2
- package/dist/{load-profile-CXHBU_AI.js.map → load-profile-DxrviVkC.js.map} +1 -1
- package/dist/{main-CtHA5Ylu.js → main-DIn8dJ9L.js} +16 -16
- package/dist/{main-CtHA5Ylu.js.map → main-DIn8dJ9L.js.map} +1 -1
- package/dist/{node-BOIz1I5S.js → node-C9D1REPh.js} +3 -3
- package/dist/{node-BOIz1I5S.js.map → node-C9D1REPh.js.map} +1 -1
- package/dist/{node-DaL4eJRQ.js → node-CHCdepF2.js} +3 -3
- package/dist/{node-DaL4eJRQ.js.map → node-CHCdepF2.js.map} +1 -1
- package/dist/{node-DPPbAAw0.js → node-CU0lZEVr.js} +2 -2
- package/dist/{node-DPPbAAw0.js.map → node-CU0lZEVr.js.map} +1 -1
- package/dist/{node-D9dPV0eu.js → node-CrPwEb6e.js} +4 -4
- package/dist/{node-D9dPV0eu.js.map → node-CrPwEb6e.js.map} +1 -1
- package/dist/{node-C2cKbj9k.js → node-D-xGtMhE.js} +3 -3
- package/dist/{node-C2cKbj9k.js.map → node-D-xGtMhE.js.map} +1 -1
- package/dist/{node-DZCyuAqY.js → node-DQLcKPbG.js} +2 -2
- package/dist/{node-DZCyuAqY.js.map → node-DQLcKPbG.js.map} +1 -1
- package/dist/{read_file.node-CAD-I3qI.js → read_file.node-DTbjOJwN.js} +2 -2
- package/dist/{read_file.node-CAD-I3qI.js.map → read_file.node-DTbjOJwN.js.map} +1 -1
- package/dist/{stdio-7mSc8Mj0.js → stdio-DuUbi3RX.js} +3 -3
- package/dist/{stdio-7mSc8Mj0.js.map → stdio-DuUbi3RX.js.map} +1 -1
- package/dist/storybook.js +1 -1
- package/dist/{undo_edit.node-BYH1ok_y.js → undo_edit.node-qujh3sgI.js} +2 -2
- package/dist/{undo_edit.node-BYH1ok_y.js.map → undo_edit.node-qujh3sgI.js.map} +1 -1
- package/package.json +1 -1
- package/dist/console-D_ZxbRrA.js.map +0 -1
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"undo_edit.node-BYH1ok_y.js","sources":["../../core/src/tools/builtin/filesystem/undo_edit.util.ts","../../core/src/tools/builtin/filesystem/undo_edit.node.ts"],"sourcesContent":["import type { UndoEditToolDef } from './undo_edit.common'\nimport logger from '../../../common/logger'\n\nexport abstract class EditHistoryManager<HistoryID> {\n\tprotected abstract storeEdit(\n\t\tfilePath: string,\n\t\toldContent: string,\n\t\tnewContent: string,\n\t): Promise<HistoryID>\n\tprotected abstract fetchEdit(\n\t\tfilePath: string,\n\t): Promise<{ id: HistoryID; oldContent: string; newContent: string } | undefined>\n\tprotected abstract deleteEdit(id: HistoryID): Promise<void>\n\n\tprivate readonly MAX_TRACKED_EDITS = 50\n\tprivate readonly editQueue: HistoryID[] = []\n\n\tpublic async recordEdit(\n\t\tfilePath: string,\n\t\toldContent: string,\n\t\tnewContent: string,\n\t): Promise<void> {\n\t\ttry {\n\t\t\tconst editKey = await this.storeEdit(filePath, oldContent, newContent)\n\n\t\t\t// Update the FIFO queue\n\t\t\t// Remove if already in queue (to add it to the end)\n\t\t\tconst existingIndex = this.editQueue.indexOf(editKey)\n\t\t\tif (existingIndex >= 0) {\n\t\t\t\tthis.editQueue.splice(existingIndex, 1)\n\t\t\t}\n\n\t\t\t// Add to end of queue (most recent)\n\t\t\tthis.editQueue.push(editKey)\n\n\t\t\t// If we exceed the limit, remove the oldest edit\n\t\t\tif (this.editQueue.length > this.MAX_TRACKED_EDITS) {\n\t\t\t\tconst oldestKey = this.editQueue.shift()\n\t\t\t\tif (oldestKey) {\n\t\t\t\t\tthis.deleteEdit(oldestKey)\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tlogger.error('Failed to record edit:', error)\n\t\t}\n\t}\n\n\t// Function to get and remove the most recent edit for a file\n\tpublic async getLastEdit(\n\t\tfilePath: string,\n\t): Promise<{ oldContent: string; newContent: string } | undefined> {\n\t\ttry {\n\t\t\t// Get the edit data from memory\n\t\t\tconst editData = await this.fetchEdit(filePath)\n\t\t\tif (!editData) {\n\t\t\t\treturn undefined\n\t\t\t}\n\n\t\t\t// Remove from queue and map\n\t\t\tconst queueIndex = this.editQueue.indexOf(editData.id)\n\t\t\tif (queueIndex >= 0) {\n\t\t\t\tthis.editQueue.splice(queueIndex, 1)\n\t\t\t}\n\t\t\tthis.deleteEdit(editData.id)\n\n\t\t\treturn { oldContent: editData.oldContent, newContent: editData.newContent }\n\t\t} catch (error) {\n\t\t\tlogger.error('Failed to get last edit:', error)\n\t\t\treturn undefined\n\t\t}\n\t}\n}\n\nexport function checkUndoEditArgs(\n\targs: UndoEditToolDef['args'],\n): asserts args is UndoEditToolDef['args'] {\n\tif (typeof args !== 'object' || args === null) {\n\t\tthrow new Error('args must be an object. received instead: `' + JSON.stringify(args) + '`')\n\t}\n\tif (typeof args.path !== 'string') {\n\t\tthrow new Error(\n\t\t\t'path must be a string. received instead: `' + JSON.stringify(args.path) + '`',\n\t\t)\n\t}\n}\n","import { promiseFactoryToObservable } from '@sourcegraph/observable'\nimport crypto from 'node:crypto'\nimport fs, { writeFile } from 'node:fs/promises'\nimport os from 'node:os'\nimport path from 'path'\nimport logger from '../../../common/logger'\nimport { checkDirURIIsFile } from '../node-helpers'\nimport { createUnifiedDiff, formatDiffAsMarkdown } from './edit_file.common'\nimport type { undoEditToolReg } from './undo_edit.common'\nimport { EditHistoryManager, checkUndoEditArgs } from './undo_edit.util'\n\nexport const nodeUndoEditTool: NonNullable<(typeof undoEditToolReg)['fn']> = (\n\t{ args },\n\t{ dir, threadID, trackFileChange },\n) => {\n\treturn promiseFactoryToObservable(async (signal) => {\n\t\tcheckDirURIIsFile(dir)\n\t\tcheckUndoEditArgs(args)\n\n\t\tconst filePath = path.resolve(dir.fsPath, args.path)\n\n\t\t// Get the last edit from history (now async)\n\t\tconst lastEdit = await getLastEdit(args.path)\n\t\tif (!lastEdit) {\n\t\t\treturn {\n\t\t\t\tstatus: 'error' as const,\n\t\t\t\tprogress: {},\n\t\t\t\terror: {\n\t\t\t\t\tmessage: `No edit history found for file '${args.path}'.`,\n\t\t\t\t},\n\t\t\t}\n\t\t}\n\n\t\tconst diff = createUnifiedDiff(lastEdit.newContent, lastEdit.oldContent, args.path)\n\t\tconst formattedDiff = formatDiffAsMarkdown(diff)\n\n\t\tawait trackFileChange(filePath, async (path) => {\n\t\t\tawait writeFile(path, lastEdit.oldContent, {\n\t\t\t\tencoding: 'utf-8',\n\t\t\t\tsignal,\n\t\t\t})\n\t\t})\n\n\t\treturn { status: 'done', progress: {}, result: formattedDiff }\n\t})\n}\n\ntype HistoryID = string\n\nclass NodeEditHistoryManager extends EditHistoryManager<HistoryID> {\n\tasync storeEdit(filePath: string, oldContent: string, newContent: string): Promise<HistoryID> {\n\t\tconst hashedFilename = getHashedFilename(filePath)\n\t\tconst tempDir = await getTempDir()\n\t\tconst editFile = path.join(tempDir, hashedFilename)\n\n\t\tconst editData = { filePath, oldContent, newContent }\n\t\tawait fs.writeFile(editFile, JSON.stringify(editData), 'utf-8')\n\n\t\treturn hashedFilename as HistoryID\n\t}\n\tasync fetchEdit(\n\t\tfilePath: string,\n\t): Promise<{ id: HistoryID; oldContent: string; newContent: string } | undefined> {\n\t\tconst hashedFilename = getHashedFilename(filePath)\n\t\tconst tempDir = await getTempDir()\n\t\tconst editFile = path.join(tempDir, hashedFilename)\n\n\t\ttry {\n\t\t\tawait fs.access(editFile)\n\t\t} catch {\n\t\t\treturn undefined\n\t\t}\n\n\t\tconst editDataStr = await fs.readFile(editFile, 'utf-8')\n\t\tconst editData = JSON.parse(editDataStr) as {\n\t\t\tfilePath: string\n\t\t\toldContent: string\n\t\t\tnewContent: string\n\t\t}\n\t\treturn {\n\t\t\tid: hashedFilename,\n\t\t\toldContent: editData.oldContent,\n\t\t\tnewContent: editData.newContent,\n\t\t}\n\t}\n\tasync deleteEdit(id: HistoryID): Promise<void> {\n\t\tconst tempDir = await getTempDir()\n\t\tconst editFile = path.join(tempDir, id)\n\t\tawait fs.unlink(editFile).catch(() => {})\n\t}\n}\n\nconst nodeEditHistoryManager = new NodeEditHistoryManager()\n\nexport const recordEdit = nodeEditHistoryManager.recordEdit.bind(nodeEditHistoryManager)\nexport const getLastEdit = nodeEditHistoryManager.getLastEdit.bind(nodeEditHistoryManager)\n\nlet tempDir = ''\nlet tempDirPromise: Promise<string> | null = null\n\nasync function getTempDir(): Promise<string> {\n\tif (tempDir) return tempDir\n\tif (!tempDirPromise) {\n\t\ttempDirPromise = fs\n\t\t\t.mkdtemp(path.join(os.tmpdir(), 'amp-edits-'))\n\t\t\t.then((dir) => {\n\t\t\t\ttempDir = dir\n\t\t\t\treturn dir\n\t\t\t})\n\t\t\t.catch((error) => {\n\t\t\t\tlogger.error('Failed to create edit history directory:', error)\n\t\t\t\tthrow error\n\t\t\t})\n\t}\n\treturn tempDirPromise\n}\n\nfunction getHashedFilename(filePath: string): string {\n\tconst hash = crypto.createHash('sha256').update(filePath).digest('hex').slice(0, 16)\n\treturn `${hash}-${path.basename(filePath)}`\n}\n"],"names":["EditHistoryManager","filePath","oldContent","newContent","editKey","existingIndex","oldestKey","error","logger","editData","queueIndex","checkUndoEditArgs","args","nodeUndoEditTool","dir","threadID","trackFileChange","promiseFactoryToObservable","signal","checkDirURIIsFile","path","lastEdit","getLastEdit","diff","createUnifiedDiff","formattedDiff","formatDiffAsMarkdown","writeFile","NodeEditHistoryManager","hashedFilename","getHashedFilename","tempDir","getTempDir","editFile","fs","editDataStr","id","nodeEditHistoryManager","recordEdit","tempDirPromise","os","crypto"],"mappings":";;;;;;AAGO,MAAeA,EAA8B;AAAA,EAWlC,oBAAoB;AAAA,EACpB,YAAyB,CAAC;AAAA,EAE3C,MAAa,WACZC,GACAC,GACAC,GACgB;AACZ,QAAA;AACH,YAAMC,IAAU,MAAM,KAAK,UAAUH,GAAUC,GAAYC,CAAU,GAI/DE,IAAgB,KAAK,UAAU,QAAQD,CAAO;AASpD,UARIC,KAAiB,KACf,KAAA,UAAU,OAAOA,GAAe,CAAC,GAIlC,KAAA,UAAU,KAAKD,CAAO,GAGvB,KAAK,UAAU,SAAS,KAAK,m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,CAAQ,EAAE,MAAM,MAAM;AAAA,IAAA,CAAE;AAAA,EAAA;AAE1C;AAEA,MAAMI,IAAyB,IAAIT,EAAuB,GAE7CU,IAAaD,EAAuB,WAAW,KAAKA,CAAsB,GAC1Ef,IAAce,EAAuB,YAAY,KAAKA,CAAsB;AAEzF,IAAIN,IAAU,IACVQ,IAAyC;AAE7C,eAAeP,IAA8B;AAC5C,SAAID,MACCQ,MACJA,IAAiBL,EACf,QAAQd,EAAK,KAAKoB,EAAG,OAAA,GAAU,YAAY,CAAC,EAC5C,KAAK,CAAC1B,OACIiB,IAAAjB,GACHA,EACP,EACA,MAAM,CAACP,MAAU;AACV,UAAAC,EAAA,MAAM,4CAA4CD,CAAK,GACxDA;AAAA,EAAA,CACN,IAEIgC;AACR;AAEA,SAAST,EAAkB7B,GAA0B;AAEpD,SAAO,GADMwC,EAAO,WAAW,QAAQ,EAAE,OAAOxC,CAAQ,EAAE,OAAO,KAAK,EAAE,MAAM,GAAG,EAAE,CACrE,IAAImB,EAAK,SAASnB,CAAQ,CAAC;AAC1C;"}
|
1
|
+
{"version":3,"file":"undo_edit.node-qujh3sgI.js","sources":["../../core/src/tools/builtin/filesystem/undo_edit.util.ts","../../core/src/tools/builtin/filesystem/undo_edit.node.ts"],"sourcesContent":["import type { UndoEditToolDef } from './undo_edit.common'\nimport logger from '../../../common/logger'\n\nexport abstract class EditHistoryManager<HistoryID> {\n\tprotected abstract storeEdit(\n\t\tfilePath: string,\n\t\toldContent: string,\n\t\tnewContent: string,\n\t): Promise<HistoryID>\n\tprotected abstract fetchEdit(\n\t\tfilePath: string,\n\t): Promise<{ id: HistoryID; oldContent: string; newContent: string } | undefined>\n\tprotected abstract deleteEdit(id: HistoryID): Promise<void>\n\n\tprivate readonly MAX_TRACKED_EDITS = 50\n\tprivate readonly editQueue: HistoryID[] = []\n\n\tpublic async recordEdit(\n\t\tfilePath: string,\n\t\toldContent: string,\n\t\tnewContent: string,\n\t): Promise<void> {\n\t\ttry {\n\t\t\tconst editKey = await this.storeEdit(filePath, oldContent, newContent)\n\n\t\t\t// Update the FIFO queue\n\t\t\t// Remove if already in queue (to add it to the end)\n\t\t\tconst existingIndex = this.editQueue.indexOf(editKey)\n\t\t\tif (existingIndex >= 0) {\n\t\t\t\tthis.editQueue.splice(existingIndex, 1)\n\t\t\t}\n\n\t\t\t// Add to end of queue (most recent)\n\t\t\tthis.editQueue.push(editKey)\n\n\t\t\t// If we exceed the limit, remove the oldest edit\n\t\t\tif (this.editQueue.length > this.MAX_TRACKED_EDITS) {\n\t\t\t\tconst oldestKey = this.editQueue.shift()\n\t\t\t\tif (oldestKey) {\n\t\t\t\t\tthis.deleteEdit(oldestKey)\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tlogger.error('Failed to record edit:', error)\n\t\t}\n\t}\n\n\t// Function to get and remove the most recent edit for a file\n\tpublic async getLastEdit(\n\t\tfilePath: string,\n\t): Promise<{ oldContent: string; newContent: string } | undefined> {\n\t\ttry {\n\t\t\t// Get the edit data from memory\n\t\t\tconst editData = await this.fetchEdit(filePath)\n\t\t\tif (!editData) {\n\t\t\t\treturn undefined\n\t\t\t}\n\n\t\t\t// Remove from queue and map\n\t\t\tconst queueIndex = this.editQueue.indexOf(editData.id)\n\t\t\tif (queueIndex >= 0) {\n\t\t\t\tthis.editQueue.splice(queueIndex, 1)\n\t\t\t}\n\t\t\tthis.deleteEdit(editData.id)\n\n\t\t\treturn { oldContent: editData.oldContent, newContent: editData.newContent }\n\t\t} catch (error) {\n\t\t\tlogger.error('Failed to get last edit:', error)\n\t\t\treturn undefined\n\t\t}\n\t}\n}\n\nexport function checkUndoEditArgs(\n\targs: UndoEditToolDef['args'],\n): asserts args is UndoEditToolDef['args'] {\n\tif (typeof args !== 'object' || args === null) {\n\t\tthrow new Error('args must be an object. received instead: `' + JSON.stringify(args) + '`')\n\t}\n\tif (typeof args.path !== 'string') {\n\t\tthrow new Error(\n\t\t\t'path must be a string. received instead: `' + JSON.stringify(args.path) + '`',\n\t\t)\n\t}\n}\n","import { promiseFactoryToObservable } from '@sourcegraph/observable'\nimport crypto from 'node:crypto'\nimport fs, { writeFile } from 'node:fs/promises'\nimport os from 'node:os'\nimport path from 'path'\nimport logger from '../../../common/logger'\nimport { checkDirURIIsFile } from '../node-helpers'\nimport { createUnifiedDiff, formatDiffAsMarkdown } from './edit_file.common'\nimport type { undoEditToolReg } from './undo_edit.common'\nimport { EditHistoryManager, checkUndoEditArgs } from './undo_edit.util'\n\nexport const nodeUndoEditTool: NonNullable<(typeof undoEditToolReg)['fn']> = (\n\t{ args },\n\t{ dir, threadID, trackFileChange },\n) => {\n\treturn promiseFactoryToObservable(async (signal) => {\n\t\tcheckDirURIIsFile(dir)\n\t\tcheckUndoEditArgs(args)\n\n\t\tconst filePath = path.resolve(dir.fsPath, args.path)\n\n\t\t// Get the last edit from history (now async)\n\t\tconst lastEdit = await getLastEdit(args.path)\n\t\tif (!lastEdit) {\n\t\t\treturn {\n\t\t\t\tstatus: 'error' as const,\n\t\t\t\tprogress: {},\n\t\t\t\terror: {\n\t\t\t\t\tmessage: `No edit history found for file '${args.path}'.`,\n\t\t\t\t},\n\t\t\t}\n\t\t}\n\n\t\tconst diff = createUnifiedDiff(lastEdit.newContent, lastEdit.oldContent, args.path)\n\t\tconst formattedDiff = formatDiffAsMarkdown(diff)\n\n\t\tawait trackFileChange(filePath, async (path) => {\n\t\t\tawait writeFile(path, lastEdit.oldContent, {\n\t\t\t\tencoding: 'utf-8',\n\t\t\t\tsignal,\n\t\t\t})\n\t\t})\n\n\t\treturn { status: 'done', progress: {}, result: formattedDiff }\n\t})\n}\n\ntype HistoryID = string\n\nclass NodeEditHistoryManager extends EditHistoryManager<HistoryID> {\n\tasync storeEdit(filePath: string, oldContent: string, newContent: string): Promise<HistoryID> {\n\t\tconst hashedFilename = getHashedFilename(filePath)\n\t\tconst tempDir = await getTempDir()\n\t\tconst editFile = path.join(tempDir, hashedFilename)\n\n\t\tconst editData = { filePath, oldContent, newContent }\n\t\tawait fs.writeFile(editFile, JSON.stringify(editData), 'utf-8')\n\n\t\treturn hashedFilename as HistoryID\n\t}\n\tasync fetchEdit(\n\t\tfilePath: string,\n\t): Promise<{ id: HistoryID; oldContent: string; newContent: string } | undefined> {\n\t\tconst hashedFilename = getHashedFilename(filePath)\n\t\tconst tempDir = await getTempDir()\n\t\tconst editFile = path.join(tempDir, hashedFilename)\n\n\t\ttry {\n\t\t\tawait fs.access(editFile)\n\t\t} catch {\n\t\t\treturn undefined\n\t\t}\n\n\t\tconst editDataStr = await fs.readFile(editFile, 'utf-8')\n\t\tconst editData = JSON.parse(editDataStr) as {\n\t\t\tfilePath: string\n\t\t\toldContent: string\n\t\t\tnewContent: string\n\t\t}\n\t\treturn {\n\t\t\tid: hashedFilename,\n\t\t\toldContent: editData.oldContent,\n\t\t\tnewContent: editData.newContent,\n\t\t}\n\t}\n\tasync deleteEdit(id: HistoryID): Promise<void> {\n\t\tconst tempDir = await getTempDir()\n\t\tconst editFile = path.join(tempDir, id)\n\t\tawait fs.unlink(editFile).catch(() => {})\n\t}\n}\n\nconst nodeEditHistoryManager = new NodeEditHistoryManager()\n\nexport const recordEdit = nodeEditHistoryManager.recordEdit.bind(nodeEditHistoryManager)\nexport const getLastEdit = nodeEditHistoryManager.getLastEdit.bind(nodeEditHistoryManager)\n\nlet tempDir = ''\nlet tempDirPromise: Promise<string> | null = null\n\nasync function getTempDir(): Promise<string> {\n\tif (tempDir) return tempDir\n\tif (!tempDirPromise) {\n\t\ttempDirPromise = fs\n\t\t\t.mkdtemp(path.join(os.tmpdir(), 'amp-edits-'))\n\t\t\t.then((dir) => {\n\t\t\t\ttempDir = dir\n\t\t\t\treturn dir\n\t\t\t})\n\t\t\t.catch((error) => {\n\t\t\t\tlogger.error('Failed to create edit history directory:', error)\n\t\t\t\tthrow error\n\t\t\t})\n\t}\n\treturn tempDirPromise\n}\n\nfunction getHashedFilename(filePath: string): string {\n\tconst hash = crypto.createHash('sha256').update(filePath).digest('hex').slice(0, 16)\n\treturn `${hash}-${path.basename(filePath)}`\n}\n"],"names":["EditHistoryManager","filePath","oldContent","newContent","editKey","existingIndex","oldestKey","error","logger","editData","queueIndex","checkUndoEditArgs","args","nodeUndoEditTool","dir","threadID","trackFileChange","promiseFactoryToObservable","signal","checkDirURIIsFile","path","lastEdit","getLastEdit","diff","createUnifiedDiff","formattedDiff","formatDiffAsMarkdown","writeFile","NodeEditHistoryManager","hashedFilename","getHashedFilename","tempDir","getTempDir","editFile","fs","editDataStr","id","nodeEditHistoryManager","recordEdit","tempDirPromise","os","crypto"],"mappings":";;;;;;AAGO,MAAeA,EAA8B;AAAA,EAWlC,oBAAoB;AAAA,EACpB,YAAyB,CAAC;AAAA,EAE3C,MAAa,WACZC,GACAC,GACAC,GACgB;AACZ,QAAA;AACH,YAAMC,IAAU,MAAM,KAAK,UAAUH,GAAUC,GAAYC,CAAU,GAI/DE,IAAgB,KAAK,UAAU,QAAQD,CAAO;AASpD,UARIC,KAAiB,KACf,KAAA,UAAU,OAAOA,GAAe,CAAC,GAIlC,KAAA,UAAU,KAAKD,CAAO,GAGvB,KAAK,UAAU,SAAS,KAAK,mBAAmB;AAC7C,cAAAE,IAAY,KAAK,UAAU,MAAM;AACvC,QAAIA,KACH,KAAK,WAAWA,CAAS;AAAA,MAC1B;AAAA,aAEOC,GAAO;AACR,MAAAC,EAAA,MAAM,0BAA0BD,CAAK;AAAA,IAAA;AAAA,EAC7C;AAAA;AAAA,EAID,MAAa,YACZN,GACkE;AAC9D,QAAA;AAEH,YAAMQ,IAAW,MAAM,KAAK,UAAUR,CAAQ;AAC9C,UAAI,CAACQ;AACG;AAIR,YAAMC,IAAa,KAAK,UAAU,QAAQD,EAAS,EAAE;AACrD,aAAIC,KAAc,KACZ,KAAA,UAAU,OAAOA,GAAY,CAAC,GAE/B,KAAA,WAAWD,EAAS,EAAE,GAEpB,EAAE,YAAYA,EAAS,YAAY,YAAYA,EAAS,WAAW;AAAA,aAClEF,GAA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