sensemaking 0.11.5 → 0.12.1

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 (87) hide show
  1. package/README.md +4 -3
  2. package/bin/cli.js +5 -2
  3. package/dist/cjs/cli/index.d.cts +3 -3
  4. package/dist/cjs/cli/index.d.ts +3 -3
  5. package/dist/cjs/cli/index.js +3 -3
  6. package/dist/cjs/cli/index.js.map +1 -1
  7. package/dist/cjs/cli/named.js +2 -2
  8. package/dist/cjs/cli/named.js.map +1 -1
  9. package/dist/cjs/cli/related.js +1 -1
  10. package/dist/cjs/cli/related.js.map +1 -1
  11. package/dist/cjs/cli/search.js +1 -1
  12. package/dist/cjs/cli/search.js.map +1 -1
  13. package/dist/cjs/cli/shared.d.cts +3 -1
  14. package/dist/cjs/cli/shared.d.ts +3 -1
  15. package/dist/cjs/cli/shared.js +35 -5
  16. package/dist/cjs/cli/shared.js.map +1 -1
  17. package/dist/cjs/cli/sql.js +1 -1
  18. package/dist/cjs/cli/sql.js.map +1 -1
  19. package/dist/cjs/cli.js +14 -1
  20. package/dist/cjs/cli.js.map +1 -1
  21. package/dist/cjs/commands.d.cts +1 -0
  22. package/dist/cjs/commands.d.ts +1 -0
  23. package/dist/cjs/commands.js +72 -46
  24. package/dist/cjs/commands.js.map +1 -1
  25. package/dist/cjs/config.d.cts +4 -0
  26. package/dist/cjs/config.d.ts +4 -0
  27. package/dist/cjs/config.js +39 -4
  28. package/dist/cjs/config.js.map +1 -1
  29. package/dist/cjs/db.d.cts +1 -1
  30. package/dist/cjs/db.d.ts +1 -1
  31. package/dist/cjs/db.js +158 -14
  32. package/dist/cjs/db.js.map +1 -1
  33. package/dist/cjs/features/embed.d.cts +1 -1
  34. package/dist/cjs/features/embed.d.ts +1 -1
  35. package/dist/cjs/features/embed.js +2 -1
  36. package/dist/cjs/features/embed.js.map +1 -1
  37. package/dist/cjs/index.d.cts +1 -1
  38. package/dist/cjs/index.d.ts +1 -1
  39. package/dist/cjs/index.js.map +1 -1
  40. package/dist/cjs/output.d.cts +5 -1
  41. package/dist/cjs/output.d.ts +5 -1
  42. package/dist/cjs/output.js +161 -7
  43. package/dist/cjs/output.js.map +1 -1
  44. package/dist/cjs/segment.d.cts +2 -0
  45. package/dist/cjs/segment.d.ts +2 -0
  46. package/dist/cjs/segment.js +98 -0
  47. package/dist/cjs/segment.js.map +1 -0
  48. package/dist/esm/cli/index.d.ts +3 -3
  49. package/dist/esm/cli/index.js +3 -3
  50. package/dist/esm/cli/index.js.map +1 -1
  51. package/dist/esm/cli/named.js +3 -3
  52. package/dist/esm/cli/named.js.map +1 -1
  53. package/dist/esm/cli/related.js +2 -2
  54. package/dist/esm/cli/related.js.map +1 -1
  55. package/dist/esm/cli/search.js +2 -2
  56. package/dist/esm/cli/search.js.map +1 -1
  57. package/dist/esm/cli/shared.d.ts +3 -1
  58. package/dist/esm/cli/shared.js +32 -5
  59. package/dist/esm/cli/shared.js.map +1 -1
  60. package/dist/esm/cli/sql.js +2 -2
  61. package/dist/esm/cli/sql.js.map +1 -1
  62. package/dist/esm/cli.js +14 -1
  63. package/dist/esm/cli.js.map +1 -1
  64. package/dist/esm/commands.d.ts +1 -0
  65. package/dist/esm/commands.js +75 -38
  66. package/dist/esm/commands.js.map +1 -1
  67. package/dist/esm/config.d.ts +4 -0
  68. package/dist/esm/config.js +37 -4
  69. package/dist/esm/config.js.map +1 -1
  70. package/dist/esm/db.d.ts +1 -1
  71. package/dist/esm/db.js +140 -15
  72. package/dist/esm/db.js.map +1 -1
  73. package/dist/esm/features/embed.d.ts +1 -1
  74. package/dist/esm/features/embed.js +2 -1
  75. package/dist/esm/features/embed.js.map +1 -1
  76. package/dist/esm/index.d.ts +1 -1
  77. package/dist/esm/index.js.map +1 -1
  78. package/dist/esm/output.d.ts +5 -1
  79. package/dist/esm/output.js +107 -5
  80. package/dist/esm/output.js.map +1 -1
  81. package/dist/esm/segment.d.ts +2 -0
  82. package/dist/esm/segment.js +65 -0
  83. package/dist/esm/segment.js.map +1 -0
  84. package/package.json +4 -1
  85. package/schema.json +12 -1
  86. package/skills/sense/SKILL.md +6 -5
  87. package/skills/sense-setup/SKILL.md +1 -0
@@ -1,6 +1,7 @@
1
1
  import type { ParseArgsOptionsConfig } from 'node:util';
2
2
  import type { ResolvedConfig, SearchOverrides } from '../config.js';
3
3
  import type { OpenResult } from '../db.js';
4
+ import type { RowFormat } from '../output.js';
4
5
  import type { Ctx } from './types.js';
5
6
  export declare const FORMAT: ParseArgsOptionsConfig;
6
7
  export declare const CONFIG: ParseArgsOptionsConfig;
@@ -9,6 +10,7 @@ export declare const SEARCH_FLAGS: ParseArgsOptionsConfig;
9
10
  type Values = Record<string, string | boolean | string[] | undefined>;
10
11
  export declare function scopeOf(values: Values): SearchOverrides;
11
12
  export declare function formatOf(values: Values): 'table' | 'json';
