The best way to control Claude Code, Codex and more from any computer or phone
| 1 | // @effect-diagnostics nodeBuiltinImport:off - standalone catalog generation uses synchronous Node I/O. |
| 2 | // @effect-diagnostics globalConsole:off - standalone maintenance command output. |
| 3 | import * as NodeFS from "node:fs"; |
| 4 | import * as NodeModule from "node:module"; |
| 5 | import * as NodePath from "node:path"; |
| 6 | |
| 7 | import { catalog } from "@handy-computer/models"; |
| 8 | import { format } from "vite-plus/fmt"; |
| 9 | import * as Schema from "effect/Schema"; |
| 10 | |
| 11 | import manifest from "../package.json" with { type: "json" }; |
| 12 | import { renderSpeechCatalog } from "./speech-catalog.ts"; |
| 13 | |
| 14 | const require = NodeModule.createRequire(import.meta.url); |
| 15 | const source = require.resolve("@handy-computer/models/catalog.json"); |
| 16 | const sourceManifest = Schema.decodeSync( |
| 17 | Schema.fromJsonString(Schema.Struct({ version: Schema.String })), |
| 18 | )(NodeFS.readFileSync(NodePath.join(NodePath.dirname(source), "package.json"), "utf8")); |
| 19 | if (sourceManifest.version !== manifest.devDependencies["@handy-computer/models"]) { |
| 20 | throw new Error("Install the exact pinned @handy-computer/models version before generating."); |
| 21 | } |
| 22 | const target = new URL("../src/speech/catalog.json", import.meta.url); |
| 23 | const expected = await renderSpeechCatalog( |
| 24 | catalog.data, |
| 25 | sourceManifest.version, |
| 26 | manifest.dependencies["transcribe-cpp"], |
| 27 | ); |
| 28 | const policyTarget = new URL( |
| 29 | "../../../packages/shared/src/speechRecommendationPolicy.json", |
| 30 | import.meta.url, |
| 31 | ); |
| 32 | const { fastCpuMaxWaitSeconds, ...methodology } = catalog.methodology; |
| 33 | const policy = await format( |
| 34 | "speechRecommendationPolicy.json", |
| 35 | JSON.stringify({ ...methodology, fastMaxWaitSeconds: fastCpuMaxWaitSeconds }), |
| 36 | ); |
| 37 | if (policy.errors.length > 0) throw new Error("Could not format speech recommendation policy."); |
| 38 | if (process.argv.includes("--check")) { |
| 39 | if ( |
| 40 | NodeFS.readFileSync(target, "utf8") !== expected || |
| 41 | NodeFS.readFileSync(policyTarget, "utf8") !== policy.code |
| 42 | ) { |
| 43 | throw new Error("Speech catalog differs; run vp run speech:catalog:sync in apps/server."); |
| 44 | } |
| 45 | console.log("Bundled speech catalog matches the pinned source."); |
| 46 | } else { |
| 47 | NodeFS.writeFileSync(target, expected); |
| 48 | NodeFS.writeFileSync(policyTarget, policy.code); |
| 49 | console.log(`Generated speech catalog from @handy-computer/models@${sourceManifest.version}.`); |
| 50 | } |