@fish-under-sea/magpie-purge 0.4.2 → 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 +1 -0
- package/package.json +1 -1
- package/page/app.js +50 -13
- package/page/index.html +1 -0
- package/page/plan.js +102 -0
- package/page/style.css +68 -11
- package/preview/purge-preview.html +223 -24
- package/tools/build-preview.mjs +3 -0
package/README.md
CHANGED
|
@@ -336,6 +336,7 @@ node tools/scan.mjs --json
|
|
|
336
336
|
|
|
337
337
|
| 版本 | 要点 |
|
|
338
338
|
| --- | --- |
|
|
339
|
+
| `0.4.3` | 判定改由页面本地计算:技能开关、装配面板、状态条改完立刻生效,不再等后端重扫;左栏跟随右栏等高;专家开关带复选框与计数 |
|
|
339
340
|
| `0.4.2` | 状态条不再按过期判定劝人(改完模式还劝「用 replace」);修「页面导入」条目没有删除按钮、被当素材 |
|
|
340
341
|
| `0.4.1` | 修「选完模式又被换回」「确认注入点了没用」;导入区改成「选择 → 再点导入」两步并可选人设/技能;去掉来源目录与自动扫描,只扫包内与 `state/imports` |
|
|
341
342
|
| `0.4.0` | 底座人设 `大肥鱼` 取代 Prompt Forge:不绑定任务,0–9 位专家随意组合;默认不再读上游 `state.json`(要读设 `useAgentPurge:true`);默认来源只剩 `~/.magpie/purge`;模式下拉去掉「跟随上游」 |
|
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.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
|
@@ -264,7 +264,7 @@
|
|
|
264
264
|
*/
|
|
265
265
|
function renderAssembly() {
|
|
266
266
|
const host = $('assembly')
|
|
267
|
-
const plan =
|
|
267
|
+
const plan = currentPlan()
|
|
268
268
|
const last = catalog?.last
|
|
269
269
|
if (!plan) {
|
|
270
270
|
host.replaceChildren(el('h2', {}, '注入组装'))
|
|
@@ -313,14 +313,15 @@
|
|
|
313
313
|
|
|
314
314
|
/**
|
|
315
315
|
* renderExpertPicker 是「一键启用专家」:这里是每天重复最多的动作。
|
|
316
|
-
*
|
|
316
|
+
* 不用逐条点开再点启用——专家的开关摊在同一片区域,点一下就切。
|
|
317
317
|
* 只列技能:人设是「谁来写」,走另一条路(详情里的「设为当前人设」)。
|
|
318
318
|
*/
|
|
319
319
|
function renderExpertPicker() {
|
|
320
|
-
const
|
|
320
|
+
const builtin = entries().filter((e) => e.injectable && e.kind === 'skill' && e.builtin)
|
|
321
321
|
const mine = entries().filter((e) => e.injectable && e.kind === 'skill' && !e.builtin)
|
|
322
|
-
const all = [...
|
|
322
|
+
const all = [...builtin, ...mine]
|
|
323
323
|
if (!all.length) return null
|
|
324
|
+
|
|
324
325
|
const chip = (e) => {
|
|
325
326
|
const on = isEnabled(e.id)
|
|
326
327
|
return el('button', {
|
|
@@ -329,12 +330,31 @@
|
|
|
329
330
|
'aria-pressed': on ? 'true' : 'false',
|
|
330
331
|
title: on ? `停用「${e.name}」` : `启用「${e.name}」`,
|
|
331
332
|
onclick: () => save({ enabled: { ...(options.enabled || {}), [e.id]: !on } }, on ? `已停用「${e.name}」` : `已启用「${e.name}」`),
|
|
332
|
-
},
|
|
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
|
+
)
|
|
333
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
|
+
|
|
334
348
|
return el('section', { class: 'picker', 'aria-label': '启用专家' },
|
|
335
|
-
el('h3', {},
|
|
336
|
-
el('span', {
|
|
337
|
-
|
|
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
|
+
)),
|
|
338
358
|
)
|
|
339
359
|
}
|
|
340
360
|
|
|
@@ -635,13 +655,31 @@
|
|
|
635
655
|
return false
|
|
636
656
|
}
|
|
637
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
|
+
|
|
638
674
|
/**
|
|
639
675
|
* renderPlan 是「现在到底注不注、注谁、为什么没注」那一行。
|
|
640
|
-
*
|
|
676
|
+
*
|
|
677
|
+
* 判定用 currentPlan():本地算,所以改完设置立刻反映,不用等后端重扫。
|
|
678
|
+
* 快照里的 plan 只在 useAgentPurge 打开时才用得上(state.json 只有后端读得到)。
|
|
641
679
|
*/
|
|
642
680
|
function renderPlan() {
|
|
643
681
|
const host = $('plan')
|
|
644
|
-
const plan =
|
|
682
|
+
const plan = currentPlan()
|
|
645
683
|
if (!plan) {
|
|
646
684
|
host.dataset.state = 'idle'
|
|
647
685
|
host.replaceChildren(
|
|
@@ -651,9 +689,8 @@
|
|
|
651
689
|
return
|
|
652
690
|
}
|
|
653
691
|
const ready = Boolean(plan.ready)
|
|
654
|
-
//
|
|
655
|
-
//
|
|
656
|
-
// 就是因为胶囊读本地、按钮读快照。这里先认出来,过期就别再按旧的劝。
|
|
692
|
+
// 判定已经是本地的了,正常情况下不会过期;留这条只在 useAgentPurge 模式下生效,
|
|
693
|
+
// 那种模式页面算不了,只能拿快照,仍可能出现「刚改完还没重扫」的短暂不一致。
|
|
657
694
|
const stale = planStale(plan)
|
|
658
695
|
// personaFrom 的三种来源,用户一眼要能看懂「谁在顶着」:
|
|
659
696
|
// page = 自己点的、auto = 底座人设自动顶上、default = agent-purge(仅在显式开启时)
|
package/page/index.html
CHANGED
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:
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
.
|
|
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
|
|
418
|
-
min-height:
|
|
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
|
|
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
|
拆成三块:头(是谁)、主体(主栏讲用处、侧栏放事实)、底(能做什么)。
|
|
@@ -307,6 +307,111 @@ window.__PURGE_BLOCKED__ = {
|
|
|
307
307
|
window.PURGE_CATALOG = snap === 'blocked' ? window.__PURGE_BLOCKED__ : window.__PURGE_READY__
|
|
308
308
|
window.__PURGE_PICK__ = pick
|
|
309
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
|
+
|
|
310
415
|
</script>
|
|
311
416
|
<style>
|
|
312
417
|
/* 破甲 · Purge 的页面样式。
|
|
@@ -549,15 +654,18 @@ textarea { width: 100%; resize: vertical; font-family: var(--mono); font-size: 1
|
|
|
549
654
|
.seg-action.is-applied:hover { background: color-mix(in oklab, var(--ok) 20%, transparent); }
|
|
550
655
|
|
|
551
656
|
/* ---------- 主体:左列表 / 右组装 ---------- */
|
|
657
|
+
/* stretch 让左栏跟右栏等高:右边展开原文后会变很高,左栏若按自己内容收着,
|
|
658
|
+
底下就是一大片空白。 */
|
|
552
659
|
.work {
|
|
553
660
|
display: grid;
|
|
554
661
|
grid-template-columns: minmax(300px, 352px) minmax(0, 1fr);
|
|
555
662
|
gap: 26px;
|
|
556
|
-
align-items:
|
|
663
|
+
align-items: stretch;
|
|
557
664
|
}
|
|
558
|
-
@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; } }
|
|
559
666
|
|
|
560
|
-
|
|
667
|
+
/* 左栏自己纵向排布,列表吃掉剩余高度 */
|
|
668
|
+
.rail { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
|
|
561
669
|
.rail-tools { display: grid; gap: 10px; }
|
|
562
670
|
.rail-tools input { width: 100%; }
|
|
563
671
|
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
|
|
@@ -574,16 +682,19 @@ textarea { width: 100%; resize: vertical; font-family: var(--mono); font-size: 1
|
|
|
574
682
|
.rail-count { margin: 12px 0 8px; color: var(--muted); font-size: 12px; }
|
|
575
683
|
|
|
576
684
|
.list { display: grid; gap: 1px; border-top: 1px solid var(--line); }
|
|
577
|
-
/*
|
|
685
|
+
/* 桌面端列表自己滚,并且跟着右栏拉长:右栏展开原文后会很高,
|
|
686
|
+
列表若固定 540px 就留一大片空白。给一个下限,免得条目少时它缩成一条。
|
|
578
687
|
窄屏不做嵌套滚动——那比页面滚动难用。
|
|
579
688
|
底部加一层淡出:滚动区硬切会把最后一行切成半截,看起来像坏了。 */
|
|
580
689
|
@media (min-width: 901px) {
|
|
581
690
|
.list {
|
|
582
|
-
|
|
691
|
+
flex: 1 1 auto;
|
|
692
|
+
min-height: min(58vh, 540px);
|
|
583
693
|
overflow-y: auto;
|
|
584
694
|
overscroll-behavior: contain;
|
|
585
695
|
padding-bottom: 4px;
|
|
586
696
|
mask-image: linear-gradient(to bottom, #000 calc(100% - 20px), transparent);
|
|
697
|
+
align-content: start;
|
|
587
698
|
}
|
|
588
699
|
.list:has(> .row:last-child:first-child) { mask-image: none; }
|
|
589
700
|
}
|
|
@@ -711,10 +822,12 @@ textarea { width: 100%; resize: vertical; font-family: var(--mono); font-size: 1
|
|
|
711
822
|
font-variant-numeric: tabular-nums;
|
|
712
823
|
}
|
|
713
824
|
|
|
714
|
-
/*
|
|
825
|
+
/* 一键启用:把专家的开关摊平,点一下即生效。
|
|
826
|
+
芯片自带一个小方框(未选是空心,选中是实心带勾)——只靠文字颜色区分,
|
|
827
|
+
一片 chip 里哪几个开着要一行行读,方框扫一眼就有答案。 */
|
|
715
828
|
.picker { margin-top: 28px; }
|
|
716
829
|
.picker h3 {
|
|
717
|
-
margin: 0 0
|
|
830
|
+
margin: 0 0 12px;
|
|
718
831
|
font-size: 13px;
|
|
719
832
|
font-weight: 560;
|
|
720
833
|
display: flex;
|
|
@@ -722,22 +835,71 @@ textarea { width: 100%; resize: vertical; font-family: var(--mono); font-size: 1
|
|
|
722
835
|
gap: 10px;
|
|
723
836
|
flex-wrap: wrap;
|
|
724
837
|
}
|
|
725
|
-
.
|
|
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; }
|
|
726
855
|
.pick {
|
|
856
|
+
display: inline-flex;
|
|
857
|
+
align-items: center;
|
|
858
|
+
gap: 7px;
|
|
727
859
|
font-size: 12.5px;
|
|
728
|
-
padding: 4px
|
|
729
|
-
min-height:
|
|
860
|
+
padding: 4px 11px 4px 9px;
|
|
861
|
+
min-height: 30px;
|
|
730
862
|
border-radius: 999px;
|
|
731
863
|
border: 1px solid var(--line);
|
|
732
864
|
background: transparent;
|
|
733
865
|
color: var(--muted);
|
|
866
|
+
transition: border-color .12s ease, background-color .12s ease, color .12s ease;
|
|
734
867
|
}
|
|
735
|
-
.pick:hover
|
|
868
|
+
.pick:hover { color: var(--ink); border-color: color-mix(in oklab, var(--muted) 55%, var(--line)); }
|
|
736
869
|
.pick.is-on {
|
|
737
870
|
background: color-mix(in oklab, var(--kind-skill) 14%, transparent);
|
|
738
871
|
border-color: color-mix(in oklab, var(--kind-skill) 45%, var(--line));
|
|
739
872
|
color: var(--ink);
|
|
740
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
|
+
}
|
|
741
903
|
|
|
742
904
|
/* 详情
|
|
743
905
|
拆成三块:头(是谁)、主体(主栏讲用处、侧栏放事实)、底(能做什么)。
|
|
@@ -1322,7 +1484,7 @@ pre.text {
|
|
|
1322
1484
|
*/
|
|
1323
1485
|
function renderAssembly() {
|
|
1324
1486
|
const host = $('assembly')
|
|
1325
|
-
const plan =
|
|
1487
|
+
const plan = currentPlan()
|
|
1326
1488
|
const last = catalog?.last
|
|
1327
1489
|
if (!plan) {
|
|
1328
1490
|
host.replaceChildren(el('h2', {}, '注入组装'))
|
|
@@ -1371,14 +1533,15 @@ pre.text {
|
|
|
1371
1533
|
|
|
1372
1534
|
/**
|
|
1373
1535
|
* renderExpertPicker 是「一键启用专家」:这里是每天重复最多的动作。
|
|
1374
|
-
*
|
|
1536
|
+
* 不用逐条点开再点启用——专家的开关摊在同一片区域,点一下就切。
|
|
1375
1537
|
* 只列技能:人设是「谁来写」,走另一条路(详情里的「设为当前人设」)。
|
|
1376
1538
|
*/
|
|
1377
1539
|
function renderExpertPicker() {
|
|
1378
|
-
const
|
|
1540
|
+
const builtin = entries().filter((e) => e.injectable && e.kind === 'skill' && e.builtin)
|
|
1379
1541
|
const mine = entries().filter((e) => e.injectable && e.kind === 'skill' && !e.builtin)
|
|
1380
|
-
const all = [...
|
|
1542
|
+
const all = [...builtin, ...mine]
|
|
1381
1543
|
if (!all.length) return null
|
|
1544
|
+
|
|
1382
1545
|
const chip = (e) => {
|
|
1383
1546
|
const on = isEnabled(e.id)
|
|
1384
1547
|
return el('button', {
|
|
@@ -1387,12 +1550,31 @@ pre.text {
|
|
|
1387
1550
|
'aria-pressed': on ? 'true' : 'false',
|
|
1388
1551
|
title: on ? `停用「${e.name}」` : `启用「${e.name}」`,
|
|
1389
1552
|
onclick: () => save({ enabled: { ...(options.enabled || {}), [e.id]: !on } }, on ? `已停用「${e.name}」` : `已启用「${e.name}」`),
|
|
1390
|
-
},
|
|
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
|
+
)
|
|
1391
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
|
+
|
|
1392
1568
|
return el('section', { class: 'picker', 'aria-label': '启用专家' },
|
|
1393
|
-
el('h3', {},
|
|
1394
|
-
el('span', {
|
|
1395
|
-
|
|
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
|
+
)),
|
|
1396
1578
|
)
|
|
1397
1579
|
}
|
|
1398
1580
|
|
|
@@ -1693,13 +1875,31 @@ pre.text {
|
|
|
1693
1875
|
return false
|
|
1694
1876
|
}
|
|
1695
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
|
+
|
|
1696
1894
|
/**
|
|
1697
1895
|
* renderPlan 是「现在到底注不注、注谁、为什么没注」那一行。
|
|
1698
|
-
*
|
|
1896
|
+
*
|
|
1897
|
+
* 判定用 currentPlan():本地算,所以改完设置立刻反映,不用等后端重扫。
|
|
1898
|
+
* 快照里的 plan 只在 useAgentPurge 打开时才用得上(state.json 只有后端读得到)。
|
|
1699
1899
|
*/
|
|
1700
1900
|
function renderPlan() {
|
|
1701
1901
|
const host = $('plan')
|
|
1702
|
-
const plan =
|
|
1902
|
+
const plan = currentPlan()
|
|
1703
1903
|
if (!plan) {
|
|
1704
1904
|
host.dataset.state = 'idle'
|
|
1705
1905
|
host.replaceChildren(
|
|
@@ -1709,9 +1909,8 @@ pre.text {
|
|
|
1709
1909
|
return
|
|
1710
1910
|
}
|
|
1711
1911
|
const ready = Boolean(plan.ready)
|
|
1712
|
-
//
|
|
1713
|
-
//
|
|
1714
|
-
// 就是因为胶囊读本地、按钮读快照。这里先认出来,过期就别再按旧的劝。
|
|
1912
|
+
// 判定已经是本地的了,正常情况下不会过期;留这条只在 useAgentPurge 模式下生效,
|
|
1913
|
+
// 那种模式页面算不了,只能拿快照,仍可能出现「刚改完还没重扫」的短暂不一致。
|
|
1715
1914
|
const stale = planStale(plan)
|
|
1716
1915
|
// personaFrom 的三种来源,用户一眼要能看懂「谁在顶着」:
|
|
1717
1916
|
// page = 自己点的、auto = 底座人设自动顶上、default = agent-purge(仅在显式开启时)
|
package/tools/build-preview.mjs
CHANGED
|
@@ -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}`)
|