ktx/packages/cli/src/next-steps.ts
Andrey Avtomonov 2c9a58bb56
feat(cli): smart defaults and flatter command surface for ktx (#177)
Bare invocations now do the obvious thing instead of erroring out, and mode-as-subcommand patterns collapse into flags on the parent. No new top-level commands.

- `ktx ingest` (bare) ingests every configured connection. The `text` subcommand is gone; capture inline notes with `ktx ingest --text "..."` and files with `ktx ingest --file path` (use `-` for stdin). `--text`/`--file` reject a positional connection id; pass `--connection-id` to tag captured notes.
- `ktx connection` (bare) lists; `ktx connection test` (bare) tests every configured connection.
- `ktx wiki` and `ktx sl` flatten `list`/`search`: bare lists, with a `[query...]` positional searches (multi-word joined with spaces). `sl validate` and `sl query` stay as distinct verbs and now read `--connection-id` from the parent.
- `ktx mcp` (bare) prints daemon status.

Adds a shared `resolveConnectionSelection` helper consumed by ingest and connection test. Updates README, docs-site cli-reference and guides, next-steps strings, agent SKILL templates, and all affected tests. Per-package type-check, unit tests (605), smoke tests, and dead-code checks all pass.
2026-05-20 01:52:37 +02:00

86 lines
2.9 KiB
TypeScript

export const KTX_CONTEXT_BUILD_COMMANDS = [
{
command: 'ktx ingest',
description: 'Build or refresh agent-ready context from all configured connections',
},
{
command: 'ktx status',
description: 'Check setup and context readiness',
},
] as const;
export const KTX_NEXT_STEP_DIRECT_COMMANDS = [
{
command: 'ktx status --json',
description: 'Verify project setup and context readiness',
},
{
command: 'ktx sl',
description: 'Inspect generated semantic-layer sources',
},
{
command: 'ktx wiki',
description: 'Inspect generated wiki pages',
},
] as const;
export const KTX_NEXT_STEP_COMMANDS = [...KTX_NEXT_STEP_DIRECT_COMMANDS] as const;
export const KTX_NEXT_STEP_COMMAND_WIDTH = Math.max(
...[...KTX_CONTEXT_BUILD_COMMANDS, ...KTX_NEXT_STEP_COMMANDS].map((step) => step.command.length),
);
export interface KtxSetupNextStepState {
setupReady: boolean;
hasContextTargets: boolean;
contextReady: boolean;
agentIntegrationReady: boolean;
}
function commandLines(commands: ReadonlyArray<{ command: string; description: string }>, indent: string): string[] {
return commands.map((step) => `${indent}$ ${step.command.padEnd(KTX_NEXT_STEP_COMMAND_WIDTH)} ${step.description}`);
}
export function formatNextStepLines(indent = ' '): string[] {
return [
`${indent}KTX context is ready for agents. Open your coding agent from the KTX project directory and ask a data question.`,
`${indent}Verify with:`,
...commandLines(KTX_NEXT_STEP_DIRECT_COMMANDS, indent),
];
}
export function formatSetupNextStepLines(state: KtxSetupNextStepState, indent = ' '): string[] {
if (!state.setupReady) {
return [
`${indent}Finish setup first.`,
`${indent}$ ${'ktx setup'.padEnd(KTX_NEXT_STEP_COMMAND_WIDTH)} Resume configuration and validation`,
`${indent}$ ${'ktx status'.padEnd(KTX_NEXT_STEP_COMMAND_WIDTH)} Check which setup steps still need attention`,
];
}
if (!state.hasContextTargets) {
return [
`${indent}Connect data, then build context.`,
`${indent}$ ${'ktx setup'.padEnd(KTX_NEXT_STEP_COMMAND_WIDTH)} Add primary or context sources`,
`${indent}$ ${'ktx status'.padEnd(KTX_NEXT_STEP_COMMAND_WIDTH)} Check setup and context readiness`,
];
}
if (!state.contextReady) {
return [
`${indent}Build KTX context next.`,
`${indent}Run ingest to build database schema context before context-source ingest.`,
...commandLines(KTX_CONTEXT_BUILD_COMMANDS, indent),
];
}
if (!state.agentIntegrationReady) {
return [
`${indent}KTX context is built. Install agent rules when you want your coding agent to use it.`,
`${indent}$ ${'ktx setup --agents'.padEnd(KTX_NEXT_STEP_COMMAND_WIDTH)} Install CLI-based agent rules`,
`${indent}$ ${'ktx status'.padEnd(KTX_NEXT_STEP_COMMAND_WIDTH)} Check setup and context readiness`,
];
}
return formatNextStepLines(indent);
}