@kaelio/ktx 0.2.0 → 0.3.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 (87) hide show
  1. package/assets/python/{kaelio_ktx-0.2.0-py3-none-any.whl → kaelio_ktx-0.3.0-py3-none-any.whl} +0 -0
  2. package/assets/python/manifest.json +4 -4
  3. package/dist/admin-reindex.js +10 -17
  4. package/dist/admin-reindex.test.js +1 -1
  5. package/dist/cli-program.test.js +0 -2
  6. package/dist/cli-project.d.ts +18 -0
  7. package/dist/cli-project.js +52 -0
  8. package/dist/cli-project.test.js +149 -0
  9. package/dist/cli-runtime.d.ts +0 -2
  10. package/dist/cli-runtime.js +2 -8
  11. package/dist/commands/runtime-commands.js +2 -2
  12. package/dist/context-build-view.js +1 -1
  13. package/dist/index.test.js +21 -25
  14. package/dist/ingest.js +9 -2
  15. package/dist/ingest.test.js +27 -3
  16. package/dist/managed-local-embeddings.d.ts +0 -2
  17. package/dist/managed-local-embeddings.js +2 -5
  18. package/dist/managed-local-embeddings.test.js +5 -8
  19. package/dist/managed-python-daemon.js +2 -2
  20. package/dist/managed-python-daemon.test.js +1 -1
  21. package/dist/managed-python-http.js +3 -3
  22. package/dist/managed-python-http.test.js +6 -6
  23. package/dist/print-command-tree.js +0 -2
  24. package/dist/public-ingest.d.ts +4 -2
  25. package/dist/public-ingest.js +9 -3
  26. package/dist/release-version.d.ts +1 -5
  27. package/dist/release-version.js +2 -39
  28. package/dist/runtime-requirements.js +1 -1
  29. package/dist/runtime.js +6 -6
  30. package/dist/runtime.test.js +7 -7
  31. package/dist/scan.js +7 -2
  32. package/dist/scan.test.js +1 -1
  33. package/dist/setup-embeddings.js +1 -1
  34. package/dist/setup-embeddings.test.js +2 -2
  35. package/dist/setup-runtime.test.js +1 -1
  36. package/node_modules/@ktx/context/dist/core/git.service.d.ts +1 -0
  37. package/node_modules/@ktx/context/dist/core/git.service.js +12 -0
  38. package/node_modules/@ktx/context/dist/ingest/adapters/historic-sql/historic-sql.adapter.d.ts +2 -1
  39. package/node_modules/@ktx/context/dist/ingest/adapters/historic-sql/historic-sql.adapter.js +18 -0
  40. package/node_modules/@ktx/context/dist/ingest/adapters/historic-sql/local-ingest-acceptance.test.js +6 -6
  41. package/node_modules/@ktx/context/dist/ingest/adapters/historic-sql/projection.d.ts +5 -0
  42. package/node_modules/@ktx/context/dist/ingest/adapters/historic-sql/projection.js +48 -0
  43. package/node_modules/@ktx/context/dist/ingest/adapters/historic-sql/projection.test.js +83 -0
  44. package/node_modules/@ktx/context/dist/ingest/adapters/live-database/daemon-introspection.js +4 -1
  45. package/node_modules/@ktx/context/dist/ingest/adapters/live-database/daemon-introspection.test.js +32 -0
  46. package/node_modules/@ktx/context/dist/ingest/finalization-scope.d.ts +22 -0
  47. package/node_modules/@ktx/context/dist/ingest/finalization-scope.js +95 -0
  48. package/node_modules/@ktx/context/dist/ingest/finalization-scope.test.d.ts +1 -0
  49. package/node_modules/@ktx/context/dist/ingest/finalization-scope.test.js +114 -0
  50. package/node_modules/@ktx/context/dist/ingest/index.d.ts +1 -2
  51. package/node_modules/@ktx/context/dist/ingest/index.js +0 -1
  52. package/node_modules/@ktx/context/dist/ingest/ingest-bundle.runner.d.ts +2 -0
  53. package/node_modules/@ktx/context/dist/ingest/ingest-bundle.runner.isolated-diff.test.js +166 -0
  54. package/node_modules/@ktx/context/dist/ingest/ingest-bundle.runner.js +235 -45
  55. package/node_modules/@ktx/context/dist/ingest/ingest-bundle.runner.test.js +193 -38
  56. package/node_modules/@ktx/context/dist/ingest/local-bundle-ingest.test.js +22 -3
  57. package/node_modules/@ktx/context/dist/ingest/local-bundle-runtime.js +0 -4
  58. package/node_modules/@ktx/context/dist/ingest/local-ingest.js +0 -7
  59. package/node_modules/@ktx/context/dist/ingest/local-stage-ingest.js +15 -5
  60. package/node_modules/@ktx/context/dist/ingest/local-stage-ingest.test.js +29 -0
  61. package/node_modules/@ktx/context/dist/ingest/memory-flow/schema.d.ts +2 -2
  62. package/node_modules/@ktx/context/dist/ingest/memory-flow/schema.js +1 -1
  63. package/node_modules/@ktx/context/dist/ingest/memory-flow/types.d.ts +1 -1
  64. package/node_modules/@ktx/context/dist/ingest/ports.d.ts +1 -20
  65. package/node_modules/@ktx/context/dist/ingest/report-snapshot.d.ts +71 -0
  66. package/node_modules/@ktx/context/dist/ingest/report-snapshot.js +27 -0
  67. package/node_modules/@ktx/context/dist/ingest/reports.d.ts +23 -5
  68. package/node_modules/@ktx/context/dist/ingest/reports.js +7 -24
  69. package/node_modules/@ktx/context/dist/ingest/types.d.ts +33 -0
  70. package/node_modules/@ktx/context/dist/llm/index.d.ts +1 -1
  71. package/node_modules/@ktx/context/dist/llm/index.js +1 -1
  72. package/node_modules/@ktx/context/dist/llm/local-config.d.ts +0 -1
  73. package/node_modules/@ktx/context/dist/llm/local-config.js +2 -12
  74. package/node_modules/@ktx/context/dist/llm/local-config.test.js +2 -23
  75. package/node_modules/@ktx/context/dist/package-exports.test.js +2 -2
  76. package/node_modules/@ktx/context/dist/project/config.d.ts +16 -0
  77. package/node_modules/@ktx/context/dist/project/driver-schemas.d.ts +8 -0
  78. package/node_modules/@ktx/context/dist/project/driver-schemas.js +4 -0
  79. package/node_modules/@ktx/context/dist/scan/enabled-tables.d.ts +3 -0
  80. package/node_modules/@ktx/context/dist/scan/enabled-tables.js +15 -0
  81. package/node_modules/@ktx/context/dist/scan/local-scan.d.ts +2 -4
  82. package/node_modules/@ktx/context/dist/scan/local-scan.js +2 -15
  83. package/package.json +1 -1
  84. package/node_modules/@ktx/context/dist/ingest/adapters/historic-sql/post-processor.d.ts +0 -4
  85. package/node_modules/@ktx/context/dist/ingest/adapters/historic-sql/post-processor.js +0 -38
  86. package/node_modules/@ktx/context/dist/ingest/adapters/historic-sql/post-processor.test.js +0 -63
  87. /package/{node_modules/@ktx/context/dist/ingest/adapters/historic-sql/post-processor.test.d.ts → dist/cli-project.test.d.ts} +0 -0
