sensemaking 0.9.2 → 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 +6 -1
- package/bin/cli.js +5 -1
- package/dist/cjs/cli/check.js +2 -1
- 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/named.js +2 -5
- package/dist/cjs/cli/named.js.map +1 -1
- package/dist/cjs/cli/shared.d.cts +13 -8
- package/dist/cjs/cli/shared.d.ts +13 -8
- package/dist/cjs/cli/shared.js +124 -29
- package/dist/cjs/cli/shared.js.map +1 -1
- package/dist/cjs/cli.js +116 -111
- 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 +2 -1
- 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/named.js +2 -5
- package/dist/esm/cli/named.js.map +1 -1
- package/dist/esm/cli/shared.d.ts +13 -8
- package/dist/esm/cli/shared.js +55 -33
- package/dist/esm/cli/shared.js.map +1 -1
- package/dist/esm/cli.js +68 -74
- 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/cjs/cli.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
Object.defineProperty(exports, //
|
|
5
|
+
Object.defineProperty(exports, // ExitError carries a chosen code; anything else is an error -> exit 1 with its message.
|
|
6
6
|
"default", {
|
|
7
7
|
enumerable: true,
|
|
8
8
|
get: function() {
|
|
@@ -10,7 +10,9 @@ Object.defineProperty(exports, // Thrown errors -> exit 1 with the message verba
|
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
12
|
var _nodemodule = require("node:module");
|
|
13
|
-
var
|
|
13
|
+
var _exitcompat = /*#__PURE__*/ _interop_require_default(require("exit-compat"));
|
|
14
|
+
var _getoptscompat = /*#__PURE__*/ _interop_require_default(require("getopts-compat"));
|
|
15
|
+
var _exitts = require("./cli/exit.js");
|
|
14
16
|
var _indexts = require("./cli/index.js");
|
|
15
17
|
var _configts = require("./config.js");
|
|
16
18
|
function _array_like_to_array(arr, len) {
|
|
@@ -50,6 +52,19 @@ function _async_to_generator(fn) {
|
|
|
50
52
|
});
|
|
51
53
|
};
|
|
52
54
|
}
|
|
55
|
+
function _instanceof(left, right) {
|
|
56
|
+
"@swc/helpers - instanceof";
|
|
57
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
58
|
+
return !!right[Symbol.hasInstance](left);
|
|
59
|
+
} else {
|
|
60
|
+
return left instanceof right;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
function _interop_require_default(obj) {
|
|
64
|
+
return obj && obj.__esModule ? obj : {
|
|
65
|
+
default: obj
|
|
66
|
+
};
|
|
67
|
+
}
|
|
53
68
|
function _getRequireWildcardCache(nodeInterop) {
|
|
54
69
|
if (typeof WeakMap !== "function") return null;
|
|
55
70
|
var cacheBabelInterop = new WeakMap();
|
|
@@ -214,7 +229,7 @@ function _ts_generator(thisArg, body) {
|
|
|
214
229
|
// Parsing and dispatch only. Commands live in src/cli/, one file each, lazy-loaded --
|
|
215
230
|
// nothing tree- or dependency-heavy may be imported at the top of this file. Flags parse
|
|
216
231
|
// per command (each command's own parse() call); this file only handles the bare top-level
|
|
217
|
-
// flags (--version/--help/--list/--config) and dispatch.
|
|
232
|
+
// flags (--version/--help/--list/--config) and dispatch, and owns the single exit.
|
|
218
233
|
// Works from dist/cjs and dist/esm alike: walk up past the dist type-marker package.json.
|
|
219
234
|
function packageVersion() {
|
|
220
235
|
var load = (0, _nodemodule.createRequire)(require("url").pathToFileURL(__filename).toString());
|
|
@@ -252,99 +267,92 @@ function resolveConfigFor(name, configPath) {
|
|
|
252
267
|
}
|
|
253
268
|
return cfg;
|
|
254
269
|
}
|
|
270
|
+
// The top level knows four flags and nothing else; everything past the command word is the
|
|
271
|
+
// command's to parse. Reached only when there is no command word, or the first token is a flag.
|
|
272
|
+
function topLevel(argv, name) {
|
|
273
|
+
var unknown;
|
|
274
|
+
var opts = (0, _getoptscompat.default)(argv, {
|
|
275
|
+
string: [
|
|
276
|
+
'config'
|
|
277
|
+
],
|
|
278
|
+
boolean: [
|
|
279
|
+
'version',
|
|
280
|
+
'help',
|
|
281
|
+
'list'
|
|
282
|
+
],
|
|
283
|
+
alias: {
|
|
284
|
+
version: 'v',
|
|
285
|
+
help: 'h'
|
|
286
|
+
},
|
|
287
|
+
default: {
|
|
288
|
+
version: false,
|
|
289
|
+
help: false,
|
|
290
|
+
list: false
|
|
291
|
+
},
|
|
292
|
+
unknown: function unknown1(flag) {
|
|
293
|
+
if (unknown === undefined) unknown = flag;
|
|
294
|
+
return false;
|
|
295
|
+
}
|
|
296
|
+
});
|
|
297
|
+
if (unknown !== undefined) (0, _exitts.usageError)("unknown option: ".concat(unknown), usage(name));
|
|
298
|
+
if (opts.version) {
|
|
299
|
+
console.log(packageVersion());
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
if (opts.help) {
|
|
303
|
+
console.log(usage(name));
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
if (opts.list) {
|
|
307
|
+
var queries = resolveConfigFor(name, opts.config === '' ? undefined : opts.config).queries;
|
|
308
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
309
|
+
try {
|
|
310
|
+
for(var _iterator = Object.keys(queries).sort()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
311
|
+
var queryName = _step.value;
|
|
312
|
+
var entry = queries[queryName];
|
|
313
|
+
var isSavedSearch = (typeof entry === "undefined" ? "undefined" : _type_of(entry)) === 'object' && entry !== null && 'search' in entry;
|
|
314
|
+
console.log(isSavedSearch ? "".concat(queryName, " (search)") : queryName);
|
|
315
|
+
}
|
|
316
|
+
} catch (err) {
|
|
317
|
+
_didIteratorError = true;
|
|
318
|
+
_iteratorError = err;
|
|
319
|
+
} finally{
|
|
320
|
+
try {
|
|
321
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
322
|
+
_iterator.return();
|
|
323
|
+
}
|
|
324
|
+
} finally{
|
|
325
|
+
if (_didIteratorError) {
|
|
326
|
+
throw _iteratorError;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
console.error(usage(name));
|
|
333
|
+
throw new _exitts.ExitError(2);
|
|
334
|
+
}
|
|
255
335
|
function cli(argv, name) {
|
|
256
336
|
return _async_to_generator(function() {
|
|
257
|
-
var first,
|
|
337
|
+
var first, ctx, load, err;
|
|
258
338
|
return _ts_generator(this, function(_state) {
|
|
259
339
|
switch(_state.label){
|
|
260
340
|
case 0:
|
|
341
|
+
_state.trys.push([
|
|
342
|
+
0,
|
|
343
|
+
7,
|
|
344
|
+
,
|
|
345
|
+
8
|
|
346
|
+
]);
|
|
261
347
|
first = argv[0];
|
|
262
|
-
// No command word, or the first token looks like a flag: the only flags this level knows.
|
|
263
348
|
if (!first || first.startsWith('-')) {
|
|
264
|
-
;
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
options: {
|
|
269
|
-
version: {
|
|
270
|
-
type: 'boolean',
|
|
271
|
-
default: false,
|
|
272
|
-
short: 'v'
|
|
273
|
-
},
|
|
274
|
-
help: {
|
|
275
|
-
type: 'boolean',
|
|
276
|
-
default: false,
|
|
277
|
-
short: 'h'
|
|
278
|
-
},
|
|
279
|
-
list: {
|
|
280
|
-
type: 'boolean',
|
|
281
|
-
default: false
|
|
282
|
-
},
|
|
283
|
-
config: {
|
|
284
|
-
type: 'string'
|
|
285
|
-
}
|
|
286
|
-
},
|
|
287
|
-
allowPositionals: true
|
|
288
|
-
}).values;
|
|
289
|
-
} catch (err) {
|
|
290
|
-
console.error(err.message);
|
|
291
|
-
console.error(usage(name));
|
|
292
|
-
process.exit(2);
|
|
293
|
-
}
|
|
294
|
-
try {
|
|
295
|
-
if (values.version) {
|
|
296
|
-
console.log("v".concat(packageVersion()));
|
|
297
|
-
return [
|
|
298
|
-
2
|
|
299
|
-
];
|
|
300
|
-
}
|
|
301
|
-
if (values.help) {
|
|
302
|
-
console.log(usage(name));
|
|
303
|
-
return [
|
|
304
|
-
2
|
|
305
|
-
];
|
|
306
|
-
}
|
|
307
|
-
if (values.list) {
|
|
308
|
-
queries = resolveConfigFor(name, values.config).queries;
|
|
309
|
-
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
310
|
-
try {
|
|
311
|
-
for(_iterator = Object.keys(queries).sort()[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
312
|
-
queryName = _step.value;
|
|
313
|
-
entry = queries[queryName];
|
|
314
|
-
isSavedSearch = (typeof entry === "undefined" ? "undefined" : _type_of(entry)) === 'object' && entry !== null && 'search' in entry;
|
|
315
|
-
console.log(isSavedSearch ? "".concat(queryName, " (search)") : queryName);
|
|
316
|
-
}
|
|
317
|
-
} catch (err) {
|
|
318
|
-
_didIteratorError = true;
|
|
319
|
-
_iteratorError = err;
|
|
320
|
-
} finally{
|
|
321
|
-
try {
|
|
322
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
323
|
-
_iterator.return();
|
|
324
|
-
}
|
|
325
|
-
} finally{
|
|
326
|
-
if (_didIteratorError) {
|
|
327
|
-
throw _iteratorError;
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
return [
|
|
332
|
-
2
|
|
333
|
-
];
|
|
334
|
-
}
|
|
335
|
-
} catch (err) {
|
|
336
|
-
console.error(err.message);
|
|
337
|
-
process.exit(1);
|
|
338
|
-
}
|
|
339
|
-
console.error(usage(name));
|
|
340
|
-
process.exit(2);
|
|
349
|
+
topLevel(argv, name);
|
|
350
|
+
return [
|
|
351
|
+
2
|
|
352
|
+
];
|
|
341
353
|
}
|
|
342
354
|
// find -> search (breaking rename): one release of a pointer instead of "unknown query".
|
|
343
|
-
if (first === 'find')
|
|
344
|
-
console.error("".concat(name, ": find is now search"));
|
|
345
|
-
console.error(usage(name));
|
|
346
|
-
process.exit(2);
|
|
347
|
-
}
|
|
355
|
+
if (first === 'find') (0, _exitts.usageError)("".concat(name, ": find is now search"), usage(name));
|
|
348
356
|
ctx = {
|
|
349
357
|
name: name,
|
|
350
358
|
argv: argv.slice(1),
|
|
@@ -352,67 +360,64 @@ function cli(argv, name) {
|
|
|
352
360
|
return resolveConfigFor(name, configPath);
|
|
353
361
|
},
|
|
354
362
|
usageError: function usageError(message) {
|
|
355
|
-
|
|
356
|
-
process.exit(2);
|
|
363
|
+
return (0, _exitts.usageError)(message);
|
|
357
364
|
}
|
|
358
365
|
};
|
|
359
|
-
_state.label = 1;
|
|
360
|
-
case 1:
|
|
361
|
-
_state.trys.push([
|
|
362
|
-
1,
|
|
363
|
-
8,
|
|
364
|
-
,
|
|
365
|
-
9
|
|
366
|
-
]);
|
|
367
366
|
load = _indexts.COMMANDS[first];
|
|
368
367
|
if (!load) return [
|
|
369
368
|
3,
|
|
370
|
-
|
|
369
|
+
3
|
|
371
370
|
];
|
|
372
371
|
return [
|
|
373
372
|
4,
|
|
374
373
|
load()
|
|
375
374
|
];
|
|
376
|
-
case
|
|
375
|
+
case 1:
|
|
377
376
|
return [
|
|
378
377
|
4,
|
|
379
378
|
_state.sent().default(ctx)
|
|
380
379
|
];
|
|
381
|
-
case
|
|
380
|
+
case 2:
|
|
382
381
|
_state.sent();
|
|
383
382
|
return [
|
|
384
383
|
3,
|
|
385
|
-
|
|
384
|
+
6
|
|
386
385
|
];
|
|
387
|
-
case
|
|
386
|
+
case 3:
|
|
388
387
|
return [
|
|
389
388
|
4,
|
|
390
389
|
Promise.resolve().then(function() {
|
|
391
390
|
return /*#__PURE__*/ _interop_require_wildcard(require("./cli/named.js"));
|
|
392
391
|
})
|
|
393
392
|
];
|
|
394
|
-
case
|
|
393
|
+
case 4:
|
|
395
394
|
return [
|
|
396
395
|
4,
|
|
397
396
|
_state.sent().default(ctx, first)
|
|
398
397
|
];
|
|
399
|
-
case
|
|
398
|
+
case 5:
|
|
400
399
|
_state.sent();
|
|
401
|
-
_state.label =
|
|
402
|
-
case
|
|
400
|
+
_state.label = 6;
|
|
401
|
+
case 6:
|
|
403
402
|
return [
|
|
404
403
|
3,
|
|
405
|
-
|
|
404
|
+
8
|
|
406
405
|
];
|
|
407
|
-
case
|
|
406
|
+
case 7:
|
|
408
407
|
err = _state.sent();
|
|
408
|
+
if (_instanceof(err, _exitts.ExitError)) {
|
|
409
|
+
(0, _exitcompat.default)(err.code);
|
|
410
|
+
return [
|
|
411
|
+
2
|
|
412
|
+
];
|
|
413
|
+
}
|
|
409
414
|
console.error(err.message);
|
|
410
|
-
|
|
415
|
+
(0, _exitcompat.default)(1);
|
|
411
416
|
return [
|
|
412
417
|
3,
|
|
413
|
-
|
|
418
|
+
8
|
|
414
419
|
];
|
|
415
|
-
case
|
|
420
|
+
case 8:
|
|
416
421
|
return [
|
|
417
422
|
2
|
|
418
423
|
];
|
package/dist/cjs/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/cli.ts"],"sourcesContent":["import { createRequire } from 'node:module';\nimport {
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/cli.ts"],"sourcesContent":["import { createRequire } from 'node:module';\nimport exit from 'exit-compat';\nimport getopts from 'getopts-compat';\nimport { ExitError, usageError } from './cli/exit.ts';\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 live in src/cli/, one file each, lazy-loaded --\n// nothing tree- or dependency-heavy may be imported at the top of this file. Flags parse\n// per command (each command's own parse() call); this file only handles the bare top-level\n// flags (--version/--help/--list/--config) and dispatch, and owns the single exit.\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// The top level knows four flags and nothing else; everything past the command word is the\n// command's to parse. Reached only when there is no command word, or the first token is a flag.\nfunction topLevel(argv: string[], name: string): void {\n let unknown: string | undefined;\n const opts = getopts(argv, {\n string: ['config'],\n boolean: ['version', 'help', 'list'],\n alias: { version: 'v', help: 'h' },\n default: { version: false, help: false, list: false },\n unknown: (flag: string): boolean => {\n if (unknown === undefined) unknown = flag;\n return false;\n },\n });\n if (unknown !== undefined) usageError(`unknown option: ${unknown}`, usage(name));\n\n if (opts.version) {\n console.log(packageVersion());\n return;\n }\n if (opts.help) {\n console.log(usage(name));\n return;\n }\n if (opts.list) {\n const queries = resolveConfigFor(name, opts.config === '' ? undefined : (opts.config as string)).queries;\n for (const queryName of Object.keys(queries).sort()) {\n const entry = queries[queryName];\n const isSavedSearch = typeof entry === 'object' && entry !== null && 'search' in entry;\n console.log(isSavedSearch ? `${queryName} (search)` : queryName);\n }\n return;\n }\n console.error(usage(name));\n throw new ExitError(2);\n}\n\n// ExitError carries a chosen code; anything else is an error -> exit 1 with its message.\nexport default async function cli(argv: string[], name: string): Promise<void> {\n try {\n const first = argv[0];\n if (!first || first.startsWith('-')) {\n topLevel(argv, name);\n return;\n }\n\n // find -> search (breaking rename): one release of a pointer instead of \"unknown query\".\n if (first === 'find') usageError(`${name}: find is now search`, usage(name));\n\n const ctx: Ctx = {\n name,\n argv: argv.slice(1),\n resolveConfig: (configPath) => resolveConfigFor(name, configPath),\n usageError: (message) => usageError(message),\n };\n\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 if (err instanceof ExitError) {\n exit(err.code);\n return;\n }\n console.error((err as Error).message);\n exit(1);\n }\n}\n"],"names":["cli","packageVersion","load","createRequire","rel","pkg","name","version","usage","lines","Object","values","USAGE","map","u","join","resolveConfigFor","configPath","cfg","loadConfig","migratedFrom","undefined","console","warn","SUPPORTED_CONFIG_VERSION","unknownKeys","topLevel","argv","unknown","opts","getopts","string","boolean","alias","help","default","list","flag","usageError","log","queries","config","keys","sort","queryName","entry","isSavedSearch","error","ExitError","first","ctx","err","startsWith","slice","resolveConfig","message","COMMANDS","exit","code"],"mappings":";;;;+BA8EA,yFAAyF;AACzF;;;eAA8BA;;;0BA/EA;iEACb;oEACG;sBACkB;uBACN;wBAEqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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YAJK;YAAA;;;qBAAA,6BAAA;oBAAA;;;oBAAA;0BAAA;;;;QAKL;IACF;IACAtB,QAAQyB,KAAK,CAACvC,MAAMF;IACpB,MAAM,IAAI0C,iBAAS,CAAC;AACtB;AAGe,SAAehD,IAAI2B,IAAc,EAAErB,IAAY;;YAEpD2C,OASAC,KAOAhD,MAGCiD;;;;;;;;;;oBAnBDF,QAAQtB,IAAI,CAAC,EAAE;oBACrB,IAAI,CAACsB,SAASA,MAAMG,UAAU,CAAC,MAAM;wBACnC1B,SAASC,MAAMrB;wBACf;;;oBACF;oBAEA,yFAAyF;oBACzF,IAAI2C,UAAU,QAAQX,IAAAA,kBAAU,EAAC,AAAC,GAAO,OAALhC,MAAK,yBAAuBE,MAAMF;oBAEhE4C,MAAW;wBACf5C,MAAAA;wBACAqB,MAAMA,KAAK0B,KAAK,CAAC;wBACjBC,eAAe,SAAfA,cAAgBrC;mCAAeD,iBAAiBV,MAAMW;;wBACtDqB,YAAY,SAAZA,WAAaiB;mCAAYjB,IAAAA,kBAAU,EAACiB;;oBACtC;oBAEMrD,OAAOsD,iBAAQ,CAACP,MAAM;yBACxB/C,MAAAA;;;;oBAAa;;wBAAMA;;;oBAAb;;wBAAO,cAAciC,OAAO,CAACe;;;oBAA7B;;;;;;oBACE;;wBAAM;2EAAA,QAAO;;;;oBAApB;;wBAAO,cAAgCf,OAAO,CAACe,KAAKD;;;oBAApD;;;;;;;;oBACEE;oBACP,IAAIA,AAAG,YAAHA,KAAeH,iBAAS,GAAE;wBAC5BS,IAAAA,mBAAI,EAACN,IAAIO,IAAI;wBACb;;;oBACF;oBACApC,QAAQyB,KAAK,CAAC,AAACI,IAAcI,OAAO;oBACpCE,IAAAA,mBAAI,EAAC;;;;;;;;;;;IAET"}
|
package/dist/cjs/db.js
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
// The package's Node floor (>=22.16) is set here and nowhere else: node:sqlite arrived in
|
|
2
|
+
// 22.5, but FTS5 -- which search.ts's whole lexical half is built on -- and
|
|
3
|
+
// StatementSync.columns() both landed in 22.16. 22.15 fails with "no such module: fts5".
|
|
4
|
+
// Nothing outside this file, features/, and commands.ts needs anything past Node 12, so
|
|
5
|
+
// raise the floor only for a sqlite capability, and lower it for nothing.
|
|
1
6
|
"use strict";
|
|
2
7
|
Object.defineProperty(exports, "__esModule", {
|
|
3
8
|
value: true
|
package/dist/cjs/db.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/db.ts"],"sourcesContent":["import { mkdirSync, rmSync } from 'node:fs';\nimport { join } from 'node:path';\nimport { DatabaseSync } from 'node:sqlite';\nimport type { Config, ResolvedConfig } from './config.ts';\nimport { featureSignature, STATE_DIR } from './config.ts';\nimport { SenseError } from './errors.ts';\nimport { activeFeatures } from './features/index.ts';\nimport type { ReconcileDelta } from './features/types.ts';\nimport { progress } from './progress.ts';\nimport type { ParsedDoc } from './scan.ts';\nimport { listFiles, parseFile, RESERVED_COLUMNS } from './scan.ts';\n\n// path/_mtime/_size are core: every reparse legitimately rewrites them. Every other\n// RESERVED_COLUMNS entry that shows up as a real frontmatter column (currently only\n// rank's `_rank`) is feature-owned -- scan.ts already refuses to let frontmatter set it,\n// so it must never appear in the upsert below, or a reparse would blow its last computed\n// value away with NULL on every touch, not just the reconciles that recompute it.\nconst CORE_FRONTMATTER_COLUMNS = new Set(['path', '_mtime', '_size']);\n\n// Rows -> SQLite: core schema, reconcile loop, has(). Parsing lives in scan.ts;\n// everything beyond frontmatter + content lives in src/features/.\n\nexport const DB_FILENAME = 'cache.db';\n// Cache shape version, independent of the config's own `version`.\n// 7: presets replace layers -- frontmatter drops the `layer` column, a new\n// preset_files(preset, path) table tracks per-preset coverage for status/map (was: 6,\n// frontmatter gains the `layer` column).\nexport const SCHEMA_VERSION = '8';\n\n// SQLite's compile-time SQLITE_MAX_COLUMN, default 2000 (https://www.sqlite.org/limits.html).\nconst MAX_FRONTMATTER_COLUMNS = 2000;\n\nexport interface OpenResult {\n db: DatabaseSync;\n cfg: ResolvedConfig;\n dbPath: string;\n parsed: number;\n warnings: string[];\n}\n\nfunction quoteIdent(name: string): string {\n return `\"${name.split('\"').join('\"\"')}\"`;\n}\n\n// has(field, value): JSON-array field -> membership, string field -> substring, NULL -> false.\nfunction registerFunctions(db: DatabaseSync): void {\n db.function('has', { deterministic: true, varargs: false }, (field: unknown, value: unknown): number => {\n if (field === null || field === undefined) return 0;\n\n const needle = String(value);\n\n if (typeof field === 'string') {\n if (field.startsWith('[')) {\n try {\n const parsed = JSON.parse(field);\n if (Array.isArray(parsed)) {\n return parsed.some((item) => String(item) === needle) ? 1 : 0;\n }\n } catch {}\n }\n return field.includes(needle) ? 1 : 0;\n }\n\n return String(field).includes(needle) ? 1 : 0;\n });\n}\n\nfunction getColumns(db: DatabaseSync): Set<string> {\n const rows = db.prepare('PRAGMA table_info(frontmatter)').all() as Array<{ name: string }>;\n return new Set(rows.map((r) => r.name));\n}\n\n// Content is a separate table (not a column on frontmatter) so `SELECT * FROM frontmatter`\n// can't dump file text into context. Features add their own tables after the core ones.\nfunction ensureSchema(db: DatabaseSync, cfg: Config): void {\n db.exec(`CREATE TABLE IF NOT EXISTS frontmatter (\"path\" TEXT PRIMARY KEY, \"_mtime\" REAL, \"_size\" INTEGER)`);\n db.exec(`CREATE VIRTUAL TABLE IF NOT EXISTS content USING fts5(title, summary, text, path UNINDEXED, tokenize = 'porter unicode61')`);\n // Coverage, not ownership: a path can appear under several presets. Rebuilt per-file\n // alongside frontmatter/content at reconcile so status/map can report matched/embedded\n // counts per preset without recomputing globs at read time.\n // path leads the PK so the per-doc delete in reconcile is an index hit -- keyed the other\n // way it scans the whole table per doc, which made cold builds quadratic (measured 3x cost\n // per note-count doubling at 13k/26k). Coverage-by-preset reads get their own index.\n db.exec(`CREATE TABLE IF NOT EXISTS preset_files (\"path\" TEXT, preset TEXT, PRIMARY KEY (\"path\", preset))`);\n db.exec('CREATE INDEX IF NOT EXISTS preset_files_preset ON preset_files(preset)');\n for (const feature of activeFeatures(cfg)) feature.schema(db);\n if (getMeta(db, 'schema_version') === null) setMeta(db, 'schema_version', SCHEMA_VERSION);\n if (getMeta(db, 'features') === null) setMeta(db, 'features', featureSignature(cfg));\n}\n\nexport function getMeta(db: DatabaseSync, key: string): string | null {\n const row = db.prepare('SELECT value FROM meta WHERE key = ?').get(key) as { value: string } | undefined;\n return row ? row.value : null;\n}\n\nexport function setMeta(db: DatabaseSync, key: string, value: string | null): void {\n if (value === null) {\n db.prepare('DELETE FROM meta WHERE key = ?').run(key);\n return;\n }\n db.prepare('INSERT INTO meta (key, value) VALUES (?, ?) ON CONFLICT(key) DO UPDATE SET value = excluded.value').run(key, value);\n}\n\nexport function docCount(db: DatabaseSync): number {\n const row = db.prepare('SELECT COUNT(*) AS n FROM frontmatter').get() as { n: number };\n return row.n;\n}\n\nexport function reconcile(db: DatabaseSync, cfg: Config, baseDir: string): { parsed: number; warnings: string[] } {\n const files = listFiles(cfg, baseDir);\n const currentSet = new Set(files.map((f) => f.relPath));\n\n const existingRows = db.prepare(`SELECT \"path\", \"_mtime\", \"_size\" FROM frontmatter`).all() as Array<{\n path: string;\n _mtime: number;\n _size: number;\n }>;\n const existing = new Map(existingRows.map((r) => [r.path, r]));\n const vanished = existingRows.filter((r) => !currentSet.has(r.path)).map((r) => r.path);\n\n const toReparse = files.filter((f) => {\n const row = existing.get(f.relPath);\n return !row || row._mtime !== f.mtimeMs || row._size !== f.size;\n });\n\n if (vanished.length === 0 && toReparse.length === 0) return { parsed: 0, warnings: [] };\n\n const features = activeFeatures(cfg);\n const seenColumns = getColumns(db);\n const newColumns: string[] = [];\n const parsedDocs: ParsedDoc[] = [];\n const warnings: string[] = [];\n\n // Bulk reparses (a sync, a cold build) are the long silences a query can hit; short\n // reconciles stay silent (progress() has a threshold).\n const report = progress('reparsing files', toReparse.length);\n let parsedCount = 0;\n for (const file of toReparse) {\n // A doc only gets extract/store from features that apply to it (currently: embed, via\n // FileStat.embed -- true iff a covering preset has semantic on).\n const fileFeatures = features.filter((feature) => !feature.enabledForFile || feature.enabledForFile(cfg, file));\n const { doc, warnings: fileWarnings } = parseFile(file, fileFeatures);\n report.tick(++parsedCount);\n warnings.push(...fileWarnings);\n for (const key of Object.keys(doc.data)) {\n if (!seenColumns.has(key)) {\n seenColumns.add(key);\n newColumns.push(key);\n }\n }\n parsedDocs.push(doc);\n }\n report.finish();\n\n const allColumns = [...seenColumns];\n // Fence before ALTERing: SQLite's own failure past this point is a raw\n // \"too many columns on sqlite_altertab_frontmatter\" with no indication of the boundary or the levers.\n if (allColumns.length > MAX_FRONTMATTER_COLUMNS) {\n throw new SenseError(\n 'COLUMN_LIMIT',\n `frontmatter would need ${allColumns.length} columns, crossing SQLite's compile-time SQLITE_MAX_COLUMN limit (default ${MAX_FRONTMATTER_COLUMNS}; see https://www.sqlite.org/limits.html). Narrow the presets' include globs so fewer/other files are indexed, or fix whatever is generating unbounded frontmatter keys.`\n );\n }\n // Columns the frontmatter upsert actually writes: core + parsed frontmatter keys, never a\n // feature-owned reserved column (see CORE_FRONTMATTER_COLUMNS above).\n const writableColumns = allColumns.filter((c) => CORE_FRONTMATTER_COLUMNS.has(c) || !RESERVED_COLUMNS.has(c));\n // ON CONFLICT UPDATE (not OR REPLACE) keeps the row's rowid stable across reparses --\n // content rows are coupled to that rowid below.\n const insertSql = `INSERT INTO frontmatter (${writableColumns.map(quoteIdent).join(', ')}) VALUES (${writableColumns.map(() => '?').join(', ')}) ON CONFLICT(\"path\") DO UPDATE SET ${writableColumns\n .filter((c) => c !== 'path')\n .map((c) => `${quoteIdent(c)} = excluded.${quoteIdent(c)}`)\n .join(', ')}`;\n\n const added = toReparse.filter((f) => !existing.has(f.relPath)).map((f) => f.relPath);\n const delta: ReconcileDelta = { files, reparsed: parsedDocs.map((d) => d.relPath), added, vanished };\n\n const txStart = Date.now();\n db.exec('BEGIN');\n try {\n for (const col of newColumns) db.exec(`ALTER TABLE frontmatter ADD COLUMN ${quoteIdent(col)}`);\n // FTS5 has no upsert, so delete-before-insert into `content`; coupled to the\n // frontmatter rowid (indexed via its PRIMARY KEY) instead of the UNINDEXED `path`\n // column, which a per-row DELETE would otherwise scan the whole table to find.\n const delBody = db.prepare(`DELETE FROM content WHERE rowid = (SELECT rowid FROM frontmatter WHERE \"path\" = ?)`);\n const delPresetFiles = db.prepare(`DELETE FROM preset_files WHERE \"path\" = ?`);\n const insertPresetFile = db.prepare(`INSERT INTO preset_files (\"path\", preset) VALUES (?, ?)`);\n if (vanished.length > 0) {\n const del = db.prepare(`DELETE FROM frontmatter WHERE \"path\" = ?`);\n for (const path of vanished) {\n // content delete must run first: it looks up the frontmatter rowid by path, which\n // the frontmatter delete below would otherwise have already removed.\n delBody.run(path);\n del.run(path);\n delPresetFiles.run(path);\n for (const feature of features) feature.remove?.(db, path, delta);\n }\n }\n if (parsedDocs.length > 0) {\n const insert = db.prepare(insertSql);\n const insertBody = db.prepare(`INSERT INTO content (rowid, title, summary, text, \"path\") VALUES ((SELECT rowid FROM frontmatter WHERE \"path\" = ?), ?, ?, ?, ?)`);\n for (const doc of parsedDocs) {\n const values = writableColumns.map((col) => {\n if (col === 'path') return doc.relPath;\n if (col === '_mtime') return doc.mtimeMs;\n if (col === '_size') return doc.size;\n return doc.data[col] ?? null;\n });\n // Frontmatter upsert first: content's rowid lookup below depends on this row existing.\n insert.run(...values);\n // Delete-before-insert only for docs that have rows: an FTS5 DELETE by rowid on a\n // cold build (empty table, nothing to delete) is wasted work, and doing it\n // unconditionally previously made the crawl quadratic when it scanned by column --\n // measured 4x time per note-count doubling at 13k/26k notes.\n if (existing.has(doc.relPath)) {\n delBody.run(doc.relPath);\n for (const feature of features) feature.remove?.(db, doc.relPath, delta);\n }\n insertBody.run(doc.relPath, doc.search.title, doc.search.summary, doc.search.text, doc.relPath);\n // Coverage is glob-derived, not content-derived, but only reparsed/added docs are\n // touched here: a preset edit changes featureSignature and forces a full rebuild\n // (see open()), so an unchanged doc's coverage is already correct on disk. New docs\n // have no rows to clear -- skipping the delete keeps cold builds linear.\n if (existing.has(doc.relPath)) delPresetFiles.run(doc.relPath);\n for (const presetName of doc.presets) insertPresetFile.run(doc.relPath, presetName);\n for (const feature of features) feature.store?.(db, doc.relPath, doc.extracted[feature.name], delta);\n }\n }\n for (const feature of features) feature.afterReconcile?.(db, delta);\n db.exec('COMMIT');\n } catch (err) {\n db.exec('ROLLBACK');\n throw err;\n }\n\n // Reconcile's own write-transaction duration, for open()'s derived busy_timeout (F):\n // keep the observed max so a big watcher reconcile's lock hold is what the next open bounds its wait against.\n const durationMs = Date.now() - txStart;\n const prevRaw = getMeta(db, 'reconcile_max_ms');\n // -1, not 0, so a genuinely 0ms first reconcile (sub-millisecond, common on a tiny tree)\n // still gets recorded instead of losing to the \"nothing recorded yet\" default.\n const prevMax = prevRaw === null ? -1 : Number(prevRaw);\n if (durationMs > prevMax) setMeta(db, 'reconcile_max_ms', String(durationMs));\n\n return { parsed: parsedDocs.length, warnings };\n}\n\n// Names what moved between two feature signatures (see config.featureSignature's format:\n// global features, embed provider, then one segment per preset) for the rebuild notice.\nfunction signatureDiff(before: string, after: string): string {\n // Segment keys: `features`, `embed`, `preset:<name>` (config.featureSignature's format).\n const keyOf = (part: string) => (part.startsWith('preset:') ? part.split(':').slice(0, 2).join(':') : part.split(':')[0]);\n const parse = (sig: string) => new Map(sig.split('|').map((part) => [keyOf(part), part]));\n const a = parse(before);\n const b = parse(after);\n const changed = new Set<string>();\n for (const [key, val] of b) if (a.get(key) !== val) changed.add(key);\n for (const key of a.keys()) if (!b.has(key)) changed.add(key);\n const label = (key: string) => (key === 'embed' ? 'embed settings' : key.startsWith('preset:') ? `preset \"${key.slice(7)}\"` : 'features');\n return changed.size === 0 ? 'features' : [...changed].map(label).join(', ');\n}\n\nexport function open(cfg: ResolvedConfig): OpenResult {\n const stateDir = join(cfg.baseDir, STATE_DIR);\n mkdirSync(stateDir, { recursive: true });\n const dbPath = join(stateDir, DB_FILENAME);\n\n const db = new DatabaseSync(dbPath);\n db.exec('PRAGMA journal_mode = WAL');\n // Covers a concurrent watcher's bulk reconcile: the write transaction for 500 changed\n // files measures ~5s at 26k notes, so 5s expired exactly at the boundary and queries\n // racing the watcher got SQLITE_BUSY. 30s bounds the wait at ~3x the largest measured\n // reconcile; a query that outwaits it still fails loudly.\n db.exec('PRAGMA busy_timeout = 30000');\n registerFunctions(db);\n\n db.exec('CREATE TABLE IF NOT EXISTS meta (key TEXT PRIMARY KEY, value TEXT)');\n\n // Schema-version or feature-set mismatch: reconcile only reparses changed files, so an\n // old cache can't be patched incrementally -- rebuild instead (cheap: nothing expensive lives here).\n const version = getMeta(db, 'schema_version');\n const features = getMeta(db, 'features');\n const wantFeatures = featureSignature(cfg);\n if ((version !== null && version !== SCHEMA_VERSION) || (features !== null && features !== wantFeatures)) {\n // Indexing derives from presets, so a config edit rebuilding the cache must say so and\n // name what changed -- silent rebuilds make derived indexing look like a hang or a bug.\n if (version !== null && version !== SCHEMA_VERSION) {\n console.error('sense: cache format changed (new sensemaking version); rebuilding the index');\n } else {\n const changed = signatureDiff(features ?? '', wantFeatures);\n console.error(`sense: config change (${changed}) rebuilds the index`);\n }\n db.close();\n rmSync(stateDir, { recursive: true, force: true });\n return open(cfg);\n }\n\n ensureSchema(db, cfg);\n\n // Derived from reconcile's own recorded max (F): 3x the largest reconcile this cache has\n // ever held its write transaction for, floored at the 30s default and capped at 10min so\n // one pathological build can't pin every later open to an unbounded wait. Installed\n // before reconcile() below -- this open's own reconcile is exactly the operation that\n // races a concurrent watcher's transaction and needs the derived wait.\n const recordedMaxMs = Number(getMeta(db, 'reconcile_max_ms') ?? '0');\n db.exec(`PRAGMA busy_timeout = ${Math.min(Math.max(30000, 3 * recordedMaxMs), 600_000)}`);\n\n const { parsed, warnings } = reconcile(db, cfg, cfg.baseDir);\n\n return { db, cfg, dbPath, parsed, warnings };\n}\n\n// Manual reset for a doubted cache.\nexport function rebuild(cfg: ResolvedConfig): OpenResult {\n rmSync(join(cfg.baseDir, STATE_DIR), { recursive: true, force: true });\n return open(cfg);\n}\n"],"names":["DB_FILENAME","SCHEMA_VERSION","docCount","getMeta","open","rebuild","reconcile","setMeta","CORE_FRONTMATTER_COLUMNS","Set","MAX_FRONTMATTER_COLUMNS","quoteIdent","name","split","join","registerFunctions","db","function","deterministic","varargs","field","value","undefined","needle","String","startsWith","parsed","JSON","parse","Array","isArray","some","item","includes","getColumns","rows","prepare","all","map","r","ensureSchema","cfg","exec","activeFeatures","feature","schema","featureSignature","key","row","get","run","n","baseDir","files","listFiles","currentSet","f","relPath","existingRows","existing","Map","path","vanished","filter","has","toReparse","_mtime","mtimeMs","_size","size","length","warnings","features","seenColumns","newColumns","parsedDocs","report","progress","parsedCount","file","fileFeatures","enabledForFile","parseFile","doc","fileWarnings","tick","push","Object","keys","data","add","finish","allColumns","SenseError","writableColumns","c","RESERVED_COLUMNS","insertSql","added","delta","reparsed","d","txStart","Date","now","col","delBody","delPresetFiles","insertPresetFile","del","remove","insert","insertBody","values","search","title","summary","text","presets","presetName","store","extracted","afterReconcile","err","durationMs","prevRaw","prevMax","Number","signatureDiff","before","after","keyOf","part","slice","sig","a","b","changed","val","label","stateDir","STATE_DIR","mkdirSync","recursive","dbPath","DatabaseSync","version","wantFeatures","console","error","close","rmSync","force","recordedMaxMs","Math","min","max"],"mappings":";;;;;;;;;;;QAsBaA;eAAAA;;QAKAC;eAAAA;;QA4EGC;eAAAA;;QAbAC;eAAAA;;QA2KAC;eAAAA;;QAmDAC;eAAAA;;QA5MAC;eAAAA;;QAbAC;eAAAA;;;sBA/FkB;wBACb;0BACQ;wBAEe;wBACjB;uBACI;0BAEN;sBAE8B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEvD,oFAAoF;AACpF,oFAAoF;AACpF,yFAAyF;AACzF,yFAAyF;AACzF,kFAAkF;AAClF,IAAMC,2BAA2B,IAAIC,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WAAW;YAAMS,OAAO;QAAK;QAChD,OAAOpJ,KAAKqC;IACd;IAEAD,aAAaxB,IAAIyB;IAEjB,yFAAyF;IACzF,yFAAyF;IACzF,oFAAoF;IACpF,sFAAsF;IACtF,uEAAuE;IACvE,IAAMgH,gBAAgB1B,QAAO5H,WAAAA,QAAQa,IAAI,iCAAZb,sBAAAA,WAAmC;IAChEa,GAAG0B,IAAI,CAAC,AAAC,yBAA8E,OAAtDgH,KAAKC,GAAG,CAACD,KAAKE,GAAG,CAAC,OAAO,IAAIH,gBAAgB;IAE9E,IAA6BnJ,aAAAA,UAAUU,IAAIyB,KAAKA,IAAIW,OAAO,GAAnD1B,SAAqBpB,WAArBoB,QAAQ6C,WAAajE,WAAbiE;IAEhB,OAAO;QAAEvD,IAAAA;QAAIyB,KAAAA;QAAKuG,QAAAA;QAAQtH,QAAAA;QAAQ6C,UAAAA;IAAS;AAC7C;AAGO,SAASlE,QAAQoC,GAAmB;IACzC8G,IAAAA,cAAM,EAACzI,IAAAA,cAAI,EAAC2B,IAAIW,OAAO,EAAEyF,mBAAS,GAAG;QAAEE,WAAW;QAAMS,OAAO;IAAK;IACpE,OAAOpJ,KAAKqC;AACd"}
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/db.ts"],"sourcesContent":["// The package's Node floor (>=22.16) is set here and nowhere else: node:sqlite arrived in\n// 22.5, but FTS5 -- which search.ts's whole lexical half is built on -- and\n// StatementSync.columns() both landed in 22.16. 22.15 fails with \"no such module: fts5\".\n// Nothing outside this file, features/, and commands.ts needs anything past Node 12, so\n// raise the floor only for a sqlite capability, and lower it for nothing.\nimport { mkdirSync, rmSync } from 'node:fs';\nimport { join } from 'node:path';\nimport { DatabaseSync } from 'node:sqlite';\nimport type { Config, ResolvedConfig } from './config.ts';\nimport { featureSignature, STATE_DIR } from './config.ts';\nimport { SenseError } from './errors.ts';\nimport { activeFeatures } from './features/index.ts';\nimport type { ReconcileDelta } from './features/types.ts';\nimport { progress } from './progress.ts';\nimport type { ParsedDoc } from './scan.ts';\nimport { listFiles, parseFile, RESERVED_COLUMNS } from './scan.ts';\n\n// path/_mtime/_size are core: every reparse legitimately rewrites them. Every other\n// RESERVED_COLUMNS entry that shows up as a real frontmatter column (currently only\n// rank's `_rank`) is feature-owned -- scan.ts already refuses to let frontmatter set it,\n// so it must never appear in the upsert below, or a reparse would blow its last computed\n// value away with NULL on every touch, not just the reconciles that recompute it.\nconst CORE_FRONTMATTER_COLUMNS = new Set(['path', '_mtime', '_size']);\n\n// Rows -> SQLite: core schema, reconcile loop, has(). Parsing lives in scan.ts;\n// everything beyond frontmatter + content lives in src/features/.\n\nexport const DB_FILENAME = 'cache.db';\n// Cache shape version, independent of the config's own `version`.\n// 7: presets replace layers -- frontmatter drops the `layer` column, a new\n// preset_files(preset, path) table tracks per-preset coverage for status/map (was: 6,\n// frontmatter gains the `layer` column).\nexport const SCHEMA_VERSION = '8';\n\n// SQLite's compile-time SQLITE_MAX_COLUMN, default 2000 (https://www.sqlite.org/limits.html).\nconst MAX_FRONTMATTER_COLUMNS = 2000;\n\nexport interface OpenResult {\n db: DatabaseSync;\n cfg: ResolvedConfig;\n dbPath: string;\n parsed: number;\n warnings: string[];\n}\n\nfunction quoteIdent(name: string): string {\n return `\"${name.split('\"').join('\"\"')}\"`;\n}\n\n// has(field, value): JSON-array field -> membership, string field -> substring, NULL -> false.\nfunction registerFunctions(db: DatabaseSync): void {\n db.function('has', { deterministic: true, varargs: false }, (field: unknown, value: unknown): number => {\n if (field === null || field === undefined) return 0;\n\n const needle = String(value);\n\n if (typeof field === 'string') {\n if (field.startsWith('[')) {\n try {\n const parsed = JSON.parse(field);\n if (Array.isArray(parsed)) {\n return parsed.some((item) => String(item) === needle) ? 1 : 0;\n }\n } catch {}\n }\n return field.includes(needle) ? 1 : 0;\n }\n\n return String(field).includes(needle) ? 1 : 0;\n });\n}\n\nfunction getColumns(db: DatabaseSync): Set<string> {\n const rows = db.prepare('PRAGMA table_info(frontmatter)').all() as Array<{ name: string }>;\n return new Set(rows.map((r) => r.name));\n}\n\n// Content is a separate table (not a column on frontmatter) so `SELECT * FROM frontmatter`\n// can't dump file text into context. Features add their own tables after the core ones.\nfunction ensureSchema(db: DatabaseSync, cfg: Config): void {\n db.exec(`CREATE TABLE IF NOT EXISTS frontmatter (\"path\" TEXT PRIMARY KEY, \"_mtime\" REAL, \"_size\" INTEGER)`);\n db.exec(`CREATE VIRTUAL TABLE IF NOT EXISTS content USING fts5(title, summary, text, path UNINDEXED, tokenize = 'porter unicode61')`);\n // Coverage, not ownership: a path can appear under several presets. Rebuilt per-file\n // alongside frontmatter/content at reconcile so status/map can report matched/embedded\n // counts per preset without recomputing globs at read time.\n // path leads the PK so the per-doc delete in reconcile is an index hit -- keyed the other\n // way it scans the whole table per doc, which made cold builds quadratic (measured 3x cost\n // per note-count doubling at 13k/26k). Coverage-by-preset reads get their own index.\n db.exec(`CREATE TABLE IF NOT EXISTS preset_files (\"path\" TEXT, preset TEXT, PRIMARY KEY (\"path\", preset))`);\n db.exec('CREATE INDEX IF NOT EXISTS preset_files_preset ON preset_files(preset)');\n for (const feature of activeFeatures(cfg)) feature.schema(db);\n if (getMeta(db, 'schema_version') === null) setMeta(db, 'schema_version', SCHEMA_VERSION);\n if (getMeta(db, 'features') === null) setMeta(db, 'features', featureSignature(cfg));\n}\n\nexport function getMeta(db: DatabaseSync, key: string): string | null {\n const row = db.prepare('SELECT value FROM meta WHERE key = ?').get(key) as { value: string } | undefined;\n return row ? row.value : null;\n}\n\nexport function setMeta(db: DatabaseSync, key: string, value: string | null): void {\n if (value === null) {\n db.prepare('DELETE FROM meta WHERE key = ?').run(key);\n return;\n }\n db.prepare('INSERT INTO meta (key, value) VALUES (?, ?) ON CONFLICT(key) DO UPDATE SET value = excluded.value').run(key, value);\n}\n\nexport function docCount(db: DatabaseSync): number {\n const row = db.prepare('SELECT COUNT(*) AS n FROM frontmatter').get() as { n: number };\n return row.n;\n}\n\nexport function reconcile(db: DatabaseSync, cfg: Config, baseDir: string): { parsed: number; warnings: string[] } {\n const files = listFiles(cfg, baseDir);\n const currentSet = new Set(files.map((f) => f.relPath));\n\n const existingRows = db.prepare(`SELECT \"path\", \"_mtime\", \"_size\" FROM frontmatter`).all() as Array<{\n path: string;\n _mtime: number;\n _size: number;\n }>;\n const existing = new Map(existingRows.map((r) => [r.path, r]));\n const vanished = existingRows.filter((r) => !currentSet.has(r.path)).map((r) => r.path);\n\n const toReparse = files.filter((f) => {\n const row = existing.get(f.relPath);\n return !row || row._mtime !== f.mtimeMs || row._size !== f.size;\n });\n\n if (vanished.length === 0 && toReparse.length === 0) return { parsed: 0, warnings: [] };\n\n const features = activeFeatures(cfg);\n const seenColumns = getColumns(db);\n const newColumns: string[] = [];\n const parsedDocs: ParsedDoc[] = [];\n const warnings: string[] = [];\n\n // Bulk reparses (a sync, a cold build) are the long silences a query can hit; short\n // reconciles stay silent (progress() has a threshold).\n const report = progress('reparsing files', toReparse.length);\n let parsedCount = 0;\n for (const file of toReparse) {\n // A doc only gets extract/store from features that apply to it (currently: embed, via\n // FileStat.embed -- true iff a covering preset has semantic on).\n const fileFeatures = features.filter((feature) => !feature.enabledForFile || feature.enabledForFile(cfg, file));\n const { doc, warnings: fileWarnings } = parseFile(file, fileFeatures);\n report.tick(++parsedCount);\n warnings.push(...fileWarnings);\n for (const key of Object.keys(doc.data)) {\n if (!seenColumns.has(key)) {\n seenColumns.add(key);\n newColumns.push(key);\n }\n }\n parsedDocs.push(doc);\n }\n report.finish();\n\n const allColumns = [...seenColumns];\n // Fence before ALTERing: SQLite's own failure past this point is a raw\n // \"too many columns on sqlite_altertab_frontmatter\" with no indication of the boundary or the levers.\n if (allColumns.length > MAX_FRONTMATTER_COLUMNS) {\n throw new SenseError(\n 'COLUMN_LIMIT',\n `frontmatter would need ${allColumns.length} columns, crossing SQLite's compile-time SQLITE_MAX_COLUMN limit (default ${MAX_FRONTMATTER_COLUMNS}; see https://www.sqlite.org/limits.html). Narrow the presets' include globs so fewer/other files are indexed, or fix whatever is generating unbounded frontmatter keys.`\n );\n }\n // Columns the frontmatter upsert actually writes: core + parsed frontmatter keys, never a\n // feature-owned reserved column (see CORE_FRONTMATTER_COLUMNS above).\n const writableColumns = allColumns.filter((c) => CORE_FRONTMATTER_COLUMNS.has(c) || !RESERVED_COLUMNS.has(c));\n // ON CONFLICT UPDATE (not OR REPLACE) keeps the row's rowid stable across reparses --\n // content rows are coupled to that rowid below.\n const insertSql = `INSERT INTO frontmatter (${writableColumns.map(quoteIdent).join(', ')}) VALUES (${writableColumns.map(() => '?').join(', ')}) ON CONFLICT(\"path\") DO UPDATE SET ${writableColumns\n .filter((c) => c !== 'path')\n .map((c) => `${quoteIdent(c)} = excluded.${quoteIdent(c)}`)\n .join(', ')}`;\n\n const added = toReparse.filter((f) => !existing.has(f.relPath)).map((f) => f.relPath);\n const delta: ReconcileDelta = { files, reparsed: parsedDocs.map((d) => d.relPath), added, vanished };\n\n const txStart = Date.now();\n db.exec('BEGIN');\n try {\n for (const col of newColumns) db.exec(`ALTER TABLE frontmatter ADD COLUMN ${quoteIdent(col)}`);\n // FTS5 has no upsert, so delete-before-insert into `content`; coupled to the\n // frontmatter rowid (indexed via its PRIMARY KEY) instead of the UNINDEXED `path`\n // column, which a per-row DELETE would otherwise scan the whole table to find.\n const delBody = db.prepare(`DELETE FROM content WHERE rowid = (SELECT rowid FROM frontmatter WHERE \"path\" = ?)`);\n const delPresetFiles = db.prepare(`DELETE FROM preset_files WHERE \"path\" = ?`);\n const insertPresetFile = db.prepare(`INSERT INTO preset_files (\"path\", preset) VALUES (?, ?)`);\n if (vanished.length > 0) {\n const del = db.prepare(`DELETE FROM frontmatter WHERE \"path\" = ?`);\n for (const path of vanished) {\n // content delete must run first: it looks up the frontmatter rowid by path, which\n // the frontmatter delete below would otherwise have already removed.\n delBody.run(path);\n del.run(path);\n delPresetFiles.run(path);\n for (const feature of features) feature.remove?.(db, path, delta);\n }\n }\n if (parsedDocs.length > 0) {\n const insert = db.prepare(insertSql);\n const insertBody = db.prepare(`INSERT INTO content (rowid, title, summary, text, \"path\") VALUES ((SELECT rowid FROM frontmatter WHERE \"path\" = ?), ?, ?, ?, ?)`);\n for (const doc of parsedDocs) {\n const values = writableColumns.map((col) => {\n if (col === 'path') return doc.relPath;\n if (col === '_mtime') return doc.mtimeMs;\n if (col === '_size') return doc.size;\n return doc.data[col] ?? null;\n });\n // Frontmatter upsert first: content's rowid lookup below depends on this row existing.\n insert.run(...values);\n // Delete-before-insert only for docs that have rows: an FTS5 DELETE by rowid on a\n // cold build (empty table, nothing to delete) is wasted work, and doing it\n // unconditionally previously made the crawl quadratic when it scanned by column --\n // measured 4x time per note-count doubling at 13k/26k notes.\n if (existing.has(doc.relPath)) {\n delBody.run(doc.relPath);\n for (const feature of features) feature.remove?.(db, doc.relPath, delta);\n }\n insertBody.run(doc.relPath, doc.search.title, doc.search.summary, doc.search.text, doc.relPath);\n // Coverage is glob-derived, not content-derived, but only reparsed/added docs are\n // touched here: a preset edit changes featureSignature and forces a full rebuild\n // (see open()), so an unchanged doc's coverage is already correct on disk. New docs\n // have no rows to clear -- skipping the delete keeps cold builds linear.\n if (existing.has(doc.relPath)) delPresetFiles.run(doc.relPath);\n for (const presetName of doc.presets) insertPresetFile.run(doc.relPath, presetName);\n for (const feature of features) feature.store?.(db, doc.relPath, doc.extracted[feature.name], delta);\n }\n }\n for (const feature of features) feature.afterReconcile?.(db, delta);\n db.exec('COMMIT');\n } catch (err) {\n db.exec('ROLLBACK');\n throw err;\n }\n\n // Reconcile's own write-transaction duration, for open()'s derived busy_timeout (F):\n // keep the observed max so a big watcher reconcile's lock hold is what the next open bounds its wait against.\n const durationMs = Date.now() - txStart;\n const prevRaw = getMeta(db, 'reconcile_max_ms');\n // -1, not 0, so a genuinely 0ms first reconcile (sub-millisecond, common on a tiny tree)\n // still gets recorded instead of losing to the \"nothing recorded yet\" default.\n const prevMax = prevRaw === null ? -1 : Number(prevRaw);\n if (durationMs > prevMax) setMeta(db, 'reconcile_max_ms', String(durationMs));\n\n return { parsed: parsedDocs.length, warnings };\n}\n\n// Names what moved between two feature signatures (see config.featureSignature's format:\n// global features, embed provider, then one segment per preset) for the rebuild notice.\nfunction signatureDiff(before: string, after: string): string {\n // Segment keys: `features`, `embed`, `preset:<name>` (config.featureSignature's format).\n const keyOf = (part: string) => (part.startsWith('preset:') ? part.split(':').slice(0, 2).join(':') : part.split(':')[0]);\n const parse = (sig: string) => new Map(sig.split('|').map((part) => [keyOf(part), part]));\n const a = parse(before);\n const b = parse(after);\n const changed = new Set<string>();\n for (const [key, val] of b) if (a.get(key) !== val) changed.add(key);\n for (const key of a.keys()) if (!b.has(key)) changed.add(key);\n const label = (key: string) => (key === 'embed' ? 'embed settings' : key.startsWith('preset:') ? `preset \"${key.slice(7)}\"` : 'features');\n return changed.size === 0 ? 'features' : [...changed].map(label).join(', ');\n}\n\nexport function open(cfg: ResolvedConfig): OpenResult {\n const stateDir = join(cfg.baseDir, STATE_DIR);\n mkdirSync(stateDir, { recursive: true });\n const dbPath = join(stateDir, DB_FILENAME);\n\n const db = new DatabaseSync(dbPath);\n db.exec('PRAGMA journal_mode = WAL');\n // Covers a concurrent watcher's bulk reconcile: the write transaction for 500 changed\n // files measures ~5s at 26k notes, so 5s expired exactly at the boundary and queries\n // racing the watcher got SQLITE_BUSY. 30s bounds the wait at ~3x the largest measured\n // reconcile; a query that outwaits it still fails loudly.\n db.exec('PRAGMA busy_timeout = 30000');\n registerFunctions(db);\n\n db.exec('CREATE TABLE IF NOT EXISTS meta (key TEXT PRIMARY KEY, value TEXT)');\n\n // Schema-version or feature-set mismatch: reconcile only reparses changed files, so an\n // old cache can't be patched incrementally -- rebuild instead (cheap: nothing expensive lives here).\n const version = getMeta(db, 'schema_version');\n const features = getMeta(db, 'features');\n const wantFeatures = featureSignature(cfg);\n if ((version !== null && version !== SCHEMA_VERSION) || (features !== null && features !== wantFeatures)) {\n // Indexing derives from presets, so a config edit rebuilding the cache must say so and\n // name what changed -- silent rebuilds make derived indexing look like a hang or a bug.\n if (version !== null && version !== SCHEMA_VERSION) {\n console.error('sense: cache format changed (new sensemaking version); rebuilding the index');\n } else {\n const changed = signatureDiff(features ?? '', wantFeatures);\n console.error(`sense: config change (${changed}) rebuilds the index`);\n }\n db.close();\n rmSync(stateDir, { recursive: true, force: true });\n return open(cfg);\n }\n\n ensureSchema(db, cfg);\n\n // Derived from reconcile's own recorded max (F): 3x the largest reconcile this cache has\n // ever held its write transaction for, floored at the 30s default and capped at 10min so\n // one pathological build can't pin every later open to an unbounded wait. Installed\n // before reconcile() below -- this open's own reconcile is exactly the operation that\n // races a concurrent watcher's transaction and needs the derived wait.\n const recordedMaxMs = Number(getMeta(db, 'reconcile_max_ms') ?? '0');\n db.exec(`PRAGMA busy_timeout = ${Math.min(Math.max(30000, 3 * recordedMaxMs), 600_000)}`);\n\n const { parsed, warnings } = reconcile(db, cfg, cfg.baseDir);\n\n return { db, cfg, dbPath, parsed, warnings };\n}\n\n// Manual reset for a doubted cache.\nexport function rebuild(cfg: ResolvedConfig): OpenResult {\n rmSync(join(cfg.baseDir, STATE_DIR), { recursive: true, force: true });\n return open(cfg);\n}\n"],"names":["DB_FILENAME","SCHEMA_VERSION","docCount","getMeta","open","rebuild","reconcile","setMeta","CORE_FRONTMATTER_COLUMNS","Set","MAX_FRONTMATTER_COLUMNS","quoteIdent","name","split","join","registerFunctions","db","function","deterministic","varargs","field","value","undefined","needle","String","startsWith","parsed","JSON","parse","Array","isArray","some","item","includes","getColumns","rows","prepare","all","map","r","ensureSchema","cfg","exec","activeFeatures","feature","schema","featureSignature","key","row","get","run","n","baseDir","files","listFiles","currentSet","f","relPath","existingRows","existing","Map","path","vanished","filter","has","toReparse","_mtime","mtimeMs","_size","size","length","warnings","features","seenColumns","newColumns","parsedDocs","report","progress","parsedCount","file","fileFeatures","enabledForFile","parseFile","doc","fileWarnings","tick","push","Object","keys","data","add","finish","allColumns","SenseError","writableColumns","c","RESERVED_COLUMNS","insertSql","added","delta","reparsed","d","txStart","Date","now","col","delBody","delPresetFiles","insertPresetFile","del","remove","insert","insertBody","values","search","title","summary","text","presets","presetName","store","extracted","afterReconcile","err","durationMs","prevRaw","prevMax","Number","signatureDiff","before","after","keyOf","part","slice","sig","a","b","changed","val","label","stateDir","STATE_DIR","mkdirSync","recursive","dbPath","DatabaseSync","version","wantFeatures","console","error","close","rmSync","force","recordedMaxMs","Math","min","max"],"mappings":"AAAA,0FAA0F;AAC1F,4EAA4E;AAC5E,yFAAyF;AACzF,wFAAwF;AACxF,0EAA0E;;;;;;;;;;;;QAuB7DA;eAAAA;;QAKAC;eAAAA;;QA4EGC;eAAAA;;QAbAC;eAAAA;;QA2KAC;eAAAA;;QAmDAC;eAAAA;;QA5MAC;eAAAA;;QAbAC;eAAAA;;;sBA/FkB;wBACb;0BACQ;wBAEe;wBACjB;uBACI;0BAEN;sBAE8B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEvD,oFAAoF;AACpF,oFAAoF;AACpF,yFAAyF;AACzF,yFAAyF;AACzF,kFAAkF;AAClF,IAAMC,2BAA2B,IAAIC,IAAI;IAAC;IAAQ;IAAU;CAAQ;AAK7D,IAAMT,cAAc;AAKpB,IAAMC,iBAAiB;AAE9B,8FAA8F;AAC9F,IAAMS,0BAA0B;AAUhC,SAASC,WAAWC,IAAY;IAC9B,OAAO,AAAC,IAA8B,OAA3BA,KAAKC,KAAK,CAAC,KAAKC,IAAI,CAAC,OAAM;AACxC;AAEA,+FAA+F;AAC/F,SAASC,kBAAkBC,EAAgB;IACzCA,GAAGC,QAAQ,CAAC,OAAO;QAAEC,eAAe;QAAMC,SAAS;IAAM,GAAG,SAACC,OAAgBC;QAC3E,IAAID,UAAU,QAAQA,UAAUE,WAAW,OAAO;QAElD,IAAMC,SAASC,OAAOH;QAEtB,IAAI,OAAOD,UAAU,UAAU;YAC7B,IAAIA,MAAMK,UAAU,C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B,KAAAA;QAAKuG,QAAAA;QAAQtH,QAAAA;QAAQ6C,UAAAA;IAAS;AAC7C;AAGO,SAASlE,QAAQoC,GAAmB;IACzC8G,IAAAA,cAAM,EAACzI,IAAAA,cAAI,EAAC2B,IAAIW,OAAO,EAAEyF,mBAAS,GAAG;QAAEE,WAAW;QAAMS,OAAO;IAAK;IACpE,OAAOpJ,KAAKqC;AACd"}
|
package/dist/esm/cli/check.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { search } from '../commands.js';
|
|
2
2
|
import { open } from '../db.js';
|
|
3
3
|
import { printRows } from '../output.js';
|
|
4
|
+
import { ExitError } from './exit.js';
|
|
4
5
|
import { USAGE } from './index.js';
|
|
5
6
|
import { CONFIG, FORMAT, formatOf, parse, printWarnings } from './shared.js';
|
|
6
7
|
// A saved query that returns zero rows looks identical to a true empty result, so a broken
|
|
@@ -89,6 +90,6 @@ const check = async (ctx)=>{
|
|
|
89
90
|
return;
|
|
90
91
|
}
|
|
91
92
|
printRows(rows, format);
|
|
92
|
-
if (failed > 0)
|
|
93
|
+
if (failed > 0) throw new ExitError(1);
|
|
93
94
|
};
|
|
94
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 { 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)
|
|
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,O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ZjB;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"}
|