@leiyi-works/dsh-session-tmpdir 0.9.6 → 0.9.8
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 +4 -0
- package/index.js +42 -13
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -223,3 +223,7 @@ v0.9.4 变更(2026-11-16):**命令守卫减少误拦**(不影响正常
|
|
|
223
223
|
v0.9.5 变更(2026-11-16):**复制/移动类命令不再判源路径**。`Copy-Item`、`Move-Item`、`cp`、`mv`、`rsync`、`scp`、`robocopy`、`xcopy`、`Expand-Archive`、`Compress-Archive` 的源参数是"读",只有目标才是写落点:有 `-Destination`/`-DestinationPath`/`-Dest`/`-Target` 时只判该目标,否则位置参数形式下判**最后一个路径**(目标),其余按源跳过。这样"源文件缺失 + 检查/写入已存在目标"的命令不会再被误拦;目标新建未审批仍照常拦截。
|
|
224
224
|
|
|
225
225
|
v0.9.6 变更(2026-11-16):**`Start-Process` 不再默认算写命令**。它只是启动外部程序,参数里的路径通常是程序要打开的文件(读)。现在只有带 `-RedirectStandardOutput` / `-RedirectStandardError`(真正写文件)时才参与路径判定;`Start-Process notepad C:\缺失.txt` 这类不再误拦。
|
|
226
|
+
|
|
227
|
+
v0.9.7 变更(2026-11-16):白名单曾改为按机器名分文件(`session-tmpdir-approvals-<机器名>.json`),意图是避免跨机同步互相覆盖。**该前提判断有误**,见 0.9.8。
|
|
228
|
+
|
|
229
|
+
v0.9.8 变更(2026-11-16):**白名单恢复通用文件名**。核对云端同步源码(`sync.js`:`data/session-tmpdir-*` 直接跳过)后确认:白名单文件本来就**不参与云端同步**,因此不会跨机覆盖、也不会每台机器多出别的机器的文件。改回固定路径 `<DSH_HOME>/data/session-tmpdir-approvals.json`(每台机器只有这一个文件);0.9.7 的按机器名文件只作为**读取回退**,写入统一回到通用文件。白名单语义:本机有效、同机重启后保留、跨机不共享(本来也不同步)。
|
package/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from 'node:fs'
|
|
2
2
|
import { appendFile, mkdir, readdir, readFile, rename, rm, stat, writeFile } from 'node:fs/promises'
|
|
3
|
-
import { homedir, tmpdir } from 'node:os'
|
|
3
|
+
import { homedir, hostname, tmpdir } from 'node:os'
|
|
4
4
|
import { basename, dirname, isAbsolute, join, parse, resolve } from 'node:path'
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -1305,24 +1305,53 @@ export function resolveDshHome() { const fromEnv = process.env.DSH_HOME && proc
|
|
|
1305
1305
|
/** v0.9: persisted long-term whitelist file (exact files + directory prefixes). */
|
|
1306
1306
|
const APPROVALS_FILE = 'session-tmpdir-approvals.json'
|
|
1307
1307
|
|
|
1308
|
-
/**
|
|
1308
|
+
/**
|
|
1309
|
+
* 白名单是本机文件:云端同步的排除名单包含 `data/session-tmpdir-*`
|
|
1310
|
+
* (cloud-sync: `rel.slice(5).startsWith('session-tmpdir-')` 直接跳过),
|
|
1311
|
+
* 因此固定用通用文件名即可,不会跨机同步、不会按机器产生多份文件。
|
|
1312
|
+
*/
|
|
1313
|
+
function machineApprovalsPathV097() {
|
|
1314
|
+
let raw = ''
|
|
1315
|
+
try {
|
|
1316
|
+
raw = String(hostname() ?? '')
|
|
1317
|
+
} catch {
|
|
1318
|
+
raw = ''
|
|
1319
|
+
}
|
|
1320
|
+
const safe =
|
|
1321
|
+
raw
|
|
1322
|
+
.toLowerCase()
|
|
1323
|
+
.replace(/[^a-z0-9._-]+/g, '-')
|
|
1324
|
+
.replace(/^-+|-+$/g, '')
|
|
1325
|
+
.slice(0, 40) || 'machine'
|
|
1326
|
+
return join(resolveDshHome(), 'data', `session-tmpdir-approvals-${safe}.json`)
|
|
1327
|
+
}
|
|
1328
|
+
|
|
1329
|
+
/** Absolute path of the whitelist store (machine-local; never cloud-synced). */
|
|
1309
1330
|
export function approvalsFilePath() {
|
|
1310
1331
|
return join(resolveDshHome(), 'data', APPROVALS_FILE)
|
|
1311
1332
|
}
|
|
1312
1333
|
|
|
1334
|
+
/** v0.9.8: 0.9.7 曾按机器名分文件;仅作读取回退,写入统一回到通用文件。 */
|
|
1335
|
+
export function legacyApprovalsFilePath() {
|
|
1336
|
+
return machineApprovalsPathV097()
|
|
1337
|
+
}
|
|
1338
|
+
|
|
1313
1339
|
/** Load the whitelist; a missing or corrupt file means an empty whitelist. */
|
|
1314
1340
|
export function loadApprovalsState() {
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1341
|
+
for (const file of [approvalsFilePath(), legacyApprovalsFilePath()]) {
|
|
1342
|
+
try {
|
|
1343
|
+
const parsed = JSON.parse(readFileSync(file, 'utf8'))
|
|
1344
|
+
const entries = Array.isArray(parsed?.entries)
|
|
1345
|
+
? parsed.entries.filter(
|
|
1346
|
+
(entry) => entry && typeof entry.path === 'string' && entry.path.trim() && typeof entry.sessionId === 'string',
|
|
1347
|
+
)
|
|
1348
|
+
: []
|
|
1349
|
+
return { version: 1, entries }
|
|
1350
|
+
} catch {
|
|
1351
|
+
// try the next candidate
|
|
1352
|
+
}
|
|
1325
1353
|
}
|
|
1354
|
+
return { version: 1, entries: [] }
|
|
1326
1355
|
}
|
|
1327
1356
|
|
|
1328
1357
|
/** Persist the whitelist; a failure only warns (the in-memory copy still works). */
|
|
@@ -2197,7 +2226,7 @@ export function apply(ctx, config) {
|
|
|
2197
2226
|
'',
|
|
2198
2227
|
'### Whitelist panel',
|
|
2199
2228
|
'',
|
|
2200
|
-
`Every approval is stored
|
|
2229
|
+
`Every approval is stored in the machine-local file \`<DSH_HOME>/data/session-tmpdir-approvals.json\` (files under \`data/session-tmpdir-*\` are excluded from cloud sync, so nothing is shared across machines) and shown in the left sidebar panel 「临时目录」 (display + remove only). Approvals survive a restart of the same session; entries whose session was deleted are pruned by the cleanup tick, and entries whose target no longer exists are pruned when the panel refreshes.`,
|
|
2201
2230
|
].join('\n'),
|
|
2202
2231
|
}),
|
|
2203
2232
|
)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leiyi-works/dsh-session-tmpdir",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.8",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Per-session task temp folder with a long-term write guard. v0.9 (方案3): creating a new file outside _tmp requires the user's approval (per file by default, per directory with mode=dir), overwriting an existing file is allowed without asking, every write channel is guarded (write/edit, shell including ffmpeg/pandoc/Export-*/IO APIs, publish copies, code runtimes, unknown tools), and the persisted whitelist is shown in a left-sidebar panel「临时目录」 where entries can be removed. Every session also gets _tmp/<session title>/ in its working directory, cleaned 7 days after the session is deleted; the same tick reclaims the attachment store.",
|
|
6
6
|
"exports": {
|