feat(cli): improve setup progress UX (#69)

This commit is contained in:
Andrey Avtomonov 2026-05-13 17:01:48 +02:00 committed by GitHub
parent d7147f9ca1
commit 754e4a9039
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
23 changed files with 1125 additions and 346 deletions

View file

@ -1,5 +1,4 @@
import { writeFile } from 'node:fs/promises';
import { cancel, isCancel, password, select } from '@clack/prompts';
import { resolveKtxConfigReference } from '@ktx/context/core';
import {
type KtxProjectConfig,
@ -19,9 +18,12 @@ import {
type ManagedLocalEmbeddingsDaemon,
} from './managed-local-embeddings.js';
import type { KtxManagedPythonInstallPolicy } from './managed-python-command.js';
import { withMenuOptionsSpacing, withTextInputNavigation } from './prompt-navigation.js';
import { withSetupInterruptConfirmation } from './setup-interrupt.js';
import { withTextInputNavigation } from './prompt-navigation.js';
import { envCredentialReference, writeProjectLocalSecretReference } from './setup-secrets.js';
import {
createKtxSetupPromptAdapter,
type KtxSetupPromptOption,
} from './setup-prompts.js';
export type KtxSetupEmbeddingBackend = 'openai' | 'sentence-transformers';
@ -46,7 +48,7 @@ export type KtxSetupEmbeddingsResult =
| { status: 'failed'; projectDir: string };
export interface KtxSetupEmbeddingsPromptAdapter {
select(options: { message: string; options: Array<{ value: string; label: string }> }): Promise<string>;
select(options: { message: string; options: KtxSetupPromptOption[] }): Promise<string>;
password(options: { message: string }): Promise<string | undefined>;
cancel(message: string): void;
}
@ -85,25 +87,7 @@ const EMBEDDING_OPTION_PROMPT_CONTEXT =
const LOCAL_EMBEDDING_HEALTH_TIMEOUT_MS = 120_000;
function createPromptAdapter(): KtxSetupEmbeddingsPromptAdapter {
return {
async select(options) {
const value = await withSetupInterruptConfirmation(() => select(withMenuOptionsSpacing(options)));
if (isCancel(value)) {
cancel('Setup cancelled.');
return 'back';
}
return value;
},
async password(options) {
const value = await withSetupInterruptConfirmation(() =>
password({ ...options, message: withTextInputNavigation(options.message) }),
);
return isCancel(value) ? undefined : value;
},
cancel(message) {
cancel(message);
},
};
return createKtxSetupPromptAdapter({ selectCancelValue: 'back' });
}
async function hasCompletedEmbeddings(projectDir: string, config: KtxProjectConfig): Promise<boolean> {
@ -293,7 +277,7 @@ async function chooseEmbeddingBackend(
message: `Which embedding option should KTX use?\n\n${EMBEDDING_OPTION_PROMPT_CONTEXT}`,
options: [
{ value: 'sentence-transformers', label: 'Local sentence-transformers embeddings' },
{ value: 'openai', label: 'OpenAI embeddings (recommended)' },
{ value: 'openai', label: 'OpenAI embeddings', hint: 'recommended' },
{ value: 'back', label: 'Back' },
],
});