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';
|
refactor(release): drop release-policy.json runtime dep and next branch (#180)
* chore: standardize daemon naming on "KTX daemon"
Replace inconsistent names ("KTX Python daemon", "KTX local embeddings
daemon", "KTX managed daemon", "Python daemon") with the single name
"KTX daemon" in CLI output, errors, command descriptions, test
assertions, smoke scripts, docs, AGENTS.md, issue templates, and
codecov flags. The daemon is a portable compute server with endpoints
for SQL analysis, semantic layer, LookML, database introspection, and
embeddings; the previous labels misrepresented it as embeddings-only or
exposed implementation details ("Python", "managed").
The "KTX Python runtime" concept (installed interpreter + packages) is
deliberately left as-is — it is a separate concept from the daemon
process.
* refactor(release): drop release-policy.json runtime dep and next branch
Strips the release-policy.json fallback from release-version.ts so the CLI
reads its version straight from packages/cli/package.json. dev → 0.0.0-private,
installed @kaelio/ktx → the real semver baked into the published package.json.
KtxCliPackageInfo collapses to { name, version, contextPackageName }; /health
no longer depends on version files surviving past a CI run.
Replaces the dual-branch (main + next) semantic-release model with a single-
branch model on main. rcs and stables interleave on the same branch via
{ name: 'main', prerelease: 'rc', channel: 'next' } / ['main']. Drops
@semantic-release/git and @semantic-release/changelog (nothing is committed
back to the repo on any channel) and the workflow's "Prepare next prerelease
branch" step plus the KTX_PRERELEASE_BRANCH plumbing. The git tag plus the
published npm artifact carry the version forward.
Updates docs/release.md, removes the two now-unused devDeps, regenerates
pnpm-lock.yaml. 611/611 @ktx/cli tests, 173/173 script tests, type-check,
biome, knip all clean.
* fix(release): don't throw on non-main branches at config-load time
knip loads .releaserc.cjs on every PR run, where GITHUB_REF_NAME is the
merge ref (e.g. 180/merge). The previous version of releaseBranches threw
immediately when the branch wasn't main, which made knip fail to evaluate
the config and then mis-flag @semantic-release/exec as an unused dep.
semantic-release already refuses to publish when the current branch doesn't
match a configured release branch, so the explicit throw was redundant.
Drop it (and the unused currentBranch helper) and replace the
"rejects releases from non-main" assertion with one that exercises a CI-
shaped GITHUB_REF_NAME and confirms the config loads.
2026-05-20 13:53:14 +02:00
|
|
|
import { assertCliVersion } 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-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-10 23:12:26 +02:00
|
|
|
return {
|
2026-05-11 15:50:34 +02:00
|
|
|
name: packageJson.name,
|
refactor(release): drop release-policy.json runtime dep and next branch (#180)
* chore: standardize daemon naming on "KTX daemon"
Replace inconsistent names ("KTX Python daemon", "KTX local embeddings
daemon", "KTX managed daemon", "Python daemon") with the single name
"KTX daemon" in CLI output, errors, command descriptions, test
assertions, smoke scripts, docs, AGENTS.md, issue templates, and
codecov flags. The daemon is a portable compute server with endpoints
for SQL analysis, semantic layer, LookML, database introspection, and
embeddings; the previous labels misrepresented it as embeddings-only or
exposed implementation details ("Python", "managed").
The "KTX Python runtime" concept (installed interpreter + packages) is
deliberately left as-is — it is a separate concept from the daemon
process.
* refactor(release): drop release-policy.json runtime dep and next branch
Strips the release-policy.json fallback from release-version.ts so the CLI
reads its version straight from packages/cli/package.json. dev → 0.0.0-private,
installed @kaelio/ktx → the real semver baked into the published package.json.
KtxCliPackageInfo collapses to { name, version, contextPackageName }; /health
no longer depends on version files surviving past a CI run.
Replaces the dual-branch (main + next) semantic-release model with a single-
branch model on main. rcs and stables interleave on the same branch via
{ name: 'main', prerelease: 'rc', channel: 'next' } / ['main']. Drops
@semantic-release/git and @semantic-release/changelog (nothing is committed
back to the repo on any channel) and the workflow's "Prepare next prerelease
branch" step plus the KTX_PRERELEASE_BRANCH plumbing. The git tag plus the
published npm artifact carry the version forward.
Updates docs/release.md, removes the two now-unused devDeps, regenerates
pnpm-lock.yaml. 611/611 @ktx/cli tests, 173/173 script tests, type-check,
biome, knip all clean.
* fix(release): don't throw on non-main branches at config-load time
knip loads .releaserc.cjs on every PR run, where GITHUB_REF_NAME is the
merge ref (e.g. 180/merge). The previous version of releaseBranches threw
immediately when the branch wasn't main, which made knip fail to evaluate
the config and then mis-flag @semantic-release/exec as an unused dep.
semantic-release already refuses to publish when the current branch doesn't
match a configured release branch, so the explicit throw was redundant.
Drop it (and the unused currentBranch helper) and replace the
"rejects releases from non-main" assertion with one that exercises a CI-
shaped GITHUB_REF_NAME and confirms the config loads.
2026-05-20 13:53:14 +02:00
|
|
|
version: assertCliVersion(packageJson.version, `${packageJson.name}/package.json`),
|
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,
|
|
|
|
|
});
|
|
|
|
|
}
|