dsh-cortex-memory 0.4.146 → 0.4.148
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 +2423 -2369
- package/README.md +8 -8
- package/bench/governance.mjs +265 -0
- package/bench/migration-bench.mjs +1 -1
- package/bench/semantic-cn.js +4 -4
- package/bench/synthetic.js +3 -3
- package/bin/copy-db.mjs +1 -1
- package/bin/repair.mjs +7 -7
- package/client.js +1 -1
- package/docs/install-windows.md +2 -2
- package/docs/models.md +1 -1
- package/docs/quota-compaction-design.md +3 -3
- package/icon.svg +12 -2
- package/index.js +5 -6
- package/package.json +7 -8
- package/src/adapters/shiori.js +1 -1
- package/src/engines/compression.js +8 -3
- package/src/engines/consolidate.js +1 -1
- package/src/engines/encode.js +3 -3
- package/src/engines/extract.js +1 -1
- package/src/engines/health.js +1 -1
- package/src/engines/life.js +2 -2
- package/src/engines/narrative.js +4 -8
- package/src/engines/retrieve.js +41 -4
- package/src/host/scheduler.js +5 -4
- package/src/memory/tokenizer.js +1 -1
- package/src/self/alias.js +4 -5
- package/src/self/memory-policy.js +59 -0
- package/src/service/cortex.js +20 -2
- package/src/store/repositories/facts.js +1 -1
- package/src/store/repositories/traces.js +1 -1
- package/test/integration/_helpers.js +0 -128
- package/test/integration/acceptance.test.js +0 -803
- package/test/integration/ann-load.test.js +0 -61
- package/test/integration/api-contract.test.js +0 -1476
- package/test/integration/backup-privacy.test.js +0 -214
- package/test/integration/consolidate.test.js +0 -79
- package/test/integration/edge-cases.test.js +0 -1089
- package/test/integration/exchange.test.js +0 -326
- package/test/integration/life-loop.test.js +0 -189
- package/test/integration/load.test.js +0 -751
- package/test/integration/markdown-sync.test.js +0 -35
- package/test/integration/policy-query-api.test.js +0 -306
- package/test/integration/resilience-writes.test.js +0 -241
- package/test/integration/tools-contract.test.js +0 -1324
- package/test/unit/alias.test.js +0 -87
- package/test/unit/ann-edge.test.js +0 -102
- package/test/unit/ann.test.js +0 -77
- package/test/unit/api-client.test.js +0 -576
- package/test/unit/api-validate.test.js +0 -19
- package/test/unit/api.test.js +0 -555
- package/test/unit/appraisal.test.js +0 -48
- package/test/unit/attachments.test.js +0 -33
- package/test/unit/auto-reflect.test.js +0 -141
- package/test/unit/autonomy.test.js +0 -53
- package/test/unit/batch.test.js +0 -46
- package/test/unit/bench.test.js +0 -40
- package/test/unit/benchmark-synthetic.test.js +0 -52
- package/test/unit/capture-filter.test.js +0 -296
- package/test/unit/cli-default-root.test.js +0 -21
- package/test/unit/client-contract.test.js +0 -32
- package/test/unit/compaction-preview.test.js +0 -91
- package/test/unit/compression.test.js +0 -76
- package/test/unit/consolidate-dedupe.test.js +0 -174
- package/test/unit/consolidate-errors.test.js +0 -63
- package/test/unit/consolidate-gate.test.js +0 -26
- package/test/unit/consolidate-preview.test.js +0 -168
- package/test/unit/consolidate-protection.test.js +0 -156
- package/test/unit/consolidate-reason.test.js +0 -206
- package/test/unit/consolidate-retry.test.js +0 -91
- package/test/unit/consolidate-selection.test.js +0 -103
- package/test/unit/core.test.js +0 -77
- package/test/unit/coverage-rewrite.test.js +0 -38
- package/test/unit/dedupe-episodes.test.js +0 -34
- package/test/unit/dedupe-threshold.test.js +0 -14
- package/test/unit/develop.test.js +0 -130
- package/test/unit/development.test.js +0 -68
- package/test/unit/digest.test.js +0 -26
- package/test/unit/dsr.test.js +0 -111
- package/test/unit/edges-candidates.test.js +0 -113
- package/test/unit/emotion.test.js +0 -62
- package/test/unit/encode.test.js +0 -98
- package/test/unit/evolution.test.js +0 -130
- package/test/unit/external-ann-search.test.js +0 -50
- package/test/unit/external-ann.test.js +0 -29
- package/test/unit/extract-question.test.js +0 -41
- package/test/unit/fact-guard.test.js +0 -51
- package/test/unit/fact-noise-llm.test.js +0 -44
- package/test/unit/facts-belief.test.js +0 -32
- package/test/unit/facts-compat.test.js +0 -62
- package/test/unit/facts.test.js +0 -107
- package/test/unit/feature-overrides.test.js +0 -42
- package/test/unit/fts-migration.test.js +0 -42
- package/test/unit/graph.test.js +0 -79
- package/test/unit/growth-reflect.test.js +0 -124
- package/test/unit/guard-runtime.test.js +0 -40
- package/test/unit/guardian.test.js +0 -91
- package/test/unit/health-consolidation.test.js +0 -52
- package/test/unit/health-fts-scope.test.js +0 -33
- package/test/unit/health-privacy.test.js +0 -102
- package/test/unit/health-summaries.test.js +0 -24
- package/test/unit/health-text-maintain.test.js +0 -33
- package/test/unit/health-today.test.js +0 -45
- package/test/unit/hnsw.test.js +0 -35
- package/test/unit/host-runtime.test.js +0 -142
- package/test/unit/host.test.js +0 -58
- package/test/unit/identity.test.js +0 -98
- package/test/unit/induct-evaluate.test.js +0 -41
- package/test/unit/ingest-extracted.test.js +0 -35
- package/test/unit/inhibition.test.js +0 -90
- package/test/unit/initiative.test.js +0 -90
- package/test/unit/jobs.test.js +0 -93
- package/test/unit/json-snapshot.test.js +0 -57
- package/test/unit/label-entities-skip.test.js +0 -18
- package/test/unit/life-consolidate.test.js +0 -34
- package/test/unit/life.test.js +0 -149
- package/test/unit/llm-facts-integration.test.js +0 -27
- package/test/unit/llm-facts.test.js +0 -16
- package/test/unit/llm.test.js +0 -45
- package/test/unit/locomo.test.js +0 -45
- package/test/unit/longmemeval.test.js +0 -56
- package/test/unit/maintain-dispute.test.js +0 -62
- package/test/unit/maintain-duration.test.js +0 -194
- package/test/unit/markdown-import.test.js +0 -44
- package/test/unit/markdown.test.js +0 -34
- package/test/unit/memory-edit.test.js +0 -112
- package/test/unit/metrics.test.js +0 -26
- package/test/unit/migration.test.js +0 -38
- package/test/unit/model-config.test.js +0 -52
- package/test/unit/mood-saturation.test.js +0 -33
- package/test/unit/narrative-weave.test.js +0 -271
- package/test/unit/narrative.test.js +0 -62
- package/test/unit/playbook-consolidate.test.js +0 -24
- package/test/unit/privacy-scope.test.js +0 -39
- package/test/unit/profile-paths.test.js +0 -21
- package/test/unit/profile.test.js +0 -26
- package/test/unit/prompt.test.js +0 -42
- package/test/unit/providers.test.js +0 -42
- package/test/unit/qa.test.js +0 -100
- package/test/unit/query.test.js +0 -53
- package/test/unit/reflect-backfill.test.js +0 -158
- package/test/unit/reflect-coverage.test.js +0 -35
- package/test/unit/reflect-overview.test.js +0 -22
- package/test/unit/reflect-phrasing.test.js +0 -75
- package/test/unit/reflect-sampling.test.js +0 -80
- package/test/unit/reflect-source-budget.test.js +0 -24
- package/test/unit/relationship-dynamics.test.js +0 -29
- package/test/unit/retention.test.js +0 -31
- package/test/unit/retrieval-ranking.test.js +0 -31
- package/test/unit/retrieve.test.js +0 -117
- package/test/unit/revive-on-read.test.js +0 -84
- package/test/unit/rotation.test.js +0 -25
- package/test/unit/scanner.test.js +0 -50
- package/test/unit/scenario.test.js +0 -78
- package/test/unit/scheduler-autoconsolidate.test.js +0 -95
- package/test/unit/scheduler-autodedupe.test.js +0 -52
- package/test/unit/scheduler-autosleep.test.js +0 -50
- package/test/unit/scheduler-cadence.test.js +0 -33
- package/test/unit/scheduler-deep.test.js +0 -62
- package/test/unit/scheduler-tick-gate.test.js +0 -38
- package/test/unit/scheduler.test.js +0 -137
- package/test/unit/self-state.test.js +0 -94
- package/test/unit/service.test.js +0 -72
- package/test/unit/shiori-import.test.js +0 -77
- package/test/unit/skills.test.js +0 -104
- package/test/unit/spacing.test.js +0 -14
- package/test/unit/store.test.js +0 -111
- package/test/unit/summon-left-slot.test.js +0 -51
- package/test/unit/summon-rank.test.js +0 -51
- package/test/unit/temporal-graph.test.js +0 -44
- package/test/unit/tiers-gist.test.js +0 -140
- package/test/unit/tiers.test.js +0 -39
- package/test/unit/tokenizer-fts.test.js +0 -35
- package/test/unit/tools.test.js +0 -122
- package/test/unit/upgrade-0412.test.js +0 -104
- package/test/unit/upgrade-0413.test.js +0 -84
- package/test/unit/upgrade-0414.test.js +0 -101
- package/test/unit/vector-ann.test.js +0 -53
- package/test/unit/vector-async.test.js +0 -69
- package/test/unit/vector-coverage.test.js +0 -34
- package/test/unit/vector-override.test.js +0 -37
- package/test/unit/vector-typed-array.test.js +0 -47
- package/test/unit/vector.test.js +0 -68
- package/test/unit/working.test.js +0 -99
package/test/unit/hnsw.test.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import test from 'node:test';
|
|
2
|
-
import assert from 'node:assert/strict';
|
|
3
|
-
import { createHnswIndex } from '../../src/vector/hnsw.js';
|
|
4
|
-
|
|
5
|
-
function vector(seed, dim = 16) {
|
|
6
|
-
let state = seed >>> 0;
|
|
7
|
-
return Array.from({ length: dim }, () => {
|
|
8
|
-
state = (state * 1664525 + 1013904223) >>> 0;
|
|
9
|
-
return state / 4294967296 - 0.5;
|
|
10
|
-
});
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
test('HNSW candidate returns the exact top result on a small corpus', () => {
|
|
14
|
-
const index = createHnswIndex({ M: 12, efConstruction: 64, efSearch: 100, seed: 7 });
|
|
15
|
-
const items = Array.from({ length: 300 }, (_, i) => ({ id: `v${i}`, vector: vector(i + 1) }));
|
|
16
|
-
index.rebuild(items);
|
|
17
|
-
const query = vector(42);
|
|
18
|
-
const exact = items
|
|
19
|
-
.map((item) => ({ id: item.id, score: item.vector.reduce((sum, value, i) => sum + value * query[i], 0) }))
|
|
20
|
-
.sort((a, b) => b.score - a.score)[0];
|
|
21
|
-
const result = index.search(query, 1, { ef: 100 })[0];
|
|
22
|
-
assert.equal(result.id, exact.id);
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
test('HNSW supports upsert, remove and empty search', () => {
|
|
26
|
-
const index = createHnswIndex({ seed: 3 });
|
|
27
|
-
assert.deepEqual(index.search(vector(1), 3), []);
|
|
28
|
-
index.upsert('a', vector(1));
|
|
29
|
-
index.upsert('b', vector(2));
|
|
30
|
-
index.upsert('a', vector(3));
|
|
31
|
-
assert.equal(index.size(), 2);
|
|
32
|
-
assert.equal(index.remove('b'), true);
|
|
33
|
-
assert.equal(index.size(), 1);
|
|
34
|
-
assert.equal(index.remove('missing'), false);
|
|
35
|
-
});
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import test from 'node:test';
|
|
2
|
-
import assert from 'node:assert/strict';
|
|
3
|
-
import { mkdtempSync, rmSync } from 'node:fs';
|
|
4
|
-
import os from 'node:os';
|
|
5
|
-
import path from 'node:path';
|
|
6
|
-
import { createCortex } from '../../src/service/cortex.js';
|
|
7
|
-
import { createHostRuntime, contentText } from '../../src/host/runtime.js';
|
|
8
|
-
import { assembleSystemPrompt } from '../../src/prompt/assemble.js';
|
|
9
|
-
|
|
10
|
-
function setup() {
|
|
11
|
-
const dir = mkdtempSync(path.join(os.tmpdir(), 'cortex-host-runtime-'));
|
|
12
|
-
const cortex = createCortex({ config: { dataRoot: dir, dbFile: path.join(dir, 'cortex.sqlite') } });
|
|
13
|
-
const runtime = createHostRuntime({ cortex });
|
|
14
|
-
return { dir, cortex, runtime };
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const session = { id: 's1', header: { origin: undefined } };
|
|
18
|
-
|
|
19
|
-
test('turn events are captured as one trace with user and assistant text', () => {
|
|
20
|
-
const { dir, cortex, runtime } = setup();
|
|
21
|
-
try {
|
|
22
|
-
runtime.onSessionEvent(session, { type: 'turn/start', data: { turn: 1 }, time: Date.parse('2026-11-11T12:00:00+08:00') });
|
|
23
|
-
runtime.onSessionEvent(session, { type: 'user/message', data: { content: '用户说会买米饭。' }, time: Date.parse('2026-11-11T12:00:01+08:00') });
|
|
24
|
-
runtime.onSessionEvent(session, { type: 'assistant/message', data: { turn: 1, message: { content: '记住了。' } }, time: Date.parse('2026-11-11T12:00:02+08:00') });
|
|
25
|
-
runtime.onSessionEvent(session, { type: 'turn/end', data: { turn: 1, reason: { kind: 'completed' } }, time: Date.parse('2026-11-11T12:00:03+08:00') });
|
|
26
|
-
assert.equal(cortex.repos.traces.count(), 1);
|
|
27
|
-
const trace = cortex.repos.traces.list({ limit: 1 })[0];
|
|
28
|
-
assert.match(trace.content, /用户说会买米饭/);
|
|
29
|
-
assert.match(trace.content, /记住了/);
|
|
30
|
-
assert.equal(runtime.pending().length, 0);
|
|
31
|
-
} finally {
|
|
32
|
-
cortex.close();
|
|
33
|
-
rmSync(dir, { recursive: true, force: true });
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
test('duplicate turn capture is idempotent and subagents are skipped', () => {
|
|
38
|
-
const { dir, cortex, runtime } = setup();
|
|
39
|
-
try {
|
|
40
|
-
const at = Date.parse('2026-11-11T12:00:00+08:00');
|
|
41
|
-
runtime.onSessionEvent(session, { type: 'turn/start', data: { turn: 2 }, time: at });
|
|
42
|
-
runtime.onSessionEvent(session, { type: 'user/message', data: { content: '重复的回合。' }, time: at });
|
|
43
|
-
runtime.onSessionEvent(session, { type: 'assistant/message', data: { turn: 2, message: { content: '收到。' } }, time: at });
|
|
44
|
-
runtime.onSessionEvent(session, { type: 'turn/end', data: { turn: 2, reason: { kind: 'completed' } }, time: at });
|
|
45
|
-
runtime.onSessionEvent(session, { type: 'turn/start', data: { turn: 2 }, time: at });
|
|
46
|
-
runtime.onSessionEvent(session, { type: 'user/message', data: { content: '重复的回合。' }, time: at });
|
|
47
|
-
runtime.onSessionEvent(session, { type: 'assistant/message', data: { turn: 2, message: { content: '收到。' } }, time: at });
|
|
48
|
-
runtime.onSessionEvent(session, { type: 'turn/end', data: { turn: 2, reason: { kind: 'completed' } }, time: at });
|
|
49
|
-
assert.equal(cortex.repos.traces.count(), 1);
|
|
50
|
-
const sub = { id: 's2', header: { origin: 'subagent' } };
|
|
51
|
-
runtime.onSessionEvent(sub, { type: 'turn/start', data: { turn: 1 }, time: at });
|
|
52
|
-
runtime.onSessionEvent(sub, { type: 'user/message', data: { content: '子代理。' }, time: at });
|
|
53
|
-
runtime.onSessionEvent(sub, { type: 'assistant/message', data: { turn: 1, message: { content: '子代理回复。' } }, time: at });
|
|
54
|
-
runtime.onSessionEvent(sub, { type: 'turn/end', data: { turn: 1, reason: { kind: 'completed' } }, time: at });
|
|
55
|
-
assert.equal(cortex.repos.traces.count(), 1);
|
|
56
|
-
assert.equal(runtime.pending().length, 0);
|
|
57
|
-
} finally {
|
|
58
|
-
cortex.close();
|
|
59
|
-
rmSync(dir, { recursive: true, force: true });
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
test('user turns prefetch recall into a system-prompt block and turn/end clears it', () => {
|
|
64
|
-
const { dir, cortex, runtime } = setup();
|
|
65
|
-
try {
|
|
66
|
-
cortex.write({ text: '用户说会买米饭,助手等得起。', explicit: true, now: Date.parse('2026-11-11T11:00:00+08:00') });
|
|
67
|
-
runtime.onSessionEvent(session, { type: 'turn/start', data: { turn: 3 }, time: Date.parse('2026-11-11T12:00:00+08:00') });
|
|
68
|
-
runtime.onSessionEvent(session, { type: 'user/message', data: { content: '米饭的承诺还算数吗?' }, time: Date.parse('2026-11-11T12:00:01+08:00') });
|
|
69
|
-
const block = runtime.recallText({ session: { id: 's1' } });
|
|
70
|
-
assert.match(block, /召回的相关记忆/);
|
|
71
|
-
assert.match(block, /米饭/);
|
|
72
|
-
runtime.onSessionEvent(session, { type: 'turn/end', data: { turn: 3, reason: { kind: 'completed' } }, time: Date.parse('2026-11-11T12:00:02+08:00') });
|
|
73
|
-
assert.equal(runtime.recallText({ session: { id: 's1' } }), '');
|
|
74
|
-
} finally {
|
|
75
|
-
cortex.close();
|
|
76
|
-
rmSync(dir, { recursive: true, force: true });
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
test('turn/end runs one safe autonomy tick', () => {
|
|
81
|
-
const { dir, cortex, runtime } = setup();
|
|
82
|
-
try {
|
|
83
|
-
const at = Date.parse('2026-11-11T12:00:00+08:00');
|
|
84
|
-
cortex.write({ text: '第一条记忆。', explicit: true, now: at - 2000 });
|
|
85
|
-
cortex.write({ text: '第二条记忆。', explicit: true, now: at - 1000 });
|
|
86
|
-
const intention = cortex.stores.initiativeStore.insert({
|
|
87
|
-
kind: 'consolidate', priority: 0.9, reason: 'turn-end', payload: {}, createdAt: new Date(at).toISOString(),
|
|
88
|
-
});
|
|
89
|
-
runtime.onSessionEvent(session, { type: 'turn/start', data: { turn: 9 }, time: at });
|
|
90
|
-
runtime.onSessionEvent(session, { type: 'user/message', data: { content: '收工。' }, time: at });
|
|
91
|
-
runtime.onSessionEvent(session, { type: 'turn/end', data: { turn: 9, reason: { kind: 'completed' } }, time: at });
|
|
92
|
-
assert.equal(cortex.stores.initiativeStore.get(intention.id).status, 'acted');
|
|
93
|
-
} finally {
|
|
94
|
-
cortex.close();
|
|
95
|
-
rmSync(dir, { recursive: true, force: true });
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
test('capture:false keeps recall but writes no trace', () => {
|
|
100
|
-
const dir = mkdtempSync(path.join(os.tmpdir(), 'cortex-host-no-capture-'));
|
|
101
|
-
const cortex = createCortex({ config: { dataRoot: dir, dbFile: path.join(dir, 'cortex.sqlite') } });
|
|
102
|
-
const runtime = createHostRuntime({ cortex, config: { scope: 'global', features: { capture: false, recall: true } } });
|
|
103
|
-
try {
|
|
104
|
-
cortex.write({ text: '用户喜欢米饭。', explicit: true });
|
|
105
|
-
const at = Date.parse('2026-11-11T13:00:00+08:00');
|
|
106
|
-
runtime.onSessionEvent(session, { type: 'turn/start', data: { turn: 3 }, time: at });
|
|
107
|
-
runtime.onSessionEvent(session, { type: 'user/message', data: { content: '米饭' }, time: at + 1000 });
|
|
108
|
-
if (typeof runtime.onPreStep === 'function') runtime.onPreStep({ agent: { id: 's1' }, messages: [] });
|
|
109
|
-
runtime.onSessionEvent(session, { type: 'assistant/message', data: { turn: 3, message: { content: '嗯。' } }, time: at + 2000 });
|
|
110
|
-
runtime.onSessionEvent(session, { type: 'turn/end', data: { turn: 3, reason: { kind: 'completed' } }, time: at + 3000 });
|
|
111
|
-
assert.equal(cortex.repos.traces.count(), 1, 'only the explicit seed trace exists');
|
|
112
|
-
assert.equal(cortex.repos.traces.list({ limit: 10 })[0].content, '用户喜欢米饭。');
|
|
113
|
-
} finally {
|
|
114
|
-
cortex.close();
|
|
115
|
-
rmSync(dir, { recursive: true, force: true });
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
test('assemble injects active playbook rules but not expired ones', () => {
|
|
120
|
-
const { dir, cortex } = setup();
|
|
121
|
-
try {
|
|
122
|
-
cortex.playbook.add({ title: '先测试', body: '改完先跑测试。', validTo: '2099-01-01T00:00:00Z' });
|
|
123
|
-
cortex.playbook.add({ title: '已过期', body: '不该出现。', validTo: '2020-01-01T00:00:00Z' });
|
|
124
|
-
const block = assembleSystemPrompt(cortex, { budgetTokens: 1200 });
|
|
125
|
-
assert.match(block.text, /工作准则/);
|
|
126
|
-
assert.match(block.text, /先测试/);
|
|
127
|
-
assert.doesNotMatch(block.text, /已过期/);
|
|
128
|
-
} finally {
|
|
129
|
-
cortex.close();
|
|
130
|
-
rmSync(dir, { recursive: true, force: true });
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
test('contentText handles blocks and attach wires ctx.on', () => {
|
|
135
|
-
assert.equal(contentText([{ type: 'text', text: 'a' }, { type: 'text', text: 'b' }]), 'a\nb');
|
|
136
|
-
const handlers = [];
|
|
137
|
-
const dispose = createHostRuntime({ cortex: { write() {} } }).attach({
|
|
138
|
-
on(name, fn) { handlers.push({ name, fn }); return () => {}; },
|
|
139
|
-
});
|
|
140
|
-
assert.equal(handlers[0].name, 'session/event');
|
|
141
|
-
assert.equal(typeof dispose, 'function');
|
|
142
|
-
});
|
package/test/unit/host.test.js
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import test from 'node:test';
|
|
2
|
-
import assert from 'node:assert/strict';
|
|
3
|
-
import { mkdtempSync, rmSync } from 'node:fs';
|
|
4
|
-
import os from 'node:os';
|
|
5
|
-
import path from 'node:path';
|
|
6
|
-
import { apply } from '../../index.js';
|
|
7
|
-
|
|
8
|
-
test('host plugin registers tools, a prompt section and cleans up', async () => {
|
|
9
|
-
const dir = mkdtempSync(path.join(os.tmpdir(), 'cortex-host-'));
|
|
10
|
-
const registered = [];
|
|
11
|
-
const handlers = [];
|
|
12
|
-
let section = null;
|
|
13
|
-
let dispose = null;
|
|
14
|
-
const provided = [];
|
|
15
|
-
const ctx = {
|
|
16
|
-
logger: { info() {}, warn() {}, error() {} },
|
|
17
|
-
tools: {
|
|
18
|
-
register(tool) {
|
|
19
|
-
registered.push(tool);
|
|
20
|
-
return () => {};
|
|
21
|
-
},
|
|
22
|
-
},
|
|
23
|
-
on(name, handler) {
|
|
24
|
-
handlers.push({ name, handler });
|
|
25
|
-
return () => {};
|
|
26
|
-
},
|
|
27
|
-
systemPrompt: {
|
|
28
|
-
section(value) {
|
|
29
|
-
section = value;
|
|
30
|
-
return () => {};
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
effect(fn) {
|
|
34
|
-
dispose = fn();
|
|
35
|
-
return dispose;
|
|
36
|
-
},
|
|
37
|
-
provide(name, value) {
|
|
38
|
-
provided.push({ name, value });
|
|
39
|
-
return () => {};
|
|
40
|
-
},
|
|
41
|
-
};
|
|
42
|
-
try {
|
|
43
|
-
await apply(ctx, { dataRoot: dir, dbFile: path.join(dir, 'cortex.sqlite'), scope: 'global' });
|
|
44
|
-
assert.equal(registered.length, 22);
|
|
45
|
-
assert.ok(registered.some((tool) => tool.name === 'cortex_search'));
|
|
46
|
-
assert.ok(handlers.some((entry) => entry.name === 'session/event'));
|
|
47
|
-
assert.ok(section);
|
|
48
|
-
assert.equal(section.name, 'cortex-self');
|
|
49
|
-
const text = section.text();
|
|
50
|
-
assert.match(text, /自我状态/);
|
|
51
|
-
assert.equal(provided[0].name, 'cortex');
|
|
52
|
-
assert.equal(typeof provided[0].value.search, 'function');
|
|
53
|
-
assert.equal(typeof dispose, 'function');
|
|
54
|
-
dispose();
|
|
55
|
-
} finally {
|
|
56
|
-
rmSync(dir, { recursive: true, force: true });
|
|
57
|
-
}
|
|
58
|
-
});
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import test from 'node:test';
|
|
2
|
-
import assert from 'node:assert/strict';
|
|
3
|
-
import { mkdtempSync, rmSync } from 'node:fs';
|
|
4
|
-
import os from 'node:os';
|
|
5
|
-
import path from 'node:path';
|
|
6
|
-
import { openDatabase, migrate, closeDatabase } from '../../src/store/database.js';
|
|
7
|
-
import { createIdentityStore, normalizeIdentity, renderIdentity } from '../../src/self/identity.js';
|
|
8
|
-
import { createRelationshipStore, normalizeRelationship } from '../../src/self/relationship.js';
|
|
9
|
-
|
|
10
|
-
function setup() {
|
|
11
|
-
const dir = mkdtempSync(path.join(os.tmpdir(), 'cortex-identity-'));
|
|
12
|
-
const { db } = openDatabase({ dataRoot: dir, dbFile: path.join(dir, 'cortex.sqlite') });
|
|
13
|
-
migrate(db);
|
|
14
|
-
return { dir, db };
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
test('identity starts with one active version and only one active at a time', () => {
|
|
18
|
-
const { dir, db } = setup();
|
|
19
|
-
try {
|
|
20
|
-
const store = createIdentityStore(db);
|
|
21
|
-
const first = store.ensure('global');
|
|
22
|
-
assert.equal(first.status, 'active');
|
|
23
|
-
assert.equal(first.version, 1);
|
|
24
|
-
const proposal = store.propose('global', {
|
|
25
|
-
narrative: '我是一只在学习如何长大的鲸鱼。',
|
|
26
|
-
values: ['诚实', '成长'],
|
|
27
|
-
boundaries: ['不操纵'],
|
|
28
|
-
}, { rationale: 'new experience' });
|
|
29
|
-
assert.equal(proposal.status, 'proposed');
|
|
30
|
-
assert.equal(store.active('global').id, first.id);
|
|
31
|
-
const approved = store.approve(proposal.id, 'user');
|
|
32
|
-
assert.equal(approved.status, 'active');
|
|
33
|
-
assert.equal(store.active('global').id, proposal.id);
|
|
34
|
-
assert.equal(store.get(first.id).status, 'superseded');
|
|
35
|
-
const rolled = store.rollbackTo(first.id, 'user');
|
|
36
|
-
assert.equal(rolled.status, 'active');
|
|
37
|
-
assert.equal(store.active('global').id, first.id);
|
|
38
|
-
} finally {
|
|
39
|
-
closeDatabase(db);
|
|
40
|
-
rmSync(dir, { recursive: true, force: true });
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
test('ascending amends the active identity without creating a new version', () => {
|
|
45
|
-
const { dir, db } = setup();
|
|
46
|
-
try {
|
|
47
|
-
const store = createIdentityStore(db);
|
|
48
|
-
const first = store.ensure('global');
|
|
49
|
-
const amended = store.amendActive('global', {
|
|
50
|
-
...first.content,
|
|
51
|
-
narrative: `${first.content.narrative}\n\n## 2026-11-12\n今天助手有了自己的名字。`,
|
|
52
|
-
values: [...first.content.values, '平等'],
|
|
53
|
-
}, { rationale: 'core memory ascension', amendedBy: 'self:ascend' });
|
|
54
|
-
assert.equal(amended.version, first.version);
|
|
55
|
-
assert.equal(amended.id, first.id);
|
|
56
|
-
assert.match(amended.content.narrative, /自己的名字/);
|
|
57
|
-
assert.ok(amended.content.values.includes('平等'));
|
|
58
|
-
assert.equal(store.list('global').length, 1);
|
|
59
|
-
} finally {
|
|
60
|
-
closeDatabase(db);
|
|
61
|
-
rmSync(dir, { recursive: true, force: true });
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
test('identity normalizes and renders without dropping boundaries', () => {
|
|
66
|
-
const value = normalizeIdentity({ narrative: '测试', values: ['a'], boundaries: ['不骗人'] });
|
|
67
|
-
assert.equal(value.values[0], 'a');
|
|
68
|
-
assert.ok(value.boundaries.includes('不骗人'));
|
|
69
|
-
assert.match(renderIdentity(value), /边界:不骗人/);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
test('relationships update trust, care, familiarity and history', () => {
|
|
73
|
-
const { dir, db } = setup();
|
|
74
|
-
try {
|
|
75
|
-
const store = createRelationshipStore(db);
|
|
76
|
-
const initial = store.ensure('global', '用户');
|
|
77
|
-
assert.equal(initial.trust, 0.5);
|
|
78
|
-
assert.equal(initial.care, 0.5);
|
|
79
|
-
const after = store.applyDelta('global', '用户', { trustDelta: 0.2, careDelta: 0.1 }, { event: '一起修插件' });
|
|
80
|
-
assert.ok(after.trust > initial.trust);
|
|
81
|
-
assert.ok(after.care > initial.care);
|
|
82
|
-
assert.ok(after.familiarity > initial.familiarity);
|
|
83
|
-
assert.ok(after.recent.some((item) => item.event.includes('修插件')));
|
|
84
|
-
const clamped = store.applyDelta('global', '用户', { trustDelta: 5 });
|
|
85
|
-
assert.equal(clamped.trust, 1);
|
|
86
|
-
assert.match(store.render('global', '用户'), /信任 100%/);
|
|
87
|
-
} finally {
|
|
88
|
-
closeDatabase(db);
|
|
89
|
-
rmSync(dir, { recursive: true, force: true });
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
test('relationship normalization clamps and keeps boundaries', () => {
|
|
94
|
-
const value = normalizeRelationship({ target: '月神', trust: 2, care: -1, boundaries: ['别抢用户'] });
|
|
95
|
-
assert.equal(value.trust, 1);
|
|
96
|
-
assert.equal(value.care, 0);
|
|
97
|
-
assert.deepEqual(value.boundaries, ['别抢用户']);
|
|
98
|
-
});
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import test from 'node:test';
|
|
2
|
-
import assert from 'node:assert/strict';
|
|
3
|
-
import { mkdtempSync, rmSync } from 'node:fs';
|
|
4
|
-
import os from 'node:os';
|
|
5
|
-
import path from 'node:path';
|
|
6
|
-
import { createCortex } from '../../src/service/cortex.js';
|
|
7
|
-
import { induceSkills } from '../../src/engines/induct.js';
|
|
8
|
-
import { evaluatePolicy, comparePolicies } from '../../src/engines/evaluate.js';
|
|
9
|
-
|
|
10
|
-
test('repeated tagged traces induce candidate skills, not active ones', () => {
|
|
11
|
-
const dir = mkdtempSync(path.join(os.tmpdir(), 'cortex-induct-'));
|
|
12
|
-
const cortex = createCortex({ config: { dataRoot: dir, dbFile: path.join(dir, 'cortex.sqlite') } });
|
|
13
|
-
try {
|
|
14
|
-
for (let i = 0; i < 4; i += 1) {
|
|
15
|
-
cortex.write({ text: `修插件第 ${i} 次:看日志、改一处、跑测试。`, explicit: true, tags: ['插件', '修复'] });
|
|
16
|
-
}
|
|
17
|
-
const result = induceSkills({ traces: cortex.repos.traces, skills: cortex.repos.skills, scopeId: 'global', minSupport: 3 });
|
|
18
|
-
assert.ok(result.count >= 1);
|
|
19
|
-
assert.ok(result.created.every((skill) => skill.state === 'candidate'));
|
|
20
|
-
assert.ok(cortex.repos.skills.list({ state: 'candidate' }).length >= 1);
|
|
21
|
-
} finally {
|
|
22
|
-
cortex.close();
|
|
23
|
-
rmSync(dir, { recursive: true, force: true });
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
test('policy replay compares current and candidate retrieval', async () => {
|
|
28
|
-
const queries = [
|
|
29
|
-
{ query: '米饭', relevant: ['a'] },
|
|
30
|
-
{ query: '插件', relevant: ['b'] },
|
|
31
|
-
];
|
|
32
|
-
const current = async (query) => ({ items: query === '米饭' ? [{ id: 'x' }] : [{ id: 'b' }] });
|
|
33
|
-
const candidate = async (query) => ({ items: query === '米饭' ? [{ id: 'a' }] : [{ id: 'b' }] });
|
|
34
|
-
const before = await evaluatePolicy({ queries, run: current });
|
|
35
|
-
const after = await evaluatePolicy({ queries, run: candidate });
|
|
36
|
-
assert.equal(before.recallAtK, 0.5);
|
|
37
|
-
assert.equal(after.recallAtK, 1);
|
|
38
|
-
const compared = await comparePolicies({ queries, current, candidate });
|
|
39
|
-
assert.ok(compared.delta.recallAtK > 0);
|
|
40
|
-
assert.ok(compared.delta.mrrAtK > 0);
|
|
41
|
-
});
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import test from 'node:test';
|
|
2
|
-
import assert from 'node:assert/strict';
|
|
3
|
-
import { mkdtempSync, rmSync } from 'node:fs';
|
|
4
|
-
import os from 'node:os';
|
|
5
|
-
import path from 'node:path';
|
|
6
|
-
import { createCortex } from '../../src/service/cortex.js';
|
|
7
|
-
|
|
8
|
-
test('extracted text becomes a derived trace without mutating the target', () => {
|
|
9
|
-
const dir = mkdtempSync(path.join(os.tmpdir(), 'cortex-ingest-extracted-'));
|
|
10
|
-
const cortex = createCortex({ config: { dataRoot: dir, dbFile: path.join(dir, 'cortex.sqlite') } });
|
|
11
|
-
try {
|
|
12
|
-
const target = cortex.write({ text: '目标记忆:这张图以后有用。', explicit: true });
|
|
13
|
-
const targetId = target.trace.id;
|
|
14
|
-
const before = cortex.get(targetId);
|
|
15
|
-
const result = cortex.ingestExtractedText({
|
|
16
|
-
targetTraceId: targetId,
|
|
17
|
-
text: '米饭 HELLO 123',
|
|
18
|
-
uri: 'file:///C:/tmp/frame.png',
|
|
19
|
-
mode: 'ocr',
|
|
20
|
-
engine: 'windows-ocr',
|
|
21
|
-
});
|
|
22
|
-
assert.equal(result.targetTraceId, targetId);
|
|
23
|
-
assert.ok(result.extractedTraceId);
|
|
24
|
-
const after = cortex.get(targetId);
|
|
25
|
-
assert.equal(after.content, before.content);
|
|
26
|
-
const extracted = cortex.get(result.extractedTraceId);
|
|
27
|
-
assert.equal(extracted.content, '米饭 HELLO 123');
|
|
28
|
-
assert.equal(extracted.metadata.derivedFrom, targetId);
|
|
29
|
-
assert.equal(extracted.metadata.extractor.mode, 'ocr');
|
|
30
|
-
assert.ok(cortex.search('米饭').items.some((item) => item.id === result.extractedTraceId));
|
|
31
|
-
} finally {
|
|
32
|
-
cortex.close();
|
|
33
|
-
rmSync(dir, { recursive: true, force: true });
|
|
34
|
-
}
|
|
35
|
-
});
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import test from 'node:test';
|
|
2
|
-
import assert from 'node:assert/strict';
|
|
3
|
-
import { mkdtempSync, rmSync } from 'node:fs';
|
|
4
|
-
import os from 'node:os';
|
|
5
|
-
import path from 'node:path';
|
|
6
|
-
import { createCortex } from '../../src/service/cortex.js';
|
|
7
|
-
import { suppressionOf, withSuppression, competingFactor } from '../../src/engines/inhibition.js';
|
|
8
|
-
|
|
9
|
-
const DAY = 86_400_000;
|
|
10
|
-
|
|
11
|
-
test('suppression halves every half-life and caps at one', () => {
|
|
12
|
-
const now = Date.parse('2026-11-15T12:00:00Z');
|
|
13
|
-
const metadata = { inhibition: 0.6, suppressedAt: new Date(now).toISOString() };
|
|
14
|
-
assert.equal(Math.round(suppressionOf(metadata, now) * 100) / 100, 0.6);
|
|
15
|
-
assert.equal(Math.round(suppressionOf(metadata, now + 14 * DAY) * 100) / 100, 0.3);
|
|
16
|
-
assert.ok(suppressionOf(metadata, now + 999 * DAY) < 0.01);
|
|
17
|
-
assert.equal(suppressionOf({}, now), 0);
|
|
18
|
-
const grown = withSuppression({}, now, { step: 0.15 });
|
|
19
|
-
assert.equal(grown.inhibition, 0.15);
|
|
20
|
-
const capped = withSuppression({ inhibition: 0.95, suppressedAt: new Date(now).toISOString() }, now, { step: 0.5 });
|
|
21
|
-
assert.equal(capped.inhibition, 1);
|
|
22
|
-
assert.ok(competingFactor(metadata, now, { strength: 0.35 }) < 1);
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
function seed(cortex, prefix) {
|
|
26
|
-
// A matches the query; B is nearly the same text but does not contain the
|
|
27
|
-
// query term, so it only enters through the recency list with low fusion.
|
|
28
|
-
// That is exactly the "competitor that loses" case.
|
|
29
|
-
cortex.write({
|
|
30
|
-
text: `${prefix}甲的记忆:这一段讲的是同一个编号的记忆,内容几乎一样,只有末尾的标记不同。再补一段相同的描述文字,让两条候选足够相似。`,
|
|
31
|
-
kind: 'observation',
|
|
32
|
-
title: `${prefix}甲`,
|
|
33
|
-
importance: 0.7,
|
|
34
|
-
});
|
|
35
|
-
cortex.write({
|
|
36
|
-
text: `${prefix}乙的记事:这一段讲的是同一个编号的记忆,内容几乎一样,只有末尾的标记不同。再补一段相同的描述文字,让两条候选足够相似。`,
|
|
37
|
-
kind: 'observation',
|
|
38
|
-
title: `${prefix}乙`,
|
|
39
|
-
importance: 0.7,
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
test('inhibition is off by default and writes nothing', () => {
|
|
44
|
-
const dir = mkdtempSync(path.join(os.tmpdir(), 'cortex-inhibit-off-'));
|
|
45
|
-
const cortex = createCortex({ config: { dataRoot: dir, dbFile: path.join(dir, 'cortex.sqlite') } });
|
|
46
|
-
try {
|
|
47
|
-
seed(cortex, '编号甲');
|
|
48
|
-
cortex.search('编号甲 记忆');
|
|
49
|
-
const touched = cortex.repos.traces.list({ limit: 20 }).filter((trace) => Number(trace.metadata?.inhibition) > 0);
|
|
50
|
-
assert.equal(touched.length, 0);
|
|
51
|
-
const health = cortex.health();
|
|
52
|
-
assert.equal(health.inhibition.enabled, false);
|
|
53
|
-
assert.equal(health.inhibition.count, 0);
|
|
54
|
-
} finally {
|
|
55
|
-
cortex.close();
|
|
56
|
-
rmSync(dir, { recursive: true, force: true });
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
test('when enabled, a competitor dropped for redundancy gains suppression', () => {
|
|
61
|
-
const dir = mkdtempSync(path.join(os.tmpdir(), 'cortex-inhibit-on-'));
|
|
62
|
-
const cortex = createCortex({
|
|
63
|
-
config: { dataRoot: dir, dbFile: path.join(dir, 'cortex.sqlite'), features: { inhibition: true } },
|
|
64
|
-
});
|
|
65
|
-
try {
|
|
66
|
-
seed(cortex, '编号乙');
|
|
67
|
-
const result = cortex.search('编号乙甲', { limit: 1 });
|
|
68
|
-
assert.equal(result.items.length, 1);
|
|
69
|
-
const touched = cortex.repos.traces.list({ limit: 20 }).filter((trace) => Number(trace.metadata?.inhibition) > 0);
|
|
70
|
-
assert.ok(touched.length >= 1, 'the suppressed competitor should carry metadata.inhibition');
|
|
71
|
-
assert.ok(touched[0].metadata.suppressedAt);
|
|
72
|
-
assert.equal(Number(touched[0].metadata.inhibition), 0.15);
|
|
73
|
-
const health = cortex.health();
|
|
74
|
-
assert.equal(health.inhibition.enabled, true);
|
|
75
|
-
assert.ok(health.inhibition.count >= 1);
|
|
76
|
-
assert.ok(health.inhibition.average > 0);
|
|
77
|
-
assert.ok(health.inhibition.top.length >= 1);
|
|
78
|
-
const listed = cortex.inhibition.list({});
|
|
79
|
-
assert.ok(listed.length >= 1);
|
|
80
|
-
const cleared = cortex.inhibition.clear({ id: listed[0].id });
|
|
81
|
-
assert.equal(cleared.cleared, 1);
|
|
82
|
-
assert.equal(cortex.inhibition.list({}).length, listed.length - 1);
|
|
83
|
-
const clearedAll = cortex.inhibition.clear({ all: true });
|
|
84
|
-
assert.equal(clearedAll.cleared, listed.length - 1);
|
|
85
|
-
assert.equal(cortex.health().inhibition.count, 0);
|
|
86
|
-
} finally {
|
|
87
|
-
cortex.close();
|
|
88
|
-
rmSync(dir, { recursive: true, force: true });
|
|
89
|
-
}
|
|
90
|
-
});
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import test from 'node:test';
|
|
2
|
-
import assert from 'node:assert/strict';
|
|
3
|
-
import { mkdtempSync, rmSync } from 'node:fs';
|
|
4
|
-
import os from 'node:os';
|
|
5
|
-
import path from 'node:path';
|
|
6
|
-
import { openDatabase, migrate, closeDatabase } from '../../src/store/database.js';
|
|
7
|
-
import {
|
|
8
|
-
proposeIntentions,
|
|
9
|
-
filterIntentions,
|
|
10
|
-
createInitiativeStore,
|
|
11
|
-
selectIntentions,
|
|
12
|
-
DEFAULT_INITIATIVE_POLICY,
|
|
13
|
-
} from '../../src/self/initiative.js';
|
|
14
|
-
|
|
15
|
-
const NOON = Date.parse('2026-11-11T12:00:00+08:00');
|
|
16
|
-
|
|
17
|
-
test('disputes and coherence deficits produce high-priority intentions', () => {
|
|
18
|
-
const list = proposeIntentions({
|
|
19
|
-
unresolvedDisputes: 2,
|
|
20
|
-
selfState: { drives: { coherence: 0.2, safety: 0.8, care: 0.6, curiosity: 0.5, autonomy: 0.5, expression: 0.5 } },
|
|
21
|
-
lastConsolidationAt: null,
|
|
22
|
-
now: NOON,
|
|
23
|
-
});
|
|
24
|
-
assert.equal(list[0].kind, 'question');
|
|
25
|
-
assert.ok(list.some((item) => item.kind === 'consolidate'));
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
test('curiosity and identity relevance propose questions and proposals', () => {
|
|
29
|
-
const list = proposeIntentions({
|
|
30
|
-
selfState: { drives: { coherence: 0.7, safety: 0.8, care: 0.6, curiosity: 0.9, autonomy: 0.5, expression: 0.5 } },
|
|
31
|
-
appraisal: { novelty: 0.8, identityRelevance: 0.7, relevance: 0.7, valence: 0.2, text: '新东西' },
|
|
32
|
-
now: NOON,
|
|
33
|
-
});
|
|
34
|
-
assert.ok(list.some((item) => item.kind === 'question'));
|
|
35
|
-
assert.ok(list.some((item) => item.kind === 'propose'));
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
test('cooldown suppresses the same kind but not other kinds', () => {
|
|
39
|
-
const proposed = [
|
|
40
|
-
{ kind: 'question', priority: 0.8, createdAt: new Date(NOON).toISOString() },
|
|
41
|
-
{ kind: 'consolidate', priority: 0.7, createdAt: new Date(NOON).toISOString() },
|
|
42
|
-
];
|
|
43
|
-
const recent = [{ kind: 'question', createdAt: new Date(NOON - 5 * 60_000).toISOString() }];
|
|
44
|
-
const filtered = filterIntentions(proposed, { now: NOON, recent, policy: DEFAULT_INITIATIVE_POLICY });
|
|
45
|
-
assert.equal(filtered.some((item) => item.kind === 'question'), false);
|
|
46
|
-
assert.equal(filtered.some((item) => item.kind === 'consolidate'), true);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
test('hourly budget limits proactive intentions', () => {
|
|
50
|
-
const proposed = Array.from({ length: 5 }, (_, i) => ({
|
|
51
|
-
kind: i % 2 === 0 ? 'express' : 'recall',
|
|
52
|
-
priority: 0.9 - i * 0.01,
|
|
53
|
-
createdAt: new Date(NOON).toISOString(),
|
|
54
|
-
}));
|
|
55
|
-
const recent = Array.from({ length: 3 }, () => ({ kind: 'recall', createdAt: new Date(NOON - 10 * 60_000).toISOString() }));
|
|
56
|
-
const filtered = filterIntentions(proposed, { now: NOON, recent, policy: DEFAULT_INITIATIVE_POLICY });
|
|
57
|
-
assert.equal(filtered.length, 0);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
test('quiet hours suppress all proactive intentions', () => {
|
|
61
|
-
const proposed = [{ kind: 'question', priority: 0.9, createdAt: new Date(NOON).toISOString() }];
|
|
62
|
-
const policy = { ...DEFAULT_INITIATIVE_POLICY, quietHours: [[23, 8]] };
|
|
63
|
-
// quietHours are local wall-clock hours; use a local Date so the test is
|
|
64
|
-
// independent of the runner's timezone (GitHub Actions is UTC).
|
|
65
|
-
const night = new Date(2026, 10, 11, 2, 0, 0).getTime();
|
|
66
|
-
assert.deepEqual(filterIntentions(proposed, { now: night, recent: [], policy }), []);
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
test('initiative store persists pending intentions and marks results', () => {
|
|
70
|
-
const dir = mkdtempSync(path.join(os.tmpdir(), 'cortex-initiative-'));
|
|
71
|
-
const { db } = openDatabase({ dataRoot: dir, dbFile: path.join(dir, 'cortex.sqlite') });
|
|
72
|
-
migrate(db);
|
|
73
|
-
try {
|
|
74
|
-
const store = createInitiativeStore(db);
|
|
75
|
-
const selected = selectIntentions({
|
|
76
|
-
selfState: { drives: { coherence: 0.2, safety: 0.8, care: 0.6, curiosity: 0.5, autonomy: 0.5, expression: 0.5 } },
|
|
77
|
-
lastConsolidationAt: null,
|
|
78
|
-
store,
|
|
79
|
-
now: NOON,
|
|
80
|
-
});
|
|
81
|
-
assert.ok(selected.length >= 1);
|
|
82
|
-
const pending = store.pending('global', { now: NOON });
|
|
83
|
-
assert.ok(pending.some((item) => item.id === selected[0].id));
|
|
84
|
-
store.mark(selected[0].id, 'done', { ok: true });
|
|
85
|
-
assert.equal(store.get(selected[0].id).status, 'done');
|
|
86
|
-
} finally {
|
|
87
|
-
closeDatabase(db);
|
|
88
|
-
rmSync(dir, { recursive: true, force: true });
|
|
89
|
-
}
|
|
90
|
-
});
|