@kaelio/ktx 0.14.0 → 0.16.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 (96) hide show
  1. package/assets/python/kaelio_ktx-0.16.0-py3-none-any.whl +0 -0
  2. package/assets/python/manifest.json +4 -4
  3. package/dist/.tsbuildinfo +1 -1
  4. package/dist/commands/setup-commands.js +2 -0
  5. package/dist/connection-drivers.d.ts +1 -1
  6. package/dist/connection-drivers.js +2 -0
  7. package/dist/connection.js +1 -0
  8. package/dist/connectors/athena/connector.d.ts +160 -0
  9. package/dist/connectors/athena/connector.js +378 -0
  10. package/dist/connectors/athena/dialect.d.ts +31 -0
  11. package/dist/connectors/athena/dialect.js +146 -0
  12. package/dist/connectors/athena/live-database-introspection.d.ts +10 -0
  13. package/dist/connectors/athena/live-database-introspection.js +24 -0
  14. package/dist/connectors/duckdb/connector.d.ts +60 -0
  15. package/dist/connectors/duckdb/connector.js +282 -0
  16. package/dist/connectors/duckdb/dialect.d.ts +31 -0
  17. package/dist/connectors/duckdb/dialect.js +155 -0
  18. package/dist/connectors/duckdb/federated-attach.js +7 -0
  19. package/dist/connectors/duckdb/federated-executor.js +7 -13
  20. package/dist/connectors/duckdb/live-database-introspection.d.ts +8 -0
  21. package/dist/connectors/duckdb/live-database-introspection.js +24 -0
  22. package/dist/connectors/shared/duckdb-json-safe.d.ts +3 -0
  23. package/dist/connectors/shared/duckdb-json-safe.js +12 -0
  24. package/dist/context/connections/connection-type-dialect.d.ts +2 -0
  25. package/dist/context/connections/connection-type-dialect.js +20 -0
  26. package/dist/context/connections/connection-type.d.ts +6 -15
  27. package/dist/context/connections/connection-type.js +1 -10
  28. package/dist/context/connections/dialects.js +4 -0
  29. package/dist/context/connections/drivers.js +38 -0
  30. package/dist/context/connections/federation.d.ts +1 -1
  31. package/dist/context/connections/federation.js +6 -5
  32. package/dist/context/connections/local-warehouse-descriptor.d.ts +1 -0
  33. package/dist/context/connections/local-warehouse-descriptor.js +10 -0
  34. package/dist/context/connections/project-sql-executor.d.ts +24 -0
  35. package/dist/context/connections/project-sql-executor.js +56 -0
  36. package/dist/context/connections/query-policy.d.ts +12 -0
  37. package/dist/context/connections/query-policy.js +46 -0
  38. package/dist/context/core/config-reference.js +11 -1
  39. package/dist/context/daemon/semantic-layer-compute.d.ts +16 -0
  40. package/dist/context/daemon/semantic-layer-compute.js +44 -2
  41. package/dist/context/ingest/adapters/looker/mapping.d.ts +1 -0
  42. package/dist/context/ingest/adapters/looker/mapping.js +3 -10
  43. package/dist/context/ingest/adapters/looker/types.d.ts +6 -15
  44. package/dist/context/ingest/adapters/metabase/mapping.d.ts +1 -0
  45. package/dist/context/ingest/adapters/metabase/mapping.js +1 -0
  46. package/dist/context/ingest/adapters/sigma/chunk.d.ts +6 -0
  47. package/dist/context/ingest/adapters/sigma/chunk.js +119 -0
  48. package/dist/context/ingest/adapters/sigma/client-port.d.ts +45 -0
  49. package/dist/context/ingest/adapters/sigma/client-port.js +1 -0
  50. package/dist/context/ingest/adapters/sigma/client.d.ts +33 -0
  51. package/dist/context/ingest/adapters/sigma/client.js +176 -0
  52. package/dist/context/ingest/adapters/sigma/detect.d.ts +1 -0
  53. package/dist/context/ingest/adapters/sigma/detect.js +23 -0
  54. package/dist/context/ingest/adapters/sigma/fetch.d.ts +14 -0
  55. package/dist/context/ingest/adapters/sigma/fetch.js +191 -0
  56. package/dist/context/ingest/adapters/sigma/local-sigma.adapter.d.ts +17 -0
  57. package/dist/context/ingest/adapters/sigma/local-sigma.adapter.js +41 -0
  58. package/dist/context/ingest/adapters/sigma/project.d.ts +8 -0
  59. package/dist/context/ingest/adapters/sigma/project.js +186 -0
  60. package/dist/context/ingest/adapters/sigma/sigma.adapter.d.ts +18 -0
  61. package/dist/context/ingest/adapters/sigma/sigma.adapter.js +43 -0
  62. package/dist/context/ingest/adapters/sigma/types.d.ts +80 -0
  63. package/dist/context/ingest/adapters/sigma/types.js +82 -0
  64. package/dist/context/ingest/local-adapters.d.ts +2 -1
  65. package/dist/context/ingest/local-adapters.js +22 -0
  66. package/dist/context/mcp/context-tools.js +1 -0
  67. package/dist/context/mcp/local-project-ports.d.ts +1 -1
  68. package/dist/context/mcp/local-project-ports.js +53 -51
  69. package/dist/context/project/config.d.ts +122 -0
  70. package/dist/context/project/driver-schemas.d.ts +61 -0
  71. package/dist/context/project/driver-schemas.js +47 -0
  72. package/dist/context/scan/local-scan.js +3 -1
  73. package/dist/context/scan/types.d.ts +1 -1
  74. package/dist/context/sl/local-query.js +23 -6
  75. package/dist/context/sl/semantic-layer.service.d.ts +0 -4
  76. package/dist/context/sl/semantic-layer.service.js +3 -20
  77. package/dist/context/sl/tools/sl-warehouse-validation.d.ts +1 -1
  78. package/dist/context/sl/tools/sl-warehouse-validation.js +2 -2
  79. package/dist/context/sl/types.d.ts +1 -0
  80. package/dist/context/sql-analysis/dialect-notes.d.ts +1 -1
  81. package/dist/context/sql-analysis/dialect-notes.js +3 -2
  82. package/dist/context/sql-analysis/dialect.js +1 -0
  83. package/dist/context/sql-analysis/dialects/athena.md +12 -0
  84. package/dist/context/sql-analysis/dialects/duckdb.md +10 -0
  85. package/dist/local-adapters.js +17 -0
  86. package/dist/public-ingest.js +1 -0
  87. package/dist/setup-databases.d.ts +1 -1
  88. package/dist/setup-databases.js +52 -2
  89. package/dist/setup-sources.d.ts +2 -1
  90. package/dist/setup-sources.js +84 -0
  91. package/dist/skills/sigma_ingest/SKILL.md +189 -0
  92. package/dist/sql.js +9 -14
  93. package/dist/status-project.js +2 -1
  94. package/dist/telemetry/events.d.ts +1 -1
  95. package/package.json +3 -1
  96. package/assets/python/kaelio_ktx-0.14.0-py3-none-any.whl +0 -0
