2026-05-12 13:00:08 +02:00
|
|
|
import { execFile, spawn } from 'node:child_process';
|
2026-05-14 14:35:55 +02:00
|
|
|
import { mkdir, open, readFile, rm, writeFile } from 'node:fs/promises';
|
2026-05-11 15:50:34 +02:00
|
|
|
import { createServer } from 'node:net';
|
|
|
|
|
import { setTimeout as delay } from 'node:timers/promises';
|
2026-05-12 13:00:08 +02:00
|
|
|
import { promisify } from 'node:util';
|
2026-05-11 15:50:34 +02:00
|
|
|
import { z } from 'zod';
|
test: split cli tests from source tree (#216)
* feat(cli): define full warehouse dialect contract
* test(cli): keep dialect edge tests focused
* fix(cli): stabilize dialect contract foundation
* refactor(connectors): own read-only query preparation
* refactor(connectors): resolve dialects through registry
* refactor(connectors): keep concrete dialect classes internal
* chore(workspace): enforce dialect import boundary
* refactor(cli): resolve relationship dialect at scan boundary
* refactor(cli): use dialect display parsing for entity details
* refactor(cli): use dialect display parsing for warehouse catalog
* refactor(cli): use dialect SQL in relationship workflows
* test(cli): verify solid dialect scan workflow closure
* test: split cli tests from source tree
* refactor(cli): standardize BigQuery scope listing
* feat(sqlite): implement connector scope listing
* test(connectors): cover required table listing
* feat(cli): add warehouse driver registry
* refactor(setup): route scope discovery through driver registry
* refactor(cli): route local query execution through driver registry
* refactor(historic-sql): route dialect support through driver registry
* refactor(cli): test warehouse connections through driver registry
* fix(cli): close driver registry type export gaps
* Improve setup daemon diagnostics
* refactor(setup): centralize rail-prefixed diagnostics + query-history fallback
Extract errorMessage, writePrefixedLines, and flushPrefixedBufferedCommandOutput
into clack.ts so the setup wizard, managed daemons, and embedding/agent steps
share one rail-formatted writer. setup-databases.ts also adds a
"disable query history and retry" option when the schema-context build fails
and query history is the likely culprit, surfaced via a new
failed-query-history-unavailable status.
* fix(cli): carry catalog through the picker so BigQuery/Snowflake/SQL Server scope filters match
The setup picker's KtxTableListEntry was a 2-level { schema, name }, so
qualifiedTableId always wrote db.name into enabled_tables. When BigQuery,
Snowflake, or SQL Server later ran fast ingest, their introspect step filtered
the scope set with scopedTableNames(scope, { catalog: projectId|database, db })
— catalog was non-null on the introspect side but null in the scope refs, so
every entry was rejected, the live-database adapter staged zero table files,
and detect() failed with 'Adapter "live-database" did not recognize fetched
source output'.
Align the picker boundary with the canonical 3-level KtxTableRef:
- Add catalog: string | null to KtxTableListEntry.
- BigQuery/Snowflake/SQL Server listTables populate catalog from the
resolved projectId / database; Postgres/MySQL/ClickHouse/SQLite set null.
- qualifiedTableId emits catalog.schema.name when catalog is non-null
(resolveEnabledTables already accepts the 3-part shape) and
schemasFromEnabledTables now goes through parseDottedTableEntry so it
recovers the schema correctly from both 2-part and 3-part entries.
- Export parseDottedTableEntry from enabled-tables.ts (@internal) for picker
reuse.
Update listTables expectations in all seven connector tests and the setup /
picker test fixtures. Add a picker regression test that covers the
catalog-bearing round-trip (save + refine).
* fix(cli): allow debug telemetry under opt-out env
2026-05-26 08:49:05 +02:00
|
|
|
import { describeError } from './error-message.js';
|
2026-05-11 15:50:34 +02:00
|
|
|
import {
|
|
|
|
|
installManagedPythonRuntime,
|
2026-05-14 14:35:55 +02:00
|
|
|
managedPythonDaemonLayout,
|
2026-05-11 15:50:34 +02:00
|
|
|
runtimeFeatureSchema,
|
|
|
|
|
type KtxRuntimeFeature,
|
2026-05-14 14:35:55 +02:00
|
|
|
type ManagedPythonDaemonLayout,
|
|
|
|
|
type ManagedPythonDaemonLayoutOptions,
|
2026-05-11 15:50:34 +02:00
|
|
|
type ManagedPythonRuntimeInstallOptions,
|
|
|
|
|
type ManagedPythonRuntimeInstallResult,
|
|
|
|
|
} from './managed-python-runtime.js';
|
2026-05-19 18:18:56 +02:00
|
|
|
import { sanitizeChildProxyEnv } from './proxy-env.js';
|
2026-05-11 15:50:34 +02:00
|
|
|
|
test: split cli tests from source tree (#216)
* feat(cli): define full warehouse dialect contract
* test(cli): keep dialect edge tests focused
* fix(cli): stabilize dialect contract foundation
* refactor(connectors): own read-only query preparation
* refactor(connectors): resolve dialects through registry
* refactor(connectors): keep concrete dialect classes internal
* chore(workspace): enforce dialect import boundary
* refactor(cli): resolve relationship dialect at scan boundary
* refactor(cli): use dialect display parsing for entity details
* refactor(cli): use dialect display parsing for warehouse catalog
* refactor(cli): use dialect SQL in relationship workflows
* test(cli): verify solid dialect scan workflow closure
* test: split cli tests from source tree
* refactor(cli): standardize BigQuery scope listing
* feat(sqlite): implement connector scope listing
* test(connectors): cover required table listing
* feat(cli): add warehouse driver registry
* refactor(setup): route scope discovery through driver registry
* refactor(cli): route local query execution through driver registry
* refactor(historic-sql): route dialect support through driver registry
* refactor(cli): test warehouse connections through driver registry
* fix(cli): close driver registry type export gaps
* Improve setup daemon diagnostics
* refactor(setup): centralize rail-prefixed diagnostics + query-history fallback
Extract errorMessage, writePrefixedLines, and flushPrefixedBufferedCommandOutput
into clack.ts so the setup wizard, managed daemons, and embedding/agent steps
share one rail-formatted writer. setup-databases.ts also adds a
"disable query history and retry" option when the schema-context build fails
and query history is the likely culprit, surfaced via a new
failed-query-history-unavailable status.
* fix(cli): carry catalog through the picker so BigQuery/Snowflake/SQL Server scope filters match
The setup picker's KtxTableListEntry was a 2-level { schema, name }, so
qualifiedTableId always wrote db.name into enabled_tables. When BigQuery,
Snowflake, or SQL Server later ran fast ingest, their introspect step filtered
the scope set with scopedTableNames(scope, { catalog: projectId|database, db })
— catalog was non-null on the introspect side but null in the scope refs, so
every entry was rejected, the live-database adapter staged zero table files,
and detect() failed with 'Adapter "live-database" did not recognize fetched
source output'.
Align the picker boundary with the canonical 3-level KtxTableRef:
- Add catalog: string | null to KtxTableListEntry.
- BigQuery/Snowflake/SQL Server listTables populate catalog from the
resolved projectId / database; Postgres/MySQL/ClickHouse/SQLite set null.
- qualifiedTableId emits catalog.schema.name when catalog is non-null
(resolveEnabledTables already accepts the 3-part shape) and
schemasFromEnabledTables now goes through parseDottedTableEntry so it
recovers the schema correctly from both 2-part and 3-part entries.
- Export parseDottedTableEntry from enabled-tables.ts (@internal) for picker
reuse.
Update listTables expectations in all seven connector tests and the setup /
picker test fixtures. Add a picker regression test that covers the
catalog-bearing round-trip (save + refine).
* fix(cli): allow debug telemetry under opt-out env
2026-05-26 08:49:05 +02:00
|
|
|
export class ManagedPythonDaemonStartError extends Error {
|
|
|
|
|
readonly detail: string;
|
|
|
|
|
readonly stderrLog: string;
|
|
|
|
|
constructor(detail: string, stderrLog: string) {
|
|
|
|
|
super(`KTX daemon failed to start: ${detail}. stderr: ${stderrLog}`);
|
|
|
|
|
this.name = 'ManagedPythonDaemonStartError';
|
|
|
|
|
this.detail = detail;
|
|
|
|
|
this.stderrLog = stderrLog;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-11 15:50:34 +02:00
|
|
|
export interface ManagedPythonDaemonState {
|
|
|
|
|
schemaVersion: 1;
|
|
|
|
|
pid: number;
|
|
|
|
|
host: '127.0.0.1';
|
|
|
|
|
port: number;
|
|
|
|
|
version: string;
|
|
|
|
|
features: KtxRuntimeFeature[];
|
|
|
|
|
startedAt: string;
|
|
|
|
|
stdoutLog: string;
|
|
|
|
|
stderrLog: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export type ManagedPythonDaemonStatus =
|
2026-05-14 14:35:55 +02:00
|
|
|
| { kind: 'stopped'; detail: string; layout: ManagedPythonDaemonLayout }
|
|
|
|
|
| { kind: 'running'; detail: string; layout: ManagedPythonDaemonLayout; state: ManagedPythonDaemonState; baseUrl: string }
|
|
|
|
|
| { kind: 'stale'; detail: string; layout: ManagedPythonDaemonLayout; state?: ManagedPythonDaemonState };
|
2026-05-11 15:50:34 +02:00
|
|
|
|
|
|
|
|
export interface ManagedPythonDaemonStartResult {
|
|
|
|
|
status: 'started' | 'reused';
|
2026-05-14 14:35:55 +02:00
|
|
|
layout: ManagedPythonDaemonLayout;
|
2026-05-11 15:50:34 +02:00
|
|
|
state: ManagedPythonDaemonState;
|
|
|
|
|
baseUrl: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface ManagedPythonDaemonStopResult {
|
|
|
|
|
status: 'stopped' | 'already-stopped';
|
2026-05-14 14:35:55 +02:00
|
|
|
layout: ManagedPythonDaemonLayout;
|
2026-05-11 15:50:34 +02:00
|
|
|
state?: ManagedPythonDaemonState;
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-12 13:00:08 +02:00
|
|
|
export interface ManagedPythonDaemonProcessInfo {
|
|
|
|
|
pid: number;
|
|
|
|
|
command: string;
|
|
|
|
|
}
|
|
|
|
|
|
chore(workspace): gate dead-code with knip production mode (#196)
* refactor(workspace): relocate @ktx/llm source into packages/cli/src/llm
* refactor(workspace): rewrite @ktx/llm imports to relative paths
* refactor(workspace): fold internal packages into cli
* chore(workspace): gate dead-code with knip production mode
Turn on production-mode knip plus an autofix run in pre-commit and the
`pnpm dead-code` script, document the `/** @internal */` convention for
test-only exports in AGENTS.md, annotate test-only exports across the
CLI with that JSDoc, and drop dead exports/wrappers the new gate
surfaced (e.g. `cli-project.ts`, `lookerRuntimeSourceToFileAdapterSource`,
`createLocalScanEnrichmentProvidersFromConfig`,
`PGLITE_OWNER_PROCESS_BACKEND_CAPABILITIES`, stale type re-exports).
Replace the loose `ignoreIssues` allowlist in `knip.json` with explicit
production entries so cross-package barrel leaks are caught.
* refactor(cli): delete internal barrel index.ts files
The 34 `index.ts` re-export barrels inside `packages/cli/src/` were
holdovers from the pre-fold multi-workspace structure. Post-fold-in they
served no production purpose: external consumers go through the single
package main entry, and in-repo callers mostly imported through them
only because the path was short. Internally, knip flagged most barrel
re-exports as production-dead (only reached via tests).
This change:
- Deletes every internal barrel except `packages/cli/src/index.ts`
(the published package entry).
- Rewrites ~270 source/test files to import each name directly from
the file that defines it.
- Moves `tools/warehouse-verification/index.ts` to
`create-warehouse-verification-tools.ts` (the function it defined
locally) and updates its single consumer.
- Renames `search/backend-conformance.ts` → `.test-utils.ts` to match
the existing test-helper file convention.
- Deletes 13 dead test-only chains (dbt-descriptions/*,
live-database/extracted-schema, live-database/structural-sync,
relationship-* feedback/review chain) plus their tests and a
cascading orphan integration test.
- Updates test mocks that pointed at deleted barrel paths
(notion-client, connector barrels in scan/local-scan-connectors
tests) to mock the source files instead.
- Points the maintainer benchmark script
(`scripts/relationship-benchmark-report.mjs`) at source files
instead of `dist/context/scan/index.js`.
- Drops the barrel `!` entries from `knip.json`; adds explicit
production entries only for the benchmark code reached via dist by
the maintainer script.
Net: 413 files changed, ~1.2k insertions, ~9.4k deletions.
`pnpm run dead-code` (Biome + knip default + knip production) and
`pnpm run type-check` are clean; 2277 tests pass.
* refactor(workspace): rename @ktx/cli to @kaelio/ktx and pack it directly
Promote the CLI workspace package to the public name `@kaelio/ktx` and
drop the separate `scripts/build-public-npm-package.mjs` wrapper. The
CLI package is now publishable in place (`publishConfig.access: public`,
`provenance: true`), so artifact packing uses `pnpm pack` against
`packages/cli/` instead of assembling a parallel package tree.
Updates all workspace filter invocations, docs, tests, and release
readiness checks to reference the new package name, and folds the
tarball-name helper into `scripts/public-npm-release-metadata.mjs`.
* docs: align "agent clients" and "data agents" terminology
Replace "client agents" with "agent clients" and "database agents" with
"data agents" across AGENTS.md, README.md, the docs-site copy, and the
matching setup-agents test description, matching the canonical
vocabulary in docs/terminology.md.
Also moves packages/cli/tsconfig.json's tsBuildInfoFile from
node_modules/.cache/ to dist/.tsbuildinfo so incremental builds survive
node_modules reinstalls.
* refactor(release): single source of truth for package version
Make packages/cli/package.json the single source of truth for the
@kaelio/ktx version. publicNpmPackageVersion() now reads it directly,
so artifact filenames, release-readiness checks, and the Python wheel
version all derive from one field. The duplicate
release-policy.json.publicNpmPackageVersion is removed.
Previously the two fields could drift: tarballs were named
kaelio-ktx-0.4.1.tgz while internally containing
@kaelio/ktx@0.0.0-private.
- update-public-release-version.mjs rewrites both Python pyproject.toml
files (ktx-daemon, ktx-sl) alongside the npm package.jsons,
normalizing the version for PEP 440 (e.g. 0.1.0-rc.2 -> 0.1.0rc2).
- semantic-release-config.cjs adds the two pyproject.toml files to
@semantic-release/git assets so the release commit back to main
carries every version source in lockstep.
- The six "?? '0.0.0-private'" fallback literals across the CLI are
replaced with "?? getKtxCliPackageInfo().version", and
createDefaultKtxMcpServer makes its version arg required.
- docs/release.md describes the actual commit-back model: the dev tree
always reflects the most recent release; no sentinel pin to
maintain.
Verified: pnpm run artifacts:build now produces
kaelio-ktx-0.4.1.tgz and kaelio_ktx-0.4.1-py3-none-any.whl with
@kaelio/ktx@0.4.1 inside. Full type-check, dead-code, and
2287 vitests + 173 script tests pass.
* refactor(cli): inject embedding provider resolution and detect sentence-transformers runtime
Make resolveProjectEmbeddingProvider and runtimeIo injectable in ingest and
scan command entrypoints so tests can stub them, and teach
resolvePublicIngestRuntimeRequirements to flag the local-embeddings runtime
feature when ktx.yaml selects sentence-transformers.
* chore(cli): mark buildLocalStatsStatus and LocalStatsStatus as @internal
Both symbols are consumed only by status-project.test.ts. Annotating with
/** @internal */ keeps knip's production-mode check clean without changing
runtime behavior.
* fix(cli): use real package metadata in print-command-tree
The stubbed package name embedded a forbidden product identifier that
tripped the boundary check in CI. Read the metadata from package.json
instead — keeps the rendered tree unchanged and removes a duplicate
source of truth.
* feat(cli): show embedding coverage in `ktx status`, drop duplicate disk counts
Inline `(N embedded)` next to the Wiki scope counts and Semantic-layer
source counts, computed with `SUM(embedding_json IS NOT NULL)` over
`knowledge_pages` and `local_sl_sources`. Rename the "Knowledge" label to
"Wiki" (canonical per `docs/terminology.md`) and rename the matching
`localStats.knowledgePages` field to `localStats.wikiPages`.
Drop `wiki=N md` and `semantic-layer=N yaml` from the Disk row — those
duplicated the per-surface rows above. Disk now reports only actual byte
usage (db, cache, raw-sources). The unused `wikiGlobalMarkdownCount` /
`semanticLayerYamlCount` fields, the `isMarkdownEntry` / `isYamlEntry`
helpers, and the `filter` arg on `summarizeDir` are removed.
2026-05-21 15:28:58 +02:00
|
|
|
type ManagedPythonDaemonStopAllSource = 'state' | 'process';
|
2026-05-12 13:00:08 +02:00
|
|
|
|
|
|
|
|
export interface ManagedPythonDaemonStopAllEntry {
|
|
|
|
|
pid: number;
|
|
|
|
|
source: ManagedPythonDaemonStopAllSource;
|
|
|
|
|
url?: string;
|
|
|
|
|
health?: 'healthy' | 'unreachable';
|
|
|
|
|
version?: string;
|
|
|
|
|
command?: string;
|
|
|
|
|
statePaths: string[];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface ManagedPythonDaemonStopAllFailure extends ManagedPythonDaemonStopAllEntry {
|
|
|
|
|
detail: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface ManagedPythonDaemonStopAllResult {
|
|
|
|
|
stopped: ManagedPythonDaemonStopAllEntry[];
|
|
|
|
|
stale: ManagedPythonDaemonStopAllEntry[];
|
|
|
|
|
failed: ManagedPythonDaemonStopAllFailure[];
|
|
|
|
|
scanErrors: string[];
|
|
|
|
|
}
|
|
|
|
|
|
chore(workspace): gate dead-code with knip production mode (#196)
* refactor(workspace): relocate @ktx/llm source into packages/cli/src/llm
* refactor(workspace): rewrite @ktx/llm imports to relative paths
* refactor(workspace): fold internal packages into cli
* chore(workspace): gate dead-code with knip production mode
Turn on production-mode knip plus an autofix run in pre-commit and the
`pnpm dead-code` script, document the `/** @internal */` convention for
test-only exports in AGENTS.md, annotate test-only exports across the
CLI with that JSDoc, and drop dead exports/wrappers the new gate
surfaced (e.g. `cli-project.ts`, `lookerRuntimeSourceToFileAdapterSource`,
`createLocalScanEnrichmentProvidersFromConfig`,
`PGLITE_OWNER_PROCESS_BACKEND_CAPABILITIES`, stale type re-exports).
Replace the loose `ignoreIssues` allowlist in `knip.json` with explicit
production entries so cross-package barrel leaks are caught.
* refactor(cli): delete internal barrel index.ts files
The 34 `index.ts` re-export barrels inside `packages/cli/src/` were
holdovers from the pre-fold multi-workspace structure. Post-fold-in they
served no production purpose: external consumers go through the single
package main entry, and in-repo callers mostly imported through them
only because the path was short. Internally, knip flagged most barrel
re-exports as production-dead (only reached via tests).
This change:
- Deletes every internal barrel except `packages/cli/src/index.ts`
(the published package entry).
- Rewrites ~270 source/test files to import each name directly from
the file that defines it.
- Moves `tools/warehouse-verification/index.ts` to
`create-warehouse-verification-tools.ts` (the function it defined
locally) and updates its single consumer.
- Renames `search/backend-conformance.ts` → `.test-utils.ts` to match
the existing test-helper file convention.
- Deletes 13 dead test-only chains (dbt-descriptions/*,
live-database/extracted-schema, live-database/structural-sync,
relationship-* feedback/review chain) plus their tests and a
cascading orphan integration test.
- Updates test mocks that pointed at deleted barrel paths
(notion-client, connector barrels in scan/local-scan-connectors
tests) to mock the source files instead.
- Points the maintainer benchmark script
(`scripts/relationship-benchmark-report.mjs`) at source files
instead of `dist/context/scan/index.js`.
- Drops the barrel `!` entries from `knip.json`; adds explicit
production entries only for the benchmark code reached via dist by
the maintainer script.
Net: 413 files changed, ~1.2k insertions, ~9.4k deletions.
`pnpm run dead-code` (Biome + knip default + knip production) and
`pnpm run type-check` are clean; 2277 tests pass.
* refactor(workspace): rename @ktx/cli to @kaelio/ktx and pack it directly
Promote the CLI workspace package to the public name `@kaelio/ktx` and
drop the separate `scripts/build-public-npm-package.mjs` wrapper. The
CLI package is now publishable in place (`publishConfig.access: public`,
`provenance: true`), so artifact packing uses `pnpm pack` against
`packages/cli/` instead of assembling a parallel package tree.
Updates all workspace filter invocations, docs, tests, and release
readiness checks to reference the new package name, and folds the
tarball-name helper into `scripts/public-npm-release-metadata.mjs`.
* docs: align "agent clients" and "data agents" terminology
Replace "client agents" with "agent clients" and "database agents" with
"data agents" across AGENTS.md, README.md, the docs-site copy, and the
matching setup-agents test description, matching the canonical
vocabulary in docs/terminology.md.
Also moves packages/cli/tsconfig.json's tsBuildInfoFile from
node_modules/.cache/ to dist/.tsbuildinfo so incremental builds survive
node_modules reinstalls.
* refactor(release): single source of truth for package version
Make packages/cli/package.json the single source of truth for the
@kaelio/ktx version. publicNpmPackageVersion() now reads it directly,
so artifact filenames, release-readiness checks, and the Python wheel
version all derive from one field. The duplicate
release-policy.json.publicNpmPackageVersion is removed.
Previously the two fields could drift: tarballs were named
kaelio-ktx-0.4.1.tgz while internally containing
@kaelio/ktx@0.0.0-private.
- update-public-release-version.mjs rewrites both Python pyproject.toml
files (ktx-daemon, ktx-sl) alongside the npm package.jsons,
normalizing the version for PEP 440 (e.g. 0.1.0-rc.2 -> 0.1.0rc2).
- semantic-release-config.cjs adds the two pyproject.toml files to
@semantic-release/git assets so the release commit back to main
carries every version source in lockstep.
- The six "?? '0.0.0-private'" fallback literals across the CLI are
replaced with "?? getKtxCliPackageInfo().version", and
createDefaultKtxMcpServer makes its version arg required.
- docs/release.md describes the actual commit-back model: the dev tree
always reflects the most recent release; no sentinel pin to
maintain.
Verified: pnpm run artifacts:build now produces
kaelio-ktx-0.4.1.tgz and kaelio_ktx-0.4.1-py3-none-any.whl with
@kaelio/ktx@0.4.1 inside. Full type-check, dead-code, and
2287 vitests + 173 script tests pass.
* refactor(cli): inject embedding provider resolution and detect sentence-transformers runtime
Make resolveProjectEmbeddingProvider and runtimeIo injectable in ingest and
scan command entrypoints so tests can stub them, and teach
resolvePublicIngestRuntimeRequirements to flag the local-embeddings runtime
feature when ktx.yaml selects sentence-transformers.
* chore(cli): mark buildLocalStatsStatus and LocalStatsStatus as @internal
Both symbols are consumed only by status-project.test.ts. Annotating with
/** @internal */ keeps knip's production-mode check clean without changing
runtime behavior.
* fix(cli): use real package metadata in print-command-tree
The stubbed package name embedded a forbidden product identifier that
tripped the boundary check in CI. Read the metadata from package.json
instead — keeps the rendered tree unchanged and removes a duplicate
source of truth.
* feat(cli): show embedding coverage in `ktx status`, drop duplicate disk counts
Inline `(N embedded)` next to the Wiki scope counts and Semantic-layer
source counts, computed with `SUM(embedding_json IS NOT NULL)` over
`knowledge_pages` and `local_sl_sources`. Rename the "Knowledge" label to
"Wiki" (canonical per `docs/terminology.md`) and rename the matching
`localStats.knowledgePages` field to `localStats.wikiPages`.
Drop `wiki=N md` and `semantic-layer=N yaml` from the Disk row — those
duplicated the per-surface rows above. Disk now reports only actual byte
usage (db, cache, raw-sources). The unused `wikiGlobalMarkdownCount` /
`semanticLayerYamlCount` fields, the `isMarkdownEntry` / `isYamlEntry`
helpers, and the `filter` arg on `summarizeDir` are removed.
2026-05-21 15:28:58 +02:00
|
|
|
/** @internal */
|
2026-05-11 15:50:34 +02:00
|
|
|
export interface ManagedPythonDaemonChild {
|
|
|
|
|
pid?: number;
|
|
|
|
|
unref(): void;
|
|
|
|
|
}
|
|
|
|
|
|
chore(workspace): gate dead-code with knip production mode (#196)
* refactor(workspace): relocate @ktx/llm source into packages/cli/src/llm
* refactor(workspace): rewrite @ktx/llm imports to relative paths
* refactor(workspace): fold internal packages into cli
* chore(workspace): gate dead-code with knip production mode
Turn on production-mode knip plus an autofix run in pre-commit and the
`pnpm dead-code` script, document the `/** @internal */` convention for
test-only exports in AGENTS.md, annotate test-only exports across the
CLI with that JSDoc, and drop dead exports/wrappers the new gate
surfaced (e.g. `cli-project.ts`, `lookerRuntimeSourceToFileAdapterSource`,
`createLocalScanEnrichmentProvidersFromConfig`,
`PGLITE_OWNER_PROCESS_BACKEND_CAPABILITIES`, stale type re-exports).
Replace the loose `ignoreIssues` allowlist in `knip.json` with explicit
production entries so cross-package barrel leaks are caught.
* refactor(cli): delete internal barrel index.ts files
The 34 `index.ts` re-export barrels inside `packages/cli/src/` were
holdovers from the pre-fold multi-workspace structure. Post-fold-in they
served no production purpose: external consumers go through the single
package main entry, and in-repo callers mostly imported through them
only because the path was short. Internally, knip flagged most barrel
re-exports as production-dead (only reached via tests).
This change:
- Deletes every internal barrel except `packages/cli/src/index.ts`
(the published package entry).
- Rewrites ~270 source/test files to import each name directly from
the file that defines it.
- Moves `tools/warehouse-verification/index.ts` to
`create-warehouse-verification-tools.ts` (the function it defined
locally) and updates its single consumer.
- Renames `search/backend-conformance.ts` → `.test-utils.ts` to match
the existing test-helper file convention.
- Deletes 13 dead test-only chains (dbt-descriptions/*,
live-database/extracted-schema, live-database/structural-sync,
relationship-* feedback/review chain) plus their tests and a
cascading orphan integration test.
- Updates test mocks that pointed at deleted barrel paths
(notion-client, connector barrels in scan/local-scan-connectors
tests) to mock the source files instead.
- Points the maintainer benchmark script
(`scripts/relationship-benchmark-report.mjs`) at source files
instead of `dist/context/scan/index.js`.
- Drops the barrel `!` entries from `knip.json`; adds explicit
production entries only for the benchmark code reached via dist by
the maintainer script.
Net: 413 files changed, ~1.2k insertions, ~9.4k deletions.
`pnpm run dead-code` (Biome + knip default + knip production) and
`pnpm run type-check` are clean; 2277 tests pass.
* refactor(workspace): rename @ktx/cli to @kaelio/ktx and pack it directly
Promote the CLI workspace package to the public name `@kaelio/ktx` and
drop the separate `scripts/build-public-npm-package.mjs` wrapper. The
CLI package is now publishable in place (`publishConfig.access: public`,
`provenance: true`), so artifact packing uses `pnpm pack` against
`packages/cli/` instead of assembling a parallel package tree.
Updates all workspace filter invocations, docs, tests, and release
readiness checks to reference the new package name, and folds the
tarball-name helper into `scripts/public-npm-release-metadata.mjs`.
* docs: align "agent clients" and "data agents" terminology
Replace "client agents" with "agent clients" and "database agents" with
"data agents" across AGENTS.md, README.md, the docs-site copy, and the
matching setup-agents test description, matching the canonical
vocabulary in docs/terminology.md.
Also moves packages/cli/tsconfig.json's tsBuildInfoFile from
node_modules/.cache/ to dist/.tsbuildinfo so incremental builds survive
node_modules reinstalls.
* refactor(release): single source of truth for package version
Make packages/cli/package.json the single source of truth for the
@kaelio/ktx version. publicNpmPackageVersion() now reads it directly,
so artifact filenames, release-readiness checks, and the Python wheel
version all derive from one field. The duplicate
release-policy.json.publicNpmPackageVersion is removed.
Previously the two fields could drift: tarballs were named
kaelio-ktx-0.4.1.tgz while internally containing
@kaelio/ktx@0.0.0-private.
- update-public-release-version.mjs rewrites both Python pyproject.toml
files (ktx-daemon, ktx-sl) alongside the npm package.jsons,
normalizing the version for PEP 440 (e.g. 0.1.0-rc.2 -> 0.1.0rc2).
- semantic-release-config.cjs adds the two pyproject.toml files to
@semantic-release/git assets so the release commit back to main
carries every version source in lockstep.
- The six "?? '0.0.0-private'" fallback literals across the CLI are
replaced with "?? getKtxCliPackageInfo().version", and
createDefaultKtxMcpServer makes its version arg required.
- docs/release.md describes the actual commit-back model: the dev tree
always reflects the most recent release; no sentinel pin to
maintain.
Verified: pnpm run artifacts:build now produces
kaelio-ktx-0.4.1.tgz and kaelio_ktx-0.4.1-py3-none-any.whl with
@kaelio/ktx@0.4.1 inside. Full type-check, dead-code, and
2287 vitests + 173 script tests pass.
* refactor(cli): inject embedding provider resolution and detect sentence-transformers runtime
Make resolveProjectEmbeddingProvider and runtimeIo injectable in ingest and
scan command entrypoints so tests can stub them, and teach
resolvePublicIngestRuntimeRequirements to flag the local-embeddings runtime
feature when ktx.yaml selects sentence-transformers.
* chore(cli): mark buildLocalStatsStatus and LocalStatsStatus as @internal
Both symbols are consumed only by status-project.test.ts. Annotating with
/** @internal */ keeps knip's production-mode check clean without changing
runtime behavior.
* fix(cli): use real package metadata in print-command-tree
The stubbed package name embedded a forbidden product identifier that
tripped the boundary check in CI. Read the metadata from package.json
instead — keeps the rendered tree unchanged and removes a duplicate
source of truth.
* feat(cli): show embedding coverage in `ktx status`, drop duplicate disk counts
Inline `(N embedded)` next to the Wiki scope counts and Semantic-layer
source counts, computed with `SUM(embedding_json IS NOT NULL)` over
`knowledge_pages` and `local_sl_sources`. Rename the "Knowledge" label to
"Wiki" (canonical per `docs/terminology.md`) and rename the matching
`localStats.knowledgePages` field to `localStats.wikiPages`.
Drop `wiki=N md` and `semantic-layer=N yaml` from the Disk row — those
duplicated the per-surface rows above. Disk now reports only actual byte
usage (db, cache, raw-sources). The unused `wikiGlobalMarkdownCount` /
`semanticLayerYamlCount` fields, the `isMarkdownEntry` / `isYamlEntry`
helpers, and the `filter` arg on `summarizeDir` are removed.
2026-05-21 15:28:58 +02:00
|
|
|
/** @internal */
|
2026-05-11 15:50:34 +02:00
|
|
|
export type ManagedPythonDaemonSpawn = (
|
|
|
|
|
command: string,
|
|
|
|
|
args: string[],
|
|
|
|
|
options: {
|
|
|
|
|
detached: boolean;
|
|
|
|
|
stdio: ['ignore', number, number];
|
|
|
|
|
env: NodeJS.ProcessEnv;
|
|
|
|
|
},
|
|
|
|
|
) => ManagedPythonDaemonChild;
|
|
|
|
|
|
chore(workspace): gate dead-code with knip production mode (#196)
* refactor(workspace): relocate @ktx/llm source into packages/cli/src/llm
* refactor(workspace): rewrite @ktx/llm imports to relative paths
* refactor(workspace): fold internal packages into cli
* chore(workspace): gate dead-code with knip production mode
Turn on production-mode knip plus an autofix run in pre-commit and the
`pnpm dead-code` script, document the `/** @internal */` convention for
test-only exports in AGENTS.md, annotate test-only exports across the
CLI with that JSDoc, and drop dead exports/wrappers the new gate
surfaced (e.g. `cli-project.ts`, `lookerRuntimeSourceToFileAdapterSource`,
`createLocalScanEnrichmentProvidersFromConfig`,
`PGLITE_OWNER_PROCESS_BACKEND_CAPABILITIES`, stale type re-exports).
Replace the loose `ignoreIssues` allowlist in `knip.json` with explicit
production entries so cross-package barrel leaks are caught.
* refactor(cli): delete internal barrel index.ts files
The 34 `index.ts` re-export barrels inside `packages/cli/src/` were
holdovers from the pre-fold multi-workspace structure. Post-fold-in they
served no production purpose: external consumers go through the single
package main entry, and in-repo callers mostly imported through them
only because the path was short. Internally, knip flagged most barrel
re-exports as production-dead (only reached via tests).
This change:
- Deletes every internal barrel except `packages/cli/src/index.ts`
(the published package entry).
- Rewrites ~270 source/test files to import each name directly from
the file that defines it.
- Moves `tools/warehouse-verification/index.ts` to
`create-warehouse-verification-tools.ts` (the function it defined
locally) and updates its single consumer.
- Renames `search/backend-conformance.ts` → `.test-utils.ts` to match
the existing test-helper file convention.
- Deletes 13 dead test-only chains (dbt-descriptions/*,
live-database/extracted-schema, live-database/structural-sync,
relationship-* feedback/review chain) plus their tests and a
cascading orphan integration test.
- Updates test mocks that pointed at deleted barrel paths
(notion-client, connector barrels in scan/local-scan-connectors
tests) to mock the source files instead.
- Points the maintainer benchmark script
(`scripts/relationship-benchmark-report.mjs`) at source files
instead of `dist/context/scan/index.js`.
- Drops the barrel `!` entries from `knip.json`; adds explicit
production entries only for the benchmark code reached via dist by
the maintainer script.
Net: 413 files changed, ~1.2k insertions, ~9.4k deletions.
`pnpm run dead-code` (Biome + knip default + knip production) and
`pnpm run type-check` are clean; 2277 tests pass.
* refactor(workspace): rename @ktx/cli to @kaelio/ktx and pack it directly
Promote the CLI workspace package to the public name `@kaelio/ktx` and
drop the separate `scripts/build-public-npm-package.mjs` wrapper. The
CLI package is now publishable in place (`publishConfig.access: public`,
`provenance: true`), so artifact packing uses `pnpm pack` against
`packages/cli/` instead of assembling a parallel package tree.
Updates all workspace filter invocations, docs, tests, and release
readiness checks to reference the new package name, and folds the
tarball-name helper into `scripts/public-npm-release-metadata.mjs`.
* docs: align "agent clients" and "data agents" terminology
Replace "client agents" with "agent clients" and "database agents" with
"data agents" across AGENTS.md, README.md, the docs-site copy, and the
matching setup-agents test description, matching the canonical
vocabulary in docs/terminology.md.
Also moves packages/cli/tsconfig.json's tsBuildInfoFile from
node_modules/.cache/ to dist/.tsbuildinfo so incremental builds survive
node_modules reinstalls.
* refactor(release): single source of truth for package version
Make packages/cli/package.json the single source of truth for the
@kaelio/ktx version. publicNpmPackageVersion() now reads it directly,
so artifact filenames, release-readiness checks, and the Python wheel
version all derive from one field. The duplicate
release-policy.json.publicNpmPackageVersion is removed.
Previously the two fields could drift: tarballs were named
kaelio-ktx-0.4.1.tgz while internally containing
@kaelio/ktx@0.0.0-private.
- update-public-release-version.mjs rewrites both Python pyproject.toml
files (ktx-daemon, ktx-sl) alongside the npm package.jsons,
normalizing the version for PEP 440 (e.g. 0.1.0-rc.2 -> 0.1.0rc2).
- semantic-release-config.cjs adds the two pyproject.toml files to
@semantic-release/git assets so the release commit back to main
carries every version source in lockstep.
- The six "?? '0.0.0-private'" fallback literals across the CLI are
replaced with "?? getKtxCliPackageInfo().version", and
createDefaultKtxMcpServer makes its version arg required.
- docs/release.md describes the actual commit-back model: the dev tree
always reflects the most recent release; no sentinel pin to
maintain.
Verified: pnpm run artifacts:build now produces
kaelio-ktx-0.4.1.tgz and kaelio_ktx-0.4.1-py3-none-any.whl with
@kaelio/ktx@0.4.1 inside. Full type-check, dead-code, and
2287 vitests + 173 script tests pass.
* refactor(cli): inject embedding provider resolution and detect sentence-transformers runtime
Make resolveProjectEmbeddingProvider and runtimeIo injectable in ingest and
scan command entrypoints so tests can stub them, and teach
resolvePublicIngestRuntimeRequirements to flag the local-embeddings runtime
feature when ktx.yaml selects sentence-transformers.
* chore(cli): mark buildLocalStatsStatus and LocalStatsStatus as @internal
Both symbols are consumed only by status-project.test.ts. Annotating with
/** @internal */ keeps knip's production-mode check clean without changing
runtime behavior.
* fix(cli): use real package metadata in print-command-tree
The stubbed package name embedded a forbidden product identifier that
tripped the boundary check in CI. Read the metadata from package.json
instead — keeps the rendered tree unchanged and removes a duplicate
source of truth.
* feat(cli): show embedding coverage in `ktx status`, drop duplicate disk counts
Inline `(N embedded)` next to the Wiki scope counts and Semantic-layer
source counts, computed with `SUM(embedding_json IS NOT NULL)` over
`knowledge_pages` and `local_sl_sources`. Rename the "Knowledge" label to
"Wiki" (canonical per `docs/terminology.md`) and rename the matching
`localStats.knowledgePages` field to `localStats.wikiPages`.
Drop `wiki=N md` and `semantic-layer=N yaml` from the Disk row — those
duplicated the per-surface rows above. Disk now reports only actual byte
usage (db, cache, raw-sources). The unused `wikiGlobalMarkdownCount` /
`semanticLayerYamlCount` fields, the `isMarkdownEntry` / `isYamlEntry`
helpers, and the `filter` arg on `summarizeDir` are removed.
2026-05-21 15:28:58 +02:00
|
|
|
/** @internal */
|
2026-05-11 15:50:34 +02:00
|
|
|
export type ManagedPythonDaemonFetch = (
|
|
|
|
|
url: string,
|
|
|
|
|
) => Promise<{
|
|
|
|
|
ok: boolean;
|
|
|
|
|
status: number;
|
|
|
|
|
json(): Promise<unknown>;
|
|
|
|
|
text(): Promise<string>;
|
|
|
|
|
}>;
|
|
|
|
|
|
chore(workspace): gate dead-code with knip production mode (#196)
* refactor(workspace): relocate @ktx/llm source into packages/cli/src/llm
* refactor(workspace): rewrite @ktx/llm imports to relative paths
* refactor(workspace): fold internal packages into cli
* chore(workspace): gate dead-code with knip production mode
Turn on production-mode knip plus an autofix run in pre-commit and the
`pnpm dead-code` script, document the `/** @internal */` convention for
test-only exports in AGENTS.md, annotate test-only exports across the
CLI with that JSDoc, and drop dead exports/wrappers the new gate
surfaced (e.g. `cli-project.ts`, `lookerRuntimeSourceToFileAdapterSource`,
`createLocalScanEnrichmentProvidersFromConfig`,
`PGLITE_OWNER_PROCESS_BACKEND_CAPABILITIES`, stale type re-exports).
Replace the loose `ignoreIssues` allowlist in `knip.json` with explicit
production entries so cross-package barrel leaks are caught.
* refactor(cli): delete internal barrel index.ts files
The 34 `index.ts` re-export barrels inside `packages/cli/src/` were
holdovers from the pre-fold multi-workspace structure. Post-fold-in they
served no production purpose: external consumers go through the single
package main entry, and in-repo callers mostly imported through them
only because the path was short. Internally, knip flagged most barrel
re-exports as production-dead (only reached via tests).
This change:
- Deletes every internal barrel except `packages/cli/src/index.ts`
(the published package entry).
- Rewrites ~270 source/test files to import each name directly from
the file that defines it.
- Moves `tools/warehouse-verification/index.ts` to
`create-warehouse-verification-tools.ts` (the function it defined
locally) and updates its single consumer.
- Renames `search/backend-conformance.ts` → `.test-utils.ts` to match
the existing test-helper file convention.
- Deletes 13 dead test-only chains (dbt-descriptions/*,
live-database/extracted-schema, live-database/structural-sync,
relationship-* feedback/review chain) plus their tests and a
cascading orphan integration test.
- Updates test mocks that pointed at deleted barrel paths
(notion-client, connector barrels in scan/local-scan-connectors
tests) to mock the source files instead.
- Points the maintainer benchmark script
(`scripts/relationship-benchmark-report.mjs`) at source files
instead of `dist/context/scan/index.js`.
- Drops the barrel `!` entries from `knip.json`; adds explicit
production entries only for the benchmark code reached via dist by
the maintainer script.
Net: 413 files changed, ~1.2k insertions, ~9.4k deletions.
`pnpm run dead-code` (Biome + knip default + knip production) and
`pnpm run type-check` are clean; 2277 tests pass.
* refactor(workspace): rename @ktx/cli to @kaelio/ktx and pack it directly
Promote the CLI workspace package to the public name `@kaelio/ktx` and
drop the separate `scripts/build-public-npm-package.mjs` wrapper. The
CLI package is now publishable in place (`publishConfig.access: public`,
`provenance: true`), so artifact packing uses `pnpm pack` against
`packages/cli/` instead of assembling a parallel package tree.
Updates all workspace filter invocations, docs, tests, and release
readiness checks to reference the new package name, and folds the
tarball-name helper into `scripts/public-npm-release-metadata.mjs`.
* docs: align "agent clients" and "data agents" terminology
Replace "client agents" with "agent clients" and "database agents" with
"data agents" across AGENTS.md, README.md, the docs-site copy, and the
matching setup-agents test description, matching the canonical
vocabulary in docs/terminology.md.
Also moves packages/cli/tsconfig.json's tsBuildInfoFile from
node_modules/.cache/ to dist/.tsbuildinfo so incremental builds survive
node_modules reinstalls.
* refactor(release): single source of truth for package version
Make packages/cli/package.json the single source of truth for the
@kaelio/ktx version. publicNpmPackageVersion() now reads it directly,
so artifact filenames, release-readiness checks, and the Python wheel
version all derive from one field. The duplicate
release-policy.json.publicNpmPackageVersion is removed.
Previously the two fields could drift: tarballs were named
kaelio-ktx-0.4.1.tgz while internally containing
@kaelio/ktx@0.0.0-private.
- update-public-release-version.mjs rewrites both Python pyproject.toml
files (ktx-daemon, ktx-sl) alongside the npm package.jsons,
normalizing the version for PEP 440 (e.g. 0.1.0-rc.2 -> 0.1.0rc2).
- semantic-release-config.cjs adds the two pyproject.toml files to
@semantic-release/git assets so the release commit back to main
carries every version source in lockstep.
- The six "?? '0.0.0-private'" fallback literals across the CLI are
replaced with "?? getKtxCliPackageInfo().version", and
createDefaultKtxMcpServer makes its version arg required.
- docs/release.md describes the actual commit-back model: the dev tree
always reflects the most recent release; no sentinel pin to
maintain.
Verified: pnpm run artifacts:build now produces
kaelio-ktx-0.4.1.tgz and kaelio_ktx-0.4.1-py3-none-any.whl with
@kaelio/ktx@0.4.1 inside. Full type-check, dead-code, and
2287 vitests + 173 script tests pass.
* refactor(cli): inject embedding provider resolution and detect sentence-transformers runtime
Make resolveProjectEmbeddingProvider and runtimeIo injectable in ingest and
scan command entrypoints so tests can stub them, and teach
resolvePublicIngestRuntimeRequirements to flag the local-embeddings runtime
feature when ktx.yaml selects sentence-transformers.
* chore(cli): mark buildLocalStatsStatus and LocalStatsStatus as @internal
Both symbols are consumed only by status-project.test.ts. Annotating with
/** @internal */ keeps knip's production-mode check clean without changing
runtime behavior.
* fix(cli): use real package metadata in print-command-tree
The stubbed package name embedded a forbidden product identifier that
tripped the boundary check in CI. Read the metadata from package.json
instead — keeps the rendered tree unchanged and removes a duplicate
source of truth.
* feat(cli): show embedding coverage in `ktx status`, drop duplicate disk counts
Inline `(N embedded)` next to the Wiki scope counts and Semantic-layer
source counts, computed with `SUM(embedding_json IS NOT NULL)` over
`knowledge_pages` and `local_sl_sources`. Rename the "Knowledge" label to
"Wiki" (canonical per `docs/terminology.md`) and rename the matching
`localStats.knowledgePages` field to `localStats.wikiPages`.
Drop `wiki=N md` and `semantic-layer=N yaml` from the Disk row — those
duplicated the per-surface rows above. Disk now reports only actual byte
usage (db, cache, raw-sources). The unused `wikiGlobalMarkdownCount` /
`semanticLayerYamlCount` fields, the `isMarkdownEntry` / `isYamlEntry`
helpers, and the `filter` arg on `summarizeDir` are removed.
2026-05-21 15:28:58 +02:00
|
|
|
type ManagedPythonDaemonKillProcess = (pid: number, signal?: NodeJS.Signals) => void;
|
2026-05-12 13:00:08 +02:00
|
|
|
|
2026-05-14 14:35:55 +02:00
|
|
|
export interface ManagedPythonDaemonStartOptions extends ManagedPythonDaemonLayoutOptions {
|
2026-05-11 15:50:34 +02:00
|
|
|
features: KtxRuntimeFeature[];
|
|
|
|
|
force?: boolean;
|
|
|
|
|
installRuntime?: (options: ManagedPythonRuntimeInstallOptions) => Promise<ManagedPythonRuntimeInstallResult>;
|
|
|
|
|
spawnDaemon?: ManagedPythonDaemonSpawn;
|
|
|
|
|
fetch?: ManagedPythonDaemonFetch;
|
|
|
|
|
allocatePort?: () => Promise<number>;
|
|
|
|
|
processAlive?: (pid: number) => boolean;
|
2026-05-12 13:00:08 +02:00
|
|
|
killProcess?: ManagedPythonDaemonKillProcess;
|
2026-05-11 15:50:34 +02:00
|
|
|
now?: () => Date;
|
|
|
|
|
startupTimeoutMs?: number;
|
|
|
|
|
pollIntervalMs?: number;
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-14 14:35:55 +02:00
|
|
|
export interface ManagedPythonDaemonStatusOptions extends ManagedPythonDaemonLayoutOptions {
|
2026-05-11 15:50:34 +02:00
|
|
|
fetch?: ManagedPythonDaemonFetch;
|
|
|
|
|
processAlive?: (pid: number) => boolean;
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-14 14:35:55 +02:00
|
|
|
export interface ManagedPythonDaemonStopOptions extends ManagedPythonDaemonLayoutOptions {
|
2026-05-11 15:50:34 +02:00
|
|
|
processAlive?: (pid: number) => boolean;
|
2026-05-12 13:00:08 +02:00
|
|
|
killProcess?: ManagedPythonDaemonKillProcess;
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-14 14:35:55 +02:00
|
|
|
export interface ManagedPythonDaemonStopAllOptions extends ManagedPythonDaemonLayoutOptions {
|
2026-05-12 13:00:08 +02:00
|
|
|
listProcesses?: () => Promise<ManagedPythonDaemonProcessInfo[]>;
|
|
|
|
|
processAlive?: (pid: number) => boolean;
|
|
|
|
|
killProcess?: ManagedPythonDaemonKillProcess;
|
|
|
|
|
stopGraceMs?: number;
|
|
|
|
|
pollIntervalMs?: number;
|
|
|
|
|
healthProbeMs?: number;
|
2026-05-11 15:50:34 +02:00
|
|
|
}
|
|
|
|
|
|
2026-05-12 13:00:08 +02:00
|
|
|
const execFileAsync = promisify(execFile);
|
|
|
|
|
|
2026-05-11 15:50:34 +02:00
|
|
|
const daemonStateSchema = z.object({
|
|
|
|
|
schemaVersion: z.literal(1),
|
|
|
|
|
pid: z.number().int().positive(),
|
|
|
|
|
host: z.literal('127.0.0.1'),
|
|
|
|
|
port: z.number().int().min(1).max(65535),
|
|
|
|
|
version: z.string().min(1),
|
|
|
|
|
features: z.array(runtimeFeatureSchema).min(1),
|
|
|
|
|
startedAt: z.string().min(1),
|
|
|
|
|
stdoutLog: z.string().min(1),
|
|
|
|
|
stderrLog: z.string().min(1),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
function normalizeFeatures(features: KtxRuntimeFeature[]): KtxRuntimeFeature[] {
|
|
|
|
|
const requested = new Set<KtxRuntimeFeature>(['core', ...features]);
|
|
|
|
|
return runtimeFeatureSchema.options.filter((feature) => requested.has(feature));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function hasFeatures(state: ManagedPythonDaemonState, features: KtxRuntimeFeature[]): boolean {
|
|
|
|
|
return normalizeFeatures(features).every((feature) => state.features.includes(feature));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function defaultFetch(url: string): ReturnType<ManagedPythonDaemonFetch> {
|
|
|
|
|
return fetch(url) as ReturnType<ManagedPythonDaemonFetch>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function defaultProcessAlive(pid: number): boolean {
|
|
|
|
|
try {
|
|
|
|
|
process.kill(pid, 0);
|
|
|
|
|
return true;
|
|
|
|
|
} catch {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-12 13:00:08 +02:00
|
|
|
function defaultKillProcess(pid: number, signal: NodeJS.Signals = 'SIGTERM'): void {
|
2026-05-11 15:50:34 +02:00
|
|
|
try {
|
2026-05-12 13:00:08 +02:00
|
|
|
process.kill(pid, signal);
|
2026-05-11 15:50:34 +02:00
|
|
|
} catch (error) {
|
|
|
|
|
const code = (error as { code?: unknown }).code;
|
|
|
|
|
if (code !== 'ESRCH') {
|
|
|
|
|
throw error;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function defaultSpawnDaemon(
|
|
|
|
|
command: string,
|
|
|
|
|
args: string[],
|
|
|
|
|
options: Parameters<ManagedPythonDaemonSpawn>[2],
|
|
|
|
|
): ManagedPythonDaemonChild {
|
|
|
|
|
return spawn(command, args, options);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function baseUrl(state: Pick<ManagedPythonDaemonState, 'host' | 'port'>): string {
|
|
|
|
|
return `http://${state.host}:${state.port}`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function readState(path: string): Promise<ManagedPythonDaemonState | undefined> {
|
|
|
|
|
try {
|
|
|
|
|
return daemonStateSchema.parse(JSON.parse(await readFile(path, 'utf8')) as unknown);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
const code = (error as { code?: unknown }).code;
|
|
|
|
|
if (code === 'ENOENT') {
|
|
|
|
|
return undefined;
|
|
|
|
|
}
|
|
|
|
|
throw error;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function writeState(path: string, state: ManagedPythonDaemonState): Promise<void> {
|
|
|
|
|
await writeFile(path, `${JSON.stringify(state, null, 2)}\n`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function healthOk(input: {
|
|
|
|
|
state: ManagedPythonDaemonState;
|
|
|
|
|
cliVersion: string;
|
|
|
|
|
fetch: ManagedPythonDaemonFetch;
|
|
|
|
|
}): Promise<{ ok: true } | { ok: false; detail: string }> {
|
|
|
|
|
try {
|
|
|
|
|
const response = await input.fetch(`${baseUrl(input.state)}/health`);
|
|
|
|
|
if (!response.ok) {
|
|
|
|
|
return { ok: false, detail: `Health check returned HTTP ${response.status}: ${await response.text()}` };
|
|
|
|
|
}
|
|
|
|
|
const body = (await response.json()) as unknown;
|
|
|
|
|
if (!body || typeof body !== 'object' || Array.isArray(body)) {
|
|
|
|
|
return { ok: false, detail: 'Health check returned non-object JSON' };
|
|
|
|
|
}
|
|
|
|
|
const record = body as Record<string, unknown>;
|
|
|
|
|
if (record.status !== 'healthy') {
|
|
|
|
|
return { ok: false, detail: `Health check returned status ${String(record.status)}` };
|
|
|
|
|
}
|
|
|
|
|
if (record.version !== input.cliVersion) {
|
|
|
|
|
return {
|
|
|
|
|
ok: false,
|
|
|
|
|
detail: `Daemon version ${String(record.version)} does not match CLI ${input.cliVersion}`,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
return { ok: true };
|
|
|
|
|
} catch (error) {
|
test: split cli tests from source tree (#216)
* feat(cli): define full warehouse dialect contract
* test(cli): keep dialect edge tests focused
* fix(cli): stabilize dialect contract foundation
* refactor(connectors): own read-only query preparation
* refactor(connectors): resolve dialects through registry
* refactor(connectors): keep concrete dialect classes internal
* chore(workspace): enforce dialect import boundary
* refactor(cli): resolve relationship dialect at scan boundary
* refactor(cli): use dialect display parsing for entity details
* refactor(cli): use dialect display parsing for warehouse catalog
* refactor(cli): use dialect SQL in relationship workflows
* test(cli): verify solid dialect scan workflow closure
* test: split cli tests from source tree
* refactor(cli): standardize BigQuery scope listing
* feat(sqlite): implement connector scope listing
* test(connectors): cover required table listing
* feat(cli): add warehouse driver registry
* refactor(setup): route scope discovery through driver registry
* refactor(cli): route local query execution through driver registry
* refactor(historic-sql): route dialect support through driver registry
* refactor(cli): test warehouse connections through driver registry
* fix(cli): close driver registry type export gaps
* Improve setup daemon diagnostics
* refactor(setup): centralize rail-prefixed diagnostics + query-history fallback
Extract errorMessage, writePrefixedLines, and flushPrefixedBufferedCommandOutput
into clack.ts so the setup wizard, managed daemons, and embedding/agent steps
share one rail-formatted writer. setup-databases.ts also adds a
"disable query history and retry" option when the schema-context build fails
and query history is the likely culprit, surfaced via a new
failed-query-history-unavailable status.
* fix(cli): carry catalog through the picker so BigQuery/Snowflake/SQL Server scope filters match
The setup picker's KtxTableListEntry was a 2-level { schema, name }, so
qualifiedTableId always wrote db.name into enabled_tables. When BigQuery,
Snowflake, or SQL Server later ran fast ingest, their introspect step filtered
the scope set with scopedTableNames(scope, { catalog: projectId|database, db })
— catalog was non-null on the introspect side but null in the scope refs, so
every entry was rejected, the live-database adapter staged zero table files,
and detect() failed with 'Adapter "live-database" did not recognize fetched
source output'.
Align the picker boundary with the canonical 3-level KtxTableRef:
- Add catalog: string | null to KtxTableListEntry.
- BigQuery/Snowflake/SQL Server listTables populate catalog from the
resolved projectId / database; Postgres/MySQL/ClickHouse/SQLite set null.
- qualifiedTableId emits catalog.schema.name when catalog is non-null
(resolveEnabledTables already accepts the 3-part shape) and
schemasFromEnabledTables now goes through parseDottedTableEntry so it
recovers the schema correctly from both 2-part and 3-part entries.
- Export parseDottedTableEntry from enabled-tables.ts (@internal) for picker
reuse.
Update listTables expectations in all seven connector tests and the setup /
picker test fixtures. Add a picker regression test that covers the
catalog-bearing round-trip (save + refine).
* fix(cli): allow debug telemetry under opt-out env
2026-05-26 08:49:05 +02:00
|
|
|
return { ok: false, detail: describeError(error) };
|
2026-05-11 15:50:34 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function readManagedPythonDaemonStatus(
|
|
|
|
|
options: ManagedPythonDaemonStatusOptions,
|
|
|
|
|
): Promise<ManagedPythonDaemonStatus> {
|
2026-05-14 14:35:55 +02:00
|
|
|
const layout = managedPythonDaemonLayout(options);
|
2026-05-11 15:50:34 +02:00
|
|
|
let state: ManagedPythonDaemonState | undefined;
|
|
|
|
|
try {
|
|
|
|
|
state = await readState(layout.daemonStatePath);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
return {
|
|
|
|
|
kind: 'stale',
|
|
|
|
|
detail: `Daemon state is invalid: ${error instanceof Error ? error.message : String(error)}`,
|
|
|
|
|
layout,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
if (!state) {
|
|
|
|
|
return { kind: 'stopped', detail: `No daemon state at ${layout.daemonStatePath}`, layout };
|
|
|
|
|
}
|
|
|
|
|
if (state.version !== options.cliVersion) {
|
|
|
|
|
return {
|
|
|
|
|
kind: 'stale',
|
|
|
|
|
detail: `Daemon is for CLI ${state.version}, current CLI is ${options.cliVersion}`,
|
|
|
|
|
layout,
|
|
|
|
|
state,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
const processAlive = options.processAlive ?? defaultProcessAlive;
|
|
|
|
|
if (!processAlive(state.pid)) {
|
|
|
|
|
return { kind: 'stale', detail: `Daemon process ${state.pid} is not running`, layout, state };
|
|
|
|
|
}
|
|
|
|
|
const health = await healthOk({
|
|
|
|
|
state,
|
|
|
|
|
cliVersion: options.cliVersion,
|
|
|
|
|
fetch: options.fetch ?? defaultFetch,
|
|
|
|
|
});
|
|
|
|
|
if (!health.ok) {
|
|
|
|
|
return { kind: 'stale', detail: health.detail, layout, state };
|
|
|
|
|
}
|
|
|
|
|
return { kind: 'running', detail: `Daemon running at ${baseUrl(state)}`, layout, state, baseUrl: baseUrl(state) };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function allocateDaemonPort(): Promise<number> {
|
|
|
|
|
return await new Promise((resolve, reject) => {
|
|
|
|
|
const server = createServer();
|
|
|
|
|
server.on('error', reject);
|
|
|
|
|
server.listen(0, '127.0.0.1', () => {
|
|
|
|
|
const address = server.address();
|
|
|
|
|
server.close(() => {
|
|
|
|
|
if (address && typeof address === 'object') {
|
|
|
|
|
resolve(address.port);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
reject(new Error('Failed to allocate a daemon port'));
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function waitForHealth(input: {
|
|
|
|
|
state: ManagedPythonDaemonState;
|
|
|
|
|
cliVersion: string;
|
|
|
|
|
fetch: ManagedPythonDaemonFetch;
|
|
|
|
|
timeoutMs: number;
|
|
|
|
|
pollIntervalMs: number;
|
|
|
|
|
}): Promise<void> {
|
|
|
|
|
const deadline = Date.now() + input.timeoutMs;
|
|
|
|
|
let lastDetail = 'daemon did not answer health checks';
|
|
|
|
|
while (Date.now() <= deadline) {
|
|
|
|
|
const health = await healthOk({
|
|
|
|
|
state: input.state,
|
|
|
|
|
cliVersion: input.cliVersion,
|
|
|
|
|
fetch: input.fetch,
|
|
|
|
|
});
|
|
|
|
|
if (health.ok) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
lastDetail = health.detail;
|
|
|
|
|
await delay(input.pollIntervalMs);
|
|
|
|
|
}
|
2026-05-12 10:26:01 +02:00
|
|
|
const finalHealth = await healthOk({
|
|
|
|
|
state: input.state,
|
|
|
|
|
cliVersion: input.cliVersion,
|
|
|
|
|
fetch: input.fetch,
|
|
|
|
|
});
|
|
|
|
|
if (finalHealth.ok) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
lastDetail = finalHealth.detail;
|
test: split cli tests from source tree (#216)
* feat(cli): define full warehouse dialect contract
* test(cli): keep dialect edge tests focused
* fix(cli): stabilize dialect contract foundation
* refactor(connectors): own read-only query preparation
* refactor(connectors): resolve dialects through registry
* refactor(connectors): keep concrete dialect classes internal
* chore(workspace): enforce dialect import boundary
* refactor(cli): resolve relationship dialect at scan boundary
* refactor(cli): use dialect display parsing for entity details
* refactor(cli): use dialect display parsing for warehouse catalog
* refactor(cli): use dialect SQL in relationship workflows
* test(cli): verify solid dialect scan workflow closure
* test: split cli tests from source tree
* refactor(cli): standardize BigQuery scope listing
* feat(sqlite): implement connector scope listing
* test(connectors): cover required table listing
* feat(cli): add warehouse driver registry
* refactor(setup): route scope discovery through driver registry
* refactor(cli): route local query execution through driver registry
* refactor(historic-sql): route dialect support through driver registry
* refactor(cli): test warehouse connections through driver registry
* fix(cli): close driver registry type export gaps
* Improve setup daemon diagnostics
* refactor(setup): centralize rail-prefixed diagnostics + query-history fallback
Extract errorMessage, writePrefixedLines, and flushPrefixedBufferedCommandOutput
into clack.ts so the setup wizard, managed daemons, and embedding/agent steps
share one rail-formatted writer. setup-databases.ts also adds a
"disable query history and retry" option when the schema-context build fails
and query history is the likely culprit, surfaced via a new
failed-query-history-unavailable status.
* fix(cli): carry catalog through the picker so BigQuery/Snowflake/SQL Server scope filters match
The setup picker's KtxTableListEntry was a 2-level { schema, name }, so
qualifiedTableId always wrote db.name into enabled_tables. When BigQuery,
Snowflake, or SQL Server later ran fast ingest, their introspect step filtered
the scope set with scopedTableNames(scope, { catalog: projectId|database, db })
— catalog was non-null on the introspect side but null in the scope refs, so
every entry was rejected, the live-database adapter staged zero table files,
and detect() failed with 'Adapter "live-database" did not recognize fetched
source output'.
Align the picker boundary with the canonical 3-level KtxTableRef:
- Add catalog: string | null to KtxTableListEntry.
- BigQuery/Snowflake/SQL Server listTables populate catalog from the
resolved projectId / database; Postgres/MySQL/ClickHouse/SQLite set null.
- qualifiedTableId emits catalog.schema.name when catalog is non-null
(resolveEnabledTables already accepts the 3-part shape) and
schemasFromEnabledTables now goes through parseDottedTableEntry so it
recovers the schema correctly from both 2-part and 3-part entries.
- Export parseDottedTableEntry from enabled-tables.ts (@internal) for picker
reuse.
Update listTables expectations in all seven connector tests and the setup /
picker test fixtures. Add a picker regression test that covers the
catalog-bearing round-trip (save + refine).
* fix(cli): allow debug telemetry under opt-out env
2026-05-26 08:49:05 +02:00
|
|
|
throw new ManagedPythonDaemonStartError(lastDetail, input.state.stderrLog);
|
2026-05-11 15:50:34 +02:00
|
|
|
}
|
|
|
|
|
|
2026-05-14 14:35:55 +02:00
|
|
|
async function removeState(layout: ManagedPythonDaemonLayout): Promise<void> {
|
2026-05-11 15:50:34 +02:00
|
|
|
await rm(layout.daemonStatePath, { force: true });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function stopRecordedDaemon(input: {
|
2026-05-14 14:35:55 +02:00
|
|
|
layout: ManagedPythonDaemonLayout;
|
2026-05-11 15:50:34 +02:00
|
|
|
state: ManagedPythonDaemonState;
|
|
|
|
|
processAlive: (pid: number) => boolean;
|
2026-05-12 13:00:08 +02:00
|
|
|
killProcess: ManagedPythonDaemonKillProcess;
|
2026-05-11 15:50:34 +02:00
|
|
|
}): Promise<void> {
|
|
|
|
|
if (input.processAlive(input.state.pid)) {
|
|
|
|
|
input.killProcess(input.state.pid);
|
|
|
|
|
}
|
|
|
|
|
await removeState(input.layout);
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-12 13:00:08 +02:00
|
|
|
async function removeStatePaths(paths: string[]): Promise<void> {
|
|
|
|
|
await Promise.all([...new Set(paths)].map((path) => rm(path, { force: true })));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface ManagedPythonDaemonStopCandidate {
|
|
|
|
|
pid: number;
|
|
|
|
|
source: ManagedPythonDaemonStopAllSource;
|
|
|
|
|
host?: string;
|
|
|
|
|
port?: number;
|
|
|
|
|
version?: string;
|
|
|
|
|
command?: string;
|
|
|
|
|
statePaths: string[];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function candidateUrl(candidate: ManagedPythonDaemonStopCandidate): string | undefined {
|
|
|
|
|
if (!candidate.host || !candidate.port) {
|
|
|
|
|
return undefined;
|
|
|
|
|
}
|
|
|
|
|
return `http://${candidate.host}:${candidate.port}`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function candidateEntry(candidate: ManagedPythonDaemonStopCandidate): ManagedPythonDaemonStopAllEntry {
|
|
|
|
|
return {
|
|
|
|
|
pid: candidate.pid,
|
|
|
|
|
source: candidate.source,
|
|
|
|
|
...(candidateUrl(candidate) ? { url: candidateUrl(candidate) } : {}),
|
|
|
|
|
...(candidate.version ? { version: candidate.version } : {}),
|
|
|
|
|
...(candidate.command ? { command: candidate.command } : {}),
|
|
|
|
|
statePaths: [...candidate.statePaths],
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function probeCandidateHealth(
|
|
|
|
|
candidate: ManagedPythonDaemonStopCandidate,
|
|
|
|
|
timeoutMs: number,
|
|
|
|
|
): Promise<'healthy' | 'unreachable' | undefined> {
|
|
|
|
|
const url = candidateUrl(candidate);
|
|
|
|
|
if (!url) {
|
|
|
|
|
return undefined;
|
|
|
|
|
}
|
|
|
|
|
const controller = new AbortController();
|
|
|
|
|
const timeout = setTimeout(() => {
|
|
|
|
|
controller.abort();
|
|
|
|
|
}, timeoutMs);
|
|
|
|
|
try {
|
|
|
|
|
const response = await fetch(`${url}/health`, { signal: controller.signal });
|
|
|
|
|
if (!response.ok) {
|
|
|
|
|
return 'unreachable';
|
|
|
|
|
}
|
|
|
|
|
const body = (await response.json()) as unknown;
|
|
|
|
|
if (!body || typeof body !== 'object' || Array.isArray(body)) {
|
|
|
|
|
return 'unreachable';
|
|
|
|
|
}
|
|
|
|
|
return (body as Record<string, unknown>).status === 'healthy' ? 'healthy' : 'unreachable';
|
|
|
|
|
} catch {
|
|
|
|
|
return 'unreachable';
|
|
|
|
|
} finally {
|
|
|
|
|
clearTimeout(timeout);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-14 14:35:55 +02:00
|
|
|
async function readStateCandidates(statePath: string): Promise<ManagedPythonDaemonStopCandidate[]> {
|
|
|
|
|
let state: ManagedPythonDaemonState | undefined;
|
2026-05-12 13:00:08 +02:00
|
|
|
try {
|
2026-05-14 14:35:55 +02:00
|
|
|
state = await readState(statePath);
|
|
|
|
|
} catch {
|
|
|
|
|
return [];
|
2026-05-12 13:00:08 +02:00
|
|
|
}
|
2026-05-14 14:35:55 +02:00
|
|
|
if (!state) {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
return [
|
|
|
|
|
{
|
2026-05-12 13:00:08 +02:00
|
|
|
pid: state.pid,
|
|
|
|
|
source: 'state',
|
|
|
|
|
host: state.host,
|
|
|
|
|
port: state.port,
|
|
|
|
|
version: state.version,
|
|
|
|
|
statePaths: [statePath],
|
2026-05-14 14:35:55 +02:00
|
|
|
},
|
|
|
|
|
];
|
2026-05-12 13:00:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function tokenizeCommand(command: string): string[] {
|
|
|
|
|
const tokens: string[] = [];
|
|
|
|
|
for (const match of command.matchAll(/"([^"]*)"|'([^']*)'|(\S+)/g)) {
|
|
|
|
|
tokens.push(match[1] ?? match[2] ?? match[3] ?? '');
|
|
|
|
|
}
|
|
|
|
|
return tokens;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function executableName(token: string): string {
|
|
|
|
|
return token.split(/[\\/]/).at(-1) ?? token;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function isKtxDaemonExecutable(token: string): boolean {
|
|
|
|
|
return executableName(token) === 'ktx-daemon' || executableName(token) === 'ktx-daemon.exe';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function normalizedExecutableName(token: string): string {
|
|
|
|
|
return executableName(token).replace(/\.exe$/i, '').toLowerCase();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function hasUvRunPrefix(tokens: string[], daemonIndex: number): boolean {
|
|
|
|
|
return normalizedExecutableName(tokens[0] ?? '') === 'uv' && tokens.slice(1, daemonIndex).includes('run');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function isPythonExecutable(token: string): boolean {
|
|
|
|
|
const name = normalizedExecutableName(token);
|
|
|
|
|
return name === 'python' || name === 'python3';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function hasPythonModulePrefix(tokens: string[], moduleFlagIndex: number): boolean {
|
|
|
|
|
if (moduleFlagIndex === 1 && isPythonExecutable(tokens[0] ?? '')) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return (
|
|
|
|
|
normalizedExecutableName(tokens[0] ?? '') === 'uv' &&
|
|
|
|
|
tokens.slice(1, moduleFlagIndex).includes('run') &&
|
|
|
|
|
tokens.some((token, index) => index < moduleFlagIndex && isPythonExecutable(token))
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function isKtxDaemonServeHttp(tokens: string[]): boolean {
|
|
|
|
|
for (let index = 0; index < tokens.length; index += 1) {
|
|
|
|
|
if (
|
|
|
|
|
isKtxDaemonExecutable(tokens[index] ?? '') &&
|
|
|
|
|
tokens[index + 1] === 'serve-http' &&
|
|
|
|
|
(index === 0 || hasUvRunPrefix(tokens, index))
|
|
|
|
|
) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (
|
|
|
|
|
tokens[index] === '-m' &&
|
|
|
|
|
tokens[index + 1] === 'ktx_daemon' &&
|
|
|
|
|
tokens[index + 2] === 'serve-http' &&
|
|
|
|
|
hasPythonModulePrefix(tokens, index)
|
|
|
|
|
) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function parseCommandOption(tokens: string[], option: string): string | undefined {
|
|
|
|
|
for (let index = 0; index < tokens.length; index += 1) {
|
|
|
|
|
const token = tokens[index];
|
|
|
|
|
if (token === option) {
|
|
|
|
|
return tokens[index + 1];
|
|
|
|
|
}
|
|
|
|
|
if (token?.startsWith(`${option}=`)) {
|
|
|
|
|
return token.slice(option.length + 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return undefined;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function processCandidate(processInfo: ManagedPythonDaemonProcessInfo): ManagedPythonDaemonStopCandidate | undefined {
|
|
|
|
|
const tokens = tokenizeCommand(processInfo.command);
|
|
|
|
|
if (!isKtxDaemonServeHttp(tokens)) {
|
|
|
|
|
return undefined;
|
|
|
|
|
}
|
|
|
|
|
const host = parseCommandOption(tokens, '--host') ?? '127.0.0.1';
|
|
|
|
|
const rawPort = parseCommandOption(tokens, '--port');
|
|
|
|
|
const parsedPort = rawPort ? Number.parseInt(rawPort, 10) : 8765;
|
|
|
|
|
const port = Number.isInteger(parsedPort) && parsedPort >= 1 && parsedPort <= 65535 ? parsedPort : 8765;
|
|
|
|
|
return {
|
|
|
|
|
pid: processInfo.pid,
|
|
|
|
|
source: 'process',
|
|
|
|
|
host,
|
|
|
|
|
port,
|
|
|
|
|
command: processInfo.command,
|
|
|
|
|
statePaths: [],
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function mergeCandidates(candidates: ManagedPythonDaemonStopCandidate[]): ManagedPythonDaemonStopCandidate[] {
|
|
|
|
|
const byPid = new Map<number, ManagedPythonDaemonStopCandidate>();
|
|
|
|
|
for (const candidate of candidates) {
|
|
|
|
|
const existing = byPid.get(candidate.pid);
|
|
|
|
|
if (!existing) {
|
|
|
|
|
byPid.set(candidate.pid, { ...candidate, statePaths: [...candidate.statePaths] });
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
existing.statePaths.push(...candidate.statePaths);
|
|
|
|
|
if (existing.source === 'process' && candidate.source === 'state') {
|
|
|
|
|
byPid.set(candidate.pid, {
|
|
|
|
|
...candidate,
|
|
|
|
|
statePaths: [...new Set([...existing.statePaths, ...candidate.statePaths])],
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
existing.statePaths = [...new Set(existing.statePaths)];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return [...byPid.values()].sort((left, right) => left.pid - right.pid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function parsePosixProcessList(output: string): ManagedPythonDaemonProcessInfo[] {
|
|
|
|
|
const processes: ManagedPythonDaemonProcessInfo[] = [];
|
|
|
|
|
for (const line of output.split(/\r?\n/)) {
|
|
|
|
|
const match = line.match(/^\s*(\d+)\s+(.+)$/);
|
|
|
|
|
if (!match) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
processes.push({ pid: Number.parseInt(match[1], 10), command: match[2] });
|
|
|
|
|
}
|
|
|
|
|
return processes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function parseWindowsProcessList(output: string): ManagedPythonDaemonProcessInfo[] {
|
|
|
|
|
if (!output.trim()) {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
const parsed = JSON.parse(output) as unknown;
|
|
|
|
|
const records = Array.isArray(parsed) ? parsed : [parsed];
|
|
|
|
|
const processes: ManagedPythonDaemonProcessInfo[] = [];
|
|
|
|
|
for (const record of records) {
|
|
|
|
|
if (!record || typeof record !== 'object') {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
const value = record as Record<string, unknown>;
|
|
|
|
|
const pid = value.ProcessId;
|
|
|
|
|
const command = value.CommandLine;
|
|
|
|
|
if (typeof pid === 'number' && typeof command === 'string' && command.length > 0) {
|
|
|
|
|
processes.push({ pid, command });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return processes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function defaultListProcesses(platform: NodeJS.Platform = process.platform): Promise<ManagedPythonDaemonProcessInfo[]> {
|
|
|
|
|
if (platform === 'win32') {
|
|
|
|
|
const command = [
|
|
|
|
|
'Get-CimInstance Win32_Process',
|
|
|
|
|
'| Where-Object { $_.CommandLine -ne $null }',
|
|
|
|
|
'| Select-Object ProcessId,CommandLine',
|
|
|
|
|
'| ConvertTo-Json -Compress',
|
|
|
|
|
].join(' ');
|
|
|
|
|
const { stdout } = await execFileAsync('powershell.exe', ['-NoProfile', '-Command', command], {
|
|
|
|
|
encoding: 'utf8',
|
|
|
|
|
maxBuffer: 10 * 1024 * 1024,
|
|
|
|
|
});
|
|
|
|
|
return parseWindowsProcessList(stdout);
|
|
|
|
|
}
|
|
|
|
|
const { stdout } = await execFileAsync('ps', ['-axo', 'pid=,command='], {
|
|
|
|
|
encoding: 'utf8',
|
|
|
|
|
maxBuffer: 10 * 1024 * 1024,
|
|
|
|
|
});
|
|
|
|
|
return parsePosixProcessList(stdout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function waitUntilStopped(input: {
|
|
|
|
|
pid: number;
|
|
|
|
|
processAlive: (pid: number) => boolean;
|
|
|
|
|
timeoutMs: number;
|
|
|
|
|
pollIntervalMs: number;
|
|
|
|
|
}): Promise<boolean> {
|
|
|
|
|
const deadline = Date.now() + input.timeoutMs;
|
|
|
|
|
do {
|
|
|
|
|
if (!input.processAlive(input.pid)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (Date.now() >= deadline) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
await delay(input.pollIntervalMs);
|
|
|
|
|
} while (Date.now() <= deadline);
|
|
|
|
|
return !input.processAlive(input.pid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function discoverStopAllCandidates(
|
|
|
|
|
options: ManagedPythonDaemonStopAllOptions,
|
|
|
|
|
): Promise<{
|
2026-05-14 14:35:55 +02:00
|
|
|
layout: ManagedPythonDaemonLayout;
|
2026-05-12 13:00:08 +02:00
|
|
|
candidates: ManagedPythonDaemonStopCandidate[];
|
|
|
|
|
scanErrors: string[];
|
|
|
|
|
}> {
|
2026-05-14 14:35:55 +02:00
|
|
|
const layout = managedPythonDaemonLayout(options);
|
|
|
|
|
const stateCandidates = await readStateCandidates(layout.daemonStatePath);
|
2026-05-12 13:00:08 +02:00
|
|
|
const scanErrors: string[] = [];
|
|
|
|
|
let processCandidates: ManagedPythonDaemonStopCandidate[] = [];
|
|
|
|
|
try {
|
|
|
|
|
const processes = await (options.listProcesses ?? defaultListProcesses)();
|
|
|
|
|
processCandidates = processes.flatMap((processInfo) => {
|
|
|
|
|
const candidate = processCandidate(processInfo);
|
|
|
|
|
return candidate ? [candidate] : [];
|
|
|
|
|
});
|
|
|
|
|
} catch (error) {
|
|
|
|
|
scanErrors.push(error instanceof Error ? error.message : String(error));
|
|
|
|
|
}
|
|
|
|
|
return {
|
2026-05-14 14:35:55 +02:00
|
|
|
layout,
|
2026-05-12 13:00:08 +02:00
|
|
|
candidates: mergeCandidates([...stateCandidates, ...processCandidates]),
|
|
|
|
|
scanErrors,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-11 15:50:34 +02:00
|
|
|
export async function startManagedPythonDaemon(
|
|
|
|
|
options: ManagedPythonDaemonStartOptions,
|
|
|
|
|
): Promise<ManagedPythonDaemonStartResult> {
|
|
|
|
|
const features = normalizeFeatures(options.features);
|
|
|
|
|
const installRuntime = options.installRuntime ?? installManagedPythonRuntime;
|
|
|
|
|
const layoutOverrides = {
|
|
|
|
|
...(options.runtimeRoot !== undefined ? { runtimeRoot: options.runtimeRoot } : {}),
|
|
|
|
|
...(options.assetDir !== undefined ? { assetDir: options.assetDir } : {}),
|
|
|
|
|
...(options.platform !== undefined ? { platform: options.platform } : {}),
|
|
|
|
|
...(options.env !== undefined ? { env: options.env } : {}),
|
|
|
|
|
...(options.homeDir !== undefined ? { homeDir: options.homeDir } : {}),
|
|
|
|
|
};
|
2026-05-14 14:35:55 +02:00
|
|
|
const layout = managedPythonDaemonLayout({
|
|
|
|
|
cliVersion: options.cliVersion,
|
|
|
|
|
projectDir: options.projectDir,
|
|
|
|
|
...layoutOverrides,
|
|
|
|
|
});
|
2026-05-11 15:50:34 +02:00
|
|
|
const processAlive = options.processAlive ?? defaultProcessAlive;
|
|
|
|
|
const killProcess = options.killProcess ?? defaultKillProcess;
|
|
|
|
|
const fetchImpl = options.fetch ?? defaultFetch;
|
|
|
|
|
|
|
|
|
|
const status = await readManagedPythonDaemonStatus({
|
|
|
|
|
cliVersion: options.cliVersion,
|
2026-05-14 14:35:55 +02:00
|
|
|
projectDir: options.projectDir,
|
2026-05-11 15:50:34 +02:00
|
|
|
...layoutOverrides,
|
|
|
|
|
fetch: fetchImpl,
|
|
|
|
|
processAlive,
|
|
|
|
|
});
|
|
|
|
|
if (options.force !== true && status.kind === 'running' && hasFeatures(status.state, features)) {
|
|
|
|
|
return { status: 'reused', layout, state: status.state, baseUrl: status.baseUrl };
|
|
|
|
|
}
|
|
|
|
|
if ('state' in status && status.state) {
|
|
|
|
|
await stopRecordedDaemon({ layout, state: status.state, processAlive, killProcess });
|
|
|
|
|
} else {
|
|
|
|
|
await removeState(layout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const installed = await installRuntime({
|
|
|
|
|
cliVersion: options.cliVersion,
|
|
|
|
|
...layoutOverrides,
|
|
|
|
|
features,
|
|
|
|
|
force: false,
|
|
|
|
|
});
|
|
|
|
|
|
2026-05-14 14:35:55 +02:00
|
|
|
await mkdir(layout.daemonStateDir, { recursive: true });
|
2026-05-11 15:50:34 +02:00
|
|
|
const stdout = await open(layout.daemonStdoutPath, 'a');
|
|
|
|
|
const stderr = await open(layout.daemonStderrPath, 'a');
|
|
|
|
|
try {
|
|
|
|
|
const port = await (options.allocatePort ?? allocateDaemonPort)();
|
|
|
|
|
const spawnDaemon = options.spawnDaemon ?? defaultSpawnDaemon;
|
|
|
|
|
const child = spawnDaemon(
|
|
|
|
|
installed.manifest.python.daemonExecutable,
|
|
|
|
|
['serve-http', '--host', '127.0.0.1', '--port', String(port)],
|
|
|
|
|
{
|
|
|
|
|
detached: true,
|
|
|
|
|
stdio: ['ignore', stdout.fd, stderr.fd],
|
2026-05-19 18:18:56 +02:00
|
|
|
env: sanitizeChildProxyEnv({
|
2026-05-11 15:50:34 +02:00
|
|
|
...process.env,
|
|
|
|
|
KTX_DAEMON_VERSION: options.cliVersion,
|
2026-05-19 18:18:56 +02:00
|
|
|
}),
|
2026-05-11 15:50:34 +02:00
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
child.unref();
|
|
|
|
|
if (!child.pid) {
|
refactor(release): drop release-policy.json runtime dep and next branch (#180)
* chore: standardize daemon naming on "KTX daemon"
Replace inconsistent names ("KTX Python daemon", "KTX local embeddings
daemon", "KTX managed daemon", "Python daemon") with the single name
"KTX daemon" in CLI output, errors, command descriptions, test
assertions, smoke scripts, docs, AGENTS.md, issue templates, and
codecov flags. The daemon is a portable compute server with endpoints
for SQL analysis, semantic layer, LookML, database introspection, and
embeddings; the previous labels misrepresented it as embeddings-only or
exposed implementation details ("Python", "managed").
The "KTX Python runtime" concept (installed interpreter + packages) is
deliberately left as-is — it is a separate concept from the daemon
process.
* refactor(release): drop release-policy.json runtime dep and next branch
Strips the release-policy.json fallback from release-version.ts so the CLI
reads its version straight from packages/cli/package.json. dev → 0.0.0-private,
installed @kaelio/ktx → the real semver baked into the published package.json.
KtxCliPackageInfo collapses to { name, version, contextPackageName }; /health
no longer depends on version files surviving past a CI run.
Replaces the dual-branch (main + next) semantic-release model with a single-
branch model on main. rcs and stables interleave on the same branch via
{ name: 'main', prerelease: 'rc', channel: 'next' } / ['main']. Drops
@semantic-release/git and @semantic-release/changelog (nothing is committed
back to the repo on any channel) and the workflow's "Prepare next prerelease
branch" step plus the KTX_PRERELEASE_BRANCH plumbing. The git tag plus the
published npm artifact carry the version forward.
Updates docs/release.md, removes the two now-unused devDeps, regenerates
pnpm-lock.yaml. 611/611 @ktx/cli tests, 173/173 script tests, type-check,
biome, knip all clean.
* fix(release): don't throw on non-main branches at config-load time
knip loads .releaserc.cjs on every PR run, where GITHUB_REF_NAME is the
merge ref (e.g. 180/merge). The previous version of releaseBranches threw
immediately when the branch wasn't main, which made knip fail to evaluate
the config and then mis-flag @semantic-release/exec as an unused dep.
semantic-release already refuses to publish when the current branch doesn't
match a configured release branch, so the explicit throw was redundant.
Drop it (and the unused currentBranch helper) and replace the
"rejects releases from non-main" assertion with one that exercises a CI-
shaped GITHUB_REF_NAME and confirms the config loads.
2026-05-20 13:53:14 +02:00
|
|
|
throw new Error(`KTX daemon did not report a pid. stderr: ${layout.daemonStderrPath}`);
|
2026-05-11 15:50:34 +02:00
|
|
|
}
|
|
|
|
|
const state: ManagedPythonDaemonState = {
|
|
|
|
|
schemaVersion: 1,
|
|
|
|
|
pid: child.pid,
|
|
|
|
|
host: '127.0.0.1',
|
|
|
|
|
port,
|
|
|
|
|
version: options.cliVersion,
|
|
|
|
|
features: installed.manifest.features,
|
|
|
|
|
startedAt: (options.now ?? (() => new Date()))().toISOString(),
|
|
|
|
|
stdoutLog: layout.daemonStdoutPath,
|
|
|
|
|
stderrLog: layout.daemonStderrPath,
|
|
|
|
|
};
|
test: split cli tests from source tree (#216)
* feat(cli): define full warehouse dialect contract
* test(cli): keep dialect edge tests focused
* fix(cli): stabilize dialect contract foundation
* refactor(connectors): own read-only query preparation
* refactor(connectors): resolve dialects through registry
* refactor(connectors): keep concrete dialect classes internal
* chore(workspace): enforce dialect import boundary
* refactor(cli): resolve relationship dialect at scan boundary
* refactor(cli): use dialect display parsing for entity details
* refactor(cli): use dialect display parsing for warehouse catalog
* refactor(cli): use dialect SQL in relationship workflows
* test(cli): verify solid dialect scan workflow closure
* test: split cli tests from source tree
* refactor(cli): standardize BigQuery scope listing
* feat(sqlite): implement connector scope listing
* test(connectors): cover required table listing
* feat(cli): add warehouse driver registry
* refactor(setup): route scope discovery through driver registry
* refactor(cli): route local query execution through driver registry
* refactor(historic-sql): route dialect support through driver registry
* refactor(cli): test warehouse connections through driver registry
* fix(cli): close driver registry type export gaps
* Improve setup daemon diagnostics
* refactor(setup): centralize rail-prefixed diagnostics + query-history fallback
Extract errorMessage, writePrefixedLines, and flushPrefixedBufferedCommandOutput
into clack.ts so the setup wizard, managed daemons, and embedding/agent steps
share one rail-formatted writer. setup-databases.ts also adds a
"disable query history and retry" option when the schema-context build fails
and query history is the likely culprit, surfaced via a new
failed-query-history-unavailable status.
* fix(cli): carry catalog through the picker so BigQuery/Snowflake/SQL Server scope filters match
The setup picker's KtxTableListEntry was a 2-level { schema, name }, so
qualifiedTableId always wrote db.name into enabled_tables. When BigQuery,
Snowflake, or SQL Server later ran fast ingest, their introspect step filtered
the scope set with scopedTableNames(scope, { catalog: projectId|database, db })
— catalog was non-null on the introspect side but null in the scope refs, so
every entry was rejected, the live-database adapter staged zero table files,
and detect() failed with 'Adapter "live-database" did not recognize fetched
source output'.
Align the picker boundary with the canonical 3-level KtxTableRef:
- Add catalog: string | null to KtxTableListEntry.
- BigQuery/Snowflake/SQL Server listTables populate catalog from the
resolved projectId / database; Postgres/MySQL/ClickHouse/SQLite set null.
- qualifiedTableId emits catalog.schema.name when catalog is non-null
(resolveEnabledTables already accepts the 3-part shape) and
schemasFromEnabledTables now goes through parseDottedTableEntry so it
recovers the schema correctly from both 2-part and 3-part entries.
- Export parseDottedTableEntry from enabled-tables.ts (@internal) for picker
reuse.
Update listTables expectations in all seven connector tests and the setup /
picker test fixtures. Add a picker regression test that covers the
catalog-bearing round-trip (save + refine).
* fix(cli): allow debug telemetry under opt-out env
2026-05-26 08:49:05 +02:00
|
|
|
try {
|
|
|
|
|
await waitForHealth({
|
|
|
|
|
state,
|
|
|
|
|
cliVersion: options.cliVersion,
|
|
|
|
|
fetch: fetchImpl,
|
|
|
|
|
timeoutMs: options.startupTimeoutMs ?? 30_000,
|
|
|
|
|
pollIntervalMs: options.pollIntervalMs ?? 100,
|
|
|
|
|
});
|
|
|
|
|
} catch (error) {
|
|
|
|
|
if (processAlive(state.pid)) {
|
|
|
|
|
killProcess(state.pid);
|
|
|
|
|
}
|
|
|
|
|
await removeState(layout);
|
|
|
|
|
throw error;
|
|
|
|
|
}
|
2026-05-11 15:50:34 +02:00
|
|
|
await writeState(layout.daemonStatePath, state);
|
|
|
|
|
return { status: 'started', layout, state, baseUrl: baseUrl(state) };
|
|
|
|
|
} finally {
|
|
|
|
|
await stdout.close();
|
|
|
|
|
await stderr.close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function stopManagedPythonDaemon(
|
|
|
|
|
options: ManagedPythonDaemonStopOptions,
|
|
|
|
|
): Promise<ManagedPythonDaemonStopResult> {
|
2026-05-14 14:35:55 +02:00
|
|
|
const layout = managedPythonDaemonLayout(options);
|
2026-05-11 15:50:34 +02:00
|
|
|
const state = await readState(layout.daemonStatePath);
|
|
|
|
|
if (!state) {
|
|
|
|
|
return { status: 'already-stopped', layout };
|
|
|
|
|
}
|
|
|
|
|
await stopRecordedDaemon({
|
|
|
|
|
layout,
|
|
|
|
|
state,
|
|
|
|
|
processAlive: options.processAlive ?? defaultProcessAlive,
|
|
|
|
|
killProcess: options.killProcess ?? defaultKillProcess,
|
|
|
|
|
});
|
|
|
|
|
return { status: 'stopped', layout, state };
|
|
|
|
|
}
|
2026-05-12 13:00:08 +02:00
|
|
|
|
|
|
|
|
export async function stopAllManagedPythonDaemons(
|
|
|
|
|
options: ManagedPythonDaemonStopAllOptions,
|
|
|
|
|
): Promise<ManagedPythonDaemonStopAllResult> {
|
|
|
|
|
const processAlive = options.processAlive ?? defaultProcessAlive;
|
|
|
|
|
const killProcess = options.killProcess ?? defaultKillProcess;
|
|
|
|
|
const stopGraceMs = options.stopGraceMs ?? 500;
|
|
|
|
|
const pollIntervalMs = options.pollIntervalMs ?? 50;
|
|
|
|
|
const healthProbeMs = options.healthProbeMs ?? 100;
|
|
|
|
|
const discovery = await discoverStopAllCandidates(options);
|
|
|
|
|
const stopped: ManagedPythonDaemonStopAllEntry[] = [];
|
|
|
|
|
const stale: ManagedPythonDaemonStopAllEntry[] = [];
|
|
|
|
|
const failed: ManagedPythonDaemonStopAllFailure[] = [];
|
|
|
|
|
|
|
|
|
|
for (const candidate of discovery.candidates) {
|
|
|
|
|
const health = await probeCandidateHealth(candidate, healthProbeMs);
|
|
|
|
|
const entry = { ...candidateEntry(candidate), ...(health ? { health } : {}) };
|
|
|
|
|
if (!processAlive(candidate.pid)) {
|
|
|
|
|
await removeStatePaths(candidate.statePaths);
|
|
|
|
|
stale.push(entry);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
killProcess(candidate.pid, 'SIGTERM');
|
|
|
|
|
if (
|
|
|
|
|
!(await waitUntilStopped({
|
|
|
|
|
pid: candidate.pid,
|
|
|
|
|
processAlive,
|
|
|
|
|
timeoutMs: stopGraceMs,
|
|
|
|
|
pollIntervalMs,
|
|
|
|
|
}))
|
|
|
|
|
) {
|
|
|
|
|
killProcess(candidate.pid, 'SIGKILL');
|
|
|
|
|
if (
|
|
|
|
|
!(await waitUntilStopped({
|
|
|
|
|
pid: candidate.pid,
|
|
|
|
|
processAlive,
|
|
|
|
|
timeoutMs: stopGraceMs,
|
|
|
|
|
pollIntervalMs,
|
|
|
|
|
}))
|
|
|
|
|
) {
|
|
|
|
|
failed.push({ ...entry, detail: 'Process still running after SIGKILL' });
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
await removeStatePaths(candidate.statePaths);
|
|
|
|
|
stopped.push(entry);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
failed.push({ ...entry, detail: error instanceof Error ? error.message : String(error) });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
stopped,
|
|
|
|
|
stale,
|
|
|
|
|
failed,
|
|
|
|
|
scanErrors: discovery.scanErrors,
|
|
|
|
|
};
|
|
|
|
|
}
|