13
+ export declare function rowFormatOf(values: Values): RowFormat;
12
14
  export declare function parse(argv: string[], usage: string, options: ParseArgsOptionsConfig): {
13
15
  values: Values;
14
16
  positionals: string[];
@@ -16,5 +18,5 @@ export declare function parse(argv: string[], usage: string, options: ParseArgsO
16
18
  export declare function parseK(k: string | undefined, usageError: (message: string) => never): number | undefined;
17
19
  export declare function printWarnings(warnings: string[]): void;
18
20
  export declare function withDb(ctx: Ctx, configPath: string | undefined, fn: (db: OpenResult['db'], cfg: ResolvedConfig) => void | Promise<void>): Promise<void>;
19
- export declare function runSql(cfg: ResolvedConfig, sql: string, params: string[], format: 'table' | 'json', label: string, preset?: string): void;
21
+ export declare function runSql(cfg: ResolvedConfig, sql: string, params: string[], format: RowFormat, label: string, preset?: string): void;
20
22
  export {};
@@ -1,7 +1,7 @@
1
1
  import { parseArgs } from 'node:util';
2
2
  import { resolvePreset } from '../config.js';
3
3
  import { open } from '../db.js';
4
- import { printRows } from '../output.js';
4
+ import { printRowStream } from '../output.js';
5
5
  import { searchError } from '../search-error.js';
6
6
  // Spreadable option fragments -- one flag name keeps one meaning across every command's table.
7
7
  export const FORMAT = {
@@ -57,8 +57,28 @@ export function scopeOf(values) {
57
57
  noExclude: values['no-exclude'] === true
58
58
  };
59
59
  }
60
+ // An unrecognised value used to fall through to `table`, so a typo looked like it worked.
61
+ // parseArgs is strict about flag names; this is the same strictness for the value.
62
+ function pickFormat(values, allowed) {
63
+ const format = String(values.format);
64
+ if (allowed.includes(format)) return format;
65
+ console.error(`unknown --format "${format}"; expected ${allowed.join(', ')}`);
66
+ process.exit(2);
67
+ }
60
68
  export function formatOf(values) {
61
- return values.format === 'json' ? 'json' : 'table';
69
+ return pickFormat(values, [
70
+ 'table',
71
+ 'json'
72
+ ]);
73
+ }
74
+ // csv is a row set rendered as rows; map, peek, status, and path render structures instead,
75
+ // and take formatOf.
76
+ export function rowFormatOf(values) {
77
+ return pickFormat(values, [
78
+ 'table',
79
+ 'json',
80
+ 'csv'
81
+ ]);
62
82
  }
63
83
  // Per-command parseArgs: strict (a foreign flag exits 2), and every table gets --help for free.
64
84
  export function parse(argv, usage, options) {
@@ -144,9 +164,17 @@ export function runSql(cfg, sql, params, format, label, preset) {
144
164
  const { db, warnings } = open(cfg);
145
165
  printWarnings(warnings);
146
166
  if (preset !== undefined) bindScope(db, cfg, preset);
147
- let rows;
167
+ // Streamed rather than collected: `sql` is the one caller whose result size is the
168
+ // statement's business, not this package's, so the rows are never held here in bulk.
169
+ // columns() reads the statement's own metadata, so a 0-row csv still has its header.
170
+ // A mid-stream SQLite error (e.g. SQLITE_BUSY outlasting busy_timeout) can still leave
171
+ // partial output; the nonzero exit code is the caller's signal, output completeness is not
172
+ // guaranteed on failure.
148
173
  try {
149
- rows = db.prepare(sql).all(...params);
174
+ const statement = db.prepare(sql);
175
+ statement.setReadBigInts(true); // int64 past 2^53 arrives as BigInt instead of throwing at step time
176
+ const columns = statement.columns().map((c)=>c.name);
177
+ printRowStream(statement.iterate(...params), format, columns);
150
178
  } catch (err) {
151
179
  db.close();
152
180
  // A saved query or ad-hoc SQL can carry `content MATCH ?` too, so the same FTS5
@@ -155,6 +183,5 @@ export function runSql(cfg, sql, params, format, label, preset) {
155
183
  if (/\bMATCH\b/i.test(sql)) throw searchError(err, params.join(' '));
156
184
  throw err;
157
185
  }
158
- printRows(rows, format);
159
186
  db.close();
160
187
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/cli/shared.ts"],"sourcesContent":["import type { ParseArgsOptionsConfig } from 'node:util';\nimport { parseArgs } from 'node:util';\nimport type { ResolvedConfig, SearchOverrides } from '../config.ts';\nimport { resolvePreset } from '../config.ts';\nimport type { OpenResult } from '../db.ts';\nimport { open } from '../db.ts';\nimport type { Row } from '../output.ts';\nimport { printRows } from '../output.ts';\nimport { searchError } from '../search-error.ts';\nimport type { Ctx } from './types.ts';\n\n// Spreadable option fragments -- one flag name keeps one meaning across every command's table.\nexport const FORMAT: ParseArgsOptionsConfig = { format: { type: 'string', default: 'table' } };\nexport const CONFIG: ParseArgsOptionsConfig = { config: { type: 'string' } };\n// The scope vocabulary every scoped command shares: named preset, ad hoc include/exclude\n// globs, a where SQL condition. search adds k on top.\nexport const SCOPE: ParseArgsOptionsConfig = {\n where: { type: 'string' },\n preset: { type: 'string' },\n include: { type: 'string', multiple: true },\n exclude: { type: 'string', multiple: true },\n // Widening, which no other flag can express: --include and --exclude each override their\n // own side of the preset, so neither can drop an exclusion the preset declares.\n 'no-exclude': { type: 'boolean', default: false },\n};\nexport const SEARCH_FLAGS: ParseArgsOptionsConfig = { ...SCOPE, k: { type: 'string' } };\n\ntype Values = Record<string, string | boolean | string[] | undefined>;\n\n// The SCOPE fragment's parsed values as the overrides every scoped command passes down. One\n// place to read them, so a new scope field is added to the fragment and here, not in each\n// command's call.\nexport function scopeOf(values: Values): SearchOverrides {\n return {\n preset: values.preset as string | undefined,\n include: values.include as string[] | undefined,\n exclude: values.exclude as string[] | undefined,\n where: values.where as string | undefined,\n noExclude: values['no-exclude'] === true,\n };\n}\n\nexport function formatOf(values: Values): 'table' | 'json' {\n return values.format === 'json' ? 'json' : 'table';\n}\n\n// Per-command parseArgs: strict (a foreign flag exits 2), and every table gets --help for free.\nexport function parse(argv: string[], usage: string, options: ParseArgsOptionsConfig): { values: Values; positionals: string[] } {\n let values: Values;\n let positionals: string[];\n try {\n ({ values, positionals } = parseArgs({\n args: argv,\n options: { ...options, help: { type: 'boolean', default: false, short: 'h' } },\n strict: true,\n allowPositionals: true,\n }));\n } catch (err) {\n console.error((err as Error).message);\n console.error(usage);\n process.exit(2);\n }\n if (values.help) {\n console.log(usage);\n process.exit(0);\n }\n return { values, positionals };\n}\n\n// --k must be a positive integer: SQLite reads a bound LIMIT of -1 as \"unlimited\" and 0 as\n// \"nothing\", and parseInt would silently truncate \"5.9\" -- all three are caller mistakes\n// worth a usage error, matching the config-level SavedSearch validation.\nexport function parseK(k: string | undefined, usageError: (message: string) => never): number | undefined {\n if (k === undefined) return undefined;\n const parsed = Number(k);\n if (!Number.isInteger(parsed) || parsed <= 0) usageError(`--k expects a positive integer, got \"${k}\"`);\n return parsed;\n}\n\n// Shared open-query-close envelope for commands that touch the tree.\n\nexport function printWarnings(warnings: string[]): void {\n for (const w of warnings) console.warn(w);\n}\n\nexport async function withDb(ctx: Ctx, configPath: string | undefined, fn: (db: OpenResult['db'], cfg: ResolvedConfig) => void | Promise<void>): Promise<void> {\n const cfg = ctx.resolveConfig(configPath);\n const { db, warnings } = open(cfg);\n printWarnings(warnings);\n try {\n await fn(db, cfg);\n } finally {\n db.close();\n }\n}\n\n// `--preset` on SQL binds the scope rather than applying it: the statement joins `scope`\n// itself. Filtering behind the query's back is not available -- the obvious version, temp views\n// shadowing the base tables, cannot cover `content`, because FTS5 `MATCH` uses the table name\n// as a hidden column and a view has none. A flag that silently scoped three tables of four\n// would look scoped and not be. See plans/vault-field-report-fixes.md item F.\nfunction bindScope(db: OpenResult['db'], cfg: ResolvedConfig, preset: string): void {\n const { name } = resolvePreset(cfg, preset); // unknown names throw, listing what is declared\n db.exec('DROP TABLE IF EXISTS temp.scope');\n db.exec('CREATE TEMP TABLE scope (\"path\" TEXT PRIMARY KEY)');\n db.prepare('INSERT INTO temp.scope (\"path\") SELECT \"path\" FROM preset_files WHERE preset = ?').run(name);\n}\n\n// An unbound `?` silently binds NULL, so mismatched param counts fail loudly instead.\nexport function runSql(cfg: ResolvedConfig, sql: string, params: string[], format: 'table' | 'json', label: string, preset?: string): void {\n const placeholderCount = (sql.match(/\\?/g) ?? []).length;\n if (params.length !== placeholderCount) {\n console.error(`${label} expects ${placeholderCount} parameter(s), got ${params.length}`);\n process.exit(2);\n }\n // Naming a preset and never joining it would return the whole index while reading as scoped,\n // which is the one hazard of binding rather than applying. Refuse instead.\n if (preset !== undefined && !/\\bscope\\b/i.test(sql)) {\n console.error(`--preset binds a temporary \"scope\" table of the preset's paths, and ${label} never joins it, so the preset would have no effect`);\n console.error(`add: JOIN scope ON scope.\"path\" = <table>.\"path\"`);\n process.exit(2);\n }\n const { db, warnings } = open(cfg);\n printWarnings(warnings);\n if (preset !== undefined) bindScope(db, cfg, preset);\n let rows: Row[];\n try {\n rows = db.prepare(sql).all(...params) as Row[];\n } catch (err) {\n db.close();\n // A saved query or ad-hoc SQL can carry `content MATCH ?` too, so the same FTS5\n // punctuation trap applies -- the bound parameters are the search terms there. SQL\n // without MATCH gets its error verbatim; search advice on a plain typo would mislead.\n if (/\\bMATCH\\b/i.test(sql)) throw searchError(err as Error, params.join(' '));\n throw err;\n }\n printRows(rows, format);\n db.close();\n}\n"],"names":["parseArgs","resolvePreset","open","printRows","searchError","FORMAT","format","type","default","CONFIG","config","SCOPE","where","preset","include","multiple","exclude","SEARCH_FLAGS","k","scopeOf","values","noExclude","formatOf","parse","argv","usage","options","positionals","args","help","short","strict","allowPositionals","err","console","error","message","process","exit","log","parseK","usageError","undefined","parsed","Number","isInteger","printWarnings","warnings","w","warn","withDb","ctx","configPath","fn","cfg","resolveConfig","db","close","bindScope","name","exec","prepare","run","runSql","sql","params","label","placeholderCount","match","length","test","rows","all","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BkD,GAAGC,KAAK;AACV"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/cli/shared.ts"],"sourcesContent":["import type { ParseArgsOptionsConfig } from 'node:util';\nimport { parseArgs } from 'node:util';\nimport type { ResolvedConfig, SearchOverrides } from '../config.ts';\nimport { resolvePreset } from '../config.ts';\nimport type { OpenResult } from '../db.ts';\nimport { open } from '../db.ts';\nimport type { Row, RowFormat } from '../output.ts';\nimport { printRowStream } from '../output.ts';\nimport { searchError } from '../search-error.ts';\nimport type { Ctx } from './types.ts';\n\n// Spreadable option fragments -- one flag name keeps one meaning across every command's table.\nexport const FORMAT: ParseArgsOptionsConfig = { format: { type: 'string', default: 'table' } };\nexport const CONFIG: ParseArgsOptionsConfig = { config: { type: 'string' } };\n// The scope vocabulary every scoped command shares: named preset, ad hoc include/exclude\n// globs, a where SQL condition. search adds k on top.\nexport const SCOPE: ParseArgsOptionsConfig = {\n where: { type: 'string' },\n preset: { type: 'string' },\n include: { type: 'string', multiple: true },\n exclude: { type: 'string', multiple: true },\n // Widening, which no other flag can express: --include and --exclude each override their\n // own side of the preset, so neither can drop an exclusion the preset declares.\n 'no-exclude': { type: 'boolean', default: false },\n};\nexport const SEARCH_FLAGS: ParseArgsOptionsConfig = { ...SCOPE, k: { type: 'string' } };\n\ntype Values = Record<string, string | boolean | string[] | undefined>;\n\n// The SCOPE fragment's parsed values as the overrides every scoped command passes down. One\n// place to read them, so a new scope field is added to the fragment and here, not in each\n// command's call.\nexport function scopeOf(values: Values): SearchOverrides {\n return {\n preset: values.preset as string | undefined,\n include: values.include as string[] | undefined,\n exclude: values.exclude as string[] | undefined,\n where: values.where as string | undefined,\n noExclude: values['no-exclude'] === true,\n };\n}\n\n// An unrecognised value used to fall through to `table`, so a typo looked like it worked.\n// parseArgs is strict about flag names; this is the same strictness for the value.\nfunction pickFormat<T extends string>(values: Values, allowed: readonly T[]): T {\n const format = String(values.format);\n if ((allowed as readonly string[]).includes(format)) return format as T;\n console.error(`unknown --format \"${format}\"; expected ${allowed.join(', ')}`);\n process.exit(2);\n}\n\nexport function formatOf(values: Values): 'table' | 'json' {\n return pickFormat(values, ['table', 'json'] as const);\n}\n\n// csv is a row set rendered as rows; map, peek, status, and path render structures instead,\n// and take formatOf.\nexport function rowFormatOf(values: Values): RowFormat {\n return pickFormat(values, ['table', 'json', 'csv'] as const);\n}\n\n// Per-command parseArgs: strict (a foreign flag exits 2), and every table gets --help for free.\nexport function parse(argv: string[], usage: string, options: ParseArgsOptionsConfig): { values: Values; positionals: string[] } {\n let values: Values;\n let positionals: string[];\n try {\n ({ values, positionals } = parseArgs({\n args: argv,\n options: { ...options, help: { type: 'boolean', default: false, short: 'h' } },\n strict: true,\n allowPositionals: true,\n }));\n } catch (err) {\n console.error((err as Error).message);\n console.error(usage);\n process.exit(2);\n }\n if (values.help) {\n console.log(usage);\n process.exit(0);\n }\n return { values, positionals };\n}\n\n// --k must be a positive integer: SQLite reads a bound LIMIT of -1 as \"unlimited\" and 0 as\n// \"nothing\", and parseInt would silently truncate \"5.9\" -- all three are caller mistakes\n// worth a usage error, matching the config-level SavedSearch validation.\nexport function parseK(k: string | undefined, usageError: (message: string) => never): number | undefined {\n if (k === undefined) return undefined;\n const parsed = Number(k);\n if (!Number.isInteger(parsed) || parsed <= 0) usageError(`--k expects a positive integer, got \"${k}\"`);\n return parsed;\n}\n\n// Shared open-query-close envelope for commands that touch the tree.\n\nexport function printWarnings(warnings: string[]): void {\n for (const w of warnings) console.warn(w);\n}\n\nexport async function withDb(ctx: Ctx, configPath: string | undefined, fn: (db: OpenResult['db'], cfg: ResolvedConfig) => void | Promise<void>): Promise<void> {\n const cfg = ctx.resolveConfig(configPath);\n const { db, warnings } = open(cfg);\n printWarnings(warnings);\n try {\n await fn(db, cfg);\n } finally {\n db.close();\n }\n}\n\n// `--preset` on SQL binds the scope rather than applying it: the statement joins `scope`\n// itself. Filtering behind the query's back is not available -- the obvious version, temp views\n// shadowing the base tables, cannot cover `content`, because FTS5 `MATCH` uses the table name\n// as a hidden column and a view has none. A flag that silently scoped three tables of four\n// would look scoped and not be. See plans/vault-field-report-fixes.md item F.\nfunction bindScope(db: OpenResult['db'], cfg: ResolvedConfig, preset: string): void {\n const { name } = resolvePreset(cfg, preset); // unknown names throw, listing what is declared\n db.exec('DROP TABLE IF EXISTS temp.scope');\n db.exec('CREATE TEMP TABLE scope (\"path\" TEXT PRIMARY KEY)');\n db.prepare('INSERT INTO temp.scope (\"path\") SELECT \"path\" FROM preset_files WHERE preset = ?').run(name);\n}\n\n// An unbound `?` silently binds NULL, so mismatched param counts fail loudly instead.\nexport function runSql(cfg: ResolvedConfig, sql: string, params: string[], format: RowFormat, label: string, preset?: string): void {\n const placeholderCount = (sql.match(/\\?/g) ?? []).length;\n if (params.length !== placeholderCount) {\n console.error(`${label} expects ${placeholderCount} parameter(s), got ${params.length}`);\n process.exit(2);\n }\n // Naming a preset and never joining it would return the whole index while reading as scoped,\n // which is the one hazard of binding rather than applying. Refuse instead.\n if (preset !== undefined && !/\\bscope\\b/i.test(sql)) {\n console.error(`--preset binds a temporary \"scope\" table of the preset's paths, and ${label} never joins it, so the preset would have no effect`);\n console.error(`add: JOIN scope ON scope.\"path\" = <table>.\"path\"`);\n process.exit(2);\n }\n const { db, warnings } = open(cfg);\n printWarnings(warnings);\n if (preset !== undefined) bindScope(db, cfg, preset);\n // Streamed rather than collected: `sql` is the one caller whose result size is the\n // statement's business, not this package's, so the rows are never held here in bulk.\n // columns() reads the statement's own metadata, so a 0-row csv still has its header.\n // A mid-stream SQLite error (e.g. SQLITE_BUSY outlasting busy_timeout) can still leave\n // partial output; the nonzero exit code is the caller's signal, output completeness is not\n // guaranteed on failure.\n try {\n const statement = db.prepare(sql);\n statement.setReadBigInts(true); // int64 past 2^53 arrives as BigInt instead of throwing at step time\n const columns = statement.columns().map((c) => c.name);\n printRowStream(statement.iterate(...params) as Iterable<Row>, format, columns);\n } catch (err) {\n db.close();\n // A saved query or ad-hoc SQL can carry `content MATCH ?` too, so the same FTS5\n // punctuation trap applies -- the bound parameters are the search terms there. SQL\n // without MATCH gets its error verbatim; search advice on a plain typo would mislead.\n if (/\\bMATCH\\b/i.test(sql)) throw searchError(err as Error, params.join(' '));\n throw err;\n }\n db.close();\n}\n"],"names":["parseArgs","resolvePreset","open","printRowStream","searchError","FORMAT","format","type","default","CONFIG","config","SCOPE","where","preset","include","multiple","exclude","SEARCH_FLAGS","k","scopeOf","values","noExclude","pickFormat","allowed","String","includes","console","error","join","process","exit","formatOf","rowFormatOf","parse","argv","usage","options","positionals","args","help","short","strict","allowPositionals","err","message","log","parseK","usageError","undefined","parsed","Number","isInteger","printWarnings","warnings","w","warn","withDb","ctx","configPath","fn","cfg","resolveConfig","db","close","bindScope","name","exec","prepare","run","runSql","sql","params","label","placeholderCount","match","length","test","statement","setReadBigInts","columns","map","c","iterate"],"mappings":"AACA,SAASA,SAAS,QAAQ,YAAY;AAEtC,SAASC,aAAa,QAAQ,eAAe;AAE7C,SAASC,IAAI,QAAQ,WAAW;AAEhC,SAASC,cAAc,QAAQ,eAAe;AAC9C,SAASC,WAAW,QAAQ,qBAAqB;AAGjD,+FAA+F;AAC/F,OAAO,MAAMC,SAAiC;IAAEC,QAAQ;QAAEC,MAAM;QAAUC,SAAS;IAAQ;AAAE,EAAE;AAC/F,OAAO,MAAMC,SAAiC;IAAEC,QAAQ;QAAEH,MAAM;IAAS;AAAE,EAAE;AAC7E,yFAAyF;AACzF,sDAAsD;AACtD,OAAO,MAAMI,QAAgC;IAC3CC,OAAO;QAAEL,MAAM;IAAS;IACxBM,QAAQ;QAAEN,MAAM;IAAS;IACzBO,SAAS;QAAEP,MAAM;QAAUQ,UAAU;IAAK;IAC1CC,SAAS;QAAET,MAAM;QAAUQ,UAAU;IAAK;IAC1C,yFAAyF;IACzF,gFAAgF;IAChF,cAAc;QAAER,MAAM;QAAWC,SAAS;IAAM;AAClD,EAAE;AACF,OAAO,MAAMS,eAAuC;IAAE,GAAGN,KAA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  import { USAGE } from './index.js';
2
- import { CONFIG, FORMAT, formatOf, parse, runSql } from './shared.js';
2
+ import { CONFIG, FORMAT, parse, rowFormatOf, runSql } from './shared.js';
3
3
  const sqlCmd = (ctx)=>{
4
4
  const usage = `usage: ${ctx.name} ${USAGE.sql}`;
5
5
  const { values, positionals } = parse(ctx.argv, usage, {
@@ -11,7 +11,7 @@ const sqlCmd = (ctx)=>{
11
11
  });
12
12
  const [sql, ...params] = positionals;
13
13
  if (!sql) ctx.usageError(usage);
14
- const format = formatOf(values);
14
+ const format = rowFormatOf(values);
15
15
  runSql(ctx.resolveConfig(values.config), sql, params, format, 'ad-hoc statement', values.preset);
16
16
  };
17
17
  export default sqlCmd;
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/cli/sql.ts"],"sourcesContent":["import { USAGE } from './index.ts';\nimport { CONFIG, FORMAT, formatOf, parse, runSql } from './shared.ts';\nimport type { Command } from './types.ts';\n\nconst sqlCmd: Command = (ctx) => {\n const usage = `usage: ${ctx.name} ${USAGE.sql}`;\n const { values, positionals } = parse(ctx.argv, usage, { ...FORMAT, ...CONFIG, preset: { type: 'string' } });\n const [sql, ...params] = positionals;\n if (!sql) ctx.usageError(usage);\n const format = formatOf(values);\n runSql(ctx.resolveConfig(values.config as string | undefined), sql, params, format, 'ad-hoc statement', values.preset as string | undefined);\n};\nexport default sqlCmd;\n"],"names":["USAGE","CONFIG","FORMAT","formatOf","parse","runSql","sqlCmd","ctx","usage","name","sql","values","positionals","argv","preset","type","params","usageError","format","resolveConfig","config"],"mappings":"AAAA,SAASA,KAAK,QAAQ,aAAa;AACnC,SAASC,MAAM,EAAEC,MAAM,EAAEC,QAAQ,EAAEC,KAAK,EAAEC,MAAM,QAAQ,cAAc;AAGtE,MAAMC,SAAkB,CAACC;IACvB,MAAMC,QAAQ,CAAC,OAAO,EAAED,IAAIE,IAAI,CAAC,CAAC,EAAET,MAAMU,GAAG,EAAE;IAC/C,MAAM,EAAEC,MAAM,EAAEC,WAAW,EAAE,GAAGR,MAAMG,IAAIM,IAAI,EAAEL,OAAO;QAAE,GAAGN,MAAM;QAAE,GAAGD,MAAM;QAAEa,QAAQ;YAAEC,MAAM;QAAS;IAAE;IAC1G,MAAM,CAACL,KAAK,GAAGM,OAAO,GAAGJ;IACzB,IAAI,CAACF,KAAKH,IAAIU,UAAU,CAACT;IACzB,MAAMU,SAASf,SAASQ;IACxBN,OAAOE,IAAIY,aAAa,CAACR,OAAOS,MAAM,GAAyBV,KAAKM,QAAQE,QAAQ,oBAAoBP,OAAOG,MAAM;AACvH;AACA,eAAeR,OAAO"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/cli/sql.ts"],"sourcesContent":["import { USAGE } from './index.ts';\nimport { CONFIG, FORMAT, parse, rowFormatOf, runSql } from './shared.ts';\nimport type { Command } from './types.ts';\n\nconst sqlCmd: Command = (ctx) => {\n const usage = `usage: ${ctx.name} ${USAGE.sql}`;\n const { values, positionals } = parse(ctx.argv, usage, { ...FORMAT, ...CONFIG, preset: { type: 'string' } });\n const [sql, ...params] = positionals;\n if (!sql) ctx.usageError(usage);\n const format = rowFormatOf(values);\n runSql(ctx.resolveConfig(values.config as string | undefined), sql, params, format, 'ad-hoc statement', values.preset as string | undefined);\n};\nexport default sqlCmd;\n"],"names":["USAGE","CONFIG","FORMAT","parse","rowFormatOf","runSql","sqlCmd","ctx","usage","name","sql","values","positionals","argv","preset","type","params","usageError","format","resolveConfig","config"],"mappings":"AAAA,SAASA,KAAK,QAAQ,aAAa;AACnC,SAASC,MAAM,EAAEC,MAAM,EAAEC,KAAK,EAAEC,WAAW,EAAEC,MAAM,QAAQ,cAAc;AAGzE,MAAMC,SAAkB,CAACC;IACvB,MAAMC,QAAQ,CAAC,OAAO,EAAED,IAAIE,IAAI,CAAC,CAAC,EAAET,MAAMU,GAAG,EAAE;IAC/C,MAAM,EAAEC,MAAM,EAAEC,WAAW,EAAE,GAAGT,MAAMI,IAAIM,IAAI,EAAEL,OAAO;QAAE,GAAGN,MAAM;QAAE,GAAGD,MAAM;QAAEa,QAAQ;YAAEC,MAAM;QAAS;IAAE;IAC1G,MAAM,CAACL,KAAK,GAAGM,OAAO,GAAGJ;IACzB,IAAI,CAACF,KAAKH,IAAIU,UAAU,CAACT;IACzB,MAAMU,SAASd,YAAYO;IAC3BN,OAAOE,IAAIY,aAAa,CAACR,OAAOS,MAAM,GAAyBV,KAAKM,QAAQE,QAAQ,oBAAoBP,OAAOG,MAAM;AACvH;AACA,eAAeR,OAAO"}
package/dist/esm/cli.js CHANGED
@@ -22,7 +22,7 @@ function packageVersion() {
22
22
  function usage(name) {
23
23
  const lines = Object.values(USAGE).map((u)=>` ${name} ${u}`);
24
24
  return [
25
- `usage: ${name} <name> [params...] [--format table|json] [--config path]`,
25
+ `usage: ${name} <name> [params...] [--format table|json|csv] [--config path]`,
26
26
  ...lines,
27
27
  ` ${name} --list`,
28
28
  ` ${name} --version`
@@ -40,6 +40,19 @@ function resolveConfigFor(name, configPath) {
40
40
  }
41
41
  // Thrown errors -> exit 1 with the message verbatim; usage errors exit 2 directly.
42
42
  export default async function cli(argv, name) {
43
+ // stdout is a pipe whenever the caller pipes or redirects, and a reader that goes away
44
+ // (`| head`) makes every later write fail. The failure arrives asynchronously, after the
45
+ // write loop has already returned: console.log absorbs it, process.stdout.write (what the
46
+ // streaming formats use) does not, so with no listener the process dies on an unhandled
47
+ // 'error' event having already done its work. Neither throwing nor exiting is safe from
48
+ // here. The event is async, so a throw is an uncaught exception rather than something
49
+ // bin/cli.js can catch, and process.exit() would skip the cleanup `sense watch` runs on the
50
+ // way out, leaving a heartbeat behind that makes a dead watcher look alive.
51
+ process.stdout.on('error', (err)=>{
52
+ if (err.code === 'EPIPE') return;
53
+ console.error(`sense: ${err.message}`);
54
+ process.exitCode = 1;
55
+ });
43
56
  const first = argv[0];
44
57
  // No command word, or the first token looks like a flag: the only flags this level knows.
45
58
  if (!first || first.startsWith('-')) {
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/cli.ts"],"sourcesContent":["import { createRequire } from 'node:module';\nimport { parseArgs } from 'node:util';\nimport { COMMANDS, USAGE } from './cli/index.ts';\nimport type { Ctx } from './cli/types.ts';\nimport { loadConfig, SUPPORTED_CONFIG_VERSION } from './config.ts';\n\n// Parsing and dispatch only; commands lazy-load from src/cli/, so nothing heavy is imported\n// here. Flags parse per command -- this file handles only --version/--help/--list/--config.\n\n// Works from dist/cjs and dist/esm alike: walk up past the dist type-marker package.json.\nfunction packageVersion(): string {\n const load = createRequire(import.meta.url);\n for (const rel of ['../package.json', '../../package.json', '../../../package.json']) {\n try {\n const pkg = load(rel) as { name?: string; version?: string };\n if (pkg.name === 'sensemaking' && pkg.version) return pkg.version;\n } catch {}\n }\n return 'unknown';\n}\n\nfunction usage(name: string): string {\n const lines = Object.values(USAGE).map((u) => ` ${name} ${u}`);\n return [`usage: ${name} <name> [params...] [--format table|json] [--config path]`, ...lines, ` ${name} --list`, ` ${name} --version`].join('\\n');\n}\n\nfunction resolveConfigFor(name: string, configPath: string | undefined) {\n const cfg = loadConfig(configPath);\n if (cfg.migratedFrom !== undefined) {\n console.warn(`${name}: migrated ${cfg.configPath} from config version ${cfg.migratedFrom} to ${SUPPORTED_CONFIG_VERSION}`);\n }\n if (cfg.unknownKeys !== undefined) {\n console.warn(`${name}: ${cfg.configPath} sets ${cfg.unknownKeys.join(', ')}, which this build does not read (no effect); see schema.json for the keys it does`);\n }\n return cfg;\n}\n\n// Thrown errors -> exit 1 with the message verbatim; usage errors exit 2 directly.\nexport default async function cli(argv: string[], name: string): Promise<void> {\n const first = argv[0];\n\n // No command word, or the first token looks like a flag: the only flags this level knows.\n if (!first || first.startsWith('-')) {\n let values: Record<string, string | boolean | undefined>;\n try {\n ({ values } = parseArgs({\n args: argv,\n options: {\n version: { type: 'boolean', default: false, short: 'v' },\n help: { type: 'boolean', default: false, short: 'h' },\n list: { type: 'boolean', default: false },\n config: { type: 'string' },\n },\n allowPositionals: true,\n }));\n } catch (err) {\n console.error((err as Error).message);\n console.error(usage(name));\n process.exit(2);\n }\n\n try {\n if (values.version) {\n console.log(packageVersion());\n return;\n }\n if (values.help) {\n console.log(usage(name));\n return;\n }\n if (values.list) {\n const queries = resolveConfigFor(name, values.config as string | undefined).queries;\n for (const queryName of Object.keys(queries).sort()) {\n // Every entry names its verb, so --list can label both kinds rather than only\n // marking the exception.\n console.log(`${queryName} (${'search' in queries[queryName] ? 'search' : 'sql'})`);\n }\n return;\n }\n } catch (err) {\n console.error((err as Error).message);\n process.exit(1);\n }\n\n console.error(usage(name));\n process.exit(2);\n }\n\n // Breaking renames get one release of a pointer instead of an \"unknown\" error: find ->\n // search, and query -> sql (which took its name back from the search sense of \"query\").\n const RENAMED: Record<string, string> = { find: 'search', query: 'sql' };\n if (RENAMED[first]) {\n console.error(`${name}: ${first} is now ${RENAMED[first]}`);\n console.error(usage(name));\n process.exit(2);\n }\n\n const ctx: Ctx = {\n name,\n argv: argv.slice(1),\n resolveConfig: (configPath) => resolveConfigFor(name, configPath),\n usageError(message) {\n console.error(message);\n process.exit(2);\n },\n };\n\n try {\n const load = COMMANDS[first];\n if (load) await (await load()).default(ctx);\n else await (await import('./cli/named.ts')).default(ctx, first);\n } catch (err) {\n console.error((err as Error).message);\n process.exit(1);\n }\n}\n"],"names":["createRequire","parseArgs","COMMANDS","USAGE","loadConfig","SUPPORTED_CONFIG_VERSION","packageVersion","load","url","rel","pkg","name","version","usage","lines","Object","values","map","u","join","resolveConfigFor","configPath","cfg","migratedFrom","undefined","console","warn","unknownKeys","cli","argv","first","startsWith","args","options","type","default","short","help","list","config","allowPositionals","err","error","message","process","exit","log","queries","queryName","keys","sort","RENAMED","find","query","ctx","slice","resolveConfig","usageError"],"mappings":"AAAA,SAASA,aAAa,QAAQ,cAAc;AAC5C,SAASC,SAAS,QAAQ,YAAY;AACtC,SAASC,QAAQ,EAAEC,K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ACpBiC,QAAQC,IAAI,CAAC;IACf;IAEA,uFAAuF;IACvF,wFAAwF;IACxF,MAAMM,UAAkC;QAAEC,MAAM;QAAUC,OAAO;IAAM;IACvE,IAAIF,OAAO,CAACrB,MAAM,EAAE;QAClBL,QAAQiB,KAAK,CAAC,GAAG/B,KAAK,EAAE,EAAEmB,MAAM,QAAQ,EAAEqB,OAAO,CAACrB,MAAM,EAAE;QAC1DL,QAAQiB,KAAK,CAAC7B,MAAMF;QACpBiC,QAAQC,IAAI,CAAC;IACf;IAEA,MAAMS,MAAW;QACf3C;QACAkB,MAAMA,KAAK0B,KAAK,CAAC;QACjBC,eAAe,CAACnC,aAAeD,iBAAiBT,MAAMU;QACtDoC,YAAWd,OAAO;YAChBlB,QAAQiB,KAAK,CAACC;YACdC,QAAQC,IAAI,CAAC;QACf;IACF;IAEA,IAAI;QACF,MAAMtC,OAAOL,QAAQ,CAAC4B,MAAM;QAC5B,IAAIvB,MAAM,MAAM,AAAC,CAAA,MAAMA,MAAK,EAAG4B,OAAO,CAACmB;aAClC,MAAM,AAAC,CAAA,MAAM,MAAM,CAAC,iBAAgB,EAAGnB,OAAO,CAACmB,KAAKxB;IAC3D,EAAE,OAAOW,KAAK;QACZhB,QAAQiB,KAAK,CAAC,AAACD,IAAcE,OAAO;QACpCC,QAAQC,IAAI,CAAC;IACf;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/cli.ts"],"sourcesContent":["import { createRequire } from 'node:module';\nimport { parseArgs } from 'node:util';\nimport { COMMANDS, USAGE } from './cli/index.ts';\nimport type { Ctx } from './cli/types.ts';\nimport { loadConfig, SUPPORTED_CONFIG_VERSION } from './config.ts';\n\n// Parsing and dispatch only; commands lazy-load from src/cli/, so nothing heavy is imported\n// here. Flags parse per command -- this file handles only --version/--help/--list/--config.\n\n// Works from dist/cjs and dist/esm alike: walk up past the dist type-marker package.json.\nfunction packageVersion(): string {\n const load = createRequire(import.meta.url);\n for (const rel of ['../package.json', '../../package.json', '../../../package.json']) {\n try {\n const pkg = load(rel) as { name?: string; version?: string };\n if (pkg.name === 'sensemaking' && pkg.version) return pkg.version;\n } catch {}\n }\n return 'unknown';\n}\n\nfunction usage(name: string): string {\n const lines = Object.values(USAGE).map((u) => ` ${name} ${u}`);\n return [`usage: ${name} <name> [params...] [--format table|json|csv] [--config path]`, ...lines, ` ${name} --list`, ` ${name} --version`].join('\\n');\n}\n\nfunction resolveConfigFor(name: string, configPath: string | undefined) {\n const cfg = loadConfig(configPath);\n if (cfg.migratedFrom !== undefined) {\n console.warn(`${name}: migrated ${cfg.configPath} from config version ${cfg.migratedFrom} to ${SUPPORTED_CONFIG_VERSION}`);\n }\n if (cfg.unknownKeys !== undefined) {\n console.warn(`${name}: ${cfg.configPath} sets ${cfg.unknownKeys.join(', ')}, which this build does not read (no effect); see schema.json for the keys it does`);\n }\n return cfg;\n}\n\n// Thrown errors -> exit 1 with the message verbatim; usage errors exit 2 directly.\nexport default async function cli(argv: string[], name: string): Promise<void> {\n // stdout is a pipe whenever the caller pipes or redirects, and a reader that goes away\n // (`| head`) makes every later write fail. The failure arrives asynchronously, after the\n // write loop has already returned: console.log absorbs it, process.stdout.write (what the\n // streaming formats use) does not, so with no listener the process dies on an unhandled\n // 'error' event having already done its work. Neither throwing nor exiting is safe from\n // here. The event is async, so a throw is an uncaught exception rather than something\n // bin/cli.js can catch, and process.exit() would skip the cleanup `sense watch` runs on the\n // way out, leaving a heartbeat behind that makes a dead watcher look alive.\n process.stdout.on('error', (err: NodeJS.ErrnoException) => {\n if (err.code === 'EPIPE') return;\n console.error(`sense: ${err.message}`);\n process.exitCode = 1;\n });\n\n const first = argv[0];\n\n // No command word, or the first token looks like a flag: the only flags this level knows.\n if (!first || first.startsWith('-')) {\n let values: Record<string, string | boolean | undefined>;\n try {\n ({ values } = parseArgs({\n args: argv,\n options: {\n version: { type: 'boolean', default: false, short: 'v' },\n help: { type: 'boolean', default: false, short: 'h' },\n list: { type: 'boolean', default: false },\n config: { type: 'string' },\n },\n allowPositionals: true,\n }));\n } catch (err) {\n console.error((err as Error).message);\n console.error(usage(name));\n process.exit(2);\n }\n\n try {\n if (values.version) {\n console.log(packageVersion());\n return;\n }\n if (values.help) {\n console.log(usage(name));\n return;\n }\n if (values.list) {\n const queries = resolveConfigFor(name, values.config as string | undefined).queries;\n for (const queryName of Object.keys(queries).sort()) {\n // Every entry names its verb, so --list can label both kinds rather than only\n // marking the exception.\n console.log(`${queryName} (${'search' in queries[queryName] ? 'search' : 'sql'})`);\n }\n return;\n }\n } catch (err) {\n console.error((err as Error).message);\n process.exit(1);\n }\n\n console.error(usage(name));\n process.exit(2);\n }\n\n // Breaking renames get one release of a pointer instead of an \"unknown\" error: find ->\n // search, and query -> sql (which took its name back from the search sense of \"query\").\n const RENAMED: Record<string, string> = { find: 'search', query: 'sql' };\n if (RENAMED[first]) {\n console.error(`${name}: ${first} is now ${RENAMED[first]}`);\n console.error(usage(name));\n process.exit(2);\n }\n\n const ctx: Ctx = {\n name,\n argv: argv.slice(1),\n resolveConfig: (configPath) => resolveConfigFor(name, configPath),\n usageError(message) {\n console.error(message);\n process.exit(2);\n },\n };\n\n try {\n const load = COMMANDS[first];\n if (load) await (await load()).default(ctx);\n else await (await import('./cli/named.ts')).default(ctx, first);\n } catch (err) {\n console.error((err as Error).message);\n process.exit(1);\n }\n}\n"],"names":["createRequire","parseArgs","COMMANDS","USAGE","loadConfig","SUPPORTED_CONFIG_VERSION","packageVersion","load","url","rel","pkg","name","version","usage","lines","Object","values","map","u","join","resolveConfigFor","configPath","cfg","migratedFrom","undefined","console","warn","unknownKeys","cli","argv","process","stdout","on","err","code","error","message","exitCode","first","startsWith","args","options","type","default","short","help","list","config","allowPositionals","exit","log","queries","queryName","keys","sort","RENAMED","find","query","ctx","slice","resolveConfig","usageError"],"mappings":"AAAA,SAASA,aAAa,QAAQ,cAAc;AAC5C,SAASC,SAAS,QAAQ,YAAY;AACtC,SAASC,QAAQ,EAAEC,KAA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: string | null;
35
36
  }
36
37
  export declare function mapTree(db: DatabaseSync, cfg: ResolvedConfig, overrides?: SearchOverrides): TreeMap;
37
38
  export declare function resolveNote(paths: string[], arg: string): string;
@@ -1,15 +1,18 @@
1
1
  import { readFileSync } from 'node:fs';
2
2
  import { join, matchesGlob } from 'node:path';
3
3
  import posix from 'node:path/posix';
4
- import { anyPresetEmbeds, embedEnabled, featureEnabled, featureStates, presetNames, presetSemanticEnabled, resolveSearch } from './config.js';
4
+ import { anyPresetEmbeds, contentTokenize, embedEnabled, featureEnabled, featureStates, presetNames, presetSemanticEnabled, resolveSearch } from './config.js';
5
5
  import { SenseError } from './errors.js';
6
6
  import { embedPending, hasEmbedding, modelPresent, semanticCandidates, similarNotes } from './features/embed.js';
7
7
  import { linkEdges } from './features/index.js';
8
8
  import { personalizedRank } from './graph.js';
9
9
  import { searchError } from './search-error.js';
10
+ import { segmentMatch } from './segment.js';
10
11
  // The three commands: mapTree (orient), search (locate), peek (structure).
11
12
  // Each returns data; cli.ts renders. All of them degrade when a feature is off.
12
- const WEIGHTED_BM25 = 'bm25(content, 10.0, 5.0, 1.0)';
13
+ // Mirrors the main columns onto the sidecars, so a title match found through title_seg ranks
14
+ // like a title match found through title, not like a body match.
15
+ const WEIGHTED_BM25 = 'bm25(content, 10.0, 5.0, 1.0, 0, 10.0, 5.0, 1.0)';
13
16
  const RRF_K = 60;
14
17
  // snippet() re-tokenizes each candidate doc, superlinearly: ~10s for one 1MB doc
15
18
  // (BENCHMARKING.md). Past this bound, rows get the linear JS excerpt instead.
@@ -124,43 +127,59 @@ function scopeHasEmbeddings(db, cfg, scopedPaths) {
124
127
  export async function search(db, cfg, terms, opts = {}) {
125
128
  var _hits_get, _chunkLines_get, _chunkSimilarity_get;
126
129
  const effective = resolveSearch(cfg, opts);
127
- const { k, include, exclude } = effective;
130
+ const { k } = effective;
128
131
  const allPaths = db.prepare('SELECT "path" FROM frontmatter').all().map((r)=>r.path);
129
- // A preset scope reads the coverage reconcile indexed; re-matching globs here could disagree
130
- // with it. Only ad-hoc scope flags, which have no persisted coverage, pay the JS match.
131
- const adHocScope = opts.include !== undefined || opts.exclude !== undefined || opts.noExclude === true;
132
- const scopedPaths = adHocScope ? new Set(allPaths.filter((p)=>inScope(p, include, exclude))) : new Set(db.prepare('SELECT "path" FROM preset_files WHERE preset = ?').all(effective.presetName).map((r)=>r.path));
133
- // A scope narrower than the whole index needs a bigger candidate pool before filtering, or
134
- // filtering can starve k even though enough in-scope matches exist further down the ranked
135
- // list that a plain over-fetch wouldn't have reached.
136
- const scopeActive = scopedPaths.size < allPaths.length;
137
- const fetch = scopeActive ? Math.max(k * 5, 50) : Math.max(k * 3, 30);
132
+ const scopePaths = rawScope(db, cfg, opts, allPaths);
133
+ const scopeActive = scopePaths.size < allPaths.length;
134
+ // The set every candidate pool must be filtered to before truncation: scope narrowed by
135
+ // --where, the same composition scopedPaths() gives the other commands. Runs the same where
136
+ // fragment matchSql does, so a bad column gets the same attributed error either way.
137
+ let allowedPaths;
138
+ try {
139
+ allowedPaths = narrowByWhere(db, scopePaths, effective.where);
140
+ } catch (err) {
141
+ throw searchError(err, terms, effective.where);
142
+ }
143
+ const fetch = Math.max(k * 3, 30);
138
144
  // Asking for vectors without a model is a misconfiguration, not a mode: degrading would make
139
145
  // the same search answer differently before and after a download. semantic:false never asks.
140
146
  const wantsVectors = effective.semantic && anyPresetEmbeds(cfg);
141
147
  if (wantsVectors && !modelPresent(cfg)) {
142
148
  throw new SenseError('EMBED_MODEL_MISSING', `preset "${effective.presetName}" searches with vectors, but the embedding model is not available; run \`sense download\`, or set "semantic": false on that preset to search on words and links`);
143
149
  }
144
- const semanticEnabled = wantsVectors && scopeHasEmbeddings(db, cfg, scopedPaths);
145
- // Terms pass verbatim to MATCH; invalid syntax errors rather than being rewritten. --where
150
+ const semanticEnabled = wantsVectors && scopeHasEmbeddings(db, cfg, allowedPaths);
151
+ // Terms pass to MATCH as written, with one transform: a run of text whose language marks no
152
+ // word boundaries becomes a quoted grapheme phrase (and a title:/summary:/text: qualifier
153
+ // ahead of it retargets its _seg column), matching how it was indexed. Text that already
154
+ // carries boundaries comes through untouched, so this is a no-op for the languages that
155
+ // never needed it. Gated on the same predicate that decided whether the sidecars were
156
+ // populated (contentTokenize(cfg) === undefined), so index and query can't disagree. Invalid
157
+ // syntax still errors rather than being rewritten.
158
+ // --where
146
159
  // applies inside the candidate query (a post-filter would drop matches ranked past the pool)
147
160
  // and again on the final select, for link-derived rows.
148
161
  const scope = effective.where;
149
162
  const whereJoin = scope ? `JOIN frontmatter f ON f."path" = content.path` : '';
150
163
  const whereCond = scope ? `AND (${scope})` : '';
164
+ // A scope narrower than the whole index must filter the candidate pool before LIMIT, not
165
+ // after -- otherwise scoped notes ranking below the global top-`fetch` never reach the
166
+ // filter. A join against a temp table, not a bound parameter list: real scopes run to
167
+ // thousands of paths, past SQLITE_MAX_VARIABLE_NUMBER on older builds.
168
+ if (scopeActive) materializeScope(db, '_search_scope', scopePaths);
169
+ const scopeCond = scopeActive ? `AND content.path IN (SELECT "path" FROM _search_scope)` : '';
151
170
  // Docs past SNIPPET_BOUND skip snippet() entirely -- SQLite
152
171
  // short-circuits the untaken CASE branch, so it's never invoked on them.
153
- const matchSql = `SELECT content.path AS path, CASE WHEN length(content.text) <= ${SNIPPET_BOUND} THEN snippet(content, -1, '«', '»', '…', 10) ELSE NULL END AS hit FROM content ${whereJoin} WHERE content MATCH ? ${whereCond} ORDER BY ${WEIGHTED_BM25} LIMIT ${fetch}`;
172
+ // Column 2 (text), not -1 (best column): -1 could surface a _seg sidecar as the excerpt,
173
+ // which is machine-spaced and not what the author wrote. A row that matches only in a
174
+ // sidecar gets an unhighlighted text excerpt below instead -- a stated cost.
175
+ 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}`;
176
+ const query = contentTokenize(cfg) === undefined ? segmentMatch(terms) : terms;
154
177
  let matchRows;
155
178
  try {
156
- matchRows = db.prepare(matchSql).all(terms);
179
+ matchRows = db.prepare(matchSql).all(query);
157
180
  } catch (err) {
158
181
  throw searchError(err, terms, scope);
159
182
  }
160
- // Scope filtering happens in JS, on each candidate list, rather than in SQL: FTS5 match,
161
- // link expansion, and vector search all run unscoped above (cheap to over-fetch), then get
162
- // filtered here against the effective include/exclude before ranking is finalized.
163
- matchRows = matchRows.filter((r)=>scopedPaths.has(r.path));
164
183
  const hits = new Map(matchRows.map((r)=>[
165
184
  r.path,
166
185
  r.hit
@@ -186,7 +205,7 @@ export async function search(db, cfg, terms, opts = {}) {
186
205
  ]));
187
206
  const ranked = [
188
207
  ...personalizedRank(allPaths, edges, seeds)
189
- ].filter(([path, score])=>score > 1e-9 && scopedPaths.has(path)).sort((a, b)=>b[1] - a[1]).slice(0, fetch);
208
+ ].filter(([path, score])=>score > 1e-9 && allowedPaths.has(path)).sort((a, b)=>b[1] - a[1]).slice(0, fetch);
190
209
  ranked.forEach(([path], i)=>{
191
210
  const existing = candidates.get(path);
192
211
  if (existing) {
@@ -205,7 +224,7 @@ export async function search(db, cfg, terms, opts = {}) {
205
224
  const chunkLines = new Map();
206
225
  const chunkSimilarity = new Map();
207
226
  if (semanticEnabled) {
208
- const vec = (await semanticCandidates(db, cfg, terms, fetch)).filter((v)=>scopedPaths.has(v.path));
227
+ const vec = await semanticCandidates(db, cfg, terms, fetch, allowedPaths);
209
228
  vec.forEach(({ path, lines, similarity }, i)=>{
210
229
  chunkLines.set(path, lines);
211
230
  chunkSimilarity.set(path, similarity);
@@ -225,8 +244,9 @@ export async function search(db, cfg, terms, opts = {}) {
225
244
  db.exec('CREATE TEMP TABLE _search ("path" TEXT PRIMARY KEY, score REAL, via TEXT, hit TEXT, lines TEXT, similarity REAL)');
226
245
  const insert = db.prepare('INSERT INTO _search ("path", score, via, hit, lines, similarity) VALUES (?, ?, ?, ?, ?, ?)');
227
246
  for (const [path, c] of candidates)insert.run(path, c.score, c.via, (_hits_get = hits.get(path)) !== null && _hits_get !== void 0 ? _hits_get : null, (_chunkLines_get = chunkLines.get(path)) !== null && _chunkLines_get !== void 0 ? _chunkLines_get : null, (_chunkSimilarity_get = chunkSimilarity.get(path)) !== null && _chunkSimilarity_get !== void 0 ? _chunkSimilarity_get : null);
228
- // Already scope-filtered above; the final select reapplies --where only for link-derived
229
- // rows, which never passed through whereCond.
247
+ // All three candidate paths (match, link, vector) already filtered to scope+where before
248
+ // reaching _search; this reapplies --where anyway since the join to frontmatter is already
249
+ // needed for the path column.
230
250
  const where = scope ? `WHERE (${scope})` : '';
231
251
  // lines is always present now: semantic rows carry their chunk's range, oversized-doc
232
252
  // lexical rows gain one below, everything else stays null. similarity stays semantic-only.
@@ -251,15 +271,18 @@ export async function search(db, cfg, terms, opts = {}) {
251
271
  }
252
272
  return rows;
253
273
  }
254
- // The scope resolver for non-search commands (path, peek, map): same coverage rule search()
255
- // applies (preset_files for a named preset, JS glob matching for an ad hoc include/exclude),
256
- // then narrowed by the resolved `where`.
257
- export function scopedPaths(db, cfg, overrides) {
274
+ // Scope only (no --where): preset_files for a named preset, JS glob matching for an ad hoc
275
+ // include/exclude override. Shared by scopedPaths() and search(), which also needs the
276
+ // pre-where set to size the candidate-pool filter.
277
+ function rawScope(db, cfg, overrides, allPaths) {
258
278
  const effective = resolveSearch(cfg, overrides);
259
- const { include, exclude, where } = effective;
260
- const allPaths = db.prepare('SELECT "path" FROM frontmatter').all().map((r)=>r.path);
279
+ const { include, exclude } = effective;
261
280
  const adHocScope = overrides.include !== undefined || overrides.exclude !== undefined || overrides.noExclude === true;
262
- const paths = adHocScope ? new Set(allPaths.filter((p)=>inScope(p, include, exclude))) : new Set(db.prepare('SELECT "path" FROM preset_files WHERE preset = ?').all(effective.presetName).map((r)=>r.path));
281
+ if (!adHocScope) return new Set(db.prepare('SELECT "path" FROM preset_files WHERE preset = ?').all(effective.presetName).map((r)=>r.path));
282
+ const paths = allPaths !== null && allPaths !== void 0 ? allPaths : db.prepare('SELECT "path" FROM frontmatter').all().map((r)=>r.path);
283
+ return new Set(paths.filter((p)=>inScope(p, include, exclude)));
284
+ }
285
+ function narrowByWhere(db, paths, where) {
263
286
  if (!where) return paths;
264
287
  const whereRows = db.prepare(`SELECT "path" FROM frontmatter f WHERE (${where})`).all();
265
288
  const wherePaths = new Set(whereRows.map((r)=>r.path));
@@ -267,6 +290,12 @@ export function scopedPaths(db, cfg, overrides) {
267
290
  ...paths
268
291
  ].filter((p)=>wherePaths.has(p)));
269
292
  }
293
+ // The scope resolver for non-search commands (path, peek, map): same coverage rule search()
294
+ // applies, then narrowed by the resolved `where`.
295
+ export function scopedPaths(db, cfg, overrides) {
296
+ const effective = resolveSearch(cfg, overrides);
297
+ return narrowByWhere(db, rawScope(db, cfg, overrides), effective.where);
298
+ }
270
299
  // Indexing derives from presets, so the derivation stays visible. Read from preset_files, not
271
300
  // recomputed from globs, so it reflects the cache rather than the config.
272
301
  export function presetCoverage(db, cfg) {
@@ -297,15 +326,18 @@ function chunk(items, size) {
297
326
  for(let i = 0; i < items.length; i += size)out.push(items.slice(i, i + size));
298
327
  return out;
299
328
  }
300
- // Materializes the resolved scope into a temp table (same shape as traverse.ts's
301
- // allowed_nodes) so every mapTree query can join/filter against it cheaply.
302
- function setupMapScope(db, paths) {
303
- db.exec('DROP TABLE IF EXISTS _map_scope');
304
- db.exec('CREATE TEMP TABLE _map_scope ("path" TEXT PRIMARY KEY)');
305
- db.prepare('INSERT INTO _map_scope SELECT DISTINCT value FROM json_each(?1)').run(JSON.stringify([
329
+ // Materializes a path set into a named temp table (same shape as traverse.ts's allowed_nodes)
330
+ // so a query can join/filter against it cheaply instead of binding a parameter per path.
331
+ function materializeScope(db, table, paths) {
332
+ db.exec(`DROP TABLE IF EXISTS ${table}`);
333
+ db.exec(`CREATE TEMP TABLE ${table} ("path" TEXT PRIMARY KEY)`);
334
+ db.prepare(`INSERT INTO ${table} SELECT DISTINCT value FROM json_each(?1)`).run(JSON.stringify([
306
335
  ...paths
307
336
  ]));
308
337
  }
338
+ function setupMapScope(db, paths) {
339
+ materializeScope(db, '_map_scope', paths);
340
+ }
309
341
  // What is this scope: fixed-size output regardless of tree size. Coverage and features stay
310
342
  // global -- they describe the tree, not the current question.
311
343
  export function mapTree(db, cfg, overrides = {}) {
@@ -336,6 +368,10 @@ export function mapTree(db, cfg, overrides = {}) {
336
368
  const fields = allFields.slice(0, 20);
337
369
  const hubs = featureEnabled(cfg, 'rank') ? db.prepare(`SELECT f."path" AS path, round(f."_rank" * 100, 2) AS rank, content.title FROM frontmatter f JOIN content ON content.path = f."path" WHERE f."_rank" IS NOT NULL ${scopeAnd} ORDER BY f."_rank" DESC LIMIT 8`).all() : [];
338
370
  const recent = db.prepare(`SELECT "path", datetime("_mtime" / 1000, 'unixepoch') AS modified FROM frontmatter ${scopeWhere} ORDER BY "_mtime" DESC LIMIT 5`).all();
371
+ // A fresh clone/copy stamps files with checkout time, not edit history; second granularity
372
+ // matches the `recent` table above and is coarse enough to catch that without an exact-ms match.
373
+ const topSecond = db.prepare(`SELECT COUNT(*) AS n FROM frontmatter ${scopeWhere} GROUP BY CAST("_mtime" / 1000 AS INTEGER) ORDER BY n DESC LIMIT 1`).get();
374
+ const recentCaveat = topSecond && docs.count > 1 && topSecond.n > docs.count / 2 ? `${topSecond.n} of ${docs.count} files share one modified second, so recency likely reflects a checkout or copy, not edit history` : null;
339
375
  return {
340
376
  docs,
341
377
  fields,
@@ -343,7 +379,8 @@ export function mapTree(db, cfg, overrides = {}) {
343
379
  features: featureStates(cfg),
344
380
  presets: presetCoverage(db, cfg),
345
381
  hubs,
346
- recent
382
+ recent,
383
+ recentCaveat
347
384
  };
348
385
  }
349
386
  // Note resolution shared by peek and path: an exact path, or a unique basename (case