@@ -0,0 +1,189 @@
1
+ ---
2
+ name: sigma_ingest
3
+ description: Extract durable ktx wiki knowledge from staged Sigma data model specs and workbook summaries. Load for WorkUnits with unitKey sigma-data-models or sigma-workbooks.
4
+ callers: [memory_agent]
5
+ ---
6
+
7
+ # Sigma Ingest
8
+
9
+ Sigma ingest turns staged data model specs and workbook summaries into durable ktx wiki knowledge. The deterministic `project()` step has already written semantic-layer YAML for all warehouse-table data model elements before this skill runs — do not re-write those SL sources.
10
+
11
+ ## Work unit structure
12
+
13
+ Sigma produces at minimum two work units per ingest run:
14
+
15
+ - `sigma-data-models` or `sigma-data-models-N`
16
+ - `rawFiles`: `data-models/<id>.json` files (one per data model in this batch)
17
+ - `peerFileIndex`: `workbooks/<id>.json` files + `sigma-manifest.json` + `sigma-projection-config.json`
18
+ - When the workspace has more than 50 data models, split into batches: `sigma-data-models-0`, `sigma-data-models-1`, … with `displayLabel` like `"Sigma: data models (1/8)"`. When ≤50 data models, the unitKey is simply `sigma-data-models` with no suffix.
19
+ - `sigma-workbooks` or `sigma-workbooks-N`
20
+ - `rawFiles`: `workbooks/<id>.json` files (one per workbook in this batch)
21
+ - `peerFileIndex`: `data-models/<id>.json` files + `sigma-manifest.json` + `sigma-projection-config.json`
22
+ - When the workspace has more than 2000 workbooks, split into batches: `sigma-workbooks-0`, `sigma-workbooks-1`, … with `displayLabel` like `"Sigma: workbooks (1/4)"`. When ≤2000 workbooks, the unitKey is simply `sigma-workbooks` with no suffix.
23
+
24
+ `sigma-manifest.json` and `sigma-projection-config.json` are never in `rawFiles`. They live at the staged dir root and always appear in `peerFileIndex`.
25
+
26
+ ## Staged file shapes
27
+
28
+ **`data-models/<id>.json`** — one per data model (in `rawFiles` for data-model units):
29
+ ```json
30
+ {
31
+ "sigmaId": "abc-123",
32
+ "name": "Revenue Model",
33
+ "path": "Finance/Revenue Model",
34
+ "latestVersion": 3,
35
+ "updatedAt": "2026-01-15T00:00:00Z",
36
+ "isArchived": false,
37
+ "spec": {
38
+ "name": "Revenue Model",
39
+ "pages": [{
40
+ "id": "p1",
41
+ "name": "Main",
42
+ "elements": [{
43
+ "id": "elem1",
44
+ "kind": "table",
45
+ "name": "Opportunities",
46
+ "hidden": false,
47
+ "source": {
48
+ "kind": "warehouse-table",
49
+ "connectionId": "<sigma-internal-uuid>",
50
+ "path": ["DATABASE", "SCHEMA", "OPPORTUNITIES"]
51
+ },
52
+ "columns": [
53
+ { "id": "c1", "name": "Deal Amount", "formula": "[OPPORTUNITIES/Amount]", "description": "Net contract value in USD" },
54
+ { "id": "c2", "name": "Total ARR", "formula": "Sum([OPPORTUNITIES/ARR])", "description": "Annualised recurring revenue" }
55
+ ]
56
+ }]
57
+ }]
58
+ }
59
+ }
60
+ ```
61
+
62
+ `source.kind` discriminates:
63
+ - `warehouse-table` — element maps directly to a warehouse table. Has `connectionId` and `path` (array of path segments forming the fully-qualified table name). `project()` writes an SL source when `connectionMappings` covers this `connectionId`.
64
+ - `table` — element is a derived view layered on top of another element; identified by `source.elementId`. No warehouse path. Wiki-only.
65
+
66
+ **`workbooks/<id>.json`** — one per workbook, in `rawFiles` for workbook units (summary only; no spec endpoint exists):
67
+ ```json
68
+ {
69
+ "sigmaId": "wb-abc",
70
+ "name": "ARR Tracker",
71
+ "path": "Finance/Dashboards",
72
+ "latestVersion": 2,
73
+ "updatedAt": "2026-01-16T00:00:00Z",
74
+ "isArchived": false,
75
+ "workbookUrlId": "57a96EMo3G...",
76
+ "description": "Tracks ARR by segment and cohort for the finance team"
77
+ }
78
+ ```
79
+
80
+ **Peer files (available via `peerFileIndex`, not `rawFiles`):**
81
+
82
+ **`sigma-manifest.json`** — fetch summary; use for provenance only.
83
+
84
+ **`sigma-projection-config.json`** — written by `fetch()`, contains two fields the skill must read:
85
+
86
+ - `connectionMappings`: `{sigmaInternalUuid: ktxWarehouseConnectionId}`. Use the mapped warehouse connection ID for `entity_details` when verifying warehouse identifiers found in data model specs.
87
+ - `workbookFilter`: the filter settings that were active when workbooks were last fetched:
88
+ - `includeArchived` (default `false`) — when `false`, archived workbooks are not in `workbooks/`; `isArchived: true` files will only appear when this was `true`.
89
+ - `includeExplorations` (default `false`) — when `false`, exploration-type workbooks (unsaved analyses) are excluded; treat present workbooks as intentional, curated reports.
90
+ - `updatedSince` (optional ISO 8601 string) — when set, only workbooks updated on or after this date are staged; the set is a recent-changes slice, not the full workspace. Do not infer that absent workbooks were deleted.
91
+
92
+ `sigma-manifest.json` also reflects any active `dataModelFilter`. When `dataModelFilter.updatedSince` was set during fetch, `dataModelCount` reflects only matching models, not the full workspace. Do not infer that absent data models were deleted.
93
+
94
+ Read `sigma-projection-config.json` first and keep `workbookFilter` in scope while processing the WorkUnit.
95
+
96
+ ## Required workflow
97
+
98
+ 1. Read every `rawFiles` entry for the WorkUnit.
99
+ 2. Read `sigma-projection-config.json` from the staged dir to get `connectionMappings`.
100
+ 3. For each data model file: extract business semantics from element names, column descriptions, and the domain context of the model. Skip hidden elements and hidden columns.
101
+ 4. For each workbook file: extract business domain knowledge from the name and description. When `workbookFilter.updatedSince` is set, treat the staged set as a recent-changes slice — absent workbooks were not deleted, they were simply outside the filter window.
102
+ 5. Use `discover_data` before writing to find existing wiki pages on the same topic.
103
+ 6. Write wiki candidates with `context_candidate_write`. Do not call `wiki_write` directly from a Sigma WorkUnit; Stage 4 reconciliation promotes candidates.
104
+ 7. Do not write or edit SL sources. The `project()` step owns all SL output for Sigma.
105
+
106
+ ## Identifier Verification Protocol
107
+
108
+ Before writing a wiki page or SL source on any topic:
109
+
110
+ 1. `discover_data({query: "<topic>"})` - see what wikis, SL sources, and raw
111
+ tables already exist. Prefer updating existing pages over creating new ones.
112
+
113
+ Before emitting any `schema.table` or `schema.table.column` into a wiki body,
114
+ SL source, `tables:` frontmatter, `sl_refs`, or `emit_unmapped_fallback`:
115
+
116
+ 2. `entity_details({connectionId, targets: [{display: "<identifier>"}]})` -
117
+ confirm the identifier resolves; inspect native types, FK/PK, and
118
+ sampleValues. Use the warehouse `connectionId` from `connectionMappings` in
119
+ `sigma-projection-config.json`, not the Sigma connection ID. If
120
+ `connectionMappings` has no entry for the element's `source.connectionId`,
121
+ skip `entity_details` — there is no mapped warehouse to verify against —
122
+ and wrap any identifier references with `[unverified - from <rawPath>]`.
123
+ 3. For literal values from the source, such as status codes or plan tiers,
124
+ check whether they appear in `entity_details` sampleValues for the relevant
125
+ column. If sampleValues is short or the sample may have missed real values,
126
+ run a `sql_execution` probe with the same warehouse connection id:
127
+ `sql_execution({connectionId, sql: "SELECT DISTINCT <col> FROM <ref> LIMIT 50"})`.
128
+ 4. If the candidate identifier still does not resolve, do one of:
129
+ - Use `sql_execution({connectionId, sql: "SELECT 1 FROM <ref> LIMIT 0"})`.
130
+ If it errors, the identifier is fictional.
131
+ - Wrap the identifier in `[unverified - from <rawPath>]` in the wiki body,
132
+ citing the exact raw path that mentioned it.
133
+ - When recording `emit_unmapped_fallback` with `no_physical_table`, include
134
+ the failing probe error in `clarification`.
135
+ 5. Never copy `<schema>.<table>` placeholder strings from these instructions
136
+ into output.
137
+
138
+ ## Data model elements
139
+
140
+ ### Warehouse-table elements (`source.kind === "warehouse-table"`)
141
+
142
+ `project()` writes an SL source for a warehouse-table element **only when** the element's `source.connectionId` has an entry in `connectionMappings`. When no mapping exists, no SL source is written and the element is wiki-only.
143
+
144
+ To determine whether an SL source exists: check whether `connectionMappings[element.source.connectionId]` resolves. If it does, use `sl_discover` to find the source by its slugified name (`<dataModelName>_<elementName>`), then:
145
+
146
+ - Read the existing SL source with `sl_read_source` to understand what columns and measures are captured.
147
+ - Write a wiki candidate about the business domain if the element name, column descriptions, or data model description reveals durable knowledge not already in the wiki.
148
+ - `sl_refs` in the wiki candidate should point to the already-written SL source name.
149
+
150
+ If `connectionMappings` has no entry for the element's `source.connectionId`, treat the element as wiki-only — do not attempt `sl_discover` or `sl_read_source` for it, as no source was written.
151
+
152
+ ### Joins within a data model
153
+
154
+ Joins are not projected in v1; `joins: []` is always written by `project()`. `Lookup()` formulas may be described in wiki prose instead.
155
+
156
+ ### Non-warehouse elements (`source.kind === "table"`)
157
+
158
+ These reference another element by `elementId` — they are derived views layered on top of a warehouse-table element. They have no warehouse path of their own. Do not attempt SL writes for these elements. They may produce wiki candidates if their column names or descriptions reveal business semantics not captured by the underlying warehouse-table element.
159
+
160
+ ## Workbooks
161
+
162
+ Workbooks have summary metadata only. There is no spec endpoint.
163
+
164
+ Extract business domain knowledge from:
165
+ - `name`: the workbook's primary topic (e.g. "ARR Tracker" → ARR tracking concepts)
166
+ - `description`: business context and intended audience
167
+ - `path`: team or functional area (e.g. `Finance/Dashboards`)
168
+
169
+ Write wiki candidates when the name or description reveals a reusable business concept, metric definition, or domain convention. Write one candidate per distinct concept, not one per workbook.
170
+
171
+ Skip workbooks whose name or description contains no durable business semantics (e.g. "Untitled Workbook", "Test Dashboard").
172
+
173
+ ## Capture rules
174
+
175
+ Write wiki candidates for:
176
+ - Metric definitions mentioned in element names or column descriptions (e.g. "Net ARR", "Churned MRR")
177
+ - Domain conventions such as cohort definitions, segment taxonomies, or fiscal calendar rules
178
+ - Relationships between business entities revealed by data model joins
179
+
180
+ Skip:
181
+ - Visualization settings, layout, colors, chart types
182
+ - Owner names, folder paths, and version numbers as wiki narrative
183
+ - Hidden elements and hidden columns
184
+ - Data model names that are purely technical with no business meaning
185
+ - When `workbookFilter.includeExplorations` is `false` (the default), all staged workbooks are intentional reports — no extra exploration filter needed. When it is `true`, workbooks without a description or with a generic auto-generated name are likely ephemeral explorations; skip those.
186
+
187
+ ## Usage signals
188
+
189
+ Sigma workbooks carry `latestVersion` but no usage counts. Treat a higher `latestVersion` as weak evidence of continued maintenance; do not include version numbers in wiki prose.
package/dist/sql.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { FEDERATED_CONNECTION_ID } from './context/connections/federation.js';
2
- import { executeProjectReadOnlySql } from './context/connections/project-sql-executor.js';
2
+ import { executeProjectRawSql } from './context/connections/project-sql-executor.js';
3
3
  import { assertSqlQueryableConnection } from './context/connections/dialects.js';
