sensemaking 0.9.5 → 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 +24 -18
- 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 +7 -3
- package/schema.json +12 -16
- package/skills/sense/EXAMPLES.md +8 -8
- package/skills/sense/SKILL.md +41 -19
- package/skills/sense-setup/EXAMPLES.md +24 -21
- package/skills/sense-setup/SKILL.md +9 -9
- 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/cjs/commands.js
CHANGED
|
@@ -18,6 +18,15 @@ _export(exports, {
|
|
|
18
18
|
get presetCoverage () {
|
|
19
19
|
return presetCoverage;
|
|
20
20
|
},
|
|
21
|
+
get relatedNotes () {
|
|
22
|
+
return relatedNotes;
|
|
23
|
+
},
|
|
24
|
+
get resolveNote () {
|
|
25
|
+
return resolveNote;
|
|
26
|
+
},
|
|
27
|
+
get scopedPaths () {
|
|
28
|
+
return scopedPaths;
|
|
29
|
+
},
|
|
21
30
|
get search () {
|
|
22
31
|
return search;
|
|
23
32
|
}
|
|
@@ -226,11 +235,8 @@ function _ts_generator(thisArg, body) {
|
|
|
226
235
|
// Each returns data; cli.ts renders. All of them degrade when a feature is off.
|
|
227
236
|
var WEIGHTED_BM25 = 'bm25(content, 10.0, 5.0, 1.0)';
|
|
228
237
|
var RRF_K = 60;
|
|
229
|
-
//
|
|
230
|
-
//
|
|
231
|
-
// (plans/performance-findings.md finding A). 16KB keeps the whole pool's snippet cost in
|
|
232
|
-
// the low-ms range; bigger docs get the JS-computed excerpt, linear and only for the rows
|
|
233
|
-
// actually returned.
|
|
238
|
+
// snippet() re-tokenizes each candidate doc, superlinearly: ~10s for one 1MB doc
|
|
239
|
+
// (BENCHMARKING.md). Past this bound, rows get the linear JS excerpt instead.
|
|
234
240
|
var SNIPPET_BOUND = 16384;
|
|
235
241
|
var EXCERPT_WINDOW = 160;
|
|
236
242
|
// Bare terms from an FTS5 query string: strips operators/quoting so the oversized-doc excerpt
|
|
@@ -367,8 +373,8 @@ function lineRangeFor(db, path, line) {
|
|
|
367
373
|
return row ? "L".concat(row.start_line, "-").concat(row.end_line) : null;
|
|
368
374
|
}
|
|
369
375
|
// node:path's matchesGlob is experimental (stable behind an unstable-API flag) as of the
|
|
370
|
-
// engines floor (Node >=22.
|
|
371
|
-
// it's used here in JS rather than
|
|
376
|
+
// engines floor (Node >=22.20); scope filtering only ever needs single-pattern matching, so
|
|
377
|
+
// it's used here in JS rather than running a directory walk in the query path.
|
|
372
378
|
function inScope(path, include, exclude) {
|
|
373
379
|
if (!include.some(function(g) {
|
|
374
380
|
return (0, _nodepath.matchesGlob)(path, g);
|
|
@@ -387,7 +393,7 @@ function scopeHasEmbeddings(db, cfg, scopedPaths) {
|
|
|
387
393
|
}
|
|
388
394
|
function search(_0, _1, _2) {
|
|
389
395
|
return _async_to_generator(function(db, cfg, terms) {
|
|
390
|
-
var opts, _hits_get, _chunkLines_get, _chunkSimilarity_get, effective, k, include, exclude, allPaths, scopedPaths, scopeActive, fetch, semanticEnabled, scope, whereJoin, whereCond, matchSql, matchRows, hits, oversized, candidates, edges, linked, seeds, ranked, chunkLines, chunkSimilarity, vec, insert, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _step_value, path, c, where, similarityCol, rows, bareTerms, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, row, text, _computeExcerpt, excerpt, offset;
|
|
396
|
+
var opts, _hits_get, _chunkLines_get, _chunkSimilarity_get, effective, k, include, exclude, allPaths, adHocScope, scopedPaths, scopeActive, fetch, wantsVectors, semanticEnabled, scope, whereJoin, whereCond, matchSql, matchRows, hits, oversized, candidates, edges, linked, seeds, ranked, chunkLines, chunkSimilarity, vec, insert, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _step_value, path, c, where, similarityCol, rows, bareTerms, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, row, text, _computeExcerpt, excerpt, offset;
|
|
391
397
|
var _arguments = arguments;
|
|
392
398
|
return _ts_generator(this, function(_state) {
|
|
393
399
|
switch(_state.label){
|
|
@@ -398,11 +404,10 @@ function search(_0, _1, _2) {
|
|
|
398
404
|
allPaths = db.prepare('SELECT "path" FROM frontmatter').all().map(function(r) {
|
|
399
405
|
return r.path;
|
|
400
406
|
});
|
|
401
|
-
// A preset scope reads
|
|
402
|
-
//
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
scopedPaths = opts.include ? new Set(allPaths.filter(function(p) {
|
|
407
|
+
// A preset scope reads the coverage reconcile indexed; re-matching globs here could disagree
|
|
408
|
+
// with it. Only ad-hoc scope flags, which have no persisted coverage, pay the JS match.
|
|
409
|
+
adHocScope = opts.include !== undefined || opts.exclude !== undefined || opts.noExclude === true;
|
|
410
|
+
scopedPaths = adHocScope ? new Set(allPaths.filter(function(p) {
|
|
406
411
|
return inScope(p, include, exclude);
|
|
407
412
|
})) : new Set(db.prepare('SELECT "path" FROM preset_files WHERE preset = ?').all(effective.presetName).map(function(r) {
|
|
408
413
|
return r.path;
|
|
@@ -412,16 +417,16 @@ function search(_0, _1, _2) {
|
|
|
412
417
|
// list that a plain over-fetch wouldn't have reached.
|
|
413
418
|
scopeActive = scopedPaths.size < allPaths.length;
|
|
414
419
|
fetch = scopeActive ? Math.max(k * 5, 50) : Math.max(k * 3, 30);
|
|
415
|
-
//
|
|
416
|
-
//
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
//
|
|
423
|
-
//
|
|
424
|
-
//
|
|
420
|
+
// Asking for vectors without a model is a misconfiguration, not a mode: degrading would make
|
|
421
|
+
// the same search answer differently before and after a download. semantic:false never asks.
|
|
422
|
+
wantsVectors = !opts.probe && effective.semantic && (0, _configts.anyPresetEmbeds)(cfg);
|
|
423
|
+
if (wantsVectors && !(0, _embedts.modelPresent)(cfg)) {
|
|
424
|
+
throw new _errorsts.SenseError('EMBED_MODEL_MISSING', 'preset "'.concat(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'));
|
|
425
|
+
}
|
|
426
|
+
semanticEnabled = wantsVectors && scopeHasEmbeddings(db, cfg, scopedPaths);
|
|
427
|
+
// Terms pass verbatim to MATCH; invalid syntax errors rather than being rewritten. --where
|
|
428
|
+
// applies inside the candidate query (a post-filter would drop matches ranked past the pool)
|
|
429
|
+
// and again on the final select, for link-derived rows.
|
|
425
430
|
scope = effective.where;
|
|
426
431
|
whereJoin = scope ? 'JOIN frontmatter f ON f."path" = content.path' : '';
|
|
427
432
|
whereCond = scope ? "AND (".concat(scope, ")") : '';
|
|
@@ -461,10 +466,8 @@ function search(_0, _1, _2) {
|
|
|
461
466
|
});
|
|
462
467
|
edges = (0, _configts.featureEnabled)(cfg, 'links') && matchRows.length > 0 ? (0, _indexts.linkEdges)(db) : [];
|
|
463
468
|
if (edges.length > 0) {
|
|
464
|
-
//
|
|
465
|
-
//
|
|
466
|
-
// that mass from the score list reweights fusion toward connectivity and measurably
|
|
467
|
-
// wrecks ranking on link-dense corpora (FEVER hit@10 0.997 -> 0.907; fusion-tuning.md).
|
|
469
|
+
// Gates the label only, not the score: restart mass ranks every seed without an incident
|
|
470
|
+
// edge, but dropping it from the score reweights fusion (FEVER hit@10 0.997 -> 0.907).
|
|
468
471
|
linked = new Set(edges.flat());
|
|
469
472
|
seeds = new Map(matchRows.map(function(r, i) {
|
|
470
473
|
return [
|
|
@@ -525,9 +528,9 @@ function search(_0, _1, _2) {
|
|
|
525
528
|
});
|
|
526
529
|
_state.label = 2;
|
|
527
530
|
case 2:
|
|
528
|
-
db.exec('DROP TABLE IF EXISTS
|
|
529
|
-
db.exec('CREATE TEMP TABLE
|
|
530
|
-
insert = db.prepare('INSERT INTO
|
|
531
|
+
db.exec('DROP TABLE IF EXISTS _search');
|
|
532
|
+
db.exec('CREATE TEMP TABLE _search ("path" TEXT PRIMARY KEY, score REAL, via TEXT, hit TEXT, lines TEXT, similarity REAL)');
|
|
533
|
+
insert = db.prepare('INSERT INTO _search ("path", score, via, hit, lines, similarity) VALUES (?, ?, ?, ?, ?, ?)');
|
|
531
534
|
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
532
535
|
try {
|
|
533
536
|
for(_iterator = candidates[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
@@ -548,15 +551,13 @@ function search(_0, _1, _2) {
|
|
|
548
551
|
}
|
|
549
552
|
}
|
|
550
553
|
}
|
|
551
|
-
//
|
|
552
|
-
//
|
|
553
|
-
// whichever candidate query didn't itself apply it to (link-derived rows never touched
|
|
554
|
-
// whereCond above).
|
|
554
|
+
// Already scope-filtered above; the final select reapplies --where only for link-derived
|
|
555
|
+
// rows, which never passed through whereCond.
|
|
555
556
|
where = scope ? "WHERE (".concat(scope, ")") : '';
|
|
556
557
|
// lines is always present now: semantic rows carry their chunk's range, oversized-doc
|
|
557
558
|
// lexical rows gain one below, everything else stays null. similarity stays semantic-only.
|
|
558
|
-
similarityCol = semanticEnabled ? ',
|
|
559
|
-
rows = db.prepare('SELECT f."path" AS path, content.title, content.summary,
|
|
559
|
+
similarityCol = semanticEnabled ? ', _search.similarity' : '';
|
|
560
|
+
rows = db.prepare('SELECT f."path" AS path, content.title, content.summary, _search.hit, _search.via, round(_search.score, 4) AS score, _search.lines'.concat(similarityCol, '\n FROM _search JOIN frontmatter f ON f."path" = _search."path" JOIN content ON content.path = _search."path"\n ').concat(where, " ORDER BY _search.score DESC LIMIT ?")).all(k);
|
|
560
561
|
if (oversized.size > 0) {
|
|
561
562
|
bareTerms = extractBareTerms(terms);
|
|
562
563
|
_iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
|
|
@@ -597,6 +598,27 @@ function search(_0, _1, _2) {
|
|
|
597
598
|
});
|
|
598
599
|
}).apply(this, arguments);
|
|
599
600
|
}
|
|
601
|
+
function scopedPaths(db, cfg, overrides) {
|
|
602
|
+
var effective = (0, _configts.resolveSearch)(cfg, overrides);
|
|
603
|
+
var include = effective.include, exclude = effective.exclude, where = effective.where;
|
|
604
|
+
var allPaths = db.prepare('SELECT "path" FROM frontmatter').all().map(function(r) {
|
|
605
|
+
return r.path;
|
|
606
|
+
});
|
|
607
|
+
var adHocScope = overrides.include !== undefined || overrides.exclude !== undefined || overrides.noExclude === true;
|
|
608
|
+
var paths = adHocScope ? new Set(allPaths.filter(function(p) {
|
|
609
|
+
return inScope(p, include, exclude);
|
|
610
|
+
})) : new Set(db.prepare('SELECT "path" FROM preset_files WHERE preset = ?').all(effective.presetName).map(function(r) {
|
|
611
|
+
return r.path;
|
|
612
|
+
}));
|
|
613
|
+
if (!where) return paths;
|
|
614
|
+
var whereRows = db.prepare('SELECT "path" FROM frontmatter f WHERE ('.concat(where, ")")).all();
|
|
615
|
+
var wherePaths = new Set(whereRows.map(function(r) {
|
|
616
|
+
return r.path;
|
|
617
|
+
}));
|
|
618
|
+
return new Set(_to_consumable_array(paths).filter(function(p) {
|
|
619
|
+
return wherePaths.has(p);
|
|
620
|
+
}));
|
|
621
|
+
}
|
|
600
622
|
function presetCoverage(db, cfg) {
|
|
601
623
|
var embedActive = (0, _configts.anyPresetEmbeds)(cfg);
|
|
602
624
|
return (0, _configts.presetNames)(cfg).map(function(name) {
|
|
@@ -623,19 +645,26 @@ function chunk(items, size) {
|
|
|
623
645
|
for(var i = 0; i < items.length; i += size)out.push(items.slice(i, i + size));
|
|
624
646
|
return out;
|
|
625
647
|
}
|
|
648
|
+
// Materializes the resolved scope into a temp table (same shape as traverse.ts's
|
|
649
|
+
// allowed_nodes) so every mapTree query can join/filter against it cheaply.
|
|
650
|
+
function setupMapScope(db, paths) {
|
|
651
|
+
db.exec('DROP TABLE IF EXISTS _map_scope');
|
|
652
|
+
db.exec('CREATE TEMP TABLE _map_scope ("path" TEXT PRIMARY KEY)');
|
|
653
|
+
db.prepare('INSERT INTO _map_scope SELECT DISTINCT value FROM json_each(?1)').run(JSON.stringify(_to_consumable_array(paths)));
|
|
654
|
+
}
|
|
626
655
|
function mapTree(db, cfg) {
|
|
627
|
-
var
|
|
656
|
+
var overrides = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
657
|
+
setupMapScope(db, scopedPaths(db, cfg, overrides));
|
|
658
|
+
var scopeWhere = 'WHERE "path" IN (SELECT "path" FROM _map_scope)';
|
|
659
|
+
var scopeAnd = 'AND f."path" IN (SELECT "path" FROM _map_scope)';
|
|
660
|
+
var docs = db.prepare('SELECT COUNT(*) AS count, COALESCE(SUM("_size"), 0) AS bytes FROM frontmatter '.concat(scopeWhere)).get();
|
|
628
661
|
var columns = db.prepare('PRAGMA table_info(frontmatter)').all().map(function(r) {
|
|
629
662
|
return r.name;
|
|
630
663
|
}).filter(function(name) {
|
|
631
664
|
return !INTERNAL_COLUMNS.has(name);
|
|
632
665
|
});
|
|
633
|
-
// Observed
|
|
634
|
-
//
|
|
635
|
-
// Listing every distinct type makes both the type and any drift visible.
|
|
636
|
-
// One aggregate scan per chunk of columns rather than one scan per column: COUNT already
|
|
637
|
-
// ignores NULL, and FILTER keeps typeof() looking only at the non-null rows COUNT counted,
|
|
638
|
-
// matching the old per-column `WHERE ... IS NOT NULL` exactly.
|
|
666
|
+
// Observed types, not declared: SQLite types per value, so a field can be text in most notes
|
|
667
|
+
// and numeric in a few. One aggregate scan per chunk of columns; FILTER matches COUNT's nulls.
|
|
639
668
|
var allFields = [];
|
|
640
669
|
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
641
670
|
try {
|
|
@@ -645,7 +674,7 @@ function mapTree(db, cfg) {
|
|
|
645
674
|
var quoted = '"'.concat(name.split('"').join('""'), '"');
|
|
646
675
|
return "COUNT(".concat(quoted, ") AS n").concat(i, ", GROUP_CONCAT(DISTINCT typeof(").concat(quoted, ")) FILTER (WHERE ").concat(quoted, " IS NOT NULL) AS t").concat(i);
|
|
647
676
|
});
|
|
648
|
-
var result = db.prepare("SELECT ".concat(exprs.join(', '), " FROM frontmatter")).get();
|
|
677
|
+
var result = db.prepare("SELECT ".concat(exprs.join(', '), " FROM frontmatter ").concat(scopeWhere)).get();
|
|
649
678
|
group.forEach(function(name, i) {
|
|
650
679
|
var _result_;
|
|
651
680
|
return allFields.push({
|
|
@@ -674,8 +703,8 @@ function mapTree(db, cfg) {
|
|
|
674
703
|
return b.coverage - a.coverage;
|
|
675
704
|
});
|
|
676
705
|
var fields = allFields.slice(0, 20);
|
|
677
|
-
var hubs = (0, _configts.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() : [];
|
|
678
|
-
var recent = db.prepare('SELECT "path", datetime("_mtime" / 1000, \'unixepoch\') AS modified FROM frontmatter ORDER BY "_mtime" DESC LIMIT 5').all();
|
|
706
|
+
var hubs = (0, _configts.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 '.concat(scopeAnd, ' ORDER BY f."_rank" DESC LIMIT 8')).all() : [];
|
|
707
|
+
var recent = db.prepare('SELECT "path", datetime("_mtime" / 1000, \'unixepoch\') AS modified FROM frontmatter '.concat(scopeWhere, ' ORDER BY "_mtime" DESC LIMIT 5')).all();
|
|
679
708
|
return {
|
|
680
709
|
docs: docs,
|
|
681
710
|
fields: fields,
|
|
@@ -686,24 +715,27 @@ function mapTree(db, cfg) {
|
|
|
686
715
|
recent: recent
|
|
687
716
|
};
|
|
688
717
|
}
|
|
718
|
+
function resolveNote(paths, arg) {
|
|
719
|
+
var exact = paths.find(function(p) {
|
|
720
|
+
return p === arg;
|
|
721
|
+
});
|
|
722
|
+
if (exact) return exact;
|
|
723
|
+
var base = _posix.default.basename(arg).replace(/\.md$/i, '').toLowerCase();
|
|
724
|
+
var matches = paths.filter(function(p) {
|
|
725
|
+
return _posix.default.basename(p).replace(/\.md$/i, '').toLowerCase() === base;
|
|
726
|
+
});
|
|
727
|
+
if (matches.length === 1) return matches[0];
|
|
728
|
+
if (matches.length > 1) throw new _errorsts.SenseError('NOTE_AMBIGUOUS', '"'.concat(arg, '" is ambiguous: ').concat(matches.join(', ')));
|
|
729
|
+
throw new _errorsts.SenseError('NOTE_NOT_FOUND', 'no note matches "'.concat(arg, '"'));
|
|
730
|
+
}
|
|
689
731
|
var PEEK_LIST_LIMIT = 20;
|
|
690
732
|
function peek(db, cfg, pathArg) {
|
|
733
|
+
var overrides = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {};
|
|
691
734
|
var _row__size;
|
|
692
735
|
var paths = db.prepare('SELECT "path" FROM frontmatter').all().map(function(r) {
|
|
693
736
|
return r.path;
|
|
694
737
|
});
|
|
695
|
-
var path = paths
|
|
696
|
-
return p === pathArg;
|
|
697
|
-
});
|
|
698
|
-
if (!path) {
|
|
699
|
-
var base = _posix.default.basename(pathArg).replace(/\.md$/i, '').toLowerCase();
|
|
700
|
-
var matches = paths.filter(function(p) {
|
|
701
|
-
return _posix.default.basename(p).replace(/\.md$/i, '').toLowerCase() === base;
|
|
702
|
-
});
|
|
703
|
-
if (matches.length === 1) path = matches[0];
|
|
704
|
-
else if (matches.length > 1) throw new _errorsts.SenseError('NOTE_AMBIGUOUS', '"'.concat(pathArg, '" is ambiguous: ').concat(matches.join(', ')));
|
|
705
|
-
else throw new _errorsts.SenseError('NOTE_NOT_FOUND', 'no note matches "'.concat(pathArg, '"'));
|
|
706
|
-
}
|
|
738
|
+
var path = resolveNote(paths, pathArg);
|
|
707
739
|
var row = db.prepare('SELECT * FROM frontmatter WHERE "path" = ?').get(path);
|
|
708
740
|
var frontmatter = {};
|
|
709
741
|
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
@@ -732,6 +764,7 @@ function peek(db, cfg, pathArg) {
|
|
|
732
764
|
var backlinks = [];
|
|
733
765
|
var unresolved = [];
|
|
734
766
|
var backlinksTotal = 0;
|
|
767
|
+
var _allowed = scopedPaths(db, cfg, overrides);
|
|
735
768
|
if ((0, _configts.featureEnabled)(cfg, 'links')) {
|
|
736
769
|
var out = db.prepare('SELECT target, dst FROM links WHERE src = ? ORDER BY target').all(path);
|
|
737
770
|
outbound = _to_consumable_array(new Set(out.filter(function(l) {
|
|
@@ -769,4 +802,51 @@ function peek(db, cfg, pathArg) {
|
|
|
769
802
|
})
|
|
770
803
|
};
|
|
771
804
|
}
|
|
805
|
+
function relatedNotes(db, cfg, pathArg, overrides, k) {
|
|
806
|
+
return _async_to_generator(function() {
|
|
807
|
+
var paths, path, outbound, backlinks, exclude, allowed;
|
|
808
|
+
return _ts_generator(this, function(_state) {
|
|
809
|
+
switch(_state.label){
|
|
810
|
+
case 0:
|
|
811
|
+
paths = db.prepare('SELECT "path" FROM frontmatter').all().map(function(r) {
|
|
812
|
+
return r.path;
|
|
813
|
+
});
|
|
814
|
+
path = resolveNote(paths, pathArg);
|
|
815
|
+
outbound = db.prepare('SELECT DISTINCT dst FROM links WHERE src = ? AND dst IS NOT NULL').all(path).map(function(r) {
|
|
816
|
+
return r.dst;
|
|
817
|
+
});
|
|
818
|
+
backlinks = db.prepare('SELECT DISTINCT src FROM links WHERE dst = ?').all(path).map(function(r) {
|
|
819
|
+
return r.src;
|
|
820
|
+
});
|
|
821
|
+
exclude = new Set([
|
|
822
|
+
path
|
|
823
|
+
].concat(_to_consumable_array(outbound), _to_consumable_array(backlinks)));
|
|
824
|
+
allowed = scopedPaths(db, cfg, overrides);
|
|
825
|
+
if (!scopeHasEmbeddings(db, cfg, allowed)) return [
|
|
826
|
+
2,
|
|
827
|
+
[]
|
|
828
|
+
];
|
|
829
|
+
// Vectors are the only signal, so [] would read as "nothing is related" rather than "no
|
|
830
|
+
// model". Top up pending rows too, or a fresh index answers 0 until some search runs.
|
|
831
|
+
if (!(0, _embedts.modelPresent)(cfg)) {
|
|
832
|
+
throw new _errorsts.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)');
|
|
833
|
+
}
|
|
834
|
+
return [
|
|
835
|
+
4,
|
|
836
|
+
(0, _embedts.embedPending)(db, cfg, cfg.baseDir)
|
|
837
|
+
];
|
|
838
|
+
case 1:
|
|
839
|
+
_state.sent();
|
|
840
|
+
return [
|
|
841
|
+
2,
|
|
842
|
+
(0, _embedts.similarNotes)(db, cfg, path, {
|
|
843
|
+
exclude: exclude,
|
|
844
|
+
allowed: allowed,
|
|
845
|
+
k: k
|
|
846
|
+
})
|
|
847
|
+
];
|
|
848
|
+
}
|
|
849
|
+
});
|
|
850
|
+
})();
|
|
851
|
+
}
|
|
772
852
|
/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }
|
package/dist/cjs/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":["mapTree","peek","presetCoverage","search","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","matchesGlob","scopeHasEmbeddings","cfg","scopedPaths","anyPresetEmbeds","rows","all","r","has","opts","hits","chunkLines","chunkSimilarity","effective","k","allPaths","scopeActive","fetch","semanticEnabled","scope","whereJoin","whereCond","matchSql","matchRows","oversized","candidates","edges","linked","seeds","ranked","vec","insert","c","where","similarityCol","bareTerms","resolveSearch","p","presetName","max","semantic","err","searchError","Map","hit","forEach","set","score","via","featureEnabled","linkEdges","flat","personalizedRank","existing","semanticCandidates","v","lines","similarity","exec","run","readFileSync","join","baseDir","embedActive","presetNames","name","files","n","embedded","INTERNAL_COLUMNS","MAP_COLUMN_CHUNK","chunk","items","docs","columns","allFields","group","exprs","quoted","result","field","coverage","type","fields","hubs","recent","fieldsTotal","features","featureStates","presets","PEEK_LIST_LIMIT","pathArg","paths","find","base","posix","basename","matches","SenseError","frontmatter","Object","entries","key","value","sectionsTotal","sections","outbound","backlinks","unresolved","backlinksTotal","l","dst","target","src","tokens","ceil","_size","outboundTotal","unresolvedTotal","off"],"mappings":";;;;;;;;;;;QAqUgBA;eAAAA;;QAmDAC;eAAAA;;QAnFAC;eAAAA;;QAjJMC;eAAAA;;;sBApJO;wBACK;4DAChB;wBAGyE;wBAChE;uBACQ;uBACT;uBACO;6BAEL;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE5B,2EAA2E;AAC3E,gFAAgF;AAEhF,IAAMC,gBAAgB;AACtB,IAAMC,QAAQ;AAEd,uFAAuF;AACvF,wFAAwF;AACxF,yFAAyF;AACzF,0FAA0F;AAC1F,qBAAqB;AACrB,IAAMC,gBAAgB;AACtB,IAAMC,iBAAiB;AAEvB,8FAA8F;AAC9F,qEAAqE;AACrE,SAASC,iBAAiBC,KAAa;IACrC,IAAMC,UAAUD,MACbE,OAAO,CAAC,MAAM,KACdA,OAAO,CAAC,UAAU,KAClBA,OAAO,CAAC,mCAAmC;IAC9C,OAAOD,QACJE,KAAK,CAAC,OACNC,GAAG,CAAC,SAACC;eAAQA,IAAIH,OAAO,CAAC,kBAAkB;OAAK,iCAAiC;KACjFE,GAAG,CAAC,SAACC;eAAQA,IAAIC,WAAW,GAAGC,IAAI;OACnCC,MAAM,CAAC,SA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AAAA,wBAAc,EAAC/C,KAAK+D;;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":["mapTree","peek","presetCoverage","relatedNotes","resolveNote","scopedPaths","search","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","matchesGlob","scopeHasEmbeddings","cfg","anyPresetEmbeds","rows","all","r","has","opts","hits","chunkLines","chunkSimilarity","effective","k","allPaths","adHocScope","scopeActive","fetch","wantsVectors","semanticEnabled","scope","whereJoin","whereCond","matchSql","matchRows","oversized","candidates","edges","linked","seeds","ranked","vec","insert","c","where","similarityCol","bareTerms","resolveSearch","undefined","noExclude","p","presetName","max","probe","semantic","modelPresent","SenseError","err","searchError","Map","hit","forEach","set","score","via","featureEnabled","linkEdges","flat","personalizedRank","existing","semanticCandidates","v","lines","similarity","exec","run","readFileSync","join","baseDir","overrides","paths","whereRows","wherePaths","embedActive","presetNames","name","files","n","embedded","INTERNAL_COLUMNS","MAP_COLUMN_CHUNK","chunk","items","setupMapScope","JSON","stringify","scopeWhere","scopeAnd","docs","columns","allFields","group","exprs","quoted","result","field","coverage","type","fields","hubs","recent","fieldsTotal","features","featureStates","presets","arg","exact","find","base","posix","basename","matches","PEEK_LIST_LIMIT","pathArg","frontmatter","Object","entries","key","value","sectionsTotal","sections","outbound","backlinks","unresolved","backlinksTotal","_allowed","l","dst","target","src","tokens","ceil","_size","outboundTotal","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A;4BAAS3H,GAAAA;wBAAE;;;;IAC3D"}
|
package/dist/cjs/config.d.cts
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;
|
package/dist/cjs/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;
|