dsh-cortex-memory 0.3.0 → 0.4.11
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/README.md +41 -12
- package/client.js +33 -19
- package/cordis.patch.yml +1 -1
- package/index.js +8 -1
- package/package.json +3 -13
- package/src/adapters/shiori.js +1 -1
- package/src/api/routes.js +30 -3
- package/src/core/config.js +6 -0
- package/src/engines/develop.js +1 -1
- package/src/engines/extract.js +23 -4
- package/src/engines/growth.js +1 -1
- package/src/engines/life.js +57 -42
- package/src/engines/reflect.js +1 -1
- package/src/engines/retrieve.js +4 -0
- package/src/guardian/guardian.js +15 -1
- package/src/host/runtime.js +14 -4
- package/src/host/scheduler.js +11 -2
- package/src/llm/adapter.js +19 -7
- package/src/memory/query.js +1 -1
- package/src/self/appraisal.js +3 -3
- package/src/self/emotion.js +1 -1
- package/src/self/evolution.js +115 -4
- package/src/self/identity.js +1 -1
- package/src/self/policies.js +8 -1
- package/src/self/relationship.js +2 -2
- package/src/service/cortex.js +94 -13
- package/src/tools/definitions.js +19 -1
- package/src/web/search.js +97 -0
- package/bench/ab-engine.mjs +0 -60
- package/bench/ann-bench.mjs +0 -78
- package/bench/hnsw-bench.mjs +0 -79
- package/bench/locomo.js +0 -89
- package/bench/longmemeval.js +0 -83
- package/bench/metrics.js +0 -67
- package/bench/migration-bench.mjs +0 -69
- package/bench/run.js +0 -77
- package/bench/synthetic.js +0 -99
- package/bench/vector-ab.mjs +0 -76
- package/docs/install-windows.md +0 -144
- package/docs/models.md +0 -183
- package/docs/multimodal.md +0 -112
- package/docs/permissions.md +0 -49
- package/docs/privacy.md +0 -48
- package/docs/scopes.md +0 -142
- package/examples/README.md +0 -72
- package/examples/setup-cortex-bge.ps1 +0 -66
- package/examples/uninstall-cortex.ps1 +0 -91
package/docs/models.md
DELETED
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
# 可选模型:embedder / rerank
|
|
2
|
-
|
|
3
|
-
> 结论先说:**安装包不自动下载模型,也不默认联网。**
|
|
4
|
-
> 大模型动辄几百 MB,自动下载会把“装插件”变成“装模型”,还可能带来磁盘、网络、校验和更新问题。
|
|
5
|
-
> 本插件只提供可插拔接口;用户显式配置后才使用。
|
|
6
|
-
|
|
7
|
-
## 0. 当前接线状态(2026-11-11)
|
|
8
|
-
|
|
9
|
-
- HTTP rerank:**已接到 QA**(`cortex_qa`),默认关,失败开放。
|
|
10
|
-
- HTTP embedder:**接口已实现**(`createOpenAIEmbedder`);**异步索引入口** `POST /vector/index` / `POST /vector/rebuild` 已可用,写不会被网络阻塞;**异步混合检索** `GET /search?async=true` 与 QA 已走 `searchAsync`(远程向量可参与);默认同步 `/search` 仍不等待网络。
|
|
11
|
-
- 安装包**不自动下载**任何模型。
|
|
12
|
-
|
|
13
|
-
## 1. 默认路径(零依赖)
|
|
14
|
-
|
|
15
|
-
- `features.vector = false`:不用向量,FTS5 + 图 + recent 融合。
|
|
16
|
-
- `features.vector = true`:使用内置 `hash-256` embedder(词法哈希,**不是语义模型**)。
|
|
17
|
-
- 不下载任何文件;不需要 `node_modules`;Windows 直接可用。
|
|
18
|
-
|
|
19
|
-
## 2. 可选 HTTP embedder
|
|
20
|
-
|
|
21
|
-
代码:`src/vector/providers.js` 的 `createOpenAIEmbedder`。
|
|
22
|
-
|
|
23
|
-
接口是 OpenAI-compatible `/embeddings`:
|
|
24
|
-
|
|
25
|
-
```http
|
|
26
|
-
POST {baseUrl}/embeddings
|
|
27
|
-
Authorization: Bearer <apiKey>
|
|
28
|
-
{"model":"bge-m3","input":["文本"]}
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
返回:
|
|
32
|
-
|
|
33
|
-
```json
|
|
34
|
-
{"data":[{"embedding":[0.1,0.2]}]}
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
它不会在安装时运行。要接本地服务(如 Xinference / Ollama 的 OpenAI 兼容层 / vLLM),由用户自己启动服务并提供 `baseUrl`。
|
|
38
|
-
**不要把 API key 写进仓库或安装包。**
|
|
39
|
-
|
|
40
|
-
## 2.1 本地 bge 可选配置(默认关)
|
|
41
|
-
|
|
42
|
-
本机实测用 Ollama 的 `bge-m3`(1024 维)通过 OpenAI 兼容 `/v1/embeddings` 接入。
|
|
43
|
-
|
|
44
|
-
### profile 配置
|
|
45
|
-
|
|
46
|
-
```yaml
|
|
47
|
-
- id: cortex
|
|
48
|
-
name: dsh-cortex
|
|
49
|
-
config:
|
|
50
|
-
features:
|
|
51
|
-
vector: true
|
|
52
|
-
# dataRoot / dbFile 按你的 profile 配
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
### 模型配置
|
|
56
|
-
|
|
57
|
-
在 cortex 的 dataRoot 下放 `model-config.json`(可在面板模型设置里保存,效果相同):
|
|
58
|
-
|
|
59
|
-
```json
|
|
60
|
-
{
|
|
61
|
-
"embedding": {
|
|
62
|
-
"mode": "local",
|
|
63
|
-
"baseUrl": "http://127.0.0.1:11434/v1",
|
|
64
|
-
"model": "bge-m3",
|
|
65
|
-
"dim": 1024,
|
|
66
|
-
"apiKey": ""
|
|
67
|
-
},
|
|
68
|
-
"rerank": {
|
|
69
|
-
"enabled": false,
|
|
70
|
-
"baseUrl": "",
|
|
71
|
-
"model": "",
|
|
72
|
-
"apiKey": ""
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
- `mode: local` 表示本地 keyless 服务;不要把云端 key 写进仓库。
|
|
78
|
-
- 不配模型时,`features.vector=true` 只会用内置 `hash-256` 词法哈希,**不是语义模型**。
|
|
79
|
-
- 向量索引是暴力扫描,适合个人千条级记忆;不是十亿级 ANN。
|
|
80
|
-
|
|
81
|
-
### 实测代价(2026-11-11,300 traces / 50 paraphrase queries)
|
|
82
|
-
|
|
83
|
-
```text
|
|
84
|
-
FTS: hit 0.96 / MRR 0.694 / nDCG 0.603 / p50 4.5-4.8ms
|
|
85
|
-
bge: hit 1.00 / MRR 0.960 / nDCG 0.883 / p50 51-63ms
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
- 语义召回明显提升,但查询延迟约 10 倍。
|
|
89
|
-
- 这是合成 paraphrase,不是 LoCoMo;不能当公开 SOTA。
|
|
90
|
-
- 默认仍关闭;没有本地模型/服务就不要开。
|
|
91
|
-
|
|
92
|
-
## 2.2 可选 ANN(默认关)
|
|
93
|
-
|
|
94
|
-
```yaml
|
|
95
|
-
features:
|
|
96
|
-
vector: true
|
|
97
|
-
vectorAnn: true
|
|
98
|
-
vectorAnnMin: 20000
|
|
99
|
-
vectorAnnEngine: hnsw
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
- 复用 `src/vector/ann.js` 的单层 NSW 索引;纯 JS,无原生依赖。
|
|
103
|
-
- 小于 `vectorAnnMin` 时仍走暴力精确扫描。
|
|
104
|
-
- ANN 命中不足 5 条时自动回退暴力扫描,避免 scope/过滤把结果卡空。
|
|
105
|
-
- 首次搜索从 embeddings 懒构建;写入/删除会同步索引。
|
|
106
|
-
- 默认 `vectorAnn: false`;不开启时行为不变。
|
|
107
|
-
- 当前验证是单元/小规模,不是 100k ANN 压测;大库收益和召回还需单独 benchmark。
|
|
108
|
-
- 5000 条 A/B 结论(dim 64):ANN ef=120 recall@10 0.29,ef=400 0.70(p50 0.99ms,暴力 1.11ms),ef=800 0.93(p50 2.73ms,暴力 1.16ms),ef=1600 0.998(p50 11ms)。**小库暴力反而更快**,所以默认阈值放在 20000,且 ANN 默认关。
|
|
109
|
-
- 20k / 100k 复验(ef=800/1600):20k recall 0.591(ANN p50 5.4ms,暴力 9.2ms);100k recall 0.413(ANN p50 10.9ms,暴力 38.9ms,构建约 101s)。
|
|
110
|
-
- HNSW 候选(`src/vector/hnsw.js`,二叉堆版)在 5k/20k 的质量:
|
|
111
|
-
- 5k:recall 0.997,build 5.5s,p50 2.24ms(暴力 1.15ms)
|
|
112
|
-
- 20k:recall 0.956,build 58.4s,p50 4.88ms(暴力 5.78ms)
|
|
113
|
-
- 所以 `vectorAnnEngine: hnsw` 已接到可选路径,但 **`vectorAnn` 仍默认关**;HNSW 冷构建慢,20k 以下没明显查询优势。
|
|
114
|
-
- 旧 NSW 保留为 `vectorAnnEngine: nsw` 的兼容选项,不再是默认引擎。
|
|
115
|
-
- 100k 构建/内存尚未验证;不建议在生产库直接开。
|
|
116
|
-
|
|
117
|
-
### 外置 ANN(默认关)
|
|
118
|
-
|
|
119
|
-
```yaml
|
|
120
|
-
features:
|
|
121
|
-
vector: true
|
|
122
|
-
vectorAnnExternal: true
|
|
123
|
-
vectorAnnEndpoint: 'http://127.0.0.1:8765/search'
|
|
124
|
-
vectorAnnTimeoutMs: 800
|
|
125
|
-
```
|
|
126
|
-
|
|
127
|
-
- 只接 `searchAsync` 异步路径;同步 `search` 继续精确扫描。
|
|
128
|
-
- 端点为空或请求失败 → 回退精确扫描,不丢召回。
|
|
129
|
-
- 客户端契约见 `docs/external-ann.md`。
|
|
130
|
-
- **需要你手动启动本地 ANN 服务**;当前没有常驻服务。
|
|
131
|
-
- 20k 端到端验证:recall@10 1.0,p50 20.3-20.8ms(HTTP 客户端 + HNSW 服务)。
|
|
132
|
-
|
|
133
|
-
## 3. 可选 HTTP rerank(已接到 QA)
|
|
134
|
-
|
|
135
|
-
代码:`createHttpReranker`,已在 `cortex_qa` 的检索结果上生效(失败开放,回退融合顺序)。
|
|
136
|
-
|
|
137
|
-
配置:
|
|
138
|
-
|
|
139
|
-
```yaml
|
|
140
|
-
- id: cortex
|
|
141
|
-
name: dsh-cortex
|
|
142
|
-
config:
|
|
143
|
-
rerankEnabled: true
|
|
144
|
-
rerankBaseUrl: "http://127.0.0.1:9000/v1"
|
|
145
|
-
rerankModel: "bge-reranker-base"
|
|
146
|
-
# rerankApiKey: "" # 本机服务通常不需要
|
|
147
|
-
```
|
|
148
|
-
|
|
149
|
-
接口:
|
|
150
|
-
|
|
151
|
-
```http
|
|
152
|
-
POST {baseUrl}/rerank
|
|
153
|
-
{"model":"bge-reranker-base","query":"...","documents":["..."],"top_n":8}
|
|
154
|
-
```
|
|
155
|
-
|
|
156
|
-
返回 `results: [{index, relevance_score}]`。
|
|
157
|
-
|
|
158
|
-
默认关;没有配置或请求失败时,QA 保持原来的 RRF 顺序,不阻塞回答。
|
|
159
|
-
|
|
160
|
-
## 4. 本地 ONNX 模型(未内置)
|
|
161
|
-
|
|
162
|
-
本鲸没有把 `onnxruntime-node` 或 `@huggingface/transformers` 放进运行时依赖,原因:
|
|
163
|
-
|
|
164
|
-
- 安装体积大(数百 MB);
|
|
165
|
-
- Windows 上原生二进制/驱动差异;
|
|
166
|
-
- 安装期下载模型不可审计。
|
|
167
|
-
|
|
168
|
-
后续如果要内置,应该是**单独的 optional 包**,并满足:
|
|
169
|
-
|
|
170
|
-
1. 用户显式点“下载模型”;
|
|
171
|
-
2. 显示 URL、大小、SHA-256;
|
|
172
|
-
3. 下载到 `~/.dsh/cortex/models/`,不写 profile;
|
|
173
|
-
4. 失败开放,不影响 FTS;
|
|
174
|
-
5. 可一键删除。
|
|
175
|
-
|
|
176
|
-
## 5. 安装包里有什么
|
|
177
|
-
|
|
178
|
-
- 没有模型文件;
|
|
179
|
-
- 没有原生 `.node`;
|
|
180
|
-
- 没有 `node_modules`;
|
|
181
|
-
- 只有纯 JS + SQL + 文档。
|
|
182
|
-
|
|
183
|
-
所以 Windows 用户装完即可用;要用语义模型时再按上面的配置接服务。
|
package/docs/multimodal.md
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
# 多模态附件:只存引用,不存字节
|
|
2
|
-
|
|
3
|
-
> 当前实现是**元数据边界**,不是视觉/音频理解模型。
|
|
4
|
-
|
|
5
|
-
## 1. 写入
|
|
6
|
-
|
|
7
|
-
`cortex_write` / `POST /api/cortex/write` 支持 `attachments`:
|
|
8
|
-
|
|
9
|
-
```json
|
|
10
|
-
{
|
|
11
|
-
"text": "用户发来一张示例图片。",
|
|
12
|
-
"explicit": true,
|
|
13
|
-
"attachments": [
|
|
14
|
-
{
|
|
15
|
-
"kind": "image",
|
|
16
|
-
"uri": "https://example.test/rice.png",
|
|
17
|
-
"name": "rice.png",
|
|
18
|
-
"mime": "image/png",
|
|
19
|
-
"bytes": 12345,
|
|
20
|
-
"sha256": "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
|
|
21
|
-
}
|
|
22
|
-
]
|
|
23
|
-
}
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
约束:
|
|
27
|
-
|
|
28
|
-
- 最多 8 个
|
|
29
|
-
- `kind`: image / audio / video / file
|
|
30
|
-
- `uri` 必填,最长 2000
|
|
31
|
-
- `sha256` 必须是 64 位 hex
|
|
32
|
-
- `bytes` 0..1e9
|
|
33
|
-
- **不读取、不下载、不解析 URI**
|
|
34
|
-
- 不把二进制写进 SQLite
|
|
35
|
-
|
|
36
|
-
## 2. 存储
|
|
37
|
-
|
|
38
|
-
落在 `traces.metadata_json.attachments`:
|
|
39
|
-
|
|
40
|
-
```json
|
|
41
|
-
{
|
|
42
|
-
"attachments": [
|
|
43
|
-
{"kind": "image", "uri": "https://example.test/rice.png", "mime": "image/png", "bytes": 12345}
|
|
44
|
-
]
|
|
45
|
-
}
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
没有单独附件表,也没有内容寻址存储。旧库会通过 `ensureTraceColumns` 自动补 `metadata_json` 列,默认 `{}`。
|
|
49
|
-
|
|
50
|
-
## 3. 当前能做什么
|
|
51
|
-
|
|
52
|
-
- 记录“这条记忆关联了哪些附件”的引用
|
|
53
|
-
- 在 trace 读取时返回 metadata
|
|
54
|
-
- 在写入结果里报告附件数量
|
|
55
|
-
- 为未来的视觉/音频模型留出入口
|
|
56
|
-
|
|
57
|
-
## 4. 当前不能做什么
|
|
58
|
-
|
|
59
|
-
- 不能读取图片/音频内容
|
|
60
|
-
- 不能生成缩略图
|
|
61
|
-
- 不能做 OCR / 语音转写
|
|
62
|
-
- 不能校验 URI 指向的内容
|
|
63
|
-
- 不能防止恶意 URI(调用方自己负责)
|
|
64
|
-
- 不能自动下载模型
|
|
65
|
-
|
|
66
|
-
## 5. 安全边界
|
|
67
|
-
|
|
68
|
-
- 附件只是引用,不是可信内容
|
|
69
|
-
- 不要把私密 URL、token、签名参数写进 uri
|
|
70
|
-
- 隐私删除 trace 时,metadata 随 trace 一起离开;外部 URI 上的文件不在 cortex 控制内
|
|
71
|
-
- 导出 Markdown 是否包含附件元数据,后续再定
|
|
72
|
-
|
|
73
|
-
## 5.1 可选本地读取器(默认关)
|
|
74
|
-
|
|
75
|
-
```yaml
|
|
76
|
-
features:
|
|
77
|
-
attachmentReader: true
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
```http
|
|
81
|
-
POST /api/cortex/attachments/inspect
|
|
82
|
-
{"uri":"file:///C:/path/rice.txt"}
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
- **只接受 `file://`**
|
|
86
|
-
- 只返回 name/bytes/mtime/sha256
|
|
87
|
-
- 不返回文件内容
|
|
88
|
-
- 最大 50MB
|
|
89
|
-
- 默认关;未开启 403
|
|
90
|
-
- 写入 audit:`attachment.inspect`
|
|
91
|
-
|
|
92
|
-
这不是 OCR/转写。它只做本地文件元数据与哈希校验,方便把附件引用和实际文件对上。
|
|
93
|
-
|
|
94
|
-
## 5.2 提取器联动(可选)
|
|
95
|
-
|
|
96
|
-
独立包 `dsh-cortex-extractors` 的 `cortex_extract_text` 支持显式 `traceId`:
|
|
97
|
-
|
|
98
|
-
```json
|
|
99
|
-
{"uri":"file:///C:/tmp/frame.png","mode":"ocr","traceId":"trc_target"}
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
- 主脑写入一条 **派生 trace**(不修改原 trace)
|
|
103
|
-
- metadata 保留 `derivedFrom`、URI、mode、engine
|
|
104
|
-
- 需要提取器与主脑同时启用
|
|
105
|
-
- 不传 `traceId` 时仍只返回文字,不写记忆
|
|
106
|
-
|
|
107
|
-
## 6. 下一步
|
|
108
|
-
|
|
109
|
-
1. 可选附件读取器接口(本地、显式开启)
|
|
110
|
-
2. 图片缩略图/OCR 作为独立可选包
|
|
111
|
-
3. 附件级删除/保留策略
|
|
112
|
-
4. 与 bge 一样:默认关,失败开放,不自动下载模型
|
package/docs/permissions.md
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
# Permissions and scopes
|
|
2
|
-
|
|
3
|
-
Cortex is local-first. The defaults are intentionally conservative.
|
|
4
|
-
|
|
5
|
-
## Local API
|
|
6
|
-
|
|
7
|
-
- The API is loopback-only by default.
|
|
8
|
-
- Requests carry a local token; cross-origin and unsafe POSTs are rejected.
|
|
9
|
-
- `POST /permissions` requires `confirm: true`; a permission change writes a local override and takes effect after a DSH restart.
|
|
10
|
-
- `POST /permissions/rollback` removes the override and also takes effect after restart.
|
|
11
|
-
|
|
12
|
-
## Scopes
|
|
13
|
-
|
|
14
|
-
- Every trace, fact, relation, goal and working item has a scope.
|
|
15
|
-
- The global scope is writable by default; shared scopes may be read-only.
|
|
16
|
-
- Scope resolution order is header, then query, then body, then the server default.
|
|
17
|
-
- A write to a read-only scope is refused; it is not silently redirected.
|
|
18
|
-
|
|
19
|
-
## Shared write grants
|
|
20
|
-
|
|
21
|
-
- Shared write grants are for API clients that send `x-cortex-agent`.
|
|
22
|
-
- A grant is a `scope:agent` pair, with an optional expiry.
|
|
23
|
-
- Revoke takes effect immediately; the tool path does not send an agent header.
|
|
24
|
-
- The grant list is visible in the Settings tab.
|
|
25
|
-
|
|
26
|
-
## Network permissions
|
|
27
|
-
|
|
28
|
-
- `llm`: allow the configured model service for QA, consolidation or extraction facts.
|
|
29
|
-
- `embed`: allow remote embedding; local embeddings remain available.
|
|
30
|
-
- `rerank`: allow remote reranking.
|
|
31
|
-
- `vector`: enable vector indexing/search.
|
|
32
|
-
- If a provider fails or a permission is off, Cortex falls back to non-vector or evidence-only paths instead of inventing data.
|
|
33
|
-
|
|
34
|
-
## Feature flags
|
|
35
|
-
|
|
36
|
-
Feature flags and metrics on the Settings page are a read-only snapshot. Permission buttons are the writable part; they always show a confirmation and a restart notice.
|
|
37
|
-
|
|
38
|
-
## Audit and rollback
|
|
39
|
-
|
|
40
|
-
- Writes, merges, forgets, permission changes and guardian operations append to the audit ledger.
|
|
41
|
-
- `cortex_guard` can back up, validate, export and restore.
|
|
42
|
-
- Delete is a privacy cascade; the event ledger keeps only a content hash.
|
|
43
|
-
- A bad permission override can be removed with the rollback button.
|
|
44
|
-
|
|
45
|
-
## What Cortex does not do
|
|
46
|
-
|
|
47
|
-
- It does not read arbitrary files just because they are on disk.
|
|
48
|
-
- It does not send memories to a model unless the corresponding permission and provider are configured.
|
|
49
|
-
- It does not store API keys or passwords in memory.
|
package/docs/privacy.md
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
# Privacy notes
|
|
2
|
-
|
|
3
|
-
## Where data lives
|
|
4
|
-
|
|
5
|
-
Default data root:
|
|
6
|
-
|
|
7
|
-
```text
|
|
8
|
-
~/.dsh/cortex/
|
|
9
|
-
cortex.sqlite
|
|
10
|
-
backups/
|
|
11
|
-
vector/
|
|
12
|
-
```
|
|
13
|
-
|
|
14
|
-
The exact paths are shown in the Settings tab. This data stays on the machine unless the user configures a remote provider or moves it.
|
|
15
|
-
|
|
16
|
-
## What is stored
|
|
17
|
-
|
|
18
|
-
- traces (episodic, semantic, reflective, derived)
|
|
19
|
-
- facts and graph edges
|
|
20
|
-
- working memory, goals, playbook rules
|
|
21
|
-
- audit events
|
|
22
|
-
- emotional appraisals and relationship state
|
|
23
|
-
- optional derived text from local OCR/ASR, with source URI and engine metadata
|
|
24
|
-
|
|
25
|
-
## What is not stored
|
|
26
|
-
|
|
27
|
-
- API keys, tokens or passwords
|
|
28
|
-
- raw model files
|
|
29
|
-
- the contents of arbitrary local files that were not explicitly passed to an extraction tool
|
|
30
|
-
- a copy of a deleted trace's body (delete cascades; the ledger keeps a content hash)
|
|
31
|
-
|
|
32
|
-
## Deletion and export
|
|
33
|
-
|
|
34
|
-
- `cortex_forget` archive keeps a trace recoverable; delete removes it and its derived data.
|
|
35
|
-
- `cortex_guard export` writes a Markdown mirror for inspection.
|
|
36
|
-
- `cortex_guard backup` creates a SQLite backup; validate a backup before restoring.
|
|
37
|
-
- Attachments are metadata references; the default attachment reader is disabled.
|
|
38
|
-
|
|
39
|
-
## OCR / ASR
|
|
40
|
-
|
|
41
|
-
- Extraction is explicit: a `file://` URI and a configured local engine.
|
|
42
|
-
- The extractor never downloads a model automatically.
|
|
43
|
-
- Extracted text is written as a **derived trace**; the target trace is unchanged.
|
|
44
|
-
- PaddleOCR/Tesseract/Whisper models are local files owned by the user.
|
|
45
|
-
|
|
46
|
-
## Cloud / network
|
|
47
|
-
|
|
48
|
-
Remote LLM, embedding and rerank calls are off unless explicitly enabled and configured. The local API is loopback-only by default. There is no automatic telemetry from Cortex itself.
|
package/docs/scopes.md
DELETED
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
# Scope 与只读共享
|
|
2
|
-
|
|
3
|
-
> 结论先说:`scope` 是**数据隔离边界**,`readOnlyScopes` 是**写保护**;
|
|
4
|
-
> 它们不是完整的身份认证/授权系统。能读 shared 的调用方仍然能读,只是不能改。
|
|
5
|
-
|
|
6
|
-
## 0. 默认行为
|
|
7
|
-
|
|
8
|
-
- 默认 scope:`global`
|
|
9
|
-
- 默认 `readOnlyScopes: []`
|
|
10
|
-
- 默认 dataRoot:`desktop` profile 仍是历史 `~/.dsh/cortex`;其他 profile 未显式配置时派生到 `~/.dsh/cortex/profiles/<profile>`(避免干净 profile 读到 desktop 库)
|
|
11
|
-
- 显式 `dataRoot` / `dbFile` / `CORTEX_HOME` 优先级更高
|
|
12
|
-
- 不配置 `readOnlyScopes` 时,写权限行为和以前一样
|
|
13
|
-
|
|
14
|
-
## 1. scope 怎么用
|
|
15
|
-
|
|
16
|
-
API 支持:
|
|
17
|
-
|
|
18
|
-
```http
|
|
19
|
-
x-cortex-scope: agent-a
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
或查询参数:
|
|
23
|
-
|
|
24
|
-
```text
|
|
25
|
-
?scope=agent-a
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
工具大多只操作当前配置的默认 scope;按 id 的写工具会先查记录所属 scope。
|
|
29
|
-
|
|
30
|
-
## 2. 只读共享示例
|
|
31
|
-
|
|
32
|
-
主配置:
|
|
33
|
-
|
|
34
|
-
```yaml
|
|
35
|
-
- id: cortex
|
|
36
|
-
name: dsh-cortex
|
|
37
|
-
config:
|
|
38
|
-
scope: agent-a
|
|
39
|
-
readOnlyScopes:
|
|
40
|
-
- shared
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
含义:
|
|
44
|
-
|
|
45
|
-
- `agent-a` 可写自己的 scope
|
|
46
|
-
- `shared` 只能读
|
|
47
|
-
- 写 `shared` 的记忆、工作项、目标、准则、候选边、日记、情绪都会拒绝
|
|
48
|
-
- `forget` / compress / retention / consolidate / vector rebuild 也不会动 `shared`
|
|
49
|
-
|
|
50
|
-
API 返回:
|
|
51
|
-
|
|
52
|
-
```json
|
|
53
|
-
{"ok":false,"error":"scope-read-only","scopeId":"shared"}
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
状态码:**403**。
|
|
57
|
-
|
|
58
|
-
工具返回:
|
|
59
|
-
|
|
60
|
-
```text
|
|
61
|
-
未执行:该记录属于只读共享 scope。
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
## 2.1 显式写授权(可选)
|
|
65
|
-
|
|
66
|
-
默认只读 scope 谁都写不了。需要给某个 agent 开写时:
|
|
67
|
-
|
|
68
|
-
```yaml
|
|
69
|
-
- id: cortex
|
|
70
|
-
name: dsh-cortex
|
|
71
|
-
config:
|
|
72
|
-
readOnlyScopes:
|
|
73
|
-
- shared
|
|
74
|
-
scopeWriteGrants:
|
|
75
|
-
- shared:agent-a
|
|
76
|
-
- grant: shared:agent-b
|
|
77
|
-
until: '2026-12-31T00:00:00Z'
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
字符串是永久授权;对象形式到期自动失效。调用时带:
|
|
81
|
-
|
|
82
|
-
```http
|
|
83
|
-
x-cortex-agent: agent-a
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
未带 header / 未授权仍是 403。
|
|
87
|
-
|
|
88
|
-
### 运行时撤销/新增(不重启)
|
|
89
|
-
|
|
90
|
-
```text
|
|
91
|
-
GET /api/cortex/security/grants
|
|
92
|
-
POST /api/cortex/security/grants { "action": "add", "grant": "shared:agent-a" }
|
|
93
|
-
POST /api/cortex/security/grants { "action": "revoke", "grant": "shared:agent-a" }
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
覆盖保存在 `<dataRoot>/scope-grants.json`,重启后仍生效。
|
|
97
|
-
撤销会写入 `revoked` 列表,优先于配置文件里的同名 grant。
|
|
98
|
-
这些改动会进 audit:`scope.grant.add` / `scope.grant.revoke`。
|
|
99
|
-
|
|
100
|
-
这不是登录或签名:header 是本地调用方自报的 agent id,只适合本机多 agent 协作。工具路径不带这个 header,因此工具仍按“默认 scope 只读”处理。
|
|
101
|
-
|
|
102
|
-
## 3. 多 agent 的两种隔离
|
|
103
|
-
|
|
104
|
-
### 同一 dataRoot,不同 scope
|
|
105
|
-
|
|
106
|
-
适合“一个进程里多个 agent / 会话共享一份库”。
|
|
107
|
-
|
|
108
|
-
- 各自读写自己的 scope
|
|
109
|
-
- `shared` 设为只读
|
|
110
|
-
- 谁有 API 访问权,谁就能读 `shared`
|
|
111
|
-
|
|
112
|
-
### 不同 dataRoot / profile
|
|
113
|
-
|
|
114
|
-
适合“完全不同的 agent,不共享数据库”。
|
|
115
|
-
|
|
116
|
-
- 每个 profile 独立 `dataRoot`
|
|
117
|
-
- 不会互相看到 traces/facts/graph
|
|
118
|
-
- 需要共享时,走导出/导入或单独的共享库
|
|
119
|
-
|
|
120
|
-
## 4. 这不是什么
|
|
121
|
-
|
|
122
|
-
- 不是多用户登录 / token 身份系统
|
|
123
|
-
- 不是按 agent 的细粒度 ACL
|
|
124
|
-
- 不会阻止能访问本地 API 的人读取 shared
|
|
125
|
-
- 不会自动把 desktop 数据迁到 shared
|
|
126
|
-
- 不会替调用方判断“这个 agent 该不该读”
|
|
127
|
-
|
|
128
|
-
## 5. 已验证的边界
|
|
129
|
-
|
|
130
|
-
- 两个 scope 的 facts / as-of 互不可见
|
|
131
|
-
- 两个 scope 的候选边互不混
|
|
132
|
-
- 只读 scope 的 write / working / goal / playbook / candidate / life / emotion / compress / forget 都会拒绝
|
|
133
|
-
- 候选边仍然要人工 approve 才进图
|
|
134
|
-
|
|
135
|
-
## 6. 还没做
|
|
136
|
-
|
|
137
|
-
- agent 身份与签名
|
|
138
|
-
- 显式 share grant / 到期时间
|
|
139
|
-
- 跨 agent 审计报表
|
|
140
|
-
- 多模态附件的共享边界
|
|
141
|
-
|
|
142
|
-
在这些完成前,文档里不要把它写成“多 agent 安全模型”,只能写“scope 隔离 + 写保护”。
|
package/examples/README.md
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
# Cortex bge 可选 profile
|
|
2
|
-
|
|
3
|
-
默认 **不开启** bge。这个示例只给想要本地语义召回的人用:
|
|
4
|
-
|
|
5
|
-
- 需要本地 Ollama / OpenAI-compatible embedding 服务
|
|
6
|
-
- 需要 `bge-m3`(1024 维)
|
|
7
|
-
- 查询延迟会明显高于 FTS
|
|
8
|
-
- 没有服务时不要开;失败会退开放,不会假装成功
|
|
9
|
-
|
|
10
|
-
## 一键创建独立 profile
|
|
11
|
-
|
|
12
|
-
```powershell
|
|
13
|
-
powershell -ExecutionPolicy Bypass -File .\examples\setup-cortex-bge.ps1 `
|
|
14
|
-
-Dsh "D:\path\to\dsh.cmd" `
|
|
15
|
-
-Profile cortex-bge `
|
|
16
|
-
-Package "C:\path\to\dsh-cortex-memory-0.1.0.tgz"
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
首次先用 Ollama 启动模型服务:
|
|
20
|
-
|
|
21
|
-
```powershell
|
|
22
|
-
ollama serve
|
|
23
|
-
ollama pull bge-m3
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
脚本会:
|
|
27
|
-
|
|
28
|
-
1. 用 DSH 的 `web` 模板新建一个空 profile
|
|
29
|
-
2. 安装 cortex 包
|
|
30
|
-
3. 写独立的 `dataRoot/dbFile`
|
|
31
|
-
4. 写 `features.vector: true`
|
|
32
|
-
5. 写 `model-config.json`(local / bge-m3 / 1024)
|
|
33
|
-
|
|
34
|
-
它**不会**改 desktop,也不会自动启动服务。
|
|
35
|
-
|
|
36
|
-
## 启动
|
|
37
|
-
|
|
38
|
-
```powershell
|
|
39
|
-
& $Dsh --profile cortex-bge --port 0 --no-open
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
打开后到 Cortex 设置里确认:
|
|
43
|
-
|
|
44
|
-
```text
|
|
45
|
-
embedding mode: local
|
|
46
|
-
model: bge-m3
|
|
47
|
-
dim: 1024
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
## 关闭
|
|
51
|
-
|
|
52
|
-
移除 profile 或把 `features.vector` 改回 `false`。
|
|
53
|
-
不想用语义模型时,FTS 仍是默认路径。
|
|
54
|
-
|
|
55
|
-
## 卸载 cortex
|
|
56
|
-
|
|
57
|
-
`dsh plugin remove` 不会删手写 patch。用:
|
|
58
|
-
|
|
59
|
-
```powershell
|
|
60
|
-
powershell -ExecutionPolicy Bypass -File .\examples\uninstall-cortex.ps1 `
|
|
61
|
-
-Dsh "D:\path\to\dsh.cmd" `
|
|
62
|
-
-Profile cortex-bge
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
脚本会:
|
|
66
|
-
|
|
67
|
-
1. 若已安装则 `plugin remove`
|
|
68
|
-
2. 只删除 `- id: cortex` 段,保留其他 patch
|
|
69
|
-
3. 跑一次 `--dump-config`
|
|
70
|
-
4. **不删 dataRoot**
|
|
71
|
-
|
|
72
|
-
如果已经手动移除,脚本会跳过 remove,仍清理残留 patch。
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
[CmdletBinding()]
|
|
2
|
-
param(
|
|
3
|
-
[string]$Dsh = 'dsh',
|
|
4
|
-
[string]$Profile = 'cortex-bge',
|
|
5
|
-
[string]$Package = 'dsh-cortex-memory',
|
|
6
|
-
[string]$DataRoot = (Join-Path $HOME '.dsh\cortex-bge'),
|
|
7
|
-
[string]$BaseUrl = 'http://127.0.0.1:11434/v1',
|
|
8
|
-
[string]$Model = 'bge-m3',
|
|
9
|
-
[int]$Dim = 1024
|
|
10
|
-
)
|
|
11
|
-
|
|
12
|
-
$ErrorActionPreference = 'Stop'
|
|
13
|
-
$dshCommand = Get-Command $Dsh -ErrorAction SilentlyContinue
|
|
14
|
-
if (-not $dshCommand) { throw "dsh command not found: $Dsh. Pass -Dsh with the path to dsh.cmd." }
|
|
15
|
-
$dshPath = $dshCommand.Source
|
|
16
|
-
$profilePath = Join-Path (Join-Path $HOME '.dsh\profiles') $Profile
|
|
17
|
-
if (Test-Path $profilePath) { throw "profile already exists: $profilePath. Choose another -Profile or remove it first." }
|
|
18
|
-
|
|
19
|
-
if ($Package -match '\.tgz$') {
|
|
20
|
-
$Package = (Resolve-Path $Package).Path
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
& $dshPath --profile $Profile --from-default-profile web --dump-config | Out-Null
|
|
24
|
-
& $dshPath plugin --profile $Profile add $Package
|
|
25
|
-
if ($LASTEXITCODE -ne 0) { throw "plugin install failed with exit code $LASTEXITCODE" }
|
|
26
|
-
|
|
27
|
-
New-Item -ItemType Directory -Force -Path $DataRoot | Out-Null
|
|
28
|
-
$modelConfig = [ordered]@{
|
|
29
|
-
embedding = [ordered]@{
|
|
30
|
-
mode = 'local'
|
|
31
|
-
baseUrl = $BaseUrl
|
|
32
|
-
model = $Model
|
|
33
|
-
dim = $Dim
|
|
34
|
-
apiKey = ''
|
|
35
|
-
}
|
|
36
|
-
rerank = [ordered]@{
|
|
37
|
-
enabled = $false
|
|
38
|
-
baseUrl = ''
|
|
39
|
-
model = ''
|
|
40
|
-
apiKey = ''
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
$utf8 = New-Object System.Text.UTF8Encoding($false)
|
|
44
|
-
[System.IO.File]::WriteAllText(
|
|
45
|
-
(Join-Path $DataRoot 'model-config.json'),
|
|
46
|
-
(($modelConfig | ConvertTo-Json -Depth 5) + "`n"),
|
|
47
|
-
$utf8
|
|
48
|
-
)
|
|
49
|
-
|
|
50
|
-
$patchFile = Join-Path $profilePath 'cordis.patch.yml'
|
|
51
|
-
$patch = @"
|
|
52
|
-
# bge profile generated by examples/setup-cortex-bge.ps1
|
|
53
|
-
- id: cortex
|
|
54
|
-
name: dsh-cortex
|
|
55
|
-
config:
|
|
56
|
-
dataRoot: '$($DataRoot.Replace('\','/'))'
|
|
57
|
-
dbFile: '$((Join-Path $DataRoot 'cortex.sqlite').Replace('\','/'))'
|
|
58
|
-
features:
|
|
59
|
-
vector: true
|
|
60
|
-
"@
|
|
61
|
-
[System.IO.File]::WriteAllText($patchFile, $patch + "`n", $utf8)
|
|
62
|
-
|
|
63
|
-
Write-Host "profile: $profilePath"
|
|
64
|
-
Write-Host "dataRoot: $DataRoot"
|
|
65
|
-
Write-Host "Next: & '$dshPath' --profile $Profile --port 0 --no-open"
|
|
66
|
-
Write-Host "Start the local embedding service first: $BaseUrl"
|