@fish-under-sea/magpie-purge 0.4.1 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/package.json +1 -1
- package/page/app.js +81 -30
- package/preview/catalog.demo.js +10 -1
- package/preview/host.html +3 -2
- package/preview/purge-preview.html +91 -30
package/README.md
CHANGED
|
@@ -336,6 +336,7 @@ node tools/scan.mjs --json
|
|
|
336
336
|
|
|
337
337
|
| 版本 | 要点 |
|
|
338
338
|
| --- | --- |
|
|
339
|
+
| `0.4.2` | 状态条不再按过期判定劝人(改完模式还劝「用 replace」);修「页面导入」条目没有删除按钮、被当素材 |
|
|
339
340
|
| `0.4.1` | 修「选完模式又被换回」「确认注入点了没用」;导入区改成「选择 → 再点导入」两步并可选人设/技能;去掉来源目录与自动扫描,只扫包内与 `state/imports` |
|
|
340
341
|
| `0.4.0` | 底座人设 `大肥鱼` 取代 Prompt Forge:不绑定任务,0–9 位专家随意组合;默认不再读上游 `state.json`(要读设 `useAgentPurge:true`);默认来源只剩 `~/.magpie/purge`;模式下拉去掉「跟随上游」 |
|
|
341
342
|
| `0.3.0` | 内置 9 位专家技能包(由本机 `dsh-purge` 的 23 份原子技能提炼);内置条目带「内置」标、可停用不可删 |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fish-under-sea/magpie-purge",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"description": "magpie-purge: a magpie page plugin that treats a local purge folder as a free plugin/skill source, inspects and validates what is in it, and rewrites the gateway's system prompt by mode (off / strict / replace / append).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
package/page/app.js
CHANGED
|
@@ -96,7 +96,35 @@
|
|
|
96
96
|
|
|
97
97
|
const entries = () => (Array.isArray(catalog?.entries) ? catalog.entries : [])
|
|
98
98
|
const inlineEntries = () => (Array.isArray(options.inline) ? options.inline : [])
|
|
99
|
-
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* shaped 给「页面导入」的条目补齐其它条目都有的字段。
|
|
102
|
+
*
|
|
103
|
+
* 列表与检查器必须看同一份形状:之前只有列表补了,检查器拿到的是裸对象,
|
|
104
|
+
* 于是 source 缺失 → 认不出是 inline → 不给删除按钮、还把它当素材。
|
|
105
|
+
*/
|
|
106
|
+
const shaped = (e) => ({
|
|
107
|
+
...e,
|
|
108
|
+
status: 'ok',
|
|
109
|
+
reason: '',
|
|
110
|
+
source: { rel: '页面导入(options)', root: 'inline' },
|
|
111
|
+
size: 0,
|
|
112
|
+
meta: { format: 'inline', description: '从「导入」里挑进来的文件,正文存在插件的 options 里。' },
|
|
113
|
+
version: e.version ?? 1,
|
|
114
|
+
importedAt: 0,
|
|
115
|
+
chars: String(e.text || '').length,
|
|
116
|
+
injectable: true,
|
|
117
|
+
builtin: false,
|
|
118
|
+
digest: e.digest || '',
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
// findEntry 统一走 shaped:检查器与列表必须看到同一份对象,否则判定会打架。
|
|
122
|
+
const findEntry = (id) =>
|
|
123
|
+
entries().find((e) => e.id === id) ||
|
|
124
|
+
(() => {
|
|
125
|
+
const hit = inlineEntries().find((e) => e.id === id)
|
|
126
|
+
return hit ? shaped(hit) : null
|
|
127
|
+
})()
|
|
100
128
|
const isEnabled = (id) => (options.enabled?.[id] !== undefined ? options.enabled[id] : findEntry(id)?.kind === 'persona')
|
|
101
129
|
/** defaultPersona 是「现在最能顶上的人设」:内置底座优先,其次第一个可用的人设。 */
|
|
102
130
|
const defaultPersona = () =>
|
|
@@ -165,17 +193,7 @@
|
|
|
165
193
|
inlineEntries()
|
|
166
194
|
.filter((e) => (filter ? e.kind === filter : true))
|
|
167
195
|
.filter((e) => (q ? `${e.name} ${e.id}`.toLowerCase().includes(q) : true))
|
|
168
|
-
.map(
|
|
169
|
-
...e,
|
|
170
|
-
status: 'ok',
|
|
171
|
-
source: { rel: '页面导入(options)', root: 'inline' },
|
|
172
|
-
size: 0,
|
|
173
|
-
meta: { format: 'inline', description: '' },
|
|
174
|
-
version: 1,
|
|
175
|
-
chars: String(e.text || '').length,
|
|
176
|
-
injectable: true,
|
|
177
|
-
digest: '',
|
|
178
|
-
})),
|
|
196
|
+
.map(shaped),
|
|
179
197
|
)
|
|
180
198
|
}
|
|
181
199
|
|
|
@@ -187,7 +205,7 @@
|
|
|
187
205
|
return
|
|
188
206
|
}
|
|
189
207
|
if (!rows.length) {
|
|
190
|
-
host.replaceChildren(el('p', { class: 'empty', text: '
|
|
208
|
+
host.replaceChildren(el('p', { class: 'empty', text: '没有匹配的条目。清掉搜索,或导入一份文件再来。' }))
|
|
191
209
|
return
|
|
192
210
|
}
|
|
193
211
|
// 分组比逐行挂「内置」胶囊干净:内置是「这一整组都随包来」,说一次就够。
|
|
@@ -544,8 +562,8 @@
|
|
|
544
562
|
const n = entries().length
|
|
545
563
|
host.replaceChildren(el('li', {
|
|
546
564
|
text: n
|
|
547
|
-
? '
|
|
548
|
-
: '
|
|
565
|
+
? '没有拒绝项:现在这些文件都认得出来。'
|
|
566
|
+
: '还没有扫描结果:导入一份文件,或点一下「导入」区里的按钮触发重扫。',
|
|
549
567
|
}))
|
|
550
568
|
return
|
|
551
569
|
}
|
|
@@ -603,9 +621,23 @@
|
|
|
603
621
|
return '还没选模式:请求原样放行。选一个(比如 replace)才开始注入。'
|
|
604
622
|
}
|
|
605
623
|
|
|
624
|
+
/**
|
|
625
|
+
* planStale 判断「快照里的判定」是否已经跟不上本地设置了。
|
|
626
|
+
*
|
|
627
|
+
* 只比这两件会直接改变结论的事:模式与生效的人设。比完就知道该不该按旧结论劝人。
|
|
628
|
+
*/
|
|
629
|
+
function planStale(plan) {
|
|
630
|
+
if (!plan) return false
|
|
631
|
+
const localMode = MODES().includes(options.mode) ? options.mode : ''
|
|
632
|
+
if (localMode && localMode !== plan.mode) return true
|
|
633
|
+
const localPersona = typeof options.persona === 'string' ? options.persona.trim() : ''
|
|
634
|
+
if (localPersona && localPersona !== plan.personaId) return true
|
|
635
|
+
return false
|
|
636
|
+
}
|
|
637
|
+
|
|
606
638
|
/**
|
|
607
639
|
* renderPlan 是「现在到底注不注、注谁、为什么没注」那一行。
|
|
608
|
-
* 判定由后端算好放在快照的 plan
|
|
640
|
+
* 判定由后端算好放在快照的 plan 里(页面不能读磁盘)。
|
|
609
641
|
*/
|
|
610
642
|
function renderPlan() {
|
|
611
643
|
const host = $('plan')
|
|
@@ -619,6 +651,10 @@
|
|
|
619
651
|
return
|
|
620
652
|
}
|
|
621
653
|
const ready = Boolean(plan.ready)
|
|
654
|
+
// plan 是后端上一次扫描算出来的;本地刚改过设置时它就过期了。
|
|
655
|
+
// 状态条左边说「已选 append」、右边却还在劝「用 replace 开始注入」,
|
|
656
|
+
// 就是因为胶囊读本地、按钮读快照。这里先认出来,过期就别再按旧的劝。
|
|
657
|
+
const stale = planStale(plan)
|
|
622
658
|
// personaFrom 的三种来源,用户一眼要能看懂「谁在顶着」:
|
|
623
659
|
// page = 自己点的、auto = 底座人设自动顶上、default = agent-purge(仅在显式开启时)
|
|
624
660
|
const fromText = { page: '本页设置', auto: '底座人设(没选人设时自动顶上)', default: '默认' }
|
|
@@ -631,10 +667,13 @@
|
|
|
631
667
|
save({ ...patch, refreshAt: Date.now() }, note)
|
|
632
668
|
pollSnapshot('等后端按新设置重扫…', 25)
|
|
633
669
|
}
|
|
670
|
+
// 本地已经选好模式时,绝不再劝「用 replace 开始注入」——
|
|
671
|
+
// 那正是图一里「写着 append、旁边却叫你换成 replace」的自相矛盾。
|
|
672
|
+
const localMode = MODES().includes(options.mode) ? options.mode : ''
|
|
673
|
+
if (!ready && !localMode) {
|
|
674
|
+
fix.push(el('button', { type: 'button', class: 'primary', onclick: () => fixed({ mode: 'replace' }, '模式改为 replace') }, '用 replace 开始注入'))
|
|
675
|
+
}
|
|
634
676
|
if (!ready) {
|
|
635
|
-
if (plan.blockedCode === 'no-mode' || plan.blockedCode === 'mode-off') {
|
|
636
|
-
fix.push(el('button', { type: 'button', class: 'primary', onclick: () => fixed({ mode: 'replace' }, '模式改为 replace') }, '用 replace 开始注入'))
|
|
637
|
-
}
|
|
638
677
|
// 旧人设被删掉后 options.persona 会一直指着它,卡在 persona-missing:
|
|
639
678
|
// 这个问题点「去看人设」永远绕不出来,得给一个直接改掉它的动作。
|
|
640
679
|
if (plan.blockedCode === 'persona-missing' && defaultPersona()) {
|
|
@@ -645,13 +684,13 @@
|
|
|
645
684
|
onclick: () => fixed({ persona: next.id }, `人设改为「${next.name}」`),
|
|
646
685
|
}, `改用「${next.name}」`))
|
|
647
686
|
}
|
|
648
|
-
if (plan.blockedCode === 'no-persona' || plan.blockedCode === 'persona-missing') {
|
|
687
|
+
if (!stale && (plan.blockedCode === 'no-persona' || plan.blockedCode === 'persona-missing')) {
|
|
649
688
|
fix.push(el('button', {
|
|
650
689
|
type: 'button',
|
|
651
690
|
onclick: () => { filter = 'persona'; query = ''; render() },
|
|
652
691
|
}, '去看人设'))
|
|
653
692
|
}
|
|
654
|
-
if (plan.blockedCode === 'no-persona-file') {
|
|
693
|
+
if (!stale && plan.blockedCode === 'no-persona-file') {
|
|
655
694
|
fix.push(el('button', {
|
|
656
695
|
type: 'button',
|
|
657
696
|
class: 'primary',
|
|
@@ -662,15 +701,23 @@
|
|
|
662
701
|
|
|
663
702
|
// 两行文字放进同一列:第一行是结论,第二行是依据;右边的胶囊组跨两行垂直居中。
|
|
664
703
|
// 原来「为什么」那行缩进 20px,看起来像挂件;现在两行左对齐,读起来是一段话。
|
|
704
|
+
// 过期时不复述旧结论:直接说「等重扫」,免得左边写 append、右边说「还没选模式」。
|
|
705
|
+
const who = stale
|
|
706
|
+
? '设置已改,等后端重扫确认'
|
|
707
|
+
: ready
|
|
708
|
+
? `下一次 agent 请求会注入「${plan.personaName || plan.personaId}」`
|
|
709
|
+
: '现在不会注入:请求原样放行'
|
|
710
|
+
const why = stale
|
|
711
|
+
? '刚改完模式或人设:下一次请求按新设置走,这里显示的是上一次扫描的判定'
|
|
712
|
+
: ready
|
|
713
|
+
? `人设来源:${fromText[plan.personaFrom] || plan.personaFrom}`
|
|
714
|
+
: plan.blocked
|
|
715
|
+
|
|
665
716
|
const rows = [
|
|
666
717
|
el('span', { class: 'dot' }),
|
|
667
718
|
el('span', { class: 'plan-text' },
|
|
668
|
-
el('span', { class: ready ? 'who' : 'who is-empty' },
|
|
669
|
-
|
|
670
|
-
: '现在不会注入:请求原样放行'),
|
|
671
|
-
el('span', { class: 'why', text: ready
|
|
672
|
-
? `人设来源:${fromText[plan.personaFrom] || plan.personaFrom}`
|
|
673
|
-
: plan.blocked }),
|
|
719
|
+
el('span', { class: ready && !stale ? 'who' : 'who is-empty' }, who),
|
|
720
|
+
el('span', { class: 'why', text: why }),
|
|
674
721
|
),
|
|
675
722
|
el('span', { class: 'plan-controls' },
|
|
676
723
|
modePill(),
|
|
@@ -778,9 +825,13 @@
|
|
|
778
825
|
* 签名一变,「已注入」自动退回「确认注入」。
|
|
779
826
|
*/
|
|
780
827
|
function confirmButton(plan) {
|
|
781
|
-
|
|
828
|
+
// 签名用「实际会生效的那一套」:刚改了模式但后端还没重扫时,plan 是旧的,
|
|
829
|
+
// 拿它算签名会让按钮继续显示「已注入」——那等于替一套还没生效的配置背书。
|
|
830
|
+
const mode = MODES().includes(options.mode) ? options.mode : plan.mode
|
|
831
|
+
const persona = (typeof options.persona === 'string' && options.persona.trim()) || plan.personaId || ''
|
|
832
|
+
const sig = `${mode}|${persona}`
|
|
782
833
|
const last = catalog?.last
|
|
783
|
-
const evidence = Boolean(last && !last.skipped && last.mode ===
|
|
834
|
+
const evidence = Boolean(last && !last.skipped && last.mode === mode && (last.persona || '') === persona)
|
|
784
835
|
const applied = evidence || confirmedSig === sig
|
|
785
836
|
return el('button', {
|
|
786
837
|
type: 'button',
|
|
@@ -826,7 +877,7 @@
|
|
|
826
877
|
return
|
|
827
878
|
}
|
|
828
879
|
if (Date.now() < until) setTimeout(tick, 1200)
|
|
829
|
-
else say('后端还没写出新快照:magpie
|
|
880
|
+
else say('后端还没写出新快照:magpie 里插件可能没重启,或它写不进自己的 state 目录。', 'bad')
|
|
830
881
|
}
|
|
831
882
|
script.onerror = () => {
|
|
832
883
|
script.remove()
|
package/preview/catalog.demo.js
CHANGED
|
@@ -161,4 +161,13 @@ window.PURGE_CATALOG = {
|
|
|
161
161
|
// 不加这个参数时,演示快照里 last 与 plan 对得上,按钮直接是「已注入」。
|
|
162
162
|
if (new URLSearchParams(location.search).get('unsent') === '1') {
|
|
163
163
|
window.PURGE_CATALOG.last = null
|
|
164
|
-
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// 预览开关:?inline=1 造一条「页面导入」的条目,用来看那条路径的检查器
|
|
167
|
+
// (它有「删除导入」「改判」两个按钮,不导入就看不到)。
|
|
168
|
+
if (new URLSearchParams(location.search).get('inline') === '1') {
|
|
169
|
+
window.PURGE_CATALOG.options = {
|
|
170
|
+
...window.PURGE_CATALOG.options,
|
|
171
|
+
inline: [{ id: 'mine', name: '我的技能', kind: 'skill', text: '这是从页面导入的正文。\n\n## 用法\n\n点一下就来。\n' }],
|
|
172
|
+
}
|
|
173
|
+
}
|
package/preview/host.html
CHANGED
|
@@ -38,8 +38,9 @@
|
|
|
38
38
|
// 把预览用的开关一起转给业务页:unsent=1 抹掉「最近一次生效」,
|
|
39
39
|
// 好看「确认注入」还没按下的那副样子。
|
|
40
40
|
const pass = new URLSearchParams({ theme })
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
for (const flag of ['unsent', 'menu', 'inline']) {
|
|
42
|
+
if (new URLSearchParams(location.search).get(flag) === '1') pass.set(flag, '1')
|
|
43
|
+
}
|
|
43
44
|
frame.src = `/page/index.html?${pass}`
|
|
44
45
|
document.getElementById('mode').textContent = `预览:mock 宿主 · ${theme === 'light' ? '浅色' : '深色'}`
|
|
45
46
|
// 默认不选任何条目:右栏默认就是「注入组装」,那是最该看的一屏。
|
|
@@ -238,6 +238,16 @@ window.__PURGE_READY__ = {
|
|
|
238
238
|
if (new URLSearchParams(location.search).get('unsent') === '1') {
|
|
239
239
|
window.__PURGE_READY__.last = null
|
|
240
240
|
}
|
|
241
|
+
|
|
242
|
+
// 预览开关:?inline=1 造一条「页面导入」的条目,用来看那条路径的检查器
|
|
243
|
+
// (它有「删除导入」「改判」两个按钮,不导入就看不到)。
|
|
244
|
+
if (new URLSearchParams(location.search).get('inline') === '1') {
|
|
245
|
+
window.__PURGE_READY__.options = {
|
|
246
|
+
...window.__PURGE_READY__.options,
|
|
247
|
+
inline: [{ id: 'mine', name: '我的技能', kind: 'skill', text: '这是从页面导入的正文。\n\n## 用法\n\n点一下就来。\n' }],
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
241
251
|
</script>
|
|
242
252
|
<script>
|
|
243
253
|
// 演示快照(没就绪的那种):只有素材、没人设、模式也没选。
|
|
@@ -1144,7 +1154,35 @@ pre.text {
|
|
|
1144
1154
|
|
|
1145
1155
|
const entries = () => (Array.isArray(catalog?.entries) ? catalog.entries : [])
|
|
1146
1156
|
const inlineEntries = () => (Array.isArray(options.inline) ? options.inline : [])
|
|
1147
|
-
|
|
1157
|
+
|
|
1158
|
+
/**
|
|
1159
|
+
* shaped 给「页面导入」的条目补齐其它条目都有的字段。
|
|
1160
|
+
*
|
|
1161
|
+
* 列表与检查器必须看同一份形状:之前只有列表补了,检查器拿到的是裸对象,
|
|
1162
|
+
* 于是 source 缺失 → 认不出是 inline → 不给删除按钮、还把它当素材。
|
|
1163
|
+
*/
|
|
1164
|
+
const shaped = (e) => ({
|
|
1165
|
+
...e,
|
|
1166
|
+
status: 'ok',
|
|
1167
|
+
reason: '',
|
|
1168
|
+
source: { rel: '页面导入(options)', root: 'inline' },
|
|
1169
|
+
size: 0,
|
|
1170
|
+
meta: { format: 'inline', description: '从「导入」里挑进来的文件,正文存在插件的 options 里。' },
|
|
1171
|
+
version: e.version ?? 1,
|
|
1172
|
+
importedAt: 0,
|
|
1173
|
+
chars: String(e.text || '').length,
|
|
1174
|
+
injectable: true,
|
|
1175
|
+
builtin: false,
|
|
1176
|
+
digest: e.digest || '',
|
|
1177
|
+
})
|
|
1178
|
+
|
|
1179
|
+
// findEntry 统一走 shaped:检查器与列表必须看到同一份对象,否则判定会打架。
|
|
1180
|
+
const findEntry = (id) =>
|
|
1181
|
+
entries().find((e) => e.id === id) ||
|
|
1182
|
+
(() => {
|
|
1183
|
+
const hit = inlineEntries().find((e) => e.id === id)
|
|
1184
|
+
return hit ? shaped(hit) : null
|
|
1185
|
+
})()
|
|
1148
1186
|
const isEnabled = (id) => (options.enabled?.[id] !== undefined ? options.enabled[id] : findEntry(id)?.kind === 'persona')
|
|
1149
1187
|
/** defaultPersona 是「现在最能顶上的人设」:内置底座优先,其次第一个可用的人设。 */
|
|
1150
1188
|
const defaultPersona = () =>
|
|
@@ -1213,17 +1251,7 @@ pre.text {
|
|
|
1213
1251
|
inlineEntries()
|
|
1214
1252
|
.filter((e) => (filter ? e.kind === filter : true))
|
|
1215
1253
|
.filter((e) => (q ? `${e.name} ${e.id}`.toLowerCase().includes(q) : true))
|
|
1216
|
-
.map(
|
|
1217
|
-
...e,
|
|
1218
|
-
status: 'ok',
|
|
1219
|
-
source: { rel: '页面导入(options)', root: 'inline' },
|
|
1220
|
-
size: 0,
|
|
1221
|
-
meta: { format: 'inline', description: '' },
|
|
1222
|
-
version: 1,
|
|
1223
|
-
chars: String(e.text || '').length,
|
|
1224
|
-
injectable: true,
|
|
1225
|
-
digest: '',
|
|
1226
|
-
})),
|
|
1254
|
+
.map(shaped),
|
|
1227
1255
|
)
|
|
1228
1256
|
}
|
|
1229
1257
|
|
|
@@ -1235,7 +1263,7 @@ pre.text {
|
|
|
1235
1263
|
return
|
|
1236
1264
|
}
|
|
1237
1265
|
if (!rows.length) {
|
|
1238
|
-
host.replaceChildren(el('p', { class: 'empty', text: '
|
|
1266
|
+
host.replaceChildren(el('p', { class: 'empty', text: '没有匹配的条目。清掉搜索,或导入一份文件再来。' }))
|
|
1239
1267
|
return
|
|
1240
1268
|
}
|
|
1241
1269
|
// 分组比逐行挂「内置」胶囊干净:内置是「这一整组都随包来」,说一次就够。
|
|
@@ -1592,8 +1620,8 @@ pre.text {
|
|
|
1592
1620
|
const n = entries().length
|
|
1593
1621
|
host.replaceChildren(el('li', {
|
|
1594
1622
|
text: n
|
|
1595
|
-
? '
|
|
1596
|
-
: '
|
|
1623
|
+
? '没有拒绝项:现在这些文件都认得出来。'
|
|
1624
|
+
: '还没有扫描结果:导入一份文件,或点一下「导入」区里的按钮触发重扫。',
|
|
1597
1625
|
}))
|
|
1598
1626
|
return
|
|
1599
1627
|
}
|
|
@@ -1651,9 +1679,23 @@ pre.text {
|
|
|
1651
1679
|
return '还没选模式:请求原样放行。选一个(比如 replace)才开始注入。'
|
|
1652
1680
|
}
|
|
1653
1681
|
|
|
1682
|
+
/**
|
|
1683
|
+
* planStale 判断「快照里的判定」是否已经跟不上本地设置了。
|
|
1684
|
+
*
|
|
1685
|
+
* 只比这两件会直接改变结论的事:模式与生效的人设。比完就知道该不该按旧结论劝人。
|
|
1686
|
+
*/
|
|
1687
|
+
function planStale(plan) {
|
|
1688
|
+
if (!plan) return false
|
|
1689
|
+
const localMode = MODES().includes(options.mode) ? options.mode : ''
|
|
1690
|
+
if (localMode && localMode !== plan.mode) return true
|
|
1691
|
+
const localPersona = typeof options.persona === 'string' ? options.persona.trim() : ''
|
|
1692
|
+
if (localPersona && localPersona !== plan.personaId) return true
|
|
1693
|
+
return false
|
|
1694
|
+
}
|
|
1695
|
+
|
|
1654
1696
|
/**
|
|
1655
1697
|
* renderPlan 是「现在到底注不注、注谁、为什么没注」那一行。
|
|
1656
|
-
* 判定由后端算好放在快照的 plan
|
|
1698
|
+
* 判定由后端算好放在快照的 plan 里(页面不能读磁盘)。
|
|
1657
1699
|
*/
|
|
1658
1700
|
function renderPlan() {
|
|
1659
1701
|
const host = $('plan')
|
|
@@ -1667,6 +1709,10 @@ pre.text {
|
|
|
1667
1709
|
return
|
|
1668
1710
|
}
|
|
1669
1711
|
const ready = Boolean(plan.ready)
|
|
1712
|
+
// plan 是后端上一次扫描算出来的;本地刚改过设置时它就过期了。
|
|
1713
|
+
// 状态条左边说「已选 append」、右边却还在劝「用 replace 开始注入」,
|
|
1714
|
+
// 就是因为胶囊读本地、按钮读快照。这里先认出来,过期就别再按旧的劝。
|
|
1715
|
+
const stale = planStale(plan)
|
|
1670
1716
|
// personaFrom 的三种来源,用户一眼要能看懂「谁在顶着」:
|
|
1671
1717
|
// page = 自己点的、auto = 底座人设自动顶上、default = agent-purge(仅在显式开启时)
|
|
1672
1718
|
const fromText = { page: '本页设置', auto: '底座人设(没选人设时自动顶上)', default: '默认' }
|
|
@@ -1679,10 +1725,13 @@ pre.text {
|
|
|
1679
1725
|
save({ ...patch, refreshAt: Date.now() }, note)
|
|
1680
1726
|
pollSnapshot('等后端按新设置重扫…', 25)
|
|
1681
1727
|
}
|
|
1728
|
+
// 本地已经选好模式时,绝不再劝「用 replace 开始注入」——
|
|
1729
|
+
// 那正是图一里「写着 append、旁边却叫你换成 replace」的自相矛盾。
|
|
1730
|
+
const localMode = MODES().includes(options.mode) ? options.mode : ''
|
|
1731
|
+
if (!ready && !localMode) {
|
|
1732
|
+
fix.push(el('button', { type: 'button', class: 'primary', onclick: () => fixed({ mode: 'replace' }, '模式改为 replace') }, '用 replace 开始注入'))
|
|
1733
|
+
}
|
|
1682
1734
|
if (!ready) {
|
|
1683
|
-
if (plan.blockedCode === 'no-mode' || plan.blockedCode === 'mode-off') {
|
|
1684
|
-
fix.push(el('button', { type: 'button', class: 'primary', onclick: () => fixed({ mode: 'replace' }, '模式改为 replace') }, '用 replace 开始注入'))
|
|
1685
|
-
}
|
|
1686
1735
|
// 旧人设被删掉后 options.persona 会一直指着它,卡在 persona-missing:
|
|
1687
1736
|
// 这个问题点「去看人设」永远绕不出来,得给一个直接改掉它的动作。
|
|
1688
1737
|
if (plan.blockedCode === 'persona-missing' && defaultPersona()) {
|
|
@@ -1693,13 +1742,13 @@ pre.text {
|
|
|
1693
1742
|
onclick: () => fixed({ persona: next.id }, `人设改为「${next.name}」`),
|
|
1694
1743
|
}, `改用「${next.name}」`))
|
|
1695
1744
|
}
|
|
1696
|
-
if (plan.blockedCode === 'no-persona' || plan.blockedCode === 'persona-missing') {
|
|
1745
|
+
if (!stale && (plan.blockedCode === 'no-persona' || plan.blockedCode === 'persona-missing')) {
|
|
1697
1746
|
fix.push(el('button', {
|
|
1698
1747
|
type: 'button',
|
|
1699
1748
|
onclick: () => { filter = 'persona'; query = ''; render() },
|
|
1700
1749
|
}, '去看人设'))
|
|
1701
1750
|
}
|
|
1702
|
-
if (plan.blockedCode === 'no-persona-file') {
|
|
1751
|
+
if (!stale && plan.blockedCode === 'no-persona-file') {
|
|
1703
1752
|
fix.push(el('button', {
|
|
1704
1753
|
type: 'button',
|
|
1705
1754
|
class: 'primary',
|
|
@@ -1710,15 +1759,23 @@ pre.text {
|
|
|
1710
1759
|
|
|
1711
1760
|
// 两行文字放进同一列:第一行是结论,第二行是依据;右边的胶囊组跨两行垂直居中。
|
|
1712
1761
|
// 原来「为什么」那行缩进 20px,看起来像挂件;现在两行左对齐,读起来是一段话。
|
|
1762
|
+
// 过期时不复述旧结论:直接说「等重扫」,免得左边写 append、右边说「还没选模式」。
|
|
1763
|
+
const who = stale
|
|
1764
|
+
? '设置已改,等后端重扫确认'
|
|
1765
|
+
: ready
|
|
1766
|
+
? `下一次 agent 请求会注入「${plan.personaName || plan.personaId}」`
|
|
1767
|
+
: '现在不会注入:请求原样放行'
|
|
1768
|
+
const why = stale
|
|
1769
|
+
? '刚改完模式或人设:下一次请求按新设置走,这里显示的是上一次扫描的判定'
|
|
1770
|
+
: ready
|
|
1771
|
+
? `人设来源:${fromText[plan.personaFrom] || plan.personaFrom}`
|
|
1772
|
+
: plan.blocked
|
|
1773
|
+
|
|
1713
1774
|
const rows = [
|
|
1714
1775
|
el('span', { class: 'dot' }),
|
|
1715
1776
|
el('span', { class: 'plan-text' },
|
|
1716
|
-
el('span', { class: ready ? 'who' : 'who is-empty' },
|
|
1717
|
-
|
|
1718
|
-
: '现在不会注入:请求原样放行'),
|
|
1719
|
-
el('span', { class: 'why', text: ready
|
|
1720
|
-
? `人设来源:${fromText[plan.personaFrom] || plan.personaFrom}`
|
|
1721
|
-
: plan.blocked }),
|
|
1777
|
+
el('span', { class: ready && !stale ? 'who' : 'who is-empty' }, who),
|
|
1778
|
+
el('span', { class: 'why', text: why }),
|
|
1722
1779
|
),
|
|
1723
1780
|
el('span', { class: 'plan-controls' },
|
|
1724
1781
|
modePill(),
|
|
@@ -1826,9 +1883,13 @@ pre.text {
|
|
|
1826
1883
|
* 签名一变,「已注入」自动退回「确认注入」。
|
|
1827
1884
|
*/
|
|
1828
1885
|
function confirmButton(plan) {
|
|
1829
|
-
|
|
1886
|
+
// 签名用「实际会生效的那一套」:刚改了模式但后端还没重扫时,plan 是旧的,
|
|
1887
|
+
// 拿它算签名会让按钮继续显示「已注入」——那等于替一套还没生效的配置背书。
|
|
1888
|
+
const mode = MODES().includes(options.mode) ? options.mode : plan.mode
|
|
1889
|
+
const persona = (typeof options.persona === 'string' && options.persona.trim()) || plan.personaId || ''
|
|
1890
|
+
const sig = `${mode}|${persona}`
|
|
1830
1891
|
const last = catalog?.last
|
|
1831
|
-
const evidence = Boolean(last && !last.skipped && last.mode ===
|
|
1892
|
+
const evidence = Boolean(last && !last.skipped && last.mode === mode && (last.persona || '') === persona)
|
|
1832
1893
|
const applied = evidence || confirmedSig === sig
|
|
1833
1894
|
return el('button', {
|
|
1834
1895
|
type: 'button',
|
|
@@ -1874,7 +1935,7 @@ pre.text {
|
|
|
1874
1935
|
return
|
|
1875
1936
|
}
|
|
1876
1937
|
if (Date.now() < until) setTimeout(tick, 1200)
|
|
1877
|
-
else say('后端还没写出新快照:magpie
|
|
1938
|
+
else say('后端还没写出新快照:magpie 里插件可能没重启,或它写不进自己的 state 目录。', 'bad')
|
|
1878
1939
|
}
|
|
1879
1940
|
script.onerror = () => {
|
|
1880
1941
|
script.remove()
|