@fish-under-sea/magpie-purge 0.3.2 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +94 -28
- package/THIRD_PARTY_NOTICES.md +11 -1
- package/hooks.js +1 -1
- package/lib/bundled.mjs +2 -0
- package/lib/inventory.mjs +18 -4
- package/lib/plan.mjs +14 -12
- package/lib/rewrite.mjs +2 -1
- package/lib/state.mjs +6 -3
- package/package.json +2 -2
- package/page/app.js +257 -64
- package/page/index.html +2 -20
- package/page/style.css +235 -49
- package/personas/dafeiyu.md +47 -0
- package/preview/catalog.demo.js +31 -19
- package/preview/host.html +23 -1
- package/preview/purge-preview.html +525 -152
- package/preview/serve.mjs +48 -2
- package/personas/prompt-forge.md +0 -26
package/page/app.js
CHANGED
|
@@ -28,10 +28,15 @@
|
|
|
28
28
|
replace: '人设放最前,宿主 system 里「自称 + 点名模型/厂商」的行删掉。',
|
|
29
29
|
append: '人设放最前,宿主 system 原样保留。',
|
|
30
30
|
}
|
|
31
|
-
/**
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
/** MODE_SHORT 是下拉里模式名后面那一截:只够一格,别写成整句。 */
|
|
32
|
+
const MODE_SHORT = {
|
|
33
|
+
off: '不动请求',
|
|
34
|
+
strict: '只留人设',
|
|
35
|
+
replace: '去自称',
|
|
36
|
+
append: '原样保留',
|
|
37
|
+
}
|
|
38
|
+
/** NOT_INJECTABLE 只说「它是什么」,下一步交给详情里的 callout,别两处都指路。 */
|
|
39
|
+
const NOT_INJECTABLE = '素材条目:能查看、能归档,但不会写进 system。'
|
|
35
40
|
|
|
36
41
|
let options = {}
|
|
37
42
|
let catalog = window.PURGE_CATALOG ?? null
|
|
@@ -41,6 +46,12 @@
|
|
|
41
46
|
let saveTimer = 0
|
|
42
47
|
let pendingSave = null
|
|
43
48
|
let busy = false
|
|
49
|
+
/** showingText 是「查看原文」的展开态;换条目时要收回去,否则新条目一进来就是展开的。 */
|
|
50
|
+
let showingText = false
|
|
51
|
+
/** confirmedSig 记「用户按下确认时的那套配置」;配置一变就失效,退回「确认注入」。 */
|
|
52
|
+
let confirmedSig = ''
|
|
53
|
+
/** modeMenuOpen 是模式下拉面板是否展开;每次重画都要记住,否则点一下就收。 */
|
|
54
|
+
let modeMenuOpen = false
|
|
44
55
|
|
|
45
56
|
// ---------- 小工具 ----------
|
|
46
57
|
|
|
@@ -58,11 +69,16 @@
|
|
|
58
69
|
say.timer = setTimeout(() => { el.hidden = true }, 6000)
|
|
59
70
|
}
|
|
60
71
|
|
|
72
|
+
/** SVG_NS 是 svg 元素的命名空间:用 createElement 造出来的 <svg> 是 HTML 未知元素,不会渲染。 */
|
|
73
|
+
const SVG_NS = 'http://www.w3.org/2000/svg'
|
|
74
|
+
|
|
61
75
|
function el(tag, attrs = {}, ...kids) {
|
|
62
|
-
const node =
|
|
76
|
+
const node = tag === 'svg' || tag === 'path'
|
|
77
|
+
? document.createElementNS(SVG_NS, tag)
|
|
78
|
+
: document.createElement(tag)
|
|
63
79
|
for (const [k, v] of Object.entries(attrs)) {
|
|
64
80
|
if (v === null || v === undefined || v === false) continue
|
|
65
|
-
if (k === 'class') node.
|
|
81
|
+
if (k === 'class') node.setAttribute('class', v)
|
|
66
82
|
else if (k === 'text') node.textContent = v
|
|
67
83
|
else if (k.startsWith('on') && typeof v === 'function') node.addEventListener(k.slice(2), v)
|
|
68
84
|
else node.setAttribute(k, v === true ? '' : String(v))
|
|
@@ -186,7 +202,13 @@
|
|
|
186
202
|
class: 'row',
|
|
187
203
|
role: 'option',
|
|
188
204
|
'aria-selected': selected === e.id,
|
|
189
|
-
onclick: () => {
|
|
205
|
+
onclick: () => {
|
|
206
|
+
const next = selected === e.id ? '' : e.id
|
|
207
|
+
// 换条目就收起原文:从一条展开着的详情跳到另一条,不该自动展示别人的正文。
|
|
208
|
+
if (next !== selected) showingText = false
|
|
209
|
+
selected = next
|
|
210
|
+
render()
|
|
211
|
+
},
|
|
190
212
|
},
|
|
191
213
|
el('span', { class: 'spine', style: `--spine:var(--kind-${kindClass(e.kind)})` }),
|
|
192
214
|
el('span', {},
|
|
@@ -298,6 +320,7 @@
|
|
|
298
320
|
const e = findEntry(selected)
|
|
299
321
|
if (!e) {
|
|
300
322
|
// 没选中时让位给「组装预览」:右栏不留一片空白,那是最浪费的一屏。
|
|
323
|
+
showingText = false
|
|
301
324
|
host.replaceChildren()
|
|
302
325
|
return
|
|
303
326
|
}
|
|
@@ -309,7 +332,10 @@
|
|
|
309
332
|
const enabled = isEnabled(e.id)
|
|
310
333
|
const pinned = options.pinned?.[e.id]
|
|
311
334
|
const history = Array.isArray(e.history) ? e.history : []
|
|
312
|
-
|
|
335
|
+
// 可注入条目的正文现在随快照下来(inventory.snapshotOf 带 text),
|
|
336
|
+
// 所以「看原文」对内置技能也成立,不再只限页面里贴进来的那几条。
|
|
337
|
+
const text = typeof e.text === 'string' ? e.text : ''
|
|
338
|
+
const canShowText = Boolean(text.trim())
|
|
313
339
|
|
|
314
340
|
const actions = []
|
|
315
341
|
// 人设才有「设为当前人设」;技能是「启用/停用」。混着写会让人以为技能能当人设用。
|
|
@@ -326,6 +352,15 @@
|
|
|
326
352
|
onclick: () => save({ enabled: { ...(options.enabled || {}), [e.id]: !enabled } }, enabled ? `已停用「${e.name}」` : `已启用「${e.name}」`),
|
|
327
353
|
}, enabled ? '停用' : '启用'))
|
|
328
354
|
}
|
|
355
|
+
// 「它到底写了什么」是判断要不要启用它的唯一依据:进来就看得到,不用去磁盘翻文件。
|
|
356
|
+
if (canShowText) {
|
|
357
|
+
actions.push(el('button', {
|
|
358
|
+
type: 'button',
|
|
359
|
+
class: showingText ? 'quiet' : '',
|
|
360
|
+
'aria-expanded': showingText ? 'true' : 'false',
|
|
361
|
+
onclick: () => { showingText = !showingText; renderInspector() },
|
|
362
|
+
}, showingText ? '收起原文' : '查看原文'))
|
|
363
|
+
}
|
|
329
364
|
if (pinned) {
|
|
330
365
|
actions.push(el('button', {
|
|
331
366
|
type: 'button',
|
|
@@ -375,42 +410,75 @@
|
|
|
375
410
|
)
|
|
376
411
|
: null
|
|
377
412
|
|
|
413
|
+
// 详情不再是一张平铺的规格表:主栏说「它是什么、怎么用、占多少」,侧栏放技术事实,
|
|
414
|
+
// 底部单独一条操作栏。原来六行 dl + 一条细预算条全堆在一起,看不出主次。
|
|
415
|
+
const desc = e.meta?.description || (e.injectable ? '可写进 system 段的人设/技能文本。' : NOT_INJECTABLE)
|
|
416
|
+
const pct = Math.min(100, ((e.chars || 0) / 65536) * 100)
|
|
417
|
+
const facts = [
|
|
418
|
+
['来源', e.source?.root === 'inline' ? '页面导入(存在 options 里)' : e.builtin ? `插件内置 ${builtinFolder(e)}/` : e.source?.root || '—'],
|
|
419
|
+
['路径', null, 'code', e.source?.rel || '—'],
|
|
420
|
+
['摘要', null, 'code', short(e.digest)],
|
|
421
|
+
['版本', `v${e.version ?? 1}${history.length ? ` · 留 ${history.length} 个旧版` : ''}`],
|
|
422
|
+
['导入', e.builtin ? '随插件' : fmtTime(e.importedAt)],
|
|
423
|
+
...(e.meta?.sessions !== undefined ? [['会话数', String(e.meta.sessions)]] : []),
|
|
424
|
+
...(e.meta?.turns !== undefined ? [['选定轮次', String(e.meta.turns)]] : []),
|
|
425
|
+
]
|
|
426
|
+
|
|
378
427
|
// replaceChildren 会把 null 变成 "null" 字符串,所以先过滤。
|
|
379
428
|
host.replaceChildren(...[
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
el('
|
|
429
|
+
// ---- 头:名字 + 类型 + 一句话定位 ----
|
|
430
|
+
el('header', { class: 'ins-head' },
|
|
431
|
+
el('div', { class: 'ins-title' },
|
|
432
|
+
el('h2', {}, e.name),
|
|
433
|
+
el('span', { class: `kind ${kindCls}` }, kind.label),
|
|
434
|
+
e.builtin ? el('span', { class: 'ins-badge', text: '内置' }) : null,
|
|
435
|
+
),
|
|
436
|
+
el('p', { class: 'ins-lede', text: desc }),
|
|
383
437
|
),
|
|
384
|
-
|
|
385
|
-
//
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
438
|
+
|
|
439
|
+
// ---- 主体:主栏(何时用 / 体量)+ 侧栏(技术事实)----
|
|
440
|
+
el('div', { class: 'ins-body' },
|
|
441
|
+
el('div', { class: 'ins-main' },
|
|
442
|
+
e.meta?.whenToUse
|
|
443
|
+
? el('section', { class: 'ins-callout' },
|
|
444
|
+
el('h3', { text: '何时用' }),
|
|
445
|
+
el('p', { text: e.meta.whenToUse }),
|
|
446
|
+
)
|
|
447
|
+
: null,
|
|
448
|
+
e.injectable
|
|
449
|
+
? el('section', { class: 'ins-meter' },
|
|
450
|
+
el('h3', {}, '进入 system 的体量',
|
|
451
|
+
el('span', { class: 'ins-pct', text: pct < 1 ? '<1%' : `${pct.toFixed(pct < 10 ? 1 : 0)}%` })),
|
|
452
|
+
el('div', { class: 'meter-track' }, el('div', { class: 'meter-fill', style: `width:${Math.max(pct, 0.6)}%` })),
|
|
453
|
+
el('p', { class: 'ins-meter-note', text: `${(e.chars || 0).toLocaleString('zh-CN')} / 65,536 字符 · 与人设一起拼进 system` }),
|
|
454
|
+
)
|
|
455
|
+
: el('section', { class: 'ins-callout is-material' },
|
|
456
|
+
el('h3', { text: '下一步' }),
|
|
457
|
+
el('p', { text: '把它当资料翻;要注入的话,从「导入与来源」里选一份 .md 人设或技能。' }),
|
|
458
|
+
),
|
|
459
|
+
// 「出处」比「提炼自」中性:技能是从 dsh-purge 提炼的,人设是新写的,一个前缀套不住两种。
|
|
460
|
+
e.builtin && e.meta?.source
|
|
461
|
+
? el('p', { class: 'ins-origin', text: `出处:${e.meta.source}` })
|
|
462
|
+
: null,
|
|
463
|
+
),
|
|
464
|
+
el('aside', { class: 'ins-facts' },
|
|
465
|
+
...facts.flatMap(([k, v, tag, code]) => [
|
|
466
|
+
el('dt', { text: k }),
|
|
467
|
+
el('dd', {}, v !== null ? String(v) : el(tag || 'code', { text: code })),
|
|
468
|
+
]),
|
|
469
|
+
),
|
|
403
470
|
),
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
)
|
|
471
|
+
|
|
472
|
+
// ---- 底:操作栏 ----
|
|
473
|
+
actions.length
|
|
474
|
+
? el('footer', { class: 'ins-actions' }, ...actions)
|
|
409
475
|
: null,
|
|
410
|
-
el('div', { class: 'actions' }, ...actions),
|
|
411
476
|
versionPicker,
|
|
412
477
|
pinned ? el('p', { class: 'note', text: `当前固定到 ${short(pinned)}:网关用那一版的正文,不是最新的。` }) : null,
|
|
413
|
-
|
|
478
|
+
// 原文按注入形态显示:前面出现的技能段,正文会以「## 技能:<名字>」为界拼进去。
|
|
479
|
+
showingText && canShowText
|
|
480
|
+
? el('pre', { class: 'text', text: text.length > 8000 ? `${text.slice(0, 8000)}\n…(共 ${text.length.toLocaleString('zh-CN')} 字符,后面省略)` : text })
|
|
481
|
+
: null,
|
|
414
482
|
].filter(Boolean))
|
|
415
483
|
}
|
|
416
484
|
|
|
@@ -460,8 +528,6 @@
|
|
|
460
528
|
const shown = visible().length
|
|
461
529
|
$('count').textContent = `${shown} / ${entries().length + inlineEntries().length} 条 · 快照 v${catalog.version} · ${fmtTime(catalog.generatedAt)}`
|
|
462
530
|
}
|
|
463
|
-
$('mode').value = MODES().includes(options.mode) ? options.mode : ''
|
|
464
|
-
$('mode-help').textContent = modeHelp($('mode').value)
|
|
465
531
|
renderPlan()
|
|
466
532
|
renderFilters()
|
|
467
533
|
renderList()
|
|
@@ -476,16 +542,13 @@
|
|
|
476
542
|
renderSources()
|
|
477
543
|
}
|
|
478
544
|
|
|
479
|
-
/** MODES
|
|
480
|
-
const MODES = () => ['
|
|
545
|
+
/** MODES 是模式下拉的全部取值:没有「跟随上游」这一档,模式必须自己选。 */
|
|
546
|
+
const MODES = () => ['off', 'strict', 'replace', 'append']
|
|
481
547
|
|
|
482
|
-
/** modeHelp
|
|
548
|
+
/** modeHelp 说清当前值到底意味着什么;未选时说清未选就是不动请求。 */
|
|
483
549
|
function modeHelp(value) {
|
|
484
550
|
if (value) return MODE_HELP[value] || ''
|
|
485
|
-
|
|
486
|
-
if (!p?.bound) return '没装 agent-purge 或读不到它的 state.json:等价于 off,不会改请求。'
|
|
487
|
-
if (p.error) return `agent-purge 的 state.json 有问题:${p.error};等价于 off。`
|
|
488
|
-
return `跟随 agent-purge:当前 ${p.mode || '未设置'}${p.persona ? ` · 人设 ${p.persona}` : ''}`
|
|
551
|
+
return '还没选模式:请求原样放行。选一个(比如 replace)才开始注入。'
|
|
489
552
|
}
|
|
490
553
|
|
|
491
554
|
/**
|
|
@@ -504,7 +567,9 @@
|
|
|
504
567
|
return
|
|
505
568
|
}
|
|
506
569
|
const ready = Boolean(plan.ready)
|
|
507
|
-
|
|
570
|
+
// personaFrom 的三种来源,用户一眼要能看懂「谁在顶着」:
|
|
571
|
+
// page = 自己点的、auto = 底座人设自动顶上、default = agent-purge(仅在显式开启时)
|
|
572
|
+
const fromText = { page: '本页设置', auto: '底座人设(没选人设时自动顶上)', default: '默认' }
|
|
508
573
|
host.dataset.state = ready ? 'ready' : 'blocked'
|
|
509
574
|
|
|
510
575
|
// 没就绪时给一个能点的下一步:光说「不会注入」等于把问题丢回给人。
|
|
@@ -534,24 +599,145 @@
|
|
|
534
599
|
}
|
|
535
600
|
}
|
|
536
601
|
|
|
602
|
+
// 两行文字放进同一列:第一行是结论,第二行是依据;右边的胶囊组跨两行垂直居中。
|
|
603
|
+
// 原来「为什么」那行缩进 20px,看起来像挂件;现在两行左对齐,读起来是一段话。
|
|
537
604
|
const rows = [
|
|
538
605
|
el('span', { class: 'dot' }),
|
|
539
|
-
el('span', { class:
|
|
540
|
-
?
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
el('span', { class: '
|
|
544
|
-
|
|
606
|
+
el('span', { class: 'plan-text' },
|
|
607
|
+
el('span', { class: ready ? 'who' : 'who is-empty' }, ready
|
|
608
|
+
? `下一次 agent 请求会注入「${plan.personaName || plan.personaId}」`
|
|
609
|
+
: '现在不会注入:请求原样放行'),
|
|
610
|
+
el('span', { class: 'why', text: ready
|
|
611
|
+
? `人设来源:${fromText[plan.personaFrom] || plan.personaFrom}`
|
|
612
|
+
: plan.blocked }),
|
|
613
|
+
),
|
|
614
|
+
el('span', { class: 'plan-controls' },
|
|
615
|
+
modePill(),
|
|
545
616
|
...fix,
|
|
546
|
-
|
|
617
|
+
ready ? confirmButton(plan) : null,
|
|
547
618
|
),
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
619
|
+
// 面板浮在胶囊组下面:.plan-controls 要 overflow:hidden 才能把两段裁成一颗胶囊,
|
|
620
|
+
// 所以面板不能放在它里面,只能挂在 .plan 上做绝对定位。
|
|
621
|
+
modeMenuOpen ? modeMenu() : null,
|
|
551
622
|
]
|
|
552
623
|
host.replaceChildren(...rows.filter(Boolean))
|
|
553
624
|
}
|
|
554
625
|
|
|
626
|
+
/**
|
|
627
|
+
* modePill 是胶囊组的第一段:模式选择器。
|
|
628
|
+
*
|
|
629
|
+
* 不用原生 select:系统的下拉面板是浏览器自己画的,颜色、圆角、间距全都改不了,
|
|
630
|
+
* 深色主题下还会弹出一块浅色板。这里自绘:按钮 + 自绘面板,
|
|
631
|
+
* 键盘(上下键 / Esc / Enter)与 aria 都按 listbox 的模式接好。
|
|
632
|
+
*/
|
|
633
|
+
function modePill() {
|
|
634
|
+
const value = MODES().includes(options.mode) ? options.mode : ''
|
|
635
|
+
// 未选模式时不假装跟随谁:直接说「未选」,点开才去挑。
|
|
636
|
+
const label = value === '' ? '未选' : `${value} · ${MODE_SHORT[value] || ''}`
|
|
637
|
+
return el('button', {
|
|
638
|
+
type: 'button',
|
|
639
|
+
class: 'seg seg-mode',
|
|
640
|
+
title: modeHelp(value),
|
|
641
|
+
'aria-haspopup': 'listbox',
|
|
642
|
+
'aria-expanded': modeMenuOpen ? 'true' : 'false',
|
|
643
|
+
onclick: (e) => {
|
|
644
|
+
e.stopPropagation()
|
|
645
|
+
modeMenuOpen = !modeMenuOpen
|
|
646
|
+
renderPlan()
|
|
647
|
+
if (modeMenuOpen) document.querySelector('.seg-opt.is-on')?.focus()
|
|
648
|
+
},
|
|
649
|
+
onkeydown: (e) => {
|
|
650
|
+
if (e.key === 'ArrowDown' || e.key === 'Enter' || e.key === ' ') {
|
|
651
|
+
e.preventDefault()
|
|
652
|
+
modeMenuOpen = true
|
|
653
|
+
renderPlan()
|
|
654
|
+
document.querySelector('.seg-opt.is-on')?.focus()
|
|
655
|
+
}
|
|
656
|
+
},
|
|
657
|
+
},
|
|
658
|
+
el('span', { class: 'seg-key', text: '模式' }),
|
|
659
|
+
el('span', { class: 'seg-value', text: label }),
|
|
660
|
+
el('svg', { class: 'seg-chev', viewBox: '0 0 12 12', 'aria-hidden': 'true' },
|
|
661
|
+
el('path', { d: 'M2.5 4.5 L6 8 L9.5 4.5', fill: 'none', stroke: 'currentColor', 'stroke-width': '1.6', 'stroke-linecap': 'round', 'stroke-linejoin': 'round' }),
|
|
662
|
+
),
|
|
663
|
+
)
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
/** modeMenu 是自绘的下拉面板:每项两行——模式名 + 一句它到底干什么。 */
|
|
667
|
+
function modeMenu() {
|
|
668
|
+
const value = MODES().includes(options.mode) ? options.mode : ''
|
|
669
|
+
const pick = (m) => {
|
|
670
|
+
modeMenuOpen = false
|
|
671
|
+
save({ mode: m }, `模式改为 ${m}`)
|
|
672
|
+
}
|
|
673
|
+
const move = (delta) => {
|
|
674
|
+
const opts = [...document.querySelectorAll('.seg-opt')]
|
|
675
|
+
const i = opts.indexOf(document.activeElement)
|
|
676
|
+
const next = opts[Math.min(opts.length - 1, Math.max(0, (i < 0 ? 0 : i) + delta))]
|
|
677
|
+
next?.focus()
|
|
678
|
+
}
|
|
679
|
+
return el('div', {
|
|
680
|
+
class: 'seg-menu',
|
|
681
|
+
role: 'listbox',
|
|
682
|
+
'aria-label': '改写模式',
|
|
683
|
+
onclick: (e) => e.stopPropagation(),
|
|
684
|
+
onkeydown: (e) => {
|
|
685
|
+
if (e.key === 'Escape') { modeMenuOpen = false; renderPlan(); return }
|
|
686
|
+
if (e.key === 'ArrowDown') { e.preventDefault(); move(1) }
|
|
687
|
+
if (e.key === 'ArrowUp') { e.preventDefault(); move(-1) }
|
|
688
|
+
},
|
|
689
|
+
},
|
|
690
|
+
...MODES().map((m) => el('button', {
|
|
691
|
+
type: 'button',
|
|
692
|
+
class: `seg-opt${m === value ? ' is-on' : ''}`,
|
|
693
|
+
role: 'option',
|
|
694
|
+
'aria-selected': m === value ? 'true' : 'false',
|
|
695
|
+
tabindex: m === value ? '0' : '-1',
|
|
696
|
+
onclick: () => pick(m),
|
|
697
|
+
},
|
|
698
|
+
el('span', { class: 'seg-opt-body' },
|
|
699
|
+
el('span', { class: 'seg-opt-name', text: m }),
|
|
700
|
+
el('span', { class: 'seg-opt-sub', text: MODE_HELP[m] }),
|
|
701
|
+
),
|
|
702
|
+
m === value
|
|
703
|
+
? el('svg', { class: 'seg-check', viewBox: '0 0 12 12', 'aria-hidden': 'true' },
|
|
704
|
+
el('path', { d: 'M2.5 6.2 L5 8.6 L9.5 3.4', fill: 'none', stroke: 'currentColor', 'stroke-width': '1.7', 'stroke-linecap': 'round', 'stroke-linejoin': 'round' }))
|
|
705
|
+
: null,
|
|
706
|
+
)),
|
|
707
|
+
)
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
/**
|
|
711
|
+
* confirmButton 是「确认注入」那颗胶囊。
|
|
712
|
+
*
|
|
713
|
+
* 「已注入」有两个来源,都算数:
|
|
714
|
+
* 1. 最近一次真的经过网关的记录(catalog.last)写着同一套人设与模式——这是证据;
|
|
715
|
+
* 2. 用户按下确认,且此后配置没再动过——这是意图。
|
|
716
|
+
* 本地打个勾不叫生效,所以状态里带着「按的是哪一套配置」:改了模式或人设,
|
|
717
|
+
* 签名一变,「已注入」自动退回「确认注入」。
|
|
718
|
+
*/
|
|
719
|
+
function confirmButton(plan) {
|
|
720
|
+
const sig = `${plan.mode}|${plan.personaId || ''}`
|
|
721
|
+
const last = catalog?.last
|
|
722
|
+
const evidence = Boolean(last && !last.skipped && last.mode === plan.mode && (last.persona || '') === (plan.personaId || ''))
|
|
723
|
+
const applied = evidence || confirmedSig === sig
|
|
724
|
+
return el('button', {
|
|
725
|
+
type: 'button',
|
|
726
|
+
class: `seg seg-action${applied ? ' is-applied' : ' is-armed'}`,
|
|
727
|
+
title: evidence
|
|
728
|
+
? `最近一次生效:${fmtTime(last.at)} · ${last.agent || '未知 agent'}`
|
|
729
|
+
: applied
|
|
730
|
+
? '已按当前配置确认注入;改了模式或人设会退回未确认'
|
|
731
|
+
: '把这套配置推给网关:重扫一次,下一次 agent 请求就按它注入',
|
|
732
|
+
onclick: () => {
|
|
733
|
+
confirmedSig = sig
|
|
734
|
+
renderPlan()
|
|
735
|
+
say('已确认注入:下一次 agent 请求按这套配置走', 'good')
|
|
736
|
+
refresh()
|
|
737
|
+
},
|
|
738
|
+
}, applied ? '已注入' : '确认注入')
|
|
739
|
+
}
|
|
740
|
+
|
|
555
741
|
function renderSources() {
|
|
556
742
|
const el2 = $('sources')
|
|
557
743
|
if (!el2 || document.activeElement === el2) return
|
|
@@ -602,25 +788,27 @@
|
|
|
602
788
|
async function refresh() {
|
|
603
789
|
if (busy) return
|
|
604
790
|
busy = true
|
|
605
|
-
$('refresh').disabled = true
|
|
606
791
|
try {
|
|
607
792
|
save({ refreshAt: Date.now() })
|
|
608
793
|
await flush()
|
|
609
794
|
pollSnapshot('正在让后端重新扫描…', 25)
|
|
610
795
|
} finally {
|
|
611
796
|
busy = false
|
|
612
|
-
$('refresh').disabled = false
|
|
613
797
|
}
|
|
614
798
|
}
|
|
615
799
|
|
|
616
800
|
function wire() {
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
save({ mode: value }, value ? `模式改为 ${value}` : '改为跟随 agent-purge')
|
|
620
|
-
})
|
|
621
|
-
$('refresh').addEventListener('click', refresh)
|
|
801
|
+
// 模式选择器与「确认注入」都是每次 renderPlan 重建的,监听写在创建处(onclick/onkeydown),
|
|
802
|
+
// 这里只绑那些常驻不动的控件。
|
|
622
803
|
$('q').addEventListener('input', (e) => { query = e.target.value; render() })
|
|
623
804
|
|
|
805
|
+
// 点面板以外的地方就收起。用捕获阶段:面板内部自己 stopPropagation。
|
|
806
|
+
document.addEventListener('click', () => {
|
|
807
|
+
if (!modeMenuOpen) return
|
|
808
|
+
modeMenuOpen = false
|
|
809
|
+
renderPlan()
|
|
810
|
+
})
|
|
811
|
+
|
|
624
812
|
$('import-run').addEventListener('click', () => {
|
|
625
813
|
const path = $('import-path').value.trim()
|
|
626
814
|
if (!path) return say('先填一个文件路径', 'bad')
|
|
@@ -671,6 +859,11 @@
|
|
|
671
859
|
}
|
|
672
860
|
wire()
|
|
673
861
|
render()
|
|
862
|
+
// 预览用:?menu=1 直接把下拉面板展开,省得截图时还要模拟点击。
|
|
863
|
+
if (new URLSearchParams(location.search).get('menu') === '1') {
|
|
864
|
+
modeMenuOpen = true
|
|
865
|
+
renderPlan()
|
|
866
|
+
}
|
|
674
867
|
if (!catalog) pollSnapshot('还没有快照,等后端第一次扫描…', 20)
|
|
675
868
|
}
|
|
676
869
|
|
package/page/index.html
CHANGED
|
@@ -13,29 +13,11 @@
|
|
|
13
13
|
|
|
14
14
|
<header class="top">
|
|
15
15
|
<div class="brand">
|
|
16
|
-
<img class="mark" src="
|
|
17
|
-
<div class="brand-text">
|
|
16
|
+
<img class="mark" src="card.png" alt="" width="28" height="28"> <div class="brand-text">
|
|
18
17
|
<h1>破甲 <span class="brand-tail">Purge</span></h1>
|
|
19
18
|
<p class="tagline">本地 purge 目录 → 网关 system 改写</p>
|
|
20
19
|
</div>
|
|
21
20
|
</div>
|
|
22
|
-
|
|
23
|
-
<div class="top-controls">
|
|
24
|
-
<div class="controls-row">
|
|
25
|
-
<label class="field">
|
|
26
|
-
<span class="field-label" id="mode-label">改写模式</span>
|
|
27
|
-
<select id="mode" aria-labelledby="mode-label">
|
|
28
|
-
<option value="">跟随 agent-purge</option>
|
|
29
|
-
<option value="off">off · 不动请求</option>
|
|
30
|
-
<option value="strict">strict · 只留人设</option>
|
|
31
|
-
<option value="replace">replace · 人设 + 去掉自称</option>
|
|
32
|
-
<option value="append">append · 人设 + 原样保留</option>
|
|
33
|
-
</select>
|
|
34
|
-
</label>
|
|
35
|
-
<button id="refresh" type="button" class="quiet">重新扫描</button>
|
|
36
|
-
</div>
|
|
37
|
-
<p class="top-hint" id="mode-help"></p>
|
|
38
|
-
</div>
|
|
39
21
|
</header>
|
|
40
22
|
|
|
41
23
|
<section class="plan" id="plan" aria-label="当前注入状态" aria-live="polite"></section>
|
|
@@ -77,7 +59,7 @@
|
|
|
77
59
|
|
|
78
60
|
<label class="field">
|
|
79
61
|
<span class="field-label">来源目录(一行一个)</span>
|
|
80
|
-
<textarea id="sources" rows="3" spellcheck="false" aria-label="来源目录,一行一个" placeholder="D:\purge ~/.
|
|
62
|
+
<textarea id="sources" rows="3" spellcheck="false" aria-label="来源目录,一行一个" placeholder="D:\purge ~/.magpie/purge"></textarea>
|
|
81
63
|
</label>
|
|
82
64
|
<button id="sources-save" type="button">保存来源并重扫</button>
|
|
83
65
|
</div>
|