@furongjun1999/dsh-memory 0.10.1 → 0.10.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.en.md +65 -0
- package/CHANGELOG.md +642 -516
- package/README.en.md +1 -1
- package/README.md +2 -2
- package/docs/mdcg/cogmap_ops.md +15 -13
- package/lib/tools.d.ts +2 -2
- package/md_cg/bucketscope.py +36 -18
- package/md_cg/cohesion.py +337 -0
- package/md_cg/config_registry_bulk.py +5 -0
- package/md_cg/constraint_audit.py +231 -0
- package/md_cg/constraint_watch.py +206 -0
- package/md_cg/context_audit.py +240 -0
- package/md_cg/context_plan.py +142 -0
- package/md_cg/distill.py +247 -0
- package/md_cg/dossier.py +151 -0
- package/md_cg/entities.py +133 -0
- package/md_cg/mcp_server.py +60 -7
- package/md_cg/mdcg.py +27 -0
- package/md_cg/mdcos.py +319 -2
- package/md_cg/op_table.py +14 -0
- package/md_cg/profiles.py +298 -0
- package/md_cg/protocol.py +7 -1
- package/md_cg/reldate.py +142 -0
- package/md_cg/selfstmt.py +139 -0
- package/md_cg/state_slots.py +4 -0
- package/md_cg/state_view.py +181 -0
- package/md_cg/sustain.py +28 -2
- package/md_cg/test_alternatives_historical.py +4 -1
- package/md_cg/test_bucket_time_rounds.py +87 -0
- package/md_cg/test_cohesion.py +107 -0
- package/md_cg/test_constraint_audit.py +87 -0
- package/md_cg/test_constraint_watch.py +108 -0
- package/md_cg/test_context_audit.py +110 -0
- package/md_cg/test_context_plan.py +81 -0
- package/md_cg/tokens.py +1 -1
- package/md_cg/version_anchor.py +84 -1
- package/md_cg/whitebox_kb/wisdom/code_solidified.json +6195 -6195
- package/package.json +137 -137
package/README.en.md
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
|
|
18
18
|
**A high-performance, hallucination-free long-term memory system for multi-agent use (v0.10.1)**
|
|
19
19
|
|
|
20
|
-
> **Current version: `0.10.
|
|
20
|
+
> **Current version: `0.10.2`** (npm `latest`) · verified on **DSH `0.2.1-rc.5`** (tested by the maintainer).
|
|
21
21
|
> **Roadmap**: development now focuses on the **LINGSHU 1.0 architecture**; fixes for existing issues are **deferred**
|
|
22
22
|
> (still accepted, but lower priority than 1.0).
|
|
23
23
|
|
package/README.md
CHANGED
|
@@ -12,9 +12,9 @@
|
|
|
12
12
|
|
|
13
13
|

|
|
14
14
|
|
|
15
|
-
**高性能 · 无幻觉 · 多智能体适用的长期记忆系统(v0.10.
|
|
15
|
+
**高性能 · 无幻觉 · 多智能体适用的长期记忆系统(v0.10.2)**
|
|
16
16
|
|
|
17
|
-
> **当前版本 `0.10.
|
|
17
|
+
> **当前版本 `0.10.2`**(npm `latest`)· 已在 **DSH `0.2.1-rc.5`** 上验证可用(维护者实测)。
|
|
18
18
|
> **路线**:后续开发专注 **灵枢 1.0 架构**;存量 issue 的修复会**延后**处理(不停止受理,但优先级低于 1.0)。
|
|
19
19
|
|
|
20
20
|
📖 **[官方使用教程](docs/灵枢使用教程.md)** —— 分层怎么选 / 六要素怎么写 / 读三面怎么用 / 七个必踩的坑(10 分钟上手)。
|
package/docs/mdcg/cogmap_ops.md
CHANGED
|
@@ -5,27 +5,29 @@
|
|
|
5
5
|
|
|
6
6
|
<!-- COGMAP:BEGIN (scripts/cogmap_sync.py 自动生成 · 真源 md_cg/mcp_server.py · 勿手改段内) -->
|
|
7
7
|
|
|
8
|
-
**两个认知基元 ·
|
|
8
|
+
**两个认知基元 · 44 个 op**(`kernel` 面)——下列 op 清单、实现模块与全部链接行号由 [cogmap_sync](../..//scripts/cogmap_sync.py) 从真源自动提取,`check` 门禁守卫漂移;**点击任意名字直达源码对应行**:
|
|
9
9
|
|
|
10
10
|
| 基元 | op 数 | op 清单(点击直达实现分支) |
|
|
11
11
|
|---|---|---|
|
|
12
|
-
| **[`cg`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L796)** 认知图统一入口 |
|
|
13
|
-
| **[`stg`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L1183)** 语义时空图入口 | 5 | [`relation`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#
|
|
12
|
+
| **[`cg`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L796)** 认知图统一入口 | 39 | [`help`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L2551) [`write`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L3106) [`status`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L2568) [`edges`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L2571) [`theory`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L2574) [`link`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L2591) [`info`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L2731) [`route`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L2860) [`read`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L2883) [`audit`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L3073) [`goal`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L3144) [`task`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L3193) [`recent`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L3196) [`state_event`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L3235) [`state_view`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L3255) [`verify`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L3266) [`review`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L3272) [`forget`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L3307) [`protect`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L3317) [`identity`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L3320) [`consistency`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L3323) [`metacognition`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L3326) [`self_state`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L3329) [`evolution`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L3332) [`sustain`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L3335) [`scrub`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L3338) [`predict`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L3341) [`causal`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L3344) [`whitebox`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L3347) [`index_code`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L3350) [`index_doc`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L3423) [`ref`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L3491) [`session`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L3494) [`ingest`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L3497) [`export`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L3500) [`maintain`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L3503) [`consolidate`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L3506) [`insight`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L3509) [`ccg`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L3512) |
|
|
13
|
+
| **[`stg`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L1183)** 语义时空图入口 | 5 | [`relation`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L4214) [`timeline`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L4216) [`anchors`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L4223) [`consistency`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L4227) [`state_chain`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L4230) |
|
|
14
14
|
|
|
15
15
|
**op → 实现模块**(认知图投影:功能在哪段代码,一眼可达):
|
|
16
16
|
|
|
17
17
|
| op(点击直达实现分支) | 实现模块(点击直达源码) |
|
|
18
18
|
|---|---|
|
|
19
|
-
| [`help`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#
|
|
20
|
-
| [`index_code`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#
|
|
21
|
-
| [`info`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#
|
|
22
|
-
| [`audit`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#
|
|
23
|
-
| [`link`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#
|
|
24
|
-
| [`goal`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#
|
|
25
|
-
| [`read`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#
|
|
26
|
-
| [`
|
|
27
|
-
| [`
|
|
28
|
-
| [`
|
|
19
|
+
| [`help`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L2551) [`write`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L3106) [`status`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L2568) [`edges`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L2571) [`route`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L2860) [`task`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L3193) [`verify`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L3266) [`review`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L3272) [`forget`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L3307) [`protect`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L3317) [`identity`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L3320) [`consistency`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L3323) [`metacognition`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L3326) [`self_state`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L3329) [`evolution`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L3332) [`sustain`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L3335) [`scrub`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L3338) [`predict`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L3341) [`causal`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L3344) [`whitebox`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L3347) [`ref`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L3491) [`session`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L3494) [`ingest`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L3497) [`export`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L3500) [`maintain`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L3503) [`consolidate`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L3506) [`insight`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L3509) [`ccg`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L3512) | [`_cg_dispatch` 内联](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L2541) |
|
|
20
|
+
| [`index_code`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L3350) [`index_doc`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L3423) | [`refindex`](../..//md_cg/refindex.py), [`security`](../..//md_cg/security.py) |
|
|
21
|
+
| [`info`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L2731) | [`audit`](../..//md_cg/audit.py), [`bucketindex`](../..//md_cg/bucketindex.py), [`generation`](../..//md_cg/generation.py), [`links`](../..//md_cg/links.py), [`nodefile`](../..//md_cg/nodefile.py), [`theory`](../..//md_cg/theory.py), [`writegate`](../..//md_cg/writegate.py) |
|
|
22
|
+
| [`audit`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L3073) | [`auditview`](../..//md_cg/auditview.py) |
|
|
23
|
+
| [`link`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L2591) | [`evidence`](../..//md_cg/evidence.py), [`links`](../..//md_cg/links.py), [`provenance`](../..//md_cg/provenance.py), [`security`](../..//md_cg/security.py), [`signer`](../..//md_cg/signer.py) |
|
|
24
|
+
| [`goal`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L3144) | [`goal_gen`](../..//md_cg/goal_gen.py) |
|
|
25
|
+
| [`read`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L2883) | [`mdcos`](../..//md_cg/mdcos.py), [`refindex`](../..//md_cg/refindex.py) |
|
|
26
|
+
| [`state_event`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L3235) | [`state_events`](../..//md_cg/state_events.py) |
|
|
27
|
+
| [`recent`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L3196) | [`state_extract`](../..//md_cg/state_extract.py) |
|
|
28
|
+
| [`state_view`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L3255) | [`state_view`](../..//md_cg/state_view.py) |
|
|
29
|
+
| [`theory`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L2574) | [`theory`](../..//md_cg/theory.py) |
|
|
30
|
+
| [`relation`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L4214) [`timeline`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L4216) [`anchors`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L4223) [`consistency`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L4227) [`state_chain`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L4230) | [`_stg_call` 内联](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L4195) |
|
|
29
31
|
|
|
30
32
|
**细粒度面**(`MDCG_MCP_SURFACE=full`,插件运行时使用):[`cg`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L796) + [`stg`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L1183) + **31 个 `mdcg_*`** = **33 个工具**:
|
|
31
33
|
|
package/lib/tools.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ import type { LingshuBridge } from './bridge.ts';
|
|
|
13
13
|
* 旧的 aeis 工具名(remember/recall/think…)已不存在,写在这里只会被筛成空集
|
|
14
14
|
* ——「工具永久缺失」的根因,故一并移除。全部记忆/召回/时间线/落图能力由
|
|
15
15
|
* `cg(op=…)` / `stg(op=…)` 覆盖(见 src/lib/mdcg_client.ts 的显式映射)。 */
|
|
16
|
-
export declare const CORE_TOOLS: readonly [
|
|
16
|
+
export declare const CORE_TOOLS: readonly ['cg', 'stg'];
|
|
17
17
|
/**
|
|
18
18
|
* 大脑模式工具集:`cg`/`stg` 基元 + md_cg 全部细粒度工具(`MDCG_MCP_SURFACE=full`)。
|
|
19
19
|
*
|
|
@@ -21,7 +21,7 @@ export declare const CORE_TOOLS: readonly ["cg", "stg"];
|
|
|
21
21
|
* 管理类(forget / restore / review_decide)按映射表裁定「收窄后不留」,不在此列
|
|
22
22
|
* (如需显式启用,用 `tools: ['mdcg_forget', …]` 显式数组——显式配置不受 RISK 限制)。
|
|
23
23
|
*/
|
|
24
|
-
export declare const BRAIN_TOOLS: readonly [
|
|
24
|
+
export declare const BRAIN_TOOLS: readonly ['cg', 'stg', 'mdcg_remember', 'mdcg_recall', 'mdcg_search', 'mdcg_get', 'mdcg_reflect', 'mdcg_verify', 'mdcg_flywheel', 'mdcg_mine_fix_pairs', 'mdcg_rejected', 'mdcg_unresolved', 'mdcg_propose', 'mdcg_review_list', 'mdcg_review_records', 'mdcg_protect', 'mdcg_forgetting_history', 'mdcg_identity', 'mdcg_consistency', 'mdcg_metacognition', 'mdcg_self_state', 'mdcg_predict', 'mdcg_causal', 'mdcg_evolution', 'mdcg_health', 'mdcg_whoami', 'mdcg_ingest', 'mdcg_watermarks', 'mdcg_whitebox', 'mdcg_service_info'];
|
|
25
25
|
/** tools 配置:'core' | 'brain' | 'all' | 显式名称数组。 */
|
|
26
26
|
export type ToolSelection = 'core' | 'brain' | 'all' | string[];
|
|
27
27
|
/** 按工具名判定并发安全(只读查询 true;写操作 false) */
|
package/md_cg/bucketscope.py
CHANGED
|
@@ -17,6 +17,7 @@ from __future__ import annotations
|
|
|
17
17
|
|
|
18
18
|
import os
|
|
19
19
|
import re
|
|
20
|
+
import time
|
|
20
21
|
|
|
21
22
|
from . import bucketindex as _bi
|
|
22
23
|
|
|
@@ -85,8 +86,12 @@ def _pick(store, ids, terms, cap, validity=False, now=None, fallback_recency=Fal
|
|
|
85
86
|
# 只命中 114 ⇒ 116 被丢)。现改为:命中优先,**按时间序补足到 cap**。
|
|
86
87
|
if fill_rest and len(out) < cap:
|
|
87
88
|
chosen = {n.get("id") for n, _s, _q, _p in out}
|
|
89
|
+
# 补足路径同样要过 validity 闸(#856 守卫抓到的漏洞:
|
|
90
|
+
# 早先只对「词面命中」的节点做了过期过滤,`fill_rest` 会把过期节点补进来,
|
|
91
|
+
# 等于把 #843 的修复在另一条分支上绕过了)。
|
|
88
92
|
rest = [n for n in (store.get(i) for i in list(ids)[:MAX_SCAN])
|
|
89
|
-
if n and n.get("id") not in chosen
|
|
93
|
+
if n and n.get("id") not in chosen
|
|
94
|
+
and not (validity and _is_expired(n, now))]
|
|
90
95
|
rest.sort(key=lambda n: (_recency_key(n), str(n.get("id"))))
|
|
91
96
|
for n in rest[:cap - len(out)]:
|
|
92
97
|
out.append((n, 0.0, {"reason": "bucket_scope",
|
|
@@ -310,26 +315,39 @@ def scope_recall(store, query, session, now, cap=DEFAULT_CAP, validity=False):
|
|
|
310
315
|
# 【外测 2026-11-11】跨日桶**轮转分配**:早先每天拿走「剩余全部名额」,
|
|
311
316
|
# 第一个桶条目够多就把 cap 吃光(实测 8 桶 cap=4 只覆盖到 2 桶,末日永不入选)。
|
|
312
317
|
# 现每轮每天最多取 per_day 条,保证「任何一天拿第 2 条之前,所有天都先拿到第 1 条」。
|
|
313
|
-
per_day = max(1, cap // max(1, len(days))) if days else cap
|
|
314
318
|
# 判据:桶是**按理由选进来**的(声明日期 / 早段意图 / 共现)⇒ 桶内补足;
|
|
315
319
|
# 若只是「最近 N 天」兜底,桶本身不携带查询证据,仍严格按词面筛选(避免塞无关条目)。
|
|
316
320
|
_fill = bool(_declared_days or _early_hit)
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
321
|
+
# 先各桶取一批(保证覆盖),必要时**再跑下一轮**取第二批。
|
|
322
|
+
# 【#857】早先只跑一轮:9 条匹配 + cap=8 时,若某些日桶只出 0–1 条就永远补不满(实测只回 6 条)。
|
|
323
|
+
_taken = {d: 0 for d in days}
|
|
324
|
+
_round = 0
|
|
325
|
+
while len(out) < cap and _round < 3:
|
|
326
|
+
_round += 1
|
|
327
|
+
_per = max(1, (cap - len(out)) // max(1, len(days))) if _round == 1 else 2
|
|
328
|
+
_progress = False
|
|
329
|
+
for day in days:
|
|
330
|
+
if len(out) >= cap:
|
|
331
|
+
break
|
|
332
|
+
picked = _pick(store, _bi.day_ids(store, day), terms,
|
|
333
|
+
_per + _taken[day],
|
|
334
|
+
validity=validity, now=now, fallback_recency=True,
|
|
335
|
+
fill_rest=_fill)
|
|
336
|
+
for node, score, qual, prov in picked:
|
|
337
|
+
if len(out) >= cap:
|
|
338
|
+
break
|
|
339
|
+
if node.get("id") in seen:
|
|
340
|
+
continue
|
|
341
|
+
qual = dict(qual)
|
|
342
|
+
qual["bucket"] = "day:%s" % day
|
|
343
|
+
if resolved_dates:
|
|
344
|
+
qual["resolved_dates"] = resolved_dates
|
|
345
|
+
out.append((node, score, qual, prov))
|
|
346
|
+
seen.add(node.get("id"))
|
|
347
|
+
_taken[day] += 1
|
|
348
|
+
_progress = True
|
|
349
|
+
if not _progress:
|
|
350
|
+
break # 所有桶都取不出新条目 ⇒ 提前结束,不空转
|
|
333
351
|
# ③ 排序:**会话桶整体优先**,再按时间降序;日桶同样按时间降序。
|
|
334
352
|
# 使用者口径「会话优先使用会话桶,然后按日期倒排」——只按时间排会让日桶插到会话前面(实测发生过)。
|
|
335
353
|
def _key(it):
|
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""上下文质量读数(cohesion)——接缝 + 信噪比两个读数。
|
|
3
|
+
|
|
4
|
+
本模块提供上下文失效三种形态中的两种的读数:
|
|
5
|
+
* **断裂** → seam_ratio(接缝/块内)
|
|
6
|
+
* **稀释** → signal_ratio(目标词占全部实词的比例)
|
|
7
|
+
第三种(丢弃)由 constraint_watch 覆盖。三者合起来对应框架 v5 第二节。
|
|
8
|
+
|
|
9
|
+
——以下为原始说明(接缝部分)——
|
|
10
|
+
|
|
11
|
+
判断一段上下文是「可闭合」还是「散段拼装」。
|
|
12
|
+
|
|
13
|
+
为什么需要(2026-10-24 实测,见 docs/dsh设计/上下文管理研究_第十六轮):
|
|
14
|
+
检索结果的全局词汇重叠 ratio 会骗人(中位 2.61,比连续文本还高)——
|
|
15
|
+
因为**节点内部的强承接把接缝的断裂稀释了**。
|
|
16
|
+
分界测量才看清真相:块内承接 0.09-0.13,跨节点接缝仅 0.00-0.035。
|
|
17
|
+
|
|
18
|
+
两个读数:
|
|
19
|
+
inner_adj 块内部相邻句重叠均值("每块都对")
|
|
20
|
+
cross_boundary 相邻块「末句→首句」重叠均值("拼不成一件事")
|
|
21
|
+
seam_ratio cross / inner,低于阈值即判拼装为断
|
|
22
|
+
|
|
23
|
+
理论依据:
|
|
24
|
+
智能论 3.4 §3.5 意识层输入控制 + 使用者底稿「可闭合性」命题。
|
|
25
|
+
本模块把"可闭合性"落成一个纯计数、无需 LLM 的代理指标。
|
|
26
|
+
|
|
27
|
+
诚实边界:
|
|
28
|
+
1. 这是**结构代理**,不是语义判定——接缝高不代表支撑得住某个判断;
|
|
29
|
+
2. 阈值 0.5 是初设值,来自 4 个检索样本,未做充分验证;
|
|
30
|
+
3. 只对中文/英文混排做过验证;纯代码块或表格文本不适用(句子切分失效)。
|
|
31
|
+
|
|
32
|
+
**适用边界(2026-10-24 实测补充,重要)**:
|
|
33
|
+
本模块测的是**词汇承接**,它区分的是「连续叙述」与「章节并列」,
|
|
34
|
+
而**不是**「好」与「坏」。同样低的接缝比,含义取决于文本类型:
|
|
35
|
+
|
|
36
|
+
连续叙述(原文段落、论文正文)→ 低接缝 = 真断裂
|
|
37
|
+
结构化文档(报告、设计稿) → 低接缝 = 正常(章节本就并列,
|
|
38
|
+
读者靠标题层级导航,不靠句间重叠)
|
|
39
|
+
|
|
40
|
+
实测证据:本研究系列 17 份研究文档(结构化写作)中有 3 份被本模块判为
|
|
41
|
+
「断裂」(ratio 0.128 / 0.339 / 0.386),但它们逻辑上均连贯。
|
|
42
|
+
|
|
43
|
+
因此正确用法是**两步**:
|
|
44
|
+
① 先定任务需要哪种形态——L1「查事实」并列够用;L3「理解论证」需连续;
|
|
45
|
+
② 再测接缝比;仅当「任务需要连续而 ratio 低」时才判为缺陷。
|
|
46
|
+
单看 ratio 下结论是错的(见 docs/dsh设计/上下文管理研究_第十八轮)。
|
|
47
|
+
"""
|
|
48
|
+
|
|
49
|
+
import re
|
|
50
|
+
|
|
51
|
+
__all__ = [
|
|
52
|
+
"split_sentences", "inner_adjacency", "cross_boundary",
|
|
53
|
+
"seam_ratio", "check", "DEFAULT_THRESHOLD",
|
|
54
|
+
"signal_ratio", "SIGNAL_LOW", "SIGNAL_OK",
|
|
55
|
+
"logic_flow", "LOGIC_LOW", "LOGIC_OK", "CONNECTORS",
|
|
56
|
+
]
|
|
57
|
+
|
|
58
|
+
#: 接缝比阈值:低于此值判为「拼装断裂」。初设 0.5(4 样本,待更多验证)。
|
|
59
|
+
DEFAULT_THRESHOLD = 0.5
|
|
60
|
+
|
|
61
|
+
_SENT_SPLIT = re.compile(r"(?<=[。!?;;\n])")
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def split_sentences(text, min_len=4, drop_headings=True):
|
|
65
|
+
"""切句。
|
|
66
|
+
|
|
67
|
+
过滤两类噪声:
|
|
68
|
+
① 过短片段(标点、单字)
|
|
69
|
+
② **标题行**(以 # 开头)——2026-10-24 实测:标题与正文无共同词,
|
|
70
|
+
会把真实接缝算成 0(同章节按段落切两半时首句恰是 "### 2.7.1 …")。
|
|
71
|
+
标题是小节标记,不是承接内容,不参与重叠计算。
|
|
72
|
+
"""
|
|
73
|
+
out = []
|
|
74
|
+
for piece in _SENT_SPLIT.split(str(text or "")):
|
|
75
|
+
for line in piece.split("\n"):
|
|
76
|
+
s = line.strip()
|
|
77
|
+
if drop_headings and s.startswith("#"):
|
|
78
|
+
continue
|
|
79
|
+
if len(s) >= min_len:
|
|
80
|
+
out.append(s)
|
|
81
|
+
return out
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def _tokens(sentence):
|
|
85
|
+
"""中英混排取词:中文二字滑窗近似、英文/标识符按词。"""
|
|
86
|
+
s = str(sentence)
|
|
87
|
+
zh = re.findall(r"[\u4e00-\u9fa5]", s)
|
|
88
|
+
bigrams = {"".join(zh[i:i + 2]) for i in range(len(zh) - 1)}
|
|
89
|
+
words = {w.lower() for w in re.findall(r"[A-Za-z_]{2,}", s)}
|
|
90
|
+
return bigrams | words
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def _token_list(text):
|
|
94
|
+
"""实词**列表**(不去重,保留词次)。用于稀释度量。"""
|
|
95
|
+
s = str(text or "")
|
|
96
|
+
zh = re.findall(r"[\u4e00-\u9fa5]", s)
|
|
97
|
+
bigrams = ["".join(zh[i:i + 2]) for i in range(len(zh) - 1)]
|
|
98
|
+
words = [w.lower() for w in re.findall(r"[A-Za-z_]{2,}", s)]
|
|
99
|
+
return bigrams + words
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def _overlap(a, b):
|
|
103
|
+
"""两集合重叠:交集 / 较小集。空集返回 None(不计入均值)。"""
|
|
104
|
+
ta, tb = _tokens(a), _tokens(b)
|
|
105
|
+
if not ta or not tb:
|
|
106
|
+
return None
|
|
107
|
+
return len(ta & tb) / float(min(len(ta), len(tb)))
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def _mean(values):
|
|
111
|
+
vals = [v for v in values if v is not None]
|
|
112
|
+
return sum(vals) / len(vals) if vals else 0.0
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def inner_adjacency(segments):
|
|
116
|
+
"""块内部相邻句重叠均值。segments 为「每块一个字符串」的列表。"""
|
|
117
|
+
vals = []
|
|
118
|
+
for seg in segments or []:
|
|
119
|
+
sents = split_sentences(seg)
|
|
120
|
+
for a, b in zip(sents, sents[1:]):
|
|
121
|
+
vals.append(_overlap(a, b))
|
|
122
|
+
return _mean(vals)
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
#: 接缝比较窗口:取上块末尾 WINDOW 句与下块开头 WINDOW 句整体比较。
|
|
126
|
+
#: 为什么不是「末句 vs 首句」——相邻两句常无共同词却有逻辑承接,
|
|
127
|
+
#: 单句对太稀疏会系统性返回 0(2026-10-24 实测:同章节切两半也判 0.0)。
|
|
128
|
+
WINDOW = 3
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def cross_boundary(segments):
|
|
132
|
+
"""相邻块接缝承接:上块末尾窗口 vs 下块开头窗口的重叠均值。"""
|
|
133
|
+
segs = [s for s in (segments or []) if s]
|
|
134
|
+
if len(segs) < 2:
|
|
135
|
+
return 0.0
|
|
136
|
+
vals = []
|
|
137
|
+
for prev, nxt in zip(segs, segs[1:]):
|
|
138
|
+
p = split_sentences(prev)
|
|
139
|
+
n = split_sentences(nxt)
|
|
140
|
+
if p and n:
|
|
141
|
+
# 逐句对算再取均值:**不要先合并成长文本**——合并后 bigram 集合变大,
|
|
142
|
+
# 交集/较小集 会被稀释到接近 0(2026-10-24 实测:同章节切两半也判 0.0)。
|
|
143
|
+
cross = [_overlap(a, b) for a in p[-WINDOW:] for b in n[:WINDOW]]
|
|
144
|
+
vals.append(_mean(cross))
|
|
145
|
+
return _mean(vals)
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def seam_ratio(segments):
|
|
149
|
+
"""接缝比 = cross_boundary / inner_adj。
|
|
150
|
+
|
|
151
|
+
三种"算不出"一律返回 None,**不记 0**——把「没法算」当成「断裂」是
|
|
152
|
+
与 I2 同型的错误(不确定的结论不能伪装成确定):
|
|
153
|
+
① 块数 < 2 —— 根本没有接缝可言
|
|
154
|
+
② inner_adj = 0 —— 分母为零
|
|
155
|
+
"""
|
|
156
|
+
segs = [s for s in (segments or []) if s]
|
|
157
|
+
inner = inner_adjacency(segs)
|
|
158
|
+
cross = cross_boundary(segs) if len(segs) >= 2 else 0.0
|
|
159
|
+
if len(segs) < 2:
|
|
160
|
+
return None, {"inner_adj": round(inner, 4), "cross_boundary": None,
|
|
161
|
+
"segments": len(segs), "ratio": None}
|
|
162
|
+
ratio = (cross / inner) if inner > 0 else None
|
|
163
|
+
return ratio, {"inner_adj": round(inner, 4), "cross_boundary": round(cross, 4),
|
|
164
|
+
"segments": len([s for s in (segments or []) if s]),
|
|
165
|
+
"ratio": (round(ratio, 3) if ratio is not None else None)}
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
def check(segments, threshold=DEFAULT_THRESHOLD):
|
|
169
|
+
"""判定拼装是否可闭合。
|
|
170
|
+
|
|
171
|
+
返回 dict:
|
|
172
|
+
ok True=接缝尚可;False=判为断裂;None=**无法判定**(不给默认通过)
|
|
173
|
+
reason 文字说明
|
|
174
|
+
注意 ok=None 与 ok=False 不同:前者是「算不出来」,后者是「算出来是断的」。
|
|
175
|
+
"""
|
|
176
|
+
ratio, detail = seam_ratio(segments)
|
|
177
|
+
detail["threshold"] = threshold
|
|
178
|
+
if ratio is None:
|
|
179
|
+
detail["ok"] = None
|
|
180
|
+
detail["reason"] = "无法判定:块内无有效相邻句(内容过短或全是表格/代码)"
|
|
181
|
+
return detail
|
|
182
|
+
detail["ok"] = ratio >= threshold
|
|
183
|
+
detail["reason"] = ("接缝承接为块内的 %.0f%%,%s阈值 %.2f"
|
|
184
|
+
% (ratio * 100,
|
|
185
|
+
"不低于" if detail["ok"] else "**低于**",
|
|
186
|
+
threshold))
|
|
187
|
+
return detail
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
#: 信噪比参考线(2026-10-24 第三十四轮实测):
|
|
191
|
+
#: 233 字上下文目标占 16.5%,1 万字上下文仅 0.45%。
|
|
192
|
+
#: 低于 1% 视为「严重稀释」——目标事实被淹没。
|
|
193
|
+
SIGNAL_LOW = 0.01
|
|
194
|
+
SIGNAL_OK = 0.05
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
def signal_ratio(target_text, context_text):
|
|
198
|
+
"""信噪比:目标文本的实词占上下文全部实词的比例。
|
|
199
|
+
|
|
200
|
+
这是「稀释」这一种损失的读数(框架 v5 第二节)。
|
|
201
|
+
回答的不是「目标在不在」,而是「**目标有多显眼**」——
|
|
202
|
+
在不在由 constraint_watch 判,显不显眼由本函数判。
|
|
203
|
+
|
|
204
|
+
返回 dict:
|
|
205
|
+
ok True=占比不低于 SIGNAL_OK;
|
|
206
|
+
False=低于 SIGNAL_LOW(严重稀释);
|
|
207
|
+
None=**介于两者之间**(说不清,不给默认通过)
|
|
208
|
+
ratio 目标词占全部实词的比例
|
|
209
|
+
verdict 'clear' / 'thin' / 'drowned' / 'unknown'
|
|
210
|
+
"""
|
|
211
|
+
# 按**词次**而非词种:稀释的本质是「占用空间」,
|
|
212
|
+
# 若用 set 去重,重复内容不占空间,稀释就测不出来
|
|
213
|
+
# (2026-10-24 守卫抓到:'无关内容。'×400 用去重法得 70.8% clear,实为严重稀释)。
|
|
214
|
+
tgt_list = _token_list(target_text)
|
|
215
|
+
if not tgt_list:
|
|
216
|
+
return {"ok": None, "ratio": None, "verdict": "unknown",
|
|
217
|
+
"reason": "目标文本没有实词"}
|
|
218
|
+
ctx_list = _token_list(context_text)
|
|
219
|
+
if not ctx_list:
|
|
220
|
+
return {"ok": None, "ratio": None, "verdict": "unknown",
|
|
221
|
+
"reason": "上下文为空"}
|
|
222
|
+
tgt_set = set(tgt_list)
|
|
223
|
+
hit = sum(1 for w in ctx_list if w in tgt_set)
|
|
224
|
+
ratio = hit / float(len(ctx_list))
|
|
225
|
+
tgt = tgt_set
|
|
226
|
+
ctx = ctx_list
|
|
227
|
+
if ratio >= SIGNAL_OK:
|
|
228
|
+
ok, verdict = True, "clear"
|
|
229
|
+
elif ratio < SIGNAL_LOW:
|
|
230
|
+
ok, verdict = False, "drowned"
|
|
231
|
+
else:
|
|
232
|
+
ok, verdict = None, "thin"
|
|
233
|
+
return {"ok": ok, "ratio": round(ratio, 4), "verdict": verdict,
|
|
234
|
+
"target_words": len(tgt), "hit_words": hit,
|
|
235
|
+
"context_words": len(ctx),
|
|
236
|
+
"note": "占比 %.2f%%(%d/%d 实词)" % (ratio * 100, hit, len(ctx))}
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
#: 逻辑连接词(2026-10-24 第四十三轮发现「词汇接缝测不出逻辑过渡」后补):
|
|
240
|
+
#: 好的过渡往往**刻意用不同词汇**,靠逻辑连接而非重复上节的词。
|
|
241
|
+
#: 故词汇接缝低可能是好现象——需要一个独立的逻辑度量来区分
|
|
242
|
+
#: 「逻辑连贯但用词不同」与「真的跳跃」。
|
|
243
|
+
CONNECTORS = (
|
|
244
|
+
"因为", "所以", "因此", "因而", "于是", "故", "这就",
|
|
245
|
+
"但是", "然而", "不过", "可是", "但",
|
|
246
|
+
"而且", "并且", "此外", "同时", "更重要的是",
|
|
247
|
+
"总之", "综上", "可见", "这说明", "也就是说", "换言之",
|
|
248
|
+
"例如", "比如", "譬如", "具体说",
|
|
249
|
+
"换言之", "换句话说", "归根结底", "说到底",
|
|
250
|
+
"第一", "第二", "第三", "首先", "其次", "最后",
|
|
251
|
+
)
|
|
252
|
+
#: 参考线:句首连接词占比。低于 LOW 视为「缺显式逻辑标记」。
|
|
253
|
+
LOGIC_LOW = 0.15
|
|
254
|
+
LOGIC_OK = 0.30
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
def logic_flow(segments):
|
|
258
|
+
"""连接词密度——**注意:这测的是文风,不是连贯**(2026-10-24 实测证伪)。
|
|
259
|
+
|
|
260
|
+
初衷:第四十三轮发现「词汇接缝测不出逻辑过渡」,想加一个逻辑度量来区分
|
|
261
|
+
「逻辑连贯但用词不同」与「真的跳跃」。
|
|
262
|
+
|
|
263
|
+
**实测失败**:同一文本打乱句序后,连接词句数**不变**(纲要 5 → 5)。
|
|
264
|
+
因为本指标是与**顺序无关**的统计量——它数的是「文本里有多少句以连接词开头」,
|
|
265
|
+
而不是「连接词是否真的连接了上下文」。
|
|
266
|
+
|
|
267
|
+
所以:
|
|
268
|
+
* 它能告诉你「这份文本用不用显式连接词」(文风);
|
|
269
|
+
* **不能**告诉你「逻辑是否连贯」——后者依赖语义,与词形无关,
|
|
270
|
+
和第十八轮「词频与嵌入看不见结构」同型。
|
|
271
|
+
|
|
272
|
+
**不要把它的 ok/verdict 当作连贯性判据。** 保留它只因为文风本身有参考价值。
|
|
273
|
+
|
|
274
|
+
——以下关于 signal_ratio 的补充(2026-10-24 第五十八轮)——
|
|
275
|
+
|
|
276
|
+
**ratio 已归一化,不要再用它除以字符数做「每千字信噪比」**:
|
|
277
|
+
那等于除了两次规模,会放大短文本(实测:去冗余后 per1k +211%,
|
|
278
|
+
而 ratio 只 +4%——升幅几乎全是规模效应的假象)。
|
|
279
|
+
比较不同规模的方案时,**用 ratio 本身**;规模效应另议。
|
|
280
|
+
|
|
281
|
+
返回 dict:
|
|
282
|
+
ok True=不低于 LOGIC_OK;False=低于 LOGIC_LOW;None=之间
|
|
283
|
+
rate 句首连接词占比
|
|
284
|
+
verdict 'marked' / 'sparse' / 'bare' / 'unknown'
|
|
285
|
+
"""
|
|
286
|
+
all_sents = []
|
|
287
|
+
for seg in (segments or []):
|
|
288
|
+
all_sents.extend(split_sentences(seg))
|
|
289
|
+
if not all_sents:
|
|
290
|
+
return {"ok": None, "rate": None, "verdict": "unknown",
|
|
291
|
+
"reason": "没有可分析的句子"}
|
|
292
|
+
marked = 0
|
|
293
|
+
for s in all_sents:
|
|
294
|
+
# 先剥掉 Markdown 标记(**、#、>、-、*)与序号——
|
|
295
|
+
# 否则「**但这里…**」的 startswith("但") 永远失败
|
|
296
|
+
# (2026-10-24 实测:不剥标记时纲要报 0%,与打乱文本无法区分)。
|
|
297
|
+
head = s.lstrip("\u3000 \t*#>-·•0123456789.、))]】")
|
|
298
|
+
if any(head.startswith(c) for c in CONNECTORS):
|
|
299
|
+
marked += 1
|
|
300
|
+
rate = marked / float(len(all_sents))
|
|
301
|
+
if rate >= LOGIC_OK:
|
|
302
|
+
ok, verdict = True, "marked"
|
|
303
|
+
elif rate < LOGIC_LOW:
|
|
304
|
+
ok, verdict = False, "bare"
|
|
305
|
+
else:
|
|
306
|
+
ok, verdict = None, "sparse"
|
|
307
|
+
return {"ok": ok, "rate": round(rate, 4), "verdict": verdict,
|
|
308
|
+
"sentences": len(all_sents), "marked": marked,
|
|
309
|
+
"note": "句首连接词 %d/%d = %.1f%%" % (marked, len(all_sents), rate * 100)}
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
def main(argv=None):
|
|
313
|
+
import json
|
|
314
|
+
import sys
|
|
315
|
+
try:
|
|
316
|
+
sys.stdout.reconfigure(encoding="utf-8")
|
|
317
|
+
except Exception:
|
|
318
|
+
pass
|
|
319
|
+
argv = list(sys.argv[1:] if argv is None else argv)
|
|
320
|
+
if not argv or argv[0] in ("-h", "--help"):
|
|
321
|
+
print("用法:python -m md_cg.cohesion <文件1> <文件2> ...")
|
|
322
|
+
print(" 把每个文件当作一个「块」,测拼装接缝")
|
|
323
|
+
return 2
|
|
324
|
+
segs = []
|
|
325
|
+
for p in argv:
|
|
326
|
+
try:
|
|
327
|
+
with open(p, "r", encoding="utf-8", errors="replace") as fh:
|
|
328
|
+
segs.append(fh.read())
|
|
329
|
+
except OSError as exc:
|
|
330
|
+
print("跳过 %s:%s" % (p, exc), file=sys.stderr)
|
|
331
|
+
rep = check(segs)
|
|
332
|
+
print(json.dumps(rep, ensure_ascii=False, indent=1))
|
|
333
|
+
return 0 if rep["ok"] is not False else 1
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
if __name__ == "__main__":
|
|
337
|
+
raise SystemExit(main())
|
|
@@ -451,8 +451,13 @@ ENV_CATEGORY_ROWS = [
|
|
|
451
451
|
('MDCG_STATE_ROOT', 'env', 'dsh-memory-main', '目录路径', ''),
|
|
452
452
|
('MDCG_STATE_EXTRACT', 'env', 'dsh-memory-main', '开关', 'L2 状态台账抽取开关:缺省开,置 0 关闭(md_cg/state_extract.py:76;recent·add 接线)'),
|
|
453
453
|
('MDCG_STATE_SUBJECT', 'env', 'dsh-memory-main', '字符串', 'L2 台账抽取主体覆盖,缺省「我」(md_cg/state_extract.py:108)'),
|
|
454
|
+
('MDCG_STATE_TTL_DAYS', 'env', 'dsh-memory-main', '正数(天)', 'state_view 的槽位租约 TTL 全局覆盖;缺省按槽位名启发式(时间30/地点365/状态7/其余180,md_cg/state_view.py:48)'),
|
|
455
|
+
('MDCG_PROFILE_CARDS', 'env', 'dsh-memory-main', '整数(张)', '资料卡在 pack 里的配额上限,缺省 3;置 0 表示不限制(md_cg/mdcos.py recall)'),
|
|
456
|
+
('MDCG_ROLE_USER', 'env', 'dsh-memory-main', '字符串', '用户角色名(闭集):配置后 role=user 的节点归到角色卡;未配置不建卡(不猜名字;md_cg/profiles.py)'),
|
|
457
|
+
('MDCG_ROLE_AI', 'env', 'dsh-memory-main', '字符串', 'AI 角色名(闭集):配置后 role=assistant 的节点归到角色卡;未配置不建卡(md_cg/profiles.py)'),
|
|
454
458
|
('MDCG_SUSTAIN_DIR', 'env', 'dsh-memory-main', '目录路径', ''),
|
|
455
459
|
('MDCG_SUSTAIN_NAME', 'env', 'dsh-memory-main', '字符串', ''),
|
|
460
|
+
('MDCG_SELFSTMT_LIMIT', 'env', 'dsh-memory-main', '整数(条)', '自述轮次注入上限,缺省 20(按信息密度降序取;登记总量通常 3–16/库;md_cg/mdcos.py _selfstmt_nodes)'),
|
|
456
461
|
('MDCG_SWARM_DIR', 'env', 'dsh-memory-main', '目录路径', ''),
|
|
457
462
|
('MDCG_TENANT_REGISTRY', 'env', 'dsh-memory-main', '文件路径', ''),
|
|
458
463
|
('MDCG_TESTLOG_DIR', 'env', 'dsh-memory-main', '目录路径', ''),
|