dsh-seal-scripts 0.5.0 → 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.
@@ -207,12 +207,12 @@ export function oversizeDiagnostic(dshHome, cwd, error) {
207
207
  const total = files.reduce((n, f) => n + f.bytes, 0)
208
208
  const biggest = files[0]
209
209
  const lines = [
210
- '【回顾没有载入成功】工作区 ' + cwd + ' 的回顾装配失败,最可能是回顾过大。',
211
- '目录:' + dir,
212
- '现状:' + files.length + ' 份,合计 ' + kb(total) +
213
- (biggest ? ',最大 ' + biggest.name + '(' + kb(biggest.bytes) + ')' : ''),
214
- '处理:换到别的工作区的会话,或把上面最大的那份回顾删掉、精简后再回来。',
215
- '原始错误:' + (error && error.message ? error.message : String(error))
210
+ '【Review assembly failed】assembling reviews for workspace ' + cwd + ' failed; most likely the reviews are too large.',
211
+ 'Directory: ' + dir,
212
+ 'Now: ' + files.length + ' file(s), ' + kb(total) + ' in total' +
213
+ (biggest ? ', biggest ' + biggest.name + ' (' + kb(biggest.bytes) + ')' : ''),
214
+ 'Fix: switch to a session in another workspace, or delete/trim the biggest review above and come back.',
215
+ 'Original error: ' + (error && error.message ? error.message : String(error))
216
216
  ]
217
217
  return lines.join('\n')
218
218
  }