@@ -221,6 +221,77 @@ export declare const ingestReportSnapshotSchema: z.ZodObject<{
221
221
  errorCount: z.ZodNumber;
222
222
  toolNames: z.ZodArray<z.ZodString>;
223
223
  }, z.core.$strip>>>;
224
+ finalization: z.ZodOptional<z.ZodObject<{
225
+ sourceKey: z.ZodString;
226
+ status: z.ZodEnum<{
227
+ success: "success";
228
+ skipped: "skipped";
229
+ failed: "failed";
230
+ }>;
231
+ commitSha: z.ZodNullable<z.ZodString>;
232
+ touchedPaths: z.ZodArray<z.ZodString>;
233
+ declaredTouchedSources: z.ZodArray<z.ZodObject<{
234
+ connectionId: z.ZodString;
235
+ sourceName: z.ZodString;
236
+ }, z.core.$strip>>;
237
+ derivedTouchedSources: z.ZodArray<z.ZodObject<{
238
+ connectionId: z.ZodString;
239
+ sourceName: z.ZodString;
240
+ }, z.core.$strip>>;
241
+ declaredChangedWikiPageKeys: z.ZodArray<z.ZodString>;
242
+ derivedChangedWikiPageKeys: z.ZodArray<z.ZodString>;
243
+ mismatches: z.ZodDefault<z.ZodArray<z.ZodObject<{
244
+ artifactKind: z.ZodEnum<{
245
+ wiki: "wiki";
246
+ sl: "sl";
247
+ }>;
248
+ key: z.ZodString;
249
+ direction: z.ZodEnum<{
250
+ missing_from_adapter_declaration: "missing_from_adapter_declaration";
251
+ extra_in_adapter_declaration: "extra_in_adapter_declaration";
252
+ }>;
253
+ }, z.core.$strip>>>;
254
+ result: z.ZodOptional<z.ZodUnknown>;
255
+ errors: z.ZodArray<z.ZodString>;
256
+ warnings: z.ZodArray<z.ZodString>;
257
+ actions: z.ZodDefault<z.ZodArray<z.ZodObject<{
258
+ target: z.ZodEnum<{
259
+ wiki: "wiki";
260
+ sl: "sl";
261
+ }>;
262
+ type: z.ZodEnum<{
263
+ created: "created";
264
+ updated: "updated";
265
+ removed: "removed";
266
+ }>;
267
+ key: z.ZodString;
268
+ detail: z.ZodString;
269
+ targetConnectionId: z.ZodDefault<z.ZodNullable<z.ZodString>>;
270
+ rawPaths: z.ZodOptional<z.ZodArray<z.ZodString>>;
271
+ }, z.core.$strip>>>;
272
+ provenanceExclusions: z.ZodDefault<z.ZodArray<z.ZodObject<{
273
+ action: z.ZodObject<{
274
+ target: z.ZodEnum<{
275
+ wiki: "wiki";
276
+ sl: "sl";
277
+ }>;
278
+ type: z.ZodEnum<{
279
+ created: "created";
280
+ updated: "updated";
281
+ removed: "removed";
282
+ }>;
283
+ key: z.ZodString;
284
+ detail: z.ZodString;
285
+ targetConnectionId: z.ZodDefault<z.ZodNullable<z.ZodString>>;
286
+ rawPaths: z.ZodOptional<z.ZodArray<z.ZodString>>;
287
+ }, z.core.$strip>;
288
+ reason: z.ZodEnum<{
289
+ missing_raw_paths: "missing_raw_paths";
290
+ raw_path_not_defensible: "raw_path_not_defensible";
291
+ }>;
292
+ invalidRawPaths: z.ZodOptional<z.ZodArray<z.ZodString>>;
293
+ }, z.core.$strip>>>;
294
+ }, z.core.$strip>>;
224
295
  memoryFlow: z.ZodOptional<z.ZodType<import("./index.js").MemoryFlowReplayInput, unknown, z.core.$ZodTypeInternals<import("./index.js").MemoryFlowReplayInput, unknown>>>;
225
296
  }, z.core.$loose>;
226
297
  }, z.core.$loose>;
@@ -114,6 +114,32 @@ const ingestReportFailureSchema = z.object({
114
114
  message: z.string().min(1),
115
115
  details: z.record(z.string(), z.unknown()).optional(),
116
116
  });
