dsh-seal-scripts 0.0.0-stage → 0.4.8
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/LICENSE +21 -0
- package/README.en.md +318 -0
- package/README.md +342 -2
- package/cordis.patch.yml +6 -0
- package/index.js +12 -0
- package/lib/client.js +1465 -0
- package/lib/core/assembly.js +321 -0
- package/lib/core/catalog-snapshot.js +78 -0
- package/lib/core/diary.js +100 -0
- package/lib/core/health.js +72 -0
- package/lib/core/index.js +491 -0
- package/lib/core/inject.js +146 -0
- package/lib/core/lang.js +251 -0
- package/lib/core/locale.js +56 -0
- package/lib/core/memory-file.js +214 -0
- package/lib/core/migrate.js +97 -0
- package/lib/core/path-guard.js +43 -0
- package/lib/core/project-key.js +52 -0
- package/lib/core/render.js +228 -0
- package/lib/core/schema-runner.js +281 -0
- package/lib/core/schema-tools.js +794 -0
- package/lib/core/schema.js +493 -0
- package/lib/core/search.js +254 -0
- package/lib/core/settings.js +158 -0
- package/lib/core/store.js +408 -0
- package/lib/core/tool-transfer.js +249 -0
- package/lib/core/tool.js +602 -0
- package/lib/core/zip.js +226 -0
- package/lib/core/zstd-js.js +705 -0
- package/lib/core/zstd.js +103 -0
- package/lib/host/api.js +9 -0
- package/lib/host/capabilities.js +155 -0
- package/lib/host/compact-delete.js +76 -0
- package/lib/host/delete.js +136 -0
- package/lib/host/host-contract.js +73 -0
- package/lib/host/http-util.js +82 -0
- package/lib/host/lifecycle.js +66 -0
- package/lib/host/register.js +63 -0
- package/lib/host/routes/memories.js +102 -0
- package/lib/host/routes/options.js +46 -0
- package/lib/host/routes/sessions.js +194 -0
- package/lib/host/routes/tools.js +103 -0
- package/lib/host/summary.js +71 -0
- package/package.json +71 -4
package/lib/client.js
ADDED
|
@@ -0,0 +1,1465 @@
|
|
|
1
|
+
window.__ModuleLoader__.load({
|
|
2
|
+
id: 'dsh-seal-scripts',
|
|
3
|
+
factory: (require) => {
|
|
4
|
+
var module = { exports: {} }
|
|
5
|
+
var exports = module.exports
|
|
6
|
+
var React = require('react')
|
|
7
|
+
var h = React.createElement
|
|
8
|
+
|
|
9
|
+
var API = '/api/session-recall.'
|
|
10
|
+
var NS = 'session-recall'
|
|
11
|
+
|
|
12
|
+
/* ── 语言(0.2.3)────────────────────────────────────────────
|
|
13
|
+
只跟 DSH 设置:读客户端的 locale 服务,每次切换就把它 POST 到
|
|
14
|
+
/api/session-recall.locale,宿主那半边注入时按这个文件换字。
|
|
15
|
+
界面文字走下面这张表;回顾正文里的中文标记由宿主当通配键处理。 */
|
|
16
|
+
|
|
17
|
+
var LANG = 'zh'
|
|
18
|
+
var langSubs = []
|
|
19
|
+
var langPushed = false
|
|
20
|
+
|
|
21
|
+
function normalizeLangId(id) {
|
|
22
|
+
var s = String(id === undefined || id === null ? '' : id).trim().toLowerCase()
|
|
23
|
+
return s === 'en' || s.indexOf('en-') === 0 || s.indexOf('en_') === 0 ? 'en' : 'zh'
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function pushLang() {
|
|
27
|
+
try {
|
|
28
|
+
if (typeof fetch !== 'function') return
|
|
29
|
+
fetch(API + 'locale', {
|
|
30
|
+
method: 'POST',
|
|
31
|
+
headers: { 'Content-Type': 'application/json' },
|
|
32
|
+
body: JSON.stringify({ locale: LANG })
|
|
33
|
+
}).catch(function () { /* 老宿主没有这个端点:忽略,宿主按中文走 */ })
|
|
34
|
+
} catch (e) { /* 同上 */ }
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
var localeService = null
|
|
38
|
+
|
|
39
|
+
/** 页面自己的语言标记:locale 服务拿不到时的兜底。 */
|
|
40
|
+
function pageLang() {
|
|
41
|
+
try {
|
|
42
|
+
if (typeof document !== 'undefined' && document && document.documentElement &&
|
|
43
|
+
typeof document.documentElement.lang === 'string') return document.documentElement.lang
|
|
44
|
+
} catch (e) { /* 没有 document:当空 */ }
|
|
45
|
+
return ''
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** 读 DSH 现在用的语言;服务优先,页面标记兜底,都没有就给空串(保持现状)。 */
|
|
49
|
+
function readActiveLocale() {
|
|
50
|
+
if (!localeService) return pageLang()
|
|
51
|
+
try {
|
|
52
|
+
var snap = typeof localeService.getSnapshot === 'function'
|
|
53
|
+
? localeService.getSnapshot()
|
|
54
|
+
: (typeof localeService.getLocale === 'function' ? localeService.getLocale() : null)
|
|
55
|
+
if (snap && typeof snap.active === 'string' && snap.active !== '') return snap.active
|
|
56
|
+
} catch (e) { /* 服务坏了就退回页面标记 */ }
|
|
57
|
+
return pageLang()
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* 收下一种语言。notify 为真时通知已挂载的组件重渲染;
|
|
62
|
+
* 渲染路径里调它(label thunk、组件开头)要传 false,免得在渲染中 setState。
|
|
63
|
+
*/
|
|
64
|
+
function applyLang(id, notify) {
|
|
65
|
+
var next = normalizeLangId(id)
|
|
66
|
+
var changed = next !== LANG
|
|
67
|
+
LANG = next
|
|
68
|
+
if (changed && notify) {
|
|
69
|
+
for (var i = 0; i < langSubs.length; i++) { try { langSubs[i]() } catch (e) { /* 单个订阅坏掉不连累别的 */ } }
|
|
70
|
+
}
|
|
71
|
+
// 第一次解析出来的语言一定要推一次:否则宿主那边会留着上次的语言。
|
|
72
|
+
if (changed || !langPushed) { langPushed = true; pushLang() }
|
|
73
|
+
return changed
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** 从 locale 服务现读一次(渲染路径用,不触发重渲染)。 */
|
|
77
|
+
function syncLangFromService() {
|
|
78
|
+
var active = readActiveLocale()
|
|
79
|
+
if (active !== '') applyLang(active, false)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** locale 服务变了:重读并通知界面重渲染。 */
|
|
83
|
+
function ensureLangNow() {
|
|
84
|
+
var active = readActiveLocale()
|
|
85
|
+
if (active !== '') applyLang(active, true)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** 订阅语言变化(组件用它重渲染)。 */
|
|
89
|
+
function subscribeLang(fn) {
|
|
90
|
+
langSubs.push(fn)
|
|
91
|
+
return function () {
|
|
92
|
+
var i = langSubs.indexOf(fn)
|
|
93
|
+
if (i >= 0) langSubs.splice(i, 1)
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** 组件里调一下就行:语言一变,这个组件重渲染。 */
|
|
98
|
+
function useLangTick() {
|
|
99
|
+
var st = React.useState(0)
|
|
100
|
+
var bump = st[1]
|
|
101
|
+
React.useEffect(function () {
|
|
102
|
+
return subscribeLang(function () { bump(function (n) { return n + 1 }) })
|
|
103
|
+
}, [])
|
|
104
|
+
return st[0]
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* 跟着 DSH 的 locale 服务走。插件依赖里声明了 'locale'(见文件尾 inject),
|
|
109
|
+
* 所以 ctx.locale 就是那个服务;旧宿主或测试桩没有它时退回 ctx.get('locale'),
|
|
110
|
+
* 再没有就按中文——绝不让界面因为拿不到语言而空白。
|
|
111
|
+
*/
|
|
112
|
+
function watchLocale(ctx) {
|
|
113
|
+
try { localeService = ctx && ctx.locale ? ctx.locale : null } catch (e) { localeService = null }
|
|
114
|
+
if (!localeService) {
|
|
115
|
+
try { localeService = ctx && typeof ctx.get === 'function' ? ctx.get('locale') : null } catch (e) { localeService = null }
|
|
116
|
+
}
|
|
117
|
+
if (!localeService) {
|
|
118
|
+
// 服务拿不到:至少把页面自己的语言标记读一次(不能订阅,切语言靠重新挂载)。
|
|
119
|
+
syncLangFromService()
|
|
120
|
+
return
|
|
121
|
+
}
|
|
122
|
+
syncLangFromService()
|
|
123
|
+
try {
|
|
124
|
+
if (typeof localeService.subscribe === 'function') localeService.subscribe(ensureLangNow)
|
|
125
|
+
} catch (e) { /* 没有订阅能力就只读一次 */ }
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** 界面词条:中文就是原来的文案,英文一一对应。 */
|
|
129
|
+
var TEXTS = {
|
|
130
|
+
zh: {
|
|
131
|
+
'app.title': '工具(脚本)管理',
|
|
132
|
+
'tab.sessions': '会话',
|
|
133
|
+
'tab.memory': '回顾',
|
|
134
|
+
'tab.toolList': '自创工具',
|
|
135
|
+
'tab.options': '选项',
|
|
136
|
+
'loading': '读取中…',
|
|
137
|
+
'loading.first': '读取中…(第一次要扫一遍会话日志)',
|
|
138
|
+
'empty.sessions': '还没有任何会话',
|
|
139
|
+
'empty.memories': '这个工作区还没有回顾',
|
|
140
|
+
'health.failedTitle': '上次自动回顾失败',
|
|
141
|
+
'health.failed': function (when, msg) { return '上次自动回顾失败(' + when + '):' + msg },
|
|
142
|
+
'host.degraded': function (blocks) { return '当前宿主能力不全,已关闭相关功能:' + blocks },
|
|
143
|
+
'digest.noZstd': '本机 Node 缺 zstd 解压能力,会话标题与条数读不出来(回顾本身不受影响)',
|
|
144
|
+
'ws.archived': function (n) { return ' · ' + n + ' 个归档' },
|
|
145
|
+
'badge.archived': '归档',
|
|
146
|
+
'ws.unknown': '(找不到当前工作区)',
|
|
147
|
+
'box.none': '(当前没有载入任何回顾)',
|
|
148
|
+
'box.noContent': '(这一条没有内容)',
|
|
149
|
+
'box.err': function (msg) { return '(' + msg + ')' },
|
|
150
|
+
'head.base': '当前载入的回顾',
|
|
151
|
+
'head.pick': function (id, chars, loading) {
|
|
152
|
+
return ' · 只看 ' + id + (loading ? ' · 读取中…' : ' · ' + chars + ' 字') + ' · 点这里回到全部'
|
|
153
|
+
},
|
|
154
|
+
'head.all': function (n, chars, level) {
|
|
155
|
+
return ' · ' + n + ' 条 · ' + chars + ' 字' + (typeof level === 'number' ? ' · 载入深度 ' + level : '')
|
|
156
|
+
},
|
|
157
|
+
'ws.count': function (cwd, n, ranged, inRange) {
|
|
158
|
+
return cwd + ' · ' + n + ' 条回顾' + (ranged ? ' · 区间内 ' + inRange + ' 条' : '')
|
|
159
|
+
},
|
|
160
|
+
'chip.depth': function (level, forced, pinned) {
|
|
161
|
+
return '深度 ' + level + (forced ? ' · 载入覆盖' : (pinned ? ' · 锁定' : ''))
|
|
162
|
+
},
|
|
163
|
+
'range.empty': function (from, to) {
|
|
164
|
+
return '选的区间里没有回顾(' + from + (to !== from ? ' ~ ' + to : '') + ')'
|
|
165
|
+
},
|
|
166
|
+
'btn.delete': '删除',
|
|
167
|
+
'btn.deleteCompact': '删除并回顾',
|
|
168
|
+
'btn.confirm': '确认删除?',
|
|
169
|
+
'btn.confirmCompact': '确认压缩并删?',
|
|
170
|
+
'btn.memDelete': '删除这条回顾',
|
|
171
|
+
'note.saved': '已保存',
|
|
172
|
+
'note.memConfirm': '再点一次确认:这条回顾会被永久删掉',
|
|
173
|
+
'note.memDeleted': function (f) { return '已删除回顾 ' + f },
|
|
174
|
+
'note.deleteConfirm': '再点一次确认删除(不可恢复)',
|
|
175
|
+
'note.deleted': '已删除',
|
|
176
|
+
'note.deletedLost': '已删除(响应中断,列表已确认消失)',
|
|
177
|
+
'note.compactConfirm': '再点一次确认:先压缩改写历史再删除,两者都不可逆',
|
|
178
|
+
'note.compacted': function (m) { return '已压缩并删除,回顾 ' + m },
|
|
179
|
+
'err.request': function (p) { return '请求没送回结果(' + p + ')' },
|
|
180
|
+
'cal.hint': '点两天选区间,再点一次清空',
|
|
181
|
+
'cal.clear': '清空',
|
|
182
|
+
'cal.month': function (y, m) { return y + ' 年 ' + (m + 1) + ' 月' },
|
|
183
|
+
'cal.dow': ['日', '一', '二', '三', '四', '五', '六'],
|
|
184
|
+
'switch.on': '已开启',
|
|
185
|
+
'switch.off': '已关闭',
|
|
186
|
+
'box.injectOff': '(回顾注入已关闭,未注入任何内容)',
|
|
187
|
+
'opt.group.inject': '回顾注入',
|
|
188
|
+
'opt.inject': '回顾注入',
|
|
189
|
+
'opt.inject.desc': '开启时按下面的设置把回顾注入上下文,提醒注入到设置选择的对应位置。默认开启。',
|
|
190
|
+
'opt.inject.offDesc': '已关闭:停止一切注入行为;下面四项只变灰不可改,已存的值原样保留、暂不生效。',
|
|
191
|
+
'opt.group.content': '回顾内容',
|
|
192
|
+
'opt.fullLoad': '全量加载',
|
|
193
|
+
'opt.fullLoad.desc': '开启后深度 3 不再过滤工具内容:载入框与真正注入的回顾都保留 ▸ / ◂ 和报错。默认关闭。',
|
|
194
|
+
'opt.fullLoad.warn': '警告:开启此项后,每一次压缩后都将全文回灌!将出现“压缩后比压缩前上下文更长”的负面情况!本选项是为新会话完整接续而设立的,如果你拥有其他导入会话的手段,请关闭此项!',
|
|
195
|
+
'opt.reminder': '概括提醒',
|
|
196
|
+
'opt.reminder.systemDesc': '在系统侧提醒:作为系统提示词段发出(0.1.47 起的方式)。日记一写完,这一段自动消失。',
|
|
197
|
+
'opt.reminder.contextDesc': '在上下文提醒(默认):并进回顾正文(0.1.46 的做法);几份回顾日记都空着时,一份一段全列在同一条提醒里。',
|
|
198
|
+
'opt.reminder.context': '在上下文提醒',
|
|
199
|
+
'opt.reminder.system': '在系统侧提醒',
|
|
200
|
+
'opt.group.depth': '回顾深度',
|
|
201
|
+
'opt.stop': '停止降低',
|
|
202
|
+
'opt.stop.desc': '开启后所有回顾停在载入文件里记下的深度,不再按自然日衰减。默认关闭。',
|
|
203
|
+
'opt.loadLevel': '载入数值',
|
|
204
|
+
'opt.loadLevel.off': '停止降低已开启:这一项不可选,已回到「跟随深度载入」。',
|
|
205
|
+
'opt.loadLevel.desc': '只改载入时用哪一级,不改已经标记好的深度。',
|
|
206
|
+
'opt.loadLevel.now': function (n) { return ' 现在所有回顾按第 ' + n + ' 级载入。' },
|
|
207
|
+
'opt.follow': '跟随深度载入',
|
|
208
|
+
'opt.l3': '3 · 原文',
|
|
209
|
+
'opt.l2': '2 · 摘要',
|
|
210
|
+
'opt.l1': '1 · 日记',
|
|
211
|
+
'opt.l0': '0 · 关键词',
|
|
212
|
+
'opt.note': '选项对全部工作区生效;改完立刻生效——注入、载入框、深度徽章都按新设置重算。',
|
|
213
|
+
'opt.group.tools': '工具固存',
|
|
214
|
+
'help.toolStore': '这一组只管「工具组清单」那一段系统提示词:注不注入、什么时候重算。它和「自动回顾」「回顾注入」互不影响,单独生效。',
|
|
215
|
+
'opt.tlRefresh': '清单词刷新时刻',
|
|
216
|
+
'opt.tlRefresh.newSession': '新会话开始之前',
|
|
217
|
+
'opt.tlRefresh.realtime': '会话内实时刷新',
|
|
218
|
+
'opt.tlRefresh.newDesc': '默认。清单在会话第一次装配时取一次现词,之后固定到会话结束:会话中途新增工具脚本,系统提示词不变,下一句仍走缓存。要让已经聊起来的会话看到新工具,开一个新会话。',
|
|
219
|
+
'opt.tlRefresh.realtimeDesc': '每轮现算清单(0.4.4 及以前的做法):装/删工具脚本后下一句就用新的系统提示词,但那一句要把整份会话当作未缓存输入重发一次。',
|
|
220
|
+
'tl.group': '工具组清单',
|
|
221
|
+
'tl.inject': '注入工具组清单',
|
|
222
|
+
'tl.desc': '开启时把工具组清单注进系统提示词末尾:每个工具脚本一行(id、用途、入口、参数)。它和「自动回顾」「回顾注入」互不影响,单独开关。默认开启。',
|
|
223
|
+
'tl.offDesc': '已关闭:工具组清单这一段不再注入。回顾正文与日记提醒不归这一项管——它们看「选项」里的「自动回顾」总闸与「回顾注入」开关。',
|
|
224
|
+
'tl.preview': '要注入的内容',
|
|
225
|
+
'tl.bytes': function (n) { return ' · ' + n + ' 字节' },
|
|
226
|
+
'tl.empty': '(工具组里还没有工具脚本,这一段是空的;装好第一个工具脚本之后才会出现)',
|
|
227
|
+
'tl.off': '(已关闭,不会注入;下面这框是关掉前的原文)',
|
|
228
|
+
'tl.note': '预览框用的是和装配同一个函数算出来的现词,看到的就是会进系统提示词的那几行。它什么时候真的换新:',
|
|
229
|
+
'tl.note.newSession': '当前是「新会话开始之前」——上面这框是下一个新会话会拿到的原文;当前会话里再装/删工具,系统提示词不会变,下一句仍走缓存。',
|
|
230
|
+
'tl.note.realtime': '当前是「会话内实时刷新」——装/删工具脚本后下一轮才变(系统提示词缓存会未命中一次)。',
|
|
231
|
+
'tl.path': function (p) { return '工具路径:' + p },
|
|
232
|
+
'tl.export': '导出',
|
|
233
|
+
'tl.import': '导入',
|
|
234
|
+
'tl.exported': function (file, files, size) { return '已导出到 ' + file + '(' + files + ' 个文件,' + size + ' 字节,压缩率 0)' },
|
|
235
|
+
'tl.overwritten': ';覆盖了同名文件',
|
|
236
|
+
'tl.noWorkspace': '读不到当前会话的工作区,先随便发一条消息再回来点一次',
|
|
237
|
+
'tl.importPreview': function (n, m) { return '读到 ' + n + ' 个工具脚本' + (m > 0 ? (',其中 ' + m + ' 个会覆盖本机同名的(旧目录留 .bak-)') : ',和本机的都不冲突') },
|
|
238
|
+
'tl.importSkipLine': function (n) { return '另有 ' + n + ' 项不收(运行溢写、备份目录、越界路径之类)' },
|
|
239
|
+
'tl.importConfirm': '确认导入',
|
|
240
|
+
'tl.importCancel': '取消',
|
|
241
|
+
'tl.imported': function (n, k) { return '已导入 ' + n + ' 个工具脚本' + (k > 0 ? ('(覆盖了 ' + k + ' 个)') : '') },
|
|
242
|
+
'tl.importSkipped': function (n) { return ';跳过 ' + n + ' 项(运行溢写、备份目录、越界路径之类不收)' },
|
|
243
|
+
// 问号气泡(0.3.10):两段只读说明,点问号才出现。
|
|
244
|
+
'help.aria': '说明',
|
|
245
|
+
'help.toolList': '本页列出模型已通过该插件工具总结的脚本工作流,对模型发送提示词“将上述流程总结成工具”可让模型通过调用session_tool_create_write工具制作脚本序列;跨会话时,如果拥有回顾,对模型发送提示词“将之前会话的流程总结成工具”,模型会自己先调用session_tool_create_read读取之前会话的回顾文件。通过这些方式总结成可直接通过session_tool_call调用的脚本序列,会作为一项工具组注入到系统提示词。',
|
|
246
|
+
'help.injectGroup': '回顾划分为四级深度,载入内容分别为:3级,载入原对话文本;2级,载入压缩概述;1级,载入模型总结;0级,仅载入关键词作为索引。\n回顾深度降低点分别为第二天、第三天、第二十八天及以后,在被用户指出模型内容记忆有误时,模型自身会调用session_mem_read直接读取回顾文件的原会话对话文本,并且对对应回顾加权并锁定载入内容。使用过程中出现深度为1级、0级的空回顾时,这是正常现象,插件会通过注入提醒来让模型调用session_mem_write写总结与提取关键词,上下文侧与系统提示词侧的遵守程度不同,请根据实际情况选用。\n不建议开启“全量加载”,关键节点建议直接使用DSH自带的分支功能。',
|
|
247
|
+
'opt.auto': '自动回顾',
|
|
248
|
+
'opt.auto.desc': '开启时维持原来的行为:压缩后创建回顾文件,并按下面的设置将回顾注入上下文,将提醒注入到选择的位置。关闭后停止创建与注入,下面所有选项变为不可改。',
|
|
249
|
+
'opt.auto.off': '未开启回顾功能,已停止回顾文件的创建与注入,如果你没有其他记忆插件或者回顾工作流系统,建议开启本项。'
|
|
250
|
+
},
|
|
251
|
+
en: {
|
|
252
|
+
'app.title': 'Tool (script) manager',
|
|
253
|
+
'tab.sessions': 'Sessions',
|
|
254
|
+
'tab.memory': 'Reviews',
|
|
255
|
+
'tab.toolList': 'toolList',
|
|
256
|
+
'tab.options': 'Options',
|
|
257
|
+
'loading': 'Loading…',
|
|
258
|
+
'loading.first': 'Loading… (the first run scans session logs)',
|
|
259
|
+
'empty.sessions': 'No sessions yet',
|
|
260
|
+
'empty.memories': 'No reviews in this workspace yet',
|
|
261
|
+
'health.failedTitle': 'Last auto review failed',
|
|
262
|
+
'health.failed': function (when, msg) { return 'Last auto review failed (' + when + '): ' + msg },
|
|
263
|
+
'host.degraded': function (blocks) { return 'Host capabilities are incomplete; affected features are off: ' + blocks },
|
|
264
|
+
'digest.noZstd': 'This Node build lacks zstd decompression, so session titles and counts cannot be read (reviews themselves are unaffected)',
|
|
265
|
+
'ws.archived': function (n) { return ' · ' + n + ' archived' },
|
|
266
|
+
'badge.archived': 'archived',
|
|
267
|
+
'ws.unknown': '(current workspace not found)',
|
|
268
|
+
'box.none': '(no review is loaded right now)',
|
|
269
|
+
'box.noContent': '(this review has no content)',
|
|
270
|
+
'box.err': function (msg) { return '(' + msg + ')' },
|
|
271
|
+
'head.base': 'Currently loaded reviews',
|
|
272
|
+
'head.pick': function (id, chars, loading) {
|
|
273
|
+
return ' · only ' + id + (loading ? ' · loading…' : ' · ' + chars + ' chars') + ' · click to show all'
|
|
274
|
+
},
|
|
275
|
+
'head.all': function (n, chars, level) {
|
|
276
|
+
return ' · ' + n + ' reviews · ' + chars + ' chars' + (typeof level === 'number' ? ' · load depth ' + level : '')
|
|
277
|
+
},
|
|
278
|
+
'ws.count': function (cwd, n, ranged, inRange) {
|
|
279
|
+
return cwd + ' · ' + n + ' reviews' + (ranged ? ' · ' + inRange + ' in range' : '')
|
|
280
|
+
},
|
|
281
|
+
'chip.depth': function (level, forced, pinned) {
|
|
282
|
+
return 'depth ' + level + (forced ? ' · load override' : (pinned ? ' · locked' : ''))
|
|
283
|
+
},
|
|
284
|
+
'range.empty': function (from, to) {
|
|
285
|
+
return 'No reviews in the selected range (' + from + (to !== from ? ' ~ ' + to : '') + ')'
|
|
286
|
+
},
|
|
287
|
+
'btn.delete': 'Delete',
|
|
288
|
+
'btn.deleteCompact': 'Delete + review',
|
|
289
|
+
'btn.confirm': 'Confirm delete?',
|
|
290
|
+
'btn.confirmCompact': 'Confirm compact + delete?',
|
|
291
|
+
'btn.memDelete': 'Delete this review',
|
|
292
|
+
'note.saved': 'Saved',
|
|
293
|
+
'note.memConfirm': 'Click again: this review will be deleted permanently',
|
|
294
|
+
'note.memDeleted': function (f) { return 'Deleted review ' + f },
|
|
295
|
+
'note.deleteConfirm': 'Click again to confirm delete (cannot be undone)',
|
|
296
|
+
'note.deleted': 'Deleted',
|
|
297
|
+
'note.deletedLost': 'Deleted (the response was lost; the list confirms it is gone)',
|
|
298
|
+
'note.compactConfirm': 'Click again: compact the history first, then delete — neither can be undone',
|
|
299
|
+
'note.compacted': function (m) { return 'Compacted and deleted; review ' + m },
|
|
300
|
+
'err.request': function (p) { return 'No response from ' + p },
|
|
301
|
+
'cal.hint': 'Click two days to pick a range; click again to clear',
|
|
302
|
+
'cal.clear': 'Clear',
|
|
303
|
+
'cal.month': function (y, m) {
|
|
304
|
+
return ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'][m] + ' ' + y
|
|
305
|
+
},
|
|
306
|
+
'cal.dow': ['S', 'M', 'T', 'W', 'T', 'F', 'S'],
|
|
307
|
+
'switch.on': 'On',
|
|
308
|
+
'switch.off': 'Off',
|
|
309
|
+
'box.injectOff': '(recall injection is off — nothing is injected)',
|
|
310
|
+
'opt.group.inject': 'Recall injection',
|
|
311
|
+
'opt.inject': 'Recall injection',
|
|
312
|
+
'opt.inject.desc': 'When on, reviews are injected into the context and the system prompt per the options below. On by default.',
|
|
313
|
+
'opt.inject.offDesc': 'Off: all injection stops; the four options below are greyed out and keep their stored values, which have no effect until this is turned back on.',
|
|
314
|
+
'opt.group.content': 'Review content',
|
|
315
|
+
'opt.fullLoad': 'Full load',
|
|
316
|
+
'opt.fullLoad.desc': 'When on, depth 3 stops filtering tool content: both the preview and the real injection keep ▸ / ◂ and errors. Off by default.',
|
|
317
|
+
'opt.fullLoad.warn': 'Warning: with this on, every compaction is replayed in full! The context after a compaction can end up longer than before it. This option exists so a new session can continue seamlessly; if you have another way to import sessions, turn it off.',
|
|
318
|
+
'opt.reminder': 'Reminder',
|
|
319
|
+
'opt.reminder.systemDesc': 'In system prompt: sent as a system-prompt section (the 0.1.47 way). It disappears as soon as the diary is written.',
|
|
320
|
+
'opt.reminder.contextDesc': 'In context (default): merged into the review body (the 0.1.46 way); when several reviews still lack diaries, they are listed one after another in a single reminder.',
|
|
321
|
+
'opt.reminder.context': 'In context',
|
|
322
|
+
'opt.reminder.system': 'In system prompt',
|
|
323
|
+
'opt.group.depth': 'Review depth',
|
|
324
|
+
'opt.stop': 'Stop lowering',
|
|
325
|
+
'opt.stop.desc': 'When on, every review stays at the depth recorded in its load file and never decays by calendar day. Off by default.',
|
|
326
|
+
'opt.loadLevel': 'Load level',
|
|
327
|
+
'opt.loadLevel.off': 'Stop lowering is on: this option is disabled and has been reset to “Follow depth”.',
|
|
328
|
+
'opt.loadLevel.desc': 'Only changes which level is used when loading; it never changes the marked depth.',
|
|
329
|
+
'opt.loadLevel.now': function (n) { return ' All reviews now load at level ' + n + '.' },
|
|
330
|
+
'opt.follow': 'Follow depth',
|
|
331
|
+
'opt.l3': '3 · transcript',
|
|
332
|
+
'opt.l2': '2 · summary',
|
|
333
|
+
'opt.l1': '1 · diary',
|
|
334
|
+
'opt.l0': '0 · keywords',
|
|
335
|
+
'opt.note': 'Options apply to every workspace and take effect immediately — injection, preview and depth chips all recompute.',
|
|
336
|
+
'opt.group.tools': 'Sealed tools',
|
|
337
|
+
'help.toolStore': 'This group governs only the toolSequence section of the system prompt: whether it is injected and when it is recomputed. It is independent of "Auto review" and "Recall injection".',
|
|
338
|
+
'opt.tlRefresh': 'When the list is refreshed',
|
|
339
|
+
'opt.tlRefresh.newSession': 'Before a new session starts',
|
|
340
|
+
'opt.tlRefresh.realtime': 'Live within the session',
|
|
341
|
+
'opt.tlRefresh.newDesc': 'Default. The list is taken once, when a session is first assembled, and then frozen until that session ends: installing a toolScript mid-session leaves the system prompt untouched and the next turn still hits the cache. To show an ongoing session the new tool, start a new session.',
|
|
342
|
+
'opt.tlRefresh.realtimeDesc': 'The list is recomputed every turn (the behaviour up to 0.4.4): the next turn after installing or removing a toolScript uses the new system prompt, at the cost of re-sending the whole conversation as uncached input once.',
|
|
343
|
+
'tl.group': 'ToolSequence list',
|
|
344
|
+
'tl.inject': 'Inject toolSequence list',
|
|
345
|
+
'tl.desc': 'When on, the toolSequence list is appended to the system prompt: one line per toolScript (id, purpose, entry, args). It is independent of "Auto review" and "Recall injection" and has its own switch. On by default.',
|
|
346
|
+
'tl.offDesc': 'Off: this section is not injected. The review body and diary reminder are not governed by this switch — they follow "Auto review" and "Recall injection" in Options.',
|
|
347
|
+
'tl.preview': 'What would be injected',
|
|
348
|
+
'tl.bytes': function (n) { return ' · ' + n + ' bytes' },
|
|
349
|
+
'tl.empty': '(the toolSequence has no toolScripts yet, so this section is empty; it appears once the first toolScript is installed)',
|
|
350
|
+
'tl.off': '(off — nothing is injected; the box below shows the text from before it was turned off)',
|
|
351
|
+
'tl.note': 'The preview calls the same function the assembler uses, so it is exactly the text that would enter the system prompt. When it actually changes:',
|
|
352
|
+
'tl.note.newSession': 'currently "Before a new session starts" — the box above is what the next new session will get; installing or removing toolScripts in this session leaves the system prompt untouched.',
|
|
353
|
+
'tl.note.realtime': 'currently "Live within the session" — it changes on the next turn after installing or removing a toolScript (one prompt-cache miss).',
|
|
354
|
+
'tl.path': function (p) { return 'Tool path: ' + p },
|
|
355
|
+
'tl.export': 'Export',
|
|
356
|
+
'tl.import': 'Import',
|
|
357
|
+
'tl.exported': function (file, files, size) { return 'Exported to ' + file + ' (' + files + ' files, ' + size + ' bytes, compression level 0)' },
|
|
358
|
+
'tl.overwritten': '; the file with the same name was overwritten',
|
|
359
|
+
'tl.noWorkspace': 'Cannot tell which workspace this session belongs to; send one message and come back',
|
|
360
|
+
'tl.importPreview': function (n, m) { return n + ' toolScripts found' + (m > 0 ? ('; ' + m + ' overwrite local ones with the same id (the old folder is kept as .bak-)') : ', none clash with local ones') },
|
|
361
|
+
'tl.importSkipLine': function (n) { return n + ' more entries are not taken (run spills, backup folders, out-of-range paths)' },
|
|
362
|
+
'tl.importConfirm': 'Confirm import',
|
|
363
|
+
'tl.importCancel': 'Cancel',
|
|
364
|
+
'tl.imported': function (n, k) { return 'Imported ' + n + ' toolScripts' + (k > 0 ? (' (' + k + ' overwritten)') : '') },
|
|
365
|
+
'tl.importSkipped': function (n) { return '; skipped ' + n + ' entries (run spills, backup folders and out-of-range paths are not taken)' },
|
|
366
|
+
'help.aria': 'Help',
|
|
367
|
+
'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
|
+
'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.',
|
|
369
|
+
'opt.auto': 'Auto review',
|
|
370
|
+
'opt.auto.desc': 'When on, behaviour stays as before: a review is created on every compaction and injected into the context and system prompt per the options below. When off, creation and injection stop and every option below becomes read-only.',
|
|
371
|
+
'opt.auto.off': 'Review is off, so review files are neither created nor injected. If you have no other memory plugin or review workflow, turn this on.'
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/** 取一条界面文案;缺英文就回中文,绝不留空。 */
|
|
376
|
+
function tr(key) {
|
|
377
|
+
var dict = TEXTS[LANG] || TEXTS.zh
|
|
378
|
+
var value = Object.prototype.hasOwnProperty.call(dict, key) ? dict[key] : TEXTS.zh[key]
|
|
379
|
+
if (typeof value === 'function') return value.apply(null, Array.prototype.slice.call(arguments, 1))
|
|
380
|
+
return value === undefined ? key : value
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
// 右侧拖条:::-webkit-scrollbar 是伪元素,内联样式改不到,只能注入一段真 CSS。
|
|
384
|
+
// 四个滚动容器共用 .recall-scroll 这个 class。
|
|
385
|
+
var SCROLL_CSS = [
|
|
386
|
+
'.recall-scroll { overflow-y: auto; overscroll-behavior: contain; }',
|
|
387
|
+
'.recall-scroll::-webkit-scrollbar { width: 20px; height: 20px; }',
|
|
388
|
+
'.recall-scroll::-webkit-scrollbar-button { display: none; width: 0; height: 0; }',
|
|
389
|
+
'.recall-scroll::-webkit-scrollbar-track { background: transparent; }',
|
|
390
|
+
'.recall-scroll::-webkit-scrollbar-thumb { background-color: rgba(0,0,0,.38); border-radius: 20px; border: 3px solid transparent; background-clip: content-box; min-height: 48px; }',
|
|
391
|
+
'.recall-scroll::-webkit-scrollbar-thumb:active { background-color: rgba(0,0,0,.62); }',
|
|
392
|
+
'.recall-scroll::-webkit-scrollbar-corner { background: transparent; }'
|
|
393
|
+
].join('')
|
|
394
|
+
|
|
395
|
+
/** 只注入一次;没有 document 的环境直接跳过。 */
|
|
396
|
+
function ensureScrollCss() {
|
|
397
|
+
if (typeof document === 'undefined' || !document.head) return
|
|
398
|
+
if (document.getElementById('dsh-seal-scripts-css')) return
|
|
399
|
+
var el = document.createElement('style')
|
|
400
|
+
el.id = 'dsh-seal-scripts-css'
|
|
401
|
+
el.textContent = SCROLL_CSS
|
|
402
|
+
document.head.appendChild(el)
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
// 样式规矩(踩过的坑):
|
|
406
|
+
// 1. 不要用 JS 改 inline style,会和 React 的 style diff 打架;
|
|
407
|
+
// 2. border 简写与 borderColor 不能混用 —— 撤销时 removeProperty 会回退到 currentColor(黑框);
|
|
408
|
+
// 所以归档左边条用一个独立的绝对定位子元素画虚线,完全不碰行的 border。
|
|
409
|
+
var S = {
|
|
410
|
+
wrap: { display: 'flex', flexDirection: 'column', gap: 12, minHeight: 0 },
|
|
411
|
+
head: { display: 'flex', alignItems: 'baseline', justifyContent: 'space-between', gap: 10 },
|
|
412
|
+
h1: { fontSize: 15, fontWeight: 600 },
|
|
413
|
+
sub: { fontSize: 12, opacity: 0.6 },
|
|
414
|
+
tabs: { display: 'flex', gap: 8, borderBottom: '1px solid #e5e5e5', paddingBottom: 8 },
|
|
415
|
+
tab: { padding: '6px 14px', borderRadius: 8, border: '1px solid transparent', background: 'transparent', cursor: 'pointer', fontSize: 14, color: 'inherit', opacity: 0.62 },
|
|
416
|
+
tabOn: { padding: '6px 14px', borderRadius: 8, border: '1px solid #e5e5e5', background: '#f6f6f6', cursor: 'pointer', fontSize: 14, color: 'inherit', opacity: 1, fontWeight: 600 },
|
|
417
|
+
ws: { fontSize: 12, opacity: 0.6, margin: '12px 0 6px', fontFamily: 'ui-monospace, monospace' },
|
|
418
|
+
list: { display: 'flex', flexDirection: 'column', gap: 6, maxHeight: '42vh', overflowY: 'auto' },
|
|
419
|
+
row: { position: 'relative', display: 'flex', alignItems: 'center', gap: 8, padding: '9px 12px', borderRadius: 10, border: '1px solid #e5e5e5', cursor: 'pointer', fontSize: 13, background: 'transparent', color: 'inherit', textAlign: 'left', width: '100%', boxSizing: 'border-box', outline: 'none', boxShadow: 'none', WebkitTapHighlightColor: 'transparent', userSelect: 'none' },
|
|
420
|
+
rowOn: { background: 'rgba(64,120,255,0.12)', border: '1px solid #4078ff' },
|
|
421
|
+
leftBar: { position: 'absolute', left: 0, top: 0, bottom: 0, width: 0, borderLeft: '1px dashed #9a9a9a', pointerEvents: 'none' },
|
|
422
|
+
dot: { width: 9, height: 9, borderRadius: 999, border: '1px solid currentColor', flex: '0 0 auto', opacity: 0.4 },
|
|
423
|
+
dotOn: { width: 9, height: 9, borderRadius: 999, background: '#4078ff', border: '1px solid #4078ff', flex: '0 0 auto' },
|
|
424
|
+
title: { flex: 1, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' },
|
|
425
|
+
muted: { opacity: 0.62 },
|
|
426
|
+
badge: { fontSize: 10, padding: '1px 6px', borderRadius: 999, border: '1px dashed #9a9a9a', opacity: 0.8, flex: '0 0 auto' },
|
|
427
|
+
footer: { display: 'flex', gap: 10, paddingTop: 12, borderTop: '1px solid #e5e5e5', marginTop: 12 },
|
|
428
|
+
btn: { padding: '8px 16px', borderRadius: 9, border: '1px solid #e5e5e5', background: '#f6f6f6', cursor: 'pointer', fontSize: 13, color: 'inherit' },
|
|
429
|
+
btnDanger: { padding: '8px 16px', borderRadius: 9, border: '1px solid #d9534f', background: 'transparent', color: '#d9534f', cursor: 'pointer', fontSize: 13 },
|
|
430
|
+
btnOff: { padding: '8px 16px', borderRadius: 9, border: '1px solid #e5e5e5', background: 'transparent', color: 'inherit', opacity: 0.35, cursor: 'not-allowed', fontSize: 13 },
|
|
431
|
+
note: { fontSize: 12, opacity: 0.6, minHeight: 18 },
|
|
432
|
+
err: { fontSize: 12, color: '#d9534f', minHeight: 18 },
|
|
433
|
+
chip: { fontSize: 11, padding: '1px 7px', borderRadius: 999, border: '1px solid #ddd', opacity: 0.85, flex: '0 0 auto' },
|
|
434
|
+
// 锁定过的深度用实心蓝底,跟普通灰框一眼分得开(锁定意味着不再衰减)。
|
|
435
|
+
chipLocked: { fontSize: 11, padding: '1px 7px', borderRadius: 999, border: '1px solid #4078ff', background: '#4078ff', color: '#fff', fontWeight: 600, flex: '0 0 auto' },
|
|
436
|
+
// 「载入数值」强制某一级时:蓝框不填色,和锁定(实心)分得开。
|
|
437
|
+
chipForced: { fontSize: 11, padding: '1px 7px', borderRadius: 999, border: '1px dashed #4078ff', color: '#4078ff', fontWeight: 600, flex: '0 0 auto' },
|
|
438
|
+
cal: { border: '1px solid #e5e5e5', borderRadius: 10, padding: 10, marginTop: 10 },
|
|
439
|
+
calHead: { display: 'flex', alignItems: 'center', justifyContent: 'space-between', marginBottom: 8 },
|
|
440
|
+
calGrid: { display: 'grid', gridTemplateColumns: 'repeat(7, 1fr)', gap: 4 },
|
|
441
|
+
calDow: { fontSize: 10, opacity: 0.5, textAlign: 'center' },
|
|
442
|
+
day: { textAlign: 'center', fontSize: 12, padding: '6px 0', borderRadius: 7, cursor: 'pointer', border: '1px solid transparent', color: 'inherit', background: 'transparent' },
|
|
443
|
+
dayEmpty: { textAlign: 'center', fontSize: 12, padding: '6px 0', opacity: 0.15 },
|
|
444
|
+
dayHas: { fontWeight: 600 },
|
|
445
|
+
dayRange: { background: 'rgba(64,120,255,0.16)' },
|
|
446
|
+
dayEdge: { background: '#4078ff', color: '#fff' },
|
|
447
|
+
dayToday: { border: '1px solid #4078ff' },
|
|
448
|
+
disc: { display: 'flex', alignItems: 'center' },
|
|
449
|
+
discBtn: { width: '100%', display: 'flex', alignItems: 'center', gap: 8, padding: '10px 12px', borderRadius: 10, border: '1px solid #e5e5e5', background: '#f6f6f6', cursor: 'pointer', fontSize: 13, color: 'inherit', textAlign: 'left', boxSizing: 'border-box', outline: 'none' },
|
|
450
|
+
caret: { fontSize: 11, opacity: 0.6, width: 12, flex: '0 0 auto' },
|
|
451
|
+
page: { maxHeight: '60vh', overflowY: 'auto', overscrollBehavior: 'contain' },
|
|
452
|
+
// 选项页内容一屏装得下:不套 60vh 滚动框,右侧就不会多出一道拉条(0.2.1)。
|
|
453
|
+
pageFlat: { minHeight: 0 },
|
|
454
|
+
preWide: { whiteSpace: 'pre-wrap', wordBreak: 'break-word', fontSize: 12, lineHeight: 1.6, background: '#f8f8f8', border: '1px solid #e5e5e5', borderRadius: 10, padding: 12, maxHeight: '52vh', overflowY: 'auto', fontFamily: 'inherit' },
|
|
455
|
+
// 选项页:一组一块,标签在左、开关/下拉在右。
|
|
456
|
+
optGroup: { fontSize: 12, opacity: 0.6, paddingBottom: 6, borderBottom: '1px solid #ececec', marginTop: 6 },
|
|
457
|
+
optRow: { display: 'flex', alignItems: 'flex-start', justifyContent: 'space-between', gap: 14, padding: '10px 0', borderBottom: '1px solid #f4f4f4' },
|
|
458
|
+
optText: { display: 'flex', flexDirection: 'column', gap: 4, minWidth: 0 },
|
|
459
|
+
optLabel: { fontSize: 13, fontWeight: 600 },
|
|
460
|
+
optDesc: { fontSize: 12, opacity: 0.62, lineHeight: 1.55 },
|
|
461
|
+
// 全量加载开启后整段警示标红:不用 0.62 透明度,红字要压得住。
|
|
462
|
+
optDescWarn: { fontSize: 12, lineHeight: 1.55, color: '#d9534f', fontWeight: 600 },
|
|
463
|
+
// 「自创工具」页的预览框:等宽、可折行,自己的高度上限里滚,不撑破整页。
|
|
464
|
+
expPre: { margin: 0, whiteSpace: 'pre-wrap', wordBreak: 'break-word', fontSize: 12, lineHeight: 1.6, fontFamily: 'ui-monospace, monospace', background: '#f8f8f8', border: '1px solid #e5e5e5', borderRadius: 10, padding: 12, maxHeight: '38vh', overflowY: 'auto' },
|
|
465
|
+
// 大类标题 + 问号(0.3.10):问号贴着标题,气泡以它为锚点弹出来。
|
|
466
|
+
// 标题本身 0.6 透明(S.groupTitle),外层不透明——否则气泡里的字也被压淡。
|
|
467
|
+
groupHead: { display: 'flex', alignItems: 'center', gap: 6, flexWrap: 'wrap', opacity: 1 },
|
|
468
|
+
groupTitle: { opacity: 0.6, fontSize: 12 },
|
|
469
|
+
helpWrap: { position: 'relative', display: 'inline-flex', alignItems: 'center', flex: '0 0 auto' },
|
|
470
|
+
helpBtn: { width: 16, height: 16, padding: 0, lineHeight: '14px', borderRadius: 999, border: '1px solid #c9c9c9', background: 'transparent', color: 'inherit', fontSize: 11, cursor: 'pointer', opacity: 0.75, flex: '0 0 auto' },
|
|
471
|
+
helpBtnOn: { width: 16, height: 16, padding: 0, lineHeight: '14px', borderRadius: 999, border: '1px solid #4078ff', background: 'transparent', color: '#4078ff', fontSize: 11, cursor: 'pointer', fontWeight: 600, flex: '0 0 auto' },
|
|
472
|
+
// 气泡压在下面的行上面:绝对定位 + zIndex,不改任何父容器的定位与溢出。
|
|
473
|
+
helpBubble: { position: 'absolute', top: '135%', left: 0, zIndex: 60, width: 400, maxWidth: '76vw', padding: '10px 12px', borderRadius: 10, border: '1px solid #d6d6d6', background: '#f8f8f8', color: 'inherit', boxShadow: '0 6px 20px rgba(0,0,0,.18)', fontSize: 12, lineHeight: 1.65, whiteSpace: 'pre-wrap', wordBreak: 'break-word', textAlign: 'left', fontWeight: 'normal', maxHeight: '46vh', overflowY: 'auto' },
|
|
474
|
+
// 工具组目录那一行:等宽、可选中复制(路径要能被人直接拿去用)。
|
|
475
|
+
pathLine: { fontSize: 12, fontFamily: 'ui-monospace, monospace', opacity: 0.72, wordBreak: 'break-all', margin: '2px 0 0', userSelect: 'text' },
|
|
476
|
+
swOn: { flex: '0 0 auto', padding: '5px 12px', borderRadius: 999, border: '1px solid #4078ff', background: '#4078ff', color: '#fff', fontSize: 12, fontWeight: 600, cursor: 'pointer' },
|
|
477
|
+
swOff: { flex: '0 0 auto', padding: '5px 12px', borderRadius: 999, border: '1px solid #c9c9c9', background: 'transparent', color: 'inherit', fontSize: 12, cursor: 'pointer', opacity: 0.7 },
|
|
478
|
+
select: { flex: '0 0 auto', padding: '6px 8px', borderRadius: 8, border: '1px solid #e5e5e5', background: '#fff', color: 'inherit', fontSize: 12, maxWidth: 210 },
|
|
479
|
+
selectOff: { flex: '0 0 auto', padding: '6px 8px', borderRadius: 8, border: '1px solid #e5e5e5', background: '#f4f4f4', color: 'inherit', fontSize: 12, maxWidth: 210, opacity: 0.42, cursor: 'not-allowed' },
|
|
480
|
+
// 导入确认弹窗(0.4.3):照 persona-select 的 ConfirmDialog —— 全屏遮罩 + 居中盒子 + Esc 取消。
|
|
481
|
+
modalOverlay: { position: 'fixed', inset: 0, zIndex: 2147483000, display: 'flex', alignItems: 'center', justifyContent: 'center', padding: 16, background: 'rgba(0,0,0,0.42)' },
|
|
482
|
+
modalBox: { maxWidth: 440, width: '100%', display: 'flex', flexDirection: 'column', gap: 14, padding: 16, borderRadius: 10, border: '1px solid rgba(127,127,127,0.35)', background: 'var(--dsw-alias-bg-elevated, Canvas)', color: 'inherit', boxShadow: '0 12px 40px rgba(0,0,0,0.35)' },
|
|
483
|
+
modalBody: { margin: 0, fontSize: 13, lineHeight: '20px', whiteSpace: 'pre-wrap', wordBreak: 'break-word' },
|
|
484
|
+
btnPrimary: { padding: '8px 16px', borderRadius: 9, border: '1px solid #4078ff', background: '#4078ff', color: '#fff', cursor: 'pointer', fontSize: 13, fontWeight: 600 },
|
|
485
|
+
btnGhost: { padding: '8px 16px', borderRadius: 9, border: '1px solid #e5e5e5', background: 'transparent', color: 'inherit', cursor: 'pointer', fontSize: 13 }
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
function pad(n) { return String(n).padStart(2, '0') }
|
|
489
|
+
|
|
490
|
+
/** 从文件名取短标识:20261028-171157-29e68643.md -> 29e68643 */
|
|
491
|
+
function shortId(file) {
|
|
492
|
+
var s = String(file === undefined || file === null ? '' : file).replace(/\.md$/, '')
|
|
493
|
+
var parts = s.split('-')
|
|
494
|
+
return parts.length > 1 ? parts[parts.length - 1] : s
|
|
495
|
+
}
|
|
496
|
+
function ym(d) { return d.getFullYear() + '-' + pad(d.getMonth() + 1) }
|
|
497
|
+
function ymd(d) { return ym(d) + '-' + pad(d.getDate()) }
|
|
498
|
+
/** 失败心跳的时间:本地「月-日 时:分」,读不出就空着。 */
|
|
499
|
+
function dayTime(ms) {
|
|
500
|
+
var d = new Date(Number(ms) || 0)
|
|
501
|
+
if (isNaN(d.getTime())) return ''
|
|
502
|
+
return pad(d.getMonth() + 1) + '-' + pad(d.getDate()) + ' ' + pad(d.getHours()) + ':' + pad(d.getMinutes())
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
// 回顾页必须跟着「当前正在看的会话」走。以前它只认手选的工作区或
|
|
506
|
+
// 「按目录名排第一的有回顾工作区」,所以在别的工作区打开设置,看到的
|
|
507
|
+
// 还是原来那份回顾 —— 那就是这次报上来的 bug。
|
|
508
|
+
var sessionsHolder = { service: null }
|
|
509
|
+
|
|
510
|
+
/** 拿到会话服务(宿主没给 useSessions 时用它)。拿不到就一直是 null。 */
|
|
511
|
+
function bindSessions(ctx) {
|
|
512
|
+
try {
|
|
513
|
+
var got = typeof ctx.get === 'function' ? ctx.get('sessions') : undefined
|
|
514
|
+
sessionsHolder.service = got || ctx.sessions || sessionsHolder.service
|
|
515
|
+
} catch (e) { /* 老宿主没有 ctx.get,退回 props.useSessions */ }
|
|
516
|
+
try {
|
|
517
|
+
if (typeof ctx.inject === 'function') {
|
|
518
|
+
ctx.inject(['sessions'], function (scoped) {
|
|
519
|
+
sessionsHolder.service = (scoped && scoped.sessions) || sessionsHolder.service
|
|
520
|
+
})
|
|
521
|
+
}
|
|
522
|
+
} catch (e) { /* 没有会话服务就只靠 props */ }
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
/** 从会话快照里取「主视图当前那条」的 id;取不到给空串。 */
|
|
526
|
+
function currentSessionIdOf(state) {
|
|
527
|
+
if (!state || typeof state !== 'object') return ''
|
|
528
|
+
if (typeof state.current === 'string' && state.current !== '') return state.current
|
|
529
|
+
var byId = state.byId
|
|
530
|
+
if (!byId || typeof byId !== 'object') return ''
|
|
531
|
+
for (var key in byId) {
|
|
532
|
+
var row = byId[key]
|
|
533
|
+
if (!row || typeof row !== 'object') continue
|
|
534
|
+
var kept = row.retainedBy && typeof row.retainedBy.mainView === 'number' ? row.retainedBy.mainView : 0
|
|
535
|
+
if (kept > 0) return typeof row.id === 'string' && row.id !== '' ? row.id : key
|
|
536
|
+
}
|
|
537
|
+
return ''
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
/** 订阅会话服务拿当前会话 id(宿主没给 useSessions 时的退路)。 */
|
|
541
|
+
function useSessionStoreId() {
|
|
542
|
+
var s = React.useState('')
|
|
543
|
+
var setId = s[1]
|
|
544
|
+
React.useEffect(function () {
|
|
545
|
+
var store = sessionsHolder.service && sessionsHolder.service.list
|
|
546
|
+
function read() {
|
|
547
|
+
var snapshot = null
|
|
548
|
+
try { snapshot = store && typeof store.getSnapshot === 'function' ? store.getSnapshot() : null } catch (e) { snapshot = null }
|
|
549
|
+
setId(currentSessionIdOf(snapshot))
|
|
550
|
+
}
|
|
551
|
+
read()
|
|
552
|
+
if (!store || typeof store.subscribe !== 'function') return undefined
|
|
553
|
+
return store.subscribe(read)
|
|
554
|
+
}, [])
|
|
555
|
+
return s[0]
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
async function post(path, body) {
|
|
559
|
+
var res
|
|
560
|
+
try {
|
|
561
|
+
res = await fetch(API + path, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body || {}) })
|
|
562
|
+
} catch (e) { throw new Error(tr('err.request', path)) }
|
|
563
|
+
var json = await res.json().catch(function () { return {} })
|
|
564
|
+
if (!res.ok) throw new Error((json.error && json.error.message) || ('HTTP ' + res.status))
|
|
565
|
+
return json
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
/** 一行:点谁选谁。归档用左侧内阴影标记,不碰 border。 */
|
|
569
|
+
function Row(props) {
|
|
570
|
+
var style = Object.assign({}, S.row, props.archived ? S.rowArchived : {}, props.on ? S.rowOn : {})
|
|
571
|
+
return h('div', {
|
|
572
|
+
title: props.title || undefined,
|
|
573
|
+
style: style,
|
|
574
|
+
onClick: props.onClick,
|
|
575
|
+
onMouseDown: function (e) { e.preventDefault() },
|
|
576
|
+
onTouchStart: function (e) { if (e.cancelable) e.preventDefault() }
|
|
577
|
+
}, props.archived ? h('span', { style: S.leftBar }) : null, props.children)
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
/** 月历:点两下选起止日,区间高亮。 */
|
|
581
|
+
function Calendar(props) {
|
|
582
|
+
var cursor = React.useState(props.initial || new Date())
|
|
583
|
+
var at = cursor[0], setAt = cursor[1]
|
|
584
|
+
var year = at.getFullYear(), month = at.getMonth()
|
|
585
|
+
var firstDow = new Date(year, month, 1).getDay()
|
|
586
|
+
var days = new Date(year, month + 1, 0).getDate()
|
|
587
|
+
var cells = []
|
|
588
|
+
for (var i = 0; i < firstDow; i++) cells.push(null)
|
|
589
|
+
for (var d = 1; d <= days; d++) cells.push(d)
|
|
590
|
+
var todayKey = ymd(new Date())
|
|
591
|
+
|
|
592
|
+
function shift(n) { setAt(new Date(year, month + n, 1)) }
|
|
593
|
+
|
|
594
|
+
return h('div', { style: S.cal },
|
|
595
|
+
h('div', { style: S.calHead },
|
|
596
|
+
h('button', { style: S.btn, onClick: function () { shift(-1) } }, '‹'),
|
|
597
|
+
h('span', { style: { fontSize: 13, fontWeight: 600 } }, tr('cal.month', year, month)),
|
|
598
|
+
h('button', { style: S.btn, onClick: function () { shift(1) } }, '›')
|
|
599
|
+
),
|
|
600
|
+
h('div', { style: S.calGrid },
|
|
601
|
+
tr('cal.dow').map(function (w) { return h('div', { key: w, style: S.calDow }, w) }),
|
|
602
|
+
cells.map(function (day, idx) {
|
|
603
|
+
if (day === null) return h('div', { key: 'e' + idx, style: S.dayEmpty });
|
|
604
|
+
var key = year + '-' + pad(month + 1) + '-' + pad(day)
|
|
605
|
+
var has = props.dates && props.dates[key] === true
|
|
606
|
+
var inRange = props.range && props.range.from && props.range.to && key >= props.range.from && key <= props.range.to
|
|
607
|
+
var isEdge = props.range && (key === props.range.from || key === props.range.to)
|
|
608
|
+
var style = Object.assign({}, S.day,
|
|
609
|
+
has ? S.dayHas : {},
|
|
610
|
+
inRange ? S.dayRange : {},
|
|
611
|
+
isEdge ? S.dayEdge : {},
|
|
612
|
+
key === todayKey ? S.dayToday : {});
|
|
613
|
+
return h('button', { key: key, style: style, onClick: function () { props.onPick(key) } }, String(day));
|
|
614
|
+
})
|
|
615
|
+
),
|
|
616
|
+
h('div', { style: { display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginTop: 8 } },
|
|
617
|
+
h('span', { style: S.sub }, props.range && props.range.from
|
|
618
|
+
? (props.range.from === props.range.to ? props.range.from : props.range.from + ' ~ ' + props.range.to)
|
|
619
|
+
: tr('cal.hint')),
|
|
620
|
+
h('button', { style: S.btn, onClick: function () { props.onClear() } }, tr('cal.clear'))
|
|
621
|
+
)
|
|
622
|
+
)
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
/** 开关样子的按钮:开着实心蓝,关着灰框。 */
|
|
626
|
+
function Switch(props) {
|
|
627
|
+
return h('button', {
|
|
628
|
+
type: 'button',
|
|
629
|
+
role: 'switch',
|
|
630
|
+
'aria-checked': props.on ? 'true' : 'false',
|
|
631
|
+
style: props.on ? S.swOn : S.swOff,
|
|
632
|
+
disabled: props.disabled === true,
|
|
633
|
+
onClick: props.onClick
|
|
634
|
+
}, props.on ? (props.onText || tr('switch.on')) : (props.offText || tr('switch.off')))
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
/** 选项页的一行:左边标签 + 说明,右边控件。 */
|
|
638
|
+
function OptionRow(props) {
|
|
639
|
+
return h('div', { style: S.optRow },
|
|
640
|
+
h('div', { style: S.optText },
|
|
641
|
+
h('div', { style: S.optLabel }, props.label),
|
|
642
|
+
props.desc ? h('div', { style: props.descStyle || S.optDesc }, props.desc) : null
|
|
643
|
+
),
|
|
644
|
+
props.control
|
|
645
|
+
)
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
/**
|
|
649
|
+
* 问号(0.3.10):点一下在气泡里显示一段只读说明,再点一下、或点页面别处就收起。
|
|
650
|
+
* 气泡是绝对定位的,不改父容器的定位与溢出;点气泡里面不会把它顺手关掉。
|
|
651
|
+
*/
|
|
652
|
+
function HelpDot(props) {
|
|
653
|
+
var st = React.useState(false)
|
|
654
|
+
var open = st[0], setOpen = st[1]
|
|
655
|
+
var box = React.useRef(null)
|
|
656
|
+
React.useEffect(function () {
|
|
657
|
+
if (!open) return undefined
|
|
658
|
+
var doc = typeof document !== 'undefined' ? document : null
|
|
659
|
+
if (!doc || typeof doc.addEventListener !== 'function') return undefined
|
|
660
|
+
function away(e) {
|
|
661
|
+
var node = box.current
|
|
662
|
+
if (node && typeof node.contains === 'function' && e && e.target && node.contains(e.target)) return
|
|
663
|
+
setOpen(false)
|
|
664
|
+
}
|
|
665
|
+
doc.addEventListener('click', away)
|
|
666
|
+
return function () { doc.removeEventListener('click', away) }
|
|
667
|
+
}, [open])
|
|
668
|
+
return h('span', { ref: box, style: S.helpWrap },
|
|
669
|
+
h('button', {
|
|
670
|
+
type: 'button',
|
|
671
|
+
'aria-label': tr('help.aria'),
|
|
672
|
+
'aria-expanded': open ? 'true' : 'false',
|
|
673
|
+
title: tr('help.aria'),
|
|
674
|
+
style: open ? S.helpBtnOn : S.helpBtn,
|
|
675
|
+
onClick: function () { setOpen(!open) },
|
|
676
|
+
onMouseDown: function (e) { e.preventDefault() }
|
|
677
|
+
}, '?'),
|
|
678
|
+
open ? h('div', { role: 'note', style: S.helpBubble }, props.text) : null
|
|
679
|
+
)
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
/** 下拉:options 是 [值, 文字] 的数组,值统一按字符串传。 */
|
|
683
|
+
function Select(props) {
|
|
684
|
+
return h('select', {
|
|
685
|
+
style: props.disabled ? S.selectOff : S.select,
|
|
686
|
+
value: String(props.value),
|
|
687
|
+
disabled: props.disabled === true,
|
|
688
|
+
onChange: function (e) { props.onChange(e.target.value) }
|
|
689
|
+
}, (props.options || []).map(function (pair) {
|
|
690
|
+
return h('option', { key: pair[0], value: pair[0] }, pair[1])
|
|
691
|
+
}))
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
function Section(props) {
|
|
695
|
+
var hasHost = props !== null && props !== undefined && typeof props.useSessions === 'function'
|
|
696
|
+
return hasHost ? h(SectionHost, props) : h(SectionFallback)
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
// 两个变体各自是独立组件类型,钩子顺序才不会在两种宿主之间跳变。
|
|
700
|
+
function SectionHost(props) {
|
|
701
|
+
var id = props.useSessions(currentSessionIdOf)
|
|
702
|
+
return h(SectionImpl, { currentSessionId: typeof id === 'string' ? id : '' })
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
function SectionFallback() {
|
|
706
|
+
return h(SectionImpl, { currentSessionId: useSessionStoreId() })
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
function SectionImpl(props) {
|
|
710
|
+
useLangTick()
|
|
711
|
+
// 每次渲染现读一次语言:设置页在语言切换后重新挂载时,这里就能拿到新值。
|
|
712
|
+
syncLangFromService()
|
|
713
|
+
var currentSessionId = typeof props.currentSessionId === 'string' ? props.currentSessionId : ''
|
|
714
|
+
var s = React.useState({ loading: true, error: '', workspaces: [] })
|
|
715
|
+
var data = s[0], setData = s[1]
|
|
716
|
+
var t = React.useState('toolList')
|
|
717
|
+
var tab = t[0], setTab = t[1]
|
|
718
|
+
var sel = React.useState(null)
|
|
719
|
+
var selected = sel[0], setSelected = sel[1]
|
|
720
|
+
var rng = React.useState(null)
|
|
721
|
+
var range = rng[0], setRange = rng[1]
|
|
722
|
+
var note = React.useState(''); var setNote = note[1]
|
|
723
|
+
var err = React.useState(''); var setErr = err[1]
|
|
724
|
+
var ldi = React.useState(null); var loadInfo = ldi[0], setLoadInfo = ldi[1]
|
|
725
|
+
var op = React.useState(false); var open = op[0], setOpen = op[1]
|
|
726
|
+
var mp = React.useState(null); var memPick = mp[0], setMemPick = mp[1]
|
|
727
|
+
var mc = React.useState(''); var memConfirm = mc[0], setMemConfirm = mc[1]
|
|
728
|
+
var busy = React.useState(false); var isBusy = busy[0], setBusy = busy[1]
|
|
729
|
+
var confirm = React.useState(''); var confirming = confirm[0], setConfirming = confirm[1]
|
|
730
|
+
// 已经请求过上下文的工作区。用它当守卫,不依赖服务器回传的 cwd,避免来回重试。
|
|
731
|
+
var ctxCwd = React.useRef('')
|
|
732
|
+
// 选中某一条时它单独那份渲染;没选时载入框用整段(loadInfo)。
|
|
733
|
+
var pk = React.useState(null); var pickInfo = pk[0], setPickInfo = pk[1]
|
|
734
|
+
// 连点两条时,晚到的旧响应不能盖掉新的。
|
|
735
|
+
var pickSeq = React.useRef(0)
|
|
736
|
+
// 选项(「选项」标签)。/state 一起带回来;拿不到就单独 GET 一次。
|
|
737
|
+
var so = React.useState(null); var options = so[0], setOptions = so[1]
|
|
738
|
+
// 「自创工具」标签那一段的原文(/api/session-recall.toolSequence 现算的)。
|
|
739
|
+
var tk = React.useState(null); var toolSequence = tk[0], setToolList = tk[1]
|
|
740
|
+
// 「导入 / 导出」(0.4.3):选中的那个包、预演结果(还没写盘)、隐藏的文件选择框。
|
|
741
|
+
var impFile = React.useState(null); var importFile = impFile[0], setImportFile = impFile[1]
|
|
742
|
+
var impPlan = React.useState(null); var importPlan = impPlan[0], setImportPlan = impPlan[1]
|
|
743
|
+
// 导入 / 导出的回执(0.4.4):只属于「自创工具」页,渲染在那一页里。
|
|
744
|
+
// 以前它写进全页共享的 note——那条行在标签内容区外面,切到别的页也会一直挂着。
|
|
745
|
+
var impNote = React.useState(''); var importNote = impNote[0], setImportNote = impNote[1]
|
|
746
|
+
var fileInput = React.useRef(null)
|
|
747
|
+
|
|
748
|
+
var load = React.useCallback(async function () {
|
|
749
|
+
try {
|
|
750
|
+
var res = await fetch(API + 'state')
|
|
751
|
+
var json = await res.json()
|
|
752
|
+
if (!res.ok) throw new Error((json.error && json.error.message) || ('HTTP ' + res.status))
|
|
753
|
+
setData({ loading: false, error: '', workspaces: json.workspaces || [], capabilities: json.capabilities || null })
|
|
754
|
+
if (json.options) setOptions(json.options)
|
|
755
|
+
return json
|
|
756
|
+
} catch (e) {
|
|
757
|
+
setData({ loading: false, error: String(e.message || e), workspaces: [] })
|
|
758
|
+
return null
|
|
759
|
+
}
|
|
760
|
+
}, [])
|
|
761
|
+
|
|
762
|
+
React.useEffect(function () { load() }, [])
|
|
763
|
+
|
|
764
|
+
var selectedWorkspace = selected
|
|
765
|
+
? data.workspaces.filter(function (w) { return w.cwd === selected.cwd })[0]
|
|
766
|
+
: null
|
|
767
|
+
|
|
768
|
+
// 当前会话落在哪个工作区:拿会话 id 去 /state 里反查。反查不到才算「不知道」。
|
|
769
|
+
var currentWorkspace = null
|
|
770
|
+
if (currentSessionId !== '') {
|
|
771
|
+
for (var wi = 0; wi < data.workspaces.length; wi++) {
|
|
772
|
+
var wsj = data.workspaces[wi]
|
|
773
|
+
if ((wsj.sessions || []).some(function (x) { return x.id === currentSessionId })) { currentWorkspace = wsj; break }
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
// 回顾页看哪个工作区:手选的 > 当前会话所在的 > (不知道当前会话时)第一个有回顾的。
|
|
778
|
+
var wsForMem = selectedWorkspace || currentWorkspace ||
|
|
779
|
+
data.workspaces.filter(function (w) { return w.memories.length > 0 })[0] || null
|
|
780
|
+
var memCwd = wsForMem ? wsForMem.cwd : ''
|
|
781
|
+
|
|
782
|
+
// 换会话就把上一轮的选择清掉,否则会拿着旧工作区的选中项继续显示。
|
|
783
|
+
React.useEffect(function () {
|
|
784
|
+
setSelected(null); setMemPick(null); setRange(null); setConfirming(''); setNote('')
|
|
785
|
+
}, [currentSessionId])
|
|
786
|
+
|
|
787
|
+
// 换工作区时清掉这条回顾的选择与日期区间。
|
|
788
|
+
React.useEffect(function () {
|
|
789
|
+
setMemPick(null); setRange(null); setConfirming('')
|
|
790
|
+
}, [memCwd])
|
|
791
|
+
|
|
792
|
+
React.useEffect(function () {
|
|
793
|
+
if (tab !== 'memory' || data.loading || data.error || memCwd === '') return
|
|
794
|
+
if (ctxCwd.current === memCwd) return
|
|
795
|
+
ctxCwd.current = memCwd
|
|
796
|
+
loadContext(memCwd)
|
|
797
|
+
}, [tab, data, memCwd])
|
|
798
|
+
|
|
799
|
+
// 选中某条回顾:只取这一条会被注入成什么,框里跟着换。
|
|
800
|
+
React.useEffect(function () {
|
|
801
|
+
if (tab !== 'memory' || memCwd === '' || !memPick) { setPickInfo(null); return }
|
|
802
|
+
loadPick(memCwd, memPick)
|
|
803
|
+
}, [tab, memCwd, memPick])
|
|
804
|
+
|
|
805
|
+
// 进「选项」标签时还没有选项(老宿主不往 /state 里带),单独取一次。
|
|
806
|
+
React.useEffect(function () {
|
|
807
|
+
if (tab !== 'options' || options !== null) return
|
|
808
|
+
loadOptions()
|
|
809
|
+
}, [tab, options])
|
|
810
|
+
|
|
811
|
+
// 进「自创工具」标签:取一次要注入的原文(和装配同一个函数算出来的)。
|
|
812
|
+
React.useEffect(function () {
|
|
813
|
+
if (tab !== 'toolList') return
|
|
814
|
+
loadToolList()
|
|
815
|
+
}, [tab])
|
|
816
|
+
|
|
817
|
+
async function loadOptions() {
|
|
818
|
+
try {
|
|
819
|
+
var res = await fetch(API + 'options')
|
|
820
|
+
var json = await res.json()
|
|
821
|
+
if (!res.ok) throw new Error((json.error && json.error.message) || ('HTTP ' + res.status))
|
|
822
|
+
if (json.options) setOptions(json.options)
|
|
823
|
+
} catch (e) { setErr(String(e.message || e)) }
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
async function loadToolList() {
|
|
827
|
+
try {
|
|
828
|
+
var res = await fetch(API + 'toolSequence')
|
|
829
|
+
var json = await res.json()
|
|
830
|
+
if (!res.ok) throw new Error((json.error && json.error.message) || ('HTTP ' + res.status))
|
|
831
|
+
setToolList({ enabled: json.enabled !== false, path: json.path || '', text: json.text || '', bytes: json.bytes || 0 })
|
|
832
|
+
} catch (e) { setErr(String(e.message || e)) }
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
/** 0.4.3:文件读成 base64。分块转,几 MB 的包也不会把调用栈撑爆。 */
|
|
836
|
+
function readFileAsBase64(file) {
|
|
837
|
+
return new Promise(function (yes, no) {
|
|
838
|
+
var reader = new FileReader()
|
|
839
|
+
reader.onerror = function () { no(new Error('读不到这个文件:' + (file && file.name ? file.name : ''))) }
|
|
840
|
+
reader.onload = function () {
|
|
841
|
+
try {
|
|
842
|
+
var bytes = new Uint8Array(reader.result)
|
|
843
|
+
var chunk = 0x8000
|
|
844
|
+
var parts = []
|
|
845
|
+
for (var i = 0; i < bytes.length; i += chunk) {
|
|
846
|
+
parts.push(String.fromCharCode.apply(null, bytes.subarray(i, i + chunk)))
|
|
847
|
+
}
|
|
848
|
+
yes(window.btoa(parts.join('')))
|
|
849
|
+
} catch (e) { no(e) }
|
|
850
|
+
}
|
|
851
|
+
reader.readAsArrayBuffer(file)
|
|
852
|
+
})
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
/** 点「导入」:先把隐藏的 file 选择框清空再点,选同一个文件也要能触发。 */
|
|
856
|
+
function pickImportFile() {
|
|
857
|
+
if (isBusy) return
|
|
858
|
+
setErr(''); setImportNote(''); setImportPlan(null); setImportFile(null)
|
|
859
|
+
var el = fileInput.current
|
|
860
|
+
if (el) { el.value = ''; el.click() }
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
/** 选好文件先走一遍 dryRun:只报会装什么,不写盘。确认之后才真装。 */
|
|
864
|
+
async function onImportChosen(ev) {
|
|
865
|
+
var file = ev && ev.target && ev.target.files && ev.target.files[0]
|
|
866
|
+
if (!file) return
|
|
867
|
+
setBusy(true); setErr(''); setImportNote(''); setImportPlan(null); setImportFile(null)
|
|
868
|
+
try {
|
|
869
|
+
var data = await readFileAsBase64(file)
|
|
870
|
+
var res = await fetch(API + 'toolSequence/import', {
|
|
871
|
+
method: 'POST',
|
|
872
|
+
headers: { 'Content-Type': 'application/json' },
|
|
873
|
+
body: JSON.stringify({ name: file.name, data: data, dryRun: true })
|
|
874
|
+
})
|
|
875
|
+
var json = await res.json()
|
|
876
|
+
if (!res.ok) throw new Error((json.error && json.error.message) || ('HTTP ' + res.status))
|
|
877
|
+
setImportFile({ name: file.name, data: data })
|
|
878
|
+
setImportPlan({ imported: json.imported || [], overwritten: json.overwritten || [], skipped: json.skipped || [] })
|
|
879
|
+
} catch (e) {
|
|
880
|
+
setErr(String(e.message || e))
|
|
881
|
+
} finally { setBusy(false) }
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
/** 确认导入:同一个包再发一次,这次 dryRun 为假。 */
|
|
885
|
+
async function confirmImport() {
|
|
886
|
+
if (isBusy || !importFile) return
|
|
887
|
+
setBusy(true); setErr(''); setImportNote('')
|
|
888
|
+
try {
|
|
889
|
+
var res = await fetch(API + 'toolSequence/import', {
|
|
890
|
+
method: 'POST',
|
|
891
|
+
headers: { 'Content-Type': 'application/json' },
|
|
892
|
+
body: JSON.stringify({ name: importFile.name, data: importFile.data, dryRun: false })
|
|
893
|
+
})
|
|
894
|
+
var json = await res.json()
|
|
895
|
+
if (!res.ok) throw new Error((json.error && json.error.message) || ('HTTP ' + res.status))
|
|
896
|
+
var n = (json.imported || []).length
|
|
897
|
+
var k = (json.overwritten || []).length
|
|
898
|
+
var missed = (json.skipped || []).length
|
|
899
|
+
setImportNote(tr('tl.imported', n, k) + (missed > 0 ? tr('tl.importSkipped', missed) : ''))
|
|
900
|
+
setImportFile(null); setImportPlan(null)
|
|
901
|
+
await loadToolList()
|
|
902
|
+
await load()
|
|
903
|
+
} catch (e) {
|
|
904
|
+
setErr(String(e.message || e))
|
|
905
|
+
} finally { setBusy(false) }
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
/**
|
|
909
|
+
* 导出:让宿主把 toolSequence.zip 直接写进当前会话所在的工作区文件夹。
|
|
910
|
+
* 落点由宿主算(它拿得到真实路径),界面只负责把它念出来。
|
|
911
|
+
*/
|
|
912
|
+
async function doExport() {
|
|
913
|
+
if (isBusy) return
|
|
914
|
+
var outDir = currentWorkspace && currentWorkspace.cwd
|
|
915
|
+
? currentWorkspace.cwd
|
|
916
|
+
: ((data.workspaces && data.workspaces[0] && data.workspaces[0].cwd) ? data.workspaces[0].cwd : '')
|
|
917
|
+
if (outDir === '') { setErr(tr('tl.noWorkspace')); return }
|
|
918
|
+
setBusy(true); setErr(''); setImportNote('')
|
|
919
|
+
try {
|
|
920
|
+
var res = await fetch(API + 'toolSequence/export', {
|
|
921
|
+
method: 'POST',
|
|
922
|
+
headers: { 'Content-Type': 'application/json' },
|
|
923
|
+
body: JSON.stringify({ cwd: outDir })
|
|
924
|
+
})
|
|
925
|
+
var json = await res.json()
|
|
926
|
+
if (!res.ok) throw new Error((json.error && json.error.message) || ('HTTP ' + res.status))
|
|
927
|
+
setImportNote(tr('tl.exported', json.file || '', json.files || 0, json.size || 0) +
|
|
928
|
+
(json.overwritten ? tr('tl.overwritten') : ''))
|
|
929
|
+
} catch (e) {
|
|
930
|
+
setErr(String(e.message || e))
|
|
931
|
+
} finally { setBusy(false) }
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
/** 关掉导入弹窗:包和预演结果一起作废,不写盘。 */
|
|
935
|
+
function closeImportDialog() {
|
|
936
|
+
if (isBusy) return
|
|
937
|
+
setImportFile(null); setImportPlan(null)
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
// Esc 关弹窗:和 persona-select 的 ConfirmDialog 一样只认 Esc,不劫持遮罩点击。
|
|
941
|
+
React.useEffect(function () {
|
|
942
|
+
if (importPlan === null) return undefined
|
|
943
|
+
if (typeof document === 'undefined' || typeof document.addEventListener !== 'function') return undefined
|
|
944
|
+
function onKey(e) { if (e && e.key === 'Escape') closeImportDialog() }
|
|
945
|
+
document.addEventListener('keydown', onKey)
|
|
946
|
+
return function () { document.removeEventListener('keydown', onKey) }
|
|
947
|
+
}, [importPlan, isBusy])
|
|
948
|
+
|
|
949
|
+
/**
|
|
950
|
+
* 导入确认弹窗(0.4.3):结构照 persona-select 的 ConfirmDialog ——
|
|
951
|
+
* 固定遮罩 + 居中盒子 + role=dialog/aria-modal + 右下主次两个键。
|
|
952
|
+
*/
|
|
953
|
+
function importDialogView() {
|
|
954
|
+
if (importPlan === null) return null
|
|
955
|
+
var missed = (importPlan.skipped || []).length
|
|
956
|
+
return h('div', { style: S.modalOverlay, 'data-import-dialog': '1' },
|
|
957
|
+
h('div', { style: S.modalBox, role: 'dialog', 'aria-modal': 'true' },
|
|
958
|
+
h('p', { style: S.modalBody }, tr('tl.importPreview', importPlan.imported.length, importPlan.overwritten.length)),
|
|
959
|
+
missed > 0 ? h('p', { style: S.modalBody }, tr('tl.importSkipLine', missed)) : null,
|
|
960
|
+
h('div', { style: { display: 'flex', gap: 8, justifyContent: 'flex-end', flexWrap: 'wrap' } },
|
|
961
|
+
h('button', {
|
|
962
|
+
type: 'button',
|
|
963
|
+
style: isBusy ? S.btnOff : S.btnPrimary,
|
|
964
|
+
disabled: isBusy,
|
|
965
|
+
'data-confirm-action': 'primary',
|
|
966
|
+
onClick: confirmImport
|
|
967
|
+
}, tr('tl.importConfirm')),
|
|
968
|
+
h('button', {
|
|
969
|
+
type: 'button',
|
|
970
|
+
style: isBusy ? S.btnOff : S.btnGhost,
|
|
971
|
+
disabled: isBusy,
|
|
972
|
+
'data-confirm-action': 'cancel',
|
|
973
|
+
onClick: closeImportDialog
|
|
974
|
+
}, tr('tl.importCancel'))
|
|
975
|
+
)
|
|
976
|
+
)
|
|
977
|
+
)
|
|
978
|
+
}
|
|
979
|
+
|
|
980
|
+
/**
|
|
981
|
+
* 改一个或多个选项。落盘后把回顾页的预览与深度徽章全部作废重取:
|
|
982
|
+
* 选项只改载入时的装配,不改载入文件里记下的深度,所以重取就能看到新内容。
|
|
983
|
+
*/
|
|
984
|
+
async function patchOptions(patch) {
|
|
985
|
+
if (isBusy) return
|
|
986
|
+
setBusy(true); setErr(''); setNote('')
|
|
987
|
+
try {
|
|
988
|
+
var res = await post('options', patch)
|
|
989
|
+
if (res.options) setOptions(res.options)
|
|
990
|
+
setNote(tr('note.saved'))
|
|
991
|
+
// 让两个 effect 重新取:载入框、单条预览、工作区级别都按新选项重算。
|
|
992
|
+
ctxCwd.current = ''
|
|
993
|
+
setLoadInfo(null)
|
|
994
|
+
setPickInfo(null)
|
|
995
|
+
await load()
|
|
996
|
+
if (tab === 'toolList') await loadToolList()
|
|
997
|
+
} catch (e) { setErr(String(e.message || e)) }
|
|
998
|
+
finally { setBusy(false) }
|
|
999
|
+
}
|
|
1000
|
+
|
|
1001
|
+
async function doMemDelete() {
|
|
1002
|
+
if (!memPick) return
|
|
1003
|
+
if (memConfirm !== 'mem') { setMemConfirm('mem'); setNote(tr('note.memConfirm')); return }
|
|
1004
|
+
var cwd = loadInfo ? loadInfo.cwd : null
|
|
1005
|
+
if (!cwd) return
|
|
1006
|
+
setBusy(true); setErr(''); setNote('')
|
|
1007
|
+
try {
|
|
1008
|
+
await post('memory-delete', { cwd: cwd, file: memPick })
|
|
1009
|
+
setNote(tr('note.memDeleted', memPick))
|
|
1010
|
+
setMemPick(null); setMemConfirm('')
|
|
1011
|
+
await load()
|
|
1012
|
+
await loadContext(cwd)
|
|
1013
|
+
} catch (e) { setErr(String(e.message || e)) }
|
|
1014
|
+
finally { setBusy(false) }
|
|
1015
|
+
}
|
|
1016
|
+
|
|
1017
|
+
async function loadContext(cwd) {
|
|
1018
|
+
if (!cwd) return
|
|
1019
|
+
ctxCwd.current = cwd
|
|
1020
|
+
try {
|
|
1021
|
+
var res = await post('memory-context', { cwd: cwd })
|
|
1022
|
+
setLoadInfo(Object.assign({}, res, { cwd: cwd }))
|
|
1023
|
+
} catch (e) { setErr(String(e.message || e)) }
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
/** 只取一条回顾的渲染文本;连点时只有最后一次的响应算数。 */
|
|
1027
|
+
async function loadPick(cwd, file) {
|
|
1028
|
+
var my = ++pickSeq.current
|
|
1029
|
+
var key = cwd + '\u0000' + file
|
|
1030
|
+
try {
|
|
1031
|
+
var res = await post('memory-context', { cwd: cwd, file: file })
|
|
1032
|
+
if (my !== pickSeq.current) return
|
|
1033
|
+
setPickInfo({ key: key, text: res.text || '', chars: res.chars || 0, error: res.error || null })
|
|
1034
|
+
} catch (e) {
|
|
1035
|
+
if (my !== pickSeq.current) return
|
|
1036
|
+
setErr(String(e.message || e))
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
/** 点日历:没有起点 -> 设起点;有起点没终点 -> 设终点;都有 -> 重新开始。 */
|
|
1041
|
+
function pickDay(key) {
|
|
1042
|
+
// 选完区间就把列表摊开,否则列表收着,看不出区间生效了。
|
|
1043
|
+
setOpen(true)
|
|
1044
|
+
if (range === null || range.from === null) { setRange({ from: key, to: key }); return }
|
|
1045
|
+
if (range.from === range.to) {
|
|
1046
|
+
if (key < range.from) setRange({ from: key, to: range.from })
|
|
1047
|
+
else setRange({ from: range.from, to: key })
|
|
1048
|
+
return
|
|
1049
|
+
}
|
|
1050
|
+
setRange({ from: key, to: key })
|
|
1051
|
+
}
|
|
1052
|
+
|
|
1053
|
+
async function doDelete() {
|
|
1054
|
+
if (!selected) return
|
|
1055
|
+
if (confirming !== 'delete') { setConfirming('delete'); setNote(tr('note.deleteConfirm')); return }
|
|
1056
|
+
setBusy(true); setErr(''); setNote(''); setConfirming('')
|
|
1057
|
+
var target = selected.id
|
|
1058
|
+
try {
|
|
1059
|
+
await post('delete', { sessionId: target })
|
|
1060
|
+
setNote(tr('note.deleted')); setSelected(null)
|
|
1061
|
+
await load()
|
|
1062
|
+
} catch (e) {
|
|
1063
|
+
var fresh = await load()
|
|
1064
|
+
var alive = fresh !== null && (fresh.workspaces || []).some(function (w) {
|
|
1065
|
+
return (w.sessions || []).some(function (x) { return x.id === target })
|
|
1066
|
+
})
|
|
1067
|
+
if (fresh !== null && !alive) { setNote(tr('note.deletedLost')); setSelected(null) }
|
|
1068
|
+
else setErr(String(e.message || e))
|
|
1069
|
+
} finally { setBusy(false) }
|
|
1070
|
+
}
|
|
1071
|
+
|
|
1072
|
+
async function doCompactDelete() {
|
|
1073
|
+
if (!selected) return
|
|
1074
|
+
if (confirming !== 'compact') { setConfirming('compact'); setNote(tr('note.compactConfirm')); return }
|
|
1075
|
+
setBusy(true); setErr(''); setNote(''); setConfirming('')
|
|
1076
|
+
var target = selected.id
|
|
1077
|
+
try {
|
|
1078
|
+
var res = await post('compact-delete', { sessionId: target })
|
|
1079
|
+
setNote(tr('note.compacted', res.memory)); setSelected(null)
|
|
1080
|
+
await load()
|
|
1081
|
+
} catch (e) {
|
|
1082
|
+
var fresh2 = await load()
|
|
1083
|
+
var alive2 = fresh2 !== null && (fresh2.workspaces || []).some(function (w) {
|
|
1084
|
+
return (w.sessions || []).some(function (x) { return x.id === target })
|
|
1085
|
+
})
|
|
1086
|
+
if (fresh2 !== null && !alive2) { setNote(tr('note.deletedLost')); setSelected(null) }
|
|
1087
|
+
else setErr(String(e.message || e))
|
|
1088
|
+
} finally { setBusy(false) }
|
|
1089
|
+
}
|
|
1090
|
+
|
|
1091
|
+
/**
|
|
1092
|
+
* 「选项」标签:0.2.8 起「回顾注入」是一组,开头先是总开关,再是原来的两组。
|
|
1093
|
+
* 0.3.11:同一组开头先放「自动回顾」总闸,再放「回顾注入」(0.3.10 误放在组标题上面)。
|
|
1094
|
+
* 总闸或总开关关掉时,下面不可改的部分整片变灰——已经存的值一个都不动(服务端也不动它们)。
|
|
1095
|
+
* 停止降低开启时载入数值禁用(服务端也会把它收回「跟随深度载入」),
|
|
1096
|
+
* 客户端只是把这件事显示出来,不自己决定怎么存。
|
|
1097
|
+
*/
|
|
1098
|
+
/**
|
|
1099
|
+
* 「自创工具」标签(0.3.1):只管工具组清单(A 段)。
|
|
1100
|
+
* 拆出来的理由:「不想让回顾铺满上下文」和「不想把自己的手收走」是两件事。
|
|
1101
|
+
* 0.4.5:「注入工具组清单」这个开关连同新的「清单词刷新时刻」一起挪到「选项」页的
|
|
1102
|
+
* 「工具固存」大类;这一页只留路径、预览、导入导出,并写明开关去哪了。
|
|
1103
|
+
*/
|
|
1104
|
+
function toolListView() {
|
|
1105
|
+
if (options === null) return h('div', { style: S.note }, tr('loading'))
|
|
1106
|
+
var on = options.toolListEnabled !== false
|
|
1107
|
+
var refreshMode = options.toolListRefresh === 'realtime' ? 'realtime' : 'newSession'
|
|
1108
|
+
var preview = toolSequence === null ? tr('loading') : (toolSequence.text || tr('tl.empty'))
|
|
1109
|
+
// 工具路径(0.3.10):/toolSequence 现算回来的工具组目录,就是 session_tool_call 取脚本的地方。
|
|
1110
|
+
var pathText = toolSequence !== null && toolSequence.path ? tr('tl.path', toolSequence.path) : ''
|
|
1111
|
+
return h('div', { style: { display: 'flex', flexDirection: 'column', gap: 14 } },
|
|
1112
|
+
h('div', { style: { display: 'flex', flexDirection: 'column', gap: 4 } },
|
|
1113
|
+
h('div', { style: Object.assign({}, S.optGroup, S.groupHead) },
|
|
1114
|
+
h('span', { style: S.groupTitle }, tr('tl.group')),
|
|
1115
|
+
h(HelpDot, { text: tr('help.toolList') })
|
|
1116
|
+
),
|
|
1117
|
+
pathText ? h('div', { style: S.pathLine }, pathText) : null
|
|
1118
|
+
),
|
|
1119
|
+
h('div', { style: S.optGroup },
|
|
1120
|
+
tr('tl.preview') + (toolSequence !== null && toolSequence.bytes ? tr('tl.bytes', toolSequence.bytes) : '') +
|
|
1121
|
+
(on ? '' : ' ' + tr('tl.off'))),
|
|
1122
|
+
h('pre', { className: 'recall-scroll', style: S.expPre }, preview),
|
|
1123
|
+
h('div', { style: S.note }, tr('tl.note')),
|
|
1124
|
+
h('div', { style: S.note, 'data-tl-refresh': refreshMode },
|
|
1125
|
+
refreshMode === 'realtime' ? tr('tl.note.realtime') : tr('tl.note.newSession')),
|
|
1126
|
+
importNote ? h('div', { style: S.note, 'data-import-note': '1' }, importNote) : null,
|
|
1127
|
+
h('div', { style: { display: 'flex', gap: 10, flexWrap: 'wrap', paddingTop: 12, borderTop: '1px solid #ececec' } },
|
|
1128
|
+
h('button', { style: isBusy ? S.btnOff : S.btn, disabled: isBusy, onClick: pickImportFile }, tr('tl.import')),
|
|
1129
|
+
h('button', { style: isBusy ? S.btnOff : S.btn, disabled: isBusy, onClick: doExport }, tr('tl.export'))
|
|
1130
|
+
),
|
|
1131
|
+
h('input', {
|
|
1132
|
+
type: 'file',
|
|
1133
|
+
accept: '.zip,application/zip',
|
|
1134
|
+
style: { display: 'none' },
|
|
1135
|
+
ref: fileInput,
|
|
1136
|
+
onChange: onImportChosen
|
|
1137
|
+
}),
|
|
1138
|
+
importDialogView()
|
|
1139
|
+
)
|
|
1140
|
+
}
|
|
1141
|
+
|
|
1142
|
+
function optionsView() {
|
|
1143
|
+
if (options === null) return h('div', { style: S.note }, tr('loading'))
|
|
1144
|
+
var o = options
|
|
1145
|
+
// 0.3.10:「自动回顾」是总闸。关着时服务端返回的 injectEnabled 已经是 false,
|
|
1146
|
+
// 下面整片变灰不可改;再打开时,原来存的那些值一个都没动过。
|
|
1147
|
+
var autoOn = o.autoReviewEnabled === true
|
|
1148
|
+
var injectOn = autoOn && o.injectEnabled !== false
|
|
1149
|
+
var locked = !injectOn
|
|
1150
|
+
// 0.4.5:「工具固存」这一组不跟「自动回顾」「回顾注入」连带,自己看自己的开关。
|
|
1151
|
+
var tlOn = o.toolListEnabled !== false
|
|
1152
|
+
var refresh = o.toolListRefresh === 'realtime' ? 'realtime' : 'newSession'
|
|
1153
|
+
var levelOptions = [
|
|
1154
|
+
['follow', tr('opt.follow')],
|
|
1155
|
+
['3', tr('opt.l3')],
|
|
1156
|
+
['2', tr('opt.l2')],
|
|
1157
|
+
['1', tr('opt.l1')],
|
|
1158
|
+
['0', tr('opt.l0')]
|
|
1159
|
+
]
|
|
1160
|
+
var levelNow = o.loadLevel === 'follow' ? 'follow' : String(o.loadLevel)
|
|
1161
|
+
// 0.3.11:总闸关着时,连「回顾注入」这一行也要跟着变灰(它已经点不动了);
|
|
1162
|
+
// 只关注入时,这一行保持清楚,只有它下面那四行——0.2.8 的样子。
|
|
1163
|
+
var dimStyle = { display: 'flex', flexDirection: 'column', gap: 14, opacity: 0.42 }
|
|
1164
|
+
var plainStyle = { display: 'flex', flexDirection: 'column', gap: 14 }
|
|
1165
|
+
var tailDim = autoOn ? plainStyle : dimStyle
|
|
1166
|
+
var belowDim = locked && autoOn ? dimStyle : plainStyle
|
|
1167
|
+
return h('div', { style: { display: 'flex', flexDirection: 'column', gap: 14 } },
|
|
1168
|
+
// 0.4.5:「工具固存」独立一类,排在「回顾注入」之前。它只管工具组清单那一段,
|
|
1169
|
+
// 不受「自动回顾」总闸与「回顾注入」开关连带——那两项管的是回顾正文与日记提醒。
|
|
1170
|
+
h('div', { style: Object.assign({}, S.optGroup, S.groupHead) },
|
|
1171
|
+
h('span', { style: S.groupTitle }, tr('opt.group.tools')),
|
|
1172
|
+
h(HelpDot, { text: tr('help.toolStore') })
|
|
1173
|
+
),
|
|
1174
|
+
h(OptionRow, {
|
|
1175
|
+
label: tr('tl.inject'),
|
|
1176
|
+
desc: tlOn ? tr('tl.desc') : tr('tl.offDesc'),
|
|
1177
|
+
descStyle: tlOn ? null : S.optDescWarn,
|
|
1178
|
+
control: h(Switch, {
|
|
1179
|
+
on: tlOn,
|
|
1180
|
+
onClick: function () { patchOptions({ toolListEnabled: !tlOn }) }
|
|
1181
|
+
})
|
|
1182
|
+
}),
|
|
1183
|
+
h(OptionRow, {
|
|
1184
|
+
label: tr('opt.tlRefresh'),
|
|
1185
|
+
desc: refresh === 'realtime' ? tr('opt.tlRefresh.realtimeDesc') : tr('opt.tlRefresh.newDesc'),
|
|
1186
|
+
control: h(Select, {
|
|
1187
|
+
value: refresh,
|
|
1188
|
+
options: [['newSession', tr('opt.tlRefresh.newSession')], ['realtime', tr('opt.tlRefresh.realtime')]],
|
|
1189
|
+
disabled: !tlOn,
|
|
1190
|
+
onChange: function (v) { patchOptions({ toolListRefresh: v === 'realtime' ? 'realtime' : 'newSession' }) }
|
|
1191
|
+
})
|
|
1192
|
+
}),
|
|
1193
|
+
// 「自动回顾」在「回顾注入」这一类里面,排在「回顾注入」这一项之前(0.3.11)。
|
|
1194
|
+
h('div', { style: Object.assign({}, S.optGroup, S.groupHead) },
|
|
1195
|
+
h('span', { style: S.groupTitle }, tr('opt.group.inject')),
|
|
1196
|
+
h(HelpDot, { text: tr('help.injectGroup') })
|
|
1197
|
+
),
|
|
1198
|
+
h(OptionRow, {
|
|
1199
|
+
label: tr('opt.auto'),
|
|
1200
|
+
desc: autoOn ? tr('opt.auto.desc') : tr('opt.auto.off'),
|
|
1201
|
+
descStyle: autoOn ? null : S.optDescWarn,
|
|
1202
|
+
control: h(Switch, {
|
|
1203
|
+
on: autoOn,
|
|
1204
|
+
onClick: function () { patchOptions({ autoReviewEnabled: !autoOn }) }
|
|
1205
|
+
})
|
|
1206
|
+
}),
|
|
1207
|
+
h('div', { style: tailDim },
|
|
1208
|
+
h(OptionRow, {
|
|
1209
|
+
label: tr('opt.inject'),
|
|
1210
|
+
desc: injectOn ? tr('opt.inject.desc') : tr('opt.inject.offDesc'),
|
|
1211
|
+
descStyle: injectOn ? null : S.optDescWarn,
|
|
1212
|
+
control: h(Switch, {
|
|
1213
|
+
on: injectOn,
|
|
1214
|
+
disabled: !autoOn,
|
|
1215
|
+
onClick: function () { patchOptions({ injectEnabled: !injectOn }) }
|
|
1216
|
+
})
|
|
1217
|
+
}),
|
|
1218
|
+
h('div', { style: belowDim },
|
|
1219
|
+
h('div', { style: S.optGroup }, tr('opt.group.content')),
|
|
1220
|
+
h(OptionRow, {
|
|
1221
|
+
label: tr('opt.fullLoad'),
|
|
1222
|
+
desc: o.fullLoad ? tr('opt.fullLoad.warn') : tr('opt.fullLoad.desc'),
|
|
1223
|
+
descStyle: o.fullLoad ? S.optDescWarn : null,
|
|
1224
|
+
control: h(Switch, {
|
|
1225
|
+
on: o.fullLoad,
|
|
1226
|
+
disabled: locked,
|
|
1227
|
+
onClick: function () { patchOptions({ fullLoad: !o.fullLoad }) }
|
|
1228
|
+
})
|
|
1229
|
+
}),
|
|
1230
|
+
h(OptionRow, {
|
|
1231
|
+
label: tr('opt.reminder'),
|
|
1232
|
+
desc: o.reminderChannel === 'system'
|
|
1233
|
+
? tr('opt.reminder.systemDesc')
|
|
1234
|
+
: tr('opt.reminder.contextDesc'),
|
|
1235
|
+
control: h(Select, {
|
|
1236
|
+
value: o.reminderChannel,
|
|
1237
|
+
options: [['context', tr('opt.reminder.context')], ['system', tr('opt.reminder.system')]],
|
|
1238
|
+
disabled: locked,
|
|
1239
|
+
onChange: function (v) { patchOptions({ reminderChannel: v }) }
|
|
1240
|
+
})
|
|
1241
|
+
}),
|
|
1242
|
+
h('div', { style: S.optGroup }, tr('opt.group.depth')),
|
|
1243
|
+
h(OptionRow, {
|
|
1244
|
+
label: tr('opt.stop'),
|
|
1245
|
+
desc: tr('opt.stop.desc'),
|
|
1246
|
+
control: h(Switch, {
|
|
1247
|
+
on: o.stopLowering,
|
|
1248
|
+
disabled: locked,
|
|
1249
|
+
onClick: function () { patchOptions({ stopLowering: !o.stopLowering }) }
|
|
1250
|
+
})
|
|
1251
|
+
}),
|
|
1252
|
+
h(OptionRow, {
|
|
1253
|
+
label: tr('opt.loadLevel'),
|
|
1254
|
+
desc: (o.stopLowering
|
|
1255
|
+
? tr('opt.loadLevel.off')
|
|
1256
|
+
: tr('opt.loadLevel.desc'))
|
|
1257
|
+
+ (levelNow === 'follow' ? '' : tr('opt.loadLevel.now', levelNow)),
|
|
1258
|
+
control: h(Select, {
|
|
1259
|
+
value: levelNow,
|
|
1260
|
+
options: levelOptions,
|
|
1261
|
+
disabled: locked || o.stopLowering,
|
|
1262
|
+
onChange: function (v) { patchOptions({ loadLevel: v === 'follow' ? 'follow' : Number(v) }) }
|
|
1263
|
+
})
|
|
1264
|
+
})
|
|
1265
|
+
) // 「回顾内容」「回顾深度」两组(belowDim)
|
|
1266
|
+
), // 「回顾注入」这一类:自动回顾 + 回顾注入 + 下面两组
|
|
1267
|
+
h('div', { style: S.note }, tr('opt.note'))
|
|
1268
|
+
)
|
|
1269
|
+
}
|
|
1270
|
+
|
|
1271
|
+
var head = h('div', { style: S.head },
|
|
1272
|
+
h('div', { style: S.h1 }, tr('app.title'))
|
|
1273
|
+
)
|
|
1274
|
+
|
|
1275
|
+
// 0.3.10:「自创工具」提到第一个位置,打开设置页先落这一页。
|
|
1276
|
+
var tabs = h('div', { style: S.tabs },
|
|
1277
|
+
h('button', { style: tab === 'toolList' ? S.tabOn : S.tab, onClick: function () { setTab('toolList') } }, tr('tab.toolList')),
|
|
1278
|
+
h('button', { style: tab === 'sessions' ? S.tabOn : S.tab, onClick: function () { setTab('sessions') } }, tr('tab.sessions')),
|
|
1279
|
+
h('button', { style: tab === 'memory' ? S.tabOn : S.tab, onClick: function () { setTab('memory') } }, tr('tab.memory')),
|
|
1280
|
+
h('button', { style: tab === 'options' ? S.tabOn : S.tab, onClick: function () { setTab('options') } }, tr('tab.options'))
|
|
1281
|
+
)
|
|
1282
|
+
|
|
1283
|
+
var body = null
|
|
1284
|
+
if (data.loading) body = h('div', { style: S.note }, tr('loading.first'))
|
|
1285
|
+
else if (data.error) body = h('div', { style: S.err }, data.error)
|
|
1286
|
+
else if (tab === 'toolList') body = toolListView()
|
|
1287
|
+
else if (tab === 'options') body = optionsView()
|
|
1288
|
+
else if (data.workspaces.length === 0) body = h('div', { style: S.note }, tr('empty.sessions'))
|
|
1289
|
+
else if (tab === 'sessions') {
|
|
1290
|
+
// E3:有会话读不出标题时,列表顶部明说原因;别让「空会话」冒充结论。
|
|
1291
|
+
var noZstd = false
|
|
1292
|
+
for (var nz = 0; nz < data.workspaces.length; nz++) {
|
|
1293
|
+
if (data.workspaces[nz].sessions.some(function (x) { return x.digestCode === 'no-zstd' })) { noZstd = true; break }
|
|
1294
|
+
}
|
|
1295
|
+
body = h('div', null,
|
|
1296
|
+
noZstd ? h('div', { style: S.note }, tr('digest.noZstd')) : null,
|
|
1297
|
+
data.workspaces.map(function (ws) {
|
|
1298
|
+
if (ws.sessions.length === 0) return null
|
|
1299
|
+
var ac = ws.sessions.filter(function (x) { return x.archived }).length
|
|
1300
|
+
return h('div', { key: ws.cwd },
|
|
1301
|
+
h('div', { style: S.ws }, ws.cwd + (ac > 0 ? tr('ws.archived', ac) : '')),
|
|
1302
|
+
h('div', { className: 'recall-scroll', style: S.list }, ws.sessions.map(function (sess) {
|
|
1303
|
+
var on = selected && selected.id === sess.id
|
|
1304
|
+
return h(Row, {
|
|
1305
|
+
key: sess.id, title: sess.id, on: on, archived: sess.archived,
|
|
1306
|
+
onClick: function () { setSelected({ id: sess.id, cwd: ws.cwd }); setConfirming(''); setNote('') }
|
|
1307
|
+
},
|
|
1308
|
+
h('span', { style: on ? S.dotOn : S.dot }),
|
|
1309
|
+
h('span', { style: Object.assign({}, S.title, sess.hasTitle ? {} : S.muted) }, sess.title),
|
|
1310
|
+
sess.archived ? h('span', { style: S.badge }, tr('badge.archived')) : null
|
|
1311
|
+
)
|
|
1312
|
+
}))
|
|
1313
|
+
)
|
|
1314
|
+
}))
|
|
1315
|
+
} else {
|
|
1316
|
+
if (!wsForMem || wsForMem.memories.length === 0) {
|
|
1317
|
+
body = h('div', null,
|
|
1318
|
+
h('div', { style: S.ws }, memCwd !== '' ? memCwd : tr('ws.unknown')),
|
|
1319
|
+
h('div', { style: S.note }, tr('empty.memories'))
|
|
1320
|
+
)
|
|
1321
|
+
} else {
|
|
1322
|
+
// 日历高亮和列表显示都用本地日期:compactedAt 是 UTC,直接切前 10 位在
|
|
1323
|
+
// 北京时间会差一天(00:55 压的记在昨天那一格)。
|
|
1324
|
+
var dayOf = function (m) { return ymd(new Date(m.compactedAt)) }
|
|
1325
|
+
var dates = {}
|
|
1326
|
+
wsForMem.memories.forEach(function (m) { dates[dayOf(m)] = true })
|
|
1327
|
+
var info = loadInfo && loadInfo.cwd === wsForMem.cwd ? loadInfo : null
|
|
1328
|
+
// 选区生效时,列表只留区间内的条目(按同一个本地日期比较)。
|
|
1329
|
+
var ranged = range !== null && range.from !== null && range.from !== undefined
|
|
1330
|
+
var shown = info === null ? [] : info.entries.filter(function (e) {
|
|
1331
|
+
if (!ranged) return true
|
|
1332
|
+
var d = dayOf(e)
|
|
1333
|
+
return d >= range.from && d <= range.to
|
|
1334
|
+
})
|
|
1335
|
+
// 载入框两种状态:没选回顾看整段注入;选了只看那一条(跟注入同一套 renderEntry)。
|
|
1336
|
+
// 注入总开关关掉时框里明说「没有注入」,不拿旧文本冒充(0.2.8)。
|
|
1337
|
+
var pickKey = wsForMem.cwd + '\u0000' + (memPick || '')
|
|
1338
|
+
var picked = memPick && pickInfo && pickInfo.key === pickKey ? pickInfo : null
|
|
1339
|
+
var boxText = ''
|
|
1340
|
+
if (!memPick) {
|
|
1341
|
+
boxText = info ? (info.disabled ? tr('box.injectOff') : (info.text || tr('box.none'))) : ''
|
|
1342
|
+
} else if (picked) {
|
|
1343
|
+
boxText = picked.disabled ? tr('box.injectOff')
|
|
1344
|
+
: (picked.error ? tr('box.err', picked.error) : (picked.text || tr('box.noContent')))
|
|
1345
|
+
}
|
|
1346
|
+
var headText = tr('head.base')
|
|
1347
|
+
if (memPick) headText += tr('head.pick', shortId(memPick), picked ? picked.chars : 0, !picked)
|
|
1348
|
+
else if (info) headText += tr('head.all', info.entries.length, info.chars,
|
|
1349
|
+
info.loadForced && info.entries.length > 0 ? info.entries[0].level : null)
|
|
1350
|
+
body = h('div', { style: { display: 'flex', flexDirection: 'column', gap: 10 } },
|
|
1351
|
+
h('div', { style: S.ws }, tr('ws.count', wsForMem.cwd, wsForMem.memories.length, ranged, shown.length)),
|
|
1352
|
+
h(Calendar, {
|
|
1353
|
+
dates: dates,
|
|
1354
|
+
range: range,
|
|
1355
|
+
initial: new Date(wsForMem.memories[0].compactedAt),
|
|
1356
|
+
onPick: pickDay,
|
|
1357
|
+
onClear: function () { setRange(null) }
|
|
1358
|
+
}),
|
|
1359
|
+
h('div', { style: S.disc },
|
|
1360
|
+
h('button', {
|
|
1361
|
+
style: S.discBtn,
|
|
1362
|
+
onClick: function () {
|
|
1363
|
+
// 选中了某条时,点列表头先回到「全部」,不收起 —— 收起就看不到内容了。
|
|
1364
|
+
if (memPick) { setMemPick(null); setMemConfirm(''); setNote(''); if (!open) setOpen(true); return }
|
|
1365
|
+
setOpen(!open)
|
|
1366
|
+
}
|
|
1367
|
+
},
|
|
1368
|
+
h('span', { style: S.caret }, open ? '▾' : '▸'),
|
|
1369
|
+
h('span', { style: { flex: 1, textAlign: 'left' } }, headText)
|
|
1370
|
+
)
|
|
1371
|
+
),
|
|
1372
|
+
open
|
|
1373
|
+
? (info === null
|
|
1374
|
+
? h('div', { style: S.note }, tr('loading'))
|
|
1375
|
+
: h('div', { style: { display: 'flex', flexDirection: 'column', gap: 8 } },
|
|
1376
|
+
h('div', { style: { display: 'flex', flexDirection: 'column', gap: 6 } },
|
|
1377
|
+
shown.map(function (e) {
|
|
1378
|
+
var picked = memPick === e.file
|
|
1379
|
+
return h(Row, {
|
|
1380
|
+
key: e.file, title: e.file, on: picked,
|
|
1381
|
+
onClick: function () { setMemPick(e.file); setMemConfirm(''); setNote('') }
|
|
1382
|
+
},
|
|
1383
|
+
h('span', { style: picked ? S.dotOn : S.dot }),
|
|
1384
|
+
h('span', { style: { fontSize: 12, opacity: 0.72, flex: '0 0 auto' } }, ymd(new Date(e.compactedAt))),
|
|
1385
|
+
h('span', { style: e.loadForced ? S.chipForced : (e.pinned ? S.chipLocked : S.chip) },
|
|
1386
|
+
tr('chip.depth', e.level, e.loadForced, e.pinned)),
|
|
1387
|
+
h('span', { style: Object.assign({}, S.title, S.muted) }, shortId(e.file))
|
|
1388
|
+
)
|
|
1389
|
+
})
|
|
1390
|
+
),
|
|
1391
|
+
ranged && shown.length === 0
|
|
1392
|
+
? h('div', { style: S.note }, tr('range.empty', range.from, range.to))
|
|
1393
|
+
: null,
|
|
1394
|
+
h('div', { className: 'recall-scroll', style: S.preWide }, memPick && !picked ? tr('loading') : boxText),
|
|
1395
|
+
h('div', { style: { display: 'flex', justifyContent: 'flex-end' } },
|
|
1396
|
+
h('button', {
|
|
1397
|
+
style: !memPick || isBusy ? S.btnOff : S.btnDanger,
|
|
1398
|
+
disabled: !memPick || isBusy,
|
|
1399
|
+
onClick: doMemDelete
|
|
1400
|
+
}, memConfirm ? tr('btn.confirm') : tr('btn.memDelete'))
|
|
1401
|
+
)
|
|
1402
|
+
))
|
|
1403
|
+
: null
|
|
1404
|
+
)
|
|
1405
|
+
}
|
|
1406
|
+
}
|
|
1407
|
+
|
|
1408
|
+
// 上次自动回顾失败(F6):回顾页顶部一行红字。
|
|
1409
|
+
// 以前失败只落日志,用户看到的是「一份看起来完全正常、只是不再增长的列表」。
|
|
1410
|
+
if (tab === 'memory' && wsForMem && wsForMem.health && wsForMem.health.ok === false) {
|
|
1411
|
+
body = h('div', { style: { display: 'flex', flexDirection: 'column', gap: 8 } },
|
|
1412
|
+
h('div', { style: S.err }, tr('health.failed', dayTime(wsForMem.health.at), wsForMem.health.message || tr('health.failedTitle'))),
|
|
1413
|
+
body)
|
|
1414
|
+
}
|
|
1415
|
+
|
|
1416
|
+
var footer = tab === 'sessions' ? h('div', { style: S.footer },
|
|
1417
|
+
h('button', { style: !selected || isBusy ? S.btnOff : S.btnDanger, disabled: !selected || isBusy, onClick: doDelete },
|
|
1418
|
+
confirming === 'delete' ? tr('btn.confirm') : tr('btn.delete')),
|
|
1419
|
+
h('button', { style: !selected || isBusy ? S.btnOff : S.btn, disabled: !selected || isBusy, onClick: doCompactDelete },
|
|
1420
|
+
confirming === 'compact' ? tr('btn.confirmCompact') : tr('btn.deleteCompact'))
|
|
1421
|
+
) : null
|
|
1422
|
+
|
|
1423
|
+
// 会话、回顾两页内容可能很长,仍走 .recall-scroll;选项页只四行,不要滚动框。
|
|
1424
|
+
// 0.4.3:自创工具页多了导入/导出一块,整页不再保证一屏装得下,跟着一起滚。
|
|
1425
|
+
var pageBox = tab === 'options'
|
|
1426
|
+
? h('div', { style: S.pageFlat }, body)
|
|
1427
|
+
: h('div', { className: 'recall-scroll', style: S.page }, body)
|
|
1428
|
+
|
|
1429
|
+
// E1:宿主能力不全时,在每页顶部都说清缺了什么、哪块被关了。
|
|
1430
|
+
var missingCaps = data.capabilities && data.capabilities.ok === false
|
|
1431
|
+
&& Array.isArray(data.capabilities.missing) ? data.capabilities.missing : []
|
|
1432
|
+
var capWarn = missingCaps.length > 0
|
|
1433
|
+
? h('div', { style: S.err }, tr('host.degraded', missingCaps.map(function (m) { return m.block }).join(', ')))
|
|
1434
|
+
: null
|
|
1435
|
+
|
|
1436
|
+
return h('div', { style: S.wrap },
|
|
1437
|
+
head, tabs, capWarn, pageBox, footer,
|
|
1438
|
+
note[0] ? h('div', { style: S.note }, note[0]) : null,
|
|
1439
|
+
err[0] ? h('div', { style: S.err }, err[0]) : null
|
|
1440
|
+
)
|
|
1441
|
+
}
|
|
1442
|
+
|
|
1443
|
+
// 'locale' 必须写进依赖:DSH 按依赖注入服务,只有声明了才会把 ctx.locale 交给插件。
|
|
1444
|
+
var inject = ['slots', 'locale']
|
|
1445
|
+
|
|
1446
|
+
function apply(ctx) {
|
|
1447
|
+
ensureScrollCss()
|
|
1448
|
+
bindSessions(ctx)
|
|
1449
|
+
watchLocale(ctx)
|
|
1450
|
+
ctx.slots.inject('settings.section', function () {
|
|
1451
|
+
return ctx.slots.register({
|
|
1452
|
+
name: 'settings.section',
|
|
1453
|
+
id: NS,
|
|
1454
|
+
order: 32,
|
|
1455
|
+
// 导航里的名字:每次投影现读,切语言后跟着变。
|
|
1456
|
+
label: function () { syncLangFromService(); return tr('app.title') }
|
|
1457
|
+
}, Section)
|
|
1458
|
+
})
|
|
1459
|
+
}
|
|
1460
|
+
|
|
1461
|
+
exports.apply = apply
|
|
1462
|
+
exports.inject = inject
|
|
1463
|
+
return module.exports
|
|
1464
|
+
}
|
|
1465
|
+
})
|