2026-05-11 15:50:34 +02:00
|
|
|
import { type Command, Option } from '@commander-js/extra-typings';
|
|
|
|
|
import type { KtxCliCommandContext } from '../cli-program.js';
|
|
|
|
|
import type { KtxRuntimeArgs } from '../runtime.js';
|
|
|
|
|
|
|
|
|
|
type RuntimeFeature = Extract<KtxRuntimeArgs, { command: 'install' }>['feature'];
|
|
|
|
|
|
|
|
|
|
function createRuntimeFeatureOption() {
|
|
|
|
|
return new Option('--feature <feature>', 'Runtime feature level')
|
|
|
|
|
.choices(['core', 'local-embeddings'])
|
|
|
|
|
.default('core');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function runRuntimeArgs(context: KtxCliCommandContext, args: KtxRuntimeArgs): Promise<void> {
|
|
|
|
|
const runner = context.deps.runtime ?? (await import('../runtime.js')).runKtxRuntime;
|
|
|
|
|
context.setExitCode(await runner(args, context.io));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function registerRuntimeCommands(program: Command, context: KtxCliCommandContext): void {
|
|
|
|
|
const runtime = program
|
|
|
|
|
.command('runtime')
|
2026-05-13 12:28:24 +02:00
|
|
|
.description('Install, start, stop, and inspect the KTX-managed Python runtime')
|
2026-05-11 15:50:34 +02:00
|
|
|
.showHelpAfterError();
|
|
|
|
|
|
|
|
|
|
runtime
|
|
|
|
|
.command('install')
|
|
|
|
|
.description('Install the bundled Python runtime wheel into the managed runtime')
|
|
|
|
|
.addOption(createRuntimeFeatureOption())
|
|
|
|
|
.option('--yes', 'Accept runtime installation without prompting', false)
|
|
|
|
|
.option('--force', 'Reinstall even when the runtime already looks ready', false)
|
|
|
|
|
.action(async (options: { feature: RuntimeFeature; yes?: boolean; force?: boolean }) => {
|
|
|
|
|
await runRuntimeArgs(context, {
|
|
|
|
|
command: 'install',
|
|
|
|
|
cliVersion: context.packageInfo.version,
|
|
|
|
|
feature: options.feature,
|
|
|
|
|
force: options.force === true,
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
runtime
|
|
|
|
|
.command('start')
|
|
|
|
|
.description('Start the KTX-managed Python HTTP daemon')
|
|
|
|
|
.addOption(createRuntimeFeatureOption())
|
|
|
|
|
.option('--force', 'Restart even when a matching daemon is already running', false)
|
|
|
|
|
.action(async (options: { feature: RuntimeFeature; force?: boolean }) => {
|
|
|
|
|
await runRuntimeArgs(context, {
|
|
|
|
|
command: 'start',
|
|
|
|
|
cliVersion: context.packageInfo.version,
|
|
|
|
|
feature: options.feature,
|
|
|
|
|
force: options.force === true,
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
runtime
|
|
|
|
|
.command('stop')
|
|
|
|
|
.description('Stop the KTX-managed Python HTTP daemon')
|
2026-05-12 13:00:08 +02:00
|
|
|
.option('--all', 'Stop all KTX daemon processes recorded or discoverable on this machine', false)
|
|
|
|
|
.action(async (options: { all?: boolean }) => {
|
2026-05-11 15:50:34 +02:00
|
|
|
await runRuntimeArgs(context, {
|
|
|
|
|
command: 'stop',
|
|
|
|
|
cliVersion: context.packageInfo.version,
|
2026-05-12 13:00:08 +02:00
|
|
|
all: options.all === true,
|
2026-05-11 15:50:34 +02:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
runtime
|
|
|
|
|
.command('status')
|
2026-05-13 12:28:24 +02:00
|
|
|
.description('Show managed Python runtime status and readiness checks')
|
2026-05-11 15:50:34 +02:00
|
|
|
.option('--json', 'Print JSON output', false)
|
|
|
|
|
.action(async (options: { json?: boolean }) => {
|
|
|
|
|
await runRuntimeArgs(context, {
|
|
|
|
|
command: 'status',
|
|
|
|
|
cliVersion: context.packageInfo.version,
|
|
|
|
|
json: options.json === true,
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|