lingshu-skill 3.88.0 → 3.90.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 +23 -0
- package/README.md +1 -1
- package/SKILL.md +1 -1
- package/cordis-plugin/lingshu-startup/context-pressure.js +15 -1
- package/cordis-plugin/lingshu-startup/plugin.js +5 -1
- package/docs//350/277/233/345/261/225/344/270/216/345/276/205/345/212/236.md +4 -0
- package/package.json +1 -1
- package/scripts/astrbot_plugin_lingshu/CHECKSUMS.json +5 -5
- package/scripts/astrbot_plugin_lingshu/engine/CHANGELOG.md +23 -0
- package/scripts/astrbot_plugin_lingshu/engine/README.md +1 -1
- package/scripts/astrbot_plugin_lingshu/engine/SKILL.md +1 -1
- package/scripts/astrbot_plugin_lingshu/engine/scripts/cli.py +6 -2
- package/scripts/astrbot_plugin_lingshu/engine/scripts/memory.py +44 -1
- package/scripts/cli.py +6 -2
- package/scripts/memory.py +44 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# 更新日志
|
|
2
2
|
|
|
3
|
+
## v3.90(2026-11-23)
|
|
4
|
+
|
|
5
|
+
> 主题:**P9 #58 注入噪音被当记忆存进库**——真库 244 条里 23 条(9.4%)是宿主样板。
|
|
6
|
+
|
|
7
|
+
- **问题**:`<system-reminder>`、`Current Coding Agent Web GUI URL: …`、`Approval prompts are disabled…` 这类宿主注入样板被 `capture`(即记即存)原文搬运进了记忆库;`auto_dream` 再把它们机械拼接成「最近关于X的一组事情(N条):<样板>」送进审核队列。
|
|
8
|
+
- **修**:
|
|
9
|
+
- 新增 `memory._is_noise_text()`:命中噪音标记后剔掉标记片段,剩余实质字符不足 40 判为纯噪音;混合段(样板+真实内容)保留,宁多存不漏存。
|
|
10
|
+
- `capture` 的 `_split_segments` 末段过滤加噪音判断——**verbatim 原文归档不经过这里,仍完整保留**(可追溯性不受影响)。
|
|
11
|
+
- `auto_dream` 拼接摘要前先滤噪音文本;滤完不足 2 条则不出摘要。
|
|
12
|
+
- 实测:6 类判据全对;capture 跳噪音但真实内容不丢;混合段保留。
|
|
13
|
+
|
|
14
|
+
验证:`tests/test_noise_filter.py` 3/3;六项检查 + 行为基线 + 全量测试全过。
|
|
15
|
+
|
|
16
|
+
## v3.89(2026-11-23)
|
|
17
|
+
|
|
18
|
+
> 主题:**P9 #57 新会话水位时序缺陷**——首次注入把上个会话的水位标成"本会话实测"。
|
|
19
|
+
|
|
20
|
+
- **问题**:`agent/created` 生成 startup 文本时读 `.context-pressure.json`,但该文件是**上个会话** pre-step 写的(本会话 pre-step 尚未运行)→ 全新会话可能显示"水位 90%(本会话实测)",误导 AI 在空会话里做梦/封存。
|
|
21
|
+
- **修**:`context-pressure.js` 新增 `clearContextPressure()`;startup 插件在 `agent/created` 且 `source === 'startup'`(全新会话)时先清掉陈旧样本 → 首轮诚实显示"未知(本次尚未测量)",pre-step 再写本会话真实值。**resume 不清**(同一会话续聊,样本仍有效)。
|
|
22
|
+
- 实测:清除函数生效(文件存在→不存在);无样本时 `_water_level` 正确报 `stale=True` + 保留 last_session_pct 供"上次记录"展示。
|
|
23
|
+
|
|
24
|
+
验证:`tests/test_water_linkage.py` 3/3;JS 两文件 node --check;六项检查 + 行为基线 + 全量测试全过。
|
|
25
|
+
|
|
3
26
|
## v3.88(2026-11-23)
|
|
4
27
|
|
|
5
28
|
> 主题:**P9 水位联动审查**——发现 v3.86 只接通了"显示",注入降档仍读老机制(恒 full),本次打通联动。
|
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
> 名字取自《黄帝内经》:**算力给思考,人格给灵魂,记忆给生命。**
|
|
4
4
|
|
|
5
|
-
> 当前版本 **v3.
|
|
5
|
+
> 当前版本 **v3.90**(变更见 [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.md
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
// - 任何异常都吞掉(pre-step 是 wrapping 监听器,抛异常会破坏请求);
|
|
13
13
|
// - ctx.tokenMeter 不存在(旧版 DSH/未挂载)时静默跳过,写 availability=false 让 Python 侧知道。
|
|
14
14
|
|
|
15
|
-
import { readFileSync, writeFileSync } from 'node:fs'
|
|
15
|
+
import { readFileSync, rmSync, writeFileSync } from 'node:fs'
|
|
16
16
|
import { homedir } from 'node:os'
|
|
17
17
|
import { join } from 'node:path'
|
|
18
18
|
|
|
@@ -78,3 +78,17 @@ function write(file, out) {
|
|
|
78
78
|
} catch { /* 写失败不影响请求 */ }
|
|
79
79
|
return out
|
|
80
80
|
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* 新会话启动时清掉上个会话留下的样本(P9 #57)。
|
|
84
|
+
*
|
|
85
|
+
* 为什么需要:`agent/created` 生成 startup 文本时,`.context-pressure.json`
|
|
86
|
+
* 还是**上个会话** pre-step 写的(本会话 pre-step 尚未运行)。不清掉的话,
|
|
87
|
+
* 全新会话会显示"水位 90%(本会话实测)"——误导 AI 在空会话里做梦/封存。
|
|
88
|
+
* 清掉后首轮诚实显示"未知(本次尚未测量)",pre-step 再写本会话真实值。
|
|
89
|
+
*/
|
|
90
|
+
export function clearContextPressure() {
|
|
91
|
+
try {
|
|
92
|
+
rmSync(join(memoryHome(), '.context-pressure.json'), { force: true })
|
|
93
|
+
} catch { /* 清不掉也不影响:首轮只是显示旧值 */ }
|
|
94
|
+
}
|
|
@@ -25,7 +25,7 @@ import { homedir } from 'node:os'
|
|
|
25
25
|
import { delimiter, dirname, join } from 'node:path'
|
|
26
26
|
import { createHash, randomUUID } from 'node:crypto'
|
|
27
27
|
import { fileURLToPath } from 'node:url'
|
|
28
|
-
import { sampleContextPressure } from './context-pressure.js'
|
|
28
|
+
import { clearContextPressure, sampleContextPressure } from './context-pressure.js'
|
|
29
29
|
|
|
30
30
|
// 刻意零外部依赖:不 import @deepseek-ai/schemastery。原因——link: 安装时模块
|
|
31
31
|
// 真实路径留在技能目录,Node 从那里向上找 node_modules 一路到盘符根都找不到
|
|
@@ -265,6 +265,10 @@ export function apply(ctx, config) {
|
|
|
265
265
|
if (source !== 'startup' && source !== 'resume') return
|
|
266
266
|
if (source === 'resume' && !cfg.injectResume) return
|
|
267
267
|
if (pending.has(agent)) return
|
|
268
|
+
// P9 #57:全新会话先清掉上个会话留下的水位样本——否则首轮注入会把
|
|
269
|
+
// 上个会话的"水位 90%"标成"本会话实测",误导 AI 在空会话里做梦/封存。
|
|
270
|
+
// resume 不清:同一会话续聊,样本仍属本会话,清掉反而丢有效值。
|
|
271
|
+
if (source === 'startup') clearContextPressure()
|
|
268
272
|
|
|
269
273
|
const brainPy = await findBrainPy(cfg.brainPy, ctx)
|
|
270
274
|
if (!brainPy) {
|
|
@@ -359,6 +359,10 @@ startup 注入的记忆块与 cron 的瞬态提醒**同名**,于是 cron 的 p
|
|
|
359
359
|
55. **【中·口径分裂】两套压力文件各说各话**:显示用 `.context-pressure.json`(0-1 小数、实时),降档用 `_pressure.json`(0-100、手工写),只在主动跑 check-context 时同步一次。**修**:同 #54 统一到 tokenMeter 优先。 **【已在 v3.88 修】统一口径(手工新鲜值优先,token其次)**
|
|
360
360
|
56. **【中·提示陈旧】水位守则的 pct 显示来自老文件**(`memory.py:4148`):minimal 档提示"上下文已偏满(X%)"用的是 `_pressure.get('pct')`(可能陈旧/None),不是实时值。**随 #54 一起修**。 **【已在 v3.88 修】守则提示 pct 随 read_pressure 变实时**
|
|
361
361
|
|
|
362
|
+
57. **【中·时序缺陷】新会话首次注入显示上个会话的水位且标“本会话实测”**:`agent/created` 生成 startup 文本时读 `.context-pressure.json`,但该文件是**上个会话** pre-step 写的(本会话 pre-step 还没跑)→ 全新会话可能显示“水位 90%(本会话实测)”,误导 AI 在空会话里做梦/封存。**修**:plugin 在 `agent/created`(source=startup)时先清掉陈旧样本,让首轮诚实显示“未知(本次尚未测量)”,pre-step 再写真实值。 **【已在 v3.89 修】新会话启动清掉陈旧样本,首轮诚实报未知**
|
|
363
|
+
|
|
364
|
+
58. **【中·数据质量】注入噪音被当记忆存进库**:真库 244 条记忆里 **23 条(9.4%)是纯噪音**——`<system-reminder>`、`Current Coding Agent Web GUI URL: …`、`Approval prompts are disabled…`。`session_import.py` 已有同类过滤,但 `capture`(即记即存)路径没有,原文搬运时把这些注入块也存成了记忆;`auto_dream` 再把它们机械拼接成「最近关于X的一组事情(N条):…」进审核队列。**修**:加共享噪音识别 `_is_noise_text()`,`capture` 跳噪音段(verbatim 原文仍全留,保可追溯),`auto_dream` 拼接前先滤噪音、干净文本不足 2 条则不出摘要。 **【已在 v3.90 修】_is_noise_text + capture 跳噪音段 + auto_dream 滤噪音**
|
|
365
|
+
|
|
362
366
|
## 三、已知问题与风险
|
|
363
367
|
|
|
364
368
|
| # | 现象 | 影响 | 处置 |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lingshu-skill",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.90.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,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"PATCH_NOTES.md": "9296e524f743f358fd11115598398a754cfd69534526dde9c8ad85f14a418f89",
|
|
3
3
|
"README.md": "3d634d743b085eebd2cbb5dd3a00edfa728ed23947e20cc29e7c3b29087ec043",
|
|
4
|
-
"engine/CHANGELOG.md": "
|
|
5
|
-
"engine/README.md": "
|
|
4
|
+
"engine/CHANGELOG.md": "456b0c2d7ae0c49e0c19958962f1f0616c730a8abddcd16254cc245d29f36d27",
|
|
5
|
+
"engine/README.md": "bb549e6ec80efdd228aa82ca2705b5edcd7a68310e38805bb5550068e42e7e7b",
|
|
6
6
|
"engine/SKILL-lite.md": "04b87789232a0f7537c861c857888b4a0e947bcf92a461cbad5328af05361c58",
|
|
7
7
|
"engine/SKILL-tiny.md": "74e1955cc5bf4ec0ca28d52030f799f039283de27a52345a33ce783d6ee0c608",
|
|
8
|
-
"engine/SKILL.md": "
|
|
8
|
+
"engine/SKILL.md": "d0b3fe51d7e6f7df7b198474983ba19e40e482a4f14e2d419be5c2caaa9e4097",
|
|
9
9
|
"engine/assets/panel.html": "8b368f16f0c1447413456a16cb4666daa4df08983bd30d627af04ad2a0fbda26",
|
|
10
10
|
"engine/docs/commands.md": "15f57adbeeca393fe001831853d5b9a5dfb237ac666711fa5662000eb22b2c59",
|
|
11
11
|
"engine/docs/mechanics.md": "e8a6602a434ed5b78cac64a98884f65a6888eb48daa7a1c0be1f6c3984041b34",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"engine/scripts/check_pressure_sync.py": "46d53934f17c7b740d0ec9fdbef9d2653850f6e01e883eedd70ff9a1527e869a",
|
|
20
20
|
"engine/scripts/check_tag.py": "6f0b8209dc2deebb1f9ec90d429e1fad60c040a2ec014a6406d9d3498faafd7f",
|
|
21
21
|
"engine/scripts/checkpoint.py": "ec74e70e6ae1338ee3d7048c71b8297a1f60bd3c572a2e2843b8e9696bdf2d9a",
|
|
22
|
-
"engine/scripts/cli.py": "
|
|
22
|
+
"engine/scripts/cli.py": "a2ed9d8c50383046a2bc48168b44c2baff31002876598a0313b96dc7e44863b0",
|
|
23
23
|
"engine/scripts/context_ab.py": "3d383f1fc16d328612825bbf731866fa427da0746490d027a0ddb719d210f1cb",
|
|
24
24
|
"engine/scripts/core.py": "08be3f2e57eebc29e9b096a75f953cc1ff5c1e6000b2f84f74f1c5c8f965f162",
|
|
25
25
|
"engine/scripts/dream.py": "e25749c32fe6cb3b3845c9541ef663dffe8efaa0d9bd251f611e1359208800b9",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"engine/scripts/mem_lesson.py": "6d9c26d4307dccb80f01d406e5253fe26f3540e0774b212f5fbd939d2ac442f0",
|
|
36
36
|
"engine/scripts/mem_score.py": "95dcecba5f4db7c0c16ebc415434e1cb58cc7dd8b8213360b4df36e2a90faf6e",
|
|
37
37
|
"engine/scripts/mem_topic.py": "c22f75c128cdd3b26ff845f1a71608401bc0dc8955f9f0e1988d7f0cd663d0d5",
|
|
38
|
-
"engine/scripts/memory.py": "
|
|
38
|
+
"engine/scripts/memory.py": "43e694e06b0274fecabab5a66c87f4f514afcb18cd81d9dd622f28fe0615109b",
|
|
39
39
|
"engine/scripts/npm_prepack.py": "d62c491a6f9edfcab2dd465a995e72df879a61b4da26ae0fe76121c8adc77e02",
|
|
40
40
|
"engine/scripts/panel_build.py": "6394c1d74d203093e43b2106d7acca6e0ca9db61ca1cd6cd3a1616053653414b",
|
|
41
41
|
"engine/scripts/panel_cloud.py": "fff72888123d45bbf05ab329a06b2126f1c0b972c76283ecff32454bc4155c58",
|
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# 更新日志
|
|
2
2
|
|
|
3
|
+
## v3.90(2026-11-23)
|
|
4
|
+
|
|
5
|
+
> 主题:**P9 #58 注入噪音被当记忆存进库**——真库 244 条里 23 条(9.4%)是宿主样板。
|
|
6
|
+
|
|
7
|
+
- **问题**:`<system-reminder>`、`Current Coding Agent Web GUI URL: …`、`Approval prompts are disabled…` 这类宿主注入样板被 `capture`(即记即存)原文搬运进了记忆库;`auto_dream` 再把它们机械拼接成「最近关于X的一组事情(N条):<样板>」送进审核队列。
|
|
8
|
+
- **修**:
|
|
9
|
+
- 新增 `memory._is_noise_text()`:命中噪音标记后剔掉标记片段,剩余实质字符不足 40 判为纯噪音;混合段(样板+真实内容)保留,宁多存不漏存。
|
|
10
|
+
- `capture` 的 `_split_segments` 末段过滤加噪音判断——**verbatim 原文归档不经过这里,仍完整保留**(可追溯性不受影响)。
|
|
11
|
+
- `auto_dream` 拼接摘要前先滤噪音文本;滤完不足 2 条则不出摘要。
|
|
12
|
+
- 实测:6 类判据全对;capture 跳噪音但真实内容不丢;混合段保留。
|
|
13
|
+
|
|
14
|
+
验证:`tests/test_noise_filter.py` 3/3;六项检查 + 行为基线 + 全量测试全过。
|
|
15
|
+
|
|
16
|
+
## v3.89(2026-11-23)
|
|
17
|
+
|
|
18
|
+
> 主题:**P9 #57 新会话水位时序缺陷**——首次注入把上个会话的水位标成"本会话实测"。
|
|
19
|
+
|
|
20
|
+
- **问题**:`agent/created` 生成 startup 文本时读 `.context-pressure.json`,但该文件是**上个会话** pre-step 写的(本会话 pre-step 尚未运行)→ 全新会话可能显示"水位 90%(本会话实测)",误导 AI 在空会话里做梦/封存。
|
|
21
|
+
- **修**:`context-pressure.js` 新增 `clearContextPressure()`;startup 插件在 `agent/created` 且 `source === 'startup'`(全新会话)时先清掉陈旧样本 → 首轮诚实显示"未知(本次尚未测量)",pre-step 再写本会话真实值。**resume 不清**(同一会话续聊,样本仍有效)。
|
|
22
|
+
- 实测:清除函数生效(文件存在→不存在);无样本时 `_water_level` 正确报 `stale=True` + 保留 last_session_pct 供"上次记录"展示。
|
|
23
|
+
|
|
24
|
+
验证:`tests/test_water_linkage.py` 3/3;JS 两文件 node --check;六项检查 + 行为基线 + 全量测试全过。
|
|
25
|
+
|
|
3
26
|
## v3.88(2026-11-23)
|
|
4
27
|
|
|
5
28
|
> 主题:**P9 水位联动审查**——发现 v3.86 只接通了"显示",注入降档仍读老机制(恒 full),本次打通联动。
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
> 名字取自《黄帝内经》:**算力给思考,人格给灵魂,记忆给生命。**
|
|
4
4
|
|
|
5
|
-
> 当前版本 **v3.
|
|
5
|
+
> 当前版本 **v3.90**(变更见 [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
|
|
|
@@ -926,6 +926,7 @@ def auto_dream(trigger: str = "auto", dry_run: bool = False) -> dict:
|
|
|
926
926
|
"""内置自愈式做梦:机器重放 → 启发式压缩 → 自动沉淀。
|
|
927
927
|
不依赖外部 dream_auto 脚本;人格不自动改;更抽象的压缩仍建议人工复核梦报告。"""
|
|
928
928
|
from collections import Counter
|
|
929
|
+
import memory as _mem # 局部导入:与 cli.py 其它函数一致,裸导入 cli 也能用
|
|
929
930
|
report = dream(trigger, dry_run=dry_run)
|
|
930
931
|
if not report["clusters"]:
|
|
931
932
|
return {"applied": False, "report": report, "memories": 0}
|
|
@@ -937,12 +938,15 @@ def auto_dream(trigger: str = "auto", dry_run: bool = False) -> dict:
|
|
|
937
938
|
}
|
|
938
939
|
memories = []
|
|
939
940
|
for c in report["clusters"]:
|
|
940
|
-
|
|
941
|
+
# P9 #58:先剔掉宿主注入样板(system-reminder / GUI URL 等)——
|
|
942
|
+
# 它们不是对话内容,拼进摘要只会造出「最近关于X的一组事情:<样板>」这种垃圾条目。
|
|
943
|
+
texts = [t for t in c["texts"] if not _mem._is_noise_text(t.get("text", ""))]
|
|
941
944
|
top = sorted(texts, key=lambda t: _num(t.get("importance"), 0.5), reverse=True)[:3]
|
|
942
|
-
kind = Counter(t["kind"] for t in texts).most_common(1)[0][0]
|
|
945
|
+
kind = Counter(t["kind"] for t in texts).most_common(1)[0][0] if texts else "episode"
|
|
943
946
|
label = "、".join(c["tags"][:4]) or "、".join(c["entities"][:4]) or "未命名主题"
|
|
944
947
|
# 只有 1 条记忆的簇不值得造摘要——摘要几乎等于原文复制,入库后和源记忆
|
|
945
948
|
# 重叠(还共享标签/实体,自动联想又给它们连一堆冗余边)。单条簇跳过。
|
|
949
|
+
# 滤完噪音后不足 2 条同样跳过(否则摘要里只剩噪音)。
|
|
946
950
|
if len(texts) < 2:
|
|
947
951
|
continue
|
|
948
952
|
joined = ";".join(t["text"] for t in top)
|
|
@@ -2817,6 +2817,46 @@ _SPEAKER_RE = re.compile(
|
|
|
2817
2817
|
re.IGNORECASE,
|
|
2818
2818
|
)
|
|
2819
2819
|
|
|
2820
|
+
# 宿主注入的样板文本(P9 #58):不是对话内容,存成记忆只会污染库与审核队列。
|
|
2821
|
+
# 真库实测 244 条记忆里 23 条(9.4%)是这类噪音。session_import 早有同类过滤,
|
|
2822
|
+
# 但 capture(即记即存)路径没有——这里补上共享判据。
|
|
2823
|
+
_NOISE_MARKERS = (
|
|
2824
|
+
"system-reminder",
|
|
2825
|
+
"current coding agent web gui url",
|
|
2826
|
+
"current coding agent implementation checkout",
|
|
2827
|
+
"current app file policy",
|
|
2828
|
+
"approval prompts are disabled",
|
|
2829
|
+
"actions that require approval are rejected automatically",
|
|
2830
|
+
"current deepseek",
|
|
2831
|
+
"available_skills",
|
|
2832
|
+
"the following information describes your current session",
|
|
2833
|
+
"sandbox_permissions",
|
|
2834
|
+
)
|
|
2835
|
+
|
|
2836
|
+
|
|
2837
|
+
def _is_noise_text(text: str) -> bool:
|
|
2838
|
+
"""判断一段文本是否基本全是宿主注入样板(无对话价值)。
|
|
2839
|
+
|
|
2840
|
+
规则:命中任一噪音标记后,把标记片段剔掉再看剩余有效字符——剩余不足 40
|
|
2841
|
+
字符判为纯噪音(整段都是样板);剩余够多说明是"样板+真实内容"的混合段,
|
|
2842
|
+
保留(宁多存不漏存,真实内容别丢)。
|
|
2843
|
+
"""
|
|
2844
|
+
s = str(text or "").strip()
|
|
2845
|
+
if not s:
|
|
2846
|
+
return True
|
|
2847
|
+
low = s.lower()
|
|
2848
|
+
if not any(m in low for m in _NOISE_MARKERS):
|
|
2849
|
+
return False
|
|
2850
|
+
rest = s
|
|
2851
|
+
for m in _NOISE_MARKERS:
|
|
2852
|
+
rest = re.sub(re.escape(m), "", rest, flags=re.IGNORECASE)
|
|
2853
|
+
# 剔掉标记后剩余的实质字符(去掉尖括号标签、URL、空白)
|
|
2854
|
+
rest = re.sub(r"</?[a-zA-Z_][\w-]*[^>]*>", " ", rest)
|
|
2855
|
+
rest = re.sub(r"https?://\S+", " ", rest)
|
|
2856
|
+
rest = re.sub(r"[\s\W_]+", "", rest)
|
|
2857
|
+
return len(rest) < 40
|
|
2858
|
+
|
|
2859
|
+
|
|
2820
2860
|
|
|
2821
2861
|
def _split_segments(text: str) -> list:
|
|
2822
2862
|
"""把一段会话原文切成可独立成条的片段:空行 / 分隔线 / 说话人切换。
|
|
@@ -2846,7 +2886,10 @@ def _split_segments(text: str) -> list:
|
|
|
2846
2886
|
out = []
|
|
2847
2887
|
for s in segs:
|
|
2848
2888
|
s = re.sub(r"\s+", " ", s).strip()
|
|
2849
|
-
|
|
2889
|
+
# P9 #58:跳过宿主注入样板(system-reminder / GUI URL / 审批提示)——
|
|
2890
|
+
# 它们不是对话内容,存成记忆只会污染库与审核队列。verbatim 原文归档
|
|
2891
|
+
# 不经过这里,仍完整保留(可追溯性不受影响)。
|
|
2892
|
+
if len(s) >= CAPTURE_MIN_LEN and not _is_noise_text(s):
|
|
2850
2893
|
out.append(s)
|
|
2851
2894
|
return out
|
|
2852
2895
|
|
package/scripts/cli.py
CHANGED
|
@@ -926,6 +926,7 @@ def auto_dream(trigger: str = "auto", dry_run: bool = False) -> dict:
|
|
|
926
926
|
"""内置自愈式做梦:机器重放 → 启发式压缩 → 自动沉淀。
|
|
927
927
|
不依赖外部 dream_auto 脚本;人格不自动改;更抽象的压缩仍建议人工复核梦报告。"""
|
|
928
928
|
from collections import Counter
|
|
929
|
+
import memory as _mem # 局部导入:与 cli.py 其它函数一致,裸导入 cli 也能用
|
|
929
930
|
report = dream(trigger, dry_run=dry_run)
|
|
930
931
|
if not report["clusters"]:
|
|
931
932
|
return {"applied": False, "report": report, "memories": 0}
|
|
@@ -937,12 +938,15 @@ def auto_dream(trigger: str = "auto", dry_run: bool = False) -> dict:
|
|
|
937
938
|
}
|
|
938
939
|
memories = []
|
|
939
940
|
for c in report["clusters"]:
|
|
940
|
-
|
|
941
|
+
# P9 #58:先剔掉宿主注入样板(system-reminder / GUI URL 等)——
|
|
942
|
+
# 它们不是对话内容,拼进摘要只会造出「最近关于X的一组事情:<样板>」这种垃圾条目。
|
|
943
|
+
texts = [t for t in c["texts"] if not _mem._is_noise_text(t.get("text", ""))]
|
|
941
944
|
top = sorted(texts, key=lambda t: _num(t.get("importance"), 0.5), reverse=True)[:3]
|
|
942
|
-
kind = Counter(t["kind"] for t in texts).most_common(1)[0][0]
|
|
945
|
+
kind = Counter(t["kind"] for t in texts).most_common(1)[0][0] if texts else "episode"
|
|
943
946
|
label = "、".join(c["tags"][:4]) or "、".join(c["entities"][:4]) or "未命名主题"
|
|
944
947
|
# 只有 1 条记忆的簇不值得造摘要——摘要几乎等于原文复制,入库后和源记忆
|
|
945
948
|
# 重叠(还共享标签/实体,自动联想又给它们连一堆冗余边)。单条簇跳过。
|
|
949
|
+
# 滤完噪音后不足 2 条同样跳过(否则摘要里只剩噪音)。
|
|
946
950
|
if len(texts) < 2:
|
|
947
951
|
continue
|
|
948
952
|
joined = ";".join(t["text"] for t in top)
|
package/scripts/memory.py
CHANGED
|
@@ -2817,6 +2817,46 @@ _SPEAKER_RE = re.compile(
|
|
|
2817
2817
|
re.IGNORECASE,
|
|
2818
2818
|
)
|
|
2819
2819
|
|
|
2820
|
+
# 宿主注入的样板文本(P9 #58):不是对话内容,存成记忆只会污染库与审核队列。
|
|
2821
|
+
# 真库实测 244 条记忆里 23 条(9.4%)是这类噪音。session_import 早有同类过滤,
|
|
2822
|
+
# 但 capture(即记即存)路径没有——这里补上共享判据。
|
|
2823
|
+
_NOISE_MARKERS = (
|
|
2824
|
+
"system-reminder",
|
|
2825
|
+
"current coding agent web gui url",
|
|
2826
|
+
"current coding agent implementation checkout",
|
|
2827
|
+
"current app file policy",
|
|
2828
|
+
"approval prompts are disabled",
|
|
2829
|
+
"actions that require approval are rejected automatically",
|
|
2830
|
+
"current deepseek",
|
|
2831
|
+
"available_skills",
|
|
2832
|
+
"the following information describes your current session",
|
|
2833
|
+
"sandbox_permissions",
|
|
2834
|
+
)
|
|
2835
|
+
|
|
2836
|
+
|
|
2837
|
+
def _is_noise_text(text: str) -> bool:
|
|
2838
|
+
"""判断一段文本是否基本全是宿主注入样板(无对话价值)。
|
|
2839
|
+
|
|
2840
|
+
规则:命中任一噪音标记后,把标记片段剔掉再看剩余有效字符——剩余不足 40
|
|
2841
|
+
字符判为纯噪音(整段都是样板);剩余够多说明是"样板+真实内容"的混合段,
|
|
2842
|
+
保留(宁多存不漏存,真实内容别丢)。
|
|
2843
|
+
"""
|
|
2844
|
+
s = str(text or "").strip()
|
|
2845
|
+
if not s:
|
|
2846
|
+
return True
|
|
2847
|
+
low = s.lower()
|
|
2848
|
+
if not any(m in low for m in _NOISE_MARKERS):
|
|
2849
|
+
return False
|
|
2850
|
+
rest = s
|
|
2851
|
+
for m in _NOISE_MARKERS:
|
|
2852
|
+
rest = re.sub(re.escape(m), "", rest, flags=re.IGNORECASE)
|
|
2853
|
+
# 剔掉标记后剩余的实质字符(去掉尖括号标签、URL、空白)
|
|
2854
|
+
rest = re.sub(r"</?[a-zA-Z_][\w-]*[^>]*>", " ", rest)
|
|
2855
|
+
rest = re.sub(r"https?://\S+", " ", rest)
|
|
2856
|
+
rest = re.sub(r"[\s\W_]+", "", rest)
|
|
2857
|
+
return len(rest) < 40
|
|
2858
|
+
|
|
2859
|
+
|
|
2820
2860
|
|
|
2821
2861
|
def _split_segments(text: str) -> list:
|
|
2822
2862
|
"""把一段会话原文切成可独立成条的片段:空行 / 分隔线 / 说话人切换。
|
|
@@ -2846,7 +2886,10 @@ def _split_segments(text: str) -> list:
|
|
|
2846
2886
|
out = []
|
|
2847
2887
|
for s in segs:
|
|
2848
2888
|
s = re.sub(r"\s+", " ", s).strip()
|
|
2849
|
-
|
|
2889
|
+
# P9 #58:跳过宿主注入样板(system-reminder / GUI URL / 审批提示)——
|
|
2890
|
+
# 它们不是对话内容,存成记忆只会污染库与审核队列。verbatim 原文归档
|
|
2891
|
+
# 不经过这里,仍完整保留(可追溯性不受影响)。
|
|
2892
|
+
if len(s) >= CAPTURE_MIN_LEN and not _is_noise_text(s):
|
|
2850
2893
|
out.append(s)
|
|
2851
2894
|
return out
|
|
2852
2895
|
|