dsh-memory-gate 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/LICENSE +21 -0
  3. package/README.md +126 -0
  4. package/cordis.patch.yml +14 -0
  5. package/docs/architecture.md +142 -0
  6. package/docs/benchmark.md +41 -0
  7. package/lib/authority.d.ts +9 -0
  8. package/lib/authority.d.ts.map +1 -0
  9. package/lib/authority.js +71 -0
  10. package/lib/authority.js.map +1 -0
  11. package/lib/commands.d.ts +7 -0
  12. package/lib/commands.d.ts.map +1 -0
  13. package/lib/commands.js +225 -0
  14. package/lib/commands.js.map +1 -0
  15. package/lib/config.d.ts +19 -0
  16. package/lib/config.d.ts.map +1 -0
  17. package/lib/config.js +33 -0
  18. package/lib/config.js.map +1 -0
  19. package/lib/contracts.d.ts +94 -0
  20. package/lib/contracts.d.ts.map +1 -0
  21. package/lib/contracts.js +2 -0
  22. package/lib/contracts.js.map +1 -0
  23. package/lib/extractor.d.ts +8 -0
  24. package/lib/extractor.d.ts.map +1 -0
  25. package/lib/extractor.js +44 -0
  26. package/lib/extractor.js.map +1 -0
  27. package/lib/harness.d.ts +19 -0
  28. package/lib/harness.d.ts.map +1 -0
  29. package/lib/harness.js +85 -0
  30. package/lib/harness.js.map +1 -0
  31. package/lib/index.d.ts +15 -0
  32. package/lib/index.d.ts.map +1 -0
  33. package/lib/index.js +44 -0
  34. package/lib/index.js.map +1 -0
  35. package/lib/message-text.d.ts +3 -0
  36. package/lib/message-text.d.ts.map +1 -0
  37. package/lib/message-text.js +21 -0
  38. package/lib/message-text.js.map +1 -0
  39. package/lib/redaction.d.ts +7 -0
  40. package/lib/redaction.d.ts.map +1 -0
  41. package/lib/redaction.js +23 -0
  42. package/lib/redaction.js.map +1 -0
  43. package/lib/repository.d.ts +39 -0
  44. package/lib/repository.d.ts.map +1 -0
  45. package/lib/repository.js +492 -0
  46. package/lib/repository.js.map +1 -0
  47. package/lib/scope.d.ts +4 -0
  48. package/lib/scope.d.ts.map +1 -0
  49. package/lib/scope.js +26 -0
  50. package/lib/scope.js.map +1 -0
  51. package/lib/service.d.ts +42 -0
  52. package/lib/service.d.ts.map +1 -0
  53. package/lib/service.js +157 -0
  54. package/lib/service.js.map +1 -0
  55. package/package.json +74 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,32 @@
