mirror of
https://github.com/Kaelio/ktx.git
synced 2026-06-22 08:38:08 +02:00
feat(cli): setup progress spinners, Tab-to-select, and banner polish (#296)
* fix(cli): double the height of the setup banner t crossbar
* fix(cli): unify setup multi-select hints and make Tab the select key
The six interactive multi-select surfaces in `ktx setup` documented three
different hint voices, one had no hint at all, and they named two different
select keys (Space vs Tab). Tab is the only key that can toggle selection
without colliding with type-to-search input, so make it the single documented
select key everywhere and compose every hint from one shared fragment
vocabulary in prompt-navigation.ts.
- Register `updateSettings({ aliases: { tab: 'space' } })` so Tab toggles flat
multiselects; the alias applies only to non-text prompts, leaving typed
search input (schema/Notion) untouched.
- Add the missing hint to the agent-targets prompt and drop the stray
"Space to select … Esc …" info line plus the now-dead writeSetupInfo helper.
- Replace the schema-scope ad-hoc hint with the searchable-multiselect voice
and standardize "filter" -> "search" vocabulary.
- Delete DEFAULT_TREE_PICKER_HELP_TEXT and the unused TreePickerChrome.helpText
seam; render the shared tree hint instead.
* refactor(cli): show LLM check progress for every setup backend
Rename runLlmHealthCheckWithProgress to validateModelWithProgress and
wrap the Claude subscription and Codex auth probes in the same spinner
progress as the Anthropic API and Vertex backends, so each backend shows
consistent "Checking <provider> LLM" output during setup.
* feat(cli): add ktx-orange progress spinners to setup steps
Add a shared runWithCliSpinner helper and a TTY-aware createCliSpinner:
an animated clack spinner in a terminal, and a static stderr-only spinner
before raw-mode pickers (the table tree picker and demo tour), where the
animated spinner's stdin grab would otherwise corrupt the next prompt.
Wrap the slow setup waits in progress spinners: managed runtime install,
embedding daemon start + first-run model download, embeddings health
check, the connection-test gate, and source validation / dbt clone /
Metabase discovery. Recolor every spinner frame from clack's magenta to
the ktx mascot orange (#FF8A4C) via the static helper and clack's
styleFrame option.
This commit is contained in:
parent
e1067bf734
commit
663eaff940
24 changed files with 402 additions and 120 deletions
|
|
@ -81,27 +81,39 @@ class KtxCliPromptCancelledError extends Error {
|
|||
}
|
||||
|
||||
export function createClackSpinner(): KtxCliSpinner {
|
||||
return spinner();
|
||||
// clack colors the animated spinner frame magenta by default; styleFrame
|
||||
// (typed in SpinnerOptions, absent from the README) recolors it ktx orange.
|
||||
return spinner({ styleFrame: orange });
|
||||
}
|
||||
|
||||
function magenta(text: string): string {
|
||||
return ansiColor(text, 35, 39);
|
||||
// ktx mascot orange (#FF8A4C) via 24-bit truecolor.
|
||||
function orange(text: string): string {
|
||||
if (!ansiEnabled()) {
|
||||
return text;
|
||||
}
|
||||
return `${ESC}[38;2;255;138;76m${text}${ESC}[39m`;
|
||||
}
|
||||
|
||||
function red(text: string): string {
|
||||
return ansiColor(text, 31, 39);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stderr-only, non-animated spinner. Use this instead of {@link createCliSpinner}
|
||||
* when the next step reads stdin in raw mode (an Ink TUI or a keypress wait):
|
||||
* the animated clack spinner seizes stdin via `@clack/core`'s `block()` and
|
||||
* leaves it dirty, which the following raw-mode reader misreads as a stray key.
|
||||
*/
|
||||
export function createStaticCliSpinner(io: KtxCliSpinnerIo): KtxCliSpinner {
|
||||
return {
|
||||
start(message) {
|
||||
io.stderr.write(`${magenta('◐')} ${message}\n`);
|
||||
io.stderr.write(`${orange('◐')} ${message}\n`);
|
||||
},
|
||||
message(message) {
|
||||
io.stderr.write(`${magenta('│')} ${message}\n`);
|
||||
io.stderr.write(`${orange('│')} ${message}\n`);
|
||||
},
|
||||
stop(message) {
|
||||
io.stderr.write(`${magenta('◇')} ${message}\n`);
|
||||
io.stderr.write(`${orange('◇')} ${message}\n`);
|
||||
},
|
||||
error(message) {
|
||||
io.stderr.write(`${red('■')} ${message}\n`);
|
||||
|
|
@ -109,6 +121,30 @@ export function createStaticCliSpinner(io: KtxCliSpinnerIo): KtxCliSpinner {
|
|||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Animated spinner in an interactive terminal, static `◐/◇/■` lines otherwise
|
||||
* (scripts, CI, piped output) so logs stay clean and uncluttered by frames.
|
||||
*/
|
||||
export function createCliSpinner(io: KtxCliIo): KtxCliSpinner {
|
||||
return io.stdout.isTTY === true ? createClackSpinner() : createStaticCliSpinner(io);
|
||||
}
|
||||
|
||||
export async function runWithCliSpinner<T>(
|
||||
spinner: KtxCliSpinner,
|
||||
text: { start: string; success: string; failure: string },
|
||||
run: () => Promise<T>,
|
||||
): Promise<T> {
|
||||
spinner.start(text.start);
|
||||
try {
|
||||
const value = await run();
|
||||
spinner.stop(text.success);
|
||||
return value;
|
||||
} catch (error) {
|
||||
spinner.error(text.failure);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
export function createClackPromptAdapter(): KtxCliPromptAdapter {
|
||||
return {
|
||||
async confirm(options) {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
import { parseDottedTableEntry } from './context/scan/enabled-tables.js';
|
||||
import type { KtxTableListEntry } from './context/scan/types.js';
|
||||
import type { KtxCliIo } from './cli-runtime.js';
|
||||
import { createStaticCliSpinner } from './clack.js';
|
||||
import { profileMark } from './startup-profile.js';
|
||||
import { withSearchableMultiselectNavigation } from './prompt-navigation.js';
|
||||
import {
|
||||
buildInitialState,
|
||||
buildPickerTree,
|
||||
|
|
@ -275,7 +277,9 @@ export async function pickDatabaseScope(
|
|||
let selectedSchemas = initialStageOneSchemas(args);
|
||||
while (true) {
|
||||
const pickedSchemas = await args.prompts.autocompleteMultiselect({
|
||||
message: `Choose ${args.schemaNounPlural} to enable for ${args.connectionId}\nType to filter. Space to select. Enter when done.`,
|
||||
message: withSearchableMultiselectNavigation(
|
||||
`Choose ${args.schemaNounPlural} to enable for ${args.connectionId}`,
|
||||
),
|
||||
placeholder: `Search ${args.schemaNounPlural}`,
|
||||
options: schemaOptions(args),
|
||||
initialValues: selectedSchemas,
|
||||
|
|
@ -286,7 +290,7 @@ export async function pickDatabaseScope(
|
|||
}
|
||||
selectedSchemas = pickedSchemas;
|
||||
if (selectedSchemas.length === 0) {
|
||||
io.stderr.write(`Nothing selected - type to filter, or Escape to skip ${args.schemaNoun} scope.\n`);
|
||||
io.stderr.write(`Nothing selected - type to search, or Escape to skip ${args.schemaNoun} scope.\n`);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -304,7 +308,19 @@ export async function pickDatabaseScope(
|
|||
continue;
|
||||
}
|
||||
|
||||
const discovered = await args.listTablesForSchemas(selectedSchemas);
|
||||
// Static (stderr-only) spinner: the stage-two table picker below is a raw-mode
|
||||
// Ink TUI, and an animated clack spinner would leave stdin dirty so Ink reads a
|
||||
// stray Escape and exits immediately.
|
||||
const tablesSpinner = createStaticCliSpinner(io);
|
||||
tablesSpinner.start(`Listing tables in ${selectedSchemas.length} ${selectedNoun}…`);
|
||||
let discovered: KtxTableListEntry[];
|
||||
try {
|
||||
discovered = await args.listTablesForSchemas(selectedSchemas);
|
||||
} catch (error) {
|
||||
tablesSpinner.error('Could not list tables');
|
||||
throw error;
|
||||
}
|
||||
tablesSpinner.stop(`Found ${discovered.length} ${discovered.length === 1 ? 'table' : 'tables'}`);
|
||||
if (action === 'save' && args.existing.enabledTables.length === 0) {
|
||||
return {
|
||||
kind: 'selected',
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import type { KtxEmbeddingConfig } from './llm/types.js';
|
||||
import type { KtxCliIo } from './cli-runtime.js';
|
||||
import { writePrefixedLines } from './clack.js';
|
||||
import { createCliSpinner } from './clack.js';
|
||||
import {
|
||||
ensureManagedPythonCommandRuntime,
|
||||
type KtxManagedPythonInstallPolicy,
|
||||
|
|
@ -66,15 +66,22 @@ export async function ensureManagedLocalEmbeddingsDaemon(
|
|||
io: options.io,
|
||||
feature: 'local-embeddings',
|
||||
});
|
||||
const daemon = await startDaemon({
|
||||
cliVersion: options.cliVersion,
|
||||
projectDir: options.projectDir,
|
||||
features: ['local-embeddings'],
|
||||
force: false,
|
||||
});
|
||||
|
||||
const spinner = createCliSpinner(options.io);
|
||||
spinner.start('Starting ktx embedding daemon (first run downloads the model)…');
|
||||
let daemon: ManagedPythonDaemonStartResult;
|
||||
try {
|
||||
daemon = await startDaemon({
|
||||
cliVersion: options.cliVersion,
|
||||
projectDir: options.projectDir,
|
||||
features: ['local-embeddings'],
|
||||
force: false,
|
||||
});
|
||||
} catch (error) {
|
||||
spinner.error('ktx embedding daemon failed to start');
|
||||
throw error;
|
||||
}
|
||||
const verb = daemon.status === 'started' ? 'Started' : 'Using';
|
||||
writePrefixedLines((chunk) => options.io.stderr.write(chunk), `${verb} ktx daemon: ${daemon.baseUrl}`);
|
||||
spinner.stop(`${verb} ktx daemon: ${daemon.baseUrl}`);
|
||||
|
||||
return {
|
||||
baseUrl: daemon.baseUrl,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { createPythonSemanticLayerComputePort, type KtxSemanticLayerComputePort } from './context/daemon/semantic-layer-compute.js';
|
||||
import type { KtxCliIo } from './cli-runtime.js';
|
||||
import { createClackPromptAdapter, createStaticCliSpinner, type KtxCliSpinner } from './clack.js';
|
||||
import { createClackPromptAdapter, createCliSpinner, type KtxCliSpinner } from './clack.js';
|
||||
import {
|
||||
installManagedPythonRuntime,
|
||||
readManagedPythonRuntimeStatus,
|
||||
|
|
@ -105,7 +105,7 @@ export async function ensureManagedPythonCommandRuntime(
|
|||
}
|
||||
}
|
||||
|
||||
const progress = (options.spinner ?? (() => createStaticCliSpinner(options.io)))();
|
||||
const progress = (options.spinner ?? (() => createCliSpinner(options.io)))();
|
||||
progress.start(`Installing ktx Python runtime (${feature}) with uv...`);
|
||||
try {
|
||||
const installed = await installRuntime({
|
||||
|
|
|
|||
|
|
@ -1,5 +1,50 @@
|
|||
const MULTISELECT_MENU_NAVIGATION_HINT =
|
||||
'Use Up/Down to move, Space to select or unselect, Enter to confirm, Escape to go back, or Ctrl+C to exit.';
|
||||
/** @internal */
|
||||
export const MULTISELECT_NAVIGATION_FRAGMENTS = {
|
||||
move: 'Up/Down to move',
|
||||
expand: 'Right/Left to expand or collapse',
|
||||
select: 'Tab to select or unselect',
|
||||
search: 'Type to search',
|
||||
confirm: 'Enter to confirm',
|
||||
back: 'Escape to go back',
|
||||
backSearchableTree: 'Escape to clear search or go back',
|
||||
exit: 'Ctrl+C to exit',
|
||||
} as const;
|
||||
|
||||
function composeNavigationHint(fragments: readonly string[]): string {
|
||||
return `${fragments.join(', ')}.`;
|
||||
}
|
||||
|
||||
const fragment = MULTISELECT_NAVIGATION_FRAGMENTS;
|
||||
|
||||
/** @internal */
|
||||
export const FLAT_MULTISELECT_NAVIGATION_HINT = composeNavigationHint([
|
||||
fragment.move,
|
||||
fragment.select,
|
||||
fragment.confirm,
|
||||
fragment.back,
|
||||
fragment.exit,
|
||||
]);
|
||||
|
||||
/** @internal */
|
||||
export const SEARCHABLE_MULTISELECT_NAVIGATION_HINT = composeNavigationHint([
|
||||
fragment.move,
|
||||
fragment.select,
|
||||
fragment.search,
|
||||
fragment.confirm,
|
||||
fragment.back,
|
||||
fragment.exit,
|
||||
]);
|
||||
|
||||
export const TREE_PICKER_NAVIGATION_HINT = composeNavigationHint([
|
||||
fragment.move,
|
||||
fragment.expand,
|
||||
fragment.select,
|
||||
fragment.search,
|
||||
fragment.confirm,
|
||||
fragment.backSearchableTree,
|
||||
fragment.exit,
|
||||
]);
|
||||
|
||||
const TEXT_INPUT_NAVIGATION_HINT = 'Press Escape to go back.';
|
||||
|
||||
function removeTrailingBlankLines(message: string): string {
|
||||
|
|
@ -51,10 +96,17 @@ export function withMenuOptionsSpacing<T extends { message: string }>(options: T
|
|||
}
|
||||
|
||||
export function withMultiselectNavigation(message: string): string {
|
||||
if (message.includes(MULTISELECT_MENU_NAVIGATION_HINT)) {
|
||||
if (message.includes(FLAT_MULTISELECT_NAVIGATION_HINT)) {
|
||||
return message;
|
||||
}
|
||||
return `${message}\n${MULTISELECT_MENU_NAVIGATION_HINT}`;
|
||||
return `${message}\n${FLAT_MULTISELECT_NAVIGATION_HINT}`;
|
||||
}
|
||||
|
||||
export function withSearchableMultiselectNavigation(message: string): string {
|
||||
if (message.includes(SEARCHABLE_MULTISELECT_NAVIGATION_HINT)) {
|
||||
return message;
|
||||
}
|
||||
return `${message}\n${SEARCHABLE_MULTISELECT_NAVIGATION_HINT}`;
|
||||
}
|
||||
|
||||
export function withTextInputNavigation(message: string): string {
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ import {
|
|||
type KtxSetupPromptOption,
|
||||
} from './setup-prompts.js';
|
||||
import { readKtxMcpDaemonStatus } from './managed-mcp-daemon.js';
|
||||
import { withMultiselectNavigation } from './prompt-navigation.js';
|
||||
|
||||
export type KtxAgentTarget = 'claude-code' | 'claude-desktop' | 'codex' | 'cursor' | 'opencode' | 'universal';
|
||||
export type KtxAgentScope = 'project' | 'global' | 'local';
|
||||
|
|
@ -84,14 +85,6 @@ interface KtxCliLauncher {
|
|||
args: string[];
|
||||
}
|
||||
|
||||
function writeSetupInfo(io: KtxCliIo, message: string): void {
|
||||
if (isWritableTtyOutput(io.stdout)) {
|
||||
log.info(message, { output: io.stdout });
|
||||
return;
|
||||
}
|
||||
io.stdout.write(`${message}\n`);
|
||||
}
|
||||
|
||||
function writeSetupStep(io: KtxCliIo, message: string): void {
|
||||
if (isWritableTtyOutput(io.stdout)) {
|
||||
log.step(message, { output: io.stdout });
|
||||
|
|
@ -1097,9 +1090,6 @@ export async function runKtxSetupAgentsStep(
|
|||
}
|
||||
|
||||
const prompts = deps.prompts ?? createPromptAdapter();
|
||||
if (args.inputMode === 'auto' && args.target === undefined) {
|
||||
writeSetupInfo(io, 'Space to select, Enter to confirm, Esc to go back.');
|
||||
}
|
||||
const mode =
|
||||
args.inputMode === 'disabled'
|
||||
? args.mode
|
||||
|
|
@ -1135,7 +1125,7 @@ export async function runKtxSetupAgentsStep(
|
|||
: args.inputMode === 'disabled'
|
||||
? []
|
||||
: ((await prompts.multiselect({
|
||||
message: 'Which agent targets should ktx install?',
|
||||
message: withMultiselectNavigation('Which agent targets should ktx install?'),
|
||||
options: [
|
||||
{ value: 'claude-code', label: 'Claude Code' },
|
||||
{ value: 'claude-desktop', label: 'Claude Desktop' },
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ interface KtxBannerRow {
|
|||
|
||||
const WORDMARK: readonly KtxBannerRow[] = [
|
||||
{ art: '███ ███', rgb: [253, 186, 116], ansi256: 215 },
|
||||
{ art: '███ ▄██▀ ▀▀███▀▀ ▀██▄ ▄██▀', rgb: [251, 146, 60], ansi256: 214 },
|
||||
{ art: '███ ▄██▀ ███████ ▀██▄ ▄██▀', rgb: [251, 146, 60], ansi256: 214 },
|
||||
{ art: '███▄██▀ ███ ▀████▀', rgb: [249, 115, 22], ansi256: 208 },
|
||||
{ art: '███▀██▄ ███ ▄████▄', rgb: [234, 88, 12], ansi256: 202 },
|
||||
{ art: '███ ▀██▄ ███ ▄██▀ ▀██▄', rgb: [194, 65, 12], ansi256: 166 },
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import { type KtxLocalProject, loadKtxProject } from './context/project/project.
|
|||
import { markKtxSetupStateStepComplete, readKtxSetupState } from './context/project/setup-config.js';
|
||||
import { serializeKtxProjectConfig } from './context/project/config.js';
|
||||
import type { KtxCliIo } from './cli-runtime.js';
|
||||
import { errorMessage, writePrefixedLines } from './clack.js';
|
||||
import { createCliSpinner, errorMessage, writePrefixedLines } from './clack.js';
|
||||
import { formatErrorDetail } from './telemetry/scrubber.js';
|
||||
import { buildPublicIngestPlan } from './public-ingest.js';
|
||||
import { runKtxConnection } from './connection.js';
|
||||
|
|
@ -320,13 +320,22 @@ async function testRequiredConnections(
|
|||
project: KtxLocalProject,
|
||||
targets: KtxSetupContextTargets,
|
||||
testConnection: (projectDir: string, connectionId: string, io: KtxCliIo) => Promise<number>,
|
||||
io: KtxCliIo,
|
||||
): Promise<ConnectionGateResult> {
|
||||
const failures: ConnectionGateFailure[] = [];
|
||||
for (const connectionId of requiredConnectionIds(targets)) {
|
||||
const connectionIds = requiredConnectionIds(targets);
|
||||
for (const [index, connectionId] of connectionIds.entries()) {
|
||||
const driver = connectorTypeLabel(project, connectionId);
|
||||
const counter = connectionIds.length > 1 ? ` (${index + 1}/${connectionIds.length})` : '';
|
||||
const spinner = createCliSpinner(io);
|
||||
spinner.start(`Testing connection ${connectionId}${counter}…`);
|
||||
const buffered: BufferedCommandIo = createBufferedCommandIo();
|
||||
const exitCode = await testConnection(projectDir, connectionId, buffered);
|
||||
if (exitCode !== 0) {
|
||||
failures.push({ connectionId, driver: connectorTypeLabel(project, connectionId) });
|
||||
if (exitCode === 0) {
|
||||
spinner.stop(`Connection ${connectionId} (${driver}) is reachable`);
|
||||
} else {
|
||||
spinner.error(`Connection ${connectionId} (${driver}) is not reachable`);
|
||||
failures.push({ connectionId, driver });
|
||||
}
|
||||
}
|
||||
return failures.length === 0 ? { ok: true } : { ok: false, failures };
|
||||
|
|
@ -826,7 +835,7 @@ export async function runKtxSetupContextStep(
|
|||
// error text.
|
||||
const testConnection = deps.testConnection ?? defaultGateTestConnection;
|
||||
while (true) {
|
||||
const gate = await testRequiredConnections(args.projectDir, project, targets, testConnection);
|
||||
const gate = await testRequiredConnections(args.projectDir, project, targets, testConnection, io);
|
||||
if (gate.ok) {
|
||||
return await runBuild(args, io, deps, project, targets);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import type { KtxCliIo } from './cli-runtime.js';
|
||||
import { createStaticCliSpinner, runWithCliSpinner } from './clack.js';
|
||||
import type {
|
||||
ContextBuildTargetState,
|
||||
ContextBuildViewState,
|
||||
|
|
@ -348,7 +349,14 @@ export async function runDemoTour(
|
|||
const ensureProject = deps.ensureProject ?? ensureSeededDemoProject;
|
||||
|
||||
const projectDir = defaultDemoProjectDir();
|
||||
await ensureProject({ projectDir, force: false, io, cliVersion: args.cliVersion });
|
||||
// Static (stderr-only) spinner: the demo navigation below reads stdin in raw mode,
|
||||
// and an animated clack spinner would leave stdin dirty so the first keypress wait
|
||||
// sees a stray key and skips the intro.
|
||||
await runWithCliSpinner(
|
||||
createStaticCliSpinner(io),
|
||||
{ start: 'Preparing demo project…', success: 'Demo project ready', failure: 'Could not prepare demo project' },
|
||||
() => ensureProject({ projectDir, force: false, io, cliVersion: args.cliVersion }),
|
||||
);
|
||||
|
||||
io.stdout.write(renderDemoBanner(projectDir) + '\n');
|
||||
io.stdout.write(`\n│ ${dim('Press Enter to continue, Escape to go back')}\n└\n`);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import { markKtxSetupStateStepComplete, readKtxSetupState } from './context/proj
|
|||
import type { KtxEmbeddingConfig } from './llm/types.js';
|
||||
import { type KtxEmbeddingHealthCheckResult, runKtxEmbeddingHealthCheck } from './llm/embedding-health.js';
|
||||
import type { KtxCliIo } from './cli-runtime.js';
|
||||
import { createStaticCliSpinner, errorMessage, writePrefixedLines, type KtxCliSpinner } from './clack.js';
|
||||
import { createCliSpinner, errorMessage, writePrefixedLines, type KtxCliSpinner } from './clack.js';
|
||||
import {
|
||||
ensureManagedLocalEmbeddingsDaemon,
|
||||
managedLocalEmbeddingHealthConfig,
|
||||
|
|
@ -444,7 +444,7 @@ export async function runKtxSetupEmbeddingsStep(
|
|||
dimensions,
|
||||
credentialValue,
|
||||
});
|
||||
const healthSpinner = (deps.spinner ?? (() => createStaticCliSpinner(io)))();
|
||||
const healthSpinner = (deps.spinner ?? (() => createCliSpinner(io)))();
|
||||
const progress = startHealthCheckProgress(healthSpinner, healthCheckStartText(selectedBackend, model, dimensions));
|
||||
let health: KtxEmbeddingHealthCheckResult;
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -313,13 +313,13 @@ function buildVertexHealthConfig(vertex: { project?: string; location: string },
|
|||
};
|
||||
}
|
||||
|
||||
type LlmHealthProvider = 'Anthropic API' | 'Vertex AI';
|
||||
type LlmCheckProvider = 'Anthropic API' | 'Vertex AI' | 'Claude subscription' | 'Codex';
|
||||
|
||||
function llmHealthCheckStartText(provider: LlmHealthProvider, model: string): string {
|
||||
function llmCheckStartText(provider: LlmCheckProvider, model: string): string {
|
||||
return `Checking ${provider} LLM (${model}).`;
|
||||
}
|
||||
|
||||
function startLlmHealthCheckProgress(
|
||||
function startLlmCheckProgress(
|
||||
spinner: KtxCliSpinner,
|
||||
message: string,
|
||||
): { succeed(msg: string): void; fail(msg: string): void } {
|
||||
|
|
@ -334,30 +334,26 @@ function startLlmHealthCheckProgress(
|
|||
};
|
||||
}
|
||||
|
||||
async function runLlmHealthCheckWithProgress(
|
||||
config: KtxLlmConfig,
|
||||
provider: LlmHealthProvider,
|
||||
async function validateModelWithProgress(
|
||||
provider: LlmCheckProvider,
|
||||
model: string,
|
||||
healthCheck: (config: KtxLlmConfig) => Promise<KtxLlmHealthCheckResult>,
|
||||
deps: KtxSetupModelDeps,
|
||||
): Promise<KtxLlmHealthCheckResult> {
|
||||
const progress = startLlmHealthCheckProgress(
|
||||
(deps.spinner ?? createClackSpinner)(),
|
||||
llmHealthCheckStartText(provider, model),
|
||||
);
|
||||
let health: KtxLlmHealthCheckResult;
|
||||
run: () => Promise<PresetModelValidationResult>,
|
||||
): Promise<PresetModelValidationResult> {
|
||||
const progress = startLlmCheckProgress((deps.spinner ?? createClackSpinner)(), llmCheckStartText(provider, model));
|
||||
let result: PresetModelValidationResult;
|
||||
try {
|
||||
health = await healthCheck(config);
|
||||
result = await run();
|
||||
} catch (error) {
|
||||
progress.fail('LLM test failed');
|
||||
throw error;
|
||||
}
|
||||
if (health.ok) {
|
||||
if (result.ok) {
|
||||
progress.succeed(`LLM test passed (${provider}, ${model})`);
|
||||
} else {
|
||||
progress.fail('LLM test failed');
|
||||
}
|
||||
return health;
|
||||
return result;
|
||||
}
|
||||
|
||||
function formatVertexHealthFailure(message: string, vertex: { project?: string; location: string }): string {
|
||||
|
|
@ -857,14 +853,8 @@ export async function runKtxSetupAnthropicModelStep(
|
|||
const preset = presetForBackend('vertex');
|
||||
const validation = await validatePresetModels(
|
||||
preset,
|
||||
async (model) =>
|
||||
runLlmHealthCheckWithProgress(
|
||||
buildVertexHealthConfig(vertex.values, model),
|
||||
'Vertex AI',
|
||||
model,
|
||||
healthCheck,
|
||||
deps,
|
||||
),
|
||||
(model) =>
|
||||
validateModelWithProgress('Vertex AI', model, deps, () => healthCheck(buildVertexHealthConfig(vertex.values, model))),
|
||||
io,
|
||||
);
|
||||
if (validation.status !== 'ready') {
|
||||
|
|
@ -889,7 +879,10 @@ export async function runKtxSetupAnthropicModelStep(
|
|||
const probe = deps.claudeCodeAuthProbe ?? runClaudeCodeAuthProbe;
|
||||
const validation = await validatePresetModels(
|
||||
preset,
|
||||
async (model) => probe({ projectDir: args.projectDir, model, env: deps.env ?? process.env }),
|
||||
(model) =>
|
||||
validateModelWithProgress('Claude subscription', model, deps, () =>
|
||||
probe({ projectDir: args.projectDir, model, env: deps.env ?? process.env }),
|
||||
),
|
||||
io,
|
||||
);
|
||||
if (validation.status !== 'ready') {
|
||||
|
|
@ -912,7 +905,11 @@ export async function runKtxSetupAnthropicModelStep(
|
|||
if (backendChoice.backend === 'codex') {
|
||||
const preset = presetForBackend('codex');
|
||||
const probe = deps.codexAuthProbe ?? runCodexAuthProbe;
|
||||
const validation = await validatePresetModels(preset, async (model) => probe({ projectDir: args.projectDir, model }), io);
|
||||
const validation = await validatePresetModels(
|
||||
preset,
|
||||
(model) => validateModelWithProgress('Codex', model, deps, () => probe({ projectDir: args.projectDir, model })),
|
||||
io,
|
||||
);
|
||||
if (validation.status !== 'ready') {
|
||||
io.stderr.write(`${validation.message}\n`);
|
||||
return { status: 'failed', projectDir: args.projectDir };
|
||||
|
|
@ -937,13 +934,9 @@ export async function runKtxSetupAnthropicModelStep(
|
|||
const preset = presetForBackend('anthropic');
|
||||
const validation = await validatePresetModels(
|
||||
preset,
|
||||
async (model) =>
|
||||
runLlmHealthCheckWithProgress(
|
||||
buildAnthropicHealthConfig(credential.value, model),
|
||||
'Anthropic API',
|
||||
model,
|
||||
healthCheck,
|
||||
deps,
|
||||
(model) =>
|
||||
validateModelWithProgress('Anthropic API', model, deps, () =>
|
||||
healthCheck(buildAnthropicHealthConfig(credential.value, model)),
|
||||
),
|
||||
io,
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import { updateSettings } from '@clack/core';
|
||||
import {
|
||||
autocomplete,
|
||||
autocompleteMultiselect,
|
||||
|
|
@ -19,6 +20,11 @@ import { renderKtxSetupBanner } from './setup-banner.js';
|
|||
import { revealPassword } from './reveal-password-prompt.js';
|
||||
import { withSetupInterruptConfirmation } from './setup-interrupt.js';
|
||||
|
||||
// clack remaps Tab to Space only on non-text prompts (flat multiselect/select/
|
||||
// confirm); text inputs and autocomplete search set _track, so typed Tab is
|
||||
// untouched. This makes Tab the single documented select key across setup.
|
||||
updateSettings({ aliases: { tab: 'space' } });
|
||||
|
||||
export interface KtxSetupPromptOption<Value extends string = string> {
|
||||
value: Value;
|
||||
label: string;
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ import { type KtxProjectConfig, type KtxProjectConnectionConfig, serializeKtxPro
|
|||
import { loadKtxProject } from './context/project/project.js';
|
||||
import { markKtxSetupStateStepComplete } from './context/project/setup-config.js';
|
||||
import type { KtxCliIo } from './cli-runtime.js';
|
||||
import { errorMessage, writePrefixedLines } from './clack.js';
|
||||
import { createCliSpinner, errorMessage, writePrefixedLines } from './clack.js';
|
||||
import { pickNotionRootPages } from './notion-page-picker.js';
|
||||
import { runKtxSourceMapping } from './source-mapping.js';
|
||||
import {
|
||||
|
|
@ -975,16 +975,20 @@ async function chooseMetabaseDatabaseId(input: {
|
|||
state: SourcePromptState;
|
||||
prompts: KtxSetupSourcesPromptAdapter;
|
||||
deps: KtxSetupSourcesDeps;
|
||||
io: KtxCliIo;
|
||||
}): Promise<number | 'back'> {
|
||||
const sourceUrl = input.state.sourceUrl;
|
||||
const sourceApiKeyRef = input.state.sourceApiKeyRef;
|
||||
if (sourceUrl && sourceApiKeyRef) {
|
||||
const discoverSpinner = createCliSpinner(input.io);
|
||||
discoverSpinner.start('Discovering Metabase databases…');
|
||||
try {
|
||||
const discovered = await (input.deps.discoverMetabaseDatabases ?? defaultDiscoverMetabaseDatabases)({
|
||||
sourceUrl,
|
||||
sourceApiKeyRef,
|
||||
sourceConnectionId: input.state.sourceConnectionId ?? 'metabase-main',
|
||||
});
|
||||
discoverSpinner.stop(`Found ${discovered.length} ${discovered.length === 1 ? 'database' : 'databases'}`);
|
||||
if (discovered.length === 1) {
|
||||
return discovered[0].id;
|
||||
}
|
||||
|
|
@ -1008,6 +1012,7 @@ async function chooseMetabaseDatabaseId(input: {
|
|||
} catch {
|
||||
// Discovery is a convenience. Fall back to the raw id prompt when credentials
|
||||
// are unavailable locally or the Metabase API cannot be reached yet.
|
||||
discoverSpinner.error('Could not reach Metabase — enter the database id manually');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1148,6 +1153,8 @@ async function promptForInteractiveSource(
|
|||
if (currentState.sourceLocation === 'path' && currentState.sourcePath) {
|
||||
scanDir = currentState.sourcePath;
|
||||
} else if (currentState.sourceLocation === 'git' && currentState.sourceGitUrl) {
|
||||
const cloneSpinner = createCliSpinner(io);
|
||||
cloneSpinner.start('Cloning repository to scan for dbt projects…');
|
||||
try {
|
||||
const cacheDir = await mkdtemp(join(tmpdir(), 'ktx-setup-dbt-scan-'));
|
||||
const authToken = currentState.sourceAuthTokenRef
|
||||
|
|
@ -1160,7 +1167,9 @@ async function promptForInteractiveSource(
|
|||
branch: currentState.sourceBranch ?? 'main',
|
||||
});
|
||||
scanDir = cacheDir;
|
||||
cloneSpinner.stop('Repository cloned');
|
||||
} catch {
|
||||
cloneSpinner.error('Could not clone repository');
|
||||
// Clone failed — fall through to manual prompt
|
||||
}
|
||||
}
|
||||
|
|
@ -1256,6 +1265,7 @@ async function promptForInteractiveSource(
|
|||
state,
|
||||
prompts,
|
||||
deps: { discoverMetabaseDatabases: discoverMetabaseDatabaseList },
|
||||
io,
|
||||
});
|
||||
if (databaseId === 'back') return 'back';
|
||||
state.metabaseDatabaseId = databaseId;
|
||||
|
|
@ -1790,15 +1800,25 @@ async function validateSourceConnectionAndMapping(input: {
|
|||
io: KtxCliIo;
|
||||
deps: KtxSetupSourcesDeps;
|
||||
}): Promise<ValidateResult> {
|
||||
const validation = await validateSource(
|
||||
input.source,
|
||||
{ projectDir: input.args.projectDir, connectionId: input.connectionId, connection: input.connection },
|
||||
input.deps,
|
||||
);
|
||||
const validateSpinner = createCliSpinner(input.io);
|
||||
validateSpinner.start(`Validating ${sourceLabel(input.source)} source…`);
|
||||
let validation: SourceValidationResult;
|
||||
try {
|
||||
validation = await validateSource(
|
||||
input.source,
|
||||
{ projectDir: input.args.projectDir, connectionId: input.connectionId, connection: input.connection },
|
||||
input.deps,
|
||||
);
|
||||
} catch (error) {
|
||||
validateSpinner.error(`${sourceLabel(input.source)} source validation failed`);
|
||||
throw error;
|
||||
}
|
||||
if (!validation.ok) {
|
||||
validateSpinner.error(`${sourceLabel(input.source)} source validation failed`);
|
||||
input.io.stderr.write(`${validation.message}\n`);
|
||||
return { status: 'failed' };
|
||||
}
|
||||
validateSpinner.stop(`${sourceLabel(input.source)} source validated`);
|
||||
|
||||
if (input.source === 'metabase' || input.source === 'looker') {
|
||||
input.prompts.log?.(`Validating ${sourceLabel(input.source)} mapping...`);
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import {
|
|||
type PickerState,
|
||||
} from './tree-picker-state.js';
|
||||
import type { KtxCliIo } from './cli-runtime.js';
|
||||
import { TREE_PICKER_NAVIGATION_HINT } from './prompt-navigation.js';
|
||||
|
||||
const COLOR_THEME = {
|
||||
text: 'white',
|
||||
|
|
@ -31,9 +32,6 @@ const NO_COLOR_THEME = {
|
|||
|
||||
type TreePickerTheme = Record<keyof typeof COLOR_THEME, string>;
|
||||
|
||||
const DEFAULT_TREE_PICKER_HELP_TEXT =
|
||||
'Up/Down to move, Right/Left to expand or collapse, Tab to select, Type to search, Enter to confirm, Escape to clear search or go back, Ctrl+C to exit.';
|
||||
|
||||
const DEFAULT_SKIP_EMPTY_MESSAGE =
|
||||
'Nothing selected. Skip this step? Press Enter to skip or Escape to go back.';
|
||||
|
||||
|
|
@ -60,7 +58,6 @@ export type TreePickerResult = { kind: 'save'; selectedIds: string[] } | { kind:
|
|||
|
||||
export interface TreePickerChrome {
|
||||
title: string;
|
||||
helpText?: string;
|
||||
subtitleLines?: readonly string[];
|
||||
warningLines?: readonly string[];
|
||||
confirmSaveMessage?: (state: PickerState) => string;
|
||||
|
|
@ -221,7 +218,6 @@ export function TreePickerApp(props: TreePickerAppProps): ReactNode {
|
|||
const hiddenBelow = Math.max(0, visibleIds.length - rows.offset - rows.items.length);
|
||||
const searchMatchCount = filterTree(state).visibleIds.size;
|
||||
const width = resolveTreePickerWidth(props.terminalWidth);
|
||||
const helpText = props.chrome.helpText ?? DEFAULT_TREE_PICKER_HELP_TEXT;
|
||||
const skipEmptyMessage = props.chrome.skipEmptyMessage ?? DEFAULT_SKIP_EMPTY_MESSAGE;
|
||||
|
||||
stateRef.current = state;
|
||||
|
|
@ -284,7 +280,7 @@ export function TreePickerApp(props: TreePickerAppProps): ReactNode {
|
|||
borderColor={theme.active}
|
||||
paddingLeft={1}
|
||||
>
|
||||
<Text color={theme.muted}>{helpText}</Text>
|
||||
<Text color={theme.muted}>{TREE_PICKER_NAVIGATION_HINT}</Text>
|
||||
<Text> </Text>
|
||||
{(props.chrome.subtitleLines ?? []).map((line, idx) => (
|
||||
<Text key={`subtitle-${idx}`} color={theme.muted}>
|
||||
|
|
@ -304,7 +300,7 @@ export function TreePickerApp(props: TreePickerAppProps): ReactNode {
|
|||
<Text>
|
||||
<Text color={theme.muted}>Search: </Text>
|
||||
{state.isNavigating ? (
|
||||
<Text color={theme.muted}>{state.search.query || '(type to filter)'}</Text>
|
||||
<Text color={theme.muted}>{state.search.query || '(type to search)'}</Text>
|
||||
) : (
|
||||
<Text>
|
||||
{state.search.query}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue