sensemaking 0.9.3 → 0.9.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -4
- package/dist/cjs/cli/check.js +1 -2
- package/dist/cjs/cli/check.js.map +1 -1
- package/dist/cjs/cli/named.js +5 -2
- package/dist/cjs/cli/named.js.map +1 -1
- package/dist/cjs/cli/shared.d.cts +8 -13
- package/dist/cjs/cli/shared.d.ts +8 -13
- package/dist/cjs/cli/shared.js +29 -124
- package/dist/cjs/cli/shared.js.map +1 -1
- package/dist/cjs/cli.js +111 -116
- package/dist/cjs/cli.js.map +1 -1
- package/dist/esm/cli/check.js +1 -2
- package/dist/esm/cli/check.js.map +1 -1
- package/dist/esm/cli/named.js +5 -2
- package/dist/esm/cli/named.js.map +1 -1
- package/dist/esm/cli/shared.d.ts +8 -13
- package/dist/esm/cli/shared.js +33 -55
- package/dist/esm/cli/shared.js.map +1 -1
- package/dist/esm/cli.js +74 -68
- package/dist/esm/cli.js.map +1 -1
- package/package.json +1 -3
- package/dist/cjs/cli/exit.d.cts +0 -5
- package/dist/cjs/cli/exit.d.ts +0 -5
- package/dist/cjs/cli/exit.js +0 -147
- package/dist/cjs/cli/exit.js.map +0 -1
- package/dist/esm/cli/exit.d.ts +0 -5
- package/dist/esm/cli/exit.js +0 -15
- package/dist/esm/cli/exit.js.map +0 -1
package/README.md
CHANGED
|
@@ -185,10 +185,8 @@ features, frontmatter conventions, and note size are decisions with consequences
|
|
|
185
185
|
Dependencies: [yaml](https://github.com/eemeli/yaml),
|
|
186
186
|
[remove-markdown](https://github.com/zuchka/remove-markdown),
|
|
187
187
|
[fast-glob](https://github.com/mrmlnc/fast-glob),
|
|
188
|
-
[@huggingface/tokenizers](https://github.com/huggingface/tokenizers.js) (pure JS),
|
|
189
|
-
|
|
190
|
-
[exit-compat](https://github.com/kmalakoff/exit-compat) for the CLI, and Node's
|
|
191
|
-
built-in SQLite. No native builds.
|
|
188
|
+
[@huggingface/tokenizers](https://github.com/huggingface/tokenizers.js) (pure JS), and
|
|
189
|
+
Node's built-in SQLite. No native builds.
|
|
192
190
|
|
|
193
191
|
## License
|
|
194
192
|
|
package/dist/cjs/cli/check.js
CHANGED
|
@@ -11,7 +11,6 @@ Object.defineProperty(exports, "default", {
|
|
|
11
11
|
var _commandsts = require("../commands.js");
|
|
12
12
|
var _dbts = require("../db.js");
|
|
13
13
|
var _outputts = require("../output.js");
|
|
14
|
-
var _exitts = require("./exit.js");
|
|
15
14
|
var _indexts = require("./index.js");
|
|
16
15
|
var _sharedts = require("./shared.js");
|
|
17
16
|
function _array_like_to_array(arr, len) {
|
|
@@ -387,7 +386,7 @@ var check = function check(ctx) {
|
|
|
387
386
|
];
|
|
388
387
|
}
|
|
389
388
|
(0, _outputts.printRows)(rows, format);
|
|
390
|
-
if (failed > 0)
|
|
389
|
+
if (failed > 0) process.exit(1);
|
|
391
390
|
return [
|
|
392
391
|
2
|
|
393
392
|
];
|
|
@@ -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 {
|
|
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) process.exit(1);\n};\nexport default check;\n"],"names":["check","ctx","cfg","values","format","open","db","warnings","rows","failed","name","entry","sql","count","err","params","statement","parse","argv","USAGE","FORMAT","CONFIG","formatOf","resolveConfig","config","printWarnings","Object","entries","queries","search","k","where","preset","include","semantic","length","push","query","status","message","match","prepare","all","close","console","log","printRows","process","exit"],"mappings":";;;;+BA8DA;;;eAAA;;;0BA9DuB;oBACF;wBAEK;uBACJ;wBACyC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAG/D,2FAA2F;AAC3F,wFAAwF;AACxF,4FAA4F;AAC5F,2FAA2F;AAC3F,4FAA4F;AAC5F,6FAA6F;AAC7F,8FAA8F;AAC9F,6FAA6F;AAC7F,wFAAwF;AACxF,4FAA4F;AAC5F,IAAMA,QAAiB,eAAOC;;YASeC,cARnCC,QACFC,QACAF,KACmBG,OAAjBC,IAAIC,UAGNC,MACFC,QACC,2BAAA,mBAAA,gBAAA,WAAA,oBAAOC,MAAMC,OAYAC,YATNC,OAECC,KAMLF,KACAG,QAEEC,WAKAH;;;;oBA3BFV,SAAWc,IAAAA,eAAK,EAAChB,IAAIiB,IAAI,EAAE,AAAC,UAAqBC,OAAZlB,IAAIS,IAAI,EAAC,KAAe,OAAZS,cAAK,CAACnB,KAAK,GAAI,mBAAKoB,gBAAM,EAAKC,gBAAM,GAAtFlB;oBACFC,SAASkB,IAAAA,kBAAQ,EAACnB;oBAClBD,MAAMD,IAAIsB,aAAa,CAACpB,OAAOqB,MAAM;oBAClBnB,QAAAA,IAAAA,UAAI,EAACH,MAAtBI,KAAiBD,MAAjBC,IAAIC,WAAaF,MAAbE;oBACZkB,IAAAA,uBAAa,EAAClB;oBAERC;oBACFC,SAAS;oBACR,kCAAA,2BAAA;;;;;;;;;oBAAA,YAAuBiB,OAAOC,OAAO,EAACzB,eAAAA,IAAI0B,OAAO,cAAX1B,0BAAAA,e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K;oBACtG,EAAE,OAAOC,KAAK;wBACZL;wBACAD,KAAK4B,IAAI,CAAC;4BAAEC,OAAO3B;4BAAMK,QAAAA;4BAAQP,MAAM;4BAAK8B,QAAQ,AAAC,WAAiC,OAAvB,AAACxB,IAAcyB,OAAO;wBAAG;oBAC1F;;;oBAxBG;;;;;;;;;;;;oBAAA;oBAAA;;;;;;;6BAAA,6BAAA;4BAAA;;;4BAAA;kCAAA;;;;;;;oBA2BLjC,GAAGqC,KAAK;oBACR,IAAInC,KAAK2B,MAAM,KAAK,GAAG;wBACrBS,QAAQC,GAAG,CAAC;wBACZ;;;oBACF;oBACAC,IAAAA,mBAAS,EAACtC,MAAMJ;oBAChB,IAAIK,SAAS,GAAGsC,QAAQC,IAAI,CAAC;;;;;;IAC/B;;IACA,WAAehD"}
|
package/dist/cjs/cli/named.js
CHANGED
|
@@ -14,7 +14,6 @@ Object.defineProperty(exports, // Fallback when the first positional is not a co
|
|
|
14
14
|
});
|
|
15
15
|
var _commandsts = require("../commands.js");
|
|
16
16
|
var _outputts = require("../output.js");
|
|
17
|
-
var _exitts = require("./exit.js");
|
|
18
17
|
var _sharedts = require("./shared.js");
|
|
19
18
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
20
19
|
try {
|
|
@@ -184,7 +183,11 @@ function named(ctx, queryName) {
|
|
|
184
183
|
configPath = values.config;
|
|
185
184
|
cfg = ctx.resolveConfig(configPath);
|
|
186
185
|
entry = cfg.queries[queryName];
|
|
187
|
-
if (entry === undefined)
|
|
186
|
+
if (entry === undefined) {
|
|
187
|
+
console.error('unknown query: "'.concat(queryName, '"'));
|
|
188
|
+
console.error("valid queries: ".concat(Object.keys(cfg.queries).sort().join(', ')));
|
|
189
|
+
process.exit(2);
|
|
190
|
+
}
|
|
188
191
|
if (typeof entry === 'string') {
|
|
189
192
|
(0, _sharedts.runSql)(cfg, entry, params, format, 'query "'.concat(queryName, '"'));
|
|
190
193
|
return [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/cli/named.ts"],"sourcesContent":["import { search } from '../commands.ts';\nimport { printRows } from '../output.ts';\nimport {
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/cli/named.ts"],"sourcesContent":["import { search } from '../commands.ts';\nimport { printRows } from '../output.ts';\nimport { CONFIG, FORMAT, formatOf, parse, parseK, runSql, SEARCH_FLAGS, withDb } from './shared.ts';\nimport type { Ctx } from './types.ts';\n\n// Fallback when the first positional is not a command: a named query from config, either a\n// SQL string (run as-is) or a saved search (run through the `search` command's own machinery).\n// Flags cover both shapes -- SEARCH_FLAGS override a saved search's fields the same way they\n// override a preset's.\nexport default async function named(ctx: Ctx, queryName: string): Promise<void> {\n const usage = `usage: ${ctx.name} ${queryName} [params...] [--format table|json] [--config path] [--where \"<sql>\"] [--k n] [--preset name] [--include glob ...] [--lexical]`;\n const { values, positionals: params } = parse(ctx.argv, usage, { ...SEARCH_FLAGS, ...FORMAT, ...CONFIG });\n const format = formatOf(values);\n const configPath = values.config as string | undefined;\n\n const cfg = ctx.resolveConfig(configPath);\n const entry = cfg.queries[queryName];\n if (entry === undefined) {\n console.error(`unknown query: \"${queryName}\"`);\n console.error(`valid queries: ${Object.keys(cfg.queries).sort().join(', ')}`);\n process.exit(2);\n }\n\n if (typeof entry === 'string') {\n runSql(cfg, entry, params, format, `query \"${queryName}\"`);\n return;\n }\n if ('sql' in entry) {\n runSql(cfg, entry.sql, params, format, `query \"${queryName}\"`);\n return;\n }\n\n // A saved search's text is fixed in config; there is nowhere for a positional to bind.\n if (params.length > 0) {\n ctx.usageError(`\"${queryName}\" is a saved search and takes no positional parameters; edit its \"search\" in sense.config.json, or use \"${ctx.name} search\" directly`);\n }\n const k = parseK(values.k as string | undefined, ctx.usageError) ?? entry.k;\n const where = (values.where as string | undefined) ?? entry.where;\n const preset = (values.preset as string | undefined) ?? entry.preset;\n const include = (values.include as string[] | undefined) ?? entry.include;\n // --lexical upgrades a saved search's semantic behavior the same way --where/--k\n // override; absent means the saved value (the flag has no default false override).\n const semantic = values.lexical ? false : entry.semantic;\n await withDb(ctx, configPath, async (db, resolvedCfg) => printRows(await search(db, resolvedCfg, entry.search, { k, where, preset, include, semantic }), format));\n}\n"],"names":["named","ctx","queryName","parseK","values","usage","parse","params","format","configPath","cfg","entry","k","where","preset","include","semantic","name","argv","SEARCH_FLAGS","FORMAT","CONFIG","positionals","formatOf","config","resolveConfig","queries","undefined","console","error","Object","keys","sort","join","process","exit","runSql","sql","length","usageError","lexical","withDb","db","resolvedCfg","search","printRows"],"mappings":";;;;+BAKA,2FAA2F;AAC3F,+FAA+F;AAC/F,6FAA6F;AAC7F,uBAAuB;AACvB;;;eAA8BA;;;0BATP;wBACG;wBAC4D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOvE,SAAeA,MAAMC,GAAQ,EAAEC,SAAiB;;YA2BnDC,SACKC,eACCA,gBACCA,iBA7BXC,OACkCC,QAAhCF,QAAqBG,QACvBC,QACAC,YAEAC,KACAC,OAoBAC,GACAC,OACAC,QACAC,SAGAC;;;;oBAhCAX,QAAQ,AAAC,UAAqBH,OAAZD,IAAIgB,IAAI,EAAC,KAAa,OAAVf,WAAU;oBACNI,SAAAA,IAAAA,eAAK,EAACL,IAAIiB,IAAI,EAAEb,OAAO,mBAAKc,sBAAY,EAAKC,gBAAM,EAAKC,gBAAM,IAA9FjB,SAAgCE,OAAhCF,QAAqBG,SAAWD,OAAxBgB;oBACVd,SAASe,IAAAA,kBAAQ,EAACnB;oBAClBK,aAAaL,OAAOoB,MAAM;oBAE1Bd,MAAMT,IAAIwB,aAAa,CAAChB;oBACxBE,QAAQD,IA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AAMC,IAAAA,kBAAM,EAACF,IAAIC,aAAahC,MAAMiC,MAAM,EAAE;oDAAEhC,GAAAA;oDAAGC,OAAAA;oDAAOC,QAAAA;oDAAQC,SAAAA;oDAASC,UAAAA;gDAAS;;;;;gDAA5F6B,mBAAS;oDAAC;oDAAsFrC;;;;;;;;;oBAAzJ;;;;;;IACF"}
|
|
@@ -1,23 +1,18 @@
|
|
|
1
|
+
import type { ParseArgsOptionsConfig } from 'node:util';
|
|
1
2
|
import type { ResolvedConfig } from '../config.js';
|
|
2
3
|
import type { OpenResult } from '../db.js';
|
|
3
4
|
import type { Ctx } from './types.js';
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
short?: string;
|
|
9
|
-
}
|
|
10
|
-
export type Flags = Record<string, Flag>;
|
|
11
|
-
export declare const FORMAT: Flags;
|
|
12
|
-
export declare const CONFIG: Flags;
|
|
13
|
-
export declare const SEARCH_FLAGS: Flags;
|
|
14
|
-
export type Values = Record<string, string | boolean | string[] | undefined>;
|
|
5
|
+
export declare const FORMAT: ParseArgsOptionsConfig;
|
|
6
|
+
export declare const CONFIG: ParseArgsOptionsConfig;
|
|
7
|
+
export declare const SEARCH_FLAGS: ParseArgsOptionsConfig;
|
|
8
|
+
type Values = Record<string, string | boolean | string[] | undefined>;
|
|
15
9
|
export declare function formatOf(values: Values): 'table' | 'json';
|
|
16
|
-
export declare function parse(argv: string[], usage: string,
|
|
10
|
+
export declare function parse(argv: string[], usage: string, options: ParseArgsOptionsConfig): {
|
|
17
11
|
values: Values;
|
|
18
12
|
positionals: string[];
|
|
19
13
|
};
|
|
20
|
-
export declare function parseK(k: string | undefined,
|
|
14
|
+
export declare function parseK(k: string | undefined, usageError: (message: string) => never): number | undefined;
|
|
21
15
|
export declare function printWarnings(warnings: string[]): void;
|
|
22
16
|
export declare function withDb(ctx: Ctx, configPath: string | undefined, fn: (db: OpenResult['db'], cfg: ResolvedConfig) => void | Promise<void>): Promise<void>;
|
|
23
17
|
export declare function runSql(cfg: ResolvedConfig, sql: string, params: string[], format: 'table' | 'json', label: string): void;
|
|
18
|
+
export {};
|
package/dist/cjs/cli/shared.d.ts
CHANGED
|
@@ -1,23 +1,18 @@
|
|
|
1
|
+
import type { ParseArgsOptionsConfig } from 'node:util';
|
|
1
2
|
import type { ResolvedConfig } from '../config.js';
|
|
2
3
|
import type { OpenResult } from '../db.js';
|
|
3
4
|
import type { Ctx } from './types.js';
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
short?: string;
|
|
9
|
-
}
|
|
10
|
-
export type Flags = Record<string, Flag>;
|
|
11
|
-
export declare const FORMAT: Flags;
|
|
12
|
-
export declare const CONFIG: Flags;
|
|
13
|
-
export declare const SEARCH_FLAGS: Flags;
|
|
14
|
-
export type Values = Record<string, string | boolean | string[] | undefined>;
|
|
5
|
+
export declare const FORMAT: ParseArgsOptionsConfig;
|
|
6
|
+
export declare const CONFIG: ParseArgsOptionsConfig;
|
|
7
|
+
export declare const SEARCH_FLAGS: ParseArgsOptionsConfig;
|
|
8
|
+
type Values = Record<string, string | boolean | string[] | undefined>;
|
|
15
9
|
export declare function formatOf(values: Values): 'table' | 'json';
|
|
16
|
-
export declare function parse(argv: string[], usage: string,
|
|
10
|
+
export declare function parse(argv: string[], usage: string, options: ParseArgsOptionsConfig): {
|
|
17
11
|
values: Values;
|
|
18
12
|
positionals: string[];
|
|
19
13
|
};
|
|
20
|
-
export declare function parseK(k: string | undefined,
|
|
14
|
+
export declare function parseK(k: string | undefined, usageError: (message: string) => never): number | undefined;
|
|
21
15
|
export declare function printWarnings(warnings: string[]): void;
|
|
22
16
|
export declare function withDb(ctx: Ctx, configPath: string | undefined, fn: (db: OpenResult['db'], cfg: ResolvedConfig) => void | Promise<void>): Promise<void>;
|
|
23
17
|
export declare function runSql(cfg: ResolvedConfig, sql: string, params: string[], format: 'table' | 'json', label: string): void;
|
|
18
|
+
export {};
|
package/dist/cjs/cli/shared.js
CHANGED
|
@@ -37,19 +37,15 @@ _export(exports, {
|
|
|
37
37
|
return withDb;
|
|
38
38
|
}
|
|
39
39
|
});
|
|
40
|
-
var
|
|
40
|
+
var _nodeutil = require("node:util");
|
|
41
41
|
var _dbts = require("../db.js");
|
|
42
42
|
var _outputts = require("../output.js");
|
|
43
43
|
var _searcherrorts = require("../search-error.js");
|
|
44
|
-
var _exitts = require("./exit.js");
|
|
45
44
|
function _array_like_to_array(arr, len) {
|
|
46
45
|
if (len == null || len > arr.length) len = arr.length;
|
|
47
46
|
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
48
47
|
return arr2;
|
|
49
48
|
}
|
|
50
|
-
function _array_with_holes(arr) {
|
|
51
|
-
if (Array.isArray(arr)) return arr;
|
|
52
|
-
}
|
|
53
49
|
function _array_without_holes(arr) {
|
|
54
50
|
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
|
55
51
|
}
|
|
@@ -95,41 +91,9 @@ function _define_property(obj, key, value) {
|
|
|
95
91
|
}
|
|
96
92
|
return obj;
|
|
97
93
|
}
|
|
98
|
-
function _interop_require_default(obj) {
|
|
99
|
-
return obj && obj.__esModule ? obj : {
|
|
100
|
-
default: obj
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
94
|
function _iterable_to_array(iter) {
|
|
104
95
|
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
105
96
|
}
|
|
106
|
-
function _iterable_to_array_limit(arr, i) {
|
|
107
|
-
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
108
|
-
if (_i == null) return;
|
|
109
|
-
var _arr = [];
|
|
110
|
-
var _n = true;
|
|
111
|
-
var _d = false;
|
|
112
|
-
var _s, _e;
|
|
113
|
-
try {
|
|
114
|
-
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
115
|
-
_arr.push(_s.value);
|
|
116
|
-
if (i && _arr.length === i) break;
|
|
117
|
-
}
|
|
118
|
-
} catch (err) {
|
|
119
|
-
_d = true;
|
|
120
|
-
_e = err;
|
|
121
|
-
} finally{
|
|
122
|
-
try {
|
|
123
|
-
if (!_n && _i["return"] != null) _i["return"]();
|
|
124
|
-
} finally{
|
|
125
|
-
if (_d) throw _e;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
return _arr;
|
|
129
|
-
}
|
|
130
|
-
function _non_iterable_rest() {
|
|
131
|
-
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
132
|
-
}
|
|
133
97
|
function _non_iterable_spread() {
|
|
134
98
|
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
135
99
|
}
|
|
@@ -172,9 +136,6 @@ function _object_spread_props(target, source) {
|
|
|
172
136
|
}
|
|
173
137
|
return target;
|
|
174
138
|
}
|
|
175
|
-
function _sliced_to_array(arr, i) {
|
|
176
|
-
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
177
|
-
}
|
|
178
139
|
function _to_consumable_array(arr) {
|
|
179
140
|
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
180
141
|
}
|
|
@@ -318,100 +279,41 @@ var SEARCH_FLAGS = {
|
|
|
318
279
|
function formatOf(values) {
|
|
319
280
|
return values.format === 'json' ? 'json' : 'table';
|
|
320
281
|
}
|
|
321
|
-
function parse(argv, usage) {
|
|
322
|
-
var
|
|
323
|
-
var
|
|
324
|
-
help: {
|
|
325
|
-
type: 'boolean',
|
|
326
|
-
default: false,
|
|
327
|
-
short: 'h'
|
|
328
|
-
}
|
|
329
|
-
});
|
|
330
|
-
var string = [];
|
|
331
|
-
var boolean = [];
|
|
332
|
-
var alias = {};
|
|
333
|
-
var defaults = {};
|
|
334
|
-
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
282
|
+
function parse(argv, usage, options) {
|
|
283
|
+
var values;
|
|
284
|
+
var positionals;
|
|
335
285
|
try {
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
286
|
+
var ref;
|
|
287
|
+
ref = (0, _nodeutil.parseArgs)({
|
|
288
|
+
args: argv,
|
|
289
|
+
options: _object_spread_props(_object_spread({}, options), {
|
|
290
|
+
help: {
|
|
291
|
+
type: 'boolean',
|
|
292
|
+
default: false,
|
|
293
|
+
short: 'h'
|
|
294
|
+
}
|
|
295
|
+
}),
|
|
296
|
+
strict: true,
|
|
297
|
+
allowPositionals: true
|
|
298
|
+
}), values = ref.values, positionals = ref.positionals, ref;
|
|
342
299
|
} catch (err) {
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
try {
|
|
347
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
348
|
-
_iterator.return();
|
|
349
|
-
}
|
|
350
|
-
} finally{
|
|
351
|
-
if (_didIteratorError) {
|
|
352
|
-
throw _iteratorError;
|
|
353
|
-
}
|
|
354
|
-
}
|
|
300
|
+
console.error(err.message);
|
|
301
|
+
console.error(usage);
|
|
302
|
+
process.exit(2);
|
|
355
303
|
}
|
|
356
|
-
|
|
357
|
-
// ignored, which is the bug 0.9.2 fixed. Record the first and fail below; returning false
|
|
358
|
-
// also keeps it out of the result. `--k -1` arrives here as unknown option "1", because
|
|
359
|
-
// getopts reads a leading dash as a new option rather than as --k's value; the message is
|
|
360
|
-
// blunter than the old one but it is still a usage error rather than a silent default.
|
|
361
|
-
var unknown;
|
|
362
|
-
var parsed = (0, _getoptscompat.default)(argv, {
|
|
363
|
-
string: string,
|
|
364
|
-
boolean: boolean,
|
|
365
|
-
alias: alias,
|
|
366
|
-
default: defaults,
|
|
367
|
-
unknown: function unknown1(name) {
|
|
368
|
-
if (unknown === undefined) unknown = name;
|
|
369
|
-
return false;
|
|
370
|
-
}
|
|
371
|
-
});
|
|
372
|
-
if (unknown !== undefined) (0, _exitts.usageError)("unknown option: ".concat(unknown), usage);
|
|
373
|
-
if (parsed.help) {
|
|
304
|
+
if (values.help) {
|
|
374
305
|
console.log(usage);
|
|
375
|
-
|
|
376
|
-
}
|
|
377
|
-
// Two getopts shapes the callers must not see: an unset string flag reads as "" rather
|
|
378
|
-
// than undefined, and a flag passed once reads as a string rather than a one-element
|
|
379
|
-
// array. Both matter -- `?? saved.field` means "flag absent", and --include is a list.
|
|
380
|
-
var values = {};
|
|
381
|
-
var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
|
|
382
|
-
try {
|
|
383
|
-
for(var _iterator1 = Object.entries(table)[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
|
|
384
|
-
var _step_value1 = _sliced_to_array(_step1.value, 2), name1 = _step_value1[0], flag1 = _step_value1[1];
|
|
385
|
-
var raw = parsed[name1];
|
|
386
|
-
if (flag1.type === 'boolean') values[name1] = raw;
|
|
387
|
-
else if (flag1.multiple) values[name1] = raw === '' ? undefined : Array.isArray(raw) ? raw : [
|
|
388
|
-
raw
|
|
389
|
-
];
|
|
390
|
-
else values[name1] = raw === '' ? undefined : raw;
|
|
391
|
-
}
|
|
392
|
-
} catch (err) {
|
|
393
|
-
_didIteratorError1 = true;
|
|
394
|
-
_iteratorError1 = err;
|
|
395
|
-
} finally{
|
|
396
|
-
try {
|
|
397
|
-
if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
|
|
398
|
-
_iterator1.return();
|
|
399
|
-
}
|
|
400
|
-
} finally{
|
|
401
|
-
if (_didIteratorError1) {
|
|
402
|
-
throw _iteratorError1;
|
|
403
|
-
}
|
|
404
|
-
}
|
|
306
|
+
process.exit(0);
|
|
405
307
|
}
|
|
406
308
|
return {
|
|
407
309
|
values: values,
|
|
408
|
-
positionals:
|
|
310
|
+
positionals: positionals
|
|
409
311
|
};
|
|
410
312
|
}
|
|
411
|
-
function parseK(k,
|
|
313
|
+
function parseK(k, usageError) {
|
|
412
314
|
if (k === undefined) return undefined;
|
|
413
315
|
var parsed = Number(k);
|
|
414
|
-
if (!Number.isInteger(parsed) || parsed <= 0)
|
|
316
|
+
if (!Number.isInteger(parsed) || parsed <= 0) usageError('--k expects a positive integer, got "'.concat(k, '"'));
|
|
415
317
|
return parsed;
|
|
416
318
|
}
|
|
417
319
|
function printWarnings(warnings) {
|
|
@@ -479,7 +381,10 @@ function withDb(ctx, configPath, fn) {
|
|
|
479
381
|
function runSql(cfg, sql, params, format, label) {
|
|
480
382
|
var _sql_match;
|
|
481
383
|
var placeholderCount = ((_sql_match = sql.match(/\?/g)) !== null && _sql_match !== void 0 ? _sql_match : []).length;
|
|
482
|
-
if (params.length !== placeholderCount)
|
|
384
|
+
if (params.length !== placeholderCount) {
|
|
385
|
+
console.error("".concat(label, " expects ").concat(placeholderCount, " parameter(s), got ").concat(params.length));
|
|
386
|
+
process.exit(2);
|
|
387
|
+
}
|
|
483
388
|
var _open = (0, _dbts.open)(cfg), db = _open.db, warnings = _open.warnings;
|
|
484
389
|
printWarnings(warnings);
|
|
485
390
|
var rows;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/cli/shared.ts"],"sourcesContent":["import getopts from 'getopts-compat';\nimport 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 { searchError } from '../search-error.ts';\nimport { ExitError, usageError } from './exit.ts';\nimport type { Ctx } from './types.ts';\n\n// Flag descriptors, spreadable so one flag name keeps one meaning across every command's\n// table. parse() converts them to the getopts call the rest of the CLIs here make directly.\nexport interface Flag {\n type: 'string' | 'boolean';\n default?: string | boolean;\n multiple?: boolean;\n short?: string;\n}\nexport type Flags = Record<string, Flag>;\n\nexport const FORMAT: Flags = { format: { type: 'string', default: 'table' } };\nexport const CONFIG: Flags = { config: { type: 'string' } };\nexport const SEARCH_FLAGS: Flags = {\n where: { type: 'string' },\n k: { type: 'string' },\n preset: { type: 'string' },\n include: { type: 'string', multiple: true },\n lexical: { type: 'boolean', default: false },\n};\n\nexport type Values = Record<string, string | boolean | string[] | undefined>;\n\nexport function formatOf(values: Values): 'table' | 'json' {\n return values.format === 'json' ? 'json' : 'table';\n}\n\n// Per-command parse: strict (a foreign flag exits 2), and every table gets --help for free.\nexport function parse(argv: string[], usage: string, flags: Flags = {}): { values: Values; positionals: string[] } {\n const table: Flags = { ...flags, help: { type: 'boolean', default: false, short: 'h' } };\n const string: string[] = [];\n const boolean: string[] = [];\n const alias: Record<string, string> = {};\n const defaults: Record<string, string | boolean> = {};\n for (const [name, flag] of Object.entries(table)) {\n (flag.type === 'boolean' ? boolean : string).push(name);\n if (flag.default !== undefined) defaults[name] = flag.default;\n if (flag.short !== undefined) alias[name] = flag.short;\n }\n\n // getopts is lenient about undeclared flags -- they land in the result and are silently\n // ignored, which is the bug 0.9.2 fixed. Record the first and fail below; returning false\n // also keeps it out of the result. `--k -1` arrives here as unknown option \"1\", because\n // getopts reads a leading dash as a new option rather than as --k's value; the message is\n // blunter than the old one but it is still a usage error rather than a silent default.\n let unknown: string | undefined;\n const parsed = getopts(argv, {\n string,\n boolean,\n alias,\n default: defaults,\n unknown: (name: string): boolean => {\n if (unknown === undefined) unknown = name;\n return false;\n },\n });\n if (unknown !== undefined) usageError(`unknown option: ${unknown}`, usage);\n if (parsed.help) {\n console.log(usage);\n throw new ExitError(0);\n }\n\n // Two getopts shapes the callers must not see: an unset string flag reads as \"\" rather\n // than undefined, and a flag passed once reads as a string rather than a one-element\n // array. Both matter -- `?? saved.field` means \"flag absent\", and --include is a list.\n const values: Values = {};\n for (const [name, flag] of Object.entries(table)) {\n const raw = parsed[name];\n if (flag.type === 'boolean') values[name] = raw as boolean;\n else if (flag.multiple) values[name] = raw === '' ? undefined : Array.isArray(raw) ? (raw as string[]) : [raw as string];\n else values[name] = raw === '' ? undefined : (raw as string);\n }\n return { values, positionals: parsed._ };\n}\n\n// --k must be a positive integer: SQLite reads a bound LIMIT of -1 as \"unlimited\" and 0 as\n// \"nothing\", and parseInt would silently truncate \"5.9\" -- all three are caller mistakes\n// worth a usage error, matching the config-level SavedSearch validation.\nexport function parseK(k: string | undefined, usageErrorFn: (message: string) => never): number | undefined {\n if (k === undefined) return undefined;\n const parsed = Number(k);\n if (!Number.isInteger(parsed) || parsed <= 0) usageErrorFn(`--k expects a positive integer, got \"${k}\"`);\n return parsed;\n}\n\n// Shared open-query-close envelope for commands that touch the tree.\n\nexport function printWarnings(warnings: string[]): void {\n for (const w of warnings) console.warn(w);\n}\n\nexport async function withDb(ctx: Ctx, configPath: string | undefined, fn: (db: OpenResult['db'], cfg: ResolvedConfig) => void | Promise<void>): Promise<void> {\n const cfg = ctx.resolveConfig(configPath);\n const { db, warnings } = open(cfg);\n printWarnings(warnings);\n try {\n await fn(db, cfg);\n } finally {\n db.close();\n }\n}\n\n// 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) usageError(`${label} expects ${placeholderCount} parameter(s), got ${params.length}`);\n const { db, warnings } = open(cfg);\n printWarnings(warnings);\n let rows: Row[];\n try {\n rows = db.prepare(sql).all(...params) as Row[];\n } catch (err) {\n db.close();\n // A saved query or ad-hoc SQL can carry `content MATCH ?` too, so the same FTS5\n // punctuation trap applies -- the bound parameters are the search terms there. SQL\n // without MATCH gets its error verbatim; search advice on a plain typo would mislead.\n if (/\\bMATCH\\b/i.test(sql)) throw searchError(err as Error, params.join(' '));\n throw err;\n }\n printRows(rows, format);\n db.close();\n}\n"],"names":["CONFIG","FORMAT","SEARCH_FLAGS","formatOf","parse","parseK","printWarnings","runSql","withDb","format","type","default","config","where","k","preset","include","multiple","lexical","values","argv","usage","flags","table","help","short","string","boolean","alias","defaults","Object","entries","name","flag","push","undefined","unknown","parsed","getopts","usageError","console","log","ExitError","raw","Array","isArray","positionals","_","usageErrorFn","Number","isInteger","warnings","w","warn","ctx","configPath","fn","cfg","open","db","resolveConfig","close","sql","params","label","placeholderCount","match","length","rows","prepare","all","err","test","searchError","join","printRows"],"mappings":";;;;;;;;;;;QAqBaA;eAAAA;;QADAC;eAAAA;;QAEAC;eAAAA;;QAUGC;eAAAA;;QAKAC;eAAAA;;QAkDAC;eAAAA;;QASAC;eAAAA;;QAgBAC;eAAAA;;QAZMC;eAAAA;;;oEApGF;oBAGC;wBAEK;6BACE;sBACU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAa/B,IAAMP,SAAgB;IAAEQ,QAAQ;QAAEC,MAAM;QAAUC,SAAS;IAAQ;AAAE;AACrE,IAAMX,SAAgB;IAAEY,QAAQ;QAAEF,MAAM;IAAS;AAAE;AACnD,IAAMR,eAAsB;IACjCW,OAAO;QAAEH,MAAM;IAAS;IACxBI,GAAG;QAAEJ,MAAM;IAAS;IACpBK,QAAQ;QAAEL,MAAM;IAAS;IACzBM,SAAS;QAAEN,MAAM;QAAUO,UAAU;IAAK;IAC1CC,SAAS;QAAER,MAAM;QAAWC,SAAS;IAAM;AAC7C;AAIO,SAASR,SAASgB,MAAc;IACrC,OAAOA,OAAOV,MAAM,KAAK,SAAS,SA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;;oBAEZ;;wBAAMK,GAAGG,IAAIF;;;oBAAb;;;;;;oBAEAE,GAAGE,KAAK;;;;;;;;;;IAEZ;;AAGO,SAAStD,OAAOkD,GAAmB,EAAEK,GAAW,EAAEC,MAAgB,EAAEtD,MAAwB,EAAEuD,KAAa;QACtFF;IAA1B,IAAMG,mBAAmB,EAACH,aAAAA,IAAII,KAAK,CAAC,oBAAVJ,wBAAAA,aAAoB,EAAE,EAAEK,MAAM;IACxD,IAAIJ,OAAOI,MAAM,KAAKF,kBAAkB1B,IAAAA,kBAAU,EAAC,AAAC,GAAmB0B,OAAjBD,OAAM,aAAiDD,OAAtCE,kBAAiB,uBAAmC,OAAdF,OAAOI,MAAM;IAC1H,IAAyBT,QAAAA,IAAAA,UAAI,EAACD,MAAtBE,KAAiBD,MAAjBC,IAAIR,WAAaO,MAAbP;IACZ7C,cAAc6C;IACd,IAAIiB;IACJ,IAAI;YACKT;QAAPS,OAAOT,CAAAA,cAAAA,GAAGU,OAAO,CAACP,MAAKQ,GAAG,OAAnBX,aAAoB,qBAAGI;IAChC,EAAE,OAAOQ,KAAK;QACZZ,GAAGE,KAAK;QACR,gFAAgF;QAChF,mFAAmF;QACnF,sFAAsF;QACtF,IAAI,aAAaW,IAAI,CAACV,MAAM,MAAMW,IAAAA,0BAAW,EAACF,KAAcR,OAAOW,IAAI,CAAC;QACxE,MAAMH;IACR;IACAI,IAAAA,mBAAS,EAACP,MAAM3D;IAChBkD,GAAGE,KAAK;AACV"}
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/cli/shared.ts"],"sourcesContent":["import type { ParseArgsOptionsConfig } from 'node:util';\nimport { parseArgs } from 'node:util';\nimport type { ResolvedConfig } from '../config.ts';\nimport type { OpenResult } from '../db.ts';\nimport { open } from '../db.ts';\nimport type { Row } from '../output.ts';\nimport { printRows } from '../output.ts';\nimport { searchError } from '../search-error.ts';\nimport type { Ctx } from './types.ts';\n\n// Spreadable option fragments -- one flag name keeps one meaning across every command's table.\nexport const FORMAT: ParseArgsOptionsConfig = { format: { type: 'string', default: 'table' } };\nexport const CONFIG: ParseArgsOptionsConfig = { config: { type: 'string' } };\nexport const SEARCH_FLAGS: ParseArgsOptionsConfig = {\n where: { type: 'string' },\n k: { type: 'string' },\n preset: { type: 'string' },\n include: { type: 'string', multiple: true },\n lexical: { type: 'boolean', default: false },\n};\n\ntype Values = Record<string, string | boolean | string[] | undefined>;\n\nexport function formatOf(values: Values): 'table' | 'json' {\n return values.format === 'json' ? 'json' : 'table';\n}\n\n// Per-command parseArgs: strict (a foreign flag exits 2), and every table gets --help for free.\nexport function parse(argv: string[], usage: string, options: ParseArgsOptionsConfig): { values: Values; positionals: string[] } {\n let values: Values;\n let positionals: string[];\n try {\n ({ values, positionals } = parseArgs({\n args: argv,\n options: { ...options, help: { type: 'boolean', default: false, short: 'h' } },\n strict: true,\n allowPositionals: true,\n }));\n } catch (err) {\n console.error((err as Error).message);\n console.error(usage);\n process.exit(2);\n }\n if (values.help) {\n console.log(usage);\n process.exit(0);\n }\n return { values, positionals };\n}\n\n// --k must be a positive integer: SQLite reads a bound LIMIT of -1 as \"unlimited\" and 0 as\n// \"nothing\", and parseInt would silently truncate \"5.9\" -- all three are caller mistakes\n// worth a usage error, matching the config-level SavedSearch validation.\nexport function parseK(k: string | undefined, usageError: (message: string) => never): number | undefined {\n if (k === undefined) return undefined;\n const parsed = Number(k);\n if (!Number.isInteger(parsed) || parsed <= 0) usageError(`--k expects a positive integer, got \"${k}\"`);\n return parsed;\n}\n\n// Shared open-query-close envelope for commands that touch the tree.\n\nexport function printWarnings(warnings: string[]): void {\n for (const w of warnings) console.warn(w);\n}\n\nexport async function withDb(ctx: Ctx, configPath: string | undefined, fn: (db: OpenResult['db'], cfg: ResolvedConfig) => void | Promise<void>): Promise<void> {\n const cfg = ctx.resolveConfig(configPath);\n const { db, warnings } = open(cfg);\n printWarnings(warnings);\n try {\n await fn(db, cfg);\n } finally {\n db.close();\n }\n}\n\n// 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 let rows: Row[];\n try {\n rows = db.prepare(sql).all(...params) as Row[];\n } catch (err) {\n db.close();\n // A saved query or ad-hoc SQL can carry `content MATCH ?` too, so the same FTS5\n // punctuation trap applies -- the bound parameters are the search terms there. SQL\n // without MATCH gets its error verbatim; search advice on a plain typo would mislead.\n if (/\\bMATCH\\b/i.test(sql)) throw searchError(err as Error, params.join(' '));\n throw err;\n }\n printRows(rows, format);\n db.close();\n}\n"],"names":["CONFIG","FORMAT","SEARCH_FLAGS","formatOf","parse","parseK","printWarnings","runSql","withDb","format","type","default","config","where","k","preset","include","multiple","lexical","values","argv","usage","options","positionals","parseArgs","args","help","short","strict","allowPositionals","err","console","error","message","process","exit","log","usageError","undefined","parsed","Number","isInteger","warnings","w","warn","ctx","configPath","fn","cfg","open","db","resolveConfig","close","sql","params","label","placeholderCount","match","length","rows","prepare","all","test","searchError","join","printRows"],"mappings":";;;;;;;;;;;QAYaA;eAAAA;;QADAC;eAAAA;;QAEAC;eAAAA;;QAUGC;eAAAA;;QAKAC;eAAAA;;QAyBAC;eAAAA;;QASAC;eAAAA;;QAgBAC;eAAAA;;QAZMC;eAAAA;;;wBAjEI;oBAGL;wBAEK;6BACE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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