117
+ const finalizationMismatchSchema = z.object({
118
+ artifactKind: z.enum(['sl', 'wiki']),
119
+ key: z.string().min(1),
120
+ direction: z.enum(['missing_from_adapter_declaration', 'extra_in_adapter_declaration']),
121
+ });
122
+ const finalizationProvenanceExclusionSchema = z.object({
123
+ action: ingestActionSchema,
124
+ reason: z.enum(['missing_raw_paths', 'raw_path_not_defensible']),
125
+ invalidRawPaths: z.array(z.string()).optional(),
126
+ });
127
+ const finalizationOutcomeSchema = z.object({
128
+ sourceKey: z.string().min(1),
129
+ status: z.enum(['success', 'failed', 'skipped']),
130
+ commitSha: z.string().nullable(),
131
+ touchedPaths: z.array(z.string()),
132
+ declaredTouchedSources: z.array(touchedSlSourceSchema),
133
+ derivedTouchedSources: z.array(touchedSlSourceSchema),
134
+ declaredChangedWikiPageKeys: z.array(z.string()),
135
+ derivedChangedWikiPageKeys: z.array(z.string()),
136
+ mismatches: z.array(finalizationMismatchSchema).default([]),
137
+ result: z.unknown().optional(),
138
+ errors: z.array(z.string()),
139
+ warnings: z.array(z.string()),
140
+ actions: z.array(ingestActionSchema).default([]),
141
+ provenanceExclusions: z.array(finalizationProvenanceExclusionSchema).default([]),
142
+ });
117
143
  export const ingestReportSnapshotSchema = z
118
144
  .object({
119
145
  id: z.string().min(1),
@@ -171,6 +197,7 @@ export const ingestReportSnapshotSchema = z
171
197
  overrideOf: z.string().nullable().default(null),
172
198
  provenanceRows: z.array(provenanceDetailSchema).default([]),
173
199
  toolTranscripts: z.array(toolTranscriptSummarySchema).default([]),
200
+ finalization: finalizationOutcomeSchema.optional(),
174
201
  memoryFlow: memoryFlowReplayInputSchema.optional(),
175
202
  })
176
203
  .passthrough(),
@@ -29,13 +29,31 @@ export interface IngestReportToolTranscriptSummary {
29
29
  errorCount: number;
30
30
  toolNames: string[];
31
31
  }
