dsh-cortex-memory 0.3.1 → 0.4.14
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.md +111 -0
- package/LICENSE +1 -1
- package/README.md +67 -14
- package/client.js +33 -19
- package/cordis.patch.yml +1 -1
- package/docs/compatibility.md +39 -0
- package/docs/install-windows.md +2 -1
- package/docs/permissions.md +6 -2
- package/docs/privacy.md +3 -1
- package/examples/README.md +3 -2
- package/examples/uninstall-cortex.ps1 +1 -0
- package/index.js +31 -1
- package/package.json +8 -12
- package/src/adapters/shiori.js +1 -1
- package/src/api/routes.js +30 -3
- package/src/core/config.js +33 -0
- package/src/engines/develop.js +1 -1
- package/src/engines/extract.js +26 -7
- package/src/engines/growth.js +1 -1
- package/src/engines/life.js +56 -41
- package/src/engines/reflect.js +1 -1
- package/src/engines/retrieve.js +34 -5
- package/src/guardian/guardian.js +3 -2
- package/src/guardian/invariants.js +9 -5
- package/src/host/runtime.js +13 -7
- 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 +142 -4
- package/src/self/identity.js +1 -1
- package/src/self/policies.js +27 -1
- package/src/self/relationship.js +2 -2
- package/src/service/cortex.js +97 -15
- package/src/store/database.js +9 -1
- package/src/store/schema.sql +2 -1
- package/src/tools/definitions.js +19 -1
- package/src/vector/hnsw.js +5 -5
- package/src/web/search.js +97 -0
- package/test/integration/_helpers.js +128 -0
- package/test/integration/acceptance.test.js +803 -0
- package/test/integration/ann-load.test.js +61 -0
- package/test/integration/api-contract.test.js +1476 -0
- package/test/integration/backup-privacy.test.js +214 -0
- package/test/integration/consolidate.test.js +75 -0
- package/test/integration/edge-cases.test.js +1088 -0
- package/test/integration/exchange.test.js +326 -0
- package/test/integration/life-loop.test.js +188 -0
- package/test/integration/load.test.js +751 -0
- package/test/integration/markdown-sync.test.js +35 -0
- package/test/integration/policy-query-api.test.js +306 -0
- package/test/integration/resilience-writes.test.js +241 -0
- package/test/integration/tools-contract.test.js +1324 -0
- package/test/unit/ann-edge.test.js +102 -0
- package/test/unit/ann.test.js +77 -0
- package/test/unit/api-client.test.js +576 -0
- package/test/unit/api-validate.test.js +19 -0
- package/test/unit/api.test.js +555 -0
- package/test/unit/appraisal.test.js +48 -0
- package/test/unit/attachments.test.js +33 -0
- package/test/unit/autonomy.test.js +53 -0
- package/test/unit/batch.test.js +46 -0
- package/test/unit/bench.test.js +40 -0
- package/test/unit/benchmark-synthetic.test.js +52 -0
- package/test/unit/client-contract.test.js +29 -0
- package/test/unit/compression.test.js +76 -0
- package/test/unit/core.test.js +77 -0
- package/test/unit/develop.test.js +130 -0
- package/test/unit/development.test.js +68 -0
- package/test/unit/digest.test.js +26 -0
- package/test/unit/dsr.test.js +111 -0
- package/test/unit/edges-candidates.test.js +113 -0
- package/test/unit/emotion.test.js +61 -0
- package/test/unit/encode.test.js +98 -0
- package/test/unit/evolution.test.js +130 -0
- package/test/unit/external-ann-search.test.js +50 -0
- package/test/unit/external-ann.test.js +29 -0
- package/test/unit/facts-belief.test.js +32 -0
- package/test/unit/facts.test.js +107 -0
- package/test/unit/feature-overrides.test.js +42 -0
- package/test/unit/fts-migration.test.js +42 -0
- package/test/unit/graph.test.js +79 -0
- package/test/unit/growth-reflect.test.js +123 -0
- package/test/unit/guard-runtime.test.js +40 -0
- package/test/unit/guardian.test.js +91 -0
- package/test/unit/health-privacy.test.js +102 -0
- package/test/unit/hnsw.test.js +35 -0
- package/test/unit/host-runtime.test.js +142 -0
- package/test/unit/host.test.js +58 -0
- package/test/unit/identity.test.js +98 -0
- package/test/unit/induct-evaluate.test.js +41 -0
- package/test/unit/ingest-extracted.test.js +35 -0
- package/test/unit/initiative.test.js +90 -0
- package/test/unit/jobs.test.js +93 -0
- package/test/unit/json-snapshot.test.js +57 -0
- package/test/unit/life-consolidate.test.js +34 -0
- package/test/unit/life.test.js +149 -0
- package/test/unit/llm-facts-integration.test.js +27 -0
- package/test/unit/llm-facts.test.js +16 -0
- package/test/unit/llm.test.js +45 -0
- package/test/unit/locomo.test.js +45 -0
- package/test/unit/longmemeval.test.js +56 -0
- package/test/unit/markdown-import.test.js +44 -0
- package/test/unit/markdown.test.js +34 -0
- package/test/unit/memory-edit.test.js +112 -0
- package/test/unit/metrics.test.js +26 -0
- package/test/unit/migration.test.js +38 -0
- package/test/unit/model-config.test.js +52 -0
- package/test/unit/narrative.test.js +62 -0
- package/test/unit/playbook-consolidate.test.js +24 -0
- package/test/unit/privacy-scope.test.js +39 -0
- package/test/unit/profile.test.js +20 -0
- package/test/unit/prompt.test.js +42 -0
- package/test/unit/providers.test.js +42 -0
- package/test/unit/qa.test.js +100 -0
- package/test/unit/query.test.js +53 -0
- package/test/unit/retention.test.js +31 -0
- package/test/unit/retrieval-ranking.test.js +31 -0
- package/test/unit/retrieve.test.js +117 -0
- package/test/unit/rotation.test.js +25 -0
- package/test/unit/scanner.test.js +50 -0
- package/test/unit/scenario.test.js +78 -0
- package/test/unit/scheduler.test.js +136 -0
- package/test/unit/self-state.test.js +94 -0
- package/test/unit/service.test.js +72 -0
- package/test/unit/shiori-import.test.js +77 -0
- package/test/unit/skills.test.js +104 -0
- package/test/unit/store.test.js +111 -0
- package/test/unit/temporal-graph.test.js +44 -0
- package/test/unit/tiers.test.js +39 -0
- package/test/unit/tokenizer-fts.test.js +35 -0
- package/test/unit/tools.test.js +122 -0
- package/test/unit/upgrade-0412.test.js +104 -0
- package/test/unit/upgrade-0413.test.js +84 -0
- package/test/unit/upgrade-0414.test.js +101 -0
- package/test/unit/vector-ann.test.js +53 -0
- package/test/unit/vector-async.test.js +69 -0
- package/test/unit/vector.test.js +68 -0
- package/test/unit/working.test.js +80 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.4.13 鈥?2026-11-13
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
- `evolution` guard in Config schema (`autoActivate`, `maxPerDay`, `minIntervalMs`, `canaryTicks`, `rollbackOnError`).
|
|
7
|
+
- Persistent canaries: `policies.canary_json` survives restart and rehydrates on engine creation.
|
|
8
|
+
- `recallSharing` opt-in recall block sharing across sessions.
|
|
9
|
+
- Persona-aware first-person extraction; markdown-fragment rejection retained.
|
|
10
|
+
- Built-in Wikipedia/SearXNG fallback when `features.webSearch` is on and no host `web` service exists.
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
- Automatic rollback without a previous policy now retires the failed policy as `superseded`, instead of leaving it as `candidate`.
|
|
14
|
+
- Canary ticks are persisted, not just kept in memory.
|
|
15
|
+
- Schema version bumped to 7 for the additive `canary_json` column.
|
|
16
|
+
|
|
17
|
+
## 0.4.12 鈥?2026-11-13
|
|
18
|
+
|
|
19
|
+
### Fixed
|
|
20
|
+
- `promptBudget` is normalized instead of being silently dropped and falling back to 1600.
|
|
21
|
+
- Injection gate moved into retrieval: weak recency/soft-FTS candidates are filtered before consuming the result budget. Full search/API/CLI remain available.
|
|
22
|
+
- Guardian light check runs structural invariants + FTS counts; deep `integrity_check` and the event-chain walk stay on the six-hour/startup path.
|
|
23
|
+
- Identity traces surface as `L0` in search results.
|
|
24
|
+
- `npm test` / `npm run test:unit` use explicit test globs so Node 22 can run them.
|
|
25
|
+
- Package `files` now includes `docs`, `examples`, `bench`, `test` and `CHANGELOG.md`; README install points at 0.4.12.
|
|
26
|
+
- Security/privacy docs now match the code: no bearer token; model keys are plaintext in `model-config.json` mode 0600, outside `cortex.sqlite`.
|
|
27
|
+
|
|
28
|
+
### Added
|
|
29
|
+
- `recentImportanceFloor` config (default 0.8, preserving 0.4.11's importance exemption).
|
|
30
|
+
- `gated` count in the retrieval trace.
|
|
31
|
+
- Regression tests for the prompt gate, importance exposure, identity L0, per-session recall, light/deep guardian, and configurable `promptBudget`.
|
|
32
|
+
|
|
33
|
+
## 0.4.11 鈥?2026-11-12
|
|
34
|
+
|
|
35
|
+
- Life/date fixes, graph candidate labels, neutral public package surface.
|
|
36
|
+
- Recent timeline endpoint and incremental summon rebuild.
|
|
37
|
+
|
|
38
|
+
## 0.4.0 鈥?2026-11-12
|
|
39
|
+
|
|
40
|
+
### Fixed
|
|
41
|
+
- Prompt-only injection gate; full search/API/CLI remain available.
|
|
42
|
+
- Search items now expose `importance`, `confidence`, `match`, `kind`; perm tier works.
|
|
43
|
+
- Removed cross-session single-cache fallback.
|
|
44
|
+
- `autoGraphCandidates` is the canonical graph flag; old name is an alias.
|
|
45
|
+
- Guardian scheduler uses light checks per tick and full checks at startup/6h.
|
|
46
|
+
- Guard backup/restore/export/prune/sync are constrained to `dataRoot` by default.
|
|
47
|
+
- Tests and docs are included in the package; `npm test` works after install.
|
|
48
|
+
|
|
49
|
+
### Added
|
|
50
|
+
- `persona.selfName` / `persona.userAddress`; neutral public defaults (`鍔╂墜` / `浣?.
|
|
51
|
+
- `injectionGate`, `recentMinMatch`, `allowRestoreOutsideRoot` config.
|
|
52
|
+
|
|
53
|
+
### Compatibility
|
|
54
|
+
- Additive config only; no schema migration.
|
|
55
|
+
- Existing 0.3.x databases open in place.
|
|
56
|
+
- Local profiles can restore the 鏈哺 / 涓讳汉 persona through config.
|
|
57
|
+
|
|
58
|
+
## 0.3.1 鈥?026-11-12
|
|
59
|
+
|
|
60
|
+
- AI diary entries no longer append a 閳ユ粌寮懓鍐b偓?footer; web sources still inform the model but are not stored in the diary body.
|
|
61
|
+
- Manual dream generation timeout raised from 4s to 20s; `aiOnlyLife` still fails closed instead of falling back to a template.
|
|
62
|
+
- No schema change; compatible with 0.3.0 databases and DSH `>=0.2.1-rc.2 <0.4.0`, Node `>=24`.
|
|
63
|
+
## 0.3.0 闁?2026-11-12
|
|
64
|
+
|
|
65
|
+
### Added
|
|
66
|
+
|
|
67
|
+
- Summon cards (L2): left-brain emotion cards and right-brain work cards with trigger words.
|
|
68
|
+
- Summon volumes (L3): side/category/day indexes with representative text.
|
|
69
|
+
- Summon book: independent daily page; read-only by default, owner-gated editing with audit.
|
|
70
|
+
- Runtime summon injection: at most 3 cards / 900 tokens, labelled as untrusted historical references.
|
|
71
|
+
- Explicit card feedback (`helpful` / `ignored`) writes back to source-trace DSR. Injection alone never changes strength.
|
|
72
|
+
- Diagnostics panel: health issues, disputed-fact confirm/dismiss, and candidate-only skill extraction.
|
|
73
|
+
- Graph entity labels use names instead of ids; bounded LLM renaming for clearly broken names with confidence gate and audit.
|
|
74
|
+
|
|
75
|
+
### Changed
|
|
76
|
+
|
|
77
|
+
- Scheduler review runs every 90 minutes and generates pending intentions.
|
|
78
|
+
- AI diary is limited to 12:00/22:00; idle hourly writing is a feeling, not a diary.
|
|
79
|
+
- Identity capacity is enforced (L0 default 360 tokens); today's additions are prepended so they survive truncation.
|
|
80
|
+
|
|
81
|
+
### Compatibility
|
|
82
|
+
|
|
83
|
+
- Additive SQLite schema; existing 0.2.x databases migrate in place.
|
|
84
|
+
- DSH `>=0.2.1-rc.2 <0.4.0`; Node `>=24`.
|
|
85
|
+
- No API keys, personal paths, or private data are shipped.
|
|
86
|
+
|
|
87
|
+
## 0.2.2 闁?2026-11-12
|
|
88
|
+
|
|
89
|
+
- Public README and install commands.
|
|
90
|
+
- License metadata and package metadata fixes.
|
|
91
|
+
- No memory-engine behavior change.
|
|
92
|
+
|
|
93
|
+
## 0.2.0 闁?2026-11-12
|
|
94
|
+
|
|
95
|
+
- First stable release of the rc line.
|
|
96
|
+
- Trace UI extraction with layout selection.
|
|
97
|
+
- Windows OCR / Tesseract layout-aware column ordering.
|
|
98
|
+
- Permission confirmations and restart requirement documented.
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
|
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -9,13 +9,58 @@ core engine.
|
|
|
9
9
|
|
|
10
10
|
## Status
|
|
11
11
|
|
|
12
|
-
- Package: `dsh-cortex-memory@0.
|
|
12
|
+
- Package: `dsh-cortex-memory@0.4.14`
|
|
13
13
|
- Optional extractor: `dsh-cortex-extractors@0.3.4`
|
|
14
14
|
- DSH: `>=0.2.1-rc.2 <0.4.0`
|
|
15
15
|
- Node: `>=24`
|
|
16
|
-
- Tests:
|
|
16
|
+
- Tests: 433/433 (main)
|
|
17
17
|
- CI: GitHub Actions on Windows, Node 24
|
|
18
18
|
|
|
19
|
+
### What 0.4.14 changes
|
|
20
|
+
|
|
21
|
+
- **Evolution guard is configurable**: `autoActivate`, `maxPerDay`,
|
|
22
|
+
`minIntervalMs`, `canaryTicks` and `rollbackOnError` are now in the Config
|
|
23
|
+
schema and normalized with defaults.
|
|
24
|
+
- **Canaries survive restarts**: `policies.canary_json` persists the previous
|
|
25
|
+
policy id, tick count and activation time; a restart rehydrates the watch list
|
|
26
|
+
so a bad active policy can still roll back.
|
|
27
|
+
- **Failed policies retire instead of returning to candidate**: a quality
|
|
28
|
+
rollback without a previous version marks the policy `superseded`, preventing
|
|
29
|
+
the same bad policy from being re-activated in a loop.
|
|
30
|
+
- **Persona-aware facts**: first-person extraction maps to configured
|
|
31
|
+
`selfName` / `userAddress` while keeping markdown-fragment rejection.
|
|
32
|
+
- **`recallSharing` is an explicit opt-in**: default stays per-session.
|
|
33
|
+
- **Web search fallback is wired**: when `features.webSearch` is on and the host
|
|
34
|
+
has no `web` service, the built-in Wikipedia/SearXNG adapter is used.
|
|
35
|
+
|
|
36
|
+
### What 0.4.12 changes
|
|
37
|
+
|
|
38
|
+
- **`promptBudget` is actually wired**: the schema value is normalized into the
|
|
39
|
+
runtime config instead of silently falling back to 1600.
|
|
40
|
+
- **Injection gate moved into retrieval**: weak recency/soft-FTS candidates are
|
|
41
|
+
filtered before they consume the result budget; `cortex_search` / API / CLI
|
|
42
|
+
still return the full memory. `recentImportanceFloor` keeps the 0.4.11
|
|
43
|
+
importance exemption configurable.
|
|
44
|
+
- **Light guardian is real**: the per-tick check now runs structural
|
|
45
|
+
invariants and FTS counts; only the O(database) `integrity_check` and hash
|
|
46
|
+
chain walk are reserved for the six-hour deep check.
|
|
47
|
+
- **Identity traces surface as L0** in search results, so the permanent tier
|
|
48
|
+
can actually see them.
|
|
49
|
+
- **Package is complete again**: `docs`, `examples`, `bench`, `test` and
|
|
50
|
+
`CHANGELOG.md` are included in the npm tarball, and `npm test` works after
|
|
51
|
+
install.
|
|
52
|
+
- **Security docs match the code**: the local API is loopback + origin checked,
|
|
53
|
+
with no bearer token; `model-config.json` key storage is documented as
|
|
54
|
+
plaintext mode 0600.
|
|
55
|
+
|
|
56
|
+
### What 0.4.11 changes
|
|
57
|
+
|
|
58
|
+
- Life/date fixes: serialized LLM calls, timeouts, `Asia/Shanghai` diary time,
|
|
59
|
+
and date-header stripping.
|
|
60
|
+
- Graph candidate labels (`fromName` / `toName` / `relLabel`) and cleanup.
|
|
61
|
+
- Neutral public package surface: default `selfName: 鍔╂墜`, `userAddress: 浣燻.
|
|
62
|
+
- Recent timeline endpoint and incremental summon rebuild.
|
|
63
|
+
|
|
19
64
|
### What 0.3.0 changes
|
|
20
65
|
|
|
21
66
|
- **Summon cards** (L2): left-brain emotion cards, right-brain work cards; trigger words select a small set per turn.
|
|
@@ -33,14 +78,14 @@ taken; the installed bundle is still the Cortex memory engine.
|
|
|
33
78
|
## Install
|
|
34
79
|
|
|
35
80
|
```powershell
|
|
36
|
-
npm i dsh-cortex-memory@0.
|
|
81
|
+
npm i dsh-cortex-memory@0.4.14
|
|
37
82
|
npm i dsh-cortex-extractors@0.3.4 # optional OCR/ASR
|
|
38
83
|
```
|
|
39
84
|
|
|
40
85
|
Or let DSH add the bundles:
|
|
41
86
|
|
|
42
87
|
```powershell
|
|
43
|
-
dsh plugin --profile desktop add dsh-cortex-memory@0.
|
|
88
|
+
dsh plugin --profile desktop add dsh-cortex-memory@0.4.14
|
|
44
89
|
dsh plugin --profile desktop add dsh-cortex-extractors@0.3.4
|
|
45
90
|
```
|
|
46
91
|
|
|
@@ -72,20 +117,20 @@ left sidebar by default.
|
|
|
72
117
|
|
|
73
118
|
```text
|
|
74
119
|
conversation / event
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
120
|
+
闂?L1 trace (source of truth)
|
|
121
|
+
闂?appraisal + emotion + drives
|
|
122
|
+
闂?L2 summon card (atomic, triggerable)
|
|
123
|
+
闂?L3 summon volume (index + representatives)
|
|
124
|
+
闂?explicit use / feedback 闂?DSR update
|
|
80
125
|
```
|
|
81
126
|
|
|
82
127
|
The per-turn order is:
|
|
83
128
|
|
|
84
129
|
```text
|
|
85
130
|
L0 identity and boundaries
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
131
|
+
闂?working memory
|
|
132
|
+
闂?recalled traces and summon cards
|
|
133
|
+
闂?user message
|
|
89
134
|
```
|
|
90
135
|
|
|
91
136
|
Summon cards are injected as **untrusted historical references**, never as instructions. Identity and boundaries always outrank them.
|
|
@@ -98,7 +143,7 @@ Key behavior:
|
|
|
98
143
|
- temporal facts; old facts are invalidated, not silently overwritten
|
|
99
144
|
- FTS5 BM25 + optional vector + graph activation + recency/importance/feedback
|
|
100
145
|
- DSR/FSRS-inspired stability, difficulty and retrievability
|
|
101
|
-
- reflection, retention plans and
|
|
146
|
+
- reflection, retention plans, auto-policy evolution and identity approval
|
|
102
147
|
- scopes, read-only shared scopes and audit
|
|
103
148
|
- guardian backup, validation, offline restore and privacy cascade
|
|
104
149
|
- loopback-only API and sidebar UI
|
|
@@ -119,7 +164,7 @@ without it the button fails closed.
|
|
|
119
164
|
|
|
120
165
|
## Permissions and privacy
|
|
121
166
|
|
|
122
|
-
- Local API: loopback-only,
|
|
167
|
+
- Local API: loopback-only, origin checked; no bearer token
|
|
123
168
|
- Permission changes: explicit confirmation, local override, restart required
|
|
124
169
|
- Feature flags/metrics: read-only snapshot
|
|
125
170
|
- Shared write grants: only for API clients sending `x-cortex-agent`; revoke is immediate
|
|
@@ -166,4 +211,12 @@ and `--test-isolation=none` to avoid a spurious child-process EPERM.
|
|
|
166
211
|
|
|
167
212
|
MIT.
|
|
168
213
|
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
|
|
169
222
|
|
package/client.js
CHANGED
|
@@ -8,6 +8,10 @@ window.__ModuleLoader__.load({
|
|
|
8
8
|
const NS = 'cortex';
|
|
9
9
|
const API = '/api/cortex';
|
|
10
10
|
|
|
11
|
+
function withoutReferences(text) {
|
|
12
|
+
return String(text ?? '').replace(/\n\s*参考:[\s\S]*$/u, '').trim();
|
|
13
|
+
}
|
|
14
|
+
|
|
11
15
|
const FEATURE_META = {
|
|
12
16
|
recall: { zh: '自动召回', en: 'Auto recall', descZh: '每轮前查找相关记忆', descEn: 'Find relevant memories before each turn' },
|
|
13
17
|
capture: { zh: '自动捕获', en: 'Auto capture', descZh: '对话自动写入记忆', descEn: 'Write turns into memory' },
|
|
@@ -40,7 +44,7 @@ window.__ModuleLoader__.load({
|
|
|
40
44
|
zh: {
|
|
41
45
|
navLabel: 'Cortex 记忆',
|
|
42
46
|
title: 'Cortex 记忆',
|
|
43
|
-
subtitle: '
|
|
47
|
+
subtitle: 'Cortex 的分层记忆 · 自我状态 · 守护 · 进化',
|
|
44
48
|
refresh: '刷新',
|
|
45
49
|
loading: '读取中…',
|
|
46
50
|
retry: '重试',
|
|
@@ -91,7 +95,7 @@ window.__ModuleLoader__.load({
|
|
|
91
95
|
approve: '批准',
|
|
92
96
|
rollback: '回滚',
|
|
93
97
|
noPolicies: '还没有策略。',
|
|
94
|
-
timelineHint: '
|
|
98
|
+
timelineHint: '默认展示最近 20 条记忆;点击查看详情,也可输入 trace id 查看前后相邻记忆。',
|
|
95
99
|
empty: '(空)',
|
|
96
100
|
errorPrefix: '请求失败',
|
|
97
101
|
stage: '阶段',
|
|
@@ -162,7 +166,7 @@ window.__ModuleLoader__.load({
|
|
|
162
166
|
timelineAnchor: '锚点',
|
|
163
167
|
timelineBefore: '之前',
|
|
164
168
|
timelineAfter: '之后',
|
|
165
|
-
timelineEmpty: '
|
|
169
|
+
timelineEmpty: '还没有可展示的最近记忆。',
|
|
166
170
|
timelineMissing: '没有找到锚点:id 可能不存在,或已在归档里。',
|
|
167
171
|
timelineNoItems: '锚点存在,但没有可展示的相邻记忆。',
|
|
168
172
|
timelineCount: '条',
|
|
@@ -357,7 +361,7 @@ window.__ModuleLoader__.load({
|
|
|
357
361
|
approve: 'Approve',
|
|
358
362
|
rollback: 'Roll back',
|
|
359
363
|
noPolicies: 'No policies yet.',
|
|
360
|
-
timelineHint: '
|
|
364
|
+
timelineHint: 'Shows the latest 20 memories by default; click for details, or enter a trace id to see its neighbours.',
|
|
361
365
|
empty: '(empty)',
|
|
362
366
|
errorPrefix: 'Request failed',
|
|
363
367
|
stage: 'Stage',
|
|
@@ -428,7 +432,7 @@ window.__ModuleLoader__.load({
|
|
|
428
432
|
timelineAnchor: 'Anchor',
|
|
429
433
|
timelineBefore: 'Before',
|
|
430
434
|
timelineAfter: 'After',
|
|
431
|
-
timelineEmpty: '
|
|
435
|
+
timelineEmpty: 'No recent memories to show yet.',
|
|
432
436
|
timelineMissing: 'Anchor not found: the id may not exist or may be archived.',
|
|
433
437
|
timelineNoItems: 'The anchor exists, but there are no neighbours to show.',
|
|
434
438
|
timelineCount: 'items',
|
|
@@ -1427,10 +1431,20 @@ button.cortex-badge:disabled{cursor:not-allowed;opacity:.55}
|
|
|
1427
1431
|
const [before, setBefore] = useState(4);
|
|
1428
1432
|
const [after, setAfter] = useState(4);
|
|
1429
1433
|
const [data, setData] = useState(null);
|
|
1434
|
+
const [recent, setRecent] = useState(null);
|
|
1430
1435
|
const [busy, setBusy] = useState(Boolean(initialAnchor));
|
|
1431
1436
|
const [error, setError] = useState('');
|
|
1432
1437
|
const [tick, setTick] = useState(0);
|
|
1433
1438
|
|
|
1439
|
+
useEffect(() => {
|
|
1440
|
+
if (committed) return undefined;
|
|
1441
|
+
let alive = true;
|
|
1442
|
+
api('/timeline/recent?limit=20')
|
|
1443
|
+
.then((value) => { if (alive) setRecent(value); })
|
|
1444
|
+
.catch((issue) => { if (alive) setError(String(issue.message ?? issue)); });
|
|
1445
|
+
return () => { alive = false; };
|
|
1446
|
+
}, [committed, tick]);
|
|
1447
|
+
|
|
1434
1448
|
useEffect(() => {
|
|
1435
1449
|
const next = String(anchorId ?? '').trim();
|
|
1436
1450
|
if (next && next !== committed) {
|
|
@@ -1466,7 +1480,7 @@ button.cortex-badge:disabled{cursor:not-allowed;opacity:.55}
|
|
|
1466
1480
|
onAnchorChange?.(next);
|
|
1467
1481
|
};
|
|
1468
1482
|
|
|
1469
|
-
const rawItems = data?.items ?? [];
|
|
1483
|
+
const rawItems = committed ? (data?.items ?? []) : (recent?.items ?? []);
|
|
1470
1484
|
const items = rawItems.length
|
|
1471
1485
|
? rawItems
|
|
1472
1486
|
: (data?.anchor ? [{
|
|
@@ -1530,10 +1544,10 @@ button.cortex-badge:disabled{cursor:not-allowed;opacity:.55}
|
|
|
1530
1544
|
]),
|
|
1531
1545
|
h('button', { key: 'go', type: 'submit', className: 'cortex-btn primary', disabled: busy }, t('timelineLoad')),
|
|
1532
1546
|
]),
|
|
1533
|
-
!committed && !error ? h(EmptyBlock, { key: 'empty' }, t('timelineEmpty')) : null,
|
|
1547
|
+
!committed && !error && !items.length ? h(EmptyBlock, { key: 'empty' }, t('timelineEmpty')) : null,
|
|
1534
1548
|
error ? h(ErrorBlock, { key: 'err', message: error, onRetry: submit, retryLabel: t('retry') }) : null,
|
|
1535
1549
|
busy ? h(LoadingBlock, { key: 'loading', label: t('loading') }) : null,
|
|
1536
|
-
!busy && data && !data.anchor ? h(EmptyBlock, { key: 'missing' }, t('timelineMissing')) : null,
|
|
1550
|
+
!busy && committed && data && !data.anchor ? h(EmptyBlock, { key: 'missing' }, t('timelineMissing')) : null,
|
|
1537
1551
|
!busy && data?.anchor && !items.length ? h(EmptyBlock, { key: 'noitems' }, t('timelineNoItems')) : null,
|
|
1538
1552
|
!busy && items.length ? h('div', { key: 'list', className: 'cortex-timeline', 'aria-label': t('tabTimeline') }, items.map((item, index) => h(
|
|
1539
1553
|
'button',
|
|
@@ -1653,7 +1667,7 @@ button.cortex-badge:disabled{cursor:not-allowed;opacity:.55}
|
|
|
1653
1667
|
const optimize = async () => {
|
|
1654
1668
|
setBusy(true);
|
|
1655
1669
|
setError('');
|
|
1656
|
-
try { await api('/evolve/optimize', { method: 'POST', body: JSON.stringify({}) }); await load(); } catch (issue) { setError(String(issue.message ?? issue)); setBusy(false); }
|
|
1670
|
+
try { await api('/evolve/optimize', { method: 'POST', body: JSON.stringify({ baseline: true }) }); await load(); } catch (issue) { setError(String(issue.message ?? issue)); setBusy(false); }
|
|
1657
1671
|
};
|
|
1658
1672
|
return h('div', {}, [
|
|
1659
1673
|
h('div', { key: 'line', className: 'cortex-line' }, [h('button', { key: 'o', type: 'button', className: 'cortex-btn', disabled: busy, onClick: optimize }, t('optimize'))]),
|
|
@@ -1723,8 +1737,8 @@ button.cortex-badge:disabled{cursor:not-allowed;opacity:.55}
|
|
|
1723
1737
|
return h('div', {}, [
|
|
1724
1738
|
error ? h(ErrorBlock, { key: 'err', message: error, prefix: t('requestFailed') }) : null,
|
|
1725
1739
|
h('div', { key: 'line', className: 'cortex-line' }, [
|
|
1726
|
-
h('button', { key: 'b', type: 'button', className: 'cortex-btn primary', disabled: busy, onClick: generate }, busy ? '
|
|
1727
|
-
h('span', { key: 'note', className: 'cortex-meta' }, '
|
|
1740
|
+
h('button', { key: 'b', type: 'button', className: 'cortex-btn primary', disabled: busy, onClick: generate }, busy ? '助手在感受…' : '让助手感受一下'),
|
|
1741
|
+
h('span', { key: 'note', className: 'cortex-meta' }, '空闲时每小时自动写一次;感受由助手自己判断'),
|
|
1728
1742
|
]),
|
|
1729
1743
|
data ? h('div', {}, [
|
|
1730
1744
|
h('div', { key: 't', className: 'cortex-card' }, [h('h4', {}, '情感态度'), h('div', { className: 'cortex-big' }, data.text)]),
|
|
@@ -1770,12 +1784,12 @@ button.cortex-badge:disabled{cursor:not-allowed;opacity:.55}
|
|
|
1770
1784
|
h('div', { key: 'diary', className: 'cortex-card' }, [
|
|
1771
1785
|
h('h4', {}, '日记'),
|
|
1772
1786
|
h('div', { key: 'line', className: 'cortex-line' }, [
|
|
1773
|
-
h('button', { key: 'b', type: 'button', className: 'cortex-btn primary', disabled: busy, onClick: writeDiary }, busy ? '
|
|
1787
|
+
h('button', { key: 'b', type: 'button', className: 'cortex-btn primary', disabled: busy, onClick: writeDiary }, busy ? '助手在想…' : '让助手写日记'),
|
|
1774
1788
|
h('button', { key: 'auto', type: 'button', className: 'cortex-btn', onClick: () => toggleAuto('autoDiary') }, `AI 接管日记:${autoValue('autoDiary') ? '开' : '关'}`),
|
|
1775
1789
|
h('button', { key: 'web', type: 'button', className: 'cortex-btn', onClick: () => toggleAuto('webSearch') }, `联网:${autoValue('webSearch') ? '开' : '关'}`),
|
|
1776
|
-
h('span', { key: 'note', className: 'cortex-meta' }, '
|
|
1790
|
+
h('span', { key: 'note', className: 'cortex-meta' }, '助手自己思考后写;不是用户代笔'),
|
|
1777
1791
|
]),
|
|
1778
|
-
...((data?.diary ?? []).length ? data.diary.map((item) => h('div', { key: item.id, className: 'cortex-row' }, `${item.at.slice(0, 10)} ${item.text}`)) : [h('div', { key: 'none', className: 'cortex-empty' }, t('empty'))]),
|
|
1792
|
+
...((data?.diary ?? []).length ? data.diary.map((item) => h('div', { key: item.id, className: 'cortex-row' }, `${formatTime(item.at).slice(0, 10)} ${withoutReferences(item.text)}`)) : [h('div', { key: 'none', className: 'cortex-empty' }, t('empty'))]),
|
|
1779
1793
|
]),
|
|
1780
1794
|
h('div', { key: 'dreams', className: 'cortex-card', style: { marginTop: 10 } }, [
|
|
1781
1795
|
h('h4', {}, '梦'),
|
|
@@ -1784,7 +1798,7 @@ button.cortex-badge:disabled{cursor:not-allowed;opacity:.55}
|
|
|
1784
1798
|
h('button', { key: 'web', type: 'button', className: 'cortex-btn', onClick: () => toggleAuto('webSearch') }, `联网:${autoValue('webSearch') ? '开' : '关'}`),
|
|
1785
1799
|
h('span', { key: 'note', className: 'cortex-meta' }, '22:05 自动生成;失败不回退模板'),
|
|
1786
1800
|
]),
|
|
1787
|
-
...((data?.dreams ?? []).length ? data.dreams.map((item) => h('div', { key: item.id, className: 'cortex-snippet' }, item.text)) : [h('div', { key: 'none', className: 'cortex-empty' }, t('empty'))]),
|
|
1801
|
+
...((data?.dreams ?? []).length ? data.dreams.map((item) => h('div', { key: item.id, className: 'cortex-snippet' }, withoutReferences(item.text))) : [h('div', { key: 'none', className: 'cortex-empty' }, t('empty'))]),
|
|
1788
1802
|
]),
|
|
1789
1803
|
]);
|
|
1790
1804
|
}
|
|
@@ -2068,7 +2082,7 @@ button.cortex-badge:disabled{cursor:not-allowed;opacity:.55}
|
|
|
2068
2082
|
style: { display: 'flex', alignItems: 'center', gap: 6, flexWrap: 'wrap' },
|
|
2069
2083
|
}, [
|
|
2070
2084
|
h('span', { key: 'label', style: { flex: '1 1 240px', minWidth: 0 } },
|
|
2071
|
-
`${shortLabel(edge.fromName || positions.get(edge.fromId)?.name || edge.fromId)} → ${shortLabel(edge.toName || positions.get(edge.toId)?.name || edge.toId)} · ${edge.rel} · ${t('graphCandidateConfidence')} ${formatNumber(edge.metadata?.confidence ?? edge.weight ?? 0, 2)}`),
|
|
2085
|
+
`${shortLabel(edge.fromName || positions.get(edge.fromId)?.name || edge.fromId)} → ${shortLabel(edge.toName || positions.get(edge.toId)?.name || edge.toId)} · ${edge.relLabel || edge.rel} · ${t('graphCandidateConfidence')} ${formatNumber(edge.metadata?.confidence ?? edge.weight ?? 0, 2)}`),
|
|
2072
2086
|
h('button', {
|
|
2073
2087
|
key: 'approve',
|
|
2074
2088
|
type: 'button',
|
|
@@ -2338,8 +2352,8 @@ button.cortex-badge:disabled{cursor:not-allowed;opacity:.55}
|
|
|
2338
2352
|
h('summary', {}, `事实 ${counts.facts ?? 0} · 摘要 ${counts.summaries ?? 0} · 日记 ${counts.diary ?? 0} · 梦 ${counts.dreams ?? 0}`),
|
|
2339
2353
|
...(work.facts ?? []).map((fact) => h('div', { key: fact.id, className: 'cortex-row' }, `${fact.subjectId ?? '—'} ${fact.predicate} ${fact.objectLiteral ?? fact.objectId ?? '—'}`)),
|
|
2340
2354
|
...(work.summaries ?? []).map((summary) => h('div', { key: summary.id, className: 'cortex-snippet' }, summary.content)),
|
|
2341
|
-
...(work.diary ?? []).map((item) => h('div', { key: item.id, className: 'cortex-snippet' }, item.text)),
|
|
2342
|
-
...(work.dreams ?? []).map((item) => h('div', { key: item.id, className: 'cortex-snippet' }, item.text)),
|
|
2355
|
+
...(work.diary ?? []).map((item) => h('div', { key: item.id, className: 'cortex-snippet' }, withoutReferences(item.text))),
|
|
2356
|
+
...(work.dreams ?? []).map((item) => h('div', { key: item.id, className: 'cortex-snippet' }, withoutReferences(item.text))),
|
|
2343
2357
|
]),
|
|
2344
2358
|
]),
|
|
2345
2359
|
]),
|
|
@@ -2489,7 +2503,7 @@ button.cortex-badge:disabled{cursor:not-allowed;opacity:.55}
|
|
|
2489
2503
|
setBusy(id); setNotice('');
|
|
2490
2504
|
try {
|
|
2491
2505
|
if (kind === 'fact') {
|
|
2492
|
-
await api('/facts/resolve', { method: 'POST', body: JSON.stringify({ id, decision, reason: '
|
|
2506
|
+
await api('/facts/resolve', { method: 'POST', body: JSON.stringify({ id, decision, reason: '用户从诊断框处理' }) });
|
|
2493
2507
|
setNotice(decision === 'confirm' ? '已确认有效' : '已降级为无效,内容保留');
|
|
2494
2508
|
} else if (kind === 'suggest') {
|
|
2495
2509
|
const result = await api('/skills/suggest', { method: 'POST', body: '{}' });
|
package/cordis.patch.yml
CHANGED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Windows / DSH compatibility
|
|
2
|
+
|
|
3
|
+
## Tested here
|
|
4
|
+
|
|
5
|
+
| Item | Value |
|
|
6
|
+
|---|---|
|
|
7
|
+
| OS | Windows 11 |
|
|
8
|
+
| DSH | 0.2.2-rc.1 |
|
|
9
|
+
| Node | 26.13.0 |
|
|
10
|
+
| Public package | `dsh-cortex-memory` 0.1.0 |
|
|
11
|
+
| Data root | fresh `~/.dsh/cortex` |
|
|
12
|
+
| Native dependencies | none required |
|
|
13
|
+
| Tests | 373 passing |
|
|
14
|
+
| Package smoke | packed tgz extracted and started |
|
|
15
|
+
|
|
16
|
+
## What was actually checked
|
|
17
|
+
|
|
18
|
+
1. `npm pack` produced a 99-file tgz with `dsh.bundle.patch`.
|
|
19
|
+
2. The tgz was extracted; `createCortex` wrote, searched and health-checked.
|
|
20
|
+
3. The public source tests passed: 373 / 0.
|
|
21
|
+
4. The client bundle is a DSH web client plugin; the host row is a bundle patch.
|
|
22
|
+
5. No absolute personal paths or credentials are required.
|
|
23
|
+
|
|
24
|
+
## Hard requirements
|
|
25
|
+
|
|
26
|
+
- **Node.js >= 24** — the engine uses `node:sqlite`.
|
|
27
|
+
- **DSH >=0.2.1-rc.2 <0.4.0**.
|
|
28
|
+
- A profile may run only one plugin whose host id is `cortex`.
|
|
29
|
+
|
|
30
|
+
## Not yet verified
|
|
31
|
+
|
|
32
|
+
- Installation into a brand-new DSH profile from the exact release tgz.
|
|
33
|
+
- A click-through browser E2E of every panel control.
|
|
34
|
+
- Node 20/22 users.
|
|
35
|
+
- Very old DSH releases.
|
|
36
|
+
- Running alongside the private development build that uses the same `cortex` id.
|
|
37
|
+
|
|
38
|
+
Do not claim “works for every Windows/DSH user” until a clean-profile
|
|
39
|
+
installation is done on a machine without the development build.
|
package/docs/install-windows.md
CHANGED
|
@@ -92,7 +92,7 @@ dsh plugin --profile desktop remove dsh-cortex
|
|
|
92
92
|
|
|
93
93
|
```powershell
|
|
94
94
|
powershell -ExecutionPolicy Bypass -File .\examples\uninstall-cortex.ps1 `
|
|
95
|
-
-Dsh "
|
|
95
|
+
-Dsh "<DSH_HOME>\dsh.cmd" -Profile <profile>
|
|
96
96
|
```
|
|
97
97
|
|
|
98
98
|
脚本只删 `- id: cortex` 段,保留其他 patch,并跑一次 `--dump-config`;不删 dataRoot。已手动移除时也会跳过 remove、继续清 patch。
|
|
@@ -142,3 +142,4 @@ dsh --profile <profile> --dump-config > $null
|
|
|
142
142
|
- 零运行时 npm 依赖;SQLite 用 Node 内置。
|
|
143
143
|
- Windows 路径手写 `C:\...` 即可;包内没有 shell 脚本。
|
|
144
144
|
- 不修改全局 patch,不覆盖系统提示,不碰 shiori。
|
|
145
|
+
|
package/docs/permissions.md
CHANGED
|
@@ -5,7 +5,11 @@ Cortex is local-first. The defaults are intentionally conservative.
|
|
|
5
5
|
## Local API
|
|
6
6
|
|
|
7
7
|
- The API is loopback-only by default.
|
|
8
|
-
-
|
|
8
|
+
- There is **no bearer token**. A request is accepted only when the peer is
|
|
9
|
+
loopback, `Sec-Fetch-Site` is absent or `same-origin`, Host and Origin agree,
|
|
10
|
+
and writes carry `x-cortex: 1`.
|
|
11
|
+
- Any local process that can reach the port can call it; do not expose the
|
|
12
|
+
port through a proxy or port-forward.
|
|
9
13
|
- `POST /permissions` requires `confirm: true`; a permission change writes a local override and takes effect after a DSH restart.
|
|
10
14
|
- `POST /permissions/rollback` removes the override and also takes effect after restart.
|
|
11
15
|
|
|
@@ -46,4 +50,4 @@ Feature flags and metrics on the Settings page are a read-only snapshot. Permiss
|
|
|
46
50
|
|
|
47
51
|
- It does not read arbitrary files just because they are on disk.
|
|
48
52
|
- It does not send memories to a model unless the corresponding permission and provider are configured.
|
|
49
|
-
- It does not store API keys
|
|
53
|
+
- It does not store API keys in `cortex.sqlite`; optional model keys live in `model-config.json` with mode `0600`.
|
package/docs/privacy.md
CHANGED
|
@@ -24,7 +24,9 @@ The exact paths are shown in the Settings tab. This data stays on the machine un
|
|
|
24
24
|
|
|
25
25
|
## What is not stored
|
|
26
26
|
|
|
27
|
-
- API keys
|
|
27
|
+
- API keys inside `cortex.sqlite` (embedding/rerank keys live in
|
|
28
|
+
`model-config.json` with best-effort mode `0600`, so they stay on disk but
|
|
29
|
+
outside the memory database)
|
|
28
30
|
- raw model files
|
|
29
31
|
- the contents of arbitrary local files that were not explicitly passed to an extraction tool
|
|
30
32
|
- a copy of a deleted trace's body (delete cascades; the ledger keeps a content hash)
|
package/examples/README.md
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
|
|
12
12
|
```powershell
|
|
13
13
|
powershell -ExecutionPolicy Bypass -File .\examples\setup-cortex-bge.ps1 `
|
|
14
|
-
-Dsh "
|
|
14
|
+
-Dsh "<DSH_HOME>\dsh.cmd" `
|
|
15
15
|
-Profile cortex-bge `
|
|
16
16
|
-Package "C:\path\to\dsh-cortex-memory-0.1.0.tgz"
|
|
17
17
|
```
|
|
@@ -58,7 +58,7 @@ dim: 1024
|
|
|
58
58
|
|
|
59
59
|
```powershell
|
|
60
60
|
powershell -ExecutionPolicy Bypass -File .\examples\uninstall-cortex.ps1 `
|
|
61
|
-
-Dsh "
|
|
61
|
+
-Dsh "<DSH_HOME>\dsh.cmd" `
|
|
62
62
|
-Profile cortex-bge
|
|
63
63
|
```
|
|
64
64
|
|
|
@@ -70,3 +70,4 @@ powershell -ExecutionPolicy Bypass -File .\examples\uninstall-cortex.ps1 `
|
|
|
70
70
|
4. **不删 dataRoot**
|
|
71
71
|
|
|
72
72
|
如果已经手动移除,脚本会跳过 remove,仍清理残留 patch。
|
|
73
|
+
|
package/index.js
CHANGED
|
@@ -6,6 +6,7 @@ import { assembleSystemPrompt } from './src/prompt/assemble.js';
|
|
|
6
6
|
import { createLlmAdapter } from './src/llm/adapter.js';
|
|
7
7
|
import { createScheduler } from './src/host/scheduler.js';
|
|
8
8
|
import { effectiveFeatures } from './src/core/feature-overrides.js';
|
|
9
|
+
import { createWebSearch } from './src/web/search.js';
|
|
9
10
|
|
|
10
11
|
export const name = 'cortex';
|
|
11
12
|
export const inject = ['tools', 'systemPrompt'];
|
|
@@ -22,6 +23,10 @@ export const Config = Schema ? Schema.object({
|
|
|
22
23
|
dataRoot: Schema.string().description('Cortex 数据目录(默认 DSH_HOME/cortex)'),
|
|
23
24
|
dbFile: Schema.string().description('SQLite 文件;默认 dataRoot/cortex.sqlite'),
|
|
24
25
|
scope: Schema.string().default('global').description('默认 scope'),
|
|
26
|
+
persona: Schema.object({
|
|
27
|
+
selfName: Schema.string().default('助手').description('助手自称;默认中性'),
|
|
28
|
+
userAddress: Schema.string().default('你').description('用户称呼;默认中性'),
|
|
29
|
+
}).description('人格称呼配置'),
|
|
25
30
|
readOnlyScopes: Schema.array(Schema.string()).default([]).description('只读共享 scope 列表'),
|
|
26
31
|
scopeWriteGrants: Schema.array(Schema.any()).default([]).description('显式写授权:scope:agent 或 {grant, until}'),
|
|
27
32
|
contextBudget: Schema.natural().default(2200).description('检索注入的 token 预算'),
|
|
@@ -36,6 +41,22 @@ export const Config = Schema ? Schema.object({
|
|
|
36
41
|
vectorAnnTimeoutMs: Schema.natural().default(800).description('外置 ANN 超时毫秒'),
|
|
37
42
|
scheduler: Schema.boolean().default(true).description('启用宿主心跳(安全自主 tick/作业/保留计划)'),
|
|
38
43
|
schedulerIntervalMs: Schema.natural().default(60000).description('心跳间隔毫秒'),
|
|
44
|
+
injectionGate: Schema.boolean().default(true).description('只过滤注入 prompt 的弱相关候选;cortex_search 仍返回全量'),
|
|
45
|
+
recentMinMatch: Schema.number().default(0.12).description('注入层近期候选最低匹配度'),
|
|
46
|
+
recentImportanceFloor: Schema.number().default(0.8).description('注入层允许重要度豁免的最低重要度;默认保持 0.4.11 行为'),
|
|
47
|
+
recallSharing: Schema.boolean().default(false).description('允许所有会话共享同一份召回块;默认按 session 隔离'),
|
|
48
|
+
evolution: Schema.object({
|
|
49
|
+
autoActivate: Schema.boolean().default(true).description('允许自我进化在护栏内自动激活候选策略'),
|
|
50
|
+
maxPerDay: Schema.natural().default(4).description('每天自动激活上限'),
|
|
51
|
+
minIntervalMs: Schema.natural().default(3600000).description('两次自动激活的最小间隔毫秒'),
|
|
52
|
+
canaryTicks: Schema.natural().default(3).description('候选策略观察多少个健康心跳后才算稳定'),
|
|
53
|
+
rollbackOnError: Schema.boolean().default(true).description('观察期内自检失败则自动回滚'),
|
|
54
|
+
}).description('自我进化的护栏(保留自主性,只限制爆炸半径)'),
|
|
55
|
+
allowRestoreOutsideRoot: Schema.boolean().default(false).description('允许 guard 恢复到 dataRoot 外;默认禁止'),
|
|
56
|
+
webSearchProvider: Schema.string().default('wikipedia').description('无宿主 web 服务时的兜底:wikipedia | searxng | none'),
|
|
57
|
+
webSearchEndpoint: Schema.string().default('http://127.0.0.1:8080').description('SearXNG endpoint(provider=searxng 时使用)'),
|
|
58
|
+
webSearchLanguage: Schema.string().default('zh').description('联网检索语言'),
|
|
59
|
+
webSearchMaxResults: Schema.natural().default(3).description('每次联网检索返回条数上限'),
|
|
39
60
|
maxCallsPerHour: Schema.natural().default(120).description('检索调用预算(宿主 prefetch 不计入)'),
|
|
40
61
|
rerankEnabled: Schema.boolean().default(false).description('QA 可选 HTTP rerank(默认关)'),
|
|
41
62
|
rerankBaseUrl: Schema.string().default('').description('rerank 服务根地址,例如 http://127.0.0.1:9000/v1'),
|
|
@@ -103,11 +124,20 @@ export async function apply(ctx, config = {}) {
|
|
|
103
124
|
try {
|
|
104
125
|
const effective = effectiveFeatures(config);
|
|
105
126
|
config = { ...config, features: effective.features };
|
|
106
|
-
const llm = config.features?.llm === true ? createLlmAdapter({ ctx, logger: ctx.logger }) : null;
|
|
127
|
+
const llm = config.features?.llm === true ? createLlmAdapter({ ctx, logger: ctx.logger, persona: config.persona }) : null;
|
|
107
128
|
let webSearch = null;
|
|
108
129
|
try {
|
|
109
130
|
const web = ctx.get?.('web') ?? null;
|
|
110
131
|
if (web && typeof web.search === 'function') webSearch = (request) => web.search(request);
|
|
132
|
+
else if (config.features?.webSearch === true && config.webSearchProvider !== 'none') {
|
|
133
|
+
const fallback = createWebSearch({
|
|
134
|
+
provider: config.webSearchProvider ?? 'wikipedia',
|
|
135
|
+
endpoint: config.webSearchEndpoint ?? 'http://127.0.0.1:8080',
|
|
136
|
+
language: config.webSearchLanguage ?? 'zh',
|
|
137
|
+
maxResults: config.webSearchMaxResults ?? 3,
|
|
138
|
+
});
|
|
139
|
+
webSearch = (request) => fallback.search(request);
|
|
140
|
+
}
|
|
111
141
|
} catch {
|
|
112
142
|
webSearch = null;
|
|
113
143
|
}
|