@leiyi-works/dsh-session-tmpdir 0.10.0 → 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.
Files changed (2) hide show
  1. package/index.js +24 -0
  2. package/package.json +1 -1
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) &&
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leiyi-works/dsh-session-tmpdir",
3
- "version": "0.10.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": {