@leiyi-works/dsh-session-tmpdir 0.9.4 → 0.9.6

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.
Files changed (3) hide show
  1. package/README.md +4 -0
  2. package/index.js +29 -4
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -219,3 +219,7 @@ v0.9.4 变更(2026-11-16):**命令守卫减少误拦**(不影响正常
219
219
  1. **按语句分段判定**:`pwsh`/`bash` 命令先按 `;`、`&&`、`||`、`|`、换行拆段,只检查"这一段里真的有写动作"的绝对路径。此前整条命令共用一个判定:同一条命令里既有写动作、又有只读检查(例如 `Invoke-RestMethod …; Test-Path C:\不存在的路径`),只读路径会被误当成新建产物而拦截。
220
220
  2. **下载类命令只在带输出参数时才算写**:`Invoke-WebRequest`/`Invoke-RestMethod` 需带 `-OutFile`/`-OutFileList`,`curl` 需带 `-o`/`--output`/`-O`,`wget` 需带 `-O`/`--output-document`;不带输出参数时按只读处理,不再扫描路径。
221
221
  3. 行为回归:`ffmpeg`/`pandoc`/`Export-*`/`[IO.File]::WriteAllText` 等程序级写盘、`New-Item`/`Set-Content`/重定向/管道写文件仍照旧判定;已存在文件仍按"改写放行"。
222
+
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
+
225
+ v0.9.6 变更(2026-11-16):**`Start-Process` 不再默认算写命令**。它只是启动外部程序,参数里的路径通常是程序要打开的文件(读)。现在只有带 `-RedirectStandardOutput` / `-RedirectStandardError`(真正写文件)时才参与路径判定;`Start-Process notepad C:\缺失.txt` 这类不再误拦。
package/index.js CHANGED
@@ -135,16 +135,24 @@ const CREATE_VERB_PATTERN =
135
135
  * `Invoke-RestMethod …` / `curl https://…` without `-OutFile`/`-o` are pure reads.
136
136
  */
137
137
  const DOWNLOAD_WRITE_PATTERN =
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/i
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.9.5: copy-like commands read their source arguments — only the destination is a
143
+ * write target. A missing source must never make the guard blame the destination check.
144
+ */
145
+ const COPY_LIKE_VERB_PATTERN =
146
+ /\b(?:Copy-Item|Move-Item|cp|mv|rsync|scp|robocopy|xcopy|Expand-Archive|Compress-Archive)\b/i
147
+ /** Explicit destination flag of a copy-like command (`-Destination`, `-DestinationPath`, …). */
148
+ const DESTINATION_FLAG_PATTERN = /-(?:Destination|Dest|DestinationPath|Target)\b\s+(?:"([^"]+)"|'([^']+)'|([^\s;|&]+))/i
141
149
  /**
142
150
  * v0.9: programs/APIs that write files but never match CREATE_VERB_PATTERN.
143
151
  * Without this list a command like `ffmpeg … D:\out.mp4` skipped the path scan
144
152
  * entirely, so a "new long-term artifact" could land without asking.
145
153
  */
146
154
  const WRITE_PROGRAM_PATTERN =
147
- /\b(?:ffmpeg|ffmpeg\.exe|pandoc|soffice|libreoffice|wkhtmltopdf|magick|convert|gs|zip|rar|Export-Csv|Export-Clixml|Export-Pdf|WriteAllText|WriteAllBytes|WriteAllLines|AppendAllText|AppendAllBytes|CreateText|OpenWrite|Start-Process)\b/i
155
+ /\b(?:ffmpeg|ffmpeg\.exe|pandoc|soffice|libreoffice|wkhtmltopdf|magick|convert|gs|zip|rar|Export-Csv|Export-Clixml|Export-Pdf|WriteAllText|WriteAllBytes|WriteAllLines|AppendAllText|AppendAllBytes|CreateText|OpenWrite)\b/i
148
156
  /** Redirection source shared by the global form. */
149
157
  const REDIRECT_SOURCE =
150
158
  '(?:^|[\\s;&|])(?:>>|\\d?>>?)\\s*(?:"([^"]+)"|\'([^\']+)\'|([^\\s;&|]+))'
@@ -535,10 +543,27 @@ export function longtermCommandGuardReason(command, workspaceRoot, options = {})
535
543
  // v0.7 (review M3): strip `scheme://…` first — `https://` contains `s:/`, which the
536
544
  // Windows drive-path pattern would otherwise treat as a directory.
537
545
  const scanText = segment.replace(URL_PATTERN, ' ')
538
- const tokens = new Set([...redirectTokens])
539
- for (const match of scanText.matchAll(pathPattern)) tokens.add(match[1])
546
+ const ordered = []
547
+ for (const match of scanText.matchAll(pathPattern)) ordered.push(match[1])
548
+ const tokens = new Set([...redirectTokens, ...ordered])
549
+ // v0.9.5: copy/move/archive sources are reads, not write targets.
550
+ const skipSources = new Set()
551
+ if (COPY_LIKE_VERB_PATTERN.test(segment)) {
552
+ const destMatch = DESTINATION_FLAG_PATTERN.exec(segment)
553
+ if (destMatch) {
554
+ const destValue = destMatch[1] ?? destMatch[2] ?? destMatch[3]
555
+ for (const item of ordered) {
556
+ if (String(item).replace(/["'`]+$/, '') !== destValue) skipSources.add(item)
557
+ }
558
+ } else if (ordered.length >= 2) {
559
+ // Positional form: the last path token is the destination, the rest are sources.
560
+ const destination = ordered[ordered.length - 1]
561
+ for (const item of ordered) if (item !== destination) skipSources.add(item)
562
+ }
563
+ }
540
564
  for (const raw of tokens) {
541
565
  if (!raw) continue
566
+ if (skipSources.has(raw) && !redirectTokens.has(raw)) continue
542
567
  const cleaned = String(raw).replace(/["'`]+$/, '')
543
568
  let abs
544
569
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leiyi-works/dsh-session-tmpdir",
3
- "version": "0.9.4",
3
+ "version": "0.9.6",
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": {