sensemaking 0.9.1 → 0.9.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -2
- package/bin/cli.js +5 -1
- package/dist/cjs/cli/check.js +36 -4
- package/dist/cjs/cli/check.js.map +1 -1
- package/dist/cjs/cli/exit.d.cts +5 -0
- package/dist/cjs/cli/exit.d.ts +5 -0
- package/dist/cjs/cli/exit.js +147 -0
- package/dist/cjs/cli/exit.js.map +1 -0
- package/dist/cjs/cli/index.d.cts +11 -0
- package/dist/cjs/cli/index.d.ts +11 -0
- package/dist/cjs/cli/index.js +22 -3
- package/dist/cjs/cli/index.js.map +1 -1
- package/dist/cjs/cli/init.js +3 -0
- package/dist/cjs/cli/init.js.map +1 -1
- package/dist/cjs/cli/map.js +33 -2
- package/dist/cjs/cli/map.js.map +1 -1
- package/dist/cjs/cli/named.d.cts +1 -1
- package/dist/cjs/cli/named.d.ts +1 -1
- package/dist/cjs/cli/named.js +48 -17
- package/dist/cjs/cli/named.js.map +1 -1
- package/dist/cjs/cli/peek.js +36 -4
- package/dist/cjs/cli/peek.js.map +1 -1
- package/dist/cjs/cli/query.js +35 -3
- package/dist/cjs/cli/query.js.map +1 -1
- package/dist/cjs/cli/rebuild.js +31 -1
- package/dist/cjs/cli/rebuild.js.map +1 -1
- package/dist/cjs/cli/search.js +42 -10
- package/dist/cjs/cli/search.js.map +1 -1
- package/dist/cjs/cli/shared.d.cts +18 -2
- package/dist/cjs/cli/shared.d.ts +18 -2
- package/dist/cjs/cli/shared.js +238 -11
- package/dist/cjs/cli/shared.js.map +1 -1
- package/dist/cjs/cli/status.js +5 -2
- package/dist/cjs/cli/status.js.map +1 -1
- package/dist/cjs/cli/types.d.cts +2 -12
- package/dist/cjs/cli/types.d.ts +2 -12
- package/dist/cjs/cli/watch.js +38 -2
- package/dist/cjs/cli/watch.js.map +1 -1
- package/dist/cjs/cli.js +147 -150
- package/dist/cjs/cli.js.map +1 -1
- package/dist/cjs/db.js +5 -0
- package/dist/cjs/db.js.map +1 -1
- package/dist/esm/cli/check.js +11 -4
- package/dist/esm/cli/check.js.map +1 -1
- package/dist/esm/cli/exit.d.ts +5 -0
- package/dist/esm/cli/exit.js +15 -0
- package/dist/esm/cli/exit.js.map +1 -0
- package/dist/esm/cli/index.d.ts +11 -0
- package/dist/esm/cli/index.js +14 -0
- package/dist/esm/cli/index.js.map +1 -1
- package/dist/esm/cli/init.js +3 -0
- package/dist/esm/cli/init.js.map +1 -1
- package/dist/esm/cli/map.js +11 -3
- package/dist/esm/cli/map.js.map +1 -1
- package/dist/esm/cli/named.d.ts +1 -1
- package/dist/esm/cli/named.js +25 -18
- package/dist/esm/cli/named.js.map +1 -1
- package/dist/esm/cli/peek.js +12 -5
- package/dist/esm/cli/peek.js.map +1 -1
- package/dist/esm/cli/query.js +11 -4
- package/dist/esm/cli/query.js.map +1 -1
- package/dist/esm/cli/rebuild.js +6 -2
- package/dist/esm/cli/rebuild.js.map +1 -1
- package/dist/esm/cli/search.js +18 -10
- package/dist/esm/cli/search.js.map +1 -1
- package/dist/esm/cli/shared.d.ts +18 -2
- package/dist/esm/cli/shared.js +100 -11
- package/dist/esm/cli/shared.js.map +1 -1
- package/dist/esm/cli/status.js +9 -3
- package/dist/esm/cli/status.js.map +1 -1
- package/dist/esm/cli/types.d.ts +2 -12
- package/dist/esm/cli/types.js.map +1 -1
- package/dist/esm/cli/watch.js +11 -3
- package/dist/esm/cli/watch.js.map +1 -1
- package/dist/esm/cli.js +83 -102
- package/dist/esm/cli.js.map +1 -1
- package/dist/esm/db.js +5 -0
- package/dist/esm/db.js.map +1 -1
- package/package.json +3 -1
package/dist/esm/cli/check.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { search } from '../commands.js';
|
|
2
2
|
import { open } from '../db.js';
|
|
3
3
|
import { printRows } from '../output.js';
|
|
4
|
-
import {
|
|
4
|
+
import { ExitError } from './exit.js';
|
|
5
|
+
import { USAGE } from './index.js';
|
|
6
|
+
import { CONFIG, FORMAT, formatOf, parse, printWarnings } from './shared.js';
|
|
5
7
|
// A saved query that returns zero rows looks identical to a true empty result, so a broken
|
|
6
8
|
// one can sit unnoticed -- one field report had `WHERE flag = 'true'` against a numeric
|
|
7
9
|
// column reading as "nothing tagged yet" for hours. Preparing each query catches syntax and
|
|
@@ -14,7 +16,12 @@ import { printWarnings } from './shared.js';
|
|
|
14
16
|
// result being empty is good or bad is the reader's judgment -- there is no assertion path.
|
|
15
17
|
const check = async (ctx)=>{
|
|
16
18
|
var _cfg_queries;
|
|
17
|
-
const
|
|
19
|
+
const { values } = parse(ctx.argv, `usage: ${ctx.name} ${USAGE.check}`, {
|
|
20
|
+
...FORMAT,
|
|
21
|
+
...CONFIG
|
|
22
|
+
});
|
|
23
|
+
const format = formatOf(values);
|
|
24
|
+
const cfg = ctx.resolveConfig(values.config);
|
|
18
25
|
const { db, warnings } = open(cfg);
|
|
19
26
|
printWarnings(warnings);
|
|
20
27
|
const rows = [];
|
|
@@ -82,7 +89,7 @@ const check = async (ctx)=>{
|
|
|
82
89
|
console.log('no saved queries in config');
|
|
83
90
|
return;
|
|
84
91
|
}
|
|
85
|
-
printRows(rows,
|
|
86
|
-
if (failed > 0)
|
|
92
|
+
printRows(rows, format);
|
|
93
|
+
if (failed > 0) throw new ExitError(1);
|
|
87
94
|
};
|
|
88
95
|
export default check;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/cli/check.ts"],"sourcesContent":["import { search } from '../commands.ts';\nimport { open } from '../db.ts';\nimport type { Row } from '../output.ts';\nimport { printRows } from '../output.ts';\nimport { printWarnings } from './shared.ts';\nimport type { Command } from './types.ts';\n\n// A saved query that returns zero rows looks identical to a true empty result, so a broken\n// one can sit unnoticed -- one field report had `WHERE flag = 'true'` against a numeric\n// column reading as \"nothing tagged yet\" for hours. Preparing each query catches syntax and\n// unknown-column errors without executing it; queries that take no parameters are also run\n// for a row count. Parameterised queries are validated but not counted: inventing arguments\n// would report a count for a query nobody ran. Saved searches run lexically with k=1 -- that\n// validates the `where` fragment, the FTS5 terms, and the `preset` name (resolveSearch throws\n// on an unknown one, the same breakage class prepare() catches for SQL strings) -- but never\n// semantically (a semantic pass costs model time and, on api trees, network). Whether a\n// result being empty is good or bad is the reader's judgment -- there is no assertion path.\nconst check: Command = async (ctx) => {\n const cfg = ctx.resolveConfig();\n const { db, warnings } = open(cfg);\n printWarnings(warnings);\n\n const rows: Row[] = [];\n let failed = 0;\n for (const [name, entry] of Object.entries(cfg.queries ?? {})) {\n if (typeof entry === 'object' && entry !== null && 'search' in entry) {\n try {\n const count = (await search(db, cfg, entry.search, { k: 1, where: entry.where, preset: entry.preset, include: entry.include, semantic: false })).length;\n rows.push({ query: name, params: '—', rows: '—', status: count === 0 ? 'ok, but matches 0 notes (lexical probe)' : 'ok (probe run with k=1)' });\n } catch (err) {\n failed++;\n rows.push({ query: name, params: '—', rows: '—', status: `FAILED: ${(err as Error).message}` });\n }\n continue;\n }\n const sql = typeof entry === 'string' ? entry : entry.sql;\n const params = (sql.match(/\\?/g) ?? []).length;\n try {\n const statement = db.prepare(sql);\n if (params > 0) {\n rows.push({ query: name, params, rows: '—', status: 'ok (not run: needs parameters)' });\n continue;\n }\n const count = (statement.all() as unknown[]).length;\n rows.push({ query: name, params, rows: count, status: count === 0 ? 'ok, but returns 0 rows' : 'ok' });\n } catch (err) {\n failed++;\n rows.push({ query: name, params, rows: '—', status: `FAILED: ${(err as Error).message}` });\n }\n }\n\n db.close();\n if (rows.length === 0) {\n console.log('no saved queries in config');\n return;\n }\n printRows(rows,
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/cli/check.ts"],"sourcesContent":["import { search } from '../commands.ts';\nimport { open } from '../db.ts';\nimport type { Row } from '../output.ts';\nimport { printRows } from '../output.ts';\nimport { ExitError } from './exit.ts';\nimport { USAGE } from './index.ts';\nimport { CONFIG, FORMAT, formatOf, parse, printWarnings } from './shared.ts';\nimport type { Command } from './types.ts';\n\n// A saved query that returns zero rows looks identical to a true empty result, so a broken\n// one can sit unnoticed -- one field report had `WHERE flag = 'true'` against a numeric\n// column reading as \"nothing tagged yet\" for hours. Preparing each query catches syntax and\n// unknown-column errors without executing it; queries that take no parameters are also run\n// for a row count. Parameterised queries are validated but not counted: inventing arguments\n// would report a count for a query nobody ran. Saved searches run lexically with k=1 -- that\n// validates the `where` fragment, the FTS5 terms, and the `preset` name (resolveSearch throws\n// on an unknown one, the same breakage class prepare() catches for SQL strings) -- but never\n// semantically (a semantic pass costs model time and, on api trees, network). Whether a\n// result being empty is good or bad is the reader's judgment -- there is no assertion path.\nconst check: Command = async (ctx) => {\n const { values } = parse(ctx.argv, `usage: ${ctx.name} ${USAGE.check}`, { ...FORMAT, ...CONFIG });\n const format = formatOf(values);\n const cfg = ctx.resolveConfig(values.config as string | undefined);\n const { db, warnings } = open(cfg);\n printWarnings(warnings);\n\n const rows: Row[] = [];\n let failed = 0;\n for (const [name, entry] of Object.entries(cfg.queries ?? {})) {\n if (typeof entry === 'object' && entry !== null && 'search' in entry) {\n try {\n const count = (await search(db, cfg, entry.search, { k: 1, where: entry.where, preset: entry.preset, include: entry.include, semantic: false })).length;\n rows.push({ query: name, params: '—', rows: '—', status: count === 0 ? 'ok, but matches 0 notes (lexical probe)' : 'ok (probe run with k=1)' });\n } catch (err) {\n failed++;\n rows.push({ query: name, params: '—', rows: '—', status: `FAILED: ${(err as Error).message}` });\n }\n continue;\n }\n const sql = typeof entry === 'string' ? entry : entry.sql;\n const params = (sql.match(/\\?/g) ?? []).length;\n try {\n const statement = db.prepare(sql);\n if (params > 0) {\n rows.push({ query: name, params, rows: '—', status: 'ok (not run: needs parameters)' });\n continue;\n }\n const count = (statement.all() as unknown[]).length;\n rows.push({ query: name, params, rows: count, status: count === 0 ? 'ok, but returns 0 rows' : 'ok' });\n } catch (err) {\n failed++;\n rows.push({ query: name, params, rows: '—', status: `FAILED: ${(err as Error).message}` });\n }\n }\n\n db.close();\n if (rows.length === 0) {\n console.log('no saved queries in config');\n return;\n }\n printRows(rows, format);\n if (failed > 0) throw new ExitError(1);\n};\nexport default check;\n"],"names":["search","open","printRows","ExitError","USAGE","CONFIG","FORMAT","formatOf","parse","printWarnings","check","ctx","cfg","values","argv","name","format","resolveConfig","config","db","warnings","rows","failed","entry","Object","entries","queries","sql","count","k","where","preset","include","semantic","length","push","query","params","status","err","message","match","statement","prepare","all","close","console","log"],"mappings":"AAAA,SAASA,MAAM,QAAQ,iBAAiB;AACxC,SAASC,IAAI,QAAQ,WAAW;AAEhC,SAASC,SAAS,QAAQ,eAAe;AACzC,SAASC,SAAS,QAAQ,YAAY;AACtC,SAASC,KAAK,QAAQ,aAAa;AACnC,SAASC,MAAM,EAAEC,MAAM,EAAEC,QAAQ,EAAEC,KAAK,EAAEC,aAAa,QAAQ,cAAc;AAG7E,2FAA2F;AAC3F,wFAAwF;AACxF,4FAA4F;AAC5F,2FAA2F;AAC3F,4FAA4F;AAC5F,6FAA6F;AAC7F,8FAA8F;AAC9F,6FAA6F;AAC7F,wFAAwF;AACxF,4FAA4F;AAC5F,MAAMC,QAAiB,OAAOC;QASeC;IAR3C,MAAM,EAAEC,MAAM,EAAE,GAAGL,MAAMG,IAAIG,IAAI,EAAE,CAAC,OAAO,EAAEH,IAAII,IAAI,CAAC,CAAC,EAAEX,MAAMM,KAAK,EAAE,EAAE;QAAE,GAAGJ,MAAM;QAAE,GAAGD,MAAM;IAAC;IAC/F,MAAMW,SAAST,SAASM;IACxB,MAAMD,MAAMD,IAAIM,aAAa,CAACJ,OAAOK,MAAM;IAC3C,MAAM,EAAEC,EAAE,EAAEC,QAAQ,EAAE,GAAGnB,KAAKW;IAC9BH,cAAcW;IAEd,MAAMC,OAAc,EAAE;IACtB,IAAIC,SAAS;IACb,KAAK,MAAM,CAACP,MAAMQ,MAAM,IAAIC,OAAOC,OAAO,EAACb,eAAAA,IAAIc,OAAO,cAAXd,0BAAAA,eAAe,CAAC,GAAI;YAY7Ce;QAXhB,IAAI,OAAOJ,UAAU,YAAYA,UAAU,QAAQ,YAAYA,OAAO;YACpE,IAAI;gBACF,MAAMK,QAAQ,AAAC,CAAA,MAAM5B,OAAOmB,IAAIP,KAAKW,MAAMvB,MAAM,EAAE;oBAAE6B,GAAG;oBAAGC,OAAOP,MAAMO,KAAK;oBAAEC,QAAQR,MAAMQ,MAAM;oBAAEC,SAAST,MAAMS,OAAO;oBAAEC,UAAU;gBAAM,EAAC,EAAGC,MAAM;gBACvJb,KAAKc,IAAI,CAAC;oBAAEC,OAAOrB;oBAAMsB,QAAQ;oBAAKhB,MAAM;oBAAKiB,QAAQV,UAAU,IAAI,4CAA4C;gBAA0B;YAC/I,EAAE,OAAOW,KAAK;gBACZjB;gBACAD,KAAKc,IAAI,CAAC;oBAAEC,OAAOrB;oBAAMsB,QAAQ;oBAAKhB,MAAM;oBAAKiB,QAAQ,CAAC,QAAQ,EAAE,AAACC,IAAcC,OAAO,EAAE;gBAAC;YAC/F;YACA;QACF;QACA,MAAMb,MAAM,OAAOJ,UAAU,WAAWA,QAAQA,MAAMI,GAAG;QACzD,MAAMU,SAAS,EAACV,aAAAA,IAAIc,KAAK,CAAC,oBAAVd,wBAAAA,aAAoB,EAAE,EAAEO,MAAM;QAC9C,IAAI;YACF,MAAMQ,YAAYvB,GAAGwB,OAAO,CAAChB;YAC7B,IAAIU,SAAS,GAAG;gBACdhB,KAAKc,IAAI,CAAC;oBAAEC,OAAOrB;oBAAMsB;oBAAQhB,MAAM;oBAAKiB,QAAQ;gBAAiC;gBACrF;YACF;YACA,MAAMV,QAAQ,AAACc,UAAUE,GAAG,GAAiBV,MAAM;YACnDb,KAAKc,IAAI,CAAC;gBAAEC,OAAOrB;gBAAMsB;gBAAQhB,MAAMO;gBAAOU,QAAQV,UAAU,IAAI,2BAA2B;YAAK;QACtG,EAAE,OAAOW,KAAK;YACZjB;YACAD,KAAKc,IAAI,CAAC;gBAAEC,OAAOrB;gBAAMsB;gBAAQhB,MAAM;gBAAKiB,QAAQ,CAAC,QAAQ,EAAE,AAACC,IAAcC,OAAO,EAAE;YAAC;QAC1F;IACF;IAEArB,GAAG0B,KAAK;IACR,IAAIxB,KAAKa,MAAM,KAAK,GAAG;QACrBY,QAAQC,GAAG,CAAC;QACZ;IACF;IACA7C,UAAUmB,MAAML;IAChB,IAAIM,SAAS,GAAG,MAAM,IAAInB,UAAU;AACtC;AACA,eAAeO,MAAM"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Commands never end the process themselves: they throw this, and cli.ts -- the one place
|
|
2
|
+
// that owns the exit -- drains stdio through exit-compat and returns. Neither alternative
|
|
3
|
+
// works here: a direct process.exit() races a pending write, and a bare return would let a
|
|
4
|
+
// command body run on after --help had already printed its usage.
|
|
5
|
+
export class ExitError extends Error {
|
|
6
|
+
constructor(code){
|
|
7
|
+
super(`exit ${code}`);
|
|
8
|
+
this.code = code;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export function usageError(message, usage) {
|
|
12
|
+
console.error(message);
|
|
13
|
+
if (usage !== undefined) console.error(usage);
|
|
14
|
+
throw new ExitError(2);
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/cli/exit.ts"],"sourcesContent":["// Commands never end the process themselves: they throw this, and cli.ts -- the one place\n// that owns the exit -- drains stdio through exit-compat and returns. Neither alternative\n// works here: a direct process.exit() races a pending write, and a bare return would let a\n// command body run on after --help had already printed its usage.\nexport class ExitError extends Error {\n readonly code: number;\n constructor(code: number) {\n super(`exit ${code}`);\n this.code = code;\n }\n}\n\nexport function usageError(message: string, usage?: string): never {\n console.error(message);\n if (usage !== undefined) console.error(usage);\n throw new ExitError(2);\n}\n"],"names":["ExitError","Error","code","usageError","message","usage","console","error","undefined"],"mappings":"AAAA,0FAA0F;AAC1F,0FAA0F;AAC1F,2FAA2F;AAC3F,kEAAkE;AAClE,OAAO,MAAMA,kBAAkBC;IAE7B,YAAYC,IAAY,CAAE;QACxB,KAAK,CAAC,CAAC,KAAK,EAAEA,MAAM;QACpB,IAAI,CAACA,IAAI,GAAGA;IACd;AACF;AAEA,OAAO,SAASC,WAAWC,OAAe,EAAEC,KAAc;IACxDC,QAAQC,KAAK,CAACH;IACd,IAAIC,UAAUG,WAAWF,QAAQC,KAAK,CAACF;IACvC,MAAM,IAAIL,UAAU;AACtB"}
|
package/dist/esm/cli/index.d.ts
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
import type { Command } from './types.js';
|
|
2
|
+
export declare const USAGE: {
|
|
3
|
+
readonly init: "init";
|
|
4
|
+
readonly watch: "watch [--force] [--config path]";
|
|
5
|
+
readonly status: "status [--format table|json] [--config path]";
|
|
6
|
+
readonly check: "check [--format table|json] [--config path]";
|
|
7
|
+
readonly rebuild: "rebuild [--config path]";
|
|
8
|
+
readonly query: "query \"<sql>\" [params...] [--format table|json] [--config path]";
|
|
9
|
+
readonly search: "search \"<terms>\" [--preset name] [--include glob ...] [--where \"<sql>\"] [--k n] [--lexical] [--format table|json] [--config path]";
|
|
10
|
+
readonly map: "map [--format table|json] [--config path]";
|
|
11
|
+
readonly peek: "peek <path> [--format table|json] [--config path]";
|
|
12
|
+
};
|
|
2
13
|
export declare const COMMANDS: Record<string, () => Promise<{
|
|
3
14
|
default: Command;
|
|
4
15
|
}>>;
|
package/dist/esm/cli/index.js
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
// Each command's usage line, minus the leading "usage: <name> " -- shared by cli.ts's
|
|
2
|
+
// top-level usage() and the command's own parse() error/--help output, so there is one
|
|
3
|
+
// copy of each line, not two that can drift.
|
|
4
|
+
export const USAGE = {
|
|
5
|
+
init: 'init',
|
|
6
|
+
watch: 'watch [--force] [--config path]',
|
|
7
|
+
status: 'status [--format table|json] [--config path]',
|
|
8
|
+
check: 'check [--format table|json] [--config path]',
|
|
9
|
+
rebuild: 'rebuild [--config path]',
|
|
10
|
+
query: 'query "<sql>" [params...] [--format table|json] [--config path]',
|
|
11
|
+
search: 'search "<terms>" [--preset name] [--include glob ...] [--where "<sql>"] [--k n] [--lexical] [--format table|json] [--config path]',
|
|
12
|
+
map: 'map [--format table|json] [--config path]',
|
|
13
|
+
peek: 'peek <path> [--format table|json] [--config path]'
|
|
14
|
+
};
|
|
1
15
|
// Lazy registry: a command's imports load only when it runs, so a heavy dependency in one
|
|
2
16
|
// command never taxes the others (or --version/--help). These names are reserved: a named
|
|
3
17
|
// query in config can never shadow them.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/cli/index.ts"],"sourcesContent":["import type { Command } from './types.ts';\n\n// Lazy registry: a command's imports load only when it runs, so a heavy dependency in one\n// command never taxes the others (or --version/--help). These names are reserved: a named\n// query in config can never shadow them.\nexport const COMMANDS: Record<string, () => Promise<{ default: Command }>> = {\n init: () => import('./init.ts'),\n watch: () => import('./watch.ts'),\n status: () => import('./status.ts'),\n check: () => import('./check.ts'),\n rebuild: () => import('./rebuild.ts'),\n query: () => import('./query.ts'),\n search: () => import('./search.ts'),\n map: () => import('./map.ts'),\n peek: () => import('./peek.ts'),\n};\n\nexport type { Command, Ctx } from './types.ts';\n"],"names":["
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/cli/index.ts"],"sourcesContent":["import type { Command } from './types.ts';\n\n// Each command's usage line, minus the leading \"usage: <name> \" -- shared by cli.ts's\n// top-level usage() and the command's own parse() error/--help output, so there is one\n// copy of each line, not two that can drift.\nexport const USAGE = {\n init: 'init',\n watch: 'watch [--force] [--config path]',\n status: 'status [--format table|json] [--config path]',\n check: 'check [--format table|json] [--config path]',\n rebuild: 'rebuild [--config path]',\n query: 'query \"<sql>\" [params...] [--format table|json] [--config path]',\n search: 'search \"<terms>\" [--preset name] [--include glob ...] [--where \"<sql>\"] [--k n] [--lexical] [--format table|json] [--config path]',\n map: 'map [--format table|json] [--config path]',\n peek: 'peek <path> [--format table|json] [--config path]',\n} as const;\n\n// Lazy registry: a command's imports load only when it runs, so a heavy dependency in one\n// command never taxes the others (or --version/--help). These names are reserved: a named\n// query in config can never shadow them.\nexport const COMMANDS: Record<string, () => Promise<{ default: Command }>> = {\n init: () => import('./init.ts'),\n watch: () => import('./watch.ts'),\n status: () => import('./status.ts'),\n check: () => import('./check.ts'),\n rebuild: () => import('./rebuild.ts'),\n query: () => import('./query.ts'),\n search: () => import('./search.ts'),\n map: () => import('./map.ts'),\n peek: () => import('./peek.ts'),\n};\n\nexport type { Command, Ctx } from './types.ts';\n"],"names":["USAGE","init","watch","status","check","rebuild","query","search","map","peek","COMMANDS"],"mappings":"AAEA,sFAAsF;AACtF,uFAAuF;AACvF,6CAA6C;AAC7C,OAAO,MAAMA,QAAQ;IACnBC,MAAM;IACNC,OAAO;IACPC,QAAQ;IACRC,OAAO;IACPC,SAAS;IACTC,OAAO;IACPC,QAAQ;IACRC,KAAK;IACLC,MAAM;AACR,EAAW;AAEX,0FAA0F;AAC1F,0FAA0F;AAC1F,yCAAyC;AACzC,OAAO,MAAMC,WAAgE;IAC3ET,MAAM,IAAM,MAAM,CAAC;IACnBC,OAAO,IAAM,MAAM,CAAC;IACpBC,QAAQ,IAAM,MAAM,CAAC;IACrBC,OAAO,IAAM,MAAM,CAAC;IACpBC,SAAS,IAAM,MAAM,CAAC;IACtBC,OAAO,IAAM,MAAM,CAAC;IACpBC,QAAQ,IAAM,MAAM,CAAC;IACrBC,KAAK,IAAM,MAAM,CAAC;IAClBC,MAAM,IAAM,MAAM,CAAC;AACrB,EAAE"}
|
package/dist/esm/cli/init.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { initConfig } from '../config.js';
|
|
2
|
+
import { USAGE } from './index.js';
|
|
3
|
+
import { parse } from './shared.js';
|
|
2
4
|
const init = (ctx)=>{
|
|
5
|
+
parse(ctx.argv, `usage: ${ctx.name} ${USAGE.init}`, {});
|
|
3
6
|
const configPath = initConfig(process.cwd());
|
|
4
7
|
console.log(`created ${configPath}`);
|
|
5
8
|
console.log(`query away: ${ctx.name} query "SELECT path FROM frontmatter LIMIT 10"`);
|
package/dist/esm/cli/init.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/cli/init.ts"],"sourcesContent":["import { initConfig } from '../config.ts';\nimport type { Command } from './types.ts';\n\nconst init: Command = (ctx) => {\n const configPath = initConfig(process.cwd());\n console.log(`created ${configPath}`);\n console.log(`query away: ${ctx.name} query \"SELECT path FROM frontmatter LIMIT 10\"`);\n // The decisions a new tree faces -- features, frontmatter conventions, note size -- are not\n // in this output; name both places that hold them, since an agent may have neither.\n console.log('features and tree design: the sense-setup skill, or schema.json');\n};\nexport default init;\n"],"names":["initConfig","init","ctx","configPath","process","cwd","console","log"
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/cli/init.ts"],"sourcesContent":["import { initConfig } from '../config.ts';\nimport { USAGE } from './index.ts';\nimport { parse } from './shared.ts';\nimport type { Command } from './types.ts';\n\nconst init: Command = (ctx) => {\n parse(ctx.argv, `usage: ${ctx.name} ${USAGE.init}`, {});\n const configPath = initConfig(process.cwd());\n console.log(`created ${configPath}`);\n console.log(`query away: ${ctx.name} query \"SELECT path FROM frontmatter LIMIT 10\"`);\n // The decisions a new tree faces -- features, frontmatter conventions, note size -- are not\n // in this output; name both places that hold them, since an agent may have neither.\n console.log('features and tree design: the sense-setup skill, or schema.json');\n};\nexport default init;\n"],"names":["initConfig","USAGE","parse","init","ctx","argv","name","configPath","process","cwd","console","log"],"mappings":"AAAA,SAASA,UAAU,QAAQ,eAAe;AAC1C,SAASC,KAAK,QAAQ,aAAa;AACnC,SAASC,KAAK,QAAQ,cAAc;AAGpC,MAAMC,OAAgB,CAACC;IACrBF,MAAME,IAAIC,IAAI,EAAE,CAAC,OAAO,EAAED,IAAIE,IAAI,CAAC,CAAC,EAAEL,MAAME,IAAI,EAAE,EAAE,CAAC;IACrD,MAAMI,aAAaP,WAAWQ,QAAQC,GAAG;IACzCC,QAAQC,GAAG,CAAC,CAAC,QAAQ,EAAEJ,YAAY;IACnCG,QAAQC,GAAG,CAAC,CAAC,YAAY,EAAEP,IAAIE,IAAI,CAAC,8CAA8C,CAAC;IACnF,4FAA4F;IAC5F,oFAAoF;IACpFI,QAAQC,GAAG,CAAC;AACd;AACA,eAAeR,KAAK"}
|
package/dist/esm/cli/map.js
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
import { mapTree } from '../commands.js';
|
|
2
2
|
import { renderMap } from '../output.js';
|
|
3
|
-
import {
|
|
4
|
-
|
|
3
|
+
import { USAGE } from './index.js';
|
|
4
|
+
import { CONFIG, FORMAT, formatOf, parse, withDb } from './shared.js';
|
|
5
|
+
const map = (ctx)=>{
|
|
6
|
+
const { values } = parse(ctx.argv, `usage: ${ctx.name} ${USAGE.map}`, {
|
|
7
|
+
...FORMAT,
|
|
8
|
+
...CONFIG
|
|
9
|
+
});
|
|
10
|
+
const format = formatOf(values);
|
|
11
|
+
return withDb(ctx, values.config, (db, cfg)=>{
|
|
5
12
|
const result = mapTree(db, cfg);
|
|
6
|
-
console.log(
|
|
13
|
+
console.log(format === 'json' ? JSON.stringify(result, null, 2) : renderMap(result));
|
|
7
14
|
});
|
|
15
|
+
};
|
|
8
16
|
export default map;
|
package/dist/esm/cli/map.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/cli/map.ts"],"sourcesContent":["import { mapTree } from '../commands.ts';\nimport { renderMap } from '../output.ts';\nimport { withDb } from './shared.ts';\nimport type { Command } from './types.ts';\n\nconst map: Command = (ctx)
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/cli/map.ts"],"sourcesContent":["import { mapTree } from '../commands.ts';\nimport { renderMap } from '../output.ts';\nimport { USAGE } from './index.ts';\nimport { CONFIG, FORMAT, formatOf, parse, withDb } from './shared.ts';\nimport type { Command } from './types.ts';\n\nconst map: Command = (ctx) => {\n const { values } = parse(ctx.argv, `usage: ${ctx.name} ${USAGE.map}`, { ...FORMAT, ...CONFIG });\n const format = formatOf(values);\n return withDb(ctx, values.config as string | undefined, (db, cfg) => {\n const result = mapTree(db, cfg);\n console.log(format === 'json' ? JSON.stringify(result, null, 2) : renderMap(result));\n });\n};\nexport default map;\n"],"names":["mapTree","renderMap","USAGE","CONFIG","FORMAT","formatOf","parse","withDb","map","ctx","values","argv","name","format","config","db","cfg","result","console","log","JSON","stringify"],"mappings":"AAAA,SAASA,OAAO,QAAQ,iBAAiB;AACzC,SAASC,SAAS,QAAQ,eAAe;AACzC,SAASC,KAAK,QAAQ,aAAa;AACnC,SAASC,MAAM,EAAEC,MAAM,EAAEC,QAAQ,EAAEC,KAAK,EAAEC,MAAM,QAAQ,cAAc;AAGtE,MAAMC,MAAe,CAACC;IACpB,MAAM,EAAEC,MAAM,EAAE,GAAGJ,MAAMG,IAAIE,IAAI,EAAE,CAAC,OAAO,EAAEF,IAAIG,IAAI,CAAC,CAAC,EAAEV,MAAMM,GAAG,EAAE,EAAE;QAAE,GAAGJ,MAAM;QAAE,GAAGD,MAAM;IAAC;IAC7F,MAAMU,SAASR,SAASK;IACxB,OAAOH,OAAOE,KAAKC,OAAOI,MAAM,EAAwB,CAACC,IAAIC;QAC3D,MAAMC,SAASjB,QAAQe,IAAIC;QAC3BE,QAAQC,GAAG,CAACN,WAAW,SAASO,KAAKC,SAAS,CAACJ,QAAQ,MAAM,KAAKhB,UAAUgB;IAC9E;AACF;AACA,eAAeT,IAAI"}
|
package/dist/esm/cli/named.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { Ctx } from './types.js';
|
|
2
|
-
export default function named(ctx: Ctx, queryName: string
|
|
2
|
+
export default function named(ctx: Ctx, queryName: string): Promise<void>;
|
package/dist/esm/cli/named.js
CHANGED
|
@@ -1,41 +1,48 @@
|
|
|
1
1
|
import { search } from '../commands.js';
|
|
2
2
|
import { printRows } from '../output.js';
|
|
3
|
-
import {
|
|
3
|
+
import { usageError } from './exit.js';
|
|
4
|
+
import { CONFIG, FORMAT, formatOf, parse, parseK, runSql, SEARCH_FLAGS, withDb } from './shared.js';
|
|
4
5
|
// Fallback when the first positional is not a command: a named query from config, either a
|
|
5
6
|
// SQL string (run as-is) or a saved search (run through the `search` command's own machinery).
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
// Flags cover both shapes -- SEARCH_FLAGS override a saved search's fields the same way they
|
|
8
|
+
// override a preset's.
|
|
9
|
+
export default async function named(ctx, queryName) {
|
|
10
|
+
var _parseK, _values_where, _values_preset, _values_include;
|
|
11
|
+
const usage = `usage: ${ctx.name} ${queryName} [params...] [--format table|json] [--config path] [--where "<sql>"] [--k n] [--preset name] [--include glob ...] [--lexical]`;
|
|
12
|
+
const { values, positionals: params } = parse(ctx.argv, usage, {
|
|
13
|
+
...SEARCH_FLAGS,
|
|
14
|
+
...FORMAT,
|
|
15
|
+
...CONFIG
|
|
16
|
+
});
|
|
17
|
+
const format = formatOf(values);
|
|
18
|
+
const configPath = values.config;
|
|
19
|
+
const cfg = ctx.resolveConfig(configPath);
|
|
9
20
|
const entry = cfg.queries[queryName];
|
|
10
|
-
if (entry === undefined) {
|
|
11
|
-
console.error(`unknown query: "${queryName}"`);
|
|
12
|
-
console.error(`valid queries: ${Object.keys(cfg.queries).sort().join(', ')}`);
|
|
13
|
-
process.exit(2);
|
|
14
|
-
}
|
|
21
|
+
if (entry === undefined) usageError(`unknown query: "${queryName}"`, `valid queries: ${Object.keys(cfg.queries).sort().join(', ')}`);
|
|
15
22
|
if (typeof entry === 'string') {
|
|
16
|
-
runSql(cfg, entry, params,
|
|
23
|
+
runSql(cfg, entry, params, format, `query "${queryName}"`);
|
|
17
24
|
return;
|
|
18
25
|
}
|
|
19
26
|
if ('sql' in entry) {
|
|
20
|
-
runSql(cfg, entry.sql, params,
|
|
27
|
+
runSql(cfg, entry.sql, params, format, `query "${queryName}"`);
|
|
21
28
|
return;
|
|
22
29
|
}
|
|
23
30
|
// A saved search's text is fixed in config; there is nowhere for a positional to bind.
|
|
24
31
|
if (params.length > 0) {
|
|
25
32
|
ctx.usageError(`"${queryName}" is a saved search and takes no positional parameters; edit its "search" in sense.config.json, or use "${ctx.name} search" directly`);
|
|
26
33
|
}
|
|
27
|
-
const k = (_parseK = parseK(ctx)) !== null && _parseK !== void 0 ? _parseK : entry.k;
|
|
28
|
-
const where = (
|
|
29
|
-
const preset = (
|
|
30
|
-
const include = (
|
|
34
|
+
const k = (_parseK = parseK(values.k, ctx.usageError)) !== null && _parseK !== void 0 ? _parseK : entry.k;
|
|
35
|
+
const where = (_values_where = values.where) !== null && _values_where !== void 0 ? _values_where : entry.where;
|
|
36
|
+
const preset = (_values_preset = values.preset) !== null && _values_preset !== void 0 ? _values_preset : entry.preset;
|
|
37
|
+
const include = (_values_include = values.include) !== null && _values_include !== void 0 ? _values_include : entry.include;
|
|
31
38
|
// --lexical upgrades a saved search's semantic behavior the same way --where/--k
|
|
32
39
|
// override; absent means the saved value (the flag has no default false override).
|
|
33
|
-
const semantic =
|
|
34
|
-
await withDb(ctx, async (db, resolvedCfg)=>printRows(await search(db, resolvedCfg, entry.search, {
|
|
40
|
+
const semantic = values.lexical ? false : entry.semantic;
|
|
41
|
+
await withDb(ctx, configPath, async (db, resolvedCfg)=>printRows(await search(db, resolvedCfg, entry.search, {
|
|
35
42
|
k,
|
|
36
43
|
where,
|
|
37
44
|
preset,
|
|
38
45
|
include,
|
|
39
46
|
semantic
|
|
40
|
-
}),
|
|
47
|
+
}), format));
|
|
41
48
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/cli/named.ts"],"sourcesContent":["import { search } from '../commands.ts';\nimport { printRows } from '../output.ts';\nimport { parseK, runSql, withDb } from './shared.ts';\nimport type { Ctx } from './types.ts';\n\n// Fallback when the first positional is not a command: a named query from config, either a\n// SQL string (run as-is) or a saved search (run through the `search` command's own machinery).\nexport default async function named(ctx: Ctx, queryName: string
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/cli/named.ts"],"sourcesContent":["import { search } from '../commands.ts';\nimport { printRows } from '../output.ts';\nimport { usageError } from './exit.ts';\nimport { CONFIG, FORMAT, formatOf, parse, parseK, runSql, SEARCH_FLAGS, withDb } from './shared.ts';\nimport type { Ctx } from './types.ts';\n\n// Fallback when the first positional is not a command: a named query from config, either a\n// SQL string (run as-is) or a saved search (run through the `search` command's own machinery).\n// Flags cover both shapes -- SEARCH_FLAGS override a saved search's fields the same way they\n// override a preset's.\nexport default async function named(ctx: Ctx, queryName: string): Promise<void> {\n const usage = `usage: ${ctx.name} ${queryName} [params...] [--format table|json] [--config path] [--where \"<sql>\"] [--k n] [--preset name] [--include glob ...] [--lexical]`;\n const { values, positionals: params } = parse(ctx.argv, usage, { ...SEARCH_FLAGS, ...FORMAT, ...CONFIG });\n const format = formatOf(values);\n const configPath = values.config as string | undefined;\n\n const cfg = ctx.resolveConfig(configPath);\n const entry = cfg.queries[queryName];\n if (entry === undefined) usageError(`unknown query: \"${queryName}\"`, `valid queries: ${Object.keys(cfg.queries).sort().join(', ')}`);\n\n if (typeof entry === 'string') {\n runSql(cfg, entry, params, format, `query \"${queryName}\"`);\n return;\n }\n if ('sql' in entry) {\n runSql(cfg, entry.sql, params, format, `query \"${queryName}\"`);\n return;\n }\n\n // A saved search's text is fixed in config; there is nowhere for a positional to bind.\n if (params.length > 0) {\n ctx.usageError(`\"${queryName}\" is a saved search and takes no positional parameters; edit its \"search\" in sense.config.json, or use \"${ctx.name} search\" directly`);\n }\n const k = parseK(values.k as string | undefined, ctx.usageError) ?? entry.k;\n const where = (values.where as string | undefined) ?? entry.where;\n const preset = (values.preset as string | undefined) ?? entry.preset;\n const include = (values.include as string[] | undefined) ?? entry.include;\n // --lexical upgrades a saved search's semantic behavior the same way --where/--k\n // override; absent means the saved value (the flag has no default false override).\n const semantic = values.lexical ? false : entry.semantic;\n await withDb(ctx, configPath, async (db, resolvedCfg) => printRows(await search(db, resolvedCfg, entry.search, { k, where, preset, include, semantic }), format));\n}\n"],"names":["search","printRows","usageError","CONFIG","FORMAT","formatOf","parse","parseK","runSql","SEARCH_FLAGS","withDb","named","ctx","queryName","values","usage","name","positionals","params","argv","format","configPath","config","cfg","resolveConfig","entry","queries","undefined","Object","keys","sort","join","sql","length","k","where","preset","include","semantic","lexical","db","resolvedCfg"],"mappings":"AAAA,SAASA,MAAM,QAAQ,iBAAiB;AACxC,SAASC,SAAS,QAAQ,eAAe;AACzC,SAASC,UAAU,QAAQ,YAAY;AACvC,SAASC,MAAM,EAAEC,MAAM,EAAEC,QAAQ,EAAEC,KAAK,EAAEC,MAAM,EAAEC,MAAM,EAAEC,YAAY,EAAEC,MAAM,QAAQ,cAAc;AAGpG,2FAA2F;AAC3F,+FAA+F;AAC/F,6FAA6F;AAC7F,uBAAuB;AACvB,eAAe,eAAeC,MAAMC,GAAQ,EAAEC,SAAiB;QAuBnDN,SACKO,eACCA,gBACCA;IAzBjB,MAAMC,QAAQ,CAAC,OAAO,EAAEH,IAAII,IAAI,CAAC,CAAC,EAAEH,UAAU,6HAA6H,CAAC;IAC5K,MAAM,EAAEC,MAAM,EAAEG,aAAaC,MAAM,EAAE,GAAGZ,MAAMM,IAAIO,IAAI,EAAEJ,OAAO;QAAE,GAAGN,YAAY;QAAE,GAAGL,MAAM;QAAE,GAAGD,MAAM;IAAC;IACvG,MAAMiB,SAASf,SAASS;IACxB,MAAMO,aAAaP,OAAOQ,MAAM;IAEhC,MAAMC,MAAMX,IAAIY,aAAa,CAACH;IAC9B,MAAMI,QAAQF,IAAIG,OAAO,CAACb,UAAU;IACpC,IAAIY,UAAUE,WAAWzB,WAAW,CAAC,gBAAgB,EAAEW,UAAU,CAAC,CAAC,EAAE,CAAC,eAAe,EAAEe,OAAOC,IAAI,CAACN,IAAIG,OAAO,EAAEI,IAAI,GAAGC,IAAI,CAAC,OAAO;IAEnI,IAAI,OAAON,UAAU,UAAU;QAC7BjB,OAAOe,KAAKE,OAAOP,QAAQE,QAAQ,CAAC,OAAO,EAAEP,UAAU,CAAC,CAAC;QACzD;IACF;IACA,IAAI,SAASY,OAAO;QAClBjB,OAAOe,KAAKE,MAAMO,GAAG,EAAEd,QAAQE,QAAQ,CAAC,OAAO,EAAEP,UAAU,CAAC,CAAC;QAC7D;IACF;IAEA,uFAAuF;IACvF,IAAIK,OAAOe,MAAM,GAAG,GAAG;QACrBrB,IAAIV,UAAU,CAAC,CAAC,CAAC,EAAEW,UAAU,wGAAwG,EAAED,IAAII,IAAI,CAAC,iBAAiB,CAAC;IACpK;IACA,MAAMkB,KAAI3B,UAAAA,OAAOO,OAAOoB,CAAC,EAAwBtB,IAAIV,UAAU,eAArDK,qBAAAA,UAA0DkB,MAAMS,CAAC;IAC3E,MAAMC,SAASrB,gBAAAA,OAAOqB,KAAK,cAAZrB,2BAAAA,gBAAuCW,MAAMU,KAAK;IACjE,MAAMC,UAAUtB,iBAAAA,OAAOsB,MAAM,cAAbtB,4BAAAA,iBAAwCW,MAAMW,MAAM;IACpE,MAAMC,WAAWvB,kBAAAA,OAAOuB,OAAO,cAAdvB,6BAAAA,kBAA2CW,MAAMY,OAAO;IACzE,iFAAiF;IACjF,mFAAmF;IACnF,MAAMC,WAAWxB,OAAOyB,OAAO,GAAG,QAAQd,MAAMa,QAAQ;IACxD,MAAM5B,OAAOE,KAAKS,YAAY,OAAOmB,IAAIC,cAAgBxC,UAAU,MAAMD,OAAOwC,IAAIC,aAAahB,MAAMzB,MAAM,EAAE;YAAEkC;YAAGC;YAAOC;YAAQC;YAASC;QAAS,IAAIlB;AAC3J"}
|
package/dist/esm/cli/peek.js
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
import { peek } from '../commands.js';
|
|
2
2
|
import { renderPeek } from '../output.js';
|
|
3
|
-
import {
|
|
3
|
+
import { USAGE } from './index.js';
|
|
4
|
+
import { CONFIG, FORMAT, formatOf, parse, withDb } from './shared.js';
|
|
4
5
|
const peekCmd = (ctx)=>{
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
const usage = `usage: ${ctx.name} ${USAGE.peek}`;
|
|
7
|
+
const { values, positionals } = parse(ctx.argv, usage, {
|
|
8
|
+
...FORMAT,
|
|
9
|
+
...CONFIG
|
|
10
|
+
});
|
|
11
|
+
const [pathArg] = positionals;
|
|
12
|
+
if (!pathArg) ctx.usageError(usage);
|
|
13
|
+
const format = formatOf(values);
|
|
14
|
+
return withDb(ctx, values.config, (db, cfg)=>{
|
|
8
15
|
const result = peek(db, cfg, pathArg);
|
|
9
|
-
console.log(
|
|
16
|
+
console.log(format === 'json' ? JSON.stringify(result, null, 2) : renderPeek(result));
|
|
10
17
|
});
|
|
11
18
|
};
|
|
12
19
|
export default peekCmd;
|
package/dist/esm/cli/peek.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/cli/peek.ts"],"sourcesContent":["import { peek } from '../commands.ts';\nimport { renderPeek } from '../output.ts';\nimport { withDb } from './shared.ts';\nimport type { Command } from './types.ts';\n\nconst peekCmd: Command = (ctx) => {\n const [pathArg] =
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/cli/peek.ts"],"sourcesContent":["import { peek } from '../commands.ts';\nimport { renderPeek } from '../output.ts';\nimport { USAGE } from './index.ts';\nimport { CONFIG, FORMAT, formatOf, parse, withDb } from './shared.ts';\nimport type { Command } from './types.ts';\n\nconst peekCmd: Command = (ctx) => {\n const usage = `usage: ${ctx.name} ${USAGE.peek}`;\n const { values, positionals } = parse(ctx.argv, usage, { ...FORMAT, ...CONFIG });\n const [pathArg] = positionals;\n if (!pathArg) ctx.usageError(usage);\n const format = formatOf(values);\n return withDb(ctx, values.config as string | undefined, (db, cfg) => {\n const result = peek(db, cfg, pathArg);\n console.log(format === 'json' ? JSON.stringify(result, null, 2) : renderPeek(result));\n });\n};\nexport default peekCmd;\n"],"names":["peek","renderPeek","USAGE","CONFIG","FORMAT","formatOf","parse","withDb","peekCmd","ctx","usage","name","values","positionals","argv","pathArg","usageError","format","config","db","cfg","result","console","log","JSON","stringify"],"mappings":"AAAA,SAASA,IAAI,QAAQ,iBAAiB;AACtC,SAASC,UAAU,QAAQ,eAAe;AAC1C,SAASC,KAAK,QAAQ,aAAa;AACnC,SAASC,MAAM,EAAEC,MAAM,EAAEC,QAAQ,EAAEC,KAAK,EAAEC,MAAM,QAAQ,cAAc;AAGtE,MAAMC,UAAmB,CAACC;IACxB,MAAMC,QAAQ,CAAC,OAAO,EAAED,IAAIE,IAAI,CAAC,CAAC,EAAET,MAAMF,IAAI,EAAE;IAChD,MAAM,EAAEY,MAAM,EAAEC,WAAW,EAAE,GAAGP,MAAMG,IAAIK,IAAI,EAAEJ,OAAO;QAAE,GAAGN,MAAM;QAAE,GAAGD,MAAM;IAAC;IAC9E,MAAM,CAACY,QAAQ,GAAGF;IAClB,IAAI,CAACE,SAASN,IAAIO,UAAU,CAACN;IAC7B,MAAMO,SAASZ,SAASO;IACxB,OAAOL,OAAOE,KAAKG,OAAOM,MAAM,EAAwB,CAACC,IAAIC;QAC3D,MAAMC,SAASrB,KAAKmB,IAAIC,KAAKL;QAC7BO,QAAQC,GAAG,CAACN,WAAW,SAASO,KAAKC,SAAS,CAACJ,QAAQ,MAAM,KAAKpB,WAAWoB;IAC/E;AACF;AACA,eAAeb,QAAQ"}
|
package/dist/esm/cli/query.js
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { USAGE } from './index.js';
|
|
2
|
+
import { CONFIG, FORMAT, formatOf, parse, runSql } from './shared.js';
|
|
2
3
|
const query = (ctx)=>{
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
const usage = `usage: ${ctx.name} ${USAGE.query}`;
|
|
5
|
+
const { values, positionals } = parse(ctx.argv, usage, {
|
|
6
|
+
...FORMAT,
|
|
7
|
+
...CONFIG
|
|
8
|
+
});
|
|
9
|
+
const [sql, ...params] = positionals;
|
|
10
|
+
if (!sql) ctx.usageError(usage);
|
|
11
|
+
const format = formatOf(values);
|
|
12
|
+
runSql(ctx.resolveConfig(values.config), sql, params, format, 'ad-hoc query');
|
|
6
13
|
};
|
|
7
14
|
export default query;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/cli/query.ts"],"sourcesContent":["import { runSql } from './shared.ts';\nimport type { Command } from './types.ts';\n\nconst query: Command = (ctx) => {\n const [sql, ...params] =
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/cli/query.ts"],"sourcesContent":["import { USAGE } from './index.ts';\nimport { CONFIG, FORMAT, formatOf, parse, runSql } from './shared.ts';\nimport type { Command } from './types.ts';\n\nconst query: Command = (ctx) => {\n const usage = `usage: ${ctx.name} ${USAGE.query}`;\n const { values, positionals } = parse(ctx.argv, usage, { ...FORMAT, ...CONFIG });\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 query');\n};\nexport default query;\n"],"names":["USAGE","CONFIG","FORMAT","formatOf","parse","runSql","query","ctx","usage","name","values","positionals","argv","sql","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,QAAiB,CAACC;IACtB,MAAMC,QAAQ,CAAC,OAAO,EAAED,IAAIE,IAAI,CAAC,CAAC,EAAET,MAAMM,KAAK,EAAE;IACjD,MAAM,EAAEI,MAAM,EAAEC,WAAW,EAAE,GAAGP,MAAMG,IAAIK,IAAI,EAAEJ,OAAO;QAAE,GAAGN,MAAM;QAAE,GAAGD,MAAM;IAAC;IAC9E,MAAM,CAACY,KAAK,GAAGC,OAAO,GAAGH;IACzB,IAAI,CAACE,KAAKN,IAAIQ,UAAU,CAACP;IACzB,MAAMQ,SAASb,SAASO;IACxBL,OAAOE,IAAIU,aAAa,CAACP,OAAOQ,MAAM,GAAyBL,KAAKC,QAAQE,QAAQ;AACtF;AACA,eAAeV,MAAM"}
|
package/dist/esm/cli/rebuild.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { docCount, rebuild } from '../db.js';
|
|
2
|
-
import {
|
|
2
|
+
import { USAGE } from './index.js';
|
|
3
|
+
import { CONFIG, parse, printWarnings } from './shared.js';
|
|
3
4
|
const rebuildCmd = (ctx)=>{
|
|
4
|
-
const
|
|
5
|
+
const { values } = parse(ctx.argv, `usage: ${ctx.name} ${USAGE.rebuild}`, {
|
|
6
|
+
...CONFIG
|
|
7
|
+
});
|
|
8
|
+
const result = rebuild(ctx.resolveConfig(values.config));
|
|
5
9
|
printWarnings(result.warnings);
|
|
6
10
|
console.log(`rebuilt: ${docCount(result.db)} docs`);
|
|
7
11
|
result.db.close();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/cli/rebuild.ts"],"sourcesContent":["import { docCount, rebuild } from '../db.ts';\nimport { printWarnings } from './shared.ts';\nimport type { Command } from './types.ts';\n\nconst rebuildCmd: Command = (ctx) => {\n const result = rebuild(ctx.resolveConfig());\n printWarnings(result.warnings);\n console.log(`rebuilt: ${docCount(result.db)} docs`);\n result.db.close();\n};\nexport default rebuildCmd;\n"],"names":["docCount","rebuild","printWarnings","rebuildCmd","ctx","result","resolveConfig","warnings","console","log","db","close"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,OAAO,QAAQ,WAAW;AAC7C,SAASC,aAAa,QAAQ,cAAc;
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/cli/rebuild.ts"],"sourcesContent":["import { docCount, rebuild } from '../db.ts';\nimport { USAGE } from './index.ts';\nimport { CONFIG, parse, printWarnings } from './shared.ts';\nimport type { Command } from './types.ts';\n\nconst rebuildCmd: Command = (ctx) => {\n const { values } = parse(ctx.argv, `usage: ${ctx.name} ${USAGE.rebuild}`, { ...CONFIG });\n const result = rebuild(ctx.resolveConfig(values.config as string | undefined));\n printWarnings(result.warnings);\n console.log(`rebuilt: ${docCount(result.db)} docs`);\n result.db.close();\n};\nexport default rebuildCmd;\n"],"names":["docCount","rebuild","USAGE","CONFIG","parse","printWarnings","rebuildCmd","ctx","values","argv","name","result","resolveConfig","config","warnings","console","log","db","close"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,OAAO,QAAQ,WAAW;AAC7C,SAASC,KAAK,QAAQ,aAAa;AACnC,SAASC,MAAM,EAAEC,KAAK,EAAEC,aAAa,QAAQ,cAAc;AAG3D,MAAMC,aAAsB,CAACC;IAC3B,MAAM,EAAEC,MAAM,EAAE,GAAGJ,MAAMG,IAAIE,IAAI,EAAE,CAAC,OAAO,EAAEF,IAAIG,IAAI,CAAC,CAAC,EAAER,MAAMD,OAAO,EAAE,EAAE;QAAE,GAAGE,MAAM;IAAC;IACtF,MAAMQ,SAASV,QAAQM,IAAIK,aAAa,CAACJ,OAAOK,MAAM;IACtDR,cAAcM,OAAOG,QAAQ;IAC7BC,QAAQC,GAAG,CAAC,CAAC,SAAS,EAAEhB,SAASW,OAAOM,EAAE,EAAE,KAAK,CAAC;IAClDN,OAAOM,EAAE,CAACC,KAAK;AACjB;AACA,eAAeZ,WAAW"}
|
package/dist/esm/cli/search.js
CHANGED
|
@@ -1,16 +1,24 @@
|
|
|
1
1
|
import { search } from '../commands.js';
|
|
2
2
|
import { printRows } from '../output.js';
|
|
3
|
-
import {
|
|
3
|
+
import { USAGE } from './index.js';
|
|
4
|
+
import { CONFIG, FORMAT, formatOf, parse, parseK, SEARCH_FLAGS, withDb } from './shared.js';
|
|
4
5
|
const searchCmd = async (ctx)=>{
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
const usage = `usage: ${ctx.name} ${USAGE.search}`;
|
|
7
|
+
const { values, positionals } = parse(ctx.argv, usage, {
|
|
8
|
+
...SEARCH_FLAGS,
|
|
9
|
+
...FORMAT,
|
|
10
|
+
...CONFIG
|
|
11
|
+
});
|
|
12
|
+
const [terms] = positionals;
|
|
13
|
+
if (!terms) ctx.usageError(usage);
|
|
14
|
+
const k = parseK(values.k, ctx.usageError);
|
|
15
|
+
const format = formatOf(values);
|
|
16
|
+
await withDb(ctx, values.config, async (db, cfg)=>printRows(await search(db, cfg, terms, {
|
|
9
17
|
k,
|
|
10
|
-
where:
|
|
11
|
-
preset:
|
|
12
|
-
include:
|
|
13
|
-
semantic:
|
|
14
|
-
}),
|
|
18
|
+
where: values.where,
|
|
19
|
+
preset: values.preset,
|
|
20
|
+
include: values.include,
|
|
21
|
+
semantic: values.lexical ? false : undefined
|
|
22
|
+
}), format));
|
|
15
23
|
};
|
|
16
24
|
export default searchCmd;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/cli/search.ts"],"sourcesContent":["import { search } from '../commands.ts';\nimport { printRows } from '../output.ts';\nimport { parseK, withDb } from './shared.ts';\nimport type { Command } from './types.ts';\n\nconst searchCmd: Command = async (ctx) => {\n const
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/cli/search.ts"],"sourcesContent":["import { search } from '../commands.ts';\nimport { printRows } from '../output.ts';\nimport { USAGE } from './index.ts';\nimport { CONFIG, FORMAT, formatOf, parse, parseK, SEARCH_FLAGS, withDb } from './shared.ts';\nimport type { Command } from './types.ts';\n\nconst searchCmd: Command = async (ctx) => {\n const usage = `usage: ${ctx.name} ${USAGE.search}`;\n const { values, positionals } = parse(ctx.argv, usage, { ...SEARCH_FLAGS, ...FORMAT, ...CONFIG });\n const [terms] = positionals;\n if (!terms) ctx.usageError(usage);\n const k = parseK(values.k as string | undefined, ctx.usageError);\n const format = formatOf(values);\n await withDb(ctx, values.config as string | undefined, async (db, cfg) => printRows(await search(db, cfg, terms, { k, where: values.where as string | undefined, preset: values.preset as string | undefined, include: values.include as string[] | undefined, semantic: values.lexical ? false : undefined }), format));\n};\nexport default searchCmd;\n"],"names":["search","printRows","USAGE","CONFIG","FORMAT","formatOf","parse","parseK","SEARCH_FLAGS","withDb","searchCmd","ctx","usage","name","values","positionals","argv","terms","usageError","k","format","config","db","cfg","where","preset","include","semantic","lexical","undefined"],"mappings":"AAAA,SAASA,MAAM,QAAQ,iBAAiB;AACxC,SAASC,SAAS,QAAQ,eAAe;AACzC,SAASC,KAAK,QAAQ,aAAa;AACnC,SAASC,MAAM,EAAEC,MAAM,EAAEC,QAAQ,EAAEC,KAAK,EAAEC,MAAM,EAAEC,YAAY,EAAEC,MAAM,QAAQ,cAAc;AAG5F,MAAMC,YAAqB,OAAOC;IAChC,MAAMC,QAAQ,CAAC,OAAO,EAAED,IAAIE,IAAI,CAAC,CAAC,EAAEX,MAAMF,MAAM,EAAE;IAClD,MAAM,EAAEc,MAAM,EAAEC,WAAW,EAAE,GAAGT,MAAMK,IAAIK,IAAI,EAAEJ,OAAO;QAAE,GAAGJ,YAAY;QAAE,GAAGJ,MAAM;QAAE,GAAGD,MAAM;IAAC;IAC/F,MAAM,CAACc,MAAM,GAAGF;IAChB,IAAI,CAACE,OAAON,IAAIO,UAAU,CAACN;IAC3B,MAAMO,IAAIZ,OAAOO,OAAOK,CAAC,EAAwBR,IAAIO,UAAU;IAC/D,MAAME,SAASf,SAASS;IACxB,MAAML,OAAOE,KAAKG,OAAOO,MAAM,EAAwB,OAAOC,IAAIC,MAAQtB,UAAU,MAAMD,OAAOsB,IAAIC,KAAKN,OAAO;YAAEE;YAAGK,OAAOV,OAAOU,KAAK;YAAwBC,QAAQX,OAAOW,MAAM;YAAwBC,SAASZ,OAAOY,OAAO;YAA0BC,UAAUb,OAAOc,OAAO,GAAG,QAAQC;QAAU,IAAIT;AAClT;AACA,eAAeV,UAAU"}
|
package/dist/esm/cli/shared.d.ts
CHANGED
|
@@ -1,7 +1,23 @@
|
|
|
1
1
|
import type { ResolvedConfig } from '../config.js';
|
|
2
2
|
import type { OpenResult } from '../db.js';
|
|
3
3
|
import type { Ctx } from './types.js';
|
|
4
|
-
export
|
|
4
|
+
export interface Flag {
|
|
5
|
+
type: 'string' | 'boolean';
|
|
6
|
+
default?: string | boolean;
|
|
7
|
+
multiple?: boolean;
|
|
8
|
+
short?: string;
|
|
9
|
+
}
|
|
10
|
+
export type Flags = Record<string, Flag>;
|
|
11
|
+
export declare const FORMAT: Flags;
|
|
12
|
+
export declare const CONFIG: Flags;
|
|
13
|
+
export declare const SEARCH_FLAGS: Flags;
|
|
14
|
+
export type Values = Record<string, string | boolean | string[] | undefined>;
|
|
15
|
+
export declare function formatOf(values: Values): 'table' | 'json';
|
|
16
|
+
export declare function parse(argv: string[], usage: string, flags?: Flags): {
|
|
17
|
+
values: Values;
|
|
18
|
+
positionals: string[];
|
|
19
|
+
};
|
|
20
|
+
export declare function parseK(k: string | undefined, usageErrorFn: (message: string) => never): number | undefined;
|
|
5
21
|
export declare function printWarnings(warnings: string[]): void;
|
|
6
|
-
export declare function withDb(ctx: Ctx, fn: (db: OpenResult['db'], cfg: ResolvedConfig) => void | Promise<void>): Promise<void>;
|
|
22
|
+
export declare function withDb(ctx: Ctx, configPath: string | undefined, fn: (db: OpenResult['db'], cfg: ResolvedConfig) => void | Promise<void>): Promise<void>;
|
|
7
23
|
export declare function runSql(cfg: ResolvedConfig, sql: string, params: string[], format: 'table' | 'json', label: string): void;
|
package/dist/esm/cli/shared.js
CHANGED
|
@@ -1,21 +1,113 @@
|
|
|
1
|
+
import getopts from 'getopts-compat';
|
|
1
2
|
import { open } from '../db.js';
|
|
2
3
|
import { printRows } from '../output.js';
|
|
3
4
|
import { searchError } from '../search-error.js';
|
|
5
|
+
import { ExitError, usageError } from './exit.js';
|
|
6
|
+
export const FORMAT = {
|
|
7
|
+
format: {
|
|
8
|
+
type: 'string',
|
|
9
|
+
default: 'table'
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
export const CONFIG = {
|
|
13
|
+
config: {
|
|
14
|
+
type: 'string'
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
export const SEARCH_FLAGS = {
|
|
18
|
+
where: {
|
|
19
|
+
type: 'string'
|
|
20
|
+
},
|
|
21
|
+
k: {
|
|
22
|
+
type: 'string'
|
|
23
|
+
},
|
|
24
|
+
preset: {
|
|
25
|
+
type: 'string'
|
|
26
|
+
},
|
|
27
|
+
include: {
|
|
28
|
+
type: 'string',
|
|
29
|
+
multiple: true
|
|
30
|
+
},
|
|
31
|
+
lexical: {
|
|
32
|
+
type: 'boolean',
|
|
33
|
+
default: false
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
export function formatOf(values) {
|
|
37
|
+
return values.format === 'json' ? 'json' : 'table';
|
|
38
|
+
}
|
|
39
|
+
// Per-command parse: strict (a foreign flag exits 2), and every table gets --help for free.
|
|
40
|
+
export function parse(argv, usage, flags = {}) {
|
|
41
|
+
const table = {
|
|
42
|
+
...flags,
|
|
43
|
+
help: {
|
|
44
|
+
type: 'boolean',
|
|
45
|
+
default: false,
|
|
46
|
+
short: 'h'
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
const string = [];
|
|
50
|
+
const boolean = [];
|
|
51
|
+
const alias = {};
|
|
52
|
+
const defaults = {};
|
|
53
|
+
for (const [name, flag] of Object.entries(table)){
|
|
54
|
+
(flag.type === 'boolean' ? boolean : string).push(name);
|
|
55
|
+
if (flag.default !== undefined) defaults[name] = flag.default;
|
|
56
|
+
if (flag.short !== undefined) alias[name] = flag.short;
|
|
57
|
+
}
|
|
58
|
+
// getopts is lenient about undeclared flags -- they land in the result and are silently
|
|
59
|
+
// ignored, which is the bug 0.9.2 fixed. Record the first and fail below; returning false
|
|
60
|
+
// also keeps it out of the result. `--k -1` arrives here as unknown option "1", because
|
|
61
|
+
// getopts reads a leading dash as a new option rather than as --k's value; the message is
|
|
62
|
+
// blunter than the old one but it is still a usage error rather than a silent default.
|
|
63
|
+
let unknown;
|
|
64
|
+
const parsed = getopts(argv, {
|
|
65
|
+
string,
|
|
66
|
+
boolean,
|
|
67
|
+
alias,
|
|
68
|
+
default: defaults,
|
|
69
|
+
unknown: (name)=>{
|
|
70
|
+
if (unknown === undefined) unknown = name;
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
if (unknown !== undefined) usageError(`unknown option: ${unknown}`, usage);
|
|
75
|
+
if (parsed.help) {
|
|
76
|
+
console.log(usage);
|
|
77
|
+
throw new ExitError(0);
|
|
78
|
+
}
|
|
79
|
+
// Two getopts shapes the callers must not see: an unset string flag reads as "" rather
|
|
80
|
+
// than undefined, and a flag passed once reads as a string rather than a one-element
|
|
81
|
+
// array. Both matter -- `?? saved.field` means "flag absent", and --include is a list.
|
|
82
|
+
const values = {};
|
|
83
|
+
for (const [name, flag] of Object.entries(table)){
|
|
84
|
+
const raw = parsed[name];
|
|
85
|
+
if (flag.type === 'boolean') values[name] = raw;
|
|
86
|
+
else if (flag.multiple) values[name] = raw === '' ? undefined : Array.isArray(raw) ? raw : [
|
|
87
|
+
raw
|
|
88
|
+
];
|
|
89
|
+
else values[name] = raw === '' ? undefined : raw;
|
|
90
|
+
}
|
|
91
|
+
return {
|
|
92
|
+
values,
|
|
93
|
+
positionals: parsed._
|
|
94
|
+
};
|
|
95
|
+
}
|
|
4
96
|
// --k must be a positive integer: SQLite reads a bound LIMIT of -1 as "unlimited" and 0 as
|
|
5
97
|
// "nothing", and parseInt would silently truncate "5.9" -- all three are caller mistakes
|
|
6
98
|
// worth a usage error, matching the config-level SavedSearch validation.
|
|
7
|
-
export function parseK(
|
|
8
|
-
if (
|
|
9
|
-
const
|
|
10
|
-
if (!Number.isInteger(
|
|
11
|
-
return
|
|
99
|
+
export function parseK(k, usageErrorFn) {
|
|
100
|
+
if (k === undefined) return undefined;
|
|
101
|
+
const parsed = Number(k);
|
|
102
|
+
if (!Number.isInteger(parsed) || parsed <= 0) usageErrorFn(`--k expects a positive integer, got "${k}"`);
|
|
103
|
+
return parsed;
|
|
12
104
|
}
|
|
13
105
|
// Shared open-query-close envelope for commands that touch the tree.
|
|
14
106
|
export function printWarnings(warnings) {
|
|
15
107
|
for (const w of warnings)console.warn(w);
|
|
16
108
|
}
|
|
17
|
-
export async function withDb(ctx, fn) {
|
|
18
|
-
const cfg = ctx.resolveConfig();
|
|
109
|
+
export async function withDb(ctx, configPath, fn) {
|
|
110
|
+
const cfg = ctx.resolveConfig(configPath);
|
|
19
111
|
const { db, warnings } = open(cfg);
|
|
20
112
|
printWarnings(warnings);
|
|
21
113
|
try {
|
|
@@ -28,10 +120,7 @@ export async function withDb(ctx, fn) {
|
|
|
28
120
|
export function runSql(cfg, sql, params, format, label) {
|
|
29
121
|
var _sql_match;
|
|
30
122
|
const placeholderCount = ((_sql_match = sql.match(/\?/g)) !== null && _sql_match !== void 0 ? _sql_match : []).length;
|
|
31
|
-
if (params.length !== placeholderCount) {
|
|
32
|
-
console.error(`${label} expects ${placeholderCount} parameter(s), got ${params.length}`);
|
|
33
|
-
process.exit(2);
|
|
34
|
-
}
|
|
123
|
+
if (params.length !== placeholderCount) usageError(`${label} expects ${placeholderCount} parameter(s), got ${params.length}`);
|
|
35
124
|
const { db, warnings } = open(cfg);
|
|
36
125
|
printWarnings(warnings);
|
|
37
126
|
let rows;
|