Clone any viral video with AI agents. Not just a script, the whole workflow: swap the face, the words, the B-roll, ship 100 variants in one command, and get your 100M views.
TypeScript agentic-aiaiai-agentsai-videocompilerdslffmpeggenerative-aillmmarkup-languagemonorepoplugin-systemprogramming-languagetext-to-videotypescriptvideovideo-automationvideo-clonevideo-editingvideo-generation
refactor: separate projects from on-demand machine runtimes
kashorin4a733d8efd03
diff --git a/.agents/skills/hypit/scripts/check-environment.mjs b/.agents/skills/hypit/scripts/check-environment.mjsindex 687a9da3..94c38200 100755--- a/.agents/skills/hypit/scripts/check-environment.mjs+++ b/.agents/skills/hypit/scripts/check-environment.mjs@@ -2,16 +2,15 @@import { execFileSync } from "node:child_process";import process from "node:process";const commands = [- ["node", "--version"],- ["pnpm", "--version"],- ["corepack", "--version"],- ["ffmpeg", "-version"],- ["ffprobe", "-version"],- ["uv", "--version"],+ ["node", ["--version"]],+ ["hypit", ["paths", "--json"]],+ ["ffmpeg", ["-version"]],+ ["ffprobe", ["-version"]],+ ["uv", ["--version"]],];-for (const [command, versionFlag] of commands) {+for (const [command, args] of commands) {try {- const version = execFileSync(command, [versionFlag], { encoding: "utf8", stdio: ["ignore", "pipe", "pipe"], windowsHide: true }).trim().split(/\r?\n/, 1)[0];+ const version = execFileSync(command, args, { encoding: "utf8", stdio: ["ignore", "pipe", "pipe"], windowsHide: true }).trim().split(/\r?\n/, 1)[0];console.log(`${command}\tok\t${version}`);} catch { console.log(`${command}\tmissing`); }}diff --git a/.agents/skills/hypit/scripts/locate-repository.mjs b/.agents/skills/hypit/scripts/locate-repository.mjsdeleted file mode 100755index e3548c18..00000000--- a/.agents/skills/hypit/scripts/locate-repository.mjs+++ /dev/null@@ -1,68 +0,0 @@-#!/usr/bin/env node-/**- * Report the Hypit checkout every route runs against, cloning one when this machine has none.- *- * Usage: node scripts/locate-repository.mjs- *- * This is the one script that runs from the skill's own copy rather than from the checkout, so it- * depends on nothing but Node. It writes the report to stdout and leaves git's progress on stderr.- */-import { execFileSync } from "node:child_process";-import { existsSync, readFileSync } from "node:fs";-import { homedir } from "node:os";-import { dirname, join, resolve } from "node:path";-import process from "node:process";-import { fileURLToPath } from "node:url";--const remote = "https://github.com/hypit-ai/hypit.git";-const target = join(homedir(), "hypit");--const fail = (message) => { console.error(`locate-repository: ${message}`); process.exit(1); };--function isCheckout(directory) {- try {- return JSON.parse(readFileSync(join(directory, "package.json"), "utf8")).name === "@hypit/repository";- } catch { return false; }-}--function nearestCheckout(start) {- let directory = resolve(start);- while (true) {- if (isCheckout(directory)) return directory;- const parent = dirname(directory);- if (parent === directory) return undefined;- directory = parent;- }-}--function clone() {- if (existsSync(target)) fail(`${target} exists and is not a Hypit checkout; move it or set HYPIT_REPOSITORY`);- try {- execFileSync("git", ["clone", remote, target], { stdio: ["ignore", "inherit", "inherit"], windowsHide: true });- } catch (error) {- if (error?.code === "ENOENT") fail("git is not installed");- fail(`git clone ${remote} ${target} failed`);- }- if (!isCheckout(target)) fail(`git clone ${remote} ${target} produced no checkout`);- return target;-}--function locate() {- const override = process.env.HYPIT_REPOSITORY?.trim();- if (override) {- const directory = resolve(override);- if (!isCheckout(directory)) fail(`HYPIT_REPOSITORY is not a Hypit checkout: ${directory}`);- return ["env", directory];- }- const fromWorkingDirectory = nearestCheckout(process.cwd());- if (fromWorkingDirectory !== undefined) return ["cwd", fromWorkingDirectory];- const fromSkill = nearestCheckout(dirname(fileURLToPath(import.meta.url)));- if (fromSkill !== undefined) return ["skill", fromSkill];- if (isCheckout(target)) return ["home", target];- return ["cloned", clone()];-}--const [source, repository] = locate();-console.log(`repository\t${repository}`);-console.log(`source\t${source}`);-console.log(`installed\t${existsSync(join(repository, "node_modules", "@hypit")) ? "yes" : "no"}`);diff --git a/.agents/skills/hypit/scripts/preview-check.mjs b/.agents/skills/hypit/scripts/preview-check.mjsdeleted file mode 100644index 96aded09..00000000--- a/.agents/skills/hypit/scripts/preview-check.mjs+++ /dev/null@@ -1,125 +0,0 @@-#!/usr/bin/env node-/**- * Preview-check a reconstruction before it is delivered.- *- * `pnpm hypit check` proves a Source is legal; it proves nothing about whether- * the tracks it declares can actually be built. A track that fails here fails- * the same way when the author opens Studio, so find out now.- *- * Usage: node --import tsx .agents/skills/hypit/scripts/preview-check.mjs <build.svrun> [<hypit.runtime.json>]- * Exit: 0 when the graph is sound — either Studio opened and every Track- * resolved, or the only thing missing is Providers that have not run.- * 1 when the graph itself is wrong, naming what refused and why.- *- * The argument is the Run Source, not the Author SVML. Studio's unit of work is- * the Run — it reads the Author SVML back out of it — so a check that took the- * `.svml` would be checking something Studio never opens.- *- * Studio names what it cannot resolve and stops, so preflight throwing is itself- * the report rather than something to inspect around. Two kinds of issue come- * back, and they mean opposite things. An unresolved *capability* means the- * graph traced all the way to a Film and a semantic spine, and what remains is- * work a Provider has to do — the ordinary state of a Source that declares its- * generation rather than performing it. Every other issue means the graph is- * wrong and no amount of generation will fix it. Only the second kind fails.- * `StudioPreflightError` carries `issues` as an array so the two can be told- * apart rather than matched out of one joined message.- *- * Run it from the repository root. `tsx` is the repository's own dependency, so- * a working directory outside the repository fails to resolve it before this- * script runs at all — the error names `tsx`, not the source being checked.- */-import { dirname, resolve } from "node:path";-import { fileURLToPath } from "node:url";--// The script lives under `.agents/`; resolve Studio from the repo root.-// Stay in URL space the whole way: a specifier built from a filesystem path is read as a URL, so-// on Windows the drive letter becomes a scheme and the import fails before it resolves anything.-const studio = (name) => new URL(`../../../../packages/studio/src/${name}`, import.meta.url).href;-const { openStudioArchive } = await import(studio("archive.js"));-const { loadStudioAdapterRegistry } = await import(studio("adapter-profile.js"));-const { loadStudioDomain } = await import(studio("domain.js"));-const { loadStudioRun } = await import(studio("run.js"));-const { readStudioSession } = await import(studio("session.js"));-const { inspectStudioRun } = await import(studio("studio-preflight.js"));-const { videoCliDistribution } = await import(new URL("../../../../packages/video-cli/src/index.js", import.meta.url).href);--const runArgument = process.argv[2];-if (runArgument === undefined) {- console.error("usage: preview-check.mjs <build.svrun> [<hypit.runtime.json>]");- process.exit(2);-}-const invokedFrom = process.env.INIT_CWD ?? process.cwd();-const runPath = resolve(invokedFrom, runArgument);-const runtimeArgument = process.argv[3];-const runtimePath = runtimeArgument === undefined ? undefined : resolve(invokedFrom, runtimeArgument);-const workspaceRoot = dirname(runPath);-const packageRoot = workspaceRoot;-const distributionPackageRoot = videoCliDistribution.packageRoot- ?? fileURLToPath(new URL("../../../..", import.meta.url));--const registry = await loadStudioAdapterRegistry({ workspaceRoot, packageRoot, distributionPackageRoot });-const domain = await loadStudioDomain({ run: runPath, workspaceRoot, packageRoot });-const archive = await openStudioArchive(runtimePath, packageRoot, distributionPackageRoot);-const AWAITING = "the Studio projection closure requires unresolved capabilities:";--let session;-let refusal;-let awaiting;-try {- const run = await loadStudioRun({- run: runPath,- domain,- ...(archive === undefined ? {} : { archive }),- });- // Preflight first, so an unopenable Run is reported as the refusal it is- // rather than as whatever the build happens to fail on afterwards.- inspectStudioRun(registry, run.source, run);- session = await readStudioSession({- domain,- registry,- run,- ...(archive === undefined ? {} : { archive }),- revision: 0,- });-} catch (error) {- const issues = Array.isArray(error?.issues) ? error.issues : undefined;- if (issues !== undefined && issues.every((issue) => issue.startsWith(AWAITING))) {- awaiting = issues.flatMap((issue) => issue.slice(AWAITING.length).split(",").map((c) => c.trim()));- } else {- refusal = error instanceof Error ? error.message : String(error);- }-} finally {- // Close before reporting: `process.exit` in a `try` skips the `finally`, and- // a runtime archive left open outlives the check.- await archive?.close();-}--if (refusal !== undefined) {- console.log(JSON.stringify({ refused: refusal }, null, 2));- process.exit(1);-}--if (awaiting !== undefined) {- // The graph traced all the way to a Film and a semantic spine; what is left is- // work a Provider has to do. That is a pass for this gate, and the delivery- // measurements happen on the real Build either way.- const noun = awaiting.length === 1 ? "capability" : "capabilities";- console.log(`preview-check: the graph is sound, waiting on ${awaiting.length} ${noun}.`);- for (const capability of awaiting) console.log(` - ${capability}`);- process.exit(0);-}--const problems = [];-for (const track of session.snapshot.tracks) {- const { status, errors, output } = track.provenance;- if (errors.length > 0) problems.push({ track: track.label, errors });- else if (status === "unresolved") problems.push({ track: track.label, unresolved: output });-}--if (problems.length === 0) {- console.log(`preview-check: every Track resolved (${session.snapshot.tracks.length}).`);- process.exit(0);-}-for (const item of problems) console.log(JSON.stringify(item, null, 2));-process.exit(1);diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex 21f98b9a..b6b5d33a 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -3,9 +3,6 @@ name: CIon:push:branches: [main]- # Documentation-only changes are covered by deploy-pages.yml, which builds the site and runs- # the same repository hygiene checks. Nothing under docs/ is in tsconfig's include or reachable- # from the test suite, so type checking and the full test suite would prove nothing here.paths-ignore:- "docs/**"pull_request:@@ -19,22 +16,11 @@ concurrency:jobs:check:- # Windows-only breakage used to reach authors instead of this file — a render whose temporary- # paths ran past the length a Windows path may be, a transcriber that opened a console window- # per worker, a script that could not import itself, a file name that on one platform was the- # whole path. One matrix rather than two jobs, so a step added here cannot be added to only- # one of them.- #- # Neither runner image ships ffmpeg, so the media tests that probe for it skip on both legs- # alike. That gap is real and older than this matrix; closing it means adding ffmpeg to both,- # not to one, which would leave a red leg ambiguous between the two causes.runs-on: ${{ matrix.os }}strategy:- # Breakage on one platform is a different finding from breakage on the other, and cancelling- # the second leg would throw away the half of the answer nobody has yet.fail-fast: falsematrix:- os: [ubuntu-latest, windows-latest]+ os: [macos-latest, windows-latest]steps:- name: Checkoutuses: actions/checkout@v4diff --git a/bin/hypit-preview-check.mjs b/bin/hypit-preview-check.mjsnew file mode 100644index 00000000..edf5a084--- /dev/null+++ b/bin/hypit-preview-check.mjs@@ -0,0 +1,17 @@+#!/usr/bin/env node+import { register } from "tsx/esm/api";+import { dirname, resolve } from "node:path";+import { fileURLToPath } from "node:url";++const distributionRoot = resolve(dirname(fileURLToPath(import.meta.url)), "..");+process.env.HYPIT_DISTRIBUTION_ROOT ??= distributionRoot;+process.env.INIT_CWD ??= process.cwd();+register();+const {+ installDistributionPackageResolution,+ installExternalPackageResolution,+} = await import("../packages/package-loader-node/src/distribution-resolution.ts");+installDistributionPackageResolution([distributionRoot]);+const { hypitHostPackageRoot } = await import("../packages/runtime-host-node/src/index.ts");+installExternalPackageResolution([hypitHostPackageRoot()]);+await import("../packages/studio/preview-check.ts");diff --git a/bin/hypit-studio.mjs b/bin/hypit-studio.mjsindex ba64e206..295c6f2f 100755--- a/bin/hypit-studio.mjs+++ b/bin/hypit-studio.mjs@@ -1,9 +1,30 @@#!/usr/bin/env nodeimport { register } from "tsx/esm/api";+import { dirname, resolve } from "node:path";+import { fileURLToPath } from "node:url";// Keep author-relative paths anchored to the caller even though Studio itself// is executed from the replaceable Hypit Distribution checkout.process.env.INIT_CWD ??= process.cwd();+const distributionRoot = resolve(dirname(fileURLToPath(import.meta.url)), "..");+process.env.HYPIT_DISTRIBUTION_ROOT ??= distributionRoot;register();+const {+ installDistributionPackageResolution,+ installExternalPackageResolution,+} = await import("../packages/package-loader-node/src/distribution-resolution.ts");+installDistributionPackageResolution([distributionRoot]);+const {+ hypitHostPackageRoot,+ prepareHostPackages,+} = await import("../packages/runtime-host-node/src/index.ts");+const machinePackages = hypitHostPackageRoot();+installExternalPackageResolution([machinePackages]);+await prepareHostPackages(["[email protected]"], {+ root: machinePackages,+ onProgress(event) {+ if (event.phase === "installing") process.stderr.write(`Installing ${event.specifier} for Studio...\n`);+ },+});await import("../packages/studio/start.ts");diff --git a/bin/hypit.mjs b/bin/hypit.mjsindex 34bcd27e..b12ab643 100755--- a/bin/hypit.mjs+++ b/bin/hypit.mjs@@ -1,6 +1,15 @@#!/usr/bin/env nodeimport { register } from "tsx/esm/api";+import { readFileSync } from "node:fs";+import { dirname, resolve } from "node:path";+import { fileURLToPath } from "node:url";++if (process.argv.length === 3 && ["--version", "-v"].includes(process.argv[2])) {+ const manifest = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));+ console.log(manifest.version);+ process.exit(0);+}const emitWarning = process.emitWarning;process.emitWarning = function hypitWarning(warning, ...args) {@@ -9,6 +18,15 @@ process.emitWarning = function hypitWarning(warning, ...args) {return emitWarning.call(process, warning, ...args);};+const distributionRoot = resolve(dirname(fileURLToPath(import.meta.url)), "..");process.env.HYPIT_CLI_LAUNCHER ??= import.meta.filename;+process.env.HYPIT_DISTRIBUTION_ROOT ??= distributionRoot;register();+const {+ installDistributionPackageResolution,+ installExternalPackageResolution,+} = await import("../packages/package-loader-node/src/distribution-resolution.ts");+installDistributionPackageResolution([distributionRoot]);+const { hypitHostPackageRoot } = await import("../packages/runtime-host-node/src/index.ts");+installExternalPackageResolution([hypitHostPackageRoot()]);await import("../packages/video-cli/src/cli.ts");diff --git a/package.json b/package.jsonindex 033c9e05..8b578c00 100644--- a/package.json+++ b/package.json@@ -1,15 +1,42 @@{- "name": "@hypit/repository",- "version": "0.0.1",+ "name": "hypit",+ "version": "0.1.0",+ "description": "Hypit video authoring Distribution for AI agents","license": "SEE LICENSE IN LICENSE",- "private": true,"type": "module","bin": {"hypit": "./bin/hypit.mjs","hypit-studio": "./bin/hypit-studio.mjs",+ "hypit-preview-check": "./bin/hypit-preview-check.mjs","hypit-reference-video-tools": "./packages/reference-video-tools/bin/reference-video-tools.mjs"},"packageManager": "[email protected]",+ "files": [+ "bin",+ "packages/*/src/**/*",+ "packages/*/bin/**/*",+ "packages/*/runtime/**/*",+ "packages/*/preview/**/*",+ "packages/*/kits/**/*",+ "packages/*/*.ts",+ "packages/*/*.html",+ "packages/*/package.json",+ "packages/*/README.md",+ "services/image-opencv/pyproject.toml",+ "services/image-opencv/package.json",+ "services/image-opencv/uv.lock",+ "services/image-opencv/README.md",+ "services/whisperx/pyproject.toml",+ "services/whisperx/package.json",+ "services/whisperx/uv.lock",+ "services/whisperx/README.md",+ "services/whisperx/src/**/*.py",+ "docs/public/hypit-logo-dark.svg",+ "docs/public/hypit-logo-light.svg",+ "README.md",+ "README.zh-CN.md",+ "LICENSE"+ ],"scripts": {"check": "tsc -p tsconfig.json --noEmit","docs:dev": "vitepress dev docs",@@ -27,8 +54,7 @@"build:media-lambda-layer": "pnpm --filter @hypit/media-lambda build:layer"},"engines": {- "node": ">=22",- "pnpm": ">=10.33.0 <11"+ "node": ">=22"},"devDependencies": {"@hypit/artifact": "workspace:*",@@ -41,7 +67,7 @@"@hypit/comment-sticker": "workspace:*","@hypit/composition": "workspace:*","@hypit/credential-store-env": "workspace:*",- "@hypit/credential-store-keychain": "workspace:*",+ "@hypit/credential-store-os": "workspace:*","@hypit/deck-track": "workspace:*","@hypit/estimate": "workspace:*","@hypit/film": "workspace:*",@@ -52,12 +78,11 @@"@hypit/hyperframes": "workspace:*","@hypit/image-compose": "workspace:*","@hypit/image-transform": "workspace:*",- "@hypit/runtime-local": "workspace:*","@hypit/media": "workspace:*",- "@hypit/media-track": "workspace:*","@hypit/media-pipeline": "workspace:*",- "@hypit/minimax-h3": "workspace:*",+ "@hypit/media-track": "workspace:*","@hypit/mimo-tts": "workspace:*",+ "@hypit/minimax-h3": "workspace:*","@hypit/nano-banana": "workspace:*","@hypit/narrative": "workspace:*","@hypit/program-space": "workspace:*",@@ -74,8 +99,9 @@"@hypit/raster": "workspace:*","@hypit/render-hyperframes": "workspace:*","@hypit/run-markup": "workspace:*",- "@hypit/runtime-kit": "workspace:*","@hypit/runtime-host-node": "workspace:*",+ "@hypit/runtime-kit": "workspace:*",+ "@hypit/runtime-local": "workspace:*","@hypit/screen-overlay": "workspace:*","@hypit/script": "workspace:*","@hypit/seedance": "workspace:*",@@ -97,9 +123,10 @@"@hypit/visual-ir": "workspace:*","@hypit/whisperx": "workspace:*","@types/node": "24.10.1",- "tsx": "4.21.0","typescript": "5.9.3",- "vite": "5.4.21","vitepress": "^1.6.4"+ },+ "dependencies": {+ "tsx": "4.21.0"}}diff --git a/packages/artifact-store-s3/package.json b/packages/artifact-store-s3/package.jsonindex 9fdfb8c2..791abfaf 100644--- a/packages/artifact-store-s3/package.json+++ b/packages/artifact-store-s3/package.json@@ -11,7 +11,7 @@"activation": "./src/activation.ts"},"dependencies": {- "@aws-sdk/client-s3": "^3.1103.0",+ "@aws-sdk/client-s3": "3.1103.0","@hypit/protocol": "workspace:*","@hypit/runtime": "workspace:*","@hypit/runtime-kit": "workspace:*"diff --git a/packages/cli/src/main.ts b/packages/cli/src/main.tsindex 44f0b106..7eee7b40 100644--- a/packages/cli/src/main.ts+++ b/packages/cli/src/main.ts@@ -4,6 +4,11 @@ import { mkdir, readFile, stat, writeFile } from "node:fs/promises";import type { NodeCompiledSourceClosure } from "@hypit/compiler-node";import type { NodeRuntimeHost } from "@hypit/runtime-host-node";+import {+ hypitHostPackageRoot,+ inspectHostPackage,+ prepareHostPackages,+} from "@hypit/runtime-host-node";import { plannedNeeds } from "@hypit/runtime";import type { BuildCatalogDescriptor, CapacityReservation, OperationProgress } from "@hypit/runtime";import type { BuildState, CapabilityRef, TypeRef } from "@hypit/protocol";@@ -68,8 +73,6 @@ type ParsedArgs = {readonly model: string | undefined;readonly aspectRatio: string | undefined;readonly resolution: string | undefined;- /** Leave the declared external programs alone; build against what is running. */- readonly noPrograms: boolean;readonly json: boolean;readonly color: CliColorMode;readonly verbose: boolean;@@ -108,7 +111,8 @@ async function resolvePackageRoot(projectStart: string): Promise<string> {function parseArgs(argv: readonly string[]): ParsedArgs {const [command, ...tail] = argv;- const scoped = command === "programs" || command === "runtime" || command === "auth";+ const scoped = command === "programs" || command === "runtime" || command === "auth"+ || command === "packages";const action = scoped ? tail[0] : undefined;const positional = scoped ? tail.slice(1) : tail;const noFile = command === "builds" || command === "queue" || command === "paths"@@ -132,7 +136,6 @@ function parseArgs(argv: readonly string[]): ParsedArgs {let model: string | undefined;let aspectRatio: string | undefined;let resolution: string | undefined;- let noPrograms = false;let json = false;let color: CliColorMode = "auto";let verbose = false;@@ -149,7 +152,7 @@ function parseArgs(argv: readonly string[]): ParsedArgs {if (item.startsWith("--")) {const repeatable = ["--json", "--jsonl", "--watch", "--verbose", "--debug",- "--no-color", "--follow", "--no-programs", "--asset-root",+ "--no-color", "--follow", "--asset-root",].includes(item);if (!repeatable && seenOptions.has(item)) throw new Error(`${item} cannot be repeated`);seenOptions.add(item);@@ -288,10 +291,6 @@ function parseArgs(argv: readonly string[]): ParsedArgs {pin = true;continue;}- if (item === "--no-programs") {- noPrograms = true;- continue;- }if (item === "--max-wait-ms") {const value = rest[index + 1];if (value === undefined || value.startsWith("--")) throw new Error("--max-wait-ms requires milliseconds");@@ -359,7 +358,6 @@ function parseArgs(argv: readonly string[]): ParsedArgs {model,aspectRatio,resolution,- noPrograms,json,color,verbose,@@ -388,6 +386,8 @@ function assertCommandOptions(args: ParsedArgs): void {add("--runtime");if (args.action === "up" || args.action === "down") add("--max-wait-ms");break;+ case "packages":+ break;case "auth":add("--runtime", "--slot");if (args.action === "login") add("--from");@@ -424,7 +424,7 @@ function assertCommandOptions(args: ParsedArgs): void {break;case "build":add("--runtime", "--package-root", "--workspace", "--asset-root", "--follow",- "--max-wait-ms", "--no-programs");+ "--max-wait-ms");break;}const invalid = args.seenOptions.find((item) => !allowed.has(item));@@ -448,10 +448,11 @@ function usage(): string {" hypit runtime use <runtime-profile>"," hypit runtime unset"," hypit runtime up|status|logs|down [<runtime-profile>]",+ " hypit packages install|status <package@exact-version>"," hypit queue [--runtime profile.json] [--watch]"," hypit check <self-described-source> [--runtime profile.json] [--workspace workspace] [--asset-root directory]"," hypit plan <run-source> [--runtime profile.json] [--workspace workspace] [--asset-root directory]",- " hypit build <run-source> [--runtime profile.json] [--workspace workspace] [--asset-root directory] [--follow] [--no-programs]",+ " hypit build <run-source> [--runtime profile.json] [--workspace workspace] [--asset-root directory] [--follow]"," hypit status <build-id> [--runtime profile.json] [--watch]"," hypit builds [--runtime profile.json]"," hypit history [source-output-name] [--runtime profile.json] [--source author.svml] [--pin]",@@ -503,41 +504,6 @@ function createCatalogDescriptor(options: {};}-/**- * Starts the external programs the Runtime Profile's Endpoints declare, before- * the Build reaches an Operation that would need one. A WhisperX that is not- * running otherwise surfaces as a refused connection partway through, after the- * paid generation ahead of it has already been spent.- *- * Programs are started and left running: a developer submits several Builds- * against one warm program, and stopping it between them would pay the model- * load every time. `hypit programs down` ends them.- */-async function startDeclaredPrograms(- controller: CliRuntimeController,- capabilities: readonly CapabilityRef[],- onProgress?: (event: CliManagedProgramProgress) => void,-): Promise<readonly CliManagedProgramReport[] | undefined> {- const result = await controller.programs.up({- capabilities,- ...(onProgress === undefined ? {} : { onProgress }),- });- const unavailable = result.programs.filter((item) => item.state.state !== "ready");- if (unavailable.length > 0) {- throw new Error([- `${unavailable.length} external program${unavailable.length === 1 ? " is" : "s are"} not ready:`,- // The report carries two reasons that do not overlap: what the probe saw,- // and why the attempt to fix it fell short. Both name a different repair.- ...unavailable.map((item) => ` ${item.id}: ${item.state.state}`- + `${"detail" in item.state ? ` — ${item.state.detail}` : ""}`- + `${item.detail === undefined ? "" : `; ${item.detail}`}`- + `${item.logPath === undefined ? "" : ` (log: ${item.logPath})`}`),- "Fix the program, or pass --no-programs to build against what is already running.",- ].join("\n"));- }- return result.programs;-}-function demandedCapabilities(state: BuildState): readonly CapabilityRef[] {const found = new Map(plannedNeeds(state).map((need) => [capabilityName(need.capability), need.capability]));return [...found.entries()].sort(([left], [right]) => left.localeCompare(right)).map(([, value]) => value);@@ -552,7 +518,7 @@ async function preflightPlan(state: BuildState,) {const capabilities = demandedCapabilities(state);- const result = await host.doctor({ capabilities });+ const result = await host.preflight({ capabilities });return {ok: !result.diagnostics.some((item) => item.severity === "error"),dataRoot: result.dataRoot,@@ -563,12 +529,9 @@ async function preflightPlan(function assertPreflight(preflight: Awaited<ReturnType<typeof preflightPlan>>,- ignoredCodes: ReadonlySet<string> = new Set(),): void {if (preflight === undefined || preflight.ok) return;- const errors = preflight.diagnostics.filter((item) =>- item.severity === "error" && !ignoredCodes.has(item.code));- if (errors.length === 0) return;+ const errors = preflight.diagnostics.filter((item) => item.severity === "error");throw new Error([`Runtime preflight failed for ${errors.length} demanded deployment requirement${errors.length === 1 ? "" : "s"}:`,...errors.map((item) => ` ${item.code}${item.subject === undefined ? "" : ` (${item.subject})`}: ${item.message}`),@@ -821,13 +784,18 @@ export async function runCli(: (event: CliManagedProgramProgress): void => {const verb = {checking: "Checking",- preparing: "Preparing",+ installing: "Installing",starting: "Starting",waiting: "Waiting for",ready: "Ready",}[event.phase];io.write(` · ${verb} ${event.id}\n`);};+ const reportPackageProgress = args.json || args.jsonl+ ? undefined+ : (event: { readonly specifier: string; readonly phase: "checking" | "installing" | "ready" }): void => {+ if (event.phase === "installing") io.write(` · Installing ${event.specifier}\n`);+ };const runtimeHosts = new Map<string, Promise<NodeRuntimeHost>>();const runtimeHost = async (path: string, requestedPackageRoot?: string): Promise<NodeRuntimeHost> => {const profile = resolve(path);@@ -910,7 +878,7 @@ export async function runCli(|| args.command === "inspect" || args.command === "get" || args.command === "cancel"|| args.command === "doctor" || args.command === "programs"|| args.command === "runtime" || args.command === "queue" || args.command === "paths"- || args.command === "image";+ || args.command === "image" || args.command === "packages";const operational = known || args.command === "auth";const fileOptional = args.command === "builds" || args.command === "history" || args.command === "queue"|| args.command === "paths" || args.command === "image"@@ -927,9 +895,6 @@ export async function runCli(if (args.command === "queue" && args.watch && args.json) {throw new Error("queue --watch is a stream; use --jsonl instead of --json");}- if (args.noPrograms && args.command !== "build") {- throw new Error("--no-programs is only valid for build; no other command starts an external program");- }if (args.command === "history" && args.file === undefined && args.source === undefined) {throw new Error("history requires an output name or --source path");}@@ -989,6 +954,8 @@ export async function runCli(profile: args.runtime,runtimeData: runtimePaths?.runtimeDataRoot,hostState: hypitHostStateRoot(),+ machinePackages: hypitHostPackageRoot(),+ distribution: distribution.packageRoot,};writeOperational(machine, "Hypit paths", "info", [["Project", machine.project],@@ -996,7 +963,37 @@ export async function runCli(["Runtime Profile", machine.profile ?? "not selected"],["Runtime data", machine.runtimeData ?? "not selected"],["Host state", machine.hostState],+ ["Machine packages", machine.machinePackages],+ ["Distribution", machine.distribution ?? "embedded"],+ ]);+ return;+ }+ if (args.command === "packages") {+ if (args.action !== "install" && args.action !== "status") {+ throw new Error("packages takes install or status");+ }+ if (args.file === undefined) throw new Error(`packages ${args.action} requires package@exact-version`);+ const root = hypitHostPackageRoot();+ const existing = await inspectHostPackage(args.file, root);+ const reports = args.action === "install"+ ? await prepareHostPackages([args.file], {+ root,+ ...(reportPackageProgress === undefined ? {} : { onProgress: reportPackageProgress }),+ })+ : existing === undefined ? [] : [existing];+ const ready = reports.length === 1;+ writeOperational({+ format: "hypit.cli-packages-status@1",+ ok: ready,+ root,+ packages: reports,+ }, args.action === "install" ? "Machine package is ready" : "Machine package status",+ ready ? "success" : "warning", [+ ["Package", args.file],+ ["Root", root],+ ["Ready", String(ready)],]);+ if (!ready) io.setExitCode?.(1);return;}if (args.command === "doctor") {@@ -1035,6 +1032,10 @@ export async function runCli(const profileInput = args.runtime ?? args.file;if (profileInput === undefined) throw new Error("programs requires a Runtime Profile");const profile = resolve(profileInput);+ const host = await runtimeHost(profile);+ const prepared = args.action === "up"+ ? await host.prepare(reportPackageProgress === undefined ? {} : { onProgress: reportPackageProgress })+ : [];const controller = await runtimeController(profile);const result = args.action === "up"? await controller.programs.up({@@ -1052,6 +1053,7 @@ export async function runCli(ok: args.action === "status" ? true : desiredState,ready,dataRoot: result.dataRoot,+ packages: prepared,programs: result.programs,};const shownPrograms = args.verbose || args.action !== "status"@@ -1078,9 +1080,13 @@ export async function runCli(const profile = resolve(profileInput);const controller = await runtimeController(profile);if (args.action === "up") {- // Read the Runtime Profile before starting the Worker or its programs.const packageRoot = await packageRootForProject();- const validated = await loadRuntime(await runtimeHost(profile, packageRoot));+ const host = await runtimeHost(profile, packageRoot);+ const prepared = await host.prepare(+ reportPackageProgress === undefined ? {} : { onProgress: reportPackageProgress },+ );+ // Read the Runtime Profile before starting the Worker or its programs.+ const validated = await loadRuntime(host);await validated.close();const external = await controller.programs.up({...(args.maxWaitMs === undefined ? {} : { maxWaitMs: args.maxWaitMs }),@@ -1091,8 +1097,9 @@ export async function runCli(});const ok = processState.state === "running"&& external.programs.every((item) => item.state.state === "ready");- writeOperational({ ok, worker: processState, programs: external.programs }, "Runtime is up",+ writeOperational({ ok, packages: prepared, worker: processState, programs: external.programs }, "Runtime is up",ok ? "success" : "warning", [+ ["Machine packages", String(prepared.length)],["Worker", String(processState.pid)],["External programs", String(external.programs.length)],]);@@ -1200,7 +1207,7 @@ export async function runCli(: `configure ${item.ref.key} through CredentialStore ${item.ref.store}`;throw new Error(`CredentialStore ${item.ref.store} is read-only for ${item.label}; ${source}, `- + "or select a writable CredentialStore such as keychain in the Runtime Profile",+ + "or select the writable OS CredentialStore in the Runtime Profile",);}const raw = args.from === undefined@@ -1737,22 +1744,12 @@ export async function runCli(const controller = await (await runtimeHost(args.runtime)).controller({packageRoot: sourcePackageRoot,});- let programs: Awaited<ReturnType<typeof startDeclaredPrograms>> | undefined;let worker = await controller.worker.status();const preflight = await preflightPlan(await runtimeHost(args.runtime), result.state);- // A managed program being down is repairable after Runtime validation;- // every other deployment error fails before we construct execution or- // start anything. With --no-programs, readiness errors remain fatal.- assertPreflight(preflight, args.noPrograms- ? new Set()- : new Set(["MANAGED_PROGRAM_DOWN", "MANAGED_PROGRAM_MISMATCH"]));- programs = args.noPrograms- ? undefined- : await startDeclaredPrograms(- controller,- demandedCapabilities(result.state),- reportProgramProgress,- );+ // Build is an execution boundary, not a provisioning command. The cheap+ // preflight must already be clean; `runtime up` is the explicit place for+ // installing or starting declared programs.+ assertPreflight(preflight);runtime = await loadRuntime(await runtimeHost(args.runtime));let built = await runtime.build(request);try {@@ -1801,9 +1798,6 @@ export async function runCli(build: built.id,status: built.status,worker,- ...(programs === undefined ? {} : {- programs: programs.map((item) => ({ id: item.id, action: item.action })),- }),goals: built.state.plan.goals.map((goal) => {const record = built.state.records.find((item) => item.id === goal.record);return {@@ -1879,7 +1873,7 @@ export async function runCli(kind: "plan",machine: {format: "hypit.cli-plan@1",- ok: true,+ ok: preflight?.ok ?? true,plan: result.definition.plan,unreached: unreachedGenerations(result.compilation.author.graph, result.state, outputNames),...(preflight === undefined ? {} : { preflight }),@@ -1888,6 +1882,7 @@ export async function runCli(outputNames,satisfactionNames: loaded.run.satisfactionNames,});+ if (preflight !== undefined && !preflight.ok) io.setExitCode?.(1);} finally {await runtime?.close();}diff --git a/packages/cli/src/output.ts b/packages/cli/src/output.tsindex 3b534ecc..3ffc2b84 100644--- a/packages/cli/src/output.ts+++ b/packages/cli/src/output.ts@@ -438,10 +438,9 @@ function commandHelp(topic: string, colors: Palette): readonly string[] | undeficolors.accent(colors.strong("hypit build")),colors.dim("Submit one durable Build and ensure its selected Runtime Worker is available."),"",- " hypit build <run-source> [--runtime <profile>] [--asset-root <directory>] [--follow] [--no-programs]",+ " hypit build <run-source> [--runtime <profile>] [--asset-root <directory>] [--follow]",""," --follow observe the Build; the Worker still owns execution",- " --no-programs do not start declared external programs"," --max-wait-ms <ms> bound startup or follow waiting",],runtime: [@@ -450,14 +449,24 @@ function commandHelp(topic: string, colors: Palette): readonly string[] | undefi""," hypit runtime use <profile> select the Profile for this project"," hypit runtime unset remove only the local selection",- " hypit runtime up [<profile>] validate the Profile, start programs and Worker",+ " hypit runtime up [<profile>] prepare selected packages, programs and Worker"," hypit runtime status [<profile>] inspect Worker, queue capacity and declared programs"," hypit runtime logs [<profile>] read Worker logs"," hypit runtime down [<profile>] stop the Worker; external programs keep running",],+ packages: [+ colors.accent(colors.strong("hypit packages")),+ colors.dim("Inspect or install one pinned upstream npm package in the shared machine home."),+ "",+ " hypit packages status <package@exact-version>",+ " hypit packages install <package@exact-version>",+ "",+ "The package is reused by every project and later session on this machine.",+ "npm owns the ordinary package.json; Hypit creates no package lock or receipt.",+ ],programs: [colors.accent(colors.strong("hypit programs")),- colors.dim("Operate only the external programs declared by Endpoints in one Runtime Profile."),+ colors.dim("Prepare and operate external programs declared by Endpoints in one Runtime Profile."),""," hypit programs up [<profile>] [--max-wait-ms <ms>]"," hypit programs status [<profile>]",@@ -584,8 +593,9 @@ export function writeCliHelp(io: CliIo, topic?: string): void {colors.strong("Runtime"),row("doctor [profile]", "validate deployment without executing"),row("runtime use|unset", "select this project's Runtime Profile"),- row("runtime up|status|logs|down", "manage the durable Worker"),+ row("runtime up|status|logs|down", "prepare deployment and manage the Worker"),row("programs up|status|down", "manage declared external programs only"),+ row("packages install|status", "manage pinned upstream packages in the machine home"),row("queue [--watch]", "inspect durable dispatch and shared capacity"),row("paths", "show every effective state location"),row("auth status|login|logout", "manage Endpoint-declared credential references"),diff --git a/packages/cli/src/paths.ts b/packages/cli/src/paths.tsindex 431900d6..8ccddae6 100644--- a/packages/cli/src/paths.ts+++ b/packages/cli/src/paths.ts@@ -1,28 +1,6 @@-import { homedir } from "node:os";-import { join, resolve } from "node:path";+import { resolve } from "node:path";-export function hypitHostStateRoot(options: {- readonly env?: NodeJS.ProcessEnv;- readonly platform?: NodeJS.Platform;- readonly home?: string;-} = {}): string {- const env = options.env ?? process.env;- const override = env.HYPIT_STATE_HOME;- if (override !== undefined && override.trim().length > 0) return resolve(override);- const platform = options.platform ?? process.platform;- const home = options.home ?? homedir();- if (platform === "darwin") return join(home, "Library", "Application Support", "Hypit");- if (platform === "win32") {- const local = env.LOCALAPPDATA;- return join(local === undefined || local.trim().length === 0- ? join(home, "AppData", "Local")- : local, "Hypit");- }- const state = env.XDG_STATE_HOME;- return join(state === undefined || state.trim().length === 0- ? join(home, ".local", "state")- : state, "hypit");-}+export { hypitHostStateRoot } from "@hypit/runtime-host-node";export function hypitProjectStateRoot(projectRoot: string): string {return resolve(projectRoot, ".hypit");diff --git a/packages/cli/test/build-programs.test.ts b/packages/cli/test/build-programs.test.tsindex f25abf27..29778726 100644--- a/packages/cli/test/build-programs.test.ts+++ b/packages/cli/test/build-programs.test.ts@@ -1,5 +1,5 @@import assert from "node:assert/strict";-import { mkdtemp, writeFile } from "node:fs/promises";+import { mkdtemp, readFile, writeFile } from "node:fs/promises";import { tmpdir } from "node:os";import { join } from "node:path";import test from "node:test";@@ -8,7 +8,7 @@ import { createRunFrontendHostFacet } from "@hypit/run";import { runCli } from "../src/main.js";import type { CliDistribution } from "../src/distribution.js";-import type { CliManagedProgramReport } from "../src/runtime-port.js";+import type { RuntimeDoctorDiagnostic } from "@hypit/runtime-kit";const io = { write: () => {} };@@ -19,7 +19,7 @@ const io = { write: () => {} };*/function distribution(calls: string[],- programs: readonly CliManagedProgramReport[],+ diagnostics: readonly RuntimeDoctorDiagnostic[],): CliDistribution {return {bootstrapPackages: [{@@ -28,16 +28,65 @@ function distribution(format: "hypit.node-package@1",hostFacets: [createRunFrontendHostFacet({id: "@hypit/run-markup@1",- discover() { throw new Error("createRuntime is unavailable"); },- decode() { throw new Error("createRuntime is unavailable"); },+ discover: () => ({ author: { source: "./main.svml" }, imports: [] }),+ decode: () => ({ document: {+ format: "hypit.run-document@1",+ author: { source: "./main.svml" },+ imports: [],+ targets: [{ output: "result" }],+ candidates: [],+ satisfactions: [],+ } }),})],},}],createCompiler: () => ({- openFile: async (path: string) => ({- entry: { name: path, text: '<?svml using="@hypit/run-markup@1"?>\n<svrun/>\n' },- }),+ openFile: async (path: string) => {+ const source = async (name: string) => ({ id: name, name, text: await readFile(name, "utf8") });+ return {+ entry: await source(path),+ resolveSource: async (_importer: unknown, request: { readonly from: string }) =>+ await source(join(path, "..", request.from)),+ attachments: async () => [],+ };+ },supportsFrontend: () => false,+ compileSource: async (entry: { readonly id: string }) => ({+ closure: { entry: entry.id, units: [] },+ program: { closure: { format: "hypit.closure@1", modules: [{ manifest: {+ format: "hypit.module@1",+ name: "example.value",+ version: "1",+ dependencies: [],+ types: [{ name: "Value" }],+ capabilities: [],+ producers: [],+ } }] }, records: [] },+ graph: {+ format: "hypit.graph@1",+ outputs: [{+ id: "result",+ type: { module: { name: "example.value", version: "1" }, name: "Value" },+ primary: "provided-result",+ }],+ candidates: [{+ id: "provided-result",+ type: { module: { name: "example.value", version: "1" }, name: "Value" },+ root: { kind: "value", value: {+ id: "record-result",+ value: { kind: "inline", value: "ready" },+ } },+ }],+ operations: [],+ },+ exports: [{+ name: "result",+ type: { module: { name: "example.value", version: "1" }, name: "Value" },+ ref: { kind: "logical-output", id: "result" },+ }],+ attachments: [],+ }),+ extendExecutionProgram: (program: unknown) => program,}),openRuntimeHost: async (path: string) => ({profile: path,@@ -54,12 +103,13 @@ function distribution(programs: {up: async () => {calls.push(`up ${path}`);- return { dataRoot: "/tmp", programs };+ return { dataRoot: "/tmp", programs: [] };},down: async () => ({ dataRoot: "/tmp", programs: [] }),report: async () => ({ dataRoot: "/tmp", programs: [] }),},}),+ preflight: async () => ({ dataRoot: "/tmp", diagnostics }),doctor: async () => ({ dataRoot: "/tmp", diagnostics: [] }),createRuntime: async () => { throw new Error("createRuntime is unavailable"); },openArchive: async () => ({ status: async () => ({}) }),@@ -71,10 +121,11 @@ async function runSource(): Promise<string> {const root = await mkdtemp(join(tmpdir(), "hypit-build-programs-"));const path = join(root, "build.svrun");await writeFile(path, '<?svml using="@hypit/run-markup@1"?>\n<svrun/>\n', "utf8");+ await writeFile(join(root, "main.svml"), "author", "utf8");return path;}-test("a Build that cannot construct its Runtime starts no declared external program", async () => {+test("Build fails its cheap preflight before submitting or starting programs", async () => {const calls: string[] = [];const source = await runSource();await assert.rejects(@@ -82,46 +133,65 @@ test("a Build that cannot construct its Runtime starts no declared external prog["build", source, "--runtime", "/p/hypit.runtime.json"],io,distribution(calls, [{- id: "whisperx",- instances: ["whisperx.local"],- action: "unchanged",- state: { state: "down", detail: "nothing is answering at http://127.0.0.1:8765" },- detail: "uv failed: no such project",+ severity: "error",+ code: "MANAGED_PROGRAM_DOWN",+ subject: "whisperx",+ message: "whisperx is not usable",}]),),- /createRuntime is unavailable/u,+ /Runtime preflight failed/u,);assert.deepEqual(calls, []);});-test("--no-programs leaves the declared programs alone", async () => {+test("Build never provisions programs after a clean preflight", async () => {const calls: string[] = [];const source = await runSource();- // Reaching the Runtime is the boundary just past the gate: the stub has no- // createRuntime, so arriving there proves the down program was- // never consulted rather than merely tolerated.await assert.rejects(async () => await runCli(- ["build", source, "--runtime", "/p/hypit.runtime.json", "--no-programs"],+ ["build", source, "--runtime", "/p/hypit.runtime.json"],io,- distribution(calls, [{- id: "whisperx",- instances: ["whisperx.local"],- state: { state: "down", detail: "nothing is answering" },- }]),+ distribution(calls, []),),/createRuntime is unavailable/u,);assert.deepEqual(calls, []);});-test("--no-programs belongs to build, the only command that starts a program", async () => {+test("the removed --no-programs switch is rejected", async () => {await assert.rejects(async () => await runCli(- ["plan", "/p/build.svrun", "--no-programs"],+ ["build", "/p/build.svrun", "--no-programs"],io,distribution([], []),),- /--no-programs is only valid for build/u,+ /unknown option --no-programs/u,+ );+});++test("plan preserves the frozen plan but exits non-zero when cheap preflight fails", async () => {+ const source = await runSource();+ let output = "";+ let exitCode: number | undefined;+ await runCli(+ ["plan", source, "--runtime", "/p/hypit.runtime.json", "--json"],+ {+ write(text) { output += text; },+ setExitCode(code) { exitCode = code; },+ },+ distribution([], [{+ severity: "error",+ code: "RUNTIME_CREDENTIAL_MISSING",+ message: "credential is absent",+ }]),);+ const value = JSON.parse(output) as {+ readonly ok: boolean;+ readonly plan: unknown;+ readonly preflight: { readonly ok: boolean };+ };+ assert.equal(value.ok, false);+ assert.equal(value.preflight.ok, false);+ assert.notEqual(value.plan, undefined);+ assert.equal(exitCode, 1);});diff --git a/packages/cli/test/programs-command.test.ts b/packages/cli/test/programs-command.test.tsindex 2f3068e5..17608235 100644--- a/packages/cli/test/programs-command.test.ts+++ b/packages/cli/test/programs-command.test.ts@@ -39,6 +39,7 @@ function distribution(calls: string[], reports: readonly CliManagedProgramReportbootstrapPackages: [],openRuntimeHost: async (path: string) => ({profile: path,+ prepare: async () => [],controller: async () => controller(path, calls, reports),}),} as unknown as CliDistribution;@@ -95,6 +96,7 @@ test("runtime up validates the Runtime before it starts Programs", async () => {...base,openRuntimeHost: async (path: string) => ({profile: path,+ prepare: async () => [],controller: async () => controller(path, calls),createRuntime: async () => { throw new Error("Runtime Profile conflict"); },}),diff --git a/packages/credential-store-env/test/store.test.ts b/packages/credential-store-env/test/store.test.tsindex c492f72b..5fa64dc3 100644--- a/packages/credential-store-env/test/store.test.ts+++ b/packages/credential-store-env/test/store.test.ts@@ -13,5 +13,5 @@ test("environment credentials resolve only the explicitly requested key", asyncsecret: "secret-value",});assert.equal(await store.resolve(credentialRef("env", "MISSING")), undefined);- assert.equal(await store.resolve(credentialRef("keychain", "PROVIDER_KEY")), undefined);+ assert.equal(await store.resolve(credentialRef("os", "PROVIDER_KEY")), undefined);});diff --git a/packages/credential-store-keychain/README.md b/packages/credential-store-keychain/README.mddeleted file mode 100644index b434b501..00000000--- a/packages/credential-store-keychain/README.md+++ /dev/null@@ -1,25 +0,0 @@-# `@hypit/credential-store-keychain`--macOS Keychain-backed implementation of the domain-neutral Runtime `CredentialStore` port, including-its optional writable facet.--It resolves only explicit `{ store: "keychain", key }` references and cannot enumerate credentials.-Secrets never enter Runtime Profile or BuildState. The package invokes the bounded-`/usr/bin/security find-generic-password` command without a shell and returns no command output on-failure.--The Runtime Profile adapter accepts one optional `service` name. Selecting this package requires the-explicit `process:keychain` permission. Merely installing it grants no credential authority.--`hypit auth login <endpoint> --runtime <profile>` writes only when an Endpoint's configured-`CredentialRef.store` is `keychain` and this exact Store instance was selected. `auth status` is-read-only; `auth logout` removes only that exact account. The CLI contains no Provider-name switch.--Add a value under the service/account pair selected by the Runtime Profile with:--```bash-security add-generic-password -s hypit -a KIE_API_KEY -w-```--The account name is the `CredentialRef.key`; the secret is prompted by the `security` command and-must not be committed to source or Profile data.diff --git a/packages/credential-store-keychain/src/activation.ts b/packages/credential-store-keychain/src/activation.tsdeleted file mode 100644index a783c427..00000000--- a/packages/credential-store-keychain/src/activation.ts+++ /dev/null@@ -1,32 +0,0 @@-import {- createRuntimeCredentialStoreAdapterFacet,- runtimeConfigExact,- runtimeConfigObject,- runtimeConfigString,-} from "@hypit/runtime-kit";--import { KeychainCredentialStore } from "./store.js";--const keychainCredentialStoreRuntimeAdapter = createRuntimeCredentialStoreAdapterFacet({- use: "@hypit/credential-store-keychain",- validate(context) {- const config = runtimeConfigObject(context.config, "keychain CredentialStore");- runtimeConfigExact(config, ["service"], "keychain CredentialStore");- runtimeConfigString(config.service, "keychain service");- },- open(context) {- const config = runtimeConfigObject(context.config, "keychain CredentialStore");- runtimeConfigExact(config, ["service"], "keychain CredentialStore");- return { value: new KeychainCredentialStore({- ...(runtimeConfigString(config.service, "keychain service") === undefined- ? {} : { service: config.service as string }),- }) };- },-});--export const hypitPackage = {- format: "hypit.node-package@1" as const,- hostFacets: [keychainCredentialStoreRuntimeAdapter],-};--export default hypitPackage;diff --git a/packages/credential-store-keychain/src/index.ts b/packages/credential-store-keychain/src/index.tsdeleted file mode 100644index a3b65aa7..00000000--- a/packages/credential-store-keychain/src/index.ts+++ /dev/null@@ -1,7 +0,0 @@-export { KeychainCredentialStore, keychainCredentialStoreModuleRef } from "./store.js";-export type {- CreateKeychainCredentialStorePackageOptions,- KeychainDeleter,- KeychainReader,- KeychainWriter,-} from "./store.js";diff --git a/packages/credential-store-keychain/src/store.ts b/packages/credential-store-keychain/src/store.tsdeleted file mode 100644index b2926e07..00000000--- a/packages/credential-store-keychain/src/store.ts+++ /dev/null@@ -1,126 +0,0 @@-import { execFile } from "node:child_process";--import { verifyCredentialRef } from "@hypit/runtime";-import type {- CredentialRef,- CredentialValue,- WritableCredentialStore,-} from "@hypit/runtime";--export const keychainCredentialStoreModuleRef = {- name: "@hypit/credential-store-keychain",- version: "1",-} as const;--/** Reads one named secret. Substituted in tests so no test touches a real keychain. */-export type KeychainReader = (service: string, account: string) => Promise<string | undefined>;-export type KeychainWriter = (service: string, account: string, secret: string) => Promise<void>;-export type KeychainDeleter = (service: string, account: string) => Promise<boolean>;--export type CreateKeychainCredentialStorePackageOptions = {- readonly instance?: string;- /** Keychain service name every lookup is scoped to. */- readonly service?: string;- readonly read?: KeychainReader;- readonly write?: KeychainWriter;- readonly remove?: KeychainDeleter;-};--const DEFAULT_SERVICE = "hypit";--/**- * `security find-generic-password -s <service> -a <account> -w`- *- * The account is the CredentialRef key, so a lookup asks for exactly the one- * entry it was told to ask for. Nothing here can enumerate the keychain, and a- * failure never carries the tool's output, which may quote the item.- */-function macosSecurity(service: string): KeychainReader {- return async (_service, account) => await new Promise((resolve, reject) => {- execFile("/usr/bin/security",- ["find-generic-password", "-s", service, "-a", account, "-w"],- { timeout: 10_000, shell: false, windowsHide: true },- (error, stdout) => {- if (error === null) {- resolve(stdout.replace(/\n$/u, ""));- return;- }- // 44 is "item not found": an answer, not a failure.- if ((error as { code?: number }).code === 44) resolve(undefined);- else reject(new Error(`keychain lookup for ${account} failed`));- });- });-}--function macosWriter(service: string): KeychainWriter {- return async (_service, account, secret) => await new Promise((resolve, reject) => {- execFile("/usr/bin/security",- ["add-generic-password", "-U", "-s", service, "-a", account, "-w", secret],- { timeout: 10_000, shell: false, windowsHide: true },- (error) => error === null ? resolve() : reject(new Error(`keychain write for ${account} failed`)));- });-}--function macosDeleter(service: string): KeychainDeleter {- return async (_service, account) => await new Promise((resolve, reject) => {- execFile("/usr/bin/security",- ["delete-generic-password", "-s", service, "-a", account],- { timeout: 10_000, shell: false, windowsHide: true },- (error) => {- if (error === null) resolve(true);- else if ((error as { code?: number }).code === 44) resolve(false);- else reject(new Error(`keychain delete for ${account} failed`));- });- });-}--/**- * A CredentialStore backed by the operating system keychain.- *- * It answers only for `store: "keychain"` references, exactly as the- * environment store answers only for `store: "env"`. Anything else is not its- * business and it says so by returning undefined rather than guessing.- */-export class KeychainCredentialStore implements WritableCredentialStore {- readonly #read: KeychainReader;- readonly #write: KeychainWriter;- readonly #remove: KeychainDeleter;- readonly #service: string;-- constructor(options: {- readonly service?: string;- readonly read?: KeychainReader;- readonly write?: KeychainWriter;- readonly remove?: KeychainDeleter;- } = {}) {- this.#service = options.service ?? DEFAULT_SERVICE;- this.#read = options.read ?? macosSecurity(this.#service);- this.#write = options.write ?? macosWriter(this.#service);- this.#remove = options.remove ?? macosDeleter(this.#service);- }-- owns(ref: CredentialRef): boolean {- return ref.store === "keychain";- }-- async resolve(ref: CredentialRef): Promise<CredentialValue | undefined> {- verifyCredentialRef(ref);- if (ref.store !== "keychain") return undefined;- const secret = await this.#read(this.#service, ref.key);- if (secret === undefined || secret.length === 0) return undefined;- return { secret };- }-- async put(ref: CredentialRef, value: CredentialValue): Promise<void> {- verifyCredentialRef(ref);- if (!this.owns(ref)) throw new Error(`keychain CredentialStore does not own ${ref.store}`);- if (value.secret.length === 0) throw new Error("credential secret is empty");- await this.#write(this.#service, ref.key, value.secret);- }-- async delete(ref: CredentialRef): Promise<boolean> {- verifyCredentialRef(ref);- if (!this.owns(ref)) throw new Error(`keychain CredentialStore does not own ${ref.store}`);- return await this.#remove(this.#service, ref.key);- }-}diff --git a/packages/credential-store-keychain/test/store.test.ts b/packages/credential-store-keychain/test/store.test.tsdeleted file mode 100644index e1811fb4..00000000--- a/packages/credential-store-keychain/test/store.test.ts+++ /dev/null@@ -1,46 +0,0 @@-import assert from "node:assert/strict";-import test from "node:test";--import { credentialRef } from "@hypit/runtime";--import { KeychainCredentialStore } from "@hypit/credential-store-keychain";--const reader = (entries: Readonly<Record<string, string>>) =>- async (_service: string, account: string) => entries[account];--test("it answers for its own store name and declines every other", async () => {- const store = new KeychainCredentialStore({ read: reader({ KIE_API_KEY: "secret" }) });- assert.deepEqual(await store.resolve(credentialRef("keychain", "KIE_API_KEY")), { secret: "secret" });- // Not this store's business: the environment store's references are not- // guessed at, they are declined.- assert.equal(await store.resolve(credentialRef("env", "KIE_API_KEY")), undefined);-});--test("an absent entry is absent, and an empty one is not a secret", async () => {- const store = new KeychainCredentialStore({ read: reader({ EMPTY: "" }) });- assert.equal(await store.resolve(credentialRef("keychain", "ABSENT")), undefined);- assert.equal(await store.resolve(credentialRef("keychain", "EMPTY")), undefined);-});--test("a malformed reference is refused before anything is looked up", async () => {- let asked = 0;- const store = new KeychainCredentialStore({ read: async () => { asked += 1; return "x"; } });- await assert.rejects(async () => await store.resolve({ store: "keychain", key: " " } as never));- assert.equal(asked, 0);-});--test("writable facet stores and removes only keychain-owned references", async () => {- const values = new Map<string, string>();- const store = new KeychainCredentialStore({- read: async (_service, account) => values.get(account),- write: async (_service, account, secret) => { values.set(account, secret); },- remove: async (_service, account) => values.delete(account),- });- const ref = credentialRef("keychain", "provider.api-key");- assert.equal(store.owns(ref), true);- await store.put(ref, { secret: "new-secret" });- assert.deepEqual(await store.resolve(ref), { secret: "new-secret" });- assert.equal(await store.delete(ref), true);- assert.equal(await store.resolve(ref), undefined);- await assert.rejects(store.put(credentialRef("env", "PROVIDER_KEY"), { secret: "x" }), /does not own/u);-});diff --git a/packages/credential-store-os/README.md b/packages/credential-store-os/README.mdnew file mode 100644index 00000000..313df6b3--- /dev/null+++ b/packages/credential-store-os/README.md@@ -0,0 +1,13 @@+# `@hypit/credential-store-os`++Writable Runtime `CredentialStore` backed by the current user's operating-system credential locker:+macOS Keychain or Windows Credential Locker. Runtime Profiles use one stable `{ store: "os", key }`+reference on both systems; Source and project files never contain the secret.++The adapter accepts one optional `service` name. It reads, writes or deletes only the exact+service/account pair requested by the selected Endpoint and cannot enumerate credentials. Windows+passes the request over a private child-process pipe to the packaged PowerShell bridge, so secret+bytes do not appear in command arguments or temporary files.++Use `hypit auth login <endpoint> --runtime <profile>` to write the selected credential and+`hypit auth logout` to remove it.diff --git a/packages/credential-store-keychain/package.json b/packages/credential-store-os/package.jsonsimilarity index 75%rename from packages/credential-store-keychain/package.jsonrename to packages/credential-store-os/package.jsonindex 6ba85966..39f08026 100644--- a/packages/credential-store-keychain/package.json+++ b/packages/credential-store-os/package.json@@ -1,5 +1,5 @@{- "name": "@hypit/credential-store-keychain",+ "name": "@hypit/credential-store-os","version": "0.0.0-dev","license": "SEE LICENSE IN LICENSE","private": true,@@ -7,6 +7,11 @@"exports": {".": "./src/index.ts"},+ "files": [+ "src",+ "runtime",+ "README.md"+ ],"hypit": {"activation": "./src/activation.ts"},diff --git a/packages/credential-store-os/runtime/windows-credential.ps1 b/packages/credential-store-os/runtime/windows-credential.ps1new file mode 100644index 00000000..ce87d5b2--- /dev/null+++ b/packages/credential-store-os/runtime/windows-credential.ps1@@ -0,0 +1,57 @@+param(+ [Parameter(Mandatory = $true)]+ [ValidateSet("read", "write", "delete")]+ [string]$Operation+)++$ErrorActionPreference = "Stop"+[Console]::OutputEncoding = New-Object System.Text.UTF8Encoding($false)+$request = [Console]::In.ReadToEnd() | ConvertFrom-Json+$null = [Windows.Security.Credentials.PasswordVault, Windows.Security.Credentials, ContentType = WindowsRuntime]+$null = [Windows.Security.Credentials.PasswordCredential, Windows.Security.Credentials, ContentType = WindowsRuntime]+$vault = New-Object Windows.Security.Credentials.PasswordVault+$notFound = -2147023728 # HRESULT_FROM_WIN32(ERROR_NOT_FOUND)++function Find-Credential {+ try {+ return $vault.Retrieve([string]$request.service, [string]$request.account)+ } catch {+ if ($_.Exception.HResult -eq $notFound) { return $null }+ throw+ }+}++switch ($Operation) {+ "read" {+ $credential = Find-Credential+ if ($null -eq $credential) {+ @{ found = $false } | ConvertTo-Json -Compress+ break+ }+ $credential.RetrievePassword()+ $bytes = [System.Text.Encoding]::UTF8.GetBytes($credential.Password)+ @{ found = $true; secret = [Convert]::ToBase64String($bytes) } | ConvertTo-Json -Compress+ }+ "write" {+ $existing = Find-Credential+ if ($null -ne $existing) { $vault.Remove($existing) }+ $bytes = [Convert]::FromBase64String([string]$request.secret)+ $secret = [System.Text.Encoding]::UTF8.GetString($bytes)+ $credential = New-Object Windows.Security.Credentials.PasswordCredential(+ [string]$request.service,+ [string]$request.account,+ $secret+ )+ $vault.Add($credential)+ @{ ok = $true } | ConvertTo-Json -Compress+ }+ "delete" {+ $credential = Find-Credential+ if ($null -eq $credential) {+ @{ deleted = $false } | ConvertTo-Json -Compress+ break+ }+ $vault.Remove($credential)+ @{ deleted = $true } | ConvertTo-Json -Compress+ }+}diff --git a/packages/credential-store-os/src/activation.ts b/packages/credential-store-os/src/activation.tsnew file mode 100644index 00000000..1d563f31--- /dev/null+++ b/packages/credential-store-os/src/activation.ts@@ -0,0 +1,32 @@+import {+ createRuntimeCredentialStoreAdapterFacet,+ runtimeConfigExact,+ runtimeConfigObject,+ runtimeConfigString,+} from "@hypit/runtime-kit";++import { OsCredentialStore } from "./store.js";++const osCredentialStoreRuntimeAdapter = createRuntimeCredentialStoreAdapterFacet({+ use: "@hypit/credential-store-os",+ validate(context) {+ const config = runtimeConfigObject(context.config, "OS CredentialStore");+ runtimeConfigExact(config, ["service"], "OS CredentialStore");+ runtimeConfigString(config.service, "OS credential service");+ },+ open(context) {+ const config = runtimeConfigObject(context.config, "OS CredentialStore");+ runtimeConfigExact(config, ["service"], "OS CredentialStore");+ return { value: new OsCredentialStore({+ ...(runtimeConfigString(config.service, "OS credential service") === undefined+ ? {} : { service: config.service as string }),+ }) };+ },+});++export const hypitPackage = {+ format: "hypit.node-package@1" as const,+ hostFacets: [osCredentialStoreRuntimeAdapter],+};++export default hypitPackage;diff --git a/packages/credential-store-os/src/index.ts b/packages/credential-store-os/src/index.tsnew file mode 100644index 00000000..88cc2fe5--- /dev/null+++ b/packages/credential-store-os/src/index.ts@@ -0,0 +1,2 @@+export { OsCredentialStore, osCredentialStoreModuleRef } from "./store.js";+export type { OsCredentialDeleter, OsCredentialReader, OsCredentialWriter } from "./store.js";diff --git a/packages/credential-store-os/src/store.ts b/packages/credential-store-os/src/store.tsnew file mode 100644index 00000000..1e7edbda--- /dev/null+++ b/packages/credential-store-os/src/store.ts@@ -0,0 +1,196 @@+import { execFile, spawn } from "node:child_process";+import { fileURLToPath } from "node:url";++import { verifyCredentialRef } from "@hypit/runtime";+import type {+ CredentialRef,+ CredentialValue,+ WritableCredentialStore,+} from "@hypit/runtime";++export const osCredentialStoreModuleRef = {+ name: "@hypit/credential-store-os",+ version: "1",+} as const;++export type OsCredentialReader = (service: string, account: string) => Promise<string | undefined>;+export type OsCredentialWriter = (service: string, account: string, secret: string) => Promise<void>;+export type OsCredentialDeleter = (service: string, account: string) => Promise<boolean>;++const DEFAULT_SERVICE = "hypit";++function macosReader(service: string): OsCredentialReader {+ return async (_service, account) => await new Promise((resolve, reject) => {+ execFile("/usr/bin/security", ["find-generic-password", "-s", service, "-a", account, "-w"], {+ timeout: 10_000, shell: false, windowsHide: true,+ }, (error, stdout) => {+ if (error === null) resolve(stdout.replace(/\n$/u, ""));+ else if ((error as { code?: number }).code === 44) resolve(undefined);+ else reject(new Error(`OS credential lookup for ${account} failed`));+ });+ });+}++function macosWriter(service: string): OsCredentialWriter {+ return async (_service, account, secret) => await new Promise((resolve, reject) => {+ const child = spawn("/usr/bin/security", ["add-generic-password", "-U", "-s", service, "-a", account, "-w"], {+ shell: false, windowsHide: true, stdio: ["pipe", "ignore", "ignore"],+ });+ const timeout = setTimeout(() => child.kill(), 10_000);+ child.on("error", (error) => { clearTimeout(timeout); reject(error); });+ child.on("close", (code) => {+ clearTimeout(timeout);+ if (code === 0) resolve();+ else reject(new Error(`OS credential write for ${account} failed`));+ });+ child.stdin.end(`${secret}\n`);+ });+}++function macosDeleter(service: string): OsCredentialDeleter {+ return async (_service, account) => await new Promise((resolve, reject) => {+ execFile("/usr/bin/security", ["delete-generic-password", "-s", service, "-a", account], {+ timeout: 10_000, shell: false, windowsHide: true,+ }, (error) => {+ if (error === null) resolve(true);+ else if ((error as { code?: number }).code === 44) resolve(false);+ else reject(new Error(`OS credential delete for ${account} failed`));+ });+ });+}++type WindowsCredentialResult = {+ readonly found?: boolean;+ readonly deleted?: boolean;+ readonly secret?: string;+};++const windowsScript = fileURLToPath(new URL("../runtime/windows-credential.ps1", import.meta.url));++function windowsCredential(+ operation: "read" | "write" | "delete",+ service: string,+ account: string,+ secret?: string,+): Promise<WindowsCredentialResult> {+ return new Promise((resolve, reject) => {+ const child = spawn("powershell.exe", [+ "-NoLogo", "-NoProfile", "-NonInteractive", "-ExecutionPolicy", "Bypass",+ "-File", windowsScript, "-Operation", operation,+ ], { shell: false, windowsHide: true, stdio: ["pipe", "pipe", "pipe"] });+ let stdout = "";+ let stderr = "";+ let settled = false;+ const fail = (error: Error): void => {+ if (settled) return;+ settled = true;+ reject(error);+ };+ child.on("error", fail);+ child.stdout.on("data", (chunk: Buffer) => {+ stdout += chunk.toString("utf8");+ if (stdout.length > 4 * 1024 * 1024) fail(new Error("Windows credential response is too large"));+ });+ child.stderr.on("data", (chunk: Buffer) => {+ stderr += chunk.toString("utf8");+ if (stderr.length > 64 * 1024) fail(new Error("Windows credential error is too large"));+ });+ child.on("close", (code) => {+ if (settled) return;+ if (code !== 0) {+ fail(new Error(`Windows credential ${operation} for ${account} failed${stderr.trim().length === 0 ? "" : `: ${stderr.trim()}`}`));+ return;+ }+ try {+ const result = JSON.parse(stdout.replace(/^\uFEFF/u, "").trim()) as WindowsCredentialResult;+ settled = true;+ resolve(result);+ } catch {+ fail(new Error(`Windows credential ${operation} returned an invalid response`));+ }+ });+ child.stdin.end(JSON.stringify({+ service,+ account,+ ...(secret === undefined ? {} : { secret: Buffer.from(secret, "utf8").toString("base64") }),+ }));+ });+}++function windowsBackend(): {+ readonly read: OsCredentialReader;+ readonly write: OsCredentialWriter;+ readonly remove: OsCredentialDeleter;+} {+ return {+ read: async (service, account) => {+ const result = await windowsCredential("read", service, account);+ return result.found === true && result.secret !== undefined+ ? Buffer.from(result.secret, "base64").toString("utf8")+ : undefined;+ },+ write: async (service, account, secret) => {+ await windowsCredential("write", service, account, secret);+ },+ remove: async (service, account) => (await windowsCredential("delete", service, account)).deleted === true,+ };+}++function platformBackend(service: string) {+ if (process.platform === "darwin") {+ return { read: macosReader(service), write: macosWriter(service), remove: macosDeleter(service) };+ }+ if (process.platform === "win32") return windowsBackend();+ throw new Error("OS CredentialStore supports macOS and Windows only");+}++/** One logical writable store backed by the current user's OS credential locker. */+export class OsCredentialStore implements WritableCredentialStore {+ readonly #read: OsCredentialReader;+ readonly #write: OsCredentialWriter;+ readonly #remove: OsCredentialDeleter;+ readonly #service: string;++ constructor(options: {+ readonly service?: string;+ readonly read?: OsCredentialReader;+ readonly write?: OsCredentialWriter;+ readonly remove?: OsCredentialDeleter;+ } = {}) {+ this.#service = options.service ?? DEFAULT_SERVICE;+ const supplied = options.read !== undefined || options.write !== undefined || options.remove !== undefined;+ if (supplied && (options.read === undefined || options.write === undefined || options.remove === undefined)) {+ throw new Error("OS CredentialStore test backend must provide read, write and remove together");+ }+ const backend = supplied+ ? { read: options.read!, write: options.write!, remove: options.remove! }+ : platformBackend(this.#service);+ this.#read = backend.read;+ this.#write = backend.write;+ this.#remove = backend.remove;+ }++ owns(ref: CredentialRef): boolean {+ return ref.store === "os";+ }++ async resolve(ref: CredentialRef): Promise<CredentialValue | undefined> {+ verifyCredentialRef(ref);+ if (!this.owns(ref)) return undefined;+ const secret = await this.#read(this.#service, ref.key);+ return secret === undefined || secret.length === 0 ? undefined : { secret };+ }++ async put(ref: CredentialRef, value: CredentialValue): Promise<void> {+ verifyCredentialRef(ref);+ if (!this.owns(ref)) throw new Error(`OS CredentialStore does not own ${ref.store}`);+ if (value.secret.length === 0) throw new Error("credential secret is empty");+ await this.#write(this.#service, ref.key, value.secret);+ }++ async delete(ref: CredentialRef): Promise<boolean> {+ verifyCredentialRef(ref);+ if (!this.owns(ref)) throw new Error(`OS CredentialStore does not own ${ref.store}`);+ return await this.#remove(this.#service, ref.key);+ }+}diff --git a/packages/credential-store-os/test/store.test.ts b/packages/credential-store-os/test/store.test.tsnew file mode 100644index 00000000..51064057--- /dev/null+++ b/packages/credential-store-os/test/store.test.ts@@ -0,0 +1,37 @@+import assert from "node:assert/strict";+import test from "node:test";++import { credentialRef } from "@hypit/runtime";+import { OsCredentialStore } from "@hypit/credential-store-os";++function memoryStore(entries: Readonly<Record<string, string>> = {}) {+ const values = new Map(Object.entries(entries));+ return new OsCredentialStore({+ read: async (_service, account) => values.get(account),+ write: async (_service, account, secret) => { values.set(account, secret); },+ remove: async (_service, account) => values.delete(account),+ });+}++test("the OS store owns one logical name and is writable without exposing another store", async () => {+ const store = memoryStore({ "provider.api-key": "secret" });+ const ref = credentialRef("os", "provider.api-key");+ assert.deepEqual(await store.resolve(ref), { secret: "secret" });+ assert.equal(await store.resolve(credentialRef("env", "PROVIDER_KEY")), undefined);+ await store.put(ref, { secret: "replacement" });+ assert.deepEqual(await store.resolve(ref), { secret: "replacement" });+ assert.equal(await store.delete(ref), true);+ assert.equal(await store.resolve(ref), undefined);+});++test("malformed and foreign references are refused before the backend is touched", async () => {+ let reads = 0;+ const store = new OsCredentialStore({+ read: async () => { reads += 1; return "x"; },+ write: async () => {},+ remove: async () => false,+ });+ await assert.rejects(async () => await store.resolve({ store: "os", key: " " } as never));+ await assert.rejects(async () => await store.put(credentialRef("env", "PROVIDER_KEY"), { secret: "x" }));+ assert.equal(reads, 0);+});diff --git a/packages/fonts-open/package.json b/packages/fonts-open/package.jsonindex b9f1d083..b8d993f8 100644--- a/packages/fonts-open/package.json+++ b/packages/fonts-open/package.json@@ -10,7 +10,7 @@"hypit": {"activation": "./src/activation.ts"},- "dependencies": {+ "optionalDependencies": {"@fontsource-variable/archivo": "5.3.0","@fontsource-variable/bodoni-moda": "5.3.0","@fontsource-variable/cabin": "5.3.0",@@ -119,7 +119,9 @@"@fontsource/zcool-kuaile": "5.3.0","@fontsource/zcool-qingke-huangyou": "5.3.0","@fontsource/zcool-xiaowei": "5.3.0",- "@infolektuell/noto-color-emoji": "0.2.0",+ "@infolektuell/noto-color-emoji": "0.2.0"+ },+ "dependencies": {"@hypit/media": "workspace:*","@hypit/protocol": "workspace:*","@hypit/markup": "workspace:*"diff --git a/packages/fonts-open/src/surface.ts b/packages/fonts-open/src/surface.tsindex 5c6d9126..bb8ad8c1 100644--- a/packages/fonts-open/src/surface.ts+++ b/packages/fonts-open/src/surface.ts@@ -23,6 +23,18 @@ import type {const require = createRequire(import.meta.url);+function resolveFontPackageFile(packageName: string, path: string): string {+ try {+ return require.resolve(`${packageName}/${path}`);+ } catch (error) {+ const version = packageName === "@infolektuell/noto-color-emoji" ? "0.2.0" : "5.3.0";+ throw new Error(+ `${packageName} is needed by this authored font. Install it once with: hypit packages install ${packageName}@${version}`,+ { cause: error },+ );+ }+}+function attributes(element: StructuredElement,required: readonly string[],@@ -76,7 +88,7 @@ function oneFile(const filename = family.kind === "static"? `${family.fileStem}-${weight}-${style}.woff2`: `${family.fileStem}-${style}.woff2`;- return require.resolve(`${family.packageName}/files/${filename}`);+ return resolveFontPackageFile(family.packageName, `files/${filename}`);}function splitFiles(@@ -89,7 +101,7 @@ function splitFiles(: family.kind === "external-split"? family.css: `${weight}${style === "italic" ? "-italic" : ""}.css`;- const cssPath = require.resolve(`${family.packageName}/${css}`);+ const cssPath = resolveFontPackageFile(family.packageName, css);const contents = readFileSync(cssPath, "utf8");return [...contents.matchAll(/@font-face\s*\{([\s\S]*?)\}/gu)].map((match) => {const body = match[1]!;@@ -98,7 +110,7 @@ function splitFiles(if (file === undefined || unicodeRange === undefined) {throw new Error(`${family.packageName}/${css} contains an unsupported @font-face`);}- return { path: require.resolve(`${family.packageName}/files/${file}`), unicodeRange };+ return { path: resolveFontPackageFile(family.packageName, `files/${file}`), unicodeRange };});}diff --git a/packages/package-loader-node/src/distribution-resolution.ts b/packages/package-loader-node/src/distribution-resolution.tsindex b2c4d228..33533efd 100644--- a/packages/package-loader-node/src/distribution-resolution.ts+++ b/packages/package-loader-node/src/distribution-resolution.ts@@ -1,20 +1,51 @@import { createRequire, registerHooks } from "node:module";import { basename, join, resolve } from "node:path";-import { existsSync, readFileSync } from "node:fs";+import { existsSync, readFileSync, readdirSync } from "node:fs";import { pathToFileURL } from "node:url";let installed: readonly string[] = [];+let externalInstalled: readonly string[] = [];++function packageAddress(specifier: string): { readonly name: string; readonly subpath: string } | undefined {+ const parts = specifier.split("/");+ if (specifier.startsWith("@")) {+ if (parts.length < 2) return undefined;+ return { name: `${parts[0]}/${parts[1]}`, subpath: parts.slice(2).join("/") };+ }+ return { name: parts[0]!, subpath: parts.slice(1).join("/") };+}++function packageDirectory(root: string, name: string): string | undefined {+ const conventional = join(root, "packages", basename(name));+ if (existsSync(join(conventional, "package.json"))) return conventional;+ const services = join(root, "services");+ if (!existsSync(services)) return undefined;+ for (const entry of readdirSync(services, { withFileTypes: true })) {+ if (!entry.isDirectory()) continue;+ const candidate = join(services, entry.name);+ const manifestPath = join(candidate, "package.json");+ if (!existsSync(manifestPath)) continue;+ const manifest = JSON.parse(readFileSync(manifestPath, "utf8")) as { readonly name?: string };+ if (manifest.name === name) return candidate;+ }+ return undefined;+}function distributionPackageEntry(root: string, specifier: string): string | undefined {- const packageRoot = join(root, "packages", basename(specifier));+ const address = packageAddress(specifier);+ if (address === undefined) return undefined;+ const packageRoot = packageDirectory(root, address.name);+ if (packageRoot === undefined) return undefined;const manifestPath = join(packageRoot, "package.json");- if (!existsSync(manifestPath)) return undefined;const manifest = JSON.parse(readFileSync(manifestPath, "utf8")) as {readonly name?: string;- readonly exports?: string | { readonly "."?: string };+ readonly exports?: string | Readonly<Record<string, string>>;};- if (manifest.name !== specifier) return undefined;- const declared = typeof manifest.exports === "string" ? manifest.exports : manifest.exports?.["."];+ if (manifest.name !== address.name) return undefined;+ const key = address.subpath.length === 0 ? "." : `./${address.subpath}`;+ const declared = typeof manifest.exports === "string"+ ? (key === "." ? manifest.exports : undefined)+ : manifest.exports?.[key];return declared === undefined ? undefined : resolve(packageRoot, declared);}@@ -32,17 +63,10 @@ export function installDistributionPackageResolution(roots: readonly string[]):registerHooks({resolve(specifier, context, nextResolve) {if (specifier.startsWith("@hypit/")) {- // Absolute/file parent ids are already part of this Distribution's- // module graph; let ordinary package-relative resolution use that- // package's own pnpm links.- if (context.parentURL !== undefined- && context.parentURL.startsWith("file:")- && rootUrls.some((root) => context.parentURL!.startsWith(root))) {- return nextResolve(specifier, context);- }- // Package-relative pnpm links are legitimate only when their real target- // remains in this Distribution. A project-local shadow with the same- // spelling resolves successfully too, so success alone is not enough.+ // A contributor checkout may resolve through workspace links. An installed+ // monolithic Distribution resolves from its own packages/services tree.+ // Accept ordinary resolution only when its real target remains inside this+ // Distribution; a project-local package with the same spelling may not shadow it.try {const found = nextResolve(specifier, context);if (found.url.startsWith("file:") && rootUrls.some((root) => found.url.startsWith(root))) {@@ -66,3 +90,36 @@ export function installDistributionPackageResolution(roots: readonly string[]):},});}++/**+ * Fall back to the machine npm home for upstream packages that are not part of+ * the Distribution or the current project. Project resolution always wins;+ * the @hypit namespace always remains Distribution-owned.+ */+export function installExternalPackageResolution(roots: readonly string[]): void {+ const next = roots.map((root) => resolve(root));+ if (next.every((root, index) => root === externalInstalled[index])+ && next.length === externalInstalled.length) return;+ if (externalInstalled.length > 0) {+ throw new Error("External package roots cannot change inside one Host process");+ }+ externalInstalled = next;+ const resolvers = externalInstalled.map((root) => createRequire(join(root, "__hypit_external__.cjs")));+ registerHooks({+ resolve(specifier, context, nextResolve) {+ if (specifier.startsWith("@hypit/")) return nextResolve(specifier, context);+ try {+ return nextResolve(specifier, context);+ } catch (original) {+ for (const resolver of resolvers) {+ try {+ return { url: pathToFileURL(resolver.resolve(specifier)).href, shortCircuit: true };+ } catch {+ // Try the next machine package root before preserving Node's error.+ }+ }+ throw original;+ }+ },+ });+}diff --git a/packages/package-loader-node/src/index.ts b/packages/package-loader-node/src/index.tsindex 51af8883..abaf5223 100644--- a/packages/package-loader-node/src/index.ts+++ b/packages/package-loader-node/src/index.ts@@ -5,6 +5,10 @@ export {loadNodePackageSelection,NodePackageSelectionMissingError,physicalPackageName,+ distributionExternalPackageRequirements,} from "./loader.js";-export { installDistributionPackageResolution } from "./distribution-resolution.js";+export {+ installDistributionPackageResolution,+ installExternalPackageResolution,+} from "./distribution-resolution.js";export type * from "./types.js";diff --git a/packages/package-loader-node/src/loader.ts b/packages/package-loader-node/src/loader.tsindex 1ca7d331..80b3adb4 100644--- a/packages/package-loader-node/src/loader.ts+++ b/packages/package-loader-node/src/loader.ts@@ -1,4 +1,4 @@-import { readFile, realpath, stat } from "node:fs/promises";+import { readFile, readdir, realpath, stat } from "node:fs/promises";import { createRequire } from "node:module";import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";import { pathToFileURL } from "node:url";@@ -15,7 +15,9 @@ import type {type PackageJson = {readonly name: string;+ readonly version?: string;readonly hypit?: { readonly activation?: string };+ readonly dependencies: Readonly<Record<string, string>>;};type ResolvedPackage = { readonly root: string; readonly json: PackageJson };@@ -37,9 +39,15 @@ function text(value: unknown, subject: string): string {function parsePackageJson(value: unknown, subject: string): PackageJson {const item = object(value, subject);const hypit = item.hypit === undefined ? undefined : object(item.hypit, `${subject}.hypit`);+ const dependencies = item.dependencies === undefined ? {} : object(item.dependencies, `${subject}.dependencies`);return {name: text(item.name, `${subject}.name`),+ ...(item.version === undefined ? {} : { version: text(item.version, `${subject}.version`) }),...(hypit?.activation === undefined ? {} : { hypit: { activation: text(hypit.activation, `${subject}.hypit.activation`) } }),+ dependencies: Object.fromEntries(Object.entries(dependencies).map(([name, version]) => [+ name,+ text(version, `${subject}.dependencies.${name}`),+ ])),};}@@ -78,12 +86,23 @@ async function resolvePackage(specifier: string, roots: readonly string[]): Promtry {entry = resolver.resolve(`${specifier}/package.json`);} catch {- const local = join(resolve(from), "packages", basename(specifier));+ const root = resolve(from);+ const local = join(root, "packages", basename(specifier));+ const candidates = [local];try {- const json = await packageJson(local);- if (json.name === specifier) return { root: local, json };- } catch (localError) {- if (!missingFile(localError)) throw localError;+ for (const service of await readdir(join(root, "services"), { withFileTypes: true })) {+ if (service.isDirectory()) candidates.push(join(root, "services", service.name));+ }+ } catch (servicesError) {+ if (!missingFile(servicesError)) throw servicesError;+ }+ for (const candidate of candidates) {+ try {+ const json = await packageJson(candidate);+ if (json.name === specifier) return { root: candidate, json };+ } catch (localError) {+ if (!missingFile(localError)) throw localError;+ }}failure = entryError;continue;@@ -126,6 +145,34 @@ async function importContribution(item: ResolvedPackage): Promise<NodePackageConreturn contribution as NodePackageContribution;}+function within(root: string, candidate: string): boolean {+ const relation = relative(resolve(root), resolve(candidate));+ return relation === "" || (relation !== ".." && !relation.startsWith(`..${sep}`) && !isAbsolute(relation));+}++async function assertExternalDependencies(+ item: ResolvedPackage,+ distributionRoots: readonly string[],+): Promise<void> {+ const resolver = createRequire(join(item.root, "__hypit_package_dependencies__.cjs"));+ const distributionOwned = distributionRoots.some((root) => within(root, item.root));+ for (const [name, required] of Object.entries(item.json.dependencies)) {+ if (name.startsWith("@hypit/") || required.startsWith("workspace:")) continue;+ try {+ const resolved = await packageRoot(resolver.resolve(name), name);+ if (/^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?$/u.test(required)+ && resolved.json.version !== required) {+ throw new Error(`installed version is ${resolved.json.version ?? "unknown"}`);+ }+ } catch (error) {+ const repair = distributionOwned+ ? `Install it once with: hypit packages install ${name}@${required}`+ : `Install it with the project package manager that owns ${item.root}`;+ throw new Error(`${item.json.name} requires ${name}@${required}. ${repair}`, { cause: error });+ }+ }+}+function addressKey(value: LogicalPackageAddress): string {return `${value.abi}\u0000${value.name}`;}@@ -159,6 +206,41 @@ export class NodePackageSelectionMissingError extends Error {}}+/**+ * Resolve the ordinary upstream npm dependencies of Distribution packages.+ * Internal @hypit dependencies are followed to their manifests; no project+ * package is copied into the machine dependency home.+ */+export async function distributionExternalPackageRequirements(+ specifiers: readonly string[],+ distributionRoot: string,+): Promise<readonly { readonly name: string; readonly version: string; readonly specifier: string }[]> {+ const root = resolve(distributionRoot);+ const queue = [...new Set(specifiers)].sort();+ const visited = new Set<string>();+ const external = new Map<string, string>();+ while (queue.length > 0) {+ const name = queue.shift()!;+ if (visited.has(name)) continue;+ visited.add(name);+ const physical = await resolvePackage(name, [root]);+ for (const [dependency, version] of Object.entries(physical.json.dependencies)) {+ if (dependency.startsWith("@hypit/")) {+ queue.push(dependency);+ continue;+ }+ const previous = external.get(dependency);+ if (previous !== undefined && previous !== version) {+ throw new Error(`${dependency} is required at both ${previous} and ${version} by the selected Distribution packages`);+ }+ external.set(dependency, version);+ }+ }+ return [...external.entries()]+ .sort(([left], [right]) => left.localeCompare(right))+ .map(([name, version]) => ({ name, version, specifier: `${name}@${version}` }));+}+/*** Load the packages explicitly named by Source discovery or a Runtime Profile.* Node's package manager owns installed versions and bytes; Hypit validates only the@@ -203,7 +285,10 @@ export async function loadNodePackageSelection(};for (const item of await Promise.all(roots.map(async (physical) => ({physical,- contribution: await importContribution(physical),+ contribution: await (async () => {+ await assertExternalDependencies(physical, distributionRoots);+ return await importContribution(physical);+ })(),})))) add(item);for (let cursor = 0; cursor < requirements.length; cursor += 1) {@@ -215,6 +300,7 @@ export async function loadNodePackageSelection(providerPackage,resolutionRoots(providerPackage, [requirement.from, root], distributionRoots),);+ await assertExternalDependencies(physical, distributionRoots);const provider = { physical, contribution: await importContribution(physical) };add(provider);assert(providedModules.has(requirement.key), `${providerPackage} does not provide the required ${requirement.key}`);diff --git a/packages/package-loader-node/test/loader.test.ts b/packages/package-loader-node/test/loader.test.tsindex f3ac1d8c..854a4848 100644--- a/packages/package-loader-node/test/loader.test.ts+++ b/packages/package-loader-node/test/loader.test.ts@@ -4,7 +4,10 @@ import { tmpdir } from "node:os";import { join } from "node:path";import test from "node:test";-import { loadNodePackageSelection } from "@hypit/package-loader-node";+import {+ distributionExternalPackageRequirements,+ loadNodePackageSelection,+} from "@hypit/package-loader-node";async function installedPackage(root: string,@@ -27,6 +30,7 @@ async function projectPackage(root: string,name: string,contribution: string,+ dependencies: Readonly<Record<string, string>> = {},): Promise<void> {const directory = join(root, "packages", name.split("/").at(-1)!);await mkdir(directory, { recursive: true });@@ -35,6 +39,7 @@ async function projectPackage(version: "0.0.0-dev",type: "module",hypit: { activation: "./activation.mjs" },+ dependencies,}), "utf8");await writeFile(join(directory, "activation.mjs"), `export default ${contribution};\n`, "utf8");}@@ -53,6 +58,31 @@ test("loads an explicitly selected installed package", async () => {}});+test("Distribution requirements follow internal packages and return only exact upstream npm packages", async () => {+ const root = await mkdtemp(join(tmpdir(), "hypit-distribution-requirements-"));+ try {+ await projectPackage(root, "@hypit/provider-example", `{+ format: "hypit.node-package@1"+ }`, {+ "@hypit/transport-example": "workspace:*",+ "example-sdk": "2.3.4",+ });+ await projectPackage(root, "@hypit/transport-example", `{+ format: "hypit.node-package@1"+ }`, {+ "example-transport": "1.2.3",+ });+ assert.deepEqual(await distributionExternalPackageRequirements(+ ["@hypit/provider-example"], root,+ ), [+ { name: "example-sdk", version: "2.3.4", specifier: "[email protected]" },+ { name: "example-transport", version: "1.2.3", specifier: "[email protected]" },+ ]);+ } finally {+ await rm(root, { recursive: true, force: true });+ }+});+test("resolves a logical request to its conventional installed package", async () => {const root = await mkdtemp(join(tmpdir(), "hypit-package-selection-"));try {diff --git a/packages/provider-hyperframes-aws-lambda/package.json b/packages/provider-hyperframes-aws-lambda/package.jsonindex 0dc3f51d..be865b13 100644--- a/packages/provider-hyperframes-aws-lambda/package.json+++ b/packages/provider-hyperframes-aws-lambda/package.json@@ -14,8 +14,8 @@"activation": "./src/activation.ts"},"dependencies": {- "@aws-sdk/client-s3": "^3.700.0",- "@aws-sdk/client-sfn": "^3.700.0",+ "@aws-sdk/client-s3": "3.1103.0",+ "@aws-sdk/client-sfn": "3.1103.0","@hyperframes/aws-lambda": "0.7.101","@hypit/endpoint-kit": "workspace:*","@hypit/hyperframes": "workspace:*",diff --git a/packages/provider-hyperframes-aws-lambda/test/provider.test.ts b/packages/provider-hyperframes-aws-lambda/test/provider.test.tsindex c0592a8d..c68b3d21 100644--- a/packages/provider-hyperframes-aws-lambda/test/provider.test.ts+++ b/packages/provider-hyperframes-aws-lambda/test/provider.test.ts@@ -246,6 +246,7 @@ test("the Runtime adapter refuses a hardware-GPU deployment wish instead of ignoconst facet = awsLambdaActivation.hostFacets[0]!;const implementation = facet.implementation as RuntimeEndpointAdapterImplementation;assert.throws(() => implementation.activate({+ hostStateRoot: "/host",dataRoot: "/tmp",instance: "hyperframes.lambda.test",pool: "hyperframes.lambda.test",diff --git a/packages/provider-hyperframes-local/src/program.ts b/packages/provider-hyperframes-local/src/program.tsindex 5168c9e6..a27a8e07 100644--- a/packages/provider-hyperframes-local/src/program.ts+++ b/packages/provider-hyperframes-local/src/program.ts@@ -32,20 +32,28 @@ export function localHyperframesBrowserProgram(const node = resolveRuntimeExecutable(context.dataRoot, configuredNode ?? process.execPath);const cli = resolveRuntimeExecutable(context.dataRoot, configuredCli ?? defaultHyperframesCliPath());const ffprobe = resolveRuntimeExecutable(context.dataRoot, configuredFfprobe ?? "ffprobe");+ const probeBrowser = async (): Promise<ManagedProgramState> => {+ const located = await run(node, [cli, "browser", "path"]);+ if (!located.ok) return { state: "down", detail: `HyperFrames browser is unavailable: ${located.output}` };+ const path = located.output.trim();+ if (path.length === 0 || path.includes("\n") || path.includes("\r")) {+ return { state: "mismatch", detail: "HyperFrames returned an invalid browser path" };+ }+ const version = await run(path, ["--version"]);+ if (!version.ok || version.output.length === 0) {+ return { state: "mismatch", detail: `HyperFrames browser cannot start: ${version.output}` };+ }+ return { state: "ready" };+ };return {id: "hyperframes-browser",- prepare: { command: node, args: [cli, "browser", "ensure"] },+ installation: {+ probe: probeBrowser,+ commands: [{ command: node, args: [cli, "browser", "ensure"] }],+ },async probe(): Promise<ManagedProgramState> {- const located = await run(node, [cli, "browser", "path"]);- if (!located.ok) return { state: "down", detail: `HyperFrames browser is unavailable: ${located.output}` };- const path = located.output.trim();- if (path.length === 0 || path.includes("\n") || path.includes("\r")) {- return { state: "mismatch", detail: "HyperFrames returned an invalid browser path" };- }- const version = await run(path, ["--version"]);- if (!version.ok || version.output.length === 0) {- return { state: "mismatch", detail: `HyperFrames browser cannot start: ${version.output}` };- }+ const browser = await probeBrowser();+ if (browser.state !== "ready") return browser;const media = await probeMediaToolchain({ ffprobePath: ffprobe });return media.state === "ready"? { state: "ready" }diff --git a/packages/provider-hyperframes-local/test/provider.test.ts b/packages/provider-hyperframes-local/test/provider.test.tsindex f0e50160..de810eff 100644--- a/packages/provider-hyperframes-local/test/provider.test.ts+++ b/packages/provider-hyperframes-local/test/provider.test.ts@@ -107,11 +107,13 @@ test("local HyperFrames Provider exposes one exact visual capability and two sep"Runtime request admission must remain separate from HyperFrames frame workers");});-test("the selected HyperFrames Provider owns one idempotent browser preparation", () => {- const program = localHyperframesBrowserProgram({ dataRoot: "/project", instance: "hyperframes", config: {} });+test("the selected HyperFrames Provider owns one idempotent browser installation", () => {+ const program = localHyperframesBrowserProgram({+ hostStateRoot: "/host", dataRoot: "/project", instance: "hyperframes", config: {},+ });assert.equal(program.id, "hyperframes-browser");assert.equal(program.start, undefined);- assert.deepEqual(program.prepare?.args.slice(-2), ["browser", "ensure"]);+ assert.deepEqual(program.installation?.commands[0]?.args.slice(-2), ["browser", "ensure"]);});test("local HyperFrames Provider really renders a silent frame-exact MP4 with parallel workers", {diff --git a/packages/provider-image-opencv-local/README.md b/packages/provider-image-opencv-local/README.mdindex a2c91e1c..915cff59 100644--- a/packages/provider-image-opencv-local/README.md+++ b/packages/provider-image-opencv-local/README.md@@ -8,8 +8,9 @@ interpolation, alpha and encoding primitives across both variants. It runs in aand stores one new image Artifact. Temporary paths, OpenCV details and diagnostics stay inside theEndpoint and never enter the image Product.-The repository ships the frozen deployment environment in `services/image-opencv`. With the Runtime-Adapter's declared configuration, `programs up` runs `uv sync --frozen`; the Endpoint and program probe-and doctor all resolve the resulting `.venv` interpreter. An explicit `pythonExecutable` selects an-operator-managed compatible environment and suppresses that managed prepare. Runtime admission and+The Distribution ships the frozen deployment source from `services/image-opencv`. With the Runtime+Adapter's declared configuration, `programs up` installs it only when the machine Program Home has no+healthy environment; the Endpoint, program probe and doctor all resolve the shared `.venv`+interpreter. An explicit `pythonExecutable` selects an operator-managed compatible environment and+suppresses the managed installation. Runtime admission andinner image work share the configured Endpoint pool/lane resources; no separate queue is hidden in this package.diff --git a/packages/provider-image-opencv-local/package.json b/packages/provider-image-opencv-local/package.jsonindex 161e2b38..03b44eb4 100644--- a/packages/provider-image-opencv-local/package.json+++ b/packages/provider-image-opencv-local/package.json@@ -15,6 +15,7 @@"@hypit/endpoint-kit": "workspace:*","@hypit/protocol": "workspace:*","@hypit/raster": "workspace:*",+ "@hypit/image-opencv-runtime": "workspace:*","@hypit/runtime-kit": "workspace:*","@hypit/runtime-host-node": "workspace:*"},diff --git a/packages/provider-image-opencv-local/src/deployment.ts b/packages/provider-image-opencv-local/src/deployment.tsindex 1f2e9f01..0c9e904e 100644--- a/packages/provider-image-opencv-local/src/deployment.ts+++ b/packages/provider-image-opencv-local/src/deployment.ts@@ -1,32 +1,31 @@import { existsSync } from "node:fs";+import { createRequire } from "node:module";import { join } from "node:path";-import { fileURLToPath } from "node:url";import { runtimeConfigObject, runtimeConfigString } from "@hypit/runtime-kit";import type { RuntimeAdapterFactoryContext, ManagedProgramCommand } from "@hypit/runtime-kit";-import { resolveRuntimeExecutable } from "@hypit/runtime-host-node";+import {+ pythonEnvironmentExecutable,+ resolveRuntimeExecutable,+} from "@hypit/runtime-host-node";/**- * Repository deployment bundled beside this Provider during development. A- * published package must ship the same project as package data; it must never- * silently fall back to an unrelated system Python.+ * The locked Python project is its own package asset. Repository workspaces and+ * installed npm distributions therefore resolve the same immutable input.*/-export const localOpenCvManagedProject = fileURLToPath(- new URL("../../../services/image-opencv", import.meta.url),+const require = createRequire(import.meta.url);+export const localOpenCvManagedProject = join(+ require.resolve("@hypit/image-opencv-runtime/pyproject.toml"),+ "..",);export type LocalOpenCvDeployment = {readonly pythonExecutable: string;- readonly prepare?: ManagedProgramCommand;+ readonly stateRoot?: string;+ readonly installCommands?: readonly ManagedProgramCommand[];readonly ownership: "managed" | "external";};-function managedPython(project: string): string {- return process.platform === "win32"- ? join(project, ".venv", "Scripts", "python.exe")- : join(project, ".venv", "bin", "python");-}-/*** One resolution function is shared by Endpoint construction, doctor and the* service lifecycle. An explicit executable is operator-owned and receives no@@ -49,12 +48,16 @@ export function resolveLocalOpenCvDeployment("local OpenCV has no bundled managed runtime; configure pythonExecutable explicitly",);}+ const stateRoot = join(context.hostStateRoot, "programs", "image-opencv");+ const environment = join(stateRoot, ".venv");return {- pythonExecutable: managedPython(localOpenCvManagedProject),- prepare: {+ pythonExecutable: pythonEnvironmentExecutable(environment),+ stateRoot,+ installCommands: [{command: "uv",args: ["sync", "--project", localOpenCvManagedProject, "--frozen"],- },+ env: { UV_PROJECT_ENVIRONMENT: environment },+ }],ownership: "managed",};}diff --git a/packages/provider-image-opencv-local/src/program.ts b/packages/provider-image-opencv-local/src/program.tsindex d57b6e45..d6b8e7d2 100644--- a/packages/provider-image-opencv-local/src/program.ts+++ b/packages/provider-image-opencv-local/src/program.ts@@ -32,8 +32,17 @@ export function localOpenCvProgram(context: RuntimeAdapterFactoryContext): Managconst python = deployment.pythonExecutable;return {id: "image-opencv",- ...(deployment.prepare === undefined ? {} : { prepare: deployment.prepare }),- async probe(): Promise<ManagedProgramState> {+ ...(deployment.stateRoot === undefined ? {} : { stateRoot: deployment.stateRoot }),+ ...(deployment.installCommands === undefined ? {} : {+ installation: {+ commands: deployment.installCommands,+ probe,+ },+ }),+ probe,+ };++ async function probe(): Promise<ManagedProgramState> {const result = await run(python, ["-c", PROBE_PROGRAM]);if (!result.ok) return { state: "down", detail: `${python} cannot import cv2 and numpy: ${result.output}` };let found: Record<string, string>;@@ -48,6 +57,5 @@ export function localOpenCvProgram(context: RuntimeAdapterFactoryContext): Managreturn differs.length === 0? { state: "ready" }: { state: "mismatch", detail: `${python} carries ${differs.join("; ")}` };- },- };+ }}diff --git a/packages/provider-image-opencv-local/test/program.test.ts b/packages/provider-image-opencv-local/test/program.test.tsindex 50c63e26..a8732176 100644--- a/packages/provider-image-opencv-local/test/program.test.ts+++ b/packages/provider-image-opencv-local/test/program.test.ts@@ -8,6 +8,7 @@ import test from "node:test";import { localOpenCvProgram } from "../src/program.js";const context = (config: Record<string, unknown> = {}) => ({+ hostStateRoot: join(tmpdir(), "hypit-opencv-host"),dataRoot: process.cwd(), instance: "opencv.test", config: config as never,});@@ -17,11 +18,12 @@ test("OpenCV declares how to install its interpreter and nothing to keep runningassert.equal(program.start, undefined, "OpenCV runs per Need; there is no daemon to start");// Absolute: a Runtime root is wherever the Profile lives, not where the// pinned uv project lives.- assert.equal(program.prepare?.command, "uv");- assert.equal(program.prepare?.args.at(-1), "--frozen");- const project = program.prepare?.args.at(-2) ?? "";+ assert.equal(program.installation?.commands[0]?.command, "uv");+ assert.equal(program.installation?.commands[0]?.args.at(-1), "--frozen");+ const project = program.installation?.commands[0]?.args.at(-2) ?? "";assert.ok(isAbsolute(project), `${project} must be absolute`);assert.ok(existsSync(join(project, "pyproject.toml")), `${project} must be the pinned uv project`);+ assert.equal(program.stateRoot, join(context().hostStateRoot, "programs", "image-opencv"));});test("an interpreter without cv2 is reported here, not mid-Build", async () => {@@ -51,8 +53,10 @@ test("an interpreter carrying another OpenCV major is a mismatch, not a failure"}});-test("the major versions the probe demands are the ones the locked project installs", async () => {- const pyproject = await readFile(new URL("../../../services/image-opencv/pyproject.toml", import.meta.url), "utf8");+test("the major versions the probe demands are the ones the packaged project installs", async () => {+ const project = localOpenCvProgram(context()).installation?.commands[0]?.args.at(-2);+ assert.ok(project);+ const pyproject = await readFile(join(project, "pyproject.toml"), "utf8");assert.match(pyproject, /"opencv-python-headless>=4\./u, "probe expects cv2 4.x");assert.match(pyproject, /"numpy>=2\./u, "probe expects numpy 2.x");});diff --git a/packages/provider-image-opencv-local/test/provider.test.ts b/packages/provider-image-opencv-local/test/provider.test.tsindex 3ce5310a..dabcccf2 100644--- a/packages/provider-image-opencv-local/test/provider.test.ts+++ b/packages/provider-image-opencv-local/test/provider.test.ts@@ -67,18 +67,19 @@ test("the OpenCV package is one replaceable Endpoint with no second queue", asyn});test("managed and external OpenCV deployments never mix their interpreters", () => {- const managedContext = { dataRoot: "/project", instance: "opencv", config: {} } as const;+ const managedContext = { hostStateRoot: "/host", dataRoot: "/project", instance: "opencv", config: {} } as const;const managed = resolveLocalOpenCvDeployment(managedContext);assert.equal(managed.ownership, "managed");// The deployment already branches on the platform for the venv layout, so the tail it produces// is joined with the platform's separator too. Spell the separator as either one.assert.match(managed.pythonExecutable,- /services[\\/]image-opencv[\\/]\.venv[\\/](?:bin[\\/]python|Scripts[\\/]python\.exe)$/u);- assert.deepEqual(managed.prepare?.args.slice(-1), ["--frozen"]);+ /host[\\/]programs[\\/]image-opencv[\\/]\.venv[\\/](?:bin[\\/]python|Scripts[\\/]python\.exe)$/u);+ assert.deepEqual(managed.installCommands?.[0]?.args.slice(-1), ["--frozen"]);const managedProgram = localOpenCvProgram(managedContext);- assert.deepEqual(managedProgram.prepare, managed.prepare);+ assert.deepEqual(managedProgram.installation?.commands, managed.installCommands);const externalContext = {+ hostStateRoot: "/host",dataRoot: "/project",instance: "opencv",config: { pythonExecutable: "./tools/python" },@@ -86,8 +87,8 @@ test("managed and external OpenCV deployments never mix their interpreters", ()const external = resolveLocalOpenCvDeployment(externalContext);assert.equal(external.ownership, "external");assert.equal(external.pythonExecutable, resolve(join("/project", "tools", "python")));- assert.equal(external.prepare, undefined);- assert.equal(localOpenCvProgram(externalContext).prepare, undefined);+ assert.equal(external.installCommands, undefined);+ assert.equal(localOpenCvProgram(externalContext).installation, undefined);});const liveEnabled = process.env.HYPIT_OPENCV_TESTS === "1";diff --git a/packages/provider-kie/README.md b/packages/provider-kie/README.mdindex cc0873de..1d4c6dd5 100644--- a/packages/provider-kie/README.md+++ b/packages/provider-kie/README.md@@ -42,7 +42,7 @@ Declarative activation names an ordinary CredentialRef, not an environment-speci"use": "@hypit/provider-kie","instance": "kie.personal","config": {- "apiKey": { "store": "keychain", "key": "kie.api-key" },+ "apiKey": { "store": "os", "key": "kie.api-key" },"defaultConcurrency": 8,"laneConcurrency": {"seedance-2.5": 4,diff --git a/packages/provider-media-local/test/provider.test.ts b/packages/provider-media-local/test/provider.test.tsindex c5119ee5..72826e8e 100644--- a/packages/provider-media-local/test/provider.test.ts+++ b/packages/provider-media-local/test/provider.test.ts@@ -31,9 +31,11 @@ const hasMediaBinaries = spawnSync("ffmpeg", ["-version"], { stdio: "ignore", wi&& spawnSync("ffprobe", ["-version"], { stdio: "ignore", windowsHide: true }).status === 0;test("the local media Provider declares its external toolchain without owning a second daemon", async () => {- const program = localMediaToolchainProgram({ dataRoot: "/project", instance: "media", config: {} });+ const program = localMediaToolchainProgram({+ hostStateRoot: "/host", dataRoot: "/project", instance: "media", config: {},+ });assert.equal(program.id, "media-ffmpeg-toolchain");- assert.equal(program.prepare, undefined);+ assert.equal(program.installation, undefined);assert.equal(program.start, undefined);const state = await program.probe();assert.equal(state.state, hasMediaBinaries ? "ready" : "down");diff --git a/packages/provider-whisperx-local/README.md b/packages/provider-whisperx-local/README.mdindex a794654b..c7cbed3a 100644--- a/packages/provider-whisperx-local/README.md+++ b/packages/provider-whisperx-local/README.md@@ -30,5 +30,6 @@ Provider; it is a different deployment package but must return the sameThe configured model, device, compute mode and batch size are checked through `/health` before use.This prevents a warm process with an incompatible inference configuration from accepting work.-Install and run the service with the commands in `services/whisperx/README.md`. The current local-package and service are trusted code; this is not a community-plugin sandbox.+The Runtime installs and starts the packaged service in the machine Program Home when this Endpoint+is selected. The environment is reused across projects and sessions. The current local package and+service are trusted code; this is not a community-plugin sandbox.diff --git a/packages/provider-whisperx-local/package.json b/packages/provider-whisperx-local/package.jsonindex 0ab821a6..0edf9a55 100644--- a/packages/provider-whisperx-local/package.json+++ b/packages/provider-whisperx-local/package.json@@ -13,9 +13,11 @@"dependencies": {"@hypit/endpoint-kit": "workspace:*","@hypit/protocol": "workspace:*",+ "@hypit/runtime-host-node": "workspace:*","@hypit/runtime-kit": "workspace:*","@hypit/speech-evidence": "workspace:*",- "@hypit/whisperx": "workspace:*"+ "@hypit/whisperx": "workspace:*",+ "@hypit/whisperx-service-runtime": "workspace:*"},"devDependencies": {"@hypit/driver-node": "workspace:*",diff --git a/packages/provider-whisperx-local/src/activation.ts b/packages/provider-whisperx-local/src/activation.tsindex 0e05b5d5..019e7790 100644--- a/packages/provider-whisperx-local/src/activation.ts+++ b/packages/provider-whisperx-local/src/activation.ts@@ -16,9 +16,9 @@ const localWhisperXRuntimeAdapter = createRuntimeEndpointAdapterFacet({const config = runtimeConfigObject(context.config, "local WhisperX");runtimeConfigExact(config, ["baseUrl", "expectedModel", "expectedDevice", "expectedCompute", "expectedBatchSize",- "expectedServiceVersion", "expectedWhisperXVersion", "expectedPunktTabDigest",+ "expectedServiceVersion", "expectedWhisperXVersion","defaultConcurrency", "requestTimeoutMs", "maxResponseBytes",- "serviceCommand", "servicePrepareCommand",+ "serviceCommand",], "local WhisperX");const baseUrl = runtimeConfigString(config.baseUrl, "WhisperX baseUrl");if (baseUrl !== undefined) {@@ -34,14 +34,10 @@ const localWhisperXRuntimeAdapter = createRuntimeEndpointAdapterFacet({const expectedBatchSize = runtimeConfigPositiveInteger(config.expectedBatchSize, "WhisperX expectedBatchSize");const expectedServiceVersion = runtimeConfigString(config.expectedServiceVersion, "WhisperX expectedServiceVersion");const expectedWhisperXVersion = runtimeConfigString(config.expectedWhisperXVersion, "WhisperX expectedWhisperXVersion");- const expectedPunktTabDigest = runtimeConfigString(config.expectedPunktTabDigest, "WhisperX expectedPunktTabDigest");- if (expectedPunktTabDigest !== undefined && !/^[0-9a-f]{64}$/u.test(expectedPunktTabDigest)) {- throw new Error("WhisperX expectedPunktTabDigest is invalid");- }const defaultConcurrency = runtimeConfigPositiveInteger(config.defaultConcurrency, "WhisperX defaultConcurrency");const requestTimeoutMs = runtimeConfigPositiveInteger(config.requestTimeoutMs, "WhisperX requestTimeoutMs");const maxResponseBytes = runtimeConfigPositiveInteger(config.maxResponseBytes, "WhisperX maxResponseBytes");- for (const key of ["serviceCommand", "servicePrepareCommand"] as const) {+ for (const key of ["serviceCommand"] as const) {const value = config[key];if (value !== undefined&& (!Array.isArray(value) || value.length === 0@@ -60,7 +56,6 @@ const localWhisperXRuntimeAdapter = createRuntimeEndpointAdapterFacet({...(expectedBatchSize === undefined ? {} : { expectedBatchSize }),...(expectedServiceVersion === undefined ? {} : { expectedServiceVersion }),...(expectedWhisperXVersion === undefined ? {} : { expectedWhisperXVersion }),- ...(expectedPunktTabDigest === undefined ? {} : { expectedPunktTabDigest }),...(defaultConcurrency === undefined ? {} : { defaultConcurrency }),...(requestTimeoutMs === undefined ? {} : { requestTimeoutMs }),...(maxResponseBytes === undefined ? {} : { maxResponseBytes }),diff --git a/packages/provider-whisperx-local/src/program.ts b/packages/provider-whisperx-local/src/program.tsindex 4ca81109..aa414ffc 100644--- a/packages/provider-whisperx-local/src/program.ts+++ b/packages/provider-whisperx-local/src/program.ts@@ -1,10 +1,16 @@+import { execFile } from "node:child_process";import { existsSync } from "node:fs";-import { fileURLToPath } from "node:url";+import { createRequire } from "node:module";+import { join } from "node:path";import { runtimeConfigObject, runtimeConfigString } from "@hypit/runtime-kit";-import type { RuntimeAdapterFactoryContext, ManagedProgram, ManagedProgramState } from "@hypit/runtime-kit";--import { localWhisperXPunktTabDigest } from "./provider.js";+import type {+ ManagedProgram,+ ManagedProgramCommand,+ ManagedProgramState,+ RuntimeAdapterFactoryContext,+} from "@hypit/runtime-kit";+import { pythonEnvironmentCommand } from "@hypit/runtime-host-node";/*** WhisperX loads multi-gigabyte weights before it can answer, so it is a warm@@ -12,18 +18,15 @@ import { localWhisperXPunktTabDigest } from "./provider.js";* Provider declares how to bring it up; the Runtime Profile may override the* command for an environment that installs WhisperX differently.*- * The default names the pinned uv project shipped beside this package in the- * Hypit repository, by absolute path — a Runtime root is wherever the- * operator keeps their Profile, and it is not where that project lives. An- * installation that obtained this package on its own has no such directory and- * must say what to run instead; `serviceCommand` is that.+ * The locked project is a package asset. Its environment lives in the Host's+ * program home, while this read-only project remains replaceable Distribution+ * input. A custom service command transfers process ownership to that deployment.*/-const WORKSPACE_PROJECT = fileURLToPath(new URL("../../../services/whisperx", import.meta.url));--function workspaceCommand(entry: string): { command: string; args: readonly string[] } | undefined {- if (!existsSync(WORKSPACE_PROJECT)) return undefined;- return { command: "uv", args: ["run", "--project", WORKSPACE_PROJECT, "--frozen", entry] };-}+const require = createRequire(import.meta.url);+export const localWhisperXManagedProject = join(+ require.resolve("@hypit/whisperx-service-runtime/pyproject.toml"),+ "..",+);function configuredCommand(value: unknown, key: string) {if (value === undefined) return undefined;@@ -33,32 +36,104 @@ function configuredCommand(value: unknown, key: string) {return { command: value[0] as string, args: (value as string[]).slice(1) };}+function run(command: ManagedProgramCommand): Promise<{ readonly ok: boolean; readonly output: string }> {+ return new Promise((resolve) => {+ execFile(command.command, [...command.args], {+ cwd: command.cwd,+ env: { ...process.env, ...command.env },+ timeout: 60_000,+ shell: false,+ windowsHide: true,+ }, (error, stdout, stderr) => {+ resolve(error === null+ ? { ok: true, output: stdout.trim() }+ : { ok: false, output: (stderr.trim() || error.message).split(/\r?\n/u).at(-1) ?? "" });+ });+ });+}+export function localWhisperXProgram(context: RuntimeAdapterFactoryContext): ManagedProgram {const config = runtimeConfigObject(context.config, "local WhisperX");const baseUrl = (runtimeConfigString(config.baseUrl, "WhisperX baseUrl") ?? "http://127.0.0.1:8765").replace(/\/+$/u, "");+ const serviceUrl = new URL(baseUrl);+ const expectedDevice = runtimeConfigString(config.expectedDevice, "WhisperX expectedDevice") ?? "cpu";const expected = {protocol: "hypit.whisperx-service@1",serviceVersion: runtimeConfigString(config.expectedServiceVersion, "WhisperX expectedServiceVersion") ?? "0.1.0",whisperxVersion: runtimeConfigString(config.expectedWhisperXVersion, "WhisperX expectedWhisperXVersion") ?? "3.8.6",model: runtimeConfigString(config.expectedModel, "WhisperX expectedModel") ?? "small",- device: runtimeConfigString(config.expectedDevice, "WhisperX expectedDevice") ?? "cpu",- punktTabDigest: runtimeConfigString(config.expectedPunktTabDigest, "WhisperX expectedPunktTabDigest")- ?? localWhisperXPunktTabDigest,+ device: expectedDevice,+ compute: runtimeConfigString(config.expectedCompute, "WhisperX expectedCompute")+ ?? (expectedDevice === "cpu" ? "int8" : "float16"),+ batchSize: typeof config.expectedBatchSize === "number" ? config.expectedBatchSize : 8,};const customStart = configuredCommand(config.serviceCommand, "serviceCommand");- const customPrepare = configuredCommand(config.servicePrepareCommand, "servicePrepareCommand");- // Any lifecycle override transfers ownership to the deployment. This avoids- // preparing the repository uv project before starting an unrelated conda,- // systemd or container command. With no override the bundled project is the- // managed default; when it is not present this becomes probe-only.- const managed = customStart === undefined && customPrepare === undefined;- const prepare = customPrepare ?? (managed ? workspaceCommand("hypit-whisperx-prepare") : undefined);- const start = customStart ?? (managed ? workspaceCommand("hypit-whisperx-service") : undefined);+ const managed = customStart === undefined;+ if (managed && !existsSync(localWhisperXManagedProject)) {+ throw new Error("local WhisperX has no packaged managed runtime; configure serviceCommand explicitly");+ }+ const stateRoot = join(context.hostStateRoot, "programs", "whisperx");+ const environment = join(stateRoot, ".venv");+ const nltkData = join(stateRoot, "nltk_data");+ const serviceEnvironment = {+ HYPIT_WHISPERX_PORT: serviceUrl.port || "80",+ HYPIT_WHISPERX_MODEL: expected.model,+ HYPIT_WHISPERX_DEVICE: expected.device,+ HYPIT_WHISPERX_COMPUTE: expected.compute,+ HYPIT_WHISPERX_BATCH_SIZE: String(expected.batchSize),+ HYPIT_WHISPERX_NLTK_DATA: nltkData,+ };+ const check: ManagedProgramCommand = {+ command: pythonEnvironmentCommand(environment, "hypit-whisperx-check"),+ args: [],+ env: { HYPIT_WHISPERX_NLTK_DATA: nltkData },+ };+ const managedStart: ManagedProgramCommand = {+ command: pythonEnvironmentCommand(environment, "hypit-whisperx-service"),+ args: [],+ env: serviceEnvironment,+ };+ const installationProbe = async (): Promise<ManagedProgramState> => {+ const result = await run(check);+ if (!result.ok) return { state: "down", detail: `${check.command} is not ready: ${result.output}` };+ let report: {+ readonly protocol?: unknown;+ readonly serviceVersion?: unknown;+ readonly packages?: Record<string, unknown>;+ };+ try {+ report = JSON.parse(result.output) as typeof report;+ } catch {+ return { state: "mismatch", detail: `${check.command} returned an invalid installation report` };+ }+ const differs = [+ report.protocol === expected.protocol ? undefined : `protocol is ${String(report.protocol)}`,+ report.serviceVersion === expected.serviceVersion ? undefined : `serviceVersion is ${String(report.serviceVersion)}`,+ report.packages?.whisperx === expected.whisperxVersion ? undefined : `whisperx is ${String(report.packages?.whisperx)}`,+ ].filter((item): item is string => item !== undefined);+ return differs.length === 0+ ? { state: "ready" }+ : { state: "mismatch", detail: differs.join("; ") };+ };return {id: "whisperx",- ...(prepare === undefined ? {} : { prepare }),- ...(start === undefined ? {} : { start }),+ ...(managed ? {+ stateRoot,+ installation: {+ probe: installationProbe,+ commands: [{+ command: "uv",+ args: ["sync", "--project", localWhisperXManagedProject, "--frozen", "--no-editable"],+ env: { UV_PROJECT_ENVIRONMENT: environment },+ }, {+ command: pythonEnvironmentCommand(environment, "hypit-whisperx-prepare"),+ args: ["--nltk-data", nltkData],+ env: { HYPIT_WHISPERX_NLTK_DATA: nltkData },+ }],+ },+ } : {}),+ start: customStart ?? managedStart,async probe(): Promise<ManagedProgramState> {let health: Record<string, unknown>;try {diff --git a/packages/provider-whisperx-local/src/provider.ts b/packages/provider-whisperx-local/src/provider.tsindex d9bfaac5..98acbd28 100644--- a/packages/provider-whisperx-local/src/provider.ts+++ b/packages/provider-whisperx-local/src/provider.ts@@ -16,9 +16,6 @@ export const localWhisperXProviderModuleRef = {name: "@hypit/provider-whisperx-local",version: "1",} as const;-export const localWhisperXPunktTabDigest =- "e57f64187974277726a3417ca6f181ec5403676c717672eef6a748a7b20e0106";-export type CreateLocalWhisperXProviderOptions = {readonly instance?: string;readonly pool?: string;@@ -30,7 +27,6 @@ export type CreateLocalWhisperXProviderOptions = {readonly expectedBatchSize?: number;readonly expectedServiceVersion?: string;readonly expectedWhisperXVersion?: string;- readonly expectedPunktTabDigest?: string;readonly defaultConcurrency?: number;readonly requestTimeoutMs?: number;readonly maxResponseBytes?: number;@@ -225,13 +221,11 @@ export function createLocalWhisperXProvider(config: CreateLocalWhisperXProviderOconst expectedBatchSize = positiveInteger(config.expectedBatchSize ?? 8, "expectedBatchSize");const expectedServiceVersion = config.expectedServiceVersion ?? "0.1.0";const expectedWhisperXVersion = config.expectedWhisperXVersion ?? "3.8.6";- const expectedPunktTabDigest = config.expectedPunktTabDigest ?? localWhisperXPunktTabDigest;assert(expectedModel.trim().length > 0, "expectedModel is empty");assert(expectedDevice.trim().length > 0, "expectedDevice is empty");assert(expectedCompute.trim().length > 0, "expectedCompute is empty");assert(expectedServiceVersion.trim().length > 0, "expectedServiceVersion is empty");assert(expectedWhisperXVersion.trim().length > 0, "expectedWhisperXVersion is empty");- assert(/^[0-9a-f]{64}$/u.test(expectedPunktTabDigest), "expectedPunktTabDigest is invalid");const requestTimeoutMs = positiveInteger(config.requestTimeoutMs ?? 10 * 60_000, "requestTimeoutMs");const maxResponseBytes = positiveInteger(config.maxResponseBytes ?? 64 * 1024 * 1024, "maxResponseBytes");@@ -269,7 +263,6 @@ export function createLocalWhisperXProvider(config: CreateLocalWhisperXProviderOreadonly device?: unknown;readonly compute?: unknown;readonly batchSize?: unknown;- readonly punktTabDigest?: unknown;};assert(healthValue.ok === true&& healthValue.protocol === "hypit.whisperx-service@1"@@ -278,8 +271,7 @@ export function createLocalWhisperXProvider(config: CreateLocalWhisperXProviderO&& healthValue.model === expectedModel&& healthValue.device === expectedDevice&& healthValue.compute === expectedCompute- && healthValue.batchSize === expectedBatchSize- && healthValue.punktTabDigest === expectedPunktTabDigest,+ && healthValue.batchSize === expectedBatchSize,"WhisperX service runtime identity differs from the configured Provider");const transcriptionResponse = await fetch(`${normalizedBaseUrl}/transcribe`, {method: "POST",diff --git a/packages/provider-whisperx-local/test/program.test.ts b/packages/provider-whisperx-local/test/program.test.tsindex 8a7125eb..c8992ea3 100644--- a/packages/provider-whisperx-local/test/program.test.ts+++ b/packages/provider-whisperx-local/test/program.test.ts@@ -1,37 +1,33 @@import assert from "node:assert/strict";import { existsSync } from "node:fs";import { isAbsolute, join } from "node:path";+import { tmpdir } from "node:os";import test from "node:test";import { localWhisperXProgram } from "../src/program.js";const context = (config: Record<string, unknown> = {}) => ({- dataRoot: "/tmp", instance: "whisperx.test", config: config as never,+ hostStateRoot: join(tmpdir(), "hypit-whisperx-host"),+ dataRoot: tmpdir(), instance: "whisperx.test", config: config as never,});test("the Provider declares how to bring WhisperX up and how to recognise it", () => {const program = localWhisperXProgram(context());assert.equal(program.id, "whisperx");- assert.equal(program.start?.command, "uv");- assert.equal(program.start?.args.at(-1), "hypit-whisperx-service");- assert.equal(program.prepare?.args.at(-1), "hypit-whisperx-prepare");- // Absolute: a Runtime root is wherever the Profile lives, not where the- // pinned uv project lives.- const project = program.start?.args.at(-3) ?? "";+ assert.match(program.start?.command ?? "", /hypit-whisperx-service(?:\.exe)?$/u);+ assert.equal(program.installation?.commands[0]?.command, "uv");+ assert.match(program.installation?.commands[1]?.command ?? "", /hypit-whisperx-prepare(?:\.exe)?$/u);+ const project = program.installation?.commands[0]?.args.at(-3) ?? "";assert.ok(isAbsolute(project), `${project} must be absolute`);assert.ok(existsSync(join(project, "pyproject.toml")), `${project} must be the pinned uv project`);+ assert.equal(program.stateRoot, join(context().hostStateRoot, "programs", "whisperx"));});test("a deployment that installs WhisperX elsewhere overrides the command", () => {const program = localWhisperXProgram(context({ serviceCommand: ["conda", "run", "whisperx-serve"] }));assert.deepEqual(program.start, { command: "conda", args: ["run", "whisperx-serve"] });- assert.equal(program.prepare, undefined);-});--test("custom prepare and probe-only deployments do not inherit managed lifecycle commands", () => {- const prepared = localWhisperXProgram(context({ servicePrepareCommand: ["make", "models"] }));- assert.deepEqual(prepared.prepare, { command: "make", args: ["models"] });- assert.equal(prepared.start, undefined);+ assert.equal(program.installation, undefined);+ assert.equal(program.stateRoot, undefined);});test("a program answering with another identity is reported, never used", async () => {@@ -43,7 +39,6 @@ test("a program answering with another identity is reported, never used", asyncwhisperxVersion: "3.8.6",model: "large-v3",device: "cpu",- punktTabDigest: "sha256:" + "0".repeat(64),}), { status: 200 })) as typeof fetch;try {const state = await localWhisperXProgram(context()).probe();diff --git a/packages/provider-whisperx-local/test/provider.test.ts b/packages/provider-whisperx-local/test/provider.test.tsindex b4f1ce50..6aa5d567 100644--- a/packages/provider-whisperx-local/test/provider.test.ts+++ b/packages/provider-whisperx-local/test/provider.test.ts@@ -87,7 +87,6 @@ test("local Provider stages canonical evidence bytes unchanged and returns sealedevice: "cpu",compute: "int8",batchSize: 8,- punktTabDigest: "e57f64187974277726a3417ca6f181ec5403676c717672eef6a748a7b20e0106",}), { headers: { "content-type": "application/json" } });}assert.ok(url.endsWith("/transcribe"));diff --git a/packages/provider-xiaomi-mimo/README.md b/packages/provider-xiaomi-mimo/README.mdindex 135cae4b..f1def4c1 100644--- a/packages/provider-xiaomi-mimo/README.md+++ b/packages/provider-xiaomi-mimo/README.md@@ -16,7 +16,7 @@ Runtime Profile example:"use": "@hypit/provider-xiaomi-mimo","pool": "mimo.official","config": {- "apiKey": { "store": "keychain", "key": "xiaomi-mimo.api-key" },+ "apiKey": { "store": "os", "key": "xiaomi-mimo.api-key" },"defaultConcurrency": 2}}diff --git a/packages/reference-video-tools/README.md b/packages/reference-video-tools/README.mdindex bfda6d5a..7eb6b0a3 100644--- a/packages/reference-video-tools/README.md+++ b/packages/reference-video-tools/README.md@@ -5,7 +5,7 @@ CLI tools for reconstructing a reference video with Hypit.The package exposes six CLI subcommands: `list_svml_packages`, `prepare_reference`,`observe_reference`, `record_observation`, `inspect_svml_vocabulary`, and `compare_reconstruction`.Each command prints one JSON result to stdout. The final source files are authored by the calling-agent and checked with the existing `pnpm hypit check` command.+agent and checked with the installed `hypit check` command.`--observer` on `prepare_reference` chooses who reads the reference, once per reference:@@ -22,16 +22,16 @@ shape. Neither receives SVML syntax, and neither writes SVML.Run the CLI from the repository or an installed package:```bash-pnpm hypit-reference-video-tools list_svml_packages-pnpm hypit-reference-video-tools prepare_reference --video-path ./reference.mp4-pnpm hypit-reference-video-tools prepare_reference --video-path ./reference.mp4 --redo people-pnpm hypit-reference-video-tools prepare_reference --video-path ./reference.mp4 --redo transcript-pnpm hypit-reference-video-tools observe_reference --reference-id <reference-id>-pnpm hypit-reference-video-tools observe_reference --reference-id <reference-id> --shot-id shot-007-pnpm hypit-reference-video-tools observe_reference --reference-id <reference-id> --shot-id shot-007 --question "How thick is the outline on the caption words?"-pnpm hypit-reference-video-tools observe_reference --reference-id <reference-id> --shot-id shot-007 --reobserve-pnpm hypit-reference-video-tools inspect_svml_vocabulary --package @hypit/media-track --tag Track-pnpm hypit-reference-video-tools compare_reconstruction --reference-id <reference-id> --shot-id shot-007 --image ./rendered.png+hypit-reference-video-tools list_svml_packages+hypit-reference-video-tools prepare_reference --video-path ./reference.mp4+hypit-reference-video-tools prepare_reference --video-path ./reference.mp4 --redo people+hypit-reference-video-tools prepare_reference --video-path ./reference.mp4 --redo transcript+hypit-reference-video-tools observe_reference --reference-id <reference-id>+hypit-reference-video-tools observe_reference --reference-id <reference-id> --shot-id shot-007+hypit-reference-video-tools observe_reference --reference-id <reference-id> --shot-id shot-007 --question "How thick is the outline on the caption words?"+hypit-reference-video-tools observe_reference --reference-id <reference-id> --shot-id shot-007 --reobserve+hypit-reference-video-tools inspect_svml_vocabulary --package @hypit/media-track --tag Track+hypit-reference-video-tools compare_reconstruction --reference-id <reference-id> --shot-id shot-007 --image ./rendered.png```For automation, every command also accepts `--input '{"...":"..."}'` with the complete JSON input@@ -56,7 +56,7 @@ every single word. Placing an on-screen text reveal against the line that triggeof the word, not of the sentence around it, and that question comes up in every reconstruction. Thespeech audio is extracted to `speech.wav` beside the shot media and measured by the local WhisperXProvider in `@hypit/provider-whisperx-local`, which answers a loopback service on-`http://127.0.0.1:8765`; start it with `uv run --project services/whisperx --frozen hypit-whisperx-service`.+`http://127.0.0.1:8765`; start the selected managed service with `hypit runtime up`.The result reports `status`, `transcript_ref` and `word_count`, and the words themselves live in`transcript.json` as passages, each with a `words` array of `{ text, start_seconds, end_seconds, score }`.The transcript is deterministic local evidence rather than an observation: it is never written to thediff --git a/packages/reference-video-tools/bin/reference-video-tools.mjs b/packages/reference-video-tools/bin/reference-video-tools.mjsindex ae962502..c0e232cd 100755--- a/packages/reference-video-tools/bin/reference-video-tools.mjs+++ b/packages/reference-video-tools/bin/reference-video-tools.mjs@@ -1,5 +1,16 @@#!/usr/bin/env nodeimport { register } from "tsx/esm/api";+import { dirname, resolve } from "node:path";+import { fileURLToPath } from "node:url";+const distributionRoot = resolve(dirname(fileURLToPath(import.meta.url)), "../../..");+process.env.HYPIT_DISTRIBUTION_ROOT ??= distributionRoot;register();+const {+ installDistributionPackageResolution,+ installExternalPackageResolution,+} = await import("../../package-loader-node/src/distribution-resolution.ts");+installDistributionPackageResolution([distributionRoot]);+const { hypitHostPackageRoot } = await import("../../runtime-host-node/src/index.ts");+installExternalPackageResolution([hypitHostPackageRoot()]);await import("../src/cli.ts");diff --git a/packages/reference-video-tools/package.json b/packages/reference-video-tools/package.jsonindex 53b8b4dc..5bf5b1d4 100644--- a/packages/reference-video-tools/package.json+++ b/packages/reference-video-tools/package.json@@ -8,7 +8,8 @@"hypit-reference-video-tools": "./bin/reference-video-tools.mjs"},"exports": {- ".": "./src/index.ts"+ ".": "./src/index.ts",+ "./cli": "./src/cli.ts"},"dependencies": {"@google/genai": "1.52.0",diff --git a/packages/reference-video-tools/src/cli.ts b/packages/reference-video-tools/src/cli.tsindex 3ec452aa..66a95a6f 100644--- a/packages/reference-video-tools/src/cli.ts+++ b/packages/reference-video-tools/src/cli.ts@@ -85,7 +85,11 @@ async function main(): Promise<void> {if (flags.has("rebuild") || flags.has("refresh")) {throw new Error("--rebuild and --refresh were removed; use --redo on prepare_reference or --reobserve on observe_reference");}- const tools = createReferenceVideoTools();+ const tools = createReferenceVideoTools({+ ...(process.env.HYPIT_DISTRIBUTION_ROOT === undefined+ ? {}+ : { packageRoot: process.env.HYPIT_DISTRIBUTION_ROOT }),+ });const supplied = inputObject(flags);let result: unknown;if (command === "list_svml_packages") {diff --git a/packages/reference-video-tools/src/tools.ts b/packages/reference-video-tools/src/tools.tsindex 2c141938..476b0d68 100644--- a/packages/reference-video-tools/src/tools.ts+++ b/packages/reference-video-tools/src/tools.ts@@ -1,4 +1,3 @@-import { GoogleGenAI } from "@google/genai";import type { Part } from "@google/genai";import { access, readdir, stat, writeFile } from "node:fs/promises";import { dirname, join, resolve } from "node:path";@@ -93,6 +92,15 @@ async function defaultGenerate(model: string): Promise<GenerateText> {let parsed: unknown;try { parsed = JSON.parse(credentials); } catch { throw new Error("GOOGLE_APPLICATION_CREDENTIALS_JSON is not valid JSON"); }assert(parsed !== null && typeof parsed === "object" && !Array.isArray(parsed), "Google credentials must be an object");+ let GoogleGenAI: typeof import("@google/genai")["GoogleGenAI"];+ try {+ ({ GoogleGenAI } = await import("@google/genai"));+ } catch (error) {+ throw new Error(+ "Gemini observation requires @google/genai. Install it once with: hypit packages install @google/[email protected]",+ { cause: error },+ );+ }const client = new GoogleGenAI({vertexai: true,project,diff --git a/packages/reference-video-tools/test/transcript.test.ts b/packages/reference-video-tools/test/transcript.test.tsindex e8357e1f..4545a097 100644--- a/packages/reference-video-tools/test/transcript.test.ts+++ b/packages/reference-video-tools/test/transcript.test.ts@@ -44,7 +44,6 @@ async function serving(response: unknown, run: () => Promise<void>): Promise<voidevice: "cpu",compute: "int8",batchSize: 8,- punktTabDigest: "e57f64187974277726a3417ca6f181ec5403676c717672eef6a748a7b20e0106",}: response), { headers: { "content-type": "application/json" } })) as typeof fetch;try { await run(); } finally { globalThis.fetch = original; }diff --git a/packages/runtime-host-node/src/index.ts b/packages/runtime-host-node/src/index.tsindex 98125770..5fe91dc2 100644--- a/packages/runtime-host-node/src/index.ts+++ b/packages/runtime-host-node/src/index.ts@@ -1,6 +1,7 @@import { access } from "node:fs/promises";import { constants } from "node:fs";-import { delimiter, isAbsolute, resolve } from "node:path";+import { homedir } from "node:os";+import { delimiter, isAbsolute, join, resolve } from "node:path";import type { ArtifactAttachment } from "@hypit/workspace";import type { BuildDefinition, BuildState, CapabilityRef, Digest } from "@hypit/protocol";import type {@@ -94,13 +95,13 @@ export type RuntimeHostDoctorResult = {export type ManagedProgramProgress = {readonly id: string;- readonly phase: "checking" | "preparing" | "starting" | "waiting" | "ready";+ readonly phase: "checking" | "installing" | "starting" | "waiting" | "ready";};export type ManagedProgramReport = {readonly id: string;readonly instances: readonly string[];- readonly action?: "already-running" | "prepared" | "started" | "stopped" | "not-ours" | "nothing-to-stop" | "unchanged";+ readonly action?: "already-running" | "installed" | "started" | "stopped" | "not-ours" | "nothing-to-stop" | "unchanged";readonly state:| { readonly state: "ready" }| { readonly state: "down"; readonly detail: string }@@ -156,12 +157,57 @@ export type NodeRuntimeHost = {openArchive(options?: { readonly readOnly?: boolean }): Promise<RuntimeHostArchive>;openArtifacts(): Promise<RuntimeHostArtifactAccess>;openCredentials(endpoint: string): Promise<RuntimeHostCredentialControl>;+ /** Explicitly prepare upstream packages selected by this Runtime Profile. */+ prepare(options?: {+ readonly onProgress?: (event: import("./packages.js").HostPackageProgress) => void;+ }): Promise<readonly import("./packages.js").HostPackageReport[]>;+ /**+ * Read-only, bounded deployment validation for one demanded Build slice.+ * It may inspect local files, credentials and loopback program state, but it+ * never installs, starts or contacts a remote Provider or Artifact Store.+ */+ preflight(options?: {+ readonly capabilities?: readonly CapabilityRef[];+ }): Promise<RuntimeHostDoctorResult>;+ /** Active deployment diagnosis. Unlike preflight, adapters may contact their configured services. */doctor(options?: {readonly capabilities?: readonly CapabilityRef[];}): Promise<RuntimeHostDoctorResult>;runWorker(readyFile: string): Promise<void>;};+/**+ * Persistent state owned by the installed Hypit Host, never by an author project+ * or a replaceable source checkout.+ */+export function hypitHostStateRoot(options: {+ readonly env?: NodeJS.ProcessEnv;+ readonly platform?: NodeJS.Platform;+ readonly home?: string;+} = {}): string {+ const env = options.env ?? process.env;+ const override = env.HYPIT_STATE_HOME;+ if (override !== undefined && override.trim().length > 0) return resolve(override);+ const platform = options.platform ?? process.platform;+ const home = options.home ?? homedir();+ if (platform === "darwin") return join(home, "Library", "Application Support", "Hypit");+ if (platform === "win32") {+ const local = env.LOCALAPPDATA;+ return join(local === undefined || local.trim().length === 0+ ? join(home, "AppData", "Local")+ : local, "Hypit");+ }+ const state = env.XDG_STATE_HOME;+ return join(state === undefined || state.trim().length === 0+ ? join(home, ".local", "state")+ : state, "hypit");+}++/** Upstream npm packages shared by every Hypit project and future session on this machine. */+export function hypitHostPackageRoot(hostStateRoot = hypitHostStateRoot()): string {+ return join(resolve(hostStateRoot), "packages");+}+function pathLike(value: string): boolean {return isAbsolute(value) || value.includes("/") || value.includes("\\");}@@ -174,21 +220,26 @@ export function resolveRuntimeExecutable(root: string, value: string): string {async function executableExists(value: string): Promise<boolean> {const unavailable = (error: unknown) => error instanceof Error && "code" in error&& ["ENOENT", "ENOTDIR", "EACCES"].includes(String(error.code));- if (pathLike(value)) {+ const suffixes = process.platform === "win32" && !/\.[^\\/]+$/u.test(value)+ ? (process.env.PATHEXT ?? ".COM;.EXE;.BAT;.CMD").split(";").filter(Boolean)+ : [""];+ const candidates = (base: string) => suffixes.map((suffix) => `${base}${suffix}`);+ const available = async (candidate: string): Promise<boolean> => {try {- await access(value, constants.X_OK);+ await access(candidate, process.platform === "win32" ? constants.F_OK : constants.X_OK);return true;} catch (error) {if (unavailable(error)) return false;throw error;}+ };+ if (pathLike(value)) {+ for (const candidate of candidates(value)) if (await available(candidate)) return true;+ return false;}for (const directory of (process.env.PATH ?? "").split(delimiter).filter(Boolean)) {- try {- await access(resolve(directory, value), constants.X_OK);- return true;- } catch (error) {- if (!unavailable(error)) throw error;+ for (const candidate of candidates(resolve(directory, value))) {+ if (await available(candidate)) return true;}}return false;@@ -222,3 +273,28 @@ export function diagnoseRuntimeEnvironmentCredential(subject: variable,}];}++/** Executables inside a Python virtual environment have one platform-defined layout. */+export function pythonEnvironmentExecutable(environment: string): string {+ return process.platform === "win32"+ ? resolve(environment, "Scripts", "python.exe")+ : resolve(environment, "bin", "python");+}++/** Console scripts installed by Python use an executable shim on Windows. */+export function pythonEnvironmentCommand(environment: string, name: string): string {+ return process.platform === "win32"+ ? resolve(environment, "Scripts", `${name}.exe`)+ : resolve(environment, "bin", name);+}++export {+ inspectHostPackage,+ parseRegistryPackageSpec,+ prepareHostPackages,+} from "./packages.js";+export type {+ HostPackageProgress,+ HostPackageReport,+ RegistryPackageSpec,+} from "./packages.js";diff --git a/packages/runtime-host-node/src/packages.ts b/packages/runtime-host-node/src/packages.tsnew file mode 100644index 00000000..17ed66e9--- /dev/null+++ b/packages/runtime-host-node/src/packages.ts@@ -0,0 +1,158 @@+import { spawn } from "node:child_process";+import { mkdir, readFile, writeFile } from "node:fs/promises";+import { join, resolve } from "node:path";++export type RegistryPackageSpec = {+ readonly name: string;+ readonly version: string;+ readonly specifier: string;+};++export type HostPackageReport = RegistryPackageSpec & {+ readonly root: string;+ readonly action: "already-installed" | "installed";+};++export type HostPackageProgress = RegistryPackageSpec & {+ readonly phase: "checking" | "installing" | "ready";+};++function exactVersion(value: string): boolean {+ return /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/u.test(value);+}++/** Registry packages are pinned by version; npm owns their files and dependency graph. */+export function parseRegistryPackageSpec(specifier: string): RegistryPackageSpec {+ const value = specifier.trim();+ const slash = value.startsWith("@") ? value.indexOf("/", 1) : -1;+ const at = value.lastIndexOf("@");+ const split = value.startsWith("@") ? (at > slash ? at : -1) : at;+ const name = split > 0 ? value.slice(0, split) : "";+ const version = split > 0 ? value.slice(split + 1) : "";+ if (name.length === 0 || name.startsWith("@hypit/") || !exactVersion(version)) {+ throw new Error(+ `${specifier} must name one external npm registry package at an exact version, for example [email protected]`,+ );+ }+ if (name.startsWith("@") && (slash < 2 || slash >= name.length - 1)) {+ throw new Error(`${specifier} is not a valid scoped npm package specifier`);+ }+ if (!name.startsWith("@") && !/^[a-z0-9][a-z0-9._-]*$/u.test(name)) {+ throw new Error(`${specifier} is not a valid npm package specifier`);+ }+ return { name, version, specifier: `${name}@${version}` };+}++async function installedVersion(root: string, name: string): Promise<string | undefined> {+ try {+ const manifest = JSON.parse(await readFile(+ join(root, "node_modules", ...name.split("/"), "package.json"),+ "utf8",+ )) as { readonly name?: unknown; readonly version?: unknown };+ return manifest.name === name && typeof manifest.version === "string"+ ? manifest.version+ : undefined;+ } catch (error) {+ if (error instanceof Error && "code" in error && error.code === "ENOENT") return undefined;+ throw error;+ }+}++export async function inspectHostPackage(+ specifier: string,+ root: string,+): Promise<HostPackageReport | undefined> {+ const required = parseRegistryPackageSpec(specifier);+ const version = await installedVersion(resolve(root), required.name);+ return version === required.version+ ? { ...required, root: resolve(root), action: "already-installed" }+ : undefined;+}++function runNpm(root: string, specifiers: readonly string[]): Promise<void> {+ const npmArgs = [+ "install",+ "--prefix", root,+ "--save-exact",+ "--package-lock=false",+ "--no-audit",+ "--no-fund",+ "--omit=dev",+ ...specifiers,+ ];+ const windows = process.platform === "win32";+ const command = windows ? (process.env.ComSpec ?? "cmd.exe") : "npm";+ const args = windows ? ["/d", "/s", "/c", "npm.cmd", ...npmArgs] : npmArgs;+ return new Promise((done, reject) => {+ const child = spawn(command, args, {+ shell: false,+ windowsHide: true,+ stdio: ["ignore", "pipe", "pipe"],+ });+ let output = "";+ child.stdout.on("data", (chunk: Buffer) => { output = `${output}${chunk.toString()}`.slice(-32_000); });+ child.stderr.on("data", (chunk: Buffer) => { output = `${output}${chunk.toString()}`.slice(-32_000); });+ child.on("error", reject);+ child.on("close", (code) => {+ if (code === 0) done();+ else reject(new Error(`npm install failed${output.trim().length === 0 ? "" : `: ${output.trim().split("\n").at(-1)}`}`));+ });+ });+}++/**+ * Install missing upstream packages into one user/machine npm home.+ * npm's ordinary package.json is the only persistent package-set record; Hypit+ * creates no lock, receipt, hash inventory or project-local copy.+ */+export async function prepareHostPackages(+ specifiers: readonly string[],+ options: {+ readonly root: string;+ readonly onProgress?: (event: HostPackageProgress) => void;+ },+): Promise<readonly HostPackageReport[]> {+ const root = resolve(options.root);+ const byName = new Map<string, RegistryPackageSpec>();+ for (const specifier of specifiers) {+ const parsed = parseRegistryPackageSpec(specifier);+ const previous = byName.get(parsed.name);+ if (previous !== undefined && previous.version !== parsed.version) {+ throw new Error(`${parsed.name} is required at both ${previous.version} and ${parsed.version}`);+ }+ byName.set(parsed.name, parsed);+ }+ const required = [...byName.values()].sort((left, right) => left.name.localeCompare(right.name));+ const missing: RegistryPackageSpec[] = [];+ for (const item of required) {+ options.onProgress?.({ ...item, phase: "checking" });+ if (await installedVersion(root, item.name) !== item.version) missing.push(item);+ }+ if (missing.length > 0) {+ await mkdir(root, { recursive: true });+ try {+ await readFile(join(root, "package.json"), "utf8");+ } catch (error) {+ if (!(error instanceof Error && "code" in error && error.code === "ENOENT")) throw error;+ await writeFile(join(root, "package.json"), `${JSON.stringify({+ name: "hypit-machine-packages",+ private: true,+ description: "Upstream npm packages used on demand by Hypit",+ dependencies: {},+ }, null, 2)}\n`, "utf8");+ }+ for (const item of missing) options.onProgress?.({ ...item, phase: "installing" });+ await runNpm(root, missing.map((item) => item.specifier));+ }+ const installed = new Set(missing.map((item) => item.name));+ const reports: HostPackageReport[] = [];+ for (const item of required) {+ const version = await installedVersion(root, item.name);+ if (version !== item.version) {+ throw new Error(`npm did not install ${item.specifier} into ${root}`);+ }+ options.onProgress?.({ ...item, phase: "ready" });+ reports.push({ ...item, root, action: installed.has(item.name) ? "installed" : "already-installed" });+ }+ return reports;+}diff --git a/packages/runtime-host-node/test/runtime-host-node.test.ts b/packages/runtime-host-node/test/runtime-host-node.test.tsindex fac9bbb4..b5531f8c 100644--- a/packages/runtime-host-node/test/runtime-host-node.test.ts+++ b/packages/runtime-host-node/test/runtime-host-node.test.ts@@ -6,6 +6,9 @@ import test from "node:test";import {diagnoseRuntimeExecutable,+ hypitHostPackageRoot,+ parseRegistryPackageSpec,+ prepareHostPackages,resolveRuntimeExecutable,} from "@hypit/runtime-host-node";@@ -27,3 +30,25 @@ test("configured executable paths are rooted at the Runtime Profile project", asawait rm(root, { recursive: true, force: true });}});++test("machine packages are exact npm packages reused from one Host root", async () => {+ const root = await mkdtemp(join(tmpdir(), "hypit-machine-packages-"));+ try {+ const packageRoot = hypitHostPackageRoot(root);+ await mkdir(join(packageRoot, "node_modules", "hyperframes"), { recursive: true });+ await writeFile(join(packageRoot, "node_modules", "hyperframes", "package.json"), JSON.stringify({+ name: "hyperframes",+ version: "0.7.101",+ }));+ assert.deepEqual(parseRegistryPackageSpec("[email protected]"), {+ name: "hyperframes",+ version: "0.7.101",+ specifier: "[email protected]",+ });+ assert.throws(() => parseRegistryPackageSpec("@hypit/[email protected]"), /external npm registry package/u);+ const reports = await prepareHostPackages(["[email protected]"], { root: packageRoot });+ assert.equal(reports[0]?.action, "already-installed");+ } finally {+ await rm(root, { recursive: true, force: true });+ }+});diff --git a/packages/runtime-kit/src/index.ts b/packages/runtime-kit/src/index.tsindex a3903c94..977f6eb0 100644--- a/packages/runtime-kit/src/index.ts+++ b/packages/runtime-kit/src/index.ts@@ -16,6 +16,9 @@ type RuntimeAdapterAddress = {};export type RuntimeAdapterFactoryContext = {+ /** Persistent machine/user state supplied by the Host, outside every author project. */+ readonly hostStateRoot: string;+ /** Runtime/Profile state belonging to this project. */readonly dataRoot: string;readonly instance: string;readonly pool?: string;@@ -32,6 +35,15 @@ export type RuntimeDoctorDiagnostic = {export type ManagedProgramCommand = {readonly command: string;readonly args: readonly string[];+ readonly cwd?: string;+ readonly env?: Readonly<Record<string, string>>;+};++export type ManagedProgramInstallation = {+ /** Truthful inspection of the installed program; no installer-owned receipt. */+ probe(): Promise<ManagedProgramState>;+ /** Commands run only when the installation probe is not ready. */+ readonly commands: readonly ManagedProgramCommand[];};export type ManagedProgramState =@@ -41,8 +53,11 @@ export type ManagedProgramState =export type ManagedProgram = {readonly id: string;+ /** Shared lifecycle files live here; absent means this Runtime owns them. */+ readonly stateRoot?: string;+ /** Installation and runtime readiness are deliberately separate states. */+ readonly installation?: ManagedProgramInstallation;probe(): Promise<ManagedProgramState>;- readonly prepare?: ManagedProgramCommand;readonly start?: ManagedProgramCommand;};diff --git a/packages/runtime-kit/test/registry.test.ts b/packages/runtime-kit/test/registry.test.tsindex b6faad79..4440f89c 100644--- a/packages/runtime-kit/test/registry.test.ts+++ b/packages/runtime-kit/test/registry.test.ts@@ -14,7 +14,7 @@ import {} from "@hypit/runtime-kit";import type { RuntimeAdapterFactoryContext } from "@hypit/runtime-kit";-const context = { dataRoot: "/tmp", instance: "one", config: {} };+const context = { hostStateRoot: "/host", dataRoot: "/tmp", instance: "one", config: {} };const endpointPackage = (instance: string) => ({name: instance,manifest: { facets: [] },diff --git a/packages/runtime-local/src/config.ts b/packages/runtime-local/src/config.tsindex caded3b0..3173d95d 100644--- a/packages/runtime-local/src/config.ts+++ b/packages/runtime-local/src/config.ts@@ -1,7 +1,11 @@import { readFile, stat } from "node:fs/promises";import { dirname, resolve } from "node:path";-import { collectNodePackageComponents, loadNodePackageSelection } from "@hypit/package-loader-node";+import {+ collectNodePackageComponents,+ distributionExternalPackageRequirements,+ loadNodePackageSelection,+} from "@hypit/package-loader-node";import type { NodePackageSelectionRequest } from "@hypit/package-loader-node";import { canonicalize } from "@hypit/protocol";import type { CanonicalValue, CapabilityRef } from "@hypit/protocol";@@ -19,10 +23,17 @@ import {import type {ManagedProgram,ManagedProgramState,+ RuntimeAdapterFactoryContext,RuntimeDoctorDiagnostic,RuntimeEndpointActivation,RuntimeOpened,} from "@hypit/runtime-kit";+import {+ hypitHostPackageRoot,+ hypitHostStateRoot,+ prepareHostPackages,+} from "@hypit/runtime-host-node";+import type { HostPackageProgress, HostPackageReport } from "@hypit/runtime-host-node";import { SqliteRuntimeState } from "@hypit/store-sqlite";import { createLocalRuntime } from "./runtime.js";@@ -57,6 +68,8 @@ export type LoadRuntimeConfigOptions = {readonly registry?: RuntimeAdapterRegistry;readonly packageRoot?: string;readonly distributionPackageRoot?: string;+ /** Persistent machine/user state. Defaults to the platform Hypit state root. */+ readonly hostStateRoot?: string;};export type RuntimeConfigDoctorResult = {@@ -64,6 +77,11 @@ export type RuntimeConfigDoctorResult = {readonly diagnostics: readonly RuntimeDoctorDiagnostic[];};+type RuntimeInspectionOptions = LoadRuntimeConfigOptions & {+ readonly capabilities?: readonly CapabilityRef[];+ readonly active: boolean;+};+export type ResolvedRuntimeConfigPaths = {readonly packageRoot: string;readonly dataRoot: string;@@ -204,23 +222,56 @@ export async function resolveRuntimeConfigPaths(return { packageRoot: opened.packageRoot, dataRoot: opened.root };}+/** Explicit provisioning step used by runtime/programs up, never by plan or build. */+export async function prepareRuntimeConfigPackages(+ path: string,+ options: LoadRuntimeConfigOptions & {+ readonly onProgress?: (event: HostPackageProgress) => void;+ } = {},+): Promise<readonly HostPackageReport[]> {+ if (options.distributionPackageRoot === undefined) return [];+ const { document } = await openRuntimeConfig(path, options.packageRoot);+ const requirements = await distributionExternalPackageRequirements([+ document.artifacts.use,+ ...document.credentials.map((item) => item.use),+ ...document.endpoints.map((item) => item.use),+ ], options.distributionPackageRoot);+ return await prepareHostPackages(requirements.map((item) => item.specifier), {+ root: hypitHostPackageRoot(options.hostStateRoot),+ ...(options.onProgress === undefined ? {} : { onProgress: options.onProgress }),+ });+}+function capabilityKey(capability: CapabilityRef): string {return `${capability.module.name}@${capability.module.version}#${capability.name}`;}+function adapterContext(+ root: string,+ hostStateRoot: string,+ item: RuntimeConfigEntry,+): RuntimeAdapterFactoryContext {+ return {+ hostStateRoot,+ dataRoot: root,+ instance: item.instance,+ ...(item.pool === undefined ? {} : { pool: item.pool }),+ config: item.config ?? {},+ };+}+async function activatedEndpoints(document: RuntimeConfigDocument,root: string,+ hostStateRoot: string,registry: RuntimeAdapterRegistry,): Promise<readonly { readonly entry: RuntimeConfigEntry; readonly activation: RuntimeEndpointActivation }[]> {return await Promise.all(document.endpoints.map(async (item) => ({entry: item,- activation: await registry.activateEndpoint(item.use, {- dataRoot: root,- instance: item.instance,+ activation: await registry.activateEndpoint(item.use, adapterContext(root, hostStateRoot, {+ ...item,pool: item.pool ?? item.instance,- config: item.config ?? {},- }),+ })),})));}@@ -230,13 +281,14 @@ export async function declaredManagedPrograms(): Promise<{ readonly dataRoot: string; readonly programs: readonly DeclaredManagedProgram[] }> {const { document, root, packageRoot } = await openRuntimeConfig(path, options.packageRoot);if (options.capabilities?.length === 0) return { dataRoot: root, programs: [] };+ const hostStateRoot = resolve(options.hostStateRoot ?? hypitHostStateRoot());const registry = options.registry ?? new RuntimeAdapterRegistry();await installRuntimeAdapters(registry, packageRoot, endpointPackageSelection(document), options.distributionPackageRoot);const requested = options.capabilities === undefined? undefined: new Set(options.capabilities.map(capabilityKey));const programs: DeclaredManagedProgram[] = [];- for (const { entry, activation } of await activatedEndpoints(document, root, registry)) {+ for (const { entry, activation } of await activatedEndpoints(document, root, hostStateRoot, registry)) {if (requested !== undefined && !activation.endpoint.offers.some((offer) => requested.has(capabilityKey(offer.capability)))) continue;if (activation.program !== undefined) programs.push({ instance: entry.instance, program: activation.program });}@@ -255,16 +307,13 @@ function diagnostic(error: unknown, code: string, subject?: string): RuntimeDoctasync function openCredentialStores(document: RuntimeConfigDocument,root: string,+ hostStateRoot: string,registry: RuntimeAdapterRegistry,): Promise<{ readonly store: CredentialStore; close(): Promise<void> }> {const opened: RuntimeOpened<CredentialStore>[] = [];try {for (const item of document.credentials) {- opened.push(await registry.openCredentialStore(item.use, {- dataRoot: root,- instance: item.instance,- config: item.config ?? {},- }));+ opened.push(await registry.openCredentialStore(item.use, adapterContext(root, hostStateRoot, item)));}return {store: new CompositeCredentialStore(opened.map((item) => item.value)),@@ -281,25 +330,23 @@ async function openCredentialStores(async function openArtifactStore(document: RuntimeConfigDocument,root: string,+ hostStateRoot: string,registry: RuntimeAdapterRegistry,): Promise<RuntimeOpened<ArtifactStore>> {const item = document.artifacts;- return await registry.openArtifactStore(item.use, {- dataRoot: root,- instance: item.instance,- config: item.config ?? {},- });+ return await registry.openArtifactStore(item.use, adapterContext(root, hostStateRoot, item));}function statePath(root: string): string {return resolve(root, "runtime.sqlite");}-export async function doctorRuntimeConfig(+async function inspectRuntimeConfig(path: string,- options: LoadRuntimeConfigOptions & { readonly capabilities?: readonly CapabilityRef[] } = {},+ options: RuntimeInspectionOptions,): Promise<RuntimeConfigDoctorResult> {const { absolute, document, root, packageRoot } = await openRuntimeConfig(path, options.packageRoot);+ const hostStateRoot = resolve(options.hostStateRoot ?? hypitHostStateRoot());const diagnostics: RuntimeDoctorDiagnostic[] = [];try {if (!(await stat(root)).isDirectory()) throw new Error(`Runtime root ${root} is not a directory`);@@ -319,10 +366,12 @@ export async function doctorRuntimeConfig(...document.credentials.map((item) => ({ item, kind: "credential-store" as const })),];for (const selection of storeSelections) {- const context = { dataRoot: root, instance: selection.item.instance, config: selection.item.config ?? {} };+ const context = adapterContext(root, hostStateRoot, selection.item);try {diagnostics.push(...registry.validate(selection.item.use, selection.kind, context));- diagnostics.push(...await registry.doctor(selection.item.use, selection.kind, context));+ if (options.active) {+ diagnostics.push(...await registry.doctor(selection.item.use, selection.kind, context));+ }} catch (error) {diagnostics.push(diagnostic(error, "RUNTIME_COMPONENT_CONFIG_INVALID", selection.item.instance));}@@ -335,12 +384,10 @@ export async function doctorRuntimeConfig(for (const item of document.endpoints) {let activation: RuntimeEndpointActivation;try {- activation = await registry.activateEndpoint(item.use, {- dataRoot: root,- instance: item.instance,+ activation = await registry.activateEndpoint(item.use, adapterContext(root, hostStateRoot, {+ ...item,pool: item.pool ?? item.instance,- config: item.config ?? {},- });+ }));} catch (error) {diagnostics.push(diagnostic(error, "RUNTIME_ENDPOINT_CONFIG_INVALID", item.instance));continue;@@ -382,7 +429,7 @@ export async function doctorRuntimeConfig(if (credentialEndpoints.some((item) => item.endpoint.credentials.length > 0)) {let stores: Awaited<ReturnType<typeof openCredentialStores>> | undefined;try {- stores = await openCredentialStores(document, root, registry);+ stores = await openCredentialStores(document, root, hostStateRoot, registry);for (const activation of credentialEndpoints) {for (const slot of activation.endpoint.credentials) {if (await stores.store.resolve(slot.ref) !== undefined) continue;@@ -406,25 +453,44 @@ export async function doctorRuntimeConfig(return { dataRoot: root, diagnostics };}+/**+ * Cheap Build preflight. This intentionally stops at local configuration,+ * package, credential, executable and Managed Program readiness. Remote+ * connectivity belongs to doctor, and installation belongs to runtime up.+ */+export async function preflightRuntimeConfig(+ path: string,+ options: LoadRuntimeConfigOptions & { readonly capabilities?: readonly CapabilityRef[] } = {},+): Promise<RuntimeConfigDoctorResult> {+ return await inspectRuntimeConfig(path, { ...options, active: false });+}++/** Active diagnosis may ask selected stores and adapters to verify their configured services. */+export async function doctorRuntimeConfig(+ path: string,+ options: LoadRuntimeConfigOptions & { readonly capabilities?: readonly CapabilityRef[] } = {},+): Promise<RuntimeConfigDoctorResult> {+ return await inspectRuntimeConfig(path, { ...options, active: true });+}+export async function createRuntimeFromConfig(path: string,options: LoadRuntimeConfigOptions = {},): Promise<LocalRuntime> {const { document, root, packageRoot } = await openRuntimeConfig(path, options.packageRoot);+ const hostStateRoot = resolve(options.hostStateRoot ?? hypitHostStateRoot());const registry = options.registry ?? new RuntimeAdapterRegistry();await installRuntimeAdapters(registry, packageRoot, runtimePackageSelection(document), options.distributionPackageRoot);const state = new SqliteRuntimeState(statePath(root));let artifacts: RuntimeOpened<ArtifactStore> | undefined;let credentials: Awaited<ReturnType<typeof openCredentialStores>> | undefined;try {- artifacts = await openArtifactStore(document, root, registry);- credentials = await openCredentialStores(document, root, registry);- const endpoints = await Promise.all(document.endpoints.map(async (item) => await registry.createEndpoint(item.use, {- dataRoot: root,- instance: item.instance,- pool: item.pool ?? item.instance,- config: item.config ?? {},- })));+ artifacts = await openArtifactStore(document, root, hostStateRoot, registry);+ credentials = await openCredentialStores(document, root, hostStateRoot, registry);+ const endpoints = await Promise.all(document.endpoints.map(async (item) => await registry.createEndpoint(+ item.use,+ adapterContext(root, hostStateRoot, { ...item, pool: item.pool ?? item.instance }),+ )));return await createLocalRuntime({buildStore: state.builds,buildCatalog: state.catalog,@@ -475,11 +541,12 @@ export async function createRuntimeArtifactAccessFromConfig(options: LoadRuntimeConfigOptions = {},): Promise<LocalRuntimeArtifactAccess> {const { document, root, packageRoot } = await openRuntimeConfig(path, options.packageRoot);+ const hostStateRoot = resolve(options.hostStateRoot ?? hypitHostStateRoot());const registry = options.registry ?? new RuntimeAdapterRegistry();await installRuntimeAdapters(registry, packageRoot, {selected: [], logical: [{ abi: runtimeArtifactStoreAdapterHostAbi, name: document.artifacts.use }],}, options.distributionPackageRoot);- const opened = await openArtifactStore(document, root, registry);+ const opened = await openArtifactStore(document, root, hostStateRoot, registry);return createLocalRuntimeArtifactAccess({artifactStore: opened.value,...(opened.close === undefined ? {} : { close: opened.close }),@@ -492,18 +559,17 @@ export async function createRuntimeCredentialsFromConfig(options: LoadRuntimeConfigOptions = {},): Promise<LocalCredentialControl> {const { document, root, packageRoot } = await openRuntimeConfig(path, options.packageRoot);+ const hostStateRoot = resolve(options.hostStateRoot ?? hypitHostStateRoot());const endpoint = document.endpoints.find((item) => item.instance === endpointInstance);if (endpoint === undefined) throw new Error(`Runtime Profile has no Endpoint instance ${endpointInstance}`);const registry = options.registry ?? new RuntimeAdapterRegistry();await installRuntimeAdapters(registry, packageRoot, runtimePackageSelection(document), options.distributionPackageRoot);- const credentials = await openCredentialStores(document, root, registry);+ const credentials = await openCredentialStores(document, root, hostStateRoot, registry);try {- const endpointPackage = await registry.createEndpoint(endpoint.use, {- dataRoot: root,- instance: endpoint.instance,+ const endpointPackage = await registry.createEndpoint(endpoint.use, adapterContext(root, hostStateRoot, {+ ...endpoint,pool: endpoint.pool ?? endpoint.instance,- config: endpoint.config ?? {},- });+ }));return createLocalCredentialControl({credentialStore: credentials.store,endpoints: [endpointPackage],diff --git a/packages/runtime-local/src/host.ts b/packages/runtime-local/src/host.tsindex 2db5968b..8161732a 100644--- a/packages/runtime-local/src/host.ts+++ b/packages/runtime-local/src/host.ts@@ -3,6 +3,7 @@ import type {RuntimeController,RuntimeWorkerLaunch,} from "@hypit/runtime-host-node";+import { hypitHostStateRoot } from "@hypit/runtime-host-node";import { resolve } from "node:path";import {@@ -11,6 +12,8 @@ import {createRuntimeCredentialsFromConfig,createRuntimeFromConfig,doctorRuntimeConfig,+ prepareRuntimeConfigPackages,+ preflightRuntimeConfig,resolveRuntimeConfigPaths,} from "./config.js";import {@@ -31,14 +34,18 @@ export async function openLocalRuntimeHost(hostOptions: {readonly packageRoot: string;readonly distributionPackageRoot?: string;+ readonly hostStateRoot?: string;readonly workerLaunch: RuntimeWorkerLaunch;},): Promise<NodeRuntimeHost> {const profile = resolve(path);const basePackageRoot = resolve(hostOptions.packageRoot);- const distribution = hostOptions.distributionPackageRoot === undefined- ? {}- : { distributionPackageRoot: hostOptions.distributionPackageRoot };+ const distribution = {+ hostStateRoot: resolve(hostOptions.hostStateRoot ?? hypitHostStateRoot()),+ ...(hostOptions.distributionPackageRoot === undefined+ ? {}+ : { distributionPackageRoot: hostOptions.distributionPackageRoot }),+ };const controller = async (controllerOptions: {readonly packageRoot?: string;} = {}): Promise<RuntimeController> => {@@ -106,6 +113,16 @@ export async function openLocalRuntimeHost(endpoint,{ packageRoot: basePackageRoot, ...distribution },),+ prepare: async (options) => await prepareRuntimeConfigPackages(profile, {+ packageRoot: basePackageRoot,+ ...distribution,+ ...(options?.onProgress === undefined ? {} : { onProgress: options.onProgress }),+ }),+ preflight: async (options) => await preflightRuntimeConfig(profile, {+ packageRoot: basePackageRoot,+ ...distribution,+ ...(options?.capabilities === undefined ? {} : { capabilities: options.capabilities }),+ }),doctor: async (options) => await doctorRuntimeConfig(profile, {packageRoot: basePackageRoot,...distribution,diff --git a/packages/runtime-local/src/index.ts b/packages/runtime-local/src/index.tsindex 87290914..43b2a9c3 100644--- a/packages/runtime-local/src/index.ts+++ b/packages/runtime-local/src/index.ts@@ -14,6 +14,8 @@ export {createRuntimeCredentialsFromConfig,declaredManagedPrograms,doctorRuntimeConfig,+ prepareRuntimeConfigPackages,+ preflightRuntimeConfig,parseRuntimeConfig,resolveRuntimeConfigPaths,} from "./config.js";diff --git a/packages/runtime-local/src/process-control.ts b/packages/runtime-local/src/process-control.tsnew file mode 100644index 00000000..d6215eac--- /dev/null+++ b/packages/runtime-local/src/process-control.ts@@ -0,0 +1,52 @@+import { execFile } from "node:child_process";++export type ProcessStopResult = "sent" | "gone" | "denied";++function errorCode(error: unknown): string | undefined {+ return error instanceof Error && "code" in error ? String(error.code) : undefined;+}++export function processAlive(pid: number): boolean {+ try {+ process.kill(pid, 0);+ return true;+ } catch (error) {+ return errorCode(error) === "EPERM";+ }+}++function signal(pid: number, force: boolean): ProcessStopResult {+ if (!processAlive(pid)) return "gone";+ const name = force ? "SIGKILL" : "SIGTERM";+ for (const target of [-pid, pid]) {+ try {+ process.kill(target, name);+ return "sent";+ } catch (error) {+ if (errorCode(error) === "EPERM") return "denied";+ if (errorCode(error) !== "ESRCH") throw error;+ }+ }+ return "gone";+}++function taskkill(pid: number, force: boolean): Promise<ProcessStopResult> {+ if (!processAlive(pid)) return Promise.resolve("gone");+ return new Promise((resolve, reject) => {+ execFile("taskkill", ["/PID", String(pid), "/T", ...(force ? ["/F"] : [])], {+ shell: false,+ windowsHide: true,+ timeout: 15_000,+ }, (error) => {+ if (error === null) resolve("sent");+ else if (!processAlive(pid)) resolve("sent");+ else if (errorCode(error) === "EACCES" || errorCode(error) === "EPERM") resolve("denied");+ else reject(new Error(`taskkill could not stop process tree ${pid}: ${error.message}`));+ });+ });+}++/** Stop the OS-owned process tree rooted at a process Hypit started. */+export async function stopProcessTree(pid: number, force = false): Promise<ProcessStopResult> {+ return process.platform === "win32" ? await taskkill(pid, force) : signal(pid, force);+}diff --git a/packages/runtime-local/src/programs.ts b/packages/runtime-local/src/programs.tsindex 5474ef44..d8b3c356 100644--- a/packages/runtime-local/src/programs.ts+++ b/packages/runtime-local/src/programs.ts@@ -8,10 +8,11 @@ import type { ManagedProgram, ManagedProgramCommand, ManagedProgramState } fromimport { declaredManagedPrograms } from "./config.js";import type { LoadRuntimeConfigOptions } from "./config.js";+import { processAlive, stopProcessTree } from "./process-control.js";export type ManagedProgramAction =| "already-running"- | "prepared"+ | "installed"| "started"| "stopped"| "not-ours"@@ -33,7 +34,7 @@ export type ManagedProgramReport = {export type ManagedProgramProgress = {readonly id: string;- readonly phase: "checking" | "preparing" | "starting" | "waiting" | "ready";+ readonly phase: "checking" | "installing" | "starting" | "waiting" | "ready";};export type ManagedProgramOptions = LoadRuntimeConfigOptions & {@@ -56,8 +57,8 @@ function distinct(programs: readonly { instance: string; program: ManagedProgramreturn [...unique.values()];}-function directory(root: string): string {- return join(root, "programs");+function directory(root: string, program: ManagedProgram): string {+ return program.stateRoot ?? join(root, "programs", program.id);}const LOG_ROTATE_BYTES = 10 * 1024 * 1024;@@ -79,11 +80,11 @@ async function rotateLog(path: string): Promise<void> {await rename(path, previous);}-async function readPid(root: string, id: string): Promise<number | undefined> {+async function readPid(root: string, program: ManagedProgram): Promise<number | undefined> {try {- const text = await readFile(join(directory(root), `${id}.pid`), "utf8");+ const text = await readFile(join(directory(root, program), "process.pid"), "utf8");const pid = Number.parseInt(text.trim(), 10);- if (!Number.isSafeInteger(pid) || pid < 1) throw new Error(`External program ${id} pid file is invalid`);+ if (!Number.isSafeInteger(pid) || pid < 1) throw new Error(`External program ${program.id} pid file is invalid`);return pid;} catch (error) {if (nodeError(error, "ENOENT")) return undefined;@@ -91,29 +92,15 @@ async function readPid(root: string, id: string): Promise<number | undefined> {}}-function alive(pid: number): boolean {- try {- process.kill(pid, 0);- return true;- } catch (error) {- return error instanceof Error && "code" in error && error.code === "EPERM";- }-}--function signal(pid: number, name: NodeJS.Signals): "sent" | "gone" | "denied" {- try {- process.kill(pid, name);- return "sent";- } catch (error) {- if (error instanceof Error && "code" in error && error.code === "ESRCH") return "gone";- if (error instanceof Error && "code" in error && error.code === "EPERM") return "denied";- throw error;- }-}-function run(root: string, command: ManagedProgramCommand): Promise<{ ok: boolean; detail: string }> {return new Promise((resolve) => {- const child = spawn(command.command, [...command.args], { cwd: root, shell: false, windowsHide: true, stdio: ["ignore", "pipe", "pipe"] });+ const child = spawn(command.command, [...command.args], {+ cwd: command.cwd ?? root,+ env: { ...process.env, ...command.env },+ shell: false,+ windowsHide: true,+ stdio: ["ignore", "pipe", "pipe"],+ });let output = "";child.stdout.on("data", (chunk: Buffer) => { output += chunk.toString(); });child.stderr.on("data", (chunk: Buffer) => { output += chunk.toString(); });@@ -133,7 +120,7 @@ function run(root: string, command: ManagedProgramCommand): Promise<{ ok: booleaasync function waitForReady(program: ManagedProgram, pid: number, maxWaitMs: number): Promise<ManagedProgramState> {const deadline = Date.now() + maxWaitMs;let state = await program.probe();- while (state.state === "down" && alive(pid) && Date.now() < deadline) {+ while (state.state === "down" && processAlive(pid) && Date.now() < deadline) {await sleep(1000);state = await program.probe();}@@ -159,29 +146,41 @@ async function bringUp(return { ...base, action: "unchanged", state: initial };}- if (program.prepare !== undefined) {- onProgress?.({ id: program.id, phase: "preparing" });- const prepared = await run(root, program.prepare);- if (!prepared.ok) {- return { ...base, action: "unchanged", state: initial, detail: `${program.prepare.command} failed: ${prepared.detail}` };+ let installed = false;+ if (program.installation !== undefined) {+ const installation = await program.installation.probe();+ if (installation.state !== "ready") {+ onProgress?.({ id: program.id, phase: "installing" });+ await mkdir(directory(root, program), { recursive: true });+ for (const command of program.installation.commands) {+ const result = await run(root, command);+ if (!result.ok) {+ return { ...base, action: "unchanged", state: initial, detail: `${command.command} failed: ${result.detail}` };+ }+ }+ const after = await program.installation.probe();+ if (after.state !== "ready") {+ return { ...base, action: "unchanged", state: initial, detail: `installation is ${after.state}: ${after.detail}` };+ }+ installed = true;}}if (program.start === undefined) {- // Nothing to keep running: preparing was the whole job, and the probe says- // whether it worked.+ // Nothing to keep running: installation was the whole job.const state = await program.probe();if (state.state === "ready") onProgress?.({ id: program.id, phase: "ready" });- return { ...base, action: state.state === "ready" ? "prepared" : "unchanged", state };+ return { ...base, action: state.state === "ready" && installed ? "installed" : "unchanged", state };}onProgress?.({ id: program.id, phase: "starting" });- await mkdir(directory(root), { recursive: true });- const logPath = join(directory(root), `${program.id}.log`);+ await mkdir(directory(root, program), { recursive: true });+ const logPath = join(directory(root, program), "program.log");await rotateLog(logPath);const log = await open(logPath, "a");try {const child = spawn(program.start.command, [...program.start.args], {- cwd: root,+ cwd: program.start.cwd ?? root,+ env: { ...process.env, ...program.start.env },shell: false,// Outliving this process is the point, and each platform grants that differently. POSIX// wants its own session. Windows already gives an unreferenced child its own lifetime, and@@ -197,20 +196,19 @@ async function bringUp(if (child.pid === undefined) {return { ...base, action: "unchanged", state: initial, detail: `${program.start.command} did not start`, logPath };}- await writeFile(join(directory(root), `${program.id}.pid`), `${child.pid}\n`);onProgress?.({ id: program.id, phase: "waiting" });const state = await waitForReady(program, child.pid, maxWaitMs);if (state.state === "ready") onProgress?.({ id: program.id, phase: "ready" });- const exited = state.state === "down" && !alive(child.pid);- if (exited) await rm(join(directory(root), `${program.id}.pid`), { force: true });+ const alive = processAlive(child.pid);+ if (alive) await writeFile(join(directory(root, program), "process.pid"), `${child.pid}\n`);return {...base,- action: state.state === "ready" ? "started" : "unchanged",+ action: state.state === "ready" ? (alive ? "started" : "already-running") : "unchanged",state,- pid: child.pid,+ ...(alive ? { pid: child.pid } : {}),logPath,...(state.state === "ready" ? {} : {- detail: exited ? `process exited; see ${logPath}` : `see ${logPath}`,+ detail: alive ? `see ${logPath}` : `process exited; see ${logPath}`,}),};} finally {@@ -218,21 +216,21 @@ async function bringUp(}}-/** Prepare and start every external program the Runtime Profile implies. */+/** Install when needed and start every external program the Runtime Profile implies. */export async function bringManagedProgramsUp(path: string,options: ManagedProgramOptions = {},): Promise<{ readonly dataRoot: string; readonly programs: readonly ManagedProgramReport[] }> {const { dataRoot, programs } = await declaredManagedPrograms(path, options);- // A fresh Runtime has no data directory yet. Managed commands use it as- // their working directory, so create it before the first prepare/start.+ // A fresh Runtime has no data directory yet. External commands may use it as+ // their working directory, so create it before the first install/start.await mkdir(dataRoot, { recursive: true });const reports = await Promise.all(distinct(programs).map(async ({ program, instances }) =>await bringUp(dataRoot, program, instances, options.maxWaitMs ?? 300_000, options.onProgress)));return { dataRoot, programs: reports };}-/** Stop the programs this project started. A program it did not start is left alone. */+/** Stop programs whose machine-level process records say Hypit started them. */export async function takeManagedProgramsDown(path: string,options: ManagedProgramOptions = {},@@ -240,17 +238,17 @@ export async function takeManagedProgramsDown(const { dataRoot, programs } = await declaredManagedPrograms(path, options);const reports = await Promise.all(distinct(programs).map(async ({ program, instances }): Promise<ManagedProgramReport> => {const base = { id: program.id, instances };- const pid = await readPid(dataRoot, program.id);- if (pid === undefined || !alive(pid)) {- if (pid !== undefined) await rm(join(directory(dataRoot), `${program.id}.pid`), { force: true });+ const pid = await readPid(dataRoot, program);+ if (pid === undefined || !processAlive(pid)) {+ if (pid !== undefined) await rm(join(directory(dataRoot, program), "process.pid"), { force: true });const state = await program.probe();return state.state === "down"? { ...base, action: "nothing-to-stop", state }// Someone else's process, or one started by hand. Killing it is not this// command's business; saying so is.- : { ...base, action: "not-ours", state, detail: `${program.id} is running but this project did not start it` };+ : { ...base, action: "not-ours", state, detail: `${program.id} is running without a Hypit process record` };}- const term = signal(pid, "SIGTERM");+ const term = await stopProcessTree(pid);if (term === "denied") {return {...base,@@ -261,24 +259,37 @@ export async function takeManagedProgramsDown(};}if (term === "gone") {- await rm(join(directory(dataRoot), `${program.id}.pid`), { force: true });+ await rm(join(directory(dataRoot, program), "process.pid"), { force: true });const state = await program.probe();return state.state === "down"? { ...base, action: "nothing-to-stop", state }: { ...base, action: "not-ours", state, detail: `${program.id} is now served by another process` };}const deadline = Date.now() + 15_000;- while (alive(pid) && Date.now() < deadline) await sleep(200);- if (alive(pid) && signal(pid, "SIGKILL") === "denied") {- return {- ...base,- action: "unchanged",- state: await program.probe(),- pid,- detail: `process ${pid} ignored SIGTERM and this environment cannot force-stop it`,- };+ while (processAlive(pid) && Date.now() < deadline) await sleep(200);+ if (processAlive(pid)) {+ if (await stopProcessTree(pid, true) === "denied") {+ return {+ ...base,+ action: "unchanged",+ state: await program.probe(),+ pid,+ detail: `process ${pid} ignored graceful termination and cannot be force-stopped`,+ };+ }+ const forceDeadline = Date.now() + 2_000;+ while (processAlive(pid) && Date.now() < forceDeadline) await sleep(50);+ if (processAlive(pid)) {+ return {+ ...base,+ action: "unchanged",+ state: await program.probe(),+ pid,+ detail: `process ${pid} remained alive after forced termination`,+ };+ }}- await rm(join(directory(dataRoot), `${program.id}.pid`), { force: true });+ await rm(join(directory(dataRoot, program), "process.pid"), { force: true });return { ...base, action: "stopped", state: await program.probe(), pid };}));return { dataRoot, programs: reports };@@ -292,8 +303,8 @@ export async function reportManagedPrograms(const { dataRoot, programs } = await declaredManagedPrograms(path, options);const reports = await Promise.all(distinct(programs).map(async ({ program, instances }): Promise<ManagedProgramReport> => {const state = await program.probe();- const pid = await readPid(dataRoot, program.id);- const logPath = join(directory(dataRoot), `${program.id}.log`);+ const pid = await readPid(dataRoot, program);+ const logPath = join(directory(dataRoot, program), "program.log");let hasLog = false;try {await stat(logPath);@@ -305,7 +316,7 @@ export async function reportManagedPrograms(id: program.id,instances,state,- ...(pid !== undefined && alive(pid) ? { pid } : {}),+ ...(pid !== undefined && processAlive(pid) ? { pid } : {}),...(hasLog ? { logPath } : {}),};}));diff --git a/packages/runtime-local/src/worker-process.ts b/packages/runtime-local/src/worker-process.tsindex 13adafbc..c6caab68 100644--- a/packages/runtime-local/src/worker-process.ts+++ b/packages/runtime-local/src/worker-process.ts@@ -2,6 +2,8 @@ import { spawn } from "node:child_process";import { mkdir, open, readFile, rename, rm, stat, writeFile } from "node:fs/promises";import { dirname, join, resolve } from "node:path";+import { processAlive, stopProcessTree } from "./process-control.js";+export type RuntimeWorkerLaunch = {readonly command: string;readonly args: readonly string[];@@ -49,18 +51,6 @@ async function exists(path: string): Promise<boolean> {}}-function alive(pid: number): boolean {- try {- process.kill(pid, 0);- return true;- } catch (error) {- // POSIX uses EPERM when the process exists but the caller may not signal it.- // Treat only an absent process as stopped; otherwise a restricted shell can- // make every CLI invocation launch another Worker for the same Profile.- return error instanceof Error && "code" in error && error.code === "EPERM";- }-}-async function rotateLog(path: string): Promise<void> {let size = 0;try {@@ -96,7 +86,7 @@ export async function runtimeProcessStatus(): Promise<RuntimeProcessState> {const location = paths(dataRoot);const current = await record(profile, dataRoot);- if (current === undefined || !alive(current.pid)) {+ if (current === undefined || !processAlive(current.pid)) {return { state: "stopped", profile: resolve(profile), logPath: location.log };}return {@@ -177,26 +167,32 @@ export async function ensureRuntimeProcess(async function stopRuntimeProcessUnlocked(profile: string, dataRoot: string, timeoutMs: number): Promise<RuntimeProcessState> {const current = await record(profile, dataRoot);const location = paths(dataRoot);- if (current === undefined || !alive(current.pid)) {+ if (current === undefined || !processAlive(current.pid)) {await rm(location.pid, { force: true });await rm(location.ready, { force: true });return { state: "stopped", profile: resolve(profile), logPath: location.log };}- try {- process.kill(current.pid, "SIGTERM");- } catch (error) {- if (error instanceof Error && "code" in error && error.code === "EPERM") {- throw new Error(- `Runtime Worker ${current.pid} is running but this environment cannot stop it; profile: ${resolve(profile)}`,- );- }- if (!(error instanceof Error && "code" in error && error.code === "ESRCH")) throw error;+ if (await stopProcessTree(current.pid) === "denied") {+ throw new Error(+ `Runtime Worker ${current.pid} is running but this environment cannot stop it; profile: ${resolve(profile)}`,+ );}const deadline = Date.now() + timeoutMs;- while (Date.now() <= deadline && alive(current.pid)) {+ while (Date.now() <= deadline && processAlive(current.pid)) {await new Promise((resolveWait) => setTimeout(resolveWait, 50));}- if (alive(current.pid)) throw new Error(`Runtime Worker ${current.pid} did not stop within ${timeoutMs}ms`);+ if (processAlive(current.pid)) {+ if (await stopProcessTree(current.pid, true) === "denied") {+ throw new Error(`Runtime Worker ${current.pid} did not stop within ${timeoutMs}ms`);+ }+ const forceDeadline = Date.now() + 2_000;+ while (Date.now() <= forceDeadline && processAlive(current.pid)) {+ await new Promise((resolveWait) => setTimeout(resolveWait, 20));+ }+ if (processAlive(current.pid)) {+ throw new Error(`Runtime Worker ${current.pid} remained alive after forced termination`);+ }+ }await rm(location.pid, { force: true });await rm(location.ready, { force: true });return { state: "stopped", profile: resolve(profile), logPath: location.log };diff --git a/packages/runtime-local/test/config.test.ts b/packages/runtime-local/test/config.test.tsindex 640768b8..4a71e530 100644--- a/packages/runtime-local/test/config.test.ts+++ b/packages/runtime-local/test/config.test.ts@@ -16,6 +16,7 @@ import {createRuntimeArtifactAccessFromConfig,doctorRuntimeConfig,parseRuntimeConfig,+ preflightRuntimeConfig,} from "@hypit/runtime-local";function profile(config: {@@ -118,3 +119,29 @@ test("doctor reports a down Managed Program", async () => {await rm(root, { recursive: true, force: true });}});++test("preflight validates stores without running their active doctor", async () => {+ const root = await mkdtemp(join(tmpdir(), "hypit-runtime-preflight-"));+ const path = join(root, "hypit.runtime.json");+ await writeFile(path, JSON.stringify(profile({ dataRoot: "." })));+ let activeChecks = 0;+ const registry = new RuntimeAdapterRegistry();+ registry.registerFacet(createRuntimeArtifactStoreAdapterFacet({+ use: "example.artifacts",+ validate() {},+ open: () => ({ value: new MemoryArtifactStore() }),+ doctor: async () => {+ activeChecks += 1;+ return [];+ },+ }));+ try {+ const preflight = await preflightRuntimeConfig(path, { registry });+ assert.deepEqual(preflight.diagnostics, []);+ assert.equal(activeChecks, 0);+ await doctorRuntimeConfig(path, { registry });+ assert.equal(activeChecks, 1);+ } finally {+ await rm(root, { recursive: true, force: true });+ }+});diff --git a/packages/runtime-local/test/programs.test.ts b/packages/runtime-local/test/programs.test.tsindex ce0d55dd..5a9c65f9 100644--- a/packages/runtime-local/test/programs.test.ts+++ b/packages/runtime-local/test/programs.test.ts@@ -149,7 +149,7 @@ test("up starts the program once for every Endpoint that drives it, and down stoassert.deepEqual(progress, ["example:checking", "example:starting", "example:waiting", "example:ready"]);const pid = started.programs[0]!.pid!;- assert.equal(await readFile(join(root, "programs", "example.pid"), "utf8"), `${pid}\n`);+ assert.equal(await readFile(join(root, "programs", "example", "process.pid"), "utf8"), `${pid}\n`);// Asking again changes nothing: a healthy program is left alone.const again = await bringManagedProgramsUp(path, { ...options, maxWaitMs: 20_000 });@@ -158,7 +158,7 @@ test("up starts the program once for every Endpoint that drives it, and down stoconst status = await reportManagedPrograms(path, options);assert.equal(status.programs[0]!.pid, pid);- assert.equal(status.programs[0]!.logPath, join(root, "programs", "example.log"));+ assert.equal(status.programs[0]!.logPath, join(root, "programs", "example", "program.log"));await rm(marker, { force: true });const stopped = await takeManagedProgramsDown(path, options);@@ -166,7 +166,7 @@ test("up starts the program once for every Endpoint that drives it, and down stoassert.equal(stopped.programs[0]!.pid, pid);await sleep(100);assert.throws(() => process.kill(pid, 0), "the detached program is gone");- await assert.rejects(async () => await readFile(join(root, "programs", "example.pid"), "utf8"));+ await assert.rejects(async () => await readFile(join(root, "programs", "example", "process.pid"), "utf8"));await rm(root, { recursive: true, force: true });});@@ -182,7 +182,7 @@ test("a program answering with another identity is never joined by a second copyassert.equal(result.programs[0]!.pid, undefined, "nothing was started beside it");});-test("down leaves a running program this project did not start", async () => {+test("down leaves a running program without a Hypit process record", async () => {const { path, options } = await project(() => ({id: "example",start: nodeProgram("setTimeout(() => {}, 60_000);"),@@ -190,26 +190,32 @@ test("down leaves a running program this project did not start", async () => {}));const result = await takeManagedProgramsDown(path, options);assert.equal(result.programs[0]!.action, "not-ours");- assert.match(result.programs[0]!.detail ?? "", /this project did not start it/u);+ assert.match(result.programs[0]!.detail ?? "", /without a Hypit process record/u);});-test("a program with nothing to start is prepared, and preparing is the whole job", async () => {+test("a program with nothing to start is installed once, and installation is the whole job", async () => {const directory = await mkdtemp(join(tmpdir(), "hypit-prepare-"));const marker = join(directory, "installed");- const { path, options } = await project(() => ({- id: "example",- prepare: nodeProgram('require("node:fs").writeFileSync(process.argv[1], "done");', marker),- async probe() {+ const { path, options } = await project(() => {+ const probe = async () => {try {await readFile(marker, "utf8");- return { state: "ready" };+ return { state: "ready" as const };} catch {- return { state: "down", detail: "not installed" };+ return { state: "down" as const, detail: "not installed" };}- },- }));+ };+ return {+ id: "example",+ installation: {+ commands: [nodeProgram('require("node:fs").writeFileSync(process.argv[1], "done");', marker)],+ probe,+ },+ probe,+ };+ });const result = await bringManagedProgramsUp(path, options);- assert.equal(result.programs[0]!.action, "prepared");+ assert.equal(result.programs[0]!.action, "installed");assert.deepEqual(result.programs[0]!.state, { state: "ready" });assert.equal(result.programs[0]!.pid, undefined, "there is no daemon to hold a pid");await rm(directory, { recursive: true, force: true });@@ -232,6 +238,14 @@ test("up creates a fresh Runtime data directory before running commands", async},}));const registry = new RuntimeAdapterRegistry();+ const probe = async () => {+ try {+ await readFile(join(dataRoot, "installed"), "utf8");+ return { state: "ready" as const };+ } catch {+ return { state: "down" as const, detail: "not installed" };+ }+ };registry.registerFacet(createRuntimeEndpointAdapterFacet({use: "example.program",activate: () => ({@@ -249,29 +263,28 @@ test("up creates a fresh Runtime data directory before running commands", async} as never,program: {id: "example",- prepare: nodeProgram('require("node:fs").writeFileSync("prepared", "ready");'),- async probe() {- try {- await readFile(join(dataRoot, "prepared"), "utf8");- return { state: "ready" as const };- } catch {- return { state: "down" as const, detail: "not prepared" };- }+ installation: {+ commands: [nodeProgram('require("node:fs").writeFileSync("installed", "ready");')],+ probe,},+ probe,},}),}));const result = await bringManagedProgramsUp(path, { registry });- assert.equal(result.programs[0]!.action, "prepared");- assert.equal(await readFile(join(dataRoot, "prepared"), "utf8"), "ready");+ assert.equal(result.programs[0]!.action, "installed");+ assert.equal(await readFile(join(dataRoot, "installed"), "utf8"), "ready");await rm(projectRoot, { recursive: true, force: true });});-test("a failing prepare stops before starting anything, and says which command failed", async () => {+test("a failing install stops before starting anything, and says which command failed", async () => {const { path, options } = await project(() => ({id: "example",- prepare: nodeProgram('process.stderr.write("no such project\\n"); process.exit(1);'),+ installation: {+ commands: [nodeProgram('process.stderr.write("no such project\\n"); process.exit(1);')],+ probe: async () => ({ state: "down", detail: "not installed" }),+ },start: nodeProgram(STAY_ALIVE),probe: async () => ({ state: "down", detail: "nothing is answering" }),}));@@ -296,7 +309,7 @@ test("up stops waiting when a started program exits", async () => {assert.ok(Date.now() - startedAt < 5_000, "a dead program must not consume the readiness timeout");assert.equal(result.programs[0]!.action, "unchanged");assert.match(result.programs[0]!.detail ?? "", /process exited; see/u);- await assert.rejects(async () => await readFile(join(root, "programs", "example.pid"), "utf8"));+ await assert.rejects(async () => await readFile(join(root, "programs", "example", "process.pid"), "utf8"));});test("status probes and changes nothing, so it claims no action", async () => {diff --git a/packages/runtime/src/credentials.ts b/packages/runtime/src/credentials.tsindex 68b06a16..d3f7b242 100644--- a/packages/runtime/src/credentials.ts+++ b/packages/runtime/src/credentials.ts@@ -1,5 +1,5 @@export type CredentialRef = {- /** CredentialStore implementation name, for example env, keychain or aws-default. */+ /** CredentialStore implementation name, for example env, os or aws-default. */readonly store: string;/** Store-local opaque lookup key. It is configuration, never the secret value. */readonly key: string;diff --git a/packages/seedance-kits/README.md b/packages/seedance-kits/README.mdindex be03518f..4bf4b881 100644--- a/packages/seedance-kits/README.md+++ b/packages/seedance-kits/README.md@@ -5,7 +5,7 @@ not model wrappers, Providers or new execution nodes.Vendor the selected `.svs` file into the video project (for example `./kits/speaker-v1.svs`). Thiskeeps its bytes inside the project's Source Closure and Workspace boundary; a project must not-reach back into a Hypit checkout through `../../packages/...`.+reach back into the installed Distribution through `../../packages/...`.Each Kit is rendered by the domain-neutral `text:Render` Surface. Its Text output then feeds one ofthe three low-level `@hypit/seedance` invocation modes. Reference media and duration remaindiff --git a/packages/studio/README.md b/packages/studio/README.mdindex fcae0cf5..eebfb1aa 100644--- a/packages/studio/README.md+++ b/packages/studio/README.md@@ -11,7 +11,7 @@ hypit-studio --run build.svrun```Studio is an application boundary. Core and domain packages do not import it or-register UI metadata. The tool checkout supplies the official Studio Adapter+register UI metadata. The installed Distribution supplies the official Studio Adapterdistribution. An external project may explicitly add companion Adapter packagesthrough `hypit.studio.json`; the application assembles one immutable registry forthat project session.@@ -24,7 +24,7 @@ that project session.```Project packages live at `<project>/packages/<package-basename>/`. Neither the-project nor its packages are added to the Hypit checkout or its pnpm workspace.+project nor its packages are added to the Hypit Distribution or contributor workspace.The Host resolves selected project packages from the project first and official`@hypit/*` imports from the read-only tool Distribution. The `@hypit/*`namespace is Distribution-owned and cannot be shadowed by a project install.@@ -39,6 +39,12 @@ replacement rules, fallback defaults, selection treatment, playback, zoom,scrolling and source mutation transport. A companion cannot ship arbitrary DOMor CSS into the application.+Temporal lineage comes from the exact executed graph selected by the Run. Studio indexes the+`TemporalPoint` and `TemporalWindow` records in each Track's dependency closure together with their+projection Spec and direct consumer edge, then passes that stable data view to adapters. Adapters+never infer a semantic source from SVML attribute names, Spec type names, runtime id prefixes or+coincident frame spans. Point and Window remain distinct in the inspector.+Opening Studio never invokes a Provider and never creates a Build. Everyprojection needed for display must already be supplied by the Run or bedeterministically derivable from those supplied Candidates.diff --git a/packages/studio/package.json b/packages/studio/package.jsonindex 15508f0d..c96bd234 100644--- a/packages/studio/package.json+++ b/packages/studio/package.json@@ -3,6 +3,10 @@"version": "0.0.1","private": true,"type": "module",+ "exports": {+ "./start": "./start.ts",+ "./preview-check": "./preview-check.ts"+ },"dependencies": {"@hypit/cli": "workspace:*","@hypit/compiler-node": "workspace:*",diff --git a/packages/studio/preview-check.ts b/packages/studio/preview-check.tsnew file mode 100644index 00000000..f072a8e7--- /dev/null+++ b/packages/studio/preview-check.ts@@ -0,0 +1,83 @@+#!/usr/bin/env node+import { dirname, resolve } from "node:path";++import { videoCliDistribution } from "@hypit/video-cli";++import { openStudioArchive } from "./src/archive.js";+import { loadStudioAdapterRegistry } from "./src/adapter-profile.js";+import { loadStudioDomain } from "./src/domain.js";+import { loadStudioRun } from "./src/run.js";+import { readStudioSession } from "./src/session.js";+import { inspectStudioRun } from "./src/studio-preflight.js";++const runArgument = process.argv[2];+if (runArgument === undefined) {+ process.stderr.write("usage: hypit-preview-check <build.svrun> [<hypit.runtime.json>]\n");+ process.exitCode = 2;+} else {+ const invokedFrom = process.env.INIT_CWD ?? process.cwd();+ const runPath = resolve(invokedFrom, runArgument);+ const runtimeArgument = process.argv[3];+ const runtimePath = runtimeArgument === undefined ? undefined : resolve(invokedFrom, runtimeArgument);+ const workspaceRoot = dirname(runPath);+ const packageRoot = workspaceRoot;+ const distributionPackageRoot = videoCliDistribution.packageRoot;+ if (distributionPackageRoot === undefined) throw new Error("active Hypit Distribution has no package root");++ const registry = await loadStudioAdapterRegistry({ workspaceRoot, packageRoot, distributionPackageRoot });+ const domain = await loadStudioDomain({ run: runPath, workspaceRoot, packageRoot });+ const archive = await openStudioArchive(runtimePath, packageRoot, distributionPackageRoot);+ const awaitingPrefix = "the Studio projection closure requires unresolved capabilities:";++ let session: Awaited<ReturnType<typeof readStudioSession>> | undefined;+ let refusal: string | undefined;+ let awaiting: string[] | undefined;+ try {+ const run = await loadStudioRun({+ run: runPath,+ domain,+ ...(archive === undefined ? {} : { archive }),+ });+ inspectStudioRun(registry, run.source, run);+ session = await readStudioSession({+ domain,+ registry,+ run,+ workspaceRoot,+ ...(archive === undefined ? {} : { archive }),+ revision: 0,+ });+ } catch (error) {+ const issues = (error as { readonly issues?: unknown }).issues;+ if (Array.isArray(issues)+ && issues.every((issue): issue is string => typeof issue === "string" && issue.startsWith(awaitingPrefix))) {+ awaiting = issues.flatMap((issue) => issue.slice(awaitingPrefix.length).split(",").map((item) => item.trim()));+ } else {+ refusal = error instanceof Error ? error.message : String(error);+ }+ } finally {+ await archive?.close();+ }++ if (refusal !== undefined) {+ process.stdout.write(`${JSON.stringify({ refused: refusal }, null, 2)}\n`);+ process.exitCode = 1;+ } else if (awaiting !== undefined) {+ const noun = awaiting.length === 1 ? "capability" : "capabilities";+ process.stdout.write(`preview-check: the graph is sound, waiting on ${awaiting.length} ${noun}.\n`);+ for (const capability of awaiting) process.stdout.write(` - ${capability}\n`);+ } else if (session !== undefined) {+ const problems: Array<Record<string, unknown>> = [];+ for (const track of session.snapshot.tracks) {+ const { status, errors, output } = track.provenance;+ if (errors.length > 0) problems.push({ track: track.label, errors });+ else if (status === "unresolved") problems.push({ track: track.label, unresolved: output });+ }+ if (problems.length === 0) {+ process.stdout.write(`preview-check: every Track resolved (${session.snapshot.tracks.length}).\n`);+ } else {+ for (const item of problems) process.stdout.write(`${JSON.stringify(item, null, 2)}\n`);+ process.exitCode = 1;+ }+ }+}diff --git a/packages/studio/src/server.ts b/packages/studio/src/server.tsindex 5c558d2b..c1d1c7a7 100644--- a/packages/studio/src/server.ts+++ b/packages/studio/src/server.ts@@ -2,7 +2,7 @@ import { watch } from "node:fs";import type { FSWatcher } from "node:fs";import { existsSync } from "node:fs";import { readFile, rename, writeFile, unlink } from "node:fs/promises";-import { isAbsolute, relative, resolve, dirname, join } from "node:path";+import { basename, dirname, isAbsolute, join, relative, resolve } from "node:path";import type { Plugin, ViteDevServer } from "vite";@@ -176,7 +176,7 @@ export function studioPlugin(options: StudioPluginOptions): Plugin {const temporaries: { readonly path: string; readonly temporary: string }[] = [];try {for (const [absolute, text] of nextFiles) {- const temporary = join(dirname(absolute), `.${absolute.split("/").at(-1) ?? "source"}.hypit-studio.tmp`);+ const temporary = join(dirname(absolute), `.${basename(absolute)}.hypit-studio.tmp`);await writeFile(temporary, text, "utf8");temporaries.push({ path: absolute, temporary });}diff --git a/packages/transport-aws-lambda/package.json b/packages/transport-aws-lambda/package.jsonindex 9cc34836..f9a75eef 100644--- a/packages/transport-aws-lambda/package.json+++ b/packages/transport-aws-lambda/package.json@@ -8,7 +8,7 @@".": "./src/index.ts"},"dependencies": {- "@aws-sdk/client-lambda": "^3.1103.0",+ "@aws-sdk/client-lambda": "3.1103.0","@hypit/protocol": "workspace:*"}}diff --git a/packages/video-cli/README.md b/packages/video-cli/README.mdindex 0c39486e..69627b78 100644--- a/packages/video-cli/README.md+++ b/packages/video-cli/README.md@@ -7,7 +7,7 @@ Every Frontend, Surface, deterministic Producer and Validator is activated fromInstalling a new author package therefore does not require a video CLI or Core release. Sourceimports never grant network, credential or process authority.-From the repository:+From any project:```bashcd path/to/project@@ -25,16 +25,15 @@ hypit doctorhypit gc```-Link the repository command once with `npm link`. It resolves its own TypeScript loader and CLI, so-it neither invokes pnpm per command nor requires a separate project to contain Hypit's-`package.json`.+Install the `hypit` Distribution globally once. It resolves its own TypeScript loader and CLI, so it+neither invokes npm per command nor requires a project to contain Hypit's `package.json`.`--workspace` is only the Source Workspace containment boundary. `--asset-root` may additionally admitexplicit asset bytes without widening Source imports. `--package-root` is only the Hostoverride used to resolve installed packages. By default, a project with`package.json` owns package resolution; a plain creative folder falls back to this Distribution's-installation. Keeping that separate from Source containment lets a video project live outside this-checkout without weakening canonical-path source and asset boundaries. Runtime Profiles do not+installation. Keeping that separate from Source containment lets a video project live outside the+Distribution without weakening canonical-path source and asset boundaries. Runtime Profiles do notcontain either Workspace or package-installation overrides.`check` is usable for an Author Source or a complete Run Source. `plan` and `build` require a Rundiff --git a/packages/video-cli/package.json b/packages/video-cli/package.jsonindex b9a319ea..7bac1ad2 100644--- a/packages/video-cli/package.json+++ b/packages/video-cli/package.json@@ -5,12 +5,14 @@"private": true,"type": "module","exports": {- ".": "./src/index.ts"+ ".": "./src/index.ts",+ "./cli": "./src/cli.ts"},"dependencies": {"@hypit/cli": "workspace:*","@hypit/compiler-markup-node": "workspace:*","@hypit/credential-store-env": "workspace:*",+ "@hypit/credential-store-os": "workspace:*","@hypit/driver-node": "workspace:*","@hypit/endpoint-kit": "workspace:*","@hypit/generation": "workspace:*",@@ -19,6 +21,7 @@"@hypit/package-loader-node": "workspace:*","@hypit/protocol": "workspace:*","@hypit/provider-kie": "workspace:*",+ "@hypit/runtime-host-node": "workspace:*","@hypit/runtime-local": "workspace:*","@hypit/workspace-fs-node": "workspace:*"}diff --git a/packages/video-cli/src/distribution.ts b/packages/video-cli/src/distribution.tsindex fc60e9be..f8f10f9e 100644--- a/packages/video-cli/src/distribution.ts+++ b/packages/video-cli/src/distribution.ts@@ -8,7 +8,7 @@ import {// The Distribution root is the replaceable Hypit tool checkout, not this// package's source directory and never the author's project.-const packageRoot = resolve(import.meta.dirname, "../../..");+const packageRoot = resolve(process.env.HYPIT_DISTRIBUTION_ROOT ?? resolve(import.meta.dirname, "../../.."));const installedLauncher = process.env.HYPIT_CLI_LAUNCHER;/** Official video authoring assembly for the generic CLI engine. */diff --git a/packages/video-cli/src/index.ts b/packages/video-cli/src/index.tsindex 79b41a84..efea0791 100644--- a/packages/video-cli/src/index.ts+++ b/packages/video-cli/src/index.ts@@ -4,7 +4,11 @@ import {runCli,} from "@hypit/cli";import type { CliIo } from "@hypit/cli";-import { installDistributionPackageResolution } from "@hypit/package-loader-node";+import {+ installDistributionPackageResolution,+ installExternalPackageResolution,+} from "@hypit/package-loader-node";+import { hypitHostPackageRoot } from "@hypit/runtime-host-node";import type { LoadedPackage } from "@hypit/package-loader-node";import { videoCliDistribution } from "./distribution.js";@@ -24,6 +28,7 @@ export function runVideoCli(installDistributionPackageResolution(videoCliDistribution.packageRoot === undefined? []: [videoCliDistribution.packageRoot]);+ installExternalPackageResolution([hypitHostPackageRoot()]);return runCli(argv, io, {...videoCliDistribution,bootstrapPackages: packages,diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 165798af..634a6d24 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -7,6 +7,10 @@ settings:importers:.:+ dependencies:+ tsx:+ specifier: 4.21.0+ version: 4.21.0devDependencies:'@hypit/artifact':specifier: workspace:*@@ -38,9 +42,9 @@ importers:'@hypit/credential-store-env':specifier: workspace:*version: link:packages/credential-store-env- '@hypit/credential-store-keychain':+ '@hypit/credential-store-os':specifier: workspace:*- version: link:packages/credential-store-keychain+ version: link:packages/credential-store-os'@hypit/deck-track':specifier: workspace:*version: link:packages/deck-track@@ -206,15 +210,9 @@ importers:'@types/node':specifier: 24.10.1version: 24.10.1- tsx:- specifier: 4.21.0- version: 4.21.0typescript:specifier: 5.9.3version: 5.9.3- vite:- specifier: 5.4.21- version: 5.4.21(@types/[email protected])vitepress:specifier: ^1.6.4version: 1.6.4(@algolia/[email protected])(@types/[email protected])([email protected])([email protected])([email protected])@@ -240,7 +238,7 @@ importers:packages/artifact-store-s3:dependencies:'@aws-sdk/client-s3':- specifier: ^3.1103.0+ specifier: 3.1103.0version: 3.1103.0'@hypit/protocol':specifier: workspace:*@@ -607,7 +605,7 @@ importers:specifier: workspace:*version: link:../runtime-kit- packages/credential-store-keychain:+ packages/credential-store-os:dependencies:'@hypit/runtime':specifier: workspace:*@@ -797,6 +795,16 @@ importers:packages/fonts-open:dependencies:+ '@hypit/markup':+ specifier: workspace:*+ version: link:../markup+ '@hypit/media':+ specifier: workspace:*+ version: link:../media+ '@hypit/protocol':+ specifier: workspace:*+ version: link:../protocol+ optionalDependencies:'@fontsource-variable/archivo':specifier: 5.3.0version: 5.3.0@@ -1121,15 +1129,6 @@ importers:'@fontsource/zcool-xiaowei':specifier: 5.3.0version: 5.3.0- '@hypit/markup':- specifier: workspace:*- version: link:../markup- '@hypit/media':- specifier: workspace:*- version: link:../media- '@hypit/protocol':- specifier: workspace:*- version: link:../protocol'@infolektuell/noto-color-emoji':specifier: 0.2.0version: 0.2.0@@ -1582,11 +1581,11 @@ importers:packages/provider-hyperframes-aws-lambda:dependencies:'@aws-sdk/client-s3':- specifier: ^3.700.0+ specifier: 3.1103.0version: 3.1103.0'@aws-sdk/client-sfn':- specifier: ^3.700.0- version: 3.1106.0+ specifier: 3.1103.0+ version: 3.1103.0'@hyperframes/aws-lambda':specifier: 0.7.101version: 0.7.101@@ -1673,6 +1672,9 @@ importers:'@hypit/endpoint-kit':specifier: workspace:*version: link:../endpoint-kit+ '@hypit/image-opencv-runtime':+ specifier: workspace:*+ version: link:../../services/image-opencv'@hypit/protocol':specifier: workspace:*version: link:../protocol@@ -1851,6 +1853,9 @@ importers:'@hypit/protocol':specifier: workspace:*version: link:../protocol+ '@hypit/runtime-host-node':+ specifier: workspace:*+ version: link:../runtime-host-node'@hypit/runtime-kit':specifier: workspace:*version: link:../runtime-kit@@ -1860,6 +1865,9 @@ importers:'@hypit/whisperx':specifier: workspace:*version: link:../whisperx+ '@hypit/whisperx-service-runtime':+ specifier: workspace:*+ version: link:../../services/whisperxdevDependencies:'@hypit/driver-node':specifier: workspace:*@@ -2496,15 +2504,15 @@ importers:'@hypit/semantic-track':specifier: workspace:*version: link:../semantic-track- '@hypit/svs':- specifier: workspace:*- version: link:../svs'@hypit/studio-adapter':specifier: workspace:*version: link:../studio-adapter'@hypit/studio-video-adapters':specifier: workspace:*version: link:../studio-video-adapters+ '@hypit/svs':+ specifier: workspace:*+ version: link:../svs'@hypit/validation':specifier: workspace:*version: link:../validation@@ -2551,6 +2559,9 @@ importers:packages/temporal:dependencies:+ '@hypit/component-kit':+ specifier: workspace:*+ version: link:../component-kit'@hypit/narrative':specifier: workspace:*version: link:../narrative@@ -2588,7 +2599,7 @@ importers:packages/transport-aws-lambda:dependencies:'@aws-sdk/client-lambda':- specifier: ^3.1103.0+ specifier: 3.1103.0version: 3.1103.0'@hypit/protocol':specifier: workspace:*@@ -2669,6 +2680,9 @@ importers:'@hypit/credential-store-env':specifier: workspace:*version: link:../credential-store-env+ '@hypit/credential-store-os':+ specifier: workspace:*+ version: link:../credential-store-os'@hypit/driver-node':specifier: workspace:*version: link:../driver-node@@ -2693,6 +2707,9 @@ importers:'@hypit/provider-kie':specifier: workspace:*version: link:../provider-kie+ '@hypit/runtime-host-node':+ specifier: workspace:*+ version: link:../runtime-host-node'@hypit/runtime-local':specifier: workspace:*version: link:../runtime-local@@ -2764,6 +2781,8 @@ importers:specifier: workspace:*version: link:../workspace+ services/image-opencv: {}+services/media-lambda:dependencies:'@hypit/artifact-store-s3':@@ -2795,6 +2814,8 @@ importers:specifier: ^0.25.0version: 0.25.12+ services/whisperx: {}+packages:'@algolia/[email protected]':@@ -2885,8 +2906,8 @@ packages:resolution: {integrity: sha512-FO7SB2vLhZRN3lBHVhMhRm3YKSHK8e917qjB8LMEEhU69cQ0Ahd/OMyezu+KqNANqEtyxfSnFVvYt81x6ZKGZA==}engines: {node: '>=20.0.0'}- '@aws-sdk/[email protected]':- resolution: {integrity: sha512-lU6A0y5jghCTXXOFOEKTBWRRBVvarowKAXOMhvG5vmaYj3GKwlK7j16mHIyuzhInnvuQO9AntFDJT/yQFSEyIA==}+ '@aws-sdk/[email protected]':+ resolution: {integrity: sha512-QVA5lMtidoIZL2LAUs2lppS44YzGvxHw+qrdNZP33ulqtp8/ttgk8gf44Ttpzi8nlYF5lbpbsuFeuJXcbDOG/g==}engines: {node: '>=20.0.0'}'@aws-sdk/[email protected]':@@ -5517,7 +5538,7 @@ snapshots:'@smithy/types': 4.16.1tslib: 2.8.1- '@aws-sdk/[email protected]':+ '@aws-sdk/[email protected]':dependencies:'@aws-sdk/core': 3.977.6'@aws-sdk/credential-provider-node': 3.972.78@@ -5948,203 +5969,296 @@ snapshots:'@esbuild/[email protected]':optional: true- '@fontsource-variable/[email protected]': {}+ '@fontsource-variable/[email protected]':+ optional: true- '@fontsource-variable/[email protected]': {}+ '@fontsource-variable/[email protected]':+ optional: true- '@fontsource-variable/[email protected]': {}+ '@fontsource-variable/[email protected]':+ optional: true- '@fontsource-variable/[email protected]': {}+ '@fontsource-variable/[email protected]':+ optional: true- '@fontsource-variable/[email protected]': {}+ '@fontsource-variable/[email protected]':+ optional: true- '@fontsource-variable/[email protected]': {}+ '@fontsource-variable/[email protected]':+ optional: true- '@fontsource-variable/[email protected]': {}+ '@fontsource-variable/[email protected]':+ optional: true- '@fontsource-variable/[email protected]': {}+ '@fontsource-variable/[email protected]':+ optional: true- '@fontsource-variable/[email protected]': {}+ '@fontsource-variable/[email protected]':+ optional: true- '@fontsource-variable/[email protected]': {}+ '@fontsource-variable/[email protected]':+ optional: true- '@fontsource-variable/[email protected]': {}+ '@fontsource-variable/[email protected]':+ optional: true- '@fontsource-variable/[email protected]': {}+ '@fontsource-variable/[email protected]':+ optional: true- '@fontsource-variable/[email protected]': {}+ '@fontsource-variable/[email protected]':+ optional: true- '@fontsource-variable/[email protected]': {}+ '@fontsource-variable/[email protected]':+ optional: true- '@fontsource-variable/[email protected]': {}+ '@fontsource-variable/[email protected]':+ optional: true- '@fontsource-variable/[email protected]': {}+ '@fontsource-variable/[email protected]':+ optional: true- '@fontsource-variable/[email protected]': {}+ '@fontsource-variable/[email protected]':+ optional: true- '@fontsource-variable/[email protected]': {}+ '@fontsource-variable/[email protected]':+ optional: true- '@fontsource-variable/[email protected]': {}+ '@fontsource-variable/[email protected]':+ optional: true- '@fontsource-variable/[email protected]': {}+ '@fontsource-variable/[email protected]':+ optional: true- '@fontsource-variable/[email protected]': {}+ '@fontsource-variable/[email protected]':+ optional: true- '@fontsource-variable/[email protected]': {}+ '@fontsource-variable/[email protected]':+ optional: true- '@fontsource-variable/[email protected]': {}+ '@fontsource-variable/[email protected]':+ optional: true- '@fontsource-variable/[email protected]': {}+ '@fontsource-variable/[email protected]':+ optional: true- '@fontsource-variable/[email protected]': {}+ '@fontsource-variable/[email protected]':+ optional: true- '@fontsource-variable/[email protected]': {}+ '@fontsource-variable/[email protected]':+ optional: true- '@fontsource-variable/[email protected]': {}+ '@fontsource-variable/[email protected]':+ optional: true- '@fontsource-variable/[email protected]': {}+ '@fontsource-variable/[email protected]':+ optional: true- '@fontsource-variable/[email protected]': {}+ '@fontsource-variable/[email protected]':+ optional: true- '@fontsource-variable/[email protected]': {}+ '@fontsource-variable/[email protected]':+ optional: true- '@fontsource-variable/[email protected]': {}+ '@fontsource-variable/[email protected]':+ optional: true- '@fontsource-variable/[email protected]': {}+ '@fontsource-variable/[email protected]':+ optional: true- '@fontsource-variable/[email protected]': {}+ '@fontsource-variable/[email protected]':+ optional: true- '@fontsource-variable/[email protected]': {}+ '@fontsource-variable/[email protected]':+ optional: true- '@fontsource-variable/[email protected]': {}+ '@fontsource-variable/[email protected]':+ optional: true- '@fontsource-variable/[email protected]': {}+ '@fontsource-variable/[email protected]':+ optional: true- '@fontsource-variable/[email protected]': {}+ '@fontsource-variable/[email protected]':+ optional: true- '@fontsource-variable/[email protected]': {}+ '@fontsource-variable/[email protected]':+ optional: true- '@fontsource-variable/[email protected]': {}+ '@fontsource-variable/[email protected]':+ optional: true- '@fontsource-variable/[email protected]': {}+ '@fontsource-variable/[email protected]':+ optional: true- '@fontsource-variable/[email protected]': {}+ '@fontsource-variable/[email protected]':+ optional: true- '@fontsource-variable/[email protected]': {}+ '@fontsource-variable/[email protected]':+ optional: true- '@fontsource-variable/[email protected]': {}+ '@fontsource-variable/[email protected]':+ optional: true- '@fontsource-variable/[email protected]': {}+ '@fontsource-variable/[email protected]':+ optional: true- '@fontsource-variable/[email protected]': {}+ '@fontsource-variable/[email protected]':+ optional: true- '@fontsource-variable/[email protected]': {}+ '@fontsource-variable/[email protected]':+ optional: true- '@fontsource-variable/[email protected]': {}+ '@fontsource-variable/[email protected]':+ optional: true- '@fontsource-variable/[email protected]': {}+ '@fontsource-variable/[email protected]':+ optional: true- '@fontsource-variable/[email protected]': {}+ '@fontsource-variable/[email protected]':+ optional: true- '@fontsource-variable/[email protected]': {}+ '@fontsource-variable/[email protected]':+ optional: true- '@fontsource-variable/[email protected]': {}+ '@fontsource-variable/[email protected]':+ optional: true- '@fontsource-variable/[email protected]': {}+ '@fontsource-variable/[email protected]':+ optional: true- '@fontsource-variable/[email protected]': {}+ '@fontsource-variable/[email protected]':+ optional: true- '@fontsource-variable/[email protected]': {}+ '@fontsource-variable/[email protected]':+ optional: true- '@fontsource-variable/[email protected]': {}+ '@fontsource-variable/[email protected]':+ optional: true- '@fontsource-variable/[email protected]': {}+ '@fontsource-variable/[email protected]':+ optional: true- '@fontsource-variable/[email protected]': {}+ '@fontsource-variable/[email protected]':+ optional: true- '@fontsource-variable/[email protected]': {}+ '@fontsource-variable/[email protected]':+ optional: true- '@fontsource-variable/[email protected]': {}+ '@fontsource-variable/[email protected]':+ optional: true- '@fontsource-variable/[email protected]': {}+ '@fontsource-variable/[email protected]':+ optional: true- '@fontsource-variable/[email protected]': {}+ '@fontsource-variable/[email protected]':+ optional: true- '@fontsource-variable/[email protected]': {}+ '@fontsource-variable/[email protected]':+ optional: true- '@fontsource-variable/[email protected]': {}+ '@fontsource-variable/[email protected]':+ optional: true- '@fontsource-variable/[email protected]': {}+ '@fontsource-variable/[email protected]':+ optional: true- '@fontsource-variable/[email protected]': {}+ '@fontsource-variable/[email protected]':+ optional: true- '@fontsource-variable/[email protected]': {}+ '@fontsource-variable/[email protected]':+ optional: true- '@fontsource-variable/[email protected]': {}+ '@fontsource-variable/[email protected]':+ optional: true- '@fontsource-variable/[email protected]': {}+ '@fontsource-variable/[email protected]':+ optional: true- '@fontsource-variable/[email protected]': {}+ '@fontsource-variable/[email protected]':+ optional: true- '@fontsource/[email protected]': {}+ '@fontsource/[email protected]':+ optional: true- '@fontsource/[email protected]': {}+ '@fontsource/[email protected]':+ optional: true- '@fontsource/[email protected]': {}+ '@fontsource/[email protected]':+ optional: true- '@fontsource/[email protected]': {}+ '@fontsource/[email protected]':+ optional: true'@fontsource/[email protected]': {}- '@fontsource/[email protected]': {}+ '@fontsource/[email protected]':+ optional: true- '@fontsource/[email protected]': {}+ '@fontsource/[email protected]':+ optional: true- '@fontsource/[email protected]': {}+ '@fontsource/[email protected]':+ optional: true- '@fontsource/[email protected]': {}+ '@fontsource/[email protected]':+ optional: true- '@fontsource/[email protected]': {}+ '@fontsource/[email protected]':+ optional: true- '@fontsource/[email protected]': {}+ '@fontsource/[email protected]':+ optional: true- '@fontsource/[email protected]': {}+ '@fontsource/[email protected]':+ optional: true- '@fontsource/[email protected]': {}+ '@fontsource/[email protected]':+ optional: true'@fontsource/[email protected]': {}- '@fontsource/[email protected]': {}+ '@fontsource/[email protected]':+ optional: true- '@fontsource/[email protected]': {}+ '@fontsource/[email protected]':+ optional: true- '@fontsource/[email protected]': {}+ '@fontsource/[email protected]':+ optional: true'@fontsource/[email protected]': {}- '@fontsource/[email protected]': {}+ '@fontsource/[email protected]':+ optional: true'@fontsource/[email protected]': {}'@fontsource/[email protected]': {}- '@fontsource/[email protected]': {}+ '@fontsource/[email protected]':+ optional: true- '@fontsource/[email protected]': {}+ '@fontsource/[email protected]':+ optional: true- '@fontsource/[email protected]': {}+ '@fontsource/[email protected]':+ optional: true'@fontsource/[email protected]': {}- '@fontsource/[email protected]': {}+ '@fontsource/[email protected]':+ optional: true- '@fontsource/[email protected]': {}+ '@fontsource/[email protected]':+ optional: true- '@fontsource/[email protected]': {}+ '@fontsource/[email protected]':+ optional: true- '@fontsource/[email protected]': {}+ '@fontsource/[email protected]':+ optional: true- '@fontsource/[email protected]': {}+ '@fontsource/[email protected]':+ optional: true'@fontsource/[email protected]': {}@@ -6154,31 +6268,43 @@ snapshots:'@fontsource/[email protected]': {}- '@fontsource/[email protected]': {}+ '@fontsource/[email protected]':+ optional: true- '@fontsource/[email protected]': {}+ '@fontsource/[email protected]':+ optional: true- '@fontsource/[email protected]': {}+ '@fontsource/[email protected]':+ optional: true- '@fontsource/[email protected]': {}+ '@fontsource/[email protected]':+ optional: true- '@fontsource/[email protected]': {}+ '@fontsource/[email protected]':+ optional: true- '@fontsource/[email protected]': {}+ '@fontsource/[email protected]':+ optional: true- '@fontsource/[email protected]': {}+ '@fontsource/[email protected]':+ optional: true- '@fontsource/[email protected]': {}+ '@fontsource/[email protected]':+ optional: true- '@fontsource/[email protected]': {}+ '@fontsource/[email protected]':+ optional: true'@fontsource/[email protected]': {}- '@fontsource/[email protected]': {}+ '@fontsource/[email protected]':+ optional: true- '@fontsource/[email protected]': {}+ '@fontsource/[email protected]':+ optional: true- '@fontsource/[email protected]': {}+ '@fontsource/[email protected]':+ optional: true'@google/[email protected]':dependencies:@@ -6198,7 +6324,7 @@ snapshots:'@hyperframes/[email protected]':dependencies:'@aws-sdk/client-s3': 3.1103.0- '@aws-sdk/client-sfn': 3.1106.0+ '@aws-sdk/client-sfn': 3.1103.0'@hyperframes/producer': 0.7.101'@sparticuz/chromium': 148.0.0ffmpeg-static: 5.3.0@@ -6422,7 +6548,8 @@ snapshots:'@img/[email protected]':optional: true- '@infolektuell/[email protected]': {}+ '@infolektuell/[email protected]':+ optional: true'@isaacs/[email protected]':dependencies:diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yamlindex 54b93174..79003176 100644--- a/pnpm-workspace.yaml+++ b/pnpm-workspace.yaml@@ -1,6 +1,6 @@packages:- packages/*- - services/media-lambda+ - services/*# Shipped examples are repository fixtures. Real authored projects always live outside this# tool checkout and resolve their own project-local packages through the Host's project root.- examples/*/packages/*diff --git a/services/image-opencv/README.md b/services/image-opencv/README.mdindex c1506592..3c8571f6 100644--- a/services/image-opencv/README.md+++ b/services/image-opencv/README.md@@ -3,7 +3,9 @@This is the locked Python environment used by `@hypit/provider-image-opencv-local`. It is deploymentstate, not an author-importable SVML package, a queue, a service daemon or part of Core.-Install it once:+For an ordinary installed Distribution, select the Provider and let `hypit runtime up` create and+reuse this environment in the machine Program Home. The commands below are only for a contributor+or operator deliberately managing a custom interpreter:```bashuv python install 3.13diff --git a/services/image-opencv/package.json b/services/image-opencv/package.jsonnew file mode 100644index 00000000..49feda65--- /dev/null+++ b/services/image-opencv/package.json@@ -0,0 +1,14 @@+{+ "name": "@hypit/image-opencv-runtime",+ "version": "0.1.0",+ "license": "SEE LICENSE IN LICENSE",+ "type": "module",+ "exports": {+ "./pyproject.toml": "./pyproject.toml"+ },+ "files": [+ "pyproject.toml",+ "uv.lock",+ "README.md"+ ]+}diff --git a/services/whisperx/README.md b/services/whisperx/README.mdindex db6bd733..05e35364 100644--- a/services/whisperx/README.md+++ b/services/whisperx/README.md@@ -18,6 +18,11 @@ semantic projection combines this evidence with one explicit Script Segment late## Install+For an ordinary installed Distribution, select the local WhisperX Endpoint and run+`hypit runtime up`. The Runtime creates this environment in the machine Program Home only when it is+missing, and reuses it across projects and sessions. The commands below are contributor/operator+diagnostics for a deliberately managed deployment:+WhisperX 3.8.6 supports Python 3.10 through 3.13. The checked-in lock selects Python 3.13:```bash@@ -29,8 +34,8 @@ uv run --project services/whisperx --frozen hypit-whisperx-checkThe first model start may download ASR and alignment weights. Production should put the relevantHugging Face cache on persistent storage. `hypit-whisperx-prepare` separately installs NLTK's-`punkt_tab` sentence data from a commit-pinned official archive after verifying its SHA-256. This-resource is required by WhisperX alignment and is never downloaded inside an inference request.+`punkt_tab` sentence data through NLTK's own downloader. This resource is required by WhisperX+alignment and is prepared explicitly before the warm service starts, never inside an inference request.## Rundiff --git a/services/whisperx/package.json b/services/whisperx/package.jsonnew file mode 100644index 00000000..978ba097--- /dev/null+++ b/services/whisperx/package.json@@ -0,0 +1,15 @@+{+ "name": "@hypit/whisperx-service-runtime",+ "version": "0.1.0",+ "license": "SEE LICENSE IN LICENSE",+ "type": "module",+ "exports": {+ "./pyproject.toml": "./pyproject.toml"+ },+ "files": [+ "pyproject.toml",+ "uv.lock",+ "src/**/*.py",+ "README.md"+ ]+}diff --git a/services/whisperx/src/hypit_whisperx_service/check.py b/services/whisperx/src/hypit_whisperx_service/check.pyindex af43f989..8064fdef 100644--- a/services/whisperx/src/hypit_whisperx_service/check.py+++ b/services/whisperx/src/hypit_whisperx_service/check.py@@ -6,7 +6,7 @@ import sysfrom . import PROTOCOL, SERVICE_VERSIONfrom .config import ServiceConfig-from .resources import PUNKT_TAB_SHA256, assert_punkt_tab+from .resources import assert_punkt_tabdef main() -> None:@@ -32,5 +32,4 @@ def main() -> None:"serviceVersion": SERVICE_VERSION,"python": sys.version.split()[0],"packages": versions,- "punktTabDigest": PUNKT_TAB_SHA256,}, sort_keys=True))diff --git a/services/whisperx/src/hypit_whisperx_service/engine.py b/services/whisperx/src/hypit_whisperx_service/engine.pyindex 2530f3d2..10fc6f73 100644--- a/services/whisperx/src/hypit_whisperx_service/engine.py+++ b/services/whisperx/src/hypit_whisperx_service/engine.py@@ -8,7 +8,7 @@ from typing import Any, Mappingfrom .audio import CanonicalAudiofrom .config import ServiceConfig-from .resources import PUNKT_TAB_SHA256, assert_punkt_tab+from .resources import assert_punkt_tabclass InferenceInputError(ValueError):@@ -118,7 +118,6 @@ class WhisperXEngine:"compute": self._config.compute,"batchSize": self._config.batch_size,"whisperxVersion": self._whisperx_version,- "punktTabDigest": PUNKT_TAB_SHA256,}def _alignment_model(self, language: str) -> tuple[object, object]:diff --git a/services/whisperx/src/hypit_whisperx_service/prepare.py b/services/whisperx/src/hypit_whisperx_service/prepare.pyindex 953d0b97..e32f07ee 100644--- a/services/whisperx/src/hypit_whisperx_service/prepare.py+++ b/services/whisperx/src/hypit_whisperx_service/prepare.py@@ -7,7 +7,7 @@ from .resources import default_nltk_data_root, prepare_punkt_tabdef main() -> None:- parser = argparse.ArgumentParser(description="Install locked non-wheel data for SVML WhisperX")+ parser = argparse.ArgumentParser(description="Install NLTK data required by Hypit WhisperX")parser.add_argument("--nltk-data",type=Path,diff --git a/services/whisperx/src/hypit_whisperx_service/resources.py b/services/whisperx/src/hypit_whisperx_service/resources.pyindex b294ab6d..fb8f6310 100644--- a/services/whisperx/src/hypit_whisperx_service/resources.py+++ b/services/whisperx/src/hypit_whisperx_service/resources.py@@ -1,103 +1,32 @@from __future__ import annotations-import hashlib-import io-import json-import os-from pathlib import Path, PurePosixPath-import tempfile-from urllib.request import urlopen-import zipfile---PUNKT_TAB_COMMIT = "550b6625bcef1f2abff2ff770a5a0d272c9c6b2a"-PUNKT_TAB_SHA256 = "e57f64187974277726a3417ca6f181ec5403676c717672eef6a748a7b20e0106"-PUNKT_TAB_URL = (- "https://raw.githubusercontent.com/nltk/nltk_data/"- f"{PUNKT_TAB_COMMIT}/packages/tokenizers/punkt_tab.zip"-)-MAX_ARCHIVE_BYTES = 32 * 1024 * 1024-MARKER_NAME = ".hypit-resource.json"+from pathlib import Pathdef default_nltk_data_root() -> Path:return Path.home() / ".cache" / "hypit" / "whisperx" / "nltk_data"-def _marker(root: Path) -> Path:- return root / "tokenizers" / "punkt_tab" / MARKER_NAME--def assert_punkt_tab(root: Path) -> None:- marker = _marker(root)+ import nltk++ location = str(root.expanduser().resolve())+ if location not in nltk.data.path:+ nltk.data.path.insert(0, location)try:- value = json.loads(marker.read_text(encoding="utf-8"))- except (OSError, json.JSONDecodeError) as error:+ nltk.data.find("tokenizers/punkt_tab", paths=[location])+ except LookupError as error:raise RuntimeError(- "locked NLTK punkt_tab data is unavailable; run `hypit-whisperx-prepare`"+ "NLTK punkt_tab data is unavailable; run `hypit-whisperx-prepare`") from error- if value != {"commit": PUNKT_TAB_COMMIT, "sha256": PUNKT_TAB_SHA256}:- raise RuntimeError("installed NLTK punkt_tab identity differs from the service lock")- english = marker.parent / "english"- for name in ("abbrev_types.txt", "collocations.tab", "ortho_context.tab", "sent_starters.txt"):- if not (english / name).is_file():- raise RuntimeError(f"installed NLTK punkt_tab is incomplete: english/{name}")--def _download() -> bytes:- with urlopen(PUNKT_TAB_URL, timeout=60) as response: # noqa: S310 - immutable HTTPS URL above- declared = response.headers.get("Content-Length")- if declared is not None and int(declared) > MAX_ARCHIVE_BYTES:- raise RuntimeError("punkt_tab archive exceeds its configured bound")- payload = response.read(MAX_ARCHIVE_BYTES + 1)- if len(payload) > MAX_ARCHIVE_BYTES:- raise RuntimeError("punkt_tab archive exceeds its configured bound")- return payload+def prepare_punkt_tab(root: Path) -> Path:+ import nltk-def _extract(payload: bytes, destination: Path) -> None:- with zipfile.ZipFile(io.BytesIO(payload)) as archive:- for item in archive.infolist():- relative = PurePosixPath(item.filename)- if relative.is_absolute() or ".." in relative.parts or not relative.parts or relative.parts[0] != "punkt_tab":- raise RuntimeError("punkt_tab archive contains an unsafe path")- # Unix symlinks are not valid model data.- if ((item.external_attr >> 16) & 0o170000) == 0o120000:- raise RuntimeError("punkt_tab archive contains a symbolic link")- target = destination.joinpath(*relative.parts)- if item.is_dir():- target.mkdir(parents=True, exist_ok=True)- continue- target.parent.mkdir(parents=True, exist_ok=True)- target.write_bytes(archive.read(item))---def prepare_punkt_tab(root: Path, payload: bytes | None = None) -> Path:root = root.expanduser().resolve()- try:- assert_punkt_tab(root)- return _marker(root).parent- except RuntimeError:- pass- target = root / "tokenizers" / "punkt_tab"- if target.exists():- raise RuntimeError(- f"refusing to replace unverified NLTK data at {target}; remove or relocate it explicitly"- )- archive = _download() if payload is None else payload- digest = hashlib.sha256(archive).hexdigest()- if digest != PUNKT_TAB_SHA256:- raise RuntimeError(f"punkt_tab archive digest mismatch: expected {PUNKT_TAB_SHA256}, got {digest}")-- target.parent.mkdir(parents=True, exist_ok=True)- with tempfile.TemporaryDirectory(prefix="hypit-punkt-tab-", dir=target.parent) as temporary:- staging = Path(temporary)- _extract(archive, staging)- extracted = staging / "punkt_tab"- (extracted / MARKER_NAME).write_text(- json.dumps({"commit": PUNKT_TAB_COMMIT, "sha256": PUNKT_TAB_SHA256}, sort_keys=True),- encoding="utf-8",- )- os.replace(extracted, target)+ root.mkdir(parents=True, exist_ok=True)+ if not nltk.download("punkt_tab", download_dir=str(root), quiet=False, raise_on_error=True):+ raise RuntimeError("NLTK could not install punkt_tab")assert_punkt_tab(root)- return target+ return root / "tokenizers" / "punkt_tab"diff --git a/test/repository-hygiene.test.mjs b/test/repository-hygiene.test.mjsindex a741eabb..fedb8f09 100644--- a/test/repository-hygiene.test.mjs+++ b/test/repository-hygiene.test.mjs@@ -9,7 +9,7 @@ const repositoryRoot = new URL("../", import.meta.url);const repositoryRootPath = fileURLToPath(repositoryRoot);const scanRoots = ["docs", "examples", "packages", "services", "test"];const rootTextFiles = ["README.md", "package.json", "pnpm-workspace.yaml", "tsconfig.json"];-const ignoredDirectories = new Set(["node_modules", "dist", "output", ".hypit", ".svml", ".vitepress"]);+const ignoredDirectories = new Set(["node_modules", "build", "dist", "output", ".hypit", ".svml", ".vitepress"]);const textExtensions = new Set([".css", ".html", ".js", ".json", ".jsx", ".md", ".mjs", ".sh", ".svml", ".svrun",".svs", ".ts", ".tsx", ".txt", ".yaml", ".yml",