@leiyi-works/dsh-session-tmpdir 0.9.12 → 0.10.0

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 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 }, '目标不存在') : null,
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
@@ -1345,13 +1345,44 @@ export function legacyApprovalsFilePath() {
1345
1345
  return legacyApprovalsFilePaths()[0]
1346
1346
  }
1347
1347
 
1348
- /** Normalize one stored approval (old files may miss id/originMachine). */
1348
+ /**
1349
+ * v0.10.0:白名单条目路径可移植 —— home 下的路径存成 `~/...`,换机后按各自 home 展开;
1350
+ * 工作区等不在 home 下的路径仍存绝对路径(各机路径一致即可共享)。
1351
+ */
1352
+ export function toPortableApprovalPath(target) {
1353
+ try {
1354
+ const abs = resolve(String(target ?? ''))
1355
+ const home = resolve(homedir())
1356
+ if (samePath(abs, home)) return '~'
1357
+ if (pathInside(home, abs)) {
1358
+ const rest = abs
1359
+ .slice(home.replace(/[\\/]+$/, '').length)
1360
+ .replace(/^[\\/]+/, '')
1361
+ .replace(/\\/g, '/')
1362
+ return rest ? `~/${rest}` : '~'
1363
+ }
1364
+ return abs
1365
+ } catch {
1366
+ return String(target ?? '')
1367
+ }
1368
+ }
1369
+
1370
+ /** Expand a portable approval path against this machine's home. */
1371
+ export function expandPortableApprovalPath(stored) {
1372
+ const text = typeof stored === 'string' ? stored : ''
1373
+ if (!text) return text
1374
+ if (text === '~') return homedir()
1375
+ if (text.startsWith('~/') || text.startsWith('~\\')) return join(homedir(), text.slice(2))
1376
+ return text
1377
+ }
1378
+
1379
+ /** Normalize one stored approval (old files may miss id/originMachine; absolute paths become portable). */
1349
1380
  function normalizeApprovalEntry(entry, fallbackMachine) {
1350
1381
  if (!entry || typeof entry.path !== 'string' || !entry.path.trim() || typeof entry.sessionId !== 'string') return undefined
1351
1382
  return {
1352
1383
  id: typeof entry.id === 'string' && entry.id ? entry.id : `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`,
1353
1384
  sessionId: entry.sessionId,
1354
- path: entry.path,
1385
+ path: toPortableApprovalPath(expandPortableApprovalPath(entry.path)),
1355
1386
  kind: entry.kind === 'dir' ? 'dir' : 'file',
1356
1387
  reason: typeof entry.reason === 'string' ? entry.reason : '',
1357
1388
  basis: typeof entry.basis === 'string' ? entry.basis : 'user_confirmed',
@@ -1689,35 +1720,43 @@ export function apply(ctx, config) {
1689
1720
  return merged
1690
1721
  }
1691
1722
 
1692
- /** Whitelist entries that apply to this session (exact files + directory prefixes). */
1723
+ /** Whitelist entries that apply to this session (portable paths expanded for this machine). */
1693
1724
  function approvedTargetsFor(session) {
1694
1725
  const id = sessionKey(session)
1695
1726
  if (!id) return []
1696
1727
  return approvalState.entries
1697
1728
  .filter((entry) => entry.sessionId === id)
1698
- .map((entry) => ({ path: entry.path, kind: entry.kind === 'dir' ? 'dir' : 'file' }))
1729
+ .map((entry) => ({ path: expandPortableApprovalPath(entry.path), kind: entry.kind === 'dir' ? 'dir' : 'file' }))
1699
1730
  }
1700
1731
 
1701
- /** Whitelist entries for the panel: only this machine's entries (v0.9.10; foreign entries stay in the file for merge/prune but are not shown). */
1732
+ /**
1733
+ * v0.10.0:白名单是对所有机器共用的同一份;路径按本机展开后展示。
1734
+ * `exists=false` 表示“本机没有这个路径”(可能在别的机器上),界面会标记出来但不自动删
1735
+ * (只有本机自己创建的条目才会按回收规则删)。
1736
+ */
1702
1737
  function approvalEntriesForPanel() {
1703
- return approvalState.entries
1704
- .filter((entry) => (entry.originMachine ?? '') === THIS_MACHINE)
1705
- .map((entry) => ({
1738
+ return approvalState.entries.map((entry) => {
1739
+ const expanded = expandPortableApprovalPath(entry.path)
1740
+ return {
1706
1741
  id: entry.id,
1707
1742
  sessionId: entry.sessionId,
1708
- path: entry.path,
1743
+ path: expanded,
1744
+ portable: entry.path,
1709
1745
  kind: entry.kind === 'dir' ? 'dir' : 'file',
1710
1746
  reason: entry.reason ?? '',
1711
1747
  basis: entry.basis ?? '',
1712
1748
  approvedAt: entry.approvedAt ?? 0,
1749
+ originMachine: entry.originMachine ?? '',
1750
+ local: (entry.originMachine ?? '') === THIS_MACHINE,
1713
1751
  exists: (() => {
1714
1752
  try {
1715
- return existsSync(entry.path)
1753
+ return existsSync(expanded)
1716
1754
  } catch {
1717
1755
  return false
1718
1756
  }
1719
1757
  })(),
1720
- }))
1758
+ }
1759
+ })
1721
1760
  }
1722
1761
 
1723
1762
  /** Add a tombstone so a removal stays removed after the next cross-machine merge. */
@@ -1742,7 +1781,7 @@ export function apply(ctx, config) {
1742
1781
  for (const entry of approvalState.entries) {
1743
1782
  let exists = false
1744
1783
  try {
1745
- exists = existsSync(entry.path)
1784
+ exists = existsSync(expandPortableApprovalPath(entry.path))
1746
1785
  } catch {
1747
1786
  exists = false
1748
1787
  }
@@ -1788,7 +1827,8 @@ export function apply(ctx, config) {
1788
1827
  approvalState.entries.push({
1789
1828
  id: `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`,
1790
1829
  sessionId: id,
1791
- path: normalized,
1830
+ // v0.10.0:home 下的目标存成可移植 `~/...`(换机后按各自 home 展开)
1831
+ path: toPortableApprovalPath(normalized),
1792
1832
  kind: entryKind,
1793
1833
  reason: reason ?? '',
1794
1834
  basis: basis ?? 'user_confirmed',
@@ -2334,7 +2374,7 @@ export function apply(ctx, config) {
2334
2374
  '',
2335
2375
  '### Whitelist panel',
2336
2376
  '',
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). Entries carry their origin machine and are merged by id (with tombstones for removals), so an approval made on one machine reaches the others after the next sync; the panel lists only this machine's entries (foreign ones stay in the file for merging/pruning). 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).`,
2377
+ `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
2378
  ].join('\n'),
2339
2379
  }),
2340
2380
  )
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leiyi-works/dsh-session-tmpdir",
3
- "version": "0.9.12",
3
+ "version": "0.10.0",
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": {