dsh-cortex-memory 0.2.0-rc.13 → 0.2.1
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 +114 -87
- package/client.js +4 -4
- package/docs/permissions.md +49 -0
- package/docs/privacy.md +48 -0
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -1,93 +1,120 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
The shiori stack is good at four things: a stable persona, a compact core,
|
|
11
|
-
triggered spark cards and on-demand topics. It is weaker at temporal facts,
|
|
12
|
-
episodic provenance, procedural learning, consolidation and calibrated
|
|
13
|
-
forgetting. `dsh-cortex` keeps the good parts and adds the missing layers:
|
|
14
|
-
|
|
15
|
-
| Layer | What it holds | Lifetime |
|
|
16
|
-
|---|---|---|
|
|
17
|
-
| L0 identity | self-model, values, boundaries, stable traits | long, explicit promotion |
|
|
18
|
-
| L1 working | current goals, focus, pinned context, recent turn buffer | minutes鈥揾ours |
|
|
19
|
-
| L2 episodic | what happened, when, with whom, provenance, emotion | days鈥搚ears |
|
|
20
|
-
| L3 semantic | entities, facts with validity windows, preferences | until invalidated |
|
|
21
|
-
| L4 procedural | skills, workflows, preconditions, success/failure stats | until superseded |
|
|
22
|
-
| L5 reflective | episode summaries, insights, narratives | derived, regenerable |
|
|
23
|
-
| archive | cold but searchable, wake-word recall | until privacy deletion |
|
|
24
|
-
|
|
25
|
-
## Engines
|
|
26
|
-
|
|
27
|
-
- **event log** 鈥?append-only, hash-chained, `event_id` / `operation_id`; the
|
|
28
|
-
only source of truth.
|
|
29
|
-
- **write pipeline** 鈥?scan secrets/injection 鈫?classify 鈫?dedupe 鈫? conflict-resolve 鈫?link 鈫?persist; async jobs with idempotent operation IDs.
|
|
30
|
-
- **temporal graph** 鈥?entities, facts and edges with `valid_from` /
|
|
31
|
-
`valid_to`; old facts are invalidated, never silently overwritten.
|
|
32
|
-
- **hybrid retrieval** 鈥?FTS5 BM25 + optional vector + graph activation +
|
|
33
|
-
recency / importance / feedback, fused with RRF, diversified with a greedy
|
|
34
|
-
MMR-style marginal-gain pass; query filters (`kind:`, `tag:`, `after:`,
|
|
35
|
-
`importance:>`, 鈥?.
|
|
36
|
-
- **DSR forgetting** 鈥?FSRS-inspired stability / difficulty / retrievability;
|
|
37
|
-
archive instead of delete, revive on successful recall.
|
|
38
|
-
- **compression / retention** 鈥?archive only when a derived model covers the
|
|
39
|
-
trace, or when a reviewed retention plan says it is old/low-value; important
|
|
40
|
-
memories are never auto-archived.
|
|
41
|
-
- **reflection** 鈥?episode segmentation, summaries, narrative threads,
|
|
42
|
-
duplicate/contradiction detection, optional LLM dream/summary.
|
|
43
|
-
- **self model** 鈥?drives, mood, attention, appraisal, relationships,
|
|
44
|
-
initiatives, 24-category emotion/affect, identity versions.
|
|
45
|
-
- **development** 鈥?maturity/stage from memory depth, feedback, calibration,
|
|
46
|
-
skills, narrative and relationships.
|
|
47
|
-
- **evolution** 鈥?policy proposals 鈫?replay evaluation 鈫?explicit approval 鈫? rollback; identity changes are separate and approval-only.
|
|
48
|
-
- **guardian** 鈥?invariants, circuit breaker, budget, backup/validate/offline
|
|
49
|
-
restore, FTS repair, privacy cascade, secret/injection scanner.
|
|
50
|
-
- **host runtime** 鈥?`session/event` turn capture + `user/message` /
|
|
51
|
-
`agent/pre-step` recall prefetch into the systemPrompt section.
|
|
52
|
-
- **API/UI/CLI** 鈥?loopback-only HTTP API, sidebar panel, `bin/cortex.mjs`.
|
|
1
|
+
# DSH Cortex
|
|
2
|
+
|
|
3
|
+
A local-first, layered memory engine for DeepSeek Harness.
|
|
4
|
+
|
|
5
|
+
Cortex gives an agent working memory, episodic traces, temporal facts, procedural
|
|
6
|
+
skills and reflective summaries, with calibrated forgetting instead of a flat
|
|
7
|
+
chat transcript. It runs locally on SQLite and has no native dependency in the
|
|
8
|
+
core engine.
|
|
53
9
|
|
|
54
10
|
## Status
|
|
55
11
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
12
|
+
- Stable package: `dsh-cortex-memory@0.2.0`
|
|
13
|
+
- Optional extractor: `dsh-cortex-extractors@0.3.3`
|
|
14
|
+
- DSH: `>=0.2.1-rc.2 <0.4.0`
|
|
15
|
+
- Node: `>=24`
|
|
16
|
+
- Tests: 406/406 (main), 12/12 (extractor)
|
|
17
|
+
- CI: GitHub Actions on Windows, Node 24
|
|
18
|
+
|
|
19
|
+
The npm package is named `dsh-cortex-memory` because `dsh-cortex` was already
|
|
20
|
+
taken; the installed bundle is still the Cortex memory engine.
|
|
21
|
+
|
|
22
|
+
## Install
|
|
23
|
+
|
|
24
|
+
```powershell
|
|
25
|
+
npm i dsh-cortex-memory
|
|
26
|
+
npm i dsh-cortex-extractors # optional OCR/ASR
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Or use the Windows one-click zip from the GitHub Release. The installer
|
|
30
|
+
discovers a desktop DSH installation automatically; `-DshPath` remains available
|
|
31
|
+
for custom installs.
|
|
32
|
+
|
|
33
|
+
After installing, restart DSH or reload the plugin. The Cortex panel is in the
|
|
34
|
+
left sidebar by default.
|
|
35
|
+
|
|
36
|
+
## What it provides
|
|
37
|
+
|
|
38
|
+
| Layer | Contents |
|
|
39
|
+
|---|---|
|
|
40
|
+
| L0 identity | self-model, values, boundaries, stable traits |
|
|
41
|
+
| working | focus, pins, current goals, turn buffer |
|
|
42
|
+
| episodic | what happened, when, provenance, emotion |
|
|
43
|
+
| semantic | entities, facts with validity windows, preferences |
|
|
44
|
+
| procedural | skills, workflows, preconditions, success/failure stats |
|
|
45
|
+
| reflective | episode summaries, insights, narratives |
|
|
46
|
+
| archive | cold but searchable, wakeable until privacy deletion |
|
|
47
|
+
|
|
48
|
+
Key behavior:
|
|
49
|
+
|
|
50
|
+
- append-only, hash-chained event log
|
|
51
|
+
- temporal facts; old facts are invalidated, not silently overwritten
|
|
52
|
+
- FTS5 BM25 + optional vector + graph activation + recency/importance/feedback
|
|
53
|
+
- DSR/FSRS-inspired stability, difficulty and retrievability
|
|
54
|
+
- reflection, retention plans and explicit-approval evolution
|
|
55
|
+
- scopes, read-only shared scopes and audit
|
|
56
|
+
- guardian backup, validation, offline restore and privacy cascade
|
|
57
|
+
- loopback-only API and sidebar UI
|
|
58
|
+
|
|
59
|
+
## UI: extract into memory
|
|
60
|
+
|
|
61
|
+
On a trace detail page:
|
|
62
|
+
|
|
63
|
+
1. enter a local `file://` image or audio path
|
|
64
|
+
2. choose OCR or ASR
|
|
65
|
+
3. choose a layout: auto, single, two-column or handwriting
|
|
66
|
+
4. choose a target trace
|
|
67
|
+
5. run **Extract and write**
|
|
68
|
+
|
|
69
|
+
The extracted text becomes a **derived trace**; the target trace is unchanged.
|
|
70
|
+
Text is never written when extraction returns no text. The extractor is optional;
|
|
71
|
+
without it the button fails closed.
|
|
72
|
+
|
|
73
|
+
## Permissions and privacy
|
|
74
|
+
|
|
75
|
+
- Local API: loopback-only, token and origin checks
|
|
76
|
+
- Permission changes: explicit confirmation, local override, restart required
|
|
77
|
+
- Feature flags/metrics: read-only snapshot
|
|
78
|
+
- Shared write grants: only for API clients sending `x-cortex-agent`; revoke is immediate
|
|
79
|
+
- Remote LLM/embedding/rerank: off unless configured and permitted
|
|
80
|
+
- Attachment reader: off by default
|
|
81
|
+
|
|
82
|
+
Read [permissions](docs/permissions.md) and [privacy](docs/privacy.md) before
|
|
83
|
+
enabling remote models or shared scopes.
|
|
84
|
+
|
|
85
|
+
## Optional extractors
|
|
86
|
+
|
|
87
|
+
`dsh-cortex-extractors` adds:
|
|
88
|
+
|
|
89
|
+
- Windows OCR (default on Windows)
|
|
90
|
+
- Tesseract with TSV layout ordering
|
|
91
|
+
- optional local PaddleOCR bridge for layout/handwriting
|
|
92
|
+
- whisper.cpp ASR
|
|
93
|
+
- custom command providers
|
|
94
|
+
|
|
95
|
+
It never downloads a model automatically. See the
|
|
96
|
+
[extractor engine docs](https://github.com/Lh1314-China/dsh-cortex-extractors/blob/main/docs/engines.md)
|
|
97
|
+
for model paths and failure behavior.
|
|
98
|
+
|
|
99
|
+
## Development
|
|
100
|
+
|
|
101
|
+
```powershell
|
|
102
|
+
npm test
|
|
103
|
+
npm run bench
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
The test runner uses `node:test` and the built-in `node:sqlite`; no network is
|
|
107
|
+
required. On Node 24 Windows CI the runner is invoked with explicit test files
|
|
108
|
+
and `--test-isolation=none` to avoid a spurious child-process EPERM.
|
|
109
|
+
|
|
110
|
+
## Compatibility and limits
|
|
111
|
+
|
|
112
|
+
- Windows is the primary desktop target; the core memory engine is cross-platform.
|
|
113
|
+
- Windows OCR requires an installed Windows OCR language pack.
|
|
114
|
+
- Tesseract and Whisper require local binaries/models.
|
|
115
|
+
- PaddleOCR handwriting is optional and accuracy on cursive is limited.
|
|
116
|
+
- The extractor is a separate package; it is not a dependency of the memory engine.
|
|
88
117
|
|
|
89
118
|
## License
|
|
90
119
|
|
|
91
|
-
MIT.
|
|
92
|
-
code is copied into this package.
|
|
93
|
-
|
|
120
|
+
MIT.
|
package/client.js
CHANGED
|
@@ -181,7 +181,7 @@ window.__ModuleLoader__.load({
|
|
|
181
181
|
graphReject: '拒绝',
|
|
182
182
|
graphCandidateConfidence: '置信',
|
|
183
183
|
settingsTitle: '运行设置',
|
|
184
|
-
settingsHint: '
|
|
184
|
+
settingsHint: '功能开关与指标为只读快照;权限修改会写入本机配置,重启后生效。',
|
|
185
185
|
runtime: '运行时',
|
|
186
186
|
features: '功能开关',
|
|
187
187
|
permissions: '权限 / 网络',
|
|
@@ -243,7 +243,7 @@ window.__ModuleLoader__.load({
|
|
|
243
243
|
p95: 'p95',
|
|
244
244
|
max: 'max',
|
|
245
245
|
metricsEmpty: '还没有指标样本。',
|
|
246
|
-
readOnlyNote: '
|
|
246
|
+
readOnlyNote: '快照只读;权限按钮可写,需确认并重启。',
|
|
247
247
|
refreshAll: '全部刷新',
|
|
248
248
|
metricAt: '采样时间',
|
|
249
249
|
notAvailable: '不可用',
|
|
@@ -444,7 +444,7 @@ window.__ModuleLoader__.load({
|
|
|
444
444
|
graphReject: 'Reject',
|
|
445
445
|
graphCandidateConfidence: 'Confidence',
|
|
446
446
|
settingsTitle: 'Runtime settings',
|
|
447
|
-
settingsHint: '
|
|
447
|
+
settingsHint: 'Feature flags and metrics are read-only snapshots; permission changes write local config and apply after restart.',
|
|
448
448
|
runtime: 'Runtime',
|
|
449
449
|
features: 'Feature flags',
|
|
450
450
|
permissions: 'Permissions / network',
|
|
@@ -506,7 +506,7 @@ window.__ModuleLoader__.load({
|
|
|
506
506
|
p95: 'p95',
|
|
507
507
|
max: 'max',
|
|
508
508
|
metricsEmpty: 'No metric samples yet.',
|
|
509
|
-
readOnlyNote: '
|
|
509
|
+
readOnlyNote: 'Snapshots are read-only; permission buttons write config after confirmation and need a restart.',
|
|
510
510
|
refreshAll: 'Refresh all',
|
|
511
511
|
metricAt: 'Sampled at',
|
|
512
512
|
notAvailable: 'Not available',
|
|
@@ -0,0 +1,49 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-cortex-memory",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "A layered, temporal, self-developing memory engine for DeepSeek Harness: working, episodic, semantic, procedural and reflective memory with hybrid retrieval, DSR forgetting, reflection, consolidation, gated self-evolution and guardian.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./index.js",
|
|
@@ -31,7 +31,9 @@
|
|
|
31
31
|
"docs/scopes.md",
|
|
32
32
|
"docs/multimodal.md",
|
|
33
33
|
"examples",
|
|
34
|
-
"LICENSE"
|
|
34
|
+
"LICENSE",
|
|
35
|
+
"docs/permissions.md",
|
|
36
|
+
"docs/privacy.md"
|
|
35
37
|
],
|
|
36
38
|
"scripts": {
|
|
37
39
|
"test": "node --test test/unit/ test/integration/",
|