dsh-efm-integration 0.4.8 → 0.5.1
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/README.md +36 -11
- package/README.zh.md +29 -8
- package/client.js +118 -29
- package/cordis.patch.yml +5 -0
- package/lib/archive-cleaner/core.d.ts +86 -15
- package/lib/archive-cleaner/core.d.ts.map +1 -1
- package/lib/archive-cleaner/core.js +262 -62
- package/lib/archive-cleaner/core.js.map +1 -1
- package/lib/archive-cleaner/index.d.ts +14 -1
- package/lib/archive-cleaner/index.d.ts.map +1 -1
- package/lib/archive-cleaner/index.js +341 -40
- package/lib/archive-cleaner/index.js.map +1 -1
- package/lib/archive-cleaner/paths.d.ts +36 -0
- package/lib/archive-cleaner/paths.d.ts.map +1 -0
- package/lib/archive-cleaner/paths.js +94 -0
- package/lib/archive-cleaner/paths.js.map +1 -0
- package/lib/archive-cleaner/pending.d.ts +23 -0
- package/lib/archive-cleaner/pending.d.ts.map +1 -0
- package/lib/archive-cleaner/pending.js +88 -0
- package/lib/archive-cleaner/pending.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { mkdir, readFile, rename, rm, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { dirname } from 'node:path';
|
|
3
|
+
/** Maximum archived roots retained in the pending-deletion manifest. */
|
|
4
|
+
export const MAX_PENDING_ROOTS = 10_000;
|
|
5
|
+
const VERSION = 1;
|
|
6
|
+
/**
|
|
7
|
+
* Read the roots queued for forced deletion. A missing file means no work; a
|
|
8
|
+
* malformed file is fail-closed and reported so the caller can refuse a new
|
|
9
|
+
* force request instead of silently discarding the old queue.
|
|
10
|
+
* @param file - absolute manifest path.
|
|
11
|
+
* @returns the queued root ids, or an error describing why the file is unusable.
|
|
12
|
+
*/
|
|
13
|
+
export async function readPendingRoots(file) {
|
|
14
|
+
let raw;
|
|
15
|
+
try {
|
|
16
|
+
raw = await readFile(file, 'utf8');
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
if (isNotFound(error))
|
|
20
|
+
return { roots: [] };
|
|
21
|
+
return { roots: [], error: messageOf(error) };
|
|
22
|
+
}
|
|
23
|
+
let value;
|
|
24
|
+
try {
|
|
25
|
+
value = JSON.parse(raw);
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
return { roots: [], error: `invalid JSON: ${messageOf(error)}` };
|
|
29
|
+
}
|
|
30
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
31
|
+
return { roots: [], error: 'pending deletions is not an object' };
|
|
32
|
+
}
|
|
33
|
+
const record = value;
|
|
34
|
+
if (record['version'] !== VERSION) {
|
|
35
|
+
return { roots: [], error: `unsupported pending-deletion version ${String(record['version'])}` };
|
|
36
|
+
}
|
|
37
|
+
const entries = record['roots'];
|
|
38
|
+
if (!Array.isArray(entries)) {
|
|
39
|
+
return { roots: [], error: 'pending deletions has no roots array' };
|
|
40
|
+
}
|
|
41
|
+
if (entries.length > MAX_PENDING_ROOTS) {
|
|
42
|
+
return { roots: [], error: `pending deletions has too many roots (${entries.length})` };
|
|
43
|
+
}
|
|
44
|
+
const roots = [];
|
|
45
|
+
for (const entry of entries) {
|
|
46
|
+
if (typeof entry !== 'string' || entry.length === 0) {
|
|
47
|
+
return { roots: [], error: 'pending root is not a non-empty string' };
|
|
48
|
+
}
|
|
49
|
+
if (!roots.includes(entry))
|
|
50
|
+
roots.push(entry);
|
|
51
|
+
}
|
|
52
|
+
return { roots };
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Atomically replace the pending-deletion manifest. An empty set removes the
|
|
56
|
+
* file so a clean profile has no queue.
|
|
57
|
+
* @param file - absolute manifest path.
|
|
58
|
+
* @param roots - archived root ids still waiting for deletion.
|
|
59
|
+
*/
|
|
60
|
+
export async function writePendingRoots(file, roots) {
|
|
61
|
+
const unique = [...new Set(roots)];
|
|
62
|
+
if (unique.length > MAX_PENDING_ROOTS) {
|
|
63
|
+
throw new Error(`pending deletions exceeds ${MAX_PENDING_ROOTS} roots`);
|
|
64
|
+
}
|
|
65
|
+
if (unique.length === 0) {
|
|
66
|
+
await rm(file, { force: true });
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
await mkdir(dirname(file), { recursive: true });
|
|
70
|
+
const temporary = `${file}.${process.pid}.${Date.now()}.${Math.random().toString(16).slice(2)}.tmp`;
|
|
71
|
+
try {
|
|
72
|
+
await writeFile(temporary, JSON.stringify({ version: VERSION, roots: unique, updatedAt: new Date().toISOString() }), { encoding: 'utf8', flag: 'wx', mode: 0o600 });
|
|
73
|
+
await rename(temporary, file);
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
// Preserve the original failure; temporary-file cleanup is best-effort.
|
|
77
|
+
await rm(temporary, { force: true }).catch(() => { });
|
|
78
|
+
throw error;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function isNotFound(error) {
|
|
82
|
+
return typeof error === 'object' && error !== null
|
|
83
|
+
&& 'code' in error && error.code === 'ENOENT';
|
|
84
|
+
}
|
|
85
|
+
function messageOf(error) {
|
|
86
|
+
return error instanceof Error ? error.message : String(error);
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=pending.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pending.js","sourceRoot":"","sources":["../../src/archive-cleaner/pending.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AACzE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAEnC,wEAAwE;AACxE,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAA;AAEvC,MAAM,OAAO,GAAG,CAAC,CAAA;AAQjB;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,IAAY;IACjD,IAAI,GAAW,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EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAA;IACnG,IAAI,CAAC;QACH,MAAM,SAAS,CACb,SAAS,EACT,IAAI,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,EAAE,CAAC,EACxF,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAC9C,CAAA;QACD,MAAM,MAAM,CAAC,SAAS,EAAE,IAAI,CAAC,CAAA;IAC/B,CAAC;IAAC,OAAO,KAAc,EAAE,CAAC;QACxB,wEAAwE;QACxE,MAAM,EAAE,CAAC,SAAS,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAA;QACpD,MAAM,KAAK,CAAA;IACb,CAAC;AACH,CAAC;AAED,SAAS,UAAU,CAAC,KAAc;IAChC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI;WAC7C,MAAM,IAAI,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,QAAQ,CAAA;AACjD,CAAC;AAED,SAAS,SAAS,CAAC,KAAc;IAC/B,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;AAC/D,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-efm-integration",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "A DSH plugin bundle with coding discipline, skill routing, verification, archived Session cleanup, and sidebar-managed language servers.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|