@deepseek-ai/dsh-spill-local 0.2.2-rc.1 → 0.2.2-rc.2
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/lib/types/cleanup.d.ts.map +1 -0
- package/lib/types/cleanup.js.map +1 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/index.js.map +1 -0
- package/lib/types/store.d.ts.map +1 -0
- package/lib/types/store.js.map +1 -0
- package/package.json +10 -7
- package/src/cleanup.ts +431 -0
- package/src/index.ts +164 -0
- package/src/store.ts +131 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cleanup.d.ts","sourceRoot":"","sources":["../../src/cleanup.ts"],"names":[],"mappings":"AAgCA,4FAA4F;AAC5F,MAAM,MAAM,MAAM,GAAG,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAA;AA4H9C,gFAAgF;AAChF,MAAM,WAAW,SAAS;IACxB,oCAAoC;IACpC,IAAI,EAAE,MAAM,CAAA;IACZ;;;;;;OAMG;IACH,cAAc,EAAE,OAAO,CAAA;CACxB;AAED,mGAAmG;AACnG,MAAM,WAAW,YAAY;IAC3B,qFAAqF;IACrF,KAAK,EAAE,SAAS,EAAE,CAAA;IAClB;;;;OAIG;IACH,QAAQ,EAAE,MAAM,CAAA;IAChB,uFAAuF;IACvF,IAAI,EAAE,MAAM,CAAA;CACb;AA+ED;;;;;;;;;;GAUG;AACH,wBAAsB,eAAe,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAwF1E;AAmCD;;;;;;GAMG;AACH,wBAAsB,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE,MAAiB,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAEnG;AAED;;;;;;;;;GASG;AACH,wBAAsB,gBAAgB,CACpC,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,MAAM,EACZ,gBAAgB,GAAE,MAAiB,G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AAC,KAAK,UAAU,YAAY,CAAC,OAAwB;IACzD,MAAM,GAAG,GAAG,UAAU,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,SAAS,CAAC,CAAA;IACvD,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,aAAa,CAAC,OAAO,CAAC,aAAa,CAAC,EAAE,CAAC,CAAA;IACnG,IAAI,MAAM,CAAA;IACV,SAAS,CAAC;QACR,MAAM,KAAK,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAA;QAClD,IAAI,CAAC;YACH,MAAM,GAAG,MAAM,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,CAAA;YACtC,MAAK;QACP,CAAC;QAAC,OAAO,KAAc,EAAE,CAAC;YACxB;4EACgE;YAChE,IAAI,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAC;gBAAE,SAAQ;YACtC,MAAM,KAAK,CAAA;YACX,oBAAoB;QACtB,CAAC;IACH,CAAC;IACD,IAAI,CAAC;QACH,MAAM,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;IACzC,CAAC;YAAS,CAAC;QACT,MAAM,MAAM,CAAC,KAAK,EAAE,CAAA;IACtB,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,OAAO,EAAE,MAAM,CAAC,EAAE,CAAA;AACpE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deepseek-ai/dsh-spill-local",
|
|
3
3
|
"description": "Local-filesystem implementation of the DeepSeek Harness spill storage seam (private session-scoped files)",
|
|
4
|
-
"version": "0.2.2-rc.
|
|
4
|
+
"version": "0.2.2-rc.2",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -25,11 +25,14 @@
|
|
|
25
25
|
"files": [
|
|
26
26
|
"locale/*.json",
|
|
27
27
|
"lib/index.js",
|
|
28
|
-
"lib/types/**/*.d.ts"
|
|
28
|
+
"lib/types/**/*.d.ts",
|
|
29
|
+
"lib/types/**/*.d.ts.map",
|
|
30
|
+
"lib/**/*.js.map",
|
|
31
|
+
"src"
|
|
29
32
|
],
|
|
30
33
|
"license": "MIT",
|
|
31
34
|
"peerDependencies": {
|
|
32
|
-
"@deepseek-ai/dsh-spill": "0.2.2-rc.
|
|
35
|
+
"@deepseek-ai/dsh-spill": "0.2.2-rc.2",
|
|
33
36
|
"@deepseek-ai/cordis": "~4.1.0"
|
|
34
37
|
},
|
|
35
38
|
"dependencies": {
|
|
@@ -38,10 +41,10 @@
|
|
|
38
41
|
"devDependencies": {
|
|
39
42
|
"@deepseek-ai/cordis-plugin-include": "~1.1.0",
|
|
40
43
|
"@deepseek-ai/cordis-plugin-loader": "~1.1.0",
|
|
41
|
-
"@deepseek-ai/dsh-brand": "0.2.2-rc.
|
|
42
|
-
"@deepseek-ai/dsh-llm": "0.2.2-rc.
|
|
43
|
-
"@deepseek-ai/dsh-session": "0.2.2-rc.
|
|
44
|
-
"@deepseek-ai/dsh-spill": "0.2.2-rc.
|
|
44
|
+
"@deepseek-ai/dsh-brand": "0.2.2-rc.2",
|
|
45
|
+
"@deepseek-ai/dsh-llm": "0.2.2-rc.2",
|
|
46
|
+
"@deepseek-ai/dsh-session": "0.2.2-rc.2",
|
|
47
|
+
"@deepseek-ai/dsh-spill": "0.2.2-rc.2",
|
|
45
48
|
"@deepseek-ai/cordis": "~4.1.0"
|
|
46
49
|
}
|
|
47
50
|
}
|
package/src/cleanup.ts
ADDED
|
@@ -0,0 +1,431 @@
|
|
|
1
|
+
/** Startup cleanup mechanics for local spill roots. */
|
|
2
|
+
import { lstat, readdir, realpath, rmdir, unlink } from 'node:fs/promises'
|
|
3
|
+
import type { Stats } from 'node:fs'
|
|
4
|
+
import { dirname, join } from 'node:path'
|
|
5
|
+
import { tmpdir } from 'node:os'
|
|
6
|
+
import { DEFAULT_ROOT_PREFIX, isErrno } from './store.ts'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A backend-generated default root name: `dsh-spill-` plus the 6-character
|
|
10
|
+
* suffix `mkdtemp` appends. Discovery matches this
|
|
11
|
+
* EXACT shape, not the bare prefix, so an unrelated `dsh-spill-test-*` fixture
|
|
12
|
+
* or a foreign tool's differently-shaped `dsh-spill-…` directory is never
|
|
13
|
+
* mistaken for a backend root to sweep.
|
|
14
|
+
*/
|
|
15
|
+
const DEFAULT_ROOT_RE = new RegExp(`^${DEFAULT_ROOT_PREFIX}[A-Za-z0-9]{6}$`)
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* A backend-generated session directory name: `session-` plus the 12 lowercase
|
|
19
|
+
* hex characters {@link sessionDir} derives from `sha256(sessionId)`. The sweep
|
|
20
|
+
* only descends into entries of this EXACT shape, so an unrelated
|
|
21
|
+
* `session-backup` directory under a shared configured root is never swept.
|
|
22
|
+
*/
|
|
23
|
+
const SESSION_DIR_RE = /^session-[0-9a-f]{12}$/
|
|
24
|
+
|
|
25
|
+
/** An existing root resolved to one stable filesystem identity. */
|
|
26
|
+
interface ResolvedRoot {
|
|
27
|
+
/** Canonical absolute path used for the sweep. */
|
|
28
|
+
path: string
|
|
29
|
+
/** Device/inode identity used to de-duplicate filesystem aliases. */
|
|
30
|
+
identity: string
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** A one-argument warning sink — the sweep's only side effect on failure (never throws). */
|
|
34
|
+
export type WarnFn = (message: string) => void
|
|
35
|
+
|
|
36
|
+
/** Report a best-effort sweep failure without allowing the warning sink to reject cleanup. */
|
|
37
|
+
function warnSafely(warn: WarnFn, message: string): void {
|
|
38
|
+
try {
|
|
39
|
+
warn(message)
|
|
40
|
+
} catch {
|
|
41
|
+
// Warning sinks are observational callbacks; cleanup must remain best-effort
|
|
42
|
+
// even when a logger implementation throws.
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Whether another local OS user cannot replace children of this directory. */
|
|
47
|
+
function isTrustedDirectory(stats: Stats): boolean {
|
|
48
|
+
if (!stats.isDirectory()) return false
|
|
49
|
+
/* v8 ignore next -- POSIX ownership and mode bits have no Windows equivalent. */
|
|
50
|
+
if (process.platform === 'win32' || process.geteuid === undefined) return true
|
|
51
|
+
/* v8 ignore start -- Windows takes the return above; POSIX tests exercise
|
|
52
|
+
owner and mode rejection. */
|
|
53
|
+
return stats.uid === process.geteuid() && (stats.mode & 0o022) === 0
|
|
54
|
+
/* v8 ignore stop */
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Stable identity for de-duplicating aliases of one root. */
|
|
58
|
+
function rootIdentity(path: string, stats: Stats): string {
|
|
59
|
+
/* v8 ignore next -- Windows file indexes are not portable inode identities. */
|
|
60
|
+
if (process.platform === 'win32') return path.toLowerCase()
|
|
61
|
+
/* v8 ignore start -- Windows uses the canonical path identity above; POSIX
|
|
62
|
+
tests exercise device and inode identity. */
|
|
63
|
+
return `${String(stats.dev)}:${String(stats.ino)}`
|
|
64
|
+
/* v8 ignore stop */
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Check that no ancestor permits another local OS user to replace the selected
|
|
69
|
+
* child. A sticky writable ancestor is safe because the child is owned by the
|
|
70
|
+
* current user; this admits normal per-process roots below `/tmp`.
|
|
71
|
+
*/
|
|
72
|
+
async function hasProtectedAncestors(path: string): Promise<boolean> {
|
|
73
|
+
/* v8 ignore next -- POSIX ancestry checks have no Windows ACL equivalent. */
|
|
74
|
+
if (process.platform === 'win32' || process.geteuid === undefined) return true
|
|
75
|
+
/* v8 ignore start -- Windows takes the return above; POSIX tests exercise
|
|
76
|
+
the ancestor ownership and mode policy. */
|
|
77
|
+
const currentUid = process.geteuid()
|
|
78
|
+
let child = path
|
|
79
|
+
let childStats = await lstat(child)
|
|
80
|
+
for (;;) {
|
|
81
|
+
const parent = dirname(child)
|
|
82
|
+
if (parent === child) return true
|
|
83
|
+
const stats = await lstat(parent)
|
|
84
|
+
/* v8 ignore next -- every ancestor of a successfully resolved path is a directory. */
|
|
85
|
+
if (!stats.isDirectory()) return false
|
|
86
|
+
const writableByOthers = (stats.mode & 0o022) !== 0
|
|
87
|
+
const sticky = (stats.mode & 0o1000) !== 0
|
|
88
|
+
if (writableByOthers && !sticky) return false
|
|
89
|
+
/* v8 ignore next -- requires an ancestor owned by another OS account inside
|
|
90
|
+
a writable sticky parent; ordinary test fixtures cannot change uid. */
|
|
91
|
+
if (writableByOthers && childStats.uid !== currentUid) return false
|
|
92
|
+
child = parent
|
|
93
|
+
childStats = stats
|
|
94
|
+
}
|
|
95
|
+
/* v8 ignore stop */
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Resolve one existing root without admitting a directory another local user
|
|
100
|
+
* can replace during the path-based sweep. A configured root may be a symlink;
|
|
101
|
+
* discovery passes `false` so a symlink cannot impersonate a default root.
|
|
102
|
+
*
|
|
103
|
+
* @param path Candidate root path.
|
|
104
|
+
* @param allowSymlink Whether the candidate itself may be a configured symlink.
|
|
105
|
+
* @param warn Sink for skipped or failed inspection.
|
|
106
|
+
* @returns The trusted canonical root, or `undefined` when it is absent or unsafe.
|
|
107
|
+
*/
|
|
108
|
+
async function resolveRoot(path: string, allowSymlink: boolean, warn: WarnFn): Promise<ResolvedRoot | undefined> {
|
|
109
|
+
let initial: Stats
|
|
110
|
+
try {
|
|
111
|
+
initial = await lstat(path)
|
|
112
|
+
} catch (error: unknown) {
|
|
113
|
+
/* v8 ignore start -- non-ENOENT inspection failures depend on host ACL or
|
|
114
|
+
an entry racing away and cannot be reproduced portably. */
|
|
115
|
+
if (!isErrno(error, 'ENOENT')) warnSafely(warn, `spill-local: failed to inspect root ${path}: ${String(error)}`)
|
|
116
|
+
return undefined
|
|
117
|
+
/* v8 ignore stop */
|
|
118
|
+
}
|
|
119
|
+
if (initial.isSymbolicLink()) {
|
|
120
|
+
if (!allowSymlink) return undefined
|
|
121
|
+
} else if (!isTrustedDirectory(initial)) {
|
|
122
|
+
warnSafely(warn, `spill-local: skipped unsafe root ${path}: expected a directory owned by the current user and not writable by group or others`)
|
|
123
|
+
return undefined
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
let canonical: string
|
|
127
|
+
let stats: Stats
|
|
128
|
+
try {
|
|
129
|
+
canonical = await realpath(path)
|
|
130
|
+
stats = await lstat(canonical)
|
|
131
|
+
} catch (error: unknown) {
|
|
132
|
+
/* v8 ignore start -- a root lstat'd above reaches this only by racing away
|
|
133
|
+
or by a host-specific realpath failure. */
|
|
134
|
+
if (!isErrno(error, 'ENOENT')) warnSafely(warn, `spill-local: failed to resolve root ${path}: ${String(error)}`)
|
|
135
|
+
return undefined
|
|
136
|
+
/* v8 ignore stop */
|
|
137
|
+
}
|
|
138
|
+
let protectedAncestors = false
|
|
139
|
+
try {
|
|
140
|
+
protectedAncestors = await hasProtectedAncestors(canonical)
|
|
141
|
+
} catch (error: unknown) {
|
|
142
|
+
/* v8 ignore start -- a canonical ancestor disappears only through a race;
|
|
143
|
+
other failures depend on host ACLs. */
|
|
144
|
+
if (!isErrno(error, 'ENOENT')) warnSafely(warn, `spill-local: failed to inspect ancestors of root ${canonical}: ${String(error)}`)
|
|
145
|
+
return undefined
|
|
146
|
+
/* v8 ignore stop */
|
|
147
|
+
}
|
|
148
|
+
/* v8 ignore start -- Windows has no POSIX ownership or mode rejection path;
|
|
149
|
+
POSIX tests exercise both unsafe-directory conditions. */
|
|
150
|
+
if (!isTrustedDirectory(stats) || !protectedAncestors) {
|
|
151
|
+
warnSafely(warn, `spill-local: skipped unsafe root ${canonical}: expected a current-user-owned directory with protected write and ancestor permissions`)
|
|
152
|
+
return undefined
|
|
153
|
+
}
|
|
154
|
+
/* v8 ignore stop */
|
|
155
|
+
return { path: canonical, identity: rootIdentity(canonical, stats) }
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** One root to sweep, plus whether the root itself may be pruned once empty. */
|
|
159
|
+
export interface SweepRoot {
|
|
160
|
+
/** Absolute spill root to sweep. */
|
|
161
|
+
path: string
|
|
162
|
+
/**
|
|
163
|
+
* When `true`, remove the root after its empty `session-*` children are
|
|
164
|
+
* pruned. Set for DISCOVERED prior-default `dsh-spill-*` roots (one per past
|
|
165
|
+
* process — otherwise they accumulate empty forever), never for the active
|
|
166
|
+
* root the live process is still writing into. Every root prunes empty session
|
|
167
|
+
* directories; writes retry if that races their removal.
|
|
168
|
+
*/
|
|
169
|
+
pruneWhenEmpty: boolean
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** Options for {@link sweepSpillRoots} — the roots to scan, the age cutoff, and a failure sink. */
|
|
173
|
+
export interface SweepOptions {
|
|
174
|
+
/** Roots to sweep (configured/active root and/or discovered prior-default roots). */
|
|
175
|
+
roots: SweepRoot[]
|
|
176
|
+
/**
|
|
177
|
+
* Epoch-millis cutoff: a regular file is deleted when its `mtime` is strictly
|
|
178
|
+
* older than this. The caller derives it from `now - cleanupPeriodDays`, so a
|
|
179
|
+
* file written exactly at the boundary is kept (only strictly-older expires).
|
|
180
|
+
*/
|
|
181
|
+
cutoffMs: number
|
|
182
|
+
/** Where a contained filesystem failure is reported; the sweep itself never throws. */
|
|
183
|
+
warn: WarnFn
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Delete a single path, treating a concurrent-race disappearance as success.
|
|
188
|
+
* A parallel process (or another sweep) may `unlink` the same file between our
|
|
189
|
+
* scan and our own `unlink` — ENOENT then means the goal (file gone) already
|
|
190
|
+
* holds, so it is not a failure. Any other error is reported and swallowed.
|
|
191
|
+
*
|
|
192
|
+
* @param path The absolute file path to remove.
|
|
193
|
+
* @param warn Sink for a non-ENOENT failure message.
|
|
194
|
+
* @returns Resolves once the removal was attempted (never rejects).
|
|
195
|
+
*/
|
|
196
|
+
async function unlinkIdempotent(path: string, warn: WarnFn): Promise<void> {
|
|
197
|
+
try {
|
|
198
|
+
await unlink(path)
|
|
199
|
+
} catch (error: unknown) {
|
|
200
|
+
/* v8 ignore start -- reached only when a file selected for deletion (a
|
|
201
|
+
regular file that passed lstat) then fails to unlink: either it raced away
|
|
202
|
+
(ENOENT) or a permission/IO fault struck between the stat and the unlink.
|
|
203
|
+
Neither is deterministically reproducible in-process. */
|
|
204
|
+
if (isErrno(error, 'ENOENT')) return
|
|
205
|
+
warnSafely(warn, `spill-local: failed to delete ${path}: ${String(error)}`)
|
|
206
|
+
/* v8 ignore stop */
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Sweep one spill session directory: delete expired regular files, skip
|
|
212
|
+
* everything else, and report the directory empty afterward so the caller can
|
|
213
|
+
* prune it. The `dir` entry MUST be a real directory — the caller `lstat`s it
|
|
214
|
+
* first and skips a symlink, so this never follows a `session-*` symlink into a
|
|
215
|
+
* foreign tree. Inside, a symlink or any non-regular entry (socket, fifo, nested
|
|
216
|
+
* dir) is left untouched — `lstat` never follows a link, so a planted symlink
|
|
217
|
+
* can neither be deleted nor redirect the age check. Every per-entry failure is
|
|
218
|
+
* contained: one unreadable file does not abort the directory.
|
|
219
|
+
*
|
|
220
|
+
* @param dir The absolute session directory to scan (already confirmed a real dir).
|
|
221
|
+
* @param cutoffMs Files with `mtime` strictly older than this are deleted.
|
|
222
|
+
* @param warn Sink for contained filesystem failures.
|
|
223
|
+
* @returns `true` when the directory holds no entries after the sweep (a prune candidate).
|
|
224
|
+
*/
|
|
225
|
+
async function sweepSessionDir(dir: string, cutoffMs: number, warn: WarnFn): Promise<boolean> {
|
|
226
|
+
let names: string[]
|
|
227
|
+
try {
|
|
228
|
+
names = await readdir(dir)
|
|
229
|
+
} catch (error: unknown) {
|
|
230
|
+
/* v8 ignore start -- the caller lstat'd this entry and confirmed a real
|
|
231
|
+
directory just before the call, so readdir fails only when the dir races
|
|
232
|
+
away (ENOENT) or a permission/IO fault strikes in that window; not
|
|
233
|
+
deterministically reproducible. False keeps it out of the prune step. */
|
|
234
|
+
warnSafely(warn, `spill-local: failed to read ${dir}: ${String(error)}`)
|
|
235
|
+
return false
|
|
236
|
+
/* v8 ignore stop */
|
|
237
|
+
}
|
|
238
|
+
let remaining = names.length
|
|
239
|
+
for (const name of names) {
|
|
240
|
+
const path = join(dir, name)
|
|
241
|
+
let stats
|
|
242
|
+
try {
|
|
243
|
+
stats = await lstat(path)
|
|
244
|
+
} catch (error: unknown) {
|
|
245
|
+
/* v8 ignore start -- an entry that readdir just returned then fails to
|
|
246
|
+
lstat only by racing away (ENOENT) or a permission/IO fault; keep it out
|
|
247
|
+
of the deterministic test surface. */
|
|
248
|
+
if (isErrno(error, 'ENOENT')) { remaining--; continue }
|
|
249
|
+
warnSafely(warn, `spill-local: failed to stat ${path}: ${String(error)}`)
|
|
250
|
+
continue
|
|
251
|
+
/* v8 ignore stop */
|
|
252
|
+
}
|
|
253
|
+
// Only regular files expire. Symlinks and other special entries are skipped
|
|
254
|
+
// (never followed) so the sweep cannot be redirected or delete a link.
|
|
255
|
+
if (!stats.isFile()) continue
|
|
256
|
+
if (stats.mtimeMs >= cutoffMs) continue
|
|
257
|
+
await unlinkIdempotent(path, warn)
|
|
258
|
+
remaining--
|
|
259
|
+
}
|
|
260
|
+
return remaining === 0
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Best-effort one-shot cleanup: across each root, delete expired regular files
|
|
265
|
+
* under its `session-*` directories and prune every empty session directory.
|
|
266
|
+
* Only a discovered prior-default root is itself removed. Writes recreate a
|
|
267
|
+
* session directory when pruning races a local write. Every filesystem and
|
|
268
|
+
* warning-sink failure is contained, so a caller can await this during
|
|
269
|
+
* activation/disposal without it ever rejecting.
|
|
270
|
+
*
|
|
271
|
+
* @param options The roots to sweep, the age cutoff, and the failure sink.
|
|
272
|
+
* @returns Resolves when the sweep finishes (never rejects).
|
|
273
|
+
*/
|
|
274
|
+
export async function sweepSpillRoots(options: SweepOptions): Promise<void> {
|
|
275
|
+
const { cutoffMs, warn } = options
|
|
276
|
+
const roots = new Map<string, SweepRoot>()
|
|
277
|
+
for (const candidate of options.roots) {
|
|
278
|
+
const resolved = await resolveRoot(candidate.path, false, warn)
|
|
279
|
+
if (resolved === undefined) continue
|
|
280
|
+
const existing = roots.get(resolved.identity)
|
|
281
|
+
roots.set(resolved.identity, {
|
|
282
|
+
path: resolved.path,
|
|
283
|
+
pruneWhenEmpty: (existing?.pruneWhenEmpty ?? true) && candidate.pruneWhenEmpty,
|
|
284
|
+
})
|
|
285
|
+
}
|
|
286
|
+
for (const root of roots.values()) {
|
|
287
|
+
let entries: string[]
|
|
288
|
+
try {
|
|
289
|
+
entries = await readdir(root.path)
|
|
290
|
+
} catch (error: unknown) {
|
|
291
|
+
// A root that does not exist yet (no spill ever written) is the common
|
|
292
|
+
// case, not an error: ENOENT is silent, anything else is reported.
|
|
293
|
+
/* v8 ignore start -- the trusted root was resolved immediately above; a
|
|
294
|
+
read failure now requires a race or host-specific ACL fault. */
|
|
295
|
+
if (!isErrno(error, 'ENOENT')) warnSafely(warn, `spill-local: failed to read root ${root.path}: ${String(error)}`)
|
|
296
|
+
continue
|
|
297
|
+
/* v8 ignore stop */
|
|
298
|
+
}
|
|
299
|
+
// Track whether the root holds ANY entry the sweep did not fully reclaim, so
|
|
300
|
+
// a discovered prior-default root can be pruned only when nothing remains.
|
|
301
|
+
let rootEmptiable = true
|
|
302
|
+
for (const name of entries) {
|
|
303
|
+
// Only the backend's own `session-<12 hex>` directories are swept; an
|
|
304
|
+
// unrelated sibling (`session-backup`, a stray file) is left untouched and
|
|
305
|
+
// blocks pruning the root.
|
|
306
|
+
if (!SESSION_DIR_RE.test(name)) { rootEmptiable = false; continue }
|
|
307
|
+
const dir = join(root.path, name)
|
|
308
|
+
let stats
|
|
309
|
+
try {
|
|
310
|
+
// lstat the session entry itself: a `session-*` SYMLINK must never be
|
|
311
|
+
// followed (readdir/unlink through it would delete files in a foreign
|
|
312
|
+
// target). Only a real directory is swept.
|
|
313
|
+
stats = await lstat(dir)
|
|
314
|
+
} catch (error: unknown) {
|
|
315
|
+
/* v8 ignore start -- an entry readdir just returned fails to lstat only
|
|
316
|
+
by racing away (ENOENT) or a permission/IO fault; not deterministically
|
|
317
|
+
reproducible. */
|
|
318
|
+
if (!isErrno(error, 'ENOENT')) warnSafely(warn, `spill-local: failed to stat ${dir}: ${String(error)}`)
|
|
319
|
+
continue
|
|
320
|
+
/* v8 ignore stop */
|
|
321
|
+
}
|
|
322
|
+
if (!isTrustedDirectory(stats)) {
|
|
323
|
+
warnSafely(warn, `spill-local: skipped unsafe session directory ${dir}`)
|
|
324
|
+
rootEmptiable = false
|
|
325
|
+
continue
|
|
326
|
+
}
|
|
327
|
+
const empty = await sweepSessionDir(dir, cutoffMs, warn)
|
|
328
|
+
if (!empty) { rootEmptiable = false; continue }
|
|
329
|
+
try {
|
|
330
|
+
await rmdir(dir)
|
|
331
|
+
} catch (error: unknown) {
|
|
332
|
+
/* v8 ignore start -- prune runs only on a dir observed empty; a failure
|
|
333
|
+
here means a concurrent writer added a file (ENOTEMPTY) or a
|
|
334
|
+
permission/IO fault struck — both are races outside deterministic
|
|
335
|
+
in-process testing. */
|
|
336
|
+
rootEmptiable = false
|
|
337
|
+
if (!isErrno(error, 'ENOENT') && !isErrno(error, 'ENOTEMPTY')) {
|
|
338
|
+
warnSafely(warn, `spill-local: failed to prune ${dir}: ${String(error)}`)
|
|
339
|
+
}
|
|
340
|
+
/* v8 ignore stop */
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
// A discovered prior-default root (one per past process) is removed once its
|
|
344
|
+
// last session dir is gone — otherwise empty roots accumulate forever and
|
|
345
|
+
// every future startup rescans them. The active root itself is never pruned.
|
|
346
|
+
if (root.pruneWhenEmpty && rootEmptiable) {
|
|
347
|
+
try {
|
|
348
|
+
await rmdir(root.path)
|
|
349
|
+
} catch (error: unknown) {
|
|
350
|
+
/* v8 ignore start -- prune runs only on a root whose every child was
|
|
351
|
+
reclaimed; a failure here means a concurrent writer added a fresh
|
|
352
|
+
spill after our scan (ENOTEMPTY) or removed the root already (ENOENT)
|
|
353
|
+
or a permission/IO fault struck — all races outside deterministic
|
|
354
|
+
in-process testing. */
|
|
355
|
+
if (!isErrno(error, 'ENOENT') && !isErrno(error, 'ENOTEMPTY')) {
|
|
356
|
+
warnSafely(warn, `spill-local: failed to prune root ${root.path}: ${String(error)}`)
|
|
357
|
+
}
|
|
358
|
+
/* v8 ignore stop */
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* Discover prior default spill roots: the `dsh-spill-<6 chars>` directories
|
|
366
|
+
* directly under `base` (the OS tmpdir) that earlier default-root runs created.
|
|
367
|
+
* A long-lived deployment
|
|
368
|
+
* with a configured root will find none; a series of default-root runs
|
|
369
|
+
* accumulates one per process, so the startup sweep reclaims them all. Matching
|
|
370
|
+
* is the EXACT `mkdtemp` shape (see {@link DEFAULT_ROOT_RE}), not the bare
|
|
371
|
+
* prefix, so an unrelated `dsh-spill-test-*` fixture or a foreign
|
|
372
|
+
* differently-shaped directory is never swept; symlinks and non-directories are
|
|
373
|
+
* excluded too — only real directories the backend could have created.
|
|
374
|
+
*
|
|
375
|
+
* @param warn Sink for a failure reading `base` (returns `[]` on failure).
|
|
376
|
+
* @param base The directory to scan; defaults to the OS tmpdir (a test seam).
|
|
377
|
+
* @returns Absolute paths of the discovered default roots (possibly empty).
|
|
378
|
+
*/
|
|
379
|
+
async function discoverDefaultRootRecords(warn: WarnFn, base: string): Promise<ResolvedRoot[]> {
|
|
380
|
+
let entries: string[]
|
|
381
|
+
try {
|
|
382
|
+
entries = await readdir(base)
|
|
383
|
+
} catch (error: unknown) {
|
|
384
|
+
warnSafely(warn, `spill-local: failed to scan ${base} for default roots: ${String(error)}`)
|
|
385
|
+
return []
|
|
386
|
+
}
|
|
387
|
+
const roots: ResolvedRoot[] = []
|
|
388
|
+
for (const name of entries) {
|
|
389
|
+
if (!DEFAULT_ROOT_RE.test(name)) continue
|
|
390
|
+
const path = join(base, name)
|
|
391
|
+
const resolved = await resolveRoot(path, false, warn)
|
|
392
|
+
if (resolved !== undefined) roots.push(resolved)
|
|
393
|
+
}
|
|
394
|
+
return roots
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* Discover trusted prior default roots below the OS temporary directory.
|
|
399
|
+
*
|
|
400
|
+
* @param warn Sink for contained discovery failures.
|
|
401
|
+
* @param base Directory to scan; defaults to the OS temporary directory.
|
|
402
|
+
* @returns Canonical paths of trusted default roots.
|
|
403
|
+
*/
|
|
404
|
+
export async function discoverDefaultRoots(warn: WarnFn, base: string = tmpdir()): Promise<string[]> {
|
|
405
|
+
return (await discoverDefaultRootRecords(warn, base)).map(root => root.path)
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* Gather and de-duplicate the trusted roots for one startup sweep. The active
|
|
410
|
+
* configured path may be a symlink; its resolved identity overrides a matching
|
|
411
|
+
* discovered root so the live target is never marked prunable.
|
|
412
|
+
*
|
|
413
|
+
* @param activeRoot Active configured root.
|
|
414
|
+
* @param warn Sink for contained inspection failures.
|
|
415
|
+
* @param defaultRootsBase Directory holding prior default roots.
|
|
416
|
+
* @returns Trusted roots with the active identity marked non-prunable.
|
|
417
|
+
*/
|
|
418
|
+
export async function gatherSweepRoots(
|
|
419
|
+
activeRoot: string,
|
|
420
|
+
warn: WarnFn,
|
|
421
|
+
defaultRootsBase: string = tmpdir(),
|
|
422
|
+
): Promise<SweepRoot[]> {
|
|
423
|
+
const [discovered, active] = await Promise.all([
|
|
424
|
+
discoverDefaultRootRecords(warn, defaultRootsBase),
|
|
425
|
+
resolveRoot(activeRoot, true, warn),
|
|
426
|
+
])
|
|
427
|
+
const roots = new Map<string, SweepRoot>()
|
|
428
|
+
for (const root of discovered) roots.set(root.identity, { path: root.path, pruneWhenEmpty: true })
|
|
429
|
+
if (active !== undefined) roots.set(active.identity, { path: active.path, pruneWhenEmpty: false })
|
|
430
|
+
return [...roots.values()]
|
|
431
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `LocalSpillStore`: the host-filesystem implementation of the
|
|
3
|
+
* `@deepseek-ai/dsh-spill` storage seam. Persists oversized text to a
|
|
4
|
+
* private, session-scoped file (see `./store.ts` for the traversal-safe naming
|
|
5
|
+
* and exclusive owner-only write) and returns a path locator plus local
|
|
6
|
+
* read/grep retrieval guidance. After activation it runs one best-effort
|
|
7
|
+
* startup sweep that reclaims spill files older than `cleanupPeriodDays`.
|
|
8
|
+
*
|
|
9
|
+
* @module @deepseek-ai/dsh-spill-local
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { Context } from '@deepseek-ai/cordis'
|
|
13
|
+
import { resolve } from 'node:path'
|
|
14
|
+
import { tmpdir } from 'node:os'
|
|
15
|
+
import z from '@deepseek-ai/schemastery'
|
|
16
|
+
import { SpillLocator, SpillStore } from '@deepseek-ai/dsh-spill'
|
|
17
|
+
import type { SaveTextSpill, SpillRef } from '@deepseek-ai/dsh-spill'
|
|
18
|
+
import { gatherSweepRoots, sweepSpillRoots } from './cleanup.ts'
|
|
19
|
+
import type { SweepRoot, WarnFn } from './cleanup.ts'
|
|
20
|
+
import { privateRoot, saveTextFile } from './store.ts'
|
|
21
|
+
|
|
22
|
+
export { discoverDefaultRoots, sweepSpillRoots } from './cleanup.ts'
|
|
23
|
+
export type { SweepOptions, SweepRoot, WarnFn } from './cleanup.ts'
|
|
24
|
+
export { DEFAULT_ROOT_PREFIX, encodeSegment, isErrno, privateRoot, saveTextFile, sessionDir } from './store.ts'
|
|
25
|
+
export type { SavedText, SaveTextOptions } from './store.ts'
|
|
26
|
+
|
|
27
|
+
/** Milliseconds in one day — converts the `cleanupPeriodDays` config to the sweep cutoff. */
|
|
28
|
+
const MS_PER_DAY = 24 * 60 * 60 * 1000
|
|
29
|
+
|
|
30
|
+
/** Plugin config (all optional — `static Config` supplies the defaults). */
|
|
31
|
+
export interface Config {
|
|
32
|
+
/**
|
|
33
|
+
* Root directory for spill files. Omitted uses a lazily-created private
|
|
34
|
+
* (0700) per-process directory under the OS temp dir — the safe default for
|
|
35
|
+
* a local deployment. Set it to keep spill files under a known location.
|
|
36
|
+
*/
|
|
37
|
+
root?: string
|
|
38
|
+
/**
|
|
39
|
+
* Age in days after which a spill file is eligible for the one-shot startup
|
|
40
|
+
* cleanup sweep. Defaults to `30`; `0` disables cleanup entirely. Files whose
|
|
41
|
+
* `mtime` is strictly older than the cutoff are deleted and emptied
|
|
42
|
+
* directories are pruned; fresh files, symlinks, and unrelated entries are
|
|
43
|
+
* left untouched. On POSIX, cleanup skips roots and session directories that
|
|
44
|
+
* another local user could modify or replace. Retention is deliberate — a
|
|
45
|
+
* resumed or forked session may still reference an older locator until it
|
|
46
|
+
* ages out.
|
|
47
|
+
*/
|
|
48
|
+
cleanupPeriodDays?: number
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** The shape after schemastery applied the defaults. */
|
|
52
|
+
type ResolvedConfig = Required<Omit<Config, 'root'>> & Pick<Config, 'root'>
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Local-filesystem spill backend. Files land under `<root>/session-<hash>/…`
|
|
56
|
+
* with unpredictable names, an exclusive owner-only (0600) write, and a private
|
|
57
|
+
* (0700) root — a spilled tool result must not be readable by other local users
|
|
58
|
+
* or redirectable via a planted symlink.
|
|
59
|
+
*
|
|
60
|
+
* After activation it launches ONE best-effort cleanup sweep (see
|
|
61
|
+
* {@link cleanupPeriodDays}) that reclaims expired spill files without delaying
|
|
62
|
+
* service availability; the sweep is owned by the plugin fiber and awaited
|
|
63
|
+
* during disposal, so a fiber unload never returns before it quiesces.
|
|
64
|
+
*/
|
|
65
|
+
export class LocalSpillStore extends SpillStore {
|
|
66
|
+
static Config: z<Config> = z.object({
|
|
67
|
+
root: z.string(),
|
|
68
|
+
cleanupPeriodDays: z.number().step(1).min(0).default(30),
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
/** Resolved absolute spill root (config `root`, else the private default), fixed at construction. */
|
|
72
|
+
readonly root: string
|
|
73
|
+
|
|
74
|
+
/** Validated config (schemastery applied the `cleanupPeriodDays` default before construction). */
|
|
75
|
+
readonly config: ResolvedConfig
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* The in-flight (or settled) startup cleanup sweep. Held so disposal can await
|
|
79
|
+
* it; `undefined` when cleanup is disabled (`cleanupPeriodDays === 0`).
|
|
80
|
+
*/
|
|
81
|
+
private cleanup: Promise<void> | undefined
|
|
82
|
+
|
|
83
|
+
constructor(ctx: Context, config: Config) {
|
|
84
|
+
super(ctx)
|
|
85
|
+
// schemastery (static Config) has already filled `cleanupPeriodDays`; the
|
|
86
|
+
// cast records that runtime fact for exactOptionalPropertyTypes.
|
|
87
|
+
this.config = config as ResolvedConfig
|
|
88
|
+
this.root = config.root !== undefined ? resolve(config.root) : privateRoot()
|
|
89
|
+
|
|
90
|
+
// One best-effort startup sweep, owned by the fiber. The generator body runs
|
|
91
|
+
// at activation but does NOT await the sweep — it launches it and yields an
|
|
92
|
+
// async disposer that awaits the SAME promise, so service availability is
|
|
93
|
+
// never delayed yet a fiber unload reaches quiescence (no sweep I/O outlives
|
|
94
|
+
// the fiber). Disabled (`cleanupPeriodDays === 0`) yields a no-op disposer.
|
|
95
|
+
ctx.effect(function* (this: LocalSpillStore) {
|
|
96
|
+
if (this.config.cleanupPeriodDays > 0) {
|
|
97
|
+
const warn: WarnFn = (message) => { this.ctx.logger.warn(message) }
|
|
98
|
+
this.cleanup = this.runCleanup(warn)
|
|
99
|
+
}
|
|
100
|
+
yield async () => { await this.cleanup }
|
|
101
|
+
}.bind(this), 'spill-local cleanup sweep')
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Run the one-shot cleanup: gather the roots to sweep (see {@link gatherRoots})
|
|
106
|
+
* and sweep all of them at the age cutoff. Best-effort —
|
|
107
|
+
* {@link sweepSpillRoots} contains every filesystem failure, so this never
|
|
108
|
+
* rejects and cannot fail activation or a concurrent spill write.
|
|
109
|
+
*
|
|
110
|
+
* @param warn - sink for a contained filesystem failure.
|
|
111
|
+
* @returns Resolves when the sweep finishes (never rejects).
|
|
112
|
+
*/
|
|
113
|
+
private async runCleanup(warn: WarnFn): Promise<void> {
|
|
114
|
+
const cutoffMs = Date.now() - this.config.cleanupPeriodDays * MS_PER_DAY
|
|
115
|
+
const roots = await this.gatherRoots(warn)
|
|
116
|
+
await sweepSpillRoots({ roots, cutoffMs, warn })
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* The roots the startup sweep covers: each discovered prior-default
|
|
121
|
+
* `dsh-spill-*` temp root (see {@link discoverDefaultRoots}), pruned when
|
|
122
|
+
* emptied, plus the active/configured root, which is never itself pruned while
|
|
123
|
+
* the live process may write into it. Empty session directories are pruned in
|
|
124
|
+
* every root. Filesystem identity de-duplicates aliases before the active root
|
|
125
|
+
* overrides a discovered match as non-prunable. A test overrides this to
|
|
126
|
+
* inject an isolated root set — and, being the sweep's one async gather point,
|
|
127
|
+
* to hold the sweep open across a disposal for the quiescence check; it is a
|
|
128
|
+
* test seam, not a deployment knob.
|
|
129
|
+
*
|
|
130
|
+
* @param warn - sink for a contained discovery failure.
|
|
131
|
+
* @returns The roots to sweep, each flagged for prune-when-empty.
|
|
132
|
+
*/
|
|
133
|
+
protected async gatherRoots(warn: WarnFn): Promise<SweepRoot[]> {
|
|
134
|
+
return gatherSweepRoots(this.root, warn, this.defaultRootsBase())
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* The directory scanned for prior default `dsh-spill-*` roots — the OS tmpdir,
|
|
139
|
+
* where {@link privateRoot} creates them (accumulation only happens there). A
|
|
140
|
+
* test overrides this to point discovery at an isolated fixture instead of the
|
|
141
|
+
* real tmpdir; it is a test seam, not a deployment knob.
|
|
142
|
+
*
|
|
143
|
+
* @returns The base directory to scan for default spill roots.
|
|
144
|
+
*/
|
|
145
|
+
protected defaultRootsBase(): string {
|
|
146
|
+
return tmpdir()
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
async saveText(input: SaveTextSpill): Promise<SpillRef> {
|
|
150
|
+
const saved = await saveTextFile({
|
|
151
|
+
root: this.root,
|
|
152
|
+
sessionId: input.owner.sessionId,
|
|
153
|
+
suggestedName: input.suggestedName,
|
|
154
|
+
content: input.content,
|
|
155
|
+
})
|
|
156
|
+
return {
|
|
157
|
+
locator: SpillLocator(saved.path),
|
|
158
|
+
bytes: saved.bytes,
|
|
159
|
+
retrievalHint: 'Use read with offset/limit, or grep this path to search within it.',
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export default LocalSpillStore
|
package/src/store.ts
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cordis-free storage mechanics for the local spill backend: private
|
|
3
|
+
* session-scoped directory selection, safe-name derivation, path-traversal
|
|
4
|
+
* protection, and the exclusive owner-only write.
|
|
5
|
+
*
|
|
6
|
+
* @module @deepseek-ai/dsh-spill-local/store
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { createHash, randomBytes } from 'node:crypto'
|
|
10
|
+
import { mkdtempSync } from 'node:fs'
|
|
11
|
+
import { mkdir, open } from 'node:fs/promises'
|
|
12
|
+
import { join } from 'node:path'
|
|
13
|
+
import { tmpdir } from 'node:os'
|
|
14
|
+
|
|
15
|
+
/** Prefix shared by default-root creation and startup discovery. */
|
|
16
|
+
export const DEFAULT_ROOT_PREFIX = 'dsh-spill-'
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Test a caught value for a Node system error code.
|
|
20
|
+
*
|
|
21
|
+
* @param error The caught value.
|
|
22
|
+
* @param code The expected system error code.
|
|
23
|
+
* @returns Whether the code matches.
|
|
24
|
+
*/
|
|
25
|
+
export function isErrno(error: unknown, code: string): boolean {
|
|
26
|
+
return error instanceof Error && (error as NodeJS.ErrnoException).code === code
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
let defaultRoot: string | undefined
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Return the lazily-created private per-process spill root.
|
|
33
|
+
*
|
|
34
|
+
* @returns The private root path.
|
|
35
|
+
*/
|
|
36
|
+
export function privateRoot(): string {
|
|
37
|
+
defaultRoot ??= mkdtempSync(join(tmpdir(), DEFAULT_ROOT_PREFIX))
|
|
38
|
+
return defaultRoot
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Spill keeps its empty-name policy local so storage backends stay decoupled.
|
|
42
|
+
/* jscpd:ignore-start */
|
|
43
|
+
/**
|
|
44
|
+
* Encode an arbitrary string as one safe path segment, injectively over ALL JS
|
|
45
|
+
* (UTF-16) strings. A session id / suggested name is untrusted input, so this
|
|
46
|
+
* neutralizes `../`, absolute paths, NUL, and separators before any filesystem
|
|
47
|
+
* use. Each code unit is kept literal (`[A-Za-z0-9._-]`, minus `~`) or escaped
|
|
48
|
+
* as `~XXXX`; `~` is itself escaped, so the mapping is reversible and distinct
|
|
49
|
+
* inputs never collide. The whole-segment tokens `.`/`..` are escaped so they
|
|
50
|
+
* can never traverse. An empty string encodes to `~` (never an empty segment).
|
|
51
|
+
*
|
|
52
|
+
* @param raw Untrusted text.
|
|
53
|
+
* @returns One injective filesystem-safe path segment.
|
|
54
|
+
*/
|
|
55
|
+
export function encodeSegment(raw: string): string {
|
|
56
|
+
if (raw.length === 0) return '~'
|
|
57
|
+
if (raw === '.') return '~002E'
|
|
58
|
+
if (raw === '..') return '~002E~002E'
|
|
59
|
+
let out = ''
|
|
60
|
+
for (let i = 0; i < raw.length; i++) {
|
|
61
|
+
const code = raw.charCodeAt(i)
|
|
62
|
+
const ch = String.fromCharCode(code)
|
|
63
|
+
out += ch !== '~' && /^[A-Za-z0-9._-]$/.test(ch)
|
|
64
|
+
? ch
|
|
65
|
+
: '~' + code.toString(16).toUpperCase().padStart(4, '0')
|
|
66
|
+
}
|
|
67
|
+
return out
|
|
68
|
+
}
|
|
69
|
+
/* jscpd:ignore-end */
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Derive the stable session-scoped directory under a spill root.
|
|
73
|
+
*
|
|
74
|
+
* @param root The spill root.
|
|
75
|
+
* @param sessionId The owning session id.
|
|
76
|
+
* @returns The stable session-scoped directory.
|
|
77
|
+
*/
|
|
78
|
+
export function sessionDir(root: string, sessionId: string): string {
|
|
79
|
+
const hash = createHash('sha256').update(sessionId).digest('hex').slice(0, 12)
|
|
80
|
+
return join(root, `session-${hash}`)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Inputs needed to save a local spill file. */
|
|
84
|
+
export interface SaveTextOptions {
|
|
85
|
+
/** Spill root. */
|
|
86
|
+
root: string
|
|
87
|
+
/** Owning session id. */
|
|
88
|
+
sessionId: string
|
|
89
|
+
/** Caller-suggested filename. */
|
|
90
|
+
suggestedName: string
|
|
91
|
+
/** Full text to persist. */
|
|
92
|
+
content: string
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** A written spill file. */
|
|
96
|
+
export interface SavedText {
|
|
97
|
+
/** Absolute saved path. */
|
|
98
|
+
path: string
|
|
99
|
+
/** UTF-8 content length. */
|
|
100
|
+
bytes: number
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Write text to a fresh 0600 file below its private session directory.
|
|
105
|
+
* @param options The save request.
|
|
106
|
+
* @returns The saved path and UTF-8 byte length.
|
|
107
|
+
*/
|
|
108
|
+
export async function saveTextFile(options: SaveTextOptions): Promise<SavedText> {
|
|
109
|
+
const dir = sessionDir(options.root, options.sessionId)
|
|
110
|
+
const path = join(dir, `${randomBytes(6).toString('hex')}-${encodeSegment(options.suggestedName)}`)
|
|
111
|
+
let handle
|
|
112
|
+
for (;;) {
|
|
113
|
+
await mkdir(dir, { recursive: true, mode: 0o700 })
|
|
114
|
+
try {
|
|
115
|
+
handle = await open(path, 'wx', 0o600)
|
|
116
|
+
break
|
|
117
|
+
} catch (error: unknown) {
|
|
118
|
+
/* v8 ignore start -- requires another process to remove the directory
|
|
119
|
+
between mkdir and open, or an external permission/IO race. */
|
|
120
|
+
if (isErrno(error, 'ENOENT')) continue
|
|
121
|
+
throw error
|
|
122
|
+
/* v8 ignore stop */
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
try {
|
|
126
|
+
await handle.writeFile(options.content)
|
|
127
|
+
} finally {
|
|
128
|
+
await handle.close()
|
|
129
|
+
}
|
|
130
|
+
return { path, bytes: Buffer.byteLength(options.content, 'utf8') }
|
|
131
|
+
}
|