lingshu-skill 0.0.0-stage → 3.79.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.
Files changed (135) hide show
  1. package/CHANGELOG.md +2571 -0
  2. package/LICENSE +21 -0
  3. package/README.md +698 -3
  4. package/SKILL-lite.md +45 -0
  5. package/SKILL-tiny.md +37 -0
  6. package/SKILL.md +379 -0
  7. package/assets/panel.html +5616 -0
  8. package/cordis-plugin/lingshu-cron/cordis.patch.yml +3 -0
  9. package/cordis-plugin/lingshu-cron/index.js +4 -0
  10. package/cordis-plugin/lingshu-cron/package.json +34 -0
  11. package/cordis-plugin/lingshu-cron/plugin.js +1040 -0
  12. package/cordis-plugin/lingshu-guard/plugin.js +473 -0
  13. package/cordis-plugin/lingshu-im/plugin.js +635 -0
  14. package/cordis-plugin/lingshu-startup/README.md +123 -0
  15. package/cordis-plugin/lingshu-startup/cordis.patch.yml +3 -0
  16. package/cordis-plugin/lingshu-startup/index.js +4 -0
  17. package/cordis-plugin/lingshu-startup/package.json +25 -0
  18. package/cordis-plugin/lingshu-startup/plugin.js +352 -0
  19. package/cordis.patch.yml +3 -0
  20. package/docs/commands.md +243 -0
  21. package/docs/mechanics.md +610 -0
  22. package/docs/models.md +52 -0
  23. package/docs/npm-/345/217/221/345/270/203/350/257/264/346/230/216.md +49 -0
  24. package/docs/panel-api.md +198 -0
  25. package/docs/recovery.md +90 -0
  26. package/docs/tgz-/345/256/211/350/243/205/350/257/264/346/230/216.md +53 -0
  27. package/docs//350/277/233/345/261/225/344/270/216/345/276/205/345/212/236.md +802 -0
  28. package/index.js +102 -0
  29. package/package.json +52 -6
  30. package/scripts/_panel_smoke_v299.py +27 -0
  31. package/scripts/_smoke_v299.py +31 -0
  32. package/scripts/_sync_trae_cn.py +34 -0
  33. package/scripts/assembler.py +197 -0
  34. package/scripts/astrbot_plugin_lingshu/CHECKSUMS.json +53 -0
  35. package/scripts/astrbot_plugin_lingshu/PATCH_NOTES.md +28 -0
  36. package/scripts/astrbot_plugin_lingshu/README.md +58 -0
  37. package/scripts/astrbot_plugin_lingshu/_conf_schema.json +92 -0
  38. package/scripts/astrbot_plugin_lingshu/engine/CHANGELOG.md +2571 -0
  39. package/scripts/astrbot_plugin_lingshu/engine/README.md +698 -0
  40. package/scripts/astrbot_plugin_lingshu/engine/SKILL-lite.md +45 -0
  41. package/scripts/astrbot_plugin_lingshu/engine/SKILL-tiny.md +37 -0
  42. package/scripts/astrbot_plugin_lingshu/engine/SKILL.md +379 -0
  43. package/scripts/astrbot_plugin_lingshu/engine/assets/panel.html +5616 -0
  44. package/scripts/astrbot_plugin_lingshu/engine/docs/commands.md +243 -0
  45. package/scripts/astrbot_plugin_lingshu/engine/docs/mechanics.md +610 -0
  46. package/scripts/astrbot_plugin_lingshu/engine/docs/models.md +52 -0
  47. package/scripts/astrbot_plugin_lingshu/engine/docs/panel-api.md +198 -0
  48. package/scripts/astrbot_plugin_lingshu/engine/docs/recovery.md +90 -0
  49. package/scripts/astrbot_plugin_lingshu/engine/scripts/_panel_smoke_v299.py +27 -0
  50. package/scripts/astrbot_plugin_lingshu/engine/scripts/_smoke_v299.py +31 -0
  51. package/scripts/astrbot_plugin_lingshu/engine/scripts/_sync_trae_cn.py +34 -0
  52. package/scripts/astrbot_plugin_lingshu/engine/scripts/assembler.py +197 -0
  53. package/scripts/astrbot_plugin_lingshu/engine/scripts/behavior_baseline.py +280 -0
  54. package/scripts/astrbot_plugin_lingshu/engine/scripts/bench.py +192 -0
  55. package/scripts/astrbot_plugin_lingshu/engine/scripts/brain.py +46 -0
  56. package/scripts/astrbot_plugin_lingshu/engine/scripts/check_pressure_sync.py +55 -0
  57. package/scripts/astrbot_plugin_lingshu/engine/scripts/check_tag.py +215 -0
  58. package/scripts/astrbot_plugin_lingshu/engine/scripts/checkpoint.py +165 -0
  59. package/scripts/astrbot_plugin_lingshu/engine/scripts/cli.py +4850 -0
  60. package/scripts/astrbot_plugin_lingshu/engine/scripts/context_ab.py +260 -0
  61. package/scripts/astrbot_plugin_lingshu/engine/scripts/core.py +2025 -0
  62. package/scripts/astrbot_plugin_lingshu/engine/scripts/dream.py +1137 -0
  63. package/scripts/astrbot_plugin_lingshu/engine/scripts/emotion.py +1180 -0
  64. package/scripts/astrbot_plugin_lingshu/engine/scripts/failures.py +107 -0
  65. package/scripts/astrbot_plugin_lingshu/engine/scripts/fallback_embed.py +114 -0
  66. package/scripts/astrbot_plugin_lingshu/engine/scripts/growth.py +4745 -0
  67. package/scripts/astrbot_plugin_lingshu/engine/scripts/growth_parts.py +263 -0
  68. package/scripts/astrbot_plugin_lingshu/engine/scripts/insights.py +131 -0
  69. package/scripts/astrbot_plugin_lingshu/engine/scripts/make_dsh_tgz.py +92 -0
  70. package/scripts/astrbot_plugin_lingshu/engine/scripts/mem_dialogue.py +242 -0
  71. package/scripts/astrbot_plugin_lingshu/engine/scripts/mem_embed.py +159 -0
  72. package/scripts/astrbot_plugin_lingshu/engine/scripts/mem_lesson.py +160 -0
  73. package/scripts/astrbot_plugin_lingshu/engine/scripts/mem_score.py +210 -0
  74. package/scripts/astrbot_plugin_lingshu/engine/scripts/mem_topic.py +177 -0
  75. package/scripts/astrbot_plugin_lingshu/engine/scripts/memory.py +4352 -0
  76. package/scripts/astrbot_plugin_lingshu/engine/scripts/npm_prepack.py +31 -0
  77. package/scripts/astrbot_plugin_lingshu/engine/scripts/panel_build.py +115 -0
  78. package/scripts/astrbot_plugin_lingshu/engine/scripts/panel_cloud.py +609 -0
  79. package/scripts/astrbot_plugin_lingshu/engine/scripts/panel_server.py +2703 -0
  80. package/scripts/astrbot_plugin_lingshu/engine/scripts/panels.py +591 -0
  81. package/scripts/astrbot_plugin_lingshu/engine/scripts/persona.py +2309 -0
  82. package/scripts/astrbot_plugin_lingshu/engine/scripts/retriever.py +195 -0
  83. package/scripts/astrbot_plugin_lingshu/engine/scripts/safety.py +368 -0
  84. package/scripts/astrbot_plugin_lingshu/engine/scripts/session_import.py +736 -0
  85. package/scripts/astrbot_plugin_lingshu/engine/scripts/session_rag.py +228 -0
  86. package/scripts/astrbot_plugin_lingshu/engine/scripts/session_summary.py +123 -0
  87. package/scripts/astrbot_plugin_lingshu/engine/scripts/summarizer.py +252 -0
  88. package/scripts/astrbot_plugin_lingshu/main.py +703 -0
  89. package/scripts/astrbot_plugin_lingshu/make_checksums.py +87 -0
  90. package/scripts/astrbot_plugin_lingshu/metadata.yaml +7 -0
  91. package/scripts/behavior_baseline.py +280 -0
  92. package/scripts/bench.py +192 -0
  93. package/scripts/brain.py +46 -0
  94. package/scripts/check_pressure_sync.py +55 -0
  95. package/scripts/check_tag.py +215 -0
  96. package/scripts/check_version.py +265 -0
  97. package/scripts/checkpoint.py +165 -0
  98. package/scripts/cli.py +4850 -0
  99. package/scripts/context_ab.py +260 -0
  100. package/scripts/core.py +2025 -0
  101. package/scripts/dream.py +1137 -0
  102. package/scripts/emotion.py +1180 -0
  103. package/scripts/failures.py +107 -0
  104. package/scripts/fallback_embed.py +114 -0
  105. package/scripts/growth.py +4745 -0
  106. package/scripts/growth_parts.py +263 -0
  107. package/scripts/hooks/pre-commit +18 -0
  108. package/scripts/hooks/pre-push +20 -0
  109. package/scripts/insights.py +131 -0
  110. package/scripts/make_dsh_tgz.py +92 -0
  111. package/scripts/make_manifest.py +254 -0
  112. package/scripts/make_plugin_zip.py +88 -0
  113. package/scripts/mem_dialogue.py +242 -0
  114. package/scripts/mem_embed.py +159 -0
  115. package/scripts/mem_lesson.py +160 -0
  116. package/scripts/mem_score.py +210 -0
  117. package/scripts/mem_topic.py +177 -0
  118. package/scripts/memory.py +4352 -0
  119. package/scripts/npm_prepack.py +31 -0
  120. package/scripts/panel_build.py +115 -0
  121. package/scripts/panel_cloud.py +609 -0
  122. package/scripts/panel_server.py +2703 -0
  123. package/scripts/panels.py +591 -0
  124. package/scripts/persona.py +2309 -0
  125. package/scripts/recreate_push.ps1 +117 -0
  126. package/scripts/retriever.py +195 -0
  127. package/scripts/run_tests.py +91 -0
  128. package/scripts/safety.py +368 -0
  129. package/scripts/session_import.py +736 -0
  130. package/scripts/session_rag.py +228 -0
  131. package/scripts/session_summary.py +123 -0
  132. package/scripts/summarizer.py +252 -0
  133. package/scripts/sync_engine.py +139 -0
  134. package/scripts/update_dsh_copy.ps1 +107 -0
  135. package/start-panel.bat +60 -0
