dsh-seal-scripts 0.5.1 → 0.6.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.
@@ -7,7 +7,7 @@
7
7
 
8
8
  import { randomBytes } from 'node:crypto'
9
9
  import {
10
- headerLabels, headerAliases, sectionTitle,
10
+ headerLabels, headerAliases, sectionTitle, sectionLangOf,
11
11
  coversValue, branchValue, toolCallsValue, lockedValue
12
12
  } from './lang.js'
13
13
 
@@ -184,10 +184,7 @@ export function setField(text, field, value) {
184
184
  return null
185
185
  }
186
186
 
187
- /** 这份文件的分区标题是哪种语言:老文件是中文,0.2.5 起的英文文件用英文。 */
188
- function sectionLangOf(text) {
189
- return /^##\s*(Summary|Original|Diary)\s*$/m.test(String(text ?? '')) ? 'en' : 'zh'
190
- }
187
+ /* sectionLangOf 搬进了 lang.js(0.5.2:8 种语言都要认)。 */
191
188
 
192
189
  /**
193
190
  * 换掉一个分区的内容,其余字节不动。标题跟着这份文件自己的语言走。
@@ -86,7 +86,7 @@ export async function migrateIndex(dir, workspace) {
86
86
  }, null, 2) + '\n')
87
87
  written.push(entry.file)
88
88
  }
89
- if (written.length !== valid.length) throw new Error('边车数量与旧索引条目数不一致')
89
+ if (written.length !== valid.length) throw new Error('sidecar count does not match the old index entry count')
90
90
  } catch (err) {
91
91
  for (const f of written) await fsp.rm(sidecarPath(dir, f), { force: true }).catch(() => {})
92
92
  throw err
@@ -22,14 +22,14 @@ import path from 'node:path'
22
22
  * @returns {string} 绝对路径
23
23
  */
24
24
  export function assertInside(dir, raw, options = {}) {
25
- const label = options.label ?? '这个目录'
25
+ const label = options.label ?? 'this directory'
26
26
  const text = String(raw ?? '').trim()
27
- if (text === '') throw new Error('文件名不能为空')
27
+ if (text === '') throw new Error('file name must not be empty')
28
28
  const base = path.resolve(dir)
29
29
  const abs = path.resolve(base, text)
30
30
  const rel = path.relative(base, abs)
31
31
  if (rel === '' || rel === '..' || rel.startsWith('..' + path.sep) || path.isAbsolute(rel)) {
32
- throw new Error('只能操作 ' + label + ' 里的文件:' + text)
32
+ throw new Error('only files inside ' + label + ' can be touched: ' + text)
33
33
  }
34
34
  return abs
35
35
  }
@@ -37,7 +37,7 @@ export function assertInside(dir, raw, options = {}) {
37
37
  /** 必须是 .md(回顾文件)。 */
38
38
  export function assertMarkdown(abs, raw) {
39
39
  if (!path.extname(abs).toLowerCase().endsWith('.md')) {
40
- throw new Error('不是回顾文件:' + String(raw ?? ''))
40
+ throw new Error('not a review file: ' + String(raw ?? ''))
41
41
  }
42
42
  return abs
43
43
  }
@@ -62,7 +62,7 @@ export function interpreterOf(run) {
62
62
  return { cmd: process.env.ComSpec || 'cmd.exe', args: ['/d', '/c'] }
63
63
  }
64
64
  default:
65
- throw new Error('未知执行方式:' + String(run))
65
+ throw new Error('unknown run mode: ' + String(run))
66
66
  }
67
67
  }
68
68
 
