@leiyi-works/dsh-session-tmpdir 0.9.12 → 0.10.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 +8 -0
- package/client.js +5 -2
- package/index.js +78 -14
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -245,3 +245,11 @@ v0.9.10 变更(2026-11-16):**面板默认只显示当前机器的白名单
|
|
|
245
245
|
v0.9.11 变更(2026-11-16):**修复 0.9.10 客户端语法错误**(`client.js` 少一个括号,面板无法加载)。面板渲染重写为更简单的数组结构(同样的功能:右侧边栏标签页、5 秒自动刷新、当前机器白名单展示/移除、目标不存在标记)。
|
|
246
246
|
|
|
247
247
|
v0.9.12 变更(2026-11-16):文案澄清——面板**默认只显示当前机器的白名单**(不是“机器隔离”)。界面过滤只是显示策略;白名单判定仍按绝对路径,其他机器同步来的条目如果路径在本机存在,仍然会生效。
|
|
248
|
+
|
|
249
|
+
v0.10.0 变更(2026-11-16):**白名单条目的路径可移植 + 全机队统一展示**(“N 台机器像一个 DSH”)。
|
|
250
|
+
|
|
251
|
+
1. **可移植路径**:home 下的目标在写入时存成 `~/...`(例如 `~/Desktop/x.exe`);读取/匹配/回收时按**当前机器**的 home 展开。工作区等不在 home 下的路径仍存绝对路径(各机一致即可共享)。
|
|
252
|
+
2. **一次批准、多机生效**:A 机批准 `~/Desktop/x.exe` → 同步后 B 机展开成 `C:\Users\<B用户名>\Desktop\x.exe`,同样免审批(前提是该逻辑位置在 B 机也有意义)。
|
|
253
|
+
3. **界面去掉机器过滤**:面板显示整份共享白名单(不是“本机专属”);**本机没有的路径**标记「本机无此路径」(可能存在于其他机器),不会因此自动删除;可移植路径额外标「可移植」。
|
|
254
|
+
4. 旧条目(绝对路径、home 下)在加载时自动归一为 `~/...` 并落盘;墓碑/合并/按机器回收逻辑不变。
|
|
255
|
+
5. 仍无法自动统一:盘符/工作区路径不同、机器独有路径——这类按各自绝对路径判定。
|
package/client.js
CHANGED
|
@@ -179,7 +179,10 @@ window.__ModuleLoader__.load({
|
|
|
179
179
|
const rowNodes = rows.map((row) => {
|
|
180
180
|
const meta = [
|
|
181
181
|
h('span', { key: 'kind', style: styles.tag }, row.kind === 'dir' ? '目录' : '文件'),
|
|
182
|
-
row.exists === false ? h('span', { key: 'missing', style: styles.tagWarn }, '
|
|
182
|
+
row.exists === false ? h('span', { key: 'missing', style: styles.tagWarn }, '本机无此路径') : null,
|
|
183
|
+
typeof row.portable === 'string' && row.portable.startsWith('~')
|
|
184
|
+
? h('span', { key: 'portable', style: styles.tag }, '可移植')
|
|
185
|
+
: null,
|
|
183
186
|
h('span', { key: 'time', style: styles.meta }, `同意于 ${fmtTime(row.approvedAt) || '未知时间'}`),
|
|
184
187
|
row.sessionId
|
|
185
188
|
? h(
|
|
@@ -217,7 +220,7 @@ window.__ModuleLoader__.load({
|
|
|
217
220
|
h(
|
|
218
221
|
'p',
|
|
219
222
|
{ style: styles.hint },
|
|
220
|
-
'
|
|
223
|
+
'白名单对所有机器共用一份:home 下的路径按可移植路径(`~/`)同步、在本机展开;**本机没有的路径**会标记出来(可能存在于其他机器),不会自动删除。临时目录外**新建**产物要先经过你同意;**改写已存在文件**直接放行。',
|
|
221
224
|
),
|
|
222
225
|
metaLine,
|
|
223
226
|
h(
|
package/index.js
CHANGED
|
@@ -138,6 +138,15 @@ const DOWNLOAD_WRITE_PATTERN =
|
|
|
138
138
|
/\bInvoke-(?:WebRequest|RestMethod)\b[^;|&\n]*\s-(?:OutFile|OutFileList)\b|\bcurl\b[^;|&\n]*\s(?:-o|--output|-O)\b|\bwget\b[^;|&\n]*\s(?:-O|--output-document)\b|\bStart-Process\b[^;|&\n]*\s-(?:RedirectStandardOutput|RedirectStandardError)\b/i
|
|
139
139
|
/** v0.9.4: judge a script statement by statement, so a read-only segment cannot be misread as a write. */
|
|
140
140
|
const COMMAND_SEGMENT_SPLIT = /(?:\r?\n|;|&&|\|\||\|)+/
|
|
141
|
+
/**
|
|
142
|
+
* v0.10.1: invoking a code interpreter (`node`, `python`, `perl`, `ruby`) is not itself a
|
|
143
|
+
* file write. Such a segment is judged by the code static scan (write signals paired with
|
|
144
|
+
* nearby path literals) instead of blaming every absolute path in the command text.
|
|
145
|
+
*/
|
|
146
|
+
const INTERPRETER_SEGMENT_PATTERN = /(?:^|[\\/\s"'=])(?:node(?:\.exe)?|python3?(?:\.exe)?|perl|ruby)\b/i
|
|
147
|
+
/** Create verbs excluding the interpreters above (other real write commands in the same segment). */
|
|
148
|
+
const OTHER_CREATE_VERB_PATTERN =
|
|
149
|
+
/\b(?:New-Item|mkdir|md(?=\s)|Copy-Item|Move-Item|Set-Content|Add-Content|Out-File|Expand-Archive|git\s+clone|robocopy|tar|unzip|7z|touch|tee|New-ItemProperty|cp|mv|ln|install|dd|rsync|scp|truncate|sed)\b/i
|
|
141
150
|
/**
|
|
142
151
|
* v0.9.5: copy-like commands read their source arguments — only the destination is a
|
|
143
152
|
* write target. A missing source must never make the guard blame the destination check.
|
|
@@ -531,6 +540,21 @@ export function longtermCommandGuardReason(command, workspaceRoot, options = {})
|
|
|
531
540
|
redirectTokens.add(token)
|
|
532
541
|
}
|
|
533
542
|
const hasRedirect = redirectTokens.size > 0
|
|
543
|
+
// v0.10.1:只调用解释器(node/python/perl/ruby)的段落用“代码静态扫描”判定,
|
|
544
|
+
// 不把命令文本里的任意绝对路径当成写目标(否则字符串里的示例路径会误伤)。
|
|
545
|
+
if (
|
|
546
|
+
!hasRedirect &&
|
|
547
|
+
INTERPRETER_SEGMENT_PATTERN.test(segment) &&
|
|
548
|
+
!OTHER_CREATE_VERB_PATTERN.test(segment) &&
|
|
549
|
+
!WRITE_PROGRAM_PATTERN.test(segment) &&
|
|
550
|
+
!DOWNLOAD_WRITE_PATTERN.test(segment)
|
|
551
|
+
) {
|
|
552
|
+
return codeToolGuardReason(segment, base, {
|
|
553
|
+
...classifyOptions,
|
|
554
|
+
guardOutsideWorkspace,
|
|
555
|
+
skipInside,
|
|
556
|
+
})
|
|
557
|
+
}
|
|
534
558
|
if (
|
|
535
559
|
!hasRedirect &&
|
|
536
560
|
!CREATE_VERB_PATTERN.test(segment) &&
|
|
@@ -1345,13 +1369,44 @@ export function legacyApprovalsFilePath() {
|
|
|
1345
1369
|
return legacyApprovalsFilePaths()[0]
|
|
1346
1370
|
}
|
|
1347
1371
|
|
|
1348
|
-
/**
|
|
1372
|
+
/**
|
|
1373
|
+
* v0.10.0:白名单条目路径可移植 —— home 下的路径存成 `~/...`,换机后按各自 home 展开;
|
|
1374
|
+
* 工作区等不在 home 下的路径仍存绝对路径(各机路径一致即可共享)。
|
|
1375
|
+
*/
|
|
1376
|
+
export function toPortableApprovalPath(target) {
|
|
1377
|
+
try {
|
|
1378
|
+
const abs = resolve(String(target ?? ''))
|
|
1379
|
+
const home = resolve(homedir())
|
|
1380
|
+
if (samePath(abs, home)) return '~'
|
|
1381
|
+
if (pathInside(home, abs)) {
|
|
1382
|
+
const rest = abs
|
|
1383
|
+
.slice(home.replace(/[\\/]+$/, '').length)
|
|
1384
|
+
.replace(/^[\\/]+/, '')
|
|
1385
|
+
.replace(/\\/g, '/')
|
|
1386
|
+
return rest ? `~/${rest}` : '~'
|
|
1387
|
+
}
|
|
1388
|
+
return abs
|
|
1389
|
+
} catch {
|
|
1390
|
+
return String(target ?? '')
|
|
1391
|
+
}
|
|
1392
|
+
}
|
|
1393
|
+
|
|
1394
|
+
/** Expand a portable approval path against this machine's home. */
|
|
1395
|
+
export function expandPortableApprovalPath(stored) {
|
|
1396
|
+
const text = typeof stored === 'string' ? stored : ''
|
|
1397
|
+
if (!text) return text
|
|
1398
|
+
if (text === '~') return homedir()
|
|
1399
|
+
if (text.startsWith('~/') || text.startsWith('~\\')) return join(homedir(), text.slice(2))
|
|
1400
|
+
return text
|
|
1401
|
+
}
|
|
1402
|
+
|
|
1403
|
+
/** Normalize one stored approval (old files may miss id/originMachine; absolute paths become portable). */
|
|
1349
1404
|
function normalizeApprovalEntry(entry, fallbackMachine) {
|
|
1350
1405
|
if (!entry || typeof entry.path !== 'string' || !entry.path.trim() || typeof entry.sessionId !== 'string') return undefined
|
|
1351
1406
|
return {
|
|
1352
1407
|
id: typeof entry.id === 'string' && entry.id ? entry.id : `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`,
|
|
1353
1408
|
sessionId: entry.sessionId,
|
|
1354
|
-
path: entry.path,
|
|
1409
|
+
path: toPortableApprovalPath(expandPortableApprovalPath(entry.path)),
|
|
1355
1410
|
kind: entry.kind === 'dir' ? 'dir' : 'file',
|
|
1356
1411
|
reason: typeof entry.reason === 'string' ? entry.reason : '',
|
|
1357
1412
|
basis: typeof entry.basis === 'string' ? entry.basis : 'user_confirmed',
|
|
@@ -1689,35 +1744,43 @@ export function apply(ctx, config) {
|
|
|
1689
1744
|
return merged
|
|
1690
1745
|
}
|
|
1691
1746
|
|
|
1692
|
-
/** Whitelist entries that apply to this session (
|
|
1747
|
+
/** Whitelist entries that apply to this session (portable paths expanded for this machine). */
|
|
1693
1748
|
function approvedTargetsFor(session) {
|
|
1694
1749
|
const id = sessionKey(session)
|
|
1695
1750
|
if (!id) return []
|
|
1696
1751
|
return approvalState.entries
|
|
1697
1752
|
.filter((entry) => entry.sessionId === id)
|
|
1698
|
-
.map((entry) => ({ path: entry.path, kind: entry.kind === 'dir' ? 'dir' : 'file' }))
|
|
1753
|
+
.map((entry) => ({ path: expandPortableApprovalPath(entry.path), kind: entry.kind === 'dir' ? 'dir' : 'file' }))
|
|
1699
1754
|
}
|
|
1700
1755
|
|
|
1701
|
-
/**
|
|
1756
|
+
/**
|
|
1757
|
+
* v0.10.0:白名单是对所有机器共用的同一份;路径按本机展开后展示。
|
|
1758
|
+
* `exists=false` 表示“本机没有这个路径”(可能在别的机器上),界面会标记出来但不自动删
|
|
1759
|
+
* (只有本机自己创建的条目才会按回收规则删)。
|
|
1760
|
+
*/
|
|
1702
1761
|
function approvalEntriesForPanel() {
|
|
1703
|
-
return approvalState.entries
|
|
1704
|
-
|
|
1705
|
-
|
|
1762
|
+
return approvalState.entries.map((entry) => {
|
|
1763
|
+
const expanded = expandPortableApprovalPath(entry.path)
|
|
1764
|
+
return {
|
|
1706
1765
|
id: entry.id,
|
|
1707
1766
|
sessionId: entry.sessionId,
|
|
1708
|
-
path:
|
|
1767
|
+
path: expanded,
|
|
1768
|
+
portable: entry.path,
|
|
1709
1769
|
kind: entry.kind === 'dir' ? 'dir' : 'file',
|
|
1710
1770
|
reason: entry.reason ?? '',
|
|
1711
1771
|
basis: entry.basis ?? '',
|
|
1712
1772
|
approvedAt: entry.approvedAt ?? 0,
|
|
1773
|
+
originMachine: entry.originMachine ?? '',
|
|
1774
|
+
local: (entry.originMachine ?? '') === THIS_MACHINE,
|
|
1713
1775
|
exists: (() => {
|
|
1714
1776
|
try {
|
|
1715
|
-
return existsSync(
|
|
1777
|
+
return existsSync(expanded)
|
|
1716
1778
|
} catch {
|
|
1717
1779
|
return false
|
|
1718
1780
|
}
|
|
1719
1781
|
})(),
|
|
1720
|
-
}
|
|
1782
|
+
}
|
|
1783
|
+
})
|
|
1721
1784
|
}
|
|
1722
1785
|
|
|
1723
1786
|
/** Add a tombstone so a removal stays removed after the next cross-machine merge. */
|
|
@@ -1742,7 +1805,7 @@ export function apply(ctx, config) {
|
|
|
1742
1805
|
for (const entry of approvalState.entries) {
|
|
1743
1806
|
let exists = false
|
|
1744
1807
|
try {
|
|
1745
|
-
exists = existsSync(entry.path)
|
|
1808
|
+
exists = existsSync(expandPortableApprovalPath(entry.path))
|
|
1746
1809
|
} catch {
|
|
1747
1810
|
exists = false
|
|
1748
1811
|
}
|
|
@@ -1788,7 +1851,8 @@ export function apply(ctx, config) {
|
|
|
1788
1851
|
approvalState.entries.push({
|
|
1789
1852
|
id: `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`,
|
|
1790
1853
|
sessionId: id,
|
|
1791
|
-
|
|
1854
|
+
// v0.10.0:home 下的目标存成可移植 `~/...`(换机后按各自 home 展开)
|
|
1855
|
+
path: toPortableApprovalPath(normalized),
|
|
1792
1856
|
kind: entryKind,
|
|
1793
1857
|
reason: reason ?? '',
|
|
1794
1858
|
basis: basis ?? 'user_confirmed',
|
|
@@ -2334,7 +2398,7 @@ export function apply(ctx, config) {
|
|
|
2334
2398
|
'',
|
|
2335
2399
|
'### Whitelist panel',
|
|
2336
2400
|
'',
|
|
2337
|
-
`Every approval is stored in the **cloud-synced** file \`<DSH_HOME>/data/tmpdir-guard/approvals.json\` (outside cloud-sync's \`data/session-tmpdir-*\` exclusions).
|
|
2401
|
+
`Every approval is stored in the **cloud-synced** file \`<DSH_HOME>/data/tmpdir-guard/approvals.json\` (outside cloud-sync's \`data/session-tmpdir-*\` exclusions). The whitelist is shared by all machines: paths under the user's home are stored **portably** (\`~/...\`) and expanded against each machine's home, so one approval also covers the same logical location on the other machines; workspace paths stay absolute (identical path = shared). Entries carry their origin machine and are merged by id (with tombstones for removals); each machine only auto-prunes entries it created, and entries whose target no longer exists are pruned when the panel refreshes (foreign-machine entries are kept unless never seen anywhere for 7 days). The panel lists the whole shared whitelist and marks entries whose expanded path is missing on this machine as 「本机无此路径」.`,
|
|
2338
2402
|
].join('\n'),
|
|
2339
2403
|
}),
|
|
2340
2404
|
)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leiyi-works/dsh-session-tmpdir",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.1",
|
|
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": {
|