dsh-seal-scripts 0.4.12 → 0.5.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.
package/README.en.md CHANGED
@@ -184,6 +184,17 @@ Changing that mode refreshes every remembered session to the current list — so
184
184
  - `_index.json` inside the package is not trusted; the index is rebuilt from the files on disk. `_runs`, backup directories, escaping paths and invalid ids are skipped.
185
185
  - Limits: 64 MB per entry, 128 MB total; zip64 and encrypted archives are not supported.
186
186
 
187
+ ### Clear cache (0.5.1)
188
+
189
+ The **Clear cache** button sits at the right end of the import / export row. It takes two clicks (the first only turns the button into "Confirm clear" and spells out what will go).
190
+
191
+ - **Deleted**: every `<id>.bak-<timestamp>` rollback version (the old directory kept by a reinstall or an import), and every run log in `_runs/`.
192
+ - **Kept**: `_index.json` and every `<id>/` toolScript directory — tools keep running and the index is not rebuilt. Those two live outside the index, which is exactly why the rest is safe to drop.
193
+ - Only directories named "valid id + `.bak-` + digits" count as rollback versions; anything else is left alone (better to under-delete).
194
+ - If an import is in flight, the package it staged inside `_runs/` is skipped and the receipt says how many were skipped.
195
+ - One entry that cannot be removed (in use or no permission) does not abort the run: the rest still go, and the receipt says "N could not be removed".
196
+ - The receipt reports how many rollback versions, how many run logs, and how many bytes were cleared.
197
+
187
198
  ## Reviews and context memory
188
199
 
189
200
  The problem reviews solve: after compaction the earlier detail is normally gone. Now the shadowed transcript is kept as a file and can be read back when it matters.
@@ -265,7 +276,7 @@ Settings → **Tool (script) manager**, four tabs:
265
276
 
266
277
  | Tab | Contents |
267
278
  |---|---|
268
- | Sealed tools (shown as `toolList` in the English UI) | tool path, the prompt text about to be injected, "Inject toolSequence list" toggle and refresh mode, import / export |
279
+ | Sealed tools (shown as `toolList` in the English UI) | tool path, the prompt text about to be injected, "Inject toolSequence list" toggle and refresh mode, import / export / clear cache |
269
280
  | Sessions | sessions grouped by workspace (title, archived badge), Delete / Delete + review, both confirmed |
270
281
  | Reviews | calendar range filter, review list with depth badges, injection preview, delete one review |
271
282
  | Options | four groups: Sealed tools, Recall injection, Review content, Review depth |
package/README.md CHANGED
@@ -194,6 +194,17 @@ $DSH_HOME/session-memory/toolSequence/
194
194
  - **导入**:选 zip → 先 `dryRun` 预览「会装哪些 / 会盖哪些 / 跳过哪些」→ 确认才写;同名目录留 `.bak-<时间戳>`。
195
195
  - 包内的 `_index.json` 不采信,索引按落地文件重建;`_runs`、备份目录、越界路径、非法 id 一律跳过。
196
196
  - 大小:不设死上限。0.4.11 起导入先把请求体流式落盘、再逐条解进 staging(不吃内存),解压炸弹按「解压后总字节 + 16 MB 余量 vs 磁盘可用空间」判——装不下才拒绝。不支持 zip64 与加密包。
197
+
198
+ ### 清除缓存(0.5.1)
199
+
200
+ 导入 / 导出那一行最右边的「清除缓存」,两下才动手(第一下只把按钮换成「确认清除」并写明会删什么):
201
+
202
+ - **删**:所有 `<id>.bak-<时间戳>` 回滚版本(覆盖安装 / 导入留下的旧目录)、`_runs/` 里的全部运行日志。
203
+ - **不删**:`_index.json` 与每个 `<id>/` 工具脚本目录——清完工具照常跑,索引不重建;也正因为这两类东西不在索引里,才删得干净。
204
+ - 只有名字是「合法 id + `.bak-` + 纯数字」的目录才算回滚版本;别的目录一个都不碰(宁可少删)。
205
+ - 正有一个导入在进行时,它落在 `_runs/` 的临时包会被跳过,回执里会写明跳过了几个。
206
+ - 单个条目删不掉(被占用、没权限)不中断整轮:其余照删,回执里写「有 N 项没删掉」。
207
+ - 回执写明清掉了多少个回滚版本、多少个运行日志、共多少字节。
197
208
  <a name="sec-reviews"></a>
198
209
 
199
210
 
@@ -282,7 +293,7 @@ $DSH_HOME/session-memory/toolSequence/
282
293
 
283
294
  | 标签 | 内容 |
284
295
  |---|---|
285
- | 自创工具 | 工具路径、即将注入的系统提示词原文、清单开关与刷新时刻、导入 / 导出 |
296
+ | 自创工具 | 工具路径、即将注入的系统提示词原文、清单开关与刷新时刻、导入 / 导出 / 清除缓存 |
286
297
  | 会话 | 按工作区分组的会话列表(标题、归档徽章),删除 / 删除并回顾(都二次确认) |
287
298
  | 回顾 | 日历区间筛选、回顾列表(深度徽章)、注入预览、删除单条 |
288
299
  | 选项 | 四组:工具固存、回顾注入、回顾内容、回顾深度 |
