sensemaking 0.15.2 → 0.15.4

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.
Files changed (73) hide show
  1. package/dist/cjs/cli/download.js +3 -8
  2. package/dist/cjs/cli/download.js.map +1 -1
  3. package/dist/cjs/cli/index.js +8 -19
  4. package/dist/cjs/cli/index.js.map +1 -1
  5. package/dist/cjs/cli/map.js +1 -3
  6. package/dist/cjs/cli/map.js.map +1 -1
  7. package/dist/cjs/cli/named.js +3 -8
  8. package/dist/cjs/cli/named.js.map +1 -1
  9. package/dist/cjs/cli/path.js +4 -7
  10. package/dist/cjs/cli/path.js.map +1 -1
  11. package/dist/cjs/cli/peek.js +2 -4
  12. package/dist/cjs/cli/peek.js.map +1 -1
  13. package/dist/cjs/cli/related.js +14 -20
  14. package/dist/cjs/cli/related.js.map +1 -1
  15. package/dist/cjs/cli/search.js +12 -17
  16. package/dist/cjs/cli/search.js.map +1 -1
  17. package/dist/cjs/cli/shared.js +17 -21
  18. package/dist/cjs/cli/shared.js.map +1 -1
  19. package/dist/cjs/cli/sql.js +7 -8
  20. package/dist/cjs/cli/sql.js.map +1 -1
  21. package/dist/cjs/cli/status.js +1 -3
  22. package/dist/cjs/cli/status.js.map +1 -1
  23. package/dist/cjs/cli/watch.js +3 -8
  24. package/dist/cjs/cli/watch.js.map +1 -1
  25. package/dist/cjs/cli.js +22 -34
  26. package/dist/cjs/cli.js.map +1 -1
  27. package/dist/cjs/column-hint.js +4 -2
  28. package/dist/cjs/column-hint.js.map +1 -1
  29. package/dist/cjs/commands/peek.js +5 -3
  30. package/dist/cjs/commands/peek.js.map +1 -1
  31. package/dist/cjs/commands/related.js +14 -15
  32. package/dist/cjs/commands/related.js.map +1 -1
  33. package/dist/cjs/commands/scope.js +4 -2
  34. package/dist/cjs/commands/scope.js.map +1 -1
  35. package/dist/cjs/commands/search.js +15 -16
  36. package/dist/cjs/commands/search.js.map +1 -1
  37. package/dist/cjs/config/access.js +4 -2
  38. package/dist/cjs/config/access.js.map +1 -1
  39. package/dist/cjs/config/load.js +4 -7
  40. package/dist/cjs/config/load.js.map +1 -1
  41. package/dist/cjs/config/validate.js +1 -1
  42. package/dist/cjs/db/open.js +4 -2
  43. package/dist/cjs/db/open.js.map +1 -1
  44. package/dist/cjs/db/reconcile.js +5 -3
  45. package/dist/cjs/db/reconcile.js.map +1 -1
  46. package/dist/cjs/errors.js +15 -24
  47. package/dist/cjs/errors.js.map +1 -1
  48. package/dist/cjs/features/embed.js +39 -45
  49. package/dist/cjs/features/embed.js.map +1 -1
  50. package/dist/cjs/features/links.js +4 -2
  51. package/dist/cjs/features/links.js.map +1 -1
  52. package/dist/cjs/features/rank.js +1 -1
  53. package/dist/cjs/features/tags.js +9 -127
  54. package/dist/cjs/features/tags.js.map +1 -1
  55. package/dist/cjs/fences.d.cts +1 -0
  56. package/dist/cjs/fences.d.ts +1 -0
  57. package/dist/cjs/fences.js +127 -2
  58. package/dist/cjs/fences.js.map +1 -1
  59. package/dist/cjs/graph.js +5 -3
  60. package/dist/cjs/graph.js.map +1 -1
  61. package/dist/cjs/output.js +6 -6
  62. package/dist/cjs/scan.js +5 -3
  63. package/dist/cjs/scan.js.map +1 -1
  64. package/dist/cjs/traverse.js +4 -2
  65. package/dist/cjs/traverse.js.map +1 -1
  66. package/dist/cjs/watch.js +2 -5
  67. package/dist/cjs/watch.js.map +1 -1
  68. package/dist/esm/features/tags.js +6 -126
  69. package/dist/esm/features/tags.js.map +1 -1
  70. package/dist/esm/fences.d.ts +1 -0
  71. package/dist/esm/fences.js +133 -5
  72. package/dist/esm/fences.js.map +1 -1
  73. package/package.json +1 -1
@@ -37,11 +37,8 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
37
37
  reject(error);
38
38
  return;
39
39
  }
40
- if (info.done) {
41
- resolve(value);
42
- } else {
43
- Promise.resolve(value).then(_next, _throw);
44
- }
40
+ if (info.done) resolve(value);
41
+ else Promise.resolve(value).then(_next, _throw);
45
42
  }
46
43
  function _async_to_generator(fn) {
47
44
  return function() {
@@ -59,7 +56,9 @@ function _async_to_generator(fn) {
59
56
  };
60
57
  }
61
58
  function _iterable_to_array(iter) {
62
- if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
59
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) {
60
+ return Array.from(iter);
61
+ }
63
62
  }
