@outsidedata/dolex 8.0.2 → 9.0.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/README.md +33 -7
- package/dist/src/analysis/clean-exec.d.ts +23 -0
- package/dist/src/analysis/clean-exec.js +87 -0
- package/dist/src/analysis/data-context.d.ts +140 -0
- package/dist/src/analysis/data-context.js +96 -0
- package/dist/src/analysis/planner.d.ts +2 -1
- package/dist/src/analysis/planner.js +2 -2
- package/dist/src/analysis/quality.d.ts +23 -0
- package/dist/src/analysis/quality.js +386 -11
- package/dist/src/analysis/rules.d.ts +22 -2
- package/dist/src/analysis/rules.js +100 -18
- package/dist/src/cleaning/author.d.ts +30 -0
- package/dist/src/cleaning/author.js +7 -0
- package/dist/src/cleaning/exec.d.ts +29 -0
- package/dist/src/cleaning/exec.js +161 -0
- package/dist/src/cleaning/handlers.d.ts +16 -0
- package/dist/src/cleaning/handlers.js +82 -0
- package/dist/src/cleaning/index.d.ts +4 -0
- package/dist/src/cleaning/index.js +9 -0
- package/dist/src/cleaning/manifest.d.ts +35 -0
- package/dist/src/cleaning/manifest.js +95 -0
- package/dist/src/cleaning/replay.d.ts +34 -0
- package/dist/src/cleaning/replay.js +58 -0
- package/dist/src/cli/commands/analyze.js +13 -1
- package/dist/src/cli/commands/check.js +2 -89
- package/dist/src/cli/commands/clean.d.ts +1 -0
- package/dist/src/cli/commands/clean.js +127 -0
- package/dist/src/cli/commands/deps.d.ts +1 -0
- package/dist/src/cli/commands/deps.js +41 -0
- package/dist/src/cli/commands/help.js +3 -1
- package/dist/src/cli/commands/query.js +4 -1
- package/dist/src/cli/commands/sources.d.ts +2 -2
- package/dist/src/cli/commands/sources.js +138 -12
- package/dist/src/cli/commands/transform.js +19 -4
- package/dist/src/cli/commands/visualize.js +2 -0
- package/dist/src/cli/index.js +5 -0
- package/dist/src/connectors/csv.js +110 -8
- package/dist/src/connectors/index.d.ts +2 -0
- package/dist/src/connectors/index.js +2 -0
- package/dist/src/connectors/manager.d.ts +49 -1
- package/dist/src/connectors/manager.js +200 -14
- package/dist/src/connectors/mongo/index.d.ts +13 -0
- package/dist/src/connectors/mongo/index.js +323 -0
- package/dist/src/connectors/pg/index.d.ts +2 -0
- package/dist/src/connectors/pg/index.js +248 -0
- package/dist/src/connectors/source-factory.d.ts +38 -0
- package/dist/src/connectors/source-factory.js +80 -0
- package/dist/src/connectors/sql-safety.d.ts +68 -0
- package/dist/src/connectors/sql-safety.js +167 -0
- package/dist/src/connectors/types.d.ts +51 -0
- package/dist/src/connectors/types.js +11 -1
- package/dist/src/mcp/index.d.ts +1 -1
- package/dist/src/mcp/index.js +29 -10
- package/dist/src/mcp/tools/analyze.js +11 -1
- package/dist/src/mcp/tools/capabilities.d.ts +1 -0
- package/dist/src/mcp/tools/capabilities.js +14 -0
- package/dist/src/mcp/tools/clean-column.d.ts +5 -0
- package/dist/src/mcp/tools/clean-column.js +47 -0
- package/dist/src/mcp/tools/clean-schemas.d.ts +23 -0
- package/dist/src/mcp/tools/clean-schemas.js +9 -0
- package/dist/src/mcp/tools/drop-columns.js +2 -0
- package/dist/src/mcp/tools/list-transforms.js +22 -0
- package/dist/src/mcp/tools/promote-columns.js +2 -0
- package/dist/src/mcp/tools/query-source.d.ts +2 -2
- package/dist/src/mcp/tools/query-source.js +2 -1
- package/dist/src/mcp/tools/refine-cli.d.ts +4 -4
- package/dist/src/mcp/tools/refine.d.ts +4 -4
- package/dist/src/mcp/tools/shared.d.ts +6 -0
- package/dist/src/mcp/tools/shared.js +12 -5
- package/dist/src/mcp/tools/sources.d.ts +46 -3
- package/dist/src/mcp/tools/sources.js +44 -4
- package/dist/src/mcp/tools/transform-data.js +22 -0
- package/dist/src/mcp/tools/visualize-cli.d.ts +2 -2
- package/dist/src/mcp/tools/visualize.d.ts +3 -2
- package/dist/src/mcp/tools/visualize.js +1 -0
- package/dist/src/transforms/evaluator.js +58 -3
- package/dist/src/transforms/tokenizer.js +20 -2
- package/dist/src/transforms/types.d.ts +6 -6
- package/dist/src/types.d.ts +39 -2
- package/dist/src/utils/capabilities.d.ts +28 -0
- package/dist/src/utils/capabilities.js +58 -0
- package/dist/src/utils/optional-deps.d.ts +8 -0
- package/dist/src/utils/optional-deps.js +8 -0
- package/package.json +9 -3
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { z } from 'zod';
|
|
6
6
|
import { errorResponse, jsonResponse } from './shared.js';
|
|
7
|
+
import { resolveSourceConfig } from '../../connectors/source-factory.js';
|
|
7
8
|
const SANDBOX_PATH_PATTERNS = [
|
|
8
9
|
/^\/mnt\/user-data\//,
|
|
9
10
|
/^\/home\/claude\//,
|
|
@@ -15,7 +16,17 @@ export function isSandboxPath(filePath) {
|
|
|
15
16
|
}
|
|
16
17
|
export const addSourceInputSchema = z.object({
|
|
17
18
|
name: z.string().describe('Name for this dataset'),
|
|
18
|
-
|
|
19
|
+
type: z.enum(['csv', 'postgres', 'mongodb']).optional().describe('Source type (default: csv)'),
|
|
20
|
+
path: z.string().optional().describe('CSV: path to a .csv file or directory of CSV files'),
|
|
21
|
+
uri: z.string().optional().describe('Postgres libpq connection string, or MongoDB connection URI'),
|
|
22
|
+
host: z.string().optional().describe('DB host (postgres/mongodb) if not using uri'),
|
|
23
|
+
port: z.number().optional().describe('DB port'),
|
|
24
|
+
database: z.string().optional().describe('Database name (postgres discrete / mongodb — required for mongo)'),
|
|
25
|
+
user: z.string().optional().describe('Postgres user'),
|
|
26
|
+
password: z.string().optional().describe('Postgres password (stored in plaintext — prefer passwordEnv)'),
|
|
27
|
+
passwordEnv: z.string().optional().describe('Name of an env var holding the Postgres password (e.g. "PGPASSWORD"); keeps the secret out of the saved config'),
|
|
28
|
+
schema: z.string().optional().describe('Postgres schema to introspect (default: public)'),
|
|
29
|
+
collections: z.array(z.string()).optional().describe('MongoDB: restrict to these collections'),
|
|
19
30
|
});
|
|
20
31
|
export const removeSourceInputSchema = z.object({
|
|
21
32
|
sourceId: z.string().describe('Dataset ID returned by load_csv'),
|
|
@@ -109,14 +120,33 @@ function buildSmartSummary(t) {
|
|
|
109
120
|
export function handleListSources(deps) {
|
|
110
121
|
return async () => jsonResponse(deps.sourceManager.list());
|
|
111
122
|
}
|
|
123
|
+
export const testSourceInputSchema = z.object({
|
|
124
|
+
sourceId: z.string().describe('Source id or name to health-check'),
|
|
125
|
+
});
|
|
126
|
+
/** Connectivity health-check for a registered source — is the saved DB reachable with its credentials?
|
|
127
|
+
* Returns a classified kind (unreachable / auth-failed / db-not-found / driver-missing / …) so the
|
|
128
|
+
* assistant can give the user a specific fix, and repair via load_source (re-register) if needed. */
|
|
129
|
+
export function handleTestSource(deps) {
|
|
130
|
+
return async (args) => jsonResponse(await deps.sourceManager.testSource(args.sourceId));
|
|
131
|
+
}
|
|
112
132
|
export function handleAddSource(deps) {
|
|
113
133
|
return async (args) => {
|
|
114
|
-
if (isSandboxPath(args.path)) {
|
|
134
|
+
if (args.path && isSandboxPath(args.path)) {
|
|
115
135
|
return errorResponse('This path looks like a cloud sandbox path, not a local filesystem path. '
|
|
116
136
|
+ 'Dolex runs on the user\'s machine and can access any local file — but not cloud sandbox uploads. '
|
|
117
137
|
+ 'Ask the user for the real local path (e.g. /Users/name/Downloads/data.csv).');
|
|
118
138
|
}
|
|
119
|
-
|
|
139
|
+
let config;
|
|
140
|
+
try {
|
|
141
|
+
config = resolveSourceConfig({
|
|
142
|
+
type: args.type, path: args.path, uri: args.uri, host: args.host, port: args.port,
|
|
143
|
+
database: args.database, user: args.user, password: args.password, passwordEnv: args.passwordEnv,
|
|
144
|
+
schema: args.schema, collections: args.collections,
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
catch (err) {
|
|
148
|
+
return errorResponse(err.message);
|
|
149
|
+
}
|
|
120
150
|
let entry;
|
|
121
151
|
let reconnected = false;
|
|
122
152
|
const existing = deps.sourceManager.get(args.name);
|
|
@@ -137,9 +167,19 @@ export function handleAddSource(deps) {
|
|
|
137
167
|
return errorResponse(err.message);
|
|
138
168
|
}
|
|
139
169
|
if (!addResult.ok || !addResult.entry) {
|
|
140
|
-
return errorResponse(addResult.error ?? 'Failed to load
|
|
170
|
+
return errorResponse(addResult.error ?? 'Failed to load source');
|
|
141
171
|
}
|
|
142
172
|
entry = addResult.entry;
|
|
173
|
+
// Config-first: the source is registered even if the DB wasn't reachable just now. Don't try to
|
|
174
|
+
// profile it (that would fail); tell the assistant it's saved and how to get it live.
|
|
175
|
+
if (addResult.verified === false) {
|
|
176
|
+
return jsonResponse({
|
|
177
|
+
sourceId: entry.id, name: entry.name, type: entry.type, registered: true, reachable: false,
|
|
178
|
+
message: `Registered "${entry.name}", but couldn't connect yet: ${addResult.warning}. `
|
|
179
|
+
+ `Once the database is reachable (start it / fix credentials — for a missing driver run the install command), it will work. `
|
|
180
|
+
+ `Relay the reason to the user; no re-registration is needed.`,
|
|
181
|
+
});
|
|
182
|
+
}
|
|
143
183
|
}
|
|
144
184
|
const schemaResult = await deps.sourceManager.getSchema(entry.id);
|
|
145
185
|
const schema = schemaResult.ok ? schemaResult.schema : null;
|
|
@@ -6,6 +6,28 @@ export function handleTransformData(deps) {
|
|
|
6
6
|
const ctx = await connectAndValidateTable(deps, args.sourceId, args.table);
|
|
7
7
|
if (isTransformError(ctx))
|
|
8
8
|
return ctx;
|
|
9
|
+
// Live source (PG/Mongo): materialize each derived column via the connector (native expression
|
|
10
|
+
// → shadow view / $set), visible to later queries, base data untouched. No SQLite handle.
|
|
11
|
+
if (!ctx.db) {
|
|
12
|
+
if (typeof ctx.source.applyDerivation !== 'function') {
|
|
13
|
+
return errorResponse(`This source cannot materialize a derived column (materialization: ${ctx.caps.materialization}).`);
|
|
14
|
+
}
|
|
15
|
+
const items = args.transforms ?? (args.create && args.expr ? [{ create: args.create, expr: args.expr }] : []);
|
|
16
|
+
if (!items.length)
|
|
17
|
+
return errorResponse('Provide `create` + `expr`, or a `transforms` array.');
|
|
18
|
+
try {
|
|
19
|
+
for (const t of items)
|
|
20
|
+
await ctx.source.applyDerivation(args.table, t.create, t.expr);
|
|
21
|
+
ctx.source.invalidateSchema?.();
|
|
22
|
+
return jsonResponse({
|
|
23
|
+
created: items.map((t) => ({ column: t.create, expr: t.expr, layer: 'derived', materialization: ctx.caps.materialization })),
|
|
24
|
+
note: `Derived on the live ${ctx.source.type} source (${ctx.caps.materialization}); session-local, base data untouched.`,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
catch (err) {
|
|
28
|
+
return errorResponse(err.message);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
9
31
|
const metadata = new TransformMetadata(ctx.db);
|
|
10
32
|
metadata.init();
|
|
11
33
|
const transformedNames = new Set(metadata.list(args.table).map(r => r.column));
|
|
@@ -118,9 +118,9 @@ export declare const visualizeCliInputSchema: z.ZodObject<{
|
|
|
118
118
|
colorField?: string | undefined;
|
|
119
119
|
palette?: "categorical" | "blue" | "green" | "purple" | "warm" | "blueRed" | "greenPurple" | "tealOrange" | "redGreen" | "traffic-light" | "profit-loss" | "temperature" | undefined;
|
|
120
120
|
geoRegion?: string | undefined;
|
|
121
|
+
sql?: string | undefined;
|
|
121
122
|
sourceId?: string | undefined;
|
|
122
123
|
resultId?: string | undefined;
|
|
123
|
-
sql?: string | undefined;
|
|
124
124
|
dataShapeHints?: {
|
|
125
125
|
dateColumnCount?: number | undefined;
|
|
126
126
|
categoricalColumnCount?: number | undefined;
|
|
@@ -159,9 +159,9 @@ export declare const visualizeCliInputSchema: z.ZodObject<{
|
|
|
159
159
|
colorField?: string | undefined;
|
|
160
160
|
palette?: "categorical" | "blue" | "green" | "purple" | "warm" | "blueRed" | "greenPurple" | "tealOrange" | "redGreen" | "traffic-light" | "profit-loss" | "temperature" | undefined;
|
|
161
161
|
geoRegion?: string | undefined;
|
|
162
|
+
sql?: string | undefined;
|
|
162
163
|
sourceId?: string | undefined;
|
|
163
164
|
resultId?: string | undefined;
|
|
164
|
-
sql?: string | undefined;
|
|
165
165
|
dataShapeHints?: {
|
|
166
166
|
dateColumnCount?: number | undefined;
|
|
167
167
|
categoricalColumnCount?: number | undefined;
|
|
@@ -168,9 +168,9 @@ export declare const visualizeInputSchema: z.ZodObject<{
|
|
|
168
168
|
colorField?: string | undefined;
|
|
169
169
|
palette?: "categorical" | "blue" | "green" | "purple" | "warm" | "blueRed" | "greenPurple" | "tealOrange" | "redGreen" | "traffic-light" | "profit-loss" | "temperature" | undefined;
|
|
170
170
|
geoRegion?: string | undefined;
|
|
171
|
+
sql?: string | undefined;
|
|
171
172
|
sourceId?: string | undefined;
|
|
172
173
|
resultId?: string | undefined;
|
|
173
|
-
sql?: string | undefined;
|
|
174
174
|
dataShapeHints?: {
|
|
175
175
|
dateColumnCount?: number | undefined;
|
|
176
176
|
categoricalColumnCount?: number | undefined;
|
|
@@ -208,9 +208,9 @@ export declare const visualizeInputSchema: z.ZodObject<{
|
|
|
208
208
|
colorField?: string | undefined;
|
|
209
209
|
palette?: "categorical" | "blue" | "green" | "purple" | "warm" | "blueRed" | "greenPurple" | "tealOrange" | "redGreen" | "traffic-light" | "profit-loss" | "temperature" | undefined;
|
|
210
210
|
geoRegion?: string | undefined;
|
|
211
|
+
sql?: string | undefined;
|
|
211
212
|
sourceId?: string | undefined;
|
|
212
213
|
resultId?: string | undefined;
|
|
213
|
-
sql?: string | undefined;
|
|
214
214
|
dataShapeHints?: {
|
|
215
215
|
dateColumnCount?: number | undefined;
|
|
216
216
|
categoricalColumnCount?: number | undefined;
|
|
@@ -253,6 +253,7 @@ export declare function handleVisualizeCore(selectPatterns: (input: VisualizeInp
|
|
|
253
253
|
}, queryMeta?: {
|
|
254
254
|
truncated?: boolean;
|
|
255
255
|
totalSourceRows?: number;
|
|
256
|
+
warnings?: string[];
|
|
256
257
|
}, extraMeta?: Partial<OperationMeta>) => {
|
|
257
258
|
structuredContent?: {
|
|
258
259
|
specId: string;
|
|
@@ -123,6 +123,7 @@ export function handleVisualizeCore(selectPatterns, toolName = 'visualize') {
|
|
|
123
123
|
columns: columns.map(c => ({ name: c.name, type: c.type })),
|
|
124
124
|
...(queryMeta?.truncated ? { truncated: true, totalSourceRows: queryMeta.totalSourceRows } : {}),
|
|
125
125
|
},
|
|
126
|
+
...(queryMeta?.warnings?.length ? { warnings: queryMeta.warnings } : {}),
|
|
126
127
|
};
|
|
127
128
|
if (isCompoundSpec(finalSpec)) {
|
|
128
129
|
compactResponse.compound = true;
|
|
@@ -207,11 +207,17 @@ export function evaluateExpression(expr, rows, options) {
|
|
|
207
207
|
values[i] = null;
|
|
208
208
|
continue;
|
|
209
209
|
}
|
|
210
|
-
|
|
210
|
+
const v = evaluate(ast, {
|
|
211
211
|
row: rows[i],
|
|
212
212
|
rowIndex: filteredIndex,
|
|
213
213
|
precomputed: pre,
|
|
214
214
|
});
|
|
215
|
+
// Non-finite numbers (Infinity/-Infinity/NaN — from overflow like 1e400 or
|
|
216
|
+
// x/0) are NOT valid column values: SQLite can't round-trip them and they
|
|
217
|
+
// poison aggregates. Treat them as null so they count toward the null stats
|
|
218
|
+
// and the all-null guard fires. (Symmetric with the CSV loader's isFinite
|
|
219
|
+
// check; red-team #11.)
|
|
220
|
+
values[i] = typeof v === 'number' && !Number.isFinite(v) ? null : v;
|
|
215
221
|
filteredIndex++;
|
|
216
222
|
}
|
|
217
223
|
// Compute stats
|
|
@@ -242,6 +248,40 @@ export function evaluateExpression(expr, rows, options) {
|
|
|
242
248
|
* double quotes are string literals). A string compared for equality against a
|
|
243
249
|
* column (`status == "active"`) is a legitimate value comparison and exempt.
|
|
244
250
|
*/
|
|
251
|
+
/**
|
|
252
|
+
* Per-function argument positions that genuinely take a STRING LITERAL (not a
|
|
253
|
+
* column). A string at one of these positions is exempt from the misquoted-column
|
|
254
|
+
* guard. Functions absent here (log, sqrt, abs, arithmetic, …) keep flagging, so
|
|
255
|
+
* `log("price")` is still caught. 'all' = every arg position is a string position.
|
|
256
|
+
*/
|
|
257
|
+
// Only positions that are GENUINELY string-literal slots are exempt. Crucially,
|
|
258
|
+
// arg0 of coalesce/concat/in/recode/cut is the VALUE/COLUMN slot — a quoted
|
|
259
|
+
// column name THERE is the misquote footgun, so those are NOT 'all' (red-team
|
|
260
|
+
// #10). `{rest: n}` exempts every position from n onward (e.g. in()'s comparand
|
|
261
|
+
// list, recode()'s from/to pairs). Functions absent here (log, sqrt, coalesce,
|
|
262
|
+
// concat, cut arg0, arithmetic) keep flagging. Array string elements are exempt
|
|
263
|
+
// separately in the walker (they are string-expected labels/comparands).
|
|
264
|
+
const STRING_ARG_POSITIONS = {
|
|
265
|
+
date_part: [1],
|
|
266
|
+
date_floor: [1],
|
|
267
|
+
date_diff: [2],
|
|
268
|
+
str_contains: [1],
|
|
269
|
+
str_replace: [1, 2],
|
|
270
|
+
fill_null: [1],
|
|
271
|
+
null_if: [1],
|
|
272
|
+
in: { rest: 1 },
|
|
273
|
+
recode: { rest: 1 },
|
|
274
|
+
};
|
|
275
|
+
function isStringArgPosition(fn, idx) {
|
|
276
|
+
const spec = STRING_ARG_POSITIONS[fn];
|
|
277
|
+
if (!spec)
|
|
278
|
+
return false;
|
|
279
|
+
if (spec === 'all')
|
|
280
|
+
return true;
|
|
281
|
+
if (Array.isArray(spec))
|
|
282
|
+
return spec.includes(idx);
|
|
283
|
+
return idx >= spec.rest;
|
|
284
|
+
}
|
|
245
285
|
function findMisquotedColumnLiterals(ast, columns) {
|
|
246
286
|
const hits = new Set();
|
|
247
287
|
function walk(node) {
|
|
@@ -266,10 +306,25 @@ function findMisquotedColumnLiterals(ast, columns) {
|
|
|
266
306
|
walk(node.operand);
|
|
267
307
|
return;
|
|
268
308
|
case 'call':
|
|
269
|
-
|
|
309
|
+
// A string literal at a position where the function genuinely expects a
|
|
310
|
+
// string (e.g. date_part(col, "year"), str_contains(col, "x")) is an
|
|
311
|
+
// intentional value, NOT a misquoted column — don't flag it even if it
|
|
312
|
+
// matches a column name (GOTCHA #10). Numeric functions (log, sqrt, …)
|
|
313
|
+
// are NOT in the map, so log("price") is still correctly flagged.
|
|
314
|
+
node.args.forEach((arg, idx) => {
|
|
315
|
+
if (arg.type === 'string' && isStringArgPosition(node.name, idx))
|
|
316
|
+
return;
|
|
317
|
+
walk(arg);
|
|
318
|
+
});
|
|
270
319
|
return;
|
|
271
320
|
case 'array':
|
|
272
|
-
|
|
321
|
+
// String elements of an array literal are intentional labels/values
|
|
322
|
+
// (cut labels, in-lists, recode pairs), not misquoted columns.
|
|
323
|
+
node.elements.forEach((el) => {
|
|
324
|
+
if (el.type === 'string')
|
|
325
|
+
return;
|
|
326
|
+
walk(el);
|
|
327
|
+
});
|
|
273
328
|
return;
|
|
274
329
|
default:
|
|
275
330
|
return;
|
|
@@ -24,14 +24,31 @@ export function tokenize(input) {
|
|
|
24
24
|
while (i < input.length && isDigit(input[i]))
|
|
25
25
|
i++;
|
|
26
26
|
}
|
|
27
|
+
// Optional exponent (GOTCHA #11): e/E, optional sign, ≥1 digit. Only consume
|
|
28
|
+
// it when digits actually follow, so a bare trailing "e" stays an identifier.
|
|
29
|
+
if (i < input.length && (input[i] === 'e' || input[i] === 'E')) {
|
|
30
|
+
let j = i + 1;
|
|
31
|
+
if (j < input.length && (input[j] === '+' || input[j] === '-'))
|
|
32
|
+
j++;
|
|
33
|
+
if (j < input.length && isDigit(input[j])) {
|
|
34
|
+
i = j;
|
|
35
|
+
while (i < input.length && isDigit(input[i]))
|
|
36
|
+
i++;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
27
39
|
tokens.push({ type: 'NUMBER', value: input.slice(start, i), pos: start });
|
|
28
40
|
continue;
|
|
29
41
|
}
|
|
30
|
-
|
|
42
|
+
// String literals accept EITHER double or single quotes (GOTCHA #7). The
|
|
43
|
+
// closing quote must match the opener, so an apostrophe inside a
|
|
44
|
+
// double-quoted string — and a double quote inside a single-quoted string —
|
|
45
|
+
// are literal content, not terminators.
|
|
46
|
+
if (ch === '"' || ch === "'") {
|
|
47
|
+
const quote = ch;
|
|
31
48
|
const start = i;
|
|
32
49
|
i++;
|
|
33
50
|
let str = '';
|
|
34
|
-
while (i < input.length && input[i] !==
|
|
51
|
+
while (i < input.length && input[i] !== quote) {
|
|
35
52
|
if (input[i] === '\\' && i + 1 < input.length) {
|
|
36
53
|
const esc = input[i + 1];
|
|
37
54
|
str += ESCAPE_MAP[esc] ?? ('\\' + esc);
|
|
@@ -104,6 +121,7 @@ function isIdentChar(ch) {
|
|
|
104
121
|
// ─── Lookup Tables ───────────────────────────────────────────────────────────
|
|
105
122
|
const ESCAPE_MAP = {
|
|
106
123
|
'"': '"',
|
|
124
|
+
"'": "'",
|
|
107
125
|
'\\': '\\',
|
|
108
126
|
'n': '\n',
|
|
109
127
|
't': '\t',
|
|
@@ -81,13 +81,13 @@ export declare const manifestEntrySchema: z.ZodObject<{
|
|
|
81
81
|
partitionBy: z.ZodOptional<z.ZodString>;
|
|
82
82
|
}, "strip", z.ZodTypeAny, {
|
|
83
83
|
type: "boolean" | "numeric" | "categorical" | "date";
|
|
84
|
-
expr: string;
|
|
85
84
|
column: string;
|
|
85
|
+
expr: string;
|
|
86
86
|
partitionBy?: string | undefined;
|
|
87
87
|
}, {
|
|
88
88
|
type: "boolean" | "numeric" | "categorical" | "date";
|
|
89
|
-
expr: string;
|
|
90
89
|
column: string;
|
|
90
|
+
expr: string;
|
|
91
91
|
partitionBy?: string | undefined;
|
|
92
92
|
}>;
|
|
93
93
|
export type ManifestEntry = z.infer<typeof manifestEntrySchema>;
|
|
@@ -100,29 +100,29 @@ export declare const manifestSchema: z.ZodObject<{
|
|
|
100
100
|
partitionBy: z.ZodOptional<z.ZodString>;
|
|
101
101
|
}, "strip", z.ZodTypeAny, {
|
|
102
102
|
type: "boolean" | "numeric" | "categorical" | "date";
|
|
103
|
-
expr: string;
|
|
104
103
|
column: string;
|
|
104
|
+
expr: string;
|
|
105
105
|
partitionBy?: string | undefined;
|
|
106
106
|
}, {
|
|
107
107
|
type: "boolean" | "numeric" | "categorical" | "date";
|
|
108
|
-
expr: string;
|
|
109
108
|
column: string;
|
|
109
|
+
expr: string;
|
|
110
110
|
partitionBy?: string | undefined;
|
|
111
111
|
}>, "many">>;
|
|
112
112
|
}, "strip", z.ZodTypeAny, {
|
|
113
113
|
version: 1;
|
|
114
114
|
tables: Record<string, {
|
|
115
115
|
type: "boolean" | "numeric" | "categorical" | "date";
|
|
116
|
-
expr: string;
|
|
117
116
|
column: string;
|
|
117
|
+
expr: string;
|
|
118
118
|
partitionBy?: string | undefined;
|
|
119
119
|
}[]>;
|
|
120
120
|
}, {
|
|
121
121
|
version: 1;
|
|
122
122
|
tables: Record<string, {
|
|
123
123
|
type: "boolean" | "numeric" | "categorical" | "date";
|
|
124
|
-
expr: string;
|
|
125
124
|
column: string;
|
|
125
|
+
expr: string;
|
|
126
126
|
partitionBy?: string | undefined;
|
|
127
127
|
}[]>;
|
|
128
128
|
}>;
|
package/dist/src/types.d.ts
CHANGED
|
@@ -25,6 +25,16 @@ export interface DataColumn {
|
|
|
25
25
|
value: string;
|
|
26
26
|
count: number;
|
|
27
27
|
}[];
|
|
28
|
+
/**
|
|
29
|
+
* Numeric columns only: the dominant non-numeric value the connector coerced to
|
|
30
|
+
* NULL on load (a string sentinel like "Undrafted" hiding in an otherwise-numeric
|
|
31
|
+
* column). NUMERIC affinity erases it from the stored data, so the auditor can't
|
|
32
|
+
* see it any other way — this is how the affinity-trap (mixed-type) is surfaced.
|
|
33
|
+
*/
|
|
34
|
+
coercedNonNumeric?: {
|
|
35
|
+
token: string;
|
|
36
|
+
count: number;
|
|
37
|
+
};
|
|
28
38
|
}
|
|
29
39
|
export interface DataTable {
|
|
30
40
|
name: string;
|
|
@@ -47,19 +57,46 @@ export interface DataSchema {
|
|
|
47
57
|
foreignKeys: ForeignKey[];
|
|
48
58
|
source: DataSourceInfo;
|
|
49
59
|
}
|
|
50
|
-
export type DataSourceType = 'csv';
|
|
60
|
+
export type DataSourceType = 'csv' | 'postgres' | 'mongodb';
|
|
51
61
|
export interface DataSourceInfo {
|
|
52
62
|
id: string;
|
|
53
63
|
type: DataSourceType;
|
|
54
64
|
name: string;
|
|
55
65
|
config: DataSourceConfig;
|
|
56
66
|
}
|
|
57
|
-
export type DataSourceConfig = CsvSourceConfig;
|
|
67
|
+
export type DataSourceConfig = CsvSourceConfig | PostgresSourceConfig | MongoSourceConfig;
|
|
58
68
|
export interface CsvSourceConfig {
|
|
59
69
|
type: 'csv';
|
|
60
70
|
/** Directory containing CSV files, or path to a single CSV */
|
|
61
71
|
path: string;
|
|
62
72
|
}
|
|
73
|
+
export interface PostgresSourceConfig {
|
|
74
|
+
type: 'postgres';
|
|
75
|
+
/** libpq connection string, OR provide discrete fields below. */
|
|
76
|
+
connectionString?: string;
|
|
77
|
+
host?: string;
|
|
78
|
+
port?: number;
|
|
79
|
+
database?: string;
|
|
80
|
+
user?: string;
|
|
81
|
+
/** Literal password. Stored in the registry — prefer `passwordEnv` to keep the secret out of the file. */
|
|
82
|
+
password?: string;
|
|
83
|
+
/** Name of an environment variable holding the password (e.g. "PGPASSWORD"). The registry stores
|
|
84
|
+
* only this reference, not the secret; the password is read from the environment at connect time. */
|
|
85
|
+
passwordEnv?: string;
|
|
86
|
+
/** Postgres schema to introspect (default: public). */
|
|
87
|
+
schema?: string;
|
|
88
|
+
}
|
|
89
|
+
export interface MongoSourceConfig {
|
|
90
|
+
type: 'mongodb';
|
|
91
|
+
/** Mongo connection URI, OR provide discrete host/port below. */
|
|
92
|
+
uri?: string;
|
|
93
|
+
host?: string;
|
|
94
|
+
port?: number;
|
|
95
|
+
/** Database to introspect (required — a Mongo connection has no single default db). */
|
|
96
|
+
database: string;
|
|
97
|
+
/** Restrict to these collections; omitted ⇒ all collections in the database. */
|
|
98
|
+
collections?: string[];
|
|
99
|
+
}
|
|
63
100
|
/** Filter operator (used by transform pipeline for client-side row filtering) */
|
|
64
101
|
export type RowFilterOp = '=' | '!=' | '>' | '>=' | '<' | '<=' | 'in' | 'not_in' | 'between' | 'is_null' | 'is_not_null';
|
|
65
102
|
/** A filter condition (used by transform pipeline for client-side row filtering) */
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export interface CapabilityDep {
|
|
2
|
+
package: string;
|
|
3
|
+
installed: boolean;
|
|
4
|
+
version?: string;
|
|
5
|
+
enables: string;
|
|
6
|
+
install?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface CapabilitiesReport {
|
|
9
|
+
dolexVersion?: string;
|
|
10
|
+
node: string;
|
|
11
|
+
platform: string;
|
|
12
|
+
coreOk: boolean;
|
|
13
|
+
/** Per source type: 'ready' or an actionable 'needs: npm install …'. The agent's key question. */
|
|
14
|
+
sources: {
|
|
15
|
+
csv: string;
|
|
16
|
+
postgres: string;
|
|
17
|
+
mongodb: string;
|
|
18
|
+
};
|
|
19
|
+
deps: CapabilityDep[];
|
|
20
|
+
python: {
|
|
21
|
+
available: boolean;
|
|
22
|
+
version?: string;
|
|
23
|
+
enables: string;
|
|
24
|
+
install?: string;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/** Probe the current environment for optional capabilities. Pure of side effects; never throws. */
|
|
28
|
+
export declare function probeCapabilities(): CapabilitiesReport;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Environment capability probe — the single source of truth for "what can Dolex do in THIS
|
|
3
|
+
* install?". Shared by the `dolex deps` CLI command (human + --json) and the MCP `capabilities`
|
|
4
|
+
* tool (an AI agent asks once, then drives within what's available instead of trying-and-crashing).
|
|
5
|
+
*
|
|
6
|
+
* Presence is resolved WITHOUT loading the package (no side effects); a missing optional package is
|
|
7
|
+
* a fact to report, never a crash — the connectors themselves fail gracefully (importOptional).
|
|
8
|
+
*/
|
|
9
|
+
import { createRequire } from 'module';
|
|
10
|
+
import { execFileSync } from 'child_process';
|
|
11
|
+
import { readFileSync } from 'fs';
|
|
12
|
+
import { OPTIONAL_FEATURES } from './optional-deps.js';
|
|
13
|
+
import { packagePath } from './package-root.js';
|
|
14
|
+
const require = createRequire(import.meta.url);
|
|
15
|
+
/** A package's version, resolved without loading it. `null` ⇒ not installed. */
|
|
16
|
+
function pkgVersion(spec) {
|
|
17
|
+
try {
|
|
18
|
+
return JSON.parse(readFileSync(require.resolve(`${spec}/package.json`), 'utf8')).version ?? null;
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
const PROBES = [
|
|
25
|
+
{ key: 'postgres', spec: 'pg', enables: 'Postgres data sources' },
|
|
26
|
+
{ key: 'mongodb', spec: 'mongodb', enables: 'MongoDB data sources' },
|
|
27
|
+
{ key: 'png', spec: 'playwright', enables: 'PNG / screenshot export' },
|
|
28
|
+
{ key: 'mcp', spec: '@modelcontextprotocol/sdk', enables: 'the MCP server (`dolex mcp`)' },
|
|
29
|
+
];
|
|
30
|
+
/** Probe the current environment for optional capabilities. Pure of side effects; never throws. */
|
|
31
|
+
export function probeCapabilities() {
|
|
32
|
+
const coreOk = !!pkgVersion('better-sqlite3');
|
|
33
|
+
const deps = PROBES.map((p) => {
|
|
34
|
+
const version = pkgVersion(p.spec);
|
|
35
|
+
return { package: p.spec, installed: !!version, version: version ?? undefined, enables: p.enables, install: version ? undefined : OPTIONAL_FEATURES[p.key].install };
|
|
36
|
+
});
|
|
37
|
+
const has = (spec) => deps.find((d) => d.package === spec).installed;
|
|
38
|
+
let pyVersion;
|
|
39
|
+
try {
|
|
40
|
+
pyVersion = execFileSync('python3', ['--version'], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim();
|
|
41
|
+
}
|
|
42
|
+
catch { /* absent */ }
|
|
43
|
+
const python = { available: !!pyVersion, version: pyVersion, enables: 'data cleaning (clean_column / dolex clean)', install: pyVersion ? undefined : 'install python3 and put it on PATH' };
|
|
44
|
+
let dolexVersion;
|
|
45
|
+
try {
|
|
46
|
+
dolexVersion = JSON.parse(readFileSync(packagePath('package.json'), 'utf8')).version;
|
|
47
|
+
}
|
|
48
|
+
catch { /* best-effort */ }
|
|
49
|
+
return {
|
|
50
|
+
dolexVersion, node: process.version, platform: process.platform, coreOk,
|
|
51
|
+
sources: {
|
|
52
|
+
csv: coreOk ? 'ready' : 'core missing — reinstall dolex',
|
|
53
|
+
postgres: has('pg') ? 'ready' : 'needs: npm install pg',
|
|
54
|
+
mongodb: has('mongodb') ? 'ready' : 'needs: npm install mongodb',
|
|
55
|
+
},
|
|
56
|
+
deps, python,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
@@ -25,6 +25,14 @@ export declare const OPTIONAL_FEATURES: {
|
|
|
25
25
|
readonly feature: "the MCP server (`dolex mcp`)";
|
|
26
26
|
readonly install: "npm install @modelcontextprotocol/sdk @modelcontextprotocol/ext-apps";
|
|
27
27
|
};
|
|
28
|
+
readonly postgres: {
|
|
29
|
+
readonly feature: "Postgres data sources";
|
|
30
|
+
readonly install: "npm install pg";
|
|
31
|
+
};
|
|
32
|
+
readonly mongodb: {
|
|
33
|
+
readonly feature: "MongoDB data sources";
|
|
34
|
+
readonly install: "npm install mongodb";
|
|
35
|
+
};
|
|
28
36
|
};
|
|
29
37
|
export type OptionalFeatureKey = keyof typeof OPTIONAL_FEATURES;
|
|
30
38
|
/** Build the standard, agent-and-human friendly "install this" message. */
|
|
@@ -19,6 +19,14 @@ export const OPTIONAL_FEATURES = {
|
|
|
19
19
|
feature: 'the MCP server (`dolex mcp`)',
|
|
20
20
|
install: 'npm install @modelcontextprotocol/sdk @modelcontextprotocol/ext-apps',
|
|
21
21
|
},
|
|
22
|
+
postgres: {
|
|
23
|
+
feature: 'Postgres data sources',
|
|
24
|
+
install: 'npm install pg',
|
|
25
|
+
},
|
|
26
|
+
mongodb: {
|
|
27
|
+
feature: 'MongoDB data sources',
|
|
28
|
+
install: 'npm install mongodb',
|
|
29
|
+
},
|
|
22
30
|
};
|
|
23
31
|
/** Build the standard, agent-and-human friendly "install this" message. */
|
|
24
32
|
export function missingDependencyMessage(key) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@outsidedata/dolex",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "9.0.0",
|
|
4
4
|
"description": "Turn your AI assistant into a data analyst you can trust on your own CSV files — column profiling, data-quality auditing, a prioritized analysis plan, and findings rendered across 43 chart types.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -75,7 +75,10 @@
|
|
|
75
75
|
"test:coverage": "vitest run --coverage",
|
|
76
76
|
"mcp:stdio": "tsx src/mcp/index.ts",
|
|
77
77
|
"preflight": "bash scripts/publish-preflight.sh",
|
|
78
|
-
"prepublishOnly": "npm run build && npm test"
|
|
78
|
+
"prepublishOnly": "npm run build && npm test",
|
|
79
|
+
"chat": "tsx local-orchestration/src/chat.ts",
|
|
80
|
+
"web": "tsx local-orchestration/web/server.ts",
|
|
81
|
+
"gate": "bash local-orchestration/gate.sh"
|
|
79
82
|
},
|
|
80
83
|
"dependencies": {
|
|
81
84
|
"better-sqlite3": "^11.10.0",
|
|
@@ -85,7 +88,9 @@
|
|
|
85
88
|
"optionalDependencies": {
|
|
86
89
|
"@modelcontextprotocol/ext-apps": "^1.0.1",
|
|
87
90
|
"@modelcontextprotocol/sdk": "^1.26.0",
|
|
88
|
-
"topojson-client": "^3.1.0"
|
|
91
|
+
"topojson-client": "^3.1.0",
|
|
92
|
+
"pg": "^8.22.0",
|
|
93
|
+
"mongodb": "^7.4.0"
|
|
89
94
|
},
|
|
90
95
|
"peerDependencies": {
|
|
91
96
|
"react": ">=18",
|
|
@@ -107,6 +112,7 @@
|
|
|
107
112
|
"@types/better-sqlite3": "^7.6.13",
|
|
108
113
|
"@types/node": "^20",
|
|
109
114
|
"@types/papaparse": "^5.3.16",
|
|
115
|
+
"@types/pg": "^8.20.0",
|
|
110
116
|
"@types/react": "^19.2.13",
|
|
111
117
|
"@types/react-dom": "^19.2.3",
|
|
112
118
|
"@types/topojson-client": "^3.1.5",
|