@sourcegraph/amp 0.0.1748952139-g3a80f1 → 0.0.1748980894-g854971
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-eeeVpbOj.js → client-CdGt7f2C.js} +2 -2
- package/dist/{client-eeeVpbOj.js.map → client-CdGt7f2C.js.map} +1 -1
- package/dist/{console-CN5EK-5f.js → console-B_WpLlBn.js} +7224 -7179
- package/dist/console-B_WpLlBn.js.map +1 -0
- package/dist/{create_file.node-BPbwLrpo.js → create_file.node-CsT9gDmz.js} +2 -2
- package/dist/{create_file.node-BPbwLrpo.js.map → create_file.node-CsT9gDmz.js.map} +1 -1
- package/dist/{edit_file.node-CoKkV9T6.js → edit_file.node-BBsHtcvC.js} +3 -3
- package/dist/{edit_file.node-CoKkV9T6.js.map → edit_file.node-BBsHtcvC.js.map} +1 -1
- package/dist/{executable-Dbw4UQsn.js → executable-CZmTv_uJ.js} +2 -2
- package/dist/{executable-Dbw4UQsn.js.map → executable-CZmTv_uJ.js.map} +1 -1
- package/dist/{files-vC7gbodq.js → files-smhhuXbX.js} +2 -2
- package/dist/{files-vC7gbodq.js.map → files-smhhuXbX.js.map} +1 -1
- package/dist/{glob.node-Br1inBMB.js → glob.node-B7I9kYKu.js} +4 -4
- package/dist/{glob.node-Br1inBMB.js.map → glob.node-B7I9kYKu.js.map} +1 -1
- package/dist/{index-Dgb2bOc6.js → index-gyL8W9F3.js} +2 -2
- package/dist/{index-Dgb2bOc6.js.map → index-gyL8W9F3.js.map} +1 -1
- package/dist/{list_directory.node-DGkXRIzx.js → list_directory.node-CArwg4Bh.js} +2 -2
- package/dist/{list_directory.node-DGkXRIzx.js.map → list_directory.node-CArwg4Bh.js.map} +1 -1
- package/dist/{load-profile-DvvdVESK.js → load-profile-B9gC5cKj.js} +2 -2
- package/dist/{load-profile-DvvdVESK.js.map → load-profile-B9gC5cKj.js.map} +1 -1
- package/dist/{main-CcCjhyno.js → main-BALY0T8z.js} +16 -16
- package/dist/{main-CcCjhyno.js.map → main-BALY0T8z.js.map} +1 -1
- package/dist/{node-bCOCJc2z.js → node-BRsLFKPt.js} +2 -2
- package/dist/{node-bCOCJc2z.js.map → node-BRsLFKPt.js.map} +1 -1
- package/dist/{node-uQP2zFCU.js → node-CZOJR58s.js} +3 -3
- package/dist/{node-uQP2zFCU.js.map → node-CZOJR58s.js.map} +1 -1
- package/dist/{node-CFZqx9i7.js → node-DSSqL9Am.js} +3 -3
- package/dist/{node-CFZqx9i7.js.map → node-DSSqL9Am.js.map} +1 -1
- package/dist/{node-BlIuu9mO.js → node-IKxYW21z.js} +2 -2
- package/dist/{node-BlIuu9mO.js.map → node-IKxYW21z.js.map} +1 -1
- package/dist/{node-DrR1mumq.js → node-MCjHN_Cr.js} +4 -4
- package/dist/{node-DrR1mumq.js.map → node-MCjHN_Cr.js.map} +1 -1
- package/dist/{node-BWA8OH3Y.js → node-pmgKozBB.js} +3 -3
- package/dist/{node-BWA8OH3Y.js.map → node-pmgKozBB.js.map} +1 -1
- package/dist/{read_file.node-B_mwwcms.js → read_file.node-uv7Y77zM.js} +2 -2
- package/dist/{read_file.node-B_mwwcms.js.map → read_file.node-uv7Y77zM.js.map} +1 -1
- package/dist/{stdio-CbcJDG9x.js → stdio-DI6IegyA.js} +3 -3
- package/dist/{stdio-CbcJDG9x.js.map → stdio-DI6IegyA.js.map} +1 -1
- package/dist/storybook.js +1 -1
- package/dist/undo_edit.node-D9_a5KvG.js +102 -0
- package/dist/undo_edit.node-D9_a5KvG.js.map +1 -0
- package/package.json +1 -1
- package/dist/console-CN5EK-5f.js.map +0 -1
- package/dist/undo_edit.node-CymsB0Md.js +0 -82
- package/dist/undo_edit.node-CymsB0Md.js.map +0 -1
@@ -1,82 +0,0 @@
|
|
1
|
-
#!/usr/bin/env node
|
2
|
-
import F from "node:crypto";
|
3
|
-
import s, { writeFile as D } from "node:fs/promises";
|
4
|
-
import g from "node:os";
|
5
|
-
import c from "node:path";
|
6
|
-
import { p as b, aB as C, aK as E, aL as v, C as m } from "./console-CN5EK-5f.js";
|
7
|
-
const x = 50, o = [];
|
8
|
-
async function J(t, i, d) {
|
9
|
-
try {
|
10
|
-
const e = y(t), r = await w(), a = c.join(r, e), n = { filePath: t, oldContent: i, newContent: d };
|
11
|
-
await s.writeFile(a, JSON.stringify(n), "utf-8");
|
12
|
-
const f = o.indexOf(e);
|
13
|
-
if (f >= 0 && o.splice(f, 1), o.push(e), o.length > x) {
|
14
|
-
const l = o.shift();
|
15
|
-
if (l) {
|
16
|
-
const h = c.join(r, l);
|
17
|
-
await s.unlink(h).catch(() => {
|
18
|
-
});
|
19
|
-
}
|
20
|
-
}
|
21
|
-
} catch (e) {
|
22
|
-
m.error("Failed to record edit:", e);
|
23
|
-
}
|
24
|
-
}
|
25
|
-
async function O(t) {
|
26
|
-
try {
|
27
|
-
const i = y(t), d = await w(), e = c.join(d, i);
|
28
|
-
try {
|
29
|
-
await s.access(e);
|
30
|
-
} catch {
|
31
|
-
return;
|
32
|
-
}
|
33
|
-
const r = await s.readFile(e, "utf-8"), a = JSON.parse(r), n = o.indexOf(i);
|
34
|
-
return n >= 0 && o.splice(n, 1), await s.unlink(e).catch(() => {
|
35
|
-
}), { oldContent: a.oldContent, newContent: a.newContent };
|
36
|
-
} catch (i) {
|
37
|
-
m.error("Failed to get last edit:", i);
|
38
|
-
return;
|
39
|
-
}
|
40
|
-
}
|
41
|
-
const U = ({ args: t }, { dir: i, threadID: d, trackFileChange: e }) => b(async (r) => {
|
42
|
-
C(i), _(t);
|
43
|
-
const a = c.resolve(i.fsPath, t.path), n = await O(t.path);
|
44
|
-
if (!n)
|
45
|
-
return {
|
46
|
-
status: "error",
|
47
|
-
progress: {},
|
48
|
-
error: {
|
49
|
-
message: `No edit history found for file '${t.path}'.`
|
50
|
-
}
|
51
|
-
};
|
52
|
-
const f = E(n.newContent, n.oldContent, t.path), l = v(f);
|
53
|
-
return await e(a, async (h) => {
|
54
|
-
await D(h, n.oldContent, {
|
55
|
-
encoding: "utf-8",
|
56
|
-
signal: r
|
57
|
-
});
|
58
|
-
}), { status: "done", progress: {}, result: l };
|
59
|
-
});
|
60
|
-
function _(t) {
|
61
|
-
if (typeof t != "object" || t === null)
|
62
|
-
throw new Error("args must be an object. received instead: `" + JSON.stringify(t) + "`");
|
63
|
-
if (typeof t.path != "string")
|
64
|
-
throw new Error(
|
65
|
-
"path must be a string. received instead: `" + JSON.stringify(t.path) + "`"
|
66
|
-
);
|
67
|
-
}
|
68
|
-
let u = "", p = null;
|
69
|
-
async function w() {
|
70
|
-
return u || (p || (p = s.mkdtemp(c.join(g.tmpdir(), "amp-edits-")).then((t) => (u = t, t)).catch((t) => {
|
71
|
-
throw m.error("Failed to create edit history directory:", t), t;
|
72
|
-
})), p);
|
73
|
-
}
|
74
|
-
function y(t) {
|
75
|
-
return `${F.createHash("sha256").update(t).digest("hex").slice(0, 16)}-${c.basename(t)}`;
|
76
|
-
}
|
77
|
-
export {
|
78
|
-
O as getLastEdit,
|
79
|
-
U as nodeUndoEditTool,
|
80
|
-
J as recordEdit
|
81
|
-
};
|
82
|
-
//# sourceMappingURL=undo_edit.node-CymsB0Md.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"undo_edit.node-CymsB0Md.js","sources":["../../core/src/tools/builtin/filesystem/undo_edit.node.ts"],"sourcesContent":["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 { UndoEditToolDef, undoEditToolReg } from './undo_edit.common'\n\nconst MAX_FILES = 50\nconst editQueue: string[] = []\n\nexport async function recordEdit(\n\tfilePath: string,\n\toldContent: string,\n\tnewContent: string,\n): Promise<void> {\n\ttry {\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\t// Update the FIFO queue\n\t\t// Remove if already in queue (to add it to the end)\n\t\tconst existingIndex = editQueue.indexOf(hashedFilename)\n\t\tif (existingIndex >= 0) {\n\t\t\teditQueue.splice(existingIndex, 1)\n\t\t}\n\n\t\t// Add to end of queue (most recent)\n\t\teditQueue.push(hashedFilename)\n\n\t\t// If we exceed the limit, remove the oldest edit\n\t\tif (editQueue.length > MAX_FILES) {\n\t\t\tconst oldestFile = editQueue.shift()\n\t\t\tif (oldestFile) {\n\t\t\t\tconst oldestPath = path.join(tempDir, oldestFile)\n\t\t\t\tawait fs.unlink(oldestPath).catch(() => {})\n\t\t\t}\n\t\t}\n\t} catch (error) {\n\t\tlogger.error('Failed to record edit:', error)\n\t}\n}\n\n// Function to get and remove the most recent edit for a file\nexport async function getLastEdit(\n\tfilePath: string,\n): Promise<{ oldContent: string; newContent: string } | undefined> {\n\ttry {\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\n\t\t// Remove from queue and delete file\n\t\tconst queueIndex = editQueue.indexOf(hashedFilename)\n\t\tif (queueIndex >= 0) {\n\t\t\teditQueue.splice(queueIndex, 1)\n\t\t}\n\t\tawait fs.unlink(editFile).catch(() => {})\n\n\t\treturn { oldContent: editData.oldContent, newContent: editData.newContent }\n\t} catch (error) {\n\t\tlogger.error('Failed to get last edit:', error)\n\t\treturn undefined\n\t}\n}\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\nfunction checkUndoEditArgs(args: UndoEditToolDef['args']): 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\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":["MAX_FILES","editQueue","recordEdit","filePath","oldContent","newContent","hashedFilename","getHashedFilename","tempDir","getTempDir","editFile","path","editData","fs","existingIndex","oldestFile","oldestPath","error","logger","getLastEdit","editDataStr","queueIndex","nodeUndoEditTool","args","dir","threadID","trackFileChange","promiseFactoryToObservable","signal","checkDirURIIsFile","checkUndoEditArgs","lastEdit","diff","createUnifiedDiff","formattedDiff","formatDiffAsMarkdown","writeFile","tempDirPromise","os","crypto"],"mappings":";;;;;;AAUA,MAAMA,IAAY,IACZC,IAAsB,CAAC;AAEP,eAAAC,EACrBC,GACAC,GACAC,GACgB;AACZ,MAAA;AACG,UAAAC,IAAiBC,EAAkBJ,CAAQ,GAC3CK,IAAU,MAAMC,EAAW,GAC3BC,IAAWC,EAAK,KAAKH,GAASF,CAAc,GAE5CM,IAAW,EAAE,UAAAT,GAAU,YAAAC,GAAY,YAAAC,EAAW;AACpD,UAAMQ,EAAG,UAAUH,GAAU,KAAK,UAAUE,CAAQ,GAAG,OAAO;AAIxD,UAAAE,IAAgBb,EAAU,QAAQK,CAAc;AASlD,QARAQ,KAAiB,KACVb,EAAA,OAAOa,GAAe,CAAC,GAIlCb,EAAU,KAAKK,CAAc,GAGzBL,EAAU,SAASD,GAAW;AAC3B,YAAAe,IAAad,EAAU,MAAM;AACnC,UAAIc,GAAY;AACf,cAAMC,IAAaL,EAAK,KAAKH,GAASO,CAAU;AAChD,cAAMF,EAAG,OAAOG,CAAU,EAAE,MAAM,MAAM;AAAA,QAAA,CAAE;AAAA,MAAA;AAAA,IAC3C;AAAA,WAEOC,GAAO;AACR,IAAAC,EAAA,MAAM,0BAA0BD,CAA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