2026-05-10 23:12:26 +02:00
|
|
|
|
/* @jsxImportSource react */
|
|
|
|
|
|
import { Box, Text, render as renderInkRuntime, useApp, useInput } from 'ink';
|
2026-05-13 13:33:28 +02:00
|
|
|
|
import { type ReactNode, useEffect, useMemo, useRef, useState } from 'react';
|
2026-05-10 23:12:26 +02:00
|
|
|
|
import {
|
|
|
|
|
|
filterTree,
|
|
|
|
|
|
flattenSelection,
|
2026-05-14 14:35:58 +02:00
|
|
|
|
hasPartialChildren,
|
2026-05-10 23:12:26 +02:00
|
|
|
|
isAncestorChecked,
|
|
|
|
|
|
reducer,
|
|
|
|
|
|
visibleNodeIds,
|
|
|
|
|
|
type PickerCommand,
|
|
|
|
|
|
type PickerState,
|
2026-05-13 18:41:44 -04:00
|
|
|
|
} from './tree-picker-state.js';
|
2026-05-13 15:04:50 +02:00
|
|
|
|
import type { KtxCliIo } from './cli-runtime.js';
|
2026-05-10 23:12:26 +02:00
|
|
|
|
|
|
|
|
|
|
const COLOR_THEME = {
|
|
|
|
|
|
text: 'white',
|
|
|
|
|
|
muted: 'gray',
|
|
|
|
|
|
active: 'cyan',
|
2026-05-13 17:28:48 -04:00
|
|
|
|
selected: 'green',
|
2026-05-10 23:12:26 +02:00
|
|
|
|
warning: 'yellow',
|
|
|
|
|
|
} as const;
|
|
|
|
|
|
|
|
|
|
|
|
const NO_COLOR_THEME = {
|
|
|
|
|
|
text: 'white',
|
|
|
|
|
|
muted: 'white',
|
|
|
|
|
|
active: 'white',
|
2026-05-13 17:28:48 -04:00
|
|
|
|
selected: 'white',
|
2026-05-10 23:12:26 +02:00
|
|
|
|
warning: 'white',
|
|
|
|
|
|
} as const;
|
|
|
|
|
|
|
2026-05-13 18:41:44 -04:00
|
|
|
|
type TreePickerTheme = Record<keyof typeof COLOR_THEME, string>;
|
2026-05-10 23:12:26 +02:00
|
|
|
|
|
2026-05-13 18:41:44 -04:00
|
|
|
|
const DEFAULT_TREE_PICKER_HELP_TEXT =
|
|
|
|
|
|
'Right Arrow to expand, Up/Down to move, Space to select or unselect, Slash to filter, Enter to confirm, Escape to go back, or Ctrl+C to exit.';
|
|
|
|
|
|
|
|
|
|
|
|
const DEFAULT_SKIP_EMPTY_MESSAGE =
|
|
|
|
|
|
'Nothing selected. Skip this step? Press Enter to skip or Escape to go back.';
|
|
|
|
|
|
|
|
|
|
|
|
export interface TreePickerTuiIo extends KtxCliIo {
|
2026-05-10 23:12:26 +02:00
|
|
|
|
stdin?: { isTTY?: boolean; setRawMode?(value: boolean): void };
|
2026-05-10 23:51:24 +02:00
|
|
|
|
stdout: KtxCliIo['stdout'] & { isTTY?: boolean; columns?: number; rows?: number };
|
2026-05-10 23:12:26 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
interface InkKey {
|
|
|
|
|
|
leftArrow?: boolean;
|
|
|
|
|
|
rightArrow?: boolean;
|
|
|
|
|
|
upArrow?: boolean;
|
|
|
|
|
|
downArrow?: boolean;
|
|
|
|
|
|
return?: boolean;
|
|
|
|
|
|
escape?: boolean;
|
|
|
|
|
|
ctrl?: boolean;
|
|
|
|
|
|
backspace?: boolean;
|
|
|
|
|
|
delete?: boolean;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-05-13 18:41:44 -04:00
|
|
|
|
export type TreePickerResult = { kind: 'save'; selectedIds: string[] } | { kind: 'quit' };
|
2026-05-10 23:12:26 +02:00
|
|
|
|
|
2026-05-13 18:41:44 -04:00
|
|
|
|
export interface TreePickerChrome {
|
|
|
|
|
|
title: string;
|
|
|
|
|
|
helpText?: string;
|
|
|
|
|
|
subtitleLines?: readonly string[];
|
|
|
|
|
|
warningLines?: readonly string[];
|
|
|
|
|
|
confirmSaveMessage?: (state: PickerState) => string;
|
|
|
|
|
|
skipEmptyMessage?: string;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export interface TreePickerRenderInput {
|
2026-05-10 23:12:26 +02:00
|
|
|
|
initialState: PickerState;
|
2026-05-13 18:41:44 -04:00
|
|
|
|
chrome: TreePickerChrome;
|
2026-05-10 23:12:26 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-05-13 18:41:44 -04:00
|
|
|
|
interface TreePickerAppProps extends TreePickerRenderInput {
|
2026-05-10 23:12:26 +02:00
|
|
|
|
terminalRows?: number;
|
|
|
|
|
|
terminalWidth?: number;
|
|
|
|
|
|
env?: NodeJS.ProcessEnv;
|
2026-05-13 18:41:44 -04:00
|
|
|
|
onExit(result: TreePickerResult): void;
|
2026-05-10 23:12:26 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
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-13 18:41:44 -04:00
|
|
|
|
export interface TreePickerInkInstance {
|
2026-05-10 23:12:26 +02:00
|
|
|
|
rerender(tree: ReactNode): void;
|
|
|
|
|
|
unmount(): void;
|
|
|
|
|
|
waitUntilExit(): Promise<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-13 18:41:44 -04:00
|
|
|
|
export interface TreePickerInkRenderOptions {
|
|
|
|
|
|
stdin?: TreePickerTuiIo['stdin'];
|
|
|
|
|
|
stdout: TreePickerTuiIo['stdout'];
|
|
|
|
|
|
stderr: TreePickerTuiIo['stderr'];
|
2026-05-10 23:12:26 +02:00
|
|
|
|
exitOnCtrlC: boolean;
|
|
|
|
|
|
patchConsole: boolean;
|
|
|
|
|
|
maxFps: number;
|
|
|
|
|
|
alternateScreen: boolean;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-05-13 18:41:44 -04:00
|
|
|
|
function resolveTheme(env: NodeJS.ProcessEnv = process.env): TreePickerTheme {
|
2026-05-10 23:12:26 +02:00
|
|
|
|
return env.NO_COLOR || env.TERM === 'dumb' ? NO_COLOR_THEME : COLOR_THEME;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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-13 18:41:44 -04:00
|
|
|
|
export function resolveTreePickerWidth(columns: number | undefined): number {
|
2026-05-10 23:12:26 +02:00
|
|
|
|
const resolvedColumns = columns ?? 100;
|
|
|
|
|
|
return Math.max(60, Math.min(120, resolvedColumns - 4));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function rowMatchesSearch(state: PickerState, nodeId: string): boolean {
|
|
|
|
|
|
const query = state.search.query.trim().toLocaleLowerCase();
|
|
|
|
|
|
if (!query) {
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
const node = state.byId.get(nodeId);
|
|
|
|
|
|
if (!node) {
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
return node.title.toLocaleLowerCase().includes(query) || node.path.toLocaleLowerCase().includes(query);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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-13 18:41:44 -04:00
|
|
|
|
export function sanitizeTreePickerTuiError(error: unknown): string {
|
2026-05-10 23:12:26 +02:00
|
|
|
|
const message = error instanceof Error ? error.message : String(error);
|
|
|
|
|
|
return message
|
|
|
|
|
|
.replace(/[a-z][a-z0-9+.-]*:\/\/[^\s]+/gi, '[redacted-url]')
|
|
|
|
|
|
.replace(/\b(api[_-]?key|password|token|secret)=\S+/gi, '[redacted]');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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-10 23:12:26 +02:00
|
|
|
|
export function windowOffset(count: number, selected: number, visible: number): number {
|
|
|
|
|
|
if (count <= visible) return 0;
|
|
|
|
|
|
return Math.max(0, Math.min(count - visible, selected - Math.floor(visible / 2)));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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-10 23:12:26 +02:00
|
|
|
|
export function windowItems<T>(items: T[], selected: number, visible: number): { items: T[]; offset: number } {
|
|
|
|
|
|
const offset = windowOffset(items.length, selected, visible);
|
|
|
|
|
|
return { items: items.slice(offset, offset + visible), offset };
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function truncateText(value: string, width: number): string {
|
|
|
|
|
|
if (value.length <= width) return value;
|
|
|
|
|
|
if (width <= 3) return value.slice(0, width);
|
|
|
|
|
|
return `${value.slice(0, width - 3)}...`;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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-13 18:41:44 -04:00
|
|
|
|
export function treePickerCommandForInkInput(
|
2026-05-10 23:12:26 +02:00
|
|
|
|
input: string,
|
|
|
|
|
|
key: InkKey,
|
|
|
|
|
|
search: PickerState['search'],
|
|
|
|
|
|
pendingConfirm: PickerState['pendingConfirm'],
|
|
|
|
|
|
): PickerCommand | null {
|
|
|
|
|
|
if (pendingConfirm) {
|
|
|
|
|
|
if (input === 'y' || key.return) return 'save-confirm';
|
|
|
|
|
|
if (input === 'n' || key.escape) return 'save-cancel';
|
|
|
|
|
|
if (key.ctrl === true && input === 'c') return 'quit';
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (search.editing) {
|
|
|
|
|
|
if (key.escape) return 'search-cancel';
|
|
|
|
|
|
if (key.return) return 'search-submit';
|
|
|
|
|
|
if (key.backspace || key.delete) return 'search-backspace';
|
|
|
|
|
|
if (key.downArrow) return 'cursor-down';
|
|
|
|
|
|
if (key.upArrow) return 'cursor-up';
|
2026-05-13 18:41:44 -04:00
|
|
|
|
if (input.length === 1 && input >= ' ' && input !== '') return { type: 'search-input', value: input };
|
2026-05-10 23:12:26 +02:00
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (key.ctrl === true && input === 'c') return 'quit';
|
|
|
|
|
|
if (key.upArrow) return 'cursor-up';
|
|
|
|
|
|
if (key.downArrow) return 'cursor-down';
|
|
|
|
|
|
if (key.leftArrow) return 'cursor-left';
|
|
|
|
|
|
if (key.rightArrow) return 'cursor-right';
|
2026-05-13 17:28:48 -04:00
|
|
|
|
if (key.return) return 'save-request';
|
2026-05-10 23:12:26 +02:00
|
|
|
|
if (input === ' ') return 'toggle-check';
|
|
|
|
|
|
if (input === '/') return 'search-start';
|
2026-05-14 14:35:58 +02:00
|
|
|
|
if (input === 'a') return 'toggle-select-all-visible';
|
2026-05-10 23:12:26 +02:00
|
|
|
|
if (input === 'n') return 'select-none';
|
2026-05-13 17:28:48 -04:00
|
|
|
|
if (key.escape) return 'quit';
|
2026-05-10 23:12:26 +02:00
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-05-13 18:41:44 -04:00
|
|
|
|
function PickerRow(props: { state: PickerState; nodeId: string; width: number; theme: TreePickerTheme }): ReactNode {
|
2026-05-10 23:12:26 +02:00
|
|
|
|
const node = props.state.byId.get(props.nodeId);
|
|
|
|
|
|
if (!node) return null;
|
|
|
|
|
|
const focused = props.state.cursorId === node.id;
|
|
|
|
|
|
const locked = isAncestorChecked(node.id, props.state.checked, props.state.byId);
|
|
|
|
|
|
const checked = props.state.checked.has(node.id);
|
2026-05-13 17:28:48 -04:00
|
|
|
|
const isSelected = checked || locked;
|
2026-05-14 14:35:58 +02:00
|
|
|
|
const partial = !isSelected && hasPartialChildren(node.id, props.state.checked, props.state.byId);
|
|
|
|
|
|
const glyph = isSelected ? '◼' : partial ? '◧' : '◻';
|
|
|
|
|
|
const glyphColor = isSelected || partial ? props.theme.selected : props.theme.muted;
|
2026-05-13 17:28:48 -04:00
|
|
|
|
const childAffordance =
|
2026-05-10 23:12:26 +02:00
|
|
|
|
node.childIds.length > 0 ? (props.state.expanded.has(node.id) ? ' ▾' : ` ▸ (${node.childIds.length})`) : '';
|
2026-05-13 17:28:48 -04:00
|
|
|
|
const indent = ' '.repeat(node.depth * 2);
|
2026-05-13 18:41:44 -04:00
|
|
|
|
const titleColor = focused ? props.theme.active : props.theme.text;
|
2026-05-10 23:12:26 +02:00
|
|
|
|
const inverse = rowMatchesSearch(props.state, node.id);
|
2026-05-13 18:41:44 -04:00
|
|
|
|
const prefixWidth = indent.length + 2 + childAffordance.length;
|
|
|
|
|
|
const title = truncateText(node.title, Math.max(10, props.width - prefixWidth));
|
2026-05-10 23:12:26 +02:00
|
|
|
|
|
|
|
|
|
|
return (
|
2026-05-13 17:28:48 -04:00
|
|
|
|
<Text>
|
|
|
|
|
|
<Text color={glyphColor}>
|
|
|
|
|
|
{indent}
|
|
|
|
|
|
{glyph}
|
|
|
|
|
|
</Text>
|
2026-05-13 18:41:44 -04:00
|
|
|
|
<Text color={titleColor} strikethrough={node.archived} bold={focused}>
|
2026-05-13 17:28:48 -04:00
|
|
|
|
{' '}
|
|
|
|
|
|
<Text inverse={inverse}>{title}</Text>
|
|
|
|
|
|
</Text>
|
2026-05-13 18:41:44 -04:00
|
|
|
|
{childAffordance.length > 0 ? <Text color={props.theme.muted}>{childAffordance}</Text> : null}
|
2026-05-10 23:12:26 +02:00
|
|
|
|
</Text>
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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-13 18:41:44 -04:00
|
|
|
|
export function TreePickerApp(props: TreePickerAppProps): ReactNode {
|
2026-05-10 23:12:26 +02:00
|
|
|
|
const app = useApp();
|
|
|
|
|
|
const [state, setState] = useState(props.initialState);
|
|
|
|
|
|
const stateRef = useRef(state);
|
|
|
|
|
|
const theme = useMemo(() => resolveTheme(props.env), [props.env]);
|
|
|
|
|
|
const visibleIds = visibleNodeIds(state);
|
|
|
|
|
|
const selectedIndex = Math.max(0, visibleIds.indexOf(state.cursorId));
|
2026-05-13 18:41:44 -04:00
|
|
|
|
const reservedRows = state.pendingConfirm === 'save-confirm' ? 10 : 9;
|
2026-05-13 17:28:48 -04:00
|
|
|
|
const visibleRows = Math.max(5, Math.min(12, (props.terminalRows ?? 24) - reservedRows));
|
2026-05-10 23:12:26 +02:00
|
|
|
|
const rows = windowItems(visibleIds, selectedIndex, visibleRows);
|
|
|
|
|
|
const hiddenAbove = rows.offset;
|
|
|
|
|
|
const hiddenBelow = Math.max(0, visibleIds.length - rows.offset - rows.items.length);
|
|
|
|
|
|
const searchMatchCount = filterTree(state).visibleIds.size;
|
2026-05-13 18:41:44 -04:00
|
|
|
|
const width = resolveTreePickerWidth(props.terminalWidth);
|
2026-05-10 23:12:26 +02:00
|
|
|
|
const showSearch = state.search.editing || state.search.query.trim().length > 0;
|
2026-05-13 18:41:44 -04:00
|
|
|
|
const helpText = props.chrome.helpText ?? DEFAULT_TREE_PICKER_HELP_TEXT;
|
|
|
|
|
|
const skipEmptyMessage = props.chrome.skipEmptyMessage ?? DEFAULT_SKIP_EMPTY_MESSAGE;
|
2026-05-10 23:12:26 +02:00
|
|
|
|
|
|
|
|
|
|
stateRef.current = state;
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
const hint = state.transientHint;
|
|
|
|
|
|
if (!hint) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const clearHint = () => {
|
|
|
|
|
|
setState((current) => {
|
|
|
|
|
|
const { next } = reducer(current, 'clear-transient-hint');
|
|
|
|
|
|
stateRef.current = next;
|
|
|
|
|
|
return next;
|
|
|
|
|
|
});
|
|
|
|
|
|
};
|
|
|
|
|
|
const delay = hint.expiresAt - Date.now();
|
|
|
|
|
|
if (delay <= 0) {
|
|
|
|
|
|
clearHint();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const timeout = setTimeout(clearHint, delay);
|
|
|
|
|
|
|
|
|
|
|
|
return () => clearTimeout(timeout);
|
|
|
|
|
|
}, [state.transientHint?.expiresAt]);
|
|
|
|
|
|
|
|
|
|
|
|
useInput((input, key) => {
|
2026-05-13 18:41:44 -04:00
|
|
|
|
const command = treePickerCommandForInkInput(input, key, stateRef.current.search, stateRef.current.pendingConfirm);
|
2026-05-10 23:12:26 +02:00
|
|
|
|
if (!command) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
const { next, effect } = reducer(stateRef.current, command);
|
|
|
|
|
|
stateRef.current = next;
|
|
|
|
|
|
setState(next);
|
|
|
|
|
|
if (effect === 'save') {
|
2026-05-13 18:41:44 -04:00
|
|
|
|
props.onExit({ kind: 'save', selectedIds: flattenSelection(next.checked, next.byId) });
|
2026-05-10 23:12:26 +02:00
|
|
|
|
app.exit();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (effect === 'quit-without-save') {
|
|
|
|
|
|
props.onExit({ kind: 'quit' });
|
|
|
|
|
|
app.exit();
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
<Box flexDirection="column">
|
2026-05-13 17:28:48 -04:00
|
|
|
|
<Text>
|
|
|
|
|
|
<Text color={theme.active}>◆</Text>
|
2026-05-13 18:41:44 -04:00
|
|
|
|
<Text bold> {props.chrome.title}</Text>
|
2026-05-13 17:28:48 -04:00
|
|
|
|
</Text>
|
|
|
|
|
|
<Box
|
|
|
|
|
|
flexDirection="column"
|
|
|
|
|
|
borderStyle="single"
|
|
|
|
|
|
borderTop={false}
|
|
|
|
|
|
borderRight={false}
|
|
|
|
|
|
borderBottom={false}
|
|
|
|
|
|
borderColor={theme.active}
|
|
|
|
|
|
paddingLeft={1}
|
|
|
|
|
|
>
|
2026-05-13 18:41:44 -04:00
|
|
|
|
<Text color={theme.muted}>{helpText}</Text>
|
2026-05-13 17:28:48 -04:00
|
|
|
|
<Text> </Text>
|
2026-05-13 18:41:44 -04:00
|
|
|
|
{(props.chrome.subtitleLines ?? []).map((line, idx) => (
|
|
|
|
|
|
<Text key={`subtitle-${idx}`} color={theme.muted}>
|
|
|
|
|
|
{line}
|
|
|
|
|
|
</Text>
|
|
|
|
|
|
))}
|
|
|
|
|
|
{(props.chrome.warningLines ?? []).map((line, idx) => (
|
|
|
|
|
|
<Text key={`chromewarn-${idx}`} color={theme.warning}>
|
|
|
|
|
|
{line}
|
|
|
|
|
|
</Text>
|
|
|
|
|
|
))}
|
2026-05-13 17:28:48 -04:00
|
|
|
|
{state.preLoadWarnings.map((warning) => (
|
|
|
|
|
|
<Text key={warning} color={theme.warning}>
|
2026-05-13 18:41:44 -04:00
|
|
|
|
{warning}
|
2026-05-13 17:28:48 -04:00
|
|
|
|
</Text>
|
|
|
|
|
|
))}
|
|
|
|
|
|
{showSearch ? (
|
|
|
|
|
|
<Text>
|
|
|
|
|
|
<Text color={theme.muted}>/ </Text>
|
|
|
|
|
|
<Text>
|
|
|
|
|
|
{state.search.query}
|
|
|
|
|
|
{state.search.editing ? '█' : ''}
|
|
|
|
|
|
</Text>
|
|
|
|
|
|
<Text color={theme.muted}> ({searchMatchCount} matches)</Text>
|
|
|
|
|
|
</Text>
|
|
|
|
|
|
) : null}
|
2026-05-13 18:41:44 -04:00
|
|
|
|
<Text> </Text>
|
2026-05-10 23:12:26 +02:00
|
|
|
|
{hiddenAbove > 0 ? <Text color={theme.muted}>↑ {hiddenAbove} more</Text> : null}
|
|
|
|
|
|
{rows.items.map((nodeId) => (
|
|
|
|
|
|
<PickerRow key={nodeId} state={state} nodeId={nodeId} width={width} theme={theme} />
|
|
|
|
|
|
))}
|
|
|
|
|
|
{hiddenBelow > 0 ? <Text color={theme.muted}>↓ {hiddenBelow} more</Text> : null}
|
2026-05-13 18:41:44 -04:00
|
|
|
|
{state.pendingConfirm === 'save-confirm' ? (
|
2026-05-13 17:28:48 -04:00
|
|
|
|
<Text color={theme.warning}>
|
2026-05-13 18:41:44 -04:00
|
|
|
|
{props.chrome.confirmSaveMessage
|
|
|
|
|
|
? props.chrome.confirmSaveMessage(state)
|
|
|
|
|
|
: 'Confirm save? Press Enter to confirm or Escape to go back.'}
|
2026-05-13 17:28:48 -04:00
|
|
|
|
</Text>
|
|
|
|
|
|
) : null}
|
2026-05-13 18:41:44 -04:00
|
|
|
|
{state.pendingConfirm === 'skip-empty' ? <Text color={theme.warning}>{skipEmptyMessage}</Text> : null}
|
2026-05-13 17:28:48 -04:00
|
|
|
|
{state.transientHint ? <Text color={theme.warning}>{state.transientHint.text}</Text> : null}
|
2026-05-10 23:12:26 +02:00
|
|
|
|
</Box>
|
2026-05-13 17:28:48 -04:00
|
|
|
|
<Text color={theme.active}>└</Text>
|
2026-05-10 23:12:26 +02:00
|
|
|
|
</Box>
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-05-13 18:41:44 -04:00
|
|
|
|
function renderInk(tree: ReactNode, options: TreePickerInkRenderOptions): TreePickerInkInstance {
|
2026-05-10 23:12:26 +02:00
|
|
|
|
return renderInkRuntime(tree, {
|
|
|
|
|
|
stdin: options.stdin as NodeJS.ReadStream | undefined,
|
|
|
|
|
|
stdout: options.stdout as NodeJS.WriteStream,
|
|
|
|
|
|
stderr: options.stderr as NodeJS.WriteStream,
|
|
|
|
|
|
exitOnCtrlC: options.exitOnCtrlC,
|
|
|
|
|
|
patchConsole: options.patchConsole,
|
|
|
|
|
|
maxFps: options.maxFps,
|
|
|
|
|
|
alternateScreen: options.alternateScreen,
|
2026-05-13 18:41:44 -04:00
|
|
|
|
}) as TreePickerInkInstance;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export interface RenderTreePickerOptions {
|
|
|
|
|
|
renderInk?: (tree: ReactNode, options: TreePickerInkRenderOptions) => TreePickerInkInstance;
|
|
|
|
|
|
scriptedModeHint?: string;
|
2026-05-10 23:12:26 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-05-13 18:41:44 -04:00
|
|
|
|
export async function renderTreePickerTui(
|
|
|
|
|
|
input: TreePickerRenderInput,
|
|
|
|
|
|
io: TreePickerTuiIo,
|
|
|
|
|
|
options: RenderTreePickerOptions = {},
|
|
|
|
|
|
): Promise<TreePickerResult> {
|
|
|
|
|
|
let result: TreePickerResult = { kind: 'quit' };
|
|
|
|
|
|
let instance: TreePickerInkInstance | null = null;
|
2026-05-10 23:12:26 +02:00
|
|
|
|
try {
|
|
|
|
|
|
instance = (options.renderInk ?? renderInk)(
|
2026-05-13 18:41:44 -04:00
|
|
|
|
<TreePickerApp
|
2026-05-10 23:12:26 +02:00
|
|
|
|
{...input}
|
|
|
|
|
|
terminalRows={(io.stdout as { rows?: number }).rows ?? process.stdout.rows ?? 24}
|
|
|
|
|
|
terminalWidth={io.stdout.columns ?? process.stdout.columns}
|
|
|
|
|
|
onExit={(next) => {
|
|
|
|
|
|
result = next;
|
|
|
|
|
|
instance?.unmount();
|
|
|
|
|
|
}}
|
|
|
|
|
|
/>,
|
|
|
|
|
|
{
|
|
|
|
|
|
stdin: io.stdin,
|
|
|
|
|
|
stdout: io.stdout,
|
|
|
|
|
|
stderr: io.stderr,
|
|
|
|
|
|
exitOnCtrlC: false,
|
|
|
|
|
|
patchConsole: false,
|
|
|
|
|
|
maxFps: 30,
|
2026-05-13 17:28:48 -04:00
|
|
|
|
alternateScreen: false,
|
2026-05-10 23:12:26 +02:00
|
|
|
|
},
|
|
|
|
|
|
);
|
|
|
|
|
|
await instance.waitUntilExit();
|
|
|
|
|
|
instance.unmount();
|
|
|
|
|
|
return result;
|
|
|
|
|
|
} catch (error) {
|
2026-05-13 18:41:44 -04:00
|
|
|
|
const hint = options.scriptedModeHint ?? 'Picker requires a TTY.';
|
|
|
|
|
|
io.stderr.write(`${hint} ${sanitizeTreePickerTuiError(error)}\n`);
|
2026-05-10 23:12:26 +02:00
|
|
|
|
return { kind: 'quit' };
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|