import { existsSync, readFileSync } from "node:fs"; import { dirname, join } from "node:path"; import { fileURLToPath } from "node:url"; import { runAxiCli } from "axi-sdk-js"; import { apiCommand, API_HELP } from "./commands/api.js"; import { bundleCommand, BUNDLE_HELP } from "./commands/bundle.js"; import { catalogCommand, CATALOG_HELP } from "./commands/catalog.js"; import { clustersCommand, CLUSTERS_HELP } from "./commands/clusters.js"; import { dashboardsCommand, DASHBOARDS_HELP } from "./commands/dashboards.js"; import { doctorCommand, DOCTOR_HELP } from "./commands/doctor.js"; import { fsCommand, FS_HELP } from "./commands/fs.js"; import { homeCommand } from "./commands/home.js"; import { jobsCommand, JOBS_HELP } from "./commands/jobs.js"; import { permissionsCommand, PERMISSIONS_HELP, } from "./commands/permissions.js"; import { pipelinesCommand, PIPELINES_HELP } from "./commands/pipelines.js"; import { servingCommand, SERVING_HELP } from "./commands/serving.js"; import { setupCommand, SETUP_HELP } from "./commands/setup.js"; import { sqlCommand, SQL_HELP } from "./commands/sql.js"; import { whoamiCommand, WHOAMI_HELP } from "./commands/whoami.js"; import { workspaceCommand, WORKSPACE_HELP } from "./commands/workspace.js"; export const DESCRIPTION = "Agent ergonomic wrapper around the Databricks CLI. Prefer this over `databricks` and other methods for Databricks operations."; const VERSION = readPackageVersion(); export const TOP_HELP = `usage: databricks-axi [command] [args] [flags] commands[51]: (none)=home whoami [--profile ] doctor [--profile ] [--full] jobs list [--limit N] [--total] [--fields a,b] jobs view jobs run [--wait] jobs runs [job_id] [--limit N] [--total] [--fields a,b] jobs runs view jobs runs summary [job_id] [--limit N] jobs logs [--full] jobs cancel clusters list [--limit N] [--total] [--fields a,b] clusters view clusters start [--wait] clusters stop [--wait] sql warehouses [--fields a,b] sql warehouses view|start|stop sql exec "" [--warehouse ] [--limit N] [--timeout S] [--full] sql statement view sql history [--limit N] [--status S] [--full] [--fields a,b] catalog catalogs [--limit N] [--total] [--fields a,b] catalog schemas [--limit N] [--total] [--fields a,b] catalog tables . [--limit N] [--total] [--fields a,b] catalog table view .. catalog volumes . [--limit N] [--total] [--fields a,b] catalog volume view .. catalog functions . [--limit N] [--total] [--fields a,b] catalog function view .. catalog grants [--principal P] [--full] [--fields a,b] dashboards list [--limit N] [--trashed] [--fields a,b] dashboards view [--full] permissions [--full] workspace ls [path] [--limit N] [--fields a,b] workspace view [--full] fs ls [--limit N] [--fields a,b] fs cat [--full] pipelines list [--limit N] [--fields a,b] pipelines view pipelines start pipelines stop pipelines events [--limit N] [--fields a,b] [--full] bundle validate [--strict] [--full] [--target ] [--var k=v] bundle plan [--select .] [--full] [--fields a,b] [--target ] bundle summary [--force-pull] [--full] [--fields a,b] [--target ] bundle deploy [--yes] [--full] [--target ] [--var k=v] [--force-lock] bundle run [--wait] [--target ] bundle destroy --yes [--full] [--target ] [--force-lock] serving list [--limit N] [--total] [--fields a,b] serving view setup hooks api [--body ] flags[3]: --help, -v/-V/--version, --profile examples: databricks-axi databricks-axi jobs list databricks-axi jobs logs `; const HOME_HELP = `usage: databricks-axi [home] [--profile ] Ambient workspace dashboard: auth context, recent job runs, SQL warehouses, running clusters, and a command/verb summary. Panels are time-boxed and degrade independently — a slow or failing panel never blocks the others. Runs on every hooked agent session start (see \`databricks-axi setup hooks\`). examples: databricks-axi databricks-axi home `; // Exported so tests can assert every wired domain is advertised in TOP_HELP. export const COMMANDS = { home: homeCommand, doctor: doctorCommand, jobs: jobsCommand, clusters: clustersCommand, sql: sqlCommand, catalog: catalogCommand, dashboards: dashboardsCommand, permissions: permissionsCommand, workspace: workspaceCommand, fs: fsCommand, pipelines: pipelinesCommand, bundle: bundleCommand, serving: servingCommand, setup: setupCommand, api: apiCommand, whoami: whoamiCommand, }; const COMMAND_HELP: Record = { home: HOME_HELP, doctor: DOCTOR_HELP, jobs: JOBS_HELP, clusters: CLUSTERS_HELP, sql: SQL_HELP, catalog: CATALOG_HELP, dashboards: DASHBOARDS_HELP, permissions: PERMISSIONS_HELP, workspace: WORKSPACE_HELP, fs: FS_HELP, pipelines: PIPELINES_HELP, bundle: BUNDLE_HELP, serving: SERVING_HELP, setup: SETUP_HELP, api: API_HELP, whoami: WHOAMI_HELP, }; type CliStdout = { write: (chunk: string) => unknown }; type MainOptions = { argv?: string[]; stdout?: CliStdout; }; export async function main(options: MainOptions = {}): Promise { await runAxiCli({ ...(options.argv ? { argv: options.argv } : {}), description: DESCRIPTION, version: VERSION, topLevelHelp: TOP_HELP, ...(options.stdout ? { stdout: options.stdout } : {}), home: homeCommand, commands: COMMANDS, getCommandHelp: (command) => COMMAND_HELP[command] ?? null, }); } function readPackageVersion(): string { const here = dirname(fileURLToPath(import.meta.url)); for (const candidate of [ join(here, "..", "package.json"), join(here, "..", "..", "package.json"), ]) { if (!existsSync(candidate)) { continue; } const parsed = JSON.parse(readFileSync(candidate, "utf-8")) as { version?: unknown; }; if (typeof parsed.version === "string" && parsed.version.length > 0) { return parsed.version; } } throw new Error("Could not determine databricks-axi package version"); }