1
+ # Changelog
2
+
3
+ ## 0.2.0 - 2026-08-14
4
+
5
+ - Rename the plugin, package, and repository from `dsh-memory-cbdc` to
6
+ `dsh-memory-gate` (plugin id `memory-gate`). CBDC remains the name of the
7
+ Claim → Belief → Decision → Consumption gating mechanism.
8
+ - Un-private the package so it can be published to npm; the npm spec
9
+ `dsh-memory-gate` becomes the primary install path, with the Git URL kept
10
+ as a pinned alternative. The old repository URL redirects to the new one.
11
+ - The default database path stays `$DSH_HOME/memory/cbdc.sqlite`, so existing
12
+ v0.1.x installations keep their data after upgrading.
13
+
14
+ ## 0.1.2 - 2026-08-14
15
+
16
+ - Remove the unnecessary install-time `prepare` script so pnpm 10 can install
17
+ the Git-hosted plugin without an `onlyBuiltDependencies` exception.
18
+ - Pin the documented Git install command to the tested release tag.
19
+
20
+ ## 0.1.1 - 2026-08-14
21
+
22
+ - Default to conservative assist mode with a 3-claim/1200-character budget.
23
+ - Add trusted global memory capsules and lightweight bilingual trigger recall.
24
+ - Add `/memory list [limit]`.
25
+ - Retain at most 5,000 retrieval audit runs by default.
26
+ - Add repeatable in-memory and WSL-disk performance benchmarks.
27
+
28
+ ## 0.1.0 - 2026-08-14
29
+
30
+ - Initial local SQLite + FTS5 memory plugin.
31
+ - Add CBDC authority decisions, audit records, safe commands, secret rejection,
32
+ automatic extraction, and shadow/assist/enforce modes.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 GIT121995
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,126 @@
1
+ # dsh-memory-gate(记忆闸门)
2
+
3
+ > 前身是 `dsh-memory-cbdc`(v0.1.x);v0.2.0 起更名为 **dsh-memory-gate**,
4
+ > CBDC 保留为机制名(见下)。旧仓库地址仍会重定向到本仓库。
5
+
6
+ DeepSeek Harness 的本地长期记忆插件。它把稳定信息保存为可撤销的
7
+ Claim,并在每次模型调用前执行 CBDC(Claim → Belief → Decision →
8
+ Consumption)门控,避免“检索到”直接等于“注入模型”。
9
+
10
+ 这是社区插件,不属于 DeepSeek 官方项目。许可证为 [MIT](LICENSE)。
11
+
12
+ Lightweight local long-term memory for DeepSeek Harness: SQLite-only,
13
+ cross-session recall, bounded context injection, no extra model call.
14
+
15
+ 当前版本:`0.2.0`。目标 Harness:`0.1.0-rc.6`,Node.js `>=22.5`。
16
+
17
+ ## v1 能力
18
+
19
+ - SQLite + FTS5 本地存储,不调用 embedding 或外部记忆 API。
20
+ - 双通道召回:少量可信全局偏好/约束组成记忆胶囊,其余记忆通过
21
+ 英文词项、中文二元词组、轻量同义线索和标签触发。
22
+ - session、workspace、global 三种作用域;workspace 路径只保存哈希键。
23
+ - 显式 `/memory` 管理命令和保守的中英文自动提取。
24
+ - 可解释的 `use`、`verify`、`ignore` 决策与完整检索/注入审计。
25
+ - `shadow`、`assist`、`enforce` 三种运行模式,默认保守 `assist`。
26
+ - 默认最多注入 3 条、1200 字符;不增加第二次模型调用。
27
+ - API Key、Token、密码和私钥样式内容在落库前拒绝。
28
+ - 数据库或策略异常时不阻断 Agent,只省略本次记忆注入。
29
+
30
+ ## 安装
31
+
32
+ Harness 的插件管理依赖 `pnpm`。
33
+
34
+ Linux / WSL:
35
+
36
+ ```bash
37
+ npm install -g pnpm
38
+ dsh plugin --profile web add dsh-memory-gate
39
+ dsh web --dump-config | sed -n '/memory-gate/,+18p'
40
+ ```
41
+
42
+ Windows PowerShell:
43
+
44
+ ```powershell
45
+ npm install -g pnpm
46
+ dsh plugin --profile web add dsh-memory-gate
47
+ dsh web
48
+ ```
49
+
50
+ 也可以用 Git 地址安装并锁定版本:
51
+
52
+ ```bash
53
+ dsh plugin --profile web add git+https://github.com/GIT121995/dsh-memory-gate.git#v0.2.0
54
+ ```
55
+
56
+ 安装后重启正在运行的 `dsh web`。Bundle 默认写入
57
+ `$DSH_HOME/memory/cbdc.sqlite`(文件名沿用 CBDC 机制名),并以保守 `assist`
58
+ 模式启动。每次模型调用仍只有原来的一次;插件只在本地检索,并把最多 3 条
59
+ 相关记忆放入该次调用的上下文。
60
+
61
+ 在 `$DSH_HOME/profiles/web/cordis.patch.yml` 中持久调整模式时,后置覆盖
62
+ 必须重述该插件拥有的完整配置:
63
+
64
+ ```yaml
65
+ - id: memory-gate
66
+ config:
67
+ databasePath: !!js dshHomePath('memory/cbdc.sqlite')
68
+ mode: assist
69
+ automaticExtraction: true
70
+ candidateLimit: 16
71
+ capsuleLimit: 2
72
+ injectionLimit: 3
73
+ maxInjectionChars: 1200
74
+ auditRetentionRuns: 5000
75
+ minUseBelief: 0.7
76
+ maxUseRisk: 0.45
77
+ harmfulQuarantineThreshold: 2
78
+ freshnessHalfLifeDays: 180
79
+ ```
80
+
81
+ ## 使用
82
+
83
+ ```text
84
+ /memory status
85
+ /memory list 10
86
+ /memory remember --kind preference 我偏好简洁中文回答
87
+ /memory remember --global --kind constraint 不要在回复中暴露凭据
88
+ /memory search 简洁中文
89
+ /memory explain mem_<uuid>
90
+ /memory feedback mem_<uuid> helped
91
+ /memory forget mem_<uuid>
92
+ /memory mode assist
93
+ ```
94
+
95
+ `/memory list` 显示当前 session/workspace/global 作用域内最近的活跃记忆。
96
+ `/memory mode` 只修改当前进程;重启后回到 Profile 配置。`forget` 是可审计
97
+ 的 tombstone,不会物理删除历史记录。
98
+
99
+ 模式语义:
100
+
101
+ - `shadow`:计算并审计,零模型可见注入。
102
+ - `assist`:注入 `use`,并把 `verify` 明确标为待核验线索;默认模式。
103
+ - `enforce`:只注入 `use`,省略 `verify` 和 `ignore`。
104
+
105
+ ## 开发与验证
106
+
107
+ ```bash
108
+ npm install
109
+ npm run check
110
+ npm pack --dry-run
111
+ ```
112
+
113
+ 发布前的三轮基准中位数(Node.js 22.22.1,1001 条合成记忆,每轮 300
114
+ 次查询):WSL 磁盘上的触发检索 p95 `5.343ms`,包含 CBDC 决策和 SQLite
115
+ 审计的完整召回 p95 `11.151ms`,三轮最大观测 p95 `11.663ms`。基准不会
116
+ 访问真实记忆数据库,也不会调用模型,详见
117
+ [性能基准](docs/benchmark.md)。
118
+
119
+ 召回和安全边界见 [架构说明](docs/architecture.md)。
120
+
121
+ ## v1 限制
122
+
123
+ - 轻量同义线索只能覆盖常用表达,不等价于通用语义检索。
124
+ - 自动提取只识别明显的“记住、以后、I prefer、always”等表达,宁缺毋滥。
125
+ - 不回填安装前的历史会话,也不重复保存完整 Harness transcript。
126
+ - Node.js 22 会为内置 `node:sqlite` 打印 experimental warning,不影响运行。
@@ -0,0 +1,14 @@
1
+ - insert:
2
+ - id: memory-gate
3
+ name: dsh-memory-gate
4
+ inject:
5
+ - commands
6
+ config:
7
+ databasePath: !!js dshHomePath('memory/cbdc.sqlite')
8
+ mode: assist
9
+ automaticExtraction: true
10
+ candidateLimit: 16
11
+ capsuleLimit: 2
12
+ injectionLimit: 3
13
+ maxInjectionChars: 1200
14
+ auditRetentionRuns: 5000
@@ -0,0 +1,142 @@
1
+ # dsh-memory-gate v1 详细设计
2
+
3
+ ## 1. 设计目标
4
+
5
+ 插件解决的不是“保存更多聊天记录”,而是让跨会话记忆具备四个独立阶段:
6
+
7
+ 1. **Claim**:从用户明确陈述中形成带作用域、来源和生命周期的主张。
8
+ 2. **Belief**:用 `alpha / (alpha + beta)` 表示当前可用置信度,并累计负面证据。
9
+ 3. **Decision**:结合相关度、新鲜度、置信度和风险,输出 `use/verify/ignore`。
10
+ 4. **Consumption**:人工记录 helped/harmful/stale/conflict,反向更新 Belief。
11
+
12
+ Harness Session 日志仍是会话事实源;插件数据库只是可重建的长期记忆投影和
13
+ 独立审计侧车。卸载插件不会改变 Session 事件格式和可读性。
14
+
15
+ ## 2. 组件与数据流
16
+
17
+ ```text
18
+ user/message ── turn/end ──> conservative extractor ──> secret gate
19
+
20
+ v
21
+ Claim + Evidence
22
+
23
+ first agent/pre-step ── query/scopes ──> FTS + term rank ──┤
24
+ v
25
+ Belief + CBDC decision
26
+ │ │ │
27
+ use verify ignore
28
+ │ │ └─ audit only
29
+ └── mode policy ──> recall message
30
+
31
+ injection audit
32
+
33
+ /memory feedback ──> Consumption + Evidence ──> alpha/beta/harmful_count
34
+ ```
35
+
36
+ 实现模块:
37
+
38
+ - `repository.ts`:迁移、SQLite 表、FTS5、事务、审计和 tombstone。
39
+ - `extractor.ts` / `redaction.ts`:确定性提取与凭据阻断。
40
+ - `authority.ts`:纯函数 CBDC 决策,可独立测试。
41
+ - `service.ts`:作用域检索、排序、模式策略、注入文本装配。
42
+ - `harness.ts`:唯一 Harness 适配层,监听 `session/event` 和
43
+ `agent/pre-step`。
44
+ - `commands.ts`:唯一的人类控制入口。
45
+
46
+ ## 3. 数据模型
47
+
48
+ ### claims
49
+
50
+ 核心字段为:`id`、`scope`、`scope_key`、`kind`、`content`、`tags_json`、
51
+ `state`、`origin`、`sensitivity`、`content_hash`、来源 Session/Event、有效期和
52
+ 时间戳。`state=tombstoned` 后永不参与检索。
53
+
54
+ 作用域键:
55
+
56
+ - session:`session:<session-id>`;
57
+ - workspace:`workspace:<canonical-path-sha256-prefix>`,不保存原路径;
58
+ - global:固定为 `global`,只允许显式创建。
59
+
60
+ ### evidence / beliefs
61
+
62
+ 新显式 Claim 从 `alpha=6, beta=1` 开始;启发式 Claim 从 `4,2` 开始,默认
63
+ 不足以直接 `use`。反馈增量为:helped `+alpha 1`,harmful `+beta 5` 且
64
+ `harmful_count +1`,stale `+beta 2`,conflict `+beta 4`,unknown 不改变
65
+ Belief。每次非 unknown 更新同时写 Evidence。
66
+
67
+ ### audit tables
68
+
69
+ - `retrieval_runs`:查询哈希、Session、workspace 和候选数量,不复制原始提示;
70
+ - `authority_decisions`:每个候选的动作、理由码和四项得分;
71
+ - `injections`:实际进入上下文的 Claim ID 与生成消息 ID;
72
+ - `consumption`:人工结果与可选说明。
73
+
74
+ 数据库使用 `PRAGMA user_version=1` 做幂等迁移,写入用同步短事务。文件目录
75
+ 权限创建为 `0700`;SQLite WAL 只用于磁盘数据库。
76
+
77
+ ## 4. 检索与 CBDC 决策
78
+
79
+ 召回分成两个本地通道:
80
+
81
+ - capsule:最多 2 条可信的 explicit global preference/constraint,不要求当前
82
+ 查询复述关键词;
83
+ - trigger:查询当前 session、当前 workspace 和 explicit global,先限制最多
84
+ 500 条活跃 Claim,再结合 FTS5、英文词项、中文二元词组、常用同义线索和
85
+ 标签重排。
86
+
87
+ 两个通道按 Claim ID 合并后统一进入 CBDC。最终排序权重:
88
+
89
+ ```text
90
+ rank = lexical × 0.62 + belief × 0.23 + freshness × 0.15 + scope boost + capsule boost
91
+ ```
92
+
93
+ 决策优先级:
94
+
95
+ 1. 非 active → `ignore`;
96
+ 2. 已过期 → `verify`;
97
+ 3. `harmful_count` 达隔离阈值 → `ignore`;
98
+ 4. 相关度低于 0.12 → `ignore`;
99
+ 5. 新鲜度低于 0.2 → `verify`;
100
+ 6. Belief 低于配置阈值或 Risk 高于阈值 → `verify`;
101
+ 7. 其余 → `use`。
102
+
103
+ Risk 基线按 Claim kind 区分,再叠加置信度不确定性和 harmful 历史。每项阈值
104
+ 均在插件配置中,不依赖隐藏环境变量。
105
+
106
+ ## 5. Harness 集成
107
+
108
+ 自动提取只消费 `source.kind=user` 的 `user/message`,在匹配的 `turn/end` 后
109
+ 写入,绝不学习 assistant、tool 或插件生成消息。恢复时的 seed 事件不会重复
110
+ 发布,因此不会重复提取历史。
111
+
112
+ 召回监听 `agent/pre-step`,调用下游 `next()` 后只在第一步、未取消、存在真实
113
+ 人类消息时运行。召回内容用 `createUserMessage` 生成:
114
+
115
+ ```ts
116
+ source: { kind: 'plugin', plugin: 'dsh-memory-gate', form: 'recall' }
117
+ ```
118
+
119
+ 注入文本声明其是用户记忆而非系统指令,并转义尖括号。任何检索、策略、审计
120
+ 或数据库异常都返回原消息数组,保证 Agent fail-open。数据库在启动时无法打开
121
+ 时,插件只注册一个 unavailable 状态命令,不注册提取或注入监听器,Harness
122
+ 仍可正常启动。
123
+
124
+ ## 6. 安全、隐私与运维
125
+
126
+ - 存储前检查常见 API Key、GitHub/AWS Token、Bearer、密码赋值和私钥头;
127
+ - `/memory` 设置 `recordInput=false`,避免把管理命令原文复制进 Session 的
128
+ command lifecycle;
129
+ - `forget` 只做 tombstone;v1 不提供不可恢复的 hard delete;
130
+ - 默认 assist,但限制最多 3 条、1200 字符;需要零模型可见影响时可切回 shadow;
131
+ - 只保留最近 5000 次 retrieval run 的决策和注入审计,Claim、Evidence、
132
+ Consumption 不会被自动删除;
133
+ - 数据库可以随插件停机备份,恢复时同时保留 `-wal/-shm` 或先正常停机。
134
+
135
+ ## 7. 故障边界与后续版本
136
+
137
+ v1.1 不包含向量服务、LLM 抽取器、历史回填、浏览器管理 UI 或自动 outcome
138
+ 归因。词法召回不足时,后续可以在 Repository 之上增加可选 embedding 索引,
139
+ 但 Claim、Belief、Decision 和 Consumption 仍保持同一权威模型。
140
+
141
+ 升级时只允许顺序增加 `PRAGMA user_version` migration;不得就地重写旧
142
+ Evidence 或删除 tombstone。Harness RC API 若变化,仅修改 `harness.ts` 适配层。
@@ -0,0 +1,41 @@
1
+ # Performance Benchmark
2
+
3
+ The benchmark is deterministic, local, and does not read the user's memory
4
+ database or call a model. Each of three runs creates 1,001 synthetic claims
5
+ and executes 300 mixed Chinese/English queries after warm-up. The report uses
6
+ the median metric across the three runs and also records the maximum observed
7
+ p95.
8
+
9
+ Run it with:
10
+
11
+ ```bash
12
+ npm run benchmark
13
+ ```
14
+
15
+ The script measures both an in-memory SQLite database and a temporary database
16
+ on the WSL filesystem. The pass threshold is 25 ms p95 for the complete recall
17
+ path, including trigger search, capsule merge, CBDC decisions, and audit writes.
18
+
19
+ ## Representative Result
20
+
21
+ Environment: WSL, Node.js 22.22.1, 2026-08-14.
22
+
23
+ | Storage/path | mean | p50 | p95 | p99 |
24
+ |---|---:|---:|---:|---:|
25
+ | v1 baseline trigger search, memory | 2.445 ms | 2.151 ms | 3.657 ms | 4.076 ms |
26
+ | v1.1 trigger search, memory | 4.097 ms | 3.907 ms | 5.198 ms | 5.669 ms |
27
+ | v1.1 full recall + audit, memory | 4.126 ms | 3.885 ms | 5.478 ms | 5.972 ms |
28
+ | v1.1 trigger search, WSL disk | 4.208 ms | 4.015 ms | 5.343 ms | 5.859 ms |
29
+ | v1.1 full recall + audit, WSL disk | 8.801 ms | 8.512 ms | 11.151 ms | 13.701 ms |
30
+
31
+ The maximum observed WSL-disk full-recall p95 across the three runs was
32
+ 11.663 ms. Both quality probes passed: a lightweight Chinese synonym query found the
33
+ expected memory, and an unrelated query still received the trusted global
34
+ preference through the bounded memory capsule.
35
+
36
+ ## Interpretation
37
+
38
+ Dual-channel matching adds about 2 ms p95 to the in-memory trigger search in
39
+ this workload. The realistic WSL-disk full path remains around 11 ms p95, far
40
+ smaller than normal model latency. Results vary by hardware and filesystem, so
41
+ the checked-in script is the source of truth rather than this single run.
@@ -0,0 +1,9 @@
1
+ import type { AuthorityDecision, SearchCandidate } from './contracts.js';
2
+ export interface AuthorityPolicy {
3
+ minUseBelief: number;
4
+ maxUseRisk: number;
5
+ harmfulQuarantineThreshold: number;
6
+ freshnessHalfLifeDays: number;
7
+ }
8
+ export declare function decideAuthority(candidate: SearchCandidate, policy: AuthorityPolicy, now?: number): AuthorityDecision;
9
+ //# sourceMappingURL=authority.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authority.d.ts","sourceRoot":"","sources":["../src/authority.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAExE,MAAM,WAAW,eAAe;IAC9B,YAAY,EAAE,MAAM,CAAA;IACpB,UAAU,EAAE,MAAM,CAAA;IAClB,0BAA0B,EAAE,MAAM,CAAA;IAClC,qBAAqB,EAAE,MAAM,CAAA;CAC9B;AAED,wBAAgB,eAAe,CAC7B,SAAS,EAAE,eAAe,EAC1B,MAAM,EAAE,eAAe,EACvB,GAAG,SAAa,GACf,iBAAiB,CAmDnB"}
@@ -0,0 +1,71 @@
1
+ export function decideAuthority(candidate, policy, now = Date.now()) {
2
+ const { claim, belief } = candidate;
3
+ const beliefScore = clamp(belief.alpha / Math.max(1, belief.alpha + belief.beta));
4
+ const relevanceScore = clamp(candidate.lexicalScore);
5
+ const ageDays = Math.max(0, now - claim.updatedAt) / 86_400_000;
6
+ const freshnessScore = clamp(2 ** (-ageDays / policy.freshnessHalfLifeDays));
7
+ const riskScore = clamp(baseRisk(claim.kind) + (1 - beliefScore) * 0.3 + Math.min(0.3, belief.harmfulCount * 0.15));
8
+ const reasonCodes = [];
9
+ if (candidate.recallChannel === 'capsule')
10
+ reasonCodes.push('trusted_global_capsule');
11
+ if (claim.state !== 'active') {
12
+ reasonCodes.push('claim_not_active');
13
+ return make('ignore');
14
+ }
15
+ if (claim.validUntil !== undefined && claim.validUntil <= now) {
16
+ reasonCodes.push('claim_expired');
17
+ return make('verify');
18
+ }
19
+ if (belief.harmfulCount >= policy.harmfulQuarantineThreshold) {
20
+ reasonCodes.push('harmful_quarantine');
21
+ return make('ignore');
22
+ }
23
+ if (relevanceScore < 0.12) {
24
+ reasonCodes.push('low_relevance');
25
+ return make('ignore');
26
+ }
27
+ if (freshnessScore < 0.2) {
28
+ reasonCodes.push('stale_memory');
29
+ return make('verify');
30
+ }
31
+ if (beliefScore < policy.minUseBelief)
32
+ reasonCodes.push('belief_below_use_threshold');
33
+ if (riskScore > policy.maxUseRisk)
34
+ reasonCodes.push('risk_above_use_threshold');
35
+ if (claim.origin === 'heuristic')
36
+ reasonCodes.push('heuristic_origin');
37
+ if (reasonCodes.includes('belief_below_use_threshold') || reasonCodes.includes('risk_above_use_threshold')) {
38
+ return make('verify');
39
+ }
40
+ reasonCodes.push('authority_thresholds_passed');
41
+ return make('use');
42
+ function make(action) {
43
+ return {
44
+ claimId: claim.id,
45
+ action,
46
+ reasonCodes,
47
+ beliefScore,
48
+ relevanceScore,
49
+ freshnessScore,
50
+ riskScore,
51
+ };
52
+ }
53
+ }
54
+ function baseRisk(kind) {
55
+ switch (kind) {
56
+ case 'preference':
57
+ return 0.12;
58
+ case 'fact':
59
+ return 0.2;
60
+ case 'procedure':
61
+ return 0.28;
62
+ case 'constraint':
63
+ return 0.34;
64
+ case 'warning':
65
+ return 0.4;
66
+ }
67
+ }
68
+ function clamp(value) {
69
+ return Math.max(0, Math.min(1, value));
70
+ }
71
+ //# sourceMappingURL=authority.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authority.js","sourceRoot":"","sources":["../src/authority.ts"],"names":[],"mappings":"AASA,MAAM,UAAU,eAAe,CAC7B,SAA0B,EAC1B,MAAuB,EACv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QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,YAAY;YACf,OAAO,IAAI,CAAA;QACb,KAAK,MAAM;YACT,OAAO,GAAG,CAAA;QACZ,KAAK,WAAW;YACd,OAAO,IAAI,CAAA;QACb,KAAK,YAAY;YACf,OAAO,IAAI,CAAA;QACb,KAAK,SAAS;YACZ,OAAO,GAAG,CAAA;IACd,CAAC;AACH,CAAC;AAED,SAAS,KAAK,CAAC,KAAa;IAC1B,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAA;AACxC,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { Agent } from '@deepseek-ai/dsh-agent';
2
+ import type { CommandResult, CommandRuntime } from '@deepseek-ai/dsh-commands';
3
+ import { MemoryService } from './service.js';
4
+ export declare function registerMemoryCommand(commands: CommandRuntime, service: MemoryService): () => void;
5
+ export declare function registerUnavailableMemoryCommand(commands: CommandRuntime): () => void;
6
+ export declare function executeMemoryCommand(service: MemoryService, agent: Agent, rawInput: string): CommandResult;
7
+ //# sourceMappingURL=commands.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commands.d.ts","sourceRoot":"","sources":["../src/commands.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAA;AACnD,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAI9E,OAAO,EAAE,aAAa,EAAmC,MAAM,cAAc,CAAA;AAa7E,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,cAAc,EAAE,OAAO,EAAE,aAAa,GAAG,MAAM,IAAI,CAQlG;AAED,wBAAgB,gCAAgC,CAAC,QAAQ,EAAE,cAAc,GAAG,MAAM,IAAI,CAarF;AAED,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,GAAG,aAAa,CAiH1G"}