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.
- package/README.en.md +185 -165
- package/README.md +179 -184
- package/lib/client.js +818 -7
- package/lib/core/assembly.js +8 -8
- package/lib/core/host-limits.js +5 -5
- package/lib/core/index.js +38 -31
- package/lib/core/inject.js +1 -1
- package/lib/core/lang.js +418 -75
- package/lib/core/locale.js +1 -1
- package/lib/core/memory-file.js +2 -5
- package/lib/core/migrate.js +1 -1
- package/lib/core/path-guard.js +4 -4
- package/lib/core/schema-runner.js +10 -10
- package/lib/core/schema-tools.js +88 -88
- package/lib/core/schema.js +49 -61
- package/lib/core/search.js +1 -1
- package/lib/core/settings.js +1 -1
- package/lib/core/store.js +1 -1
- package/lib/core/tool-transfer.js +14 -14
- package/lib/core/tool.js +71 -71
- package/lib/core/zip.js +35 -35
- package/lib/core/zstd-js.js +50 -50
- package/lib/core/zstd.js +1 -1
- package/lib/host/capabilities.js +3 -3
- package/lib/host/compact-delete.js +191 -27
- package/lib/host/delete.js +48 -20
- package/lib/host/host-contract.js +2 -2
- package/lib/host/http-util.js +1 -1
- package/lib/host/lifecycle.js +2 -2
- package/lib/host/register.js +3 -3
- package/lib/host/routes/memories.js +7 -7
- package/lib/host/routes/sessions.js +8 -8
- package/lib/host/routes/tools.js +6 -6
- package/package.json +4 -3
package/lib/core/assembly.js
CHANGED
|
@@ -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
|
-
'
|
|
211
|
-
'
|
|
212
|
-
'
|
|
213
|
-
(biggest ? '
|
|
214
|
-
'
|
|
215
|
-
'
|
|
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: '
|
|
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: '
|
|
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))
|
package/lib/core/host-limits.js
CHANGED
|
@@ -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
|
-
? '
|
|
166
|
+
? 'following the host terminal settings (' + source + ')'
|
|
167
167
|
: (sources.size === 0
|
|
168
|
-
? '
|
|
169
|
-
: '
|
|
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 + '
|
|
189
|
-
'ms
|
|
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?.('
|
|
208
|
-
else logger.warn?.('
|
|
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?.('
|
|
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?.('
|
|
219
|
-
void recordHealth(dshHome, '(harness)', { ok: false, code: 'host-capability', message: '
|
|
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?.('
|
|
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?.('
|
|
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?.('
|
|
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?.('
|
|
254
|
-
else if (res.added) logger.info?.('
|
|
255
|
-
else logger.info?.('
|
|
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?.('
|
|
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?.('
|
|
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?.('
|
|
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?.('
|
|
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?.('
|
|
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?.('
|
|
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?.('
|
|
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?.('
|
|
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?.('
|
|
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?.('
|
|
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?.('
|
|
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?.('
|
|
443
|
+
try { off() } catch (err) { logger.warn?.('failed to uninstall tool: ' + name + ' ' + (err?.message ?? err)) }
|
|
444
444
|
live.delete(name)
|
|
445
|
-
logger.info?.('
|
|
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?.('
|
|
451
|
+
logger.info?.('tool installed: ' + name)
|
|
452
452
|
}
|
|
453
453
|
return [...want.keys()]
|
|
454
454
|
}
|
|
@@ -461,21 +461,28 @@ 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?.('
|
|
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?.('
|
|
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'),
|
|
476
476
|
agents: webCtx.get('agents'),
|
|
477
477
|
workspaceRegistry: webCtx.get('workspaceRegistry'),
|
|
478
|
-
compaction: webCtx.get('compaction')
|
|
478
|
+
compaction: webCtx.get('compaction'),
|
|
479
|
+
// 0.5.3 本地修复:会话不在内存里时要 resume,宿主自己的组合入口才挂得上预设(含压缩)与模型。
|
|
480
|
+
sessionController: webCtx.get('sessionController'),
|
|
481
|
+
// 「删除并回顾」走 /compact 命令:压缩后端在预设隔离作用域里,只有命令处理器的 ctx 看得到。
|
|
482
|
+
commands: webCtx.get('commands'),
|
|
483
|
+
// 删完目录要让宿主索引忘掉它,否则设置页列表和搜索留幽灵。
|
|
484
|
+
sessionProjectionCache: webCtx.get('sessionProjectionCache'),
|
|
485
|
+
sessionQuery: webCtx.get('sessionQuery')
|
|
479
486
|
})
|
|
480
487
|
// 0.4.1:选项一落盘就同步工具,赶在下一次 systemPrompt.assemble() 之前。
|
|
481
488
|
// 0.4.6:切「清单词刷新时刻」那一下,把所有已记住的会话刷新成此刻的现词。
|
package/lib/core/inject.js
CHANGED
|
@@ -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 }
|