@furongjun1999/dsh-memory 0.9.23 → 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 +515 -404
- package/CHANGELOG.md +642 -449
- package/README.en.md +244 -240
- package/README.md +272 -262
- package/codebuddy/CODEBUDDY.md +1 -1
- package/docs/discipline/templates/full.md.tmpl +1 -1
- package/docs/discipline/templates/rules.mdc.tmpl +1 -1
- package/docs/en/mdcg/world-model-endpoint.md +1 -1
- package/docs/mdcg/cogmap_ops.md +19 -16
- package/lib/client.js +29 -3
- package/lib/hooks.d.ts +12 -0
- package/lib/hooks.js +43 -1
- package/lib/tools.d.ts +2 -2
- package/md_cg/bucketindex.py +231 -0
- package/md_cg/bucketscope.py +357 -0
- package/md_cg/cohesion.py +337 -0
- package/md_cg/config_registry_bulk.py +24 -10
- package/md_cg/config_validate.py +14 -2
- 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/detrerank.py +137 -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/fsutil.py +135 -0
- package/md_cg/govern/__init__.py +23 -0
- package/md_cg/iface/__init__.py +46 -0
- package/md_cg/iface/_verify.py +609 -0
- package/md_cg/iface/contracts.py +337 -0
- package/md_cg/judgment_manifest.py +14 -0
- package/md_cg/kernel/__init__.py +27 -0
- package/md_cg/mcp_server.py +6044 -5761
- package/md_cg/mdcg.py +501 -16
- package/md_cg/mdcos.py +546 -12
- package/md_cg/metacognition.py +66 -13
- package/md_cg/mutate_extract_shipped.py +126 -0
- package/md_cg/mutate_ledger_e2e.py +100 -0
- package/md_cg/op_table.py +22 -0
- package/md_cg/probe_c_ledger_integrity.py +258 -0
- package/md_cg/probe_d_retirement_discipline.py +263 -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/review_cli.py +6 -1
- package/md_cg/run_tests.py +30 -1
- package/md_cg/scopeselect.py +214 -0
- package/md_cg/scrub.py +66 -9
- package/md_cg/selfstmt.py +139 -0
- package/md_cg/state_extract.py +149 -0
- package/md_cg/state_slots.py +62 -10
- package/md_cg/state_view.py +181 -0
- package/md_cg/structboost.py +179 -0
- package/md_cg/sustain.py +28 -2
- package/md_cg/test_alternatives_historical.py +165 -0
- package/md_cg/test_b2_sensitivity_landing.py +226 -223
- package/md_cg/test_b3_merge_keeps_content.py +608 -583
- package/md_cg/test_bucket_cards.py +85 -0
- package/md_cg/test_bucket_day_order.py +74 -0
- package/md_cg/test_bucket_quota.py +79 -0
- package/md_cg/test_bucket_recency_guards.py +75 -0
- package/md_cg/test_bucket_three_causes.py +83 -0
- package/md_cg/test_bucket_time_rounds.py +87 -0
- package/md_cg/test_bucketindex.py +130 -0
- package/md_cg/test_bucketscope_early.py +71 -0
- package/md_cg/test_cohesion.py +107 -0
- package/md_cg/test_cond_term_fold_gate.py +1210 -0
- package/md_cg/test_cond_term_neg_scope.py +147 -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/test_detrerank.py +157 -0
- package/md_cg/test_gate_four_kpi.py +136 -0
- package/md_cg/test_generation_guard.py +14 -2
- package/md_cg/test_issue192_move_layer_indices_guard.py +48 -0
- package/md_cg/test_issue39_utf8_stdio.py +572 -572
- package/md_cg/test_issue413_preimage_failclosed.py +147 -9
- package/md_cg/test_issue768_overwrite_time_window_anchor.py +135 -0
- package/md_cg/test_issue789_log_plaintext_probe.py +100 -0
- package/md_cg/test_issue790_verb_negation.py +77 -0
- package/md_cg/test_issue810_root_guard.py +71 -0
- package/md_cg/test_issue812_info_index_stale.py +78 -0
- package/md_cg/test_issue827_weaken_dedup.py +361 -0
- package/md_cg/test_issue829_calibration_positive_gate.py +473 -0
- package/md_cg/test_kernel_iface_contracts.py +18 -0
- package/md_cg/test_md_cg_no_hive_dep.py +238 -17
- package/md_cg/test_probe_cd_shipped.py +385 -0
- package/md_cg/test_recent_tail.py +93 -0
- package/md_cg/test_run_tests_entry_gates.py +110 -0
- package/md_cg/test_scopeselect.py +70 -0
- package/md_cg/test_scopeselect_clock.py +70 -0
- package/md_cg/test_session_attribution_consistency.py +835 -813
- package/md_cg/test_state_extract_shipped.py +162 -0
- package/md_cg/test_state_ledger_chain.py +207 -0
- package/md_cg/test_state_ledger_e2e.py +145 -0
- package/md_cg/test_structboost.py +102 -0
- package/md_cg/test_timeboost.py +83 -0
- package/md_cg/test_timeboost_relativedate.py +71 -0
- package/md_cg/test_topicagg.py +129 -0
- package/md_cg/timeboost.py +223 -0
- package/md_cg/tokens.py +1 -1
- package/md_cg/topicagg.py +142 -0
- package/md_cg/version_anchor.py +84 -1
- package/md_cg/whitebox_kb/wisdom/code_compose.py +33 -5
- package/md_cg/whitebox_kb/wisdom/code_solidified.json +6195 -6195
- package/md_cg/whitebox_kb/wisdom/compose_engine.py +5 -1
- package/md_cg/whitebox_kb/wisdom/role_compose.py +271 -268
- package/package.json +1 -1
- package/src/hooks.ts +43 -1
- package/ui/minimal/payload/build-ui.mjs +41 -2
- package/ui/minimal/payload/lib/client.js +29 -3
- package/ui/minimal/payload/web/app.js +3 -1
- package/ui/minimal/payload/web/client.js +30 -3
- package/web/app.js +3 -1
- package/web/client.js +30 -3
- package/zcode/AGENTS.md +1 -1
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
|
|
48
48
|
三条调用铁律:
|
|
49
49
|
1. **`op` 必填**——漏传会触发参数签名推导兜底(返回标记 `op_derived: true`),复杂任务中也必须显式传,防静默执行错误意图。
|
|
50
|
-
2. **返回 `moved_to: "review_queue"` / `verdict: DEFER` 时不要重试**——这是校验闸门的正常行为(返回自带 `hint` 说明下一步);落盘须经裁决(`op=review` 的 `decision=accept/reject/edit/merge/noop`,本机工具:`python
|
|
50
|
+
2. **返回 `moved_to: "review_queue"` / `verdict: DEFER` 时不要重试**——这是校验闸门的正常行为(返回自带 `hint` 说明下一步);落盘须经裁决(`op=review` 的 `decision=accept/reject/edit/merge/noop`,本机工具:`python -m md_cg.review_cli list`)。**裁决权(2026-09-28 使用者裁定)**:写入者不得自裁——不得自己写、自己判、无复核一路到底;**经蜂群或验证端复核后,agent 可自行执行裁决**,不必每次转告使用者。**三类例外不适用该授权,必须转交使用者并止步**:①不适用于智能论这类重要协议真源的修改;②不适用于向外部发送信息和数据;③不适用于可能造成信息泄露/病毒/恶意操纵的动作。**`verdict: REJECT` 分两类,处置相反**:① 命中禁止规则(内容政策违规)→ 内容本身不该入库,重试同样结果;② 缺必需要素(`text` 类缺 CCG 六要素)→ **可修正**,按 `verdict.evidence` / `verdict.detail.missing` 给出的**完整缺失清单**补齐六要素后**重写**即落盘(本条未入库、已记入负记忆)——不要把它当「闸门故障」或「重试无用」。
|
|
51
51
|
3. `stg` 同理经 `op` 分发(`timeline` / `relation` / `anchors` 等)。
|
|
52
52
|
|
|
53
53
|
## 收尾强制流程(任务完成时不可跳过)
|
|
@@ -54,7 +54,7 @@ provider:
|
|
|
54
54
|
|
|
55
55
|
三条调用铁律:
|
|
56
56
|
1. **`op` 必填**——漏传会触发参数签名推导兜底(返回标记 `op_derived: true`),复杂任务中也必须显式传,防静默执行错误意图。
|
|
57
|
-
2. **返回 `moved_to: "review_queue"` / `verdict: DEFER` 时不要重试**——这是校验闸门的正常行为(返回自带 `hint` 说明下一步);落盘须经裁决(`op=review` 的 `decision=accept/reject/edit/merge/noop`,本机工具:`python
|
|
57
|
+
2. **返回 `moved_to: "review_queue"` / `verdict: DEFER` 时不要重试**——这是校验闸门的正常行为(返回自带 `hint` 说明下一步);落盘须经裁决(`op=review` 的 `decision=accept/reject/edit/merge/noop`,本机工具:`python -m md_cg.review_cli list`)。**裁决权(2026-09-28 使用者裁定)**:写入者不得自裁——不得自己写、自己判、无复核一路到底;**经蜂群或验证端复核后,agent 可自行执行裁决**,不必每次转告使用者。**三类例外不适用该授权,必须转交使用者并止步**:①不适用于智能论这类重要协议真源的修改;②不适用于向外部发送信息和数据;③不适用于可能造成信息泄露/病毒/恶意操纵的动作。**`verdict: REJECT` 分两类,处置相反**:① 命中禁止规则(内容政策违规)→ 内容本身不该入库,重试同样结果;② 缺必需要素(`text` 类缺 CCG 六要素)→ **可修正**,按 `verdict.evidence` / `verdict.detail.missing` 给出的**完整缺失清单**补齐六要素后**重写**即落盘(本条未入库、已记入负记忆)——不要把它当「闸门故障」或「重试无用」。
|
|
58
58
|
3. `stg` 同理经 `op` 分发(`timeline` / `relation` / `anchors` 等)。
|
|
59
59
|
|
|
60
60
|
## 收尾强制流程(任务完成时不可跳过)
|
|
@@ -220,7 +220,7 @@ python -X utf8 -m md_cg.test_state_event_op --mutate # 定点变异自证(
|
|
|
220
220
|
- The engineering ledger surface (`goal` / `task`) and statistical surfaces (`health` / `whoami` / conformance): read the index directly,
|
|
221
221
|
not constrained by this section;
|
|
222
222
|
- **Lifecycle recovery**: the library-layer entry `MdCG.set_state(node, "archived"→"active")`
|
|
223
|
-
(`md_cg/mdcg.py:
|
|
223
|
+
(`md_cg/mdcg.py:3910` → `lifecycle.set_state`, following the legal transition table, one level at a time with no level skipping); after recovery
|
|
224
224
|
the read surface / continuation surface see it again. **The MCP tool surface has no standalone lifecycle entry** (`mcp_server.py` contains the strings `set_state` / `lifecycle` nowhere)
|
|
225
225
|
— 'explicit recovery' is a library-layer call surface.
|
|
226
226
|
- Difference from `op=restore` (easy to confuse, stated explicitly): `op=restore` is `action=restore` of `op=forget`
|
package/docs/mdcg/cogmap_ops.md
CHANGED
|
@@ -5,30 +5,33 @@
|
|
|
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#
|
|
13
|
-
| **[`stg`](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
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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) |
|
|
31
|
+
|
|
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 个工具**:
|
|
33
|
+
|
|
34
|
+
[`mdcg_remember`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L314) [`mdcg_recall`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L351) [`mdcg_search`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L411) [`mdcg_get`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L424) [`mdcg_reflect`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L432) [`mdcg_verify`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L438) [`mdcg_flywheel`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L449) [`mdcg_mine_fix_pairs`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L454) [`mdcg_rejected`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L459) [`mdcg_unresolved`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L465) [`mdcg_propose`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L471) [`mdcg_review_list`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L479) [`mdcg_review_decide`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L484) [`mdcg_review_records`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L501) [`mdcg_forget`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L509) [`mdcg_protect`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L517) [`mdcg_forgetting_history`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L527) [`mdcg_identity`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L533) [`mdcg_consistency`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L576) [`mdcg_metacognition`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L598) [`mdcg_self_state`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L620) [`mdcg_predict`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L658) [`mdcg_causal`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L686) [`mdcg_evolution`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L703) [`mdcg_restore`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L726) [`mdcg_health`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L731) [`mdcg_whoami`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L736) [`mdcg_ingest`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L741) [`mdcg_watermarks`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L753) [`mdcg_whitebox`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L758) [`mdcg_service_info`](https://github.com/FuRongJun-1999/dsh-memory/blob/main/md_cg/mcp_server.py#L779)
|
|
32
35
|
|
|
33
36
|
逐个 op 的「功能 → 代码 → op」行号级映射另见[功能调用映射表](../..//docs/mdcg/功能调用映射表_v0.1.md)。
|
|
34
37
|
|
package/lib/client.js
CHANGED
|
@@ -1,11 +1,38 @@
|
|
|
1
1
|
/* generated by build-ui.mjs */
|
|
2
2
|
window.__ModuleLoader__.load({id:"@furongjun1999/dsh-memory",factory:function(require){var module={exports:{}};
|
|
3
3
|
const React = require('react');
|
|
4
|
+
const PANEL_HTML = "<!doctype html>\n<html lang=\"zh-CN\"><head><meta charset=\"utf-8\"><meta name=\"viewport\" content=\"width=device-width,initial-scale=1\"><meta name=\"color-scheme\" content=\"light dark\"><title>灵枢 · 认知工作台</title><style>:root{--bg:#f8f9f7;--surface:#fff;--ink:#252d29;--muted:#7e8780;--line:#e7ebe7;--soft:#eff3ef;--accent:#426a55;--accent-soft:#edf3ee;--danger:#a44c4c;--shadow:0 18px 65px #17221b12;font-family:Inter,\"Segoe UI\",\"Microsoft YaHei\",sans-serif;color:var(--ink);background:var(--bg);font-size:13px;color-scheme:light}\n:root[data-theme=dark]{--bg:#151918;--surface:#1b201e;--ink:#e5e9e6;--muted:#99a39c;--line:#2b332f;--soft:#232b27;--accent:#9fc9af;--accent-soft:#27372d;--danger:#e39e9e;--shadow:0 18px 65px #0004;color-scheme:dark}\n*{box-sizing:border-box}body{margin:0}button,input,select,textarea{font:inherit}button,a,input,select,textarea{-webkit-tap-highlight-color:transparent}button,a{touch-action:manipulation}button{cursor:pointer}button:disabled{cursor:wait;opacity:.5}a{color:inherit;text-decoration:none}button:focus-visible,a:focus-visible{outline:2px solid var(--accent);outline-offset:4px}button{color:inherit}h1,h2,h3,p{margin:0}h1{font-size:27px;font-weight:550;letter-spacing:-.8px}h2{font-size:17px;font-weight:550}h3{font-size:14px;font-weight:550}.shell{min-height:100vh;display:grid;grid-template-columns:200px 1fr}.sidebar{min-width:0;background:var(--surface);border-right:1px solid var(--line);padding:34px 20px 20px;display:flex;flex-direction:column;position:sticky;top:0;height:100vh}.brand{display:flex;align-items:center;gap:13px;font-size:19px;font-weight:600;padding:0 8px}.brand small{display:block;margin-top:5px;font-size:10px;font-weight:400;color:var(--muted);letter-spacing:1px}.mark{width:35px;height:39px;border:1px solid var(--accent);border-radius:9px 9px 3px 9px;color:var(--accent);display:grid;place-items:center;font-family:serif;font-size:22px;font-weight:400}.nav-caption,.eyebrow{color:var(--muted);font-size:10px;letter-spacing:1.7px}.nav-caption{padding:44px 12px 15px}nav{display:grid;gap:5px}.nav-item{width:100%;border:0;background:transparent;text-align:left;padding:12px;border-radius:7px;display:flex;align-items:center;gap:13px;color:var(--muted);font-size:12px}.nav-item:hover{background:var(--soft);color:var(--ink)}.nav-item.active{background:var(--accent-soft);color:var(--accent);font-weight:600}.nav-icon{width:17px;text-align:center;font-size:17px;font-weight:400}.sidebar-bottom{margin-top:auto;padding-top:38px}.quiet{border:0;background:none;display:flex;align-items:center;gap:12px;color:var(--muted);padding:11px 12px;font-size:11px}.version{margin:22px 12px 0;color:var(--muted);font-size:9px;letter-spacing:1.8px;opacity:.65}.workspace{min-width:0;display:flex;flex-direction:column}header{height:70px;border-bottom:1px solid var(--line);display:flex;align-items:center;justify-content:space-between;padding:0 40px;background:var(--bg)}.breadcrumb{font-size:11px;color:var(--muted);display:flex;gap:14px;align-items:center}.breadcrumb b{font-weight:400;color:var(--ink)}.breadcrumb span{opacity:.4}.header-right{display:flex;align-items:center;gap:22px}.connection{font-size:10px;color:var(--muted);display:flex;align-items:center;gap:7px}.connection:before{content:\"\";width:5px;height:5px;background:var(--muted);border-radius:50%}.connection.online:before{background:var(--accent)}.icon-button{background:none;border:0;font-size:20px;padding:7px;color:var(--muted)}main{padding:43px 40px 60px;width:100%;max-width:1250px;margin:0 auto;flex:1;outline:none}.title-row{display:flex;align-items:flex-start;justify-content:space-between;gap:18px;margin-bottom:32px}.title-row .eyebrow{margin-bottom:12px}.subtitle{color:var(--muted);font-size:12px;line-height:1.8;margin-top:11px}.button{border:1px solid var(--line);background:var(--surface);border-radius:6px;padding:9px 14px;font-size:11px;display:inline-flex;align-items:center;gap:8px;white-space:nowrap}.button:hover{border-color:var(--accent)}.button.primary{background:var(--accent);color:var(--surface);border-color:var(--accent)}[data-theme=dark] .button.primary{color:#18231d}.button.text{background:none;border:0;color:var(--accent);padding:7px 0}.stats{display:grid;grid-template-columns:repeat(4,1fr);border:1px solid var(--line);border-radius:9px;background:var(--surface);margin-bottom:29px}.stat{padding:23px 25px;border-right:1px solid var(--line)}.stat:last-child{border:0}.stat-label{font-size:10px;color:var(--muted)}.stat-value{font-size:30px;font-weight:400;letter-spacing:-1px;margin:12px 0 7px}.stat-note{font-size:10px;color:var(--muted)}.grid-two{display:grid;grid-template-columns:minmax(0,1.55fr) minmax(245px,1fr);gap:24px}.panel{background:var(--surface);border:1px solid var(--line);border-radius:9px;min-width:0}.panel-head{display:flex;align-items:center;justify-content:space-between;gap:12px;padding:22px 24px;border-bottom:1px solid var(--line)}.panel-body{padding:23px 24px}.row-item{padding:19px 24px;border-bottom:1px solid var(--line);display:flex;align-items:flex-start;gap:14px}.row-item:last-child{border:0}.node-button{display:block;width:100%;background:none;border:0;text-align:left;color:var(--ink)}.node-button:hover{background:var(--soft)}.row-dot{height:7px;width:7px;border:1px solid var(--accent);border-radius:50%;margin-top:5px;flex-shrink:0}.row-content{min-width:0;flex:1}.row-title{font-size:12px;line-height:1.75;overflow-wrap:anywhere}.row-meta{display:flex;gap:10px;align-items:center;margin-top:8px;color:var(--muted);font-size:9px}.badge{padding:3px 6px;border:1px solid var(--line);border-radius:3px;font-size:9px;color:var(--muted)}.status-line{display:flex;justify-content:space-between;gap:20px;font-size:11px;padding:12px 0;border-bottom:1px solid var(--line)}.status-line:last-child{border:0}.status-line span:first-child{color:var(--muted)}.status-line span:last-child{text-align:right;overflow-wrap:anywhere}.muted{color:var(--muted)}.hint{font-size:11px;color:var(--muted);line-height:1.9}.notice{padding:13px 17px;background:var(--accent-soft);border:1px solid var(--line);border-radius:6px;color:var(--accent);font-size:11px;line-height:1.9;margin-bottom:22px}.error{color:var(--danger);background:var(--surface)}.loading,.empty{padding:54px 24px;text-align:center;color:var(--muted);font-size:12px;line-height:2}.loading:before{content:\"\";display:inline-block;width:11px;height:11px;border:1px solid var(--line);border-top-color:var(--accent);border-radius:50%;animation:spin 1s linear infinite;margin-right:10px}@keyframes spin{to{transform:rotate(360deg)}}.toolbar{display:flex;gap:10px;flex-wrap:wrap;margin-bottom:22px}.field,input,select,textarea{border:1px solid var(--line);background:var(--surface);color:var(--ink);border-radius:6px;padding:10px 12px;outline:none}input:focus,select:focus,textarea:focus{border-color:var(--accent)}input::placeholder,textarea::placeholder{color:var(--muted);opacity:.7}.search{flex:1;min-width:180px}.form-grid{display:grid;gap:18px}.form-grid label{display:grid;gap:9px;font-size:11px;color:var(--muted)}textarea{resize:vertical;min-height:100px;line-height:1.8;font-size:12px}.form-inline{display:grid;grid-template-columns:1fr 1fr;gap:15px}.actions{display:flex;gap:10px;justify-content:flex-end;margin-top:22px}.command-tabs{display:flex;flex-wrap:wrap;gap:8px;margin-bottom:18px}.chip{font-size:11px;border:1px solid var(--line);border-radius:5px;background:var(--surface);padding:8px 12px}.chip.active{background:var(--accent-soft);color:var(--accent);border-color:var(--accent)}pre{font:11px/1.85 Consolas,\"Microsoft YaHei\",monospace;white-space:pre-wrap;overflow-wrap:anywhere;margin:0;max-height:500px;overflow:auto}#result{margin-top:22px}.result-head{display:flex;align-items:center;justify-content:space-between;margin-bottom:14px}.tool-layout{display:grid;grid-template-columns:230px minmax(0,1fr);gap:22px}.tool-list{max-height:590px;overflow:auto}.tool-choice{width:100%;display:block;text-align:left;padding:12px 14px;border:0;border-bottom:1px solid var(--line);background:none;font-family:Consolas,monospace;font-size:11px;overflow-wrap:anywhere}.tool-choice.active{color:var(--accent);background:var(--accent-soft)}.schema-field{display:grid;gap:6px}.schema-field small{color:var(--muted);font-size:10px;line-height:1.6}.schema-field input[type=checkbox]{justify-self:start}.schema-fields{display:grid;gap:15px;margin-top:22px}.schema-fields:empty{display:none}details{margin-top:18px;color:var(--muted);font-size:11px}details summary{cursor:pointer;margin-bottom:15px}.toggle-row{display:flex;align-items:center;gap:8px;font-size:11px;color:var(--muted)}footer{display:flex;justify-content:space-between;gap:20px;color:var(--muted);border-top:1px solid var(--line);padding:19px 40px;font-size:9px;letter-spacing:.3px}#toast{position:fixed;bottom:30px;left:50%;transform:translateX(-50%);padding:12px 22px;background:var(--ink);color:var(--surface);border-radius:7px;box-shadow:var(--shadow);z-index:20;font-size:12px;max-width:90vw}dialog{border:1px solid var(--line);border-radius:12px;background:var(--surface);color:var(--ink);padding:28px;box-shadow:var(--shadow);width:min(640px,90vw);max-height:85vh}dialog::backdrop{background:#17221b66;backdrop-filter:blur(3px)}dialog h2{margin:12px 0}dialog p{color:var(--muted);font-size:12px;line-height:1.9;margin-bottom:18px}dialog pre{padding:17px;background:var(--bg);border-radius:6px;max-height:45vh}.detail-head{display:flex;justify-content:space-between;align-items:center;margin-bottom:15px}.permission{margin-top:17px;font-size:10px;line-height:1.9;color:var(--muted)}.path{font:10px/1.8 Consolas,monospace;word-break:break-all;margin-top:8px}.quick-actions{display:grid;gap:12px;margin-top:20px}.quick-action{padding:15px 0;display:flex;justify-content:space-between;align-items:center;border-bottom:1px solid var(--line);font-size:11px}.quick-action:last-child{border:0}.quick-action span{color:var(--muted);font-size:10px}.section-gap{margin-top:25px}.feed-time{font-size:10px;color:var(--muted);min-width:54px;padding-top:3px}.tools-description{font-size:11px;color:var(--muted);line-height:1.8;margin-top:11px;max-height:125px;overflow:auto}.raw-args{width:100%;min-height:170px;font-family:Consolas,monospace}.count{font-size:10px;color:var(--muted)}@media(max-width:1000px){main{padding:32px 25px}.sidebar{padding:30px 13px 20px}.shell{grid-template-columns:170px 1fr}header,footer{padding-left:25px;padding-right:25px}.grid-two{grid-template-columns:1fr}.stat{padding:20px 17px}.tool-layout{grid-template-columns:190px minmax(0,1fr)}}@media(max-width:680px){.shell{grid-template-columns:1fr}.sidebar{height:auto;position:static;border-right:0;border-bottom:1px solid var(--line);padding:18px}.brand{font-size:17px}.brand small{display:none}.mark{height:30px;width:29px;font-size:17px}.nav-caption,.sidebar-bottom{display:none}nav{display:flex;overflow:auto;gap:3px;margin-top:16px}.nav-item{white-space:nowrap;width:auto;padding:9px 11px;gap:7px}.nav-icon{font-size:14px}header{height:52px;padding:0 20px}main{padding:28px 20px 40px}h1{font-size:24px}.stats{grid-template-columns:1fr 1fr}.stat:nth-child(2){border-right:0}.stat:nth-child(-n+2){border-bottom:1px solid var(--line)}.stat-value{font-size:26px}.title-row{flex-wrap:wrap}.tool-layout{grid-template-columns:1fr}.tool-list{max-height:165px}.form-inline{grid-template-columns:1fr}footer{padding:15px 20px;line-height:1.8}footer span{display:none}.panel-head,.panel-body,.row-item{padding-left:18px;padding-right:18px}.connection{font-size:9px}}@media(prefers-reduced-motion:reduce){*{animation:none!important;scroll-behavior:auto!important}}\n</style><script>(function(){\n// issue #791:srcdoc 文档里 history.replaceState(s,t,'#x') 会抛\n// 「URL 'http://…/#x' cannot be created in a document with origin … and URL 'about:srcdoc'」\n// ⇒ 启动序列被打断、面板卡在「连接中」。这里把 URL 参数降级(只写 state),\n// 面板内部导航不依赖真实 hash(hashchange 在 srcdoc 里也不会触发)。\nvar R=history.replaceState.bind(history),PU=history.pushState.bind(history);\nhistory.replaceState=function(s,t,u){try{R(s,t,u)}catch(e){try{R(s,t)}catch(e2){}}};\nhistory.pushState=function(s,t,u){try{PU(s,t,u)}catch(e){try{PU(s,t)}catch(e2){}}};\nvar P=window.parent,seq=0,waits={};\nwindow.addEventListener('message',function(e){var d=e.data||{};\nif(d.__lingshu!=='res')return;var w=waits[d.id];if(!w)return;delete waits[d.id];w(d);});\nwindow.fetch=function(u,o){o=o||{};var id=++seq;return new Promise(function(res,rej){\nwaits[id]=function(d){if(d.error){rej(new Error(d.error));return}\nres({ok:d.ok,status:d.status,text:function(){return Promise.resolve(d.text)}});};\ntry{P.postMessage({__lingshu:'req',id:id,url:String(u),method:o.method||'GET',\nbody:(o.body==null?null:o.body),headers:o.headers||{}},'*');}catch(err){rej(err);}});};})();</script></head>\n<body><div class=\"shell\"><aside class=\"sidebar\"><a class=\"brand\" href=\"/lingshu\"><span class=\"mark\">灵</span><span>灵枢<small>认知工作台</small></span></a><div class=\"nav-caption\">工作空间</div><nav id=\"nav\" aria-label=\"灵枢功能\"></nav><div class=\"sidebar-bottom\"><button id=\"theme\" class=\"quiet\">◐ <span>切换明暗</span></button><a class=\"quiet\" href=\"/\" target=\"_top\">← <span>返回对话</span></a><div class=\"version\">LINGSHU / 0.8.1</div></div></aside><div class=\"workspace\"><header><div class=\"breadcrumb\">灵枢 <span>/</span> <b id=\"crumb\">概览</b></div><div class=\"header-right\"><span id=\"connection\" class=\"connection\">连接中</span><button class=\"icon-button\" id=\"refresh\" aria-label=\"刷新\" title=\"刷新\">↻</button></div></header><main id=\"main\" tabindex=\"-1\"></main><footer>以认知图为唯一真源。每一次操作,都有迹可循。<span id=\"identity\">—</span></footer></div></div><div id=\"toast\" role=\"status\" hidden></div><dialog id=\"confirm\"><form method=\"dialog\"><div class=\"eyebrow\">确认操作</div><h2>将调用灵枢修改接口</h2><p>此操作可能写入、审核或维护真实认知数据。请检查参数;插件原有权限与护栏仍然生效。</p><pre id=\"confirm-body\"></pre><div class=\"actions\"><button value=\"cancel\" class=\"button\">取消</button><button value=\"confirm\" class=\"button primary\">确认执行</button></div></form></dialog><dialog id=\"detail\"><div class=\"detail-head\"><h2>节点详情</h2><button id=\"close-detail\" class=\"icon-button\" aria-label=\"关闭详情\">×</button></div><pre id=\"detail-body\"></pre></dialog><script>(() => {\n 'use strict';\n const $ = id => document.getElementById(id);\n const esc = value => String(value ?? '').replace(/[&<>\"']/g, c => ({'&':'&','<':'<','>':'>','\"':'"',\"'\":'''}[c]));\n const json = value => JSON.stringify(value, null, 2);\n const pages = [ ['overview','◈','概览'], ['memory','▤','记忆'], ['goals','◎','目标与任务'], ['self','◇','自我认知'], ['space','◷','时空关系'], ['review','☷','审核与维护'], ['tools','⌘','工具台'] ];\n const layers = { knowledge:'知识', contextual:'情景', structural:'结构', anchor:'锚点', self:'自我', rejected:'否证', unresolved:'待定' };\n let meta = null, info = null, page = 'overview', generation = 0, chosen = 'cg', toolsFilter = '', toastTimer;\n const safeRead = new Set(['info','read','route','help','edges','status']);\n const readActions = {goal:['list'],task:['list','get','find','session'],recent:['list'],identity:['profile'],self_state:['snapshot'],metacognition:['report'],review:['list','records'],protect:['stats'],evolution:['summary'],sustain:['status'],maintain:['stat'],ref:['stat'],theory:['check'],link:['ls'],whitebox:['ping']};\n function needsConfirm(tool, args) {\n if (tool === 'stg') return !['relation','timeline','anchors','consistency','state_chain'].includes(args.op) || ['content','text','goal','set','apply','write','force','override','auto_flywheel'].some(k=>args[k]!==undefined);\n if (tool === 'cg') return !(safeRead.has(args.op) || (readActions[args.op]?.includes(args.action) && !['content','text','goal','set','apply','write','force','override','auto_flywheel'].some(k => args[k] !== undefined)));\n return !['mdcg_recall','mdcg_search','mdcg_get','mdcg_review_list','mdcg_review_records','mdcg_forgetting_history','mdcg_health','mdcg_whoami','mdcg_service_info','mdcg_rejected','mdcg_unresolved','mdcg_watermarks'].includes(tool);\n }\n async function fetchJSON(url, options = {}) {\n const controller = new AbortController(), timeout = setTimeout(() => controller.abort(), 70000);\n try {\n const response = await fetch(url, { credentials:'same-origin', ...options, signal:controller.signal });\n const text = await response.text(); let value;\n try { value = JSON.parse(text); } catch { throw new Error(response.status === 401 ? '登录已过期,请返回 DSH 登录后重试。' : '服务器未返回 JSON,请检查插件是否已加载。'); }\n if (!response.ok) throw new Error(value.error || `请求失败 (${response.status})`);\n return value;\n } catch (e) { if (e.name === 'AbortError') throw new Error('等待超时;操作可能仍在后台进行,请检查结果,不要重复提交。'); throw e; }\n finally { clearTimeout(timeout); }\n }\n async function confirm(tool, args) {\n $('confirm-body').textContent = json({ tool, args });\n const dialog = $('confirm'); dialog.returnValue = ''; dialog.showModal();\n return new Promise(resolve => dialog.addEventListener('close', () => resolve(dialog.returnValue === 'confirm'), { once:true }));\n }\n async function call(tool, args, interactive = false) {\n if (!meta?.csrf) throw new Error('灵枢未连接,请刷新后重试。');\n const mutating = needsConfirm(tool,args);\n if (mutating && (!interactive || !await confirm(tool,args))) throw new Error('已取消操作');\n const response = await fetchJSON('/plugins/lingshu/call', { method:'POST', headers:{'Content-Type':'application/json','X-Lingshu-CSRF':meta.csrf}, body:JSON.stringify({tool,args,confirm:mutating}) });\n return response.result;\n }\n function toast(text) { $('toast').textContent=text; $('toast').hidden=false; clearTimeout(toastTimer); toastTimer=setTimeout(()=>$('toast').hidden=true,4000); }\n function time(ts) { if (!ts) return '—'; const d = new Date(typeof ts==='number'?ts*1000:ts); return Number.isNaN(d.getTime()) ? String(ts) : d.toLocaleDateString('zh-CN',{month:'2-digit',day:'2-digit'})+' '+d.toLocaleTimeString('zh-CN',{hour:'2-digit',minute:'2-digit'}); }\n function title(name, en, subtitle, action='') { return `<div class=\"title-row\"><div><div class=\"eyebrow\">${en}</div><h1>${name}</h1><p class=\"subtitle\">${subtitle}</p></div>${action}</div>`; }\n function loading() { return '<div class=\"loading\">正在读取认知图</div>'; }\n function errorHTML(error) { return `<div class=\"notice error\">${esc(error.message || error)}</div>`; }\n function nodeRows(items, events=false) {\n if (!items?.length) return '<div class=\"empty\">这里还没有记录。<br>认知从一次真实的记录开始。</div>';\n return items.map(item => { const n=item.node || item, fm=n.frontmatter || {}; const id=n.id || n.node_id; const preview=n.preview || n.content || n.text || n.goal || n.title || n.name || json(n);\n return `<${id?'button':'div'} ${id?`type=\"button\" data-node=\"${esc(id)}\"`:''} class=\"row-item ${id?'node-button':''}\">${events?`<span class=\"feed-time\">${esc(time(n.start || n.t || n.ts || fm.created_at))}</span>`:'<span class=\"row-dot\"></span>'}<div class=\"row-content\"><div class=\"row-title\">${esc(String(preview).slice(0,220))}</div><div class=\"row-meta\"><span class=\"badge\">${esc(layers[n.layer||fm.layer] || n.layer || fm.layer || n.role || fm.role || '记录')}</span><span>${esc(time(n.start||n.t||n.ts||fm.created_at))}</span>${id?`<span>${esc(id)}</span>`:''}${item.state?`<span>${esc(item.state)}</span>`:''}</div></div></${id?'button':'div'}>`;\n }).join('');\n }\n function bindNodes(root=$('main')) { root.querySelectorAll('[data-node]').forEach(button=>button.addEventListener('click',async()=> { $('detail-body').textContent='正在读取…'; $('detail').showModal(); try { const r=await call('cg',{op:'read',node_id:button.dataset.node}); $('detail-body').textContent=r===null?'节点不存在、不可见或已删除。':json(r); } catch(e) { $('detail-body').textContent=e.message; } })); }\n function rowsOf(value) { if (Array.isArray(value)) return value; for(const key of ['items','results','goals','tasks','records','events','nodes','pack']) if(Array.isArray(value?.[key])) return value[key]; return []; }\n function renderResult(value, target='result') {\n const el=$(target); if(!el)return;\n el.innerHTML=`<div class=\"panel\"><div class=\"panel-body\"><div class=\"result-head\"><h3>调用结果</h3><button id=\"copy-result\" class=\"button\">复制 JSON</button></div>${value?.error?`<div class=\"notice error\">${esc(value.error)}</div>`:''}${value?.verdict||value?.moved_to||value?.committed===false?`<div class=\"notice\">${esc(value.verdict||'未直接提交')}${value.moved_to?' · '+esc(value.moved_to):''}${value.pid?' · 审核 '+esc(value.pid):''}。以下为真实回执,不代表全部已落盘。</div>`:''}<pre id=\"result-json\"></pre></div></div>`;\n $('result-json').textContent = typeof value==='string'?value:json(value);\n $('copy-result').onclick=async()=> { try { await navigator.clipboard.writeText($('result-json').textContent); toast('已复制'); } catch { toast('无法访问剪贴板,可直接选中结果复制。'); } };\n }\n async function execute(button, tool, args) {\n button.disabled=true; const original=button.textContent; button.textContent='执行中…';\n try { renderResult(await call(tool,args,true)); } catch(e) { const target=$('result'); if(target) target.innerHTML=errorHTML(e); }\n finally { button.disabled=false; button.textContent=original; }\n }\n function permissionNote(op) { const allowed=info?.whoami?.principal?.ops_allow; return allowed && !allowed.includes('*') && !allowed.includes(op) ? `<div class=\"notice\">当前令牌未声明 ${esc(op)} 权限。入口保留,调用仍由灵枢权限系统裁定;本界面不会自动扩权。</div>`:''; }\n async function overview(token) {\n $('main').innerHTML=title('让认知,有迹可循。','COGNITIVE WORKSPACE','记忆、目标与自我,在同一张认知图中延续。','<button id=\"new-memory\" class=\"button primary\">+ 记录记忆</button>')+loading();\n $('new-memory').onclick=()=>navigate('memory',true);\n // issue #801(#677 B 的契约变更后续):面板要读 os.goals / os.review_pending / os.protection,\n // 而 info 缺省**不再返回** os(仅 full=true 才回)⇒ 面板取数必须显式带 full:true,否则整片显示「—」。\n const results=await Promise.allSettled([call('cg',{op:'info',full:true}),call('stg',{op:'timeline',limit:5,desc:true})]);\n if(token!==generation)return;\n if(results[0].status==='rejected') throw results[0].reason;\n info=results[0].value; const os=info.os||{}, who=info.whoami?.principal||{}; const timeline=results[1].status==='fulfilled'?results[1].value:null;\n $('main').innerHTML=title('让认知,有迹可循。','COGNITIVE WORKSPACE','记忆、目标与自我,在同一张认知图中延续。','<button id=\"new-memory\" class=\"button primary\">+ 记录记忆</button>')+\n `<div class=\"stats\">${[['记忆节点',info.total_nodes??info.whoami?.nodes_visible??'—','认知图中的真实记录'],['活跃目标',os.goals?.active??'—','持续追踪的行动方向'],['待审核',os.review_pending??'—','等待裁决的候选'],['受保护',os.protection?.protected_count??'—','需要保留的认知锚点']].map(([name,count,note])=>`<div class=\"stat\"><div class=\"stat-label\">${name}</div><div class=\"stat-value\">${esc(count)}</div><div class=\"stat-note\">${note}</div></div>`).join('')}</div>`+\n `<div class=\"grid-two\"><section class=\"panel\"><div class=\"panel-head\"><h3>最近记忆</h3><button class=\"button text\" id=\"all-memory\">查看全部 ↗</button></div>${timeline?nodeRows(timeline.items):errorHTML(results[1].reason)}</section><div><section class=\"panel\"><div class=\"panel-head\"><h3>运行状态</h3><span class=\"badge\">真实连接</span></div><div class=\"panel-body\">${[['大脑桥',meta.ready?'已就绪':'未就绪'],['写入权限',who.can_write?'可写 · '+(who.role||'已授权'):'只读'],['可见密级',who.clearance||'—'],['自动召回',meta.memory?.autoRecall?'开启':'关闭'],['近期窗口',meta.memory?.contextWindow?.enabled?(meta.memory.contextWindow.turns+' 条'):'关闭']].map(([k,v])=>`<div class=\"status-line\"><span>${k}</span><span>${esc(v)}</span></div>`).join('')}<div class=\"permission\">工具可见不等于全部有权限。保留现有令牌与护栏。</div></div></section><div class=\"quick-actions\"><button class=\"button quick-action\" data-page=\"goals\">目标与任务 <span>明确下一步 ↗</span></button><button class=\"button quick-action\" data-page=\"tools\">完整工具台 <span>${meta.tools.length} 个真实工具 ↗</span></button></div></div></div>`+\n `<div class=\"panel section-gap\"><div class=\"panel-body\"><h3>认知图健康</h3><p class=\"hint\" style=\"margin-top:10px\">${info.problems?.length?esc(info.problems.join(';')):'暂无健康诊断问题。'}</p><div class=\"path muted\">${esc(info.whoami?.root||'')}</div></div></div>`;\n $('new-memory').onclick=()=>navigate('memory',true); $('all-memory').onclick=()=>navigate('memory'); document.querySelectorAll('[data-page]').forEach(b=>b.onclick=()=>navigate(b.dataset.page)); bindNodes();\n }\n async function memory(token, compose) {\n $('main').innerHTML=title('记忆','MEMORY','检索已有认知,或将一条有价值的信息交给记忆闸门。','<button id=\"compose-toggle\" class=\"button primary\">+ 记录记忆</button>')+\n `<section id=\"compose\" class=\"panel\" ${compose?'':'hidden'}><div class=\"panel-head\"><h3>记录一条记忆</h3><span class=\"badge\">主动遗忘闸门</span></div><form id=\"memory-form\" class=\"panel-body form-grid\"><label>内容<textarea id=\"memory-content\" required placeholder=\"记录事实、经验或需要延续的上下文…\"></textarea></label><div class=\"form-inline\"><label>归属层<select id=\"memory-layer\"><option value=\"contextual\">情景 · 对话与经历</option><option value=\"knowledge\">知识 · 经验与事实</option><option value=\"structural\">结构 · 方法与规则</option><option value=\"self\">自我 · 身份与认知</option></select></label><label>重要性<input id=\"memory-importance\" type=\"number\" min=\"0\" max=\"1\" step=\"0.05\" value=\"0.5\"></label></div><label>标签<input id=\"memory-tags\" placeholder=\"使用逗号分隔,如:项目,经验\"></label><p class=\"hint\">通过 mdcg_remember 写入。可能接受、合并、丢弃或进入审核队列;结果以真实回执为准。不会指定节点 ID 或覆盖已有记录。</p><div class=\"actions\"><button type=\"submit\" class=\"button primary\">确认记录</button></div></form></section><form id=\"search-form\" class=\"toolbar ${compose?'section-gap':''}\"><input id=\"search-query\" class=\"search\" placeholder=\"搜索记忆中的关键词或问题…\" aria-label=\"搜索记忆\"><select id=\"search-layer\" aria-label=\"记忆层\"><option value=\"\">所有层</option>${Object.entries(layers).map(([k,v])=>`<option value=\"${k}\">${v}</option>`).join('')}</select><button class=\"button\" type=\"submit\">检索 ↗</button></form><section class=\"panel\"><div class=\"panel-head\"><h3 id=\"memory-list-title\">最近写入的记忆</h3><span class=\"count\" id=\"memory-count\"></span></div><div id=\"memory-list\">${loading()}</div></section><div id=\"result\"></div>`;\n $('compose-toggle').onclick=()=>{$('compose').hidden=!$('compose').hidden; if(!$('compose').hidden)$('memory-content').focus();};\n $('memory-form').onsubmit=async e=> { e.preventDefault(); const args={content:$('memory-content').value.trim(),layer:$('memory-layer').value,role:'user',importance:Number($('memory-importance').value),tags:$('memory-tags').value.split(/[,,]/).map(s=>s.trim()).filter(Boolean),gated:true,consistency:true,on_conflict:'defer'}; await execute(e.submitter,'mdcg_remember',args); };\n async function loadList(search=false) {\n const query=$('search-query').value.trim(), layer=$('search-layer').value;\n const list=$('memory-list'), count=$('memory-count'); list.innerHTML=loading();\n try { const result=query?await call('cg',{op:'read',query,k:30,...(layer?{layer}:{})}):await call('stg',{op:'timeline',limit:30,desc:true,...(layer?{layer}:{})}); if(token!==generation)return; const items=rowsOf(result); list.innerHTML=result?.error?errorHTML(result.error):nodeRows(items); count.textContent=`${items.length} 条${result.truncated?' · 已截断':''}`; $('memory-list-title').textContent=query?'检索结果':'最近写入的记忆'; bindNodes(list); if(search&&result?.meta)renderResult(result); } catch(e) { if(token===generation)list.innerHTML=errorHTML(e); }\n }\n $('search-form').onsubmit=e=>{e.preventDefault();void loadList(true);}; $('search-layer').onchange=()=>void loadList(); await loadList();\n }\n const presets = {\n goals: {title:'目标与任务',en:'GOALS & TASKS',description:'把目标变成可追踪的行动。查询和新增,都保留真实回执。',items:[['目标列表','cg',{op:'goal',action:'list',limit:20}],['任务列表','cg',{op:'task',action:'list',limit:20}],['新增目标','cg',{op:'goal',action:'add',goal:'',priority:1}],['开启任务','cg',{op:'task',action:'open',goal:'',plan:'',acceptance:''}]]},\n self: {title:'自我认知',en:'SELF & IDENTITY',description:'身份、状态与反思,分别读取,不把生成的文字当作认知事实。',items:[['身份档案','cg',{op:'identity',action:'profile'}],['状态快照','cg',{op:'self_state',action:'snapshot'}],['元认知报告','cg',{op:'metacognition',action:'report'}],['白箱连通','cg',{op:'whitebox',action:'ping'}]]},\n space: {title:'时空关系',en:'SPACE & TIME',description:'沿时间寻找记忆,或比较两个节点的时空关系。',items:[['记忆时间线','stg',{op:'timeline',limit:20,desc:true}],['近期事件','cg',{op:'recent',action:'list',limit:20}],['节点关系','stg',{op:'relation',a:'',b:''}],['时空一致性','stg',{op:'consistency',limit:20}],['锚点查询','stg',{op:'anchors',time_window:[0,Math.floor(Date.now()/1000)],limit:20}],['状态链','stg',{op:'state_chain',subject:'self:lingshu',limit:20}]]},\n review: {title:'审核与维护',en:'REVIEW & CARE',description:'先查看,再裁决。不会在打开页面时启动维护、遗忘或自动演化。',items:[['待审核候选','cg',{op:'review',action:'list'}],['审核记录','cg',{op:'review',action:'records'}],['保护统计','cg',{op:'protect',action:'stats'}],['演化摘要','cg',{op:'evolution',action:'summary'}],['维护状态','cg',{op:'sustain',action:'status'}],['审核裁决','cg',{op:'review',action:'decide',pid:'',decision:'reject'}],['节点核验','cg',{op:'verify',node_id:'',evidence:'',verdict:'confirmed'}]]}\n };\n function grouped(name) {\n const group=presets[name]; let active=0;\n $('main').innerHTML=title(group.title,group.en,group.description)+`<div class=\"command-tabs\">${group.items.map(([label],i)=>`<button class=\"chip ${i===0?'active':''}\" data-preset=\"${i}\">${label}</button>`).join('')}</div><div id=\"permission\"></div><section class=\"panel\"><div class=\"panel-head\"><h3 id=\"command-title\"></h3><span class=\"badge\" id=\"command-tool\"></span></div><div class=\"panel-body\"><div id=\"preset-fields\" class=\"form-grid\"></div><details><summary>原始调用参数</summary><textarea class=\"raw-args\" id=\"preset-json\" aria-label=\"原始调用参数\"></textarea></details><div class=\"actions\"><button id=\"preset-help\" class=\"button\">查看帮助</button><button id=\"preset-run\" class=\"button primary\">执行查询</button></div></div></section><div id=\"result\"></div>`;\n function select(i) {\n active=i; const [label,tool,args]=group.items[i]; $('command-title').textContent=label; $('command-tool').textContent=tool+' · '+args.op;\n document.querySelectorAll('[data-preset]').forEach(b=>b.classList.toggle('active',Number(b.dataset.preset)===i)); $('permission').innerHTML=tool==='cg'?permissionNote(args.op):''; $('preset-json').value=json(args); $('result').innerHTML='';\n $('preset-run').textContent=needsConfirm(tool,args)?'检查并执行':'执行查询';\n $('preset-fields').innerHTML=Object.entries(args).filter(([k])=>!['op','action','limit','desc'].includes(k)).map(([k,v])=>`<label>${esc(fieldLabel(k))}<${typeof v==='string'&&['plan','evidence','acceptance','goal'].includes(k)?'textarea':'input'} data-preset-field=\"${esc(k)}\" ${typeof v==='number'?'type=\"number\" step=\"any\"':''} ${Array.isArray(v)?'placeholder=\"JSON 数组\"':''} ${typeof v==='string'&&['plan','evidence','acceptance','goal'].includes(k)?'':`value=\"${esc(typeof v==='object'?json(v):v)}\"`}>${typeof v==='string'&&['plan','evidence','acceptance','goal'].includes(k)?esc(v):''}</${typeof v==='string'&&['plan','evidence','acceptance','goal'].includes(k)?'textarea':'input'}></label>`).join('') || '<p class=\"hint\">无需额外参数。点击执行,读取真实数据。</p>';\n document.querySelectorAll('[data-preset-field]').forEach(input=>input.oninput=()=>{try{const next=JSON.parse($('preset-json').value),key=input.dataset.presetField,old=args[key];next[key]=typeof old==='number'?Number(input.value):typeof old==='object'?JSON.parse(input.value):input.value;$('preset-json').value=json(next);}catch{/* 继续保留用户编辑 */}});\n }\n document.querySelectorAll('[data-preset]').forEach(b=>b.onclick=()=>select(Number(b.dataset.preset)));\n $('preset-run').onclick=async e=> { try { const args=JSON.parse($('preset-json').value); await execute(e.currentTarget,group.items[active][1],args); }catch(err){$('result').innerHTML=errorHTML(err);} };\n $('preset-help').onclick=async e=>await execute(e.currentTarget,'cg',{op:'help',query:group.items[active][2].op}); select(0);\n }\n function fieldLabel(key) { return {goal:'目标内容',plan:'执行计划',acceptance:'验收标准',priority:'优先级',a:'节点 A',b:'节点 B',node_id:'节点 ID',pid:'候选 ID',decision:'裁决:accept / reject / edit / merge',evidence:'验证依据',verdict:'判定:confirmed / weakened / falsified',time_window:'时间窗口(秒级时间戳数组)',subject:'主体'}[key]||key; }\n async function toolsPage() {\n const tools=meta?.tools||[];\n $('main').innerHTML=title('工具台','PLUGIN CAPABILITIES','完整工具来自灵枢实时目录。常用参数可填表,高级能力通过原始 JSON 调用。')+\n `<div class=\"notice\">保持插件原有权限边界。写入、裁决、索引、导出与维护操作均需确认;不会自动启动后台任务。</div><div class=\"tool-layout\"><section class=\"panel\"><div class=\"panel-body\" style=\"padding:15px\"><input id=\"tool-search\" style=\"width:100%\" placeholder=\"查找工具…\" aria-label=\"查找工具\"></div><div id=\"tool-list\" class=\"tool-list\"></div></section><section class=\"panel\"><div class=\"panel-body\"><h2 id=\"tool-name\"></h2><div id=\"tool-description\" class=\"tools-description\"></div><div id=\"op-chooser\"></div><div id=\"schema-fields\" class=\"schema-fields\"></div><details open><summary>原始 JSON 参数 · 完整能力入口</summary><textarea id=\"tool-args\" class=\"raw-args\" spellcheck=\"false\" aria-label=\"工具 JSON 参数\"></textarea></details><div class=\"actions\"><button id=\"tool-help\" class=\"button\">调用说明</button><button id=\"tool-run\" class=\"button primary\">执行调用</button></div></div></section></div><div id=\"result\"></div>`;\n function renderList() { $('tool-list').innerHTML=tools.filter(t=>(t.name+' '+t.description).toLowerCase().includes(toolsFilter.toLowerCase())).map(t=>`<button class=\"tool-choice ${chosen===t.name?'active':''}\" data-tool=\"${esc(t.name)}\">${esc(t.name)}</button>`).join('') || '<div class=\"empty\">没有匹配工具</div>'; document.querySelectorAll('[data-tool]').forEach(b=>b.onclick=()=>selectTool(b.dataset.tool)); }\n async function selectTool(name) {\n chosen=name; const tool=tools.find(t=>t.name===name); if(!tool)return;\n renderList(); $('tool-name').textContent=name; $('tool-description').textContent=tool.description;\n const properties=tool.inputSchema?.properties || {}, required=tool.inputSchema?.required || [];\n const defaults = name==='cg'?{op:'info'}:name==='stg'?{op:'timeline',limit:20,desc:true}:{};\n $('tool-args').value=json(defaults); $('result').innerHTML='';\n const opProp=properties.op;\n let ops=opProp?.enum || [];\n if(!ops.length && opProp?.description) ops=(opProp.description.split(/[\\s,。]/)[0]||'').split('|').filter(Boolean);\n $('op-chooser').innerHTML=ops.length?`<label class=\"schema-field\" style=\"margin-top:20px\">操作<select id=\"tool-op\">${ops.map(op=>`<option value=\"${esc(op)}\">${esc(op)}</option>`).join('')}</select></label>`:'';\n if($('tool-op')){ $('tool-op').value=defaults.op||ops[0]; $('tool-op').onchange=()=>{try{const args=JSON.parse($('tool-args').value);args.op=$('tool-op').value;delete args.action;$('tool-args').value=json(args);}catch(e){toast('先修正 JSON 参数。');}}; }\n const common=Object.entries(properties).filter(([key])=>key!=='op' && (required.includes(key)||['query','content','action','node_id','layer','limit','goal','evidence','verdict','a','b'].includes(key)));\n $('schema-fields').innerHTML=common.map(([key,p])=>`<label class=\"schema-field\">${esc(fieldLabel(key))}${required.includes(key)?' *':''}<input data-field=\"${esc(key)}\" data-type=\"${esc(p.type||'string')}\" placeholder=\"${esc(p.enum?.join(' / ')||p.type||'string')}\" ${p.type==='number'||p.type==='integer'?'type=\"number\" step=\"any\"':''}><small>${esc((p.description||'').slice(0,240))}</small></label>`).join('');\n document.querySelectorAll('[data-field]').forEach(input=>input.oninput=()=>{try{const args=JSON.parse($('tool-args').value),key=input.dataset.field;if(input.value==='')delete args[key];else args[key]=['number','integer'].includes(input.dataset.type)?Number(input.value):['object','array','boolean'].includes(input.dataset.type)?JSON.parse(input.value):input.value;$('tool-args').value=json(args);}catch{toast('该字段需要有效 JSON,或请直接编辑原始参数。');}});\n }\n $('tool-search').value=toolsFilter; $('tool-search').oninput=e=>{toolsFilter=e.target.value;renderList();};\n $('tool-run').onclick=async e=>{try{const args=JSON.parse($('tool-args').value);await execute(e.currentTarget,chosen,args);}catch(err){$('result').innerHTML=errorHTML(err);}};\n $('tool-help').onclick=async e=>await execute(e.currentTarget,'cg',{op:'help',query:chosen});\n if(!tools.some(t=>t.name===chosen))chosen=tools[0]?.name; renderList(); if(chosen)await selectTool(chosen); else $('tool-name').textContent='大脑未就绪,目录不可用';\n }\n async function navigate(name, compose=false) {\n page=pages.some(p=>p[0]===name)?name:'overview'; const token=++generation;\n history.replaceState(null,'', '#'+page); $('crumb').textContent=pages.find(p=>p[0]===page)[2];\n document.querySelectorAll('[data-nav]').forEach(b=>{b.classList.toggle('active',b.dataset.nav===page); if(b.dataset.nav===page)b.setAttribute('aria-current','page');else b.removeAttribute('aria-current');});\n $('main').innerHTML=loading();\n try { if(!meta)throw new Error('插件未连接,请点击右上角刷新。'); if(page==='overview')await overview(token);else if(page==='memory')await memory(token,compose);else if(presets[page])grouped(page);else await toolsPage(); }\n catch(e) { if(token===generation)$('main').innerHTML=title('暂时无法读取','CONNECTION','数据没有被替换为演示内容。请检查灵枢连接。')+errorHTML(e); }\n }\n async function boot() {\n $('refresh').disabled=true;\n try { meta=await fetchJSON('/plugins/lingshu/meta');$('connection').textContent=meta.ready?'大脑已连接':'大脑未就绪';$('connection').classList.toggle('online',meta.ready);$('identity').textContent=meta.identity+' · '+meta.tools.length+' 个工具'; await navigate(location.hash.slice(1)||page); }\n catch(e){meta=null;$('connection').textContent='连接失败';$('connection').classList.remove('online');$('main').innerHTML=errorHTML(e);}\n finally{$('refresh').disabled=false;}\n }\n $('nav').innerHTML=pages.map(([id,icon,label])=>`<button class=\"nav-item\" data-nav=\"${id}\"><span class=\"nav-icon\" aria-hidden=\"true\">${icon}</span>${label}</button>`).join('');\n document.querySelectorAll('[data-nav]').forEach(b=>b.onclick=()=>navigate(b.dataset.nav)); $('refresh').onclick=boot; $('close-detail').onclick=()=>$('detail').close();\n let theme='';try{theme=localStorage.getItem('lingshu.theme')||'';}catch{} if(theme)document.documentElement.dataset.theme=theme;else if(matchMedia('(prefers-color-scheme:dark)').matches)document.documentElement.dataset.theme='dark';\n $('theme').onclick=()=>{const next=document.documentElement.dataset.theme==='dark'?'light':'dark';document.documentElement.dataset.theme=next;try{localStorage.setItem('lingshu.theme',next);}catch{}};\n window.addEventListener('hashchange',()=>navigate(location.hash.slice(1))); void boot();\n})();\n</script></body></html>\n"; // build-ui.mjs 打包时内联(index.html + style.css + 桥 + app.js)
|
|
4
5
|
function Icon({size=16}) {
|
|
5
|
-
return React.createElement('svg', {width:size,height:size,viewBox:'0 0 24 24',fill:'none',stroke:'currentColor',strokeWidth:1.5,'aria-hidden':true}, React.createElement('path',{d:'
|
|
6
|
+
return React.createElement('svg', {width:size,height:size,viewBox:'0 0 24 24',fill:'none',stroke:'currentColor',strokeWidth:1.5,'aria-hidden':true}, React.createElement('path',{d:'M12 3v18M5 7l14 10M19 7L5 17'}));
|
|
7
|
+
}
|
|
8
|
+
// issue #791:桌面版(dsh-app://)下 iframe 子 frame 拿不到 x-dsh-desktop-renderer ⇒ 403 白屏。
|
|
9
|
+
// 改法:面板用 srcdoc 内嵌同一份 UI,页面里的 fetch 全部经 postMessage 由**主 frame** 代发
|
|
10
|
+
// (主 frame 的请求带 marker,能过 host 的 web-document 门);/lingshu 直连路由保持不变。
|
|
11
|
+
// 桥的状态必须在**模块级**:ref 每次渲染都是新函数,若状态写在 Panel 内会重复绑 listener(复核 0077)。
|
|
12
|
+
const BRIDGE = { frame: null, bound: false };
|
|
13
|
+
function onFrameRef(node) {
|
|
14
|
+
BRIDGE.frame = node;
|
|
15
|
+
if (!node || BRIDGE.bound) return;
|
|
16
|
+
BRIDGE.bound = true;
|
|
17
|
+
window.addEventListener('message', (ev) => {
|
|
18
|
+
const d = ev.data || {};
|
|
19
|
+
if (d.__lingshu !== 'req') return;
|
|
20
|
+
if (BRIDGE.frame && ev.source !== BRIDGE.frame.contentWindow) return;
|
|
21
|
+
const reply = (payload) => {
|
|
22
|
+
try { BRIDGE.frame.contentWindow.postMessage(Object.assign({ __lingshu: 'res', id: d.id }, payload), '*'); } catch (e) { /* frame 已卸载 */ }
|
|
23
|
+
};
|
|
24
|
+
fetch(d.url, { method: d.method || 'GET', body: (d.body == null ? undefined : d.body), headers: d.headers || {}, credentials: 'same-origin' })
|
|
25
|
+
.then(async (r) => reply({ ok: r.ok, status: r.status, text: await r.text() }))
|
|
26
|
+
.catch((e) => reply({ error: String((e && e.message) || e) }));
|
|
27
|
+
});
|
|
6
28
|
}
|
|
7
29
|
function Panel() {
|
|
8
|
-
return React.createElement('iframe', {
|
|
30
|
+
return React.createElement('iframe', {
|
|
31
|
+
title: '灵枢 · 认知工作台',
|
|
32
|
+
srcDoc: PANEL_HTML,
|
|
33
|
+
ref: onFrameRef,
|
|
34
|
+
style: {width:'100%',height:'100%',border:0,display:'block',background:'#f8f9f7'},
|
|
35
|
+
});
|
|
9
36
|
}
|
|
10
37
|
module.exports = {
|
|
11
38
|
inject:['slots'],
|
|
@@ -14,5 +41,4 @@ module.exports = {
|
|
|
14
41
|
ctx.slots.inject('sidebar.panellist',()=>ctx.slots.register({name:'sidebar.panellist',id:'lingshu',order:20,label:'灵枢'},Icon));
|
|
15
42
|
},
|
|
16
43
|
};
|
|
17
|
-
|
|
18
44
|
return module.exports;}});
|
package/lib/hooks.d.ts
CHANGED
|
@@ -180,6 +180,18 @@ export declare function redactForLog(value: unknown): string;
|
|
|
180
180
|
* 会让整块被最旧的一条挤掉。逐档递减后整块实测约 1133 字符(≈472 tok),
|
|
181
181
|
* 9 条全部保留。(注意:整块仍远小于一条知识节点 500~800 tok,故本块定位是
|
|
182
182
|
* 「存在性索引/提醒」,不承载知识本身——要知识请显式 mdcg_recall 并给足预算。) */
|
|
183
|
+
/**
|
|
184
|
+
* issue #739(注入面去重):同一会话内**同一条记忆最多注入 `cap` 次**。
|
|
185
|
+
*
|
|
186
|
+
* 实测(2026-11-06,`--D-6_ai--/session-c28c8589…`,192 轮 / 39.7 MB):
|
|
187
|
+
* 「灵枢最近记忆」注入 48 次、条目出现 **362 次但只有 18 条去重后节点** ⇒ 单条最高被贴 **62 次**。
|
|
188
|
+
* 上下文里同一批旧结论被反复强化会产生「复述已有结论、不再探索」的退化观感(#739 原始报告)。
|
|
189
|
+
*
|
|
190
|
+
* 口径:按 `layer + preview` 计(`timeline` 的 item 不带 id,且预览即渲染面),
|
|
191
|
+
* 超过 cap 的条目本轮丢弃;**不丢完**——若全被滤掉则保留第一条,避免整块消失导致
|
|
192
|
+
* 宿主再追加一份「没有本块」的快照(#657 的代价)。
|
|
193
|
+
*/
|
|
194
|
+
export declare function dedupeRepeatedItems(payload: unknown, seen: Map<string, number>, cap?: number): unknown;
|
|
183
195
|
export declare function formatTimelineDecayed(payload: unknown, opts?: {
|
|
184
196
|
includeIdentity?: boolean;
|
|
185
197
|
}): string;
|
package/lib/hooks.js
CHANGED
|
@@ -349,6 +349,39 @@ const RECALL_SKIP_LAYERS = new Set(['anchor', 'self']);
|
|
|
349
349
|
* 9 条全部保留。(注意:整块仍远小于一条知识节点 500~800 tok,故本块定位是
|
|
350
350
|
* 「存在性索引/提醒」,不承载知识本身——要知识请显式 mdcg_recall 并给足预算。) */
|
|
351
351
|
// issue #563:导出仅为可测(注入面脱敏顺序的回归用例需要直接喂 payload)。
|
|
352
|
+
/**
|
|
353
|
+
* issue #739(注入面去重):同一会话内**同一条记忆最多注入 `cap` 次**。
|
|
354
|
+
*
|
|
355
|
+
* 实测(2026-11-06,`--D-6_ai--/session-c28c8589…`,192 轮 / 39.7 MB):
|
|
356
|
+
* 「灵枢最近记忆」注入 48 次、条目出现 **362 次但只有 18 条去重后节点** ⇒ 单条最高被贴 **62 次**。
|
|
357
|
+
* 上下文里同一批旧结论被反复强化会产生「复述已有结论、不再探索」的退化观感(#739 原始报告)。
|
|
358
|
+
*
|
|
359
|
+
* 口径:按 `layer + preview` 计(`timeline` 的 item 不带 id,且预览即渲染面),
|
|
360
|
+
* 超过 cap 的条目本轮丢弃;**不丢完**——若全被滤掉则保留第一条,避免整块消失导致
|
|
361
|
+
* 宿主再追加一份「没有本块」的快照(#657 的代价)。
|
|
362
|
+
*/
|
|
363
|
+
export function dedupeRepeatedItems(payload, seen, cap = 2) {
|
|
364
|
+
const items = (payload && typeof payload === 'object'
|
|
365
|
+
&& Array.isArray(payload.items))
|
|
366
|
+
? payload.items
|
|
367
|
+
: null;
|
|
368
|
+
if (!items)
|
|
369
|
+
return payload;
|
|
370
|
+
const kept = [];
|
|
371
|
+
for (const it of items) {
|
|
372
|
+
const key = String(it['layer'] ?? '') + '|' + String(it['preview'] ?? '');
|
|
373
|
+
const n = seen.get(key) ?? 0;
|
|
374
|
+
if (n >= cap)
|
|
375
|
+
continue;
|
|
376
|
+
seen.set(key, n + 1);
|
|
377
|
+
kept.push(it);
|
|
378
|
+
}
|
|
379
|
+
if (kept.length === 0) {
|
|
380
|
+
const first = items[0];
|
|
381
|
+
return { ...payload, items: first ? [first] : [] };
|
|
382
|
+
}
|
|
383
|
+
return { ...payload, items: kept };
|
|
384
|
+
}
|
|
352
385
|
export function formatTimelineDecayed(payload, opts) {
|
|
353
386
|
const items = (payload && typeof payload === 'object'
|
|
354
387
|
&& Array.isArray(payload.items))
|
|
@@ -780,6 +813,8 @@ export function installMemoryHooks(ctx, mdcg, opts) {
|
|
|
780
813
|
const pendingReminder = new Map();
|
|
781
814
|
/** issue #695:已记过「本会话被排除」日志的会话(避免每条消息刷一条)。 */
|
|
782
815
|
const excludedLogged = new Set();
|
|
816
|
+
/** issue #739:会话 → (layer|preview) → 已注入次数;同一会话内同一条最多注入 2 次。 */
|
|
817
|
+
const injectSeen = new Map();
|
|
783
818
|
/** 提醒间隔:false 或 **<= 0 → 0(关闭)**;数字 → clamp 1..100;未设/非有限 → 10。
|
|
784
819
|
* issue #659 F26-21:旧实现把 0 钳成 1(每轮提醒一次),与「0 = 关」的直觉相反;
|
|
785
820
|
* 负数同样落 0(关),而不是变成 1。非有限(NaN/Infinity)仍回落默认 10。 */
|
|
@@ -859,7 +894,14 @@ export function installMemoryHooks(ctx, mdcg, opts) {
|
|
|
859
894
|
const identityPayload = identityOn
|
|
860
895
|
? await graph.timeline(IDENTITY_MAX_ITEMS * 3, {})
|
|
861
896
|
: null;
|
|
862
|
-
|
|
897
|
+
// issue #739:同一会话内同一条最多注入 2 次(见 dedupeRepeatedItems 的实测数据)。
|
|
898
|
+
const seenKey = sid || '__no_sid__';
|
|
899
|
+
let seenMap = injectSeen.get(seenKey);
|
|
900
|
+
if (!seenMap) {
|
|
901
|
+
seenMap = new Map();
|
|
902
|
+
injectSeen.set(seenKey, seenMap);
|
|
903
|
+
}
|
|
904
|
+
const text = formatTimelineDecayed(dedupeRepeatedItems(timelinePayload, seenMap, 2));
|
|
863
905
|
if (text) {
|
|
864
906
|
// 注入边界转义(issue #16):宿主 system-prompt 对 context 文本做严格
|
|
865
907
|
// `{{variable}}` 插值,裸 `{{` 会 throw → 该轮请求整体失败。记忆原文
|
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) */
|