dsh-seal-scripts 0.5.1 → 0.5.2

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.
@@ -20,6 +20,7 @@ import fsp from 'node:fs/promises'
20
20
  import path from 'node:path'
21
21
  import crypto from 'node:crypto'
22
22
  import { DSH_DEFAULTS } from './host-limits.js'
23
+ import { catalogPhrases } from './lang.js'
23
24
 
24
25
  /** 工具组目录名(在记忆根下,和 session-memory/<工作区 key>/ 平级)。 */
25
26
  export const TOOL_SEQUENCE_DIR = 'toolSequence'
@@ -51,7 +52,7 @@ export const RUN_EXT = {
51
52
  }
52
53
 
53
54
  /** 执行方式的中文名(报错与 README 用)。 */
54
- export const RUN_LABEL = { bash: 'bash 脚本', node: 'node 脚本', ps1: 'PowerShell 脚本', cmd: '批处理' }
55
+ export const RUN_LABEL = { bash: 'bash script', node: 'node script', ps1: 'PowerShell script', cmd: 'batch file' }
55
56
 
56
57
  /*
57
58
  * 0.4.11:单脚本 64 KB、整包 512 KB、清单 24 行 / 1600 字这四个死数全部删掉。
@@ -110,7 +111,7 @@ export function runsDir(dshHome) {
110
111
  export function assertToolScriptId(id) {
111
112
  const s = String(id ?? '').trim()
112
113
  if (!BUNDLE_ID_RE.test(s)) {
113
- throw new Error('toolScript.id 要写成小写字母开头的短名(只许 a-z 0-9 -,不许路径、不许点开头):' + (s || '(空)'))
114
+ throw new Error('toolScript.id must be a short lowercase name starting with a letter (a-z 0-9 - only; no paths, no leading dot): ' + (s || '(empty)'))
114
115
  }
115
116
  return s
116
117
  }
@@ -122,7 +123,7 @@ export function assertToolScriptId(id) {
122
123
  */
123
124
  export function assertFileName(name) {
124
125
  const s = String(name ?? '').trim()
125
- if (!FILE_NAME_RE.test(s)) throw new Error('脚本文件名不合法(只许字母数字 . _ -,不许带路径):' + (s || '(空)'))
126
+ if (!FILE_NAME_RE.test(s)) throw new Error('invalid script file name (letters, digits, . _ - only; no paths): ' + (s || '(empty)'))
126
127
  return s
127
128
  }
128
129
 
