|
| 1 | +import type { Argv } from "yargs" |
| 2 | +import { cmd } from "./cmd" |
| 3 | +import * as prompts from "@clack/prompts" |
| 4 | +import fs from "fs/promises" |
| 5 | +import path from "path" |
| 6 | +import os from "os" |
| 7 | + |
| 8 | +// Injected at build time by build.ts (same pattern as ALTIMATE_CLI_MIGRATIONS). |
| 9 | +// In development these fall back to reading from disk via getAssets(). |
| 10 | +declare const ALTIMATE_VALIDATE_SKILL_MD: string |
| 11 | +declare const ALTIMATE_VALIDATE_BATCH_PY: string |
| 12 | + |
| 13 | +interface ValidateAssets { |
| 14 | + skillMd: string |
| 15 | + batchPy: string |
| 16 | +} |
| 17 | + |
| 18 | +async function getAssets(): Promise<ValidateAssets> { |
| 19 | + if ( |
| 20 | + typeof ALTIMATE_VALIDATE_SKILL_MD !== "undefined" && |
| 21 | + typeof ALTIMATE_VALIDATE_BATCH_PY !== "undefined" |
| 22 | + ) { |
| 23 | + return { |
| 24 | + skillMd: ALTIMATE_VALIDATE_SKILL_MD, |
| 25 | + batchPy: ALTIMATE_VALIDATE_BATCH_PY, |
| 26 | + } |
| 27 | + } |
| 28 | + // Development fallback: read from disk relative to this source file |
| 29 | + const skillsDir = path.join(import.meta.dir, "../../skill/validate") |
| 30 | + const [skillMd, batchPy] = await Promise.all([ |
| 31 | + fs.readFile(path.join(skillsDir, "SKILL.md"), "utf-8"), |
| 32 | + fs.readFile(path.join(skillsDir, "batch_validate.py"), "utf-8"), |
| 33 | + ]) |
| 34 | + return { skillMd, batchPy } |
| 35 | +} |
| 36 | + |
| 37 | + |
| 38 | + |
| 39 | +const InstallSubcommand = cmd({ |
| 40 | + command: "install", |
| 41 | + describe: "install the /validate skill into ~/.altimate-code", |
| 42 | + handler: async () => { |
| 43 | + prompts.intro("Altimate Validate — Installer") |
| 44 | + |
| 45 | + const { skillMd, batchPy } = await getAssets() |
| 46 | + |
| 47 | + const spinner = prompts.spinner() |
| 48 | + spinner.start("Installing /validate skill...") |
| 49 | + const skillTargetDir = path.join(os.homedir(), ".altimate-code", "skills", "validate") |
| 50 | + await fs.mkdir(skillTargetDir, { recursive: true }) |
| 51 | + await fs.writeFile(path.join(skillTargetDir, "SKILL.md"), skillMd) |
| 52 | + await fs.writeFile(path.join(skillTargetDir, "batch_validate.py"), batchPy) |
| 53 | + spinner.stop(`Installed /validate skill → ${skillTargetDir}`) |
| 54 | + |
| 55 | + prompts.outro("Altimate validation skill installed successfully!") |
| 56 | + }, |
| 57 | +}) |
| 58 | + |
| 59 | +const StatusSubcommand = cmd({ |
| 60 | + command: "status", |
| 61 | + describe: "check whether the /validate skill is installed", |
| 62 | + handler: async () => { |
| 63 | + const skillDir = path.join(os.homedir(), ".altimate-code", "skills", "validate") |
| 64 | + |
| 65 | + prompts.intro("Altimate Validate — Installation Status") |
| 66 | + |
| 67 | + const check = (exists: boolean, label: string, detail: string) => |
| 68 | + prompts.log.info(`${exists ? "✓" : "✗"} ${label}${exists ? "" : " (not found)"}: ${detail}`) |
| 69 | + |
| 70 | + const skillMdExists = await fs.access(path.join(skillDir, "SKILL.md")).then(() => true).catch(() => false) |
| 71 | + const batchPyExists = await fs.access(path.join(skillDir, "batch_validate.py")).then(() => true).catch(() => false) |
| 72 | + check(skillMdExists && batchPyExists, "/validate skill", skillDir) |
| 73 | + |
| 74 | + prompts.outro("Done") |
| 75 | + }, |
| 76 | +}) |
| 77 | + |
| 78 | +export const ValidateCommand = cmd({ |
| 79 | + command: "validate", |
| 80 | + describe: "manage the Altimate validation framework (/validate skill)", |
| 81 | + builder: (yargs: Argv) => yargs.command(InstallSubcommand).command(StatusSubcommand).demandCommand(), |
| 82 | + handler: () => {}, |
| 83 | +}) |
0 commit comments