@modusensus/dsh-mneme 0.6.6 → 0.6.8
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/LICENSE +21 -21
- package/README.md +463 -457
- package/cordis.patch.yml +15 -15
- package/lib/api.js +783 -693
- package/lib/client.js +1757 -1656
- package/lib/commands.js +64 -64
- package/lib/config.js +288 -288
- package/lib/dream/clustering.js +118 -118
- package/lib/dream/decisions.js +439 -439
- package/lib/dream/sleep.js +561 -554
- package/lib/dream/tag-extractor.js +156 -156
- package/lib/dream.js +935 -929
- package/lib/embedding.js +154 -154
- package/lib/entities/extractor.js +242 -242
- package/lib/hot-memory.js +53 -53
- package/lib/index.js +361 -361
- package/lib/inject.js +208 -208
- package/lib/local-embedder.js +282 -282
- package/lib/mirror.js +170 -170
- package/lib/parser/tag.js +59 -59
- package/lib/parser/wiki-link.js +38 -38
- package/lib/quality-filter.js +123 -123
- package/lib/reranker.js +218 -218
- package/lib/search/adaptive.js +22 -22
- package/lib/search/bm25.js +96 -96
- package/lib/search/tag-boost.js +61 -61
- package/lib/service.js +1726 -1726
- package/lib/settings.js +172 -142
- package/lib/store.js +2238 -2238
- package/lib/summarize.js +236 -236
- package/lib/tools.js +290 -290
- package/lib/vector-index.js +116 -116
- package/package.json +80 -75
- package/scripts/benchmark-embed.js +201 -201
- package/scripts/benchmark-recall.js +133 -133
- package/scripts/benchmark-rerank.js +166 -166
- package/scripts/e2e-dsh.js +218 -218
- package/scripts/stress-dsh.js +255 -255
- package/scripts/sync-lib.js +52 -52
- package/src/api.js +783 -693
- package/src/commands.js +64 -64
- package/src/config.js +288 -288
- package/src/dream/clustering.js +118 -118
- package/src/dream/decisions.js +439 -439
- package/src/dream/sleep.js +561 -554
- package/src/dream/tag-extractor.js +156 -156
- package/src/dream.js +935 -929
- package/src/embedding.js +154 -154
- package/src/entities/extractor.js +242 -242
- package/src/hot-memory.js +53 -53
- package/src/index.js +361 -361
- package/src/inject.js +208 -208
- package/src/local-embedder.js +282 -282
- package/src/mirror.js +170 -170
- package/src/parser/tag.js +59 -59
- package/src/parser/wiki-link.js +38 -38
- package/src/quality-filter.js +123 -123
- package/src/reranker.js +218 -218
- package/src/search/adaptive.js +22 -22
- package/src/search/bm25.js +96 -96
- package/src/search/tag-boost.js +61 -61
- package/src/service.js +1726 -1726
- package/src/settings.js +172 -142
- package/src/store.js +2238 -2238
- package/src/summarize.js +236 -236
- package/src/tools.js +290 -290
- package/src/vector-index.js +116 -116
- package/test/api.test.js +594 -549
- package/test/audit.test.js +448 -448
- package/test/benchmark.test.js +35 -35
- package/test/boundary-v0625.test.js +82 -82
- package/test/client.test.js +368 -368
- package/test/clustering.test.js +100 -100
- package/test/commands.test.js +69 -69
- package/test/config.test.js +50 -50
- package/test/conflict-freeze.test.js +290 -290
- package/test/directory.test.js +134 -134
- package/test/dream.test.js +903 -901
- package/test/entities.test.js +522 -522
- package/test/epistemic.test.js +298 -298
- package/test/fnew-0112.test.js +311 -311
- package/test/fnew-03.test.js +422 -422
- package/test/graph-api.test.js +175 -175
- package/test/helpers/dream-mock.js +82 -82
- package/test/hot-memory.test.js +174 -174
- package/test/inject.test.js +103 -103
- package/test/llm-audit.test.js +279 -279
- package/test/local-embedder.test.js +227 -227
- package/test/mirror-dirty.test.js +424 -424
- package/test/mirror-edit-digest.test.js +187 -187
- package/test/mirror-generation.test.js +499 -499
- package/test/mirror.test.js +249 -249
- package/test/normalize-decisions.test.js +120 -120
- package/test/peer-blockers.test.js +190 -190
- package/test/policy-epoch.test.js +259 -259
- package/test/provenance.test.js +103 -103
- package/test/quality-filter.test.js +118 -118
- package/test/reasoning-effort.test.js +199 -199
- package/test/recall-evals.test.js +235 -235
- package/test/recall-layer.test.js +315 -315
- package/test/receipt-chain.test.js +451 -451
- package/test/reflection.test.js +226 -226
- package/test/reranker.test.js +240 -240
- package/test/search-fusion.test.js +90 -90
- package/test/semantic.test.js +124 -124
- package/test/service-search.test.js +199 -199
- package/test/service.test.js +435 -435
- package/test/settings.test.js +118 -101
- package/test/sleep.test.js +365 -365
- package/test/store.test.js +436 -436
- package/test/stress.test.js +209 -209
- package/test/summarize.test.js +191 -191
- package/test/tag-boost.test.js +125 -125
- package/test/tag.test.js +312 -312
- package/test/tools.test.js +285 -285
- package/test/vector-index.test.js +221 -221
- package/test/wiki-link.test.js +332 -332
package/test/clustering.test.js
CHANGED
|
@@ -1,100 +1,100 @@
|
|
|
1
|
-
import test from "node:test";
|
|
2
|
-
import assert from "node:assert/strict";
|
|
3
|
-
import { cosineSimilarity, kMeans, clusterMemories, findPotentialConflicts } from "../src/dream/clustering.js";
|
|
4
|
-
|
|
5
|
-
test("cosineSimilarity: identical vectors => 1", () => {
|
|
6
|
-
assert.equal(cosineSimilarity([1, 2, 3], [1, 2, 3]), 1);
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
test("cosineSimilarity: orthogonal vectors => 0 (approx)", () => {
|
|
10
|
-
assert.ok(Math.abs(cosineSimilarity([1, 0], [0, 1])) < 1e-9);
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
test("cosineSimilarity: mismatched or empty lengths => 0", () => {
|
|
14
|
-
assert.equal(cosineSimilarity([1, 2], [1, 2, 3]), 0);
|
|
15
|
-
assert.equal(cosineSimilarity([], []), 0);
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
test("cosineSimilarity: zero-norm vector => 0", () => {
|
|
19
|
-
assert.equal(cosineSimilarity([0, 0], [1, 1]), 0);
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
// Three well-separated point groups in the plane.
|
|
23
|
-
const GROUP1 = [[0, 0], [0, 0.1], [0.1, 0], [0.1, 0.1]];
|
|
24
|
-
const GROUP2 = [[10, 10], [10, 10.1], [10.1, 10], [10.1, 10.1]];
|
|
25
|
-
const GROUP3 = [[-10, -10], [-10, -9.9], [-9.9, -10], [-9.9, -9.9]];
|
|
26
|
-
const SEPARATED = [...GROUP1, ...GROUP2, ...GROUP3];
|
|
27
|
-
|
|
28
|
-
test("kMeans: three separated groups cluster correctly (labels may permute)", () => {
|
|
29
|
-
const clusters = kMeans(SEPARATED, 3, { maxIter: 100 });
|
|
30
|
-
assert.equal(clusters.length, 3);
|
|
31
|
-
// Content-based check: each cluster must fit exactly one expected group.
|
|
32
|
-
const expectedGroups = [[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11]];
|
|
33
|
-
for (const c of clusters) {
|
|
34
|
-
assert.ok(c.length >= 1);
|
|
35
|
-
const fits = expectedGroups.filter((g) => c.every((idx) => g.includes(idx)));
|
|
36
|
-
assert.equal(fits.length, 1, `cluster ${JSON.stringify(c)} spans multiple groups`);
|
|
37
|
-
}
|
|
38
|
-
// Every index assigned exactly once.
|
|
39
|
-
assert.deepEqual(clusters.flat().sort((a, b) => a - b), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
test("kMeans: k >= n returns a single cluster of all indices", () => {
|
|
43
|
-
assert.deepEqual(kMeans(SEPARATED, 12), [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]]);
|
|
44
|
-
assert.deepEqual(kMeans(SEPARATED, 0), [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]]);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
test("kMeans: empty input => no clusters", () => {
|
|
48
|
-
assert.deepEqual(kMeans([], 3), []);
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
test("kMeans: empty clusters get reseeded and still terminate", () => {
|
|
52
|
-
// Many points near two poles with k=3 forces one cluster empty on seed.
|
|
53
|
-
const vectors = [
|
|
54
|
-
...Array.from({ length: 30 }, () => [0, 0]),
|
|
55
|
-
...Array.from({ length: 30 }, () => [1, 1])
|
|
56
|
-
];
|
|
57
|
-
const clusters = kMeans(vectors, 3, { maxIter: 50 });
|
|
58
|
-
assert.equal(clusters.length, 3);
|
|
59
|
-
assert.equal(clusters.flat().length, vectors.length);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
test("clusterMemories: preserves object references and group count", () => {
|
|
63
|
-
const memories = SEPARATED.map((v, i) => ({ id: `m${i}`, type: "project", title: `t${i}` }));
|
|
64
|
-
const groups = clusterMemories(memories, SEPARATED, 3);
|
|
65
|
-
assert.equal(groups.length, 3);
|
|
66
|
-
assert.equal(groups.flat().length, memories.length);
|
|
67
|
-
// Reference identity preserved: every group member is an object from input.
|
|
68
|
-
const all = groups.flat();
|
|
69
|
-
for (const m of all) assert.ok(memories.includes(m), "cluster contains a foreign object");
|
|
70
|
-
// Full coverage: each source object appears exactly once across groups.
|
|
71
|
-
assert.equal(new Set(all).size, memories.length);
|
|
72
|
-
assert.equal(groups.flat().find((m) => m.id === "m5"), memories[5]);
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
test("findPotentialConflicts: only same-type highly-similar pairs reported", () => {
|
|
76
|
-
const memories = [
|
|
77
|
-
{ id: "a", type: "preference", content: "like cold coffee" },
|
|
78
|
-
{ id: "b", type: "preference", content: "hate cold coffee" },
|
|
79
|
-
{ id: "c", type: "project", content: "ship the plugin" }
|
|
80
|
-
];
|
|
81
|
-
const vectors = [
|
|
82
|
-
[1, 0, 0],
|
|
83
|
-
[0.99, 0.02, 0], // nearly parallel to a, same type => conflict
|
|
84
|
-
[0, 1, 0] // different type, ignored even if near
|
|
85
|
-
];
|
|
86
|
-
const pairs = findPotentialConflicts(memories, vectors, 0.85);
|
|
87
|
-
assert.equal(pairs.length, 1);
|
|
88
|
-
assert.equal(pairs[0].a, memories[0]);
|
|
89
|
-
assert.equal(pairs[0].b, memories[1]);
|
|
90
|
-
assert.ok(pairs[0].similarity > 0.85);
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
test("findPotentialConflicts: below threshold or different type => no pairs", () => {
|
|
94
|
-
const memories = [
|
|
95
|
-
{ id: "x", type: "preference" },
|
|
96
|
-
{ id: "y", type: "project" }
|
|
97
|
-
];
|
|
98
|
-
assert.deepEqual(findPotentialConflicts(memories, [[1, 0], [0, 1]]), []);
|
|
99
|
-
assert.deepEqual(findPotentialConflicts(memories, [[1, 0], [0.9, 0.1]], 0.95), []);
|
|
100
|
-
});
|
|
1
|
+
import test from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import { cosineSimilarity, kMeans, clusterMemories, findPotentialConflicts } from "../src/dream/clustering.js";
|
|
4
|
+
|
|
5
|
+
test("cosineSimilarity: identical vectors => 1", () => {
|
|
6
|
+
assert.equal(cosineSimilarity([1, 2, 3], [1, 2, 3]), 1);
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
test("cosineSimilarity: orthogonal vectors => 0 (approx)", () => {
|
|
10
|
+
assert.ok(Math.abs(cosineSimilarity([1, 0], [0, 1])) < 1e-9);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
test("cosineSimilarity: mismatched or empty lengths => 0", () => {
|
|
14
|
+
assert.equal(cosineSimilarity([1, 2], [1, 2, 3]), 0);
|
|
15
|
+
assert.equal(cosineSimilarity([], []), 0);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
test("cosineSimilarity: zero-norm vector => 0", () => {
|
|
19
|
+
assert.equal(cosineSimilarity([0, 0], [1, 1]), 0);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
// Three well-separated point groups in the plane.
|
|
23
|
+
const GROUP1 = [[0, 0], [0, 0.1], [0.1, 0], [0.1, 0.1]];
|
|
24
|
+
const GROUP2 = [[10, 10], [10, 10.1], [10.1, 10], [10.1, 10.1]];
|
|
25
|
+
const GROUP3 = [[-10, -10], [-10, -9.9], [-9.9, -10], [-9.9, -9.9]];
|
|
26
|
+
const SEPARATED = [...GROUP1, ...GROUP2, ...GROUP3];
|
|
27
|
+
|
|
28
|
+
test("kMeans: three separated groups cluster correctly (labels may permute)", () => {
|
|
29
|
+
const clusters = kMeans(SEPARATED, 3, { maxIter: 100 });
|
|
30
|
+
assert.equal(clusters.length, 3);
|
|
31
|
+
// Content-based check: each cluster must fit exactly one expected group.
|
|
32
|
+
const expectedGroups = [[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11]];
|
|
33
|
+
for (const c of clusters) {
|
|
34
|
+
assert.ok(c.length >= 1);
|
|
35
|
+
const fits = expectedGroups.filter((g) => c.every((idx) => g.includes(idx)));
|
|
36
|
+
assert.equal(fits.length, 1, `cluster ${JSON.stringify(c)} spans multiple groups`);
|
|
37
|
+
}
|
|
38
|
+
// Every index assigned exactly once.
|
|
39
|
+
assert.deepEqual(clusters.flat().sort((a, b) => a - b), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test("kMeans: k >= n returns a single cluster of all indices", () => {
|
|
43
|
+
assert.deepEqual(kMeans(SEPARATED, 12), [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]]);
|
|
44
|
+
assert.deepEqual(kMeans(SEPARATED, 0), [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]]);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test("kMeans: empty input => no clusters", () => {
|
|
48
|
+
assert.deepEqual(kMeans([], 3), []);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test("kMeans: empty clusters get reseeded and still terminate", () => {
|
|
52
|
+
// Many points near two poles with k=3 forces one cluster empty on seed.
|
|
53
|
+
const vectors = [
|
|
54
|
+
...Array.from({ length: 30 }, () => [0, 0]),
|
|
55
|
+
...Array.from({ length: 30 }, () => [1, 1])
|
|
56
|
+
];
|
|
57
|
+
const clusters = kMeans(vectors, 3, { maxIter: 50 });
|
|
58
|
+
assert.equal(clusters.length, 3);
|
|
59
|
+
assert.equal(clusters.flat().length, vectors.length);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test("clusterMemories: preserves object references and group count", () => {
|
|
63
|
+
const memories = SEPARATED.map((v, i) => ({ id: `m${i}`, type: "project", title: `t${i}` }));
|
|
64
|
+
const groups = clusterMemories(memories, SEPARATED, 3);
|
|
65
|
+
assert.equal(groups.length, 3);
|
|
66
|
+
assert.equal(groups.flat().length, memories.length);
|
|
67
|
+
// Reference identity preserved: every group member is an object from input.
|
|
68
|
+
const all = groups.flat();
|
|
69
|
+
for (const m of all) assert.ok(memories.includes(m), "cluster contains a foreign object");
|
|
70
|
+
// Full coverage: each source object appears exactly once across groups.
|
|
71
|
+
assert.equal(new Set(all).size, memories.length);
|
|
72
|
+
assert.equal(groups.flat().find((m) => m.id === "m5"), memories[5]);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
test("findPotentialConflicts: only same-type highly-similar pairs reported", () => {
|
|
76
|
+
const memories = [
|
|
77
|
+
{ id: "a", type: "preference", content: "like cold coffee" },
|
|
78
|
+
{ id: "b", type: "preference", content: "hate cold coffee" },
|
|
79
|
+
{ id: "c", type: "project", content: "ship the plugin" }
|
|
80
|
+
];
|
|
81
|
+
const vectors = [
|
|
82
|
+
[1, 0, 0],
|
|
83
|
+
[0.99, 0.02, 0], // nearly parallel to a, same type => conflict
|
|
84
|
+
[0, 1, 0] // different type, ignored even if near
|
|
85
|
+
];
|
|
86
|
+
const pairs = findPotentialConflicts(memories, vectors, 0.85);
|
|
87
|
+
assert.equal(pairs.length, 1);
|
|
88
|
+
assert.equal(pairs[0].a, memories[0]);
|
|
89
|
+
assert.equal(pairs[0].b, memories[1]);
|
|
90
|
+
assert.ok(pairs[0].similarity > 0.85);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
test("findPotentialConflicts: below threshold or different type => no pairs", () => {
|
|
94
|
+
const memories = [
|
|
95
|
+
{ id: "x", type: "preference" },
|
|
96
|
+
{ id: "y", type: "project" }
|
|
97
|
+
];
|
|
98
|
+
assert.deepEqual(findPotentialConflicts(memories, [[1, 0], [0, 1]]), []);
|
|
99
|
+
assert.deepEqual(findPotentialConflicts(memories, [[1, 0], [0.9, 0.1]], 0.95), []);
|
|
100
|
+
});
|
package/test/commands.test.js
CHANGED
|
@@ -1,69 +1,69 @@
|
|
|
1
|
-
import test from "node:test";
|
|
2
|
-
import assert from "node:assert/strict";
|
|
3
|
-
import { createStore } from "../src/store.js";
|
|
4
|
-
import { createSettings } from "../src/settings.js";
|
|
5
|
-
import { createCommandManager } from "../src/commands.js";
|
|
6
|
-
|
|
7
|
-
function setup() {
|
|
8
|
-
const store = createStore(":memory:");
|
|
9
|
-
const settings = createSettings(store.db);
|
|
10
|
-
const registered = new Map(); // name -> definition
|
|
11
|
-
const ctx = {
|
|
12
|
-
commands: {
|
|
13
|
-
register(def) {
|
|
14
|
-
registered.set(def.name, def);
|
|
15
|
-
return () => registered.delete(def.name);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
const manager = createCommandManager({ ctx, settings, logger: null });
|
|
20
|
-
return { store, settings, manager, registered };
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
test("sync registers all stored commands", () => {
|
|
24
|
-
const { store, settings, manager, registered } = setup();
|
|
25
|
-
settings.addCommand({ name: "agenda", description: "d", instruction: "列议程" });
|
|
26
|
-
settings.addCommand({ name: "banner", instruction: "打印横幅" });
|
|
27
|
-
manager.sync();
|
|
28
|
-
assert.equal(registered.size, 2);
|
|
29
|
-
assert.ok(registered.has("agenda") && registered.has("banner"));
|
|
30
|
-
store.close();
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
test("add registers live; remove unregisters live", () => {
|
|
34
|
-
const { store, manager, registered } = setup();
|
|
35
|
-
const cmd = manager.add({ name: "review", description: "r", instruction: "审查代码" });
|
|
36
|
-
assert.ok(registered.has("review"), "registered after add");
|
|
37
|
-
assert.equal(registered.get("review").description, "r");
|
|
38
|
-
assert.equal(manager.remove(cmd.id), true);
|
|
39
|
-
assert.ok(!registered.has("review"), "unregistered after remove");
|
|
40
|
-
store.close();
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
test("handler returns the instruction as success text", async () => {
|
|
44
|
-
const { store, manager, registered } = setup();
|
|
45
|
-
manager.add({ name: "fmt", description: "格式化", instruction: "请按项目的 lint 规则格式化当前文件" });
|
|
46
|
-
const def = registered.get("fmt");
|
|
47
|
-
assert.ok(def, "definition registered");
|
|
48
|
-
const result = await def.handler({ agent: {}, rawInput: "", signal: null });
|
|
49
|
-
assert.equal(result.kind, "success");
|
|
50
|
-
assert.equal(result.text, "请按项目的 lint 规则格式化当前文件");
|
|
51
|
-
store.close();
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
test("remove of missing id returns false", () => {
|
|
55
|
-
const { store, manager } = setup();
|
|
56
|
-
assert.equal(manager.remove("nope"), false);
|
|
57
|
-
store.close();
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
test("dispose unregisters everything", () => {
|
|
61
|
-
const { store, settings, manager, registered } = setup();
|
|
62
|
-
settings.addCommand({ name: "a", instruction: "x" });
|
|
63
|
-
settings.addCommand({ name: "b", instruction: "y" });
|
|
64
|
-
manager.sync();
|
|
65
|
-
assert.equal(registered.size, 2);
|
|
66
|
-
manager.dispose();
|
|
67
|
-
assert.equal(registered.size, 0);
|
|
68
|
-
store.close();
|
|
69
|
-
});
|
|
1
|
+
import test from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import { createStore } from "../src/store.js";
|
|
4
|
+
import { createSettings } from "../src/settings.js";
|
|
5
|
+
import { createCommandManager } from "../src/commands.js";
|
|
6
|
+
|
|
7
|
+
function setup() {
|
|
8
|
+
const store = createStore(":memory:");
|
|
9
|
+
const settings = createSettings(store.db);
|
|
10
|
+
const registered = new Map(); // name -> definition
|
|
11
|
+
const ctx = {
|
|
12
|
+
commands: {
|
|
13
|
+
register(def) {
|
|
14
|
+
registered.set(def.name, def);
|
|
15
|
+
return () => registered.delete(def.name);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
const manager = createCommandManager({ ctx, settings, logger: null });
|
|
20
|
+
return { store, settings, manager, registered };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
test("sync registers all stored commands", () => {
|
|
24
|
+
const { store, settings, manager, registered } = setup();
|
|
25
|
+
settings.addCommand({ name: "agenda", description: "d", instruction: "列议程" });
|
|
26
|
+
settings.addCommand({ name: "banner", instruction: "打印横幅" });
|
|
27
|
+
manager.sync();
|
|
28
|
+
assert.equal(registered.size, 2);
|
|
29
|
+
assert.ok(registered.has("agenda") && registered.has("banner"));
|
|
30
|
+
store.close();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test("add registers live; remove unregisters live", () => {
|
|
34
|
+
const { store, manager, registered } = setup();
|
|
35
|
+
const cmd = manager.add({ name: "review", description: "r", instruction: "审查代码" });
|
|
36
|
+
assert.ok(registered.has("review"), "registered after add");
|
|
37
|
+
assert.equal(registered.get("review").description, "r");
|
|
38
|
+
assert.equal(manager.remove(cmd.id), true);
|
|
39
|
+
assert.ok(!registered.has("review"), "unregistered after remove");
|
|
40
|
+
store.close();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test("handler returns the instruction as success text", async () => {
|
|
44
|
+
const { store, manager, registered } = setup();
|
|
45
|
+
manager.add({ name: "fmt", description: "格式化", instruction: "请按项目的 lint 规则格式化当前文件" });
|
|
46
|
+
const def = registered.get("fmt");
|
|
47
|
+
assert.ok(def, "definition registered");
|
|
48
|
+
const result = await def.handler({ agent: {}, rawInput: "", signal: null });
|
|
49
|
+
assert.equal(result.kind, "success");
|
|
50
|
+
assert.equal(result.text, "请按项目的 lint 规则格式化当前文件");
|
|
51
|
+
store.close();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test("remove of missing id returns false", () => {
|
|
55
|
+
const { store, manager } = setup();
|
|
56
|
+
assert.equal(manager.remove("nope"), false);
|
|
57
|
+
store.close();
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test("dispose unregisters everything", () => {
|
|
61
|
+
const { store, settings, manager, registered } = setup();
|
|
62
|
+
settings.addCommand({ name: "a", instruction: "x" });
|
|
63
|
+
settings.addCommand({ name: "b", instruction: "y" });
|
|
64
|
+
manager.sync();
|
|
65
|
+
assert.equal(registered.size, 2);
|
|
66
|
+
manager.dispose();
|
|
67
|
+
assert.equal(registered.size, 0);
|
|
68
|
+
store.close();
|
|
69
|
+
});
|
package/test/config.test.js
CHANGED
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
import test from "node:test";
|
|
2
|
-
import assert from "node:assert/strict";
|
|
3
|
-
import { readFileSync } from "node:fs";
|
|
4
|
-
import { fileURLToPath } from "node:url";
|
|
5
|
-
import { Config } from "../src/config.js";
|
|
6
|
-
|
|
7
|
-
// ---------------------------------------------------------------- rerank opt-in (item ⑥)
|
|
8
|
-
|
|
9
|
-
test("rerank is opt-in: default config does not enable the local reranker", () => {
|
|
10
|
-
const cfg = Config({});
|
|
11
|
-
assert.equal(cfg.rerankEnabled, false, "rerankEnabled defaults to false");
|
|
12
|
-
assert.equal(cfg.rerankProvider, "none", "rerankProvider defaults to none");
|
|
13
|
-
// The plugin gate in index.js: LocalReranker is only constructed when both
|
|
14
|
-
// hold — under defaults the gate is closed, so onnxruntime is never loaded.
|
|
15
|
-
assert.equal(cfg.rerankEnabled && cfg.rerankProvider === "local", false, "gate closed by default");
|
|
16
|
-
const enabled = Config({ rerankEnabled: true, rerankProvider: "local" });
|
|
17
|
-
assert.equal(enabled.rerankEnabled && enabled.rerankProvider === "local", true, "explicit opt-in opens the gate");
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
test("dream sliding window + implicit keep config defaults and bounds (v0.4.4)", () => {
|
|
21
|
-
const cfg = Config({});
|
|
22
|
-
assert.equal(cfg.dreamMaxSnapshotSize, 200, "window defaults to 200");
|
|
23
|
-
assert.equal(cfg.dreamImplicitKeep, true, "implicit keep defaults to true");
|
|
24
|
-
const capped = Config({ dreamMaxSnapshotSize: 1000 });
|
|
25
|
-
assert.equal(capped.dreamMaxSnapshotSize, 1000, "upper bound accepted");
|
|
26
|
-
const off = Config({ dreamImplicitKeep: false });
|
|
27
|
-
assert.equal(off.dreamImplicitKeep, false, "implicit keep can be disabled");
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
test("dream explicit coverage threshold config defaults and bounds (v0.4.4 fix)", () => {
|
|
31
|
-
const cfg = Config({});
|
|
32
|
-
assert.equal(cfg.dreamMinExplicitCoverage, 0.5, "coverage threshold defaults to 0.5");
|
|
33
|
-
const low = Config({ dreamMinExplicitCoverage: 0.1 });
|
|
34
|
-
assert.equal(low.dreamMinExplicitCoverage, 0.1, "lower bound accepted");
|
|
35
|
-
const high = Config({ dreamMinExplicitCoverage: 1 });
|
|
36
|
-
assert.equal(high.dreamMinExplicitCoverage, 1, "upper bound accepted");
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
test("startup probe: the reranker module never statically imports transformers/onnxruntime", () => {
|
|
40
|
-
// LocalReranker is imported eagerly by index.js, so a bare install must not
|
|
41
|
-
// pull onnxruntime in at module load. The heavy load is a lazy dynamic import
|
|
42
|
-
// that only runs inside init(), which index.js calls only when the opt-in gate
|
|
43
|
-
// is open (rerankEnabled && rerankProvider === "local").
|
|
44
|
-
const src = readFileSync(new URL("../src/reranker.js", import.meta.url), "utf8");
|
|
45
|
-
assert.ok(
|
|
46
|
-
!src.includes('from "@huggingface/transformers"'),
|
|
47
|
-
"no static transformers.js import in reranker.js"
|
|
48
|
-
);
|
|
49
|
-
assert.match(src, /await import\("@huggingface\/transformers"\)/, "transformers.js loads lazily via dynamic import");
|
|
50
|
-
});
|
|
1
|
+
import test from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import { readFileSync } from "node:fs";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { Config } from "../src/config.js";
|
|
6
|
+
|
|
7
|
+
// ---------------------------------------------------------------- rerank opt-in (item ⑥)
|
|
8
|
+
|
|
9
|
+
test("rerank is opt-in: default config does not enable the local reranker", () => {
|
|
10
|
+
const cfg = Config({});
|
|
11
|
+
assert.equal(cfg.rerankEnabled, false, "rerankEnabled defaults to false");
|
|
12
|
+
assert.equal(cfg.rerankProvider, "none", "rerankProvider defaults to none");
|
|
13
|
+
// The plugin gate in index.js: LocalReranker is only constructed when both
|
|
14
|
+
// hold — under defaults the gate is closed, so onnxruntime is never loaded.
|
|
15
|
+
assert.equal(cfg.rerankEnabled && cfg.rerankProvider === "local", false, "gate closed by default");
|
|
16
|
+
const enabled = Config({ rerankEnabled: true, rerankProvider: "local" });
|
|
17
|
+
assert.equal(enabled.rerankEnabled && enabled.rerankProvider === "local", true, "explicit opt-in opens the gate");
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test("dream sliding window + implicit keep config defaults and bounds (v0.4.4)", () => {
|
|
21
|
+
const cfg = Config({});
|
|
22
|
+
assert.equal(cfg.dreamMaxSnapshotSize, 200, "window defaults to 200");
|
|
23
|
+
assert.equal(cfg.dreamImplicitKeep, true, "implicit keep defaults to true");
|
|
24
|
+
const capped = Config({ dreamMaxSnapshotSize: 1000 });
|
|
25
|
+
assert.equal(capped.dreamMaxSnapshotSize, 1000, "upper bound accepted");
|
|
26
|
+
const off = Config({ dreamImplicitKeep: false });
|
|
27
|
+
assert.equal(off.dreamImplicitKeep, false, "implicit keep can be disabled");
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test("dream explicit coverage threshold config defaults and bounds (v0.4.4 fix)", () => {
|
|
31
|
+
const cfg = Config({});
|
|
32
|
+
assert.equal(cfg.dreamMinExplicitCoverage, 0.5, "coverage threshold defaults to 0.5");
|
|
33
|
+
const low = Config({ dreamMinExplicitCoverage: 0.1 });
|
|
34
|
+
assert.equal(low.dreamMinExplicitCoverage, 0.1, "lower bound accepted");
|
|
35
|
+
const high = Config({ dreamMinExplicitCoverage: 1 });
|
|
36
|
+
assert.equal(high.dreamMinExplicitCoverage, 1, "upper bound accepted");
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test("startup probe: the reranker module never statically imports transformers/onnxruntime", () => {
|
|
40
|
+
// LocalReranker is imported eagerly by index.js, so a bare install must not
|
|
41
|
+
// pull onnxruntime in at module load. The heavy load is a lazy dynamic import
|
|
42
|
+
// that only runs inside init(), which index.js calls only when the opt-in gate
|
|
43
|
+
// is open (rerankEnabled && rerankProvider === "local").
|
|
44
|
+
const src = readFileSync(new URL("../src/reranker.js", import.meta.url), "utf8");
|
|
45
|
+
assert.ok(
|
|
46
|
+
!src.includes('from "@huggingface/transformers"'),
|
|
47
|
+
"no static transformers.js import in reranker.js"
|
|
48
|
+
);
|
|
49
|
+
assert.match(src, /await import\("@huggingface\/transformers"\)/, "transformers.js loads lazily via dynamic import");
|
|
50
|
+
});
|