@fish-under-sea/magpie-purge 0.6.1 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/hooks.js +38 -4
- package/lib/inventory.mjs +8 -4
- package/lib/state.mjs +5 -1
- package/package.json +1 -1
- package/page/app.js +1 -1
- package/page/index.html +4 -4
package/README.md
CHANGED
|
@@ -418,6 +418,7 @@ node tools/scan.mjs --json
|
|
|
418
418
|
|
|
419
419
|
| 版本 | 要点 |
|
|
420
420
|
| --- | --- |
|
|
421
|
+
| `0.6.2` | 正文一律不落盘(`.js`、`.json`、`state/catalog.json` 全都不含),注入时按 `source.root/rel` 现读——彻底止住 Defender 对聚合文件的反复上传 |
|
|
421
422
|
| `0.6.1` | 修:注入关闭时人设行恒显示「未启用」、点它没有反应(判定把人设一起清空了) |
|
|
422
423
|
| `0.6.0` | 正文移出 `page/catalog.js`、改写成 `page/catalog.json` 按需取,修 Defender `Trojan:Script/Wacatac.C!ml` 误判;配色换莓石;详情改浮层;分组可折叠;整页不滚;模式去掉 off 改由开关控制 |
|
|
423
424
|
| `0.5.0` | 内置技能换成 22 份原文(原为 9 位提炼稿);左栏点行即启用、原文可编辑可删除;两侧等长;修网格行被压扁;人设改为「大肥鱼削弱版」 |
|
package/hooks.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
// 也是这个形状,我们沿用并把「清点」做成自动的。
|
|
10
10
|
//
|
|
11
11
|
// 失败一律 fail-open:改不动就原样放行,绝不把 agent 的请求弄挂。
|
|
12
|
-
import { existsSync, mkdirSync, writeFileSync } from 'node:fs'
|
|
12
|
+
import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from 'node:fs'
|
|
13
13
|
import { dirname, join } from 'node:path'
|
|
14
14
|
import { fileURLToPath } from 'node:url'
|
|
15
15
|
import { compose, rewrite, supported } from './lib/rewrite.mjs'
|
|
@@ -19,8 +19,7 @@ import { ensurePaths, loadCatalog, ownOptions, sync } from './lib/state.mjs'
|
|
|
19
19
|
|
|
20
20
|
const here = dirname(fileURLToPath(import.meta.url))
|
|
21
21
|
|
|
22
|
-
/** inlineEntries 把页面直接贴进来的人设/技能(存在 options.inline 里)并进候选。 */
|
|
23
|
-
export function inlineEntries(options = {}) {
|
|
22
|
+
/** inlineEntries 把页面直接贴进来的人设/技能(存在 options.inline 里)并进候选。 */export function inlineEntries(options = {}) {
|
|
24
23
|
const list = Array.isArray(options.inline) ? options.inline : []
|
|
25
24
|
return list
|
|
26
25
|
.filter((e) => e && typeof e.id === 'string' && typeof e.text === 'string' && e.text.trim())
|
|
@@ -38,6 +37,36 @@ export function inlineEntries(options = {}) {
|
|
|
38
37
|
}))
|
|
39
38
|
}
|
|
40
39
|
|
|
40
|
+
/**
|
|
41
|
+
* builtinText 现读一条条目的正文。
|
|
42
|
+
*
|
|
43
|
+
* 快照里不再存正文:内置技能是一批红队手册,聚进任何单个文件都会被
|
|
44
|
+
* Defender 当成脚本载荷反复上传。这里按 source.root/rel 直接读原文件,
|
|
45
|
+
* 每次注入最多读几条,代价很小;用 (路径, mtime, 大小) 做键缓存,
|
|
46
|
+
* 文件没变就不重复读。
|
|
47
|
+
*/
|
|
48
|
+
const textCache = new Map()
|
|
49
|
+
function builtinText(e) {
|
|
50
|
+
if (typeof e.text === 'string' && e.text.trim()) return e.text
|
|
51
|
+
const root = e.source?.root
|
|
52
|
+
const rel = e.source?.rel
|
|
53
|
+
if (!root || !rel) return ''
|
|
54
|
+
const file = join(root, rel)
|
|
55
|
+
try {
|
|
56
|
+
const st = statSync(file)
|
|
57
|
+
const key = `${file}|${st.mtimeMs}|${st.size}`
|
|
58
|
+
const hit = textCache.get(key)
|
|
59
|
+
if (hit !== undefined) return hit
|
|
60
|
+
const body = readFileSync(file, 'utf8')
|
|
61
|
+
// 只留最近 64 条:一次注入只用到几条,缓存是为了省重复读,不是当索引
|
|
62
|
+
if (textCache.size > 64) textCache.clear()
|
|
63
|
+
textCache.set(key, body)
|
|
64
|
+
return body
|
|
65
|
+
} catch {
|
|
66
|
+
return ''
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
41
70
|
/** pick 选出这一次要注入的文本:人设一条,显式启用的技能若干。 */
|
|
42
71
|
export function pick(catalog, options = {}, state = null, agent = '') {
|
|
43
72
|
// applyPrefs 先套「用户改过/删过」的结果:页面上编辑过的正文与删掉的条目
|
|
@@ -46,7 +75,12 @@ export function pick(catalog, options = {}, state = null, agent = '') {
|
|
|
46
75
|
[...(Array.isArray(catalog?.entries) ? catalog.entries : []), ...inlineEntries(options)],
|
|
47
76
|
options,
|
|
48
77
|
)
|
|
49
|
-
const usable = entries
|
|
78
|
+
const usable = entries
|
|
79
|
+
.filter((e) => e.status === 'ok' && e.injectable)
|
|
80
|
+
// 快照里没有正文(见 inventory.snapshotOf 的注释:聚起来会被 Defender 判毒),
|
|
81
|
+
// 这里按 source.root/rel 现读。读不到就跳过,不静默塞空串。
|
|
82
|
+
.map((e) => (builtinText(e) ? { ...e, text: builtinText(e) } : e))
|
|
83
|
+
.filter((e) => typeof e.text === 'string' && e.text.trim())
|
|
50
84
|
const pinned = options.pinned && typeof options.pinned === 'object' ? options.pinned : {}
|
|
51
85
|
|
|
52
86
|
/** resolve 按 pinned 取版本:固定到某一版时用那一版的正文,找不到就如实报告。 */
|
package/lib/inventory.mjs
CHANGED
|
@@ -475,8 +475,9 @@ export function mergeEntries(fresh, previous = []) {
|
|
|
475
475
|
}
|
|
476
476
|
const versions = (byId.get(entry.id) || []).filter((e) => e.digest !== entry.digest)
|
|
477
477
|
const version = versions.length + 1
|
|
478
|
-
//
|
|
479
|
-
|
|
478
|
+
// 历史只留摘要与时间:正文同样不落盘(理由见 snapshotOf 里那条注释)。
|
|
479
|
+
// 回滚要正文时去读那一版的源文件;没有源文件就如实报告,不再存副本。
|
|
480
|
+
const history = versions.slice(0, 2).map((v) => ({ digest: v.digest, at: v.importedAt, version: v.version, text: '' }))
|
|
480
481
|
const next = { ...entry, version, history }
|
|
481
482
|
byId.set(entry.id, [next, ...(byId.get(entry.id) || [])])
|
|
482
483
|
byDigest.set(next.digest, next)
|
|
@@ -513,8 +514,11 @@ export function snapshotOf(entries, sources, rejected, { version = 0, now = Date
|
|
|
513
514
|
injectable: e.injectable,
|
|
514
515
|
builtin: e.builtin === true,
|
|
515
516
|
default: e.default === true,
|
|
516
|
-
//
|
|
517
|
-
|
|
517
|
+
// 正文**不进快照**:内置技能是一批红队手册,把它们聚进任何单个文件
|
|
518
|
+
// (.js 或 .json 都一样)都会被 Defender 当成脚本载荷,反复上传做云端分析。
|
|
519
|
+
// 注入时由 hooks.js 按 source.root/rel 现读原文。页面只需要
|
|
520
|
+
// 「有没有正文、多少字」——那就是 injectable 与 chars。
|
|
521
|
+
text: '',
|
|
518
522
|
})),
|
|
519
523
|
rejected,
|
|
520
524
|
options,
|
package/lib/state.mjs
CHANGED
|
@@ -231,7 +231,11 @@ export function sync(here, options = {}, { force = false, limits = LIMITS, now =
|
|
|
231
231
|
duplicates: duplicates.map((d) => ({ name: d.name, rel: d.source.rel, root: d.source.root })),
|
|
232
232
|
imports: importRows,
|
|
233
233
|
}
|
|
234
|
-
|
|
234
|
+
// 落盘前把正文全部摘掉:state/catalog.json 以前是「所有手册的合集副本」,
|
|
235
|
+
// 被 Defender 当成脚本载荷反复上载。正文始终留在原文件里,
|
|
236
|
+
// 注入时由 hooks.js 按 source.root/rel 现读(见 builtinText)。
|
|
237
|
+
const persisted = { ...catalog, entries: entries.map((e) => (e.text ? { ...e, text: '' } : e)) }
|
|
238
|
+
writeFileSync(p.catalogFile, JSON.stringify(persisted, null, 2), 'utf8')
|
|
235
239
|
const snapshot = snapshotFrom(p, catalog, options, now)
|
|
236
240
|
const wrote = writeSnapshotIfChanged(p, snapshot)
|
|
237
241
|
return { catalog, changed: true, snapshot, snapshotWritten: wrote.ok, snapshotError: wrote.error }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fish-under-sea/magpie-purge",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.2",
|
|
4
4
|
"description": "magpie-purge: a magpie page plugin that treats a local purge folder as a free plugin/skill source, inspects and validates what is in it, and rewrites the gateway's system prompt by mode (off / strict / replace / append).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
package/page/app.js
CHANGED
|
@@ -1396,7 +1396,7 @@
|
|
|
1396
1396
|
if (typeof e?.text === 'string' && e.text.trim()) bodyText.set(e.id, e.text)
|
|
1397
1397
|
}
|
|
1398
1398
|
textsState = bodyText.size ? 'ready' : 'blocked'
|
|
1399
|
-
if (!bodyText.size) textsError = '
|
|
1399
|
+
if (!bodyText.size) textsError = '正文不落盘:注入时才从原文件读,页面这一份只有元数据'
|
|
1400
1400
|
render()
|
|
1401
1401
|
if (selected) renderInspector()
|
|
1402
1402
|
}
|
package/page/index.html
CHANGED
|
@@ -6,11 +6,11 @@
|
|
|
6
6
|
<title>破甲 · Purge</title>
|
|
7
7
|
<script src="_magpie/bridge.js"></script>
|
|
8
8
|
<script src="catalog.js"></script>
|
|
9
|
-
<!-- ?v=0.6.
|
|
9
|
+
<!-- ?v=0.6.2 是占位:tools/prepack.mjs 打包时换成真实版本号,postpack 换回来。
|
|
10
10
|
没有它,更新插件后浏览器可能一直用缓存的旧 app.js / style.css。 -->
|
|
11
|
-
<script src="plan.js?v=0.6.
|
|
12
|
-
<link rel="stylesheet" href="style.css?v=0.6.
|
|
13
|
-
<script src="app.js?v=0.6.
|
|
11
|
+
<script src="plan.js?v=0.6.2"></script>
|
|
12
|
+
<link rel="stylesheet" href="style.css?v=0.6.2">
|
|
13
|
+
<script src="app.js?v=0.6.2" defer></script>
|
|
14
14
|
</head>
|
|
15
15
|
<body>
|
|
16
16
|
|