@@ -133,11 +134,11 @@ export function assertFileName(name) {
133
134
  * @returns {string}
134
135
  */
135
136
  export function assertRunMatches(name, run) {
136
- if (!RUN_EXT[run]) throw new Error('run 只收 bash / node / ps1 / cmd:' + String(run))
137
+ if (!RUN_EXT[run]) throw new Error('run accepts only bash / node / ps1 / cmd: ' + String(run))
137
138
  const ext = path.extname(name).toLowerCase()
138
139
  if (!RUN_EXT[run].includes(ext)) {
139
- throw new Error(name + ' 的扩展名是 ' + (ext || '(无)') + ',和 run=' + run +
140
- ' 对不上;应该是 ' + RUN_EXT[run].join(' / '))
140
+ throw new Error(name + ' has extension ' + (ext || '(none)') + ', which does not match run=' + run +
141
+ '; expected ' + RUN_EXT[run].join(' / '))
141
142
  }
142
143
  return run
143
144
  }
@@ -155,12 +156,12 @@ export function sha256OfFile(file) {
155
156
  */
156
157
  export function resolveInside(dir, rel) {
157
158
  const raw = String(rel ?? '').trim()
158
- if (raw === '') throw new Error('文件名为空')
159
+ if (raw === '') throw new Error('file name is empty')
159
160
  const base = path.resolve(dir)
160
161
  const abs = path.resolve(base, raw)
161
162
  const r = path.relative(base, abs)
162
163
  if (r === '' || r.startsWith('..') || path.isAbsolute(r)) {
163
- throw new Error('只能操作这个工具脚本目录里的文件:' + raw)
164
+ throw new Error('only files inside this toolScript directory can be touched: ' + raw)
164
165
  }
165
166
  return abs
166
167
  }
@@ -199,17 +200,17 @@ export async function readIndexStrict(dshHome) {
199
200
  raw = await fsp.readFile(file, 'utf8')
200
201
  } catch (err) {
201
202
  if (err && err.code === 'ENOENT') return { version: INDEX_VERSION, toolScripts: {} }
202
- throw new Error('工具组索引读不出来:' + file + '(' + (err?.message ?? err) + ')')
203
+ throw new Error('cannot read the toolSequence index: ' + file + ' (' + (err?.message ?? err) + ')')
203
204
  }
204
205
  let parsed
205
206
  try {
206
207
  parsed = JSON.parse(raw)
207
208
  } catch {
208
- throw new Error('工具组索引坏了(不是合法 JSON):' + file + '。' +
209
- '它不是手改的文件——把它删掉,再重装任意一个工具脚本即可重建。')
209
+ throw new Error('the toolSequence index is broken (not valid JSON): ' + file + '. ' +
210
+ 'It is not meant to be hand-edited — delete it and reinstall any toolScript to rebuild it.')
210
211
  }
211
212
  if (!parsed || typeof parsed !== 'object' || !parsed.toolScripts || typeof parsed.toolScripts !== 'object') {
212
- throw new Error('工具组索引格式不对(缺 toolScripts):' + file + '。删掉它,再重装任意一个工具脚本即可重建。')
213
+ throw new Error('the toolSequence index has the wrong shape (missing toolScripts): ' + file + '. Delete it and reinstall any toolScript to rebuild it.')
213
214
  }
214
215
  return { version: parsed.version ?? INDEX_VERSION, toolScripts: parsed.toolScripts }
215
216
  }
@@ -282,11 +283,11 @@ export async function loadToolScript(dshHome, id) {
282
283
  try {
283
284
  raw = await fsp.readFile(path.join(dir, TOOL_SCRIPT_FILE), 'utf8')
284
285
  } catch {
285
- throw new Error('没有这个工具脚本:' + clean + '(装过的工具脚本:不带参数调用 session_tool_call 看名单)')
286
+ throw new Error('no such toolScript: ' + clean + ' (call session_tool_call with no arguments to list installed ones)')
286
287
  }
287
288
  let manifest
288
- try { manifest = JSON.parse(raw) } catch { throw new Error('这个工具脚本的 toolScript.json 坏了:' + clean) }
289
- if (!manifest || typeof manifest !== 'object') throw new Error('这个工具脚本的 toolScript.json 不是对象:' + clean)
289
+ try { manifest = JSON.parse(raw) } catch { throw new Error('this toolScript\'s toolScript.json is broken: ' + clean) }
290
+ if (!manifest || typeof manifest !== 'object') throw new Error('this toolScript\'s toolScript.json is not an object: ' + clean)
290
291
  return { manifest, dir }
291
292
  }
292
293
 
@@ -296,47 +297,47 @@ export async function loadToolScript(dshHome, id) {
296
297
  * @returns {object} 规范化后的工具脚本规格
297
298
  */
298
299
  export function normalizeToolScript(spec) {
299
- if (spec === null || typeof spec !== 'object' || Array.isArray(spec)) throw new Error('toolScript 必须是对象')
300
+ if (spec === null || typeof spec !== 'object' || Array.isArray(spec)) throw new Error('toolScript must be an object')
300
301
  const id = assertToolScriptId(spec.id)
301
302
  const title = String(spec.title ?? '').trim()
302
- if (title === '') throw new Error('toolScript.title 不能为空:一句话说这个工具脚本叫什么')
303
+ if (title === '') throw new Error('toolScript.title must not be empty: one line saying what this toolScript is called')
303
304
  const purpose = String(spec.purpose ?? '').trim()
304
- if (purpose === '') throw new Error('toolScript.purpose 不能为空:一句话说这个工具脚本干什么')
305
+ if (purpose === '') throw new Error('toolScript.purpose must not be empty: one line saying what this toolScript does')
305
306
 
306
307
  const scriptsIn = Array.isArray(spec.scripts) ? spec.scripts : []
307
308
  const docsIn = Array.isArray(spec.docs) ? spec.docs : []
308
- if (scriptsIn.length === 0) throw new Error('toolScript.scripts 不能是空的:至少要有一个能跑的脚本')
309
+ if (scriptsIn.length === 0) throw new Error('toolScript.scripts must not be empty: at least one runnable script is required')
309
310
 
310
311
  const seen = new Set()
311
312
  const scripts = scriptsIn.map((s, i) => {
312
- if (s === null || typeof s !== 'object' || Array.isArray(s)) throw new Error('scripts[' + i + '] 必须是对象')
313
+ if (s === null || typeof s !== 'object' || Array.isArray(s)) throw new Error('scripts[' + i + '] must be an object')
313
314
  const name = assertFileName(s.name)
314
315
  const run = assertRunMatches(name, s.run)
315
316
  const content = String(s.content ?? '')
316
- if (content.trim() === '') throw new Error(name + ' 的内容是空的')
317
- if (content.includes('<!--ovr:')) throw new Error(name + ' 里出现了回顾文件的分区标记 <!--ovr:,会污染解析,删掉它')
318
- if (seen.has(name)) throw new Error('同一个脚本名出现了两次:' + name)
317
+ if (content.trim() === '') throw new Error(name + ' has empty content')
318
+ if (content.includes('<!--ovr:')) throw new Error(name + ' contains the review section marker <!--ovr:, which would corrupt parsing; remove it')
319
+ if (seen.has(name)) throw new Error('the same script name appears twice: ' + name)
319
320
  seen.add(name)
320
321
  return { name, run, content, params: Array.isArray(s.params) ? s.params.map(String) : [] }
321
322
  })
322
323
  const docSeen = new Set()
323
324
  const docs = docsIn.map((d, i) => {
324
- if (d === null || typeof d !== 'object' || Array.isArray(d)) throw new Error('docs[' + i + '] 必须是对象')
325
+ if (d === null || typeof d !== 'object' || Array.isArray(d)) throw new Error('docs[' + i + '] must be an object')
325
326
  const name = assertFileName(d.name)
326
- if (path.extname(name).toLowerCase() !== '.md') throw new Error(name + ' 是说明文件,扩展名要写 .md')
327
+ if (path.extname(name).toLowerCase() !== '.md') throw new Error(name + ' is a notes file; its extension must be .md')
327
328
  if (name.toLowerCase() === 'readme.md') {
328
- throw new Error(name + ' 和安装时自动生成的 README.md 同名,装进去会被静默覆盖;换个名字(比如 ' + (i === 0 ? 'notes.md' : 'notes-' + i + '.md') + ')')
329
+ throw new Error(name + ' collides with the README.md generated on install and would be silently overwritten; pick another name (for example ' + (i === 0 ? 'notes.md' : 'notes-' + i + '.md') + ')')
329
330
  }
330
- if (docSeen.has(name)) throw new Error('docs 里同名出现了两次:' + name + '(第二份会覆盖第一份)')
331
+ if (docSeen.has(name)) throw new Error('the same name appears twice in docs: ' + name + ' (the second would overwrite the first)')
331
332
  docSeen.add(name)
332
333
  const content = String(d.content ?? '')
333
- if (content.trim() === '') throw new Error(name + ' 的内容是空的')
334
+ if (content.trim() === '') throw new Error(name + ' has empty content')
334
335
  return { name, content }
335
336
  })
336
337
  const entry = assertFileName(spec.entry ?? scripts[0].name)
337
- if (!seen.has(entry)) throw new Error('toolScript.entry 必须是 scripts 里的一个文件:' + entry)
338
+ if (!seen.has(entry)) throw new Error('toolScript.entry must be one of the files in scripts: ' + entry)
338
339
  const steps = (Array.isArray(spec.steps) ? spec.steps : []).map((s) => assertFileName(s))
339
- for (const s of steps) if (!seen.has(s)) throw new Error('toolScript.steps 里的 ' + s + ' 不在 scripts 里')
340
+ for (const s of steps) if (!seen.has(s)) throw new Error('toolScript.steps lists ' + s + ', which is not in scripts')
340
341
 
341
342
  // 0.4.11:清单里的超时只收正数,天花板交给宿主的 maxTimeoutMs(运行时夹,见 host-limits.js)。
342
343
  // 装工具脚本这一步不该依赖终端设置读没读到,所以这里既不夹、也不比宿主更严。
@@ -344,7 +345,7 @@ export function normalizeToolScript(spec) {
344
345
  // 以前这里写死 DSH_DEFAULTS.timeoutMs(120000),会让设置页改的超时对新封存的工具不生效。
345
346
  const timeoutMs = spec.timeoutMs === undefined ? undefined : Number(spec.timeoutMs)
346
347
  if (timeoutMs !== undefined && (!Number.isFinite(timeoutMs) || timeoutMs <= 0)) {
347
- throw new Error('toolScript.timeoutMs 要是正数(毫秒);实际运行时还会夹到 DSH 的 maxTimeoutMs')
348
+ throw new Error('toolScript.timeoutMs must be a positive number (ms); at run time it is also clamped to DSH\'s maxTimeoutMs')
348
349
  }
349
350
 
350
351
  const provenance = spec.provenance && typeof spec.provenance === 'object'
@@ -373,18 +374,18 @@ export function renderToolScriptReadme(manifest) {
373
374
  '',
374
375
  manifest.purpose,
375
376
  '',
376
- '- 入口:' + manifest.entry,
377
- ...(manifest.params.length > 0 ? ['- 参数:' + manifest.params.join('、')] : []),
378
- ...(manifest.steps.length > 0 ? ['- 步骤:' + manifest.steps.join(' → ')] : []),
379
- ...(manifest.provenance.memory ? ['- 出处:' + manifest.provenance.memory + (manifest.provenance.line ? (' 第 ' + manifest.provenance.line + ' 行') : '')] : []),
380
- '- 验证:' + (manifest.verified && manifest.verified.at ? (manifest.verified.at + ' exit ' + manifest.verified.exitCode) : '还没跑过'),
377
+ '- entry: ' + manifest.entry,
378
+ ...(manifest.params.length > 0 ? ['- args: ' + manifest.params.join(', ')] : []),
379
+ ...(manifest.steps.length > 0 ? ['- steps: ' + manifest.steps.join(' → ')] : []),
380
+ ...(manifest.provenance.memory ? ['- provenance: ' + manifest.provenance.memory + (manifest.provenance.line ? (' line ' + manifest.provenance.line) : '')] : []),
381
+ '- verified: ' + (manifest.verified && manifest.verified.at ? (manifest.verified.at + ' exit ' + manifest.verified.exitCode) : 'not run yet'),
381
382
  '',
382
- '## 文件',
383
+ '## Files',
383
384
  ''
384
385
  ]
385
386
  for (const s of manifest.scripts) lines.push('- ' + s.name + '(' + RUN_LABEL[s.run] + ')')
386
- for (const d of manifest.docs) lines.push('- ' + d.name + '(说明,不执行)')
387
- lines.push('', '用 session_tool_call 直接跑:toolScript 写 ' + manifest.id + ';先看一眼 argv 就加 dryRun: true。')
387
+ for (const d of manifest.docs) lines.push('- ' + d.name + ' (notes, never executed)')
388
+ lines.push('', 'Run it with session_tool_call: pass toolScript "' + manifest.id + '"; add dryRun: true to see the argv first.')
388
389
  return lines.join('\n') + '\n'
389
390
  }
390
391
 
@@ -402,8 +403,8 @@ export async function installToolScript({ dshHome, spec, replace = false }) {
402
403
  if (exists && !replace) {
403
404
  const abs = path.join(dir, TOOL_SCRIPT_FILE)
404
405
  const sha = fs.existsSync(abs) ? sha256OfFile(abs) : ''
405
- throw new Error('这个工具脚本已经装过了:' + manifest.id + '(' + dir + (sha ? ',清单 sha256 ' + sha.slice(0, 12) : '') +
406
- ');要重装就传 replace: true,旧目录会留一份 .bak-<时间戳>')
406
+ throw new Error('this toolScript is already installed: ' + manifest.id + ' (' + dir + (sha ? ', manifest sha256 ' + sha.slice(0, 12) : '') +
407
+ '); pass replace: true to reinstall, and the old directory is kept as .bak-<timestamp>')
407
408
  }
408
409
 
409
410
  const stage = path.join(root, manifest.id + '.tmp-' + process.pid + '-' + Math.random().toString(36).slice(2, 8))
@@ -470,35 +471,22 @@ export async function installToolScript({ dshHome, spec, replace = false }) {
470
471
  * @returns {string}
471
472
  */
472
473
  export function catalogText(dshHome, lang = 'zh') {
474
+ const P = catalogPhrases(lang)
473
475
  const { toolScripts } = readIndexSync(dshHome)
474
476
  const entries = Object.entries(toolScripts)
475
477
  .filter(([, m]) => m && typeof m === 'object')
476
478
  .sort((a, b) => String(a[0]).localeCompare(String(b[0])))
477
- const en = String(lang).toLowerCase().startsWith('en')
478
- // 「自创工具 = 工具脚本」的词表桥接。模型在决定「产物该是什么」时看的是这一段,
479
- // 而不是某个工具的描述——0.3.6 的新句放进了 create_write 描述里,实测仍未被采纳。
480
- const runHint = en ? 'Look before running: pass "dryRun": true to session_tool_call. ' : '跑之前想看命令,就给 session_tool_call 加 dryRun: true。'
481
- const guide = en
482
- ? 'When the user asks to turn a working setup into a reusable procedure (summarize it into a toolScript / seal it as a workflow / do it this way next time), the artifact is a toolScript — the exact commands to run again, not a markdown note and not a skill that only states a method. Write it with session_tool_create_write: from the steps you just ran, from a recall original via session_tool_create_read, or from material already in the workspace. Call session_tool_create_write only with a script that already ran clean, never a draft; editing after installing re-sends the whole context.'
483
- : '用户说「把那套总结成工具 / 封装成流程 / 以后照这个做」时,要的产物就是工具脚本——能直接跑的脚本,不是 md 笔记,也不是教方法的 skill。用 session_tool_create_write 写下来:命令来自刚跑通的步骤、经 session_tool_create_read 翻出的回顾原文,或工作区里现成的材料。调用 session_tool_create_write 之前,脚本必须已经跑通;写进去的就是跑通的那一份,不是装好再改的草稿。装完再改,等于把整段上下文重发一遍。'
479
+ // 「自创工具 = 工具脚本」的词表桥接(0.5.2:8 种语言各一套,见 lang.js 的 CATALOG)。
480
+ // 模型在决定「产物该是什么」时看的是这一段,而不是某个工具的描述。
484
481
  // 空工具组也要留一句:否则模型根本不知道有写侧工具,更不会把工具脚本当成候选产物。
485
- if (entries.length === 0) {
486
- return (en ? '【ToolSequence · empty】Nothing sealed yet. ' : '【工具组 · 空】还没有固化任何工具脚本。') + guide
487
- }
488
- const lines = []
489
- lines.push(en
490
- ? '【ToolSequence · ' + entries.length + ' toolScript(s)】Whole scripts, sealed: the exact commands from paths that worked. Run them with session_tool_call — do not rewrite them, do not re-derive commands.'
491
- : '【工具组 · ' + entries.length + ' 个工具脚本】已经固化好的脚本,直接用 session_tool_call 跑;不用自己写代码,也不用重新找命令。')
492
- // 指引紧跟标题、排在工具脚本条目之前。
493
- lines.push(runHint + guide)
482
+ if (entries.length === 0) return P.empty + P.guide
483
+ const lines = [P.header(entries.length), P.runHint + P.guide]
494
484
  // 0.4.11:不再有「还有 N 个」和 78 字截断——多少条都列全,purpose 原样显示。
495
485
  for (const [id, m] of entries) {
496
486
  const title = String(m.title ?? id)
497
487
  const purpose = String(m.purpose ?? '').replace(/\s+/g, ' ')
498
- const params = Array.isArray(m.params) && m.params.length > 0 ? '|' + (en ? 'args ' : '参数 ') + m.params.join(' ') : ''
499
- lines.push(en
500
- ? '· ' + id + ' (' + title + '): ' + purpose + '|entry ' + String(m.entry ?? '') + params
501
- : '· ' + id + '(' + title + '):' + purpose + '|入口 ' + String(m.entry ?? '') + params)
488
+ const params = Array.isArray(m.params) && m.params.length > 0 ? '|' + P.args + m.params.join(' ') : ''
489
+ lines.push(P.entry(id, title, purpose, String(m.entry ?? ''), params))
502
490
  }
503
491
  return lines.join('\n')
504
492
  }
@@ -160,7 +160,7 @@ const LEVEL_RANK = { keywords: 0, sum: 1, body: 2 }
160
160
  */
161
161
  export function termsOf(need) {
162
162
  const raw = String(need === undefined || need === null ? '' : need).trim()
163
- if (raw === '') throw new Error('need 不能为空')
163
+ if (raw === '') throw new Error('need must not be empty')
164
164
  const out = new Set([raw.toLowerCase()])
165
165
  for (const part of raw.split(/[\s,,。、;;::!!??()()【】\[\]"'“”‘’·…\-—_/\\|]+/)) {
166
166
  const t = part.trim().toLowerCase()
@@ -149,7 +149,7 @@ export function readOptionsSync(dshHome) {
149
149
  * @returns {Promise<object>} 落盘后的生效选项
150
150
  */
151
151
  export async function writeOptions(dshHome, patch) {
152
- if (typeof dshHome !== 'string' || dshHome.trim() === '') throw new Error('没有 dshHome,选项写不进去')
152
+ if (typeof dshHome !== 'string' || dshHome.trim() === '') throw new Error('no dshHome, cannot write options')
153
153
  const merged = { ...readStoredSync(dshHome), ...(patch !== null && typeof patch === 'object' ? patch : {}) }
154
154
  const next = normalizeOptions(merged)
155
155
  await fsPromises.mkdir(path.dirname(optionsPath(dshHome)), { recursive: true })
package/lib/core/store.js CHANGED
@@ -360,7 +360,7 @@ export async function captureCompaction({ dshHome, cwd, session, event, lang = '
360
360
 
361
361
  // 一条新内容都不剩:不写空壳文件,也不往载入文件里加条目。
362
362
  if (cut > 0 && keptSpans.every((sp) => sp.count === 0)) {
363
- const why = branchFrom === null ? '内容已经记过' : ('内容到 ' + branchFrom.file + ' 第 ' + branchFrom.line + ' 行为止都已记过')
363
+ const why = branchFrom === null ? 'content already recorded' : ('content up to ' + branchFrom.file + ' line ' + branchFrom.line + ' is already recorded')
364
364
  return { file: null, dir, skipped: true, reason: why, branchFrom, covered: cut, bytes: 0 }
365
365
  }
366
366
 
@@ -79,12 +79,12 @@ async function collect(dir, prefix, out) {
79
79
  */
80
80
  export async function exportToolSequence({ dshHome, dir }) {
81
81
  const target = String(dir === undefined || dir === null ? '' : dir).trim()
82
- if (target === '') throw new Error('没有指定要导出到哪个工作区文件夹')
83
- if (!path.isAbsolute(target)) throw new Error('工作区目录要是绝对路径:' + target)
82
+ if (target === '') throw new Error('no target workspace folder given for the export')
83
+ if (!path.isAbsolute(target)) throw new Error('the workspace directory must be an absolute path: ' + target)
84
84
  let st
85
- try { st = await fsp.stat(target) } catch { throw new Error('工作区目录不存在:' + target) }
86
- if (!st.isDirectory()) throw new Error('这不是一个目录:' + target)
87
- if (path.parse(target).root === target) throw new Error('不往磁盘根目录写:' + target)
85
+ try { st = await fsp.stat(target) } catch { throw new Error('workspace directory does not exist: ' + target) }
86
+ if (!st.isDirectory()) throw new Error('not a directory: ' + target)
87
+ if (path.parse(target).root === target) throw new Error('refusing to write into a drive root: ' + target)
88
88
 
89
89
  const root = toolSequenceRoot(dshHome)
90
90
  const entries = []
@@ -173,12 +173,12 @@ function planEntry(rawName) {
173
173
  const parts = safe.split('/')
174
174
  const top = parts[0]
175
175
  if (parts.length === 1 && top === INDEX_FILE) {
176
- return { skip: '本机索引按落地后的文件重建,包里的 _index.json 不采信' }
176
+ return { skip: 'the local index is rebuilt from the files on disk; _index.json inside the package is not trusted' }
177
177
  }
178
- if (parts.length < 2) return { skip: '不在任何工具脚本目录里' }
179
- if (top === RUNS_DIR) return { skip: '运行溢写目录,不收' }
180
- if (!BUNDLE_ID_RE.test(top)) return { skip: '目录名不是合法的工具脚本 id' }
181
- if (isTransientName(parts[1])) return { skip: '备份/临时目录,不收' }
178
+ if (parts.length < 2) return { skip: 'not inside any toolScript directory' }
179
+ if (top === RUNS_DIR) return { skip: 'run spill directory, not taken' }
180
+ if (!BUNDLE_ID_RE.test(top)) return { skip: 'directory name is not a valid toolScript id' }
181
+ if (isTransientName(parts[1])) return { skip: 'backup/temp directory, not taken' }
182
182
  return { id: top, rel: parts.slice(1).join('/') }
183
183
  }
184
184
 
@@ -229,8 +229,8 @@ export async function importToolSequence({ dshHome, buffer, file, dryRun = false
229
229
  const probeDir = fs.existsSync(root) ? root : dshHome
230
230
  const free = await freeBytesOf(probeDir)
231
231
  if (free !== null && need + DISK_RESERVE_BYTES > free) {
232
- throw new Error('装不下:解压后要 ' + need + ' 字节,磁盘只剩 ' + free + ' 字节(留余量 ' +
233
- DISK_RESERVE_BYTES + ' 字节);先腾空间再导入')
232
+ throw new Error('not enough room: needs ' + need + ' bytes unpacked, disk has only ' + free + ' bytes free (reserve ' +
233
+ DISK_RESERVE_BYTES + ' bytes); free some space and import again')
234
234
  }
235
235
 
236
236
  const cut = wrapperPrefix(names)
@@ -280,7 +280,7 @@ export async function importToolSequence({ dshHome, buffer, file, dryRun = false
280
280
  const target = path.join(stage, plan.rel)
281
281
  const rel = path.relative(stage, target)
282
282
  if (rel === '' || rel === '..' || rel.startsWith('..' + path.sep) || path.isAbsolute(rel)) {
283
- throw new Error('越界路径:' + plan.rel)
283
+ throw new Error('out-of-range path: ' + plan.rel)
284
284
  }
285
285
  await fsp.mkdir(path.dirname(target), { recursive: true })
286
286
  await writeBody(target)
@@ -308,7 +308,7 @@ export async function importToolSequence({ dshHome, buffer, file, dryRun = false
308
308
  if (imported.length === 0) {
309
309
  const why = skipped.length > 0 ? ('(' + skipped.slice(0, 3).map((s) => s.name + ':' + s.reason).join(';') + ')') : ''
310
310
  for (const stage of stages.values()) await fsp.rm(stage, { recursive: true, force: true }).catch(() => {})
311
- throw new Error('这个包里没有工具脚本目录' + why)
311
+ throw new Error('this package has no toolScript directories' + why)
312
312
  }
313
313
 
314
314
  if (dryRun === true) return { dryRun: true, imported, overwritten, skipped }