sensemaking 0.3.2 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/cli.js +1 -1
- package/dist/cjs/cli.js.map +1 -1
- package/dist/cjs/commands/find.js +2 -2
- package/dist/cjs/commands/find.js.map +1 -1
- package/dist/cjs/commands/map.js +3 -3
- package/dist/cjs/commands/map.js.map +1 -1
- package/dist/cjs/commands/named.js +2 -2
- package/dist/cjs/commands/named.js.map +1 -1
- package/dist/cjs/commands/peek.js +2 -2
- package/dist/cjs/commands/peek.js.map +1 -1
- package/dist/cjs/commands/query.js +2 -2
- package/dist/cjs/commands/query.js.map +1 -1
- package/dist/cjs/commands/rebuild.js +2 -2
- package/dist/cjs/commands/rebuild.js.map +1 -1
- package/dist/cjs/commands/{vault.d.cts → shared.d.cts} +1 -1
- package/dist/cjs/commands/{vault.d.ts → shared.d.ts} +1 -1
- package/dist/cjs/commands/{vault.js → shared.js} +3 -3
- package/dist/cjs/commands/shared.js.map +1 -0
- package/dist/cjs/commands/status.js +2 -2
- package/dist/cjs/commands/status.js.map +1 -1
- package/dist/cjs/commands/watch.js +2 -2
- package/dist/cjs/commands/watch.js.map +1 -1
- package/dist/cjs/features/links.js +1 -1
- package/dist/cjs/features/links.js.map +1 -1
- package/dist/cjs/index.d.cts +2 -2
- package/dist/cjs/index.d.ts +2 -2
- package/dist/cjs/index.js +3 -3
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/verbs.d.cts +2 -2
- package/dist/cjs/verbs.d.ts +2 -2
- package/dist/cjs/verbs.js +5 -5
- package/dist/cjs/verbs.js.map +1 -1
- package/dist/esm/cli.js +1 -1
- package/dist/esm/cli.js.map +1 -1
- package/dist/esm/commands/find.js +2 -2
- package/dist/esm/commands/find.js.map +1 -1
- package/dist/esm/commands/map.js +4 -4
- package/dist/esm/commands/map.js.map +1 -1
- package/dist/esm/commands/named.js +1 -1
- package/dist/esm/commands/named.js.map +1 -1
- package/dist/esm/commands/peek.js +2 -2
- package/dist/esm/commands/peek.js.map +1 -1
- package/dist/esm/commands/query.js +1 -1
- package/dist/esm/commands/query.js.map +1 -1
- package/dist/esm/commands/rebuild.js +1 -1
- package/dist/esm/commands/rebuild.js.map +1 -1
- package/dist/esm/commands/{vault.d.ts → shared.d.ts} +1 -1
- package/dist/esm/commands/{vault.js → shared.js} +2 -2
- package/dist/esm/commands/shared.js.map +1 -0
- package/dist/esm/commands/status.js +1 -1
- package/dist/esm/commands/status.js.map +1 -1
- package/dist/esm/commands/watch.js +1 -1
- package/dist/esm/commands/watch.js.map +1 -1
- package/dist/esm/features/links.js +1 -1
- package/dist/esm/features/links.js.map +1 -1
- package/dist/esm/features/types.js +1 -1
- package/dist/esm/features/types.js.map +1 -1
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/verbs.d.ts +2 -2
- package/dist/esm/verbs.js +3 -3
- package/dist/esm/verbs.js.map +1 -1
- package/package.json +1 -1
- package/skills/sense/EXAMPLES.md +12 -13
- package/skills/sense/SKILL.md +24 -15
- package/dist/cjs/commands/vault.js.map +0 -1
- package/dist/esm/commands/vault.js.map +0 -1
package/dist/cjs/cli.js
CHANGED
|
@@ -208,7 +208,7 @@ function _ts_generator(thisArg, body) {
|
|
|
208
208
|
}
|
|
209
209
|
}
|
|
210
210
|
// Parsing and dispatch only. Commands live in src/commands/, one file each, lazy-loaded --
|
|
211
|
-
// nothing
|
|
211
|
+
// nothing tree- or dependency-heavy may be imported at the top of this file.
|
|
212
212
|
// Works from dist/cjs and dist/esm alike: walk up past the dist type-marker package.json.
|
|
213
213
|
function packageVersion() {
|
|
214
214
|
var load = (0, _nodemodule.createRequire)(require("url").pathToFileURL(__filename).toString());
|
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 { parseArgs } from 'node:util';\nimport { COMMANDS } from './commands/index.ts';\nimport type { Ctx } from './commands/types.ts';\nimport { loadConfig, SUPPORTED_CONFIG_VERSION } from './config.ts';\n\n// Parsing and dispatch only. Commands live in src/commands/, one file each, lazy-loaded --\n// nothing
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/cli.ts"],"sourcesContent":["import { createRequire } from 'node:module';\nimport { parseArgs } from 'node:util';\nimport { COMMANDS } from './commands/index.ts';\nimport type { Ctx } from './commands/types.ts';\nimport { loadConfig, SUPPORTED_CONFIG_VERSION } from './config.ts';\n\n// Parsing and dispatch only. Commands live in src/commands/, one file each, lazy-loaded --\n// nothing tree- or dependency-heavy may be imported at the top of this file.\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 return (\n `usage: ${name} <name> [params...] [--format table|json] [--config path]\\n` +\n ` ${name} query \"<sql>\" [params...]\\n` +\n ` ${name} find \"<terms>\" [--where \"<sql>\"] [--k n]\\n` +\n ` ${name} map\\n` +\n ` ${name} peek <path>\\n` +\n ` ${name} --list\\n` +\n ` ${name} init\\n` +\n ` ${name} watch [--force]\\n` +\n ` ${name} status\\n` +\n ` ${name} rebuild\\n` +\n ` ${name} --version`\n );\n}\n\n// Thrown errors -> exit 1 with the message verbatim; usage errors exit 2 directly.\nexport default async function cli(argv: string[], name: string): Promise<void> {\n let values: Record<string, string | boolean | undefined>;\n let positionals: string[];\n try {\n ({ values, positionals } = parseArgs({\n args: argv,\n options: {\n format: { type: 'string', default: 'table' },\n config: { type: 'string' },\n where: { type: 'string' },\n k: { type: 'string' },\n list: { type: 'boolean', default: false },\n force: { type: 'boolean', default: false },\n version: { type: 'boolean', default: false, short: 'v' },\n help: { type: 'boolean', default: false, short: 'h' },\n },\n allowPositionals: true,\n }));\n } catch (err) {\n console.error((err as Error).message);\n console.error(usage(name));\n process.exit(2);\n }\n\n if (values.version) {\n console.log(`v${packageVersion()}`);\n return;\n }\n if (values.help) {\n console.log(usage(name));\n return;\n }\n\n const ctx: Ctx = {\n name,\n rest: positionals.slice(1),\n format: values.format === 'json' ? 'json' : 'table',\n values: values as Ctx['values'],\n resolveConfig() {\n const cfg = loadConfig(values.config as string | undefined);\n if (cfg.migratedFrom !== undefined) {\n console.warn(`${name}: migrated ${cfg.configPath} from config version ${cfg.migratedFrom} to ${SUPPORTED_CONFIG_VERSION}`);\n }\n return cfg;\n },\n usageError(message) {\n console.error(message);\n process.exit(2);\n },\n };\n\n try {\n if (values.list) {\n for (const queryName of Object.keys(ctx.resolveConfig().queries).sort()) console.log(queryName);\n return;\n }\n\n const [first, ...params] = positionals;\n if (!first) {\n console.error(usage(name));\n process.exit(2);\n }\n\n const load = COMMANDS[first];\n if (load) await (await load()).default(ctx);\n else (await import('./commands/named.ts')).default(ctx, first, params);\n } catch (err) {\n console.error((err as Error).message);\n process.exit(1);\n }\n}\n"],"names":["cli","packageVersion","load","createRequire","rel","pkg","name","version","usage","argv","values","positionals","ctx","queryName","first","params","err","parseArgs","args","options","format","type","default","config","where","k","list","force","short","help","allowPositionals","console","error","message","process","exit","log","rest","slice","resolveConfig","cfg","loadConfig","migratedFrom","undefined","warn","configPath","SUPPORTED_CONFIG_VERSION","usageError","Object","keys","queries","sort","COMMANDS"],"mappings":";;;;+BAqCA,mFAAmF;AACnF;;;eAA8BA;;;0BAtCA;wBACJ;uBACD;wBAE4B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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I2B,aAAa,GAAGW,OAAO,EAAEC,IAAI,yBAAhE,6BAAA,QAAA,yBAAA;gCAAMtC,YAAN;gCAAoEkB,QAAQK,GAAG,CAACvB;;;4BAAhF;4BAAA;;;qCAAA,6BAAA;oCAAA;;;oCAAA;0CAAA;;;;wBACL;;;oBACF;oBAE2BF,yBAAAA,cAApBG,QAAoBH,iBAAVI,SAAUJ,mBAAb;oBACd,IAAI,CAACG,OAAO;wBACViB,QAAQC,KAAK,CAACxB,MAAMF;wBACpB4B,QAAQC,IAAI,CAAC;oBACf;oBAEMjC,OAAOkD,iBAAQ,CAACtC,MAAM;yBACxBZ,MAAAA;;;;oBAAa;;wBAAMA;;;oBAAb;;wBAAO,cAAcoB,OAAO,CAACV;;;oBAA7B;;;;;;oBACJ;;wBAAM;2EAAA,QAAO;;;;oBAAb,cAAqCU,OAAO,CAACV,KAAKE,OAAOC;;;;;;;;oBACxDC;oBACPe,QAAQC,KAAK,CAAC,AAAChB,IAAciB,OAAO;oBACpCC,QAAQC,IAAI,CAAC;;;;;;;;;;;IAEjB"}
|
|
@@ -10,7 +10,7 @@ Object.defineProperty(exports, "default", {
|
|
|
10
10
|
});
|
|
11
11
|
var _outputts = require("../output.js");
|
|
12
12
|
var _verbsts = require("../verbs.js");
|
|
13
|
-
var
|
|
13
|
+
var _sharedts = require("./shared.js");
|
|
14
14
|
function _array_like_to_array(arr, len) {
|
|
15
15
|
if (len == null || len > arr.length) len = arr.length;
|
|
16
16
|
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
@@ -62,7 +62,7 @@ var findCmd = function findCmd(ctx) {
|
|
|
62
62
|
if (!terms) ctx.usageError("usage: ".concat(ctx.name, ' find "<terms>" [--where "<sql>"] [--k n]'));
|
|
63
63
|
var k = ctx.values.k === undefined ? undefined : Number.parseInt(ctx.values.k, 10);
|
|
64
64
|
if (ctx.values.k !== undefined && !Number.isInteger(k)) ctx.usageError('--k expects an integer, got "'.concat(ctx.values.k, '"'));
|
|
65
|
-
(0,
|
|
65
|
+
(0, _sharedts.withDb)(ctx, function(db, cfg) {
|
|
66
66
|
return (0, _outputts.printRows)((0, _verbsts.find)(db, cfg, terms, {
|
|
67
67
|
k: k,
|
|
68
68
|
where: ctx.values.where
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/commands/find.ts"],"sourcesContent":["import { printRows } from '../output.ts';\nimport { find } from '../verbs.ts';\nimport
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/commands/find.ts"],"sourcesContent":["import { printRows } from '../output.ts';\nimport { find } from '../verbs.ts';\nimport { withDb } from './shared.ts';\nimport type { Command } from './types.ts';\n\nconst findCmd: Command = (ctx) => {\n const [terms] = ctx.rest;\n if (!terms) ctx.usageError(`usage: ${ctx.name} find \"<terms>\" [--where \"<sql>\"] [--k n]`);\n const k = ctx.values.k === undefined ? undefined : Number.parseInt(ctx.values.k, 10);\n if (ctx.values.k !== undefined && !Number.isInteger(k)) ctx.usageError(`--k expects an integer, got \"${ctx.values.k}\"`);\n withDb(ctx, (db, cfg) => printRows(find(db, cfg, terms, { k, where: ctx.values.where }), ctx.format));\n};\nexport default findCmd;\n"],"names":["findCmd","ctx","rest","terms","usageError","name","k","values","undefined","Number","parseInt","isInteger","withDb","db","cfg","printRows","find","where","format"],"mappings":";;;;+BAYA;;;eAAA;;;wBAZ0B;uBACL;wBACE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGvB,IAAMA,UAAmB,iBAACC;IACxB,IAAgBA,6BAAAA,IAAIC,IAAI,MAAjBC,QAASF;IAChB,IAAI,CAACE,OAAOF,IAAIG,UAAU,CAAC,AAAC,UAAkB,OAATH,IAAII,IAAI,EAAC;IAC9C,IAAMC,IAAIL,IAAIM,MAAM,CAACD,CAAC,KAAKE,YAAYA,YAAYC,OAAOC,QAAQ,CAACT,IAAIM,MAAM,CAACD,CAAC,EAAE;IACjF,IAAIL,IAAIM,MAAM,CAACD,CAAC,KAAKE,aAAa,CAACC,OAAOE,SAAS,CAACL,IAAIL,IAAIG,UAAU,CAAC,AAAC,gCAA4C,OAAbH,IAAIM,MAAM,CAACD,CAAC,EAAC;IACpHM,IAAAA,gBAAM,EAACX,KAAK,SAACY,IAAIC;eAAQC,IAAAA,mBAAS,EAACC,IAAAA,aAAI,EAACH,IAAIC,KAAKX,OAAO;YAAEG,GAAAA;YAAGW,OAAOhB,IAAIM,MAAM,CAACU,KAAK;QAAC,IAAIhB,IAAIiB,MAAM;;AACrG;IACA,WAAelB"}
|
package/dist/cjs/commands/map.js
CHANGED
|
@@ -10,10 +10,10 @@ Object.defineProperty(exports, "default", {
|
|
|
10
10
|
});
|
|
11
11
|
var _outputts = require("../output.js");
|
|
12
12
|
var _verbsts = require("../verbs.js");
|
|
13
|
-
var
|
|
13
|
+
var _sharedts = require("./shared.js");
|
|
14
14
|
var map = function map(ctx) {
|
|
15
|
-
(0,
|
|
16
|
-
var result = (0, _verbsts.
|
|
15
|
+
(0, _sharedts.withDb)(ctx, function(db, cfg) {
|
|
16
|
+
var result = (0, _verbsts.mapTree)(db, cfg);
|
|
17
17
|
console.log(ctx.format === 'json' ? JSON.stringify(result, null, 2) : (0, _outputts.renderMap)(result));
|
|
18
18
|
});
|
|
19
19
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/commands/map.ts"],"sourcesContent":["import { renderMap } from '../output.ts';\nimport {
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/commands/map.ts"],"sourcesContent":["import { renderMap } from '../output.ts';\nimport { mapTree } from '../verbs.ts';\nimport { withDb } from './shared.ts';\nimport type { Command } from './types.ts';\n\nconst map: Command = (ctx) => {\n withDb(ctx, (db, cfg) => {\n const result = mapTree(db, cfg);\n console.log(ctx.format === 'json' ? JSON.stringify(result, null, 2) : renderMap(result));\n });\n};\nexport default map;\n"],"names":["map","ctx","withDb","db","cfg","result","mapTree","console","log","format","JSON","stringify","renderMap"],"mappings":";;;;+BAWA;;;eAAA;;;wBAX0B;uBACF;wBACD;AAGvB,IAAMA,MAAe,aAACC;IACpBC,IAAAA,gBAAM,EAACD,KAAK,SAACE,IAAIC;QACf,IAAMC,SAASC,IAAAA,gBAAO,EAACH,IAAIC;QAC3BG,QAAQC,GAAG,CAACP,IAAIQ,MAAM,KAAK,SAASC,KAAKC,SAAS,CAACN,QAAQ,MAAM,KAAKO,IAAAA,mBAAS,EAACP;IAClF;AACF;IACA,WAAeL"}
|
|
@@ -9,7 +9,7 @@ Object.defineProperty(exports, // Fallback when the first positional is not a co
|
|
|
9
9
|
return named;
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
|
-
var
|
|
12
|
+
var _sharedts = require("./shared.js");
|
|
13
13
|
function named(ctx, queryName, params) {
|
|
14
14
|
var cfg = ctx.resolveConfig();
|
|
15
15
|
var sql = cfg.queries[queryName];
|
|
@@ -18,6 +18,6 @@ function named(ctx, queryName, params) {
|
|
|
18
18
|
console.error("valid queries: ".concat(Object.keys(cfg.queries).sort().join(', ')));
|
|
19
19
|
process.exit(2);
|
|
20
20
|
}
|
|
21
|
-
(0,
|
|
21
|
+
(0, _sharedts.runSql)(cfg, sql, params, ctx.format, 'query "'.concat(queryName, '"'));
|
|
22
22
|
}
|
|
23
23
|
/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/commands/named.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/commands/named.ts"],"sourcesContent":["import { runSql } 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.\nexport default function named(ctx: Ctx, queryName: string, params: string[]): void {\n const cfg = ctx.resolveConfig();\n const sql = cfg.queries[queryName];\n if (!sql) {\n console.error(`unknown query: \"${queryName}\"`);\n console.error(`valid queries: ${Object.keys(cfg.queries).sort().join(', ')}`);\n process.exit(2);\n }\n runSql(cfg, sql, params, ctx.format, `query \"${queryName}\"`);\n}\n"],"names":["named","ctx","queryName","params","cfg","resolveConfig","sql","queries","console","error","Object","keys","sort","join","process","exit","runSql","format"],"mappings":";;;;+BAGA,kFAAkF;AAClF;;;eAAwBA;;;wBAJD;AAIR,SAASA,MAAMC,GAAQ,EAAEC,SAAiB,EAAEC,MAAgB;IACzE,IAAMC,MAAMH,IAAII,aAAa;IAC7B,IAAMC,MAAMF,IAAIG,OAAO,CAACL,UAAU;IAClC,IAAI,CAACI,KAAK;QACRE,QAAQC,KAAK,CAAC,AAAC,mBAA4B,OAAVP,WAAU;QAC3CM,QAAQC,KAAK,CAAC,AAAC,kBAA4D,OAA3CC,OAAOC,IAAI,CAACP,IAAIG,OAAO,EAAEK,IAAI,GAAGC,IAAI,CAAC;QACrEC,QAAQC,IAAI,CAAC;IACf;IACAC,IAAAA,gBAAM,EAACZ,KAAKE,KAAKH,QAAQF,IAAIgB,MAAM,EAAE,AAAC,UAAmB,OAAVf,WAAU;AAC3D"}
|
|
@@ -10,7 +10,7 @@ Object.defineProperty(exports, "default", {
|
|
|
10
10
|
});
|
|
11
11
|
var _outputts = require("../output.js");
|
|
12
12
|
var _verbsts = require("../verbs.js");
|
|
13
|
-
var
|
|
13
|
+
var _sharedts = require("./shared.js");
|
|
14
14
|
function _array_like_to_array(arr, len) {
|
|
15
15
|
if (len == null || len > arr.length) len = arr.length;
|
|
16
16
|
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
@@ -60,7 +60,7 @@ function _unsupported_iterable_to_array(o, minLen) {
|
|
|
60
60
|
var peekCmd = function peekCmd(ctx) {
|
|
61
61
|
var _ctx_rest = _sliced_to_array(ctx.rest, 1), pathArg = _ctx_rest[0];
|
|
62
62
|
if (!pathArg) ctx.usageError("usage: ".concat(ctx.name, " peek <path>"));
|
|
63
|
-
(0,
|
|
63
|
+
(0, _sharedts.withDb)(ctx, function(db, cfg) {
|
|
64
64
|
var result = (0, _verbsts.peek)(db, cfg, pathArg);
|
|
65
65
|
console.log(ctx.format === 'json' ? JSON.stringify(result, null, 2) : (0, _outputts.renderPeek)(result));
|
|
66
66
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/commands/peek.ts"],"sourcesContent":["import { renderPeek } from '../output.ts';\nimport { peek } from '../verbs.ts';\nimport
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/commands/peek.ts"],"sourcesContent":["import { renderPeek } from '../output.ts';\nimport { peek } from '../verbs.ts';\nimport { withDb } from './shared.ts';\nimport type { Command } from './types.ts';\n\nconst peekCmd: Command = (ctx) => {\n const [pathArg] = ctx.rest;\n if (!pathArg) ctx.usageError(`usage: ${ctx.name} peek <path>`);\n withDb(ctx, (db, cfg) => {\n const result = peek(db, cfg, pathArg);\n console.log(ctx.format === 'json' ? JSON.stringify(result, null, 2) : renderPeek(result));\n });\n};\nexport default peekCmd;\n"],"names":["peekCmd","ctx","rest","pathArg","usageError","name","withDb","db","cfg","result","peek","console","log","format","JSON","stringify","renderPeek"],"mappings":";;;;+BAaA;;;eAAA;;;wBAb2B;uBACN;wBACE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGvB,IAAMA,UAAmB,iBAACC;IACxB,IAAkBA,6BAAAA,IAAIC,IAAI,MAAnBC,UAAWF;IAClB,IAAI,CAACE,SAASF,IAAIG,UAAU,CAAC,AAAC,UAAkB,OAATH,IAAII,IAAI,EAAC;IAChDC,IAAAA,gBAAM,EAACL,KAAK,SAACM,IAAIC;QACf,IAAMC,SAASC,IAAAA,aAAI,EAACH,IAAIC,KAAKL;QAC7BQ,QAAQC,GAAG,CAACX,IAAIY,MAAM,KAAK,SAASC,KAAKC,SAAS,CAACN,QAAQ,MAAM,KAAKO,IAAAA,oBAAU,EAACP;IACnF;AACF;IACA,WAAeT"}
|
|
@@ -8,7 +8,7 @@ Object.defineProperty(exports, "default", {
|
|
|
8
8
|
return _default;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
-
var
|
|
11
|
+
var _sharedts = require("./shared.js");
|
|
12
12
|
function _array_like_to_array(arr, len) {
|
|
13
13
|
if (len == null || len > arr.length) len = arr.length;
|
|
14
14
|
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
@@ -37,7 +37,7 @@ function _unsupported_iterable_to_array(o, minLen) {
|
|
|
37
37
|
var query = function query(ctx) {
|
|
38
38
|
var _ctx_rest = _to_array(ctx.rest), sql = _ctx_rest[0], params = _ctx_rest.slice(1);
|
|
39
39
|
if (!sql) ctx.usageError("usage: ".concat(ctx.name, ' query "<sql>" [params...]'));
|
|
40
|
-
(0,
|
|
40
|
+
(0, _sharedts.runSql)(ctx.resolveConfig(), sql, params, ctx.format, 'ad-hoc query');
|
|
41
41
|
};
|
|
42
42
|
var _default = query;
|
|
43
43
|
/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/commands/query.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/commands/query.ts"],"sourcesContent":["import { runSql } from './shared.ts';\nimport type { Command } from './types.ts';\n\nconst query: Command = (ctx) => {\n const [sql, ...params] = ctx.rest;\n if (!sql) ctx.usageError(`usage: ${ctx.name} query \"<sql>\" [params...]`);\n runSql(ctx.resolveConfig(), sql, params, ctx.format, 'ad-hoc query');\n};\nexport default query;\n"],"names":["query","ctx","rest","sql","params","usageError","name","runSql","resolveConfig","format"],"mappings":";;;;+BAQA;;;eAAA;;;wBARuB;;;;;;;;;;;;;;;;;;;;;;;;;;AAGvB,IAAMA,QAAiB,eAACC;IACtB,IAAyBA,sBAAAA,IAAIC,IAAI,GAA1BC,MAAkBF,cAAb,AAAGG,SAAUH,gBAAb;IACZ,IAAI,CAACE,KAAKF,IAAII,UAAU,CAAC,AAAC,UAAkB,OAATJ,IAAIK,IAAI,EAAC;IAC5CC,IAAAA,gBAAM,EAACN,IAAIO,aAAa,IAAIL,KAAKC,QAAQH,IAAIQ,MAAM,EAAE;AACvD;IACA,WAAeT"}
|
|
@@ -9,10 +9,10 @@ Object.defineProperty(exports, "default", {
|
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
11
|
var _dbts = require("../db.js");
|
|
12
|
-
var
|
|
12
|
+
var _sharedts = require("./shared.js");
|
|
13
13
|
var rebuildCmd = function rebuildCmd(ctx) {
|
|
14
14
|
var result = (0, _dbts.rebuild)(ctx.resolveConfig());
|
|
15
|
-
(0,
|
|
15
|
+
(0, _sharedts.printWarnings)(result.warnings);
|
|
16
16
|
console.log("rebuilt: ".concat((0, _dbts.docCount)(result.db), " docs"));
|
|
17
17
|
result.db.close();
|
|
18
18
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/commands/rebuild.ts"],"sourcesContent":["import { docCount, rebuild } from '../db.ts';\nimport
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/commands/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":["rebuildCmd","ctx","result","rebuild","resolveConfig","printWarnings","warnings","console","log","docCount","db","close"],"mappings":";;;;+BAUA;;;eAAA;;;oBAVkC;wBACJ;AAG9B,IAAMA,aAAsB,oBAACC;IAC3B,IAAMC,SAASC,IAAAA,aAAO,EAACF,IAAIG,aAAa;IACxCC,IAAAA,uBAAa,EAACH,OAAOI,QAAQ;IAC7BC,QAAQC,GAAG,CAAC,AAAC,YAA+B,OAApBC,IAAAA,cAAQ,EAACP,OAAOQ,EAAE,GAAE;IAC5CR,OAAOQ,EAAE,CAACC,KAAK;AACjB;IACA,WAAeX"}
|
|
@@ -2,5 +2,5 @@ import type { ResolvedConfig } from '../config.js';
|
|
|
2
2
|
import type { OpenResult } from '../db.js';
|
|
3
3
|
import type { Ctx } from './types.js';
|
|
4
4
|
export declare function printWarnings(warnings: string[]): void;
|
|
5
|
-
export declare function
|
|
5
|
+
export declare function withDb(ctx: Ctx, fn: (db: OpenResult['db'], cfg: ResolvedConfig) => void): void;
|
|
6
6
|
export declare function runSql(cfg: ResolvedConfig, sql: string, params: string[], format: 'table' | 'json', label: string): void;
|
|
@@ -2,5 +2,5 @@ import type { ResolvedConfig } from '../config.js';
|
|
|
2
2
|
import type { OpenResult } from '../db.js';
|
|
3
3
|
import type { Ctx } from './types.js';
|
|
4
4
|
export declare function printWarnings(warnings: string[]): void;
|
|
5
|
-
export declare function
|
|
5
|
+
export declare function withDb(ctx: Ctx, fn: (db: OpenResult['db'], cfg: ResolvedConfig) => void): void;
|
|
6
6
|
export declare function runSql(cfg: ResolvedConfig, sql: string, params: string[], format: 'table' | 'json', label: string): void;
|
|
@@ -15,8 +15,8 @@ _export(exports, {
|
|
|
15
15
|
get runSql () {
|
|
16
16
|
return runSql;
|
|
17
17
|
},
|
|
18
|
-
get
|
|
19
|
-
return
|
|
18
|
+
get withDb () {
|
|
19
|
+
return withDb;
|
|
20
20
|
}
|
|
21
21
|
});
|
|
22
22
|
var _dbts = require("../db.js");
|
|
@@ -68,7 +68,7 @@ function printWarnings(warnings) {
|
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
|
-
function
|
|
71
|
+
function withDb(ctx, fn) {
|
|
72
72
|
var cfg = ctx.resolveConfig();
|
|
73
73
|
var _open = (0, _dbts.open)(cfg), db = _open.db, warnings = _open.warnings;
|
|
74
74
|
printWarnings(warnings);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/commands/shared.ts"],"sourcesContent":["import type { ResolvedConfig } from '../config.ts';\nimport type { OpenResult } from '../db.ts';\nimport { open } from '../db.ts';\nimport type { Row } from '../output.ts';\nimport { printRows } from '../output.ts';\nimport type { Ctx } from './types.ts';\n\n// Shared open-query-close envelope for commands that touch the tree.\n\nexport function printWarnings(warnings: string[]): void {\n for (const w of warnings) console.warn(w);\n}\n\nexport function withDb(ctx: Ctx, fn: (db: OpenResult['db'], cfg: ResolvedConfig) => void): void {\n const cfg = ctx.resolveConfig();\n const { db, warnings } = open(cfg);\n printWarnings(warnings);\n try {\n fn(db, cfg);\n } finally {\n db.close();\n }\n}\n\n// An unbound `?` silently binds NULL, so mismatched param counts fail loudly instead.\nexport function runSql(cfg: ResolvedConfig, sql: string, params: string[], format: 'table' | 'json', label: string): void {\n const placeholderCount = (sql.match(/\\?/g) ?? []).length;\n if (params.length !== placeholderCount) {\n console.error(`${label} expects ${placeholderCount} parameter(s), got ${params.length}`);\n process.exit(2);\n }\n const { db, warnings } = open(cfg);\n printWarnings(warnings);\n printRows(db.prepare(sql).all(...params) as Row[], format);\n db.close();\n}\n"],"names":["printWarnings","runSql","withDb","warnings","w","console","warn","ctx","fn","cfg","resolveConfig","open","db","close","sql","params","format","label","placeholderCount","match","length","error","process","exit","printRows","prepare","all"],"mappings":";;;;;;;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
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
11
|
var _dbts = require("../db.js");
|
|
12
|
-
var
|
|
12
|
+
var _sharedts = require("./shared.js");
|
|
13
13
|
var status = function status(ctx) {
|
|
14
14
|
var _open = (0, _dbts.open)(ctx.resolveConfig()), db = _open.db, dbPath = _open.dbPath, warnings = _open.warnings;
|
|
15
|
-
(0,
|
|
15
|
+
(0, _sharedts.printWarnings)(warnings);
|
|
16
16
|
console.log("db: ".concat(dbPath));
|
|
17
17
|
console.log("docs: ".concat((0, _dbts.docCount)(db)));
|
|
18
18
|
var heartbeat = (0, _dbts.getMeta)(db, 'watch_heartbeat');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/commands/status.ts"],"sourcesContent":["import { docCount, getMeta, open } from '../db.ts';\nimport
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/commands/status.ts"],"sourcesContent":["import { docCount, getMeta, open } from '../db.ts';\nimport { printWarnings } from './shared.ts';\nimport type { Command } from './types.ts';\n\nconst status: Command = (ctx) => {\n const { db, dbPath, warnings } = open(ctx.resolveConfig());\n printWarnings(warnings);\n console.log(`db: ${dbPath}`);\n console.log(`docs: ${docCount(db)}`);\n const heartbeat = getMeta(db, 'watch_heartbeat');\n if (heartbeat) console.log(`watcher: last heartbeat ${Math.round((Date.now() - Date.parse(heartbeat)) / 1000)}s ago`);\n else console.log('watcher: no watcher');\n db.close();\n};\nexport default status;\n"],"names":["status","ctx","open","resolveConfig","db","dbPath","warnings","printWarnings","console","log","docCount","heartbeat","getMeta","Math","round","Date","now","parse","close"],"mappings":";;;;+BAcA;;;eAAA;;;oBAdwC;wBACV;AAG9B,IAAMA,SAAkB,gBAACC;IACvB,IAAiCC,QAAAA,IAAAA,UAAI,EAACD,IAAIE,aAAa,KAA/CC,KAAyBF,MAAzBE,IAAIC,SAAqBH,MAArBG,QAAQC,WAAaJ,MAAbI;IACpBC,IAAAA,uBAAa,EAACD;IACdE,QAAQC,GAAG,CAAC,AAAC,OAAa,OAAPJ;IACnBG,QAAQC,GAAG,CAAC,AAAC,SAAqB,OAAbC,IAAAA,cAAQ,EAACN;IAC9B,IAAMO,YAAYC,IAAAA,aAAO,EAACR,IAAI;IAC9B,IAAIO,WAAWH,QAAQC,GAAG,CAAC,AAAC,2BAAkF,OAAxDI,KAAKC,KAAK,CAAC,AAACC,CAAAA,KAAKC,GAAG,KAAKD,KAAKE,KAAK,CAACN,UAAS,IAAK,OAAM;SACzGH,QAAQC,GAAG,CAAC;IACjBL,GAAGc,KAAK;AACV;IACA,WAAelB"}
|
|
@@ -9,7 +9,7 @@ Object.defineProperty(exports, "default", {
|
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
11
|
var _watchts = require("../watch.js");
|
|
12
|
-
var
|
|
12
|
+
var _sharedts = require("./shared.js");
|
|
13
13
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
14
14
|
try {
|
|
15
15
|
var info = gen[key](arg);
|
|
@@ -152,7 +152,7 @@ var watch = function watch(ctx) {
|
|
|
152
152
|
console.log("".concat(ctx.name, " watch: watching ").concat(event.baseDir));
|
|
153
153
|
console.log("".concat(ctx.name, " watch: db ").concat(event.dbPath));
|
|
154
154
|
} else if (event.type === 'reconciled') {
|
|
155
|
-
(0,
|
|
155
|
+
(0, _sharedts.printWarnings)(event.warnings);
|
|
156
156
|
if (event.parsed > 0) console.log("".concat(ctx.name, " watch: reconciled, ").concat(event.parsed, " file(s) reparsed (").concat(event.total, " total)"));
|
|
157
157
|
} else {
|
|
158
158
|
console.error("".concat(ctx.name, " watch: reconcile error: ").concat(event.message));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/commands/watch.ts"],"sourcesContent":["import type { WatchEvent } from '../watch.ts';\nimport { runWatch } from '../watch.ts';\nimport
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/commands/watch.ts"],"sourcesContent":["import type { WatchEvent } from '../watch.ts';\nimport { runWatch } from '../watch.ts';\nimport { printWarnings } from './shared.ts';\nimport type { Command } from './types.ts';\n\nconst watch: Command = async (ctx) => {\n await runWatch(ctx.resolveConfig(), {\n force: ctx.values.force,\n onEvent: (event: WatchEvent) => {\n if (event.type === 'started') {\n console.log(`${ctx.name} watch: watching ${event.baseDir}`);\n console.log(`${ctx.name} watch: db ${event.dbPath}`);\n } else if (event.type === 'reconciled') {\n printWarnings(event.warnings);\n if (event.parsed > 0) console.log(`${ctx.name} watch: reconciled, ${event.parsed} file(s) reparsed (${event.total} total)`);\n } else {\n console.error(`${ctx.name} watch: reconcile error: ${event.message}`);\n }\n },\n });\n};\nexport default watch;\n"],"names":["watch","ctx","runWatch","resolveConfig","force","values","onEvent","event","type","console","log","name","baseDir","dbPath","printWarnings","warnings","parsed","total","error","message"],"mappings":";;;;+BAqBA;;;eAAA;;;uBApByB;wBACK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAG9B,IAAMA,QAAiB,eAAOC;;;;;oBAC5B;;wBAAMC,IAAAA,iBAAQ,EAACD,IAAIE,aAAa,IAAI;4BAClCC,OAAOH,IAAII,MAAM,CAACD,KAAK;4BACvBE,SAAS,SAATA,QAAUC;gCACR,IAAIA,MAAMC,IAAI,KAAK,WAAW;oCAC5BC,QAAQC,GAAG,CAAC,AAAC,GAA8BH,OAA5BN,IAAIU,IAAI,EAAC,qBAAiC,OAAdJ,MAAMK,OAAO;oCACxDH,QAAQC,GAAG,CAAC,AAAC,GAAwBH,OAAtBN,IAAIU,IAAI,EAAC,eAA0B,OAAbJ,MAAMM,MAAM;gCACnD,OAAO,IAAIN,MAAMC,IAAI,KAAK,cAAc;oCACtCM,IAAAA,uBAAa,EAACP,MAAMQ,QAAQ;oCAC5B,IAAIR,MAAMS,MAAM,GAAG,GAAGP,QAAQC,GAAG,CAAC,AAAC,GAAiCH,OAA/BN,IAAIU,IAAI,EAAC,wBAAwDJ,OAAlCA,MAAMS,MAAM,EAAC,uBAAiC,OAAZT,MAAMU,KAAK,EAAC;gCACpH,OAAO;oCACLR,QAAQS,KAAK,CAAC,AAAC,GAAsCX,OAApCN,IAAIU,IAAI,EAAC,6BAAyC,OAAdJ,MAAMY,OAAO;gCACpE;4BACF;wBACF;;;oBAbA;;;;;;IAcF;;IACA,WAAenB"}
|
|
@@ -117,7 +117,7 @@ function resolveTarget(src, target, pathSet, byBase) {
|
|
|
117
117
|
return (_ref = (_byBase_get = byBase.get(baseKey(clean))) === null || _byBase_get === void 0 ? void 0 : _byBase_get[0]) !== null && _ref !== void 0 ? _ref : null;
|
|
118
118
|
}
|
|
119
119
|
// A new or deleted file can change any note's resolution, so re-resolve the whole table
|
|
120
|
-
// whenever the
|
|
120
|
+
// whenever the tree changes. An in-memory probe per row; writes only on change.
|
|
121
121
|
function resolveAll(db, files) {
|
|
122
122
|
var pathSet = new Set(files.map(function(f) {
|
|
123
123
|
return f.relPath;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/features/links.ts"],"sourcesContent":["import posix from 'node:path/posix';\nimport type { DatabaseSync } from 'node:sqlite';\nimport type { FileStat } from '../scan.ts';\nimport type { Feature } from './types.ts';\n\n// links(src, target, dst): target as written, dst the resolved path or NULL (a queryable dead link).\n\n// Wikilinks ([[target]], [[target#anchor|alias]], embeds) plus relative markdown links to .md files.\nfunction extract(_raw: string, body: string): string[] {\n const targets = new Set<string>();\n for (const m of body.matchAll(/\\[\\[([^\\]|#]+)(?:#[^\\]|]*)?(?:\\|[^\\]]*)?\\]\\]/g)) {\n const target = m[1].trim();\n if (target) targets.add(target);\n }\n for (const m of body.matchAll(/\\]\\(([^)]+\\.md)(?:#[^)]*)?\\)/g)) {\n const target = m[1].trim();\n if (target && !/^[a-z]+:\\/\\//i.test(target)) targets.add(target);\n }\n return [...targets];\n}\n\nfunction baseKey(path: string): string {\n return posix.basename(path).replace(/\\.md$/i, '').toLowerCase();\n}\n\n// Obsidian-style: exact relative path (with/without .md), path relative to the linking\n// note's directory, then basename match (lexicographically first on ties).\nfunction resolveTarget(src: string, target: string, pathSet: Set<string>, byBase: Map<string, string[]>): string | null {\n const clean = target.replace(/\\\\/g, '/').replace(/^\\.\\//, '');\n const fromSrc = posix.normalize(posix.join(posix.dirname(src), clean));\n for (const candidate of [clean, `${clean}.md`, fromSrc, `${fromSrc}.md`]) {\n if (pathSet.has(candidate)) return candidate;\n }\n return byBase.get(baseKey(clean))?.[0] ?? null;\n}\n\n// A new or deleted file can change any note's resolution, so re-resolve the whole table\n// whenever the
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/features/links.ts"],"sourcesContent":["import posix from 'node:path/posix';\nimport type { DatabaseSync } from 'node:sqlite';\nimport type { FileStat } from '../scan.ts';\nimport type { Feature } from './types.ts';\n\n// links(src, target, dst): target as written, dst the resolved path or NULL (a queryable dead link).\n\n// Wikilinks ([[target]], [[target#anchor|alias]], embeds) plus relative markdown links to .md files.\nfunction extract(_raw: string, body: string): string[] {\n const targets = new Set<string>();\n for (const m of body.matchAll(/\\[\\[([^\\]|#]+)(?:#[^\\]|]*)?(?:\\|[^\\]]*)?\\]\\]/g)) {\n const target = m[1].trim();\n if (target) targets.add(target);\n }\n for (const m of body.matchAll(/\\]\\(([^)]+\\.md)(?:#[^)]*)?\\)/g)) {\n const target = m[1].trim();\n if (target && !/^[a-z]+:\\/\\//i.test(target)) targets.add(target);\n }\n return [...targets];\n}\n\nfunction baseKey(path: string): string {\n return posix.basename(path).replace(/\\.md$/i, '').toLowerCase();\n}\n\n// Obsidian-style: exact relative path (with/without .md), path relative to the linking\n// note's directory, then basename match (lexicographically first on ties).\nfunction resolveTarget(src: string, target: string, pathSet: Set<string>, byBase: Map<string, string[]>): string | null {\n const clean = target.replace(/\\\\/g, '/').replace(/^\\.\\//, '');\n const fromSrc = posix.normalize(posix.join(posix.dirname(src), clean));\n for (const candidate of [clean, `${clean}.md`, fromSrc, `${fromSrc}.md`]) {\n if (pathSet.has(candidate)) return candidate;\n }\n return byBase.get(baseKey(clean))?.[0] ?? null;\n}\n\n// A new or deleted file can change any note's resolution, so re-resolve the whole table\n// whenever the tree changes. An in-memory probe per row; writes only on change.\nfunction resolveAll(db: DatabaseSync, files: FileStat[]): void {\n const pathSet = new Set(files.map((f) => f.relPath));\n const byBase = new Map<string, string[]>();\n for (const path of [...pathSet].sort()) {\n const list = byBase.get(baseKey(path));\n if (list) list.push(path);\n else byBase.set(baseKey(path), [path]);\n }\n const rows = db.prepare('SELECT src, target, dst FROM links').all() as Array<{ src: string; target: string; dst: string | null }>;\n const update = db.prepare('UPDATE links SET dst = ? WHERE src = ? AND target = ?');\n for (const row of rows) {\n const dst = resolveTarget(row.src, row.target, pathSet, byBase);\n if (dst !== row.dst) update.run(dst, row.src, row.target);\n }\n}\n\n// Resolved edges, for rank and for find's graph expansion.\nexport function linkEdges(db: DatabaseSync): [string, string][] {\n return (db.prepare('SELECT src, dst FROM links WHERE dst IS NOT NULL').all() as Array<{ src: string; dst: string }>).map((r) => [r.src, r.dst]);\n}\n\nexport const links: Feature = {\n name: 'links',\n schema(db) {\n db.exec('CREATE TABLE IF NOT EXISTS links (src TEXT, target TEXT, dst TEXT, PRIMARY KEY (src, target))');\n db.exec('CREATE INDEX IF NOT EXISTS links_dst ON links(dst)');\n },\n extract,\n remove(db, path) {\n db.prepare('DELETE FROM links WHERE src = ?').run(path);\n },\n store(db, path, extracted) {\n const insert = db.prepare('INSERT OR REPLACE INTO links (src, target, dst) VALUES (?, ?, NULL)');\n for (const target of extracted as string[]) insert.run(path, target);\n },\n afterReconcile: resolveAll,\n};\n"],"names":["linkEdges","links","extract","_raw","body","targets","Set","matchAll","m","target","trim","add","test","baseKey","path","posix","basename","replace","toLowerCase","resolveTarget","src","pathSet","byBase","clean","fromSrc","normalize","join","dirname","candidate","has","get","resolveAll","db","files","map","f","relPath","Map","sort","list","push","set","rows","prepare","all","update","row","dst","run","r","name","schema","exec","remove","store","extracted","insert","afterReconcile"],"mappings":";;;;;;;;;;;QAuDgBA;eAAAA;;QAIHC;eAAAA;;;4DA3DK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKlB,qGAAqG;AAErG,qGAAqG;AACrG,SAASC,QAAQC,IAAY,EAAEC,IAAY;IACzC,IAAMC,UAAU,IAAIC;QACf,kCAAA,2BAAA;;QAAL,QAAK,YAAWF,KAAKG,QAAQ,CAAC,qEAAzB,SAAA,6BAAA,QAAA,yBAAA,iCAA2E;YAA3E,IAAMC,IAAN;YACH,IAAMC,SAASD,CAAC,CAAC,EAAE,CAACE,IAAI;YACxB,IAAID,QAAQJ,QAAQM,GAAG,CAACF;QAC1B;;QAHK;QAAA;;;iBAAA,6BAAA;gBAAA;;;gBAAA;sBAAA;;;;QAIA,mCAAA,4BAAA;;QAAL,QAAK,aAAWL,KAAKG,QAAQ,CAAC,qDAAzB,UAAA,8BAAA,SAAA,0BAAA,kCAA2D;YAA3D,IAAMC,KAAN;YACH,IAAMC,UAASD,EAAC,CAAC,EAAE,CAACE,IAAI;YACxB,IAAID,WAAU,CAAC,gBAAgBG,IAAI,CAACH,UAASJ,QAAQM,GAAG,CAACF;QAC3D;;QAHK;QAAA;;;iBAAA,8BAAA;gBAAA;;;gBAAA;sBAAA;;;;IAIL,OAAQ,qBAAGJ;AACb;AAEA,SAASQ,QAAQC,IAAY;IAC3B,OAAOC,cAAK,CAACC,QAAQ,CAACF,MAAMG,OAAO,CAAC,UAAU,IAAIC,WAAW;AAC/D;AAEA,uFAAuF;AACvF,2EAA2E;AAC3E,SAASC,cAAcC,GAAW,EAAEX,MAAc,EAAEY,OAAoB,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B,GAAG,EAAE0B,IAAIrC,MAAM,EAAEY,SAASC;YACxD,IAAIyB,QAAQD,IAAIC,GAAG,EAAEF,OAAOG,GAAG,CAACD,KAAKD,IAAI1B,GAAG,EAAE0B,IAAIrC,MAAM;QAC1D;;QAHK;QAAA;;;iBAAA,8BAAA;gBAAA;;;gBAAA;sBAAA;;;;AAIP;AAGO,SAAST,UAAUgC,EAAgB;IACxC,OAAO,AAACA,GAAGW,OAAO,CAAC,oDAAoDC,GAAG,GAA2CV,GAAG,CAAC,SAACe;eAAM;YAACA,EAAE7B,GAAG;YAAE6B,EAAEF,GAAG;SAAC;;AAChJ;AAEO,IAAM9C,QAAiB;IAC5BiD,MAAM;IACNC,QAAAA,SAAAA,OAAOnB,EAAE;QACPA,GAAGoB,IAAI,CAAC;QACRpB,GAAGoB,IAAI,CAAC;IACV;IACAlD,SAAAA;IACAmD,QAAAA,SAAAA,OAAOrB,EAAE,EAAElB,IAAI;QACbkB,GAAGW,OAAO,CAAC,mCAAmCK,GAAG,CAAClC;IACpD;IACAwC,OAAAA,SAAAA,MAAMtB,EAAE,EAAElB,IAAI,EAAEyC,SAAS;QACvB,IAAMC,SAASxB,GAAGW,OAAO,CAAC;YACrB,kCAAA,2BAAA;;YAAL,QAAK,YAAgBY,8BAAhB,SAAA,6BAAA,QAAA,yBAAA;gBAAA,IAAM9C,SAAN;gBAAuC+C,OAAOR,GAAG,CAAClC,MAAML;;;YAAxD;YAAA;;;qBAAA,6BAAA;oBAAA;;;oBAAA;0BAAA;;;;IACP;IACAgD,gBAAgB1B;AAClB"}
|
package/dist/cjs/index.d.cts
CHANGED
|
@@ -13,7 +13,7 @@ export type { Row } from './output.js';
|
|
|
13
13
|
export { printRows } from './output.js';
|
|
14
14
|
export type { FileStat, ParsedDoc } from './scan.js';
|
|
15
15
|
export { listFiles, parseFile } from './scan.js';
|
|
16
|
-
export type { FindOptions, Peek,
|
|
17
|
-
export { find,
|
|
16
|
+
export type { FindOptions, Peek, TreeMap } from './verbs.js';
|
|
17
|
+
export { find, mapTree, peek } from './verbs.js';
|
|
18
18
|
export type { WatchEvent, WatchOptions } from './watch.js';
|
|
19
19
|
export { runWatch } from './watch.js';
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export type { Row } from './output.js';
|
|
|
13
13
|
export { printRows } from './output.js';
|
|
14
14
|
export type { FileStat, ParsedDoc } from './scan.js';
|
|
15
15
|
export { listFiles, parseFile } from './scan.js';
|
|
16
|
-
export type { FindOptions, Peek,
|
|
17
|
-
export { find,
|
|
16
|
+
export type { FindOptions, Peek, TreeMap } from './verbs.js';
|
|
17
|
+
export { find, mapTree, peek } from './verbs.js';
|
|
18
18
|
export type { WatchEvent, WatchOptions } from './watch.js';
|
|
19
19
|
export { runWatch } from './watch.js';
|
package/dist/cjs/index.js
CHANGED
|
@@ -64,6 +64,9 @@ _export(exports, {
|
|
|
64
64
|
get loadConfig () {
|
|
65
65
|
return _configts.loadConfig;
|
|
66
66
|
},
|
|
67
|
+
get mapTree () {
|
|
68
|
+
return _verbsts.mapTree;
|
|
69
|
+
},
|
|
67
70
|
get migrateConfig () {
|
|
68
71
|
return _configts.migrateConfig;
|
|
69
72
|
},
|
|
@@ -96,9 +99,6 @@ _export(exports, {
|
|
|
96
99
|
},
|
|
97
100
|
get setMeta () {
|
|
98
101
|
return _dbts.setMeta;
|
|
99
|
-
},
|
|
100
|
-
get vaultMap () {
|
|
101
|
-
return _verbsts.vaultMap;
|
|
102
102
|
}
|
|
103
103
|
});
|
|
104
104
|
var _configts = require("./config.js");
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/index.ts"],"sourcesContent":["// Public library API.\n\nexport type { Config, FeatureName, ResolvedConfig } from './config.ts';\nexport { CONFIG_FILENAME, enabledFeatures, FEATURE_NAMES, featureEnabled, findConfigPath, initConfig, loadConfig, migrateConfig, STATE_DIR, SUPPORTED_CONFIG_VERSION } from './config.ts';\n\nexport type { OpenResult } from './db.ts';\nexport { DB_FILENAME, docCount, getMeta, open, rebuild, reconcile, setMeta } from './db.ts';\nexport type { SenseErrorCode } from './errors.ts';\nexport { SenseError } from './errors.ts';\nexport { activeFeatures, FEATURES, linkEdges } from './features/index.ts';\nexport type { Section } from './features/sections.ts';\nexport type { Feature } from './features/types.ts';\n\nexport type { Edge } from './graph.ts';\nexport { pagerank, personalizedRank } from './graph.ts';\n\nexport type { Row } from './output.ts';\nexport { printRows } from './output.ts';\n\nexport type { FileStat, ParsedDoc } from './scan.ts';\nexport { listFiles, parseFile } from './scan.ts';\n\nexport type { FindOptions, Peek,
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/index.ts"],"sourcesContent":["// Public library API.\n\nexport type { Config, FeatureName, ResolvedConfig } from './config.ts';\nexport { CONFIG_FILENAME, enabledFeatures, FEATURE_NAMES, featureEnabled, findConfigPath, initConfig, loadConfig, migrateConfig, STATE_DIR, SUPPORTED_CONFIG_VERSION } from './config.ts';\n\nexport type { OpenResult } from './db.ts';\nexport { DB_FILENAME, docCount, getMeta, open, rebuild, reconcile, setMeta } from './db.ts';\nexport type { SenseErrorCode } from './errors.ts';\nexport { SenseError } from './errors.ts';\nexport { activeFeatures, FEATURES, linkEdges } from './features/index.ts';\nexport type { Section } from './features/sections.ts';\nexport type { Feature } from './features/types.ts';\n\nexport type { Edge } from './graph.ts';\nexport { pagerank, personalizedRank } from './graph.ts';\n\nexport type { Row } from './output.ts';\nexport { printRows } from './output.ts';\n\nexport type { FileStat, ParsedDoc } from './scan.ts';\nexport { listFiles, parseFile } from './scan.ts';\n\nexport type { FindOptions, Peek, TreeMap } from './verbs.ts';\nexport { find, mapTree, peek } from './verbs.ts';\n\nexport type { WatchEvent, WatchOptions } from './watch.ts';\nexport { runWatch } from './watch.ts';\n"],"names":["CONFIG_FILENAME","DB_FILENAME","FEATURES","FEATURE_NAMES","STATE_DIR","SUPPORTED_CONFIG_VERSION","SenseError","activeFeatures","docCount","enabledFeatures","featureEnabled","find","findConfigPath","getMeta","initConfig","linkEdges","listFiles","loadConfig","mapTree","migrateConfig","open","pagerank","parseFile","peek","personalizedRank","printRows","rebuild","reconcile","runWatch","setMeta"],"mappings":"AAAA,sBAAsB;;;;;;;;;;;;QAGbA;eAAAA,yBAAe;;QAGfC;eAAAA,iBAAW;;QAGKC;eAAAA,iBAAQ;;QANUC;eAAAA,uBAAa;;QAAyEC;eAAAA,mBAAS;;QAAEC;eAAAA,kCAAwB;;QAK3JC;eAAAA,oBAAU;;QACVC;eAAAA,uBAAc;;QAHDC;eAAAA,cAAQ;;QAHJC;eAAAA,yBAAe;;QAAiBC;eAAAA,wBAAc;;QAoB/DC;eAAAA,aAAI;;QApB6DC;eAAAA,wBAAc;;QAGxDC;eAAAA,aAAO;;QAHmDC;eAAAA,oBAAU;;QAMjEC;eAAAA,kBAAS;;QAWnCC;eAAAA,iBAAS;;QAjBoFC;eAAAA,oBAAU;;QAoBjGC;eAAAA,gBAAO;;QApB4FC;eAAAA,uBAAa;;QAGtFC;eAAAA,UAAI;;QAQpCC;eAAAA,iBAAQ;;QAMGC;eAAAA,iBAAS;;QAGLC;eAAAA,aAAI;;QATTC;eAAAA,yBAAgB;;QAG1BC;eAAAA,mBAAS;;QAX6BC;eAAAA,aAAO;;QAAEC;eAAAA,eAAS;;QAoBxDC;eAAAA,iBAAQ;;QApBkDC;eAAAA,aAAO;;;wBAHkG;oBAG1F;wBAEvD;uBACyB;uBAKT;wBAGjB;sBAGW;uBAGD;uBAGX"}
|
package/dist/cjs/verbs.d.cts
CHANGED
|
@@ -6,7 +6,7 @@ export interface FindOptions {
|
|
|
6
6
|
where?: string;
|
|
7
7
|
}
|
|
8
8
|
export declare function find(db: DatabaseSync, cfg: Config, terms: string, opts?: FindOptions): Row[];
|
|
9
|
-
export interface
|
|
9
|
+
export interface TreeMap {
|
|
10
10
|
docs: {
|
|
11
11
|
count: number;
|
|
12
12
|
bytes: number;
|
|
@@ -16,7 +16,7 @@ export interface VaultMap {
|
|
|
16
16
|
hubs: Row[];
|
|
17
17
|
recent: Row[];
|
|
18
18
|
}
|
|
19
|
-
export declare function
|
|
19
|
+
export declare function mapTree(db: DatabaseSync, cfg: Config): TreeMap;
|
|
20
20
|
export interface Peek {
|
|
21
21
|
path: string;
|
|
22
22
|
tokens: number;
|
package/dist/cjs/verbs.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export interface FindOptions {
|
|
|
6
6
|
where?: string;
|
|
7
7
|
}
|
|
8
8
|
export declare function find(db: DatabaseSync, cfg: Config, terms: string, opts?: FindOptions): Row[];
|
|
9
|
-
export interface
|
|
9
|
+
export interface TreeMap {
|
|
10
10
|
docs: {
|
|
11
11
|
count: number;
|
|
12
12
|
bytes: number;
|
|
@@ -16,7 +16,7 @@ export interface VaultMap {
|
|
|
16
16
|
hubs: Row[];
|
|
17
17
|
recent: Row[];
|
|
18
18
|
}
|
|
19
|
-
export declare function
|
|
19
|
+
export declare function mapTree(db: DatabaseSync, cfg: Config): TreeMap;
|
|
20
20
|
export interface Peek {
|
|
21
21
|
path: string;
|
|
22
22
|
tokens: number;
|
package/dist/cjs/verbs.js
CHANGED
|
@@ -12,11 +12,11 @@ _export(exports, {
|
|
|
12
12
|
get find () {
|
|
13
13
|
return find;
|
|
14
14
|
},
|
|
15
|
+
get mapTree () {
|
|
16
|
+
return mapTree;
|
|
17
|
+
},
|
|
15
18
|
get peek () {
|
|
16
19
|
return peek;
|
|
17
|
-
},
|
|
18
|
-
get vaultMap () {
|
|
19
|
-
return vaultMap;
|
|
20
20
|
}
|
|
21
21
|
});
|
|
22
22
|
var _posix = /*#__PURE__*/ _interop_require_default(require("node:path/posix"));
|
|
@@ -87,7 +87,7 @@ function _unsupported_iterable_to_array(o, minLen) {
|
|
|
87
87
|
if (n === "Map" || n === "Set") return Array.from(n);
|
|
88
88
|
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
89
89
|
}
|
|
90
|
-
// The three layer verbs:
|
|
90
|
+
// The three layer verbs: mapTree (orient), find (locate), peek (structure).
|
|
91
91
|
// Each returns data; cli.ts renders. All of them degrade when a feature is off.
|
|
92
92
|
var WEIGHTED_BM25 = 'bm25(content, 10.0, 5.0, 1.0)';
|
|
93
93
|
var RRF_K = 60;
|
|
@@ -175,7 +175,7 @@ var INTERNAL_COLUMNS = new Set([
|
|
|
175
175
|
'_size',
|
|
176
176
|
'_rank'
|
|
177
177
|
]);
|
|
178
|
-
function
|
|
178
|
+
function mapTree(db, cfg) {
|
|
179
179
|
var docs = db.prepare('SELECT COUNT(*) AS count, COALESCE(SUM("_size"), 0) AS bytes FROM frontmatter').get();
|
|
180
180
|
var columns = db.prepare('PRAGMA table_info(frontmatter)').all().map(function(r) {
|
|
181
181
|
return r.name;
|
package/dist/cjs/verbs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/verbs.ts"],"sourcesContent":["import posix from 'node:path/posix';\nimport type { DatabaseSync } from 'node:sqlite';\nimport type { Config } from './config.ts';\nimport { featureEnabled } from './config.ts';\nimport { SenseError } from './errors.ts';\nimport { linkEdges } from './features/index.ts';\nimport { personalizedRank } from './graph.ts';\nimport type { Row } from './output.ts';\n\n// The three layer verbs: vaultMap (orient), find (locate), peek (structure).\n// Each returns data; cli.ts renders. All of them degrade when a feature is off.\n\nconst WEIGHTED_BM25 = 'bm25(content, 10.0, 5.0, 1.0)';\nconst RRF_K = 60;\n\nexport interface FindOptions {\n k?: number;\n where?: string; // SQL fragment against frontmatter alias `f`, e.g. \"f.status = 'active'\"\n}\n\n// Layer 1: BM25 + link-graph expansion, fused by reciprocal rank. `via` says which\n// signal produced each row so the agent knows what evidence it is trusting.\nexport function find(db: DatabaseSync, cfg: Config, terms: string, opts: FindOptions = {}): Row[] {\n const k = opts.k ?? 10;\n const fetch = Math.max(k * 3, 30);\n\n // Terms pass verbatim to FTS5 MATCH: bare words AND-join, operators are the caller's.\n // Invalid syntax propagates as an error, zero matches return zero -- no silent rewrites.\n const matchSql = `SELECT content.path AS path, snippet(content, -1, '«', '»', '…', 10) AS hit FROM content WHERE content MATCH ? ORDER BY ${WEIGHTED_BM25} LIMIT ${fetch}`;\n const matchRows = db.prepare(matchSql).all(terms) as Array<{ path: string; hit: string }>;\n\n const hits = new Map(matchRows.map((r) => [r.path, r.hit]));\n const candidates = new Map<string, { score: number; via: string }>();\n matchRows.forEach((r, i) => {\n candidates.set(r.path, { score: 1 / (RRF_K + i), via: 'match' });\n });\n\n if (featureEnabled(cfg, 'links') && matchRows.length > 0) {\n const nodes = (db.prepare('SELECT \"path\" FROM frontmatter').all() as Array<{ path: string }>).map((r) => r.path);\n const seeds = new Map(matchRows.map((r, i) => [r.path, 1 / (i + 1)]));\n const ranked = [...personalizedRank(nodes, linkEdges(db), seeds)]\n .filter(([, score]) => score > 1e-9)\n .sort((a, b) => b[1] - a[1])\n .slice(0, fetch);\n ranked.forEach(([path], i) => {\n const existing = candidates.get(path);\n if (existing) {\n existing.score += 1 / (RRF_K + i);\n existing.via = 'match+link';\n } else {\n candidates.set(path, { score: 1 / (RRF_K + i), via: 'link' });\n }\n });\n }\n\n db.exec('CREATE TEMP TABLE IF NOT EXISTS _find (\"path\" TEXT PRIMARY KEY, score REAL, via TEXT, hit TEXT)');\n db.exec('DELETE FROM _find');\n const insert = db.prepare('INSERT INTO _find (\"path\", score, via, hit) VALUES (?, ?, ?, ?)');\n for (const [path, c] of candidates) insert.run(path, c.score, c.via, hits.get(path) ?? null);\n\n const where = opts.where ? `WHERE ${opts.where}` : '';\n return db\n .prepare(\n `SELECT f.\"path\" AS path, content.title, content.summary, _find.hit, _find.via, round(_find.score, 4) AS score\n FROM _find JOIN frontmatter f ON f.\"path\" = _find.\"path\" JOIN content ON content.path = _find.\"path\"\n ${where} ORDER BY _find.score DESC LIMIT ?`\n )\n .all(k) as Row[];\n}\n\nexport interface VaultMap {\n docs: { count: number; bytes: number };\n fields: Row[]; // top 20 by coverage; fieldsTotal carries the real count\n fieldsTotal: number;\n hubs: Row[];\n recent: Row[];\n}\n\nconst INTERNAL_COLUMNS = new Set(['path', '_mtime', '_size', '_rank']);\n\n// Layer 0: what is this vault. Fixed-size output regardless of vault size.\nexport function vaultMap(db: DatabaseSync, cfg: Config): VaultMap {\n const docs = db.prepare('SELECT COUNT(*) AS count, COALESCE(SUM(\"_size\"), 0) AS bytes FROM frontmatter').get() as { count: number; bytes: number };\n\n const columns = (db.prepare('PRAGMA table_info(frontmatter)').all() as Array<{ name: string }>).map((r) => r.name).filter((name) => !INTERNAL_COLUMNS.has(name));\n const allFields = columns\n .map((name) => {\n const { n } = db.prepare(`SELECT COUNT(\"${name.split('\"').join('\"\"')}\") AS n FROM frontmatter`).get() as { n: number };\n return { field: name, coverage: n };\n })\n .sort((a, b) => (b.coverage as number) - (a.coverage as number)) as Row[];\n const fields = allFields.slice(0, 20);\n\n const hubs = featureEnabled(cfg, 'rank') ? (db.prepare(`SELECT f.\"path\" AS path, round(f.\"_rank\" * 100, 2) AS rank, content.title FROM frontmatter f JOIN content ON content.path = f.\"path\" WHERE f.\"_rank\" IS NOT NULL ORDER BY f.\"_rank\" DESC LIMIT 8`).all() as Row[]) : [];\n\n const recent = db.prepare(`SELECT \"path\", datetime(\"_mtime\" / 1000, 'unixepoch') AS modified FROM frontmatter ORDER BY \"_mtime\" DESC LIMIT 5`).all() as Row[];\n\n return { docs, fields, fieldsTotal: allFields.length, hubs, recent };\n}\n\nexport interface Peek {\n path: string;\n tokens: number;\n frontmatter: Row;\n sections: Row[];\n outbound: string[];\n backlinks: string[];\n unresolved: string[];\n // Totals before truncation: a hub can have thousands of backlinks, and peek's whole\n // point is bounded output. Query the links table directly for the full list.\n outboundTotal: number;\n backlinksTotal: number;\n unresolvedTotal: number;\n}\n\nconst PEEK_LINK_LIMIT = 20;\n\n// Layer 2: everything about one note except its prose -- frontmatter, outline with line\n// ranges + token estimates (so the follow-up Read is a range, not the file), links both ways.\nexport function peek(db: DatabaseSync, cfg: Config, pathArg: string): Peek {\n const paths = (db.prepare('SELECT \"path\" FROM frontmatter').all() as Array<{ path: string }>).map((r) => r.path);\n let path = paths.find((p) => p === pathArg);\n if (!path) {\n const base = posix.basename(pathArg).replace(/\\.md$/i, '').toLowerCase();\n const matches = paths.filter((p) => posix.basename(p).replace(/\\.md$/i, '').toLowerCase() === base);\n if (matches.length === 1) path = matches[0];\n else if (matches.length > 1) throw new SenseError('NOTE_AMBIGUOUS', `\"${pathArg}\" is ambiguous: ${matches.join(', ')}`);\n else throw new SenseError('NOTE_NOT_FOUND', `no note matches \"${pathArg}\"`);\n }\n\n const row = db.prepare('SELECT * FROM frontmatter WHERE \"path\" = ?').get(path) as Row;\n const frontmatter: Row = {};\n for (const [key, value] of Object.entries(row)) {\n if (!INTERNAL_COLUMNS.has(key) && value !== null) frontmatter[key] = value;\n }\n\n const sections = featureEnabled(cfg, 'sections') ? (db.prepare('SELECT level, heading, start_line, end_line, tokens FROM sections WHERE \"path\" = ? ORDER BY idx').all(path) as Row[]) : [];\n\n let outbound: string[] = [];\n let backlinks: string[] = [];\n let unresolved: string[] = [];\n let backlinksTotal = 0;\n if (featureEnabled(cfg, 'links')) {\n const out = db.prepare('SELECT target, dst FROM links WHERE src = ? ORDER BY target').all(path) as Array<{ target: string; dst: string | null }>;\n outbound = [...new Set(out.filter((l) => l.dst !== null).map((l) => l.dst as string))];\n unresolved = out.filter((l) => l.dst === null).map((l) => l.target);\n backlinksTotal = (db.prepare('SELECT COUNT(DISTINCT src) AS n FROM links WHERE dst = ?').get(path) as { n: number }).n;\n backlinks = (db.prepare('SELECT DISTINCT src FROM links WHERE dst = ? ORDER BY src LIMIT ?').all(path, PEEK_LINK_LIMIT) as Array<{ src: string }>).map((r) => r.src);\n }\n\n return {\n path,\n tokens: Math.ceil(((row._size as number) ?? 0) / 4),\n frontmatter,\n sections,\n outbound: outbound.slice(0, PEEK_LINK_LIMIT),\n backlinks,\n unresolved: unresolved.slice(0, PEEK_LINK_LIMIT),\n outboundTotal: outbound.length,\n backlinksTotal,\n unresolvedTotal: unresolved.length,\n };\n}\n"],"names":["find","peek","vaultMap","WEIGHTED_BM25","RRF_K","db","cfg","terms","opts","hits","k","fetch","Math","max","matchSql","matchRows","prepare","all","Map","map","r","path","hit","candidates","forEach","i","set","score","via","featureEnabled","length","nodes","seeds","ranked","personalizedRank","linkEdges","filter","sort","a","b","slice","existing","get","exec","insert","c","run","where","INTERNAL_COLUMNS","Set","docs","columns","name","has","allFields","n","split","join","field","coverage","fields","hubs","recent","fieldsTotal","PEEK_LINK_LIMIT","pathArg","row","paths","p","base","posix","basename","replace","toLowerCase","matches","SenseError","frontmatter","Object","entries","key","value","sections","outbound","backlinks","unresolved","backlinksTotal","out","l","dst","target","src","tokens","ceil","_size","outboundTotal","unresolvedTotal"],"mappings":";;;;;;;;;;;QAsBgBA;eAAAA;;QAiGAC;eAAAA;;QAtCAC;eAAAA;;;4DAjFE;wBAGa;wBACJ;uBACD;uBACO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGjC,6EAA6E;AAC7E,gFAAgF;AAEhF,IAAMC,gBAAgB;AACtB,IAAMC,QAAQ;AASP,SAASJ,KAAKK,EAAgB,EAAEC,GAAW,EAAEC,KAAa;QAAEC,OAAAA,iEAAoB,CAAC;QAC5EA,SAmC2DC;IAnCrE,IAAMC,KAAIF,UAAAA,KAAKE,CAAC,cAANF,qBAAAA,UAAU;IACpB,IAAMG,QAAQC,KAAKC,GAAG,CAACH,IAAI,GAAG;IAE9B,sFAAsF;IACtF,yFAAyF;IACzF,IAAMI,WAAW,AAAC,iIAAiJH,OAAvBR,eAAc,WAAe,OAANQ;IACnK,IAAMI,YAAYV,GAAGW,OAAO,CAACF,UAAUG,GAAG,CAACV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AC,GAAGwB;QAC5BmB,WAAAA;QACAC,YAAYA,WAAW5C,KAAK,CAAC,GAAGwB;QAChC8B,eAAeZ,SAASpD,MAAM;QAC9BuD,gBAAAA;QACAU,iBAAiBX,WAAWtD,MAAM;IACpC;AACF"}
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/verbs.ts"],"sourcesContent":["import posix from 'node:path/posix';\nimport type { DatabaseSync } from 'node:sqlite';\nimport type { Config } from './config.ts';\nimport { featureEnabled } from './config.ts';\nimport { SenseError } from './errors.ts';\nimport { linkEdges } from './features/index.ts';\nimport { personalizedRank } from './graph.ts';\nimport type { Row } from './output.ts';\n\n// The three layer verbs: mapTree (orient), find (locate), peek (structure).\n// Each returns data; cli.ts renders. All of them degrade when a feature is off.\n\nconst WEIGHTED_BM25 = 'bm25(content, 10.0, 5.0, 1.0)';\nconst RRF_K = 60;\n\nexport interface FindOptions {\n k?: number;\n where?: string; // SQL fragment against frontmatter alias `f`, e.g. \"f.status = 'active'\"\n}\n\n// Layer 1: BM25 + link-graph expansion, fused by reciprocal rank. `via` says which\n// signal produced each row so the agent knows what evidence it is trusting.\nexport function find(db: DatabaseSync, cfg: Config, terms: string, opts: FindOptions = {}): Row[] {\n const k = opts.k ?? 10;\n const fetch = Math.max(k * 3, 30);\n\n // Terms pass verbatim to FTS5 MATCH: bare words AND-join, operators are the caller's.\n // Invalid syntax propagates as an error, zero matches return zero -- no silent rewrites.\n const matchSql = `SELECT content.path AS path, snippet(content, -1, '«', '»', '…', 10) AS hit FROM content WHERE content MATCH ? ORDER BY ${WEIGHTED_BM25} LIMIT ${fetch}`;\n const matchRows = db.prepare(matchSql).all(terms) as Array<{ path: string; hit: string }>;\n\n const hits = new Map(matchRows.map((r) => [r.path, r.hit]));\n const candidates = new Map<string, { score: number; via: string }>();\n matchRows.forEach((r, i) => {\n candidates.set(r.path, { score: 1 / (RRF_K + i), via: 'match' });\n });\n\n if (featureEnabled(cfg, 'links') && matchRows.length > 0) {\n const nodes = (db.prepare('SELECT \"path\" FROM frontmatter').all() as Array<{ path: string }>).map((r) => r.path);\n const seeds = new Map(matchRows.map((r, i) => [r.path, 1 / (i + 1)]));\n const ranked = [...personalizedRank(nodes, linkEdges(db), seeds)]\n .filter(([, score]) => score > 1e-9)\n .sort((a, b) => b[1] - a[1])\n .slice(0, fetch);\n ranked.forEach(([path], i) => {\n const existing = candidates.get(path);\n if (existing) {\n existing.score += 1 / (RRF_K + i);\n existing.via = 'match+link';\n } else {\n candidates.set(path, { score: 1 / (RRF_K + i), via: 'link' });\n }\n });\n }\n\n db.exec('CREATE TEMP TABLE IF NOT EXISTS _find (\"path\" TEXT PRIMARY KEY, score REAL, via TEXT, hit TEXT)');\n db.exec('DELETE FROM _find');\n const insert = db.prepare('INSERT INTO _find (\"path\", score, via, hit) VALUES (?, ?, ?, ?)');\n for (const [path, c] of candidates) insert.run(path, c.score, c.via, hits.get(path) ?? null);\n\n const where = opts.where ? `WHERE ${opts.where}` : '';\n return db\n .prepare(\n `SELECT f.\"path\" AS path, content.title, content.summary, _find.hit, _find.via, round(_find.score, 4) AS score\n FROM _find JOIN frontmatter f ON f.\"path\" = _find.\"path\" JOIN content ON content.path = _find.\"path\"\n ${where} ORDER BY _find.score DESC LIMIT ?`\n )\n .all(k) as Row[];\n}\n\nexport interface TreeMap {\n docs: { count: number; bytes: number };\n fields: Row[]; // top 20 by coverage; fieldsTotal carries the real count\n fieldsTotal: number;\n hubs: Row[];\n recent: Row[];\n}\n\nconst INTERNAL_COLUMNS = new Set(['path', '_mtime', '_size', '_rank']);\n\n// Layer 0: what is this tree. Fixed-size output regardless of tree size.\nexport function mapTree(db: DatabaseSync, cfg: Config): TreeMap {\n const docs = db.prepare('SELECT COUNT(*) AS count, COALESCE(SUM(\"_size\"), 0) AS bytes FROM frontmatter').get() as { count: number; bytes: number };\n\n const columns = (db.prepare('PRAGMA table_info(frontmatter)').all() as Array<{ name: string }>).map((r) => r.name).filter((name) => !INTERNAL_COLUMNS.has(name));\n const allFields = columns\n .map((name) => {\n const { n } = db.prepare(`SELECT COUNT(\"${name.split('\"').join('\"\"')}\") AS n FROM frontmatter`).get() as { n: number };\n return { field: name, coverage: n };\n })\n .sort((a, b) => (b.coverage as number) - (a.coverage as number)) as Row[];\n const fields = allFields.slice(0, 20);\n\n const hubs = featureEnabled(cfg, 'rank') ? (db.prepare(`SELECT f.\"path\" AS path, round(f.\"_rank\" * 100, 2) AS rank, content.title FROM frontmatter f JOIN content ON content.path = f.\"path\" WHERE f.\"_rank\" IS NOT NULL ORDER BY f.\"_rank\" DESC LIMIT 8`).all() as Row[]) : [];\n\n const recent = db.prepare(`SELECT \"path\", datetime(\"_mtime\" / 1000, 'unixepoch') AS modified FROM frontmatter ORDER BY \"_mtime\" DESC LIMIT 5`).all() as Row[];\n\n return { docs, fields, fieldsTotal: allFields.length, hubs, recent };\n}\n\nexport interface Peek {\n path: string;\n tokens: number;\n frontmatter: Row;\n sections: Row[];\n outbound: string[];\n backlinks: string[];\n unresolved: string[];\n // Totals before truncation: a hub can have thousands of backlinks, and peek's whole\n // point is bounded output. Query the links table directly for the full list.\n outboundTotal: number;\n backlinksTotal: number;\n unresolvedTotal: number;\n}\n\nconst PEEK_LINK_LIMIT = 20;\n\n// Layer 2: everything about one note except its prose -- frontmatter, outline with line\n// ranges + token estimates (so the follow-up Read is a range, not the file), links both ways.\nexport function peek(db: DatabaseSync, cfg: Config, pathArg: string): Peek {\n const paths = (db.prepare('SELECT \"path\" FROM frontmatter').all() as Array<{ path: string }>).map((r) => r.path);\n let path = paths.find((p) => p === pathArg);\n if (!path) {\n const base = posix.basename(pathArg).replace(/\\.md$/i, '').toLowerCase();\n const matches = paths.filter((p) => posix.basename(p).replace(/\\.md$/i, '').toLowerCase() === base);\n if (matches.length === 1) path = matches[0];\n else if (matches.length > 1) throw new SenseError('NOTE_AMBIGUOUS', `\"${pathArg}\" is ambiguous: ${matches.join(', ')}`);\n else throw new SenseError('NOTE_NOT_FOUND', `no note matches \"${pathArg}\"`);\n }\n\n const row = db.prepare('SELECT * FROM frontmatter WHERE \"path\" = ?').get(path) as Row;\n const frontmatter: Row = {};\n for (const [key, value] of Object.entries(row)) {\n if (!INTERNAL_COLUMNS.has(key) && value !== null) frontmatter[key] = value;\n }\n\n const sections = featureEnabled(cfg, 'sections') ? (db.prepare('SELECT level, heading, start_line, end_line, tokens FROM sections WHERE \"path\" = ? ORDER BY idx').all(path) as Row[]) : [];\n\n let outbound: string[] = [];\n let backlinks: string[] = [];\n let unresolved: string[] = [];\n let backlinksTotal = 0;\n if (featureEnabled(cfg, 'links')) {\n const out = db.prepare('SELECT target, dst FROM links WHERE src = ? ORDER BY target').all(path) as Array<{ target: string; dst: string | null }>;\n outbound = [...new Set(out.filter((l) => l.dst !== null).map((l) => l.dst as string))];\n unresolved = out.filter((l) => l.dst === null).map((l) => l.target);\n backlinksTotal = (db.prepare('SELECT COUNT(DISTINCT src) AS n FROM links WHERE dst = ?').get(path) as { n: number }).n;\n backlinks = (db.prepare('SELECT DISTINCT src FROM links WHERE dst = ? ORDER BY src LIMIT ?').all(path, PEEK_LINK_LIMIT) as Array<{ src: string }>).map((r) => r.src);\n }\n\n return {\n path,\n tokens: Math.ceil(((row._size as number) ?? 0) / 4),\n frontmatter,\n sections,\n outbound: outbound.slice(0, PEEK_LINK_LIMIT),\n backlinks,\n unresolved: unresolved.slice(0, PEEK_LINK_LIMIT),\n outboundTotal: outbound.length,\n backlinksTotal,\n unresolvedTotal: unresolved.length,\n };\n}\n"],"names":["find","mapTree","peek","WEIGHTED_BM25","RRF_K","db","cfg","terms","opts","hits","k","fetch","Math","max","matchSql","matchRows","prepare","all","Map","map","r","path","hit","candidates","forEach","i","set","score","via","featureEnabled","length","nodes","seeds","ranked","personalizedRank","linkEdges","filter","sort","a","b","slice","existing","get","exec","insert","c","run","where","INTERNAL_COLUMNS","Set","docs","columns","name","has","allFields","n","split","join","field","coverage","fields","hubs","recent","fieldsTotal","PEEK_LINK_LIMIT","pathArg","row","paths","p","base","posix","basename","replace","toLowerCase","matches","SenseError","frontmatter","Object","entries","key","value","sections","outbound","backlinks","unresolved","backlinksTotal","out","l","dst","target","src","tokens","ceil","_size","outboundTotal","unresolvedTotal"],"mappings":";;;;;;;;;;;QAsBgBA;eAAAA;;QA2DAC;eAAAA;;QAsCAC;eAAAA;;;4DAvHE;wBAGa;wBACJ;uBACD;uBACO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGjC,4EAA4E;AAC5E,gFAAgF;AAEhF,IAAMC,gBAAgB;AACtB,IAAMC,QAAQ;AASP,SAASJ,KAAKK,EAAgB,EAAEC,GAAW,EAAEC,KAAa;QAAEC,OAAAA,iEAAoB,CAAC;QAC5EA,SAmC2DC;IAnCrE,IAAMC,KAAIF,UAAAA,KAAKE,CAAC,cAANF,qBAAAA,UAAU;IACpB,IAAMG,QAAQC,KAAKC,GAAG,CAACH,IAAI,GAAG;IAE9B,sFAAsF;IACtF,yFAAyF;IACzF,IAAMI,WAAW,AAAC,iIAAiJH,OAAvBR,eAAc,WAAe,OAANQ;IACnK,IAAMI,YAAYV,GAAGW,OAAO,CAACF,UAAUG,GAAG,CAACV;IAE3C,IAAME,OAAO,IAAIS,IAAIH,UAAUI,GAAG,CAAC,SAACC;eAAM;YAACA,EAAEC,IAAI;YAAED,EAAEE,GAAG;SAAC;;IACzD,IAAMC,aAAa,IAAIL;IACvBH,UAAUS,OAAO,CAAC,SAACJ,GAAGK;QACpBF,WAAWG,GAAG,CAACN,EAAEC,IAAI,EAAE;YAAEM,OAAO,IAAKvB,CAAAA,QAAQqB,CAAAA;YAAIG,KAAK;QAAQ;IAChE;IAEA,IAAIC,IAAAA,wBAAc,EAACvB,KAAK,YAAYS,UAAUe,MAAM,GAAG,GAAG;QACxD,IAAMC,QAAQ,AAAC1B,GAAGW,OAAO,CAAC,kCAAkCC,GAAG,GAA+BE,GAAG,CAAC,SAACC;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rB,IAAIxD,IAAAA,wBAAc,EAACvB,KAAK,UAAU;QAChC,IAAMgF,MAAMjF,GAAGW,OAAO,CAAC,+DAA+DC,GAAG,CAACI;QAC1F6D,WAAY,qBAAG,IAAIjC,IAAIqC,IAAIlD,MAAM,CAAC,SAACmD;mBAAMA,EAAEC,GAAG,KAAK;WAAMrE,GAAG,CAAC,SAACoE;mBAAMA,EAAEC,GAAG;;QACzEJ,aAAaE,IAAIlD,MAAM,CAAC,SAACmD;mBAAMA,EAAEC,GAAG,KAAK;WAAMrE,GAAG,CAAC,SAACoE;mBAAMA,EAAEE,MAAM;;QAClEJ,iBAAiB,AAAChF,GAAGW,OAAO,CAAC,4DAA4D0B,GAAG,CAACrB,MAAwBkC,CAAC;QACtH4B,YAAY,AAAC9E,GAAGW,OAAO,CAAC,qEAAqEC,GAAG,CAACI,MAAM2C,iBAA4C7C,GAAG,CAAC,SAACC;mBAAMA,EAAEsE,GAAG;;IACrK;IAEA,OAAO;QACLrE,MAAAA;QACAsE,QAAQ/E,KAAKgF,IAAI,CAAC,EAAE1B,aAAAA,IAAI2B,KAAK,cAAT3B,wBAAAA,aAAwB,KAAK;QACjDU,aAAAA;QACAK,UAAAA;QACAC,UAAUA,SAAS1C,KAAK,CAAC,GAAGwB;QAC5BmB,WAAAA;QACAC,YAAYA,WAAW5C,KAAK,CAAC,GAAGwB;QAChC8B,eAAeZ,SAASpD,MAAM;QAC9BuD,gBAAAA;QACAU,iBAAiBX,WAAWtD,MAAM;IACpC;AACF"}
|
package/dist/esm/cli.js
CHANGED
|
@@ -3,7 +3,7 @@ import { parseArgs } from 'node:util';
|
|
|
3
3
|
import { COMMANDS } from './commands/index.js';
|
|
4
4
|
import { loadConfig, SUPPORTED_CONFIG_VERSION } from './config.js';
|
|
5
5
|
// Parsing and dispatch only. Commands live in src/commands/, one file each, lazy-loaded --
|
|
6
|
-
// nothing
|
|
6
|
+
// nothing tree- or dependency-heavy may be imported at the top of this file.
|
|
7
7
|
// Works from dist/cjs and dist/esm alike: walk up past the dist type-marker package.json.
|
|
8
8
|
function packageVersion() {
|
|
9
9
|
const load = createRequire(import.meta.url);
|