devsmind-mcp 2.4.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +317 -234
- package/dist/cli/activity.d.ts +9 -0
- package/dist/cli/activity.js +69 -0
- package/dist/cli/activity.js.map +1 -0
- package/dist/cli/describe.d.ts +31 -0
- package/dist/cli/describe.js +201 -0
- package/dist/cli/describe.js.map +1 -0
- package/dist/cli/diff.d.ts +14 -0
- package/dist/cli/diff.js +161 -0
- package/dist/cli/diff.js.map +1 -0
- package/dist/cli/embed.d.ts +6 -0
- package/dist/cli/embed.js +109 -0
- package/dist/cli/embed.js.map +1 -0
- package/dist/cli/extract-agent.d.ts +66 -0
- package/dist/cli/extract-agent.js +192 -0
- package/dist/cli/extract-agent.js.map +1 -0
- package/dist/cli/feedback.d.ts +11 -0
- package/dist/cli/feedback.js +90 -0
- package/dist/cli/feedback.js.map +1 -0
- package/dist/cli/index.js +139 -9
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/init.d.ts +30 -0
- package/dist/cli/init.js +89 -18
- package/dist/cli/init.js.map +1 -1
- package/dist/cli/integrations/memory-topics.d.ts +55 -0
- package/dist/cli/integrations/memory-topics.js +318 -0
- package/dist/cli/integrations/memory-topics.js.map +1 -0
- package/dist/cli/integrations/memory.d.ts +17 -6
- package/dist/cli/integrations/memory.js +52 -139
- package/dist/cli/integrations/memory.js.map +1 -1
- package/dist/cli/integrations/prompt.d.ts +8 -0
- package/dist/cli/integrations/prompt.js +24 -3
- package/dist/cli/integrations/prompt.js.map +1 -1
- package/dist/cli/integrations/registry.d.ts +26 -9
- package/dist/cli/integrations/registry.js +61 -30
- package/dist/cli/integrations/registry.js.map +1 -1
- package/dist/cli/llm-client.d.ts +116 -0
- package/dist/cli/llm-client.js +322 -0
- package/dist/cli/llm-client.js.map +1 -0
- package/dist/cli/rule.d.ts +22 -2
- package/dist/cli/rule.js +110 -34
- package/dist/cli/rule.js.map +1 -1
- package/dist/cli/runner.d.ts +21 -0
- package/dist/cli/runner.js +94 -276
- package/dist/cli/runner.js.map +1 -1
- package/dist/cli/sync-progress.d.ts +9 -0
- package/dist/cli/sync-progress.js +41 -0
- package/dist/cli/sync-progress.js.map +1 -0
- package/dist/cli/sync.js +5 -2
- package/dist/cli/sync.js.map +1 -1
- package/dist/cli/view.js +3 -2
- package/dist/cli/view.js.map +1 -1
- package/dist/cli/workflow.js +26 -20
- package/dist/cli/workflow.js.map +1 -1
- package/dist/db/activity-graph.d.ts +55 -0
- package/dist/db/activity-graph.js +314 -0
- package/dist/db/activity-graph.js.map +1 -0
- package/dist/db/activity.d.ts +221 -0
- package/dist/db/activity.js +348 -0
- package/dist/db/activity.js.map +1 -0
- package/dist/db/analyze.js +18 -6
- package/dist/db/analyze.js.map +1 -1
- package/dist/db/database.d.ts +654 -102
- package/dist/db/database.js +1911 -558
- package/dist/db/database.js.map +1 -1
- package/dist/db/edges.d.ts +24 -0
- package/dist/db/edges.js +84 -0
- package/dist/db/edges.js.map +1 -1
- package/dist/db/embedder.d.ts +39 -0
- package/dist/db/embedder.js +0 -0
- package/dist/db/embedder.js.map +1 -0
- package/dist/db/feedback.d.ts +128 -0
- package/dist/db/feedback.js +182 -0
- package/dist/db/feedback.js.map +1 -0
- package/dist/db/file-diff.d.ts +32 -0
- package/dist/db/file-diff.js +110 -0
- package/dist/db/file-diff.js.map +1 -0
- package/dist/db/grep.d.ts +78 -0
- package/dist/db/grep.js +475 -0
- package/dist/db/grep.js.map +1 -0
- package/dist/db/index-build.d.ts +75 -0
- package/dist/db/index-build.js +177 -0
- package/dist/db/index-build.js.map +1 -0
- package/dist/db/message-revert.d.ts +63 -0
- package/dist/db/message-revert.js +258 -0
- package/dist/db/message-revert.js.map +1 -0
- package/dist/db/revert.d.ts +31 -0
- package/dist/db/revert.js +108 -0
- package/dist/db/revert.js.map +1 -0
- package/dist/db/schema.d.ts +49 -4
- package/dist/db/schema.js +125 -73
- package/dist/db/schema.js.map +1 -1
- package/dist/db/search-index.d.ts +65 -0
- package/dist/db/search-index.js +74 -0
- package/dist/db/search-index.js.map +1 -0
- package/dist/db/staging.d.ts +91 -5
- package/dist/db/staging.js +148 -22
- package/dist/db/staging.js.map +1 -1
- package/dist/mcp/server.d.ts +29 -7
- package/dist/mcp/server.js +2637 -878
- package/dist/mcp/server.js.map +1 -1
- package/dist/mcp/vendor/3d-force-graph.min.js +5 -0
- package/dist/mcp/vendor/force-graph.min.js +5 -0
- package/dist/mcp/vendor/model/model_int8.onnx +0 -0
- package/dist/mcp/vendor/model/vocab.txt +30522 -0
- package/dist/mcp/vendor/three.min.js +7 -0
- package/dist/mcp/view.css +419 -0
- package/dist/mcp/view.html +161 -0
- package/dist/mcp/view.js +245 -0
- package/dist/mcp/view_chat.js +382 -0
- package/dist/mcp/view_graph.js +576 -0
- package/dist/mcp/visualizer.d.ts +25 -2
- package/dist/mcp/visualizer.js +31 -4
- package/dist/mcp/visualizer.js.map +1 -1
- package/dist/utils/ast.d.ts +89 -0
- package/dist/utils/ast.js +378 -10
- package/dist/utils/ast.js.map +1 -1
- package/dist/utils/diff.d.ts +44 -0
- package/dist/utils/diff.js +78 -0
- package/dist/utils/diff.js.map +1 -0
- package/dist/utils/edit.d.ts +6 -0
- package/dist/utils/edit.js +47 -14
- package/dist/utils/edit.js.map +1 -1
- package/dist/utils/scanner.d.ts +6 -4
- package/dist/utils/scanner.js +18 -8
- package/dist/utils/scanner.js.map +1 -1
- package/dist/utils/tokenize.d.ts +45 -0
- package/dist/utils/tokenize.js +129 -0
- package/dist/utils/tokenize.js.map +1 -0
- package/dist/utils/version.d.ts +14 -0
- package/dist/utils/version.js +61 -0
- package/dist/utils/version.js.map +1 -0
- package/package.json +18 -5
- package/dist/mcp/visualizer_2d.html +0 -635
- package/dist/mcp/visualizer_3d.html +0 -613
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.revertLastEdit = revertLastEdit;
|
|
4
|
+
const staging_1 = require("./staging");
|
|
5
|
+
const edit_1 = require("../utils/edit");
|
|
6
|
+
const ast_1 = require("../utils/ast");
|
|
7
|
+
/**
|
|
8
|
+
* Undoes the most recent recorded edit to one entity: restores the file, then erases what was
|
|
9
|
+
* written about it.
|
|
10
|
+
*
|
|
11
|
+
* Only the newest edit is reversible. An older one cannot be undone in isolation — every edit
|
|
12
|
+
* after it was made against the code it produced, so putting its "before" back would overwrite
|
|
13
|
+
* work that has nothing to do with it. Git is the tool for that, and it already does it properly.
|
|
14
|
+
*
|
|
15
|
+
* `expectedHistoryId`, when given, is the specific entry the caller intended to revert (e.g. the
|
|
16
|
+
* one a "Revert this change" button was clicked on). It must match the node's actual latest entry
|
|
17
|
+
* — if it doesn't (a newer entry was recorded since, perhaps from another session), the revert is
|
|
18
|
+
* refused rather than silently reverting that newer entry instead, which would undo the wrong
|
|
19
|
+
* change from the caller's point of view.
|
|
20
|
+
*
|
|
21
|
+
* The file is restored by swapping the recorded `after` back to the recorded `before`, which
|
|
22
|
+
* routes through the same exact-match write `edit_node` uses: if that text is no longer uniquely
|
|
23
|
+
* present, the write is refused rather than guessed at.
|
|
24
|
+
*/
|
|
25
|
+
function revertLastEdit(db, devmindPath, nodeId, expectedHistoryId) {
|
|
26
|
+
const node = db.getNode(nodeId);
|
|
27
|
+
const resolvedId = node ? node.id : nodeId;
|
|
28
|
+
// Staged edits are the newest thing that happened, and were never recorded — undo those first,
|
|
29
|
+
// or a revert would restore the file underneath a staged entry still waiting to be committed.
|
|
30
|
+
const staged = (0, staging_1.readStaged)(devmindPath).filter(e => e.node_id === resolvedId);
|
|
31
|
+
if (staged.length) {
|
|
32
|
+
const last = staged[staged.length - 1];
|
|
33
|
+
if (last.code_before === undefined) {
|
|
34
|
+
return { ok: false, error: `The staged change to ${resolvedId} has no recorded before-state, so it cannot be undone here. Use git to restore the file.` };
|
|
35
|
+
}
|
|
36
|
+
const restored = restoreFile(last.file_path, last.code_snapshot, last.code_before ?? '');
|
|
37
|
+
if (!restored.ok)
|
|
38
|
+
return { ok: false, error: restored.error, node_id: resolvedId, file_path: last.file_path };
|
|
39
|
+
(0, staging_1.removeLastStagedEntry)(devmindPath, resolvedId);
|
|
40
|
+
return { ok: true, node_id: resolvedId, file_path: last.file_path, was_staged: true };
|
|
41
|
+
}
|
|
42
|
+
const entry = db.getLatestHistory(resolvedId);
|
|
43
|
+
if (!entry)
|
|
44
|
+
return { ok: false, error: `No history recorded for ${resolvedId} — nothing to revert.` };
|
|
45
|
+
if (expectedHistoryId && entry.id !== expectedHistoryId) {
|
|
46
|
+
return {
|
|
47
|
+
ok: false,
|
|
48
|
+
error: `A newer change to ${resolvedId} was recorded since this one — reverting it would undo that newer change instead. Refresh and revert the newest entry, or use git.`,
|
|
49
|
+
node_id: resolvedId
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
if (!entry.edits.length) {
|
|
53
|
+
return {
|
|
54
|
+
ok: false,
|
|
55
|
+
error: `The last change to ${resolvedId} was recorded without a before-state, so there is nothing to restore it to. Entries written before edit_node tracked diffs, and legacy update_history / initial index snapshots, are both like this. Use git to restore the file.`
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
const last = entry.edits[entry.edits.length - 1];
|
|
59
|
+
if (!node)
|
|
60
|
+
return { ok: false, error: `${resolvedId} has history but no node in the graph — cannot locate its file.` };
|
|
61
|
+
// The recorded `after` must still be what is on disk. If it isn't, the code moved on after this
|
|
62
|
+
// edit and restoring `before` would silently discard whatever came since.
|
|
63
|
+
const live = db.getLiveCode(resolvedId);
|
|
64
|
+
if (live.source !== 'live' || live.code === undefined) {
|
|
65
|
+
return {
|
|
66
|
+
ok: false,
|
|
67
|
+
error: `Could not read ${resolvedId} from disk to confirm what is there now (the symbol may have been renamed, moved, or deleted). Revert refused — use git.`,
|
|
68
|
+
node_id: resolvedId
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
if (live.code !== last.after) {
|
|
72
|
+
return {
|
|
73
|
+
ok: false,
|
|
74
|
+
error: `${resolvedId} has changed since that edit was recorded — reverting would discard the newer change. Revert refused; use git to restore the file.`,
|
|
75
|
+
node_id: resolvedId,
|
|
76
|
+
file_path: node.file_path
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
const restored = restoreFile(node.file_path, last.after, last.before);
|
|
80
|
+
if (!restored.ok)
|
|
81
|
+
return { ok: false, error: restored.error, node_id: resolvedId, file_path: node.file_path };
|
|
82
|
+
const erased = db.eraseLastEdit(entry.id);
|
|
83
|
+
return {
|
|
84
|
+
ok: true,
|
|
85
|
+
node_id: resolvedId,
|
|
86
|
+
file_path: node.file_path,
|
|
87
|
+
entry_deleted: erased.entry_deleted,
|
|
88
|
+
note: erased.entry_deleted ? undefined : erased.reason
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Swaps `after` back to `before` in the file.
|
|
93
|
+
*
|
|
94
|
+
* `before` is empty when the edit created the entity, so the revert deletes it — which is the
|
|
95
|
+
* correct inverse, and the one case where the two strings could not both be present.
|
|
96
|
+
*/
|
|
97
|
+
function restoreFile(filePath, after, before) {
|
|
98
|
+
const paths = String(filePath).split(',').map(s => s.trim()).filter(Boolean);
|
|
99
|
+
const target = paths[0];
|
|
100
|
+
if (!target)
|
|
101
|
+
return { ok: false, error: 'no file path recorded for this entity' };
|
|
102
|
+
const r = (0, edit_1.replaceTextInFile)(target, after, before, false);
|
|
103
|
+
if (!r.ok)
|
|
104
|
+
return { ok: false, error: `could not restore ${target}: ${r.error}` };
|
|
105
|
+
(0, ast_1.invalidateParsedFile)(target);
|
|
106
|
+
return { ok: true };
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=revert.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"revert.js","sourceRoot":"","sources":["../../src/db/revert.ts"],"names":[],"mappings":";;AAmCA,wCAmEC;AArGD,uCAA8D;AAC9D,wCAAkD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AC,EAAE;QAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,qBAAqB,MAAM,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC;IAClF,IAAA,0BAAoB,EAAC,MAAM,CAAC,CAAC;IAC7B,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC;AACtB,CAAC"}
|
package/dist/db/schema.d.ts
CHANGED
|
@@ -4,6 +4,22 @@ export interface DbNode {
|
|
|
4
4
|
name: string;
|
|
5
5
|
file_path: string;
|
|
6
6
|
signature: string | null;
|
|
7
|
+
/**
|
|
8
|
+
* A 1-3 sentence natural-language description of what this entity does — the thing a plain
|
|
9
|
+
* identifier can't carry. This is what makes `search_nodes` findable by natural language
|
|
10
|
+
* instead of only by exact identifier/path substring. Null until an agent (or `devsmind
|
|
11
|
+
* describe`) writes one; `commit_changes` refuses to create a NEW node without it.
|
|
12
|
+
*/
|
|
13
|
+
description: string | null;
|
|
14
|
+
/**
|
|
15
|
+
* Other names this SAME entity is referenced by — a generated hook (`useGetAdminOrdersQuery`
|
|
16
|
+
* for an RTK `getAdminOrders` endpoint), a renamed default-export import, or an `export { x as
|
|
17
|
+
* y }` re-export. One implementation, several exported handles: this is what lets the edge
|
|
18
|
+
* resolver match a caller against ANY of them instead of only the entity's own declared name,
|
|
19
|
+
* which is the fix for edges that otherwise can't exist because the reference in the code never
|
|
20
|
+
* spells out the original name at all. Empty array, not null, when there are none.
|
|
21
|
+
*/
|
|
22
|
+
aliases: string[];
|
|
7
23
|
deprecated: number;
|
|
8
24
|
created_at: string;
|
|
9
25
|
}
|
|
@@ -11,6 +27,13 @@ export interface DbConnection {
|
|
|
11
27
|
source_node_id: string;
|
|
12
28
|
target_node_id: string;
|
|
13
29
|
}
|
|
30
|
+
/** One recorded edit within a history entry — what the code looked like either side of it. */
|
|
31
|
+
export interface HistoryEdit {
|
|
32
|
+
at: string;
|
|
33
|
+
before: string;
|
|
34
|
+
after: string;
|
|
35
|
+
reasoning: string;
|
|
36
|
+
}
|
|
14
37
|
export interface DbHistory {
|
|
15
38
|
id: string;
|
|
16
39
|
node_id: string;
|
|
@@ -19,12 +42,21 @@ export interface DbHistory {
|
|
|
19
42
|
updated_at: string;
|
|
20
43
|
code_snapshot: string;
|
|
21
44
|
reasoning: string;
|
|
45
|
+
/**
|
|
46
|
+
* Per-edit before/after trail, newest last. Lives only in the history JSON, never in SQLite —
|
|
47
|
+
* same as code_snapshot. Empty for entries written before this existed, and for legacy
|
|
48
|
+
* `update_history` / initial index snapshots, which have no before-state to record: both mean "no diff, no revert".
|
|
49
|
+
*/
|
|
50
|
+
edits: HistoryEdit[];
|
|
22
51
|
}
|
|
23
52
|
export interface DbWorkflow {
|
|
24
53
|
id: string;
|
|
25
54
|
name: string;
|
|
26
55
|
description: string;
|
|
27
|
-
status:
|
|
56
|
+
/** 1 = hidden from the default listing. Replaces the old `status` field: nothing ever genuinely
|
|
57
|
+
* "completes" — a feature keeps getting changed — so a completed/paused/active lifecycle was a
|
|
58
|
+
* value nobody maintained. "Archived" claims only what it can deliver: hide this from the list. */
|
|
59
|
+
archived: number;
|
|
28
60
|
created_at: string;
|
|
29
61
|
updated_at: string;
|
|
30
62
|
}
|
|
@@ -33,8 +65,21 @@ export interface DbWorkflowStep {
|
|
|
33
65
|
workflow_id: string;
|
|
34
66
|
step_index: number;
|
|
35
67
|
summary: string;
|
|
36
|
-
|
|
37
|
-
|
|
68
|
+
/** The commit's own `why`/`goal`/`decision`, copied at write time rather than joined from
|
|
69
|
+
* `history`. Deliberate duplication: history reasoning MUTATES after the fact (the 1-hour merge
|
|
70
|
+
* appends under a `── Update @ … ──` separator, and eraseLastEdit can drop a block), so a step
|
|
71
|
+
* that joined to it would describe a moving target — disqualifying for a record whose whole
|
|
72
|
+
* purpose is "what did we think at the time". */
|
|
73
|
+
reasoning: string | null;
|
|
74
|
+
/** JSON array of the node ids this step touched. Replaces `history_ids`, which could not
|
|
75
|
+
* identify a commit: within an hour, two commits on the same node merge into ONE history row,
|
|
76
|
+
* so a step's ids could point at rows an earlier commit created, and one row could be cited by
|
|
77
|
+
* several steps. Node ids have no such ambiguity and are directly usable with get_node_code. */
|
|
78
|
+
node_ids: string | null;
|
|
79
|
+
/** JSON array of repo-relative paths to research/spec docs behind this step. A path, never a
|
|
80
|
+
* copy: the file is already versioned and already shared, so it cannot go stale the way the old
|
|
81
|
+
* `workflow_artifacts` content duplicates did. */
|
|
82
|
+
doc_paths: string | null;
|
|
38
83
|
session_id: string | null;
|
|
39
84
|
created_at: string;
|
|
40
85
|
}
|
|
@@ -47,4 +92,4 @@ export interface DbWorkflowArtifact {
|
|
|
47
92
|
file_path: string;
|
|
48
93
|
created_at: string;
|
|
49
94
|
}
|
|
50
|
-
export declare const INIT_SCHEMA_SQL = "\nCREATE TABLE IF NOT EXISTS nodes (\n id TEXT PRIMARY KEY,\n type TEXT NOT NULL,\n name TEXT NOT NULL,\n file_path TEXT NOT NULL,\n signature TEXT,\n deprecated INTEGER DEFAULT 0,\n created_at DATETIME DEFAULT CURRENT_TIMESTAMP\n);\n\nCREATE TABLE IF NOT EXISTS node_connections (\n source_node_id TEXT,\n target_node_id TEXT,\n PRIMARY KEY (source_node_id, target_node_id),\n FOREIGN KEY (source_node_id) REFERENCES nodes (id) ON DELETE CASCADE,\n FOREIGN KEY (target_node_id) REFERENCES nodes (id) ON DELETE CASCADE\n);\n\nCREATE TABLE IF NOT EXISTS history (\n id TEXT PRIMARY KEY,\n node_id TEXT NOT NULL,\n session_id TEXT NOT NULL,\n created_at DATETIME DEFAULT CURRENT_TIMESTAMP,\n updated_at DATETIME DEFAULT CURRENT_TIMESTAMP,\n code_snapshot TEXT NOT NULL,\n reasoning TEXT NOT NULL,\n FOREIGN KEY (node_id) REFERENCES nodes (id) ON DELETE CASCADE\n);\n\nCREATE TABLE IF NOT EXISTS system_meta (\n key TEXT PRIMARY KEY,\n value TEXT NOT NULL,\n updated_at DATETIME DEFAULT CURRENT_TIMESTAMP\n);\n\nCREATE TABLE IF NOT EXISTS workflows (\n id TEXT PRIMARY KEY,\n name TEXT NOT NULL,\n description TEXT NOT NULL,\n status TEXT NOT NULL DEFAULT 'active',\n created_at DATETIME DEFAULT CURRENT_TIMESTAMP,\n updated_at DATETIME DEFAULT CURRENT_TIMESTAMP\n);\n\nCREATE TABLE IF NOT EXISTS workflow_steps (\n id TEXT PRIMARY KEY,\n workflow_id TEXT NOT NULL,\n step_index INTEGER NOT NULL,\n summary TEXT NOT NULL,\n pending_tasks TEXT,\n history_ids TEXT,\n session_id TEXT,\n created_at DATETIME DEFAULT CURRENT_TIMESTAMP,\n FOREIGN KEY (workflow_id) REFERENCES workflows (id) ON DELETE CASCADE\n);\n\nCREATE TABLE IF NOT EXISTS workflow_artifacts (\n id TEXT PRIMARY KEY,\n workflow_id TEXT NOT NULL,\n step_id TEXT,\n type TEXT NOT NULL,\n source_name TEXT NOT NULL,\n file_path TEXT NOT NULL,\n created_at DATETIME DEFAULT CURRENT_TIMESTAMP,\n FOREIGN KEY (workflow_id) REFERENCES workflows (id) ON DELETE CASCADE\n);\n\n-- Index for searching nodes by name and type\nCREATE INDEX IF NOT EXISTS idx_nodes_name ON nodes (name);\nCREATE INDEX IF NOT EXISTS idx_history_node_id ON history (node_id);\nCREATE INDEX IF NOT EXISTS idx_workflow_steps_workflow_id ON workflow_steps (workflow_id);\nCREATE INDEX IF NOT EXISTS idx_workflow_artifacts_workflow_id ON workflow_artifacts (workflow_id);\n";
|
|
95
|
+
export declare const INIT_SCHEMA_SQL = "\nCREATE TABLE IF NOT EXISTS nodes (\n id TEXT PRIMARY KEY,\n type TEXT NOT NULL,\n name TEXT NOT NULL,\n file_path TEXT NOT NULL,\n signature TEXT,\n description TEXT,\n aliases TEXT DEFAULT '[]',\n deprecated INTEGER DEFAULT 0,\n created_at DATETIME DEFAULT CURRENT_TIMESTAMP\n);\n\nCREATE TABLE IF NOT EXISTS node_connections (\n source_node_id TEXT,\n target_node_id TEXT,\n PRIMARY KEY (source_node_id, target_node_id),\n FOREIGN KEY (source_node_id) REFERENCES nodes (id) ON DELETE CASCADE,\n FOREIGN KEY (target_node_id) REFERENCES nodes (id) ON DELETE CASCADE\n);\n\nCREATE TABLE IF NOT EXISTS history (\n id TEXT PRIMARY KEY,\n node_id TEXT NOT NULL,\n session_id TEXT NOT NULL,\n created_at DATETIME DEFAULT CURRENT_TIMESTAMP,\n updated_at DATETIME DEFAULT CURRENT_TIMESTAMP,\n code_snapshot TEXT NOT NULL,\n reasoning TEXT NOT NULL,\n FOREIGN KEY (node_id) REFERENCES nodes (id) ON DELETE CASCADE\n);\n\nCREATE TABLE IF NOT EXISTS system_meta (\n key TEXT PRIMARY KEY,\n value TEXT NOT NULL,\n updated_at DATETIME DEFAULT CURRENT_TIMESTAMP\n);\n\n-- Local, derived search index \u2014 never synced or committed, purely a cache rebuilt from\n-- nodes+history whenever search-index.ts's fingerprint check finds it stale. Same category as\n-- brain.db itself: safe to wipe and rebuild from the source of truth at any time.\nCREATE TABLE IF NOT EXISTS node_tokens (\n node_id TEXT NOT NULL,\n token TEXT NOT NULL,\n field TEXT NOT NULL,\n tf INTEGER NOT NULL DEFAULT 1,\n PRIMARY KEY (node_id, token, field)\n);\nCREATE INDEX IF NOT EXISTS idx_node_tokens_token ON node_tokens (token);\n\n-- Semantic (dense) vectors, one per node, from the vendored ONNX embedder (src/db/embedder.ts).\n-- Unlike node_tokens, these ARE synced via git (vectors/**/*.json, mirroring graph/**/*.json) \u2014\n-- deliberately, per an explicit product decision to trade repo size for teammates skipping local\n-- inference. No foreign key to nodes(id): syncFromDisk() runs its destructive graph pass under\n-- foreign_keys=OFF, so a cascade here would silently never fire; orphans are swept explicitly\n-- instead (see syncFromDisk's vectors pass). model_id guards the git-sync hazard \u2014 vectors from\n-- a different embedding model are structurally valid but numerically meaningless, so any reader\n-- MUST check model_id before trusting a row, not just check for its presence.\nCREATE TABLE IF NOT EXISTS node_vectors (\n node_id TEXT PRIMARY KEY,\n model_id TEXT NOT NULL,\n dim INTEGER NOT NULL,\n description_hash TEXT NOT NULL,\n vector BLOB NOT NULL\n);\n\n-- status is vestigial: still declared (NOT NULL DEFAULT makes an INSERT that omits it succeed)\n-- but no longer read or written. archived replaces it -- see DbWorkflow.\nCREATE TABLE IF NOT EXISTS workflows (\n id TEXT PRIMARY KEY,\n name TEXT NOT NULL,\n description TEXT NOT NULL,\n status TEXT NOT NULL DEFAULT 'active',\n archived INTEGER NOT NULL DEFAULT 0,\n created_at DATETIME DEFAULT CURRENT_TIMESTAMP,\n updated_at DATETIME DEFAULT CURRENT_TIMESTAMP\n);\n\n-- pending_tasks and history_ids are vestigial: never written or read by current code, and kept\n-- only so an older CLI opening the same brain.db does not hit \"no such column\". They are dropped\n-- from DbWorkflowStep, so nothing in TypeScript can reach them by accident.\nCREATE TABLE IF NOT EXISTS workflow_steps (\n id TEXT PRIMARY KEY,\n workflow_id TEXT NOT NULL,\n step_index INTEGER NOT NULL,\n summary TEXT NOT NULL,\n reasoning TEXT,\n node_ids TEXT,\n doc_paths TEXT,\n pending_tasks TEXT,\n history_ids TEXT,\n session_id TEXT,\n created_at DATETIME DEFAULT CURRENT_TIMESTAMP,\n FOREIGN KEY (workflow_id) REFERENCES workflows (id) ON DELETE CASCADE\n);\n\nCREATE TABLE IF NOT EXISTS workflow_artifacts (\n id TEXT PRIMARY KEY,\n workflow_id TEXT NOT NULL,\n step_id TEXT,\n type TEXT NOT NULL,\n source_name TEXT NOT NULL,\n file_path TEXT NOT NULL,\n created_at DATETIME DEFAULT CURRENT_TIMESTAMP,\n FOREIGN KEY (workflow_id) REFERENCES workflows (id) ON DELETE CASCADE\n);\n\n-- Index for searching nodes by name and type\nCREATE INDEX IF NOT EXISTS idx_nodes_name ON nodes (name);\n-- Matches getNodesByFilePath's own normalization (REPLACE(LOWER(file_path), '', '/')) exactly \u2014\n-- without this, that call is a full table scan, and get_node_code's file_outline now puts it on\n-- the hot path of the most-called read tool (once per call, to cross-reference outline entries\n-- against indexed nodes). Idempotent: existing brains pick this up on next open, no migration.\nCREATE INDEX IF NOT EXISTS idx_nodes_file_path ON nodes (REPLACE(LOWER(file_path), '', '/'));\n-- node_connections' PRIMARY KEY is (source_node_id, target_node_id), so its autoindex serves\n-- \"what does X use\" but NOT the reverse. Every \"who uses X\" lookup \u2014 the inbound half of getGraph's\n-- BFS, getConnections' used_by, getConnectionCounts \u2014 was therefore a full table scan, and the BFS\n-- runs one PER NODE VISITED (up to 500 in a single call). The trailing source_node_id makes this\n-- covering, so the inbound query is answered from the index alone and comes back already ordered\n-- (which is what makes getGraph's ORDER BY free rather than a sort on top of a scan).\n-- Idempotent: existing brains pick this up on next open, no migration.\nCREATE INDEX IF NOT EXISTS idx_node_connections_target ON node_connections (target_node_id, source_node_id);\nCREATE INDEX IF NOT EXISTS idx_history_node_id ON history (node_id);\nCREATE INDEX IF NOT EXISTS idx_workflow_steps_workflow_id ON workflow_steps (workflow_id);\nCREATE INDEX IF NOT EXISTS idx_workflow_artifacts_workflow_id ON workflow_artifacts (workflow_id);\n";
|
package/dist/db/schema.js
CHANGED
|
@@ -1,78 +1,130 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.INIT_SCHEMA_SQL = void 0;
|
|
4
|
-
exports.INIT_SCHEMA_SQL = `
|
|
5
|
-
CREATE TABLE IF NOT EXISTS nodes (
|
|
6
|
-
id TEXT PRIMARY KEY,
|
|
7
|
-
type TEXT NOT NULL,
|
|
8
|
-
name TEXT NOT NULL,
|
|
9
|
-
file_path TEXT NOT NULL,
|
|
10
|
-
signature TEXT,
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
)
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
)
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
)
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
4
|
+
exports.INIT_SCHEMA_SQL = `
|
|
5
|
+
CREATE TABLE IF NOT EXISTS nodes (
|
|
6
|
+
id TEXT PRIMARY KEY,
|
|
7
|
+
type TEXT NOT NULL,
|
|
8
|
+
name TEXT NOT NULL,
|
|
9
|
+
file_path TEXT NOT NULL,
|
|
10
|
+
signature TEXT,
|
|
11
|
+
description TEXT,
|
|
12
|
+
aliases TEXT DEFAULT '[]',
|
|
13
|
+
deprecated INTEGER DEFAULT 0,
|
|
14
|
+
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
CREATE TABLE IF NOT EXISTS node_connections (
|
|
18
|
+
source_node_id TEXT,
|
|
19
|
+
target_node_id TEXT,
|
|
20
|
+
PRIMARY KEY (source_node_id, target_node_id),
|
|
21
|
+
FOREIGN KEY (source_node_id) REFERENCES nodes (id) ON DELETE CASCADE,
|
|
22
|
+
FOREIGN KEY (target_node_id) REFERENCES nodes (id) ON DELETE CASCADE
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
CREATE TABLE IF NOT EXISTS history (
|
|
26
|
+
id TEXT PRIMARY KEY,
|
|
27
|
+
node_id TEXT NOT NULL,
|
|
28
|
+
session_id TEXT NOT NULL,
|
|
29
|
+
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
30
|
+
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
31
|
+
code_snapshot TEXT NOT NULL,
|
|
32
|
+
reasoning TEXT NOT NULL,
|
|
33
|
+
FOREIGN KEY (node_id) REFERENCES nodes (id) ON DELETE CASCADE
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
CREATE TABLE IF NOT EXISTS system_meta (
|
|
37
|
+
key TEXT PRIMARY KEY,
|
|
38
|
+
value TEXT NOT NULL,
|
|
39
|
+
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
-- Local, derived search index — never synced or committed, purely a cache rebuilt from
|
|
43
|
+
-- nodes+history whenever search-index.ts's fingerprint check finds it stale. Same category as
|
|
44
|
+
-- brain.db itself: safe to wipe and rebuild from the source of truth at any time.
|
|
45
|
+
CREATE TABLE IF NOT EXISTS node_tokens (
|
|
46
|
+
node_id TEXT NOT NULL,
|
|
47
|
+
token TEXT NOT NULL,
|
|
48
|
+
field TEXT NOT NULL,
|
|
49
|
+
tf INTEGER NOT NULL DEFAULT 1,
|
|
50
|
+
PRIMARY KEY (node_id, token, field)
|
|
51
|
+
);
|
|
52
|
+
CREATE INDEX IF NOT EXISTS idx_node_tokens_token ON node_tokens (token);
|
|
53
|
+
|
|
54
|
+
-- Semantic (dense) vectors, one per node, from the vendored ONNX embedder (src/db/embedder.ts).
|
|
55
|
+
-- Unlike node_tokens, these ARE synced via git (vectors/**/*.json, mirroring graph/**/*.json) —
|
|
56
|
+
-- deliberately, per an explicit product decision to trade repo size for teammates skipping local
|
|
57
|
+
-- inference. No foreign key to nodes(id): syncFromDisk() runs its destructive graph pass under
|
|
58
|
+
-- foreign_keys=OFF, so a cascade here would silently never fire; orphans are swept explicitly
|
|
59
|
+
-- instead (see syncFromDisk's vectors pass). model_id guards the git-sync hazard — vectors from
|
|
60
|
+
-- a different embedding model are structurally valid but numerically meaningless, so any reader
|
|
61
|
+
-- MUST check model_id before trusting a row, not just check for its presence.
|
|
62
|
+
CREATE TABLE IF NOT EXISTS node_vectors (
|
|
63
|
+
node_id TEXT PRIMARY KEY,
|
|
64
|
+
model_id TEXT NOT NULL,
|
|
65
|
+
dim INTEGER NOT NULL,
|
|
66
|
+
description_hash TEXT NOT NULL,
|
|
67
|
+
vector BLOB NOT NULL
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
-- status is vestigial: still declared (NOT NULL DEFAULT makes an INSERT that omits it succeed)
|
|
71
|
+
-- but no longer read or written. archived replaces it -- see DbWorkflow.
|
|
72
|
+
CREATE TABLE IF NOT EXISTS workflows (
|
|
73
|
+
id TEXT PRIMARY KEY,
|
|
74
|
+
name TEXT NOT NULL,
|
|
75
|
+
description TEXT NOT NULL,
|
|
76
|
+
status TEXT NOT NULL DEFAULT 'active',
|
|
77
|
+
archived INTEGER NOT NULL DEFAULT 0,
|
|
78
|
+
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
79
|
+
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
-- pending_tasks and history_ids are vestigial: never written or read by current code, and kept
|
|
83
|
+
-- only so an older CLI opening the same brain.db does not hit "no such column". They are dropped
|
|
84
|
+
-- from DbWorkflowStep, so nothing in TypeScript can reach them by accident.
|
|
85
|
+
CREATE TABLE IF NOT EXISTS workflow_steps (
|
|
86
|
+
id TEXT PRIMARY KEY,
|
|
87
|
+
workflow_id TEXT NOT NULL,
|
|
88
|
+
step_index INTEGER NOT NULL,
|
|
89
|
+
summary TEXT NOT NULL,
|
|
90
|
+
reasoning TEXT,
|
|
91
|
+
node_ids TEXT,
|
|
92
|
+
doc_paths TEXT,
|
|
93
|
+
pending_tasks TEXT,
|
|
94
|
+
history_ids TEXT,
|
|
95
|
+
session_id TEXT,
|
|
96
|
+
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
97
|
+
FOREIGN KEY (workflow_id) REFERENCES workflows (id) ON DELETE CASCADE
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
CREATE TABLE IF NOT EXISTS workflow_artifacts (
|
|
101
|
+
id TEXT PRIMARY KEY,
|
|
102
|
+
workflow_id TEXT NOT NULL,
|
|
103
|
+
step_id TEXT,
|
|
104
|
+
type TEXT NOT NULL,
|
|
105
|
+
source_name TEXT NOT NULL,
|
|
106
|
+
file_path TEXT NOT NULL,
|
|
107
|
+
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
108
|
+
FOREIGN KEY (workflow_id) REFERENCES workflows (id) ON DELETE CASCADE
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
-- Index for searching nodes by name and type
|
|
112
|
+
CREATE INDEX IF NOT EXISTS idx_nodes_name ON nodes (name);
|
|
113
|
+
-- Matches getNodesByFilePath's own normalization (REPLACE(LOWER(file_path), '\', '/')) exactly —
|
|
114
|
+
-- without this, that call is a full table scan, and get_node_code's file_outline now puts it on
|
|
115
|
+
-- the hot path of the most-called read tool (once per call, to cross-reference outline entries
|
|
116
|
+
-- against indexed nodes). Idempotent: existing brains pick this up on next open, no migration.
|
|
117
|
+
CREATE INDEX IF NOT EXISTS idx_nodes_file_path ON nodes (REPLACE(LOWER(file_path), '\', '/'));
|
|
118
|
+
-- node_connections' PRIMARY KEY is (source_node_id, target_node_id), so its autoindex serves
|
|
119
|
+
-- "what does X use" but NOT the reverse. Every "who uses X" lookup — the inbound half of getGraph's
|
|
120
|
+
-- BFS, getConnections' used_by, getConnectionCounts — was therefore a full table scan, and the BFS
|
|
121
|
+
-- runs one PER NODE VISITED (up to 500 in a single call). The trailing source_node_id makes this
|
|
122
|
+
-- covering, so the inbound query is answered from the index alone and comes back already ordered
|
|
123
|
+
-- (which is what makes getGraph's ORDER BY free rather than a sort on top of a scan).
|
|
124
|
+
-- Idempotent: existing brains pick this up on next open, no migration.
|
|
125
|
+
CREATE INDEX IF NOT EXISTS idx_node_connections_target ON node_connections (target_node_id, source_node_id);
|
|
126
|
+
CREATE INDEX IF NOT EXISTS idx_history_node_id ON history (node_id);
|
|
127
|
+
CREATE INDEX IF NOT EXISTS idx_workflow_steps_workflow_id ON workflow_steps (workflow_id);
|
|
128
|
+
CREATE INDEX IF NOT EXISTS idx_workflow_artifacts_workflow_id ON workflow_artifacts (workflow_id);
|
|
77
129
|
`;
|
|
78
130
|
//# sourceMappingURL=schema.js.map
|
package/dist/db/schema.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/db/schema.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/db/schema.ts"],"names":[],"mappings":";;;AAqGa,QAAA,eAAe,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6H9B,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The searchable "surface" of a node, split into fields so each can carry its own relevance
|
|
3
|
+
* weight. `description` is the whole point of this module: without it, natural-language search
|
|
4
|
+
* has almost nothing to match against — an identifier and a file path are a handful of words.
|
|
5
|
+
*/
|
|
6
|
+
export type TokenField = 'identifier' | 'path' | 'description' | 'reasoning';
|
|
7
|
+
export interface TokenRow {
|
|
8
|
+
token: string;
|
|
9
|
+
field: TokenField;
|
|
10
|
+
/** Term frequency — how many times this token appears in this field, for this node. */
|
|
11
|
+
tf: number;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Tokenizes one field's text into deduplicated (token, tf) pairs, ready to write into
|
|
15
|
+
* `node_tokens`. `identifier`/`path` fields use the identifier splitter (camelCase/snake/kebab
|
|
16
|
+
* boundaries) since that's what they actually are; `description`/`reasoning` use the plain
|
|
17
|
+
* natural-language tokenizer since they're already prose.
|
|
18
|
+
*/
|
|
19
|
+
export declare function tokenizeNodeField(text: string | null | undefined, field: TokenField): TokenRow[];
|
|
20
|
+
export interface FieldWeights {
|
|
21
|
+
identifier: number;
|
|
22
|
+
path: number;
|
|
23
|
+
description: number;
|
|
24
|
+
reasoning: number;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* `description` outweighs everything else — it's the field written specifically to be found
|
|
28
|
+
* by natural language, so a hit there is the strongest possible signal that this is the right
|
|
29
|
+
* node. `identifier` is still weighted highly since an exact-ish name match is usually right.
|
|
30
|
+
* `reasoning` is last: it explains WHY something changed, not WHAT it is, so it's a weaker
|
|
31
|
+
* signal for "find the code that does X" than the other three.
|
|
32
|
+
*/
|
|
33
|
+
export declare const DEFAULT_FIELD_WEIGHTS: FieldWeights;
|
|
34
|
+
export interface FieldMatch {
|
|
35
|
+
field: TokenField;
|
|
36
|
+
/** This node's term frequency for the matched token, in this field. */
|
|
37
|
+
tf: number;
|
|
38
|
+
/** How many OTHER nodes also have this token in this field — rarer tokens carry more signal. */
|
|
39
|
+
docFreq: number;
|
|
40
|
+
/** Total nodes considered, for the IDF calculation. */
|
|
41
|
+
totalNodes: number;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* A saturating-TF, IDF-weighted score for one candidate node across every (field, token) it
|
|
45
|
+
* matched. This is BM25-shaped (the same `tf*(k1+1)/(tf+k1)` saturation and log-IDF term BM25
|
|
46
|
+
* uses) but deliberately simplified: it scores a small, already-narrowed candidate set (nodes
|
|
47
|
+
* that matched at least one query token via a SQL lookup), not a full-corpus scan, so there's
|
|
48
|
+
* no need for BM25's document-length normalization term — every "document" here is one node's
|
|
49
|
+
* handful of fields, not a variable-length passage.
|
|
50
|
+
*/
|
|
51
|
+
export declare function scoreCandidate(matches: FieldMatch[], weights?: FieldWeights): number;
|
|
52
|
+
export interface RankedId {
|
|
53
|
+
id: string;
|
|
54
|
+
score: number;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Reciprocal Rank Fusion — merges the BM25 ranking and the vector-cosine ranking into one list,
|
|
58
|
+
* using each id's POSITION within each ranking rather than the raw scores. Necessary because
|
|
59
|
+
* BM25 scores are unbounded and cosine similarity is bounded [-1,1]; there's no principled scale
|
|
60
|
+
* to sum them on directly, but "1st place" means the same thing in both rankings. An id missing
|
|
61
|
+
* from a ranking simply contributes 0 from it — appearing in both rankings compounds naturally.
|
|
62
|
+
* k=60 is the standard RRF constant (Cormack et al.): large enough that rank 1 vs rank 2 isn't a
|
|
63
|
+
* cliff, small enough that being ranked at all still matters more than being buried at rank 500.
|
|
64
|
+
*/
|
|
65
|
+
export declare function reciprocalRankFusion(rankings: string[][], k?: number): RankedId[];
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_FIELD_WEIGHTS = void 0;
|
|
4
|
+
exports.tokenizeNodeField = tokenizeNodeField;
|
|
5
|
+
exports.scoreCandidate = scoreCandidate;
|
|
6
|
+
exports.reciprocalRankFusion = reciprocalRankFusion;
|
|
7
|
+
const tokenize_1 = require("../utils/tokenize");
|
|
8
|
+
/**
|
|
9
|
+
* Tokenizes one field's text into deduplicated (token, tf) pairs, ready to write into
|
|
10
|
+
* `node_tokens`. `identifier`/`path` fields use the identifier splitter (camelCase/snake/kebab
|
|
11
|
+
* boundaries) since that's what they actually are; `description`/`reasoning` use the plain
|
|
12
|
+
* natural-language tokenizer since they're already prose.
|
|
13
|
+
*/
|
|
14
|
+
function tokenizeNodeField(text, field) {
|
|
15
|
+
if (!text)
|
|
16
|
+
return [];
|
|
17
|
+
const tokens = field === 'identifier' || field === 'path' ? (0, tokenize_1.tokenizeIdentifier)(text) : (0, tokenize_1.tokenizeText)(text);
|
|
18
|
+
const counts = new Map();
|
|
19
|
+
for (const t of tokens)
|
|
20
|
+
counts.set(t, (counts.get(t) || 0) + 1);
|
|
21
|
+
return Array.from(counts.entries()).map(([token, tf]) => ({ token, field, tf }));
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* `description` outweighs everything else — it's the field written specifically to be found
|
|
25
|
+
* by natural language, so a hit there is the strongest possible signal that this is the right
|
|
26
|
+
* node. `identifier` is still weighted highly since an exact-ish name match is usually right.
|
|
27
|
+
* `reasoning` is last: it explains WHY something changed, not WHAT it is, so it's a weaker
|
|
28
|
+
* signal for "find the code that does X" than the other three.
|
|
29
|
+
*/
|
|
30
|
+
exports.DEFAULT_FIELD_WEIGHTS = {
|
|
31
|
+
description: 4,
|
|
32
|
+
identifier: 3,
|
|
33
|
+
path: 2,
|
|
34
|
+
reasoning: 1.5
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* A saturating-TF, IDF-weighted score for one candidate node across every (field, token) it
|
|
38
|
+
* matched. This is BM25-shaped (the same `tf*(k1+1)/(tf+k1)` saturation and log-IDF term BM25
|
|
39
|
+
* uses) but deliberately simplified: it scores a small, already-narrowed candidate set (nodes
|
|
40
|
+
* that matched at least one query token via a SQL lookup), not a full-corpus scan, so there's
|
|
41
|
+
* no need for BM25's document-length normalization term — every "document" here is one node's
|
|
42
|
+
* handful of fields, not a variable-length passage.
|
|
43
|
+
*/
|
|
44
|
+
function scoreCandidate(matches, weights = exports.DEFAULT_FIELD_WEIGHTS) {
|
|
45
|
+
const K1 = 1.2;
|
|
46
|
+
let score = 0;
|
|
47
|
+
for (const m of matches) {
|
|
48
|
+
const idf = Math.log(1 + (m.totalNodes - m.docFreq + 0.5) / (m.docFreq + 0.5));
|
|
49
|
+
const tfNorm = (m.tf * (K1 + 1)) / (m.tf + K1);
|
|
50
|
+
score += weights[m.field] * Math.max(idf, 0.01) * tfNorm;
|
|
51
|
+
}
|
|
52
|
+
return score;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Reciprocal Rank Fusion — merges the BM25 ranking and the vector-cosine ranking into one list,
|
|
56
|
+
* using each id's POSITION within each ranking rather than the raw scores. Necessary because
|
|
57
|
+
* BM25 scores are unbounded and cosine similarity is bounded [-1,1]; there's no principled scale
|
|
58
|
+
* to sum them on directly, but "1st place" means the same thing in both rankings. An id missing
|
|
59
|
+
* from a ranking simply contributes 0 from it — appearing in both rankings compounds naturally.
|
|
60
|
+
* k=60 is the standard RRF constant (Cormack et al.): large enough that rank 1 vs rank 2 isn't a
|
|
61
|
+
* cliff, small enough that being ranked at all still matters more than being buried at rank 500.
|
|
62
|
+
*/
|
|
63
|
+
function reciprocalRankFusion(rankings, k = 60) {
|
|
64
|
+
const scores = new Map();
|
|
65
|
+
for (const ranking of rankings) {
|
|
66
|
+
ranking.forEach((id, index) => {
|
|
67
|
+
scores.set(id, (scores.get(id) || 0) + 1 / (k + index + 1));
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
return Array.from(scores.entries())
|
|
71
|
+
.map(([id, score]) => ({ id, score }))
|
|
72
|
+
.sort((a, b) => b.score - a.score);
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=search-index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search-index.js","sourceRoot":"","sources":["../../src/db/search-index.ts"],"names":[],"mappings":";;;AAsBA,8CAMC;AAyCD,wCASC;AAgBD,oDAUC;AAxGD,gDAAqE;AAgBrE;;;;;GAKG;AACH,SAAgB,iBAAiB,CAAC,IAA+B,EAAE,KAAiB;IAClF,IAAI,CAAC,IAAI;QAAE,OAAO,EAAE,CAAC;IACrB,MAAM,MAAM,GAAG,KAAK,KAAK,YAAY,IAAI,KAAK,KAAK,MAAM,CAAC,CAAC,CAAC,IAAA,6BAAkB,EAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAA,uBAAY,EA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