|
| 1 | +#!/usr/bin/env node |
| 2 | + |
| 3 | +import { spawnSync } from "node:child_process"; |
| 4 | +import { dirname, resolve } from "node:path"; |
| 5 | +import { fileURLToPath } from "node:url"; |
| 6 | +import { |
| 7 | + buildPrompt, |
| 8 | + flavors, |
| 9 | + getFlavorById, |
| 10 | + getModeById, |
| 11 | + modes, |
| 12 | + workflowMatrix |
| 13 | +} from "../src/data/library.js"; |
| 14 | + |
| 15 | +const root = resolve(dirname(fileURLToPath(import.meta.url)), ".."); |
| 16 | + |
| 17 | +const help = () => { |
| 18 | + console.log(`RuMa Runtime CLI |
| 19 | +
|
| 20 | +Usage: |
| 21 | + ruma-runtime list |
| 22 | + ruma-runtime matrix |
| 23 | + ruma-runtime random |
| 24 | + ruma-runtime compose <modeId> <flavorId> |
| 25 | + ruma-runtime install [bundle] [target] |
| 26 | + ruma-runtime qa`); |
| 27 | +}; |
| 28 | + |
| 29 | +const printList = () => { |
| 30 | + console.log("Flavors:"); |
| 31 | + for (const flavor of flavors) { |
| 32 | + console.log(`- ${flavor.id}: ${flavor.name} | ${flavor.strapline}`); |
| 33 | + } |
| 34 | + |
| 35 | + console.log("\nModes:"); |
| 36 | + for (const mode of modes) { |
| 37 | + console.log(`- ${mode.id}: ${mode.title} | ${mode.summary}`); |
| 38 | + } |
| 39 | +}; |
| 40 | + |
| 41 | +const printMatrix = () => { |
| 42 | + console.log("Core workflow matrix:"); |
| 43 | + for (const combo of workflowMatrix) { |
| 44 | + console.log(`- ${combo.modeId} + ${combo.flavorId}: ${combo.title}`); |
| 45 | + } |
| 46 | +}; |
| 47 | + |
| 48 | +const printRandom = () => { |
| 49 | + const combo = workflowMatrix[Math.floor(Math.random() * workflowMatrix.length)]; |
| 50 | + const mode = getModeById(combo.modeId); |
| 51 | + const flavor = getFlavorById(combo.flavorId); |
| 52 | + console.log(`Random combo: ${combo.modeId} + ${combo.flavorId}`); |
| 53 | + console.log(`${mode.title} / ${flavor.name}`); |
| 54 | + console.log(`\n${buildPrompt(mode, flavor)}`); |
| 55 | +}; |
| 56 | + |
| 57 | +const printCompose = (modeId, flavorId) => { |
| 58 | + const mode = getModeById(modeId); |
| 59 | + const flavor = getFlavorById(flavorId); |
| 60 | + |
| 61 | + if (!mode || !flavor) { |
| 62 | + console.error(`Unknown mode/flavor: ${modeId} ${flavorId}`); |
| 63 | + process.exit(1); |
| 64 | + } |
| 65 | + |
| 66 | + console.log(buildPrompt(mode, flavor)); |
| 67 | +}; |
| 68 | + |
| 69 | +const runCommand = (command, args) => |
| 70 | + spawnSync(command, args, { |
| 71 | + cwd: root, |
| 72 | + stdio: "inherit", |
| 73 | + shell: process.platform === "win32" |
| 74 | + }); |
| 75 | + |
| 76 | +const installBundle = (bundle = "ruma-runtime", target = "all") => { |
| 77 | + const result = runCommand("node", [resolve(root, "scripts", "install-agent-skill.mjs"), target, bundle]); |
| 78 | + process.exitCode = result.status ?? 1; |
| 79 | +}; |
| 80 | + |
| 81 | +const runQa = () => { |
| 82 | + const build = runCommand("npm", ["run", "build"]); |
| 83 | + if (build.status !== 0) { |
| 84 | + process.exitCode = build.status ?? 1; |
| 85 | + return; |
| 86 | + } |
| 87 | + |
| 88 | + const test = runCommand("npm", ["run", "test"]); |
| 89 | + process.exitCode = test.status ?? 1; |
| 90 | +}; |
| 91 | + |
| 92 | +const [command, ...args] = process.argv.slice(2); |
| 93 | + |
| 94 | +switch (command) { |
| 95 | + case "list": |
| 96 | + printList(); |
| 97 | + break; |
| 98 | + case "matrix": |
| 99 | + printMatrix(); |
| 100 | + break; |
| 101 | + case "random": |
| 102 | + printRandom(); |
| 103 | + break; |
| 104 | + case "compose": |
| 105 | + printCompose(args[0], args[1]); |
| 106 | + break; |
| 107 | + case "install": |
| 108 | + installBundle(args[0], args[1]); |
| 109 | + break; |
| 110 | + case "qa": |
| 111 | + runQa(); |
| 112 | + break; |
| 113 | + case "help": |
| 114 | + case undefined: |
| 115 | + help(); |
| 116 | + break; |
| 117 | + default: |
| 118 | + console.error(`Unknown command: ${command}`); |
| 119 | + help(); |
| 120 | + process.exitCode = 1; |
| 121 | +} |
0 commit comments