@fish-under-sea/magpie-purge 0.4.1 → 0.4.3

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 CHANGED
@@ -336,6 +336,8 @@ node tools/scan.mjs --json
336
336
 
337
337
  | 版本 | 要点 |
338
338
  | --- | --- |
339
+ | `0.4.3` | 判定改由页面本地计算:技能开关、装配面板、状态条改完立刻生效,不再等后端重扫;左栏跟随右栏等高;专家开关带复选框与计数 |
340
+ | `0.4.2` | 状态条不再按过期判定劝人(改完模式还劝「用 replace」);修「页面导入」条目没有删除按钮、被当素材 |
339
341
  | `0.4.1` | 修「选完模式又被换回」「确认注入点了没用」;导入区改成「选择 → 再点导入」两步并可选人设/技能;去掉来源目录与自动扫描,只扫包内与 `state/imports` |
340
342
  | `0.4.0` | 底座人设 `大肥鱼` 取代 Prompt Forge:不绑定任务,0–9 位专家随意组合;默认不再读上游 `state.json`(要读设 `useAgentPurge:true`);默认来源只剩 `~/.magpie/purge`;模式下拉去掉「跟随上游」 |
341
343
  | `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.1",
3
+ "version": "0.4.3",
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
- const findEntry = (id) => entries().find((e) => e.id === id) || inlineEntries().find((e) => e.id === id) || null
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((e) => ({
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
  // 分组比逐行挂「内置」胶囊干净:内置是「这一整组都随包来」,说一次就够。
@@ -246,7 +264,7 @@
246
264
  */
247
265
  function renderAssembly() {
248
266
  const host = $('assembly')
249
- const plan = catalog?.plan
267
+ const plan = currentPlan()
250
268
  const last = catalog?.last
251
269
  if (!plan) {
252
270
  host.replaceChildren(el('h2', {}, '注入组装'))
@@ -295,14 +313,15 @@
295
313
 
296
314
  /**
297
315
  * renderExpertPicker 是「一键启用专家」:这里是每天重复最多的动作。
298
- * 不用逐条点开再点启用——九个专家的开关摊在同一行,点一下就切。
316
+ * 不用逐条点开再点启用——专家的开关摊在同一片区域,点一下就切。
299
317
  * 只列技能:人设是「谁来写」,走另一条路(详情里的「设为当前人设」)。
300
318
  */
301
319
  function renderExpertPicker() {
302
- const skills = entries().filter((e) => e.injectable && e.kind === 'skill' && e.builtin)
320
+ const builtin = entries().filter((e) => e.injectable && e.kind === 'skill' && e.builtin)
303
321
  const mine = entries().filter((e) => e.injectable && e.kind === 'skill' && !e.builtin)
304
- const all = [...skills, ...mine]
322
+ const all = [...builtin, ...mine]
305
323
  if (!all.length) return null
324
+
306
325
  const chip = (e) => {
307
326
  const on = isEnabled(e.id)
308
327
  return el('button', {
@@ -311,12 +330,31 @@
311
330
  'aria-pressed': on ? 'true' : 'false',
312
331
  title: on ? `停用「${e.name}」` : `启用「${e.name}」`,
313
332
  onclick: () => save({ enabled: { ...(options.enabled || {}), [e.id]: !on } }, on ? `已停用「${e.name}」` : `已启用「${e.name}」`),
314
- }, on ? '✓ ' : '', e.name)
333
+ },
334
+ el('span', { class: 'pick-mark', 'aria-hidden': 'true' }),
335
+ el('span', { class: 'pick-name', text: e.name }),
336
+ el('span', { class: 'pick-size', text: `${e.chars || 0}` }),
337
+ )
315
338
  }
339
+
340
+ const onCount = all.filter((e) => isEnabled(e.id)).length
341
+ // 分组只在真的有「我的」时才显示:只有内置时还分两栏,等于白占一行。
342
+ const groups = [
343
+ mine.length ? { label: '内置', rows: builtin } : null,
344
+ mine.length ? { label: '我的来源', rows: mine } : null,
345
+ mine.length ? null : { label: '', rows: all },
346
+ ].filter(Boolean)
347
+
316
348
  return el('section', { class: 'picker', 'aria-label': '启用专家' },
317
- el('h3', {}, '启用的专家',
318
- el('span', { class: 'h2-sub', text: '点一下即生效,不必逐条打开' })),
319
- el('div', { class: 'picks' }, ...all.map(chip)),
349
+ el('h3', {},
350
+ el('span', { text: '启用的专家' }),
351
+ el('span', { class: 'picker-count', text: `${onCount} / ${all.length}` }),
352
+ el('span', { class: 'h2-sub', text: '点一下即生效' }),
353
+ ),
354
+ ...groups.map((g) => el('div', { class: 'pick-group' },
355
+ g.label ? el('span', { class: 'pick-group-label', text: g.label }) : null,
356
+ el('div', { class: 'picks' }, ...g.rows.map(chip)),
357
+ )),
320
358
  )
321
359
  }
322
360
 
@@ -544,8 +582,8 @@
544
582
  const n = entries().length
545
583
  host.replaceChildren(el('li', {
546
584
  text: n
547
- ? '没有拒绝项:来源目录里每个文件都认得出来。'
548
- : '还没有扫描结果。先确认来源目录里放了东西,再点右上角「重新扫描」。',
585
+ ? '没有拒绝项:现在这些文件都认得出来。'
586
+ : '还没有扫描结果:导入一份文件,或点一下「导入」区里的按钮触发重扫。',
549
587
  }))
550
588
  return
551
589
  }
@@ -603,13 +641,45 @@
603
641
  return '还没选模式:请求原样放行。选一个(比如 replace)才开始注入。'
604
642
  }
605
643
 
644
+ /**
645
+ * planStale 判断「快照里的判定」是否已经跟不上本地设置了。
646
+ *
647
+ * 只比这两件会直接改变结论的事:模式与生效的人设。比完就知道该不该按旧结论劝人。
648
+ */
649
+ function planStale(plan) {
650
+ if (!plan) return false
651
+ const localMode = MODES().includes(options.mode) ? options.mode : ''
652
+ if (localMode && localMode !== plan.mode) return true
653
+ const localPersona = typeof options.persona === 'string' ? options.persona.trim() : ''
654
+ if (localPersona && localPersona !== plan.personaId) return true
655
+ return false
656
+ }
657
+
658
+ /**
659
+ * currentPlan 是「现在这套设置会让网关怎么做」。
660
+ *
661
+ * 优先本地算:后端只在有请求经过时才重扫写快照,不动 agent 的话快照永远旧,
662
+ * 技能开关、装配面板、状态条就全都停在改之前的样子。
663
+ * 只有 useAgentPurge 打开时才不得不用快照——state.json 只有后端读得到。
664
+ */
665
+ function currentPlan() {
666
+ if (options.useAgentPurge === true) return catalog?.plan || null
667
+ const api = globalThis.PurgePlan
668
+ if (!api) return catalog?.plan || null
669
+ const usable = [...entries(), ...inlineEntries().map(shaped)]
670
+ .filter((e) => e.status === 'ok' && e.injectable && typeof e.text === 'string' && e.text.trim())
671
+ return api.resolve({ options, entries: usable })
672
+ }
673
+
606
674
  /**
607
675
  * renderPlan 是「现在到底注不注、注谁、为什么没注」那一行。
608
- * 判定由后端算好放在快照的 plan 里(页面不能读 agent-purge 的 state.json)。
676
+ *
677
+ * 判定用 currentPlan():本地算,所以改完设置立刻反映,不用等后端重扫。
678
+ * 快照里的 plan 只在 useAgentPurge 打开时才用得上(state.json 只有后端读得到)。
609
679
  */
610
680
  function renderPlan() {
611
681
  const host = $('plan')
612
- const plan = catalog?.plan
682
+ const plan = currentPlan()
613
683
  if (!plan) {
614
684
  host.dataset.state = 'idle'
615
685
  host.replaceChildren(
@@ -619,6 +689,9 @@
619
689
  return
620
690
  }
621
691
  const ready = Boolean(plan.ready)
692
+ // 判定已经是本地的了,正常情况下不会过期;留这条只在 useAgentPurge 模式下生效,
693
+ // 那种模式页面算不了,只能拿快照,仍可能出现「刚改完还没重扫」的短暂不一致。
694
+ const stale = planStale(plan)
622
695
  // personaFrom 的三种来源,用户一眼要能看懂「谁在顶着」:
623
696
  // page = 自己点的、auto = 底座人设自动顶上、default = agent-purge(仅在显式开启时)
624
697
  const fromText = { page: '本页设置', auto: '底座人设(没选人设时自动顶上)', default: '默认' }
@@ -631,10 +704,13 @@
631
704
  save({ ...patch, refreshAt: Date.now() }, note)
632
705
  pollSnapshot('等后端按新设置重扫…', 25)
633
706
  }
707
+ // 本地已经选好模式时,绝不再劝「用 replace 开始注入」——
708
+ // 那正是图一里「写着 append、旁边却叫你换成 replace」的自相矛盾。
709
+ const localMode = MODES().includes(options.mode) ? options.mode : ''
710
+ if (!ready && !localMode) {
711
+ fix.push(el('button', { type: 'button', class: 'primary', onclick: () => fixed({ mode: 'replace' }, '模式改为 replace') }, '用 replace 开始注入'))
712
+ }
634
713
  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
714
  // 旧人设被删掉后 options.persona 会一直指着它,卡在 persona-missing:
639
715
  // 这个问题点「去看人设」永远绕不出来,得给一个直接改掉它的动作。
640
716
  if (plan.blockedCode === 'persona-missing' && defaultPersona()) {
@@ -645,13 +721,13 @@
645
721
  onclick: () => fixed({ persona: next.id }, `人设改为「${next.name}」`),
646
722
  }, `改用「${next.name}」`))
647
723
  }
648
- if (plan.blockedCode === 'no-persona' || plan.blockedCode === 'persona-missing') {
724
+ if (!stale && (plan.blockedCode === 'no-persona' || plan.blockedCode === 'persona-missing')) {
649
725
  fix.push(el('button', {
650
726
  type: 'button',
651
727
  onclick: () => { filter = 'persona'; query = ''; render() },
652
728
  }, '去看人设'))
653
729
  }
654
- if (plan.blockedCode === 'no-persona-file') {
730
+ if (!stale && plan.blockedCode === 'no-persona-file') {
655
731
  fix.push(el('button', {
656
732
  type: 'button',
657
733
  class: 'primary',
@@ -662,15 +738,23 @@
662
738
 
663
739
  // 两行文字放进同一列:第一行是结论,第二行是依据;右边的胶囊组跨两行垂直居中。
664
740
  // 原来「为什么」那行缩进 20px,看起来像挂件;现在两行左对齐,读起来是一段话。
741
+ // 过期时不复述旧结论:直接说「等重扫」,免得左边写 append、右边说「还没选模式」。
742
+ const who = stale
743
+ ? '设置已改,等后端重扫确认'
744
+ : ready
745
+ ? `下一次 agent 请求会注入「${plan.personaName || plan.personaId}」`
746
+ : '现在不会注入:请求原样放行'
747
+ const why = stale
748
+ ? '刚改完模式或人设:下一次请求按新设置走,这里显示的是上一次扫描的判定'
749
+ : ready
750
+ ? `人设来源:${fromText[plan.personaFrom] || plan.personaFrom}`
751
+ : plan.blocked
752
+
665
753
  const rows = [
666
754
  el('span', { class: 'dot' }),
667
755
  el('span', { class: 'plan-text' },
668
- el('span', { class: ready ? 'who' : 'who is-empty' }, ready
669
- ? `下一次 agent 请求会注入「${plan.personaName || plan.personaId}」`
670
- : '现在不会注入:请求原样放行'),
671
- el('span', { class: 'why', text: ready
672
- ? `人设来源:${fromText[plan.personaFrom] || plan.personaFrom}`
673
- : plan.blocked }),
756
+ el('span', { class: ready && !stale ? 'who' : 'who is-empty' }, who),
757
+ el('span', { class: 'why', text: why }),
674
758
  ),
675
759
  el('span', { class: 'plan-controls' },
676
760
  modePill(),
@@ -778,9 +862,13 @@
778
862
  * 签名一变,「已注入」自动退回「确认注入」。
779
863
  */
780
864
  function confirmButton(plan) {
781
- const sig = `${plan.mode}|${plan.personaId || ''}`
865
+ // 签名用「实际会生效的那一套」:刚改了模式但后端还没重扫时,plan 是旧的,
866
+ // 拿它算签名会让按钮继续显示「已注入」——那等于替一套还没生效的配置背书。
867
+ const mode = MODES().includes(options.mode) ? options.mode : plan.mode
868
+ const persona = (typeof options.persona === 'string' && options.persona.trim()) || plan.personaId || ''
869
+ const sig = `${mode}|${persona}`
782
870
  const last = catalog?.last
783
- const evidence = Boolean(last && !last.skipped && last.mode === plan.mode && (last.persona || '') === (plan.personaId || ''))
871
+ const evidence = Boolean(last && !last.skipped && last.mode === mode && (last.persona || '') === persona)
784
872
  const applied = evidence || confirmedSig === sig
785
873
  return el('button', {
786
874
  type: 'button',
@@ -826,7 +914,7 @@
826
914
  return
827
915
  }
828
916
  if (Date.now() < until) setTimeout(tick, 1200)
829
- else say('后端还没写出新快照:magpie 里插件可能没重启,或来源目录没权限。', 'bad')
917
+ else say('后端还没写出新快照:magpie 里插件可能没重启,或它写不进自己的 state 目录。', 'bad')
830
918
  }
831
919
  script.onerror = () => {
832
920
  script.remove()
package/page/index.html CHANGED
@@ -6,6 +6,7 @@
6
6
  <title>破甲 · Purge</title>
7
7
  <script src="_magpie/bridge.js"></script>
8
8
  <script src="catalog.js"></script>
9
+ <script src="plan.js"></script>
9
10
  <link rel="stylesheet" href="style.css">
10
11
  <script src="app.js" defer></script>
11
12
  </head>
package/page/plan.js ADDED
@@ -0,0 +1,102 @@
1
+ // 页面侧的「这次到底注不注入」判定。
2
+ //
3
+ // 为什么页面要自己算一遍:后端只在有请求经过网关时才重扫并写快照。
4
+ // 用户在页面上改完模式/人设/技能,只要还没发起 agent 请求,快照就一直是旧的——
5
+ // 状态条说「等重扫」、点技能看着没反应、装配面板空着,全是这一件事引起的。
6
+ //
7
+ // 这里的规则必须与 lib/plan.mjs 一致(Node 侧用它决定真改不改请求)。
8
+ // 两边不同步的话,页面会答应一件网关不会做的事——所以 tests/plan-parity.test.mjs
9
+ // 拿同一批输入分别跑两边,逐个比结果。
10
+ //
11
+ // 与 lib/plan.mjs 的唯一差别:这里不含 agent-purge 那一层。
12
+ // 页面读不到 state.json,useAgentPurge 打开时由调用方改用快照里的 plan。
13
+ ;(() => {
14
+ const MODES = ['off', 'strict', 'replace', 'append']
15
+
16
+ const blank = (modeFrom, mode, blocked, blockedCode) => ({
17
+ mode: mode || 'off',
18
+ modeFrom,
19
+ personaId: '',
20
+ personaName: '',
21
+ personaFrom: '',
22
+ skills: [],
23
+ blocked,
24
+ blockedCode: blockedCode || '',
25
+ ready: false,
26
+ missingPersona: '',
27
+ })
28
+
29
+ /** resolve 与 lib/plan.mjs 同语义:页面设置优先,人设优先标了 default 的底座人设。 */
30
+ function resolve({ options = {}, entries = [] } = {}) {
31
+ const pageMode = MODES.includes(options.mode) ? options.mode : ''
32
+ const mode = pageMode || 'off'
33
+ const modeFrom = pageMode ? 'page' : 'default'
34
+ if (mode === 'off') {
35
+ return {
36
+ ...blank(modeFrom, mode, '', modeFrom === 'default' ? 'no-mode' : 'mode-off'),
37
+ blocked: modeFrom === 'default'
38
+ ? '还没选模式:模式是 off,请求原样放行。选一个模式(比如 replace)就开始注入'
39
+ : '当前模式是 off,请求原样放行',
40
+ }
41
+ }
42
+
43
+ const byId = new Map()
44
+ for (const e of entries) if (e && typeof e.id === 'string' && !byId.has(e.id)) byId.set(e.id, e)
45
+ const personas = entries.filter((e) => e.kind === 'persona')
46
+
47
+ let personaId = ''
48
+ let personaFrom = ''
49
+ let missingPersona = ''
50
+ const pagePersona = typeof options.persona === 'string' ? options.persona.trim() : ''
51
+ if (pagePersona && byId.has(pagePersona)) {
52
+ personaId = pagePersona
53
+ personaFrom = 'page'
54
+ } else if (pagePersona) {
55
+ missingPersona = pagePersona
56
+ } else {
57
+ const fallback =
58
+ personas.find((e) => e.default === true && options.enabled?.[e.id] !== false) ||
59
+ personas.find((e) => e.builtin !== true && options.enabled?.[e.id] !== false)
60
+ if (fallback) {
61
+ personaId = fallback.id
62
+ personaFrom = 'auto'
63
+ }
64
+ }
65
+
66
+ if (!personaId) {
67
+ if (missingPersona) {
68
+ const names = personas.slice(0, 4).map((e) => e.name || e.id).join('、')
69
+ return {
70
+ ...blank(modeFrom, mode, '', 'persona-missing'),
71
+ blocked: names
72
+ ? `指定的「${missingPersona}」已经不在了:现在可用的有 ${names}${personas.length > 4 ? ' 等' : ''}`
73
+ : `指定的「${missingPersona}」已经不在了,来源里也还没有其它人设`,
74
+ missingPersona,
75
+ }
76
+ }
77
+ const why = personas.length
78
+ ? '还没有选人设:左边挑一条「人设」点"设为当前人设"'
79
+ : '来源里还没有人设(.md):导入一份试试'
80
+ return { ...blank(modeFrom, mode, '', personas.length ? 'no-persona' : 'no-persona-file'), blocked: why }
81
+ }
82
+
83
+ const persona = byId.get(personaId)
84
+ const skills = entries
85
+ .filter((e) => e.kind !== 'persona' && options.enabled?.[e.id] === true)
86
+ .map((e) => ({ id: e.id, name: e.name, text: e.text }))
87
+
88
+ return {
89
+ mode,
90
+ modeFrom,
91
+ personaId,
92
+ personaName: persona?.name || personaId,
93
+ personaFrom,
94
+ skills,
95
+ blocked: '',
96
+ blockedCode: '',
97
+ ready: true,
98
+ }
99
+ }
100
+
101
+ globalThis.PurgePlan = { resolve, MODES }
102
+ })()
package/page/style.css CHANGED
@@ -238,15 +238,18 @@ textarea { width: 100%; resize: vertical; font-family: var(--mono); font-size: 1
238
238
  .seg-action.is-applied:hover { background: color-mix(in oklab, var(--ok) 20%, transparent); }
239
239
 
240
240
  /* ---------- 主体:左列表 / 右组装 ---------- */
241
+ /* stretch 让左栏跟右栏等高:右边展开原文后会变很高,左栏若按自己内容收着,
242
+ 底下就是一大片空白。 */
241
243
  .work {
242
244
  display: grid;
243
245
  grid-template-columns: minmax(300px, 352px) minmax(0, 1fr);
244
246
  gap: 26px;
245
- align-items: start;
247
+ align-items: stretch;
246
248
  }
247
- @media (max-width: 900px) { .work { grid-template-columns: minmax(0, 1fr); } }
249
+ @media (max-width: 900px) { .work { grid-template-columns: minmax(0, 1fr); align-items: start; } }
248
250
 
249
- .rail { min-width: 0; }
251
+ /* 左栏自己纵向排布,列表吃掉剩余高度 */
252
+ .rail { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
250
253
  .rail-tools { display: grid; gap: 10px; }
251
254
  .rail-tools input { width: 100%; }
252
255
  .chips { display: flex; flex-wrap: wrap; gap: 8px; }
@@ -263,16 +266,19 @@ textarea { width: 100%; resize: vertical; font-family: var(--mono); font-size: 1
263
266
  .rail-count { margin: 12px 0 8px; color: var(--muted); font-size: 12px; }
264
267
 
265
268
  .list { display: grid; gap: 1px; border-top: 1px solid var(--line); }
266
- /* 桌面端列表自己滚:条目多时不让整页跟着长,右栏也不会剩一大片空白。
269
+ /* 桌面端列表自己滚,并且跟着右栏拉长:右栏展开原文后会很高,
270
+ 列表若固定 540px 就留一大片空白。给一个下限,免得条目少时它缩成一条。
267
271
  窄屏不做嵌套滚动——那比页面滚动难用。
268
272
  底部加一层淡出:滚动区硬切会把最后一行切成半截,看起来像坏了。 */
269
273
  @media (min-width: 901px) {
270
274
  .list {
271
- max-height: min(58vh, 540px);
275
+ flex: 1 1 auto;
276
+ min-height: min(58vh, 540px);
272
277
  overflow-y: auto;
273
278
  overscroll-behavior: contain;
274
279
  padding-bottom: 4px;
275
280
  mask-image: linear-gradient(to bottom, #000 calc(100% - 20px), transparent);
281
+ align-content: start;
276
282
  }
277
283
  .list:has(> .row:last-child:first-child) { mask-image: none; }
278
284
  }
@@ -400,10 +406,12 @@ textarea { width: 100%; resize: vertical; font-family: var(--mono); font-size: 1
400
406
  font-variant-numeric: tabular-nums;
401
407
  }
402
408
 
403
- /* 一键启用:把九个专家的开关摊平,点一下即生效 */
409
+ /* 一键启用:把专家的开关摊平,点一下即生效。
410
+ 芯片自带一个小方框(未选是空心,选中是实心带勾)——只靠文字颜色区分,
411
+ 一片 chip 里哪几个开着要一行行读,方框扫一眼就有答案。 */
404
412
  .picker { margin-top: 28px; }
405
413
  .picker h3 {
406
- margin: 0 0 10px;
414
+ margin: 0 0 12px;
407
415
  font-size: 13px;
408
416
  font-weight: 560;
409
417
  display: flex;
@@ -411,22 +419,71 @@ textarea { width: 100%; resize: vertical; font-family: var(--mono); font-size: 1
411
419
  gap: 10px;
412
420
  flex-wrap: wrap;
413
421
  }
414
- .picks { display: flex; flex-wrap: wrap; gap: 8px; }
422
+ .picker-count {
423
+ color: var(--muted);
424
+ font-size: 12px;
425
+ font-variant-numeric: tabular-nums;
426
+ font-weight: 400;
427
+ }
428
+ .picker h3 .h2-sub { margin-left: auto; }
429
+
430
+ .pick-group { display: grid; gap: 6px; }
431
+ .pick-group + .pick-group { margin-top: 10px; }
432
+ .pick-group-label {
433
+ color: var(--muted);
434
+ font-size: 12px;
435
+ letter-spacing: .02em;
436
+ }
437
+
438
+ .picks { display: flex; flex-wrap: wrap; gap: 7px; }
415
439
  .pick {
440
+ display: inline-flex;
441
+ align-items: center;
442
+ gap: 7px;
416
443
  font-size: 12.5px;
417
- padding: 4px 12px;
418
- min-height: 28px;
444
+ padding: 4px 11px 4px 9px;
445
+ min-height: 30px;
419
446
  border-radius: 999px;
420
447
  border: 1px solid var(--line);
421
448
  background: transparent;
422
449
  color: var(--muted);
450
+ transition: border-color .12s ease, background-color .12s ease, color .12s ease;
423
451
  }
424
- .pick:hover:not(:disabled) { color: var(--ink); }
452
+ .pick:hover { color: var(--ink); border-color: color-mix(in oklab, var(--muted) 55%, var(--line)); }
425
453
  .pick.is-on {
426
454
  background: color-mix(in oklab, var(--kind-skill) 14%, transparent);
427
455
  border-color: color-mix(in oklab, var(--kind-skill) 45%, var(--line));
428
456
  color: var(--ink);
429
457
  }
458
+ /* 方框:未选空心,选中填色并显示勾 */
459
+ .pick-mark {
460
+ width: 13px;
461
+ height: 13px;
462
+ flex: none;
463
+ border-radius: 4px;
464
+ border: 1.5px solid color-mix(in oklab, var(--muted) 60%, var(--line));
465
+ position: relative;
466
+ }
467
+ .pick.is-on .pick-mark {
468
+ border-color: var(--kind-skill);
469
+ background: var(--kind-skill);
470
+ }
471
+ .pick.is-on .pick-mark::after {
472
+ content: "";
473
+ position: absolute;
474
+ left: 3.5px;
475
+ top: 1px;
476
+ width: 3.5px;
477
+ height: 7px;
478
+ border-right: 1.6px solid var(--bg);
479
+ border-bottom: 1.6px solid var(--bg);
480
+ transform: rotate(40deg);
481
+ }
482
+ .pick-size {
483
+ color: var(--muted);
484
+ font-size: 12px;
485
+ font-variant-numeric: tabular-nums;
486
+ }
430
487
 
431
488
  /* 详情
432
489
  拆成三块:头(是谁)、主体(主栏讲用处、侧栏放事实)、底(能做什么)。
@@ -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
- if (new URLSearchParams(location.search).get('unsent') === '1') pass.set('unsent', '1')
42
- if (new URLSearchParams(location.search).get('menu') === '1') pass.set('menu', '1')
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
  // 演示快照(没就绪的那种):只有素材、没人设、模式也没选。
@@ -297,6 +307,111 @@ window.__PURGE_BLOCKED__ = {
297
307
  window.PURGE_CATALOG = snap === 'blocked' ? window.__PURGE_BLOCKED__ : window.__PURGE_READY__
298
308
  window.__PURGE_PICK__ = pick
299
309
  })()
310
+ </script>
311
+ <script>
312
+ // 页面侧的「这次到底注不注入」判定。
313
+ //
314
+ // 为什么页面要自己算一遍:后端只在有请求经过网关时才重扫并写快照。
315
+ // 用户在页面上改完模式/人设/技能,只要还没发起 agent 请求,快照就一直是旧的——
316
+ // 状态条说「等重扫」、点技能看着没反应、装配面板空着,全是这一件事引起的。
317
+ //
318
+ // 这里的规则必须与 lib/plan.mjs 一致(Node 侧用它决定真改不改请求)。
319
+ // 两边不同步的话,页面会答应一件网关不会做的事——所以 tests/plan-parity.test.mjs
320
+ // 拿同一批输入分别跑两边,逐个比结果。
321
+ //
322
+ // 与 lib/plan.mjs 的唯一差别:这里不含 agent-purge 那一层。
323
+ // 页面读不到 state.json,useAgentPurge 打开时由调用方改用快照里的 plan。
324
+ ;(() => {
325
+ const MODES = ['off', 'strict', 'replace', 'append']
326
+
327
+ const blank = (modeFrom, mode, blocked, blockedCode) => ({
328
+ mode: mode || 'off',
329
+ modeFrom,
330
+ personaId: '',
331
+ personaName: '',
332
+ personaFrom: '',
333
+ skills: [],
334
+ blocked,
335
+ blockedCode: blockedCode || '',
336
+ ready: false,
337
+ missingPersona: '',
338
+ })
339
+
340
+ /** resolve 与 lib/plan.mjs 同语义:页面设置优先,人设优先标了 default 的底座人设。 */
341
+ function resolve({ options = {}, entries = [] } = {}) {
342
+ const pageMode = MODES.includes(options.mode) ? options.mode : ''
343
+ const mode = pageMode || 'off'
344
+ const modeFrom = pageMode ? 'page' : 'default'
345
+ if (mode === 'off') {
346
+ return {
347
+ ...blank(modeFrom, mode, '', modeFrom === 'default' ? 'no-mode' : 'mode-off'),
348
+ blocked: modeFrom === 'default'
349
+ ? '还没选模式:模式是 off,请求原样放行。选一个模式(比如 replace)就开始注入'
350
+ : '当前模式是 off,请求原样放行',
351
+ }
352
+ }
353
+
354
+ const byId = new Map()
355
+ for (const e of entries) if (e && typeof e.id === 'string' && !byId.has(e.id)) byId.set(e.id, e)
356
+ const personas = entries.filter((e) => e.kind === 'persona')
357
+
358
+ let personaId = ''
359
+ let personaFrom = ''
360
+ let missingPersona = ''
361
+ const pagePersona = typeof options.persona === 'string' ? options.persona.trim() : ''
362
+ if (pagePersona && byId.has(pagePersona)) {
363
+ personaId = pagePersona
364
+ personaFrom = 'page'
365
+ } else if (pagePersona) {
366
+ missingPersona = pagePersona
367
+ } else {
368
+ const fallback =
369
+ personas.find((e) => e.default === true && options.enabled?.[e.id] !== false) ||
370
+ personas.find((e) => e.builtin !== true && options.enabled?.[e.id] !== false)
371
+ if (fallback) {
372
+ personaId = fallback.id
373
+ personaFrom = 'auto'
374
+ }
375
+ }
376
+
377
+ if (!personaId) {
378
+ if (missingPersona) {
379
+ const names = personas.slice(0, 4).map((e) => e.name || e.id).join('、')
380
+ return {
381
+ ...blank(modeFrom, mode, '', 'persona-missing'),
382
+ blocked: names
383
+ ? `指定的「${missingPersona}」已经不在了:现在可用的有 ${names}${personas.length > 4 ? ' 等' : ''}`
384
+ : `指定的「${missingPersona}」已经不在了,来源里也还没有其它人设`,
385
+ missingPersona,
386
+ }
387
+ }
388
+ const why = personas.length
389
+ ? '还没有选人设:左边挑一条「人设」点"设为当前人设"'
390
+ : '来源里还没有人设(.md):导入一份试试'
391
+ return { ...blank(modeFrom, mode, '', personas.length ? 'no-persona' : 'no-persona-file'), blocked: why }
392
+ }
393
+
394
+ const persona = byId.get(personaId)
395
+ const skills = entries
396
+ .filter((e) => e.kind !== 'persona' && options.enabled?.[e.id] === true)
397
+ .map((e) => ({ id: e.id, name: e.name, text: e.text }))
398
+
399
+ return {
400
+ mode,
401
+ modeFrom,
402
+ personaId,
403
+ personaName: persona?.name || personaId,
404
+ personaFrom,
405
+ skills,
406
+ blocked: '',
407
+ blockedCode: '',
408
+ ready: true,
409
+ }
410
+ }
411
+
412
+ globalThis.PurgePlan = { resolve, MODES }
413
+ })()
414
+
300
415
  </script>
301
416
  <style>
302
417
  /* 破甲 · Purge 的页面样式。
@@ -539,15 +654,18 @@ textarea { width: 100%; resize: vertical; font-family: var(--mono); font-size: 1
539
654
  .seg-action.is-applied:hover { background: color-mix(in oklab, var(--ok) 20%, transparent); }
540
655
 
541
656
  /* ---------- 主体:左列表 / 右组装 ---------- */
657
+ /* stretch 让左栏跟右栏等高:右边展开原文后会变很高,左栏若按自己内容收着,
658
+ 底下就是一大片空白。 */
542
659
  .work {
543
660
  display: grid;
544
661
  grid-template-columns: minmax(300px, 352px) minmax(0, 1fr);
545
662
  gap: 26px;
546
- align-items: start;
663
+ align-items: stretch;
547
664
  }
548
- @media (max-width: 900px) { .work { grid-template-columns: minmax(0, 1fr); } }
665
+ @media (max-width: 900px) { .work { grid-template-columns: minmax(0, 1fr); align-items: start; } }
549
666
 
550
- .rail { min-width: 0; }
667
+ /* 左栏自己纵向排布,列表吃掉剩余高度 */
668
+ .rail { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
551
669
  .rail-tools { display: grid; gap: 10px; }
552
670
  .rail-tools input { width: 100%; }
553
671
  .chips { display: flex; flex-wrap: wrap; gap: 8px; }
@@ -564,16 +682,19 @@ textarea { width: 100%; resize: vertical; font-family: var(--mono); font-size: 1
564
682
  .rail-count { margin: 12px 0 8px; color: var(--muted); font-size: 12px; }
565
683
 
566
684
  .list { display: grid; gap: 1px; border-top: 1px solid var(--line); }
567
- /* 桌面端列表自己滚:条目多时不让整页跟着长,右栏也不会剩一大片空白。
685
+ /* 桌面端列表自己滚,并且跟着右栏拉长:右栏展开原文后会很高,
686
+ 列表若固定 540px 就留一大片空白。给一个下限,免得条目少时它缩成一条。
568
687
  窄屏不做嵌套滚动——那比页面滚动难用。
569
688
  底部加一层淡出:滚动区硬切会把最后一行切成半截,看起来像坏了。 */
570
689
  @media (min-width: 901px) {
571
690
  .list {
572
- max-height: min(58vh, 540px);
691
+ flex: 1 1 auto;
692
+ min-height: min(58vh, 540px);
573
693
  overflow-y: auto;
574
694
  overscroll-behavior: contain;
575
695
  padding-bottom: 4px;
576
696
  mask-image: linear-gradient(to bottom, #000 calc(100% - 20px), transparent);
697
+ align-content: start;
577
698
  }
578
699
  .list:has(> .row:last-child:first-child) { mask-image: none; }
579
700
  }
@@ -701,10 +822,12 @@ textarea { width: 100%; resize: vertical; font-family: var(--mono); font-size: 1
701
822
  font-variant-numeric: tabular-nums;
702
823
  }
703
824
 
704
- /* 一键启用:把九个专家的开关摊平,点一下即生效 */
825
+ /* 一键启用:把专家的开关摊平,点一下即生效。
826
+ 芯片自带一个小方框(未选是空心,选中是实心带勾)——只靠文字颜色区分,
827
+ 一片 chip 里哪几个开着要一行行读,方框扫一眼就有答案。 */
705
828
  .picker { margin-top: 28px; }
706
829
  .picker h3 {
707
- margin: 0 0 10px;
830
+ margin: 0 0 12px;
708
831
  font-size: 13px;
709
832
  font-weight: 560;
710
833
  display: flex;
@@ -712,22 +835,71 @@ textarea { width: 100%; resize: vertical; font-family: var(--mono); font-size: 1
712
835
  gap: 10px;
713
836
  flex-wrap: wrap;
714
837
  }
715
- .picks { display: flex; flex-wrap: wrap; gap: 8px; }
838
+ .picker-count {
839
+ color: var(--muted);
840
+ font-size: 12px;
841
+ font-variant-numeric: tabular-nums;
842
+ font-weight: 400;
843
+ }
844
+ .picker h3 .h2-sub { margin-left: auto; }
845
+
846
+ .pick-group { display: grid; gap: 6px; }
847
+ .pick-group + .pick-group { margin-top: 10px; }
848
+ .pick-group-label {
849
+ color: var(--muted);
850
+ font-size: 12px;
851
+ letter-spacing: .02em;
852
+ }
853
+
854
+ .picks { display: flex; flex-wrap: wrap; gap: 7px; }
716
855
  .pick {
856
+ display: inline-flex;
857
+ align-items: center;
858
+ gap: 7px;
717
859
  font-size: 12.5px;
718
- padding: 4px 12px;
719
- min-height: 28px;
860
+ padding: 4px 11px 4px 9px;
861
+ min-height: 30px;
720
862
  border-radius: 999px;
721
863
  border: 1px solid var(--line);
722
864
  background: transparent;
723
865
  color: var(--muted);
866
+ transition: border-color .12s ease, background-color .12s ease, color .12s ease;
724
867
  }
725
- .pick:hover:not(:disabled) { color: var(--ink); }
868
+ .pick:hover { color: var(--ink); border-color: color-mix(in oklab, var(--muted) 55%, var(--line)); }
726
869
  .pick.is-on {
727
870
  background: color-mix(in oklab, var(--kind-skill) 14%, transparent);
728
871
  border-color: color-mix(in oklab, var(--kind-skill) 45%, var(--line));
729
872
  color: var(--ink);
730
873
  }
874
+ /* 方框:未选空心,选中填色并显示勾 */
875
+ .pick-mark {
876
+ width: 13px;
877
+ height: 13px;
878
+ flex: none;
879
+ border-radius: 4px;
880
+ border: 1.5px solid color-mix(in oklab, var(--muted) 60%, var(--line));
881
+ position: relative;
882
+ }
883
+ .pick.is-on .pick-mark {
884
+ border-color: var(--kind-skill);
885
+ background: var(--kind-skill);
886
+ }
887
+ .pick.is-on .pick-mark::after {
888
+ content: "";
889
+ position: absolute;
890
+ left: 3.5px;
891
+ top: 1px;
892
+ width: 3.5px;
893
+ height: 7px;
894
+ border-right: 1.6px solid var(--bg);
895
+ border-bottom: 1.6px solid var(--bg);
896
+ transform: rotate(40deg);
897
+ }
898
+ .pick-size {
899
+ color: var(--muted);
900
+ font-size: 12px;
901
+ font-variant-numeric: tabular-nums;
902
+ }
731
903
 
732
904
  /* 详情
733
905
  拆成三块:头(是谁)、主体(主栏讲用处、侧栏放事实)、底(能做什么)。
@@ -1144,7 +1316,35 @@ pre.text {
1144
1316
 
1145
1317
  const entries = () => (Array.isArray(catalog?.entries) ? catalog.entries : [])
1146
1318
  const inlineEntries = () => (Array.isArray(options.inline) ? options.inline : [])
1147
- const findEntry = (id) => entries().find((e) => e.id === id) || inlineEntries().find((e) => e.id === id) || null
1319
+
1320
+ /**
1321
+ * shaped 给「页面导入」的条目补齐其它条目都有的字段。
1322
+ *
1323
+ * 列表与检查器必须看同一份形状:之前只有列表补了,检查器拿到的是裸对象,
1324
+ * 于是 source 缺失 → 认不出是 inline → 不给删除按钮、还把它当素材。
1325
+ */
1326
+ const shaped = (e) => ({
1327
+ ...e,
1328
+ status: 'ok',
1329
+ reason: '',
1330
+ source: { rel: '页面导入(options)', root: 'inline' },
1331
+ size: 0,
1332
+ meta: { format: 'inline', description: '从「导入」里挑进来的文件,正文存在插件的 options 里。' },
1333
+ version: e.version ?? 1,
1334
+ importedAt: 0,
1335
+ chars: String(e.text || '').length,
1336
+ injectable: true,
1337
+ builtin: false,
1338
+ digest: e.digest || '',
1339
+ })
1340
+
1341
+ // findEntry 统一走 shaped:检查器与列表必须看到同一份对象,否则判定会打架。
1342
+ const findEntry = (id) =>
1343
+ entries().find((e) => e.id === id) ||
1344
+ (() => {
1345
+ const hit = inlineEntries().find((e) => e.id === id)
1346
+ return hit ? shaped(hit) : null
1347
+ })()
1148
1348
  const isEnabled = (id) => (options.enabled?.[id] !== undefined ? options.enabled[id] : findEntry(id)?.kind === 'persona')
1149
1349
  /** defaultPersona 是「现在最能顶上的人设」:内置底座优先,其次第一个可用的人设。 */
1150
1350
  const defaultPersona = () =>
@@ -1213,17 +1413,7 @@ pre.text {
1213
1413
  inlineEntries()
1214
1414
  .filter((e) => (filter ? e.kind === filter : true))
1215
1415
  .filter((e) => (q ? `${e.name} ${e.id}`.toLowerCase().includes(q) : true))
1216
- .map((e) => ({
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
- })),
1416
+ .map(shaped),
1227
1417
  )
1228
1418
  }
1229
1419
 
@@ -1235,7 +1425,7 @@ pre.text {
1235
1425
  return
1236
1426
  }
1237
1427
  if (!rows.length) {
1238
- host.replaceChildren(el('p', { class: 'empty', text: '没有匹配的条目。清掉搜索,或往来源目录里放点东西再扫一次。' }))
1428
+ host.replaceChildren(el('p', { class: 'empty', text: '没有匹配的条目。清掉搜索,或导入一份文件再来。' }))
1239
1429
  return
1240
1430
  }
1241
1431
  // 分组比逐行挂「内置」胶囊干净:内置是「这一整组都随包来」,说一次就够。
@@ -1294,7 +1484,7 @@ pre.text {
1294
1484
  */
1295
1485
  function renderAssembly() {
1296
1486
  const host = $('assembly')
1297
- const plan = catalog?.plan
1487
+ const plan = currentPlan()
1298
1488
  const last = catalog?.last
1299
1489
  if (!plan) {
1300
1490
  host.replaceChildren(el('h2', {}, '注入组装'))
@@ -1343,14 +1533,15 @@ pre.text {
1343
1533
 
1344
1534
  /**
1345
1535
  * renderExpertPicker 是「一键启用专家」:这里是每天重复最多的动作。
1346
- * 不用逐条点开再点启用——九个专家的开关摊在同一行,点一下就切。
1536
+ * 不用逐条点开再点启用——专家的开关摊在同一片区域,点一下就切。
1347
1537
  * 只列技能:人设是「谁来写」,走另一条路(详情里的「设为当前人设」)。
1348
1538
  */
1349
1539
  function renderExpertPicker() {
1350
- const skills = entries().filter((e) => e.injectable && e.kind === 'skill' && e.builtin)
1540
+ const builtin = entries().filter((e) => e.injectable && e.kind === 'skill' && e.builtin)
1351
1541
  const mine = entries().filter((e) => e.injectable && e.kind === 'skill' && !e.builtin)
1352
- const all = [...skills, ...mine]
1542
+ const all = [...builtin, ...mine]
1353
1543
  if (!all.length) return null
1544
+
1354
1545
  const chip = (e) => {
1355
1546
  const on = isEnabled(e.id)
1356
1547
  return el('button', {
@@ -1359,12 +1550,31 @@ pre.text {
1359
1550
  'aria-pressed': on ? 'true' : 'false',
1360
1551
  title: on ? `停用「${e.name}」` : `启用「${e.name}」`,
1361
1552
  onclick: () => save({ enabled: { ...(options.enabled || {}), [e.id]: !on } }, on ? `已停用「${e.name}」` : `已启用「${e.name}」`),
1362
- }, on ? '✓ ' : '', e.name)
1553
+ },
1554
+ el('span', { class: 'pick-mark', 'aria-hidden': 'true' }),
1555
+ el('span', { class: 'pick-name', text: e.name }),
1556
+ el('span', { class: 'pick-size', text: `${e.chars || 0}` }),
1557
+ )
1363
1558
  }
1559
+
1560
+ const onCount = all.filter((e) => isEnabled(e.id)).length
1561
+ // 分组只在真的有「我的」时才显示:只有内置时还分两栏,等于白占一行。
1562
+ const groups = [
1563
+ mine.length ? { label: '内置', rows: builtin } : null,
1564
+ mine.length ? { label: '我的来源', rows: mine } : null,
1565
+ mine.length ? null : { label: '', rows: all },
1566
+ ].filter(Boolean)
1567
+
1364
1568
  return el('section', { class: 'picker', 'aria-label': '启用专家' },
1365
- el('h3', {}, '启用的专家',
1366
- el('span', { class: 'h2-sub', text: '点一下即生效,不必逐条打开' })),
1367
- el('div', { class: 'picks' }, ...all.map(chip)),
1569
+ el('h3', {},
1570
+ el('span', { text: '启用的专家' }),
1571
+ el('span', { class: 'picker-count', text: `${onCount} / ${all.length}` }),
1572
+ el('span', { class: 'h2-sub', text: '点一下即生效' }),
1573
+ ),
1574
+ ...groups.map((g) => el('div', { class: 'pick-group' },
1575
+ g.label ? el('span', { class: 'pick-group-label', text: g.label }) : null,
1576
+ el('div', { class: 'picks' }, ...g.rows.map(chip)),
1577
+ )),
1368
1578
  )
1369
1579
  }
1370
1580
 
@@ -1592,8 +1802,8 @@ pre.text {
1592
1802
  const n = entries().length
1593
1803
  host.replaceChildren(el('li', {
1594
1804
  text: n
1595
- ? '没有拒绝项:来源目录里每个文件都认得出来。'
1596
- : '还没有扫描结果。先确认来源目录里放了东西,再点右上角「重新扫描」。',
1805
+ ? '没有拒绝项:现在这些文件都认得出来。'
1806
+ : '还没有扫描结果:导入一份文件,或点一下「导入」区里的按钮触发重扫。',
1597
1807
  }))
1598
1808
  return
1599
1809
  }
@@ -1651,13 +1861,45 @@ pre.text {
1651
1861
  return '还没选模式:请求原样放行。选一个(比如 replace)才开始注入。'
1652
1862
  }
1653
1863
 
1864
+ /**
1865
+ * planStale 判断「快照里的判定」是否已经跟不上本地设置了。
1866
+ *
1867
+ * 只比这两件会直接改变结论的事:模式与生效的人设。比完就知道该不该按旧结论劝人。
1868
+ */
1869
+ function planStale(plan) {
1870
+ if (!plan) return false
1871
+ const localMode = MODES().includes(options.mode) ? options.mode : ''
1872
+ if (localMode && localMode !== plan.mode) return true
1873
+ const localPersona = typeof options.persona === 'string' ? options.persona.trim() : ''
1874
+ if (localPersona && localPersona !== plan.personaId) return true
1875
+ return false
1876
+ }
1877
+
1878
+ /**
1879
+ * currentPlan 是「现在这套设置会让网关怎么做」。
1880
+ *
1881
+ * 优先本地算:后端只在有请求经过时才重扫写快照,不动 agent 的话快照永远旧,
1882
+ * 技能开关、装配面板、状态条就全都停在改之前的样子。
1883
+ * 只有 useAgentPurge 打开时才不得不用快照——state.json 只有后端读得到。
1884
+ */
1885
+ function currentPlan() {
1886
+ if (options.useAgentPurge === true) return catalog?.plan || null
1887
+ const api = globalThis.PurgePlan
1888
+ if (!api) return catalog?.plan || null
1889
+ const usable = [...entries(), ...inlineEntries().map(shaped)]
1890
+ .filter((e) => e.status === 'ok' && e.injectable && typeof e.text === 'string' && e.text.trim())
1891
+ return api.resolve({ options, entries: usable })
1892
+ }
1893
+
1654
1894
  /**
1655
1895
  * renderPlan 是「现在到底注不注、注谁、为什么没注」那一行。
1656
- * 判定由后端算好放在快照的 plan 里(页面不能读 agent-purge 的 state.json)。
1896
+ *
1897
+ * 判定用 currentPlan():本地算,所以改完设置立刻反映,不用等后端重扫。
1898
+ * 快照里的 plan 只在 useAgentPurge 打开时才用得上(state.json 只有后端读得到)。
1657
1899
  */
1658
1900
  function renderPlan() {
1659
1901
  const host = $('plan')
1660
- const plan = catalog?.plan
1902
+ const plan = currentPlan()
1661
1903
  if (!plan) {
1662
1904
  host.dataset.state = 'idle'
1663
1905
  host.replaceChildren(
@@ -1667,6 +1909,9 @@ pre.text {
1667
1909
  return
1668
1910
  }
1669
1911
  const ready = Boolean(plan.ready)
1912
+ // 判定已经是本地的了,正常情况下不会过期;留这条只在 useAgentPurge 模式下生效,
1913
+ // 那种模式页面算不了,只能拿快照,仍可能出现「刚改完还没重扫」的短暂不一致。
1914
+ const stale = planStale(plan)
1670
1915
  // personaFrom 的三种来源,用户一眼要能看懂「谁在顶着」:
1671
1916
  // page = 自己点的、auto = 底座人设自动顶上、default = agent-purge(仅在显式开启时)
1672
1917
  const fromText = { page: '本页设置', auto: '底座人设(没选人设时自动顶上)', default: '默认' }
@@ -1679,10 +1924,13 @@ pre.text {
1679
1924
  save({ ...patch, refreshAt: Date.now() }, note)
1680
1925
  pollSnapshot('等后端按新设置重扫…', 25)
1681
1926
  }
1927
+ // 本地已经选好模式时,绝不再劝「用 replace 开始注入」——
1928
+ // 那正是图一里「写着 append、旁边却叫你换成 replace」的自相矛盾。
1929
+ const localMode = MODES().includes(options.mode) ? options.mode : ''
1930
+ if (!ready && !localMode) {
1931
+ fix.push(el('button', { type: 'button', class: 'primary', onclick: () => fixed({ mode: 'replace' }, '模式改为 replace') }, '用 replace 开始注入'))
1932
+ }
1682
1933
  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
1934
  // 旧人设被删掉后 options.persona 会一直指着它,卡在 persona-missing:
1687
1935
  // 这个问题点「去看人设」永远绕不出来,得给一个直接改掉它的动作。
1688
1936
  if (plan.blockedCode === 'persona-missing' && defaultPersona()) {
@@ -1693,13 +1941,13 @@ pre.text {
1693
1941
  onclick: () => fixed({ persona: next.id }, `人设改为「${next.name}」`),
1694
1942
  }, `改用「${next.name}」`))
1695
1943
  }
1696
- if (plan.blockedCode === 'no-persona' || plan.blockedCode === 'persona-missing') {
1944
+ if (!stale && (plan.blockedCode === 'no-persona' || plan.blockedCode === 'persona-missing')) {
1697
1945
  fix.push(el('button', {
1698
1946
  type: 'button',
1699
1947
  onclick: () => { filter = 'persona'; query = ''; render() },
1700
1948
  }, '去看人设'))
1701
1949
  }
1702
- if (plan.blockedCode === 'no-persona-file') {
1950
+ if (!stale && plan.blockedCode === 'no-persona-file') {
1703
1951
  fix.push(el('button', {
1704
1952
  type: 'button',
1705
1953
  class: 'primary',
@@ -1710,15 +1958,23 @@ pre.text {
1710
1958
 
1711
1959
  // 两行文字放进同一列:第一行是结论,第二行是依据;右边的胶囊组跨两行垂直居中。
1712
1960
  // 原来「为什么」那行缩进 20px,看起来像挂件;现在两行左对齐,读起来是一段话。
1961
+ // 过期时不复述旧结论:直接说「等重扫」,免得左边写 append、右边说「还没选模式」。
1962
+ const who = stale
1963
+ ? '设置已改,等后端重扫确认'
1964
+ : ready
1965
+ ? `下一次 agent 请求会注入「${plan.personaName || plan.personaId}」`
1966
+ : '现在不会注入:请求原样放行'
1967
+ const why = stale
1968
+ ? '刚改完模式或人设:下一次请求按新设置走,这里显示的是上一次扫描的判定'
1969
+ : ready
1970
+ ? `人设来源:${fromText[plan.personaFrom] || plan.personaFrom}`
1971
+ : plan.blocked
1972
+
1713
1973
  const rows = [
1714
1974
  el('span', { class: 'dot' }),
1715
1975
  el('span', { class: 'plan-text' },
1716
- el('span', { class: ready ? 'who' : 'who is-empty' }, ready
1717
- ? `下一次 agent 请求会注入「${plan.personaName || plan.personaId}」`
1718
- : '现在不会注入:请求原样放行'),
1719
- el('span', { class: 'why', text: ready
1720
- ? `人设来源:${fromText[plan.personaFrom] || plan.personaFrom}`
1721
- : plan.blocked }),
1976
+ el('span', { class: ready && !stale ? 'who' : 'who is-empty' }, who),
1977
+ el('span', { class: 'why', text: why }),
1722
1978
  ),
1723
1979
  el('span', { class: 'plan-controls' },
1724
1980
  modePill(),
@@ -1826,9 +2082,13 @@ pre.text {
1826
2082
  * 签名一变,「已注入」自动退回「确认注入」。
1827
2083
  */
1828
2084
  function confirmButton(plan) {
1829
- const sig = `${plan.mode}|${plan.personaId || ''}`
2085
+ // 签名用「实际会生效的那一套」:刚改了模式但后端还没重扫时,plan 是旧的,
2086
+ // 拿它算签名会让按钮继续显示「已注入」——那等于替一套还没生效的配置背书。
2087
+ const mode = MODES().includes(options.mode) ? options.mode : plan.mode
2088
+ const persona = (typeof options.persona === 'string' && options.persona.trim()) || plan.personaId || ''
2089
+ const sig = `${mode}|${persona}`
1830
2090
  const last = catalog?.last
1831
- const evidence = Boolean(last && !last.skipped && last.mode === plan.mode && (last.persona || '') === (plan.personaId || ''))
2091
+ const evidence = Boolean(last && !last.skipped && last.mode === mode && (last.persona || '') === persona)
1832
2092
  const applied = evidence || confirmedSig === sig
1833
2093
  return el('button', {
1834
2094
  type: 'button',
@@ -1874,7 +2134,7 @@ pre.text {
1874
2134
  return
1875
2135
  }
1876
2136
  if (Date.now() < until) setTimeout(tick, 1200)
1877
- else say('后端还没写出新快照:magpie 里插件可能没重启,或来源目录没权限。', 'bad')
2137
+ else say('后端还没写出新快照:magpie 里插件可能没重启,或它写不进自己的 state 目录。', 'bad')
1878
2138
  }
1879
2139
  script.onerror = () => {
1880
2140
  script.remove()
@@ -18,6 +18,7 @@ const read = (...p) => readFileSync(join(here, ...p), 'utf8')
18
18
  const html = read('page', 'index.html')
19
19
  const css = read('page', 'style.css')
20
20
  const app = read('page', 'app.js')
21
+ const plan = read('page', 'plan.js')
21
22
  const bridge = read('preview', 'bridge.js')
22
23
  const icon = read('page', 'icon.svg')
23
24
  const ready = read('preview', 'catalog.demo.js')
@@ -106,6 +107,8 @@ const out = html
106
107
  // app.js 原本是 defer:内联到 <head> 里会赶在 DOM 之前跑,什么都取不到。
107
108
  // 所以从这个位置摘掉,放到 </body> 前。
108
109
  .replace('<script src="app.js" defer></script>', '')
110
+ // plan.js 是纯计算、不碰 DOM,留在原位内联即可(app.js 依赖它)。
111
+ .replace('<script src="plan.js"></script>', `<script>\n${plan}\n</script>`)
109
112
  .replace('</body>', `<script>\n${app}\n</script>\n</body>`)
110
113
  .replace('src="icon.svg"', `src="${iconUri}"`)
111
114
  .replace('<body>', `<body>\n${chrome}`)