sensemaking 0.7.2 → 0.9.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 +90 -61
- package/dist/cjs/cli/check.js +367 -0
- package/dist/cjs/cli/check.js.map +1 -0
- package/dist/cjs/{commands → cli}/index.js +2 -2
- package/dist/cjs/cli/index.js.map +1 -0
- package/dist/cjs/{commands → cli}/init.js +3 -0
- package/dist/cjs/cli/init.js.map +1 -0
- package/dist/cjs/{commands → cli}/map.js +2 -2
- package/dist/cjs/cli/map.js.map +1 -0
- package/dist/cjs/{commands → cli}/named.d.cts +1 -1
- package/dist/cjs/{commands → cli}/named.d.ts +1 -1
- package/dist/cjs/cli/named.js +219 -0
- package/dist/cjs/cli/named.js.map +1 -0
- package/dist/cjs/{commands → cli}/peek.js +2 -2
- package/dist/cjs/cli/peek.js.map +1 -0
- package/dist/cjs/cli/query.js.map +1 -0
- package/dist/cjs/cli/rebuild.js.map +1 -0
- package/dist/cjs/cli/search.d.cts +3 -0
- package/dist/cjs/cli/search.d.ts +3 -0
- package/dist/cjs/{commands/find.js → cli/search.js} +9 -8
- package/dist/cjs/cli/search.js.map +1 -0
- package/dist/cjs/{commands → cli}/shared.d.cts +1 -0
- package/dist/{esm/commands → cjs/cli}/shared.d.ts +1 -0
- package/dist/cjs/{commands → cli}/shared.js +9 -0
- package/dist/cjs/cli/shared.js.map +1 -0
- package/dist/cjs/{commands → cli}/status.js +36 -13
- package/dist/cjs/cli/status.js.map +1 -0
- package/dist/cjs/{commands → cli}/types.d.cts +3 -1
- package/dist/{esm/commands → cjs/cli}/types.d.ts +3 -1
- package/dist/cjs/cli/watch.js.map +1 -0
- package/dist/cjs/cli.js +42 -17
- package/dist/cjs/cli.js.map +1 -1
- package/dist/{esm/verbs.d.ts → cjs/commands.d.cts} +15 -5
- package/dist/cjs/{verbs.d.cts → commands.d.ts} +15 -5
- package/dist/cjs/{verbs.js → commands.js} +329 -39
- package/dist/cjs/commands.js.map +1 -0
- package/dist/cjs/config.d.cts +45 -12
- package/dist/cjs/config.d.ts +45 -12
- package/dist/cjs/config.js +464 -125
- package/dist/cjs/config.js.map +1 -1
- package/dist/cjs/db.d.cts +1 -1
- package/dist/cjs/db.d.ts +1 -1
- package/dist/cjs/db.js +293 -76
- package/dist/cjs/db.js.map +1 -1
- package/dist/cjs/errors.d.cts +1 -1
- package/dist/cjs/errors.d.ts +1 -1
- package/dist/cjs/errors.js.map +1 -1
- package/dist/cjs/features/embed.js +19 -3
- package/dist/cjs/features/embed.js.map +1 -1
- package/dist/cjs/features/links.js +201 -24
- package/dist/cjs/features/links.js.map +1 -1
- package/dist/cjs/features/rank.js +8 -1
- package/dist/cjs/features/rank.js.map +1 -1
- package/dist/cjs/features/types.d.cts +12 -4
- package/dist/cjs/features/types.d.ts +12 -4
- package/dist/cjs/index.d.cts +3 -3
- package/dist/cjs/index.d.ts +3 -3
- package/dist/cjs/index.js +9 -6
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/output.d.cts +16 -0
- package/dist/cjs/output.d.ts +16 -0
- package/dist/cjs/output.js +27 -5
- package/dist/cjs/output.js.map +1 -1
- package/dist/cjs/progress.d.cts +5 -0
- package/dist/cjs/progress.d.ts +5 -0
- package/dist/cjs/progress.js +54 -0
- package/dist/cjs/progress.js.map +1 -0
- package/dist/cjs/scan.d.cts +4 -0
- package/dist/cjs/scan.d.ts +4 -0
- package/dist/cjs/scan.js +87 -6
- package/dist/cjs/scan.js.map +1 -1
- package/dist/esm/{commands → cli}/check.js +41 -22
- package/dist/esm/cli/check.js.map +1 -0
- package/dist/esm/{commands → cli}/index.js +1 -1
- package/dist/esm/cli/index.js.map +1 -0
- package/dist/esm/{commands → cli}/init.js +3 -0
- package/dist/esm/cli/init.js.map +1 -0
- package/dist/esm/{commands → cli}/map.js +1 -1
- package/dist/esm/cli/map.js.map +1 -0
- package/dist/esm/{commands → cli}/named.d.ts +1 -1
- package/dist/esm/cli/named.js +41 -0
- package/dist/esm/cli/named.js.map +1 -0
- package/dist/esm/{commands → cli}/peek.js +1 -1
- package/dist/esm/cli/peek.js.map +1 -0
- package/dist/esm/cli/query.js.map +1 -0
- package/dist/esm/cli/rebuild.js.map +1 -0
- package/dist/esm/cli/search.d.ts +3 -0
- package/dist/esm/cli/search.js +16 -0
- package/dist/esm/cli/search.js.map +1 -0
- package/dist/{cjs/commands → esm/cli}/shared.d.ts +1 -0
- package/dist/esm/{commands → cli}/shared.js +9 -0
- package/dist/esm/cli/shared.js.map +1 -0
- package/dist/esm/{commands → cli}/status.js +17 -11
- package/dist/esm/cli/status.js.map +1 -0
- package/dist/{cjs/commands → esm/cli}/types.d.ts +3 -1
- package/dist/esm/cli/types.js.map +1 -0
- package/dist/esm/cli/watch.js.map +1 -0
- package/dist/esm/cli.js +24 -6
- package/dist/esm/cli.js.map +1 -1
- package/dist/{cjs/verbs.d.ts → esm/commands.d.ts} +15 -5
- package/dist/esm/commands.js +386 -0
- package/dist/esm/commands.js.map +1 -0
- package/dist/esm/config.d.ts +45 -12
- package/dist/esm/config.js +367 -93
- package/dist/esm/config.js.map +1 -1
- package/dist/esm/db.d.ts +1 -1
- package/dist/esm/db.js +126 -17
- package/dist/esm/db.js.map +1 -1
- package/dist/esm/errors.d.ts +1 -1
- package/dist/esm/errors.js.map +1 -1
- package/dist/esm/features/embed.js +18 -2
- package/dist/esm/features/embed.js.map +1 -1
- package/dist/esm/features/links.js +130 -20
- package/dist/esm/features/links.js.map +1 -1
- package/dist/esm/features/rank.js +8 -1
- package/dist/esm/features/rank.js.map +1 -1
- package/dist/esm/features/types.d.ts +12 -4
- package/dist/esm/features/types.js.map +1 -1
- package/dist/esm/index.d.ts +3 -3
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/output.d.ts +16 -0
- package/dist/esm/output.js +20 -5
- package/dist/esm/output.js.map +1 -1
- package/dist/esm/progress.d.ts +5 -0
- package/dist/esm/progress.js +44 -0
- package/dist/esm/progress.js.map +1 -0
- package/dist/esm/scan.d.ts +4 -0
- package/dist/esm/scan.js +37 -6
- package/dist/esm/scan.js.map +1 -1
- package/package.json +12 -2
- package/schema.json +85 -50
- package/skills/sense/EXAMPLES.md +16 -12
- package/skills/sense/SKILL.md +74 -55
- package/skills/sense-setup/EXAMPLES.md +121 -0
- package/skills/sense-setup/SKILL.md +73 -54
- package/dist/cjs/commands/check.js +0 -143
- package/dist/cjs/commands/check.js.map +0 -1
- package/dist/cjs/commands/find.d.cts +0 -3
- package/dist/cjs/commands/find.d.ts +0 -3
- package/dist/cjs/commands/find.js.map +0 -1
- package/dist/cjs/commands/index.js.map +0 -1
- package/dist/cjs/commands/init.js.map +0 -1
- package/dist/cjs/commands/map.js.map +0 -1
- package/dist/cjs/commands/named.js +0 -23
- package/dist/cjs/commands/named.js.map +0 -1
- package/dist/cjs/commands/peek.js.map +0 -1
- package/dist/cjs/commands/query.js.map +0 -1
- package/dist/cjs/commands/rebuild.js.map +0 -1
- package/dist/cjs/commands/shared.js.map +0 -1
- package/dist/cjs/commands/status.js.map +0 -1
- package/dist/cjs/commands/watch.js.map +0 -1
- package/dist/cjs/verbs.js.map +0 -1
- package/dist/esm/commands/check.js.map +0 -1
- package/dist/esm/commands/find.d.ts +0 -3
- package/dist/esm/commands/find.js +0 -15
- package/dist/esm/commands/find.js.map +0 -1
- package/dist/esm/commands/index.js.map +0 -1
- package/dist/esm/commands/init.js.map +0 -1
- package/dist/esm/commands/map.js.map +0 -1
- package/dist/esm/commands/named.js +0 -12
- package/dist/esm/commands/named.js.map +0 -1
- package/dist/esm/commands/peek.js.map +0 -1
- package/dist/esm/commands/query.js.map +0 -1
- package/dist/esm/commands/rebuild.js.map +0 -1
- package/dist/esm/commands/shared.js.map +0 -1
- package/dist/esm/commands/status.js.map +0 -1
- package/dist/esm/commands/types.js.map +0 -1
- package/dist/esm/commands/watch.js.map +0 -1
- package/dist/esm/verbs.js +0 -190
- package/dist/esm/verbs.js.map +0 -1
- /package/dist/cjs/{commands → cli}/check.d.cts +0 -0
- /package/dist/cjs/{commands → cli}/check.d.ts +0 -0
- /package/dist/cjs/{commands → cli}/index.d.cts +0 -0
- /package/dist/cjs/{commands → cli}/index.d.ts +0 -0
- /package/dist/cjs/{commands → cli}/init.d.cts +0 -0
- /package/dist/cjs/{commands → cli}/init.d.ts +0 -0
- /package/dist/cjs/{commands → cli}/map.d.cts +0 -0
- /package/dist/cjs/{commands → cli}/map.d.ts +0 -0
- /package/dist/cjs/{commands → cli}/peek.d.cts +0 -0
- /package/dist/cjs/{commands → cli}/peek.d.ts +0 -0
- /package/dist/cjs/{commands → cli}/query.d.cts +0 -0
- /package/dist/cjs/{commands → cli}/query.d.ts +0 -0
- /package/dist/cjs/{commands → cli}/query.js +0 -0
- /package/dist/cjs/{commands → cli}/rebuild.d.cts +0 -0
- /package/dist/cjs/{commands → cli}/rebuild.d.ts +0 -0
- /package/dist/cjs/{commands → cli}/rebuild.js +0 -0
- /package/dist/cjs/{commands → cli}/status.d.cts +0 -0
- /package/dist/cjs/{commands → cli}/status.d.ts +0 -0
- /package/dist/cjs/{commands → cli}/types.js +0 -0
- /package/dist/cjs/{commands → cli}/types.js.map +0 -0
- /package/dist/cjs/{commands → cli}/watch.d.cts +0 -0
- /package/dist/cjs/{commands → cli}/watch.d.ts +0 -0
- /package/dist/cjs/{commands → cli}/watch.js +0 -0
- /package/dist/esm/{commands → cli}/check.d.ts +0 -0
- /package/dist/esm/{commands → cli}/index.d.ts +0 -0
- /package/dist/esm/{commands → cli}/init.d.ts +0 -0
- /package/dist/esm/{commands → cli}/map.d.ts +0 -0
- /package/dist/esm/{commands → cli}/peek.d.ts +0 -0
- /package/dist/esm/{commands → cli}/query.d.ts +0 -0
- /package/dist/esm/{commands → cli}/query.js +0 -0
- /package/dist/esm/{commands → cli}/rebuild.d.ts +0 -0
- /package/dist/esm/{commands → cli}/rebuild.js +0 -0
- /package/dist/esm/{commands → cli}/status.d.ts +0 -0
- /package/dist/esm/{commands → cli}/types.js +0 -0
- /package/dist/esm/{commands → cli}/watch.d.ts +0 -0
- /package/dist/esm/{commands → cli}/watch.js +0 -0
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { join, matchesGlob } from 'node:path';
|
|
3
|
+
import posix from 'node:path/posix';
|
|
4
|
+
import { anyPresetEmbeds, featureEnabled, featureStates, presetNames, resolveSearch } from './config.js';
|
|
5
|
+
import { SenseError } from './errors.js';
|
|
6
|
+
import { semanticCandidates } from './features/embed.js';
|
|
7
|
+
import { linkEdges } from './features/index.js';
|
|
8
|
+
import { personalizedRank } from './graph.js';
|
|
9
|
+
import { searchError } from './search-error.js';
|
|
10
|
+
// The three commands: mapTree (orient), search (locate), peek (structure).
|
|
11
|
+
// Each returns data; cli.ts renders. All of them degrade when a feature is off.
|
|
12
|
+
const WEIGHTED_BM25 = 'bm25(content, 10.0, 5.0, 1.0)';
|
|
13
|
+
const RRF_K = 60;
|
|
14
|
+
// FTS5 snippet() re-tokenizes the whole doc per candidate row, superlinearly: measured
|
|
15
|
+
// 2ms at 4KB docs but 189ms at 64KB for one query's pool, and ~10s for a single 1MB doc
|
|
16
|
+
// (plans/performance-findings.md finding A). 16KB keeps the whole pool's snippet cost in
|
|
17
|
+
// the low-ms range; bigger docs get the JS-computed excerpt, linear and only for the rows
|
|
18
|
+
// actually returned.
|
|
19
|
+
const SNIPPET_BOUND = 16384;
|
|
20
|
+
const EXCERPT_WINDOW = 160;
|
|
21
|
+
// Bare terms from an FTS5 query string: strips operators/quoting so the oversized-doc excerpt
|
|
22
|
+
// scan matches the same words the query matched on, not FTS5 syntax.
|
|
23
|
+
function extractBareTerms(query) {
|
|
24
|
+
const cleaned = query.replace(/"/g, ' ').replace(/[()*]/g, ' ').replace(/\b(AND|OR|NOT|NEAR)\b(\/\d+)?/gi, ' ');
|
|
25
|
+
return cleaned.split(/\s+/).map((tok)=>tok.replace(/^[A-Za-z_]\w*:/, '')) // column filter, e.g. title:term
|
|
26
|
+
.map((tok)=>tok.toLowerCase().trim()).filter((tok)=>tok.length > 0);
|
|
27
|
+
}
|
|
28
|
+
function findOccurrences(haystackLower, terms) {
|
|
29
|
+
const occ = [];
|
|
30
|
+
for (const term of terms){
|
|
31
|
+
let idx = 0;
|
|
32
|
+
for(;;){
|
|
33
|
+
const found = haystackLower.indexOf(term, idx);
|
|
34
|
+
if (found === -1) break;
|
|
35
|
+
occ.push({
|
|
36
|
+
start: found,
|
|
37
|
+
end: found + term.length,
|
|
38
|
+
term
|
|
39
|
+
});
|
|
40
|
+
idx = found + term.length;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
// Longest span first at equal start, so "tests" beats its substring "test" and the
|
|
44
|
+
// whole word gets highlighted; the emit loop then absorbs the shorter overlap.
|
|
45
|
+
return occ.sort((a, b)=>a.start - b.start || b.end - a.end);
|
|
46
|
+
}
|
|
47
|
+
// Slides a window over the sorted occurrences, same semantics as FTS5's own best-window
|
|
48
|
+
// pick: most distinct terms, ties broken by most total hits.
|
|
49
|
+
function bestWindowStart(occ, windowSize) {
|
|
50
|
+
let best = occ[0].start;
|
|
51
|
+
let bestDistinct = 0;
|
|
52
|
+
let bestCount = 0;
|
|
53
|
+
for(let i = 0; i < occ.length; i++){
|
|
54
|
+
const winEnd = occ[i].start + windowSize;
|
|
55
|
+
const seen = new Set();
|
|
56
|
+
let count = 0;
|
|
57
|
+
for(let j = i; j < occ.length && occ[j].start < winEnd; j++){
|
|
58
|
+
seen.add(occ[j].term);
|
|
59
|
+
count++;
|
|
60
|
+
}
|
|
61
|
+
if (seen.size > bestDistinct || seen.size === bestDistinct && count > bestCount) {
|
|
62
|
+
best = occ[i].start;
|
|
63
|
+
bestDistinct = seen.size;
|
|
64
|
+
bestCount = count;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return best;
|
|
68
|
+
}
|
|
69
|
+
// snippet()-shaped excerpt: matched terms wrapped in «», … at cut edges. Linear in doc
|
|
70
|
+
// length, only run for rows actually returned (<= k), unlike snippet()'s per-row cost.
|
|
71
|
+
function computeExcerpt(text, terms) {
|
|
72
|
+
const occ = findOccurrences(text.toLowerCase(), terms);
|
|
73
|
+
if (occ.length === 0) {
|
|
74
|
+
// This is a raw substring scan, not porter-stemmed: a doc matched only through a
|
|
75
|
+
// stemmed variant (query "negotiate" vs doc "negotiating") finds no occurrence here.
|
|
76
|
+
// Fall back to the doc's start, unmarked, rather than claim a match that isn't there.
|
|
77
|
+
const end = Math.min(text.length, EXCERPT_WINDOW);
|
|
78
|
+
return {
|
|
79
|
+
excerpt: `${text.slice(0, end).replace(/\s+/g, ' ').trim()}${end < text.length ? '…' : ''}`,
|
|
80
|
+
offset: 0
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
const start = bestWindowStart(occ, EXCERPT_WINDOW);
|
|
84
|
+
const end = Math.min(text.length, start + EXCERPT_WINDOW);
|
|
85
|
+
let out = '';
|
|
86
|
+
let cursor = start;
|
|
87
|
+
for (const o of occ){
|
|
88
|
+
if (o.start < start || o.end > end) continue;
|
|
89
|
+
// Occurrences of duplicate or substring-overlapping terms ("test tests") can overlap;
|
|
90
|
+
// emitting each would duplicate document text. Keep the first, absorb the rest.
|
|
91
|
+
if (o.start < cursor) continue;
|
|
92
|
+
out += `${text.slice(cursor, o.start)}«${text.slice(o.start, o.end)}»`;
|
|
93
|
+
cursor = o.end;
|
|
94
|
+
}
|
|
95
|
+
out += text.slice(cursor, end);
|
|
96
|
+
const prefix = start > 0 ? '…' : '';
|
|
97
|
+
const suffix = end < text.length ? '…' : '';
|
|
98
|
+
return {
|
|
99
|
+
excerpt: `${prefix}${out.replace(/\s+/g, ' ')}${suffix}`,
|
|
100
|
+
offset: start
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
function lineNumberAt(text, offset) {
|
|
104
|
+
let line = 1;
|
|
105
|
+
for(let i = 0; i < offset; i++)if (text.charCodeAt(i) === 10) line++;
|
|
106
|
+
return line;
|
|
107
|
+
}
|
|
108
|
+
function lineRangeFor(db, path, line) {
|
|
109
|
+
const row = db.prepare('SELECT start_line, end_line FROM sections WHERE "path" = ? AND start_line <= ? AND end_line >= ? ORDER BY start_line DESC LIMIT 1').get(path, line, line);
|
|
110
|
+
return row ? `L${row.start_line}-${row.end_line}` : null;
|
|
111
|
+
}
|
|
112
|
+
// node:path's matchesGlob is experimental (stable behind an unstable-API flag) as of the
|
|
113
|
+
// engines floor (Node >=22.16); scope filtering only ever needs single-pattern matching, so
|
|
114
|
+
// it's used here in JS rather than pulling fast-glob's directory walk into the query path.
|
|
115
|
+
function inScope(path, include, exclude) {
|
|
116
|
+
if (!include.some((g)=>matchesGlob(path, g))) return false;
|
|
117
|
+
if (exclude === null || exclude === void 0 ? void 0 : exclude.some((g)=>matchesGlob(path, g))) return false;
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
function scopeHasEmbeddings(db, cfg, scopedPaths) {
|
|
121
|
+
if (!anyPresetEmbeds(cfg)) return false; // the embeddings table doesn't exist at all in this case
|
|
122
|
+
const rows = db.prepare('SELECT DISTINCT "path" FROM embeddings').all();
|
|
123
|
+
return rows.some((r)=>scopedPaths.has(r.path));
|
|
124
|
+
}
|
|
125
|
+
// BM25 + link-graph expansion, fused by reciprocal rank. `via` says which signal produced
|
|
126
|
+
// each row so the agent knows what evidence it is trusting.
|
|
127
|
+
// Resolution precedence (built-ins <- preset <- caller overrides) lives in
|
|
128
|
+
// src/config.ts:resolveSearch; `opts` here is whatever the caller (a saved search merged
|
|
129
|
+
// with any CLI flag, or a bare CLI invocation) already resolved.
|
|
130
|
+
export async function search(db, cfg, terms, opts = {}) {
|
|
131
|
+
var _hits_get, _chunkLines_get, _chunkSimilarity_get;
|
|
132
|
+
const effective = resolveSearch(cfg, opts);
|
|
133
|
+
const { k, include, exclude } = effective;
|
|
134
|
+
const allPaths = db.prepare('SELECT "path" FROM frontmatter').all().map((r)=>r.path);
|
|
135
|
+
// A preset scope reads preset_files -- the coverage reconcile actually indexed with
|
|
136
|
+
// (fast-glob semantics); re-matching globs here with node:path's matchesGlob could
|
|
137
|
+
// silently disagree with it. Ad-hoc --include has no persisted coverage, so only that
|
|
138
|
+
// path pays the JS glob match.
|
|
139
|
+
const scopedPaths = opts.include ? new Set(allPaths.filter((p)=>inScope(p, include, exclude))) : new Set(db.prepare('SELECT "path" FROM preset_files WHERE preset = ?').all(effective.presetName).map((r)=>r.path));
|
|
140
|
+
// A scope narrower than the whole index needs a bigger candidate pool before filtering, or
|
|
141
|
+
// filtering can starve k even though enough in-scope matches exist further down the ranked
|
|
142
|
+
// list that a plain over-fetch wouldn't have reached.
|
|
143
|
+
const scopeActive = scopedPaths.size < allPaths.length;
|
|
144
|
+
const fetch = scopeActive ? Math.max(k * 5, 50) : Math.max(k * 3, 30);
|
|
145
|
+
// Semantic participation: vectors run only when the effective setting allows it AND the
|
|
146
|
+
// scope actually has embedded files -- a scope covered only by semantic-false presets (or
|
|
147
|
+
// by no preset embedding at all) searches lexically, automatically, no error.
|
|
148
|
+
const semanticEnabled = effective.semantic && scopeHasEmbeddings(db, cfg, scopedPaths);
|
|
149
|
+
// Terms pass verbatim to FTS5 MATCH: bare words AND-join, operators are the caller's.
|
|
150
|
+
// Invalid syntax propagates as an error, zero matches return zero -- no silent rewrites.
|
|
151
|
+
// --where applies inside the candidate query (a post-filter over the top-N would drop
|
|
152
|
+
// matches ranked past the pool) and again on the final select for link-derived rows.
|
|
153
|
+
// An explicit --where replaces the preset's declared where rather than ANDing with it,
|
|
154
|
+
// so a caller can always widen back to the whole scope.
|
|
155
|
+
const scope = effective.where;
|
|
156
|
+
const whereJoin = scope ? `JOIN frontmatter f ON f."path" = content.path` : '';
|
|
157
|
+
const whereCond = scope ? `AND (${scope})` : '';
|
|
158
|
+
// Docs past SNIPPET_BOUND skip snippet() entirely -- SQLite
|
|
159
|
+
// short-circuits the untaken CASE branch, so it's never invoked on them.
|
|
160
|
+
const matchSql = `SELECT content.path AS path, CASE WHEN length(content.text) <= ${SNIPPET_BOUND} THEN snippet(content, -1, '«', '»', '…', 10) ELSE NULL END AS hit FROM content ${whereJoin} WHERE content MATCH ? ${whereCond} ORDER BY ${WEIGHTED_BM25} LIMIT ${fetch}`;
|
|
161
|
+
let matchRows;
|
|
162
|
+
try {
|
|
163
|
+
matchRows = db.prepare(matchSql).all(terms);
|
|
164
|
+
} catch (err) {
|
|
165
|
+
throw searchError(err, terms, scope);
|
|
166
|
+
}
|
|
167
|
+
// Scope filtering happens in JS, on each candidate list, rather than in SQL: FTS5 match,
|
|
168
|
+
// link expansion, and vector search all run unscoped above (cheap to over-fetch), then get
|
|
169
|
+
// filtered here against the effective include/exclude before ranking is finalized.
|
|
170
|
+
matchRows = matchRows.filter((r)=>scopedPaths.has(r.path));
|
|
171
|
+
const hits = new Map(matchRows.map((r)=>[
|
|
172
|
+
r.path,
|
|
173
|
+
r.hit
|
|
174
|
+
]));
|
|
175
|
+
// hit === null here means the bound suppressed snippet(), not "no match" -- distinguish
|
|
176
|
+
// from via='link' rows (never in matchRows, so absent from this set) below.
|
|
177
|
+
const oversized = new Set(matchRows.filter((r)=>r.hit === null).map((r)=>r.path));
|
|
178
|
+
const candidates = new Map();
|
|
179
|
+
matchRows.forEach((r, i)=>{
|
|
180
|
+
candidates.set(r.path, {
|
|
181
|
+
score: 1 / (RRF_K + i),
|
|
182
|
+
via: 'match'
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
const edges = featureEnabled(cfg, 'links') && matchRows.length > 0 ? linkEdges(db) : [];
|
|
186
|
+
if (edges.length > 0) {
|
|
187
|
+
// `linked` gates the label only, not the score: PPR restart mass gives every seed a
|
|
188
|
+
// nonzero rank even without an incident edge, which is not link evidence — but dropping
|
|
189
|
+
// that mass from the score list reweights fusion toward connectivity and measurably
|
|
190
|
+
// wrecks ranking on link-dense corpora (FEVER hit@10 0.997 -> 0.907; fusion-tuning.md).
|
|
191
|
+
const linked = new Set(edges.flat());
|
|
192
|
+
const seeds = new Map(matchRows.map((r, i)=>[
|
|
193
|
+
r.path,
|
|
194
|
+
1 / (i + 1)
|
|
195
|
+
]));
|
|
196
|
+
const ranked = [
|
|
197
|
+
...personalizedRank(allPaths, edges, seeds)
|
|
198
|
+
].filter(([path, score])=>score > 1e-9 && scopedPaths.has(path)).sort((a, b)=>b[1] - a[1]).slice(0, fetch);
|
|
199
|
+
ranked.forEach(([path], i)=>{
|
|
200
|
+
const existing = candidates.get(path);
|
|
201
|
+
if (existing) {
|
|
202
|
+
existing.score += 1 / (RRF_K + i);
|
|
203
|
+
if (linked.has(path)) existing.via = 'match+link';
|
|
204
|
+
} else {
|
|
205
|
+
candidates.set(path, {
|
|
206
|
+
score: 1 / (RRF_K + i),
|
|
207
|
+
via: 'link'
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
// Vector expansion, invoked only: a third RRF list at the swept flat-region constants
|
|
213
|
+
// (weight 1, pool = fetch). Each row carries its best chunk's line range.
|
|
214
|
+
const chunkLines = new Map();
|
|
215
|
+
const chunkSimilarity = new Map();
|
|
216
|
+
if (semanticEnabled) {
|
|
217
|
+
const vec = (await semanticCandidates(db, cfg, terms, fetch)).filter((v)=>scopedPaths.has(v.path));
|
|
218
|
+
vec.forEach(({ path, lines, similarity }, i)=>{
|
|
219
|
+
chunkLines.set(path, lines);
|
|
220
|
+
chunkSimilarity.set(path, similarity);
|
|
221
|
+
const existing = candidates.get(path);
|
|
222
|
+
if (existing) {
|
|
223
|
+
existing.score += 1 / (RRF_K + i);
|
|
224
|
+
existing.via = `${existing.via}+vector`;
|
|
225
|
+
} else {
|
|
226
|
+
candidates.set(path, {
|
|
227
|
+
score: 1 / (RRF_K + i),
|
|
228
|
+
via: 'vector'
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
db.exec('DROP TABLE IF EXISTS _find');
|
|
234
|
+
db.exec('CREATE TEMP TABLE _find ("path" TEXT PRIMARY KEY, score REAL, via TEXT, hit TEXT, lines TEXT, similarity REAL)');
|
|
235
|
+
const insert = db.prepare('INSERT INTO _find ("path", score, via, hit, lines, similarity) VALUES (?, ?, ?, ?, ?, ?)');
|
|
236
|
+
for (const [path, c] of candidates)insert.run(path, c.score, c.via, (_hits_get = hits.get(path)) !== null && _hits_get !== void 0 ? _hits_get : null, (_chunkLines_get = chunkLines.get(path)) !== null && _chunkLines_get !== void 0 ? _chunkLines_get : null, (_chunkSimilarity_get = chunkSimilarity.get(path)) !== null && _chunkSimilarity_get !== void 0 ? _chunkSimilarity_get : null);
|
|
237
|
+
// Every candidate list was already filtered to scopedPaths above, so _find only ever holds
|
|
238
|
+
// in-scope rows -- the final select just needs --where again, same as before, for rows
|
|
239
|
+
// whichever candidate query didn't itself apply it to (link-derived rows never touched
|
|
240
|
+
// whereCond above).
|
|
241
|
+
const where = scope ? `WHERE (${scope})` : '';
|
|
242
|
+
// lines is always present now: semantic rows carry their chunk's range, oversized-doc
|
|
243
|
+
// lexical rows gain one below, everything else stays null. similarity stays semantic-only.
|
|
244
|
+
const similarityCol = semanticEnabled ? ', _find.similarity' : '';
|
|
245
|
+
const rows = db.prepare(`SELECT f."path" AS path, content.title, content.summary, _find.hit, _find.via, round(_find.score, 4) AS score, _find.lines${similarityCol}
|
|
246
|
+
FROM _find JOIN frontmatter f ON f."path" = _find."path" JOIN content ON content.path = _find."path"
|
|
247
|
+
${where} ORDER BY _find.score DESC LIMIT ?`).all(k);
|
|
248
|
+
if (oversized.size > 0) {
|
|
249
|
+
const bareTerms = extractBareTerms(terms);
|
|
250
|
+
for (const row of rows){
|
|
251
|
+
if (row.hit !== null || !oversized.has(row.path)) continue;
|
|
252
|
+
let text;
|
|
253
|
+
try {
|
|
254
|
+
text = readFileSync(join(cfg.baseDir, row.path), 'utf8');
|
|
255
|
+
} catch {
|
|
256
|
+
continue; // vanished since the match; leave hit/lines null rather than throw
|
|
257
|
+
}
|
|
258
|
+
const { excerpt, offset } = computeExcerpt(text, bareTerms);
|
|
259
|
+
row.hit = excerpt;
|
|
260
|
+
if (row.lines == null) row.lines = featureEnabled(cfg, 'sections') ? lineRangeFor(db, row.path, lineNumberAt(text, offset)) : null;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
return rows;
|
|
264
|
+
}
|
|
265
|
+
// Indexing and embedding are both derived from presets rather than declared directly, so
|
|
266
|
+
// that derivation must stay visible: how many files each preset actually matched, and how
|
|
267
|
+
// many of those are covered by embedding. Read from preset_files (rebuilt at reconcile), not
|
|
268
|
+
// recomputed from globs, so this always reflects what's actually on disk in the cache.
|
|
269
|
+
export function presetCoverage(db, cfg) {
|
|
270
|
+
const embedActive = anyPresetEmbeds(cfg);
|
|
271
|
+
return presetNames(cfg).map((name)=>{
|
|
272
|
+
const files = db.prepare('SELECT COUNT(*) AS n FROM preset_files WHERE preset = ?').get(name).n;
|
|
273
|
+
const embedded = embedActive ? db.prepare('SELECT COUNT(*) AS n FROM preset_files pf WHERE pf.preset = ? AND EXISTS (SELECT 1 FROM embeddings e WHERE e."path" = pf."path" AND e.vector IS NOT NULL)').get(name).n : 0;
|
|
274
|
+
return {
|
|
275
|
+
name,
|
|
276
|
+
files,
|
|
277
|
+
embedded
|
|
278
|
+
};
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
const INTERNAL_COLUMNS = new Set([
|
|
282
|
+
'path',
|
|
283
|
+
'_mtime',
|
|
284
|
+
'_size',
|
|
285
|
+
'_rank'
|
|
286
|
+
]);
|
|
287
|
+
// A result row is capped at SQLITE_MAX_COLUMN (2000, default); two aggregate expressions
|
|
288
|
+
// per field keeps a chunk's row safely under that regardless of how many fields the tree has.
|
|
289
|
+
const MAP_COLUMN_CHUNK = 300;
|
|
290
|
+
function chunk(items, size) {
|
|
291
|
+
const out = [];
|
|
292
|
+
for(let i = 0; i < items.length; i += size)out.push(items.slice(i, i + size));
|
|
293
|
+
return out;
|
|
294
|
+
}
|
|
295
|
+
// mapTree: what is this tree. Fixed-size output regardless of tree size.
|
|
296
|
+
export function mapTree(db, cfg) {
|
|
297
|
+
const docs = db.prepare('SELECT COUNT(*) AS count, COALESCE(SUM("_size"), 0) AS bytes FROM frontmatter').get();
|
|
298
|
+
const columns = db.prepare('PRAGMA table_info(frontmatter)').all().map((r)=>r.name).filter((name)=>!INTERNAL_COLUMNS.has(name));
|
|
299
|
+
// Observed storage class, not a declared one: these columns are added dynamically and
|
|
300
|
+
// SQLite types per value, so a field can be text in most notes and numeric in a few.
|
|
301
|
+
// Listing every distinct type makes both the type and any drift visible.
|
|
302
|
+
// One aggregate scan per chunk of columns rather than one scan per column: COUNT already
|
|
303
|
+
// ignores NULL, and FILTER keeps typeof() looking only at the non-null rows COUNT counted,
|
|
304
|
+
// matching the old per-column `WHERE ... IS NOT NULL` exactly.
|
|
305
|
+
const allFields = [];
|
|
306
|
+
for (const group of chunk(columns, MAP_COLUMN_CHUNK)){
|
|
307
|
+
const exprs = group.map((name, i)=>{
|
|
308
|
+
const quoted = `"${name.split('"').join('""')}"`;
|
|
309
|
+
return `COUNT(${quoted}) AS n${i}, GROUP_CONCAT(DISTINCT typeof(${quoted})) FILTER (WHERE ${quoted} IS NOT NULL) AS t${i}`;
|
|
310
|
+
});
|
|
311
|
+
const result = db.prepare(`SELECT ${exprs.join(', ')} FROM frontmatter`).get();
|
|
312
|
+
group.forEach((name, i)=>{
|
|
313
|
+
var _result_;
|
|
314
|
+
return allFields.push({
|
|
315
|
+
field: name,
|
|
316
|
+
coverage: result[`n${i}`],
|
|
317
|
+
type: (_result_ = result[`t${i}`]) !== null && _result_ !== void 0 ? _result_ : ''
|
|
318
|
+
});
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
allFields.sort((a, b)=>b.coverage - a.coverage);
|
|
322
|
+
const fields = allFields.slice(0, 20);
|
|
323
|
+
const hubs = featureEnabled(cfg, 'rank') ? db.prepare(`SELECT f."path" AS path, round(f."_rank" * 100, 2) AS rank, content.title FROM frontmatter f JOIN content ON content.path = f."path" WHERE f."_rank" IS NOT NULL ORDER BY f."_rank" DESC LIMIT 8`).all() : [];
|
|
324
|
+
const recent = db.prepare(`SELECT "path", datetime("_mtime" / 1000, 'unixepoch') AS modified FROM frontmatter ORDER BY "_mtime" DESC LIMIT 5`).all();
|
|
325
|
+
return {
|
|
326
|
+
docs,
|
|
327
|
+
fields,
|
|
328
|
+
fieldsTotal: allFields.length,
|
|
329
|
+
features: featureStates(cfg),
|
|
330
|
+
presets: presetCoverage(db, cfg),
|
|
331
|
+
hubs,
|
|
332
|
+
recent
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
const PEEK_LIST_LIMIT = 20;
|
|
336
|
+
// peek: everything about one note except its prose -- frontmatter, outline with line
|
|
337
|
+
// ranges + token estimates (so the follow-up Read is a range, not the file), links both ways.
|
|
338
|
+
export function peek(db, cfg, pathArg) {
|
|
339
|
+
var _row__size;
|
|
340
|
+
const paths = db.prepare('SELECT "path" FROM frontmatter').all().map((r)=>r.path);
|
|
341
|
+
let path = paths.find((p)=>p === pathArg);
|
|
342
|
+
if (!path) {
|
|
343
|
+
const base = posix.basename(pathArg).replace(/\.md$/i, '').toLowerCase();
|
|
344
|
+
const matches = paths.filter((p)=>posix.basename(p).replace(/\.md$/i, '').toLowerCase() === base);
|
|
345
|
+
if (matches.length === 1) path = matches[0];
|
|
346
|
+
else if (matches.length > 1) throw new SenseError('NOTE_AMBIGUOUS', `"${pathArg}" is ambiguous: ${matches.join(', ')}`);
|
|
347
|
+
else throw new SenseError('NOTE_NOT_FOUND', `no note matches "${pathArg}"`);
|
|
348
|
+
}
|
|
349
|
+
const row = db.prepare('SELECT * FROM frontmatter WHERE "path" = ?').get(path);
|
|
350
|
+
const frontmatter = {};
|
|
351
|
+
for (const [key, value] of Object.entries(row)){
|
|
352
|
+
if (!INTERNAL_COLUMNS.has(key) && value !== null) frontmatter[key] = value;
|
|
353
|
+
}
|
|
354
|
+
const sectionsTotal = featureEnabled(cfg, 'sections') ? db.prepare('SELECT COUNT(*) AS n FROM sections WHERE "path" = ?').get(path).n : 0;
|
|
355
|
+
const sections = featureEnabled(cfg, 'sections') ? db.prepare('SELECT level, heading, start_line, end_line, tokens FROM sections WHERE "path" = ? ORDER BY idx LIMIT ?').all(path, PEEK_LIST_LIMIT) : [];
|
|
356
|
+
let outbound = [];
|
|
357
|
+
let backlinks = [];
|
|
358
|
+
let unresolved = [];
|
|
359
|
+
let backlinksTotal = 0;
|
|
360
|
+
if (featureEnabled(cfg, 'links')) {
|
|
361
|
+
const out = db.prepare('SELECT target, dst FROM links WHERE src = ? ORDER BY target').all(path);
|
|
362
|
+
outbound = [
|
|
363
|
+
...new Set(out.filter((l)=>l.dst !== null).map((l)=>l.dst))
|
|
364
|
+
];
|
|
365
|
+
unresolved = out.filter((l)=>l.dst === null).map((l)=>l.target);
|
|
366
|
+
backlinksTotal = db.prepare('SELECT COUNT(DISTINCT src) AS n FROM links WHERE dst = ?').get(path).n;
|
|
367
|
+
backlinks = db.prepare('SELECT DISTINCT src FROM links WHERE dst = ? ORDER BY src LIMIT ?').all(path, PEEK_LIST_LIMIT).map((r)=>r.src);
|
|
368
|
+
}
|
|
369
|
+
return {
|
|
370
|
+
path,
|
|
371
|
+
tokens: Math.ceil(((_row__size = row._size) !== null && _row__size !== void 0 ? _row__size : 0) / 4),
|
|
372
|
+
frontmatter,
|
|
373
|
+
sections,
|
|
374
|
+
outbound: outbound.slice(0, PEEK_LIST_LIMIT),
|
|
375
|
+
backlinks,
|
|
376
|
+
unresolved: unresolved.slice(0, PEEK_LIST_LIMIT),
|
|
377
|
+
sectionsTotal,
|
|
378
|
+
outboundTotal: outbound.length,
|
|
379
|
+
backlinksTotal,
|
|
380
|
+
unresolvedTotal: unresolved.length,
|
|
381
|
+
off: [
|
|
382
|
+
'sections',
|
|
383
|
+
'links'
|
|
384
|
+
].filter((name)=>!featureEnabled(cfg, name))
|
|
385
|
+
};
|
|
386
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/commands.ts"],"sourcesContent":["import { readFileSync } from 'node:fs';\nimport { join, matchesGlob } from 'node:path';\nimport posix from 'node:path/posix';\nimport type { DatabaseSync } from 'node:sqlite';\nimport type { FeatureName, ResolvedConfig } from './config.ts';\nimport { anyPresetEmbeds, featureEnabled, featureStates, presetNames, resolveSearch } from './config.ts';\nimport { SenseError } from './errors.ts';\nimport { semanticCandidates } from './features/embed.ts';\nimport { linkEdges } from './features/index.ts';\nimport { personalizedRank } from './graph.ts';\nimport type { Row } from './output.ts';\nimport { searchError } from './search-error.ts';\n\n// The three commands: mapTree (orient), search (locate), peek (structure).\n// Each returns data; cli.ts renders. All of them degrade when a feature is off.\n\nconst WEIGHTED_BM25 = 'bm25(content, 10.0, 5.0, 1.0)';\nconst RRF_K = 60;\n\n// FTS5 snippet() re-tokenizes the whole doc per candidate row, superlinearly: measured\n// 2ms at 4KB docs but 189ms at 64KB for one query's pool, and ~10s for a single 1MB doc\n// (plans/performance-findings.md finding A). 16KB keeps the whole pool's snippet cost in\n// the low-ms range; bigger docs get the JS-computed excerpt, linear and only for the rows\n// actually returned.\nconst SNIPPET_BOUND = 16_384;\nconst EXCERPT_WINDOW = 160;\n\n// Bare terms from an FTS5 query string: strips operators/quoting so the oversized-doc excerpt\n// scan matches the same words the query matched on, not FTS5 syntax.\nfunction extractBareTerms(query: string): string[] {\n const cleaned = query\n .replace(/\"/g, ' ')\n .replace(/[()*]/g, ' ')\n .replace(/\\b(AND|OR|NOT|NEAR)\\b(\\/\\d+)?/gi, ' ');\n return cleaned\n .split(/\\s+/)\n .map((tok) => tok.replace(/^[A-Za-z_]\\w*:/, '')) // column filter, e.g. title:term\n .map((tok) => tok.toLowerCase().trim())\n .filter((tok) => tok.length > 0);\n}\n\nfunction findOccurrences(haystackLower: string, terms: string[]): Array<{ start: number; end: number; term: string }> {\n const occ: Array<{ start: number; end: number; term: string }> = [];\n for (const term of terms) {\n let idx = 0;\n for (;;) {\n const found = haystackLower.indexOf(term, idx);\n if (found === -1) break;\n occ.push({ start: found, end: found + term.length, term });\n idx = found + term.length;\n }\n }\n // Longest span first at equal start, so \"tests\" beats its substring \"test\" and the\n // whole word gets highlighted; the emit loop then absorbs the shorter overlap.\n return occ.sort((a, b) => a.start - b.start || b.end - a.end);\n}\n\n// Slides a window over the sorted occurrences, same semantics as FTS5's own best-window\n// pick: most distinct terms, ties broken by most total hits.\nfunction bestWindowStart(occ: Array<{ start: number; end: number; term: string }>, windowSize: number): number {\n let best = occ[0].start;\n let bestDistinct = 0;\n let bestCount = 0;\n for (let i = 0; i < occ.length; i++) {\n const winEnd = occ[i].start + windowSize;\n const seen = new Set<string>();\n let count = 0;\n for (let j = i; j < occ.length && occ[j].start < winEnd; j++) {\n seen.add(occ[j].term);\n count++;\n }\n if (seen.size > bestDistinct || (seen.size === bestDistinct && count > bestCount)) {\n best = occ[i].start;\n bestDistinct = seen.size;\n bestCount = count;\n }\n }\n return best;\n}\n\n// snippet()-shaped excerpt: matched terms wrapped in «», … at cut edges. Linear in doc\n// length, only run for rows actually returned (<= k), unlike snippet()'s per-row cost.\nfunction computeExcerpt(text: string, terms: string[]): { excerpt: string; offset: number } {\n const occ = findOccurrences(text.toLowerCase(), terms);\n if (occ.length === 0) {\n // This is a raw substring scan, not porter-stemmed: a doc matched only through a\n // stemmed variant (query \"negotiate\" vs doc \"negotiating\") finds no occurrence here.\n // Fall back to the doc's start, unmarked, rather than claim a match that isn't there.\n const end = Math.min(text.length, EXCERPT_WINDOW);\n return { excerpt: `${text.slice(0, end).replace(/\\s+/g, ' ').trim()}${end < text.length ? '…' : ''}`, offset: 0 };\n }\n const start = bestWindowStart(occ, EXCERPT_WINDOW);\n const end = Math.min(text.length, start + EXCERPT_WINDOW);\n let out = '';\n let cursor = start;\n for (const o of occ) {\n if (o.start < start || o.end > end) continue;\n // Occurrences of duplicate or substring-overlapping terms (\"test tests\") can overlap;\n // emitting each would duplicate document text. Keep the first, absorb the rest.\n if (o.start < cursor) continue;\n out += `${text.slice(cursor, o.start)}«${text.slice(o.start, o.end)}»`;\n cursor = o.end;\n }\n out += text.slice(cursor, end);\n const prefix = start > 0 ? '…' : '';\n const suffix = end < text.length ? '…' : '';\n return { excerpt: `${prefix}${out.replace(/\\s+/g, ' ')}${suffix}`, offset: start };\n}\n\nfunction lineNumberAt(text: string, offset: number): number {\n let line = 1;\n for (let i = 0; i < offset; i++) if (text.charCodeAt(i) === 10) line++;\n return line;\n}\n\nfunction lineRangeFor(db: DatabaseSync, path: string, line: number): string | null {\n const row = db.prepare('SELECT start_line, end_line FROM sections WHERE \"path\" = ? AND start_line <= ? AND end_line >= ? ORDER BY start_line DESC LIMIT 1').get(path, line, line) as { start_line: number; end_line: number } | undefined;\n return row ? `L${row.start_line}-${row.end_line}` : null;\n}\n\nexport interface SearchOptions {\n k?: number;\n where?: string; // SQL fragment against frontmatter alias `f`, e.g. \"f.status = 'active'\"\n preset?: string; // named preset; unknown name throws listing declared presets, undefined -> \"default\"\n include?: string[]; // ad hoc scope override (repeatable --include); replaces the preset's include/exclude\n semantic?: boolean; // false opts out of vector participation regardless of the preset\n}\n\n// node:path's matchesGlob is experimental (stable behind an unstable-API flag) as of the\n// engines floor (Node >=22.16); scope filtering only ever needs single-pattern matching, so\n// it's used here in JS rather than pulling fast-glob's directory walk into the query path.\nfunction inScope(path: string, include: string[], exclude?: string[]): boolean {\n if (!include.some((g) => matchesGlob(path, g))) return false;\n if (exclude?.some((g) => matchesGlob(path, g))) return false;\n return true;\n}\n\nfunction scopeHasEmbeddings(db: DatabaseSync, cfg: ResolvedConfig, scopedPaths: Set<string>): boolean {\n if (!anyPresetEmbeds(cfg)) return false; // the embeddings table doesn't exist at all in this case\n const rows = db.prepare('SELECT DISTINCT \"path\" FROM embeddings').all() as Array<{ path: string }>;\n return rows.some((r) => scopedPaths.has(r.path));\n}\n\n// BM25 + link-graph expansion, fused by reciprocal rank. `via` says which signal produced\n// each row so the agent knows what evidence it is trusting.\n// Resolution precedence (built-ins <- preset <- caller overrides) lives in\n// src/config.ts:resolveSearch; `opts` here is whatever the caller (a saved search merged\n// with any CLI flag, or a bare CLI invocation) already resolved.\nexport async function search(db: DatabaseSync, cfg: ResolvedConfig, terms: string, opts: SearchOptions = {}): Promise<Row[]> {\n const effective = resolveSearch(cfg, opts);\n const { k, include, exclude } = effective;\n\n const allPaths = (db.prepare('SELECT \"path\" FROM frontmatter').all() as Array<{ path: string }>).map((r) => r.path);\n // A preset scope reads preset_files -- the coverage reconcile actually indexed with\n // (fast-glob semantics); re-matching globs here with node:path's matchesGlob could\n // silently disagree with it. Ad-hoc --include has no persisted coverage, so only that\n // path pays the JS glob match.\n const scopedPaths = opts.include ? new Set(allPaths.filter((p) => inScope(p, include, exclude))) : new Set((db.prepare('SELECT \"path\" FROM preset_files WHERE preset = ?').all(effective.presetName) as Array<{ path: string }>).map((r) => r.path));\n // A scope narrower than the whole index needs a bigger candidate pool before filtering, or\n // filtering can starve k even though enough in-scope matches exist further down the ranked\n // list that a plain over-fetch wouldn't have reached.\n const scopeActive = scopedPaths.size < allPaths.length;\n const fetch = scopeActive ? Math.max(k * 5, 50) : Math.max(k * 3, 30);\n\n // Semantic participation: vectors run only when the effective setting allows it AND the\n // scope actually has embedded files -- a scope covered only by semantic-false presets (or\n // by no preset embedding at all) searches lexically, automatically, no error.\n const semanticEnabled = effective.semantic && scopeHasEmbeddings(db, cfg, scopedPaths);\n\n // Terms pass verbatim to FTS5 MATCH: bare words AND-join, operators are the caller's.\n // Invalid syntax propagates as an error, zero matches return zero -- no silent rewrites.\n // --where applies inside the candidate query (a post-filter over the top-N would drop\n // matches ranked past the pool) and again on the final select for link-derived rows.\n // An explicit --where replaces the preset's declared where rather than ANDing with it,\n // so a caller can always widen back to the whole scope.\n const scope = effective.where;\n const whereJoin = scope ? `JOIN frontmatter f ON f.\"path\" = content.path` : '';\n const whereCond = scope ? `AND (${scope})` : '';\n // Docs past SNIPPET_BOUND skip snippet() entirely -- SQLite\n // short-circuits the untaken CASE branch, so it's never invoked on them.\n const matchSql = `SELECT content.path AS path, CASE WHEN length(content.text) <= ${SNIPPET_BOUND} THEN snippet(content, -1, '«', '»', '…', 10) ELSE NULL END AS hit FROM content ${whereJoin} WHERE content MATCH ? ${whereCond} ORDER BY ${WEIGHTED_BM25} LIMIT ${fetch}`;\n let matchRows: Array<{ path: string; hit: string | null }>;\n try {\n matchRows = db.prepare(matchSql).all(terms) as Array<{ path: string; hit: string | null }>;\n } catch (err) {\n throw searchError(err as Error, terms, scope);\n }\n // Scope filtering happens in JS, on each candidate list, rather than in SQL: FTS5 match,\n // link expansion, and vector search all run unscoped above (cheap to over-fetch), then get\n // filtered here against the effective include/exclude before ranking is finalized.\n matchRows = matchRows.filter((r) => scopedPaths.has(r.path));\n\n const hits = new Map(matchRows.map((r) => [r.path, r.hit]));\n // hit === null here means the bound suppressed snippet(), not \"no match\" -- distinguish\n // from via='link' rows (never in matchRows, so absent from this set) below.\n const oversized = new Set(matchRows.filter((r) => r.hit === null).map((r) => r.path));\n const candidates = new Map<string, { score: number; via: string }>();\n matchRows.forEach((r, i) => {\n candidates.set(r.path, { score: 1 / (RRF_K + i), via: 'match' });\n });\n\n const edges = featureEnabled(cfg, 'links') && matchRows.length > 0 ? linkEdges(db) : [];\n if (edges.length > 0) {\n // `linked` gates the label only, not the score: PPR restart mass gives every seed a\n // nonzero rank even without an incident edge, which is not link evidence — but dropping\n // that mass from the score list reweights fusion toward connectivity and measurably\n // wrecks ranking on link-dense corpora (FEVER hit@10 0.997 -> 0.907; fusion-tuning.md).\n const linked = new Set(edges.flat());\n const seeds = new Map(matchRows.map((r, i) => [r.path, 1 / (i + 1)]));\n const ranked = [...personalizedRank(allPaths, edges, seeds)]\n .filter(([path, score]) => score > 1e-9 && scopedPaths.has(path))\n .sort((a, b) => b[1] - a[1])\n .slice(0, fetch);\n ranked.forEach(([path], i) => {\n const existing = candidates.get(path);\n if (existing) {\n existing.score += 1 / (RRF_K + i);\n if (linked.has(path)) existing.via = 'match+link';\n } else {\n candidates.set(path, { score: 1 / (RRF_K + i), via: 'link' });\n }\n });\n }\n\n // Vector expansion, invoked only: a third RRF list at the swept flat-region constants\n // (weight 1, pool = fetch). Each row carries its best chunk's line range.\n const chunkLines = new Map<string, string>();\n const chunkSimilarity = new Map<string, number>();\n if (semanticEnabled) {\n const vec = (await semanticCandidates(db, cfg, terms, fetch)).filter((v) => scopedPaths.has(v.path));\n vec.forEach(({ path, lines, similarity }, i) => {\n chunkLines.set(path, lines);\n chunkSimilarity.set(path, similarity);\n const existing = candidates.get(path);\n if (existing) {\n existing.score += 1 / (RRF_K + i);\n existing.via = `${existing.via}+vector`;\n } else {\n candidates.set(path, { score: 1 / (RRF_K + i), via: 'vector' });\n }\n });\n }\n\n db.exec('DROP TABLE IF EXISTS _find');\n db.exec('CREATE TEMP TABLE _find (\"path\" TEXT PRIMARY KEY, score REAL, via TEXT, hit TEXT, lines TEXT, similarity REAL)');\n const insert = db.prepare('INSERT INTO _find (\"path\", score, via, hit, lines, similarity) VALUES (?, ?, ?, ?, ?, ?)');\n for (const [path, c] of candidates) insert.run(path, c.score, c.via, hits.get(path) ?? null, chunkLines.get(path) ?? null, chunkSimilarity.get(path) ?? null);\n\n // Every candidate list was already filtered to scopedPaths above, so _find only ever holds\n // in-scope rows -- the final select just needs --where again, same as before, for rows\n // whichever candidate query didn't itself apply it to (link-derived rows never touched\n // whereCond above).\n const where = scope ? `WHERE (${scope})` : '';\n // lines is always present now: semantic rows carry their chunk's range, oversized-doc\n // lexical rows gain one below, everything else stays null. similarity stays semantic-only.\n const similarityCol = semanticEnabled ? ', _find.similarity' : '';\n const rows = db\n .prepare(\n `SELECT f.\"path\" AS path, content.title, content.summary, _find.hit, _find.via, round(_find.score, 4) AS score, _find.lines${similarityCol}\n FROM _find JOIN frontmatter f ON f.\"path\" = _find.\"path\" JOIN content ON content.path = _find.\"path\"\n ${where} ORDER BY _find.score DESC LIMIT ?`\n )\n .all(k) as Row[];\n\n if (oversized.size > 0) {\n const bareTerms = extractBareTerms(terms);\n for (const row of rows) {\n if (row.hit !== null || !oversized.has(row.path as string)) continue;\n let text: string;\n try {\n text = readFileSync(join(cfg.baseDir, row.path as string), 'utf8');\n } catch {\n continue; // vanished since the match; leave hit/lines null rather than throw\n }\n const { excerpt, offset } = computeExcerpt(text, bareTerms);\n row.hit = excerpt;\n if (row.lines == null) row.lines = featureEnabled(cfg, 'sections') ? lineRangeFor(db, row.path as string, lineNumberAt(text, offset)) : null;\n }\n }\n\n return rows;\n}\n\nexport interface PresetCoverage {\n name: string;\n files: number;\n embedded: number;\n}\n\n// Indexing and embedding are both derived from presets rather than declared directly, so\n// that derivation must stay visible: how many files each preset actually matched, and how\n// many of those are covered by embedding. Read from preset_files (rebuilt at reconcile), not\n// recomputed from globs, so this always reflects what's actually on disk in the cache.\nexport function presetCoverage(db: DatabaseSync, cfg: ResolvedConfig): PresetCoverage[] {\n const embedActive = anyPresetEmbeds(cfg);\n return presetNames(cfg).map((name) => {\n const files = (db.prepare('SELECT COUNT(*) AS n FROM preset_files WHERE preset = ?').get(name) as { n: number }).n;\n const embedded = embedActive ? (db.prepare('SELECT COUNT(*) AS n FROM preset_files pf WHERE pf.preset = ? AND EXISTS (SELECT 1 FROM embeddings e WHERE e.\"path\" = pf.\"path\" AND e.vector IS NOT NULL)').get(name) as { n: number }).n : 0;\n return { name, files, embedded };\n });\n}\n\nexport interface TreeMap {\n docs: { count: number; bytes: number };\n fields: Row[]; // top 20 by coverage; fieldsTotal carries the real count\n fieldsTotal: number;\n features: { on: FeatureName[]; off: FeatureName[] };\n presets: PresetCoverage[];\n hubs: Row[];\n recent: Row[];\n}\n\nconst INTERNAL_COLUMNS = new Set(['path', '_mtime', '_size', '_rank']);\n\n// A result row is capped at SQLITE_MAX_COLUMN (2000, default); two aggregate expressions\n// per field keeps a chunk's row safely under that regardless of how many fields the tree has.\nconst MAP_COLUMN_CHUNK = 300;\n\nfunction chunk<T>(items: T[], size: number): T[][] {\n const out: T[][] = [];\n for (let i = 0; i < items.length; i += size) out.push(items.slice(i, i + size));\n return out;\n}\n\n// mapTree: what is this tree. Fixed-size output regardless of tree size.\nexport function mapTree(db: DatabaseSync, cfg: ResolvedConfig): TreeMap {\n const docs = db.prepare('SELECT COUNT(*) AS count, COALESCE(SUM(\"_size\"), 0) AS bytes FROM frontmatter').get() as { count: number; bytes: number };\n\n const columns = (db.prepare('PRAGMA table_info(frontmatter)').all() as Array<{ name: string }>).map((r) => r.name).filter((name) => !INTERNAL_COLUMNS.has(name));\n // Observed storage class, not a declared one: these columns are added dynamically and\n // SQLite types per value, so a field can be text in most notes and numeric in a few.\n // Listing every distinct type makes both the type and any drift visible.\n // One aggregate scan per chunk of columns rather than one scan per column: COUNT already\n // ignores NULL, and FILTER keeps typeof() looking only at the non-null rows COUNT counted,\n // matching the old per-column `WHERE ... IS NOT NULL` exactly.\n const allFields: Row[] = [];\n for (const group of chunk(columns, MAP_COLUMN_CHUNK)) {\n const exprs = group.map((name, i) => {\n const quoted = `\"${name.split('\"').join('\"\"')}\"`;\n return `COUNT(${quoted}) AS n${i}, GROUP_CONCAT(DISTINCT typeof(${quoted})) FILTER (WHERE ${quoted} IS NOT NULL) AS t${i}`;\n });\n const result = db.prepare(`SELECT ${exprs.join(', ')} FROM frontmatter`).get() as Record<string, number | string | null>;\n group.forEach((name, i) => allFields.push({ field: name, coverage: result[`n${i}`] as number, type: (result[`t${i}`] as string) ?? '' }));\n }\n allFields.sort((a, b) => (b.coverage as number) - (a.coverage as number));\n const fields = allFields.slice(0, 20);\n\n const hubs = featureEnabled(cfg, 'rank') ? (db.prepare(`SELECT f.\"path\" AS path, round(f.\"_rank\" * 100, 2) AS rank, content.title FROM frontmatter f JOIN content ON content.path = f.\"path\" WHERE f.\"_rank\" IS NOT NULL ORDER BY f.\"_rank\" DESC LIMIT 8`).all() as Row[]) : [];\n\n const recent = db.prepare(`SELECT \"path\", datetime(\"_mtime\" / 1000, 'unixepoch') AS modified FROM frontmatter ORDER BY \"_mtime\" DESC LIMIT 5`).all() as Row[];\n\n return { docs, fields, fieldsTotal: allFields.length, features: featureStates(cfg), presets: presetCoverage(db, cfg), hubs, recent };\n}\n\nexport interface Peek {\n path: string;\n tokens: number;\n frontmatter: Row;\n sections: Row[];\n outbound: string[];\n backlinks: string[];\n unresolved: string[];\n // Totals before truncation: a hub can have thousands of backlinks (or a note thousands of\n // headings), and peek's whole point is bounded output. Query the sections/links tables\n // directly for the full list.\n sectionsTotal: number;\n outboundTotal: number;\n backlinksTotal: number;\n unresolvedTotal: number;\n off: FeatureName[]; // disabled features whose blocks are omitted (not empty)\n}\n\nconst PEEK_LIST_LIMIT = 20;\n\n// peek: everything about one note except its prose -- frontmatter, outline with line\n// ranges + token estimates (so the follow-up Read is a range, not the file), links both ways.\nexport function peek(db: DatabaseSync, cfg: ResolvedConfig, pathArg: string): Peek {\n const paths = (db.prepare('SELECT \"path\" FROM frontmatter').all() as Array<{ path: string }>).map((r) => r.path);\n let path = paths.find((p) => p === pathArg);\n if (!path) {\n const base = posix.basename(pathArg).replace(/\\.md$/i, '').toLowerCase();\n const matches = paths.filter((p) => posix.basename(p).replace(/\\.md$/i, '').toLowerCase() === base);\n if (matches.length === 1) path = matches[0];\n else if (matches.length > 1) throw new SenseError('NOTE_AMBIGUOUS', `\"${pathArg}\" is ambiguous: ${matches.join(', ')}`);\n else throw new SenseError('NOTE_NOT_FOUND', `no note matches \"${pathArg}\"`);\n }\n\n const row = db.prepare('SELECT * FROM frontmatter WHERE \"path\" = ?').get(path) as Row;\n const frontmatter: Row = {};\n for (const [key, value] of Object.entries(row)) {\n if (!INTERNAL_COLUMNS.has(key) && value !== null) frontmatter[key] = value;\n }\n\n const sectionsTotal = featureEnabled(cfg, 'sections') ? (db.prepare('SELECT COUNT(*) AS n FROM sections WHERE \"path\" = ?').get(path) as { n: number }).n : 0;\n const sections = featureEnabled(cfg, 'sections') ? (db.prepare('SELECT level, heading, start_line, end_line, tokens FROM sections WHERE \"path\" = ? ORDER BY idx LIMIT ?').all(path, PEEK_LIST_LIMIT) as Row[]) : [];\n\n let outbound: string[] = [];\n let backlinks: string[] = [];\n let unresolved: string[] = [];\n let backlinksTotal = 0;\n if (featureEnabled(cfg, 'links')) {\n const out = db.prepare('SELECT target, dst FROM links WHERE src = ? ORDER BY target').all(path) as Array<{ target: string; dst: string | null }>;\n outbound = [...new Set(out.filter((l) => l.dst !== null).map((l) => l.dst as string))];\n unresolved = out.filter((l) => l.dst === null).map((l) => l.target);\n backlinksTotal = (db.prepare('SELECT COUNT(DISTINCT src) AS n FROM links WHERE dst = ?').get(path) as { n: number }).n;\n backlinks = (db.prepare('SELECT DISTINCT src FROM links WHERE dst = ? ORDER BY src LIMIT ?').all(path, PEEK_LIST_LIMIT) as Array<{ src: string }>).map((r) => r.src);\n }\n\n return {\n path,\n tokens: Math.ceil(((row._size as number) ?? 0) / 4),\n frontmatter,\n sections,\n outbound: outbound.slice(0, PEEK_LIST_LIMIT),\n backlinks,\n unresolved: unresolved.slice(0, PEEK_LIST_LIMIT),\n sectionsTotal,\n outboundTotal: outbound.length,\n backlinksTotal,\n unresolvedTotal: unresolved.length,\n off: (['sections', 'links'] as FeatureName[]).filter((name) => !featureEnabled(cfg, name)),\n };\n}\n"],"names":["readFileSync","join","matchesGlob","posix","anyPresetEmbeds","featureEnabled","featureStates","presetNames","resolveSearch","SenseError","semanticCandidates","linkEdges","personalizedRank","searchError","WEIGHTED_BM25","RRF_K","SNIPPET_BOUND","EXCERPT_WINDOW","extractBareTerms","query","cleaned","replace","split","map","tok","toLowerCase","trim","filter","length","findOccurrences","haystackLower","terms","occ","term","idx","found","indexOf","push","start","end","sort","a","b","bestWindowStart","windowSize","best","bestDistinct","bestCount","i","winEnd","seen","Set","count","j","add","size","computeExcerpt","text","Math","min","excerpt","slice","offset","out","cursor","o","prefix","suffix","lineNumberAt","line","charCodeAt","lineRangeFor","db","path","row","prepare","get","start_line","end_line","inScope","include","exclude","some","g","scopeHasEmbeddings","cfg","scopedPaths","rows","all","r","has","search","opts","hits","chunkLines","chunkSimilarity","effective","k","allPaths","p","presetName","scopeActive","fetch","max","semanticEnabled","semantic","scope","where","whereJoin","whereCond","matchSql","matchRows","err","Map","hit","oversized","candidates","forEach","set","score","via","edges","linked","flat","seeds","ranked","existing","vec","v","lines","similarity","exec","insert","c","run","similarityCol","bareTerms","baseDir","presetCoverage","embedActive","name","files","n","embedded","INTERNAL_COLUMNS","MAP_COLUMN_CHUNK","chunk","items","mapTree","docs","columns","allFields","group","exprs","quoted","result","field","coverage","type","fields","hubs","recent","fieldsTotal","features","presets","PEEK_LIST_LIMIT","peek","pathArg","paths","find","base","basename","matches","frontmatter","key","value","Object","entries","sectionsTotal","sections","outbound","backlinks","unresolved","backlinksTotal","l","dst","target","src","tokens","ceil","_size","outboundTotal","unresolvedTotal","off"],"mappings":"AAAA,SAASA,YAAY,QAAQ,UAAU;AACvC,SAASC,IAAI,EAAEC,WAAW,QAAQ,YAAY;AAC9C,OAAOC,WAAW,kBAAkB;AAGpC,SAASC,eAAe,EAAEC,cAAc,EAAEC,aAAa,EAAEC,WAAW,EAAEC,aAAa,QAAQ,cAAc;AACzG,SAASC,UAAU,QAAQ,cAAc;AACzC,SAASC,kBAAkB,QAAQ,sBAAsB;AACzD,SAASC,SAAS,QAAQ,sBAAsB;AAChD,SAASC,gBAAgB,QAAQ,aAAa;AAE9C,SAASC,WAAW,QAAQ,oBAAoB;AAEhD,2EAA2E;AAC3E,gFAAgF;AAEhF,MAAMC,gBAAgB;AACtB,MAAMC,QAAQ;AAEd,uFAAuF;AACvF,wFAAwF;AACxF,yFAAyF;AACzF,0FAA0F;AAC1F,qBAAqB;AACrB,MAAMC,gBAAgB;AACtB,MAAMC,iBAAiB;AAEvB,8FAA8F;AAC9F,qEAAqE;AACrE,SAASC,iBAAiBC,KAAa;IACrC,MAAMC,UAAUD,MACbE,OAAO,CAAC,MAAM,KACdA,OAAO,CAAC,UAAU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AUA,SAASvH,KAAK,CAAC,GAAGwG;QAC5BgB;QACAC,YAAYA,WAAWzH,KAAK,CAAC,GAAGwG;QAChCa;QACAa,eAAeX,SAASxJ,MAAM;QAC9B2J;QACAS,iBAAiBV,WAAW1J,MAAM;QAClCqK,KAAK,AAAC;YAAC;YAAY;SAAQ,CAAmBtK,MAAM,CAAC,CAACiH,OAAS,CAACvI,eAAegF,KAAKuD;IACtF;AACF"}
|
package/dist/esm/config.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare const CONFIG_FILENAME = "sense.config.json";
|
|
2
2
|
export declare const STATE_DIR = ".sense";
|
|
3
|
-
export declare const SUPPORTED_CONFIG_VERSION =
|
|
3
|
+
export declare const SUPPORTED_CONFIG_VERSION = 3;
|
|
4
4
|
declare const FEATURE_NAMES: readonly ["links", "sections", "rank", "embed"];
|
|
5
5
|
export type FeatureName = (typeof FEATURE_NAMES)[number];
|
|
6
6
|
export interface EmbedConfig {
|
|
@@ -10,25 +10,35 @@ export interface EmbedConfig {
|
|
|
10
10
|
key?: string;
|
|
11
11
|
}
|
|
12
12
|
export declare const DEFAULT_EMBED_MODEL = "minishlab/potion-retrieval-32M";
|
|
13
|
+
export interface Preset {
|
|
14
|
+
include: string[];
|
|
15
|
+
exclude?: string[];
|
|
16
|
+
k?: number;
|
|
17
|
+
semantic?: boolean;
|
|
18
|
+
where?: string;
|
|
19
|
+
}
|
|
20
|
+
export interface SavedSearch {
|
|
21
|
+
search: string;
|
|
22
|
+
preset?: string;
|
|
23
|
+
include?: string[];
|
|
24
|
+
where?: string;
|
|
25
|
+
k?: number;
|
|
26
|
+
semantic?: boolean;
|
|
27
|
+
}
|
|
28
|
+
export type SavedQuery = string | {
|
|
29
|
+
sql: string;
|
|
30
|
+
} | SavedSearch;
|
|
13
31
|
export interface Config {
|
|
14
32
|
$schema?: string;
|
|
15
33
|
version?: number;
|
|
16
|
-
|
|
17
|
-
include: string[];
|
|
18
|
-
};
|
|
34
|
+
presets: Record<string, Preset>;
|
|
19
35
|
features?: {
|
|
20
36
|
links?: boolean;
|
|
21
37
|
sections?: boolean;
|
|
22
38
|
rank?: boolean;
|
|
23
|
-
embed?: boolean | EmbedConfig;
|
|
24
|
-
};
|
|
25
|
-
defaults?: {
|
|
26
|
-
find?: {
|
|
27
|
-
where?: string;
|
|
28
|
-
};
|
|
29
39
|
};
|
|
30
|
-
|
|
31
|
-
queries: Record<string,
|
|
40
|
+
embed?: EmbedConfig;
|
|
41
|
+
queries: Record<string, SavedQuery>;
|
|
32
42
|
}
|
|
33
43
|
export interface ResolvedConfig extends Config {
|
|
34
44
|
baseDir: string;
|
|
@@ -36,6 +46,9 @@ export interface ResolvedConfig extends Config {
|
|
|
36
46
|
unknownKeys?: string[];
|
|
37
47
|
migratedFrom?: number;
|
|
38
48
|
}
|
|
49
|
+
export declare function presetNames(cfg: Config): string[];
|
|
50
|
+
export declare function presetSemanticEnabled(cfg: Config, name: string): boolean;
|
|
51
|
+
export declare function anyPresetEmbeds(cfg: Config): boolean;
|
|
39
52
|
export declare function featureEnabled(cfg: Config, name: FeatureName): boolean;
|
|
40
53
|
export declare function enabledFeatures(cfg: Config): FeatureName[];
|
|
41
54
|
export declare function featureStates(cfg: Config): {
|
|
@@ -49,6 +62,26 @@ export declare function embedConfig(cfg: Config): {
|
|
|
49
62
|
key?: string;
|
|
50
63
|
} | null;
|
|
51
64
|
export declare function featureSignature(cfg: Config): string;
|
|
65
|
+
export declare function resolvePreset(cfg: Config, name?: string): {
|
|
66
|
+
name: string;
|
|
67
|
+
preset: Preset;
|
|
68
|
+
};
|
|
69
|
+
export interface SearchOverrides {
|
|
70
|
+
preset?: string;
|
|
71
|
+
k?: number;
|
|
72
|
+
where?: string;
|
|
73
|
+
include?: string[];
|
|
74
|
+
semantic?: boolean;
|
|
75
|
+
}
|
|
76
|
+
export interface EffectiveSearch {
|
|
77
|
+
presetName: string;
|
|
78
|
+
k: number;
|
|
79
|
+
where?: string;
|
|
80
|
+
include: string[];
|
|
81
|
+
exclude?: string[];
|
|
82
|
+
semantic: boolean;
|
|
83
|
+
}
|
|
84
|
+
export declare function resolveSearch(cfg: Config, opts?: SearchOverrides): EffectiveSearch;
|
|
52
85
|
export declare function migrateConfig(cfg: Config): {
|
|
53
86
|
cfg: Config;
|
|
54
87
|
from: number;
|