package/lib/client.js CHANGED
@@ -6,12 +6,12 @@ window.__ModuleLoader__.load({
6
6
  var React = require('react')
7
7
  var h = React.createElement
8
8
 
9
- var API = '/api/session-recall.'
10
- var NS = 'session-recall'
9
+ var API = '/api/session-seal-scripts.'
10
+ var NS = 'session-seal-scripts'
11
11
 
12
12
  /* ── 语言(0.2.3)────────────────────────────────────────────
13
13
  只跟 DSH 设置:读客户端的 locale 服务,每次切换就把它 POST 到
14
- /api/session-recall.locale,宿主那半边注入时按这个文件换字。
14
+ /api/session-seal-scripts.locale,宿主那半边注入时按这个文件换字。
15
15
  界面文字走下面这张表;回顾正文里的中文标记由宿主当通配键处理。 */
16
16
 
17
17
  var LANG = 'zh'
@@ -240,6 +240,14 @@ window.__ModuleLoader__.load({
240
240
  'tl.importCancel': '取消',
241
241
  'tl.imported': function (n, k) { return '已导入 ' + n + ' 个工具脚本' + (k > 0 ? ('(覆盖了 ' + k + ' 个)') : '') },
242
242
  'tl.importSkipped': function (n) { return ';跳过 ' + n + ' 项(运行溢写、备份目录、越界路径之类不收)' },
243
+ // 清除缓存(0.5.1):删回滚版本与运行日志,工具本身不动。
244
+ 'tl.clearCache': '清除缓存',
245
+ 'tl.clearCacheConfirm': '确认清除',
246
+ 'tl.clearCacheHint': '再点一次就删:所有 .bak- 回滚版本与 _runs 里的运行日志都会没掉,工具脚本本身和索引不动。',
247
+ 'tl.cacheCleared': function (b, r, size) { return '已清除 ' + b + ' 个回滚版本、' + r + ' 个运行日志(共 ' + size + ')' },
248
+ 'tl.cacheEmpty': '没有可清除的回滚版本和运行日志',
249
+ 'tl.cacheSkipped': function (n) { return ';正有一个导入在进行,跳过 ' + n + ' 个临时包' },
250
+ 'tl.cachePartial': function (n) { return ';有 ' + n + ' 项没删掉(被占用或没权限),其余已清除' },
243
251
  // 问号气泡(0.3.10):两段只读说明,点问号才出现。
244
252
  'help.aria': '说明',
245
253
  'help.toolList': '本页列出模型已通过该插件工具总结的脚本工作流,对模型发送提示词“将上述流程总结成工具”可让模型通过调用session_tool_create_write工具制作脚本序列;跨会话时,如果拥有回顾,对模型发送提示词“将之前会话的流程总结成工具”,模型会自己先调用session_tool_create_read读取之前会话的回顾文件。通过这些方式总结成可直接通过session_tool_call调用的脚本序列,会作为一项工具组注入到系统提示词。',
@@ -363,6 +371,13 @@ window.__ModuleLoader__.load({
363
371
  'tl.importCancel': 'Cancel',
364
372
  'tl.imported': function (n, k) { return 'Imported ' + n + ' toolScripts' + (k > 0 ? (' (' + k + ' overwritten)') : '') },
365
373
  'tl.importSkipped': function (n) { return '; skipped ' + n + ' entries (run spills, backup folders and out-of-range paths are not taken)' },
374
+ 'tl.clearCache': 'Clear cache',
375
+ 'tl.clearCacheConfirm': 'Confirm clear',
376
+ 'tl.clearCacheHint': 'Click once more to delete: every .bak- rollback version and every run log in _runs goes away. The toolScripts themselves and the index stay.',
377
+ 'tl.cacheCleared': function (b, r, size) { return 'Cleared ' + b + ' rollback version(s) and ' + r + ' run log(s) (' + size + ' total)' },
378
+ 'tl.cacheEmpty': 'Nothing to clear — no rollback versions or run logs',
379
+ 'tl.cacheSkipped': function (n) { return '; an import is running, so ' + n + ' temporary package(s) were skipped' },
380
+ 'tl.cachePartial': function (n) { return '; ' + n + ' item(s) could not be removed (in use or no permission), the rest is gone' },
366
381
  'help.aria': 'Help',
367
382
  'help.toolList': 'This page lists the script workflows the model has already wrapped up with this plugin’s tools. Send the model “turn the flow above into a toolScript” and it will call session_tool_create_write to build one; across sessions, when a review exists, send “turn the previous session’s flow into a toolScript” and the model will first call session_tool_create_read to read that review file. ToolScripts gathered this way are runnable with session_tool_call, and the list is injected into the system prompt as a toolSequence section.',
368
383
  'help.injectGroup': 'A review has four depths, each loading something different: level 3, the original transcript; level 2, the compaction summary; level 1, the model’s own summary; level 0, keywords only, used as an index.\nDepths drop on the second day, the third day, and the twenty-eighth day onward. When you point out that the model misremembers something, the model itself calls session_mem_read to read that review’s original transcript, then weights and locks the loaded content of that review. An empty review at depth 1 or 0 is normal: the plugin injects a reminder telling the model to call session_mem_write with a summary and keywords. Compliance differs between the context channel and the system-prompt channel, so pick whichever fits.\nTurning on “Full load” is not recommended; for important checkpoints, use DSH’s own branching instead.',
@@ -719,7 +734,9 @@ window.__ModuleLoader__.load({
719
734
  var selected = sel[0], setSelected = sel[1]
720
735
  var rng = React.useState(null)
721
736
  var range = rng[0], setRange = rng[1]
722
- var note = React.useState(''); var setNote = note[1]
737
+ // 回执(0.5.1):带上它属于哪个标签。以前是一条全页共享的字符串,而那一行
738
+ // 渲染在标签内容区外面,所以在「选项」页存完设置、切到别的页也能看见「已保存」。
739
+ var nt = React.useState(null); var note = nt[0], setNote = nt[1]
723
740
  var err = React.useState(''); var setErr = err[1]
724
741
  var ldi = React.useState(null); var loadInfo = ldi[0], setLoadInfo = ldi[1]
725
742
  var op = React.useState(false); var open = op[0], setOpen = op[1]
@@ -735,7 +752,7 @@ window.__ModuleLoader__.load({
735
752
  var pickSeq = React.useRef(0)
736
753
  // 选项(「选项」标签)。/state 一起带回来;拿不到就单独 GET 一次。
737
754
  var so = React.useState(null); var options = so[0], setOptions = so[1]
738
- // 「自创工具」标签那一段的原文(/api/session-recall.toolSequence 现算的)。
755
+ // 「自创工具」标签那一段的原文(/api/session-seal-scripts.toolSequence 现算的)。
739
756
  var tk = React.useState(null); var toolSequence = tk[0], setToolList = tk[1]
740
757
  // 「导入 / 导出」(0.4.3):选中的那个包、预演结果(还没写盘)、隐藏的文件选择框。
741
758
  var impFile = React.useState(null); var importFile = impFile[0], setImportFile = impFile[1]
@@ -743,6 +760,9 @@ window.__ModuleLoader__.load({
743
760
  // 导入 / 导出的回执(0.4.4):只属于「自创工具」页,渲染在那一页里。
744
761
  // 以前它写进全页共享的 note——那条行在标签内容区外面,切到别的页也会一直挂着。
745
762
  var impNote = React.useState(''); var importNote = impNote[0], setImportNote = impNote[1]
763
+ // 「清除缓存」(0.5.1):第一下只是举刀(按钮变红、旁边说明),第二下才真删。
764
+ var cca = React.useState(false); var clearArmed = cca[0], setClearArmed = cca[1]
765
+ var ccn = React.useState(''); var cacheNote = ccn[0], setCacheNote = ccn[1]
746
766
  var fileInput = React.useRef(null)
747
767
 
748
768
  var load = React.useCallback(async function () {
@@ -761,6 +781,9 @@ window.__ModuleLoader__.load({
761
781
 
762
782
  React.useEffect(function () { load() }, [])
763
783
 
784
+ // 切标签就把上一页的回执和「举刀」状态收掉:它们只属于生成它们的那一页(0.5.1)。
785
+ React.useEffect(function () { setNote(null); setClearArmed(false) }, [tab])
786
+
764
787
  var selectedWorkspace = selected
765
788
  ? data.workspaces.filter(function (w) { return w.cwd === selected.cwd })[0]
766
789
  : null
@@ -779,9 +802,12 @@ window.__ModuleLoader__.load({
779
802
  data.workspaces.filter(function (w) { return w.memories.length > 0 })[0] || null
780
803
  var memCwd = wsForMem ? wsForMem.cwd : ''
781
804
 
805
+ /** 写一条本页回执:记下当前标签。切页时由下面的 effect 清掉。 */
806
+ function showNote(text) { setNote({ tab: tab, text: text }) }
807
+
782
808
  // 换会话就把上一轮的选择清掉,否则会拿着旧工作区的选中项继续显示。
783
809
  React.useEffect(function () {
784
- setSelected(null); setMemPick(null); setRange(null); setConfirming(''); setNote('')
810
+ setSelected(null); setMemPick(null); setRange(null); setConfirming(''); setNote(null)
785
811
  }, [currentSessionId])
786
812
 
787
813
  // 换工作区时清掉这条回顾的选择与日期区间。
@@ -919,6 +945,45 @@ window.__ModuleLoader__.load({
919
945
  } finally { setBusy(false) }
920
946
  }
921
947
 
948
+ /** 字节数说人话:清缓存回执里用。 */
949
+ function fmtBytes(n) {
950
+ var v = Number(n) || 0
951
+ if (v < 1024) return v + ' B'
952
+ if (v < 1024 * 1024) return (v / 1024).toFixed(1) + ' KB'
953
+ return (v / (1024 * 1024)).toFixed(1) + ' MB'
954
+ }
955
+
956
+ /**
957
+ * 清除缓存(0.5.1):删掉工具的回滚版本(<id>.bak-*)和 _runs/ 里的运行日志。
958
+ * 两下才动手:第一下只把按钮换成「确认清除」并写明会删什么。
959
+ */
960
+ async function doClearCache() {
961
+ if (isBusy) return
962
+ if (!clearArmed) { setClearArmed(true); setCacheNote(''); setImportNote(''); return }
963
+ setClearArmed(false)
964
+ setBusy(true); setErr(''); setImportNote(''); setCacheNote('')
965
+ try {
966
+ var res = await fetch(API + 'toolSequence/clear-cache', {
967
+ method: 'POST',
968
+ headers: { 'Content-Type': 'application/json' },
969
+ body: '{}'
970
+ })
971
+ var json = await res.json()
972
+ if (!res.ok) throw new Error((json.error && json.error.message) || ('HTTP ' + res.status))
973
+ var nb = (json.backups && json.backups.count) || 0
974
+ var nr = (json.runs && json.runs.files) || 0
975
+ var size = (json.total && json.total.bytes) || 0
976
+ var skipped = (json.runs && json.runs.skipped) ? json.runs.skipped.length : 0
977
+ var failed = (json.failed || []).length
978
+ var text = (nb + nr) === 0 ? tr('tl.cacheEmpty') : tr('tl.cacheCleared', nb, nr, fmtBytes(size))
979
+ if (skipped > 0) text += tr('tl.cacheSkipped', skipped)
980
+ if (failed > 0) text += tr('tl.cachePartial', failed)
981
+ setCacheNote(text)
982
+ await loadToolList()
983
+ } catch (e) { setErr(String(e.message || e)) }
984
+ finally { setBusy(false) }
985
+ }
986
+
922
987
  /** 关掉导入弹窗:包和预演结果一起作废,不写盘。 */
923
988
  function closeImportDialog() {
924
989
  if (isBusy) return
@@ -971,11 +1036,11 @@ window.__ModuleLoader__.load({
971
1036
  */
972
1037
  async function patchOptions(patch) {
973
1038
  if (isBusy) return
974
- setBusy(true); setErr(''); setNote('')
1039
+ setBusy(true); setErr(''); setNote(null)
975
1040
  try {
976
1041
  var res = await post('options', patch)
977
1042
  if (res.options) setOptions(res.options)
978
- setNote(tr('note.saved'))
1043
+ showNote(tr('note.saved'))
979
1044
  // 让两个 effect 重新取:载入框、单条预览、工作区级别都按新选项重算。
980
1045
  ctxCwd.current = ''
981
1046
  setLoadInfo(null)
@@ -988,13 +1053,13 @@ window.__ModuleLoader__.load({
988
1053
 
989
1054
  async function doMemDelete() {
990
1055
  if (!memPick) return
991
- if (memConfirm !== 'mem') { setMemConfirm('mem'); setNote(tr('note.memConfirm')); return }
1056
+ if (memConfirm !== 'mem') { setMemConfirm('mem'); showNote(tr('note.memConfirm')); return }
992
1057
  var cwd = loadInfo ? loadInfo.cwd : null
993
1058
  if (!cwd) return
994
- setBusy(true); setErr(''); setNote('')
1059
+ setBusy(true); setErr(''); setNote(null)
995
1060
  try {
996
1061
  await post('memory-delete', { cwd: cwd, file: memPick })
997
- setNote(tr('note.memDeleted', memPick))
1062
+ showNote(tr('note.memDeleted', memPick))
998
1063
  setMemPick(null); setMemConfirm('')
999
1064
  await load()
1000
1065
  await loadContext(cwd)
@@ -1040,38 +1105,38 @@ window.__ModuleLoader__.load({
1040
1105
 
1041
1106
  async function doDelete() {
1042
1107
  if (!selected) return
1043
- if (confirming !== 'delete') { setConfirming('delete'); setNote(tr('note.deleteConfirm')); return }
1044
- setBusy(true); setErr(''); setNote(''); setConfirming('')
1108
+ if (confirming !== 'delete') { setConfirming('delete'); showNote(tr('note.deleteConfirm')); return }
1109
+ setBusy(true); setErr(''); setNote(null); setConfirming('')
1045
1110
  var target = selected.id
1046
1111
  try {
1047
1112
  await post('delete', { sessionId: target })
1048
- setNote(tr('note.deleted')); setSelected(null)
1113
+ showNote(tr('note.deleted')); setSelected(null)
1049
1114
  await load()
1050
1115
  } catch (e) {
1051
1116
  var fresh = await load()
1052
1117
  var alive = fresh !== null && (fresh.workspaces || []).some(function (w) {
1053
1118
  return (w.sessions || []).some(function (x) { return x.id === target })
1054
1119
  })
1055
- if (fresh !== null && !alive) { setNote(tr('note.deletedLost')); setSelected(null) }
1120
+ if (fresh !== null && !alive) { showNote(tr('note.deletedLost')); setSelected(null) }
1056
1121
  else setErr(String(e.message || e))
1057
1122
  } finally { setBusy(false) }
1058
1123
  }
1059
1124
 
1060
1125
  async function doCompactDelete() {
1061
1126
  if (!selected) return
1062
- if (confirming !== 'compact') { setConfirming('compact'); setNote(tr('note.compactConfirm')); return }
1063
- setBusy(true); setErr(''); setNote(''); setConfirming('')
1127
+ if (confirming !== 'compact') { setConfirming('compact'); showNote(tr('note.compactConfirm')); return }
1128
+ setBusy(true); setErr(''); setNote(null); setConfirming('')
1064
1129
  var target = selected.id
1065
1130
  try {
1066
1131
  var res = await post('compact-delete', { sessionId: target })
1067
- setNote(tr('note.compacted', res.memory)); setSelected(null)
1132
+ showNote(tr('note.compacted', res.memory)); setSelected(null)
1068
1133
  await load()
1069
1134
  } catch (e) {
1070
1135
  var fresh2 = await load()
1071
1136
  var alive2 = fresh2 !== null && (fresh2.workspaces || []).some(function (w) {
1072
1137
  return (w.sessions || []).some(function (x) { return x.id === target })
1073
1138
  })
1074
- if (fresh2 !== null && !alive2) { setNote(tr('note.deletedLost')); setSelected(null) }
1139
+ if (fresh2 !== null && !alive2) { showNote(tr('note.deletedLost')); setSelected(null) }
1075
1140
  else setErr(String(e.message || e))
1076
1141
  } finally { setBusy(false) }
1077
1142
  }
@@ -1114,8 +1179,17 @@ window.__ModuleLoader__.load({
1114
1179
  importNote ? h('div', { style: S.note, 'data-import-note': '1' }, importNote) : null,
1115
1180
  h('div', { style: { display: 'flex', gap: 10, flexWrap: 'wrap', paddingTop: 12, borderTop: '1px solid #ececec' } },
1116
1181
  h('button', { style: isBusy ? S.btnOff : S.btn, disabled: isBusy, onClick: pickImportFile }, tr('tl.import')),
1117
- h('button', { style: isBusy ? S.btnOff : S.btn, disabled: isBusy, onClick: doExport }, tr('tl.export'))
1182
+ h('button', { style: isBusy ? S.btnOff : S.btn, disabled: isBusy, onClick: doExport }, tr('tl.export')),
1183
+ // 0.5.1:清除缓存放在这一行最右边(规则:新的放在末尾)。
1184
+ h('button', {
1185
+ style: isBusy ? S.btnOff : (clearArmed ? S.btnDanger : S.btn),
1186
+ disabled: isBusy,
1187
+ 'data-clear-cache': '1',
1188
+ onClick: doClearCache
1189
+ }, clearArmed ? tr('tl.clearCacheConfirm') : tr('tl.clearCache'))
1118
1190
  ),
1191
+ clearArmed ? h('div', { style: S.note, 'data-clear-cache-hint': '1' }, tr('tl.clearCacheHint')) : null,
1192
+ cacheNote ? h('div', { style: S.note, 'data-clear-cache-note': '1' }, cacheNote) : null,
1119
1193
  h('input', {
1120
1194
  type: 'file',
1121
1195
  accept: '.zip,application/zip',
@@ -1291,7 +1365,7 @@ window.__ModuleLoader__.load({
1291
1365
  var on = selected && selected.id === sess.id
1292
1366
  return h(Row, {
1293
1367
  key: sess.id, title: sess.id, on: on, archived: sess.archived,
1294
- onClick: function () { setSelected({ id: sess.id, cwd: ws.cwd }); setConfirming(''); setNote('') }
1368
+ onClick: function () { setSelected({ id: sess.id, cwd: ws.cwd }); setConfirming(''); setNote(null) }
1295
1369
  },
1296
1370
  h('span', { style: on ? S.dotOn : S.dot }),
1297
1371
  h('span', { style: Object.assign({}, S.title, sess.hasTitle ? {} : S.muted) }, sess.title),
@@ -1349,7 +1423,7 @@ window.__ModuleLoader__.load({
1349
1423
  style: S.discBtn,
1350
1424
  onClick: function () {
1351
1425
  // 选中了某条时,点列表头先回到「全部」,不收起 —— 收起就看不到内容了。
1352
- if (memPick) { setMemPick(null); setMemConfirm(''); setNote(''); if (!open) setOpen(true); return }
1426
+ if (memPick) { setMemPick(null); setMemConfirm(''); setNote(null); if (!open) setOpen(true); return }
1353
1427
  setOpen(!open)
1354
1428
  }
1355
1429
  },
@@ -1366,7 +1440,7 @@ window.__ModuleLoader__.load({
1366
1440
  var picked = memPick === e.file
1367
1441
  return h(Row, {
1368
1442
  key: e.file, title: e.file, on: picked,
1369
- onClick: function () { setMemPick(e.file); setMemConfirm(''); setNote('') }
1443
+ onClick: function () { setMemPick(e.file); setMemConfirm(''); setNote(null) }
1370
1444
  },
1371
1445
  h('span', { style: picked ? S.dotOn : S.dot }),
1372
1446
  h('span', { style: { fontSize: 12, opacity: 0.72, flex: '0 0 auto' } }, ymd(new Date(e.compactedAt))),
@@ -1423,7 +1497,7 @@ window.__ModuleLoader__.load({
1423
1497
 
1424
1498
  return h('div', { style: S.wrap },
1425
1499
  head, tabs, capWarn, pageBox, footer,
1426
- note[0] ? h('div', { style: S.note }, note[0]) : null,
1500
+ note && note.tab === tab ? h('div', { style: S.note }, note.text) : null,
1427
1501
  err[0] ? h('div', { style: S.err }, err[0]) : null
1428
1502
  )
1429
1503
  }
package/lib/core/index.js CHANGED
@@ -29,10 +29,10 @@ import { probeHostFormat } from '../host/host-contract.js'
29
29
  import { createCapabilityProbe, describeMissing } from '../host/capabilities.js'
30
30
 
31
31
  /** 插件名,也是日志名。 */
32
- export const name = 'session-recall'
32
+ export const name = 'session-seal-scripts'
33
33
 
34
34
  /** 运行期上下文条目的标识(它产出的是一条 runtime-context 快照消息,不是系统提示词)。 */
35
- const CONTEXT_NAME = 'session-recall:memory'
35
+ const CONTEXT_NAME = 'session-seal-scripts:memory'
36
36
 
37
37
  /**
38
38
  * 日记提醒在系统提示词里的段名与位置。
@@ -49,7 +49,7 @@ const CONTEXT_NAME = 'session-recall:memory'
49
49
  * 取最后几节里最大的序号再 +1,所以这一段永远落在系统提示词末尾、紧挨着对话。
50
50
  * 不写死数字:DSH 换了排序也只跟着它走;读不到表的老宿主退到 1e9,仍然是最后。
51
51
  */
52
- const DIARY_SECTION_NAME = 'session-recall:diary'
52
+ const DIARY_SECTION_NAME = 'session-seal-scripts:diary'
53
53
 
54
54
  /**
55
55
  * 工具组清单在系统提示词里的段名(0.3.0)。
@@ -57,7 +57,7 @@ const DIARY_SECTION_NAME = 'session-recall:diary'
57
57
  * 它跟日记提醒同一套机制:systemPrompt.section(),紧跟在日记段后面。
58
58
  * 装/删工具脚本才会变,平时稳定——所以它只在工具脚本变动后的第一轮让缓存未命中一次。
59
59
  */
60
- const TOOLKIT_SECTION_NAME = 'session-recall:toolSequence'
60
+ const TOOLKIT_SECTION_NAME = 'session-seal-scripts:toolSequence'
61
61
 
62
62
  /** DSH 排序表里排在最后面的几节(探到哪个有就用哪个的最大值)。 */
63
63
  const TAIL_SECTION_NAMES = ['DEPLOYMENT_PERSONA_SUFFIX', 'WEB_SURFACE', 'HARNESS_SOURCE', 'STRUCTURED_OUTPUT']
@@ -190,7 +190,7 @@ export function resolveDshHome(configured) {
190
190
  */
191
191
  export function apply(ctx, config = {}) {
192
192
  const dshHome = resolveDshHome(config.dshHome)
193
- const logger = typeof ctx.logger === 'function' ? ctx.logger('session-recall') : console
193
+ const logger = typeof ctx.logger === 'function' ? ctx.logger('session-seal-scripts') : console
194
194
 
195
195
  // ── 宿主能力探测(E1):缺哪块关哪块,其余照常 ──────────────
196
196
  // cordis 的 ctx.get 只看「已经就绪」的服务;apply 刚进来时宿主服务多半还没起来,
@@ -10,10 +10,10 @@
10
10
  import { randomUUID } from 'node:crypto'
11
11
 
12
12
  /** 消息来源标识。GUI 把非 user 的 kind 都当「上下文」块渲染,不会变成用户气泡。 */
13
- export const MEMORY_SOURCE_KIND = 'session-recall'
13
+ export const MEMORY_SOURCE_KIND = 'session-seal-scripts'
14
14
 
15
15
  /** 分区名,写进 source.sections,方便以后按分区定位。 */
16
- export const MEMORY_SECTION = 'session-recall:memory'
16
+ export const MEMORY_SECTION = 'session-seal-scripts:memory'
17
17
 
18
18
  /**
19
19
  * 拼一条模型侧的 user 消息。形状与 dsh-llm 的 createUserMessage 一致
@@ -2,7 +2,7 @@
2
2
  * 语言从哪来(0.2.3):只跟 DSH 的设置。
3
3
  *
4
4
  * 设置页那一半(客户端)读 DSH 的 locale 服务,每次语言一变就把它 POST 到
5
- * /api/session-recall.locale 记在这里;注入这一半(宿主)每一步同步读这个文件。
5
+ * /api/session-seal-scripts.locale 记在这里;注入这一半(宿主)每一步同步读这个文件。
6
6
  * 没有文件(还没打开过界面、或是 CLI)就按中文——文件里没写的东西一律当默认值。
7
7
  *
8
8
  * 存在 <dshHome>/session-memory/_locale.json,和 _options.json 同层。
@@ -11,7 +11,7 @@
11
11
  * injectEnabled 回顾注入:总开关(0.2.8)。0.3.1 起只管回顾正文与日记提醒(B、C 两段);
12
12
  * 工具组清单(A 段)由 toolListEnabled 单独管。关掉后其余四项只变灰不可改,
13
13
  * 已存的值原样保留(不还原默认)
14
- * toolListEnabled 注入工具组清单(0.3.1):只管 session-recall:toolSequence 那一段,默认开
14
+ * toolListEnabled 注入工具组清单(0.3.1):只管 session-seal-scripts:toolSequence 那一段,默认开
15
15
  * toolListRefresh 清单词刷新时刻(0.4.5):'newSession' 新会话开始之前(默认)/ 'realtime' 会话内实时刷新。
16
16
  * 只管工具组那一段什么时候重算:newSession 在会话首次装配时算一次就固定,
17
17
  * 会话中途装/删工具脚本不改系统提示词(否则整份会话会被当未缓存输入重发);
@@ -0,0 +1,133 @@
1
+ /**
2
+ * 清除缓存(0.5.1):把工具组目录里不属于「工具本身」的两类东西删掉。
3
+ *
4
+ * 1. <id>.bak-<时间戳>/ 覆盖安装 / 导入时留下的回滚版本
5
+ * 2. _runs/ 里的所有东西 每次执行写下的 stdout / stderr / run.json
6
+ *
7
+ * 「工具本身」= _index.json 与每个 <id>/ 目录,一个都不碰:清完工具照常跑,
8
+ * 索引也不重建(回滚目录与运行日志本来就不在索引里)。
9
+ *
10
+ * 三条保守规矩:
11
+ * - 回滚目录名必须形如 <合法 id>.bak-<纯数字>,别的一律不认(宁可少删);
12
+ * - 删之前先量体积,删完能报「清掉了多少」;
13
+ * - 正在进行的导入会把包临时落在 _runs/import.tmp-*.zip,keepImportTmp 为真时跳过它,
14
+ * 免得把别人手上的包删掉一半。
15
+ * 单个条目删失败不中断整轮,记进 failed 一起回给界面。
16
+ */
17
+
18
+ import fsp from 'node:fs/promises'
19
+ import path from 'node:path'
20
+ import { BUNDLE_ID_RE, runsDir, toolSequenceRoot } from './schema.js'
21
+
22
+ /** 回滚目录:<id>.bak-<毫秒时间戳>(installToolScript / 导入都这么起名)。 */
23
+ const BACKUP_RE = /^(.+)\.bak-(\d+)$/
24
+
25
+ /** 导入时落在 _runs/ 的临时包名(routes/tools.js 里生成)。 */
26
+ const IMPORT_TMP_RE = /^import\.tmp-\d+-\d+\.zip$/
27
+
28
+ /** 一句话错误正文,不带堆栈。 */
29
+ function messageOf(error) {
30
+ return error && error.message ? String(error.message) : String(error)
31
+ }
32
+
33
+ /**
34
+ * 递归量一个目录下的文件数与字节数(符号链接按 0 计,不跟进去)。
35
+ * @param {string} dir
36
+ * @returns {Promise<{files:number, bytes:number}>}
37
+ */
38
+ async function sumTree(dir) {
39
+ let files = 0
40
+ let bytes = 0
41
+ let entries
42
+ try {
43
+ entries = await fsp.readdir(dir, { withFileTypes: true })
44
+ } catch (error) {
45
+ if (error && error.code === 'ENOENT') return { files, bytes }
46
+ throw error
47
+ }
48
+ for (const entry of entries) {
49
+ const full = path.join(dir, entry.name)
50
+ if (entry.isDirectory()) {
51
+ const sub = await sumTree(full)
52
+ files += sub.files
53
+ bytes += sub.bytes
54
+ } else if (entry.isFile()) {
55
+ try {
56
+ const stat = await fsp.stat(full)
57
+ files += 1
58
+ bytes += stat.size
59
+ } catch (error) {
60
+ if (!error || error.code !== 'ENOENT') throw error
61
+ }
62
+ }
63
+ }
64
+ return { files, bytes }
65
+ }
66
+
67
+ /**
68
+ * 删掉回滚版本与运行日志。
69
+ * @param {{dshHome:string, keepImportTmp?:boolean}} input
70
+ * @returns {Promise<{backups:{count:number,files:number,bytes:number,names:string[]}, runs:{dir:string,files:number,bytes:number,skipped:string[]}, total:{count:number,bytes:number}, failed:{name:string,message:string}[]}>}
71
+ */
72
+ export async function clearToolCaches({ dshHome, keepImportTmp = false } = {}) {
73
+ const root = toolSequenceRoot(dshHome)
74
+ const failed = []
75
+
76
+ // ── 回滚版本 ──────────────────────────────────────────────
77
+ let rootEntries = []
78
+ try {
79
+ rootEntries = await fsp.readdir(root, { withFileTypes: true })
80
+ } catch (error) {
81
+ if (!error || error.code !== 'ENOENT') throw error
82
+ }
83
+ const backupNames = []
84
+ let backupFiles = 0
85
+ let backupBytes = 0
86
+ for (const entry of rootEntries) {
87
+ if (!entry.isDirectory()) continue
88
+ const matched = BACKUP_RE.exec(entry.name)
89
+ if (!matched || !BUNDLE_ID_RE.test(matched[1])) continue
90
+ const full = path.join(root, entry.name)
91
+ try {
92
+ const stats = await sumTree(full)
93
+ await fsp.rm(full, { recursive: true, force: true })
94
+ backupNames.push(entry.name)
95
+ backupFiles += stats.files
96
+ backupBytes += stats.bytes
97
+ } catch (error) {
98
+ failed.push({ name: entry.name, message: messageOf(error) })
99
+ }
100
+ }
101
+
102
+ // ── 运行日志 ──────────────────────────────────────────────
103
+ const runsPath = runsDir(dshHome)
104
+ const runs = { dir: runsPath, files: 0, bytes: 0, skipped: [] }
105
+ let runEntries = []
106
+ try {
107
+ runEntries = await fsp.readdir(runsPath, { withFileTypes: true })
108
+ } catch (error) {
109
+ if (!error || error.code !== 'ENOENT') throw error
110
+ }
111
+ for (const entry of runEntries) {
112
+ if (keepImportTmp && entry.isFile() && IMPORT_TMP_RE.test(entry.name)) {
113
+ runs.skipped.push(entry.name)
114
+ continue
115
+ }
116
+ const full = path.join(runsPath, entry.name)
117
+ try {
118
+ const stats = entry.isDirectory() ? await sumTree(full) : { files: 1, bytes: (await fsp.stat(full)).size }
119
+ await fsp.rm(full, { recursive: true, force: true })
120
+ runs.files += stats.files
121
+ runs.bytes += stats.bytes
122
+ } catch (error) {
123
+ failed.push({ name: path.join('_runs', entry.name), message: messageOf(error) })
124
+ }
125
+ }
126
+
127
+ return {
128
+ backups: { count: backupNames.length, files: backupFiles, bytes: backupBytes, names: backupNames },
129
+ runs,
130
+ total: { count: backupNames.length + runs.files, bytes: backupBytes + runs.bytes },
131
+ failed
132
+ }
133
+ }
@@ -49,7 +49,7 @@ export async function compactThenDelete(deps, dshHome, sessionId, waitForSplit)
49
49
  let result
50
50
  try {
51
51
  result = await withTimeout(
52
- Promise.resolve(deps.compaction.compactNow(agent, controller.signal, 'session-recall-delete')),
52
+ Promise.resolve(deps.compaction.compactNow(agent, controller.signal, 'session-seal-scripts-delete')),
53
53
  TIMEOUT_MS,
54
54
  '压缩超时'
55
55
  )
@@ -12,7 +12,7 @@ import { assertInside, assertMarkdown } from '../../core/path-guard.js'
12
12
  import { dialogueOnly } from '../../core/render.js'
13
13
  import { respond, readBody } from '../http-util.js'
14
14
 
15
- const PREFIX = '/api/session-recall.'
15
+ const PREFIX = '/api/session-seal-scripts.'
16
16
 
17
17
  /**
18
18
  * 删掉一条回顾:先删正文,再删它的边车。路径必须在回顾目录内。
@@ -7,7 +7,7 @@ import { readOptionsSync, writeOptions } from '../../core/settings.js'
7
7
  import { readLocaleSync, writeLocale } from '../../core/locale.js'
8
8
  import { respond, readBody } from '../http-util.js'
9
9
 
10
- const PREFIX = '/api/session-recall.'
10
+ const PREFIX = '/api/session-seal-scripts.'
11
11
 
12
12
  /** @param {(path:string, handler:Function) => void} route @param {{dshHome:string, onOptionsChanged?:Function, onToolListRefreshChanged?:Function}} deps */
13
13
  export function routesOptions(route, { dshHome, onOptionsChanged, onToolListRefreshChanged }) {
@@ -15,7 +15,7 @@ import { readDigest } from '../summary.js'
15
15
  import { compactThenDelete } from '../compact-delete.js'
16
16
  import { respond, readBody } from '../http-util.js'
17
17
 
18
- const PREFIX = '/api/session-recall.'
18
+ const PREFIX = '/api/session-seal-scripts.'
19
19
  const digestCache = new Map()
20
20
 
21
21
  /** 会话 id 的短尾巴:标题读不出来时当占位。 */
@@ -8,9 +8,16 @@ import { readOptionsSync } from '../../core/settings.js'
8
8
  import { readLocaleSync } from '../../core/locale.js'
9
9
  import { catalogText, toolSequenceRoot, runsDir } from '../../core/schema.js'
10
10
  import { exportToolSequence, importToolSequence } from '../../core/tool-transfer.js'
11
+ import { clearToolCaches } from '../../core/tool-cache.js'
11
12
  import { readBody, readBodyToFile, respond } from '../http-util.js'
12
13
 
13
- const PREFIX = '/api/session-recall.'
14
+ const PREFIX = '/api/session-seal-scripts.'
15
+
16
+ /**
17
+ * 正在进行的导入条数(0.5.1)。导入会把包临时落在 _runs/ 里,
18
+ * 「清除缓存」看到有人在做就先跳过这些临时包——两边都在同一个宿主进程里,数得准。
19
+ */
20
+ let importsInFlight = 0
14
21
 
15
22
  /** @param {(path:string, handler:Function) => void} route @param {{dshHome:string, onOptionsChanged?:Function}} deps */
16
23
  export function routesTools(route, { dshHome, onOptionsChanged }) {
@@ -84,6 +91,7 @@ export function routesTools(route, { dshHome, onOptionsChanged }) {
84
91
  let buffer
85
92
  let tmpFile = ''
86
93
  let bytes = 0
94
+ importsInFlight += 1
87
95
  try {
88
96
  if (ctype.includes('application/json')) {
89
97
  const raw = await readBody(req)
@@ -134,7 +142,34 @@ export function routesTools(route, { dshHome, onOptionsChanged }) {
134
142
  skipped: result.skipped
135
143
  })
136
144
  } finally {
145
+ importsInFlight -= 1
137
146
  if (tmpFile !== '') await fsp.rm(tmpFile, { force: true }).catch(() => {})
138
147
  }
139
148
  })
149
+
150
+ /**
151
+ * 清除缓存(0.5.1):「自创工具」页最右边那颗按钮。
152
+ *
153
+ * 只删两类东西:<id>.bak-<时间戳> 回滚版本、_runs/ 里的运行日志。
154
+ * 工具目录与 _index.json 不动——清完工具照常跑,索引不用重建。
155
+ * 单个条目删不掉不算整轮失败:照样回 200,把 failed 交给界面点名。
156
+ */
157
+ route(PREFIX + 'toolSequence/clear-cache', async (req, res) => {
158
+ if (req.method !== 'POST') { respond(res, 405, { error: { code: 'method-not-allowed', message: 'POST' } }); return }
159
+ let result
160
+ try {
161
+ result = await clearToolCaches({ dshHome, keepImportTmp: importsInFlight > 0 })
162
+ } catch (error) {
163
+ respond(res, 500, { error: { code: 'clear-failed', message: error?.message ?? String(error) } })
164
+ return
165
+ }
166
+ respond(res, 200, {
167
+ ok: result.failed.length === 0,
168
+ path: toolSequenceRoot(dshHome),
169
+ backups: result.backups,
170
+ runs: result.runs,
171
+ total: result.total,
172
+ failed: result.failed
173
+ })
174
+ })
140
175
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-seal-scripts",
3
- "version": "0.4.12",
3
+ "version": "0.5.1",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "index.js",