lingshu-skill 5.67.0 → 5.69.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/CHANGELOG.md +32 -0
- package/README.md +1 -1
- package/SKILL-lite.md +1 -1
- package/SKILL-tiny.md +1 -1
- package/SKILL.md +1 -1
- package/assets/panel.html +11 -3
- package/cordis-plugin/lingshu-cron/plugin.js +59 -19
- package/cordis-plugin/lingshu-guard/plugin.js +34 -10
- package/cordis-plugin/lingshu-im/plugin.js +19 -2
- package/cordis-plugin/lingshu-startup/context-fold.js +5 -1
- package/cordis-plugin/lingshu-startup/context-pressure.js +129 -110
- package/cordis-plugin/lingshu-startup/plugin.js +9 -1
- package/index.js +26 -21
- package/manifest.json +29 -29
- package/package.json +1 -1
- package/scripts/astrbot_plugin_lingshu/CHECKSUMS.json +8 -8
- package/scripts/astrbot_plugin_lingshu/engine/CHANGELOG.md +32 -0
- package/scripts/astrbot_plugin_lingshu/engine/README.md +1 -1
- package/scripts/astrbot_plugin_lingshu/engine/SKILL-lite.md +1 -1
- package/scripts/astrbot_plugin_lingshu/engine/SKILL-tiny.md +1 -1
- package/scripts/astrbot_plugin_lingshu/engine/SKILL.md +1 -1
- package/scripts/astrbot_plugin_lingshu/engine/assets/panel.html +11 -3
- package/scripts/astrbot_plugin_lingshu/engine/scripts/panel_data.py +17 -3
- package/scripts/astrbot_plugin_lingshu/engine/scripts/panel_settings.py +24 -1
- package/scripts/panel_data.py +17 -3
- package/scripts/panel_settings.py +24 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,37 @@
|
|
|
1
1
|
# 更新日志
|
|
2
2
|
|
|
3
|
+
## v5.69(2026-12-05)
|
|
4
|
+
|
|
5
|
+
### 🛡️ 150 项审计第十三批:Cordis IM 安全与面板设置组大收官
|
|
6
|
+
|
|
7
|
+
1. **LS-093(高·guard 注册失败拒绝态)**:`lingshu-guard` 注册全部失败时进入 deny-all——所有工具调用直接拒绝并给明确诊断,IM 鉴权绝不裸奔。
|
|
8
|
+
2. **LS-094(高·IM 授权跟随真实 HOME)**:`lingshu-im` 的 `memoryHome()` 与 Python 一致解析 `.home` 指针,旧默认目录的 consent.json 不再覆盖真实库授权。
|
|
9
|
+
3. **LS-095(高·群聊缺 chatId fail-closed)**:群聊消息无有效 chatId 时返回 null 拒绝召回/写回,绝不降级成私聊作用域。
|
|
10
|
+
4. **LS-099(高·SKILL.md 缺失仍挂 guard)**:`index.js` 技能文档注册失败不再阻断 guard 等安全组件挂载。
|
|
11
|
+
5. **LS-101(中·只读白名单移除 todo_write)**:`lingshu-guard` 的 `DEFAULT_READ_ONLY` 移除有写副作用的 `todo_write`。
|
|
12
|
+
6. **LS-102(中·cron 消息去重键)**:mid 规范统一为 `${role}:${mid}`,user/assistant 同数字 id 不再互相误判。
|
|
13
|
+
7. **LS-103(中·selfReviewDays 真正控制间隔)**:`dueByDays` 按真实日期差��算到期,配 3 天不再每天执行。
|
|
14
|
+
8. **LS-109(中·extract 只收集真实对话)**:工具/系统/插件注入消息不进对话缓冲,防自我吞噬。
|
|
15
|
+
9. **LS-111(中·cron 状态原子保存)**:`saveState` 不再先删旧状态,rename 失败时旧状态原样保留。
|
|
16
|
+
10. **LS-112(中·prior 排除插件注入)**:`lastUserText` 检查 source.name/kind,cron/IM 注入不触发无关 prior 检索。
|
|
17
|
+
11. **LS-113(中·token 标定 HOME 修复)**:`_calibPaths` 改用已有的 `memoryHome()`,修复 readBrainHome 未定义。
|
|
18
|
+
12. **LS-114(中·顶层 checkpoint 识别)**:`context-fold.js` 三个位置检查 compact-checkpoint 来源。
|
|
19
|
+
13. **LS-074(中·损坏 manifest 字段容错)**:`panel_data.py` 单条记录字段级容错,正常备份照常展示。
|
|
20
|
+
14. **LS-075/077(中·enum 设置与 NaN 拒绝)**:`panel_settings.py` 支持 enum 类型校验;float 拒绝 NaN/Infinity。
|
|
21
|
+
15. **LS-076/084(中·enum 渲染与体检契约)**:前端 enum 渲染为 select;dochealth 统一走 api() 并以 items 为准。
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## v5.68(2026-12-04)
|
|
26
|
+
|
|
27
|
+
### 🔧 150 项审计第十二批:Cordis 插件多 Agent 隔离修复
|
|
28
|
+
|
|
29
|
+
1. **LS-096**:`context-pressure.js` 压力快照按会话分文件(`.context-pressure-<sid>.json`),验证一个会话水位不会触发另一个会话自救。
|
|
30
|
+
2. **LS-100**:`cron plugin.js` 的 `writePressure` 按会话隔离 `_pressure.json`,A/B 水位和注入档位互不影响。
|
|
31
|
+
3. **LS-104**:cron 运行互斥粒度改为每 Agent + 任务名(`runningByAgent` Map),A 运行期间 B 的 extract/usage/speakup 不被丢弃。
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
3
35
|
## v5.67(2026-12-04)
|
|
4
36
|
|
|
5
37
|
### 🔒 150 项审计第十一批:面板云端与 IM 鉴权组闭环修复
|
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
> 名字取自《黄帝内经》:**算力给思考,人格给灵魂,记忆给生命。**
|
|
4
4
|
|
|
5
|
-
>
|
|
5
|
+
> 当��版本 **v5.69**(变更见 [CHANGELOG.md](CHANGELOG.md))
|
|
6
6
|
|
|
7
7
|
> 🔁 **双仓库镜像**:GitHub(主)与 Gitee(镜像)保持同步——[gitee.com/htmcwy_0/lingshu-skill](https://gitee.com/htmcwy_0/lingshu-skill)。灵枢的更新检查会探测两边最新提交,**谁更新就自动从谁拉取**;任一边不可达(Gitee 匿名风控 / GitHub 限额)时走另一边兜底。
|
|
8
8
|
|
package/SKILL-lite.md
CHANGED
package/SKILL-tiny.md
CHANGED
package/SKILL.md
CHANGED
package/assets/panel.html
CHANGED
|
@@ -4250,6 +4250,14 @@ function _settingRow(it){
|
|
|
4250
4250
|
const opts = (it.choices || []).map(c =>
|
|
4251
4251
|
`<option value="${esc(c)}"${String(it.value) === c ? " selected" : ""}>${esc(c)}</option>`).join("");
|
|
4252
4252
|
ctl = `<select id="${id}" data-key="${esc(it.key)}">${opts}</select>`;
|
|
4253
|
+
} else if (it.kind === "enum"){
|
|
4254
|
+
// LS-076(v5.69):enum 设置渲染为选项控件——支持 ["a","b"] 与 [{value,label}] 两种 options
|
|
4255
|
+
const opts = (it.options || []).map(o => {
|
|
4256
|
+
const v = (o && typeof o === "object") ? String(o.value ?? "") : String(o);
|
|
4257
|
+
const label = (o && typeof o === "object") ? String(o.label ?? o.value ?? "") : String(o);
|
|
4258
|
+
return `<option value="${esc(v)}"${String(it.value) === v ? " selected" : ""}>${esc(label)}</option>`;
|
|
4259
|
+
}).join("");
|
|
4260
|
+
ctl = `<select id="${id}" data-key="${esc(it.key)}">${opts}</select>`;
|
|
4253
4261
|
} else {
|
|
4254
4262
|
const step = it.step != null ? it.step : (it.kind === "float" ? 0.05 : 1);
|
|
4255
4263
|
const min = it.min != null ? ` min="${it.min}"` : "";
|
|
@@ -7872,9 +7880,9 @@ setTimeout(() => checkUpdate(true), 1200);
|
|
|
7872
7880
|
const el = body();
|
|
7873
7881
|
if (!el) return;
|
|
7874
7882
|
try {
|
|
7875
|
-
|
|
7876
|
-
const j = await
|
|
7877
|
-
const hist = Array.isArray(j) ? j : (j.history || j.rows || []);
|
|
7883
|
+
// LS-083/084(v5.69):统一 API helper 携带 token;items 字段前后端同一契约
|
|
7884
|
+
const j = await api("/api/doctor-history?limit=90");
|
|
7885
|
+
const hist = Array.isArray(j) ? j : (j.items || j.history || j.rows || []);
|
|
7878
7886
|
if (sum()) {
|
|
7879
7887
|
const st = (!Array.isArray(j) && j.stage) || null;
|
|
7880
7888
|
const g = st ? ` · 成长阶段:${esc(st.name || st.stage || "")}` : "";
|
|
@@ -235,12 +235,15 @@ function loadState(path) {
|
|
|
235
235
|
}
|
|
236
236
|
|
|
237
237
|
function saveState(path, state) {
|
|
238
|
+
// LS-111(v5.69):cron 状态真正原子保存——不得先删除旧状态!
|
|
239
|
+
// 旧实现在 rename 前先 rmSync(path):若 rename 失败或进程崩溃,
|
|
240
|
+
// 旧状态已被删除 → 下次启动 turns/days 全丢,daily/backup 全部重跑。
|
|
241
|
+
// 同目录 rename 本身就是原子的(Windows/POSIX 语义),无需先删旧文件。
|
|
238
242
|
try {
|
|
239
243
|
mkdirSync(dirname(path), { recursive: true })
|
|
240
244
|
const tmp = `${path}.${randomUUID()}.tmp`
|
|
241
245
|
writeFileSync(tmp, JSON.stringify(state, null, 2), 'utf8')
|
|
242
|
-
|
|
243
|
-
renameSync(tmp, path) // 原子替换(同目录 rename)
|
|
246
|
+
renameSync(tmp, path) // 同目录 rename 原子替换;失败时旧状态原样保留
|
|
244
247
|
} catch {}
|
|
245
248
|
}
|
|
246
249
|
|
|
@@ -262,7 +265,18 @@ function agentKey(agent) {
|
|
|
262
265
|
|
|
263
266
|
function dueByDays(task, state) {
|
|
264
267
|
const last = state?.days?.[task.id]
|
|
265
|
-
|
|
268
|
+
// LS-103(v5.69):让 `selfReviewDays` 真正控制间隔!
|
|
269
|
+
// 旧实现只比较"上次执行日 != 今天"——days:N 配 3 天时仍然每天执行。
|
|
270
|
+
// 现在按 task.days 计算真实到期时间:last 日期 + N 天后才算 due。
|
|
271
|
+
const n = Number(task.days) || 1
|
|
272
|
+
if (!last) return true
|
|
273
|
+
if (last === todayStr()) return false
|
|
274
|
+
// 解析本地日期(YYYY-MM-DD),加 N 天与今天比较
|
|
275
|
+
const parts = String(last).split('-').map(Number)
|
|
276
|
+
if (parts.length !== 3 || parts.some(Number.isNaN)) return true
|
|
277
|
+
const lastMs = new Date(parts[0], parts[1] - 1, parts[2]).getTime()
|
|
278
|
+
const due = lastMs + n * 86400 * 1000
|
|
279
|
+
return Date.now() >= due
|
|
266
280
|
}
|
|
267
281
|
|
|
268
282
|
// 按小时间隔判定(P11 #72)。备份原来用 days:1 —— 只在"当天第一次回合"跑一次,
|
|
@@ -410,7 +424,9 @@ const pressureWritten = new Map()
|
|
|
410
424
|
* 把水位写进 `HOME/_pressure.json`(注入侧读它降档)。
|
|
411
425
|
* 只在"跨 5 个百分点"或"跨档"时真写,减少磁盘写;失败静默返回 false。
|
|
412
426
|
*/
|
|
413
|
-
export function writePressure(pct, source, prevMax, extra = null) {
|
|
427
|
+
export function writePressure(pct, source, prevMax, extra = null, agentId = '') {
|
|
428
|
+
// LS-100(v5.68):按会话隔离 _pressure.json!
|
|
429
|
+
// A/B 会话的水位和注入档位互不影响
|
|
414
430
|
try {
|
|
415
431
|
if (pct == null || !Number.isFinite(Number(pct))) return false
|
|
416
432
|
const p = Math.round(Number(pct))
|
|
@@ -420,7 +436,8 @@ export function writePressure(pct, source, prevMax, extra = null) {
|
|
|
420
436
|
const last = pressureWritten.get('last')
|
|
421
437
|
if (last && last.tier === key && Math.abs(p - last.pct) < 5) return false
|
|
422
438
|
pressureWritten.set('last', { pct: p, tier: key })
|
|
423
|
-
const
|
|
439
|
+
const _aid = String(agentId || 'default').replace(/[^a-zA-Z0-9_-]/g, '_').slice(-40)
|
|
440
|
+
const file = join(memoryHome(), agentId ? `_pressure-${_aid}.json` : '_pressure.json')
|
|
424
441
|
const tmp = `${file}.${randomUUID()}.tmp`
|
|
425
442
|
// extra 落盘估算依据(chars / tokens / limit):水位报错时能直接看出是"数漏了"
|
|
426
443
|
// 还是"系数不对",不用再猜。注入侧只读 pct,多出的字段不影响它。
|
|
@@ -561,6 +578,9 @@ export function apply(ctx, config) {
|
|
|
561
578
|
|
|
562
579
|
const turns = new Map() // agent -> 本会话轮次
|
|
563
580
|
const running = new Set() // 防并发:同名任务进行中就不重入
|
|
581
|
+
// LS-104(v5.68):运行键改为 `${agentId}:${taskId}`,不同 Agent 的任务互不互斥。
|
|
582
|
+
// 旧实现全局 Set 按任务名去重:Agent A 在跑 extract 时 Agent B 的 extract/usage/speakup 都被丢弃。
|
|
583
|
+
const runningByAgent = new Map() // `${agentId}:${taskId}` -> true
|
|
564
584
|
const convo = new Map() // agent -> { text, seen }(即记即存缓冲 + 已处理消息游标,extract 成功后清空)
|
|
565
585
|
const lastReply = new Map() // agent -> 最后一条 assistant 文本(给 usage --reply 用)
|
|
566
586
|
const lastUser = new Map() // agent -> 最后一条用户文本(给 speak-up 判"是不是在提问")
|
|
@@ -643,10 +663,16 @@ const waterState = new Map() // agent -> { max } 水位守卫已提醒的最高
|
|
|
643
663
|
|
|
644
664
|
/** fire-and-forget:绝不 await、失败允许下轮补跑一次(当日仅一次,再败等明天)。
|
|
645
665
|
* 返回 false 表示同名任务正在进行、本次没有投递(供水位自动执行如实记账)。 */
|
|
646
|
-
function
|
|
647
|
-
|
|
648
|
-
|
|
666
|
+
function _runKey(agentId, taskId) {
|
|
667
|
+
return (agentId || 'default') + ':' + (taskId || '')
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
function fire(task, agentId) {
|
|
671
|
+
const rk = _runKey(agentId, task.id)
|
|
672
|
+
if (runningByAgent.has(rk)) return false
|
|
673
|
+
runningByAgent.set(rk, true)
|
|
649
674
|
;(async () => {
|
|
675
|
+
const _rk = rk
|
|
650
676
|
try {
|
|
651
677
|
const brainPy = await ensureBrainPy()
|
|
652
678
|
if (!brainPy) {
|
|
@@ -709,7 +735,7 @@ const waterState = new Map() // agent -> { max } 水位守卫已提醒的最高
|
|
|
709
735
|
logTaskFailure(task.id, `执行异常:${err?.message || String(err)}`)
|
|
710
736
|
}
|
|
711
737
|
finally {
|
|
712
|
-
|
|
738
|
+
runningByAgent.delete(_rk || task.id)
|
|
713
739
|
}
|
|
714
740
|
})()
|
|
715
741
|
return true
|
|
@@ -788,11 +814,12 @@ const waterState = new Map() // agent -> { max } 水位守卫已提醒的最高
|
|
|
788
814
|
* 失败保留缓冲下轮重试。fire-and-forget 三铁律同样适用。
|
|
789
815
|
*/
|
|
790
816
|
function fireExtract(agent) {
|
|
791
|
-
|
|
817
|
+
const rk = _runKey(agent?.id || agent, 'extract')
|
|
818
|
+
if (runningByAgent.has(rk)) return
|
|
792
819
|
const buf = convo.get(agent)
|
|
793
820
|
const text = (buf?.text || '').trim()
|
|
794
821
|
if (!text || text.length < cfg.extractMinChars) return // 没攒够有信息量的内容,不跑
|
|
795
|
-
|
|
822
|
+
runningByAgent.set(rk, true)
|
|
796
823
|
;(async () => {
|
|
797
824
|
let ok = false
|
|
798
825
|
try {
|
|
@@ -826,7 +853,7 @@ const waterState = new Map() // agent -> { max } 水位守卫已提醒的最高
|
|
|
826
853
|
try { ctx.logger?.warn?.(`[lingshu-cron] extract 失败且缓冲超 200k,截断保留前 100k 字符(已丢失 ${(text.length - 100_000)} 字符)`) } catch {}
|
|
827
854
|
convo.set(agent, { text: text.slice(0, 100_000), seen: buf?.seen })
|
|
828
855
|
}
|
|
829
|
-
|
|
856
|
+
runningByAgent.delete(rk)
|
|
830
857
|
}
|
|
831
858
|
})()
|
|
832
859
|
}
|
|
@@ -835,9 +862,10 @@ const waterState = new Map() // agent -> { max } 水位守卫已提醒的最高
|
|
|
835
862
|
// 四道闸全在 Python 侧(概率/冷却/理智/是否提问),插件不做判断、不重复实现,
|
|
836
863
|
// 避免两边规则漂移。失败一律静默——它是锦上添花,绝不能拖住回合。
|
|
837
864
|
function fireSpeakUp(agent) {
|
|
838
|
-
|
|
865
|
+
const rk_sp = _runKey(agent?.id || agent, 'speakup')
|
|
866
|
+
if (runningByAgent.has(rk_sp)) return
|
|
839
867
|
const stmt = (lastUser.get(agent) || '').trim()
|
|
840
|
-
|
|
868
|
+
runningByAgent.set(rk_sp, true)
|
|
841
869
|
;(async () => {
|
|
842
870
|
try {
|
|
843
871
|
const brainPy = await ensureBrainPy()
|
|
@@ -861,7 +889,7 @@ const waterState = new Map() // agent -> { max } 水位守卫已提醒的最高
|
|
|
861
889
|
} finally {
|
|
862
890
|
try { rmSync(tmp, { force: true }) } catch {}
|
|
863
891
|
}
|
|
864
|
-
} catch {} finally {
|
|
892
|
+
} catch {} finally { runningByAgent.delete(rk_sp) }
|
|
865
893
|
})()
|
|
866
894
|
}
|
|
867
895
|
|
|
@@ -943,7 +971,11 @@ const waterState = new Map() // agent -> { max } 水位守卫已提醒的最高
|
|
|
943
971
|
|
|
944
972
|
function _calibPaths() {
|
|
945
973
|
try {
|
|
946
|
-
|
|
974
|
+
// LS-113(v5.69):修复 token 标定的 HOME 获取函数!
|
|
975
|
+
// 旧代码调用了不存在的 readBrainHome() → ReferenceError → 样本永远写不进、
|
|
976
|
+
// 已有拟合也读不到。本文件已有的 memoryHome() 就是权威实现(BRAIN_MEMORY_HOME
|
|
977
|
+
// > .home 指针 > ~/.brain-memory),直接复用。
|
|
978
|
+
const home = memoryHome()
|
|
947
979
|
if (!home) return null
|
|
948
980
|
return { samples: join(home, 'token-calib.jsonl'), fit: join(home, 'token-calib.json') }
|
|
949
981
|
} catch { return null }
|
|
@@ -1248,10 +1280,18 @@ const waterState = new Map() // agent -> { max } 水位守卫已提醒的最高
|
|
|
1248
1280
|
let lastAsst = lastReply.get(agent) || ''
|
|
1249
1281
|
let batchIds = []
|
|
1250
1282
|
for (const m of msgs) {
|
|
1283
|
+
// LS-109(v5.69):extract 只收集允许的真实对话来源!
|
|
1284
|
+
// 工具输出、系统消息及灵枢各插件注入的内容不进对话缓冲——
|
|
1285
|
+
// 敏感工具输出和已有记忆块不能被再次摄入(自我吞噬)。
|
|
1286
|
+
if (m?.role !== 'user' && m?.role !== 'assistant') continue
|
|
1287
|
+
if (m?.source?.name && LINGSHU_SOURCES.has(m.source.name)) continue
|
|
1251
1288
|
const mid = m?.id
|
|
1252
1289
|
if (mid != null) {
|
|
1253
|
-
|
|
1254
|
-
|
|
1290
|
+
// LS-102(v5.69):修复消息 ID 去重键——统一用 `${role}:${mid}` 规范,
|
|
1291
|
+
// 同一数字 id 在 user/assistant 两个角色下不再互相误判为重复。
|
|
1292
|
+
const normMid = `${m.role}:${mid}`
|
|
1293
|
+
if (seenIds.has(normMid)) continue // 上一步已攒过这条,跳过(只加增量)
|
|
1294
|
+
batchIds.push(normMid)
|
|
1255
1295
|
}
|
|
1256
1296
|
for (const c of (Array.isArray(m?.content) ? m.content : [])) {
|
|
1257
1297
|
if (c?.type === 'text' && typeof c.text === 'string' && c.text.trim()) {
|
|
@@ -1358,7 +1398,7 @@ const waterState = new Map() // agent -> { max } 水位守卫已提醒的最高
|
|
|
1358
1398
|
// v3.57(保护 A 的写入端):把真实水位落成 HOME/_pressure.json,注入侧
|
|
1359
1399
|
// (memory.build_injection 读 core.read_pressure)据此整体降档。
|
|
1360
1400
|
// 每跨 5 个百分点或跨档时写一次,避免每步都写盘;失败静默(不能拖住 pre-step)。
|
|
1361
|
-
writePressure(pct, est?.source || 'unknown', st.max || 0, est)
|
|
1401
|
+
writePressure(pct, est?.source || 'unknown', st.max || 0, est, agent?.id || agent?.name || '')
|
|
1362
1402
|
|
|
1363
1403
|
// v3.57(保护 B):95 / 98 两个硬档。90 仍是"建议"(用户可能还想继续干活),
|
|
1364
1404
|
// 95 改命令式,98 起自动做**无破坏性**自救(auto-archive 只打归档标记、
|
|
@@ -61,9 +61,10 @@ export const name = 'dsh-lingshu-guard'
|
|
|
61
61
|
const DEFAULT_READ_ONLY = [
|
|
62
62
|
'list_agents',
|
|
63
63
|
'skill',
|
|
64
|
-
'todo_write',
|
|
65
64
|
'ask_user_question',
|
|
66
65
|
]
|
|
66
|
+
// LS-101(v5.69):从只读白名单移除 `todo_write`——它有写副作用(修改用户的
|
|
67
|
+
// 任务列表),非 owner 不应通过 IM 操纵宿主的待办清单。
|
|
67
68
|
|
|
68
69
|
// guard 段默认值。shadow 默认 false:默认就拦(安全优先),不再"只记日志不拦"。
|
|
69
70
|
// 需要先观察误伤时显式设 shadow=true,启动会打 warn(观察模式,敏感命令不拦)。
|
|
@@ -452,13 +453,27 @@ export function apply(ctx, config) {
|
|
|
452
453
|
} catch { /* 坏载荷忽略 */ }
|
|
453
454
|
})
|
|
454
455
|
|
|
455
|
-
const check = (exec, agent) =>
|
|
456
|
+
const check = (exec, agent) => {
|
|
457
|
+
// LS-093(v5.69):注册失败的 agent 进入拒绝态——所有工具调用直接拒绝
|
|
458
|
+
if (isRegistrationFailed(agent)) {
|
|
459
|
+
return 'lingshu-guard: 守卫注册失败(deny-all 拒绝态),工具调用被拒绝。请检查宿主 dsh-tools 版本或重启会话。'
|
|
460
|
+
}
|
|
461
|
+
return checkTool(ctx, bindings, hostConfig, exec, agent, knownImSessions)
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
// LS-093: 注册失败的 agent 集合——这些 agent 的工具调用一律拒绝
|
|
465
|
+
const guardRegistrationFailed = new Set()
|
|
466
|
+
|
|
467
|
+
function isRegistrationFailed(agent) {
|
|
468
|
+
return guardRegistrationFailed.has(agent?.id || agent?.name || 'default')
|
|
469
|
+
}
|
|
456
470
|
|
|
457
471
|
/**
|
|
458
472
|
* 给一个 agent 注册守卫。注册在 agent.ctx 上,作用域随 agent 销毁自动释放:
|
|
459
473
|
* 对话结束、会话删除、agent 重建都不会留下悬挂的守卫或重复注册。
|
|
460
474
|
*/
|
|
461
475
|
function registerFor(agent) {
|
|
476
|
+
let registered = false
|
|
462
477
|
try {
|
|
463
478
|
const agentCtx = agent?.ctx
|
|
464
479
|
if (!agentCtx || typeof agentCtx.on !== 'function') return
|
|
@@ -470,19 +485,28 @@ export function apply(ctx, config) {
|
|
|
470
485
|
try {
|
|
471
486
|
// 首选:单调执行守卫(dsh-tools 的正式 API)。
|
|
472
487
|
tools.guard((exec) => check(exec, agent))
|
|
473
|
-
|
|
488
|
+
registered = true
|
|
474
489
|
} catch (error) {
|
|
475
490
|
warn('lingshu-guard: tools.guard 注册失败,退回 tools/pre-execute', error)
|
|
476
491
|
}
|
|
477
492
|
}
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
493
|
+
if (!registered) {
|
|
494
|
+
// 旧宿主降级:pre-execute waterfall 里做同样的判定。
|
|
495
|
+
agentCtx.on('tools/pre-execute', async (exec, next) => {
|
|
496
|
+
const reason = check(exec, agent)
|
|
497
|
+
if (reason) return { kind: 'deny', reason }
|
|
498
|
+
return next()
|
|
499
|
+
})
|
|
500
|
+
registered = true
|
|
501
|
+
}
|
|
484
502
|
} catch (error) {
|
|
485
|
-
|
|
503
|
+
// LS-093(v5.69):注册失败进入拒绝态!
|
|
504
|
+
// 两种注册路径都失败 = 本 agent 的 IM 鉴权完全没生效,此时放行任何工具
|
|
505
|
+
// 等于裸奔。进入 deny-all:所有工具调用直接拒绝并给明确诊断。
|
|
506
|
+
guardRegistrationFailed.add(agent?.id || agent?.name || 'default')
|
|
507
|
+
warn('lingshu-guard: 守卫注册全部失败,本 agent 进入拒绝态(deny-all);'
|
|
508
|
+
+ '请检查宿主 dsh-tools 版本。诊断:'
|
|
509
|
+
+ (error?.message || String(error)).slice(0, 200), error)
|
|
486
510
|
}
|
|
487
511
|
}
|
|
488
512
|
|
|
@@ -252,7 +252,13 @@ function toIdentity(described) {
|
|
|
252
252
|
if (!sender) return null
|
|
253
253
|
const user = `${channel}:${enc(sender)}`
|
|
254
254
|
const chatType = String(described.chatType || '').trim()
|
|
255
|
+
// LS-095(v5.69):群聊缺少有效 chatId 时 fail-closed!
|
|
256
|
+
// 旧代码 group 为空串时照常处理——召回/写回会降级成私聊作用域,
|
|
257
|
+
// 群消息被错误地记到个人名下(隐私越界)。现在返回 null 让上层拒绝。
|
|
255
258
|
const group = chatType && chatType !== 'dm' ? String(described.chatId || '').trim() : ''
|
|
259
|
+
if (chatType && chatType !== 'dm' && !group) {
|
|
260
|
+
return null // 群聊无有效 chatId:禁止召回和写回,绝不降级成私聊作用域
|
|
261
|
+
}
|
|
256
262
|
return {
|
|
257
263
|
channel,
|
|
258
264
|
user,
|
|
@@ -362,8 +368,19 @@ export function apply(ctx, config) {
|
|
|
362
368
|
return found
|
|
363
369
|
}
|
|
364
370
|
|
|
365
|
-
/** 记忆目录:配置 > 宿主环境变量 > ~/.brain-memory(与 brain.py 默认一致)。
|
|
366
|
-
|
|
371
|
+
/** 记忆目录:配置 > 宿主环境变量 > .home 指针 > ~/.brain-memory(与 brain.py 默认一致)。
|
|
372
|
+
* LS-094(v5.69):授权读取跟随真实记忆 HOME——与 Python 一样解析 .home 指针文件,
|
|
373
|
+
* 旧默认目录的 consent.json 不再覆盖真实库的授权。 */
|
|
374
|
+
const memoryHome = () => {
|
|
375
|
+
if (cfg.memoryHome) return cfg.memoryHome
|
|
376
|
+
if (process.env.BRAIN_MEMORY_HOME) return process.env.BRAIN_MEMORY_HOME
|
|
377
|
+
const base = join(homedir(), '.brain-memory')
|
|
378
|
+
try {
|
|
379
|
+
const ptr = readFileSync(join(base, '.home'), 'utf8').trim()
|
|
380
|
+
if (ptr) return ptr
|
|
381
|
+
} catch { /* 没有指针文件就用默认���录 */ }
|
|
382
|
+
return base
|
|
383
|
+
}
|
|
367
384
|
|
|
368
385
|
/** 自动写回授权(consent.json 的 capture 字段),按文件 mtime 缓存:改完下一条即生效。 */
|
|
369
386
|
function captureAllowed(user) {
|
|
@@ -87,8 +87,12 @@ export function applyFolds(decision, maxChars = 1600) {
|
|
|
87
87
|
// 所以:只要本次请求里出现 hub 的 checkpoint,就让位给宿主(只记一次日志,不打扰)。
|
|
88
88
|
try {
|
|
89
89
|
const hasHostCheckpoint = msgs.some((m) => {
|
|
90
|
+
// LS-114(v5.69):识别顶层 checkpoint 来源!
|
|
91
|
+
// 旧代码只检查 m.data.source / m.data.message.source——宿主在某些路径下
|
|
92
|
+
// 把 source 挂在**消息顶层**(m.source),这类 checkpoint 会被漏检,
|
|
93
|
+
// 导致宿主已压缩我们又重复折叠。现在三个位置都查。
|
|
90
94
|
const d = m?.data
|
|
91
|
-
const src = d?.source ?? d?.message?.source
|
|
95
|
+
const src = d?.source ?? d?.message?.source ?? m?.source
|
|
92
96
|
return src && src.kind === 'compact-checkpoint'
|
|
93
97
|
})
|
|
94
98
|
if (hasHostCheckpoint) {
|
|
@@ -1,110 +1,129 @@
|
|
|
1
|
-
// 灵枢 · 上下文压力采集器
|
|
2
|
-
//
|
|
3
|
-
// 为什么需要它:DSH 宿主注入的"上下文估算约 X%(来源:chars)"是字符粗估,
|
|
4
|
-
// 实测偏低(用户看到 14%、真实 39%)。DSH 官方有准确的 token 计量服务:
|
|
5
|
-
// ctx.tokenMeter.contextPressure(session) -> { pressureTokens, contextWindow }
|
|
6
|
-
// 但灵枢主体是 Python 进程(brain.py),拿不到 Cordis ctx。本模块在 DSH 插件层
|
|
7
|
-
// (JS,有 ctx)每步读一次准确压力,写到 HOME/.context-pressure.json,
|
|
8
|
-
// brain.py check-context / startup 注入再读这个文件——补上"没实时上下文可测"的缺口。
|
|
9
|
-
//
|
|
10
|
-
// 设计约束:
|
|
11
|
-
// - 只读 DSH 服务、只写 HOME 下一个小 JSON;绝不改 profile/注入文本;
|
|
12
|
-
// - 任何异常都吞掉(pre-step 是 wrapping 监听器,抛异常会破坏请求);
|
|
13
|
-
// - ctx.tokenMeter 不存在(旧版 DSH/未挂载)时静默跳过,写 availability=false 让 Python 侧知道。
|
|
14
|
-
|
|
15
|
-
import { readFileSync, rmSync, writeFileSync } from 'node:fs'
|
|
16
|
-
import { homedir } from 'node:os'
|
|
17
|
-
import { join } from 'node:path'
|
|
18
|
-
|
|
19
|
-
const asText = (v) => String(v ?? '').trim()
|
|
20
|
-
|
|
21
|
-
/** 记忆目录:BRAIN_MEMORY_HOME > ~/.brain-memory/.home 指针 > ~/.brain-memory。 */
|
|
22
|
-
function memoryHome() {
|
|
23
|
-
const env = asText(process.env.BRAIN_MEMORY_HOME)
|
|
24
|
-
if (env) return env
|
|
25
|
-
const base = join(homedir(), '.brain-memory')
|
|
26
|
-
try {
|
|
27
|
-
const ptr = asText(readFileSync(join(base, '.home'), 'utf8'))
|
|
28
|
-
if (ptr) return ptr
|
|
29
|
-
} catch { /* 没有指针文件就用默认目录 */ }
|
|
30
|
-
return base
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* 采集一次上下文压力并落盘。由 startup 插件在 agent/pre-step 里调用。
|
|
35
|
-
* @param ctx Cordis 上下文(需有 tokenMeter 服务)
|
|
36
|
-
* @param agent 当前 agent(用于取 session)
|
|
37
|
-
*/
|
|
38
|
-
export function sampleContextPressure(ctx, agent) {
|
|
39
|
-
const out = {
|
|
40
|
-
ts: Math.floor(Date.now() / 1000),
|
|
41
|
-
available: false,
|
|
42
|
-
source: 'token-meter',
|
|
43
|
-
pressure_tokens: null,
|
|
44
|
-
context_window: null,
|
|
45
|
-
pct: null,
|
|
46
|
-
}
|
|
47
|
-
let file = ''
|
|
48
|
-
try {
|
|
49
|
-
const dir = memoryHome()
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
out.
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
1
|
+
// 灵枢 · 上下文压力采集器
|
|
2
|
+
//
|
|
3
|
+
// 为什么需要它:DSH 宿主注入的"上下文估算约 X%(来源:chars)"是字符粗估,
|
|
4
|
+
// 实测偏低(用户看到 14%、真实 39%)。DSH 官方有准确的 token 计量服务:
|
|
5
|
+
// ctx.tokenMeter.contextPressure(session) -> { pressureTokens, contextWindow }
|
|
6
|
+
// 但灵枢主体是 Python 进程(brain.py),拿不到 Cordis ctx。本模块在 DSH 插件层
|
|
7
|
+
// (JS,有 ctx)每步读一次准确压力,写到 HOME/.context-pressure.json,
|
|
8
|
+
// brain.py check-context / startup 注入再读这个文件——补上"没实时上下文可测"的缺口。
|
|
9
|
+
//
|
|
10
|
+
// 设计约束:
|
|
11
|
+
// - 只读 DSH 服务、只写 HOME 下一个小 JSON;绝不改 profile/注入文本;
|
|
12
|
+
// - 任何异常都吞掉(pre-step 是 wrapping 监听器,抛异常会破坏请求);
|
|
13
|
+
// - ctx.tokenMeter 不存在(旧版 DSH/未挂载)时静默跳过,写 availability=false 让 Python 侧知道。
|
|
14
|
+
|
|
15
|
+
import { readFileSync, rmSync, writeFileSync } from 'node:fs'
|
|
16
|
+
import { homedir } from 'node:os'
|
|
17
|
+
import { join } from 'node:path'
|
|
18
|
+
|
|
19
|
+
const asText = (v) => String(v ?? '').trim()
|
|
20
|
+
|
|
21
|
+
/** 记忆目录:BRAIN_MEMORY_HOME > ~/.brain-memory/.home 指针 > ~/.brain-memory。 */
|
|
22
|
+
function memoryHome() {
|
|
23
|
+
const env = asText(process.env.BRAIN_MEMORY_HOME)
|
|
24
|
+
if (env) return env
|
|
25
|
+
const base = join(homedir(), '.brain-memory')
|
|
26
|
+
try {
|
|
27
|
+
const ptr = asText(readFileSync(join(base, '.home'), 'utf8'))
|
|
28
|
+
if (ptr) return ptr
|
|
29
|
+
} catch { /* 没有指针文件就用默认目录 */ }
|
|
30
|
+
return base
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* 采集一次上下文压力并落盘。由 startup 插件在 agent/pre-step 里调用。
|
|
35
|
+
* @param ctx Cordis 上下文(需有 tokenMeter 服务)
|
|
36
|
+
* @param agent 当前 agent(用于取 session)
|
|
37
|
+
*/
|
|
38
|
+
export function sampleContextPressure(ctx, agent) {
|
|
39
|
+
const out = {
|
|
40
|
+
ts: Math.floor(Date.now() / 1000),
|
|
41
|
+
available: false,
|
|
42
|
+
source: 'token-meter',
|
|
43
|
+
pressure_tokens: null,
|
|
44
|
+
context_window: null,
|
|
45
|
+
pct: null,
|
|
46
|
+
}
|
|
47
|
+
let file = ''
|
|
48
|
+
try {
|
|
49
|
+
const dir = memoryHome()
|
|
50
|
+
const session = agent?.session ?? null
|
|
51
|
+
// LS-096(v5.68):按会话隔离 tokenMeter 压力快照!
|
|
52
|
+
// 旧实现所有会话共用一个 .context-pressure.json,A 会话的水位会触发 B 会话自救。
|
|
53
|
+
const _sid = String(session?.id ?? session ?? 'default').replace(/[^a-zA-Z0-9_-]/g, '_').slice(-40)
|
|
54
|
+
file = join(dir, `.context-pressure-${_sid}.json`)
|
|
55
|
+
const meter = typeof ctx?.get === 'function' ? ctx.get('tokenMeter') : (ctx?.tokenMeter ?? null)
|
|
56
|
+
if (!meter || typeof meter.contextPressure !== 'function' || !session) {
|
|
57
|
+
out.reason = 'tokenMeter 服务或 session 不可用(旧版 DSH 或未挂载)'
|
|
58
|
+
return write(file, out)
|
|
59
|
+
}
|
|
60
|
+
const snap = meter.contextPressure(session) || {}
|
|
61
|
+
const p = Number(snap.pressureTokens)
|
|
62
|
+
const w = Number(snap.contextWindow)
|
|
63
|
+
out.available = Number.isFinite(p) && Number.isFinite(w) && w > 0
|
|
64
|
+
if (out.available) {
|
|
65
|
+
out.pressure_tokens = Math.max(0, Math.round(p))
|
|
66
|
+
out.context_window = Math.round(w)
|
|
67
|
+
out.pct = Math.min(100, Math.max(0, Math.round((p / w) * 1000) / 10))
|
|
68
|
+
} else {
|
|
69
|
+
out.reason = 'provider 还没上报 usage / route 未声明窗口(字段缺省)'
|
|
70
|
+
}
|
|
71
|
+
} catch (e) {
|
|
72
|
+
out.reason = `采集失败:${e?.message || String(e)}`.slice(0, 200)
|
|
73
|
+
}
|
|
74
|
+
return write(file, out)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function write(file, out) {
|
|
78
|
+
try {
|
|
79
|
+
if (!file) return out
|
|
80
|
+
writeFileSync(file, JSON.stringify(out, null, 2) + '\n', 'utf8')
|
|
81
|
+
} catch { /* 写失败不影响请求 */ }
|
|
82
|
+
return out
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* 新会话启动时清掉上个会话留下的样本(P9 #57)。
|
|
87
|
+
*
|
|
88
|
+
* 为什么需要:`agent/created` 生成 startup 文本时,`.context-pressure.json`
|
|
89
|
+
* 还是**上个会话** pre-step 写的(本会话 pre-step 尚未运行)。不清掉的话,
|
|
90
|
+
* 全新会话会显示"水位 90%(本会话实测)"——误导 AI 在空会话里做梦/封存。
|
|
91
|
+
* 清掉后首轮诚实显示"未知(本次尚未测量)",pre-step 再写本会话真实值。
|
|
92
|
+
*/
|
|
93
|
+
export function clearContextPressure() {
|
|
94
|
+
// LS-096(v5.68):同时清理所有 per-session 压力文件
|
|
95
|
+
try {
|
|
96
|
+
rmSync(join(memoryHome(), '.context-pressure.json'), { force: true })
|
|
97
|
+
const dir = memoryHome()
|
|
98
|
+
const fs = require('fs')
|
|
99
|
+
for (const f of fs.readdirSync(dir)) {
|
|
100
|
+
if (f.startsWith('.context-pressure-') && f.endsWith('.json')) {
|
|
101
|
+
rmSync(join(dir, f), { force: true })
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
} catch { /* 清不掉也不影响:首轮只是显示旧值 */ }
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* 读当前水位样本(不采集,只读盘)。
|
|
109
|
+
*
|
|
110
|
+
* 为什么需要:agent/created 里"先采样、采到就不清"的逻辑要判断样本是否可用,
|
|
111
|
+
* 采样函数本身会写盘——这里提供一个纯读的出口,避免为判断而多写一次盘。
|
|
112
|
+
* 返回 null = 文件不存在/读不了;否则返回解析后的 JSON(可能 available=false)。
|
|
113
|
+
*/
|
|
114
|
+
export function readPressureSample(sessionId) {
|
|
115
|
+
try {
|
|
116
|
+
// LS-096: 优先读 per-session 文件,无 sessionId 时读全局旧格式
|
|
117
|
+
if (sessionId) {
|
|
118
|
+
const _sid = String(sessionId).replace(/[^a-zA-Z0-9_-]/g, '_').slice(-40)
|
|
119
|
+
const p = join(memoryHome(), `.context-pressure-${_sid}.json`)
|
|
120
|
+
if (p && existsSync(p)) {
|
|
121
|
+
return JSON.parse(readFileSync(p, 'utf8'))
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
const raw = readFileSync(join(memoryHome(), '.context-pressure.json'), 'utf8')
|
|
125
|
+
return JSON.parse(raw)
|
|
126
|
+
} catch {
|
|
127
|
+
return null
|
|
128
|
+
}
|
|
129
|
+
}
|
|
@@ -286,12 +286,20 @@ function runPrior(pythonExe, pythonCmdFallback, brainPy, taskText, budget, timeo
|
|
|
286
286
|
})
|
|
287
287
|
}
|
|
288
288
|
|
|
289
|
-
/** 从 pre-step 决策的 messages 里抽出最后一条用户文本(含多模态里的 text
|
|
289
|
+
/** 从 pre-step 决策的 messages 里抽出最后一条用户文本(含多模态里的 text 段)。
|
|
290
|
+
* LS-112(v5.69):排除插件注入的用户角色消息!
|
|
291
|
+
* cron / IM / startup 等灵枢插件注入的消息也带 role='user',但不代表用户真的
|
|
292
|
+
* 说了话——拿它们去查 prior 会触发无关检索。同时检查 source.name 与 source.kind。 */
|
|
290
293
|
export function lastUserText(messages) {
|
|
291
294
|
if (!Array.isArray(messages)) return ''
|
|
292
295
|
for (let i = messages.length - 1; i >= 0; i--) {
|
|
293
296
|
const m = messages[i]
|
|
294
297
|
if (!m || m.role !== 'user') continue
|
|
298
|
+
// 插件注入的 user 消息(source.name 或 source.kind 标明来源��跳过
|
|
299
|
+
const srcName = m?.source?.name || ''
|
|
300
|
+
const srcKind = m?.source?.kind || ''
|
|
301
|
+
if (srcName && srcName !== 'user') continue
|
|
302
|
+
if (srcKind && srcKind !== 'user') continue
|
|
295
303
|
const c = m.content
|
|
296
304
|
if (typeof c === 'string') return c.trim()
|
|
297
305
|
if (Array.isArray(c)) {
|
package/index.js
CHANGED
|
@@ -44,28 +44,33 @@ export const inject = ['skills']
|
|
|
44
44
|
export function apply(ctx, config) {
|
|
45
45
|
const content = loadSkillBody()
|
|
46
46
|
if (content === undefined) {
|
|
47
|
-
|
|
48
|
-
return
|
|
47
|
+
// LS-099(v5.69):SKILL.md 缺失时仍挂载安全 guard!
|
|
48
|
+
// 旧实现在技能文档注册失败时直接 return——guard 等安全组件也一起没挂,
|
|
49
|
+
// IM 鉴权完全失效(裸奔)。技能文档只是"使用说明",缺它不产生安全问题;
|
|
50
|
+
// 安全组件必须无条件挂载。
|
|
51
|
+
ctx.logger?.warn?.('lingshu-skill: SKILL.md not found next to index.js, bundled skill not registered'
|
|
52
|
+
+ '(安全组件仍会挂载——LS-099)')
|
|
53
|
+
} else {
|
|
54
|
+
ctx.skills.register({
|
|
55
|
+
name: 'lingshu',
|
|
56
|
+
description:
|
|
57
|
+
'Brain-inspired persistent memory, persona and growth system for AI coding agents. ' +
|
|
58
|
+
'Local-only, zero-dependency. Requires Python 3 on PATH (or configure the startup plugin).',
|
|
59
|
+
whenToUse:
|
|
60
|
+
'需要持久记忆、人格设定、成长记录或跨会话待办时使用;' +
|
|
61
|
+
'需 Python 3,缺 Python 时 startup 注入不可用但技能文档仍可读。',
|
|
62
|
+
content,
|
|
63
|
+
// DSH validateDefinition 要求 source/provider 必须是 string,缺失时
|
|
64
|
+
// `skill(name="lingshu")` 会抛 "source must be a string"(改进清单 #2)。
|
|
65
|
+
source: 'bundled:lingshu',
|
|
66
|
+
provider: 'lingshu-skill',
|
|
67
|
+
// v3.53:必须声明资源根目录。DSH 的 runtimeCandidate 只在技能带 path/resourceBase
|
|
68
|
+
// 时才把位置暴露给 list();此前没给,子插件(startup/cron)就查不到 brain.py,
|
|
69
|
+
// 注入与即记即存会**静默停摆**——2026-11-20 那次"记忆不录入了"就是这个。
|
|
70
|
+
resourceBase: { kind: 'directory', path: here },
|
|
71
|
+
invocation: { modelInvocable: true, userInvocable: true },
|
|
72
|
+
})
|
|
49
73
|
}
|
|
50
|
-
ctx.skills.register({
|
|
51
|
-
name: 'lingshu',
|
|
52
|
-
description:
|
|
53
|
-
'Brain-inspired persistent memory, persona and growth system for AI coding agents. ' +
|
|
54
|
-
'Local-only, zero-dependency. Requires Python 3 on PATH (or configure the startup plugin).',
|
|
55
|
-
whenToUse:
|
|
56
|
-
'需要持久记忆、人格设定、成长记录或跨会话待办时使用;' +
|
|
57
|
-
'需 Python 3,缺 Python 时 startup 注入不可用但技能文档仍可读。',
|
|
58
|
-
content,
|
|
59
|
-
// DSH validateDefinition 要求 source/provider 必须是 string,缺失时
|
|
60
|
-
// `skill(name="lingshu")` 会抛 "source must be a string"(改进清单 #2)。
|
|
61
|
-
source: 'bundled:lingshu',
|
|
62
|
-
provider: 'lingshu-skill',
|
|
63
|
-
// v3.53:必须声明资源根目录。DSH 的 runtimeCandidate 只在技能带 path/resourceBase
|
|
64
|
-
// 时才把位置暴露给 list();此前没给,子插件(startup/cron)就查不到 brain.py,
|
|
65
|
-
// 注入与即记即存会**静默停摆**——2026-11-20 那次"记忆不录入了"就是这个。
|
|
66
|
-
resourceBase: { kind: 'directory', path: here },
|
|
67
|
-
invocation: { modelInvocable: true, userInvocable: true },
|
|
68
|
-
})
|
|
69
74
|
|
|
70
75
|
// 挂载子插件:startup = 会话启动自动注入人格/记忆;cron = 做梦/清点/用量等例行维护。
|
|
71
76
|
// 各自 try/catch:一个挂载失败不能拖垮另一个和技能注册本身。
|
package/manifest.json
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "5.
|
|
2
|
+
"version": "5.69",
|
|
3
3
|
"files": {
|
|
4
4
|
"CHANGELOG.md": {
|
|
5
|
-
"sha256": "
|
|
6
|
-
"size":
|
|
5
|
+
"sha256": "b6262eb1435a7bac003cd0403e1e16baee293170585119ed5803124e2459a49b",
|
|
6
|
+
"size": 437749
|
|
7
7
|
},
|
|
8
8
|
"README.md": {
|
|
9
|
-
"sha256": "
|
|
10
|
-
"size":
|
|
9
|
+
"sha256": "5ab87b76dc757e6edd6ef1d760e9a979e55df48b2b8c2b76552747fabb7b1026",
|
|
10
|
+
"size": 114306
|
|
11
11
|
},
|
|
12
12
|
"SKILL-lite.md": {
|
|
13
|
-
"sha256": "
|
|
13
|
+
"sha256": "d2728fc7fd7f5f8e15e7d50302144aa07b95ebd5323eafcc42f6b4340daa4e96",
|
|
14
14
|
"size": 4440
|
|
15
15
|
},
|
|
16
16
|
"SKILL-tiny.md": {
|
|
17
|
-
"sha256": "
|
|
17
|
+
"sha256": "a3c73b3452e1f25c78fb71cad496f56b89559af5ac9ce036f88723b17c9ef69c",
|
|
18
18
|
"size": 1913
|
|
19
19
|
},
|
|
20
20
|
"SKILL.md": {
|
|
21
|
-
"sha256": "
|
|
21
|
+
"sha256": "4663a5d3bd3e369a8dee909b9303f2a9a853b9a2c7e8e0d2723d9a171ea93e4d",
|
|
22
22
|
"size": 25366
|
|
23
23
|
},
|
|
24
24
|
"assets/lingshu-icon-preview.png": {
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
"size": 53924
|
|
35
35
|
},
|
|
36
36
|
"assets/panel.html": {
|
|
37
|
-
"sha256": "
|
|
38
|
-
"size":
|
|
37
|
+
"sha256": "7b8f3c1d595e14a06e266ea89c90620f3ce2223c2af2a089e407df734df28e17",
|
|
38
|
+
"size": 429122
|
|
39
39
|
},
|
|
40
40
|
"cordis-plugin/lingshu-cron/cordis.patch.yml": {
|
|
41
41
|
"sha256": "74fb1b914774754a985c15d01f60b64fa0c4dcbf24760de55b8bae76a015c2f7",
|
|
@@ -50,28 +50,28 @@
|
|
|
50
50
|
"size": 2205
|
|
51
51
|
},
|
|
52
52
|
"cordis-plugin/lingshu-cron/plugin.js": {
|
|
53
|
-
"sha256": "
|
|
54
|
-
"size":
|
|
53
|
+
"sha256": "b2bb77653562423dd01eeb872283eee1e0dcaf7a999c7be81b334189b9a0b2d8",
|
|
54
|
+
"size": 76447
|
|
55
55
|
},
|
|
56
56
|
"cordis-plugin/lingshu-guard/plugin.js": {
|
|
57
|
-
"sha256": "
|
|
58
|
-
"size":
|
|
57
|
+
"sha256": "c86066adb5726331099b7513ac7cc7eb078d271b0f71454b900b716303b0fd65",
|
|
58
|
+
"size": 23970
|
|
59
59
|
},
|
|
60
60
|
"cordis-plugin/lingshu-im/plugin.js": {
|
|
61
|
-
"sha256": "
|
|
62
|
-
"size":
|
|
61
|
+
"sha256": "6e36d0a1d0c0d961d581a24dfbfca89d1ae8cfe8a893fdcbbe97a33c1b231817",
|
|
62
|
+
"size": 27567
|
|
63
63
|
},
|
|
64
64
|
"cordis-plugin/lingshu-startup/README.md": {
|
|
65
65
|
"sha256": "e62016afb05dd910cd1b99fd547b1b5eead2afea43e0b90b96df2d2782c0b386",
|
|
66
66
|
"size": 8190
|
|
67
67
|
},
|
|
68
68
|
"cordis-plugin/lingshu-startup/context-fold.js": {
|
|
69
|
-
"sha256": "
|
|
70
|
-
"size":
|
|
69
|
+
"sha256": "16831c3340f2c17c3f6f31db5f1016ece20b2166442947dfeca0ed07429edea7",
|
|
70
|
+
"size": 6873
|
|
71
71
|
},
|
|
72
72
|
"cordis-plugin/lingshu-startup/context-pressure.js": {
|
|
73
|
-
"sha256": "
|
|
74
|
-
"size":
|
|
73
|
+
"sha256": "32520abe482fc95a2d865e9cea5dfcd4d31bda24482986110f1005d49c10f5b6",
|
|
74
|
+
"size": 5462
|
|
75
75
|
},
|
|
76
76
|
"cordis-plugin/lingshu-startup/cordis.patch.yml": {
|
|
77
77
|
"sha256": "8c125c21e0d742527a5ea951012f25a788abd3417ed0e235961750be3af24f91",
|
|
@@ -86,8 +86,8 @@
|
|
|
86
86
|
"size": 1391
|
|
87
87
|
},
|
|
88
88
|
"cordis-plugin/lingshu-startup/plugin.js": {
|
|
89
|
-
"sha256": "
|
|
90
|
-
"size":
|
|
89
|
+
"sha256": "9313a36b9ca91fb91c2cdefcd86646ae40ae689513125ffa7445bb382b948b5d",
|
|
90
|
+
"size": 28513
|
|
91
91
|
},
|
|
92
92
|
"cordis-plugin/lingshu-startup/resilience.js": {
|
|
93
93
|
"sha256": "05784a00d35b59c1f1b2945b4b04a632decec294cd0454dcc6991558b5179104",
|
|
@@ -134,11 +134,11 @@
|
|
|
134
134
|
"size": 8682
|
|
135
135
|
},
|
|
136
136
|
"index.js": {
|
|
137
|
-
"sha256": "
|
|
138
|
-
"size":
|
|
137
|
+
"sha256": "af3dcfd73a1e6d1de029a9b6abfae8df7e2c63ad7f08c05200f896ff7f797657",
|
|
138
|
+
"size": 6007
|
|
139
139
|
},
|
|
140
140
|
"package.json": {
|
|
141
|
-
"sha256": "
|
|
141
|
+
"sha256": "2e0bf71cfb949e9cc9a000f8950d9610489f255d2bdf31788f33fade558efdda",
|
|
142
142
|
"size": 1503
|
|
143
143
|
},
|
|
144
144
|
"scripts/anchor_retention.py": {
|
|
@@ -322,8 +322,8 @@
|
|
|
322
322
|
"size": 30102
|
|
323
323
|
},
|
|
324
324
|
"scripts/panel_data.py": {
|
|
325
|
-
"sha256": "
|
|
326
|
-
"size":
|
|
325
|
+
"sha256": "189eadcba9139fc934fc22fcd62911828b28fe3a4a189c8c0598043d227ea37b",
|
|
326
|
+
"size": 7864
|
|
327
327
|
},
|
|
328
328
|
"scripts/panel_icon.py": {
|
|
329
329
|
"sha256": "8b766740c547087c4d40ab7031a8b6845f3e0bdd3893079d2da22bb9c9694a9f",
|
|
@@ -338,8 +338,8 @@
|
|
|
338
338
|
"size": 160631
|
|
339
339
|
},
|
|
340
340
|
"scripts/panel_settings.py": {
|
|
341
|
-
"sha256": "
|
|
342
|
-
"size":
|
|
341
|
+
"sha256": "1d33fc5bf46ee64e3d1b052ecfa1b998a5da55a58e55807182a7214f8594b15b",
|
|
342
|
+
"size": 13611
|
|
343
343
|
},
|
|
344
344
|
"scripts/panel_shortcut.py": {
|
|
345
345
|
"sha256": "956374abe9d1e2b63618223e861f696070b6c0368a757f5a630f441c854ea1ea",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lingshu-skill",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.69.0",
|
|
4
4
|
"description": "Brain-inspired persistent memory, persona and growth system for AI coding agents. Local-only, zero-dependency Python. Requires Python 3.10+.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"PATCH_NOTES.md": "9296e524f743f358fd11115598398a754cfd69534526dde9c8ad85f14a418f89",
|
|
3
3
|
"README.md": "3d634d743b085eebd2cbb5dd3a00edfa728ed23947e20cc29e7c3b29087ec043",
|
|
4
|
-
"engine/CHANGELOG.md": "
|
|
5
|
-
"engine/README.md": "
|
|
6
|
-
"engine/SKILL-lite.md": "
|
|
7
|
-
"engine/SKILL-tiny.md": "
|
|
8
|
-
"engine/SKILL.md": "
|
|
9
|
-
"engine/assets/panel.html": "
|
|
4
|
+
"engine/CHANGELOG.md": "b6262eb1435a7bac003cd0403e1e16baee293170585119ed5803124e2459a49b",
|
|
5
|
+
"engine/README.md": "5ab87b76dc757e6edd6ef1d760e9a979e55df48b2b8c2b76552747fabb7b1026",
|
|
6
|
+
"engine/SKILL-lite.md": "4dcda5f429e4017a7beb0e95374e07b58e62825a7597d288ac71cbb9a0b269ef",
|
|
7
|
+
"engine/SKILL-tiny.md": "8c0304e4b6d4f55d81998a88f698eb4d51415853928cad5514404dbe3c016098",
|
|
8
|
+
"engine/SKILL.md": "4663a5d3bd3e369a8dee909b9303f2a9a853b9a2c7e8e0d2723d9a171ea93e4d",
|
|
9
|
+
"engine/assets/panel.html": "7b8f3c1d595e14a06e266ea89c90620f3ce2223c2af2a089e407df734df28e17",
|
|
10
10
|
"engine/docs/commands.md": "0ce8c88e5d2d04a8055b45c060ebd53b50c52b79b650312e2ee440845804ca4b",
|
|
11
11
|
"engine/docs/mechanics.md": "aa9683c827ed3419106e84d847ab16dc310c27fc62f588184192aaa1617523cc",
|
|
12
12
|
"engine/docs/models.md": "596bc1a3414f2de5569dcb41a0c494acae7daa534efd5a91dbcc3c4cb308d695",
|
|
@@ -52,11 +52,11 @@
|
|
|
52
52
|
"engine/scripts/occ.py": "4caac0d72ce071ea224ce2dc7d346effdbff8a516e3e7b54118a3be3ed274256",
|
|
53
53
|
"engine/scripts/panel_build.py": "5dfc687631c9818370d8392aca1443ce605f2e8994c2277019f0742e42008567",
|
|
54
54
|
"engine/scripts/panel_cloud.py": "a35155e968b90f5d51e86ffafb14c96a9e6cbb1f20152b9831cb95767d72ce09",
|
|
55
|
-
"engine/scripts/panel_data.py": "
|
|
55
|
+
"engine/scripts/panel_data.py": "189eadcba9139fc934fc22fcd62911828b28fe3a4a189c8c0598043d227ea37b",
|
|
56
56
|
"engine/scripts/panel_icon.py": "8b766740c547087c4d40ab7031a8b6845f3e0bdd3893079d2da22bb9c9694a9f",
|
|
57
57
|
"engine/scripts/panel_launcher.py": "c27c195acc126dace8b99f66906bbdb64ef4dcb4a66513907ebd4df159b97af1",
|
|
58
58
|
"engine/scripts/panel_server.py": "420292bf8f37a653f277b89f90f4f4744e9506c3062db2299a15aeca7040d3b1",
|
|
59
|
-
"engine/scripts/panel_settings.py": "
|
|
59
|
+
"engine/scripts/panel_settings.py": "1d33fc5bf46ee64e3d1b052ecfa1b998a5da55a58e55807182a7214f8594b15b",
|
|
60
60
|
"engine/scripts/panel_shortcut.py": "956374abe9d1e2b63618223e861f696070b6c0368a757f5a630f441c854ea1ea",
|
|
61
61
|
"engine/scripts/panel_splash.py": "36cd59e593ce52557a180a8767bfa9cd9c803f0cccaa141e7da8babd5a35e925",
|
|
62
62
|
"engine/scripts/panel_update.py": "b6256af938fec44e7e0c0073d7ed3f2b50487f6d52cea5772fe175d222b09f0d",
|
|
@@ -1,5 +1,37 @@
|
|
|
1
1
|
# 更新日志
|
|
2
2
|
|
|
3
|
+
## v5.69(2026-12-05)
|
|
4
|
+
|
|
5
|
+
### 🛡️ 150 项审计第十三批:Cordis IM 安全与面板设置组大收官
|
|
6
|
+
|
|
7
|
+
1. **LS-093(高·guard 注册失败拒绝态)**:`lingshu-guard` 注册全部失败时进入 deny-all——所有工具调用直接拒绝并给明确诊断,IM 鉴权绝不裸奔。
|
|
8
|
+
2. **LS-094(高·IM 授权跟随真实 HOME)**:`lingshu-im` 的 `memoryHome()` 与 Python 一致解析 `.home` 指针,旧默认目录的 consent.json 不再覆盖真实库授权。
|
|
9
|
+
3. **LS-095(高·群聊缺 chatId fail-closed)**:群聊消息无有效 chatId 时返回 null 拒绝召回/写回,绝不降级成私聊作用域。
|
|
10
|
+
4. **LS-099(高·SKILL.md 缺失仍挂 guard)**:`index.js` 技能文档注册失败不再阻断 guard 等安全组件挂载。
|
|
11
|
+
5. **LS-101(中·只读白名单移除 todo_write)**:`lingshu-guard` 的 `DEFAULT_READ_ONLY` 移除有写副作用的 `todo_write`。
|
|
12
|
+
6. **LS-102(中·cron 消息去重键)**:mid 规范统一为 `${role}:${mid}`,user/assistant 同数字 id 不再互相误判。
|
|
13
|
+
7. **LS-103(中·selfReviewDays 真正控制间隔)**:`dueByDays` 按真实日期差��算到期,配 3 天不再每天执行。
|
|
14
|
+
8. **LS-109(中·extract 只收集真实对话)**:工具/系统/插件注入消息不进对话缓冲,防自我吞噬。
|
|
15
|
+
9. **LS-111(中·cron 状态原子保存)**:`saveState` 不再先删旧状态,rename 失败时旧状态原样保留。
|
|
16
|
+
10. **LS-112(中·prior 排除插件注入)**:`lastUserText` 检查 source.name/kind,cron/IM 注入不触发无关 prior 检索。
|
|
17
|
+
11. **LS-113(中·token 标定 HOME 修复)**:`_calibPaths` 改用已有的 `memoryHome()`,修复 readBrainHome 未定义。
|
|
18
|
+
12. **LS-114(中·顶层 checkpoint 识别)**:`context-fold.js` 三个位置检查 compact-checkpoint 来源。
|
|
19
|
+
13. **LS-074(中·损坏 manifest 字段容错)**:`panel_data.py` 单条记录字段级容错,正常备份照常展示。
|
|
20
|
+
14. **LS-075/077(中·enum 设置与 NaN 拒绝)**:`panel_settings.py` 支持 enum 类型校验;float 拒绝 NaN/Infinity。
|
|
21
|
+
15. **LS-076/084(中·enum 渲染与体检契约)**:前端 enum 渲染为 select;dochealth 统一走 api() 并以 items 为准。
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## v5.68(2026-12-04)
|
|
26
|
+
|
|
27
|
+
### 🔧 150 项审计第十二批:Cordis 插件多 Agent 隔离修复
|
|
28
|
+
|
|
29
|
+
1. **LS-096**:`context-pressure.js` 压力快照按会话分文件(`.context-pressure-<sid>.json`),验证一个会话水位不会触发另一个会话自救。
|
|
30
|
+
2. **LS-100**:`cron plugin.js` 的 `writePressure` 按会话隔离 `_pressure.json`,A/B 水位和注入档位互不影响。
|
|
31
|
+
3. **LS-104**:cron 运行互斥粒度改为每 Agent + 任务名(`runningByAgent` Map),A 运行期间 B 的 extract/usage/speakup 不被丢弃。
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
3
35
|
## v5.67(2026-12-04)
|
|
4
36
|
|
|
5
37
|
### 🔒 150 项审计第十一批:面板云端与 IM 鉴权组闭环修复
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
> 名字取自《黄帝内经》:**算力给思考,人格给灵魂,记忆给生命。**
|
|
4
4
|
|
|
5
|
-
>
|
|
5
|
+
> 当��版本 **v5.69**(变更见 [CHANGELOG.md](CHANGELOG.md))
|
|
6
6
|
|
|
7
7
|
> 🔁 **双仓库镜像**:GitHub(主)与 Gitee(镜像)保持同步——[gitee.com/htmcwy_0/lingshu-skill](https://gitee.com/htmcwy_0/lingshu-skill)。灵枢的更新检查会探测两边最新提交,**谁更新就自动从谁拉取**;任一边不可达(Gitee 匿名风控 / GitHub 限额)时走另一边兜底。
|
|
8
8
|
|
|
@@ -4250,6 +4250,14 @@ function _settingRow(it){
|
|
|
4250
4250
|
const opts = (it.choices || []).map(c =>
|
|
4251
4251
|
`<option value="${esc(c)}"${String(it.value) === c ? " selected" : ""}>${esc(c)}</option>`).join("");
|
|
4252
4252
|
ctl = `<select id="${id}" data-key="${esc(it.key)}">${opts}</select>`;
|
|
4253
|
+
} else if (it.kind === "enum"){
|
|
4254
|
+
// LS-076(v5.69):enum 设置渲染为选项控件——支持 ["a","b"] 与 [{value,label}] 两种 options
|
|
4255
|
+
const opts = (it.options || []).map(o => {
|
|
4256
|
+
const v = (o && typeof o === "object") ? String(o.value ?? "") : String(o);
|
|
4257
|
+
const label = (o && typeof o === "object") ? String(o.label ?? o.value ?? "") : String(o);
|
|
4258
|
+
return `<option value="${esc(v)}"${String(it.value) === v ? " selected" : ""}>${esc(label)}</option>`;
|
|
4259
|
+
}).join("");
|
|
4260
|
+
ctl = `<select id="${id}" data-key="${esc(it.key)}">${opts}</select>`;
|
|
4253
4261
|
} else {
|
|
4254
4262
|
const step = it.step != null ? it.step : (it.kind === "float" ? 0.05 : 1);
|
|
4255
4263
|
const min = it.min != null ? ` min="${it.min}"` : "";
|
|
@@ -7872,9 +7880,9 @@ setTimeout(() => checkUpdate(true), 1200);
|
|
|
7872
7880
|
const el = body();
|
|
7873
7881
|
if (!el) return;
|
|
7874
7882
|
try {
|
|
7875
|
-
|
|
7876
|
-
const j = await
|
|
7877
|
-
const hist = Array.isArray(j) ? j : (j.history || j.rows || []);
|
|
7883
|
+
// LS-083/084(v5.69):统一 API helper 携带 token;items 字段前后端同一契约
|
|
7884
|
+
const j = await api("/api/doctor-history?limit=90");
|
|
7885
|
+
const hist = Array.isArray(j) ? j : (j.items || j.history || j.rows || []);
|
|
7878
7886
|
if (sum()) {
|
|
7879
7887
|
const st = (!Array.isArray(j) && j.stage) || null;
|
|
7880
7888
|
const g = st ? ` · 成长阶段:${esc(st.name || st.stage || "")}` : "";
|
|
@@ -98,10 +98,22 @@ def list_backups(limit: int = 30) -> dict:
|
|
|
98
98
|
except OSError:
|
|
99
99
|
continue
|
|
100
100
|
sha_file = p.with_name(p.name + ".sha256")
|
|
101
|
-
|
|
101
|
+
# LS-074(v5.69):隔离损坏备份 manifest 的字段错误!
|
|
102
|
+
# 单条记录的 manifest 读失败 / 字段类型错不再让它 abort 整个列表——
|
|
103
|
+
# 按字段级容错,正常备份照常展示。
|
|
104
|
+
man = None
|
|
105
|
+
man_err = ""
|
|
106
|
+
try:
|
|
107
|
+
man = _manifest_of(p)
|
|
108
|
+
except Exception as _me: # noqa: BLE001
|
|
109
|
+
man_err = str(_me)[:80]
|
|
102
110
|
records = None
|
|
103
|
-
if man:
|
|
104
|
-
|
|
111
|
+
if isinstance(man, dict):
|
|
112
|
+
try:
|
|
113
|
+
records = int(man.get("total_records") or 0)
|
|
114
|
+
except (TypeError, ValueError):
|
|
115
|
+
records = None
|
|
116
|
+
man_err = "total_records 字段类型异常"
|
|
105
117
|
if records is None:
|
|
106
118
|
records = _count_in_zip(p) # 老备份没清单:解包数一遍
|
|
107
119
|
age_h = max(0.0, (time.time() - st.st_mtime) / 3600.0)
|
|
@@ -120,6 +132,8 @@ def list_backups(limit: int = 30) -> dict:
|
|
|
120
132
|
"suspicious_why": ("包体过小" if bad_size
|
|
121
133
|
else (f"记录数 {records} < 阈值 {threshold}" if bad_records else "")),
|
|
122
134
|
"has_sha": sha_file.is_file(),
|
|
135
|
+
"manifest_ok": bool(isinstance(man, dict) and not man_err),
|
|
136
|
+
"manifest_error": man_err,
|
|
123
137
|
})
|
|
124
138
|
return {"dir": str(d), "dir_exists": d.is_dir(), "items": items,
|
|
125
139
|
"count": len(items), "current_records": cur,
|
|
@@ -167,7 +167,13 @@ def all_items() -> list[dict]:
|
|
|
167
167
|
|
|
168
168
|
|
|
169
169
|
def coerce(spec: dict, raw) -> Any:
|
|
170
|
-
"""按 schema 校验并转换一个值;不合法抛 ValueError(消息可直接给用户看)。
|
|
170
|
+
"""按 schema 校验并转换一个值;不合法抛 ValueError(消息可直接给用户看)。
|
|
171
|
+
|
|
172
|
+
LS-075(v5.69):实现 enum 设置的后端转换——kind=enum 按 options 校验并返回字符串。
|
|
173
|
+
LS-077(v5.69):拒绝 float 配置中的非有限数——NaN/Infinity 落盘后
|
|
174
|
+
标准 JSON 输出会变 `NaN` 字面量,前端 JSON.parse 直接失败("已写入但前端解析失败")。
|
|
175
|
+
"""
|
|
176
|
+
import math as _math
|
|
171
177
|
kind = spec["kind"]
|
|
172
178
|
if kind == "bool":
|
|
173
179
|
if isinstance(raw, bool):
|
|
@@ -178,11 +184,28 @@ def coerce(spec: dict, raw) -> Any:
|
|
|
178
184
|
if s in ("false", "0", "no", "off"):
|
|
179
185
|
return False
|
|
180
186
|
raise ValueError(f"{spec['label']} 是开关,只接受 true/false")
|
|
187
|
+
if kind == "enum":
|
|
188
|
+
# LS-075: enum 类型——按 options 白名单校验,返回字符串
|
|
189
|
+
opts = spec.get("options") or []
|
|
190
|
+
s = str(raw).strip()
|
|
191
|
+
# enum 的 options 可能是 ["a","b"] 或 [{"value":"a","label":"A"},...]
|
|
192
|
+
vals = []
|
|
193
|
+
for o in opts:
|
|
194
|
+
if isinstance(o, dict):
|
|
195
|
+
vals.append(str(o.get("value", "")))
|
|
196
|
+
else:
|
|
197
|
+
vals.append(str(o))
|
|
198
|
+
if s not in vals:
|
|
199
|
+
raise ValueError(f"{spec['label']} 只能是 {'/'.join(vals) if vals else '(无可选值)'}")
|
|
200
|
+
return s
|
|
181
201
|
if kind in ("int", "float"):
|
|
182
202
|
try:
|
|
183
203
|
num = float(raw)
|
|
184
204
|
except (TypeError, ValueError):
|
|
185
205
|
raise ValueError(f"{spec['label']} 需要是数字")
|
|
206
|
+
# LS-077: 拒绝非有限数
|
|
207
|
+
if not _math.isfinite(num):
|
|
208
|
+
raise ValueError(f"{spec['label']} 不能是 NaN 或 Infinity")
|
|
186
209
|
if kind == "int":
|
|
187
210
|
if num != int(num):
|
|
188
211
|
raise ValueError(f"{spec['label']} 需要是整数")
|
package/scripts/panel_data.py
CHANGED
|
@@ -98,10 +98,22 @@ def list_backups(limit: int = 30) -> dict:
|
|
|
98
98
|
except OSError:
|
|
99
99
|
continue
|
|
100
100
|
sha_file = p.with_name(p.name + ".sha256")
|
|
101
|
-
|
|
101
|
+
# LS-074(v5.69):隔离损坏备份 manifest 的字段错误!
|
|
102
|
+
# 单条记录的 manifest 读失败 / 字段类型错不再让它 abort 整个列表——
|
|
103
|
+
# 按字段级容错,正常备份照常展示。
|
|
104
|
+
man = None
|
|
105
|
+
man_err = ""
|
|
106
|
+
try:
|
|
107
|
+
man = _manifest_of(p)
|
|
108
|
+
except Exception as _me: # noqa: BLE001
|
|
109
|
+
man_err = str(_me)[:80]
|
|
102
110
|
records = None
|
|
103
|
-
if man:
|
|
104
|
-
|
|
111
|
+
if isinstance(man, dict):
|
|
112
|
+
try:
|
|
113
|
+
records = int(man.get("total_records") or 0)
|
|
114
|
+
except (TypeError, ValueError):
|
|
115
|
+
records = None
|
|
116
|
+
man_err = "total_records 字段类型异常"
|
|
105
117
|
if records is None:
|
|
106
118
|
records = _count_in_zip(p) # 老备份没清单:解包数一遍
|
|
107
119
|
age_h = max(0.0, (time.time() - st.st_mtime) / 3600.0)
|
|
@@ -120,6 +132,8 @@ def list_backups(limit: int = 30) -> dict:
|
|
|
120
132
|
"suspicious_why": ("包体过小" if bad_size
|
|
121
133
|
else (f"记录数 {records} < 阈值 {threshold}" if bad_records else "")),
|
|
122
134
|
"has_sha": sha_file.is_file(),
|
|
135
|
+
"manifest_ok": bool(isinstance(man, dict) and not man_err),
|
|
136
|
+
"manifest_error": man_err,
|
|
123
137
|
})
|
|
124
138
|
return {"dir": str(d), "dir_exists": d.is_dir(), "items": items,
|
|
125
139
|
"count": len(items), "current_records": cur,
|
|
@@ -167,7 +167,13 @@ def all_items() -> list[dict]:
|
|
|
167
167
|
|
|
168
168
|
|
|
169
169
|
def coerce(spec: dict, raw) -> Any:
|
|
170
|
-
"""按 schema 校验并转换一个值;不合法抛 ValueError(消息可直接给用户看)。
|
|
170
|
+
"""按 schema 校验并转换一个值;不合法抛 ValueError(消息可直接给用户看)。
|
|
171
|
+
|
|
172
|
+
LS-075(v5.69):实现 enum 设置的后端转换——kind=enum 按 options 校验并返回字符串。
|
|
173
|
+
LS-077(v5.69):拒绝 float 配置中的非有限数——NaN/Infinity 落盘后
|
|
174
|
+
标准 JSON 输出会变 `NaN` 字面量,前端 JSON.parse 直接失败("已写入但前端解析失败")。
|
|
175
|
+
"""
|
|
176
|
+
import math as _math
|
|
171
177
|
kind = spec["kind"]
|
|
172
178
|
if kind == "bool":
|
|
173
179
|
if isinstance(raw, bool):
|
|
@@ -178,11 +184,28 @@ def coerce(spec: dict, raw) -> Any:
|
|
|
178
184
|
if s in ("false", "0", "no", "off"):
|
|
179
185
|
return False
|
|
180
186
|
raise ValueError(f"{spec['label']} 是开关,只接受 true/false")
|
|
187
|
+
if kind == "enum":
|
|
188
|
+
# LS-075: enum 类型——按 options 白名单校验,返回字符串
|
|
189
|
+
opts = spec.get("options") or []
|
|
190
|
+
s = str(raw).strip()
|
|
191
|
+
# enum 的 options 可能是 ["a","b"] 或 [{"value":"a","label":"A"},...]
|
|
192
|
+
vals = []
|
|
193
|
+
for o in opts:
|
|
194
|
+
if isinstance(o, dict):
|
|
195
|
+
vals.append(str(o.get("value", "")))
|
|
196
|
+
else:
|
|
197
|
+
vals.append(str(o))
|
|
198
|
+
if s not in vals:
|
|
199
|
+
raise ValueError(f"{spec['label']} 只能是 {'/'.join(vals) if vals else '(无可选值)'}")
|
|
200
|
+
return s
|
|
181
201
|
if kind in ("int", "float"):
|
|
182
202
|
try:
|
|
183
203
|
num = float(raw)
|
|
184
204
|
except (TypeError, ValueError):
|
|
185
205
|
raise ValueError(f"{spec['label']} 需要是数字")
|
|
206
|
+
# LS-077: 拒绝非有限数
|
|
207
|
+
if not _math.isfinite(num):
|
|
208
|
+
raise ValueError(f"{spec['label']} 不能是 NaN 或 Infinity")
|
|
186
209
|
if kind == "int":
|
|
187
210
|
if num != int(num):
|
|
188
211
|
raise ValueError(f"{spec['label']} 需要是整数")
|