@@ -89,17 +89,17 @@ export async function runScript({
89
89
  }) {
90
90
  const name = String(step ?? '').trim()
91
91
  const file = resolveInside(dir, name)
92
- if (!fs.existsSync(file)) throw new Error('这个工具脚本里没有这个脚本:' + name)
92
+ if (!fs.existsSync(file)) throw new Error('this toolScript has no such script: ' + name)
93
93
 
94
94
  const scripts = Array.isArray(manifest?.scripts) ? manifest.scripts : []
95
95
  const meta = scripts.find((s) => s && s.name === name)
96
- if (!meta) throw new Error('这个文件不在这个工具脚本的清单里:' + name)
96
+ if (!meta) throw new Error('this file is not in the toolScript manifest: ' + name)
97
97
  const hashes = manifest && typeof manifest.hashes === 'object' && manifest.hashes !== null ? manifest.hashes : {}
98
98
  const expected = typeof hashes[name] === 'string' ? hashes[name] : ''
99
99
  const actual = sha256OfFile(file)
100
100
  if (expected !== '' && expected !== actual && !allowDrift) {
101
- throw new Error('脚本和清单里的 sha256 对不上,先不跑(' + name + ')。' +
102
- '如果你刚手动改过它,重装这个工具脚本(session_tool_create_write + replace),或者这次显式传 allowDrift: true。')
101
+ throw new Error('script sha256 does not match the manifest, refusing to run (' + name + '). ' +
102
+ 'If you just edited it by hand, reinstall the toolScript (session_tool_create_write + replace), or pass allowDrift: true explicitly this time.')
103
103
  }
104
104
 
105
105
  const host = limits ?? readHostLimits()
@@ -210,7 +210,7 @@ function spawnCollect({ cmd, argv, cwd, env, timeout, cap, stdin, dshHome, label
210
210
  errFd = fs.openSync(paths.stderrFile, 'w')
211
211
  } catch (err) {
212
212
  for (const fd of [outFd, errFd]) if (typeof fd === 'number') { try { fs.closeSync(fd) } catch { /* 忽略 */ } }
213
- reject(new Error('建运行日志失败:' + (err && err.message ? err.message : String(err))))
213
+ reject(new Error('failed to create the run log: ' + (err && err.message ? err.message : String(err))))
214
214
  return
215
215
  }
216
216
 
@@ -225,7 +225,7 @@ function spawnCollect({ cmd, argv, cwd, env, timeout, cap, stdin, dshHome, label
225
225
  stdio: ['pipe', outFd, errFd]
226
226
  })
227
227
  } catch (err) {
228
- reject(new Error('起不来解释器 ' + cmd + ':' + (err && err.message ? err.message : String(err))))
228
+ reject(new Error('cannot start interpreter ' + cmd + ': ' + (err && err.message ? err.message : String(err))))
229
229
  return
230
230
  } finally {
231
231
  // 子进程已经 dup 了自己的那一份,父进程这边立刻关掉,免得句柄泄漏。
@@ -306,8 +306,8 @@ function spawnCollect({ cmd, argv, cwd, env, timeout, cap, stdin, dshHome, label
306
306
  if (done) return
307
307
  done = true
308
308
  const message = err && err.code === 'ENOENT'
309
- ? '找不到解释器:' + cmd + (cmd === 'bash' ? '(这个工具脚本用 bash 写的;这台机器上 bash 不在 PATH 里,改写 node 脚本或先装 bash)' : '')
310
- : '起不来:' + (err && err.message ? err.message : String(err))
309
+ ? 'interpreter not found: ' + cmd + (cmd === 'bash' ? ' (this toolScript is written in bash; bash is not on PATH on this machine — rewrite it as a node script or install bash first)' : '')
310
+ : 'failed to start: ' + (err && err.message ? err.message : String(err))
311
311
  reject(new Error(message))
312
312
  })
313
313
 
@@ -363,7 +363,7 @@ function sleep(ms) {
363
363
  */
364
364
  export async function killRun(pid, { graceMs = KILL_GRACE_MS } = {}) {
365
365
  const n = Number(pid)
366
- if (!Number.isInteger(n) || n <= 0) throw new Error('killRun 要一个正的 pid:' + String(pid))
366
+ if (!Number.isInteger(n) || n <= 0) throw new Error('killRun needs a positive pid: ' + String(pid))
367
367
  const signal = (s) => {
368
368
  try { process.kill(-n, s); return true } catch { /* 进程组可能已经没了 */ }
369
369
  try { process.kill(n, s); return true } catch { return false }
@@ -62,7 +62,7 @@ export async function readBodyOf({ dshHome, cwd, file }) {
62
62
  const abs = resolveMemoryFile(dshHome, cwd, file)
63
63
  const text = await fsp.readFile(abs, 'utf8')
64
64
  const parsed = parseMemory(text)
65
- if (!parsed.id) throw new Error('这份文件没有回顾分区标记,不是回顾文件:' + file)
65
+ if (!parsed.id) throw new Error('this file has no review section markers, so it is not a review file: ' + file)
66
66
  return {
67
67
  file: path.basename(abs),
68
68
  path: abs,
@@ -77,12 +77,12 @@ export async function locateMemory(args, { dshHome, cwd }) {
77
77
  const hasFile = typeof args.file === 'string' && args.file.trim() !== ''
78
78
  const hasDate = args.date !== undefined
79
79
  if (!hasFile && !hasDate) {
80
- throw new Error('要么给 file(回顾文件名),要么给 date(YYYY-MM-DD,默认第 1 份)来定位哪一份回顾')
80
+ throw new Error('pass either file (a review file name) or date (YYYY-MM-DD, first review by default) to locate a review')
81
81
  }
82
- if (hasFile && hasDate) throw new Error('file 与 date 只能给一个')
82
+ if (hasFile && hasDate) throw new Error('file and date are mutually exclusive')
83
83
  if (hasFile) return String(args.file).trim()
84
84
  if (!/^\d{4}-\d{2}-\d{2}$/.test(String(args.date).trim())) {
85
- throw new Error('date 要写成 YYYY-MM-DD(本地日期):' + String(args.date))
85
+ throw new Error('date must be YYYY-MM-DD (local date): ' + String(args.date))
86
86
  }
87
87
  return resolveMemoryByDay({
88
88
  dshHome, cwd,
@@ -223,21 +223,21 @@ export function outlineOf(blocks, { maxItems = Infinity } = {}) {
223
223
  /** 骨架渲染成人读得懂的几段文字。 */
224
224
  export function renderOutline({ file, body, outline, filePath }) {
225
225
  const lines = []
226
- lines.push('原文骨架 · ' + file + '(' + filePath + ')')
227
- lines.push('正文 ' + Buffer.byteLength(body, 'utf8') + ' 字节 / ' + body.split('\n').length + ' 行' +
228
- ';工具调用 ' + outline.calls + ' 次(失败 ' + outline.failures + ' 次);去重后 ' + outline.distinct + ' 条')
226
+ lines.push('Original outline · ' + file + ' (' + filePath + ')')
227
+ lines.push('Body ' + Buffer.byteLength(body, 'utf8') + ' bytes / ' + body.split('\n').length + ' lines' +
228
+ '; ' + outline.calls + ' tool calls (' + outline.failures + ' failed); ' + outline.distinct + ' distinct after dedup')
229
229
  lines.push('')
230
230
  for (const g of outline.groups) {
231
- lines.push('▸ ' + g.tool + ' · 共 ' + g.count + ' 次' + (g.failed > 0 ? '(失败 ' + g.failed + ')' : '') +
232
- ' · 去重 ' + g.distinct + ' 条' + (g.omitted > 0 ? '(这里显示 ' + g.shown + ' 条,其余没列)' : ''))
231
+ lines.push('▸ ' + g.tool + ' · ' + g.count + ' calls' + (g.failed > 0 ? ' (' + g.failed + ' failed)' : '') +
232
+ ' · ' + g.distinct + ' distinct' + (g.omitted > 0 ? ' (showing ' + g.shown + ', the rest omitted)' : ''))
233
233
  for (const it of g.items) {
234
- lines.push(' L' + it.line + (it.failed ? ' [失败]' : '') + ' ' + (it.firstArg || '(无参数)') +
234
+ lines.push(' L' + it.line + (it.failed ? ' [failed]' : '') + ' ' + (it.firstArg || '(no args)') +
235
235
  (it.count > 1 ? ' ×' + it.count : ''))
236
236
  }
237
237
  lines.push('')
238
238
  }
239
- lines.push('要看某一条的完整参数与结果:mode=block, line=<上面那个 L 后面的数字>。')
240
- lines.push('要按原样读完整段:mode=raw(cursor 分页)。要固化:把 scripts 装进 toolScript。')
239
+ lines.push('To see one call\'s full args and result: mode=block, line=<the number after L above>.')
240
+ lines.push('To read the whole segment verbatim: mode=raw (paged by cursor). To seal it: install the scripts as a toolScript.')
241
241
  return lines.join('\n')
242
242
  }
243
243
 
@@ -245,35 +245,35 @@ export function renderOutline({ file, body, outline, filePath }) {
245
245
 
246
246
  /** 读这一侧的参数校验;写那一侧另有 validateWriteArgs(0.3.3 拆开)。 */
247
247
  function validateReadArgs(args) {
248
- if (args === null || typeof args !== 'object' || Array.isArray(args)) throw new Error('参数必须是对象')
248
+ if (args === null || typeof args !== 'object' || Array.isArray(args)) throw new Error('arguments must be an object')
249
249
  const mode = args.mode === undefined ? 'outline' : String(args.mode)
250
- if (!['outline', 'raw', 'block'].includes(mode)) throw new Error('mode 只收 outline / raw / block:' + mode)
250
+ if (!['outline', 'raw', 'block'].includes(mode)) throw new Error('mode accepts only outline / raw / block: ' + mode)
251
251
  if (args.toolScript !== undefined || args.replace !== undefined) {
252
- throw new Error('这个工具只读;装工具脚本用 ' + TOOL_CREATE_WRITE_NAME)
252
+ throw new Error('this tool is read-only; use ' + TOOL_CREATE_WRITE_NAME + ' to install a toolScript')
253
253
  }
254
- if (args.cursor !== undefined && (!Number.isInteger(args.cursor) || args.cursor < 0)) throw new Error('cursor 是 0 起的字符偏移')
254
+ if (args.cursor !== undefined && (!Number.isInteger(args.cursor) || args.cursor < 0)) throw new Error('cursor is a 0-based character offset')
255
255
  // 0.4.11:去掉 1000~200000 的死区间——分页只要求「是个正整数」。
256
256
  if (args.chars !== undefined && (!Number.isInteger(args.chars) || args.chars <= 0)) {
257
- throw new Error('chars 要是正整数(每页字符数,默认 40000)')
257
+ throw new Error('chars must be a positive integer (characters per page, default 40000)')
258
258
  }
259
- if (args.line !== undefined && (!Number.isInteger(args.line) || args.line < 1)) throw new Error('line 是 1 起的正文行号(用骨架里的 L 后面的数字)')
260
- if (args.span !== undefined && (!Number.isInteger(args.span) || args.span < 0)) throw new Error('span 是 0 起的整数(block 里多带几行)')
261
- if (args.maxItems !== undefined && (!Number.isInteger(args.maxItems) || args.maxItems < 1)) throw new Error('maxItems 要是正整数')
259
+ if (args.line !== undefined && (!Number.isInteger(args.line) || args.line < 1)) throw new Error('line is a 1-based body line number (use the number after L in the outline)')
260
+ if (args.span !== undefined && (!Number.isInteger(args.span) || args.span < 0)) throw new Error('span must be an integer from 0 (extra lines in a block)')
261
+ if (args.maxItems !== undefined && (!Number.isInteger(args.maxItems) || args.maxItems < 1)) throw new Error('maxItems must be a positive integer')
262
262
  return mode
263
263
  }
264
264
 
265
265
  /** 写盘那一侧的返回文本。 */
266
266
  function renderWriteResult(res) {
267
267
  const lines = [
268
- '已装好工具脚本:' + res.id,
269
- '目录:' + res.dir,
270
- '文件:',
271
- ...res.files.map((f) => ' · ' + f.name + '(' + f.kind + ' · ' + f.bytes + ' 字节 · sha256 ' + f.sha256.slice(0, 12) + '…)'),
272
- res.backup ? '旧版本留在:' + res.backup : '',
273
- '索引:' + res.indexPath,
268
+ 'Installed toolScript: ' + res.id,
269
+ 'Directory: ' + res.dir,
270
+ 'Files:',
271
+ ...res.files.map((f) => ' · ' + f.name + ' (' + f.kind + ' · ' + f.bytes + ' bytes · sha256 ' + f.sha256.slice(0, 12) + '…)'),
272
+ res.backup ? 'Previous version kept at: ' + res.backup : '',
273
+ 'Index: ' + res.indexPath,
274
274
  '',
275
- '现在就能跑:session_tool_call({ toolScript: "' + res.id + '" });先看命令就加 dryRun: true。',
276
- '这个工具脚本的名字与用途会在下一轮装配时进入系统提示词(工具组那一段)。'
275
+ 'Ready to run: session_tool_call({ toolScript: "' + res.id + '" }); add dryRun: true to see the commands first.',
276
+ 'This toolScript\'s name and purpose enter the system prompt (the toolSequence section) on the next assembly.'
277
277
  ]
278
278
  return lines.filter((l) => l !== '').join('\n')
279
279
  }
@@ -333,7 +333,7 @@ export function buildToolCreateReadDefinition({ dshHome, logger }) {
333
333
  async execute(args, exec) {
334
334
  const mode = validateReadArgs(args)
335
335
  const cwd = exec?.agent?.session?.header?.cwd
336
- if (typeof cwd !== 'string' || cwd === '') throw new Error(TOOL_CREATE_READ_NAME + ' 需要知道当前工作区')
336
+ if (typeof cwd !== 'string' || cwd === '') throw new Error(TOOL_CREATE_READ_NAME + ' needs to know the current workspace')
337
337
  const file = await locateMemory(args, { dshHome, cwd })
338
338
  const one = await readBodyOf({ dshHome, cwd, file })
339
339
  const body = one.body
@@ -358,26 +358,26 @@ export function buildToolCreateReadDefinition({ dshHome, logger }) {
358
358
 
359
359
  // ── 读:单块展开 ──
360
360
  if (mode === 'block') {
361
- if (args.line === undefined) throw new Error('block 要给 line(骨架里 L 后面的数字)')
361
+ if (args.line === undefined) throw new Error('block requires line (the number after L in the outline)')
362
362
  const lines = body.split('\n')
363
- if (args.line > lines.length) throw new Error('line 超过正文行数(' + lines.length + '):' + args.line)
363
+ if (args.line > lines.length) throw new Error('line exceeds the body line count (' + lines.length + '): ' + args.line)
364
364
  const target = pickBlockAt(blocks, args.line)
365
- if (!target) throw new Error('L' + args.line + ' 附近没有工具调用;用 mode=outline 先看骨架')
365
+ if (!target) throw new Error('no tool call near L' + args.line + '; use mode=outline to see the outline first')
366
366
  const span = args.span === undefined ? 0 : Math.max(0, Number(args.span) || 0)
367
367
  const from = target.line
368
368
  const to = Math.min(lines.length, Math.max(target.endLine, args.line) + span)
369
369
  const slice = lines.slice(from - 1, to).join('\n')
370
370
  const head = 'L' + from + '–' + to + ' · ' + target.name +
371
- (target.failed ? ' · 【这一条报错了】' : (target.status ? ' · ' + target.status : ' · 没有结果(执行中断)'))
371
+ (target.failed ? ' · [this call failed]' : (target.status ? ' · ' + target.status : ' · no result (execution interrupted)'))
372
372
  const parts = [head, '', slice]
373
373
  // 结果区:◂ 之前那一段。和块内的缩进段一致时就不再抄一遍(同一段字不写两次)。
374
374
  const same = target.resultText.length === target.argLines.length &&
375
375
  target.resultText.every((l, i) => l === target.argLines[i])
376
376
  if (target.resultText.length > 0 && !same) {
377
377
  const capped = target.resultText.slice(0, 40)
378
- parts.push('', '【结果区】紧挨着 ◂ 之前的内容(同一段缩进里可能混着上一条调用的输出,文本分不开):')
378
+ parts.push('', '【Result】the content right before ◂ (the previous call\'s output may share the same indentation and cannot be separated textually):')
379
379
  parts.push(capped.join('\n'))
380
- if (target.resultText.length > capped.length) parts.push('…(还有 ' + (target.resultText.length - capped.length) + ' 行,用 mode=raw 按行号取)')
380
+ if (target.resultText.length > capped.length) parts.push('… (' + (target.resultText.length - capped.length) + ' more lines; use mode=raw to fetch them by line number)')
381
381
  }
382
382
  return jsonSafe({
383
383
  mode: 'block', file: one.file, path: one.path,
@@ -406,17 +406,17 @@ export function buildToolCreateReadDefinition({ dshHome, logger }) {
406
406
 
407
407
  /** 写这一侧的参数校验:只收 toolScript / replace / 可选定位(定位只用来记出处)。 */
408
408
  function validateWriteArgs(args) {
409
- if (args === null || typeof args !== 'object' || Array.isArray(args)) throw new Error('参数必须是对象')
410
- if (args.toolScript === undefined) throw new Error('要给 toolScript:{ id, title, purpose, entry, scripts }')
411
- if (args.toolScript === null || typeof args.toolScript !== 'object' || Array.isArray(args.toolScript)) throw new Error('toolScript 必须是对象')
409
+ if (args === null || typeof args !== 'object' || Array.isArray(args)) throw new Error('arguments must be an object')
410
+ if (args.toolScript === undefined) throw new Error('toolScript is required: { id, title, purpose, entry, scripts }')
411
+ if (args.toolScript === null || typeof args.toolScript !== 'object' || Array.isArray(args.toolScript)) throw new Error('toolScript must be an object')
412
412
  for (const k of ['mode', 'cursor', 'chars', 'line', 'span', 'maxItems']) {
413
- if (args[k] !== undefined) throw new Error('装工具脚本不收 ' + k + ':那是 ' + TOOL_CREATE_READ_NAME + ' 的参数')
413
+ if (args[k] !== undefined) throw new Error('installing a toolScript does not take ' + k + ': that is an argument of ' + TOOL_CREATE_READ_NAME)
414
414
  }
415
- if (args.file !== undefined && typeof args.file !== 'string') throw new Error('file 必须是字符串(只有想记出处时才给)')
416
- if (args.file !== undefined && args.date !== undefined) throw new Error('file 与 date 只能给一个')
417
- if (args.date !== undefined && !/^\d{4}-\d{2}-\d{2}$/.test(String(args.date))) throw new Error('date 要写成 YYYY-MM-DD')
418
- if (args.nth !== undefined && (!Number.isInteger(args.nth) || args.nth < 1)) throw new Error('nth 必须是 1 起的整数')
419
- if (args.replace !== undefined && typeof args.replace !== 'boolean') throw new Error('replace 必须是布尔值')
415
+ if (args.file !== undefined && typeof args.file !== 'string') throw new Error('file must be a string (only pass it to record provenance)')
416
+ if (args.file !== undefined && args.date !== undefined) throw new Error('file and date are mutually exclusive')
417
+ if (args.date !== undefined && !/^\d{4}-\d{2}-\d{2}$/.test(String(args.date))) throw new Error('date must be YYYY-MM-DD')
418
+ if (args.nth !== undefined && (!Number.isInteger(args.nth) || args.nth < 1)) throw new Error('nth must be an integer starting at 1')
419
+ if (args.replace !== undefined && typeof args.replace !== 'boolean') throw new Error('replace must be a boolean')
420
420
  }
421
421
 
422
422
  /**
@@ -512,7 +512,7 @@ export function buildToolCreateWriteDefinition({ dshHome, logger }) {
512
512
  const spec = { ...args.toolScript }
513
513
  if (args.file !== undefined || args.date !== undefined) {
514
514
  const cwd = exec?.agent?.session?.header?.cwd
515
- if (typeof cwd !== 'string' || cwd === '') throw new Error(TOOL_CREATE_WRITE_NAME + ' 给了 file/date 就需要知道当前工作区')
515
+ if (typeof cwd !== 'string' || cwd === '') throw new Error(TOOL_CREATE_WRITE_NAME + ' needs the current workspace when file/date is given')
516
516
  const mem = await locateMemory(args, { dshHome, cwd })
517
517
  const kept = spec.provenance && typeof spec.provenance === 'object' ? spec.provenance : {}
518
518
  spec.provenance = { ...kept, memory: typeof kept.memory === 'string' && kept.memory !== '' ? kept.memory : mem }
@@ -558,7 +558,7 @@ function resolveRunCwd(value, { cwd, dir }) {
558
558
  const abs = path.resolve(raw)
559
559
  const inWorkspace = inside(cwd, abs)
560
560
  const inToolScript = inside(dir, abs)
561
- if (!inWorkspace && !inToolScript) throw new Error('cwd 只能是 workspace / toolScript,或落在两者之内的路径:' + raw)
561
+ if (!inWorkspace && !inToolScript) throw new Error('cwd must be workspace / toolScript, or a path inside either: ' + raw)
562
562
  return abs
563
563
  }
564
564
 
@@ -570,14 +570,14 @@ function inside(a, b) {
570
570
 
571
571
  /** 校验一次调用的形状。 */
572
572
  function validateCallShape(call, where) {
573
- if (call === null || typeof call !== 'object' || Array.isArray(call)) throw new Error(where + '必须是对象')
574
- if (typeof call.toolScript !== 'string' || call.toolScript.trim() === '') throw new Error(where + 'toolScript 不能为空')
573
+ if (call === null || typeof call !== 'object' || Array.isArray(call)) throw new Error(where + 'must be an object')
574
+ if (typeof call.toolScript !== 'string' || call.toolScript.trim() === '') throw new Error(where + 'toolScript must not be empty')
575
575
  if (call.args !== undefined && (!Array.isArray(call.args) || call.args.some((a) => typeof a !== 'string' && typeof a !== 'number'))) {
576
- throw new Error(where + 'args 必须是字符串数组')
576
+ throw new Error(where + 'args must be an array of strings')
577
577
  }
578
- if (call.stdin !== undefined && typeof call.stdin !== 'string') throw new Error(where + 'stdin 必须是字符串')
579
- if (call.timeoutMs !== undefined && !Number.isInteger(call.timeoutMs)) throw new Error(where + 'timeoutMs 必须是整数')
580
- if (call.cwd !== undefined && typeof call.cwd !== 'string') throw new Error(where + 'cwd 必须是字符串')
578
+ if (call.stdin !== undefined && typeof call.stdin !== 'string') throw new Error(where + 'stdin must be a string')
579
+ if (call.timeoutMs !== undefined && !Number.isInteger(call.timeoutMs)) throw new Error(where + 'timeoutMs must be an integer')
580
+ if (call.cwd !== undefined && typeof call.cwd !== 'string') throw new Error(where + 'cwd must be a string')
581
581
  }
582
582
 
583
583
  /**
@@ -593,12 +593,12 @@ function validateCallShape(call, where) {
593
593
  */
594
594
  function missingToolScriptMessage(id, detail) {
595
595
  return [
596
- '【这次调用被拦下,一条都没跑】工具组里没有 ' + id + ' 这个工具脚本。',
597
- '底层原因:' + detail,
598
- '为什么清单(系统提示词)里还挂着它:清单按会话冻住——会话中途装/删工具脚本不改系统提示词,' +
599
- '否则整份会话要当未缓存输入重发一遍。所以已删掉的脚本可能继续出现在清单里,直到清单重取或换会话。',
600
- '现在怎么办:不带参数调用 ' + TOOL_CALL_TOOL_NAME + ' 看磁盘上的真名单;' +
601
- '要让本会话的清单按磁盘现状重取,在设置页把「清单词刷新时刻」切一次,或者开一个新会话。'
596
+ '【Call blocked before anything ran】the toolSequence has no toolScript named ' + id + '.',
597
+ 'Underlying cause: ' + detail,
598
+ 'Why the list (system prompt) still shows it: the list is frozen per session — installing or removing toolScripts mid-session does not touch the system prompt, ' +
599
+ 'otherwise the whole conversation would be re-sent as uncached input. So a deleted script can keep appearing in the list until the list is refetched or the session changes.',
600
+ 'What to do: call ' + TOOL_CALL_TOOL_NAME + ' with no arguments to see the real list on disk; ' +
601
+ 'to make this session refetch the list from disk, toggle "When the list is refreshed" once in Settings, or start a new session.'
602
602
  ].join('\n')
603
603
  }
604
604
 
@@ -617,17 +617,17 @@ function planOne({ req, manifest, dir }, { cwd, args, allowDrift }) {
617
617
  const step = req.step === undefined ? manifest.entry : String(req.step)
618
618
  const script = scripts.find((s) => s && s.name === step)
619
619
  if (!script) {
620
- throw new Error('这个工具脚本里没有这个脚本:' + step + '(有:' + scripts.map((s) => s.name).join('、') + ')')
620
+ throw new Error('this toolScript has no such script: ' + step + ' (available: ' + scripts.map((s) => s.name).join(', ') + ')')
621
621
  }
622
622
  const file = resolveInside(dir, step)
623
623
  if (!fsSync.existsSync(file)) {
624
- throw new Error('清单里有这个脚本,磁盘上却没这个文件:' + step + '(重装这个工具脚本,别手删)')
624
+ throw new Error('the manifest lists this script but the file is missing on disk: ' + step + ' (reinstall this toolScript; do not delete files by hand)')
625
625
  }
626
626
  const hashes = manifest.hashes && typeof manifest.hashes === 'object' ? manifest.hashes : {}
627
627
  const expected = typeof hashes[step] === 'string' ? hashes[step] : ''
628
628
  if (expected !== '' && !allowDrift && sha256OfFile(file) !== expected) {
629
- throw new Error('脚本和清单里的 sha256 对不上,先不跑(' + step + ')。' +
630
- '如果你刚手动改过它,重装这个工具脚本(' + TOOL_CREATE_WRITE_NAME + ' + replace),或者这次显式传 allowDrift: true。')
629
+ throw new Error('script sha256 does not match the manifest, refusing to run (' + step + '). ' +
630
+ 'If you just edited it by hand, reinstall the toolScript (' + TOOL_CREATE_WRITE_NAME + ' + replace), or pass allowDrift: true explicitly this time.')
631
631
  }
632
632
  // 未知执行方式:run 只收 bash / node / ps1 / cmd;安装时已校验,这里是兜底。
633
633
  interpreterOf(script.run)
@@ -641,8 +641,8 @@ function planOne({ req, manifest, dir }, { cwd, args, allowDrift }) {
641
641
  : (Array.isArray(manifest.params) ? manifest.params : [])
642
642
  const argvArgs = (req.args ?? []).map(String)
643
643
  if (declared.length > 0 && argvArgs.length > declared.length) {
644
- throw new Error('这次给了 ' + argvArgs.length + ' 个参数,但 ' + step + ' 只声明了 ' + declared.length +
645
- ' 个(' + declared.join(' ') + ');多出来的会错位。要传就把它们写进 toolScript 的 params,别硬塞')
644
+ throw new Error('got ' + argvArgs.length + ' arguments, but ' + step + ' declares only ' + declared.length +
645
+ ' (' + declared.join(' ') + '); extras would shift positions. Put them in the toolScript params instead of forcing them in')
646
646
  }
647
647
  return { step, script, file, runCwd, timeoutMs, argvArgs }
648
648
  }
@@ -717,20 +717,20 @@ export function buildToolCallToolDefinition({ dshHome, logger }) {
717
717
  render: (_args, value) => [{ type: 'text', text: value.text ?? '' }]
718
718
  },
719
719
  async execute(args, exec) {
720
- if (args === null || typeof args !== 'object' || Array.isArray(args)) throw new Error('参数必须是对象')
720
+ if (args === null || typeof args !== 'object' || Array.isArray(args)) throw new Error('arguments must be an object')
721
721
  const cwd = exec?.agent?.session?.header?.cwd
722
- if (typeof cwd !== 'string' || cwd === '') throw new Error(TOOL_CALL_TOOL_NAME + ' 需要知道当前工作区')
722
+ if (typeof cwd !== 'string' || cwd === '') throw new Error(TOOL_CALL_TOOL_NAME + ' needs to know the current workspace')
723
723
 
724
724
  // 不带参数:列名单(注入被关掉时也能看见有什么)
725
725
  if (args.toolScript === undefined && args.calls === undefined) {
726
726
  const list = await listToolScripts(dshHome)
727
727
  const text = list.length === 0
728
- ? '工具组还是空的。要装一个工具脚本:把你刚跑通的那条链用 ' + TOOL_CREATE_WRITE_NAME + ' 写成 toolScript(命令可以来自当前上下文,也可以用 ' + TOOL_CREATE_READ_NAME + ' 从回顾原文里翻回来)。'
729
- : ['工具组 · ' + list.length + ' 个工具脚本:', ...list.map((b) =>
730
- '· ' + b.id + '(' + b.title + '):' + b.purpose + '|入口 ' + b.entry +
731
- (b.params.length > 0 ? '|参数 ' + b.params.join(' ') : '') +
732
- (b.steps.length > 0 ? '|步骤 ' + b.steps.join(' → ') : '')),
733
- '', '跑法:session_tool_call({ toolScript: "<id>" });先看命令加 dryRun: true。'].join('\n')
728
+ ? 'The toolSequence is empty. To install a toolScript, write the chain you just ran with ' + TOOL_CREATE_WRITE_NAME + ' as a toolScript (commands can come from the current context, or be recovered from a review original with ' + TOOL_CREATE_READ_NAME + ').'
729
+ : ['ToolSequence · ' + list.length + ' toolScript(s):', ...list.map((b) =>
730
+ '· ' + b.id + ' (' + b.title + '): ' + b.purpose + '|entry ' + b.entry +
731
+ (b.params.length > 0 ? '|args ' + b.params.join(' ') : '') +
732
+ (b.steps.length > 0 ? '|steps ' + b.steps.join(' → ') : '')),
733
+ '', 'Run: session_tool_call({ toolScript: "<id>" }); add dryRun: true to see the commands first.'].join('\n')
734
734
  return jsonSafe({ mode: 'list', text })
735
735
  }
736
736
 
@@ -738,9 +738,9 @@ export function buildToolCallToolDefinition({ dshHome, logger }) {
738
738
  const requests = []
739
739
  if (Array.isArray(args.calls)) {
740
740
  if (args.toolScript !== undefined || args.step !== undefined) {
741
- throw new Error('给了 calls 就别再给顶层 toolScript / step:每一项自带')
741
+ throw new Error('with calls, do not also pass top-level toolScript / step: each item carries its own')
742
742
  }
743
- if (args.calls.length === 0) throw new Error('calls 不能是空数组')
743
+ if (args.calls.length === 0) throw new Error('calls must not be an empty array')
744
744
  // 0.4.11:去掉「一次最多 20 条」的死上线,按给的顺序全跑。
745
745
  args.calls.forEach((c, i) => { validateCallShape(c, 'calls[' + i + ']:'); requests.push(c) })
746
746
  } else {
@@ -798,9 +798,9 @@ export function buildToolCallToolDefinition({ dshHome, logger }) {
798
798
  } catch (err) {
799
799
  // 只有真跑才会暴露的错(解释器不在、spawn 失败):补上现场后照样抛,不吞。
800
800
  const done = runs.length > 0
801
- ? '\n\n这次调用里先跑完的 ' + runs.length + ' 条(输出没丢):\n' + renderRuns({ runs, dryRun: false, skipped: 0 })
801
+ ? '\n\nthe ' + runs.length + ' call(s) that finished first in this invocation (output preserved):\n' + renderRuns({ runs, dryRun: false, skipped: 0 })
802
802
  : ''
803
- throw new Error('这条没跑起来,整次调用算失败:' + p.id + ' / ' + p.step + '\n' +
803
+ throw new Error('this call did not start, so the whole invocation counts as failed: ' + p.id + ' / ' + p.step + '\n' +
804
804
  String(err?.message ?? err) + done, { cause: err })
805
805
  }
806
806
  // 0.4.11:超时不再杀进程,转后台继续跑——这不是失败,是「还没跑完」。
@@ -824,9 +824,9 @@ export function buildToolCallToolDefinition({ dshHome, logger }) {
824
824
  const crashed = runs.filter((r) => r.status === 'fail')
825
825
  if (crashed.length > 0) {
826
826
  const names = crashed.map((r) => r.toolScript + ' / ' + r.step +
827
- '(exit ' + (r.exitCode === null ? 'null' : r.exitCode) + (r.timedOut ? ',超时被终止' : '') + ')').join('、')
827
+ '(exit ' + (r.exitCode === null ? 'null' : r.exitCode) + (r.timedOut ? ', killed on timeout' : '') + ')').join(', ')
828
828
  throw new Error(
829
- '【这次调用没成功】' + crashed.length + ' 条没跑成:' + names + '\n\n' +
829
+ '【Invocation failed】' + crashed.length + ' call(s) did not run: ' + names + '\n\n' +
830
830
  renderRuns({ runs, dryRun: false, skipped })
831
831
  )
832
832
  }
@@ -854,44 +854,44 @@ export function buildToolCallToolDefinition({ dshHome, logger }) {
854
854
  /** 跑完之后的回报文本:一条一块,失败先说清楚在哪一步。 */
855
855
  export function renderRuns({ runs, dryRun, skipped }) {
856
856
  const lines = []
857
- if (dryRun) lines.push('只回显不执行(dryRun)——看清 argv 再真跑。')
857
+ if (dryRun) lines.push('Echo only, nothing executed (dryRun) — check the argv before running for real.')
858
858
  for (const r of runs) {
859
859
  if (r.status === 'dry') {
860
860
  lines.push('▸ ' + r.toolScript + ' / ' + r.step + '(' + r.run + ')')
861
861
  lines.push(' argv: ' + JSON.stringify(r.argv))
862
- lines.push(' cwd: ' + r.cwd + ' 超时: ' + r.timeoutMs + 'ms 输出上限: ' + r.maxOutputBytes + ' 字节')
862
+ lines.push(' cwd: ' + r.cwd + ' timeout: ' + r.timeoutMs + 'ms output cap: ' + r.maxOutputBytes + ' bytes')
863
863
  if (r.limits) lines.push(' ' + r.limits)
864
864
  continue
865
865
  }
866
866
  if (r.status === 'error') {
867
- lines.push('✗ ' + r.toolScript + (r.step ? (' / ' + r.step) : '') + ' 没跑起来:' + r.error)
867
+ lines.push('✗ ' + r.toolScript + (r.step ? (' / ' + r.step) : '') + ' did not start: ' + r.error)
868
868
  continue
869
869
  }
870
870
  if (r.status === 'background') {
871
871
  // 0.4.10 及以前这里是「超时已终止」;0.4.11 起进程活着,输出继续往日志里写。
872
- lines.push('⏳ ' + r.toolScript + ' / ' + r.step + ' 【仍在运行 after ' + r.timeoutMs +
872
+ lines.push('⏳ ' + r.toolScript + ' / ' + r.step + ' 【still running after ' + r.timeoutMs +
873
873
  'ms; moved to background】pid ' + r.pid)
874
- lines.push(' 它没有被杀,还在跑,后面会继续往这个文件里写:')
874
+ lines.push(' It was not killed; it keeps running and will keep writing to this file:')
875
875
  lines.push(' ' + r.logFile + (r.stderrFile ? '(stderr: ' + r.stderrFile + ')' : ''))
876
876
  const head = String(r.stdout ?? '').replace(/\s+$/, '')
877
- if (head !== '') lines.push(' —— 已经写出来的部分 ——', head)
877
+ if (head !== '') lines.push(' —— output so far ——', head)
878
878
  const errHead = String(r.stderr ?? '').replace(/\s+$/, '')
879
879
  if (errHead !== '') lines.push(' —— stderr ——', errHead)
880
- lines.push(' 要看后续输出:读上面那个文件(tail 它);要停它:kill ' + r.pid)
880
+ lines.push(' To follow it: read that file (tail it); to stop it: kill ' + r.pid)
881
881
  continue
882
882
  }
883
883
  const head = (r.status === 'ok' ? '✔ ' : '✗ ') + r.toolScript + ' / ' + r.step +
884
884
  ' exit ' + (r.exitCode === null ? 'null' : r.exitCode) +
885
885
  ' ' + r.durationMs + 'ms' +
886
- (r.drift ? ' 【脚本和清单哈希不一致,这次是显式放行】' : '')
886
+ (r.drift ? ' 【script hash differs from the manifest; explicitly allowed this time】' : '')
887
887
  lines.push(head)
888
888
  const out = String(r.stdout ?? '').replace(/\s+$/, '')
889
889
  const err = String(r.stderr ?? '').replace(/\s+$/, '')
890
890
  if (out !== '') lines.push(out)
891
891
  if (err !== '') lines.push('--- stderr ---', err)
892
- if (r.truncated) lines.push('(输出被截断,完整内容:' + (r.spill || '溢写失败') + ')')
892
+ if (r.truncated) lines.push('(output truncated; full content: ' + (r.spill || 'spill failed') + ')')
893
893
  }
894
- if (skipped > 0) lines.push('还有 ' + skipped + ' 条没跑(前面失败,stopOnError 生效了)。')
894
+ if (skipped > 0) lines.push(skipped + ' call(s) did not run (an earlier one failed, so stopOnError took effect).')
895
895
  return lines.join('\n')
896
896
  }
897
897