2026-05-11 15:50:34 +02:00
|
|
|
import { createRequire } from 'node:module';
|
|
|
|
|
|
2026-05-10 23:51:24 +02:00
|
|
|
import type { KtxConnectionArgs } from './connection.js';
|
2026-05-20 01:36:54 +02:00
|
|
|
import type { KtxAdminReindexArgs } from './admin-reindex.js';
|
2026-05-10 23:51:24 +02:00
|
|
|
import type { KtxDoctorArgs } from './doctor.js';
|
|
|
|
|
import type { KtxKnowledgeArgs } from './knowledge.js';
|
2026-05-14 01:43:06 +02:00
|
|
|
import type { KtxPublicIngestArgs } from './public-ingest.js';
|
2026-05-11 15:50:34 +02:00
|
|
|
import type { KtxRuntimeArgs } from './runtime.js';
|
2026-05-10 23:51:24 +02:00
|
|
|
import type { KtxSetupArgs } from './setup.js';
|
|
|
|
|
import type { KtxSlArgs } from './sl.js';
|
2026-05-17 10:29:07 +02:00
|
|
|
import type { KtxSqlArgs } from './sql.js';
|
2026-05-10 23:12:26 +02:00
|
|
|
import { profileMark, profileSpan } from './startup-profile.js';
|
2026-05-13 19:32:49 +02:00
|
|
|
import type { KtxTextIngestArgs } from './text-ingest.js';
|
2026-05-17 19:15:09 +02:00
|
|
|
import { resolveKtxRuntimeVersion } from './release-version.js';
|
2026-05-10 23:12:26 +02:00
|
|
|
|
|
|
|
|
profileMark('module:cli-runtime');
|
|
|
|
|
|
2026-05-11 15:50:34 +02:00
|
|
|
const requirePackageJson = createRequire(import.meta.url);
|
|
|
|
|
|
2026-05-10 23:51:24 +02:00
|
|
|
export interface KtxCliPackageInfo {
|
2026-05-11 15:50:34 +02:00
|
|
|
name: string;
|
|
|
|
|
version: string;
|
2026-05-17 19:15:09 +02:00
|
|
|
packageVersion: string;
|
|
|
|
|
runtimeVersion: string;
|
2026-05-10 23:51:24 +02:00
|
|
|
contextPackageName: '@ktx/context';
|
2026-05-10 23:12:26 +02:00
|
|
|
}
|
|
|
|
|
|
2026-05-10 23:51:24 +02:00
|
|
|
export interface KtxCliIo {
|
2026-05-11 00:31:15 -07:00
|
|
|
stdout: { isTTY?: boolean; columns?: number; write(chunk: string): void };
|
2026-05-10 23:12:26 +02:00
|
|
|
stderr: { write(chunk: string): void };
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-10 23:51:24 +02:00
|
|
|
export interface KtxCliDeps {
|
2026-05-20 01:36:54 +02:00
|
|
|
adminReindex?: (args: KtxAdminReindexArgs, io: KtxCliIo) => Promise<number>;
|
2026-05-10 23:51:24 +02:00
|
|
|
setup?: (args: KtxSetupArgs, io: KtxCliIo) => Promise<number>;
|
|
|
|
|
connection?: (args: KtxConnectionArgs, io: KtxCliIo) => Promise<number>;
|
|
|
|
|
doctor?: (args: KtxDoctorArgs, io: KtxCliIo) => Promise<number>;
|
2026-05-14 01:43:06 +02:00
|
|
|
publicIngest?: (args: KtxPublicIngestArgs, io: KtxCliIo) => Promise<number>;
|
2026-05-13 19:32:49 +02:00
|
|
|
textIngest?: (args: KtxTextIngestArgs, io: KtxCliIo) => Promise<number>;
|
2026-05-11 15:50:34 +02:00
|
|
|
runtime?: (args: KtxRuntimeArgs, io: KtxCliIo) => Promise<number>;
|
2026-05-10 23:51:24 +02:00
|
|
|
knowledge?: (args: KtxKnowledgeArgs, io: KtxCliIo) => Promise<number>;
|
|
|
|
|
sl?: (args: KtxSlArgs, io: KtxCliIo) => Promise<number>;
|
2026-05-17 10:29:07 +02:00
|
|
|
sql?: (args: KtxSqlArgs, io: KtxCliIo) => Promise<number>;
|
2026-05-15 02:35:09 +02:00
|
|
|
mcp?: {
|
|
|
|
|
startDaemon?: typeof import('./managed-mcp-daemon.js').startKtxMcpDaemon;
|
|
|
|
|
stopDaemon?: typeof import('./managed-mcp-daemon.js').stopKtxMcpDaemon;
|
|
|
|
|
readStatus?: typeof import('./managed-mcp-daemon.js').readKtxMcpDaemonStatus;
|
|
|
|
|
runServer?: typeof import('./mcp-http-server.js').runKtxMcpHttpServer;
|
feat(setup): add Claude Desktop target and MCP-first agent setup (#114)
* feat(setup): add Claude Desktop target and MCP-first agent setup
Adds `ktx mcp stdio` and a `claude-desktop` setup target that generates a
local plugin ZIP wiring the analytics skill and a stdio MCP config. Replaces
the CLI-only agent install mode with MCP+analytics (default) and an optional
admin CLI skill, renames the research skill to analytics, and lets interactive
setup pick project vs global scope when every target supports it. Extracts a
shared MCP server factory used by both HTTP and stdio entrypoints.
* Add MCP agent client setup support
* Polish setup output formatting
* Add MCP tool polish design spec
Design for slimming the MCP-registered surface from 25 to 11 tools,
introducing memory_ingest, applying the per-tool polish kit (annotations,
outputSchema, .describe(), in-band error wrapping, union-drift fixes,
type-narrowed jsonToolResult), emitting progress notifications on
sql_execution + sl_query, and refining the ktx-analytics SKILL.md to
match.
* Refine MCP tool polish design spec after adversarial review iteration 1
* Refine MCP tool polish design spec after adversarial review iteration 2
* Refine MCP tool polish design spec after adversarial review iteration 3
* refactor(context): rename memory capture service to ingest
* feat(mcp): slim research tool surface
* refactor(mcp): remove admin ports from server factory
* refactor(cli): rename text ingest memory port
* docs: update analytics skill for memory ingest
* chore: verify mcp surface rename
* Add MCP tool polish v1 surface change plan
* feat(context): polish mcp tool metadata
* fix(context): enforce resolved semantic layer compute sources
* feat(context): emit mcp query progress stages
* fix(context): keep mcp progress event internal
* Add MCP tool polish v1 metadata & progress plan
* Fix CI snapshot and docs checks
2026-05-16 11:39:55 +02:00
|
|
|
runStdioServer?: typeof import('./mcp-stdio-server.js').runKtxMcpStdioServer;
|
2026-05-15 02:35:09 +02:00
|
|
|
};
|
2026-05-10 23:12:26 +02:00
|
|
|
}
|
|
|
|
|
|
2026-05-10 23:51:24 +02:00
|
|
|
export function getKtxCliPackageInfo(): KtxCliPackageInfo {
|
2026-05-11 15:50:34 +02:00
|
|
|
return packageInfoFromJson(requirePackageJson('../package.json'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function packageInfoFromJson(packageJson: unknown): KtxCliPackageInfo {
|
|
|
|
|
if (
|
|
|
|
|
typeof packageJson !== 'object' ||
|
|
|
|
|
packageJson === null ||
|
|
|
|
|
!('name' in packageJson) ||
|
|
|
|
|
!('version' in packageJson) ||
|
|
|
|
|
typeof packageJson.name !== 'string' ||
|
|
|
|
|
typeof packageJson.version !== 'string'
|
|
|
|
|
) {
|
|
|
|
|
throw new Error('Invalid KTX CLI package metadata');
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-17 19:15:09 +02:00
|
|
|
const runtimeVersion = resolveKtxRuntimeVersion({
|
|
|
|
|
packageName: packageJson.name,
|
|
|
|
|
packageVersion: packageJson.version,
|
|
|
|
|
});
|
|
|
|
|
|
2026-05-10 23:12:26 +02:00
|
|
|
return {
|
2026-05-11 15:50:34 +02:00
|
|
|
name: packageJson.name,
|
2026-05-17 19:15:09 +02:00
|
|
|
version: runtimeVersion,
|
|
|
|
|
packageVersion: packageJson.version,
|
|
|
|
|
runtimeVersion,
|
2026-05-10 23:51:24 +02:00
|
|
|
contextPackageName: '@ktx/context',
|
2026-05-10 23:12:26 +02:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-14 17:39:31 +02:00
|
|
|
async function runInit(args: { projectDir: string; force: boolean }, io: KtxCliIo): Promise<number> {
|
2026-05-10 23:51:24 +02:00
|
|
|
const { initKtxProject } = await import('@ktx/context/project');
|
|
|
|
|
const result = await initKtxProject({
|
2026-05-10 23:12:26 +02:00
|
|
|
projectDir: args.projectDir,
|
|
|
|
|
force: args.force,
|
|
|
|
|
});
|
|
|
|
|
|
2026-05-10 23:51:24 +02:00
|
|
|
io.stdout.write(`Initialized KTX project at ${result.projectDir}\n`);
|
2026-05-10 23:12:26 +02:00
|
|
|
io.stdout.write(`Config: ${result.configPath}\n`);
|
|
|
|
|
io.stdout.write(`Commit: ${result.commitHash ?? 'none'}\n`);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function runInitForCommander(
|
2026-05-14 17:39:31 +02:00
|
|
|
args: { projectDir: string; force: boolean },
|
2026-05-10 23:51:24 +02:00
|
|
|
io: KtxCliIo,
|
2026-05-10 23:12:26 +02:00
|
|
|
): Promise<number> {
|
|
|
|
|
return await runInit(args, io);
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-10 23:51:24 +02:00
|
|
|
export async function runKtxCli(
|
2026-05-10 23:12:26 +02:00
|
|
|
argv = process.argv.slice(2),
|
2026-05-10 23:51:24 +02:00
|
|
|
io: KtxCliIo = process,
|
|
|
|
|
deps: KtxCliDeps = {},
|
2026-05-10 23:12:26 +02:00
|
|
|
): Promise<number> {
|
2026-05-10 23:51:24 +02:00
|
|
|
const info = getKtxCliPackageInfo();
|
|
|
|
|
profileMark('runtime:runKtxCli');
|
|
|
|
|
const { runCommanderKtxCli } = await profileSpan('import ./cli-program.js', () => import('./cli-program.js'));
|
2026-05-10 23:12:26 +02:00
|
|
|
|
2026-05-10 23:51:24 +02:00
|
|
|
return await runCommanderKtxCli(argv, io, deps, info, {
|
2026-05-10 23:12:26 +02:00
|
|
|
runInit: runInitForCommander,
|
|
|
|
|
});
|
|
|
|
|
}
|