mirror of
https://github.com/Kaelio/ktx.git
synced 2026-06-13 08:15:14 +02:00
* 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.
251 lines
7.7 KiB
TypeScript
251 lines
7.7 KiB
TypeScript
import { updateSettings } from '@clack/core';
|
|
import {
|
|
autocomplete,
|
|
autocompleteMultiselect,
|
|
cancel,
|
|
confirm,
|
|
intro,
|
|
isCancel,
|
|
log,
|
|
multiselect,
|
|
note,
|
|
select,
|
|
text,
|
|
} from '@clack/prompts';
|
|
import type { KtxCliIo } from './cli-runtime.js';
|
|
import { unicodeSupported } from './io/symbols.js';
|
|
import { colorDepthForOutput, isWritableTtyOutput } from './io/tty.js';
|
|
import { withMenuOptionsSpacing, withTextInputNavigation } from './prompt-navigation.js';
|
|
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;
|
|
hint?: string;
|
|
disabled?: boolean;
|
|
}
|
|
|
|
interface KtxSetupSelectOptions<Value extends string = string> {
|
|
message: string;
|
|
options: Array<KtxSetupPromptOption<Value>>;
|
|
initialValue?: Value;
|
|
maxItems?: number;
|
|
}
|
|
|
|
interface KtxSetupMultiselectOptions<Value extends string = string> {
|
|
message: string;
|
|
options: Array<KtxSetupPromptOption<Value>>;
|
|
required?: boolean;
|
|
initialValues?: Value[];
|
|
maxItems?: number;
|
|
cursorAt?: Value;
|
|
}
|
|
|
|
interface KtxSetupAutocompleteOptions<Value extends string = string> {
|
|
message: string;
|
|
options: Array<KtxSetupPromptOption<Value>>;
|
|
placeholder?: string;
|
|
maxItems?: number;
|
|
}
|
|
|
|
interface KtxSetupAutocompleteMultiselectOptions<Value extends string = string> {
|
|
message: string;
|
|
options: Array<KtxSetupPromptOption<Value>>;
|
|
placeholder?: string;
|
|
required?: boolean;
|
|
maxItems?: number;
|
|
initialValues?: Value[];
|
|
}
|
|
|
|
interface KtxSetupTextOptions {
|
|
message: string;
|
|
placeholder?: string;
|
|
initialValue?: string;
|
|
defaultValue?: string;
|
|
}
|
|
|
|
interface KtxSetupPasswordOptions {
|
|
message: string;
|
|
mask?: string;
|
|
}
|
|
|
|
export interface KtxSetupPromptAdapter {
|
|
select(options: KtxSetupSelectOptions): Promise<string>;
|
|
multiselect(options: KtxSetupMultiselectOptions): Promise<string[]>;
|
|
autocomplete(options: KtxSetupAutocompleteOptions): Promise<string>;
|
|
autocompleteMultiselect(options: KtxSetupAutocompleteMultiselectOptions): Promise<string[]>;
|
|
text(options: KtxSetupTextOptions): Promise<string | undefined>;
|
|
password(options: KtxSetupPasswordOptions): Promise<string | undefined>;
|
|
cancel(message: string): void;
|
|
log(message: string): void;
|
|
}
|
|
|
|
export interface KtxSetupPromptAdapterOptions {
|
|
selectCancelValue: 'back' | 'exit';
|
|
multiselectCancelValue?: 'back';
|
|
confirmEmptyOptionalMultiselect?: boolean;
|
|
cancelOnSelectCancel?: boolean;
|
|
cancelOnMultiselectCancel?: boolean;
|
|
cancelMessage?: string;
|
|
}
|
|
|
|
const DEFAULT_SETUP_CANCEL_MESSAGE = 'Setup cancelled.';
|
|
|
|
export function createKtxSetupPromptAdapter(options: KtxSetupPromptAdapterOptions): KtxSetupPromptAdapter {
|
|
const cancelMessage = options.cancelMessage ?? DEFAULT_SETUP_CANCEL_MESSAGE;
|
|
const cancelOnSelectCancel = options.cancelOnSelectCancel ?? true;
|
|
const cancelOnMultiselectCancel = options.cancelOnMultiselectCancel ?? true;
|
|
const multiselectCancelValue = options.multiselectCancelValue ?? 'back';
|
|
|
|
return {
|
|
async select(promptOptions) {
|
|
const value = await withSetupInterruptConfirmation(() => select(withMenuOptionsSpacing(promptOptions)));
|
|
if (isCancel(value)) {
|
|
if (cancelOnSelectCancel) {
|
|
cancel(cancelMessage);
|
|
}
|
|
return options.selectCancelValue;
|
|
}
|
|
return String(value);
|
|
},
|
|
async multiselect(promptOptions) {
|
|
while (true) {
|
|
const value = await withSetupInterruptConfirmation(() => multiselect(withMenuOptionsSpacing(promptOptions)));
|
|
if (isCancel(value)) {
|
|
if (cancelOnMultiselectCancel) {
|
|
cancel(cancelMessage);
|
|
}
|
|
return [multiselectCancelValue];
|
|
}
|
|
const selected = [...value].map(String);
|
|
if (
|
|
selected.length === 0 &&
|
|
!promptOptions.required &&
|
|
options.confirmEmptyOptionalMultiselect === true
|
|
) {
|
|
const skipConfirmed = await confirm({
|
|
message: 'Nothing selected. Skip this step?',
|
|
initialValue: false,
|
|
});
|
|
if (isCancel(skipConfirmed)) {
|
|
cancel(cancelMessage);
|
|
return [multiselectCancelValue];
|
|
}
|
|
if (!skipConfirmed) {
|
|
continue;
|
|
}
|
|
}
|
|
return selected;
|
|
}
|
|
},
|
|
async autocomplete(promptOptions) {
|
|
const value = await withSetupInterruptConfirmation(() =>
|
|
autocomplete(withMenuOptionsSpacing(promptOptions)),
|
|
);
|
|
if (isCancel(value)) {
|
|
if (cancelOnSelectCancel) {
|
|
cancel(cancelMessage);
|
|
}
|
|
return options.selectCancelValue;
|
|
}
|
|
return String(value);
|
|
},
|
|
async autocompleteMultiselect(promptOptions) {
|
|
while (true) {
|
|
const value = await withSetupInterruptConfirmation(() =>
|
|
autocompleteMultiselect(withMenuOptionsSpacing(promptOptions)),
|
|
);
|
|
if (isCancel(value)) {
|
|
if (cancelOnMultiselectCancel) {
|
|
cancel(cancelMessage);
|
|
}
|
|
return [multiselectCancelValue];
|
|
}
|
|
const selected = [...value].map(String);
|
|
if (
|
|
selected.length === 0 &&
|
|
!promptOptions.required &&
|
|
options.confirmEmptyOptionalMultiselect === true
|
|
) {
|
|
const skipConfirmed = await confirm({
|
|
message: 'Nothing selected. Skip this step?',
|
|
initialValue: false,
|
|
});
|
|
if (isCancel(skipConfirmed)) {
|
|
cancel(cancelMessage);
|
|
return [multiselectCancelValue];
|
|
}
|
|
if (!skipConfirmed) {
|
|
continue;
|
|
}
|
|
}
|
|
return selected;
|
|
}
|
|
},
|
|
async text(promptOptions) {
|
|
const value = await withSetupInterruptConfirmation(() =>
|
|
text({ ...promptOptions, message: withTextInputNavigation(promptOptions.message) }),
|
|
);
|
|
return isCancel(value) ? undefined : String(value);
|
|
},
|
|
async password(promptOptions) {
|
|
const value = await withSetupInterruptConfirmation(() =>
|
|
revealPassword({ ...promptOptions, message: withTextInputNavigation(promptOptions.message) }),
|
|
);
|
|
return isCancel(value) ? undefined : String(value);
|
|
},
|
|
cancel(message) {
|
|
cancel(message);
|
|
},
|
|
log(message) {
|
|
log.info(message);
|
|
},
|
|
};
|
|
}
|
|
|
|
interface KtxSetupNoteOptions {
|
|
format?: (line: string) => string;
|
|
}
|
|
|
|
export interface KtxSetupUiAdapter {
|
|
intro(title: string, io: KtxCliIo): void;
|
|
note(message: string, title: string, io: KtxCliIo, options?: KtxSetupNoteOptions): void;
|
|
}
|
|
|
|
export function createKtxSetupUiAdapter(): KtxSetupUiAdapter {
|
|
return {
|
|
intro(title, io) {
|
|
if (isWritableTtyOutput(io.stdout)) {
|
|
const banner = renderKtxSetupBanner({
|
|
columns: io.stdout.columns ?? 80,
|
|
colorDepth: colorDepthForOutput(io.stdout),
|
|
unicode: unicodeSupported,
|
|
});
|
|
if (banner !== '') {
|
|
io.stdout.write(banner);
|
|
}
|
|
intro(title, { output: io.stdout });
|
|
return;
|
|
}
|
|
io.stdout.write(`${title}\n`);
|
|
},
|
|
note(message, title, io, options) {
|
|
if (isWritableTtyOutput(io.stdout)) {
|
|
note(message, title, {
|
|
output: io.stdout,
|
|
...(options?.format ? { format: options.format } : {}),
|
|
});
|
|
return;
|
|
}
|
|
io.stdout.write(`\n${title}:\n`);
|
|
io.stdout.write(`${message}\n`);
|
|
},
|
|
};
|
|
}
|