4
4
  import { resolveConfiguredConnection } from './context/connections/resolve-connection.js';
5
5
  import { loadKtxProject } from './context/project/project.js';
@@ -91,6 +91,8 @@ export async function runKtxSql(args, io = process, deps = {}) {
91
91
  const connection = isFederated ? undefined : resolveConfiguredConnection(project.config, args.connectionId);
92
92
  driver = isFederated ? 'duckdb' : String(connection?.driver ?? 'unknown').toLowerCase();
93
93
  demoConnection = isFederated ? false : isDemoConnection(args.connectionId, connection);
94
+ // Fail fast before creating the SQL-analysis daemon port; executeProjectRawSql
95
+ // re-asserts this for every caller.
94
96
  if (!isFederated) {
95
97
  assertSqlQueryableConnection(args.connectionId, connection?.driver);
96
98
  }
@@ -103,25 +105,18 @@ export async function runKtxSql(args, io = process, deps = {}) {
103
105
  }));
104
106
  const analysisPort = createSqlAnalysis();
105
107
  const dialect = isFederated ? 'duckdb' : sqlAnalysisDialectForDriver(connection?.driver);
106
- const validation = await analysisPort.validateReadOnly(args.sql, dialect);
107
- if (!validation.ok) {
108
- throw new Error(validation.error ?? 'SQL is not read-only.');
109
- }
110
- const referencedTableCount = await safeReferencedTableCount(analysisPort, args.sql, dialect);
111
108
  const createScanConnector = deps.createScanConnector ?? createKtxCliScanConnector;
112
- const result = await executeProjectReadOnlySql({
109
+ const result = await executeProjectRawSql({
113
110
  project,
114
- input: {
115
- connectionId: args.connectionId,
116
- projectDir: args.projectDir,
117
- connection,
118
- sql: args.sql,
119
- maxRows: args.maxRows,
120
- },
111
+ connectionId: args.connectionId,
112
+ sql: args.sql,
113
+ maxRows: args.maxRows,
114
+ sqlAnalysis: analysisPort,
121
115
  createConnector: (connectionId) => createScanConnector(project, connectionId),
122
116
  executeFederated: deps.executeFederated,
123
117
  runId: 'cli-sql',
124
118
  });
119
+ const referencedTableCount = await safeReferencedTableCount(analysisPort, args.sql, dialect);
125
120
  const mode = resolveOutputMode({ explicit: args.output, json: args.json, io });
126
121
  printSqlResult(resultOutput(args.connectionId, result), mode, io);
127
122
  await emitTelemetryEvent({
@@ -236,6 +236,7 @@ function buildConnectionStatus(name, conn, env) {
236
236
  const hint = envHint(conn.credentials_json);
237
237
  return warn(hint ? `credentials missing (env: ${hint})` : 'credentials not set', hint ? `Set ${hint}` : 'Rerun `ktx setup`');
238
238
  }
239
+ case 'duckdb':
239
240
  case 'sqlite': {
240
241
  const path = conn.path;
241
242
  if (typeof path === 'string' && path.length > 0)
@@ -361,7 +362,7 @@ async function buildQueryHistoryStatus(project, options) {
361
362
  return statuses;
362
363
  }
363
364
  const ADAPTER_DRIVER_REQUIREMENT = {
364
- 'live-database': ['postgres', 'mysql', 'snowflake', 'bigquery', 'clickhouse', 'sqlite', 'sqlserver'],
365
+ 'live-database': ['postgres', 'mysql', 'snowflake', 'bigquery', 'clickhouse', 'sqlite', 'duckdb', 'sqlserver'],
365
366
  dbt: ['dbt', 'dbt-core', 'dbt-cloud'],
366
367
  notion: ['notion'],
367
368
  metabase: ['metabase'],
@@ -66,8 +66,8 @@ export declare const telemetryEventSchemas: {
66
66
  project: "project";
67
67
  models: "models";
68
68
  sources: "sources";
69
- context: "context";
70
69
  runtime: "runtime";
70
+ context: "context";
71
71
  secrets: "secrets";
72
72
  agents: "agents";
73
73
  "demo-tour": "demo-tour";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kaelio/ktx",
3
- "version": "0.14.0",
3
+ "version": "0.16.0",
4
4
  "description": "Standalone ktx context layer for data agents",
5
5
  "author": {
6
6
  "name": "Kaelio",
@@ -36,6 +36,8 @@
36
36
  "@ai-sdk/devtools": "0.0.18",
37
37
  "@ai-sdk/google-vertex": "^4.0.134",
38
38
  "@anthropic-ai/claude-agent-sdk": "0.3.146",
39
+ "@aws-sdk/client-athena": "^3.1068.0",
40
+ "@aws-sdk/client-glue": "^3.1068.0",
39
41
  "@clack/core": "1.3.1",
40
42
  "@clack/prompts": "1.4.0",
41
43
  "@clickhouse/client": "^1.18.5",