@@ -0,0 +1,52 @@
1
+ # 灵枢 · 模型适配与更新(按需查阅)
2
+
3
+ > 这是 [SKILL.md](../SKILL.md) 的补充手册:模型分级、降档策略、能力边界、如何更新技能本体。
4
+
5
+ ## 能力边界(先读再看)
6
+
7
+ 灵枢是「提示词 + 脚本」的机制,不是能强制约束模型的框架。脚本层能兜底的部分(只读降级、损坏行自愈、退出码)都做了,但 **"该记没记、该查没查、该走 startup" 只能靠模型自觉**。效果上限取决于底层模型:中强模型(7B+、云端)能完整遵守;3B 以下的本地小模型会漏读条款、跳过命令、忘记纪律——这是模型能力问题,不是灵枢坏了。
8
+
9
+ ## 模型分级与降档
10
+
11
+ 你的能力决定哪些功能能开。**记不清就按小模型处理,宁可少做、别做错。**
12
+
13
+ - **7B+ / 云端**:完整执行。做梦合并、情绪评估、知识提炼都能用。
14
+ - **1.5B–3B**:把 `config.json` 里 `model_tier` 设为 `small`(`config set model_tier small`)。此后 `startup` 注入包会追加「小模型模式」约束:
15
+ - 不自动 `dream --apply`(合并错误 = 幻觉记忆永久落盘);
16
+ - 不自动 `knowledge tidy`(提炼产物须先 `knowledge review` 人工确认);
17
+ - 情绪评估改用手动 `emotion feel`,别替用户"打分"。
18
+ - **记不住规则**:改用 `SKILL-lite.md`(精简版)或 `SKILL-tiny.md`(三件套试用版)。
19
+
20
+ 需要模型产 JSON 的入口(`dream --apply`、`knowledge tidy --apply`)都有容错解析:去掉说明文字 / ```json 围栏后还能读;真读不出来会明确报错并返回退出码 2,不会静默当没发生。
21
+
22
+ ## 幻觉防护:三道闸
23
+
24
+ 模型整理记忆/知识/人格时可能编造,灵枢用三道闸防止幻觉逐层沉淀:
25
+
26
+ 1. **审核闸**:AI 整理出来的记忆标 `review="pending"`、知识标 `status="pending"`;`review` 查看 → `review confirm <id>` 转正 / `review discard <id>` 废弃(记忆 `m_*` 与知识 `k_*` 通用)。
27
+ 2. **溯源**:AI 发起的人格变更带 `source`(dream/自我总结/…)与 `evidence`(依据的记忆/事件 id),`persona history` 可查。
28
+ 3. **自查**:`audit` 一次看完待审计数 + 冲突记忆 + 该做什么;`detect-conflicts` 扫矛盾记忆。
29
+
30
+ 每个会话的注入包会主动提醒 `[待审核]` 与 `[人格漂移]`,不让幻觉静默沉淀。
31
+
32
+ ## 更新灵枢技能
33
+
34
+ 用户说「**更新灵枢技能 / 升级灵枢 / 更新一下**」时,照下面做。更新只动**技能本体文件**,不动记忆数据——数据在 `~/.brain-memory/`,跟技能目录是两回事,覆盖技能不会丢任何记忆。
35
+
36
+ 1. **看当前版本**:读 `<本技能目录>/SKILL.md` frontmatter 的 `version`。
37
+ 2. **拉最新代码**(第一次 clone,之后每次 pull):
38
+ ```bash
39
+ DIR="$HOME/.cache/灵枢-skill"
40
+ if [ -d "$DIR/.git" ]; then git -C "$DIR" pull; else git clone --depth 1 https://gitee.com/htmcwy_0/lingshu-skill.git "$DIR"; fi
41
+ ```
42
+ 主仓库:<https://gitee.com/htmcwy_0/lingshu-skill> 镜像:<https://github.com/Q2667671398/lingshu-skill>
43
+ 3. **对照版本**:读 `"$DIR"/SKILL.md` 的 `version` 和 `"$DIR"/CHANGELOG.md`。与本地一样 → 告诉用户"已是最新版本",结束;更高 → 继续。
44
+ 4. **覆盖更新**:把克隆目录里的这些文件/目录复制到 `<本技能目录>`(覆盖同名):
45
+ `SKILL.md`、`SKILL-lite.md`、`SKILL-tiny.md`、`README.md`、`CHANGELOG.md`、`docs/`、`assets/`、`scripts/`、`start-panel.bat`
46
+ (Windows 上等价:把克隆目录里的这些项复制粘贴到技能目录,选"覆盖"。)
47
+ 覆盖前建议先备份一次数据目录(几秒,心理踏实):`python "<本技能目录>/scripts/brain.py" backup`,产物在 `~/brain-backups/`。
48
+ 注意:**你的自定义内容不会被覆盖**——长期规则写在数据目录 `~/.brain-memory/lingshu.user.md`(更新只动技能目录,永远不碰它);**你自己写的技能**在 `~/.brain-memory/skills/`、**扩展模块**在 `~/.brain-memory/extensions/`,都在数据目录里,更新技能目录不会碰。全局 `AGENTS.md` 里 `<!-- lingshu:start -->` … `<!-- lingshu:end -->` 区块之外的手写部分,更新时原样保留。
49
+ 5. **自检**:`python "<本技能目录>/scripts/brain.py" stats` 能正常输出统计 = 数据没坏。
50
+ 6. **汇报**:对照 `CHANGELOG.md` 把本次新增的关键点讲给用户听,并明确说"记忆数据没动,还是原来的"。
51
+
52
+ > 没有 git 的环境:让用户打开 gitee 仓库页面下载 ZIP,解压后手动覆盖同名文件,效果一样。
@@ -0,0 +1,198 @@
1
+ # 灵枢 自定义面板开发规范(panel-api)
2
+
3
+ 本规范面向想给灵枢写自定义面板的用户与 AI。零第三方依赖:后端只调本机 HTTP API,前端原生 HTML/CSS/JS。
4
+
5
+ ## 1. 目录结构与放置方法
6
+
7
+ 两个本地目录(均在记忆库 `~/.brain-memory/` 下,面板服务启动时自动创建):
8
+
9
+ | 目录 | 作用 |
10
+ |---|---|
11
+ | `~/.brain-memory/panels/` | **已安装目录**。面板放进去即被识别、可启用/切换 |
12
+ | `~/.brain-memory/panel-market/` | **面板市场(本机共享库)**。上传/分享的面板放这里,供本机安装与拷贝流通 |
13
+
14
+ 每个面板是**一个独立子目录**:
15
+
16
+ ```
17
+ panels/
18
+ └── my-panel/
19
+ ├── panel.json ← manifest(必需)
20
+ ├── index.html ← 入口页(必需,entry 字段指向的文件)
21
+ ├── style.css ← 可选静态资源
22
+ └── app.js
23
+ ```
24
+
25
+ - 分享流转用 zip:把面板打包(或用别人的 zip)放进 market 目录,市场里点「安装」自动解压校验后落位;zip 不会自动解压,只有 manifest 目录形式被「已安装」识别。
26
+ - **市场没有云端后端**:panel-market 就是本机共享库,同机器直接可用;把整个 `panel-market/` 目录拷给别人,对方放到自己的 `~/.brain-memory/` 下即可流通。不假装有真云市场。
27
+
28
+ ## 2. manifest 格式(panel.json)
29
+
30
+ ```json
31
+ {
32
+ "name": "my-panel",
33
+ "title": "我的面板",
34
+ "version": "1.0.0",
35
+ "author": "",
36
+ "description": "",
37
+ "entry": "index.html",
38
+ "lingshu_api": 1
39
+ }
40
+ ```
41
+
42
+ | 字段 | 必填 | 说明 |
43
+ |---|---|---|
44
+ | `name` | ✅ | 面板标识,正则 `^[a-z0-9-_一-龥]{1,32}$`(小写字母/数字/-/_/中文),**必须与目录名一致** |
45
+ | `title` | ✅ | 展示名(面板管理界面显示) |
46
+ | `version` | ✅ | 任意字符串,建议 semver |
47
+ | `author` | — | 作者 |
48
+ | `description` | — | 描述 |
49
+ | `entry` | ✅ | 入口 HTML 相对路径(默认 index.html),**必须在面板目录内** |
50
+ | `lingshu_api` | ✅ | API 版本,当前只认 `1` |
51
+
52
+ **校验规则**(任一失败 → 面板标记 invalid,不进可切换列表,绝不影响默认面板):
53
+
54
+ - 缺 `panel.json` / JSON 损坏 / 不是对象;
55
+ - `name` 缺失、非法、或与目录名不一致;
56
+ - `title` 为空;`lingshu_api` ≠ 1;
57
+ - `entry` 是绝对路径 / 含 `..` / 文件不存在。
58
+
59
+ ## 3. 统一 API(所有面板共用同一套数据源)
60
+
61
+ 鉴权:服务端下发 HTML 时把 `/*__PANEL_TOKEN__*/` 替换为一次性 token。入口 HTML 里写:
62
+
63
+ ```js
64
+ const PANEL_TOKEN = "/*__PANEL_TOKEN__*/";
65
+ async function api(path, opts){
66
+ opts = opts || {};
67
+ opts.headers = Object.assign({}, opts.headers || {},
68
+ {Authorization: "Bearer " + PANEL_TOKEN});
69
+ const r = await fetch(path, opts);
70
+ const d = await r.json().catch(() => ({}));
71
+ if (!r.ok || d.error) throw new Error(d.error || ("HTTP " + r.status));
72
+ return d;
73
+ }
74
+ ```
75
+
76
+ 静态资源引用(css/js/图片)不要写相对路径——页面从 `/api/panels/file?...` 下发,用 helper 改写:
77
+
78
+ ```js
79
+ function pfile(p){ return "/api/panels/file?panel=面板名&p=" + encodeURIComponent(p); }
80
+ // <link rel="stylesheet" href=...> 需动态注入或直接内联样式
81
+ ```
82
+
83
+ ### 可用 GET 接口(均返回 JSON)
84
+
85
+ | 接口 | 说明 |
86
+ |---|---|
87
+ | `/api/overview` | 聚合大包:stats、layer_counts、memories、persona、mood、mind、desires、dreams 等 |
88
+ | `/api/memories?layer=&q=&limit=&offset=…` | 记忆列表(支持层/重要性/时间/标签组合筛选) |
89
+ | `/api/search?q=&k=12` | 语义检索 |
90
+ | `/api/graph?limit=300` | 联想关系图 |
91
+ | `/api/assoc?id=` | 单条记忆的关联邻居 |
92
+ | `/api/entity?name=&limit=20` | 实体档案卡 |
93
+ | `/api/persona/diff` | 人格漂移对比 |
94
+ | `/api/logs?limit=200&level=` | 运行日志 |
95
+ | `/api/conflicts?limit=50` | 矛盾记忆对 |
96
+ | `/api/inject-preview?q=` | 注入包预览 |
97
+ | `/api/growth/review?days=7` | 成长回顾 |
98
+ | `/api/workspace/search?q=&scope=knowledge` | 知识库/笔记搜索 |
99
+ | `/api/self-update` | 更新检查(只读缓存用 `?auto=1`) |
100
+ | `/api/panels` | 面板列表(本规范的管理接口) |
101
+ | `/api/panels/market` | 市场目录扫描 |
102
+ | `/api/panels/file?panel=&path=&as_page=1` | 面板静态文件(扩展名白名单:html/htm/js/css/json/png/jpg/jpeg/gif/webp/svg/ico/woff/woff2/ttf/map) |
103
+
104
+ 写接口(remember/persona/knowledge 等,见 `panel_server.py` 的 `_WRITE_ENDPOINTS`)自定义面板也可以调,但请谨慎:它们直接改记忆数据。
105
+
106
+ ## 4. 面板管理接口
107
+
108
+ | 方法 | 路径 | Body / 参数 | 说明 |
109
+ |---|---|---|---|
110
+ | GET | `/api/panels` | — | `{active, panels[], installed_dir, market_dir}`;panels 含 valid/invalid_reason |
111
+ | GET | `/api/panels/market` | — | 市场目录扫描(panels + zips) |
112
+ | GET | `/api/panels/file` | query | 静态文件;`as_page=1` 对 HTML 注入 token |
113
+ | POST | `/api/panels` | `{action:"activate", name}` | 切换面板(name="default" 回默认),热加载、无需重启 |
114
+ | POST | `/api/panels` | `{action:"deactivate"}` | 回默认面板 |
115
+ | POST | `/api/panels` | `{action:"upload", name}` | 已安装 → 市场(**剪切移动**,同名 409) |
116
+ | POST | `/api/panels` | `{action:"install", name}` | 市场 → 已安装(**复制**,市场源保留;zip 自动解压校验) |
117
+ | POST | `/api/panels` | `{action:"delete", name, source}` | 删除(source: installed/market;激活中 400 拒删) |
118
+ | POST | `/api/panels` | `{action:"open-folder", which}` | 资源管理器打开目录(installed/market) |
119
+ | POST | `/api/panels/scaffold` | `{name, title}` | 一键生成最小合法面板骨架(AI 起步入口) |
120
+
121
+ ### 云端市场(Gitee 主 + GitHub 镜像,v2.29+)
122
+
123
+ 云端市场 = 一个你自己的公开 Gitee 仓库(`owner/repo`),仓库布局:
124
+
125
+ ```
126
+ panels/<面板名>.zip 面板安装包(≤50MB)
127
+ shots/<面板名>.<ext> 截图(png/jpg/webp,≤2MB),可选但强烈建议
128
+ index.json 目录清单 {"panels":[{name,title,version,author,description,screenshot,size,updated}]}
129
+ ```
130
+
131
+ - **浏览**:不需要 token(公开仓库);`GET /api/panels/cloud[?force=1]` 拉清单,Gitee 失败自动试 GitHub,60s 缓存,全挂时降级提示不影响本机市场。
132
+ - **下载**:`POST /api/panels/cloud {action:"download", name}` → 拉 zip 落本机市场 → 复用 zip 安装校验落位。
133
+ - **发布**:`POST /api/panels/cloud {action:"publish", name, screenshot:"data:image/png;base64,…"}` → 内存打 zip → Gitee contents API 上传(更新带 sha)→ 可选同步 GitHub 镜像 → 合并回写 index.json。需要 Gitee 私人令牌(勾 projects 权限)。
134
+ - **配置**:`POST /api/panels/cloud {action:"save-config", gitee_repo, gitee_token, github_repo, github_token}`;token 只存本机 config.json 的 `panel.cloud`,API 响应一律脱敏(只露前 4 位)。
135
+ - **截图代理**:`GET /api/panels/cloud/shot?name=X&ext=.png`(前端 `<img>` 走本机端点,避免跨域)。
136
+
137
+ ## 5. 热加载与回退机制
138
+
139
+ - 首页**永远**返回内置默认面板作为「外壳」;外壳启动时读 `window.__LINGSHU_ACTIVE__`(服务端注入),激活了自定义面板就全屏 iframe 加载 `/api/panels/file?panel=X&path=index.html&as_page=1`。
140
+ - 切换 = 后端写 config 的 `panel.active`(`POST /api/panels {action:"activate"}`)+ 前端刷新外壳 → iframe 换新页面。服务进程全程不动,**热加载、即时生效**。
141
+ - 三层兜底:
142
+ 1. 面板 invalid(manifest 损坏等)→ 后端预检拒绝激活 / 外壳检查后直接回退;
143
+ 2. iframe 加载失败或 3 秒超时 → 前端自动 deactivate 并提示;
144
+ 3. 面板自身 JS 报错只崩 iframe,不影响外壳与其它功能。
145
+ - 外壳右上角有悬浮「⇱ 返回默认面板」按钮,永远有逃生口。
146
+
147
+ ## 6. 最小可运行示例
148
+
149
+ `my-panel/panel.json`:
150
+
151
+ ```json
152
+ {"name": "my-panel", "title": "我的面板", "version": "1.0.0",
153
+ "entry": "index.html", "lingshu_api": 1}
154
+ ```
155
+
156
+ `my-panel/index.html`:
157
+
158
+ ```html
159
+ <!DOCTYPE html>
160
+ <html lang="zh">
161
+ <head><meta charset="utf-8"><title>我的面板</title>
162
+ <style>body{font-family:system-ui;background:#14181e;color:#e6e1d5;padding:32px}
163
+ .card{background:#1b2028;border:1px solid #2a3140;border-radius:12px;padding:20px;max-width:640px}</style></head>
164
+ <body>
165
+ <h1>我的面板</h1>
166
+ <div class="card"><div id="out">加载中…</div></div>
167
+ <script>
168
+ const PANEL_TOKEN = "/*__PANEL_TOKEN__*/";
169
+ async function api(path, opts){
170
+ opts = opts || {};
171
+ opts.headers = Object.assign({}, opts.headers || {},
172
+ {Authorization: "Bearer " + PANEL_TOKEN});
173
+ const r = await fetch(path, opts);
174
+ const d = await r.json().catch(() => ({}));
175
+ if (!r.ok || d.error) throw new Error(d.error || ("HTTP " + r.status));
176
+ return d;
177
+ }
178
+ api("/api/overview").then(d => {
179
+ document.getElementById("out").textContent =
180
+ "记忆总数:" + (d.stats && d.stats.total != null ? d.stats.total : "?") +
181
+ ",海马体层:" + (d.layer_counts ? d.layer_counts.hippo : "?");
182
+ }).catch(e => document.getElementById("out").textContent = "加载失败:" + e.message);
183
+ </script>
184
+ </body></html>
185
+ ```
186
+
187
+ 把目录放进 `~/.brain-memory/panels/`,打开默认面板 → 「面板」按钮 → 点「启用」即可。
188
+
189
+ ## 7. AI 创建指南
190
+
191
+ 给 AI 的推荐流程:
192
+
193
+ 1. `POST /api/panels/scaffold {"name":"my-panel","title":"我的面板"}` 一键生成合法骨架(自动过 manifest 校验);
194
+ 2. 打开 `~/.brain-memory/panels/my-panel/`(可用 `open-folder`),只改 `index.html` 和 manifest 的 title/description/version;
195
+ 3. 面板内所有数据都从第 3 节的统一 API 拉,样式布局交互完全自由;不要外链 CDN(CSP 只允许同源);
196
+ 4. 放进去即生效:面板管理界面点「启用」热加载,无需重启;
197
+ 5. 出错自动回退:manifest 写坏 → 扫描标记 invalid 不进列表;运行报错 → 只崩 iframe 自动回默认面板,修好再启用即可;
198
+ 6. 做好了想分享:面板管理 → 「上传到市场」(剪切到 panel-market),整个目录拷给别人即可流通。
@@ -0,0 +1,90 @@
1
+ # 事故处置单:记忆/用户文件突然没了
2
+
3
+ > 这份文档的由来是一次真实事故:用户 `C:\Users\<name>` 下的桌面、文档、下载、
4
+ > 图片等库文件夹被未知进程整片清空,`~/.brain-memory` 一起消失;而当时的备份
5
+ > 默认写在 `~/Documents/brain-memory-backups` —— 备份和本体同目录同卷,
6
+ > 被同一次事故一起带走(**v3.45 起已改为跨卷优先、明确避开 Documents/Desktop**,
7
+ > 现行规则见下方"备份都去哪了"路径表)。**先做对顺序,再谈找原因。**
8
+
9
+ ## 第 0 步:停手(最重要)
10
+
11
+ - **不要再往出事的盘写任何东西**:不装软件、不下载、不解压、不跑 `backup` 到那块盘。
12
+ - 每写入一次,就少一分用文件恢复工具捞回来的机会。
13
+ - 需要临时文件就放到**另一块盘**(如 E:)。
14
+
15
+ ## 第 1 步:确认到底丢了什么(1 分钟)
16
+
17
+ ```bash
18
+ # 记忆库还在不在、是不是空壳
19
+ python scripts/brain.py home verify
20
+ python scripts/brain.py status --json
21
+
22
+ # 会话开始会做空库熔断:出现「⚠ 记忆库疑似被清空」横幅就是它
23
+ python scripts/brain.py startup --query "检查"
24
+ ```
25
+
26
+ 对照 `_meta.json` 里的 `seen` 快照(上次见到的各文件字节数),能看出是"一直是空的"
27
+ 还是"刚刚变空的"。
28
+
29
+ ## 第 2 步:找备份(按顺序)
30
+
31
+ | 位置 | 说明 |
32
+ |---|---|
33
+ | `%BRAIN_MEMORY_BACKUP_DIR%` | 显式指定过就以它为准 |
34
+ | 别的卷 `X:\brain-memory-backups\` | **v3.45 起的默认**(跨卷优先) |
35
+ | `<记忆库>\backups\` | 同卷兜底 |
36
+ | `D:\brain-memory-backups\` | v3.45 之前的旧默认(老版本写盘符根) |
37
+ | `~/Documents/brain-memory-backups`、`~/Desktop/brain-memory-backups` | 更老版本的位置,**可能已被同一次事故清掉** |
38
+
39
+ ```bash
40
+ # 直接问灵枢最近的备份在哪(空库熔断横幅里也会给这条路径)
41
+ python -c "import safety,core;print(safety.backup_dir_candidates(core.HOME));print(core.newest_backup_hint())"
42
+ ```
43
+
44
+ 备份包命名 `brain-memory_YYYYMMDD_HHMMSS.zip`,旁边可能有 `.sha256` 与 `.enc`。
45
+ 先验证再恢复:
46
+
47
+ ```bash
48
+ python -c "import zipfile,sys;z=zipfile.ZipFile(sys.argv[1]);print('bad:',z.testzip());print(len(z.namelist()),'files')" "备份包.zip"
49
+ ```
50
+
51
+ ## 第 3 步:恢复
52
+
53
+ ```bash
54
+ # 恢复会自动先给现状做一份备份(写进 <记忆库>/backups),失败则中止
55
+ python scripts/brain.py restore "D:\brain-memory-backups\brain-memory_20261031_201408.zip" --yes
56
+
57
+ # 想回到备份那一刻的状态(删掉备份之后新增的受管文件):
58
+ python scripts/brain.py restore "…zip" --yes --exact
59
+ ```
60
+
61
+ `--exact` **只清灵枢自己管的文件**;你自己放进记忆库的草稿、导出包、照片会被
62
+ 原样保留并在输出里列出来。恢复后 `restore` 会打印保留了哪些。
63
+
64
+ ## 第 4 步:查为什么会丢
65
+
66
+ ```bash
67
+ # 回收站(普通删除会在这里;$I 文件里是原始路径)
68
+ # 卷影副本("以前的版本"用;注意晚于事故时间的快照没有价值)
69
+ vssadmin list shadows /for=C:
70
+
71
+ # 灵枢自己的运行日志:护栏拒绝、空库熔断、写入失败都在这
72
+ python scripts/brain.py logs --level warn
73
+ python scripts/brain.py failures --days 7
74
+ ```
75
+
76
+ 如果是某个程序/脚本干的:查它的清理规则是不是按通配符扫用户目录
77
+ (`C:\Users\*\*` 这类写法一跑就是灾难)。
78
+
79
+ ## 第 5 步:别让它再发生
80
+
81
+ 1. **备份放到别的卷**(v3.45 默认如此)。同卷备份 = 同一个炸弹上的两个引信。
82
+ 2. **每周一次** `python scripts/brain.py backup`,加密备份用 `--password`。
83
+ 3. **别把记忆库放进用户库文件夹**——`safety.assert_safe_home()` 会直接拒绝
84
+ (桌面/文档/下载/图片/视频/音乐/OneDrive、盘符根、主目录本体)。
85
+ 4. **别用会"清理"用户目录的工具**做自动整理;要做也先把排除规则写死。
86
+ 5. 重要数据再留一份**离线/网盘**副本;备份包已剥离 token、跳过密钥文件,可以放心上传。
87
+
88
+ ## 一句话记忆
89
+
90
+ > 停手 → 找跨卷备份 → 先验证再恢复 → 最后才查原因。
@@ -0,0 +1,27 @@
1
+ # -*- coding: utf-8 -*-
2
+ """验证脚本:后台起 panel_server(临时 HOME),查 /api/extensions/ollama/status,然后关掉。"""
3
+ import os, subprocess, sys, tempfile, time, urllib.request
4
+
5
+ tmp = os.path.join(tempfile.gettempdir(), "lingshu-panel-smoke")
6
+ os.makedirs(tmp, exist_ok=True)
7
+ root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
8
+ flags = getattr(subprocess, "CREATE_NO_WINDOW", 0)
9
+ proc = subprocess.Popen([sys.executable, os.path.join(root, "scripts", "panel_server.py"),
10
+ "--port", "8791", "--no-browser", "--home", tmp],
11
+ cwd=root, creationflags=flags,
12
+ stdout=subprocess.DEVNULL, stderr=subprocess.PIPE)
13
+ time.sleep(6)
14
+ try:
15
+ with urllib.request.urlopen("http://127.0.0.1:8791/api/extensions/ollama/status", timeout=10) as r:
16
+ print("STATUS:", r.read().decode("utf-8"))
17
+ except Exception as exc:
18
+ print("ERR:", exc)
19
+ finally:
20
+ proc.terminate()
21
+ try:
22
+ _, err = proc.communicate(timeout=10)
23
+ if err:
24
+ print("STDERR:", err.decode("utf-8", "replace")[-800:])
25
+ except Exception:
26
+ proc.kill()
27
+ print("PANEL SMOKE DONE")
@@ -0,0 +1,31 @@
1
+ # -*- coding: utf-8 -*-
2
+ """v2.99 冒烟:临时 HOME 下写入记忆 → recall 语义相近查询 → hash 向量自检。"""
3
+ import sys, os, tempfile
4
+ tmp = tempfile.mkdtemp(prefix="lingshu-smoke-")
5
+ os.environ["BRAIN_MEMORY_HOME"] = tmp # 必须在 import 前设好,模块加载即解析 HOME
6
+ sys.path.insert(0, r"e:\丁厚同\文档\程序\灵枢-skill\scripts")
7
+ import core, memory, brain # brain 负责命名空间合并(compile_persona 等跨模块名)
8
+ from pathlib import Path
9
+ print("HOME =", core.HOME)
10
+ assert str(core.HOME) == tmp or Path(tmp) == Path(os.environ["BRAIN_MEMORY_HOME"])
11
+
12
+ # hash 向量自检
13
+ import fallback_embed as fe
14
+ a = fe.encode("用户喜欢用PostgreSQL存数据")
15
+ assert a is not None and len(a) == 256, "encode 失败"
16
+ assert abs(fe.cosine(a, a) - 1.0) < 0.01, "自相似度应为 1"
17
+ sim_rel = fe.cosine(a, fe.encode("用户偏好把数据存在PostgreSQL里"))
18
+ sim_irr = fe.cosine(a, fe.encode("今天天气很好适合出去爬山"))
19
+ assert sim_rel > sim_irr, f"语义相近应更高分: {sim_rel} vs {sim_irr}"
20
+ print(f"hash 向量: 自相似=1 OK, 相近={sim_rel:.3f} > 无关={sim_irr:.3f} OK")
21
+
22
+ # 记忆写入 + recall
23
+ memory.remember("我们把项目的数据库迁移到了 PostgreSQL 16,连接串放在 config 里", kind="fact")
24
+ memory.remember("用户生日是 3 月 12 日,喜欢巧克力蛋糕", kind="fact")
25
+ memory.remember("上周末一起去爬了香山,秋天的红叶很美", kind="episode")
26
+ import time; time.sleep(2.5) # 等异步 embedding 回写
27
+ hits = memory.recall("项目现在用的什么数据库存数据?", strengthen=False)
28
+ texts = [h[0].get("text", "")[:30] for h in hits]
29
+ print("recall 命中:", texts[:3])
30
+ assert any("PostgreSQL" in t for t in texts), "语义相近查询未命中"
31
+ print("SMOKE PASS, home =", tmp)
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ """按 manifest 清单把源仓交付物同步到 Trae CN 技能副本(一次性运维脚本,可删)。"""
4
+ import json
5
+ import shutil
6
+ import sys
7
+ from pathlib import Path
8
+
9
+ SRC = Path(r"e:\丁厚同\文档\程序\灵枢-skill")
10
+ DST = Path(r"C:\Users\Administrator\.dsh\profiles\desktop\node_modules\lingshu-skill")
11
+
12
+ m = json.loads((SRC / "manifest.json").read_text(encoding="utf-8-sig"))
13
+ ok = miss = 0
14
+ for rel in m["files"]:
15
+ s = SRC / rel
16
+ d = DST / rel
17
+ if not s.is_file():
18
+ print("SRC-MISS:", rel)
19
+ miss += 1
20
+ continue
21
+ d.parent.mkdir(parents=True, exist_ok=True)
22
+ shutil.copy2(s, d)
23
+ ok += 1
24
+ print("copied =", ok, "missing =", miss)
25
+
26
+ ver = ""
27
+ for line in (DST / "SKILL.md").read_text(encoding="utf-8-sig").splitlines():
28
+ if line.startswith("version:"):
29
+ ver = line.strip()
30
+ break
31
+ print("SKILL.md", ver)
32
+ pkg = json.loads((DST / "package.json").read_text(encoding="utf-8-sig"))
33
+ print("package.json", pkg.get("version"))
34
+ sys.exit(0 if ok and not miss else 1)
@@ -0,0 +1,197 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ """上下文五段式装配器(附录 C · P1)。
4
+
5
+ 把"这一轮该带什么"显式写成五段,并按预算裁剪:
6
+ stable 稳定系统层(人格/规则/技能,放最前,吃缓存)
7
+ summary 会话摘要层(结构化要点)
8
+ retrieved 检索片段(可裁)
9
+ recent 最近窗口(原文,保底)
10
+ current 本轮输入
11
+
12
+ `plan()` 是纯函数:不读盘、不调模型、不发网络。裁剪顺序照附录 C:
13
+ retrieved → summary → recent;stable 与 current 只在超限时告警,不静默砍。
14
+ 输出里的 tokens 是**估算**(默认 2 字符 ≈ 1 token),用于预算决策,不是计费口径。
15
+ """
16
+ from __future__ import annotations
17
+
18
+ import math
19
+
20
+ SECTIONS = ("stable", "summary", "retrieved", "recent", "current")
21
+ # 各段默认占比(相对总预算);未列出的段不设硬上限,只受总预算约束
22
+ DEFAULT_RATIOS = {
23
+ "stable": 0.10,
24
+ "summary": 0.04,
25
+ "retrieved": 0.20,
26
+ "recent": 0.15,
27
+ "current": 0.05,
28
+ }
29
+ DEGRADE_ORDER = ("retrieved", "summary", "recent")
30
+ MIN_KEEP_TOKENS = {"retrieved": 0, "summary": 0, "recent": 200}
31
+
32
+
33
+ def estimate_tokens(text: str, chars_per_token: int = 2) -> int:
34
+ """粗估 token:中文字符约 2 字/token。只用于预算,不当计费。"""
35
+ ratio = chars_per_token if isinstance(chars_per_token, int) and chars_per_token > 0 else 2
36
+ return int(math.ceil(len(text or "") / ratio))
37
+
38
+
39
+ def _trim_to_tokens(text: str, target_tokens: int, chars_per_token: int) -> str:
40
+ """按 token 目标截断文本(保留头部 + 省略号)。"""
41
+ if target_tokens <= 0:
42
+ return ""
43
+ limit = target_tokens * chars_per_token
44
+ if len(text) <= limit:
45
+ return text
46
+ if limit <= 1:
47
+ return ""
48
+ return text[:limit - 1].rstrip() + "…"
49
+
50
+
51
+ def plan(parts: dict, budget: int = 40000, *, ratios: dict | None = None,
52
+ output_reserve: float = 0.25, max_output_tokens: int | None = None,
53
+ chars_per_token: int = 2) -> dict:
54
+ """按预算排一版五段装配计划。
55
+
56
+ parts 里缺的段按空串处理;返回:
57
+ {blocks:[{name,chars,tokens,cap_tokens,trimmed_chars}],
58
+ total_tokens, budget, usable_tokens, reserve_tokens,
59
+ actions:[...], warnings:[...]}
60
+ """
61
+ budget = max(1, int(budget))
62
+ ratios = {**DEFAULT_RATIOS, **(ratios or {})}
63
+ # 输出预留:min(max_tokens, 25% 窗口),与附录 C 的 outputHeadroomMaxPct 一致
64
+ if max_output_tokens:
65
+ reserve = min(int(max_output_tokens), int(budget * output_reserve))
66
+ else:
67
+ reserve = int(budget * output_reserve)
68
+ usable = max(1, budget - reserve)
69
+
70
+ texts = {name: str(parts.get(name) or "") for name in SECTIONS}
71
+ # 段占比只对"窗口级预算"有意义:2400 这种小预算下,10% 的 stable 上限
72
+ # 比人格本身还小,天天告警等于没告警。小预算只按总量压。
73
+ use_caps = budget >= 8000
74
+ caps = ({name: max(0, int(budget * ratios[name])) for name in SECTIONS if name in ratios}
75
+ if use_caps else {})
76
+
77
+ actions: list[str] = []
78
+ warnings: list[str] = []
79
+
80
+ def total_tokens() -> int:
81
+ return sum(estimate_tokens(texts[n], chars_per_token) for n in SECTIONS)
82
+
83
+ # 1) 先按段上限裁(只裁可裁的三段;stable/current 超限只告警)
84
+ for name in DEGRADE_ORDER:
85
+ cap = caps.get(name)
86
+ if cap is None:
87
+ continue
88
+ tk = estimate_tokens(texts[name], chars_per_token)
89
+ if tk > cap:
90
+ texts[name] = _trim_to_tokens(texts[name], cap, chars_per_token)
91
+ actions.append(f"{name}: 按段上限 {cap} tokens 裁剪")
92
+ for name in ("stable", "current"):
93
+ cap = caps.get(name)
94
+ if cap and estimate_tokens(texts[name], chars_per_token) > cap:
95
+ warnings.append(f"{name} 超过建议上限 {cap} tokens(不自动裁,属配置问题)")
96
+
97
+ # 2) 总量仍超 usable → 按 retrieved → summary → recent 继续压
98
+ for name in DEGRADE_ORDER:
99
+ if total_tokens() <= usable:
100
+ break
101
+ over = total_tokens() - usable
102
+ tk = estimate_tokens(texts[name], chars_per_token)
103
+ floor = MIN_KEEP_TOKENS.get(name, 0)
104
+ target = max(floor, tk - over - 1)
105
+ if target >= tk:
106
+ continue
107
+ texts[name] = _trim_to_tokens(texts[name], target, chars_per_token)
108
+ actions.append(f"{name}: 为压回总预算裁剪 {tk - target} tokens")
109
+
110
+ blocks = []
111
+ for name in SECTIONS:
112
+ blocks.append({
113
+ "name": name,
114
+ "chars": len(texts[name]),
115
+ "tokens": estimate_tokens(texts[name], chars_per_token),
116
+ "cap_tokens": caps.get(name),
117
+ "trimmed_chars": len(str(parts.get(name) or "")) - len(texts[name]),
118
+ })
119
+ total = sum(b["tokens"] for b in blocks)
120
+ if total > usable:
121
+ warnings.append(f"总预算仍超限:{total} > {usable}(stable/current 不可裁,需调预算或拆输入)")
122
+ return {
123
+ "blocks": blocks,
124
+ "total_tokens": total,
125
+ "budget": budget,
126
+ "usable_tokens": usable,
127
+ "reserve_tokens": reserve,
128
+ "chars_per_token": chars_per_token,
129
+ "actions": actions,
130
+ "warnings": warnings,
131
+ }
132
+
133
+
134
+ def plan_from_report(report: dict, budget: int = 40000, **kwargs) -> dict:
135
+ """把 memory.build_injection(report=...) 的分段映射成五段计划。
136
+
137
+ 映射(附录 C 的落地近似):
138
+ stable = persona + rules + skills
139
+ summary = topics + mistakes + relationships
140
+ retrieved = related
141
+ recent = recent + other(梦结论等历史块)
142
+ current = dynamic(会话实时状态;真正的"本轮输入"由宿主提供,这里只做占位)
143
+ """
144
+ secs = {s.get("name"): int(s.get("chars") or 0) for s in (report.get("sections") or [])}
145
+ parts = {
146
+ "stable": "x" * (secs.get("persona", 0) + secs.get("rules", 0) + secs.get("skills", 0)),
147
+ "summary": "x" * (secs.get("topics", 0) + secs.get("mistakes", 0)
148
+ + secs.get("relationships", 0)),
149
+ "retrieved": "x" * secs.get("related", 0),
150
+ "recent": "x" * (secs.get("recent", 0) + secs.get("other", 0) + secs.get("water", 0)),
151
+ "current": "x" * secs.get("dynamic", 0),
152
+ }
153
+ ratio = int(report.get("chars_per_token") or 2)
154
+ out = plan(parts, budget=budget, chars_per_token=ratio, **kwargs)
155
+ out["source"] = "injection-report"
156
+ out["source_chars"] = report.get("total_chars")
157
+ return out
158
+
159
+
160
+ def compare(report: dict, budget: int | None = None) -> dict:
161
+ """纯计算:同一份注入包在 legacy / budgeted 两种装配下的字符数对比。
162
+
163
+ legacy = 现在的整段注入(memory.build_injection 的报告 total_chars);
164
+ budgeted = 五段式按预算裁剪后(plan_from_report)各段字符数之和。
165
+
166
+ 返回 {legacy_chars, budgeted_chars, saved_pct, degraded}:
167
+ saved_pct 省下的字符比例(百分数,保留两位小数;legacy 为 0 时记 0.0)
168
+ degraded 被裁过的段名,按 SECTIONS 顺序(没裁就是空列表)
169
+
170
+ 约定:不读盘、不写盘、不改入参、不调模型;budget 缺省用 report 自带预算。
171
+ 只被灰度观测用,不参与真正的装配决策。
172
+ """
173
+ rep = report if isinstance(report, dict) else {}
174
+ b = budget if budget is not None else (rep.get("budget") or 40000)
175
+ try:
176
+ b = int(b)
177
+ except (TypeError, ValueError):
178
+ b = 40000
179
+ if b <= 0:
180
+ b = 1
181
+ budgeted_plan = plan_from_report(rep, budget=b)
182
+ blocks = budgeted_plan.get("blocks") or []
183
+ legacy_chars = rep.get("total_chars")
184
+ if not isinstance(legacy_chars, int) or legacy_chars < 0:
185
+ legacy_chars = sum(int((s or {}).get("chars") or 0)
186
+ for s in (rep.get("sections") or []))
187
+ budgeted_chars = sum(int((bl or {}).get("chars") or 0) for bl in blocks)
188
+ saved_pct = (round((legacy_chars - budgeted_chars) * 100.0 / legacy_chars, 2)
189
+ if legacy_chars > 0 else 0.0)
190
+ degraded = [str(bl.get("name")) for bl in blocks
191
+ if int((bl or {}).get("trimmed_chars") or 0) > 0]
192
+ return {
193
+ "legacy_chars": int(legacy_chars),
194
+ "budgeted_chars": int(budgeted_chars),
195
+ "saved_pct": saved_pct,
196
+ "degraded": degraded,
197
+ }