@outsidedata/dolex 8.0.2 → 8.1.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.
Files changed (47) hide show
  1. package/README.md +3 -0
  2. package/dist/src/analysis/clean-exec.d.ts +23 -0
  3. package/dist/src/analysis/clean-exec.js +87 -0
  4. package/dist/src/analysis/data-context.d.ts +140 -0
  5. package/dist/src/analysis/data-context.js +96 -0
  6. package/dist/src/analysis/quality.d.ts +23 -0
  7. package/dist/src/analysis/quality.js +290 -6
  8. package/dist/src/analysis/rules.js +41 -0
  9. package/dist/src/cleaning/author.d.ts +30 -0
  10. package/dist/src/cleaning/author.js +7 -0
  11. package/dist/src/cleaning/exec.d.ts +29 -0
  12. package/dist/src/cleaning/exec.js +161 -0
  13. package/dist/src/cleaning/handlers.d.ts +16 -0
  14. package/dist/src/cleaning/handlers.js +82 -0
  15. package/dist/src/cleaning/index.d.ts +8 -0
  16. package/dist/src/cleaning/index.js +4 -0
  17. package/dist/src/cleaning/manifest.d.ts +35 -0
  18. package/dist/src/cleaning/manifest.js +95 -0
  19. package/dist/src/cli/commands/check.js +2 -89
  20. package/dist/src/cli/commands/clean.d.ts +1 -0
  21. package/dist/src/cli/commands/clean.js +115 -0
  22. package/dist/src/cli/commands/help.js +1 -0
  23. package/dist/src/cli/commands/query.js +4 -1
  24. package/dist/src/cli/commands/visualize.js +2 -0
  25. package/dist/src/cli/index.js +2 -0
  26. package/dist/src/connectors/csv.js +81 -8
  27. package/dist/src/connectors/manager.d.ts +10 -0
  28. package/dist/src/connectors/manager.js +60 -1
  29. package/dist/src/connectors/sql-safety.d.ts +68 -0
  30. package/dist/src/connectors/sql-safety.js +167 -0
  31. package/dist/src/mcp/index.js +9 -1
  32. package/dist/src/mcp/tools/clean-column.d.ts +5 -0
  33. package/dist/src/mcp/tools/clean-column.js +45 -0
  34. package/dist/src/mcp/tools/clean-schemas.d.ts +23 -0
  35. package/dist/src/mcp/tools/clean-schemas.js +9 -0
  36. package/dist/src/mcp/tools/query-source.d.ts +2 -2
  37. package/dist/src/mcp/tools/query-source.js +2 -1
  38. package/dist/src/mcp/tools/shared.d.ts +1 -0
  39. package/dist/src/mcp/tools/shared.js +1 -1
  40. package/dist/src/mcp/tools/visualize-cli.d.ts +2 -2
  41. package/dist/src/mcp/tools/visualize.d.ts +3 -2
  42. package/dist/src/mcp/tools/visualize.js +1 -0
  43. package/dist/src/transforms/evaluator.js +58 -3
  44. package/dist/src/transforms/tokenizer.js +20 -2
  45. package/dist/src/transforms/types.d.ts +6 -6
  46. package/dist/src/types.d.ts +10 -0
  47. package/package.json +5 -2
@@ -8,7 +8,7 @@ import { errorResponse, jsonResponse } from './shared.js';
8
8
  import { logOperation } from './operation-log.js';
9
9
  export const querySourceInputSchema = z.object({
10
10
  sourceId: z.string().describe('Dataset ID returned by load_csv'),
11
- sql: z.string().describe('SQL SELECT query. Use table and column names from load_csv/describe_data. Supports JOINs, GROUP BY, HAVING, window functions, CTEs. Custom aggregates: MEDIAN, STDDEV, P25, P75, P10, P90.'),
11
+ sql: z.string().describe('SQL SELECT query. Use table and column names from load_csv/describe_data. Supports JOINs, GROUP BY, HAVING, window functions, CTEs. Custom aggregates: MEDIAN, STDDEV, CV (coeff. of variation), MAD (median abs. deviation), P1/P5/P10/P25/P75/P90/P95/P99.'),
12
12
  maxRows: z.number().optional().describe('Max rows to return (default: 10000)'),
13
13
  });
14
14
  export function handleQuerySource(deps) {
@@ -49,6 +49,7 @@ export function handleQuerySource(deps) {
49
49
  rows: result.rows,
50
50
  totalRows: result.totalRows,
51
51
  truncated: result.truncated ?? false,
52
+ ...(result.warnings?.length ? { warnings: result.warnings } : {}),
52
53
  queryTimeMs: Date.now() - start,
53
54
  });
54
55
  };
@@ -50,6 +50,7 @@ export interface ResolvedData {
50
50
  queryMeta?: {
51
51
  truncated?: boolean;
52
52
  totalSourceRows?: number;
53
+ warnings?: string[];
53
54
  };
54
55
  extraMeta?: {
55
56
  sqlPreview?: string;
@@ -211,7 +211,7 @@ export async function resolveData(args, deps) {
211
211
  return errorResponse(result.error);
212
212
  }
213
213
  data = result.rows;
214
- queryMeta = { truncated: result.truncated, totalSourceRows: result.totalRows };
214
+ queryMeta = { truncated: result.truncated, totalSourceRows: result.totalRows, warnings: result.warnings };
215
215
  extraMeta = { sqlPreview: args.sql.slice(0, 200), sourceType };
216
216
  }
217
217
  if (!data && args.resultId) {
@@ -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
- values[i] = evaluate(ast, {
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
- node.args.forEach(walk);
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
- node.elements.forEach(walk);
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
- if (ch === '"') {
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
  }>;
@@ -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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@outsidedata/dolex",
3
- "version": "8.0.2",
3
+ "version": "8.1.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",