sensemaking 0.9.4 → 0.10.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 +50 -100
- package/dist/cjs/cli/check.js +7 -13
- package/dist/cjs/cli/check.js.map +1 -1
- package/dist/cjs/cli/download.d.cts +3 -0
- package/dist/cjs/cli/download.d.ts +3 -0
- package/dist/cjs/cli/download.js +214 -0
- package/dist/cjs/cli/download.js.map +1 -0
- package/dist/cjs/cli/index.d.cts +6 -3
- package/dist/cjs/cli/index.d.ts +6 -3
- package/dist/cjs/cli/index.js +23 -5
- package/dist/cjs/cli/index.js.map +1 -1
- package/dist/cjs/cli/init.js +4 -1
- package/dist/cjs/cli/init.js.map +1 -1
- package/dist/cjs/cli/map.js +2 -2
- package/dist/cjs/cli/map.js.map +1 -1
- package/dist/cjs/cli/named.js +10 -18
- package/dist/cjs/cli/named.js.map +1 -1
- package/dist/cjs/cli/path.d.cts +3 -0
- package/dist/cjs/cli/path.d.ts +3 -0
- package/dist/cjs/cli/path.js +161 -0
- package/dist/cjs/cli/path.js.map +1 -0
- package/dist/cjs/cli/peek.js +3 -2
- package/dist/cjs/cli/peek.js.map +1 -1
- package/dist/cjs/cli/related.d.cts +3 -0
- package/dist/cjs/cli/related.d.ts +3 -0
- package/dist/cjs/cli/related.js +279 -0
- package/dist/cjs/cli/related.js.map +1 -0
- package/dist/cjs/cli/search.js +3 -7
- package/dist/cjs/cli/search.js.map +1 -1
- package/dist/cjs/cli/shared.d.cts +3 -1
- package/dist/cjs/cli/shared.d.ts +3 -1
- package/dist/cjs/cli/shared.js +28 -5
- package/dist/cjs/cli/shared.js.map +1 -1
- package/dist/cjs/cli/sql.d.cts +3 -0
- package/dist/cjs/cli/sql.d.ts +3 -0
- package/dist/cjs/cli/{query.js → sql.js} +4 -4
- package/dist/cjs/cli/sql.js.map +1 -0
- package/dist/cjs/cli/status.js +9 -2
- package/dist/cjs/cli/status.js.map +1 -1
- package/dist/cjs/cli.js +14 -15
- package/dist/cjs/cli.js.map +1 -1
- package/dist/cjs/commands.d.cts +12 -4
- package/dist/cjs/commands.d.ts +12 -4
- package/dist/cjs/commands.js +138 -58
- package/dist/cjs/commands.js.map +1 -1
- package/dist/cjs/config.d.cts +6 -4
- package/dist/cjs/config.d.ts +6 -4
- package/dist/cjs/config.js +137 -58
- package/dist/cjs/config.js.map +1 -1
- package/dist/cjs/db.js +14 -34
- 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.d.cts +14 -0
- package/dist/cjs/features/embed.d.ts +14 -0
- package/dist/cjs/features/embed.js +248 -54
- package/dist/cjs/features/embed.js.map +1 -1
- package/dist/cjs/features/links.js +7 -16
- package/dist/cjs/features/links.js.map +1 -1
- package/dist/cjs/features/rank.js +2 -6
- package/dist/cjs/features/rank.js.map +1 -1
- package/dist/cjs/index.d.cts +1 -1
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/output.js +11 -14
- package/dist/cjs/output.js.map +1 -1
- package/dist/cjs/progress.js +2 -4
- package/dist/cjs/progress.js.map +1 -1
- package/dist/cjs/scan.d.cts +1 -0
- package/dist/cjs/scan.d.ts +1 -0
- package/dist/cjs/scan.js +67 -32
- package/dist/cjs/scan.js.map +1 -1
- package/dist/cjs/search-error.js +4 -6
- package/dist/cjs/search-error.js.map +1 -1
- package/dist/cjs/traverse.d.cts +8 -0
- package/dist/cjs/traverse.d.ts +8 -0
- package/dist/cjs/traverse.js +97 -0
- package/dist/cjs/traverse.js.map +1 -0
- package/dist/esm/cli/check.js +7 -13
- package/dist/esm/cli/check.js.map +1 -1
- package/dist/esm/cli/download.d.ts +3 -0
- package/dist/esm/cli/download.js +27 -0
- package/dist/esm/cli/download.js.map +1 -0
- package/dist/esm/cli/index.d.ts +6 -3
- package/dist/esm/cli/index.js +13 -7
- package/dist/esm/cli/index.js.map +1 -1
- package/dist/esm/cli/init.js +4 -1
- package/dist/esm/cli/init.js.map +1 -1
- package/dist/esm/cli/map.js +3 -2
- package/dist/esm/cli/map.js.map +1 -1
- package/dist/esm/cli/named.js +10 -16
- package/dist/esm/cli/named.js.map +1 -1
- package/dist/esm/cli/path.d.ts +3 -0
- package/dist/esm/cli/path.js +51 -0
- package/dist/esm/cli/path.js.map +1 -0
- package/dist/esm/cli/peek.js +4 -2
- package/dist/esm/cli/peek.js.map +1 -1
- package/dist/esm/cli/related.d.ts +3 -0
- package/dist/esm/cli/related.js +26 -0
- package/dist/esm/cli/related.js.map +1 -0
- package/dist/esm/cli/search.js +2 -5
- package/dist/esm/cli/search.js.map +1 -1
- package/dist/esm/cli/shared.d.ts +3 -1
- package/dist/esm/cli/shared.js +28 -5
- package/dist/esm/cli/shared.js.map +1 -1
- package/dist/esm/cli/sql.d.ts +3 -0
- package/dist/esm/cli/{query.js → sql.js} +4 -4
- package/dist/esm/cli/sql.js.map +1 -0
- package/dist/esm/cli/status.js +8 -1
- package/dist/esm/cli/status.js.map +1 -1
- package/dist/esm/cli.js +13 -10
- package/dist/esm/cli.js.map +1 -1
- package/dist/esm/commands.d.ts +12 -4
- package/dist/esm/commands.js +111 -68
- package/dist/esm/commands.js.map +1 -1
- package/dist/esm/config.d.ts +6 -4
- package/dist/esm/config.js +126 -75
- package/dist/esm/config.js.map +1 -1
- package/dist/esm/db.js +16 -38
- 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.d.ts +14 -0
- package/dist/esm/features/embed.js +110 -35
- package/dist/esm/features/embed.js.map +1 -1
- package/dist/esm/features/links.js +8 -17
- package/dist/esm/features/links.js.map +1 -1
- package/dist/esm/features/rank.js +2 -6
- package/dist/esm/features/rank.js.map +1 -1
- package/dist/esm/features/types.js.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/output.js +13 -16
- package/dist/esm/output.js.map +1 -1
- package/dist/esm/progress.js +2 -4
- package/dist/esm/progress.js.map +1 -1
- package/dist/esm/scan.d.ts +1 -0
- package/dist/esm/scan.js +41 -34
- package/dist/esm/scan.js.map +1 -1
- package/dist/esm/search-error.js +4 -6
- package/dist/esm/search-error.js.map +1 -1
- package/dist/esm/traverse.d.ts +8 -0
- package/dist/esm/traverse.js +71 -0
- package/dist/esm/traverse.js.map +1 -0
- package/package.json +18 -5
- package/schema.json +12 -16
- package/skills/sense/EXAMPLES.md +13 -22
- package/skills/sense/SKILL.md +65 -140
- package/skills/sense-setup/EXAMPLES.md +30 -46
- package/skills/sense-setup/SKILL.md +22 -83
- package/dist/cjs/cli/query.d.cts +0 -3
- package/dist/cjs/cli/query.d.ts +0 -3
- package/dist/cjs/cli/query.js.map +0 -1
- package/dist/esm/cli/query.d.ts +0 -3
- package/dist/esm/cli/query.js.map +0 -1
package/dist/esm/commands.js
CHANGED
|
@@ -3,7 +3,7 @@ import { join, matchesGlob } from 'node:path';
|
|
|
3
3
|
import posix from 'node:path/posix';
|
|
4
4
|
import { anyPresetEmbeds, featureEnabled, featureStates, presetNames, resolveSearch } from './config.js';
|
|
5
5
|
import { SenseError } from './errors.js';
|
|
6
|
-
import { semanticCandidates } from './features/embed.js';
|
|
6
|
+
import { embedPending, modelPresent, semanticCandidates, similarNotes } from './features/embed.js';
|
|
7
7
|
import { linkEdges } from './features/index.js';
|
|
8
8
|
import { personalizedRank } from './graph.js';
|
|
9
9
|
import { searchError } from './search-error.js';
|
|
@@ -11,11 +11,8 @@ import { searchError } from './search-error.js';
|
|
|
11
11
|
// Each returns data; cli.ts renders. All of them degrade when a feature is off.
|
|
12
12
|
const WEIGHTED_BM25 = 'bm25(content, 10.0, 5.0, 1.0)';
|
|
13
13
|
const RRF_K = 60;
|
|
14
|
-
//
|
|
15
|
-
//
|
|
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.
|
|
14
|
+
// snippet() re-tokenizes each candidate doc, superlinearly: ~10s for one 1MB doc
|
|
15
|
+
// (BENCHMARKING.md). Past this bound, rows get the linear JS excerpt instead.
|
|
19
16
|
const SNIPPET_BOUND = 16384;
|
|
20
17
|
const EXCERPT_WINDOW = 160;
|
|
21
18
|
// Bare terms from an FTS5 query string: strips operators/quoting so the oversized-doc excerpt
|
|
@@ -110,8 +107,8 @@ function lineRangeFor(db, path, line) {
|
|
|
110
107
|
return row ? `L${row.start_line}-${row.end_line}` : null;
|
|
111
108
|
}
|
|
112
109
|
// node:path's matchesGlob is experimental (stable behind an unstable-API flag) as of the
|
|
113
|
-
// engines floor (Node >=22.
|
|
114
|
-
// it's used here in JS rather than
|
|
110
|
+
// engines floor (Node >=22.20); scope filtering only ever needs single-pattern matching, so
|
|
111
|
+
// it's used here in JS rather than running a directory walk in the query path.
|
|
115
112
|
function inScope(path, include, exclude) {
|
|
116
113
|
if (!include.some((g)=>matchesGlob(path, g))) return false;
|
|
117
114
|
if (exclude === null || exclude === void 0 ? void 0 : exclude.some((g)=>matchesGlob(path, g))) return false;
|
|
@@ -122,36 +119,32 @@ function scopeHasEmbeddings(db, cfg, scopedPaths) {
|
|
|
122
119
|
const rows = db.prepare('SELECT DISTINCT "path" FROM embeddings').all();
|
|
123
120
|
return rows.some((r)=>scopedPaths.has(r.path));
|
|
124
121
|
}
|
|
125
|
-
// BM25 + link
|
|
126
|
-
//
|
|
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.
|
|
122
|
+
// BM25 + link expansion + vectors, fused by reciprocal rank; `via` names the signal per row.
|
|
123
|
+
// `opts` arrives already resolved (config.ts:resolveSearch).
|
|
130
124
|
export async function search(db, cfg, terms, opts = {}) {
|
|
131
125
|
var _hits_get, _chunkLines_get, _chunkSimilarity_get;
|
|
132
126
|
const effective = resolveSearch(cfg, opts);
|
|
133
127
|
const { k, include, exclude } = effective;
|
|
134
128
|
const allPaths = db.prepare('SELECT "path" FROM frontmatter').all().map((r)=>r.path);
|
|
135
|
-
// A preset scope reads
|
|
136
|
-
//
|
|
137
|
-
|
|
138
|
-
|
|
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));
|
|
129
|
+
// A preset scope reads the coverage reconcile indexed; re-matching globs here could disagree
|
|
130
|
+
// with it. Only ad-hoc scope flags, which have no persisted coverage, pay the JS match.
|
|
131
|
+
const adHocScope = opts.include !== undefined || opts.exclude !== undefined || opts.noExclude === true;
|
|
132
|
+
const scopedPaths = adHocScope ? 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
133
|
// A scope narrower than the whole index needs a bigger candidate pool before filtering, or
|
|
141
134
|
// filtering can starve k even though enough in-scope matches exist further down the ranked
|
|
142
135
|
// list that a plain over-fetch wouldn't have reached.
|
|
143
136
|
const scopeActive = scopedPaths.size < allPaths.length;
|
|
144
137
|
const fetch = scopeActive ? Math.max(k * 5, 50) : Math.max(k * 3, 30);
|
|
145
|
-
//
|
|
146
|
-
//
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
//
|
|
153
|
-
//
|
|
154
|
-
//
|
|
138
|
+
// Asking for vectors without a model is a misconfiguration, not a mode: degrading would make
|
|
139
|
+
// the same search answer differently before and after a download. semantic:false never asks.
|
|
140
|
+
const wantsVectors = !opts.probe && effective.semantic && anyPresetEmbeds(cfg);
|
|
141
|
+
if (wantsVectors && !modelPresent(cfg)) {
|
|
142
|
+
throw new SenseError('EMBED_MODEL_MISSING', `preset "${effective.presetName}" searches with vectors, but the embedding model is not available; run \`sense download\`, or set "semantic": false on that preset to search on words and links`);
|
|
143
|
+
}
|
|
144
|
+
const semanticEnabled = wantsVectors && scopeHasEmbeddings(db, cfg, scopedPaths);
|
|
145
|
+
// Terms pass verbatim to MATCH; invalid syntax errors rather than being rewritten. --where
|
|
146
|
+
// applies inside the candidate query (a post-filter would drop matches ranked past the pool)
|
|
147
|
+
// and again on the final select, for link-derived rows.
|
|
155
148
|
const scope = effective.where;
|
|
156
149
|
const whereJoin = scope ? `JOIN frontmatter f ON f."path" = content.path` : '';
|
|
157
150
|
const whereCond = scope ? `AND (${scope})` : '';
|
|
@@ -184,10 +177,8 @@ export async function search(db, cfg, terms, opts = {}) {
|
|
|
184
177
|
});
|
|
185
178
|
const edges = featureEnabled(cfg, 'links') && matchRows.length > 0 ? linkEdges(db) : [];
|
|
186
179
|
if (edges.length > 0) {
|
|
187
|
-
//
|
|
188
|
-
//
|
|
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).
|
|
180
|
+
// Gates the label only, not the score: restart mass ranks every seed without an incident
|
|
181
|
+
// edge, but dropping it from the score reweights fusion (FEVER hit@10 0.997 -> 0.907).
|
|
191
182
|
const linked = new Set(edges.flat());
|
|
192
183
|
const seeds = new Map(matchRows.map((r, i)=>[
|
|
193
184
|
r.path,
|
|
@@ -230,21 +221,19 @@ export async function search(db, cfg, terms, opts = {}) {
|
|
|
230
221
|
}
|
|
231
222
|
});
|
|
232
223
|
}
|
|
233
|
-
db.exec('DROP TABLE IF EXISTS
|
|
234
|
-
db.exec('CREATE TEMP TABLE
|
|
235
|
-
const insert = db.prepare('INSERT INTO
|
|
224
|
+
db.exec('DROP TABLE IF EXISTS _search');
|
|
225
|
+
db.exec('CREATE TEMP TABLE _search ("path" TEXT PRIMARY KEY, score REAL, via TEXT, hit TEXT, lines TEXT, similarity REAL)');
|
|
226
|
+
const insert = db.prepare('INSERT INTO _search ("path", score, via, hit, lines, similarity) VALUES (?, ?, ?, ?, ?, ?)');
|
|
236
227
|
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
|
-
//
|
|
238
|
-
//
|
|
239
|
-
// whichever candidate query didn't itself apply it to (link-derived rows never touched
|
|
240
|
-
// whereCond above).
|
|
228
|
+
// Already scope-filtered above; the final select reapplies --where only for link-derived
|
|
229
|
+
// rows, which never passed through whereCond.
|
|
241
230
|
const where = scope ? `WHERE (${scope})` : '';
|
|
242
231
|
// lines is always present now: semantic rows carry their chunk's range, oversized-doc
|
|
243
232
|
// lexical rows gain one below, everything else stays null. similarity stays semantic-only.
|
|
244
|
-
const similarityCol = semanticEnabled ? ',
|
|
245
|
-
const rows = db.prepare(`SELECT f."path" AS path, content.title, content.summary,
|
|
246
|
-
FROM
|
|
247
|
-
${where} ORDER BY
|
|
233
|
+
const similarityCol = semanticEnabled ? ', _search.similarity' : '';
|
|
234
|
+
const rows = db.prepare(`SELECT f."path" AS path, content.title, content.summary, _search.hit, _search.via, round(_search.score, 4) AS score, _search.lines${similarityCol}
|
|
235
|
+
FROM _search JOIN frontmatter f ON f."path" = _search."path" JOIN content ON content.path = _search."path"
|
|
236
|
+
${where} ORDER BY _search.score DESC LIMIT ?`).all(k);
|
|
248
237
|
if (oversized.size > 0) {
|
|
249
238
|
const bareTerms = extractBareTerms(terms);
|
|
250
239
|
for (const row of rows){
|
|
@@ -262,10 +251,24 @@ export async function search(db, cfg, terms, opts = {}) {
|
|
|
262
251
|
}
|
|
263
252
|
return rows;
|
|
264
253
|
}
|
|
265
|
-
//
|
|
266
|
-
//
|
|
267
|
-
//
|
|
268
|
-
|
|
254
|
+
// The scope resolver for non-search commands (path, peek, map): same coverage rule search()
|
|
255
|
+
// applies (preset_files for a named preset, JS glob matching for an ad hoc include/exclude),
|
|
256
|
+
// then narrowed by the resolved `where`.
|
|
257
|
+
export function scopedPaths(db, cfg, overrides) {
|
|
258
|
+
const effective = resolveSearch(cfg, overrides);
|
|
259
|
+
const { include, exclude, where } = effective;
|
|
260
|
+
const allPaths = db.prepare('SELECT "path" FROM frontmatter').all().map((r)=>r.path);
|
|
261
|
+
const adHocScope = overrides.include !== undefined || overrides.exclude !== undefined || overrides.noExclude === true;
|
|
262
|
+
const paths = adHocScope ? 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));
|
|
263
|
+
if (!where) return paths;
|
|
264
|
+
const whereRows = db.prepare(`SELECT "path" FROM frontmatter f WHERE (${where})`).all();
|
|
265
|
+
const wherePaths = new Set(whereRows.map((r)=>r.path));
|
|
266
|
+
return new Set([
|
|
267
|
+
...paths
|
|
268
|
+
].filter((p)=>wherePaths.has(p)));
|
|
269
|
+
}
|
|
270
|
+
// Indexing derives from presets, so the derivation stays visible. Read from preset_files, not
|
|
271
|
+
// recomputed from globs, so it reflects the cache rather than the config.
|
|
269
272
|
export function presetCoverage(db, cfg) {
|
|
270
273
|
const embedActive = anyPresetEmbeds(cfg);
|
|
271
274
|
return presetNames(cfg).map((name)=>{
|
|
@@ -292,23 +295,32 @@ function chunk(items, size) {
|
|
|
292
295
|
for(let i = 0; i < items.length; i += size)out.push(items.slice(i, i + size));
|
|
293
296
|
return out;
|
|
294
297
|
}
|
|
295
|
-
//
|
|
296
|
-
|
|
297
|
-
|
|
298
|
+
// Materializes the resolved scope into a temp table (same shape as traverse.ts's
|
|
299
|
+
// allowed_nodes) so every mapTree query can join/filter against it cheaply.
|
|
300
|
+
function setupMapScope(db, paths) {
|
|
301
|
+
db.exec('DROP TABLE IF EXISTS _map_scope');
|
|
302
|
+
db.exec('CREATE TEMP TABLE _map_scope ("path" TEXT PRIMARY KEY)');
|
|
303
|
+
db.prepare('INSERT INTO _map_scope SELECT DISTINCT value FROM json_each(?1)').run(JSON.stringify([
|
|
304
|
+
...paths
|
|
305
|
+
]));
|
|
306
|
+
}
|
|
307
|
+
// What is this scope: fixed-size output regardless of tree size. Coverage and features stay
|
|
308
|
+
// global -- they describe the tree, not the current question.
|
|
309
|
+
export function mapTree(db, cfg, overrides = {}) {
|
|
310
|
+
setupMapScope(db, scopedPaths(db, cfg, overrides));
|
|
311
|
+
const scopeWhere = 'WHERE "path" IN (SELECT "path" FROM _map_scope)';
|
|
312
|
+
const scopeAnd = 'AND f."path" IN (SELECT "path" FROM _map_scope)';
|
|
313
|
+
const docs = db.prepare(`SELECT COUNT(*) AS count, COALESCE(SUM("_size"), 0) AS bytes FROM frontmatter ${scopeWhere}`).get();
|
|
298
314
|
const columns = db.prepare('PRAGMA table_info(frontmatter)').all().map((r)=>r.name).filter((name)=>!INTERNAL_COLUMNS.has(name));
|
|
299
|
-
// Observed
|
|
300
|
-
//
|
|
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.
|
|
315
|
+
// Observed types, not declared: SQLite types per value, so a field can be text in most notes
|
|
316
|
+
// and numeric in a few. One aggregate scan per chunk of columns; FILTER matches COUNT's nulls.
|
|
305
317
|
const allFields = [];
|
|
306
318
|
for (const group of chunk(columns, MAP_COLUMN_CHUNK)){
|
|
307
319
|
const exprs = group.map((name, i)=>{
|
|
308
320
|
const quoted = `"${name.split('"').join('""')}"`;
|
|
309
321
|
return `COUNT(${quoted}) AS n${i}, GROUP_CONCAT(DISTINCT typeof(${quoted})) FILTER (WHERE ${quoted} IS NOT NULL) AS t${i}`;
|
|
310
322
|
});
|
|
311
|
-
const result = db.prepare(`SELECT ${exprs.join(', ')} FROM frontmatter`).get();
|
|
323
|
+
const result = db.prepare(`SELECT ${exprs.join(', ')} FROM frontmatter ${scopeWhere}`).get();
|
|
312
324
|
group.forEach((name, i)=>{
|
|
313
325
|
var _result_;
|
|
314
326
|
return allFields.push({
|
|
@@ -320,8 +332,8 @@ export function mapTree(db, cfg) {
|
|
|
320
332
|
}
|
|
321
333
|
allFields.sort((a, b)=>b.coverage - a.coverage);
|
|
322
334
|
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();
|
|
335
|
+
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 ${scopeAnd} ORDER BY f."_rank" DESC LIMIT 8`).all() : [];
|
|
336
|
+
const recent = db.prepare(`SELECT "path", datetime("_mtime" / 1000, 'unixepoch') AS modified FROM frontmatter ${scopeWhere} ORDER BY "_mtime" DESC LIMIT 5`).all();
|
|
325
337
|
return {
|
|
326
338
|
docs,
|
|
327
339
|
fields,
|
|
@@ -332,20 +344,24 @@ export function mapTree(db, cfg) {
|
|
|
332
344
|
recent
|
|
333
345
|
};
|
|
334
346
|
}
|
|
347
|
+
// Note resolution shared by peek and path: an exact path, or a unique basename (case
|
|
348
|
+
// insensitive, .md stripped).
|
|
349
|
+
export function resolveNote(paths, arg) {
|
|
350
|
+
const exact = paths.find((p)=>p === arg);
|
|
351
|
+
if (exact) return exact;
|
|
352
|
+
const base = posix.basename(arg).replace(/\.md$/i, '').toLowerCase();
|
|
353
|
+
const matches = paths.filter((p)=>posix.basename(p).replace(/\.md$/i, '').toLowerCase() === base);
|
|
354
|
+
if (matches.length === 1) return matches[0];
|
|
355
|
+
if (matches.length > 1) throw new SenseError('NOTE_AMBIGUOUS', `"${arg}" is ambiguous: ${matches.join(', ')}`);
|
|
356
|
+
throw new SenseError('NOTE_NOT_FOUND', `no note matches "${arg}"`);
|
|
357
|
+
}
|
|
335
358
|
const PEEK_LIST_LIMIT = 20;
|
|
336
359
|
// peek: everything about one note except its prose -- frontmatter, outline with line
|
|
337
360
|
// ranges + token estimates (so the follow-up Read is a range, not the file), links both ways.
|
|
338
|
-
export function peek(db, cfg, pathArg) {
|
|
361
|
+
export function peek(db, cfg, pathArg, overrides = {}) {
|
|
339
362
|
var _row__size;
|
|
340
363
|
const paths = db.prepare('SELECT "path" FROM frontmatter').all().map((r)=>r.path);
|
|
341
|
-
|
|
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
|
-
}
|
|
364
|
+
const path = resolveNote(paths, pathArg);
|
|
349
365
|
const row = db.prepare('SELECT * FROM frontmatter WHERE "path" = ?').get(path);
|
|
350
366
|
const frontmatter = {};
|
|
351
367
|
for (const [key, value] of Object.entries(row)){
|
|
@@ -357,6 +373,7 @@ export function peek(db, cfg, pathArg) {
|
|
|
357
373
|
let backlinks = [];
|
|
358
374
|
let unresolved = [];
|
|
359
375
|
let backlinksTotal = 0;
|
|
376
|
+
const _allowed = scopedPaths(db, cfg, overrides);
|
|
360
377
|
if (featureEnabled(cfg, 'links')) {
|
|
361
378
|
const out = db.prepare('SELECT target, dst FROM links WHERE src = ? ORDER BY target').all(path);
|
|
362
379
|
outbound = [
|
|
@@ -384,3 +401,29 @@ export function peek(db, cfg, pathArg) {
|
|
|
384
401
|
].filter((name)=>!featureEnabled(cfg, name))
|
|
385
402
|
};
|
|
386
403
|
}
|
|
404
|
+
// Notes most similar by cosine, excluding self and everything already linked either way.
|
|
405
|
+
// Its own command, not a peek section: a full embeddings scan is ~480ms at 26k notes.
|
|
406
|
+
export async function relatedNotes(db, cfg, pathArg, overrides, k) {
|
|
407
|
+
const paths = db.prepare('SELECT "path" FROM frontmatter').all().map((r)=>r.path);
|
|
408
|
+
const path = resolveNote(paths, pathArg);
|
|
409
|
+
const outbound = db.prepare('SELECT DISTINCT dst FROM links WHERE src = ? AND dst IS NOT NULL').all(path).map((r)=>r.dst);
|
|
410
|
+
const backlinks = db.prepare('SELECT DISTINCT src FROM links WHERE dst = ?').all(path).map((r)=>r.src);
|
|
411
|
+
const exclude = new Set([
|
|
412
|
+
path,
|
|
413
|
+
...outbound,
|
|
414
|
+
...backlinks
|
|
415
|
+
]);
|
|
416
|
+
const allowed = scopedPaths(db, cfg, overrides);
|
|
417
|
+
if (!scopeHasEmbeddings(db, cfg, allowed)) return [];
|
|
418
|
+
// Vectors are the only signal, so [] would read as "nothing is related" rather than "no
|
|
419
|
+
// model". Top up pending rows too, or a fresh index answers 0 until some search runs.
|
|
420
|
+
if (!modelPresent(cfg)) {
|
|
421
|
+
throw new SenseError('EMBED_MODEL_MISSING', 'related ranks notes by meaning, so it needs the embedding model, which is not downloaded; run `sense download` (search still works without it, on words and links)');
|
|
422
|
+
}
|
|
423
|
+
await embedPending(db, cfg, cfg.baseDir);
|
|
424
|
+
return similarNotes(db, cfg, path, {
|
|
425
|
+
exclude,
|
|
426
|
+
allowed,
|
|
427
|
+
k
|
|
428
|
+
});
|
|
429
|
+
}
|
package/dist/esm/commands.js.map
CHANGED
|
@@ -1 +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,8F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ACAmH,QAAQlI,KAAKmI,IAAI,CAAC,EAAEnH,aAAAA,IAAIoH,KAAK,cAATpH,wBAAAA,aAAwB,KAAK;QACjDmG;QACAM;QACAC,UAAUA,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"}
|
|
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, SearchOverrides } from './config.ts';\nimport { anyPresetEmbeds, featureEnabled, featureStates, presetNames, resolveSearch } from './config.ts';\nimport { SenseError } from './errors.ts';\nimport { embedPending, modelPresent, semanticCandidates, similarNotes } 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// snippet() re-tokenizes each candidate doc, superlinearly: ~10s for one 1MB doc\n// (BENCHMARKING.md). Past this bound, rows get the linear JS excerpt instead.\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); independent of exclude\n exclude?: string[]; // ad hoc scope override (repeatable --exclude); independent of include\n noExclude?: boolean; // --no-exclude: drop the preset's exclude for this command\n // Validation probe, no CLI flag: everything `check` validates lives in the lexical half, and\n // a vector pass would embed the tree (or bill an api) to prove a saved search parses.\n probe?: boolean;\n}\n\n// node:path's matchesGlob is experimental (stable behind an unstable-API flag) as of the\n// engines floor (Node >=22.20); scope filtering only ever needs single-pattern matching, so\n// it's used here in JS rather than running a directory walk in 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 expansion + vectors, fused by reciprocal rank; `via` names the signal per row.\n// `opts` arrives already resolved (config.ts:resolveSearch).\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 the coverage reconcile indexed; re-matching globs here could disagree\n // with it. Only ad-hoc scope flags, which have no persisted coverage, pay the JS match.\n const adHocScope = opts.include !== undefined || opts.exclude !== undefined || opts.noExclude === true;\n const scopedPaths = adHocScope ? 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 // Asking for vectors without a model is a misconfiguration, not a mode: degrading would make\n // the same search answer differently before and after a download. semantic:false never asks.\n const wantsVectors = !opts.probe && effective.semantic && anyPresetEmbeds(cfg);\n if (wantsVectors && !modelPresent(cfg)) {\n throw new SenseError('EMBED_MODEL_MISSING', `preset \"${effective.presetName}\" searches with vectors, but the embedding model is not available; run \\`sense download\\`, or set \"semantic\": false on that preset to search on words and links`);\n }\n const semanticEnabled = wantsVectors && scopeHasEmbeddings(db, cfg, scopedPaths);\n\n // Terms pass verbatim to MATCH; invalid syntax errors rather than being rewritten. --where\n // applies inside the candidate query (a post-filter would drop matches ranked past the pool)\n // and again on the final select, for link-derived rows.\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 // Gates the label only, not the score: restart mass ranks every seed without an incident\n // edge, but dropping it from the score reweights fusion (FEVER hit@10 0.997 -> 0.907).\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 _search');\n db.exec('CREATE TEMP TABLE _search (\"path\" TEXT PRIMARY KEY, score REAL, via TEXT, hit TEXT, lines TEXT, similarity REAL)');\n const insert = db.prepare('INSERT INTO _search (\"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 // Already scope-filtered above; the final select reapplies --where only for link-derived\n // rows, which never passed through whereCond.\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 ? ', _search.similarity' : '';\n const rows = db\n .prepare(\n `SELECT f.\"path\" AS path, content.title, content.summary, _search.hit, _search.via, round(_search.score, 4) AS score, _search.lines${similarityCol}\n FROM _search JOIN frontmatter f ON f.\"path\" = _search.\"path\" JOIN content ON content.path = _search.\"path\"\n ${where} ORDER BY _search.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\n// The scope resolver for non-search commands (path, peek, map): same coverage rule search()\n// applies (preset_files for a named preset, JS glob matching for an ad hoc include/exclude),\n// then narrowed by the resolved `where`.\nexport function scopedPaths(db: DatabaseSync, cfg: ResolvedConfig, overrides: SearchOverrides): Set<string> {\n const effective = resolveSearch(cfg, overrides);\n const { include, exclude, where } = effective;\n const allPaths = (db.prepare('SELECT \"path\" FROM frontmatter').all() as Array<{ path: string }>).map((r) => r.path);\n const adHocScope = overrides.include !== undefined || overrides.exclude !== undefined || overrides.noExclude === true;\n const paths = adHocScope ? 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 if (!where) return paths;\n const whereRows = db.prepare(`SELECT \"path\" FROM frontmatter f WHERE (${where})`).all() as Array<{ path: string }>;\n const wherePaths = new Set(whereRows.map((r) => r.path));\n return new Set([...paths].filter((p) => wherePaths.has(p)));\n}\n\nexport interface PresetCoverage {\n name: string;\n files: number;\n embedded: number;\n}\n\n// Indexing derives from presets, so the derivation stays visible. Read from preset_files, not\n// recomputed from globs, so it reflects the cache rather than the config.\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// Materializes the resolved scope into a temp table (same shape as traverse.ts's\n// allowed_nodes) so every mapTree query can join/filter against it cheaply.\nfunction setupMapScope(db: DatabaseSync, paths: Set<string>): void {\n db.exec('DROP TABLE IF EXISTS _map_scope');\n db.exec('CREATE TEMP TABLE _map_scope (\"path\" TEXT PRIMARY KEY)');\n db.prepare('INSERT INTO _map_scope SELECT DISTINCT value FROM json_each(?1)').run(JSON.stringify([...paths]));\n}\n\n// What is this scope: fixed-size output regardless of tree size. Coverage and features stay\n// global -- they describe the tree, not the current question.\nexport function mapTree(db: DatabaseSync, cfg: ResolvedConfig, overrides: SearchOverrides = {}): TreeMap {\n setupMapScope(db, scopedPaths(db, cfg, overrides));\n const scopeWhere = 'WHERE \"path\" IN (SELECT \"path\" FROM _map_scope)';\n const scopeAnd = 'AND f.\"path\" IN (SELECT \"path\" FROM _map_scope)';\n\n const docs = db.prepare(`SELECT COUNT(*) AS count, COALESCE(SUM(\"_size\"), 0) AS bytes FROM frontmatter ${scopeWhere}`).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 types, not declared: SQLite types per value, so a field can be text in most notes\n // and numeric in a few. One aggregate scan per chunk of columns; FILTER matches COUNT's nulls.\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 ${scopeWhere}`).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 ${scopeAnd} 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 ${scopeWhere} 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\n// Note resolution shared by peek and path: an exact path, or a unique basename (case\n// insensitive, .md stripped).\nexport function resolveNote(paths: string[], arg: string): string {\n const exact = paths.find((p) => p === arg);\n if (exact) return exact;\n const base = posix.basename(arg).replace(/\\.md$/i, '').toLowerCase();\n const matches = paths.filter((p) => posix.basename(p).replace(/\\.md$/i, '').toLowerCase() === base);\n if (matches.length === 1) return matches[0];\n if (matches.length > 1) throw new SenseError('NOTE_AMBIGUOUS', `\"${arg}\" is ambiguous: ${matches.join(', ')}`);\n throw new SenseError('NOTE_NOT_FOUND', `no note matches \"${arg}\"`);\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 // Bounded k-hop expansion beyond the immediate ring already shown by outbound/backlinks\n // (depth starts at 2).\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, overrides: SearchOverrides = {}): Peek {\n const paths = (db.prepare('SELECT \"path\" FROM frontmatter').all() as Array<{ path: string }>).map((r) => r.path);\n const path = resolveNote(paths, pathArg);\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 const _allowed = scopedPaths(db, cfg, overrides);\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\n// Notes most similar by cosine, excluding self and everything already linked either way.\n// Its own command, not a peek section: a full embeddings scan is ~480ms at 26k notes.\nexport async function relatedNotes(db: DatabaseSync, cfg: ResolvedConfig, pathArg: string, overrides: SearchOverrides, k: number): Promise<Array<{ path: string; similarity: number }>> {\n const paths = (db.prepare('SELECT \"path\" FROM frontmatter').all() as Array<{ path: string }>).map((r) => r.path);\n const path = resolveNote(paths, pathArg);\n\n const outbound = (db.prepare('SELECT DISTINCT dst FROM links WHERE src = ? AND dst IS NOT NULL').all(path) as Array<{ dst: string }>).map((r) => r.dst);\n const backlinks = (db.prepare('SELECT DISTINCT src FROM links WHERE dst = ?').all(path) as Array<{ src: string }>).map((r) => r.src);\n const exclude = new Set([path, ...outbound, ...backlinks]);\n\n const allowed = scopedPaths(db, cfg, overrides);\n if (!scopeHasEmbeddings(db, cfg, allowed)) return [];\n // Vectors are the only signal, so [] would read as \"nothing is related\" rather than \"no\n // model\". Top up pending rows too, or a fresh index answers 0 until some search runs.\n if (!modelPresent(cfg)) {\n throw new SenseError('EMBED_MODEL_MISSING', 'related ranks notes by meaning, so it needs the embedding model, which is not downloaded; run `sense download` (search still works without it, on words and links)');\n }\n await embedPending(db, cfg, cfg.baseDir);\n return similarNotes(db, cfg, path, { exclude, allowed, k });\n}\n"],"names":["readFileSync","join","matchesGlob","posix","anyPresetEmbeds","featureEnabled","featureStates","presetNames","resolveSearch","SenseError","embedPending","modelPresent","semanticCandidates","similarNotes","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","adHocScope","undefined","noExclude","p","presetName","scopeActive","fetch","max","wantsVectors","probe","semantic","semanticEnabled","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","overrides","paths","whereRows","wherePaths","presetCoverage","embedActive","name","files","n","embedded","INTERNAL_COLUMNS","MAP_COLUMN_CHUNK","chunk","items","setupMapScope","JSON","stringify","mapTree","scopeWhere","scopeAnd","docs","columns","allFields","group","exprs","quoted","result","field","coverage","type","fields","hubs","recent","fieldsTotal","features","presets","resolveNote","arg","exact","find","base","basename","matches","PEEK_LIST_LIMIT","peek","pathArg","frontmatter","key","value","Object","entries","sectionsTotal","sections","outbound","backlinks","unresolved","backlinksTotal","_allowed","l","dst","target","src","tokens","ceil","_size","outboundTotal","unresolvedTotal","off","relatedNotes","allowed"],"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,YAAY,EAAEC,YAAY,EAAEC,kBAAkB,EAAEC,YAAY,QAAQ,sBAAsB;AACnG,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,iFAAiF;AACjF,8EAA8E;AAC9E,MAAMC,gBAAgB;AACtB,MAAMC,iBAAiB;AAEvB,8FAA8F;AAC9F,qEAAqE;AACrE,SAASC,iBAAiBC,KAAa;IACrC,MAAMC,UAAUD,MACbE,OAAO,CAAC,MAAM,KACdA,OAAO,CAAC,UAAU,KAClBA,OAAO,CAAC,mCAAmC;IAC9C,OAAOD,QACJE,KAAK,CAAC,OACNC,GAAG,CAAC,CAACC,MAAQA,IAAIH,OAAO,CAAC,kBAAkB,KAAK,iCAAiC;KACjFE,GAAG,CAAC,CAACC,MAAQA,IAAIC,WA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,CAAC5M,aAAa6E,MAAM;QACtB,MAAM,IAAI/E,WAAW,uBAAuB;IAC9C;IACA,MAAMC,aAAaiE,IAAIa,KAAKA,IAAIyD,OAAO;IACvC,OAAOpI,aAAa8D,IAAIa,KAAKZ,MAAM;QAAEQ;QAASmI;QAASnH;IAAE;AAC3D"}
|
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 = 4;
|
|
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 {
|
|
@@ -21,11 +21,11 @@ export interface SavedSearch {
|
|
|
21
21
|
search: string;
|
|
22
22
|
preset?: string;
|
|
23
23
|
include?: string[];
|
|
24
|
+
exclude?: string[];
|
|
24
25
|
where?: string;
|
|
25
26
|
k?: number;
|
|
26
|
-
semantic?: boolean;
|
|
27
27
|
}
|
|
28
|
-
export type SavedQuery =
|
|
28
|
+
export type SavedQuery = {
|
|
29
29
|
sql: string;
|
|
30
30
|
} | SavedSearch;
|
|
31
31
|
export interface Config {
|
|
@@ -47,6 +47,7 @@ export interface ResolvedConfig extends Config {
|
|
|
47
47
|
migratedFrom?: number;
|
|
48
48
|
}
|
|
49
49
|
export declare function presetNames(cfg: Config): string[];
|
|
50
|
+
export declare function embedEnabled(cfg: Config): boolean;
|
|
50
51
|
export declare function presetSemanticEnabled(cfg: Config, name: string): boolean;
|
|
51
52
|
export declare function anyPresetEmbeds(cfg: Config): boolean;
|
|
52
53
|
export declare function featureEnabled(cfg: Config, name: FeatureName): boolean;
|
|
@@ -71,7 +72,8 @@ export interface SearchOverrides {
|
|
|
71
72
|
k?: number;
|
|
72
73
|
where?: string;
|
|
73
74
|
include?: string[];
|
|
74
|
-
|
|
75
|
+
exclude?: string[];
|
|
76
|
+
noExclude?: boolean;
|
|
75
77
|
}
|
|
76
78
|
export interface EffectiveSearch {
|
|
77
79
|
presetName: string;
|