@@ -295,11 +295,11 @@ export function describeEntry(dshHome, cwd, file, now = new Date(), options = re
295
295
  ? data.entries.find((e) => e && e.file === name)
296
296
  : null
297
297
  if (!entry) {
298
- return { file: name, text: '', chars: 0, level: null, age: null, error: '这条回顾不在载入清单里:' + name }
298
+ return { file: name, text: '', chars: 0, level: null, age: null, error: 'this review is not in the load list: ' + name }
299
299
  }
300
300
  const parsed = readMemorySync(dir, entry.file)
301
301
  if (!parsed) {
302
- return { file: name, text: '', chars: 0, level: null, age: null, error: '读不出这份回顾:' + entry.file }
302
+ return { file: name, text: '', chars: 0, level: null, age: null, error: 'cannot read this review: ' + entry.file }
303
303
  }
304
304
  const level = loadLevel(entry, now, options)
305
305
  const text = renderEntry(entry, parsed, level, options, readLocaleSync(dshHome))
@@ -163,10 +163,10 @@ export function readHostLimits({ ctx = null, force = false } = {}) {
163
163
 
164
164
  const source = sources.size === 0 ? 'dsh-defaults' : [...sources].join('+')
165
165
  const note = missed.length === 0
166
- ? '跟随宿主终端设置(' + source + ')'
166
+ ? 'following the host terminal settings (' + source + ')'
167
167
  : (sources.size === 0
168
- ? '读不到宿主终端设置(没有 ctx.shell.config,也没有 settings.describe().' + SETTINGS_NS[0] + '),这一轮按 DSH 默认值走'
169
- : '部分跟随宿主终端设置(' + source + ');未读到:' + missed.join('、') + ',这几项按 DSH 默认值走')
168
+ ? 'cannot read the host terminal settings (no ctx.shell.config, and settings.describe().' + SETTINGS_NS[0] + ' is missing), using DSH defaults this turn'
169
+ : 'partly following the host terminal settings (' + source + '); not read: ' + missed.join(', ') + ', those fall back to DSH defaults')
170
170
 
171
171
  const result = {
172
172
  timeoutMs: out.timeoutMs,
@@ -185,8 +185,8 @@ export function readHostLimits({ ctx = null, force = false } = {}) {
185
185
 
186
186
  /** 一行的说明,给日志与 dryRun 回报用。 */
187
187
  export function describeHostLimits(limits = readHostLimits()) {
188
- return limits.note + ':超时默认 ' + limits.timeoutMs + 'ms,上限 ' + limits.maxTimeoutMs +
189
- 'ms,单流输出 ' + limits.maxOutputBytes + ' 字节'
188
+ return limits.note + ': timeout default ' + limits.timeoutMs + 'ms, cap ' + limits.maxTimeoutMs +
189
+ 'ms, per-stream output ' + limits.maxOutputBytes + ' bytes'
190
190
  }
191
191
 
192
192
  /**
package/lib/core/index.js CHANGED
@@ -153,7 +153,7 @@ export function waitForSplitOf(sessionId, timeoutMs = 120_000) {
153
153
  return new Promise((resolve, reject) => {
154
154
  const timer = setTimeout(() => {
155
155
  splitWaiters.get(sessionId)?.delete(done)
156
- reject(new Error('等拆回顾超时'))
156
+ reject(new Error('timed out waiting for the review to be captured'))
157
157
  }, timeoutMs)
158
158
  const done = (value) => { clearTimeout(timer); resolve(value) }
159
159
  if (!splitWaiters.has(sessionId)) splitWaiters.set(sessionId, new Set())
@@ -197,17 +197,17 @@ export function apply(ctx, config = {}) {
197
197
  // 所以这里先探到 zstd(进程级),其余各项在各自的 inject 回调里再探、合并。
198
198
  // ── 0.4.11:超时与输出上限跟着宿主的终端设置走 ──────────────
199
199
  // 这里只绑上下文,真正取值在每次跑脚本时现读(设置页一改,下一次执行就生效)。
200
- ctx.effect(() => bindHostLimits(ctx), 'dsh-seal-scripts: 绑定宿主终端设置')
200
+ ctx.effect(() => bindHostLimits(ctx), 'dsh-seal-scripts: bind host terminal settings')
201
201
  ctx.on('settings/document-updated', () => { invalidateHostLimits() })
202
202
  // shell 服务起来之后读一次并写日志:跟随成功/失败都留一句,用户重启后能在日志里看见原因。
203
203
  ctx.inject(['shell'], () => {
204
204
  try {
205
205
  const limits = readHostLimits({ force: true })
206
206
  const line = describeHostLimits(limits)
207
- if (limits.missed.length === 0) logger.info?.('终端设置:' + line)
208
- else logger.warn?.('终端设置:' + line)
207
+ if (limits.missed.length === 0) logger.info?.('terminal settings: ' + line)
208
+ else logger.warn?.('terminal settings: ' + line)
209
209
  } catch (err) {
210
- logger.warn?.('读宿主终端设置失败:' + (err?.message ?? err))
210
+ logger.warn?.('failed to read host terminal settings: ' + (err?.message ?? err))
211
211
  }
212
212
  })
213
213
 
@@ -215,15 +215,15 @@ export function apply(ctx, config = {}) {
215
215
  // 只探 zstd:宿主服务此刻多半还没起来,探全表会把「还没看到」误报成「没有」。
216
216
  capabilities.probe(undefined, { only: ['zstd.decompress'] })
217
217
  if (capabilities.state.table['zstd.decompress'] !== true) {
218
- logger.warn?.('当前 Node 没有 zlib.zstdDecompressSync,会话标题读不出来(回顾本身不受影响)')
219
- void recordHealth(dshHome, '(harness)', { ok: false, code: 'host-capability', message: '当前 Node 缺 zlib.zstdDecompressSync' })
218
+ logger.warn?.('this Node lacks zlib.zstdDecompressSync, so session titles cannot be read (reviews are unaffected)')
219
+ void recordHealth(dshHome, '(harness)', { ok: false, code: 'host-capability', message: 'this Node lacks zlib.zstdDecompressSync' })
220
220
  }
221
221
  // 每个 inject 回调里调用:只把「这次新发现缺的」写一次日志。
222
222
  const reportMissing = (opts) => {
223
223
  const fresh = capabilities.probe(undefined, opts)
224
224
  if (fresh.length === 0) return capabilities.state
225
225
  const text = describeMissing({ missing: fresh })
226
- logger.warn?.('宿主能力不全,相关功能已降级:' + text)
226
+ logger.warn?.('host capabilities are incomplete; affected features are degraded: ' + text)
227
227
  void recordHealth(dshHome, '(harness)', { ok: false, code: 'host-capability', message: text })
228
228
  return capabilities.state
229
229
  }
@@ -231,7 +231,7 @@ export function apply(ctx, config = {}) {
231
231
 
232
232
  // 工具组目录一启动就建好:空目录也留在 $DSH_HOME/session-memory/ 下面,看得见。
233
233
  void ensureToolSequenceDir(dshHome).catch((err) => {
234
- logger.warn?.('建工具组目录失败:' + (err?.message ?? err))
234
+ logger.warn?.('failed to create the toolSequence directory: ' + (err?.message ?? err))
235
235
  })
236
236
 
237
237
  // ── 拆:压缩一结束就落盘 ──────────────────────────────
@@ -245,14 +245,14 @@ export function apply(ctx, config = {}) {
245
245
  if (typeof depth === 'number' && depth > 0) return
246
246
  const cwd = session?.header?.cwd
247
247
  if (typeof cwd !== 'string' || cwd === '') {
248
- logger.warn?.('压缩事件没有工作目录,跳过:' + (session?.id ?? '?'))
248
+ logger.warn?.('compaction event has no workspace, skipping: ' + (session?.id ?? '?'))
249
249
  return
250
250
  }
251
251
  void captureCompaction({ dshHome, cwd, session, event, lang: readLocaleSync(dshHome) })
252
252
  .then((res) => {
253
- if (res.skipped === true) logger.info?.('这次压缩的内容已经记过,不重复落盘:' + res.reason)
254
- else if (res.added) logger.info?.('拆出回顾 ' + res.file + '(' + res.bytes + ' 字节)→ ' + res.dir)
255
- else logger.info?.('回顾已存在,跳过 ' + res.file)
253
+ if (res.skipped === true) logger.info?.('this compaction was already recorded, not writing again: ' + res.reason)
254
+ else if (res.added) logger.info?.('captured review ' + res.file + ' (' + res.bytes + ' bytes) → ' + res.dir)
255
+ else logger.info?.('review already exists, skipping ' + res.file)
256
256
  void recordHealth(dshHome, cwd, { ok: true, file: res.file ?? '' })
257
257
  // X2:拆解成功时顺手做一次极便宜的宿主格式探测(readdir + 最多 4 字节)。
258
258
  // 宿主改了会话日志格式的话,这里留下 _health.json,设置页能看见,而不是「标题突然全空」。
@@ -262,7 +262,7 @@ export function apply(ctx, config = {}) {
262
262
  if (typeof root === 'string' && root !== '' && typeof session.id === 'string') {
263
263
  const fmt = probeHostFormat(sessionDirOf(root, cwd, session.id))
264
264
  if (fmt.ok === false) {
265
- logger.warn?.('宿主会话格式可能有变:' + fmt.detail)
265
+ logger.warn?.('host session format may have changed: ' + fmt.detail)
266
266
  void recordHealth(dshHome, cwd, { ok: false, code: 'host-format-changed', message: fmt.detail })
267
267
  }
268
268
  }
@@ -270,7 +270,7 @@ export function apply(ctx, config = {}) {
270
270
  settleSplits(session.id, res)
271
271
  })
272
272
  .catch((err) => {
273
- logger.error?.('拆回顾失败:' + (err?.stack ?? err))
273
+ logger.error?.('review capture failed: ' + (err?.stack ?? err))
274
274
  // 失败必须留下痕迹:用户看不到日志,只看得到设置页。
275
275
  // recordHealth 自己吞掉所有异常(它就跑在 catch 里),不会把 settleSplits 带走。
276
276
  void recordHealth(dshHome, cwd, { ok: false, code: err?.code ?? 'capture-failed', message: err?.message ?? String(err) })
@@ -291,7 +291,7 @@ export function apply(ctx, config = {}) {
291
291
  const decision = await next()
292
292
  try {
293
293
  // 0.4.0:开关可能刚被设置页改过,工具按当前开关重装一遍(幂等,没变就什么都不做)。
294
- try { toolGate.sync?.() } catch (err) { logger.warn?.('同步工具失败:' + (err?.message ?? err)) }
294
+ try { toolGate.sync?.() } catch (err) { logger.warn?.('failed to sync tools: ' + (err?.message ?? err)) }
295
295
  if (decision === null || typeof decision !== 'object') return decision
296
296
  if (decision.kind === 'reject') return decision
297
297
  const session = payload?.agent?.session
@@ -312,12 +312,12 @@ export function apply(ctx, config = {}) {
312
312
  messages.push(plan.message)
313
313
  touched = true
314
314
  } else if (plan.mode === 'direct' && plan.result.fallbackFrom !== undefined) {
315
- logger.warn?.('回顾替换失败,退回追加:' + plan.result.fallbackFrom)
315
+ logger.warn?.('review replacement failed, falling back to append: ' + plan.result.fallbackFrom)
316
316
  }
317
317
 
318
318
  if (touched) return { ...decision, messages }
319
319
  } catch (err) {
320
- logger.error?.('回顾注入失败(本轮退回 runtime-context):' + (err?.stack ?? err))
320
+ logger.error?.('review injection failed (falling back to runtime-context this turn): ' + (err?.stack ?? err))
321
321
  }
322
322
  return decision
323
323
  })
@@ -325,7 +325,7 @@ export function apply(ctx, config = {}) {
325
325
  // ── 装(兜底):只有在主通道还没落过时才供货 ──────────────
326
326
  ctx.inject(['systemPrompt'], (scope) => {
327
327
  reportMissing({ only: ['systemPrompt.context', 'systemPrompt.section', 'systemPrompt.getSectionOrder'] })
328
- if (cap()['systemPrompt.context'] !== true) logger.warn?.('宿主没有 systemPrompt.context(),回顾注入已关闭')
328
+ if (cap()['systemPrompt.context'] !== true) logger.warn?.('host has no systemPrompt.context(); review injection is off')
329
329
  if (cap()['systemPrompt.context'] === true) scope.systemPrompt.context({
330
330
  name: CONTEXT_NAME,
331
331
  order: CONTEXT_ORDER,
@@ -345,7 +345,7 @@ export function apply(ctx, config = {}) {
345
345
 
346
346
  // 日记提醒:系统提示词段。只有「概括提醒 = 在系统侧提醒」时供货;
347
347
  // 另一档(默认)把它并进回顾正文,这里返回空串,renderPrompt 会把这个段整个滤掉。
348
- if (cap()['systemPrompt.section'] !== true) logger.warn?.('宿主没有 systemPrompt.section(),日记提醒与工具组清单不出现')
348
+ if (cap()['systemPrompt.section'] !== true) logger.warn?.('host has no systemPrompt.section(); diary reminders and the toolSequence list will not appear')
349
349
  if (cap()['systemPrompt.section'] === true) scope.systemPrompt.section({
350
350
  name: DIARY_SECTION_NAME,
351
351
  order: diarySectionOrder(scope.systemPrompt),
@@ -364,7 +364,7 @@ export function apply(ctx, config = {}) {
364
364
  if (options.reminderChannel !== REMINDER_SYSTEM) return ''
365
365
  return diaryReminder(dshHome, cwd, new Date(), options)
366
366
  } catch (err) {
367
- logger.error?.('日记提醒失败:' + (err?.stack ?? err))
367
+ logger.error?.('diary reminder failed: ' + (err?.stack ?? err))
368
368
  return ''
369
369
  }
370
370
  }
@@ -383,7 +383,7 @@ export function apply(ctx, config = {}) {
383
383
  try {
384
384
  return toolListSectionText(dshHome, promptContext)
385
385
  } catch (err) {
386
- logger.error?.('工具组清单失败:' + (err?.stack ?? err))
386
+ logger.error?.('toolSequence list failed: ' + (err?.stack ?? err))
387
387
  return ''
388
388
  }
389
389
  }
@@ -394,7 +394,7 @@ export function apply(ctx, config = {}) {
394
394
  ctx.inject(['tools'], (scope) => {
395
395
  reportMissing({ only: ['tools.register'] })
396
396
  if (cap()['tools.register'] !== true) {
397
- logger.warn?.('宿主没有 tools.register(),回顾工具不装')
397
+ logger.warn?.('host has no tools.register(); review tools are not installed')
398
398
  return
399
399
  }
400
400
  // 深度只在「read 工具真的把本工作区自己那份回顾读出去」时加一级,由插件侧记账:
@@ -404,7 +404,7 @@ export function apply(ctx, config = {}) {
404
404
  try {
405
405
  await bumpHits(memoryDir(dshHome, res.workspace), res.workspace, res.hits.map((h) => h.file), new Date())
406
406
  } catch (err) {
407
- logger.error?.('回顾深度失败:' + (err?.stack ?? err))
407
+ logger.error?.('review depth failed: ' + (err?.stack ?? err))
408
408
  }
409
409
  }
410
410
  // 0.4.0:两组工具分别跟着两个开关走,按需装载。
@@ -440,15 +440,15 @@ export function apply(ctx, config = {}) {
440
440
  if (options.toolListEnabled !== false) for (const d of kitTools) want.set(d.name, d)
441
441
  for (const [name, off] of [...live]) {
442
442
  if (want.has(name)) continue
443
- try { off() } catch (err) { logger.warn?.('卸载工具失败:' + name + ' ' + (err?.message ?? err)) }
443
+ try { off() } catch (err) { logger.warn?.('failed to uninstall tool: ' + name + ' ' + (err?.message ?? err)) }
444
444
  live.delete(name)
445
- logger.info?.('工具已卸载:' + name)
445
+ logger.info?.('tool uninstalled: ' + name)
446
446
  }
447
447
  for (const [name, definition] of want) {
448
448
  if (live.has(name)) continue
449
449
  const off = scope.tools.register(definition)
450
450
  live.set(name, typeof off === 'function' ? off : () => {})
451
- logger.info?.('工具已装载:' + name)
451
+ logger.info?.('tool installed: ' + name)
452
452
  }
453
453
  return [...want.keys()]
454
454
  }
@@ -461,15 +461,15 @@ export function apply(ctx, config = {}) {
461
461
  ctx.inject(['webServer', 'connection', 'agents'], (webCtx) => {
462
462
  reportMissing({ only: ['webServer.register', 'connection.requestRejection', 'agents.create', 'agents.resume'] })
463
463
  if (cap()['webServer.register'] !== true) {
464
- logger.warn?.('宿主没有 webServer.register(),设置页接口不装')
464
+ logger.warn?.('host has no webServer.register(); settings routes are not installed')
465
465
  return
466
466
  }
467
467
  // 缺 agents 的公开 create/resume 时:不装生命周期捕获(以前在这里 throw,
468
468
  // 症状是设置页那半块整个没加载),只关掉「删除活会话 / 删除并回顾」;
469
469
  // 列表与回顾管理照常——它们只依赖 persistence 与文件系统。
470
470
  const canLifecycle = cap()['agents.create'] === true && cap()['agents.resume'] === true
471
- if (canLifecycle) webCtx.effect(() => installLifecycle(webCtx.agents, logger), 'dsh-seal-scripts: 生命周期捕获')
472
- else logger.warn?.('宿主缺 agents.create/resume,删除活会话与「删除并回顾」已关闭')
471
+ if (canLifecycle) webCtx.effect(() => installLifecycle(webCtx.agents, logger), 'dsh-seal-scripts: lifecycle capture')
472
+ else logger.warn?.('host lacks agents.create/resume; deleting live sessions and "Delete + review" are off')
473
473
  const getDeps = () => ({
474
474
  persistence: webCtx.get('sessionPersistence'),
475
475
  sessions: webCtx.get('sessions'),
@@ -125,7 +125,7 @@ export function planInjection(session, text) {
125
125
  export function injectMemory(session, text) {
126
126
  const value = String(text ?? '')
127
127
  if (session === null || typeof session !== 'object' || typeof session.append !== 'function') {
128
- throw new Error('没有可写入的会话')
128
+ throw new Error('no session to write into')
129
129
  }
130
130
  const previous = memoryNodeOnSurface(session)
131
131
  if (previous !== null && previous.text === value) return { action: 'skip', seq: previous.seq }