mirror of
https://github.com/Kaelio/ktx.git
synced 2026-06-07 07:55:13 +02:00
* docs: add npm managed python runtime design * build: add bundled python runtime wheel builder * build: make local embedding dependencies optional * build: bundle python runtime wheel in cli artifacts * build: track bundled python runtime release artifact * test: verify bundled python runtime wheel * docs: add plan for bundled python runtime wheel * test: cover managed python runtime lifecycle * feat: add managed python runtime installer * feat: add runtime command runner * feat: expose runtime management commands * test: verify managed python runtime commands * docs: add plan for managed python runtime installer * feat: add managed python command helper * feat: use managed runtime for sl query compute * feat: route sl query managed runtime policy * docs: add plan for managed runtime sl query integration * feat: add managed runtime daemon metadata * feat: manage python daemon lifecycle * feat: add runtime daemon start stop commands * fix: verify managed runtime daemon lifecycle * docs: add plan for managed runtime daemon lifecycle * feat: add managed local embeddings config marker * feat: add managed local embeddings daemon helper * feat: use managed runtime for local embedding setup * feat: pass managed runtime policy through setup * docs: add plan for managed local embeddings runtime * feat: read CLI package metadata dynamically * feat: assemble public kaelio ktx npm package * feat: release one public kaelio ktx npm artifact * test: cover public kaelio ktx package invocations * chore: verify public kaelio ktx package artifacts * docs: add plan for public kaelio ktx npm package * test: verify managed runtime in public package smoke * test: finalize managed runtime release smoke * docs: add plan for managed runtime release smoke * test: specify local embeddings release smoke * feat: add local embeddings runtime smoke * chore: register local embeddings smoke * fix: verify local embeddings smoke * fix: restore artifact smoke python env helper * docs: add plan for managed local embeddings release smoke * refactor: share managed runtime install policy parsing * feat: use managed runtime for agent semantic queries * feat: use managed runtime for MCP semantic compute * docs: add plan for managed agent and MCP semantic runtime * feat(cli): add managed daemon HTTP helpers * feat(cli): route local adapters through managed daemon * feat(cli): use managed daemon for ingest helpers * feat(cli): pass managed daemon options to scan * feat(context): pass MCP ingest pull config options * feat(cli): pass managed daemon options to serve ingest * test: verify managed local ingest daemon runtime * docs: add plan for managed local ingest daemon runtime * docs: align managed runtime examples * docs: add plan for managed runtime docs cleanup * test: cover published package runtime smoke commands * test: validate published package smoke outputs * docs: add plan for published package runtime smoke * build: stamp public npm package version * release: add npm public release policy * release: add guarded npm publish script * release: document public npm release handoff * docs: add plan for public npm release handoff * test: cover managed runtime prune in package smoke * docs: document managed runtime prune * docs: add plan for managed runtime prune smoke and docs * chore: encode uv runtime prerequisite policy * fix: clarify missing uv runtime error * docs: document uv runtime prerequisite * docs: add plan for uv runtime prerequisite contract * refactor: limit release artifacts to public package runtime * chore: align release policy with bundled runtime wheel * docs: describe single public runtime artifact surface * test: verify single public runtime artifact contract * docs: add plan for single public runtime artifact cleanup * fix: align local embeddings smoke with public version * docs: add plan for local embeddings smoke public version * release: soft-launch as @kaelio/ktx@0.1.0-rc.0 on next tag Publish target moves to the pre-release version 0.1.0-rc.0 under the next dist-tag so npm install @kaelio/ktx (which resolves to latest) does not pick up the soft-launch build. Users opt in via @kaelio/ktx@next. * Fix release script boundary checks * Remove PostHog from public package bundle
263 lines
8.6 KiB
JavaScript
263 lines
8.6 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
import { execFile } from 'node:child_process';
|
|
import { cp, mkdir, readFile, rm, writeFile } from 'node:fs/promises';
|
|
import { dirname, join, resolve } from 'node:path';
|
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
import { promisify } from 'node:util';
|
|
|
|
const execFileAsync = promisify(execFile);
|
|
|
|
export const PUBLIC_NPM_PACKAGE_NAME = '@kaelio/ktx';
|
|
export const PUBLIC_NPM_PACKAGE_VERSION = '0.1.0-rc.0';
|
|
|
|
export function publicNpmPackageTarballName(version = PUBLIC_NPM_PACKAGE_VERSION) {
|
|
return `kaelio-ktx-${version}.tgz`;
|
|
}
|
|
|
|
export const PUBLIC_BUNDLED_WORKSPACE_PACKAGES = [
|
|
'@ktx/llm',
|
|
'@ktx/context',
|
|
'@ktx/connector-bigquery',
|
|
'@ktx/connector-clickhouse',
|
|
'@ktx/connector-mysql',
|
|
'@ktx/connector-postgres',
|
|
'@ktx/connector-snowflake',
|
|
'@ktx/connector-sqlite',
|
|
'@ktx/connector-sqlserver',
|
|
];
|
|
|
|
export const PUBLIC_BUNDLED_WORKSPACE_PACKAGE_ROOTS = {
|
|
'@ktx/llm': 'packages/llm',
|
|
'@ktx/context': 'packages/context',
|
|
'@ktx/connector-bigquery': 'packages/connector-bigquery',
|
|
'@ktx/connector-clickhouse': 'packages/connector-clickhouse',
|
|
'@ktx/connector-mysql': 'packages/connector-mysql',
|
|
'@ktx/connector-postgres': 'packages/connector-postgres',
|
|
'@ktx/connector-snowflake': 'packages/connector-snowflake',
|
|
'@ktx/connector-sqlite': 'packages/connector-sqlite',
|
|
'@ktx/connector-sqlserver': 'packages/connector-sqlserver',
|
|
};
|
|
|
|
function scriptRootDir() {
|
|
return resolve(dirname(fileURLToPath(import.meta.url)), '..');
|
|
}
|
|
|
|
export function publicNpmPackageLayout(rootDir = scriptRootDir(), version = PUBLIC_NPM_PACKAGE_VERSION) {
|
|
return {
|
|
rootDir,
|
|
packageVersion: version,
|
|
cliPackageRoot: join(rootDir, 'packages', 'cli'),
|
|
packRoot: join(rootDir, 'dist', 'public-npm-package'),
|
|
npmDir: join(rootDir, 'dist', 'artifacts', 'npm'),
|
|
tarballPath: join(rootDir, 'dist', 'artifacts', 'npm', publicNpmPackageTarballName(version)),
|
|
};
|
|
}
|
|
|
|
async function readJson(path) {
|
|
return JSON.parse(await readFile(path, 'utf8'));
|
|
}
|
|
|
|
async function writeJson(path, value) {
|
|
await writeFile(path, `${JSON.stringify(value, null, 2)}\n`);
|
|
}
|
|
|
|
function sortedObject(entries) {
|
|
return Object.fromEntries([...entries].sort(([left], [right]) => left.localeCompare(right)));
|
|
}
|
|
|
|
function isWorkspacePackageName(name) {
|
|
return name.startsWith('@ktx/');
|
|
}
|
|
|
|
function parseCaretVersion(value) {
|
|
const match = /^\^(\d+)\.(\d+)\.(\d+)$/.exec(value);
|
|
if (!match) {
|
|
return null;
|
|
}
|
|
return {
|
|
major: Number(match[1]),
|
|
minor: Number(match[2]),
|
|
patch: Number(match[3]),
|
|
};
|
|
}
|
|
|
|
function compareParsedVersions(left, right) {
|
|
return left.major - right.major || left.minor - right.minor || left.patch - right.patch;
|
|
}
|
|
|
|
function mergeDependencyVersion(name, previous, next) {
|
|
if (previous === next) {
|
|
return previous;
|
|
}
|
|
|
|
const previousCaret = parseCaretVersion(previous);
|
|
const nextCaret = parseCaretVersion(next);
|
|
if (previousCaret && nextCaret && previousCaret.major === nextCaret.major) {
|
|
return compareParsedVersions(previousCaret, nextCaret) >= 0 ? previous : next;
|
|
}
|
|
|
|
throw new Error(`Incompatible dependency versions for ${name}: ${previous} and ${next}`);
|
|
}
|
|
|
|
export function collectPublicDependencies(packageJsons) {
|
|
const dependencies = new Map();
|
|
|
|
for (const packageJson of packageJsons) {
|
|
for (const [name, version] of Object.entries(packageJson.dependencies ?? {})) {
|
|
if (isWorkspacePackageName(name)) {
|
|
continue;
|
|
}
|
|
const previous = dependencies.get(name);
|
|
dependencies.set(name, previous ? mergeDependencyVersion(name, previous, version) : version);
|
|
}
|
|
}
|
|
|
|
return sortedObject(dependencies);
|
|
}
|
|
|
|
export function publicNpmPackageJson(cliPackageJson, dependencies, version = PUBLIC_NPM_PACKAGE_VERSION) {
|
|
return {
|
|
name: PUBLIC_NPM_PACKAGE_NAME,
|
|
version,
|
|
description: 'Standalone KTX context layer for database agents',
|
|
private: false,
|
|
type: 'module',
|
|
engines: cliPackageJson.engines ?? { node: '>=22.0.0' },
|
|
bin: { ktx: './dist/bin.js' },
|
|
main: cliPackageJson.main ?? 'dist/index.js',
|
|
types: cliPackageJson.types ?? 'dist/index.d.ts',
|
|
exports: cliPackageJson.exports ?? {
|
|
'.': {
|
|
types: './dist/index.d.ts',
|
|
import: './dist/index.js',
|
|
default: './dist/index.js',
|
|
},
|
|
'./package.json': './package.json',
|
|
},
|
|
files: ['dist', 'assets'],
|
|
dependencies,
|
|
bundledDependencies: PUBLIC_BUNDLED_WORKSPACE_PACKAGES,
|
|
license: cliPackageJson.license ?? 'Apache-2.0',
|
|
repository: {
|
|
type: 'git',
|
|
url: 'git+https://github.com/kaelio/ktx.git',
|
|
},
|
|
bugs: {
|
|
url: 'https://github.com/kaelio/ktx/issues',
|
|
},
|
|
homepage: 'https://github.com/kaelio/ktx#readme',
|
|
};
|
|
}
|
|
|
|
function bundledWorkspacePackageJson(packageJson) {
|
|
const dependencies = Object.fromEntries(
|
|
Object.entries(packageJson.dependencies ?? {}).filter(([name]) => !isWorkspacePackageName(name)),
|
|
);
|
|
|
|
return {
|
|
name: packageJson.name,
|
|
version: packageJson.version ?? PUBLIC_NPM_PACKAGE_VERSION,
|
|
private: true,
|
|
type: packageJson.type ?? 'module',
|
|
main: packageJson.main,
|
|
types: packageJson.types,
|
|
exports: packageJson.exports,
|
|
files: packageJson.files,
|
|
dependencies: sortedObject(Object.entries(dependencies)),
|
|
license: packageJson.license ?? 'Apache-2.0',
|
|
};
|
|
}
|
|
|
|
async function copyPackageFileEntries(sourceRoot, targetRoot, packageJson) {
|
|
for (const entry of packageJson.files ?? ['dist']) {
|
|
await cp(join(sourceRoot, entry), join(targetRoot, entry), {
|
|
recursive: true,
|
|
force: true,
|
|
});
|
|
}
|
|
}
|
|
|
|
async function copyCliPackage(layout, cliPackageJson, dependencies) {
|
|
await copyPackageFileEntries(layout.cliPackageRoot, layout.packRoot, cliPackageJson);
|
|
await writeJson(
|
|
join(layout.packRoot, 'package.json'),
|
|
publicNpmPackageJson(cliPackageJson, dependencies, layout.packageVersion),
|
|
);
|
|
}
|
|
|
|
async function copyBundledWorkspacePackage(rootDir, packageName, packageJson) {
|
|
const packageRoot = PUBLIC_BUNDLED_WORKSPACE_PACKAGE_ROOTS[packageName];
|
|
if (!packageRoot) {
|
|
throw new Error(`Missing bundled workspace package root for ${packageName}`);
|
|
}
|
|
|
|
const sourceRoot = join(rootDir, packageRoot);
|
|
const targetRoot = join(rootDir, 'dist', 'public-npm-package', 'node_modules', ...packageName.split('/'));
|
|
await mkdir(targetRoot, { recursive: true });
|
|
await copyPackageFileEntries(sourceRoot, targetRoot, packageJson);
|
|
await writeJson(join(targetRoot, 'package.json'), bundledWorkspacePackageJson(packageJson));
|
|
}
|
|
|
|
export async function createPublicNpmPackageTree(layout = publicNpmPackageLayout()) {
|
|
const cliPackageJson = await readJson(join(layout.cliPackageRoot, 'package.json'));
|
|
const bundledPackageJsons = await Promise.all(
|
|
PUBLIC_BUNDLED_WORKSPACE_PACKAGES.map(async (packageName) => {
|
|
const packageRoot = PUBLIC_BUNDLED_WORKSPACE_PACKAGE_ROOTS[packageName];
|
|
const packageJson = await readJson(join(layout.rootDir, packageRoot, 'package.json'));
|
|
if (packageJson.name !== packageName) {
|
|
throw new Error(`Unexpected package name in ${packageRoot}/package.json: ${packageJson.name}`);
|
|
}
|
|
return packageJson;
|
|
}),
|
|
);
|
|
const dependencies = collectPublicDependencies([cliPackageJson, ...bundledPackageJsons]);
|
|
|
|
await rm(layout.packRoot, { recursive: true, force: true });
|
|
await mkdir(layout.packRoot, { recursive: true });
|
|
await mkdir(layout.npmDir, { recursive: true });
|
|
await copyCliPackage(layout, cliPackageJson, dependencies);
|
|
|
|
for (const packageJson of bundledPackageJsons) {
|
|
await copyBundledWorkspacePackage(layout.rootDir, packageJson.name, packageJson);
|
|
}
|
|
|
|
return {
|
|
layout,
|
|
packageJson: publicNpmPackageJson(cliPackageJson, dependencies, layout.packageVersion),
|
|
bundledPackages: PUBLIC_BUNDLED_WORKSPACE_PACKAGES,
|
|
};
|
|
}
|
|
|
|
export function publicNpmPackCommand(layout = publicNpmPackageLayout()) {
|
|
return {
|
|
command: 'pnpm',
|
|
args: ['--config.node-linker=hoisted', 'pack', '--out', layout.tarballPath],
|
|
cwd: layout.packRoot,
|
|
};
|
|
}
|
|
|
|
export async function buildPublicNpmPackage(layout = publicNpmPackageLayout()) {
|
|
await createPublicNpmPackageTree(layout);
|
|
const pack = publicNpmPackCommand(layout);
|
|
await execFileAsync(pack.command, pack.args, {
|
|
cwd: pack.cwd,
|
|
encoding: 'utf8',
|
|
maxBuffer: 10 * 1024 * 1024,
|
|
});
|
|
return layout.tarballPath;
|
|
}
|
|
|
|
async function main() {
|
|
const tarball = await buildPublicNpmPackage();
|
|
process.stdout.write(`Built ${PUBLIC_NPM_PACKAGE_NAME} package: ${tarball}\n`);
|
|
}
|
|
|
|
if (import.meta.url === pathToFileURL(process.argv[1] ?? '').href) {
|
|
try {
|
|
await main();
|
|
} catch (error) {
|
|
process.stderr.write(`${error instanceof Error ? error.stack : String(error)}\n`);
|
|
process.exitCode = 1;
|
|
}
|
|
}
|