32
- export interface IngestReportPostProcessorOutcome {
32
+ export interface IngestReportFinalizationMismatch {
33
+ artifactKind: 'sl' | 'wiki';
34
+ key: string;
35
+ direction: 'missing_from_adapter_declaration' | 'extra_in_adapter_declaration';
36
+ }
37
+ export interface IngestReportFinalizationProvenanceExclusion {
38
+ action: MemoryAction;
39
+ reason: 'missing_raw_paths' | 'raw_path_not_defensible';
40
+ invalidRawPaths?: string[];
41
+ }
42
+ export interface IngestReportFinalizationOutcome {
33
43
  sourceKey: string;
34
- status: 'success' | 'failed';
44
+ status: 'success' | 'failed' | 'skipped';
45
+ commitSha: string | null;
46
+ touchedPaths: string[];
47
+ declaredTouchedSources: TouchedSlSource[];
48
+ derivedTouchedSources: TouchedSlSource[];
49
+ declaredChangedWikiPageKeys: string[];
50
+ derivedChangedWikiPageKeys: string[];
51
+ mismatches: IngestReportFinalizationMismatch[];
35
52
  result?: unknown;
36
53
  errors: string[];
37
54
  warnings: string[];
38
- touchedSources: TouchedSlSource[];
55
+ actions: MemoryAction[];
56
+ provenanceExclusions: IngestReportFinalizationProvenanceExclusion[];
39
57
  }
40
58
  export interface IngestReportFailure {
41
59
  phase: string;
@@ -79,7 +97,7 @@ export interface IngestReportBody {
79
97
  overrideOf: string | null;
80
98
  provenanceRows: IngestReportProvenanceDetail[];
81
99
  toolTranscripts: IngestReportToolTranscriptSummary[];
82
- postProcessor?: IngestReportPostProcessorOutcome;
100
+ finalization?: IngestReportFinalizationOutcome;
83
101
  wikiSlRefRepairs?: WikiSlRefRepair[];
84
102
  wikiSlRefRepairWarnings?: string[];
85
103
  memoryFlow?: MemoryFlowReplayInput;
@@ -97,6 +115,6 @@ export interface IngestSavedMemoryCounts {
97
115
  wikiCount: number;
98
116
  slCount: number;
99
117
  }
100
- export declare function postProcessorSavedMemoryCounts(postProcessor: IngestReportPostProcessorOutcome | undefined): IngestSavedMemoryCounts;
118
+ export declare function finalizationSavedMemoryCounts(finalization: IngestReportFinalizationOutcome | undefined): IngestSavedMemoryCounts;
101
119
  export declare function savedMemoryCountsForReport(report: IngestReportSnapshot): IngestSavedMemoryCounts;
102
120
  export declare function buildStageIndexFromReportBody(jobId: string, connectionId: string, body: IngestReportBody): StageIndex;
@@ -1,36 +1,19 @@
1
- function numericResultField(result, field) {
2
- const value = result[field];
3
- return typeof value === 'number' && Number.isFinite(value) && value > 0 ? value : 0;
4
- }
5
- export function postProcessorSavedMemoryCounts(postProcessor) {
6
- if (!postProcessor || postProcessor.sourceKey !== 'historic-sql') {
7
- return { wikiCount: 0, slCount: 0 };
8
- }
9
- const result = postProcessor.result;
10
- if (!result || typeof result !== 'object' || Array.isArray(result)) {
11
- return { wikiCount: 0, slCount: 0 };
12
- }
13
- const record = result;
1
+ export function finalizationSavedMemoryCounts(finalization) {
2
+ const actions = finalization?.actions ?? [];
14
3
  return {
15
- wikiCount: numericResultField(record, 'patternPagesWritten') +
16
- numericResultField(record, 'stalePatternPagesMarked') +
17
- numericResultField(record, 'archivedPatternPages'),
18
- slCount: numericResultField(record, 'tableUsageMerged') + numericResultField(record, 'staleTablesMarked'),
4
+ wikiCount: actions.filter((action) => action.target === 'wiki').length,
5
+ slCount: actions.filter((action) => action.target === 'sl').length,
19
6
  };
20
7
  }
21
8
  export function savedMemoryCountsForReport(report) {
22
9
  const workUnitActions = report.body.workUnits.flatMap((workUnit) => workUnit.actions);
23
10
  const reconciliationActions = report.body.reconciliationActions ?? [];
24
- const actions = [...workUnitActions, ...reconciliationActions];
25
- const directCounts = {
11
+ const finalizationActions = report.body.finalization?.actions ?? [];
12
+ const actions = [...workUnitActions, ...reconciliationActions, ...finalizationActions];
13
+ return {
26
14
  wikiCount: actions.filter((action) => action.target === 'wiki').length,
27
15
  slCount: actions.filter((action) => action.target === 'sl').length,
28
16
  };
29
- const postProcessorCounts = postProcessorSavedMemoryCounts(report.body.postProcessor);
30
- return {
31
- wikiCount: directCounts.wikiCount + postProcessorCounts.wikiCount,
32
- slCount: directCounts.slCount + postProcessorCounts.slCount,
33
- };
34
17
  }
35
18
  export function buildStageIndexFromReportBody(jobId, connectionId, body) {
36
19
  return {
@@ -1,6 +1,10 @@
1
1
  import type { KtxEmbeddingPort } from '../core/embedding.js';
2
+ import type { MemoryAction } from '../memory/index.js';
2
3
  import type { SemanticLayerService } from '../sl/index.js';
4
+ import type { TouchedSlSource } from '../tools/index.js';
3
5
  import type { MemoryFlowEventSink } from './memory-flow/types.js';
6
+ import type { StageIndex } from './stages/stage-index.types.js';
7
+ import type { WorkUnitOutcome } from './stages/stage-3-work-units.js';
4
8
  export type IngestTrigger = 'upload' | 'scheduled_pull' | 'manual_resync' | 'manual_override';
5
9
  export interface DiffSet {
6
10
  added: string[];
@@ -99,6 +103,34 @@ export interface ProjectionResult {
99
103
  changedWikiPageKeys: string[];
100
104
  result?: unknown;
101
105
  }
106
+ export interface FinalizationOverrideReplay {
107
+ priorJobId: string;
108
+ priorRunId: string;
109
+ priorSyncId: string;
110
+ evictionRawPaths: string[];
111
+ }
112
+ export interface DeterministicFinalizationContext {
113
+ connectionId: string;
114
+ sourceKey: string;
115
+ syncId: string;
116
+ jobId: string;
117
+ runId: string;
118
+ stagedDir: string;
119
+ workdir: string;
120
+ parseArtifacts?: unknown;
121
+ stageIndex: StageIndex;
122
+ workUnitOutcomes: WorkUnitOutcome[];
123
+ reconciliationActions: MemoryAction[];
124
+ overrideReplay?: FinalizationOverrideReplay;
125
+ }
126
+ export interface FinalizationResult {
127
+ warnings: string[];
128
+ errors: string[];
129
+ touchedSources: TouchedSlSource[];
130
+ changedWikiPageKeys: string[];
131
+ actions?: MemoryAction[];
132
+ result?: unknown;
133
+ }
102
134
  export interface SourceAdapter {
103
135
  readonly source: string;
104
136
  readonly skillNames: string[];
@@ -113,6 +145,7 @@ export interface SourceAdapter {
113
145
  chunk(stagedDir: string, diffSet?: DiffSet): Promise<ChunkResult>;
114
146
  clusterWorkUnits?(ctx: ClusterWorkUnitsContext): Promise<WorkUnit[]>;
115
147
  project?(ctx: DeterministicProjectionContext): Promise<ProjectionResult>;
148
+ finalize?(ctx: DeterministicFinalizationContext): Promise<FinalizationResult>;
116
149
  describeScope?(stagedDir: string): Promise<ScopeDescriptor>;
117
150
  onPullSucceeded?(ctx: {
118
151
  connectionId: string;
@@ -10,4 +10,4 @@ export { RuntimeAgentRunner } from './runtime-port.js';
10
10
  export { createAiSdkToolSet, createClaudeSdkTools, createRuntimeToolDescriptorFromAiTool, createRuntimeToolSetFromAiSdkTools, normalizeKtxRuntimeToolOutput, } from './runtime-tools.js';
11
11
  export type { KtxLlmDebugProviderOptionsEntry, KtxLlmDebugRequest, KtxLlmDebugRequestRecorder, SummarizeKtxLlmDebugRequestInput, } from './debug-request-recorder.js';
12
12
  export { createJsonlKtxLlmDebugRequestRecorder, summarizeKtxLlmDebugRequest, } from './debug-request-recorder.js';
13
- export { MANAGED_SENTENCE_TRANSFORMERS_BASE_URL, MANAGED_SENTENCE_TRANSFORMERS_BASE_URL_ENV, createLocalKtxEmbeddingProviderFromConfig, createLocalKtxLlmProviderFromConfig, createLocalKtxLlmRuntimeFromConfig, resolveLocalKtxEmbeddingConfig, resolveLocalKtxLlmConfig, } from './local-config.js';
13
+ export { MANAGED_SENTENCE_TRANSFORMERS_BASE_URL, createLocalKtxEmbeddingProviderFromConfig, createLocalKtxLlmProviderFromConfig, createLocalKtxLlmRuntimeFromConfig, resolveLocalKtxEmbeddingConfig, resolveLocalKtxLlmConfig, } from './local-config.js';
@@ -7,4 +7,4 @@ export { generateKtxObject, generateKtxText } from './generation.js';
7
7
  export { RuntimeAgentRunner } from './runtime-port.js';
8
8
  export { createAiSdkToolSet, createClaudeSdkTools, createRuntimeToolDescriptorFromAiTool, createRuntimeToolSetFromAiSdkTools, normalizeKtxRuntimeToolOutput, } from './runtime-tools.js';
9
9
  export { createJsonlKtxLlmDebugRequestRecorder, summarizeKtxLlmDebugRequest, } from './debug-request-recorder.js';
10
- export { MANAGED_SENTENCE_TRANSFORMERS_BASE_URL, MANAGED_SENTENCE_TRANSFORMERS_BASE_URL_ENV, createLocalKtxEmbeddingProviderFromConfig, createLocalKtxLlmProviderFromConfig, createLocalKtxLlmRuntimeFromConfig, resolveLocalKtxEmbeddingConfig, resolveLocalKtxLlmConfig, } from './local-config.js';
10
+ export { MANAGED_SENTENCE_TRANSFORMERS_BASE_URL, createLocalKtxEmbeddingProviderFromConfig, createLocalKtxLlmProviderFromConfig, createLocalKtxLlmRuntimeFromConfig, resolveLocalKtxEmbeddingConfig, resolveLocalKtxLlmConfig, } from './local-config.js';
@@ -13,7 +13,6 @@ interface LocalConfigDeps {
13
13
  }) => KtxLlmRuntimePort;
14
14
  }
15
15
  export declare const MANAGED_SENTENCE_TRANSFORMERS_BASE_URL = "managed:local-embeddings";
16
- export declare const MANAGED_SENTENCE_TRANSFORMERS_BASE_URL_ENV = "KTX_MANAGED_SENTENCE_TRANSFORMERS_BASE_URL";
17
16
  export declare function resolveLocalKtxLlmConfig(config: KtxProjectLlmConfig, env: NodeJS.ProcessEnv): KtxLlmConfig | null;
18
17
  export declare function createLocalKtxLlmProviderFromConfig(config: KtxProjectLlmConfig, deps?: LocalConfigDeps): KtxLlmProvider | null;
19
18
  export declare function createLocalKtxLlmRuntimeFromConfig(config: KtxProjectLlmConfig, deps?: LocalConfigDeps): KtxLlmRuntimePort | null;
@@ -3,7 +3,6 @@ import { resolveKtxConfigReference } from '../core/config-reference.js';
3
3
  import { AiSdkKtxLlmRuntime } from './ai-sdk-runtime.js';
4
4
  import { ClaudeCodeKtxLlmRuntime } from './claude-code-runtime.js';
5
5
  export const MANAGED_SENTENCE_TRANSFORMERS_BASE_URL = 'managed:local-embeddings';
6
- export const MANAGED_SENTENCE_TRANSFORMERS_BASE_URL_ENV = 'KTX_MANAGED_SENTENCE_TRANSFORMERS_BASE_URL';
7
6
  function resolveOptional(value, env) {
8
7
  return resolveKtxConfigReference(value, env) || undefined;
9
8
  }
@@ -94,22 +93,13 @@ export function createLocalKtxLlmRuntimeFromConfig(config, deps = {}) {
94
93
  const llmProvider = (deps.createKtxLlmProvider ?? createKtxLlmProvider)(resolved);
95
94
  return (deps.createAiSdkRuntime ?? ((runtimeDeps) => new AiSdkKtxLlmRuntime(runtimeDeps)))({ llmProvider });
96
95
  }
97
- function resolveSentenceTransformersBaseUrl(value, env) {
98
- if (!value) {
99
- return undefined;
100
- }
101
- if (value === MANAGED_SENTENCE_TRANSFORMERS_BASE_URL) {
102
- return resolveOptional(`env:${MANAGED_SENTENCE_TRANSFORMERS_BASE_URL_ENV}`, env);
103
- }
104
- return value;
105
- }
106
96
  export function resolveLocalKtxEmbeddingConfig(config, env) {
107
97
  if (config.backend === 'none') {
108
98
  return null;
109
99
  }
110
100
  if (config.backend === 'sentence-transformers') {
111
- const baseURL = resolveSentenceTransformersBaseUrl(config.sentenceTransformers?.base_url, env);
112
- if (!baseURL) {
101
+ const baseURL = config.sentenceTransformers?.base_url;
102
+ if (!baseURL || baseURL === MANAGED_SENTENCE_TRANSFORMERS_BASE_URL) {
113
103
  return null;
114
104
  }
115
105
  return {
@@ -1,6 +1,6 @@
1
1
  import { describe, expect, it, vi } from 'vitest';
2
2
  import { buildDefaultKtxProjectConfig, } from '../project/config.js';
3
- import { MANAGED_SENTENCE_TRANSFORMERS_BASE_URL, MANAGED_SENTENCE_TRANSFORMERS_BASE_URL_ENV, createLocalKtxEmbeddingProviderFromConfig, createLocalKtxLlmProviderFromConfig, resolveLocalKtxEmbeddingConfig, resolveLocalKtxLlmConfig, } from './local-config.js';
3
+ import { MANAGED_SENTENCE_TRANSFORMERS_BASE_URL, createLocalKtxEmbeddingProviderFromConfig, createLocalKtxLlmProviderFromConfig, resolveLocalKtxEmbeddingConfig, resolveLocalKtxLlmConfig, } from './local-config.js';
4
4
  describe('local KTX LLM config', () => {
5
5
  it('resolves env and file references into a KtxLlmConfig', () => {
6
6
  const config = {
@@ -116,28 +116,7 @@ describe('local KTX embedding config', () => {
116
116
  batchSize: 16,
117
117
  });
118
118
  });
119
- it('resolves managed sentence-transformers config from the CLI-provided daemon URL', () => {
120
- const config = {
121
- backend: 'sentence-transformers',
122
- model: 'all-MiniLM-L6-v2',
123
- dimensions: 384,
124
- sentenceTransformers: {
125
- base_url: MANAGED_SENTENCE_TRANSFORMERS_BASE_URL,
126
- pathPrefix: '',
127
- },
128
- batchSize: 32,
129
- };
130
- expect(resolveLocalKtxEmbeddingConfig(config, {
131
- [MANAGED_SENTENCE_TRANSFORMERS_BASE_URL_ENV]: 'http://127.0.0.1:61234',
132
- })).toEqual({
133
- backend: 'sentence-transformers',
134
- model: 'all-MiniLM-L6-v2',
135
- dimensions: 384,
136
- sentenceTransformers: { baseURL: 'http://127.0.0.1:61234', pathPrefix: '' },
137
- batchSize: 32,
138
- });
139
- });
140
- it('returns null for managed sentence-transformers when no daemon URL is available', () => {
119
+ it('returns null when sentence-transformers base_url is still the unresolved managed sentinel', () => {
141
120
  const config = {
142
121
  backend: 'sentence-transformers',
143
122
  model: 'all-MiniLM-L6-v2',
@@ -1,5 +1,6 @@
1
1
  import { describe, expect, it } from 'vitest';
2
2
  const scanTypeExportCoverage = {};
3
+ const ingestFinalizationTypeExportCoverage = {};
3
4
  describe('@ktx/context package exports', () => {
4
5
  it('exports package entry points used by host adapters', async () => {
5
6
  const core = await import('./core/index.js');
@@ -31,6 +32,7 @@ describe('@ktx/context package exports', () => {
31
32
  expect(connections.notionConnectionToPullConfig).toBeTypeOf('function');
32
33
  expect(scan).toBeDefined();
33
34
  expect(scanTypeExportCoverage).toEqual({});
35
+ expect(ingestFinalizationTypeExportCoverage).toEqual({});
34
36
  expect(scan.createKtxConnectorCapabilities).toBeTypeOf('function');
35
37
  expect(`liveDatabaseSnapshotToKtx${'SchemaSnapshot'}` in scan).toBe(false);
36
38
  expect(scan.normalizeKtxNativeType).toBeTypeOf('function');
@@ -122,7 +124,6 @@ describe('@ktx/context package exports', () => {
122
124
  expect(root.assertSearchBackendCapabilities).toBeTypeOf('function');
123
125
  expect(root.createLocalKtxEmbeddingProviderFromConfig).toBeTypeOf('function');
124
126
  expect(root.MANAGED_SENTENCE_TRANSFORMERS_BASE_URL).toBe('managed:local-embeddings');
125
- expect(root.MANAGED_SENTENCE_TRANSFORMERS_BASE_URL_ENV).toBe('KTX_MANAGED_SENTENCE_TRANSFORMERS_BASE_URL');
126
127
  expect(agent).toBeDefined();
127
128
  expect(agent.AgentRunnerService).toBeTypeOf('function');
128
129
  expect(root.AgentRunnerService).toBeTypeOf('function');
@@ -231,7 +232,6 @@ describe('@ktx/context package exports', () => {
231
232
  expect(ingest.historicSqlEvidenceEnvelopeSchema).toBeDefined();
232
233
  expect(ingest.historicSqlEvidencePath).toBeTypeOf('function');
233
234
  expect(ingest.createEmitHistoricSqlEvidenceTool).toBeTypeOf('function');
234
- expect(ingest.HistoricSqlProjectionPostProcessor).toBeTypeOf('function');
235
235
  expect(ingest.SqliteContextEvidenceStore).toBeTypeOf('function');
236
236
  expect(ingest.SqliteBundleIngestStore).toBeTypeOf('function');
237
237
  expect(ingest.CuratorPaginationService).toBeTypeOf('function');
@@ -195,27 +195,35 @@ declare const storageSchema: z.ZodObject<{
195
195
  declare const connectionSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
196
196
  driver: z.ZodLiteral<"postgres">;
197
197
  url: z.ZodOptional<z.ZodString>;
198
+ enabled_tables: z.ZodOptional<z.ZodArray<z.ZodString>>;
198
199
  }, z.core.$loose>, z.ZodObject<{
199
200
  driver: z.ZodLiteral<"postgresql">;
200
201
  url: z.ZodOptional<z.ZodString>;
202
+ enabled_tables: z.ZodOptional<z.ZodArray<z.ZodString>>;
201
203
  }, z.core.$loose>, z.ZodObject<{
202
204
  driver: z.ZodLiteral<"mysql">;
203
205
  url: z.ZodOptional<z.ZodString>;
206
+ enabled_tables: z.ZodOptional<z.ZodArray<z.ZodString>>;
204
207
  }, z.core.$loose>, z.ZodObject<{
205
208
  driver: z.ZodLiteral<"snowflake">;
206
209
  url: z.ZodOptional<z.ZodString>;
210
+ enabled_tables: z.ZodOptional<z.ZodArray<z.ZodString>>;
207
211
  }, z.core.$loose>, z.ZodObject<{
208
212
  driver: z.ZodLiteral<"bigquery">;
209
213
  url: z.ZodOptional<z.ZodString>;
214
+ enabled_tables: z.ZodOptional<z.ZodArray<z.ZodString>>;
210
215
  }, z.core.$loose>, z.ZodObject<{
211
216
  driver: z.ZodLiteral<"sqlite">;
212
217
  url: z.ZodOptional<z.ZodString>;
218
+ enabled_tables: z.ZodOptional<z.ZodArray<z.ZodString>>;
213
219
  }, z.core.$loose>, z.ZodObject<{
214
220
  driver: z.ZodLiteral<"clickhouse">;
215
221
  url: z.ZodOptional<z.ZodString>;
222
+ enabled_tables: z.ZodOptional<z.ZodArray<z.ZodString>>;
216
223
  }, z.core.$loose>, z.ZodObject<{
217
224
  driver: z.ZodLiteral<"sqlserver">;
218
225
  url: z.ZodOptional<z.ZodString>;
226
+ enabled_tables: z.ZodOptional<z.ZodArray<z.ZodString>>;
219
227
  }, z.core.$loose>, z.ZodObject<{
220
228
  driver: z.ZodLiteral<"metabase">;
221
229
  api_url: z.ZodString;
@@ -301,27 +309,35 @@ declare const ktxProjectConfigSchema: z.ZodObject<{
301
309
  connections: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodDiscriminatedUnion<[z.ZodObject<{
302
310
  driver: z.ZodLiteral<"postgres">;
303
311
  url: z.ZodOptional<z.ZodString>;
312
+ enabled_tables: z.ZodOptional<z.ZodArray<z.ZodString>>;
304
313
  }, z.core.$loose>, z.ZodObject<{
305
314
  driver: z.ZodLiteral<"postgresql">;
306
315
  url: z.ZodOptional<z.ZodString>;
316
+ enabled_tables: z.ZodOptional<z.ZodArray<z.ZodString>>;
307
317
  }, z.core.$loose>, z.ZodObject<{
308
318
  driver: z.ZodLiteral<"mysql">;
309
319
  url: z.ZodOptional<z.ZodString>;
320
+ enabled_tables: z.ZodOptional<z.ZodArray<z.ZodString>>;
310
321
  }, z.core.$loose>, z.ZodObject<{
311
322
  driver: z.ZodLiteral<"snowflake">;
312
323
  url: z.ZodOptional<z.ZodString>;
324
+ enabled_tables: z.ZodOptional<z.ZodArray<z.ZodString>>;
313
325
  }, z.core.$loose>, z.ZodObject<{
314
326
  driver: z.ZodLiteral<"bigquery">;
315
327
  url: z.ZodOptional<z.ZodString>;
328
+ enabled_tables: z.ZodOptional<z.ZodArray<z.ZodString>>;
316
329
  }, z.core.$loose>, z.ZodObject<{
317
330
  driver: z.ZodLiteral<"sqlite">;
318
331
  url: z.ZodOptional<z.ZodString>;
332
+ enabled_tables: z.ZodOptional<z.ZodArray<z.ZodString>>;
319
333
  }, z.core.$loose>, z.ZodObject<{
320
334
  driver: z.ZodLiteral<"clickhouse">;
321
335
  url: z.ZodOptional<z.ZodString>;
336
+ enabled_tables: z.ZodOptional<z.ZodArray<z.ZodString>>;
322
337
  }, z.core.$loose>, z.ZodObject<{
323
338
  driver: z.ZodLiteral<"sqlserver">;
324
339
  url: z.ZodOptional<z.ZodString>;
340
+ enabled_tables: z.ZodOptional<z.ZodArray<z.ZodString>>;
325
341
  }, z.core.$loose>, z.ZodObject<{
326
342
  driver: z.ZodLiteral<"metabase">;
327
343
  api_url: z.ZodString;
@@ -2,27 +2,35 @@ import * as z from 'zod';
2
2
  export declare const connectionConfigSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
3
3
  driver: z.ZodLiteral<"postgres">;
4
4
  url: z.ZodOptional<z.ZodString>;
5
+ enabled_tables: z.ZodOptional<z.ZodArray<z.ZodString>>;
5
6
  }, z.core.$loose>, z.ZodObject<{
6
7
  driver: z.ZodLiteral<"postgresql">;
7
8
  url: z.ZodOptional<z.ZodString>;
9
+ enabled_tables: z.ZodOptional<z.ZodArray<z.ZodString>>;
8
10
  }, z.core.$loose>, z.ZodObject<{
9
11
  driver: z.ZodLiteral<"mysql">;
10
12
  url: z.ZodOptional<z.ZodString>;
13
+ enabled_tables: z.ZodOptional<z.ZodArray<z.ZodString>>;
11
14
  }, z.core.$loose>, z.ZodObject<{
12
15
  driver: z.ZodLiteral<"snowflake">;
13
16
  url: z.ZodOptional<z.ZodString>;
17
+ enabled_tables: z.ZodOptional<z.ZodArray<z.ZodString>>;
14
18
  }, z.core.$loose>, z.ZodObject<{
15
19
  driver: z.ZodLiteral<"bigquery">;
16
20
  url: z.ZodOptional<z.ZodString>;
21
+ enabled_tables: z.ZodOptional<z.ZodArray<z.ZodString>>;
17
22
  }, z.core.$loose>, z.ZodObject<{
18
23
  driver: z.ZodLiteral<"sqlite">;
19
24
  url: z.ZodOptional<z.ZodString>;
25
+ enabled_tables: z.ZodOptional<z.ZodArray<z.ZodString>>;
20
26
  }, z.core.$loose>, z.ZodObject<{
21
27
  driver: z.ZodLiteral<"clickhouse">;
22
28
  url: z.ZodOptional<z.ZodString>;
29
+ enabled_tables: z.ZodOptional<z.ZodArray<z.ZodString>>;
23
30
  }, z.core.$loose>, z.ZodObject<{
24
31
  driver: z.ZodLiteral<"sqlserver">;
25
32
  url: z.ZodOptional<z.ZodString>;
33
+ enabled_tables: z.ZodOptional<z.ZodArray<z.ZodString>>;
26
34
  }, z.core.$loose>, z.ZodObject<{
27
35
  driver: z.ZodLiteral<"metabase">;
28
36
  api_url: z.ZodString;
@@ -19,6 +19,10 @@ function warehouseConnectionSchema(driver) {
19
19
  .min(1)
20
20
  .optional()
21
21
  .describe('Warehouse connection URL or DSN; may contain environment-variable references like env:DATABASE_URL.'),
22
+ enabled_tables: z
23
+ .array(z.string().min(1))
24
+ .optional()
25
+ .describe('Optional allowlist of fully-qualified table names ("schema.table") to ingest. When set, live-database ingest discards any table whose schema-qualified name is not in this list. Useful for smoke-testing deep ingest on a single table.'),
22
26
  })
23
27
  .describe(`${driver} warehouse connection. Additional driver-tunable fields (e.g. historicSql, context.queryHistory) are accepted and passed through.`);
24
28
  }
@@ -0,0 +1,3 @@
1
+ import type { KtxSchemaSnapshot } from './types.js';
2
+ export declare function resolveEnabledTables(connection: Record<string, unknown> | undefined): Set<string> | null;
3
+ export declare function filterSnapshotTables(snapshot: KtxSchemaSnapshot, enabledTables: Set<string>): KtxSchemaSnapshot;
@@ -0,0 +1,15 @@
1
+ export function resolveEnabledTables(connection) {
2
+ const raw = connection?.enabled_tables;
3
+ if (!Array.isArray(raw) || raw.length === 0)
4
+ return null;
5
+ return new Set(raw.filter((v) => typeof v === 'string'));
6
+ }
7
+ export function filterSnapshotTables(snapshot, enabledTables) {
8
+ return {
9
+ ...snapshot,
10
+ tables: snapshot.tables.filter((table) => {
11
+ const key = table.db ? `${table.db}.${table.name}` : table.name;
12
+ return enabledTables.has(key);
13
+ }),
14
+ };
15
+ }
@@ -4,7 +4,7 @@ import type { KtxProjectLlmConfig, KtxScanEnrichmentConfig } from '../project/co
4
4
  import type { KtxLocalProject } from '../project/index.js';
5
5
  import { type KtxLocalScanEnrichmentProviders } from './local-enrichment.js';
6
6
  import { SqliteLocalScanEnrichmentStateStore } from './sqlite-local-enrichment-state-store.js';
7
- import type { KtxProgressPort, KtxScanConnector, KtxScanMode, KtxScanReport, KtxScanTrigger, KtxSchemaSnapshot } from './types.js';
7
+ import type { KtxProgressPort, KtxScanConnector, KtxScanMode, KtxScanReport, KtxScanTrigger } from './types.js';
8
8
  export interface RunLocalScanOptions {
9
9
  project: KtxLocalProject;
10
10
  connectionId: string;
@@ -60,9 +60,7 @@ interface LocalScanEnrichmentProviderDeps {
60
60
  projectDir?: string;
61
61
  }
62
62
  export declare function createLocalScanEnrichmentProvidersFromConfig(config: KtxScanEnrichmentConfig, llmConfig: KtxProjectLlmConfig, deps?: LocalScanEnrichmentProviderDeps): KtxLocalScanEnrichmentProviders | null;
63
- export declare function resolveEnabledTables(connection: Record<string, unknown> | undefined): Set<string> | null;
64
- export declare function filterSnapshotTables(snapshot: KtxSchemaSnapshot, enabledTables: Set<string>): KtxSchemaSnapshot;
63
+ export { filterSnapshotTables, resolveEnabledTables } from './enabled-tables.js';
65
64
  export declare function runLocalScan(options: RunLocalScanOptions): Promise<LocalScanRunResult>;
66
65
  export declare function getLocalScanReport(project: KtxLocalProject, runId: string): Promise<KtxScanReport | null>;
67
66
  export declare function getLocalScanStatus(project: KtxLocalProject, runId: string): Promise<LocalScanStatusResponse | null>;
68
- export {};
@@ -2,6 +2,7 @@ import { createDefaultLocalIngestAdapters, getLocalStageOnlyIngestStatus, runLoc
2
2
  import { createLocalKtxEmbeddingProviderFromConfig, createLocalKtxLlmRuntimeFromConfig, KtxScanEmbeddingPortAdapter, } from '../llm/index.js';
3
3
  import { ktxLocalStateDbPath } from '../project/local-state-db.js';
4
4
  import { redactKtxScanReport } from './credentials.js';
5
+ import { filterSnapshotTables, resolveEnabledTables } from './enabled-tables.js';
5
6
  import { completedKtxScanEnrichmentStateSummary } from './enrichment-state.js';
6
7
  import { failedKtxScanEnrichmentSummary, ktxScanErrorMessage } from './enrichment-summary.js';
7
8
  import { createDeterministicLocalScanEnrichmentProviders, runLocalScanEnrichment, } from './local-enrichment.js';
@@ -182,21 +183,6 @@ async function readScanReport(project, connectionId, syncId) {
182
183
  return null;
183
184
  }
184
185
  }
185
- export function resolveEnabledTables(connection) {
186
- const raw = connection?.enabled_tables;
187
- if (!Array.isArray(raw) || raw.length === 0)
188
- return null;
189
- return new Set(raw.filter((v) => typeof v === 'string'));
190
- }
191
- export function filterSnapshotTables(snapshot, enabledTables) {
192
- return {
193
- ...snapshot,
194
- tables: snapshot.tables.filter((table) => {
195
- const key = table.db ? `${table.db}.${table.name}` : table.name;
196
- return enabledTables.has(key);
197
- }),
198
- };
199
- }
200
186
  function createFilteredConnector(connector, enabledTables) {
201
187
  return {
202
188
  ...connector,
@@ -206,6 +192,7 @@ function createFilteredConnector(connector, enabledTables) {
206
192
  },
207
193
  };
208
194
  }
195
+ export { filterSnapshotTables, resolveEnabledTables } from './enabled-tables.js';
209
196
  function withInternalLiveDatabaseAdapter(project) {
210
197
  if (project.config.ingest.adapters.includes(LIVE_DATABASE_ADAPTER)) {
211
198
  return project;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kaelio/ktx",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Standalone KTX context layer for database agents",
5
5
  "private": false,
6
6
  "type": "module",
@@ -1,4 +0,0 @@
1
- import type { IngestBundlePostProcessorInput, IngestBundlePostProcessorPort, IngestBundlePostProcessorResult } from '../../ports.js';
2
- export declare class HistoricSqlProjectionPostProcessor implements IngestBundlePostProcessorPort {
3
- run(input: IngestBundlePostProcessorInput): Promise<IngestBundlePostProcessorResult>;
4
- }