64
63
  function _iterable_to_array_limit(arr, i) {
65
64
  var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
@@ -86,10 +85,10 @@ function _iterable_to_array_limit(arr, i) {
86
85
  return _arr;
87
86
  }
88
87
  function _non_iterable_rest() {
89
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
88
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
90
89
  }
91
90
  function _non_iterable_spread() {
92
- throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
91
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
93
92
  }
94
93
  function _sliced_to_array(arr, i) {
95
94
  return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
@@ -97,14 +96,6 @@ function _sliced_to_array(arr, i) {
97
96
  function _to_consumable_array(arr) {
98
97
  return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
99
98
  }
100
- function _unsupported_iterable_to_array(o, minLen) {
101
- if (!o) return;
102
- if (typeof o === "string") return _array_like_to_array(o, minLen);
103
- var n = Object.prototype.toString.call(o).slice(8, -1);
104
- if (n === "Object" && o.constructor) n = o.constructor.name;
105
- if (n === "Map" || n === "Set") return Array.from(n);
106
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
107
- }
108
99
  function _ts_generator(thisArg, body) {
109
100
  var f, y, t, _ = {
110
101
  label: 0,
@@ -204,6 +195,14 @@ function _ts_generator(thisArg, body) {
204
195
  };
205
196
  }
206
197
  }
198
+ function _unsupported_iterable_to_array(o, minLen) {
199
+ if (!o) return;
200
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
201
+ var n = Object.prototype.toString.call(o).slice(8, -1);
202
+ if (n === "Object" && o.constructor) n = o.constructor.name;
203
+ if (n === "Map" || n === "Set") return Array.from(n);
204
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
205
+ }
207
206
  // Mirrors the main columns onto the sidecars, so a title match found through title_seg ranks
208
207
  // like a title match found through title, not like a body match.
209
208
  var WEIGHTED_BM25 = 'bm25(content, 10.0, 5.0, 1.0, 0, 10.0, 5.0, 1.0)';
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/commands/search.ts"],"sourcesContent":["import { readFileSync } from 'node:fs';\nimport { join } from 'node:path';\nimport type { DatabaseSync } from 'node:sqlite';\nimport type { ResolvedConfig } from '../config/index.ts';\nimport { anyPresetEmbeds, contentTokenize, featureEnabled, resolveSearch } from '../config/index.ts';\nimport { SenseError } from '../errors.ts';\nimport { modelPresent, 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';\nimport { segmentMatch } from '../segment.ts';\nimport { materializeScope, narrowByWhere, rawScope, scopeHasEmbeddings } from './scope.ts';\n\n// Mirrors the main columns onto the sidecars, so a title match found through title_seg ranks\n// like a title match found through title, not like a body match.\nconst WEIGHTED_BM25 = 'bm25(content, 10.0, 5.0, 1.0, 0, 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}\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 } = effective;\n\n const allPaths = (db.prepare('SELECT \"path\" FROM frontmatter').all() as Array<{ path: string }>).map((r) => r.path);\n const scopePaths = rawScope(db, cfg, opts, allPaths);\n const scopeActive = scopePaths.size < allPaths.length;\n // The set every candidate pool must be filtered to before truncation: scope narrowed by\n // --where, the same composition scopedPaths() gives the other commands. Runs the same where\n // fragment matchSql does, so a bad column gets the same attributed error either way.\n let allowedPaths: Set<string>;\n try {\n allowedPaths = narrowByWhere(db, scopePaths, effective.where);\n } catch (err) {\n throw searchError(err as Error, terms, effective.where);\n }\n const fetch = 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 = 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, allowedPaths);\n\n // Terms pass to MATCH as written, with one transform: a run of text whose language marks no\n // word boundaries becomes a quoted grapheme phrase (and a title:/summary:/text: qualifier\n // ahead of it retargets its _seg column), matching how it was indexed. Text that already\n // carries boundaries comes through untouched, so this is a no-op for the languages that\n // never needed it. Gated on the same predicate that decided whether the sidecars were\n // populated (contentTokenize(cfg) === undefined), so index and query can't disagree. Invalid\n // syntax still errors rather than being rewritten.\n // --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 // A scope narrower than the whole index must filter the candidate pool before LIMIT, not\n // after -- otherwise scoped notes ranking below the global top-`fetch` never reach the\n // filter. A join against a temp table, not a bound parameter list: real scopes run to\n // thousands of paths, past SQLITE_MAX_VARIABLE_NUMBER on older builds.\n if (scopeActive) materializeScope(db, '_search_scope', scopePaths);\n const scopeCond = scopeActive ? `AND content.path IN (SELECT \"path\" FROM _search_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 // Column 2 (text), not -1 (best column): -1 could surface a _seg sidecar as the excerpt,\n // which is machine-spaced and not what the author wrote. A row that matches only in a\n // sidecar gets an unhighlighted text excerpt below instead -- a stated cost.\n const matchSql = `SELECT content.path AS path, CASE WHEN length(content.text) <= ${SNIPPET_BOUND} THEN snippet(content, 2, '«', '»', '…', 10) ELSE NULL END AS hit FROM content ${whereJoin} WHERE content MATCH ? ${whereCond} ${scopeCond} ORDER BY ${WEIGHTED_BM25} LIMIT ${fetch}`;\n const query = contentTokenize(cfg) === undefined ? segmentMatch(terms) : terms;\n let matchRows: Array<{ path: string; hit: string | null }>;\n try {\n matchRows = db.prepare(matchSql).all(query) as Array<{ path: string; hit: string | null }>;\n } catch (err) {\n throw searchError(err as Error, terms, scope);\n }\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 && allowedPaths.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, allowedPaths);\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 // All three candidate paths (match, link, vector) already filtered to scope+where before\n // reaching _search; this reapplies --where anyway since the join to frontmatter is already\n // needed for the path column.\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"],"names":["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","cfg","opts","hits","chunkLines","chunkSimilarity","effective","k","allPaths","scopePaths","scopeActive","allowedPaths","fetch","wantsVectors","semanticEnabled","scope","whereJoin","whereCond","scopeCond","matchSql","matchRows","oversized","candidates","edges","linked","seeds","ranked","vec","insert","c","where","similarityCol","rows","bareTerms","resolveSearch","all","r","rawScope","narrowByWhere","err","searchError","max","semantic","anyPresetEmbeds","modelPresent","SenseError","presetName","scopeHasEmbeddings","materializeScope","contentTokenize","undefined","segmentMatch","Map","hit","forEach","set","score","via","featureEnabled","linkEdges","flat","personalizedRank","has","existing","semanticCandidates","lines","similarity","exec","run","readFileSync","join","baseDir"],"mappings":";;;;+BAgIsBA;;;eAAAA;;;sBAhIO;wBACR;uBAG2D;wBACrD;uBACsB;wBACvB;uBACO;6BAEL;yBACC;uBACiD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE9E,6FAA6F;AAC7F,iEAAiE;AACjE,IAAMC,gBAAgB;AACtB,IAAMC,QAAQ;AAEd,iFAAiF;AACjF,8EAA8E;AAC9E,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,SAACH;eAAQA,IAAII,MAAM,GAAG;;AAClC;AAEA,SAASC,gBAAgBC,aAAqB,EAAEC,KAAe;IAC7D,IAAMC,MAA2D,EAAE;QAC9D,kCAAA,2BAAA;;QAAL,QAAK,YAAcD,0BAAd,SAAA,6BAAA,QAAA,yBAAA,iCAAqB;Y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OAAO,EAAE3E,IAAID,IAAI,GAAa;gCAC7D,EAAE,eAAM;oCACN,UAAU,mEAAmE;gCAC/E;gCAC4BjB,kBAAAA,eAAeC,MAAMsD,YAAzCnD,UAAoBJ,gBAApBI,SAASE,SAAWN,gBAAXM;gCACjBY,IAAIyD,GAAG,GAAGvE;gCACV,IAAIc,IAAIqE,KAAK,IAAI,MAAMrE,IAAIqE,KAAK,GAAGP,IAAAA,uBAAc,EAACzD,KAAK,cAAcR,aAAaC,IAAIE,IAAID,IAAI,EAAYL,aAAaX,MAAMK,WAAW;4BAC1I;;4BAXK;4BAAA;;;qCAAA,8BAAA;oCAAA;;;oCAAA;0CAAA;;;;oBAYP;oBAEA;;wBAAOgD;;;;IACT"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/commands/search.ts"],"sourcesContent":["import { readFileSync } from 'node:fs';\nimport { join } from 'node:path';\nimport type { DatabaseSync } from 'node:sqlite';\nimport type { ResolvedConfig } from '../config/index.ts';\nimport { anyPresetEmbeds, contentTokenize, featureEnabled, resolveSearch } from '../config/index.ts';\nimport { SenseError } from '../errors.ts';\nimport { modelPresent, 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';\nimport { segmentMatch } from '../segment.ts';\nimport { materializeScope, narrowByWhere, rawScope, scopeHasEmbeddings } from './scope.ts';\n\n// Mirrors the main columns onto the sidecars, so a title match found through title_seg ranks\n// like a title match found through title, not like a body match.\nconst WEIGHTED_BM25 = 'bm25(content, 10.0, 5.0, 1.0, 0, 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}\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 } = effective;\n\n const allPaths = (db.prepare('SELECT \"path\" FROM frontmatter').all() as Array<{ path: string }>).map((r) => r.path);\n const scopePaths = rawScope(db, cfg, opts, allPaths);\n const scopeActive = scopePaths.size < allPaths.length;\n // The set every candidate pool must be filtered to before truncation: scope narrowed by\n // --where, the same composition scopedPaths() gives the other commands. Runs the same where\n // fragment matchSql does, so a bad column gets the same attributed error either way.\n let allowedPaths: Set<string>;\n try {\n allowedPaths = narrowByWhere(db, scopePaths, effective.where);\n } catch (err) {\n throw searchError(err as Error, terms, effective.where);\n }\n const fetch = 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 = 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, allowedPaths);\n\n // Terms pass to MATCH as written, with one transform: a run of text whose language marks no\n // word boundaries becomes a quoted grapheme phrase (and a title:/summary:/text: qualifier\n // ahead of it retargets its _seg column), matching how it was indexed. Text that already\n // carries boundaries comes through untouched, so this is a no-op for the languages that\n // never needed it. Gated on the same predicate that decided whether the sidecars were\n // populated (contentTokenize(cfg) === undefined), so index and query can't disagree. Invalid\n // syntax still errors rather than being rewritten.\n // --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 // A scope narrower than the whole index must filter the candidate pool before LIMIT, not\n // after -- otherwise scoped notes ranking below the global top-`fetch` never reach the\n // filter. A join against a temp table, not a bound parameter list: real scopes run to\n // thousands of paths, past SQLITE_MAX_VARIABLE_NUMBER on older builds.\n if (scopeActive) materializeScope(db, '_search_scope', scopePaths);\n const scopeCond = scopeActive ? `AND content.path IN (SELECT \"path\" FROM _search_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 // Column 2 (text), not -1 (best column): -1 could surface a _seg sidecar as the excerpt,\n // which is machine-spaced and not what the author wrote. A row that matches only in a\n // sidecar gets an unhighlighted text excerpt below instead -- a stated cost.\n const matchSql = `SELECT content.path AS path, CASE WHEN length(content.text) <= ${SNIPPET_BOUND} THEN snippet(content, 2, '«', '»', '…', 10) ELSE NULL END AS hit FROM content ${whereJoin} WHERE content MATCH ? ${whereCond} ${scopeCond} ORDER BY ${WEIGHTED_BM25} LIMIT ${fetch}`;\n const query = contentTokenize(cfg) === undefined ? segmentMatch(terms) : terms;\n let matchRows: Array<{ path: string; hit: string | null }>;\n try {\n matchRows = db.prepare(matchSql).all(query) as Array<{ path: string; hit: string | null }>;\n } catch (err) {\n throw searchError(err as Error, terms, scope);\n }\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 && allowedPaths.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, allowedPaths);\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 // All three candidate paths (match, link, vector) already filtered to scope+where before\n // reaching _search; this reapplies --where anyway since the join to frontmatter is already\n // needed for the path column.\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"],"names":["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","cfg","opts","hits","chunkLines","chunkSimilarity","effective","k","allPaths","scopePaths","scopeActive","allowedPaths","fetch","wantsVectors","semanticEnabled","scope","whereJoin","whereCond","scopeCond","matchSql","matchRows","oversized","candidates","edges","linked","seeds","ranked","vec","insert","c","where","similarityCol","rows","bareTerms","resolveSearch","all","r","rawScope","narrowByWhere","err","searchError","max","semantic","anyPresetEmbeds","modelPresent","SenseError","presetName","scopeHasEmbeddings","materializeScope","contentTokenize","undefined","segmentMatch","Map","hit","forEach","set","score","via","featureEnabled","linkEdges","flat","personalizedRank","has","existing","semanticCandidates","lines","similarity","exec","run","readFileSync","join","baseDir"],"mappings":";;;;+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E,IAAIqE,KAAK,GAAGP,IAAAA,uBAAc,EAACzD,KAAK,cAAcR,aAAaC,IAAIE,IAAID,IAAI,EAAYL,aAAaX,MAAMK,WAAW;4BAC1I;;4BAXK;4BAAA;;;qCAAA,8BAAA;oCAAA;;;oCAAA;0CAAA;;;;oBAYP;oBAEA;;wBAAOgD;;;;IACT"}
@@ -50,10 +50,12 @@ function _array_without_holes(arr) {
50
50
  if (Array.isArray(arr)) return _array_like_to_array(arr);
51
51
  }
52
52
  function _iterable_to_array(iter) {
53
- if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
53
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) {
54
+ return Array.from(iter);
55
+ }
54
56
  }
55
57
  function _non_iterable_spread() {
56
- throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
58
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
57
59
  }
58
60
  function _to_consumable_array(arr) {
59
61
  return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/config/access.ts"],"sourcesContent":["import { type Config, type EmbedConfig, FEATURE_NAMES, type FeatureName } from './types.ts';\n\nexport function presetNames(cfg: Config): string[] {\n return Object.keys(cfg.presets);\n}\n\n// Whether the tree names a model at all.\nexport function embedEnabled(cfg: Config): boolean {\n return typeof cfg.embed?.model === 'string' && cfg.embed.model.length > 0;\n}\n\n// A preset's own vector participation: absent or true means on, false means off.\nexport function presetSemanticEnabled(cfg: Config, name: string): boolean {\n return cfg.presets[name]?.semantic !== false;\n}\n\n// Whether embedding needs to run: a model is named AND some preset wants vectors.\nexport function anyPresetEmbeds(cfg: Config): boolean {\n return embedEnabled(cfg) && presetNames(cfg).some((name) => presetSemanticEnabled(cfg, name));\n}\n\n// Opt-out features (default on): absent block or key means enabled. `rank` additionally\n// requires `links`. `embed` is derived, not a features-block member: on iff `embed` names a model.\nexport function featureEnabled(cfg: Config, name: FeatureName): boolean {\n if (name === 'embed') return anyPresetEmbeds(cfg);\n const enabled = cfg.features?.[name] !== false;\n if (name === 'rank') return enabled && featureEnabled(cfg, 'links');\n return enabled;\n}\n\nexport function enabledFeatures(cfg: Config): FeatureName[] {\n return FEATURE_NAMES.filter((name) => featureEnabled(cfg, name));\n}\n\n// Feature states, so \"off\" and \"empty\" stay distinguishable in output. `embed` is excluded:\n// it is not a features-block toggle, and `status` reports it on its own line.\nexport function featureStates(cfg: Config): { on: FeatureName[]; off: FeatureName[] } {\n const reported = FEATURE_NAMES.filter((name) => name !== 'embed');\n return {\n on: reported.filter((name) => featureEnabled(cfg, name)),\n off: reported.filter((name) => !featureEnabled(cfg, name)),\n };\n}\n\n// Resolved embed provider settings, or null when the config names no model. There is no\n// fallback to DEFAULT_EMBED_MODEL: that constant is a template `init` and the v4 migration\n// write into the file, never an implicit runtime default.\nexport function embedConfig(cfg: Config): { model: string; type: 'static' | 'api'; url?: string; key?: string } | null {\n if (!embedEnabled(cfg)) return null;\n const e = cfg.embed as EmbedConfig;\n return { model: e.model as string, type: e.type ?? 'static', url: e.url, key: e.key };\n}\n\n// The configured FTS5 tokenizer, or undefined for the built-in default. Undefined rather than\n// the default string so featureSignature can leave the segment off entirely for trees that\n// never set it, which is what keeps existing indexes from rebuilding on upgrade.\nexport function contentTokenize(cfg: Config): string | undefined {\n const tokenize = cfg.content?.tokenize;\n return tokenize === undefined || tokenize.trim() === '' ? undefined : tokenize.trim();\n}\n\n// Cache key over everything indexing derives from, so any change to those inputs rebuilds.\nexport function featureSignature(cfg: Config): string {\n const globalPart = enabledFeatures(cfg)\n .filter((name) => name !== 'embed')\n .join(',');\n const e = embedConfig(cfg);\n const embedPart = e ? `embed:${e.type}:${e.model}` : 'embed:off';\n // One keyed segment per preset so a rebuild notice can name exactly which preset moved.\n const presetsPart = [...presetNames(cfg)]\n .sort()\n .map((name) => {\n const p = cfg.presets[name];\n const include = [...p.include].sort().join('+');\n const exclude = [...(p.exclude ?? [])].sort().join('+');\n return `preset:${name}:${include}:${exclude}:${p.semantic === false ? 'off' : 'on'}`;\n })\n .join('|');\n const tokenize = contentTokenize(cfg);\n const parts = [`features:${globalPart}`, embedPart];\n if (tokenize !== undefined) parts.push(`tokenize:${tokenize}`);\n parts.push(presetsPart);\n return parts.join('|');\n}\n"],"names":["anyPresetEmbeds","contentTokenize","embedConfig","embedEnabled","enabledFeatures","featureEnabled","featureSignature","featureStates","presetNames","presetSemanticEnabled","cfg","Object","keys","presets","embed","model","length","name","semantic","some","enabled","features","FEATURE_NAMES","filter","reported","on","off","e","type","url","key","tokenize","content","undefined","trim","globalPart","join","embedPart","presetsPart","sort","map","p","include","exclude","parts","push"],"mappings":";;;;;;;;;;;QAiBgBA;eAAAA;;QAuCAC;eAAAA;;QATAC;eAAAA;;QAxCAC;eAAAA;;QAuBAC;eAAAA;;QAPAC;eAAAA;;QAuCAC;eAAAA;;QA1BAC;eAAAA;;QAlCAC;eAAAA;;QAUAC;eAAAA;;;uBAZ+D;;;;;;;;;;;;;;;;;;;;;;;;;;AAExE,SAASD,YAAYE,GAAW;IACrC,OAAOC,OAAOC,IAAI,CAACF,IAAIG,OAAO;AAChC;AAGO,SAASV,aAAaO,GAAW;QACxBA;IAAd,OAAO,SAAOA,aAAAA,IAAII,KAAK,cAATJ,iCAAAA,WAAWK,KAAK,MAAK,YAAYL,IAAII,KAAK,CAACC,KAAK,CAACC,MAAM,GAAG;AAC1E;AAGO,SAASP,sBAAsBC,GAAW,EAAEO,IAAY;QACtDP;IAAP,OAAOA,EAAAA,oBAAAA,IAAIG,OAAO,CAACI,KAAK,cAAjBP,wCAAAA,kBAAmBQ,QAAQ,MAAK;AACzC;AAGO,SAASlB,gBAAgBU,GAAW;IACzC,OAAO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,CAAC,SAACN;eAASA,SAAS;OAC1BmB,IAAI,CAAC;IACR,IAAMT,IAAIzB,YAAYQ;IACtB,IAAM2B,YAAYV,IAAI,AAAC,SAAkBA,OAAVA,EAAEC,IAAI,EAAC,KAAW,OAARD,EAAEZ,KAAK,IAAK;IACrD,wFAAwF;IACxF,IAAMuB,cAAc,AAAC,qBAAG9B,YAAYE,MACjC6B,IAAI,GACJC,GAAG,CAAC,SAACvB;YAGiBwB;QAFrB,IAAMA,IAAI/B,IAAIG,OAAO,CAACI,KAAK;QAC3B,IAAMyB,UAAU,AAAC,qBAAGD,EAAEC,OAAO,EAAEH,IAAI,GAAGH,IAAI,CAAC;QAC3C,IAAMO,UAAU,AAAC,sBAAIF,aAAAA,EAAEE,OAAO,cAATF,wBAAAA,aAAa,EAAE,EAAGF,IAAI,GAAGH,IAAI,CAAC;QACnD,OAAO,AAAC,UAAiBM,OAARzB,MAAK,KAAc0B,OAAXD,SAAQ,KAAcD,OAAXE,SAAQ,KAAuC,OAApCF,EAAEvB,QAAQ,KAAK,QAAQ,QAAQ;IAChF,GACCkB,IAAI,CAAC;IACR,IAAML,WAAW9B,gBAAgBS;IACjC,IAAMkC,QAAQ;QAAE,YAAsB,OAAXT;QAAcE;KAAU;IACnD,IAAIN,aAAaE,WAAWW,MAAMC,IAAI,CAAC,AAAC,YAAoB,OAATd;IACnDa,MAAMC,IAAI,CAACP;IACX,OAAOM,MAAMR,IAAI,CAAC;AACpB"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/config/access.ts"],"sourcesContent":["import { type Config, type EmbedConfig, FEATURE_NAMES, type FeatureName } from './types.ts';\n\nexport function presetNames(cfg: Config): string[] {\n return Object.keys(cfg.presets);\n}\n\n// Whether the tree names a model at all.\nexport function embedEnabled(cfg: Config): boolean {\n return typeof cfg.embed?.model === 'string' && cfg.embed.model.length > 0;\n}\n\n// A preset's own vector participation: absent or true means on, false means off.\nexport function presetSemanticEnabled(cfg: Config, name: string): boolean {\n return cfg.presets[name]?.semantic !== false;\n}\n\n// Whether embedding needs to run: a model is named AND some preset wants vectors.\nexport function anyPresetEmbeds(cfg: Config): boolean {\n return embedEnabled(cfg) && presetNames(cfg).some((name) => presetSemanticEnabled(cfg, name));\n}\n\n// Opt-out features (default on): absent block or key means enabled. `rank` additionally\n// requires `links`. `embed` is derived, not a features-block member: on iff `embed` names a model.\nexport function featureEnabled(cfg: Config, name: FeatureName): boolean {\n if (name === 'embed') return anyPresetEmbeds(cfg);\n const enabled = cfg.features?.[name] !== false;\n if (name === 'rank') return enabled && featureEnabled(cfg, 'links');\n return enabled;\n}\n\nexport function enabledFeatures(cfg: Config): FeatureName[] {\n return FEATURE_NAMES.filter((name) => featureEnabled(cfg, name));\n}\n\n// Feature states, so \"off\" and \"empty\" stay distinguishable in output. `embed` is excluded:\n// it is not a features-block toggle, and `status` reports it on its own line.\nexport function featureStates(cfg: Config): { on: FeatureName[]; off: FeatureName[] } {\n const reported = FEATURE_NAMES.filter((name) => name !== 'embed');\n return {\n on: reported.filter((name) => featureEnabled(cfg, name)),\n off: reported.filter((name) => !featureEnabled(cfg, name)),\n };\n}\n\n// Resolved embed provider settings, or null when the config names no model. There is no\n// fallback to DEFAULT_EMBED_MODEL: that constant is a template `init` and the v4 migration\n// write into the file, never an implicit runtime default.\nexport function embedConfig(cfg: Config): { model: string; type: 'static' | 'api'; url?: string; key?: string } | null {\n if (!embedEnabled(cfg)) return null;\n const e = cfg.embed as EmbedConfig;\n return { model: e.model as string, type: e.type ?? 'static', url: e.url, key: e.key };\n}\n\n// The configured FTS5 tokenizer, or undefined for the built-in default. Undefined rather than\n// the default string so featureSignature can leave the segment off entirely for trees that\n// never set it, which is what keeps existing indexes from rebuilding on upgrade.\nexport function contentTokenize(cfg: Config): string | undefined {\n const tokenize = cfg.content?.tokenize;\n return tokenize === undefined || tokenize.trim() === '' ? undefined : tokenize.trim();\n}\n\n// Cache key over everything indexing derives from, so any change to those inputs rebuilds.\nexport function featureSignature(cfg: Config): string {\n const globalPart = enabledFeatures(cfg)\n .filter((name) => name !== 'embed')\n .join(',');\n const e = embedConfig(cfg);\n const embedPart = e ? `embed:${e.type}:${e.model}` : 'embed:off';\n // One keyed segment per preset so a rebuild notice can name exactly which preset moved.\n const presetsPart = [...presetNames(cfg)]\n .sort()\n .map((name) => {\n const p = cfg.presets[name];\n const include = [...p.include].sort().join('+');\n const exclude = [...(p.exclude ?? [])].sort().join('+');\n return `preset:${name}:${include}:${exclude}:${p.semantic === false ? 'off' : 'on'}`;\n })\n .join('|');\n const tokenize = contentTokenize(cfg);\n const parts = [`features:${globalPart}`, embedPart];\n if (tokenize !== undefined) parts.push(`tokenize:${tokenize}`);\n parts.push(presetsPart);\n return parts.join('|');\n}\n"],"names":["anyPresetEmbeds","contentTokenize","embedConfig","embedEnabled","enabledFeatures","featureEnabled","featureSignature","featureStates","presetNames","presetSemanticEnabled","cfg","Object","keys","presets","embed","model","length","name","semantic","some","enabled","features","FEATURE_NAMES","filter","reported","on","off","e","type","url","key","tokenize","content","undefined","trim","globalPart","join","embedPart","presetsPart","sort","map","p","include","exclude","parts","push"],"mappings":";;;;;;;;;;;QAiBgBA;eAAAA;;QAuCAC;eAAAA;;QATAC;eAAAA;;QAxCAC;eAAAA;;QAuBAC;eAAAA;;QAPAC;eAAAA;;QAuCAC;eAAAA;;QA1BAC;eAAAA;;QAlCAC;eAAAA;;QAUAC;eAAAA;;;uBAZ+D;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAExE,SAASD,YAAYE,GAAW;IACrC,OAAOC,OAAOC,IAAI,CAACF,IAAIG,OAAO;AAChC;AAGO,SAASV,aAAaO,GAAW;QACxBA;IAAd,OAAO,SAAOA,aAAAA,IAAII,KAAK,cAATJ,iCAAAA,WAAWK,KAAK,MAAK,YAAYL,IAAII,KAAK,CAACC,KAAK,CAACC,MAAM,GAAG;AAC1E;AAGO,SAASP,sBAAsBC,GAAW,EAAEO,IAAY;QACtDP;IAAP,OAAOA,EA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AASG,IAAI,OAAO,KAAKD,YAAYF,SAASG,IAAI;AACrF;AAGO,SAAS5B,iBAAiBI,GAAW;IAC1C,IAAMyB,aAAa/B,gBAAgBM,KAChCa,MAAM,CAAC,SAACN;eAASA,SAAS;OAC1BmB,IAAI,CAAC;IACR,IAAMT,IAAIzB,YAAYQ;IACtB,IAAM2B,YAAYV,IAAI,AAAC,SAAkBA,OAAVA,EAAEC,IAAI,EAAC,KAAW,OAARD,EAAEZ,KAAK,IAAK;IACrD,wFAAwF;IACxF,IAAMuB,cAAc,AAAC,qBAAG9B,YAAYE,MACjC6B,IAAI,GACJC,GAAG,CAAC,SAACvB;YAGiBwB;QAFrB,IAAMA,IAAI/B,IAAIG,OAAO,CAACI,KAAK;QAC3B,IAAMyB,UAAU,AAAC,qBAAGD,EAAEC,OAAO,EAAEH,IAAI,GAAGH,IAAI,CAAC;QAC3C,IAAMO,UAAU,AAAC,sBAAIF,aAAAA,EAAEE,OAAO,cAATF,wBAAAA,aAAa,EAAE,EAAGF,IAAI,GAAGH,IAAI,CAAC;QACnD,OAAO,AAAC,UAAiBM,OAARzB,MAAK,KAAc0B,OAAXD,SAAQ,KAAcD,OAAXE,SAAQ,KAAuC,OAApCF,EAAEvB,QAAQ,KAAK,QAAQ,QAAQ;IAChF,GACCkB,IAAI,CAAC;IACR,IAAML,WAAW9B,gBAAgBS;IACjC,IAAMkC,QAAQ;QAAE,YAAsB,OAAXT;QAAcE;KAAU;IACnD,IAAIN,aAAaE,WAAWW,MAAMC,IAAI,CAAC,AAAC,YAAoB,OAATd;IACnDa,MAAMC,IAAI,CAACP;IACX,OAAOM,MAAMR,IAAI,CAAC;AACpB"}
@@ -43,9 +43,7 @@ function _define_property(obj, key, value) {
43
43
  configurable: true,
44
44
  writable: true
45
45
  });
46
- } else {
47
- obj[key] = value;
48
- }
46
+ } else obj[key] = value;
49
47
  return obj;
