dsh-aiyayi 1.6.1 → 1.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  > **维护约定**:新版本发布时在顶部加条目。本文件由 README 正文拆出(2026-11-09 重构):版本条目与踩坑记录原文照录,数字、时间、日期一律不改(量化保真是本插件的规矩)。版本事实以 npm registry 为准。
4
4
  >
5
- > **npm 发布一览(2026-11-13 08:5x 核对 registry `dist-tags`)**:latest = **1.5.45**(2026-11-12T16:48:34.644Z 已发布);**本次发版版为 1.6.0**(工具箱自主成长开放给所有用户,publish 与 registry 回查见本文件 1.6.0 条目、DEPLOY 台账)。下列长串是 1.5.39 时代的旧记录,原文保留、以 registry 为准。已发布:1.0.0、…、1.5.7、**1.5.14**、**1.5.15**、**1.5.16**、**1.5.17**、**1.5.20**、**1.5.21**、**1.5.22**、**1.5.23**、**1.5.24**、**1.5.25**、**1.5.26**、**1.5.27**、**1.5.28**、**1.5.29**、**1.5.30**、**1.5.31**、**1.5.32**、**1.5.33**、**1.5.34**、**1.5.35**、**1.5.36**、**1.5.37**;跳号 1.3.0、1.4.1、1.4.2、1.5.0、1.5.1、1.5.2、1.5.3、**1.5.8–1.5.13** 从未发布到 npm(本地开发线:1.5.8–1.5.11 飞书桥接、1.5.12 思考纪律约束、1.5.13 内置技能同步+feishu-setup 骨架);1.5.14 已发布(坑 #58–#67 修复);1.5.15 已发布(扫码接入改造);1.5.16 已发布(feishu-setup 技能脚本入包);1.5.17 已发布(坑 #68 重入保护修复);**1.5.18 / 1.5.19 也从未发布到 npm**(见下方 1.5.18 / 1.5.19 条目——它们的代码最终随 1.5.20 一起进 npm);**1.5.20 已发布**(飞书正文改走 interactive 卡片 + lark_md,含 1.5.19 附件收发与问答卡片、1.5.20 markdown 渲染,以及 create-bot v6 权限集中化);**1.5.21 已发布**(修飞书回复正文首尾空白行,坑 #72);**1.5.22 已发布**(多应用多长连接改造+chat 归属机制,见下方 1.5.22 条目);**1.5.23–1.5.25 已发布**(230001 边界/补 import/补 feishuCode 挖码三轮装版断言增量修复,见下方对应条目);**1.5.26 已发布**(回发多文本段覆盖丢段修复,坑 #73,见下方 1.5.26 条目);**1.5.27 已发布**(微信通道并入,默认关闭,见下方 1.5.27 条目);**1.5.28 已发布**(PowerShell 版本体检 + 微信通道收尾,见下方 1.5.28 条目);**1.5.29 已发布**(发布包排除 `test/` + 测试残留空目录清理,见下方 1.5.29 条目);**1.5.30 已发布**(create-bot 注释改用 `<记忆根>` 占位,见下方 1.5.30 条目);**1.5.31 已发布**(PowerShell 体检 `major:null` 根因修复:探测链补上 powershell.exe 一级,见下方 1.5.31 条目);**1.5.32 已发布**(行为变更:首次提示同时告知微信 ClawBot 能力 + 「对接默认落到发起对接的会话」固化为 persona 准则/文档;不含路由代码改动,见下方 1.5.32 条目);**1.5.33 已发布**(同一准则落成代码:未绑定 chat 三档复用,不再无条件新建会话,见下方 1.5.33 条目);**1.5.34 已发布**(纯测试修复:`presence-clock` 跨午夜偶发失败,`lib/` 零改动,见下方 1.5.34 条目);**1.5.35 已发布**(`feishu_status` 新增最近入站路由回看 `inboundRouting` 字段,见下方 1.5.35 条目);**1.5.36 已发布**(飞书连接状态失真修复,见下方 1.5.36 条目);**1.5.37 已发布**(压缩前沉淀机制 precompact,见下方 1.5.37 条目);**1.5.38 已发布**(工具包中间层首批 toolkit_cmd / toolkit_read / toolkit_write,见下方 1.5.38 条目);**1.5.39 为本次发版版**(toolkit 三件套注册失败修复 + feishu_bind 自动绑定,见下方 1.5.39 条目;publish 留待下一步,以 registry 为准);**1.5.40 为当前开发版**(toolkit 执行输出对齐 output.schema——宿主对输出也做 schema 校验,见下方 1.5.40 条目与坑 #78;仅本地提交,不 push 不 publish);**1.5.41 为当前发版版**(Toolbox 真异步能力 + watch_read 异步工具 + mem_sync 同步工具,见下方 1.5.41 条目与坑 #79/#80;2026-11-12T07:17:11Z 已发布到 npm,latest);**1.5.42 已发布版**(新增 `pkg_stats` 同步工具——npm 下载量 + GitHub/Gitee/GitCode 仓库热度,见下方 1.5.42 条目;2026-11-12T07:46:35Z 已发布到 npm,latest)。**1.5.43 已发布**(`mem_sync` 的 P0/P1 缺陷修复 + **破坏性变更:`watch_read`/`mem_sync`/`pkg_stats` 三个私有工具移出工具面**,实现文件保留待 1.5.44 本地清单复用,见下方 1.5.43 条目;2026-11-12T13:13:36Z 已发布到 npm,latest)。**1.5.44 已发布(latest)**(本地工具清单机制:`<记忆根>/toolbox.json` + `toolbox_list` / `toolbox_reload`,包内只留 3+2 工具、私有工具走本机清单,见下方 1.5.44 条目;2026-11-12T14:30:16Z 已发布到 npm,shasum `02a5f99e…`)。**1.5.45 已发布**(飞书引导误触发三连修 + 插件注入身份自标注,见下方 1.5.45 条目;publish 与 registry 回查见 DEPLOY 台账)。**1.6.0 已发布**(工具箱自主成长开放给所有用户,2026-11-13T01:05:35.003Z 发布,shasum `c2b25e57…`,55 个文件);**本次发版版为 1.6.1**(能力声明最小闭环 + `toolbox_remove` + precompact 沉淀过滤修复(坑 #81)+ 飞书 pending 切换提示 + persona 三条 + README 瘦身,见下方 1.6.1 条目)。
5
+ > **npm 发布一览(2026-11-13 18:1x 订正:改为 1.6.3 待发布口径,发布后回填本处与 DEPLOY 台账)**:latest = **1.6.2**(2026-11-13T08:59:45.517Z 已发布,registry 记录 `2026-11-13T09:02:01.870Z`,shasum `d6e09000…`,见本文件 1.6.2 条目、DEPLOY 1.6.2 台账);**本次发版为 1.6.3(待发布,尚未 publish,发布后回填本处与 DEPLOY 台账)**(档案健康度误报修复——结构行不再当垃圾 + 阈值按档案类型分开,见本文件 1.6.3 条目)。下列长串是 1.5.39 时代的旧记录,原文保留、以 registry 为准。已发布:1.0.0、…、1.5.7、**1.5.14**、**1.5.15**、**1.5.16**、**1.5.17**、**1.5.20**、**1.5.21**、**1.5.22**、**1.5.23**、**1.5.24**、**1.5.25**、**1.5.26**、**1.5.27**、**1.5.28**、**1.5.29**、**1.5.30**、**1.5.31**、**1.5.32**、**1.5.33**、**1.5.34**、**1.5.35**、**1.5.36**、**1.5.37**;跳号 1.3.0、1.4.1、1.4.2、1.5.0、1.5.1、1.5.2、1.5.3、**1.5.8–1.5.13** 从未发布到 npm(本地开发线:1.5.8–1.5.11 飞书桥接、1.5.12 思考纪律约束、1.5.13 内置技能同步+feishu-setup 骨架);1.5.14 已发布(坑 #58–#67 修复);1.5.15 已发布(扫码接入改造);1.5.16 已发布(feishu-setup 技能脚本入包);1.5.17 已发布(坑 #68 重入保护修复);**1.5.18 / 1.5.19 也从未发布到 npm**(见下方 1.5.18 / 1.5.19 条目——它们的代码最终随 1.5.20 一起进 npm);**1.5.20 已发布**(飞书正文改走 interactive 卡片 + lark_md,含 1.5.19 附件收发与问答卡片、1.5.20 markdown 渲染,以及 create-bot v6 权限集中化);**1.5.21 已发布**(修飞书回复正文首尾空白行,坑 #72);**1.5.22 已发布**(多应用多长连接改造+chat 归属机制,见下方 1.5.22 条目);**1.5.23–1.5.25 已发布**(230001 边界/补 import/补 feishuCode 挖码三轮装版断言增量修复,见下方对应条目);**1.5.26 已发布**(回发多文本段覆盖丢段修复,坑 #73,见下方 1.5.26 条目);**1.5.27 已发布**(微信通道并入,默认关闭,见下方 1.5.27 条目);**1.5.28 已发布**(PowerShell 版本体检 + 微信通道收尾,见下方 1.5.28 条目);**1.5.29 已发布**(发布包排除 `test/` + 测试残留空目录清理,见下方 1.5.29 条目);**1.5.30 已发布**(create-bot 注释改用 `<记忆根>` 占位,见下方 1.5.30 条目);**1.5.31 已发布**(PowerShell 体检 `major:null` 根因修复:探测链补上 powershell.exe 一级,见下方 1.5.31 条目);**1.5.32 已发布**(行为变更:首次提示同时告知微信 ClawBot 能力 + 「对接默认落到发起对接的会话」固化为 persona 准则/文档;不含路由代码改动,见下方 1.5.32 条目);**1.5.33 已发布**(同一准则落成代码:未绑定 chat 三档复用,不再无条件新建会话,见下方 1.5.33 条目);**1.5.34 已发布**(纯测试修复:`presence-clock` 跨午夜偶发失败,`lib/` 零改动,见下方 1.5.34 条目);**1.5.35 已发布**(`feishu_status` 新增最近入站路由回看 `inboundRouting` 字段,见下方 1.5.35 条目);**1.5.36 已发布**(飞书连接状态失真修复,见下方 1.5.36 条目);**1.5.37 已发布**(压缩前沉淀机制 precompact,见下方 1.5.37 条目);**1.5.38 已发布**(工具包中间层首批 toolkit_cmd / toolkit_read / toolkit_write,见下方 1.5.38 条目);**1.5.39 已发布**(toolkit 三件套注册失败修复 + feishu_bind 自动绑定,见下方 1.5.39 条目;publish 留待下一步,以 registry 为准);**1.5.40 为当前开发版**(toolkit 执行输出对齐 output.schema——宿主对输出也做 schema 校验,见下方 1.5.40 条目与坑 #78;仅本地提交,不 push 不 publish);**1.5.41 已发布**(Toolbox 真异步能力 + watch_read 异步工具 + mem_sync 同步工具,见下方 1.5.41 条目与坑 #79/#80;2026-11-12T07:17:11Z 已发布到 npm,latest);**1.5.42 已发布版**(新增 `pkg_stats` 同步工具——npm 下载量 + GitHub/Gitee/GitCode 仓库热度,见下方 1.5.42 条目;2026-11-12T07:46:35Z 已发布到 npm,latest)。**1.5.43 已发布**(`mem_sync` 的 P0/P1 缺陷修复 + **破坏性变更:`watch_read`/`mem_sync`/`pkg_stats` 三个私有工具移出工具面**,实现文件保留待 1.5.44 本地清单复用,见下方 1.5.43 条目;2026-11-12T13:13:36Z 已发布到 npm,latest)。**1.5.44 已发布(latest)**(本地工具清单机制:`<记忆根>/toolbox.json` + `toolbox_list` / `toolbox_reload`,包内只留 3+2 工具、私有工具走本机清单,见下方 1.5.44 条目;2026-11-12T14:30:16Z 已发布到 npm,shasum `02a5f99e…`)。**1.5.45 已发布**(飞书引导误触发三连修 + 插件注入身份自标注,见下方 1.5.45 条目;publish 与 registry 回查见 DEPLOY 台账)。**1.6.0 已发布**(工具箱自主成长开放给所有用户,2026-11-13T01:05:35.003Z 发布,shasum `c2b25e57…`,55 个文件);**1.6.1 已发布**(能力声明最小闭环 + `toolbox_remove` + precompact 沉淀过滤修复(坑 #81)+ 飞书 pending 切换提示 + persona 三条 + README 瘦身,见下方 1.6.1 条目)。
6
6
  >
7
7
  > **环境标识约定(2026-11-10 新增)**:写版本条目/坑条目时,**顺手记录当时的 智能体工具-智能体模式-模型供应商-模型**(如 **DSH-创造模式-loomy讯飞-GLM5.3FLASH**),写在条目内(紧跟 git 记录行、或坑条目首行),方便回溯该条目是在哪套智能体/模型环境下产出与验证的。
8
8
 
@@ -10,6 +10,74 @@
10
10
 
11
11
  ---
12
12
 
13
+ ## 1.6.3(2026-11-13:档案健康度误报修复——结构行不再当垃圾 + 阈值按档案类型分开)
14
+
15
+ - 环境:DSH-执行智能体(DeepSeek Harness 子会话,模型名未确证)
16
+ - **本版定位**:1.6.2 上线后实测暴露的**误报修复**,按 1.6.0 立下的版本号规则涨 PATCH。只动 `lib/index.js` 的健康度统计口径 + `test/memory-health.test.mjs`,`package.json` 版本号与 `lib/precompact.js` 均未改;装完要重启 DSH 才生效。
17
+
18
+ - **改了什么(`lib/index.js` 的 `fileHealth` / 新增 `isStructuralLine` / 新增 `STRUCTURAL_RULES` / 新增 `isCoreFile` / `renderCore` / `HEALTH_SCHEMA` / `tree` 与 `read` 两个调用点;`test/memory-health.test.mjs`)**:
19
+
20
+ **一、`fileHealth` 不再把"不是条目本身"当罪(根本原因)**
21
+ 1.6.2 的 `fileHealth` 把**所有解析不出 `- [时间] …` 的行**都算成"非条目垃圾",于是核心记忆 `memory.md` 的索引段(`<!-- 索引 -->` … `<!-- /索引 -->` 之间 72 行纯文本目录)、`#` 标题行、`>` 引用行、`---` 分隔线全被计入分母,一上来就报出很高的污染占比——纯属误报。根因是**同一个文件里有两套过滤规则**:`renderCore()`(决定每轮注入什么)早就排除了标题/引用/索引标记,`fileHealth()` 没复用,各写各的。
22
+ - 抽出共用的 `isStructuralLine(trimmed, state)`:`#` 标题、`>` 引用、`---`/`***`/`___` 分隔线、**整段索引**(两个标记行**及其之间的所有行**,不是只跳标记行)都不进统计——既不算条目也不算非条目。
23
+ - 索引段用行序状态机整段跳过:段里除了目录还有指到 `docs/` 的指针行,形状上可能像条目,但它们同样是索引骨架。
24
+ - `renderCore()` 改为复用同一个 `isStructuralLine`,两套规则合并成一套,将来不会再分叉。
25
+
26
+ **二、阈值按档案类型分开**
27
+ - 分类档案保持 **30%**(`HEALTH_RATIO_MAX = 0.3`):分类档案本来就该几乎全是条目,这个值在 2026-11-13 清库后对 91 个文件实测全部归零,证明它没问题;
28
+ - 核心记忆给 **50%**(新增 `HEALTH_RATIO_MAX_CORE = 0.5`):核心记忆带着索引骨架与分节标题,天然比分类档案"结构行多",稍宽容一档;
29
+ - `fileHealth(raw, { isCore })` 加了一个可选项,`tree` 里核心传 `{ isCore: true }`、每个分类档案传 `{ isCore: false }`,`read` 用 `isCoreFile(file)` 按实际路径判断。**判据严格大于才报**(`ratio > ratioMax`),边界值不响。
30
+
31
+ **三、字节判据不动**
32
+ `bytes > entries × avgEntryBytes × 5` 原样保留(`HEALTH_BYTES_FACTOR = 5`)。它是对的——2026-11-13 上午 266KB 那次事故就是靠它该报的;本版只动"分子分母怎么数",不动"多大算被撑大"。
33
+
34
+ **四、文案与说明同步改准**
35
+ - 预警文案:`非条目内容占 X%(N 行非条目 / M 行内容;标题、引用、分隔线、索引段已排除,不计入分子分母;阈值 T%)`;"行非空"改称"行内容",因为分母现在是剔除结构行后的内容行数。
36
+ - `HEALTH_SCHEMA` 的 `entries` / `nonEntry` / `ratio` 三条 `description` 同步写清新口径与分档阈值。
37
+ - `tree` 底部那行说明改为"…非条目占比(已排除标题、引用、分隔线、索引段这些结构行);非条目占比超阈值(核心 50%、分类 30%)或字节数远超条目内容…"。
38
+ - `read` 的健康度摘要行尾补"(已排除标题、引用、分隔线、索引段)"。
39
+ - `lib/index.js:66` 的设计意图注释补上本次修正的原因、日期与原则:**只报可疑迹象,不把"不是条目本身"当罪**——告警响多了会被忽略,真正该看一眼的 266KB 那种反而被淹没。
40
+
41
+ **五、发布前扫包顺带清掉的本机绝对路径残留(与本版主修复无关,但同属本版)**
42
+ - `skills/feishu-setup/scripts/save-secret.js`:`--out` 缺省值原本写死成发版方本机的 `D:\AI\TRAE_PRO\阿依娅依\work\feishu-app-create\credential-<appId>.json`——**别人跑这条脚本会把凭证往不存在的目录写、直接 ENOENT**。改成 `path.join(process.cwd(), 'work', 'feishu-app-create', ...)`,与本目录 `create-bot.js` 的既有约定一致(它早就用 `process.cwd()`,本文件第 7 行的注释写的也是相对 cwd 的路径)。这个缺陷从 **1.5.16** 起就在已发布的包里(1.6.2 的 tarball 实测同样带这行)。
43
+ - `cordis.patch.yml`:`writeExtraPaths` 原本写死发版方工作区的 docs 绝对路径,对其他用户是噪音(路径不存在时不生效、也不报错)。改成 `writeExtraPaths: []` + 注释说明怎么放开自己的目录;`skg_probe` / 工具脚本两处注释里的本机路径改占位写法。
44
+ - `lib/toolkit-manifest.js` / `lib/toolkit.js` / `skills/feishu-setup/scripts/package.json`:注释与示例里的 `G:` / `D:` 盘本机路径改为 `~/tools/…` 这类通用写法(纯文档,**无行为变化**)。
45
+ - 刻意**没改**:`CHANGELOG.md` 里 12 处历史本机路径——那是已发布条目的原文,本仓规矩是"数字、时间、日期一律不改"的原文照录。
46
+
47
+ ### ⚠ 行为变化
48
+
49
+ - `health.entries` / `nonEntry` / `ratio` 三个数字的口径变了:结构行被剔除后,占比普遍低于 1.6.2。**拿 1.6.2 的占比当基线对比会看到"数字变小",那是口径修正,不是档案变干净了。**
50
+ - 核心记忆的告警阈值从 30% 放宽到 50%;分类档案不变。
51
+ - `renderCore()` 的注入正文**多剥掉了 `---` 分隔线**(原先只剥 `#` / `>` / 索引标记行)。核心记忆模板正文开头本就有两行空行,所以注入正文开头的长相不变;但手写在正文里的 `---` 不再进 prompt。
52
+ - 输出 schema 的字段**集合没变**(仍是 7 个键),只是 `description` 改了口径说明,不影响宿主校验。
53
+
54
+ - **测试**:`test/memory-health.test.mjs` **11 条 → 21 条**(新增 10 条)。既有 11 条中仅 1 条(B)因文案从"6 行非空"改成"6 行内容"而更新断言——数值(nonEntry=3 / ratio=0.5 / 预警内容)一个字没放宽,只是跟着文案改。新增覆盖:核心记忆含索引+标题+引用+分隔线时占比 0 且不告警、索引段内的"条目形状"假行不计条目(整段跳过而非只跳标记行)、缺 `/索引` 标记时后续行仍按索引段处理、45% 时核心不报而分类报、30% 边界严格大于才报、核心超 50% 照样报、真垃圾(200 行正文)两条判据都能触发、`---`/`***`/`___` 不计非条目、结构豁免不能放太宽(`#号方案…` / `-> 指向…` 仍算非条目)、`renderCore` 与健康度同口径。全量 `node --test test/*.test.mjs` **tests 189 / pass 186 / fail 3**,挂的三条是既有环境基线(`alarm-inject` 硬编码旧路径 `G:\…\presence.js`、`home-relocate` 缺 I: 盘、`tools-surface` 的 %TEMP% 在系统盘),**零新增失败**(2026-11-13 18:0x 实跑;改前基线 179/176/3 同三条)。注意 `node --test test/` 在 Node 22 会把目录当文件跑、直接 MODULE_NOT_FOUND,必须写 glob。
55
+
56
+ - **实测(本机真实记忆库干净数据,2026-11-13 18:1x;脚本在 %TEMP%、只读不写盘)**:核心 `memory.md` **16830 字节 / 109 行 / 31 条条目**(记忆库的手动清理早先已完成:早期重复索引已清,只剩末尾一份带 `<!-- 索引 -->` / `<!-- /索引 -->` 标记的索引段,第 36–108 行共 73 行)→ 旧口径非条目 74 行 / 105 行 = **70.5%**,新口径非条目 **0 行 / 31 行 = 0.0%**、**0 条告警**(`avgEntryBytes` 386)。逐行分类核对:索引段 73 行 + `# 阿依娅伊的记忆` 标题 1 行被排除,剩余 31 行全是合法条目,**没有一行落进"垃圾"桶**——0% 是干净数据实打实算出来的,不是把垃圾藏起来。分类档案(`isCore:false`,阈值 30%):`事情/dsh-aiyayi` 6209 字节 / 10 条 → 新旧均 **0%**、无告警;`用户/身份` 761 字节 / 3 条 → 新旧均 **0%**;`我/基线` 2769 字节 / 1 条 → 新旧均 **0%**。特殊文件 `事情/经验` 8929 字节 / 73 行 / 5 条条目:旧口径 45/50 = **90.0%** → 新口径 31/36 = **86.1%**,**仍告警**(这是该报的真情况:它是 docs/ 经验文档索引清单、不是条目档案,"成功/失败用例"那种分节标题被结构行豁免后剩下的仍是成片的非条目文字;属"该看一眼",本版不改这个文件)。
57
+ - **本版不修历史数据、只修误差**:`70.5%`(旧口径 vs 同一份干净数据)与 `0.0%`(新口径)之间那 74 行,全部是索引骨架 + 标题,一行真垃圾都没有。1.6.2 上线时曾报 71.6% / 69.9%,那是**清理前**的数据(当时索引还有重复段、且有一段裸在正文里没被标记包住);记忆库清干净后用旧口径算仍是 70.5%,说明**告警的真正来源是口径、不是数据**——这正是本版要修的东西。口径修正后旧基线数字不可直接对比,看趋势请统一用 1.6.3 口径。
58
+
59
+ ## 1.6.2(2026-11-13:precompact_run 输出修复 + memory_organize 档案健康度与 forget 精确定位)
60
+
61
+ - 环境:DSH-执行智能体(DeepSeek Harness 子会话,模型名未确证)
62
+ - **本版定位**:两处实锤修 bug + 一处可观测性增强,按 1.6.0 立下的版本号规则涨 PATCH。`lib/precompact.js` / `lib/index.js` 有实质改动,装完要重启 DSH 才生效。
63
+
64
+ - **改了什么(`lib/precompact.js` / `lib/index.js` / `package.json`;新增 `test/memory-health.test.mjs`、`test/memory-forget.test.mjs`,扩充 `test/precompact.test.mjs`)**:
65
+
66
+ 修复 `precompact_run` 调用即报 `returned invalid output`(三条返回分支全部过不了宿主 output 校验):`output.schema` 补齐 `trigger`/`memoryFile`/`filename`/`verdict` 四个漏声明字段,成功分支补 `skipped: false`(schema `required` 里声明了但实际没返回)。
67
+
68
+ `memory_organize` 的 `tree` / `read` 新增档案健康度:报出每个档案的真实字节数、行数、条目数、非条目内容占比,并给两条独立预警(非条目占比 > 30%、字节数 > 条目数 × 平均条目长度 × 5)。起因是 2026-11-13 上午 precompact 垃圾沉淀把 `memories/事情/经验.md` 灌到 266KB,而旧版 `read` 只显示解析得出的条目、完全看不见文件真实体量。
69
+
70
+ `memory_organize` 的 `forget` 改为精确定位:不给 `path` 时扫核心 + 全部分类档案(原先只搜核心);时间戳归一化匹配(支持显示层 `[2026-11-13 12:50]`、ISO、`T` 分隔、全角);命中多条时列出候选并支持 `which` 序号消歧,**一次只删一条、不批量删**;命中 0 条时给近似匹配诊断但绝不据此删除。
71
+
72
+ ### ⚠ 行为变化
73
+
74
+ - `forget` 不给 `path` 时的搜索范围由「只搜核心」扩大为「核心 + 全部分类档案」。原先找不到会直接报错,现在会搜全库。
75
+ - `forget` 命中多条时不再抛错,改为返回 `done: false` + `candidates` 候选列表。**判断失败要看 `done` 字段,不能再靠抛错。**删除语义未放宽:仍然一次只删一条。
76
+
77
+ - **测试**:新增 `test/memory-health.test.mjs`(11 条)与 `test/memory-forget.test.mjs`(70 条),`test/precompact.test.mjs` 补 238 行;全量 tests 179 / pass 176 / fail 3,3 挂为既有环境基线(`alarm-inject` 缺 G: 盘、`home-relocate` 缺 I: 盘、`tools-surface` 的 %TEMP% 不在系统盘),零新增失败。
78
+
79
+ ---
80
+
13
81
  ## 1.6.1(2026-11-13:能力声明最小闭环 + `toolbox_remove` + 沉淀过滤修复(坑 #81)+ 飞书 pending 切换提示 + persona 三条 + README 瘦身)
14
82
 
15
83
  - 环境:DSH-执行智能体(DeepSeek Harness 子会话,模型名未确证)
package/README.md CHANGED
@@ -128,7 +128,7 @@ npm 包为平铺结构(仓库若保留 bundle/ 子目录,发布时把其内
128
128
 
129
129
  ## 更新日志
130
130
 
131
- [更新日志](./CHANGELOG.md) —— 版本条目(新 → 旧)、npm 发布状态与完整踩坑记录(坑 #1–#80)。版本事实以 npm registry 为准,正文不再逐版本罗列。
131
+ [更新日志](./CHANGELOG.md) —— 版本条目(新 → 旧)、npm 发布状态与完整踩坑记录(坑 #1–#81)。版本事实以 npm registry 为准,正文不再逐版本罗列。
132
132
 
133
133
  ## 署名与许可
134
134
 
package/cordis.patch.yml CHANGED
@@ -242,7 +242,7 @@
242
242
  # 从清单文件移除条目并立即重载)。watch_read / mem_sync / pkg_stats
243
243
  # **已移出 npm 包**,改由**本机工具清单** <记忆根>/toolbox.json 驱动
244
244
  # (lib/toolkit-manifest.js):
245
- # · 清单里每条引用本机脚本绝对路径,脚本不进包(在 G:\阿依娅伊\工具\…);
245
+ # · 清单里每条引用本机脚本绝对路径,脚本不进包(如 ~/tools/mem_sync/mem_sync.js);
246
246
  # · 每条都必须 mode:"async"(写 sync 直接判该条校验失败并报回会话);
247
247
  # · 每个清单工具调用立刻返回 {status:'started', taskId},跑完 followup 推回;
248
248
  # · 清单坏了/条目坏了/脚本缺失会注入一条 [工具清单] 消息报回会话,不静默;
@@ -286,23 +286,25 @@
286
286
  readMaxBytes: 8192
287
287
  writeMaxBytes: 65536
288
288
  # 写入白名单:writePaths: null(默认)= 记忆根(动态解析,搬家自动跟随)
289
- # + writeExtraPaths;给数组则完全接管。工作区 docs 是本机路径,走追加项。
290
- writeExtraPaths:
291
- - D:\AI\TRAE_PRO\阿依娅依\docs
289
+ # + writeExtraPaths;给数组则完全接管。
290
+ # ⚠ 这一段是**本机(发版方)**的追加项,装到别的机器上路径不存在时不生效、
291
+ # 也不会报错;1.6.3 起已通用化(原先写死了发版方工作区的 docs 绝对路径,
292
+ # 对其他用户是噪音)。要放开自己的目录就改这里。
293
+ writeExtraPaths: []
292
294
  usageEnabled: true
293
295
  usageMaxLines: 500
294
296
  # ── 1.5.43 / 1.5.44 破坏性变更:以下三个工具已从工具面移除(不再注册、不再进白名单)──
295
297
  # watch_read / mem_sync / pkg_stats 是发版方的私有能力,不进通用安装包。
296
298
  # 实现文件仍在包里;1.5.44 起它们改由**本机工具清单**
297
- # <记忆根>/toolbox.json 按需注册(脚本在 G:\阿依娅伊\工具\…,不进包)。
299
+ # <记忆根>/toolbox.json 按需注册(脚本在各自主机目录下,如 ~/tools/…,不进包)。
298
300
  # ⚠ **下面这些 watch* / mem* / pkgStats* 配置项 1.5.44 起不再被读取**:
299
301
  # 保留只为让升级用户已写的同名项不变孤儿。**要改行为请改清单里该工具的 env**
300
302
  # (见 README「本地工具清单」一节),别在这里取消注释——不会生效。
301
303
  # ── 1.5.41 遗留项(仅作接口参考,不再生效)──
302
304
  # watch_read:手表脚本目录。不设 = 按插件自身位置推导
303
- # <包目录>/../../skg_probe/ble_direct(本机即 D:\AI\TRAE_PRO\阿依娅依\skg_probe\ble_direct)。
305
+ # <包目录>/../../skg_probe/ble_direct。
304
306
  # 目录搬家时在这里给绝对路径。watchPython 默认 'python'(需能 import bleak)。
305
- # watchDir: D:\AI\TRAE_PRO\阿依娅依\skg_probe\ble_direct
307
+ # watchDir: <包目录>/../../skg_probe/ble_direct
306
308
  # watchPython: python
307
309
  # watchTimeoutMs: 180000
308
310
  # watchDefaultRounds: 6
package/lib/index.js CHANGED
@@ -63,6 +63,198 @@ const MAX_CORE_CHARS = 12000
63
63
  const MAX_RECALL = 50
64
64
  const MAX_DEPTH = 3
65
65
 
66
+ /* 健康度判据(2026-11-13 起,memory_organize 的 tree/read 会报):
67
+ * - 非条目行占比 > 阈值:正常的档案几乎全是条目行,混进大段别的东西就是异常;
68
+ * **阈值按档案类型分开**:核心记忆 50%,分类档案 30%;
69
+ * - 字节数 > 条目数 × 平均条目长度 × 5:条目还在,但文件被非条目文本撑大了
70
+ * (266KB 那次事故就是这种:条目没少多少,字节数是条目的几十倍)。
71
+ * 判据只是"该看一眼"的提示,不是"一定坏了"。
72
+ *
73
+ * 2026-11-13 修正(1.6.2 上线后实测发现):
74
+ * 1.6.2 初版把核心记忆的索引段(`<!-- 索引 -->` … `<!-- /索引 -->` 之间几十行
75
+ * 纯文本目录)、`#` 标题行、`>` 引用行、`---` 分隔线全都算成"非条目垃圾",
76
+ * 于是本机 `D:\阿依娅伊\记忆\memory.md` 一上来就被报 71.6% 污染——纯属误报。
77
+ * 根因是 fileHealth 和 renderCore 各写一套过滤规则(renderCore 早就排除了
78
+ * 标题/引用/索引标记,fileHealth 没跟上)。改法两条:
79
+ * ① 抽出共用的 isStructuralLine,fileHealth 与 renderCore 同口径过滤;
80
+ * ② 核心记忆带着索引骨架,天然比分类档案"结构行多",阈值单独给 50%。
81
+ * 原则:**只报可疑迹象,不把"不是条目本身"当罪**——告警响多了会被忽略,
82
+ * 真正该看一眼的 266KB 那种反而被淹没。 */
83
+ const HEALTH_RATIO_MAX = 0.3
84
+ const HEALTH_RATIO_MAX_CORE = 0.5
85
+ const HEALTH_BYTES_FACTOR = 5
86
+
87
+ /**
88
+ * 这个档案是不是核心记忆(memory.md)。只用于给健康度选阈值。
89
+ * @param {string} file 档案的绝对路径
90
+ */
91
+ function isCoreFile(file) {
92
+ return file === coreFile()
93
+ }
94
+
95
+ /**
96
+ * 每一条都是"整行就是结构"的形态,行首锚定。
97
+ * - `# 标题`:1~6 个 # 后面必须跟空白(`#号方案没了` 是真内容,不能豁免);
98
+ * - `> 引用`:`>` 后面必须跟空白或整行只有 `>`(`-> 指向` 是真内容);
99
+ * - `---` / `***` / `___`:CommonMark 分隔线,同一字符 3 个以上、只有空白即可。
100
+ */
101
+ const STRUCTURAL_RULES = [/^#{1,6}(?:\s|$)/, /^>(?:\s|$)/, /^(?:-{3,}|\*{3,}|_{3,})$/]
102
+
103
+ /**
104
+ * 这行是不是"结构性行"——渲染/排版用途,本身不是记忆内容,健康度统计里
105
+ * 既不算条目也不算非条目(当空行跳过)。
106
+ *
107
+ * 两种口径,按调用场景分:
108
+ * - 默认(不传 options):**切段 Markdown 用**,与 renderCore 的老口径一致
109
+ * (`startsWith('#')` / `startsWith('>')`)。注入正文宁可多剥几行,
110
+ * 因为进 prompt 的残留 noise 比少一行的代价大;
111
+ * - `{keepRules: true}`:**健康度统计用**,改走 STRUCTURAL_RULES 的按规则表,
112
+ * 只豁免真正整行是结构的行,避免把真内容误判成结构行、把垃圾藏起来。
113
+ *
114
+ * 索引段两边都得**整段跳过**(不是只跳标记行):段里除了目录还有指到 docs/ 的
115
+ * 指针行,形状上可能像条目,但它们是索引骨架,不是记忆条目。
116
+ *
117
+ * @param {string} trimmed 已 trim 的行
118
+ * @param {{inIndex?: boolean, keepRules?: boolean}} [state] 行序遍历状态(跨行会改写 inIndex)
119
+ */
120
+ function isStructuralLine(trimmed, state = {}) {
121
+ if (state.inIndex === true) {
122
+ if (trimmed === INDEX_END) state.inIndex = false
123
+ return true
124
+ }
125
+ if (trimmed === INDEX_BEGIN) {
126
+ state.inIndex = true
127
+ return true
128
+ }
129
+ if (state.keepRules !== true) {
130
+ // 标题 / 引用(说明块)/ 分隔线:都是结构,不是内容。切段 Markdown 用。
131
+ return trimmed.startsWith('#') || trimmed.startsWith('>') || (trimmed.length >= 3 && /^-{3,}$/.test(trimmed))
132
+ }
133
+ // 按规则表了解析:只认行首锚定、整行就是结构的那几种,
134
+ // 避免把 `# 号方案…`、`-> 指向…` 这类真内容误判掉(结构豁免宁可少放、不能多放)。
135
+ return STRUCTURAL_RULES.some((rule) => rule.test(trimmed))
136
+ }
137
+
138
+ /**
139
+ * 一个档案的客观健康度(只读统计,绝不改文件)。
140
+ *
141
+ * 为什么要有它:precompact 垃圾沉淀事故(2026-11-13)把 `memories/事情/经验.md`
142
+ * 灌到 266KB,注入文本里带条目行,被解析器当成正常条目 → 同内容 ×3 重复。
143
+ * 当时 memory_organize 的 read 只显示"解析得出来的条目",文件真实多大、
144
+ * 混了多少非条目垃圾一概看不见,是事后用别的工具直读文件才发现 266KB 的。
145
+ * 教训:工具不能只报"它理解的内容",还得报"文件本身的客观状态"。
146
+ *
147
+ * 口径(2026-11-13 1.6.3 起):
148
+ * - 先剔结构性行(isStructuralLine 按 STRUCTURAL_RULES:`# 标题`、`> 引用`、
149
+ * `---` 分隔线、整段 `<!-- 索引 -->` … `<!-- /索引 -->` 含两个标记行)——
150
+ * 既不算条目也不算非条目;
151
+ * - entries:剩下的行里能按 `- [时间] …` 解析出来的(与 read/tree/forget 同口径);
152
+ * - nonEntry:剩下的非空行里、解析不出条目的(`- [` 开头的残缺行、纯文本、注入残留…);
153
+ * - ratio = nonEntry / (entries + nonEntry),分子分母都只算"内容行";
154
+ * - avgEntryBytes:条目行的平均字节数,用来做"文件被撑大"的判据,无条目时 0。
155
+ *
156
+ * 性能:调用方只读一次文件,统计全部基于同一份文本,不重复读盘。
157
+ *
158
+ * @param {string} raw 文件原文
159
+ * @param {{isCore?: boolean}} [options] isCore=true 用核心记忆的阈值(0.5),否则 0.3
160
+ */
161
+ function fileHealth(raw, options = {}) {
162
+ const text = String(raw ?? '')
163
+ const lines = text.split(/\r?\n/)
164
+ // 末尾换行会 split 出一个空串,那不是一行内容。
165
+ if (lines.length > 0 && lines[lines.length - 1] === '') lines.pop()
166
+ const ratioMax = options?.isCore === true ? HEALTH_RATIO_MAX_CORE : HEALTH_RATIO_MAX
167
+ const indexState = { keepRules: true }
168
+ let entries = 0
169
+ let nonEntry = 0
170
+ let entryBytes = 0
171
+ for (const line of lines) {
172
+ const trimmed = line.trim()
173
+ if (trimmed.length === 0) continue
174
+ if (isStructuralLine(trimmed, indexState)) continue
175
+ if (parseLine(trimmed) !== null) {
176
+ entries += 1
177
+ entryBytes += Buffer.byteLength(trimmed, 'utf8')
178
+ } else {
179
+ nonEntry += 1
180
+ }
181
+ }
182
+ const nonEmpty = entries + nonEntry
183
+ const bytes = Buffer.byteLength(text, 'utf8')
184
+ const avgEntryBytes = entries > 0 ? Math.round(entryBytes / entries) : 0
185
+ const ratio = nonEmpty === 0 ? 0 : nonEntry / nonEmpty
186
+ const warnings = []
187
+ if (ratio > ratioMax) {
188
+ warnings.push(
189
+ `⚠ 这个档案可能被污染了(precompact 垃圾沉淀或批量注入):非条目内容占 ${percent(ratio)}(${nonEntry} 行非条目 / ${nonEmpty} 行内容;标题、引用、分隔线、索引段已排除,不计入分子分母;阈值 ${percent(ratioMax)})。`,
190
+ )
191
+ }
192
+ if (entries > 0 && bytes > entries * avgEntryBytes * HEALTH_BYTES_FACTOR) {
193
+ const factor = Math.round((bytes / Math.max(1, entries * avgEntryBytes)) * 10) / 10
194
+ warnings.push(
195
+ `⚠ 这个档案可能被污染了(precompact 垃圾沉淀或批量注入):${bytes} 字节,是条目内容(${entries} 条 × 平均 ${avgEntryBytes} 字节)的 ${factor} 倍,阈值 ${HEALTH_BYTES_FACTOR} 倍。`,
196
+ )
197
+ }
198
+ if (warnings.length > 0) {
199
+ warnings.push('建议:先备份这个文件,再清掉那些非条目的垃圾段落(move/forget 只认条目行,清不掉它们);清完用 tree 复核。')
200
+ }
201
+ return { bytes, lines: lines.length, entries, nonEntry, ratio, avgEntryBytes, warnings }
202
+ }
203
+
204
+ /** 0.305 → "30.5%"。 */
205
+ function percent(ratio) {
206
+ return `${Math.round(ratio * 1000) / 10}%`
207
+ }
208
+
209
+ /** read 的条目列表之外那一行健康度摘要。 */
210
+ function healthSummary(health) {
211
+ return `健康度:${health.bytes} 字节 / ${health.lines} 行 / ${health.entries} 条条目 / 非条目占 ${percent(health.ratio)}(已排除标题、引用、分隔线、索引段)`
212
+ }
213
+
214
+ /** tree 里跟在"N 条"后面的简短健康度;空档案不啰嗦。 */
215
+ function healthBrief(health) {
216
+ if (health.bytes === 0) return '(空)'
217
+ return `(${health.bytes} 字节 / ${health.lines} 行 / 非条目 ${percent(health.ratio)})`
218
+ }
219
+
220
+ /** 输出 schema 里的健康度结构:三处引用同一份声明,避免手写漂移。 */
221
+ const HEALTH_SCHEMA = {
222
+ type: 'object',
223
+ additionalProperties: false,
224
+ properties: {
225
+ bytes: { type: 'integer', description: '文件真实字节数(UTF-8)。' },
226
+ lines: { type: 'integer', description: '文件真实行数(不含末尾换行造成的那一行)。' },
227
+ entries: { type: 'integer', description: '解析得出的条目行数(不含已排除的结构性行)。' },
228
+ nonEntry: {
229
+ type: 'integer',
230
+ description: '排除结构性行(# 标题、> 引用、--- 分隔线、整段 <!-- 索引 -->…<!-- /索引 -->)之后,非空但解析不出条目的行数。',
231
+ },
232
+ ratio: {
233
+ type: 'number',
234
+ description: '非条目占比 = nonEntry / (entries + nonEntry)(结构性行不计入分子分母),0~1。预警阈值:核心记忆 0.5、分类档案 0.3。',
235
+ },
236
+ avgEntryBytes: { type: 'integer', description: '条目行平均字节数,无条目时为 0。' },
237
+ warnings: { type: 'array', items: { type: 'string' }, description: '污染预警与建议动作;健康时为空数组。' },
238
+ },
239
+ required: ['bytes', 'lines', 'entries', 'nonEntry', 'ratio', 'avgEntryBytes', 'warnings'],
240
+ }
241
+
242
+ /** forget 的候选结构(多命中/近似命中共用):档案 + 文件 + 行号 + 时间戳 + 摘要。 */
243
+ const FORGET_CANDIDATE_SCHEMA = {
244
+ type: 'object',
245
+ additionalProperties: false,
246
+ properties: {
247
+ path: { type: 'string', description: '档案:core(核心记忆)或分类路径,如 "事情/经验"。' },
248
+ file: { type: 'string', description: '这个条目的文件绝对路径。' },
249
+ line: { type: 'integer', description: '条目在文件里的行号(1 起)。' },
250
+ time: { type: 'string', description: '条目里存的时间戳原文。' },
251
+ kind: { type: 'string', description: '类别(核心条目才有:用户/关系/我/事情),分类条目为空串。' },
252
+ content: { type: 'string', description: '条目内容。' },
253
+ preview: { type: 'string', description: '一行预览:[时间] 类别|内容(超长截断)。' },
254
+ },
255
+ required: ['path', 'file', 'line', 'time', 'kind', 'content', 'preview'],
256
+ }
257
+
66
258
  /**
67
259
  * 保证核心记忆文件在。**路径不可达时抛错**(1.5.0 起的硬失败),
68
260
  * 只有「默认路径首次不存在」才允许建目录 + 写模板;模板写入失败仍然吞掉
@@ -175,13 +367,7 @@ function listTreeFiles() {
175
367
  return found.sort()
176
368
  }
177
369
 
178
- function countEntries(file) {
179
- let count = 0
180
- for (const line of readRaw(file).split(/\r?\n/)) {
181
- if (parseLine(line) !== null) count += 1
182
- }
183
- return count
184
- }
370
+
185
371
 
186
372
  function appendEntry(file, line) {
187
373
  ensureCore()
@@ -207,6 +393,204 @@ function uniqueEntryLine(lines, match) {
207
393
  return hits[0]
208
394
  }
209
395
 
396
+ /* ------------------------------------------------------------------ *
397
+ * forget 的精确定位(1.6.2)
398
+ *
399
+ * 2026-11-13 实测:清理记忆时 forget 连扑空 4 次,两个病根——
400
+ * ① 同一条记忆在不同档案里有多个副本:旧实现要求"恰好命中一条",2 条就判
401
+ * 歧义、直接拒绝,结果明明看见它在那儿却删不掉;
402
+ * ② 拿显示层的时间戳(`[2026-11-13 12:50]`)当 match:显示串和文件里的原始
403
+ * 存储行不一定逐字相同(秒精度、T 分隔、全角冒号…),`line.includes(needle)`
404
+ * 找不到连续串就直接扑空。
405
+ * 这里把「怎么找到那一条」放宽(原样子串 / 时间戳 / 时间戳+内容 / 行号),
406
+ * 但**安全底线不动**:永远一次只删一条,命中多条就列候选让调用方挑 which。
407
+ * 近似匹配(忽略空白/标点/全半角)只用于 0 命中时的诊断,绝不拿它去删。
408
+ * ------------------------------------------------------------------ */
409
+
410
+ const MAX_FORGET_CANDIDATES = 20
411
+ const MAX_FORGET_NEAR = 10
412
+
413
+ /** 命中方式的中文说法,写进 detail 让调用方看得懂这次靠什么定位的。 */
414
+ const FORGET_MODE_LABEL = {
415
+ substring: '子串命中',
416
+ timestamp: '时间戳命中',
417
+ 'timestamp+content': '时间戳+内容命中',
418
+ line: '行号命中',
419
+ none: '没命中',
420
+ }
421
+
422
+ const pad2 = (value) => String(value).padStart(2, '0')
423
+
424
+ /** 全角数字/冒号转半角(中文输入法里时间戳常被写成全角,坑过好几轮)。 */
425
+ function toHalfWidth(text) {
426
+ return String(text ?? '')
427
+ .replace(/[\uFF10-\uFF19]/g, (ch) => String.fromCharCode(ch.charCodeAt(0) - 0xfee0))
428
+ .replace(/\uFF1A/g, ':')
429
+ }
430
+
431
+ /**
432
+ * 把各种时间戳写法归一化成一个可比较的值。
433
+ *
434
+ * 认这些:`2026-11-13 12:50`、`2026/11/13 12:50:33`、`2026.11.13 12:50`、
435
+ * `2026-11-13T12:50`、`2026年11月13日 12:50`、只写 `12:50`、带中括号的
436
+ * `[2026-11-13 12:50]`。秒和毫秒直接丢掉——显示层只到分钟。
437
+ *
438
+ * @returns {{kind:'date'|'datetime'|'time', value:string}|null}
439
+ */
440
+ function normalizeStamp(input) {
441
+ let text = toHalfWidth(input).trim()
442
+ if (text.startsWith('[') && text.endsWith(']')) text = text.slice(1, -1).trim()
443
+ if (text.length === 0) return null
444
+ text = text
445
+ .replace(/[Tt](?=\d)/, ' ')
446
+ .replace(/[年月]/g, '-')
447
+ .replace(/日/g, ' ')
448
+ .replace(/\s+/g, ' ')
449
+ .trim()
450
+ let match = /^(\d{4})[-/.](\d{1,2})[-/.](\d{1,2})(?:[ ]+(\d{1,2}):(\d{2})(?::\d{2}(?:\.\d+)?)?)?$/.exec(text)
451
+ if (match !== null) {
452
+ const date = `${match[1]}-${pad2(match[2])}-${pad2(match[3])}`
453
+ if (match[4] === undefined) return { kind: 'date', value: date }
454
+ return { kind: 'datetime', value: `${date} ${pad2(match[4])}:${match[5]}` }
455
+ }
456
+ match = /^(\d{1,2}):(\d{2})(?::\d{2}(?:\.\d+)?)?$/.exec(text)
457
+ if (match !== null) return { kind: 'time', value: `${pad2(match[1])}:${match[2]}` }
458
+ return null
459
+ }
460
+
461
+ /** 时间戳是否对得上条目里存的 time;日期只比日期、只写时刻就比时刻。 */
462
+ function stampEquals(needle, entryTime) {
463
+ const entry = normalizeStamp(entryTime)
464
+ if (entry === null || entry.kind === 'time') return false
465
+ if (needle.kind === 'date') return entry.value.slice(0, 10) === needle.value
466
+ if (needle.kind === 'time') return entry.value.slice(-5) === needle.value
467
+ return entry.kind === 'datetime' && entry.value === needle.value
468
+ }
469
+
470
+ /** match 以时间戳开头时拆成「时间戳 + 内容片段」;拆不出来返回 null。 */
471
+ function splitStampPrefix(input) {
472
+ const text = String(input ?? '').trim()
473
+ const match = /^(\[[^\]]{3,40}\]|\d{4}[-/.]\d{1,2}[-/.]\d{1,2}(?:[ T]+\d{1,2}:\d{2}(?::\d{2})?)?)\s+([\s\S]+)$/.exec(text)
474
+ if (match === null) return null
475
+ const stamp = normalizeStamp(match[1])
476
+ if (stamp === null) return null
477
+ return { stamp, rest: match[2].trim() }
478
+ }
479
+
480
+ /** 忽略空白/标点/全半角差异后的比较串:只给"近似匹配"诊断用,绝不拿它去删。 */
481
+ function squish(text) {
482
+ return toHalfWidth(text)
483
+ .replace(/\s+/g, '')
484
+ .replace(/[,。、;:!?,.;:!?…"'“”‘’()()【】\[\]{}<>《》「」\-—_~·||/\\]/g, '')
485
+ .toLowerCase()
486
+ }
487
+
488
+ /** 候选/条目的一行预览:`[时间] 类别|内容`,超长截断。 */
489
+ function entryPreview(parsed, max = 80) {
490
+ const body = `${parsed.kind ? `${parsed.kind}|` : ''}${parsed.content}`
491
+ const text = body.length > max ? `${body.slice(0, max)}…` : body
492
+ return parsed.time.length > 0 ? `[${parsed.time}] ${text}` : text
493
+ }
494
+
495
+ /** 把命中摊成结构化的候选:档案 + 文件路径 + 行号 + 时间戳 + 内容摘要。 */
496
+ function entryCandidate(item, index, parsed) {
497
+ return {
498
+ path: item.label,
499
+ file: item.file,
500
+ line: index + 1,
501
+ time: parsed.time,
502
+ kind: parsed.kind,
503
+ content: parsed.content,
504
+ preview: entryPreview(parsed),
505
+ }
506
+ }
507
+
508
+ /**
509
+ * forget 的搜索范围。
510
+ * - 给了 path:只找那个档案(原来是这个行为,保留);
511
+ * - 没给 path:核心 + 整棵分类档案树。旧实现只搜核心,于是"那条明明在
512
+ * 某个档案里"就会报没找到——她看到的是全库视图,工具却只看了一个文件。
513
+ */
514
+ function forgetScope(pathInput) {
515
+ const core = coreFile()
516
+ const labelOf = (file) => (file === core ? 'core' : file.slice(treeDir().length + 1, -3).replace(/\\/g, '/'))
517
+ const readItem = (file) => ({ file, label: labelOf(file), lines: readRaw(file).split(/\r?\n/) })
518
+ const raw = String(pathInput ?? '').trim()
519
+ if (raw !== '') return { items: [readItem(resolveTarget(raw))], explicit: true }
520
+ const items = [readItem(core)]
521
+ for (const category of listTreeFiles()) {
522
+ const file = join(treeDir(), `${category}.md`)
523
+ if (existsSync(file)) items.push(readItem(file))
524
+ }
525
+ return { items, explicit: false }
526
+ }
527
+
528
+ /** 在范围内按条件逐条扫条目行。 */
529
+ function scanEntries(items, predicate) {
530
+ const hits = []
531
+ for (const item of items) {
532
+ item.lines.forEach((line, index) => {
533
+ const parsed = parseLine(line)
534
+ if (parsed !== null && predicate(parsed, line)) hits.push({ item, index, parsed })
535
+ })
536
+ }
537
+ return hits
538
+ }
539
+
540
+ /**
541
+ * 按「行号 → 原样子串 → 时间戳+内容 → 时间戳」的顺序定位条目。
542
+ * 行号优先:调用方既然给了 line,就是要那一行。
543
+ *
544
+ * @returns {{mode:string, hits:Array, lineMissed:boolean}}
545
+ */
546
+ function locateEntries(scope, match, lineNo) {
547
+ const needle = String(match ?? '').trim()
548
+ if (Number.isSafeInteger(lineNo) && lineNo > 0) {
549
+ const item = scope.items[0]
550
+ const index = lineNo - 1
551
+ const parsed = index >= 0 && index < item.lines.length ? parseLine(item.lines[index]) : null
552
+ if (parsed !== null) return { mode: 'line', hits: [{ item, index, parsed }], lineMissed: false }
553
+ }
554
+ if (needle.length > 0) {
555
+ // 1) 原样子串:老行为,最不容易误伤。
556
+ const plain = scanEntries(scope.items, (_parsed, line) => line.includes(needle))
557
+ if (plain.length > 0) return { mode: 'substring', hits: plain, lineMissed: false }
558
+ // 2) 时间戳 + 内容片段:`2026-11-13 12:50 收尾要点`。
559
+ const combo = splitStampPrefix(needle)
560
+ if (combo !== null) {
561
+ const comboHits = scanEntries(scope.items, (parsed, line) => stampEquals(combo.stamp, parsed.time) && line.includes(combo.rest))
562
+ if (comboHits.length > 0) return { mode: 'timestamp+content', hits: comboHits, lineMissed: false }
563
+ }
564
+ // 3) 纯时间戳:显示层的 `[2026-11-13 12:50]` 也能对上存了秒/T 分隔的原始行。
565
+ const stamp = normalizeStamp(needle)
566
+ if (stamp !== null) {
567
+ const stampHits = scanEntries(scope.items, (parsed) => stampEquals(stamp, parsed.time))
568
+ if (stampHits.length > 0) return { mode: 'timestamp', hits: stampHits, lineMissed: false }
569
+ }
570
+ }
571
+ return { mode: 'none', hits: [], lineMissed: Number.isSafeInteger(lineNo) && lineNo > 0 }
572
+ }
573
+
574
+ /**
575
+ * 0 命中时的近似匹配(诊断用,调用方拿它问"你是不是要找这条")。
576
+ * 先按忽略空白/标点/全半角比一遍;还不行且 match 是时间戳的话,放宽到
577
+ * "同一天/同一时刻"——时间戳差一位数字是最常见的失手。
578
+ */
579
+ function nearEntries(scope, match, stamp) {
580
+ const needle = squish(match)
581
+ if (needle.length > 0) {
582
+ const squished = scanEntries(scope.items, (_parsed, line) => squish(line).includes(needle))
583
+ if (squished.length > 0) return squished
584
+ }
585
+ if (stamp === null) return []
586
+ return scanEntries(scope.items, (parsed) => {
587
+ const entry = normalizeStamp(parsed.time)
588
+ if (entry === null || entry.kind === 'time') return false
589
+ if (stamp.kind === 'time') return entry.value.slice(-5) === stamp.value
590
+ return entry.value.slice(0, 10) === stamp.value.slice(0, 10)
591
+ })
592
+ }
593
+
210
594
  /** 读索引段:只认"整行就是标记"的行,避免子串误匹配。 */
211
595
  function getIndex(raw) {
212
596
  const lines = raw.split(/\r?\n/)
@@ -264,12 +648,14 @@ function searchAll(query, limit) {
264
648
  function renderCore() {
265
649
  ensureCore()
266
650
  const raw = readRaw(coreFile())
651
+ // 过滤口径与健康度共用 isStructuralLine:标题/引用/分隔线/整段索引都不进注入。
652
+ const indexState = {}
267
653
  const bodyLines = raw
268
654
  .split(/\r?\n/)
269
655
  .filter((line) => {
270
656
  const trimmed = line.trim()
271
- if (trimmed === '' || trimmed.startsWith('#') || trimmed.startsWith('>')) return false
272
- return trimmed !== INDEX_BEGIN && trimmed !== INDEX_END
657
+ if (trimmed === '') return false
658
+ return !isStructuralLine(trimmed, indexState)
273
659
  })
274
660
  .map((line) => line.trimEnd())
275
661
  while (bodyLines.length > 0 && bodyLines[0].trim() === '') bodyLines.shift()
@@ -488,7 +874,7 @@ export function apply(ctx) {
488
874
  ctx.tools.register({
489
875
  name: 'memory_organize',
490
876
  description:
491
- '整理你自己的记忆库——这是你的家务事,顺手做,不用问他。核心记忆攒多了就 tree 看看家底、把过气的 move 到分类档案、彻底没用的 forget 删掉;分类档案变多变杂了就更新 index(核心记忆里的那段目录,聊到相关话题时你靠它决定调哪个档案)。match 写那条记忆的独特片段。',
877
+ '整理你自己的记忆库——这是你的家务事,顺手做,不用问他。核心记忆攒多了就 tree 看看家底、把过气的 move 到分类档案、彻底没用的 forget 删掉;分类档案变多变杂了就更新 index(核心记忆里的那段目录,聊到相关话题时你靠它决定调哪个档案)。match 写那条记忆的独特片段;forget 也认条目时间戳(`2026-11-13 12:50`)和行号(line),命中多条时不会猜着删——它会列出候选(档案/行号/时间戳/摘要),你填 which 指定第几条,一次只删一条。tree 和 read 都会报每个档案的健康度(真实字节/行数、解析出的条目数、非条目占比)——占比偏高或字节数远超条目内容时会给 ⚠ 预警,说明这个档案可能被垃圾注入了。',
492
878
  parameters: {
493
879
  type: 'object',
494
880
  additionalProperties: false,
@@ -496,13 +882,29 @@ export function apply(ctx) {
496
882
  action: {
497
883
  type: 'string',
498
884
  enum: ['tree', 'read', 'move', 'index', 'forget'],
499
- description: 'tree=看家底(核心条数+全部分类文件);read=读一个分类档案的完整内容(path,"core"=核心);move=把一条记忆挪窝(match + 可选 path=来源,省略=核心;to=去向,"core"=进核心);index=重写核心记忆里的索引段(content);forget=删掉一条记忆(match + 可选 path,省略=核心)。',
885
+ description: 'tree=看家底(核心条数+全部分类文件);read=读一个分类档案的完整内容(path,"core"=核心);move=把一条记忆挪窝(match + 可选 path=来源,省略=核心;to=去向,"core"=进核心);index=重写核心记忆里的索引段(content);forget=删掉一条记忆(match 可以是内容片段、时间戳或 "时间戳+内容",也可以直接给 line 行号;match 命中多条时只列候选、用 which 挑,一次只删一条)。',
886
+ },
887
+ match: {
888
+ type: 'string',
889
+ description:
890
+ 'move/forget 用:那条记忆的独特片段。forget 还认时间戳——`2026-11-13 12:50`、只写 `12:50`、带秒的 `2026-11-13T12:50:33` 都能对上(显示层只到分钟,存储层可能有秒/T 分隔/全角)。也可以写「时间戳 + 内容片段」。命中多条不会乱删,会列候选让你用 which 挑。',
891
+ },
892
+ path: {
893
+ type: 'string',
894
+ description:
895
+ 'read/move/forget 用:分类路径(1~3 级);省略或 "core" 代表核心记忆。forget 省略 path 时会搜核心 + 全部分类档案(只列候选,不猜着删)。',
500
896
  },
501
- match: { type: 'string', description: 'move/forget 用:那条记忆内容里独特的片段,必须恰好命中一条。' },
502
- path: { type: 'string', description: 'read/move/forget 用:分类路径(1~3 级);省略或 "core" 代表核心记忆。' },
503
897
  to: { type: 'string', description: 'move 用:去向。分类路径,或 "core" 表示升入核心记忆。' },
504
898
  kind: { type: 'string', enum: KINDS, description: 'move 进核心时用:那条记忆的类别(用户/关系/我/事情),不填算"事情"。' },
505
899
  content: { type: 'string', description: 'index 用:新的索引全文。一句话一条,比如 "用户/口味:饮食偏好、忌口"。' },
900
+ which: {
901
+ type: 'integer',
902
+ description: 'forget 用:命中多条时挑第几条(候选序号,从 1 开始)。不传又有多条命中时只列候选、一条不删。',
903
+ },
904
+ line: {
905
+ type: 'integer',
906
+ description: 'forget 用:直接按文件行号定位(1 起,按 path 指向的文件算;不写 path 就是核心记忆)。',
907
+ },
506
908
  },
507
909
  required: ['action'],
508
910
  },
@@ -513,6 +915,47 @@ export function apply(ctx) {
513
915
  properties: {
514
916
  done: { type: 'boolean' },
515
917
  detail: { type: 'string' },
918
+ // 以下三个是 1.6.x 新增的「档案健康度可见」,只加不改老的 done/detail。
919
+ // tree 用:
920
+ coreHealth: HEALTH_SCHEMA,
921
+ files: {
922
+ type: 'array',
923
+ description: 'tree 用:每个分类档案的健康度。',
924
+ items: {
925
+ type: 'object',
926
+ additionalProperties: false,
927
+ properties: {
928
+ path: { type: 'string' },
929
+ health: HEALTH_SCHEMA,
930
+ },
931
+ required: ['path', 'health'],
932
+ },
933
+ },
934
+ // read 用:
935
+ path: { type: 'string' },
936
+ health: HEALTH_SCHEMA,
937
+ // forget 用(1.6.2 精确定位):新增字段全部在此声明——
938
+ // 宿主对输出也做 schema 校验(additionalProperties:false 多一个键就被拒)。
939
+ matchedBy: {
940
+ type: 'string',
941
+ description: 'forget 用:这次靠什么定位的——substring / timestamp / timestamp+content / line / none。',
942
+ },
943
+ removedFrom: { type: 'string', description: 'forget 用:删掉的那条在哪个档案(core 或分类路径);没删时为空串。' },
944
+ searched: {
945
+ type: 'array',
946
+ items: { type: 'string' },
947
+ description: 'forget 用:这次找过的文件(core 或分类路径),0 命中时用它说明"在哪些文件找的"。',
948
+ },
949
+ candidates: {
950
+ type: 'array',
951
+ items: FORGET_CANDIDATE_SCHEMA,
952
+ description: 'forget 用:命中多条时一条都没删,候选列在这里;用 which 指定序号再调一次。成功删除后这里是剩下的副本。',
953
+ },
954
+ nearMatches: {
955
+ type: 'array',
956
+ items: FORGET_CANDIDATE_SCHEMA,
957
+ description: 'forget 用:0 命中时按空白/标点/全半角归一化后的近似命中(只提示,没删任何东西)。',
958
+ },
516
959
  },
517
960
  required: ['done', 'detail'],
518
961
  },
@@ -522,29 +965,43 @@ export function apply(ctx) {
522
965
  const action = args?.action
523
966
  if (action === 'tree') {
524
967
  ensureCore()
525
- const lines = [`核心(memory.md):${readCoreEntries().length} 条`]
968
+ // 每个文件只读一次:健康度和条目数都从同一份文本算出来。
969
+ const coreHealth = fileHealth(readRaw(coreFile()), { isCore: true })
970
+ const lines = [`核心(memory.md):${coreHealth.entries} 条${healthBrief(coreHealth)}`]
971
+ for (const warning of coreHealth.warnings) lines.push(` ${warning}`)
526
972
  const files = listTreeFiles()
973
+ const reports = []
527
974
  if (files.length === 0) {
528
975
  lines.push('分类档案:还没有。非核心的记一笔就多一个文件。')
529
976
  } else {
530
977
  lines.push(`分类档案:${files.length} 个文件`)
531
978
  for (const category of files) {
532
- lines.push(` ${category}:${countEntries(join(treeDir(), `${category}.md`))} 条`)
979
+ const health = fileHealth(readRaw(join(treeDir(), `${category}.md`)), { isCore: false })
980
+ reports.push({ path: category, health })
981
+ lines.push(` ${category}:${health.entries} 条${healthBrief(health)}`)
982
+ for (const warning of health.warnings) lines.push(` ${warning}`)
533
983
  }
534
984
  }
985
+ lines.push(
986
+ '健康度 = 真实字节/行数 + 解析出的条目数 + 非条目占比(已排除标题、引用、分隔线、索引段这些结构行);非条目占比超阈值(核心 50%、分类 30%)或字节数远超条目内容,就是有垃圾沉淀。',
987
+ )
535
988
  lines.push('核心记忆每轮都注入,宁缺毋滥;过气的用 move 挪到分类、没用的 forget 删。')
536
- return { done: true, detail: lines.join('\n') }
989
+ return { done: true, detail: lines.join('\n'), coreHealth, files: reports }
537
990
  }
538
991
  if (action === 'read') {
539
992
  const file = resolveTarget(args?.path)
993
+ const label = String(args?.path ?? 'core')
540
994
  const raw = readRaw(file)
541
- if (raw.trim().length === 0) return { done: true, detail: `${args?.path ?? 'core'}:空的或还不存在。` }
542
- const lines = raw
995
+ const health = fileHealth(raw, { isCore: isCoreFile(file) })
996
+ const entries = raw
543
997
  .split(/\r?\n/)
544
998
  .map((line) => line.trim())
545
999
  .filter((line) => parseLine(line) !== null)
546
- if (lines.length === 0) return { done: true, detail: `${args?.path ?? 'core'}:还没有条目。` }
547
- return { done: true, detail: lines.join('\n') }
1000
+ const summary = [healthSummary(health), ...health.warnings]
1001
+ // 空文件/只有垃圾时也要把健康度带出来——"看不见垃圾"正是那次事故的病根。
1002
+ if (raw.trim().length === 0) return { done: true, path: label, health, detail: `${label}:空的或还不存在。` }
1003
+ if (entries.length === 0) return { done: true, path: label, health, detail: [`${label}:还没有条目。`, ...summary].join('\n') }
1004
+ return { done: true, path: label, health, detail: [...entries, '', ...summary].join('\n') }
548
1005
  }
549
1006
  if (action === 'move') {
550
1007
  const from = resolveTarget(args?.path)
@@ -574,13 +1031,97 @@ export function apply(ctx) {
574
1031
  return { done: true, detail: `索引更新好了,现在核心记忆里带着 ${text.split(/\r?\n/).length} 行目录。分类档案变了记得回来同步。` }
575
1032
  }
576
1033
  if (action === 'forget') {
577
- const file = resolveTarget(args?.path)
578
- const lines = readRaw(file).split(/\r?\n/)
579
- const index = uniqueEntryLine(lines, args?.match)
580
- const removed = lines[index].trim()
581
- lines.splice(index, 1)
582
- rewriteFile(file, lines)
583
- return { done: true, detail: `删掉了:${removed}` }
1034
+ const needle = String(args?.match ?? '').trim()
1035
+ const which = Number.isSafeInteger(args?.which) ? args.which : null
1036
+ const lineNo = Number.isSafeInteger(args?.line) ? args.line : null
1037
+ if (needle.length === 0 && lineNo === null) {
1038
+ throw new Error('forget 需要 match(条目片段,也可以是时间戳如 "2026-11-13 12:50"),或者 line(文件行号,1 起)')
1039
+ }
1040
+ if (which !== null && which < 1) throw new Error(`which 是候选序号,从 1 开始,收到 ${which}`)
1041
+ const scope = forgetScope(args?.path)
1042
+ const searched = scope.items.map((item) => item.label)
1043
+ const located = locateEntries(scope, needle, lineNo)
1044
+ const hits = located.hits
1045
+
1046
+ // 0 命中:说清在哪些文件找的、有没有近似匹配。一条都不删。
1047
+ if (hits.length === 0) {
1048
+ const stamp = normalizeStamp(needle) ?? splitStampPrefix(needle)?.stamp ?? null
1049
+ const near = nearEntries(scope, needle, stamp)
1050
+ const shown = near.slice(0, MAX_FORGET_NEAR)
1051
+ const lines = ['没找到能对上的记忆条目,一条都没删。']
1052
+ if (located.lineMissed) lines.push(`line=${lineNo} 在 ${scope.items[0].label} 里不是条目行(越界、空行,或者不是 "- [时间] …" 的形状)。`)
1053
+ if (needle.length > 0) lines.push(`match:「${needle}」(试过原样子串、时间戳、"时间戳 + 内容"三种对法)`)
1054
+ lines.push(
1055
+ `找过的地方(${searched.length} 个文件${scope.explicit ? ',path 指定' : ',没给 path 就扫了核心 + 全部分类档案'}):${searched.join('、')}`,
1056
+ )
1057
+ if (near.length > 0) {
1058
+ lines.push(`近似命中 ${near.length} 条(把空白/标点/全半角归一化后能对上,不是精确命中,所以没删)——你是不是要找这些?`)
1059
+ shown.forEach((hit, i) => lines.push(` ${i + 1}) ${hit.item.label}|第 ${hit.index + 1} 行|${entryPreview(hit.parsed)}`))
1060
+ if (near.length > shown.length) lines.push(` …还有 ${near.length - shown.length} 条没列出,把 match 写得更准一点再找。`)
1061
+ lines.push('要动手就把 match 换成上面某条里的连续片段(或用 path + line 精确定位),再调一次 forget。')
1062
+ } else {
1063
+ lines.push('也没有近似匹配。可以复制条目里的连续片段当 match,或用 path 指定档案、line 指定行号。')
1064
+ }
1065
+ if (which !== null) lines.push(`which=${which} 这次用不上:一条都没命中。`)
1066
+ return {
1067
+ done: false,
1068
+ detail: lines.join('\n'),
1069
+ matchedBy: 'none',
1070
+ candidates: [],
1071
+ nearMatches: shown.map((hit) => entryCandidate(hit.item, hit.index, hit.parsed)),
1072
+ searched,
1073
+ removedFrom: '',
1074
+ }
1075
+ }
1076
+
1077
+ // 命中多条(或 which 越界):列全部候选、一条都不删,给 which/path 出路。
1078
+ const chosenIndex = which !== null ? (which <= hits.length ? which - 1 : -1) : hits.length === 1 ? 0 : -1
1079
+ if (chosenIndex === -1) {
1080
+ const shown = hits.slice(0, MAX_FORGET_CANDIDATES)
1081
+ const lines = [
1082
+ `match 命中 ${hits.length} 条记忆,一条都没删——forget 一次只删一条,不替你全删。`,
1083
+ '候选(挑一条,把 which 填它的序号再调一次 forget;也可以补 path 只在一个档案里找):',
1084
+ ]
1085
+ shown.forEach((hit, i) => lines.push(` ${i + 1}) ${hit.item.label}|第 ${hit.index + 1} 行|${entryPreview(hit.parsed)}`))
1086
+ if (hits.length > shown.length) lines.push(` …还有 ${hits.length - shown.length} 条没列出,用 path 缩小范围再找。`)
1087
+ lines.push(`命中方式:${FORGET_MODE_LABEL[located.mode]}${which !== null ? `;which=${which} 超出 1~${hits.length} 的范围` : ''}。`)
1088
+ lines.push('继续:which=<序号>' + (scope.explicit ? '。' : ',或 path: "core" / 分类路径 只在一个档案里找。'))
1089
+ return {
1090
+ done: false,
1091
+ detail: lines.join('\n'),
1092
+ matchedBy: located.mode,
1093
+ candidates: shown.map((hit) => entryCandidate(hit.item, hit.index, hit.parsed)),
1094
+ nearMatches: [],
1095
+ searched,
1096
+ removedFrom: '',
1097
+ }
1098
+ }
1099
+
1100
+ // 定位到唯一一条:只删这一条。
1101
+ const chosen = hits[chosenIndex]
1102
+ const next = chosen.item.lines.slice()
1103
+ next.splice(chosen.index, 1)
1104
+ // 去掉尾部空行再回写:rewriteFile 会补一个换行,不然每删一条就多积一行空行。
1105
+ while (next.length > 0 && next[next.length - 1] === '') next.pop()
1106
+ rewriteFile(chosen.item.file, next)
1107
+ const where = chosen.item.label === 'core' ? '核心记忆' : `分类档案 ${chosen.item.label}`
1108
+ const removed = entryPreview(chosen.parsed)
1109
+ const rest = hits.filter((_hit, i) => i !== chosenIndex)
1110
+ const detailLines = [`删掉了(${where} 第 ${chosen.index + 1} 行,${FORGET_MODE_LABEL[located.mode]}):${removed}`]
1111
+ if (rest.length > 0) {
1112
+ detailLines.push(
1113
+ `注意:同样的 match 还命中 ${rest.length} 条副本,一条都没动——要删就再调一次 forget(现在 which 是 1~${rest.length}),或者先确认是不是该留一份。`,
1114
+ )
1115
+ }
1116
+ return {
1117
+ done: true,
1118
+ detail: detailLines.join('\n'),
1119
+ matchedBy: located.mode,
1120
+ candidates: rest.slice(0, MAX_FORGET_CANDIDATES).map((hit) => entryCandidate(hit.item, hit.index, hit.parsed)),
1121
+ nearMatches: [],
1122
+ searched,
1123
+ removedFrom: chosen.item.label,
1124
+ }
584
1125
  }
585
1126
  throw new Error(`未知的 action "${String(action ?? '')}",可用:tree / read / move / index / forget`)
586
1127
  },
@@ -742,7 +1283,7 @@ export function apply(ctx) {
742
1283
  properties: {
743
1284
  target: {
744
1285
  type: 'string',
745
- description: '目标目录绝对路径,如 "G:\\阿依娅伊\\记忆"。不能是系统盘、不能是插件包目录、不能已存在且非空、不能是 OneDrive/Dropbox 这类云同步目录。stay: true 时可省略。',
1286
+ description: '目标目录绝对路径,如 "D:\\阿依娅伊\\记忆"。不能是系统盘、不能是插件包目录、不能已存在且非空、不能是 OneDrive/Dropbox 这类云同步目录。stay: true 时可省略。',
746
1287
  },
747
1288
  confirm: {
748
1289
  type: 'boolean',
@@ -884,4 +1425,5 @@ export const __testing = {
884
1425
  renderCore,
885
1426
  readCoreEntries,
886
1427
  listTreeFiles,
1428
+ fileHealth,
887
1429
  }
package/lib/precompact.js CHANGED
@@ -477,7 +477,10 @@ export async function runPrecompact(ctx, cfg, payload) {
477
477
  kind: payload?.kind,
478
478
  memoryPath: payload?.memoryPath,
479
479
  })
480
- return { settled: true, ...result, verdict, trigger: payload?.trigger || 'manual' }
480
+ // skipped 在 schema.required 里,成功分支也必须显式给 false(否则宿主报
481
+ // `missing required property "value.skipped"`)。改在这里而不是 settle(),
482
+ // 是为免影响 settle() 的其他调用方。
483
+ return { settled: true, ...result, skipped: false, verdict, trigger: payload?.trigger || 'manual' }
481
484
  } catch (error) {
482
485
  try {
483
486
  ctx?.logger?.warn?.(`aiyayi-precompact: 沉淀失败(已跳过,不影响主流程): ${String(error?.message ?? error)}`)
@@ -606,6 +609,22 @@ export function apply(ctx, config) {
606
609
  title: { type: 'string' },
607
610
  reason: { type: 'string' },
608
611
  error: { type: 'string' },
612
+ // 下面四个是实际返回值里带、但旧 schema 漏声明的字段:
613
+ // 宿主对 output 做 JSON Schema 校验(additionalProperties: false),
614
+ // 漏声明 → 报 `"value.xxx" is not a declared property`(坑 #82)。
615
+ trigger: { type: 'string' },
616
+ memoryFile: { type: 'string' },
617
+ filename: { type: 'string' },
618
+ verdict: {
619
+ type: 'object',
620
+ properties: {
621
+ worth: { type: 'boolean' },
622
+ score: { type: 'number' },
623
+ reasons: { type: 'array', items: { type: 'string' } },
624
+ },
625
+ required: ['worth', 'score', 'reasons'],
626
+ additionalProperties: false,
627
+ },
609
628
  },
610
629
  required: ['settled', 'skipped'],
611
630
  },
@@ -18,18 +18,18 @@
18
18
  * {
19
19
  * "name": "mem_sync", // 必填,^[a-z][a-z0-9_]{1,40}$
20
20
  * "enabled": true, // 默认 false,显式 true 才注册
21
- * "script": "G:/阿依娅伊/工具/mem_sync/mem_sync.js", // 必填,支持 ~ 与 %变量%
21
+ * "script": "~/tools/mem_sync/mem_sync.js", // 必填,支持 ~ 与 %变量%
22
22
  * "description": "…", // 必填,给模型的工具描述
23
23
  * "timeoutMs": 60000, // 默认 60000,上限 300000
24
24
  * "mode": "async", // 只支持 async(sync 一律拒绝)
25
25
  * "args": [], // 固定参数(附加在脚本路径之后)
26
26
  * "params": { "message": { "type": "string", "description": "…" } }, // 可选,调用参数
27
27
  * "env": { "KEY": "VALUE" }, // 可选,给脚本的环境变量(本机配置走这里)
28
- * "cwd": "G:/阿依娅伊/工具/mem_sync", // 可选,默认脚本所在目录
28
+ * "cwd": "~/tools/mem_sync", // 可选,默认脚本所在目录
29
29
  * "capabilities": { // 1.6.1 可选,能力声明(不声明 = 全量能力,兼容现状)
30
30
  * "paths": { // 路径白名单(绝对路径,支持 ~ 与 %变量% 展开)
31
- * "read": ["G:/阿依娅伊/记忆"],
32
- * "write": ["G:/阿依娅伊/记忆/notes"]
31
+ * "read": ["~/memory"],
32
+ * "write": ["~/memory/notes"]
33
33
  * },
34
34
  * "process": true, // 是否允许 spawn 子进程(默认 true)
35
35
  * "env": "full" // 传给脚本的环境变量:"full"(默认)或白名单键数组
package/lib/toolkit.js CHANGED
@@ -85,7 +85,7 @@ export const inject = ['tools']
85
85
  *
86
86
  * **1.6.1:`lib/toolkit-extra.js` / `lib/pkg-stats.js` 实现文件已删除**(连同 package.json 的
87
87
  * files/exports 条目)。当初保留的理由是"1.5.41/1.5.42 的单测还在用",但 test/ 不进 npm 包,
88
- * 这个理由不成立;watch_read / mem_sync / pkg_stats 现在是纯本机清单脚本(G:\阿依娅伊\工具\…),
88
+ * 这个理由不成立;watch_read / mem_sync / pkg_stats 现在是纯本机清单脚本(各自主机目录下,如 ~/tools/…),
89
89
  * 仓库里不再保留其实现。对应单测(pkg-stats.test.mjs / mem-sync-1543.test.mjs 及
90
90
  * toolkit-async.test.mjs 里依赖这两个模块的段落)一并移除。
91
91
  *
@@ -148,7 +148,7 @@ export const DEFAULT_CONFIG = {
148
148
  // 自己从 argv / 环境变量读参数)。保留默认值只为两件事:
149
149
  // ① 1.5.43 的既有单测断言这些键存在(发版方本机的 memPushRemotes / memBranch 迁移期);
150
150
  // ② 升级用户 cordis.patch.yml 里已写的同名项不会变成孤儿配置而被静默忽略。
151
- // mem_sync / pkg_stats / watch_read 的默认值现在写在各自脚本里(G:\阿依娅伊\工具\…)。
151
+ // mem_sync / pkg_stats / watch_read 的默认值现在写在各自脚本里(~/tools/…)。
152
152
  // mem_sync(1.5.41,同步;1.5.43 改默认值):提交后推哪些远端、推哪个分支(顺序即汇报顺序)。
153
153
  // ⚠ **1.5.43 破坏性变更**:`memPushRemotes` 默认由 `['gitee','gitcode']` 改为 **`[]`**。
154
154
  // 空/未配置 = **不推也不提交**(status:"noop",零副作用)。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-aiyayi",
3
- "version": "1.6.1",
3
+ "version": "1.6.3",
4
4
  "license": "MIT",
5
5
  "author": "巴依浩爷 (bayihy)",
6
6
  "keywords": [
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "_comment": "Local module-resolution override for this directory only. Not a publishable npm package.",
3
- "_reason": "The nearest ancestor package.json (G:/.../dsh-aiyayi/package.json) declares \"type\": \"module\", which makes the CommonJS scripts in this folder (create-bot.js etc., which use require()) fail with: ReferenceError: require is not defined in ES module scope. This file overrides that for this directory.",
3
+ "_reason": "The nearest ancestor package.json (the installed dsh-aiyayi/package.json) declares \"type\": \"module\", which makes the CommonJS scripts in this folder (create-bot.js etc., which use require()) fail with: ReferenceError: require is not defined in ES module scope. This file overrides that for this directory.",
4
4
  "_not_a_package": "Do not npm install / npm publish here.",
5
5
  "name": "feishu-setup-scripts-local",
6
6
  "private": true,
@@ -16,7 +16,7 @@ const path = require('path');
16
16
  const args = process.argv.slice(2);
17
17
  function arg(name, def) { const i = args.indexOf('--' + name); return i >= 0 ? args[i + 1] : def; }
18
18
  const APP_ID = arg('app-id', '');
19
- const OUT = arg('out', '') || ('D:\\AI\\TRAE_PRO\\阿依娅依\\work\\feishu-app-create\\credential-' + APP_ID + '.json');
19
+ const OUT = arg('out', '') || path.join(process.cwd(), 'work', 'feishu-app-create', 'credential-' + APP_ID + '.json');
20
20
  const PORT = arg('port', '9222');
21
21
  if (!APP_ID) { console.error('用法: node save-secret.js --app-id cli_xxx [--out 路径]'); process.exit(1); }
22
22
  function withTimeout(p, ms, label) { return Promise.race([p, new Promise((_, rej) => setTimeout(() => rej(new Error('TIMEOUT ' + label)), ms))]); }