50
48
  }
51
49
  function _iterable_to_array_limit(arr, i) {
@@ -73,7 +71,7 @@ function _iterable_to_array_limit(arr, i) {
73
71
  return _arr;
74
72
  }
75
73
  function _non_iterable_rest() {
76
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
74
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
77
75
  }
78
76
  function _object_spread(target) {
79
77
  for(var i = 1; i < arguments.length; i++){
@@ -105,9 +103,8 @@ function ownKeys(object, enumerableOnly) {
105
103
  }
106
104
  function _object_spread_props(target, source) {
107
105
  source = source != null ? source : {};
108
- if (Object.getOwnPropertyDescriptors) {
109
- Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
110
- } else {
106
+ if (Object.getOwnPropertyDescriptors) Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
107
+ else {
111
108
  ownKeys(Object(source)).forEach(function(key) {
112
109
  Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
113
110
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/config/load.ts"],"sourcesContent":["import { existsSync, readFileSync, writeFileSync } from 'node:fs';\nimport { dirname, join, resolve } from 'node:path';\nimport { SenseError } from '../errors.ts';\nimport type { Config, ResolvedConfig } from './types.ts';\nimport { CONFIG_FILENAME, DEFAULT_EMBED_MODEL, SUPPORTED_CONFIG_VERSION } from './types.ts';\nimport { unknownConfigKeys, validateConfig, validateLegacyScan } from './validate.ts';\n\n// v1 and v2 were `scan`/`find`-shaped; v3 introduced `presets`. Only the former need the\n// legacy shape check before migrating.\nconst FIRST_PRESET_VERSION = 3;\n\n// v1 -> v2 migration only: the features v2 introduced as opt-out (embed was opt-in then).\nconst V2_OPT_OUT_NAMES = ['links', 'sections', 'rank'] as const;\n\n// Pure per-version steps, chained by loadConfig. Intermediate shapes predate the Config type,\n// so steps are loosely typed and only the final result is cast back.\nconst MIGRATIONS: Record<number, (cfg: Record<string, unknown>) => Record<string, unknown>> = {\n // v1 -> v2: features block introduced, opt-out features enabled (matches the old implicit\n // behavior of `links` etc. not existing). embed stays absent -- opt-in.\n 1: (cfg) => ({ ...cfg, version: 2, features: Object.fromEntries(V2_OPT_OUT_NAMES.map((name) => [name, true])) }),\n // v2 -> v3: mechanical-minimal, by decision -- only what keeps an existing config loading.\n // No restructuring, no preset inference, no query rewriting; real trees get hand-migrated\n // separately to actually use presets.\n 2: (cfg) => {\n const { scan, defaults, features, checks, queries, ...rest } = cfg;\n const scanInclude = (scan as { include: string[] }).include;\n\n const nextQueries: Record<string, unknown> = {};\n for (const [name, value] of Object.entries((queries as Record<string, unknown> | undefined) ?? {})) {\n if (typeof value === 'string') {\n nextQueries[name] = value;\n continue;\n }\n const entry = value as { find: string; k?: number; where?: string; semantic?: boolean };\n // Loosely typed on purpose: this step emits the v3 shape, which still had `semantic`.\n // The v3 -> v4 step below strips it.\n const search: Record<string, unknown> = { search: entry.find };\n if (entry.k !== undefined) search.k = entry.k;\n if (entry.where !== undefined) search.where = entry.where;\n // semantic: true was opt-in; it is now the default, so it drops. semantic: false is kept.\n if (entry.semantic === false) search.semantic = false;\n nextQueries[name] = search;\n }\n\n const prevDefaults = defaults as { find?: { where?: string } } | undefined;\n const defaultWhere = prevDefaults?.find?.where;\n\n // features.embed false becomes semantic:false on every preset produced here.\n const prevFeatures = (features as Record<string, unknown> | undefined) ?? {};\n const embedWasOff = prevFeatures.embed === false;\n // Object form carried provider settings (model/type/url/key), not a toggle -- they move\n // to the v3 top-level `embed` block verbatim; dropping them would silently switch an\n // api tree back to the built-in static model.\n const embedProvider = typeof prevFeatures.embed === 'object' && prevFeatures.embed !== null ? prevFeatures.embed : undefined;\n const { embed: _embed, ...restFeatures } = prevFeatures;\n\n const defaultPreset: Record<string, unknown> = { include: scanInclude };\n if (defaultWhere !== undefined) defaultPreset.where = defaultWhere;\n if (embedWasOff) defaultPreset.semantic = false;\n\n // checks (assertions over saved queries) was removed in v3; its queries still run under\n // `queries`, just without the pass/fail assertion -- reachable now only as a saved query.\n if (checks !== undefined) {\n console.error('sense: v2 \"checks\" was removed in v3 (sense check no longer asserts on saved queries); its queries are carried over under \"queries\" -- a returned row set is now the reader\\'s judgment');\n }\n\n const result: Record<string, unknown> = { ...rest, version: 3, presets: { default: defaultPreset }, queries: nextQueries };\n if (embedProvider !== undefined) result.embed = embedProvider;\n if (Object.keys(restFeatures).length > 0) result.features = restFeatures;\n return result;\n },\n // v3 -> v4: write the model into the file, wrap bare-string queries as { sql }, drop a saved\n // search's `semantic` (its preset decides). Same effective model, so nothing re-embeds.\n 3: (cfg) => {\n const presets = cfg.presets as Record<string, Record<string, unknown>>;\n const embedded = Object.values(presets).some((p) => p.semantic !== false);\n\n const nextQueries: Record<string, unknown> = {};\n for (const [name, value] of Object.entries((cfg.queries as Record<string, unknown> | undefined) ?? {})) {\n // v3's bare string meant SQL by inference; v4 makes every entry name its verb.\n if (typeof value === 'string') {\n nextQueries[name] = { sql: value };\n continue;\n }\n if (typeof value !== 'object' || value === null || !('search' in value)) {\n nextQueries[name] = value;\n continue;\n }\n const { semantic: _semantic, ...rest } = value as Record<string, unknown>;\n nextQueries[name] = rest;\n }\n\n const prev = (cfg.embed as Record<string, unknown> | undefined) ?? {};\n const result: Record<string, unknown> = { ...cfg, version: 4, queries: nextQueries };\n if (embedded) {\n result.embed = { model: (prev.model as string | undefined) ?? DEFAULT_EMBED_MODEL, type: (prev.type as string | undefined) ?? 'static', ...(prev.url !== undefined ? { url: prev.url } : {}), ...(prev.key !== undefined ? { key: prev.key } : {}) };\n } else {\n delete result.embed;\n // Dropping settings silently would look like a bug in a tree that had configured an\n // api endpoint and then turned vectors off; say it, since v4 has no way to carry\n // provider settings for a tree that does not embed.\n if (Object.keys(prev).length > 0) console.error('sense: every preset has \"semantic\": false, so v4 drops the \"embed\" block (vectors stay off); re-add it, or set a preset\\'s semantic back to true, to turn them on');\n }\n return result;\n },\n};\n\nexport function migrateConfig(cfg: Config): { cfg: Config; from: number } {\n const from = cfg.version ?? 1;\n let current: Record<string, unknown> = cfg as unknown as Record<string, unknown>;\n for (let v = from; v < SUPPORTED_CONFIG_VERSION; v++) {\n const step = MIGRATIONS[v];\n if (!step) throw new SenseError('CONFIG_VERSION_UNSUPPORTED', `no migration from config version ${v}`);\n current = step(current);\n }\n return { cfg: current as unknown as Config, from };\n}\n\nfunction starterConfig(): Config {\n return {\n $schema: 'https://unpkg.com/sensemaking/schema.json',\n version: SUPPORTED_CONFIG_VERSION,\n presets: {\n default: { include: ['**/*.md'], k: 10 },\n large: { include: ['**/*.md'], k: 20 },\n },\n // Written out rather than defaulted in code: this line is what makes `sense download`\n // fetch 124 MB, so it belongs where it can be read and changed.\n embed: { model: DEFAULT_EMBED_MODEL, type: 'static' },\n queries: {},\n };\n}\n\n// Refuses to overwrite an existing config.\nexport function initConfig(dir: string): string {\n const configPath = join(dir, CONFIG_FILENAME);\n if (existsSync(configPath)) {\n throw new SenseError('CONFIG_EXISTS', `${CONFIG_FILENAME} already exists in ${dir}`);\n }\n writeFileSync(configPath, `${JSON.stringify(starterConfig(), null, 2)}\\n`);\n return configPath;\n}\n\nexport function findConfigPath(startDir: string): string | null {\n let dir = resolve(startDir);\n for (;;) {\n const candidate = join(dir, CONFIG_FILENAME);\n if (existsSync(candidate)) return candidate;\n const parent = dirname(dir);\n if (parent === dir) return null;\n dir = parent;\n }\n}\n\nexport function loadConfig(explicitPath?: string): ResolvedConfig {\n let configPath: string;\n if (explicitPath) {\n configPath = resolve(process.cwd(), explicitPath);\n if (!existsSync(configPath)) throw new SenseError('CONFIG_NOT_FOUND', `config not found: ${configPath}`);\n } else {\n const found = findConfigPath(process.cwd());\n if (!found) {\n throw new SenseError('CONFIG_NOT_FOUND', `could not find ${CONFIG_FILENAME} in ${process.cwd()} or any parent directory`);\n }\n configPath = found;\n }\n\n const raw = readFileSync(configPath, 'utf8');\n const parsed: unknown = JSON.parse(raw);\n\n // Ahead of both the version gate and legacy/current shape checks: a non-object file (or\n // an array -- typeof [] is also 'object') is malformed at every version, so it gets one\n // error regardless of which branch would otherwise run.\n if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {\n throw new SenseError('CONFIG_INVALID', `${configPath}: config must be a JSON object`);\n }\n\n // Version gate before shape validation: a config written by a newer sense should fail\n // with \"requires a newer sense\", not with shape errors its own version may not have.\n const version = typeof parsed === 'object' && parsed !== null && typeof (parsed as { version?: unknown }).version === 'number' ? (parsed as { version: number }).version : 1;\n if (version > SUPPORTED_CONFIG_VERSION) {\n throw new SenseError('CONFIG_VERSION_UNSUPPORTED', `config version ${version} requires a newer sense`);\n }\n\n // validateConfig only knows the current shape, so scan-shaped files (pre-v3) get a minimal\n // check, migrate, then the full one on the result.\n let cfg: Config;\n let migratedFrom: number | undefined;\n if (version < SUPPORTED_CONFIG_VERSION) {\n if (version < FIRST_PRESET_VERSION) validateLegacyScan(parsed, configPath);\n const result = migrateConfig(parsed as unknown as Config);\n cfg = validateConfig(result.cfg, configPath);\n migratedFrom = result.from;\n writeFileSync(configPath, `${JSON.stringify(cfg, null, 2)}\\n`);\n } else {\n cfg = validateConfig(parsed, configPath);\n }\n\n const unknownKeys = unknownConfigKeys(cfg as unknown as Record<string, unknown>);\n return { ...cfg, baseDir: dirname(configPath), configPath, migratedFrom, unknownKeys: unknownKeys.length > 0 ? unknownKeys : undefined };\n}\n"],"names":["findConfigPath","initConfig","loadConfig","migrateConfig","FIRST_PRESET_VERSION","V2_OPT_OUT_NAMES","MIGRATIONS","cfg","version","features","Object","fromEntries","map","name","prevDefaults","scan","defaults","checks","queries","rest","scanInclude","include","nextQueries","entries","value","entry","search","find","k","undefined","where","semantic","defaultWhere","prevFeatures","embedWasOff","embed","embedProvider","_embed","restFeatures","defaultPreset","console","error","result","presets","default","keys","length","embedded","values","some","p","sql","_semantic","prev","model","DEFAULT_EMBED_MODEL","type","url","key","from","current","v","SUPPORTED_CONFIG_VERSION","step","SenseError","starterConfig","$schema","large","dir","configPath","join","CONFIG_FILENAME","existsSync","writeFileSync","JSON","stringify","startDir","resolve","candidate","parent","dirname","explicitPath","process","cwd","found","raw","readFileSync","parsed","parse","Array","isArray","migratedFrom","validateLegacyScan","validateConfig","unknownKeys","unknownConfigKeys","baseDir"],"mappings":";;;;;;;;;;;QA+IgBA;eAAAA;;QATAC;eAAAA;;QAoBAC;eAAAA;;QA/CAC;eAAAA;;;sBA3GwC;wBACjB;wBACZ;uBAEoD;0BACT;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEtE,yFAAyF;AACzF,uCAAuC;AACvC,IAAMC,uBAAuB;AAE7B,0FAA0F;AAC1F,IAAMC,mBAAmB;IAAC;IAAS;IAAY;CAAO;AAEtD,8FAA8F;AAC9F,qEAAqE;AACrE,IAAMC,aAAwF;IAC5F,0FAA0F;IAC1F,wEAAwE;IACxE,GAAG,SAACC;eAAS,wCAAKA;YAAKC,SAAS;YAAGC,UAAUC,OAAOC,WAAW,CAACN,iBAAiBO,GAAG,CAAC,SAACC;uBAAS;oBAACA;oBAAM;iBAAK;;;;IAC3G,2FAA2F;IAC3F,0FAA0F;IAC1F,sCAAsC;IACtC,GAAG,SAACN;YAsBmBO;QArBrB,IAAQC,OAAuDR,IAAvDQ,MAAMC,WAAiDT,IAAjDS,UAAUP,WAAuCF,IAAvCE,UAAUQ,SAA6BV,IAA7BU,QAAQC,UAAqBX,IAArBW,SAAYC,kCAASZ;;;;;;;QAC/D,IAAMa,cAAc,AAACL,KAA+BM,OAAO;QAE3D,IAAMC,cAAuC,CAAC;YACzC,kCAAA,2BAAA;;YAAL,QAAK,YAAuBZ,OAAOa,OAAO,CAAEL,oBAAAA,qBAAAA,UAAmD,CAAC,uBAA3F,SAAA,6BAAA,QAAA,yBAAA,iCAA+F;gBAA/F,mCAAA,iBAAOL,uBAAMW;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YA,WAAW,QAAQE,MAAMC,OAAO,CAACH,SAAS;QAC1E,MAAM,IAAIvB,oBAAU,CAAC,kBAAkB,AAAC,GAAa,OAAXK,YAAW;IACvD;IAEA,sFAAsF;IACtF,qFAAqF;IACrF,IAAM7D,UAAU,CAAA,OAAO+E,uCAAP,SAAOA,OAAK,MAAM,YAAYA,WAAW,QAAQ,OAAO,AAACA,OAAiC/E,OAAO,KAAK,WAAW,AAAC+E,OAA+B/E,OAAO,GAAG;IAC3K,IAAIA,UAAUsD,iCAAwB,EAAE;QACtC,MAAM,IAAIE,oBAAU,CAAC,8BAA8B,AAAC,kBAAyB,OAARxD,SAAQ;IAC/E;IAEA,2FAA2F;IAC3F,mDAAmD;IACnD,IAAID;IACJ,IAAIoF;IACJ,IAAInF,UAAUsD,iCAAwB,EAAE;QACtC,IAAItD,UAAUJ,sBAAsBwF,IAAAA,8BAAkB,EAACL,QAAQlB;QAC/D,IAAM3B,SAASvC,cAAcoF;QAC7BhF,MAAMsF,IAAAA,0BAAc,EAACnD,OAAOnC,GAAG,EAAE8D;QACjCsB,eAAejD,OAAOiB,IAAI;QAC1Bc,IAAAA,qBAAa,EAACJ,YAAY,AAAC,GAA+B,OAA7BK,KAAKC,SAAS,CAACpE,KAAK,MAAM,IAAG;IAC5D,OAAO;QACLA,MAAMsF,IAAAA,0BAAc,EAACN,QAAQlB;IAC/B;IAEA,IAAMyB,cAAcC,IAAAA,6BAAiB,EAACxF;IACtC,OAAO,wCAAKA;QAAKyF,SAAShB,IAAAA,iBAAO,EAACX;QAAaA,YAAAA;QAAYsB,cAAAA;QAAcG,aAAaA,YAAYhD,MAAM,GAAG,IAAIgD,cAAcjE;;AAC/H"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/config/load.ts"],"sourcesContent":["import { existsSync, readFileSync, writeFileSync } from 'node:fs';\nimport { dirname, join, resolve } from 'node:path';\nimport { SenseError } from '../errors.ts';\nimport type { Config, ResolvedConfig } from './types.ts';\nimport { CONFIG_FILENAME, DEFAULT_EMBED_MODEL, SUPPORTED_CONFIG_VERSION } from './types.ts';\nimport { unknownConfigKeys, validateConfig, validateLegacyScan } from './validate.ts';\n\n// v1 and v2 were `scan`/`find`-shaped; v3 introduced `presets`. Only the former need the\n// legacy shape check before migrating.\nconst FIRST_PRESET_VERSION = 3;\n\n// v1 -> v2 migration only: the features v2 introduced as opt-out (embed was opt-in then).\nconst V2_OPT_OUT_NAMES = ['links', 'sections', 'rank'] as const;\n\n// Pure per-version steps, chained by loadConfig. Intermediate shapes predate the Config type,\n// so steps are loosely typed and only the final result is cast back.\nconst MIGRATIONS: Record<number, (cfg: Record<string, unknown>) => Record<string, unknown>> = {\n // v1 -> v2: features block introduced, opt-out features enabled (matches the old implicit\n // behavior of `links` etc. not existing). embed stays absent -- opt-in.\n 1: (cfg) => ({ ...cfg, version: 2, features: Object.fromEntries(V2_OPT_OUT_NAMES.map((name) => [name, true])) }),\n // v2 -> v3: mechanical-minimal, by decision -- only what keeps an existing config loading.\n // No restructuring, no preset inference, no query rewriting; real trees get hand-migrated\n // separately to actually use presets.\n 2: (cfg) => {\n const { scan, defaults, features, checks, queries, ...rest } = cfg;\n const scanInclude = (scan as { include: string[] }).include;\n\n const nextQueries: Record<string, unknown> = {};\n for (const [name, value] of Object.entries((queries as Record<string, unknown> | undefined) ?? {})) {\n if (typeof value === 'string') {\n nextQueries[name] = value;\n continue;\n }\n const entry = value as { find: string; k?: number; where?: string; semantic?: boolean };\n // Loosely typed on purpose: this step emits the v3 shape, which still had `semantic`.\n // The v3 -> v4 step below strips it.\n const search: Record<string, unknown> = { search: entry.find };\n if (entry.k !== undefined) search.k = entry.k;\n if (entry.where !== undefined) search.where = entry.where;\n // semantic: true was opt-in; it is now the default, so it drops. semantic: false is kept.\n if (entry.semantic === false) search.semantic = false;\n nextQueries[name] = search;\n }\n\n const prevDefaults = defaults as { find?: { where?: string } } | undefined;\n const defaultWhere = prevDefaults?.find?.where;\n\n // features.embed false becomes semantic:false on every preset produced here.\n const prevFeatures = (features as Record<string, unknown> | undefined) ?? {};\n const embedWasOff = prevFeatures.embed === false;\n // Object form carried provider settings (model/type/url/key), not a toggle -- they move\n // to the v3 top-level `embed` block verbatim; dropping them would silently switch an\n // api tree back to the built-in static model.\n const embedProvider = typeof prevFeatures.embed === 'object' && prevFeatures.embed !== null ? prevFeatures.embed : undefined;\n const { embed: _embed, ...restFeatures } = prevFeatures;\n\n const defaultPreset: Record<string, unknown> = { include: scanInclude };\n if (defaultWhere !== undefined) defaultPreset.where = defaultWhere;\n if (embedWasOff) defaultPreset.semantic = false;\n\n // checks (assertions over saved queries) was removed in v3; its queries still run under\n // `queries`, just without the pass/fail assertion -- reachable now only as a saved query.\n if (checks !== undefined) {\n console.error('sense: v2 \"checks\" was removed in v3 (sense check no longer asserts on saved queries); its queries are carried over under \"queries\" -- a returned row set is now the reader\\'s judgment');\n }\n\n const result: Record<string, unknown> = { ...rest, version: 3, presets: { default: defaultPreset }, queries: nextQueries };\n if (embedProvider !== undefined) result.embed = embedProvider;\n if (Object.keys(restFeatures).length > 0) result.features = restFeatures;\n return result;\n },\n // v3 -> v4: write the model into the file, wrap bare-string queries as { sql }, drop a saved\n // search's `semantic` (its preset decides). Same effective model, so nothing re-embeds.\n 3: (cfg) => {\n const presets = cfg.presets as Record<string, Record<string, unknown>>;\n const embedded = Object.values(presets).some((p) => p.semantic !== false);\n\n const nextQueries: Record<string, unknown> = {};\n for (const [name, value] of Object.entries((cfg.queries as Record<string, unknown> | undefined) ?? {})) {\n // v3's bare string meant SQL by inference; v4 makes every entry name its verb.\n if (typeof value === 'string') {\n nextQueries[name] = { sql: value };\n continue;\n }\n if (typeof value !== 'object' || value === null || !('search' in value)) {\n nextQueries[name] = value;\n continue;\n }\n const { semantic: _semantic, ...rest } = value as Record<string, unknown>;\n nextQueries[name] = rest;\n }\n\n const prev = (cfg.embed as Record<string, unknown> | undefined) ?? {};\n const result: Record<string, unknown> = { ...cfg, version: 4, queries: nextQueries };\n if (embedded) {\n result.embed = { model: (prev.model as string | undefined) ?? DEFAULT_EMBED_MODEL, type: (prev.type as string | undefined) ?? 'static', ...(prev.url !== undefined ? { url: prev.url } : {}), ...(prev.key !== undefined ? { key: prev.key } : {}) };\n } else {\n delete result.embed;\n // Dropping settings silently would look like a bug in a tree that had configured an\n // api endpoint and then turned vectors off; say it, since v4 has no way to carry\n // provider settings for a tree that does not embed.\n if (Object.keys(prev).length > 0) console.error('sense: every preset has \"semantic\": false, so v4 drops the \"embed\" block (vectors stay off); re-add it, or set a preset\\'s semantic back to true, to turn them on');\n }\n return result;\n },\n};\n\nexport function migrateConfig(cfg: Config): { cfg: Config; from: number } {\n const from = cfg.version ?? 1;\n let current: Record<string, unknown> = cfg as unknown as Record<string, unknown>;\n for (let v = from; v < SUPPORTED_CONFIG_VERSION; v++) {\n const step = MIGRATIONS[v];\n if (!step) throw new SenseError('CONFIG_VERSION_UNSUPPORTED', `no migration from config version ${v}`);\n current = step(current);\n }\n return { cfg: current as unknown as Config, from };\n}\n\nfunction starterConfig(): Config {\n return {\n $schema: 'https://unpkg.com/sensemaking/schema.json',\n version: SUPPORTED_CONFIG_VERSION,\n presets: {\n default: { include: ['**/*.md'], k: 10 },\n large: { include: ['**/*.md'], k: 20 },\n },\n // Written out rather than defaulted in code: this line is what makes `sense download`\n // fetch 124 MB, so it belongs where it can be read and changed.\n embed: { model: DEFAULT_EMBED_MODEL, type: 'static' },\n queries: {},\n };\n}\n\n// Refuses to overwrite an existing config.\nexport function initConfig(dir: string): string {\n const configPath = join(dir, CONFIG_FILENAME);\n if (existsSync(configPath)) {\n throw new SenseError('CONFIG_EXISTS', `${CONFIG_FILENAME} already exists in ${dir}`);\n }\n writeFileSync(configPath, `${JSON.stringify(starterConfig(), null, 2)}\\n`);\n return configPath;\n}\n\nexport function findConfigPath(startDir: string): string | null {\n let dir = resolve(startDir);\n for (;;) {\n const candidate = join(dir, CONFIG_FILENAME);\n if (existsSync(candidate)) return candidate;\n const parent = dirname(dir);\n if (parent === dir) return null;\n dir = parent;\n }\n}\n\nexport function loadConfig(explicitPath?: string): ResolvedConfig {\n let configPath: string;\n if (explicitPath) {\n configPath = resolve(process.cwd(), explicitPath);\n if (!existsSync(configPath)) throw new SenseError('CONFIG_NOT_FOUND', `config not found: ${configPath}`);\n } else {\n const found = findConfigPath(process.cwd());\n if (!found) {\n throw new SenseError('CONFIG_NOT_FOUND', `could not find ${CONFIG_FILENAME} in ${process.cwd()} or any parent directory`);\n }\n configPath = found;\n }\n\n const raw = readFileSync(configPath, 'utf8');\n const parsed: unknown = JSON.parse(raw);\n\n // Ahead of both the version gate and legacy/current shape checks: a non-object file (or\n // an array -- typeof [] is also 'object') is malformed at every version, so it gets one\n // error regardless of which branch would otherwise run.\n if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {\n throw new SenseError('CONFIG_INVALID', `${configPath}: config must be a JSON object`);\n }\n\n // Version gate before shape validation: a config written by a newer sense should fail\n // with \"requires a newer sense\", not with shape errors its own version may not have.\n const version = typeof parsed === 'object' && parsed !== null && typeof (parsed as { version?: unknown }).version === 'number' ? (parsed as { version: number }).version : 1;\n if (version > SUPPORTED_CONFIG_VERSION) {\n throw new SenseError('CONFIG_VERSION_UNSUPPORTED', `config version ${version} requires a newer sense`);\n }\n\n // validateConfig only knows the current shape, so scan-shaped files (pre-v3) get a minimal\n // check, migrate, then the full one on the result.\n let cfg: Config;\n let migratedFrom: number | undefined;\n if (version < SUPPORTED_CONFIG_VERSION) {\n if (version < FIRST_PRESET_VERSION) validateLegacyScan(parsed, configPath);\n const result = migrateConfig(parsed as unknown as Config);\n cfg = validateConfig(result.cfg, configPath);\n migratedFrom = result.from;\n writeFileSync(configPath, `${JSON.stringify(cfg, null, 2)}\\n`);\n } else {\n cfg = validateConfig(parsed, configPath);\n }\n\n const unknownKeys = unknownConfigKeys(cfg as unknown as Record<string, unknown>);\n return { ...cfg, baseDir: dirname(configPath), configPath, migratedFrom, unknownKeys: unknownKeys.length > 0 ? unknownKeys : undefined };\n}\n"],"names":["findConfigPath","initConfig","loadConfig","migrateConfig","FIRST_PRESET_VERSION","V2_OPT_OUT_NAMES","MIGRATIONS","cfg","version","features","Object","fromEntries","map","name","prevDefaults","scan","defaults","checks","queries","rest","scanInclude","include","nextQueries","entries","value","entry","search","find","k","undefined","where","semantic","defaultWhere","prevFeatures","embedWasOff","embed","embedProvider","_embed","restFeatures","defaultPreset","console","error","result","presets","default","keys","length","embedded","values","some","p","sql","_semantic","prev","model","DEFAULT_EMBED_MODEL","type","url","key","from","current","v","SUPPORTED_CONFIG_VERSION","step","SenseError","starterConfig","$schema","large","dir","configPath","join","CONFIG_FILENAME","existsSync","writeFileSync","JSON","stringify","startDir","resolve","candidate","parent","dirname","explicitPath","process","cwd","found","raw","readFileSync","parsed","parse","Array","isArray","migratedFrom","validateLegacyScan","validateConfig","unknownKeys","unknownConfigKeys","baseDir"],"mappings":";;;;;;;;;;;QA+IgBA;eAAAA;;QATAC;eAAAA;;QAoBAC;eAAAA;;QA/CAC;eAAAA;;;sBA3GwC;wBACjB;wBACZ;uBAEoD;0BACT;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEtE,yFAAyF;AACzF,uCAAuC;AACvC,IAAMC,uBAAuB;AAE7B,0FAA0F;AAC1F,IAAMC,mBAAmB;IAAC;IAAS;IAAY;CAAO;AAEtD,8FAA8F;AAC9F,qEAAqE;AACrE,IAAMC,aAAwF;IAC5F,0FAA0F;IAC1F,wEAAwE;IACxE,GAAG,SAACC;eAAS,wCAAKA;YAAKC,SAAS;YAAGC,UAAUC,OAAOC,WAAW,CAACN,iBAAiBO,GAAG,CAAC,SAACC;uBAAS;oBAACA;oBAAM;iBAAK;;;;IAC3G,2FAA2F;IAC3F,0FAA0F;IAC1F,s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MAAMsF,IAAAA,0BAAc,EAACN,QAAQlB;IAC/B;IAEA,IAAMyB,cAAcC,IAAAA,6BAAiB,EAACxF;IACtC,OAAO,wCAAKA;QAAKyF,SAAShB,IAAAA,iBAAO,EAACX;QAAaA,YAAAA;QAAYsB,cAAAA;QAAcG,aAAaA,YAAYhD,MAAM,GAAG,IAAIgD,cAAcjE;;AAC/H"}
@@ -53,7 +53,7 @@ function _iterable_to_array_limit(arr, i) {
53
53
  return _arr;
54
54
  }
55
55
  function _non_iterable_rest() {
56
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
56
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
57
57
  }
58
58
  function _sliced_to_array(arr, i) {
59
59
  return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
@@ -45,10 +45,12 @@ function _array_without_holes(arr) {
45
45
  if (Array.isArray(arr)) return _array_like_to_array(arr);
46
46
  }
47
47
  function _iterable_to_array(iter) {
48
- if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
48
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) {
49
+ return Array.from(iter);
50
+ }
49
51
  }
50
52
  function _non_iterable_spread() {
51
- throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
53
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
52
54
  }
53
55
  function _to_consumable_array(arr) {
54
56
  return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/db/open.ts"],"sourcesContent":["// The Node floor (>=22.20) is explained here and nowhere else: 22.20 is the first release with\n// both FTS5 and row-returning INSERT ... RETURNING. Raise it only for a load-bearing capability.\nimport { mkdirSync, rmSync } from 'node:fs';\nimport { join } from 'node:path';\nimport { DatabaseSync } from 'node:sqlite';\nimport type { Config, ResolvedConfig } from '../config/index.ts';\nimport { contentTokenize, featureSignature, STATE_DIR } from '../config/index.ts';\nimport { SenseError } from '../errors.ts';\nimport { activeFeatures } from '../features/index.ts';\nimport { registerFunctions } from '../sql-functions.ts';\nimport { changedSignatureKeys, rebuildContentTable, reconcile, signatureDiff } from './reconcile.ts';\nimport { getMeta, setMeta } from './shared.ts';\n\nexport const DB_FILENAME = 'cache.db';\n// Cache shape version, independent of the config's own `version`. Bumping it rebuilds\n// existing trees on first query.\nexport const SCHEMA_VERSION = '16';\n\nexport interface OpenResult {\n db: DatabaseSync;\n cfg: ResolvedConfig;\n dbPath: string;\n parsed: number;\n warnings: string[];\n}\n\n// Stemming is English-only, but the segmentation underneath it is what decides coverage:\n// unicode61 splits on spaces, so a language written without them (Chinese, Japanese, Thai)\n// indexes a whole run as one token and word search finds nothing. `content.tokenize` is how\n// such a tree picks trigram instead.\nconst DEFAULT_TOKENIZE = 'porter unicode61';\n\n// FTS5 takes its tokenizer as a string literal inside DDL, where nothing can bind, so a\n// configured value has to be concatenated. Probing a throwaway table is what makes that safe\n// and is also the whole validation: anything the linked SQLite accepts passes, anything else\n// fails here with SQLite's own message rather than against the real table. It means no table\n// of which version added which tokenizer has to be maintained.\nfunction resolveTokenize(db: DatabaseSync, cfg: Config): string {\n const configured = contentTokenize(cfg);\n if (configured === undefined) return DEFAULT_TOKENIZE;\n const literal = configured.replace(/'/g, \"''\");\n try {\n db.exec('DROP TABLE IF EXISTS temp.sense_tokenize_probe');\n db.exec(`CREATE VIRTUAL TABLE temp.sense_tokenize_probe USING fts5(x, tokenize = '${literal}')`);\n db.exec('DROP TABLE IF EXISTS temp.sense_tokenize_probe');\n } catch (err) {\n throw new SenseError('CONFIG_INVALID', `content.tokenize \"${configured}\" is not a tokenizer this SQLite accepts (${(err as Error).message}); the built-in choices are unicode61, ascii, porter, and trigram, each with their own options`);\n }\n return literal;\n}\n\n// The tokenizer the content table was actually built with, from its own DDL -- the one\n// record that cannot desynchronize from the table. NULL when the table does not exist yet.\nfunction storedTokenize(db: DatabaseSync): string | null {\n const row = db.prepare(`SELECT sql FROM sqlite_master WHERE name = 'content'`).get() as { sql: string } | undefined;\n if (!row) return null;\n const m = row.sql.match(/tokenize = '((?:[^']|'')*)'/);\n return m ? m[1] : null;\n}\n\n// Content is a separate table (not a column on frontmatter) so `SELECT * FROM frontmatter`\n// can't dump file text into context. Features add their own tables after the core ones.\nfunction ensureSchema(db: DatabaseSync, cfg: Config, tokenize: string): void {\n db.exec(`CREATE TABLE IF NOT EXISTS frontmatter (\"path\" TEXT PRIMARY KEY, \"_mtime\" REAL, \"_ctime\" REAL, \"_size\" INTEGER, \"_parse_error\" TEXT)`);\n // IF NOT EXISTS is safe against a tokenizer change: open() compares the table's own DDL\n // against the resolved tokenizer before this runs, so a stale table is already gone by now.\n // The three `_seg` sidecars are appended after path, never inserted: bm25(content, ...) and\n // snippet(content, 2, ...) are documented against the first three columns and keep working\n // (FTS5 defaults the weights it was not given). Each carries its field's exploded unspaced\n // runs for text that needs it, and an empty string for text that does not.\n db.exec(`CREATE VIRTUAL TABLE IF NOT EXISTS content USING fts5(title, summary, text, path UNINDEXED, title_seg, summary_seg, text_seg, tokenize = '${tokenize}')`);\n // Coverage, not ownership: a path can appear under several presets. path leads the PK so the\n // per-doc delete is an index hit -- keyed the other way, cold builds went quadratic.\n db.exec(`CREATE TABLE IF NOT EXISTS preset_files (\"path\" TEXT, preset TEXT, PRIMARY KEY (\"path\", preset))`);\n db.exec('CREATE INDEX IF NOT EXISTS preset_files_preset ON preset_files(preset)');\n for (const feature of activeFeatures(cfg)) feature.schema(db);\n if (getMeta(db, 'schema_version') === null) setMeta(db, 'schema_version', SCHEMA_VERSION);\n if (getMeta(db, 'features') === null) setMeta(db, 'features', featureSignature(cfg));\n}\n\nexport function docCount(db: DatabaseSync): number {\n const row = db.prepare('SELECT COUNT(*) AS n FROM frontmatter').get() as { n: number };\n return row.n;\n}\n\nexport function open(cfg: ResolvedConfig): OpenResult {\n const stateDir = join(cfg.baseDir, STATE_DIR);\n mkdirSync(stateDir, { recursive: true });\n const dbPath = join(stateDir, DB_FILENAME);\n\n const db = new DatabaseSync(dbPath);\n db.exec('PRAGMA journal_mode = WAL');\n // Covers a concurrent watcher's bulk reconcile (~5s for 500 files at 26k notes). A query\n // that outwaits it still fails loudly.\n db.exec('PRAGMA busy_timeout = 30000');\n registerFunctions(db, contentTokenize(cfg) === undefined);\n\n db.exec('CREATE TABLE IF NOT EXISTS meta (key TEXT PRIMARY KEY, value TEXT)');\n\n // Before the rebuild branch below, never after: that branch deletes the cache, so a typo'd\n // tokenizer validated later would cost a full re-index (and re-embed) to reach its own error.\n const tokenize = resolveTokenize(db, cfg);\n\n // Schema-version or feature-set mismatch: reconcile only reparses changed files, so an\n // old cache can't be patched incrementally -- rebuild instead (cheap: nothing expensive lives here).\n const version = getMeta(db, 'schema_version');\n const features = getMeta(db, 'features');\n const wantFeatures = featureSignature(cfg);\n let tokenizeOnlyRebuild = false;\n if ((version !== null && version !== SCHEMA_VERSION) || (features !== null && features !== wantFeatures)) {\n // Indexing derives from presets, so a config edit rebuilding the cache must say so and\n // name what changed -- silent rebuilds make derived indexing look like a hang or a bug.\n if (version !== null && version !== SCHEMA_VERSION) {\n console.error('sense: cache format changed (new sensemaking version); rebuilding the index');\n db.close();\n clearCache(cfg);\n return open(cfg);\n }\n const changedKeys = changedSignatureKeys(features ?? '', wantFeatures);\n // Only the tokenizer moved: frontmatter, links, sections, and embeddings are file-derived\n // and tokenizer-independent, so they don't need re-deriving. Everything else -- a preset\n // edit, an embed model change -- still takes the full clear/reopen below.\n if (changedKeys.size === 1 && changedKeys.has('tokenize')) {\n console.error('sense: config change (content tokenizer) rebuilds the text index; vectors, links, and sections are kept');\n db.exec('DROP TABLE content');\n tokenizeOnlyRebuild = true;\n } else {\n const changed = signatureDiff(features ?? '', wantFeatures);\n console.error(`sense: config change (${changed}) rebuilds the index`);\n db.close();\n clearCache(cfg);\n return open(cfg);\n }\n }\n\n // Meta can lie after a crash between table creation and the signature write; the table's\n // own DDL cannot. A mismatch here rebuilds no matter what meta says. A tokenize-only rebuild\n // just dropped content above, so storedTokenize sees no table and this guard is skipped\n // naturally rather than needing its own case.\n const stored = storedTokenize(db);\n if (stored !== null && stored !== tokenize) {\n console.error('sense: cache was built with a different content tokenizer; rebuilding the index');\n db.close();\n clearCache(cfg);\n return open(cfg);\n }\n\n ensureSchema(db, cfg, tokenize);\n\n let rebuildWarnings: string[] = [];\n if (tokenizeOnlyRebuild) {\n rebuildWarnings = rebuildContentTable(db, cfg, cfg.baseDir);\n setMeta(db, 'features', wantFeatures);\n }\n\n // 3x the largest reconcile this cache has recorded, floored at 30s and capped at 10min.\n // Installed before reconcile() -- that call is the one that races a watcher's transaction.\n const recordedMaxMs = Number(getMeta(db, 'reconcile_max_ms') ?? '0');\n db.exec(`PRAGMA busy_timeout = ${Math.min(Math.max(30000, 3 * recordedMaxMs), 600_000)}`);\n\n const { parsed, warnings } = reconcile(db, cfg, cfg.baseDir);\n\n return { db, cfg, dbPath, parsed, warnings: [...rebuildWarnings, ...warnings] };\n}\n\n// Deletes the cache directory, and only that. The rebuild is not this function's job: the next\n// open() reconciles, which is what running any command already does, so a verb that bundled the\n// two described the half that was not its own. Manual reset for a doubted cache; the schema and\n// config-signature mismatches below reset themselves.\nexport function clearCache(cfg: ResolvedConfig): void {\n rmSync(join(cfg.baseDir, STATE_DIR), { recursive: true, force: true });\n}\n"],"names":["DB_FILENAME","SCHEMA_VERSION","clearCache","docCount","open","DEFAULT_TOKENIZE","resolveTokenize","db","cfg","configured","contentTokenize","undefined","literal","replace","exec","err","SenseError","message","storedTokenize","row","prepare","get","m","sql","match","ensureSchema","tokenize","activeFeatures","feature","schema","getMeta","setMeta","featureSignature","n","stateDir","join","baseDir","STATE_DIR","mkdirSync","recursive","dbPath","DatabaseSync","registerFunctions","version","features","wantFeatures","tokenizeOnlyRebuild","console","error","close","changedKeys","changedSignatureKeys","size","has","changed","signatureDiff","stored","rebuildWarnings","rebuildContentTable","recordedMaxMs","Number","Math","min","max","reconcile","parsed","warnings","rmSync","force"],"mappings":"AAAA,+FAA+F;AAC/F,iGAAiG;;;;;;;;;;;;QAYpFA;eAAAA;;QAGAC;eAAAA;;QAyJGC;eAAAA;;QAzFAC;eAAAA;;QAKAC;eAAAA;;;sBAnFkB;wBACb;0BACQ;uBAEgC;wBAClC;wBACI;8BACG;2BACkD;wBACnD;;;;;;;;;;;;;;;;;;;;;;;;;;AAE1B,IAAMJ,cAAc;AAGpB,IAAMC,iBAAiB;AAU9B,yFAAyF;AACzF,2FAA2F;AAC3F,4FAA4F;AAC5F,qCAAqC;AACrC,IAAMI,mBAAmB;AAEzB,wFAAwF;AACxF,6FAA6F;AAC7F,6FAA6F;AAC7F,6FAA6F;AAC7F,+DAA+D;AAC/D,SAASC,gBAAgBC,EAAgB,EAAEC,GAAW;IACpD,IAAMC,aAAaC,IAAAA,wBAAe,EAACF;IACnC,IAAIC,eAAeE,WAAW,OAAON;IACrC,IAAMO,UAAUH,WAAWI,OAAO,CAAC,MAAM;IACzC,IAAI;QACFN,GAAGO,IAAI,CAAC;QACRP,GAAGO,IAAI,CAAC,AAAC,4EAAmF,OAARF,SAAQ;QAC5FL,GAAGO,IAAI,CAAC;IACV,EAAE,OAAOC,KAAK;QACZ,MAAM,IAAIC,oBAAU,CAAC,kBAAkB,AAAC,qBAA2E,OAAvDP,YAAW,8CAAmE,OAAvB,AAACM,IAAcE,OAAO,EAAC;IAC5I;IACA,OAAOL;AACT;AAEA,uFAAuF;AACvF,2FAA2F;AAC3F,SAASM,eAAeX,EAAgB;IACtC,IAAMY,MAAMZ,GAAGa,OAAO,CAAC,wDAAwDC,GA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AA8C;IAC9C,IAAMgD,SAAStC,eAAeX;IAC9B,IAAIiD,WAAW,QAAQA,WAAW9B,UAAU;QAC1CqB,QAAQC,KAAK,CAAC;QACdzC,GAAG0C,KAAK;QACR/C,WAAWM;QACX,OAAOJ,KAAKI;IACd;IAEAiB,aAAalB,IAAIC,KAAKkB;IAEtB,IAAI+B,kBAA4B,EAAE;IAClC,IAAIX,qBAAqB;QACvBW,kBAAkBC,IAAAA,gCAAmB,EAACnD,IAAIC,KAAKA,IAAI4B,OAAO;QAC1DL,IAAAA,iBAAO,EAACxB,IAAI,YAAYsC;IAC1B;IAEA,wFAAwF;IACxF,2FAA2F;IAC3F,IAAMc,gBAAgBC,QAAO9B,WAAAA,IAAAA,iBAAO,EAACvB,IAAI,iCAAZuB,sBAAAA,WAAmC;IAChEvB,GAAGO,IAAI,CAAC,AAAC,yBAA8E,OAAtD+C,KAAKC,GAAG,CAACD,KAAKE,GAAG,CAAC,OAAO,IAAIJ,gBAAgB;IAE9E,IAA6BK,aAAAA,IAAAA,sBAAS,EAACzD,IAAIC,KAAKA,IAAI4B,OAAO,GAAnD6B,SAAqBD,WAArBC,QAAQC,WAAaF,WAAbE;IAEhB,OAAO;QAAE3D,IAAAA;QAAIC,KAAAA;QAAKgC,QAAAA;QAAQyB,QAAAA;QAAQC,UAAU,AAAC,qBAAGT,wBAAiB,qBAAGS;IAAU;AAChF;AAMO,SAAShE,WAAWM,GAAmB;IAC5C2D,IAAAA,cAAM,EAAChC,IAAAA,cAAI,EAAC3B,IAAI4B,OAAO,EAAEC,kBAAS,GAAG;QAAEE,WAAW;QAAM6B,OAAO;IAAK;AACtE"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/db/open.ts"],"sourcesContent":["// The Node floor (>=22.20) is explained here and nowhere else: 22.20 is the first release with\n// both FTS5 and row-returning INSERT ... RETURNING. Raise it only for a load-bearing capability.\nimport { mkdirSync, rmSync } from 'node:fs';\nimport { join } from 'node:path';\nimport { DatabaseSync } from 'node:sqlite';\nimport type { Config, ResolvedConfig } from '../config/index.ts';\nimport { contentTokenize, featureSignature, STATE_DIR } from '../config/index.ts';\nimport { SenseError } from '../errors.ts';\nimport { activeFeatures } from '../features/index.ts';\nimport { registerFunctions } from '../sql-functions.ts';\nimport { changedSignatureKeys, rebuildContentTable, reconcile, signatureDiff } from './reconcile.ts';\nimport { getMeta, setMeta } from './shared.ts';\n\nexport const DB_FILENAME = 'cache.db';\n// Cache shape version, independent of the config's own `version`. Bumping it rebuilds\n// existing trees on first query.\nexport const SCHEMA_VERSION = '16';\n\nexport interface OpenResult {\n db: DatabaseSync;\n cfg: ResolvedConfig;\n dbPath: string;\n parsed: number;\n warnings: string[];\n}\n\n// Stemming is English-only, but the segmentation underneath it is what decides coverage:\n// unicode61 splits on spaces, so a language written without them (Chinese, Japanese, Thai)\n// indexes a whole run as one token and word search finds nothing. `content.tokenize` is how\n// such a tree picks trigram instead.\nconst DEFAULT_TOKENIZE = 'porter unicode61';\n\n// FTS5 takes its tokenizer as a string literal inside DDL, where nothing can bind, so a\n// configured value has to be concatenated. Probing a throwaway table is what makes that safe\n// and is also the whole validation: anything the linked SQLite accepts passes, anything else\n// fails here with SQLite's own message rather than against the real table. It means no table\n// of which version added which tokenizer has to be maintained.\nfunction resolveTokenize(db: DatabaseSync, cfg: Config): string {\n const configured = contentTokenize(cfg);\n if (configured === undefined) return DEFAULT_TOKENIZE;\n const literal = configured.replace(/'/g, \"''\");\n try {\n db.exec('DROP TABLE IF EXISTS temp.sense_tokenize_probe');\n db.exec(`CREATE VIRTUAL TABLE temp.sense_tokenize_probe USING fts5(x, tokenize = '${literal}')`);\n db.exec('DROP TABLE IF EXISTS temp.sense_tokenize_probe');\n } catch (err) {\n throw new SenseError('CONFIG_INVALID', `content.tokenize \"${configured}\" is not a tokenizer this SQLite accepts (${(err as Error).message}); the built-in choices are unicode61, ascii, porter, and trigram, each with their own options`);\n }\n return literal;\n}\n\n// The tokenizer the content table was actually built with, from its own DDL -- the one\n// record that cannot desynchronize from the table. NULL when the table does not exist yet.\nfunction storedTokenize(db: DatabaseSync): string | null {\n const row = db.prepare(`SELECT sql FROM sqlite_master WHERE name = 'content'`).get() as { sql: string } | undefined;\n if (!row) return null;\n const m = row.sql.match(/tokenize = '((?:[^']|'')*)'/);\n return m ? m[1] : null;\n}\n\n// Content is a separate table (not a column on frontmatter) so `SELECT * FROM frontmatter`\n// can't dump file text into context. Features add their own tables after the core ones.\nfunction ensureSchema(db: DatabaseSync, cfg: Config, tokenize: string): void {\n db.exec(`CREATE TABLE IF NOT EXISTS frontmatter (\"path\" TEXT PRIMARY KEY, \"_mtime\" REAL, \"_ctime\" REAL, \"_size\" INTEGER, \"_parse_error\" TEXT)`);\n // IF NOT EXISTS is safe against a tokenizer change: open() compares the table's own DDL\n // against the resolved tokenizer before this runs, so a stale table is already gone by now.\n // The three `_seg` sidecars are appended after path, never inserted: bm25(content, ...) and\n // snippet(content, 2, ...) are documented against the first three columns and keep working\n // (FTS5 defaults the weights it was not given). Each carries its field's exploded unspaced\n // runs for text that needs it, and an empty string for text that does not.\n db.exec(`CREATE VIRTUAL TABLE IF NOT EXISTS content USING fts5(title, summary, text, path UNINDEXED, title_seg, summary_seg, text_seg, tokenize = '${tokenize}')`);\n // Coverage, not ownership: a path can appear under several presets. path leads the PK so the\n // per-doc delete is an index hit -- keyed the other way, cold builds went quadratic.\n db.exec(`CREATE TABLE IF NOT EXISTS preset_files (\"path\" TEXT, preset TEXT, PRIMARY KEY (\"path\", preset))`);\n db.exec('CREATE INDEX IF NOT EXISTS preset_files_preset ON preset_files(preset)');\n for (const feature of activeFeatures(cfg)) feature.schema(db);\n if (getMeta(db, 'schema_version') === null) setMeta(db, 'schema_version', SCHEMA_VERSION);\n if (getMeta(db, 'features') === null) setMeta(db, 'features', featureSignature(cfg));\n}\n\nexport function docCount(db: DatabaseSync): number {\n const row = db.prepare('SELECT COUNT(*) AS n FROM frontmatter').get() as { n: number };\n return row.n;\n}\n\nexport function open(cfg: ResolvedConfig): OpenResult {\n const stateDir = join(cfg.baseDir, STATE_DIR);\n mkdirSync(stateDir, { recursive: true });\n const dbPath = join(stateDir, DB_FILENAME);\n\n const db = new DatabaseSync(dbPath);\n db.exec('PRAGMA journal_mode = WAL');\n // Covers a concurrent watcher's bulk reconcile (~5s for 500 files at 26k notes). A query\n // that outwaits it still fails loudly.\n db.exec('PRAGMA busy_timeout = 30000');\n registerFunctions(db, contentTokenize(cfg) === undefined);\n\n db.exec('CREATE TABLE IF NOT EXISTS meta (key TEXT PRIMARY KEY, value TEXT)');\n\n // Before the rebuild branch below, never after: that branch deletes the cache, so a typo'd\n // tokenizer validated later would cost a full re-index (and re-embed) to reach its own error.\n const tokenize = resolveTokenize(db, cfg);\n\n // Schema-version or feature-set mismatch: reconcile only reparses changed files, so an\n // old cache can't be patched incrementally -- rebuild instead (cheap: nothing expensive lives here).\n const version = getMeta(db, 'schema_version');\n const features = getMeta(db, 'features');\n const wantFeatures = featureSignature(cfg);\n let tokenizeOnlyRebuild = false;\n if ((version !== null && version !== SCHEMA_VERSION) || (features !== null && features !== wantFeatures)) {\n // Indexing derives from presets, so a config edit rebuilding the cache must say so and\n // name what changed -- silent rebuilds make derived indexing look like a hang or a bug.\n if (version !== null && version !== SCHEMA_VERSION) {\n console.error('sense: cache format changed (new sensemaking version); rebuilding the index');\n db.close();\n clearCache(cfg);\n return open(cfg);\n }\n const changedKeys = changedSignatureKeys(features ?? '', wantFeatures);\n // Only the tokenizer moved: frontmatter, links, sections, and embeddings are file-derived\n // and tokenizer-independent, so they don't need re-deriving. Everything else -- a preset\n // edit, an embed model change -- still takes the full clear/reopen below.\n if (changedKeys.size === 1 && changedKeys.has('tokenize')) {\n console.error('sense: config change (content tokenizer) rebuilds the text index; vectors, links, and sections are kept');\n db.exec('DROP TABLE content');\n tokenizeOnlyRebuild = true;\n } else {\n const changed = signatureDiff(features ?? '', wantFeatures);\n console.error(`sense: config change (${changed}) rebuilds the index`);\n db.close();\n clearCache(cfg);\n return open(cfg);\n }\n }\n\n // Meta can lie after a crash between table creation and the signature write; the table's\n // own DDL cannot. A mismatch here rebuilds no matter what meta says. A tokenize-only rebuild\n // just dropped content above, so storedTokenize sees no table and this guard is skipped\n // naturally rather than needing its own case.\n const stored = storedTokenize(db);\n if (stored !== null && stored !== tokenize) {\n console.error('sense: cache was built with a different content tokenizer; rebuilding the index');\n db.close();\n clearCache(cfg);\n return open(cfg);\n }\n\n ensureSchema(db, cfg, tokenize);\n\n let rebuildWarnings: string[] = [];\n if (tokenizeOnlyRebuild) {\n rebuildWarnings = rebuildContentTable(db, cfg, cfg.baseDir);\n setMeta(db, 'features', wantFeatures);\n }\n\n // 3x the largest reconcile this cache has recorded, floored at 30s and capped at 10min.\n // Installed before reconcile() -- that call is the one that races a watcher's transaction.\n const recordedMaxMs = Number(getMeta(db, 'reconcile_max_ms') ?? '0');\n db.exec(`PRAGMA busy_timeout = ${Math.min(Math.max(30000, 3 * recordedMaxMs), 600_000)}`);\n\n const { parsed, warnings } = reconcile(db, cfg, cfg.baseDir);\n\n return { db, cfg, dbPath, parsed, warnings: [...rebuildWarnings, ...warnings] };\n}\n\n// Deletes the cache directory, and only that. The rebuild is not this function's job: the next\n// open() reconciles, which is what running any command already does, so a verb that bundled the\n// two described the half that was not its own. Manual reset for a doubted cache; the schema and\n// config-signature mismatches below reset themselves.\nexport function clearCache(cfg: ResolvedConfig): void {\n rmSync(join(cfg.baseDir, STATE_DIR), { recursive: true, force: true });\n}\n"],"names":["DB_FILENAME","SCHEMA_VERSION","clearCache","docCount","open","DEFAULT_TOKENIZE","resolveTokenize","db","cfg","configured","contentTokenize","undefined","literal","replace","exec","err","SenseError","message","storedTokenize","row","prepare","get","m","sql","match","ensureSchema","tokenize","activeFeatures","feature","schema","getMeta","setMeta","featureSignature","n","stateDir","join","baseDir","STATE_DIR","mkdirSync","recursive","dbPath","DatabaseSync","registerFunctions","version","features","wantFeatures","tokenizeOnlyRebuild","console","error","close","changedKeys","changedSignatureKeys","size","has","changed","signatureDiff","stored","rebuildWarnings","rebuildContentTable","recordedMaxMs","Number","Math","min","max","reconcile","parsed","warnings","rmSync","force"],"mappings":"AAAA,+FAA+F;AAC/F,iGAAiG;;;;;;;;;;;;QAYpFA;eAAAA;;QAGAC;eAAAA;;QAyJGC;eAAAA;;QAzFAC;eAAAA;;QAKAC;eAAAA;;;sBAnFkB;wBACb;0BACQ;uBAEgC;wBAClC;wBACI;8BACG;2BACkD;wBACnD;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE1B,IAAMJ,cAAc;AAGpB,IAAMC,iBAAiB;AAU9B,yFAAyF;AACzF,2FAA2F;AAC3F,4FAA4F;AAC5F,qCAAqC;AACrC,IAAMI,mBAAmB;AAEzB,wFAAwF;AACxF,6FAA6F;AAC7F,6FAA6F;AAC7F,6FAA6F;AAC7F,+DAA+D;AAC/D,SAASC,gBAAgBC,EAAgB,EAAEC,GAAW;IACpD,IAAMC,aAAaC,IAAAA,wBAAe,EAACF;IACnC,IAAIC,eAAeE,WAAW,OAAON;IACrC,IAAMO,UAAUH,WAAWI,OAAO,CAAC,MAAM;IACzC,IAAI;QACFN,GAAGO,IAAI,CAAC;QACRP,GAAGO,IAAI,CAAC,AAAC,4EAAmF,OAARF,SAAQ;QAC5FL,GAAGO,IAAI,CAAC;IACV,EAAE,OAAOC,KAAK;QACZ,MAAM,IAAIC,oBAAU,CAAC,kBAAkB,AAAC,qBAA2E,OAAvDP,YAAW,8CAAmE,OAAvB,AAACM,IAAcE,OAAO,EAAC;IAC5I;IACA,OAAOL;AACT;AAEA,uFAAuF;AACvF,2FAA2F;AAC3F,SAASM,eAAeX,EAAgB;IACtC,IAAMY,MAAMZ,GAAGa,OAAO,CAAC,wDAAwDC,GAAG;IAClF,IAAI,CAACF,KAAK,OAAO;IACjB,IAAMG,IAAIH,IAAII,GAAG,CAACC,KAAK,CAAC;IACxB,OAAOF,IAAIA,CAAC,CAAC,EAAE,GAAG;AACpB;AAEA,2F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;QACX,OAAOJ,KAAKI;IACd;IAEAiB,aAAalB,IAAIC,KAAKkB;IAEtB,IAAI+B,kBAA4B,EAAE;IAClC,IAAIX,qBAAqB;QACvBW,kBAAkBC,IAAAA,gCAAmB,EAACnD,IAAIC,KAAKA,IAAI4B,OAAO;QAC1DL,IAAAA,iBAAO,EAACxB,IAAI,YAAYsC;IAC1B;IAEA,wFAAwF;IACxF,2FAA2F;IAC3F,IAAMc,gBAAgBC,QAAO9B,WAAAA,IAAAA,iBAAO,EAACvB,IAAI,iCAAZuB,sBAAAA,WAAmC;IAChEvB,GAAGO,IAAI,CAAC,AAAC,yBAA8E,OAAtD+C,KAAKC,GAAG,CAACD,KAAKE,GAAG,CAAC,OAAO,IAAIJ,gBAAgB;IAE9E,IAA6BK,aAAAA,IAAAA,sBAAS,EAACzD,IAAIC,KAAKA,IAAI4B,OAAO,GAAnD6B,SAAqBD,WAArBC,QAAQC,WAAaF,WAAbE;IAEhB,OAAO;QAAE3D,IAAAA;QAAIC,KAAAA;QAAKgC,QAAAA;QAAQyB,QAAAA;QAAQC,UAAU,AAAC,qBAAGT,wBAAiB,qBAAGS;IAAU;AAChF;AAMO,SAAShE,WAAWM,GAAmB;IAC5C2D,IAAAA,cAAM,EAAChC,IAAAA,cAAI,EAAC3B,IAAI4B,OAAO,EAAEC,kBAAS,GAAG;QAAEE,WAAW;QAAM6B,OAAO;IAAK;AACtE"}
@@ -41,7 +41,9 @@ function _array_without_holes(arr) {
41
41
  if (Array.isArray(arr)) return _array_like_to_array(arr);
42
42
  }
43
43
  function _iterable_to_array(iter) {
44
- if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
44
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) {
45
+ return Array.from(iter);
46
+ }
45
47
  }
46
48
  function _iterable_to_array_limit(arr, i) {
47
49
  var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
@@ -68,10 +70,10 @@ function _iterable_to_array_limit(arr, i) {
68
70
  return _arr;
69
71
  }
70
72
  function _non_iterable_rest() {
71
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
73
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
72
74
  }
73
75
  function _non_iterable_spread() {
74
- throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
76
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
75
77
  }
76
78
  function _sliced_to_array(arr, i) {
77
79
  return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();