Skip to content

armgit / hypit

Public Imported from GitHub
0

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.

refactor(runtime): make local profile explicit

kashorina8d6c488494e
diff --git a/docs/guide/runtime.md b/docs/guide/runtime.md
index c2a033c2..5ef88206 100644
--- a/docs/guide/runtime.md
+++ b/docs/guide/runtime.md
@@ -5,7 +5,7 @@ description: The execution boundary outside Hypit source and Core.
# Runtime
-Hypit keeps three decisions separate:
+Hypit keeps four decisions separate:
| Owner | Decides |
|---|---|
@@ -28,18 +28,13 @@ The Profile contains only environmental choices that genuinely vary:
```json
{
- "format": "hypit.runtime-profile@1",
- "runtime": {
- "use": "@hypit/runtime-local",
- "config": {
- "dataRoot": ".hypit/runtimes/local",
- "credentials": {
- "env": { "use": "@hypit/credential-store-env" }
- },
- "endpoints": {
- "media": { "use": "@hypit/provider-media-local" }
- }
- }
+ "format": "hypit.runtime-local@1",
+ "dataRoot": ".hypit/runtimes/local",
+ "credentials": {
+ "env": { "use": "@hypit/credential-store-env" }
+ },
+ "endpoints": {
+ "media": { "use": "@hypit/provider-media-local" }
}
}
```
@@ -47,6 +42,11 @@ The Profile contains only environmental choices that genuinely vary:
* `credentials` selects stores for explicit credential references.
* `endpoints` selects exact Provider implementations and their configuration.
+The official video Distribution selects the local Runtime before opening this file. The Profile
+does not repeat a `runtime.use` selector that cannot make another choice. Another application may
+provide a different Runtime Host at its Distribution assembly boundary without changing Core or
+the generic CLI.
+
Result storage belongs to the project, not the execution environment. A project may select it in
`hypit.results.json`; omitting the file uses the same filesystem default:
diff --git a/docs/quickstart.md b/docs/quickstart.md
index 78e09020..d2f175ba 100644
--- a/docs/quickstart.md
+++ b/docs/quickstart.md
@@ -115,7 +115,7 @@ project. By default, Build Results live under the project's `.hypit/results`; a
`hypit.results.json` may point the same complete Result model at S3. Active execution state always lives under the selected Profile's
`dataRoot`.
`runtime use` stores only a local pointer at `.hypit/runtime`. Source imports select author
-packages; the Profile independently selects Runtime packages through `use`.
+packages; the Profile independently selects Credential Stores and Endpoints through their own `use` entries.
Start from [`examples/talking-film-live`](https://github.com/hypit-ai/hypit/tree/main/examples/talking-film-live) when you need a
complete Runtime Profile. Copy the source structure, then replace its assets, Script, model choices
diff --git a/docs/zh/guide/runtime.md b/docs/zh/guide/runtime.md
index de6ef350..838fde2d 100644
--- a/docs/zh/guide/runtime.md
+++ b/docs/zh/guide/runtime.md
@@ -8,7 +8,7 @@ description: Hypit Source 与 Core 之外的执行边界。
实现审计与仍待处理的问题记录在
[Runtime 与 Build Result 实现审计](./runtime-build-result-audit.md)。
-Hypit 把三个决定分开:
+Hypit 把四个决定分开:
| 所有者 | 决定什么 |
|---|---|
@@ -29,22 +29,21 @@ Profile 只保留真正会随环境变化的选择:
```json
{
- "format": "hypit.runtime-profile@1",
- "runtime": {
- "use": "@hypit/runtime-local",
- "config": {
- "dataRoot": ".hypit/runtimes/local",
- "credentials": {
- "env": { "use": "@hypit/credential-store-env" }
- },
- "endpoints": {
- "media": { "use": "@hypit/provider-media-local" }
- }
- }
+ "format": "hypit.runtime-local@1",
+ "dataRoot": ".hypit/runtimes/local",
+ "credentials": {
+ "env": { "use": "@hypit/credential-store-env" }
+ },
+ "endpoints": {
+ "media": { "use": "@hypit/provider-media-local" }
}
}
```
+官方视频 Distribution 在打开文件前已经明确选择 Local Runtime,因此 Profile 不再重复一个无法产生第二种
+选择的 `runtime.use`。另一种应用若确实拥有不同 Runtime Host,应在自己的 Distribution 组装边界提供它;
+Core 与通用 CLI 都不需要知道具体实现,也不预建没有第二个实现验证过的 Host 插件注册表。
+
`credentials` 选择凭证存储,`endpoints` 选择明确的 Provider 实现。Result 仓库不属于执行环境,
因此不能放进 Runtime Profile。
diff --git a/docs/zh/quickstart.md b/docs/zh/quickstart.md
index df074e51..bbe84ab2 100644
--- a/docs/zh/quickstart.md
+++ b/docs/zh/quickstart.md
@@ -110,7 +110,7 @@ hypit plan build.svrun
Distribution 里的官方包。默认情况下,完整 Build Result 位于项目的 `.hypit/results`;Profile
不管理 Result,项目根的 `hypit.results.json` 可以把同一套 Result 模型指向 S3。Runtime 活跃状态与临时 Artifact 始终位于所选 Profile 的
`dataRoot`。`runtime use` 只在 `.hypit/runtime` 保存一个本地指针。Source import 选择作者包,
-Profile 则通过 `use` 独立选择 Runtime 包。
+Profile 则通过 Credential Store 与 Endpoint 各自的 `use` 独立选择环境包。
需要完整 Runtime Profile 时,从
[`examples/talking-film-live`](https://github.com/hypit-ai/hypit/tree/main/examples/talking-film-live) 的结构开始:复制文件结构,
diff --git a/packages/runtime-host-node/README.md b/packages/runtime-host-node/README.md
index 3d0dea64..30ed9431 100644
--- a/packages/runtime-host-node/README.md
+++ b/packages/runtime-host-node/README.md
@@ -14,4 +14,6 @@ read secret values, execute commands or choose fallback Providers.
The generic CLI depends only on this port. The official video application selects
`@hypit/runtime-local` directly; Runtime Profiles vary credentials, Endpoints and their services
-rather than replacing the Runtime itself or selecting Build history storage.
+rather than replacing the Runtime itself or selecting Build history storage. A second application
+may supply another `NodeRuntimeHost` at its Distribution assembly boundary; no unused Host plugin
+registry or selector is exposed in a local Profile.
diff --git a/packages/runtime-local/README.md b/packages/runtime-local/README.md
index 8011d48e..f19d796e 100644
--- a/packages/runtime-local/README.md
+++ b/packages/runtime-local/README.md
@@ -7,20 +7,18 @@ A Runtime Profile selects only the environmental parts that genuinely vary:
```json
{
- "format": "hypit.runtime-profile@1",
- "runtime": {
- "use": "@hypit/runtime-local",
- "config": {
- "dataRoot": ".hypit/runtimes/local",
- "credentials": {
- "env": { "use": "@hypit/credential-store-env" }
- },
- "endpoints": {}
- }
- }
+ "format": "hypit.runtime-local@1",
+ "dataRoot": ".hypit/runtimes/local",
+ "credentials": {
+ "env": { "use": "@hypit/credential-store-env" }
+ },
+ "endpoints": {}
}
```
+The official video Distribution selects this Runtime implementation before it opens the file. The
+Profile therefore describes only local execution and does not repeat a fake Runtime Host selector.
+
A project that wants a non-default Result repository owns a separate `hypit.results.json`:
```json
diff --git a/packages/runtime-local/src/config.ts b/packages/runtime-local/src/config.ts
index c517817e..dfa0d03c 100644
--- a/packages/runtime-local/src/config.ts
+++ b/packages/runtime-local/src/config.ts
@@ -60,18 +60,18 @@ import type {
LocalRuntimeControl,
} from "./types.js";
-export type RuntimeConfigEntry = {
+export type LocalRuntimeAdapterSelection = {
readonly use: string;
readonly instance: string;
readonly pool?: string;
readonly config?: CanonicalValue;
};
-export type RuntimeConfigDocument = {
- readonly format: "hypit.runtime-profile@1";
+export type LocalRuntimeProfile = {
+ readonly format: "hypit.runtime-local@1";
readonly dataRoot: string;
- readonly credentials: readonly RuntimeConfigEntry[];
- readonly endpoints: readonly RuntimeConfigEntry[];
+ readonly credentials: readonly LocalRuntimeAdapterSelection[];
+ readonly endpoints: readonly LocalRuntimeAdapterSelection[];
};
export type ProjectBuildResultConfig = {
@@ -113,7 +113,7 @@ export type ResolvedRuntimeConfigPaths = {
type OpenedRuntimeConfig = {
readonly absolute: string;
- readonly document: RuntimeConfigDocument;
+ readonly document: LocalRuntimeProfile;
readonly root: string;
readonly profileRoot: string;
readonly packageRoot: string;
@@ -139,7 +139,7 @@ function requiredString(value: unknown, subject: string): string {
return value;
}
-function entry(value: unknown, instance: string, subject: string, poolAllowed = false): RuntimeConfigEntry {
+function entry(value: unknown, instance: string, subject: string, poolAllowed = false): LocalRuntimeAdapterSelection {
const item = object(value, subject);
exactKeys(item, poolAllowed ? ["use", "pool", "config"] : ["use", "config"], subject);
const pool = item.pool === undefined ? undefined : requiredString(item.pool, `${subject}.pool`);
@@ -151,7 +151,7 @@ function entry(value: unknown, instance: string, subject: string, poolAllowed =
};
}
-function entries(value: unknown, subject: string, poolAllowed = false): readonly RuntimeConfigEntry[] {
+function entries(value: unknown, subject: string, poolAllowed = false): readonly LocalRuntimeAdapterSelection[] {
const values = object(value ?? {}, subject);
return Object.entries(values).sort(([left], [right]) => left.localeCompare(right)).map(([instance, item]) => {
requiredString(instance, `${subject} instance`);
@@ -159,26 +159,19 @@ function entries(value: unknown, subject: string, poolAllowed = false): readonly
});
}
-export function parseRuntimeConfig(value: unknown): RuntimeConfigDocument {
+export function parseLocalRuntimeProfile(value: unknown): LocalRuntimeProfile {
const item = object(value, "$runtime");
- exactKeys(item, ["format", "runtime"], "$runtime");
- if (item.format !== "hypit.runtime-profile@1") {
- throw new Error("$runtime.format must be hypit.runtime-profile@1");
+ exactKeys(item, ["format", "dataRoot", "credentials", "endpoints"], "$runtime");
+ if (item.format !== "hypit.runtime-local@1") {
+ throw new Error("$runtime.format must be hypit.runtime-local@1");
}
- const runtime = object(item.runtime, "$runtime.runtime");
- exactKeys(runtime, ["use", "config"], "$runtime.runtime");
- if (runtime.use !== "@hypit/runtime-local") {
- throw new Error(`Local Runtime loader cannot activate ${String(runtime.use)}`);
- }
- const config = object(runtime.config, "$runtime.runtime.config");
- exactKeys(config, ["dataRoot", "credentials", "endpoints"], "$runtime.runtime.config");
- const credentials = entries(config.credentials, "$runtime.runtime.config.credentials");
- const endpoints = entries(config.endpoints, "$runtime.runtime.config.endpoints", true);
+ const credentials = entries(item.credentials, "$runtime.credentials");
+ const endpoints = entries(item.endpoints, "$runtime.endpoints", true);
const ids = [...credentials, ...endpoints].map((value) => value.instance);
if (new Set(ids).size !== ids.length) throw new Error("$runtime repeats a Runtime instance id");
return {
- format: "hypit.runtime-profile@1",
- dataRoot: requiredString(config.dataRoot, "$runtime.runtime.config.dataRoot"),
+ format: "hypit.runtime-local@1",
+ dataRoot: requiredString(item.dataRoot, "$runtime.dataRoot"),
credentials,
endpoints,
};
@@ -186,7 +179,7 @@ export function parseRuntimeConfig(value: unknown): RuntimeConfigDocument {
async function openRuntimeConfig(path: string, packageRootHint?: string): Promise<OpenedRuntimeConfig> {
const absolute = resolve(path);
- const document = parseRuntimeConfig(JSON.parse(await readFile(absolute, "utf8")));
+ const document = parseLocalRuntimeProfile(JSON.parse(await readFile(absolute, "utf8")));
const profileRoot = dirname(absolute);
return {
absolute,
@@ -197,7 +190,7 @@ async function openRuntimeConfig(path: string, packageRootHint?: string): Promis
};
}
-function runtimePackageSelection(document: RuntimeConfigDocument): NodePackageSelectionRequest {
+function runtimePackageSelection(document: LocalRuntimeProfile): NodePackageSelectionRequest {
return {
selected: [],
logical: [
@@ -214,7 +207,7 @@ function resultPackageSelection(use: string): NodePackageSelectionRequest {
};
}
-function endpointPackageSelection(document: RuntimeConfigDocument): NodePackageSelectionRequest {
+function endpointPackageSelection(document: LocalRuntimeProfile): NodePackageSelectionRequest {
return {
selected: [],
logical: document.endpoints.map((item) => ({ abi: runtimeEndpointAdapterHostAbi, name: item.use })),
@@ -392,7 +385,7 @@ function capabilityKey(capability: CapabilityRef): string {
function adapterContext(
root: string,
hostStateRoot: string,
- item: RuntimeConfigEntry,
+ item: LocalRuntimeAdapterSelection,
): RuntimeAdapterFactoryContext {
return {
hostStateRoot,
@@ -404,11 +397,11 @@ function adapterContext(
}
async function activatedEndpoints(
- document: RuntimeConfigDocument,
+ document: LocalRuntimeProfile,
root: string,
hostStateRoot: string,
registry: RuntimeAdapterRegistry,
-): Promise<readonly { readonly entry: RuntimeConfigEntry; readonly activation: RuntimeEndpointActivation }[]> {
+): Promise<readonly { readonly entry: LocalRuntimeAdapterSelection; readonly activation: RuntimeEndpointActivation }[]> {
return await Promise.all(document.endpoints.map(async (item) => ({
entry: item,
activation: await registry.activateEndpoint(item.use, adapterContext(root, hostStateRoot, {
@@ -448,7 +441,7 @@ function diagnostic(error: unknown, code: string, subject?: string): RuntimeDoct
}
async function openCredentialStores(
- document: RuntimeConfigDocument,
+ document: LocalRuntimeProfile,
root: string,
hostStateRoot: string,
registry: RuntimeAdapterRegistry,
diff --git a/packages/runtime-local/src/index.ts b/packages/runtime-local/src/index.ts
index b5c55eec..b7256ea2 100644
--- a/packages/runtime-local/src/index.ts
+++ b/packages/runtime-local/src/index.ts
@@ -19,7 +19,7 @@ export {
doctorRuntimeConfig,
prepareRuntimeConfigPackages,
preflightRuntimeConfig,
- parseRuntimeConfig,
+ parseLocalRuntimeProfile,
resolveRuntimeConfigPaths,
} from "./config.js";
export {
diff --git a/packages/runtime-local/test/config.test.ts b/packages/runtime-local/test/config.test.ts
index 009ccaf1..2ad823b2 100644
--- a/packages/runtime-local/test/config.test.ts
+++ b/packages/runtime-local/test/config.test.ts
@@ -22,7 +22,7 @@ import {
doctorProjectBuildResultRepository,
doctorRuntimeConfig,
openProjectBuildResultRepository,
- parseRuntimeConfig,
+ parseLocalRuntimeProfile,
preflightRuntimeConfig,
} from "@hypit/runtime-local";
function profile(config: {
@@ -31,20 +31,15 @@ function profile(config: {
readonly endpoints?: Readonly<Record<string, unknown>>;
} = {}) {
return {
- format: "hypit.runtime-profile@1",
- runtime: {
- use: "@hypit/runtime-local",
- config: {
- dataRoot: config.dataRoot ?? ".hypit/runtimes/local",
- credentials: config.credentials ?? {},
- endpoints: config.endpoints ?? {},
- },
- },
+ format: "hypit.runtime-local@1",
+ dataRoot: config.dataRoot ?? ".hypit/runtimes/local",
+ credentials: config.credentials ?? {},
+ endpoints: config.endpoints ?? {},
};
}
-test("Runtime Profile names credentials and Endpoints, not project result storage", () => {
- const parsed = parseRuntimeConfig(profile({
+test("Local Runtime Profile names credentials and Endpoints, not project result storage", () => {
+ const parsed = parseLocalRuntimeProfile(profile({
credentials: { secrets: { use: "example.credentials" } },
endpoints: { generation: { use: "example.provider", pool: "shared" } },
}));
@@ -125,8 +120,8 @@ test("Build Result repositories default to the project path and can be selected
}
});
-test("Runtime Profile rejects source ownership fields", () => {
- assert.throws(() => parseRuntimeConfig({ ...profile(), root: "." }), /does not accept root/u);
+test("Local Runtime Profile rejects source ownership fields", () => {
+ assert.throws(() => parseLocalRuntimeProfile({ ...profile(), root: "." }), /does not accept root/u);
});
test("active Build inspection requires no selected ResourceStore", async () => {
diff --git a/packages/runtime-local/test/programs.test.ts b/packages/runtime-local/test/programs.test.ts
index 0dcab14a..9db9f55c 100644
--- a/packages/runtime-local/test/programs.test.ts
+++ b/packages/runtime-local/test/programs.test.ts
@@ -46,17 +46,12 @@ async function project(program: (root: string) => ManagedProgram) {
const root = await mkdtemp(join(tmpdir(), "hypit-programs-"));
const path = join(root, "hypit.runtime.json");
await writeFile(path, JSON.stringify({
- format: "hypit.runtime-profile@1",
- runtime: {
- use: "@hypit/runtime-local",
- config: {
- dataRoot: ".",
- credentials: {},
- endpoints: {
- one: { use: "example.program", pool: "example.local", config: {} },
- two: { use: "example.program", pool: "example.local", config: {} },
- },
- },
+ format: "hypit.runtime-local@1",
+ dataRoot: ".",
+ credentials: {},
+ endpoints: {
+ one: { use: "example.program", pool: "example.local", config: {} },
+ two: { use: "example.program", pool: "example.local", config: {} },
},
}));
const registry = new RuntimeAdapterRegistry();
@@ -225,15 +220,10 @@ test("up creates a fresh Runtime data directory before running commands", async
const dataRoot = join(projectRoot, "never-created");
const path = join(projectRoot, "hypit.runtime.json");
await writeFile(path, JSON.stringify({
- format: "hypit.runtime-profile@1",
- runtime: {
- use: "@hypit/runtime-local",
- config: {
- dataRoot: "./never-created",
- credentials: {},
- endpoints: { one: { use: "example.program", config: {} } },
- },
- },
+ format: "hypit.runtime-local@1",
+ dataRoot: "./never-created",
+ credentials: {},
+ endpoints: { one: { use: "example.program", config: {} } },
}));
const registry = new RuntimeAdapterRegistry();
const probe = async () => {
diff --git a/packages/runtime-local/test/worker-process.test.ts b/packages/runtime-local/test/worker-process.test.ts
index ed5285a3..d87a92b6 100644
--- a/packages/runtime-local/test/worker-process.test.ts
+++ b/packages/runtime-local/test/worker-process.test.ts
@@ -15,7 +15,7 @@ test("one detached Runtime Worker can be started, observed and stopped", async (
const root = await mkdtemp(join(tmpdir(), "hypit-runtime-process-"));
const profile = join(root, "runtime.json");
const dataRoot = join(root, ".hypit", "runtimes", "local");
- await writeFile(profile, JSON.stringify({ format: "hypit.runtime-profile@1" }), "utf8");
+ await writeFile(profile, JSON.stringify({ format: "hypit.runtime-local@1" }), "utf8");
await mkdir(join(root, ".hypit"), { recursive: true });
await writeFile(join(root, ".hypit", "runtime"), "runtime.json\n", "utf8");
const program = `
@@ -75,7 +75,7 @@ test("one detached Runtime Worker can be started, observed and stopped", async (
assert.equal((await runtimeProcessStatus(profile, dataRoot)).state, "running");
assert.match((await runtimeProcessLogs(dataRoot)).text, /worker-ready/u);
- await writeFile(profile, JSON.stringify({ format: "hypit.runtime-profile@1", changed: true }), "utf8");
+ await writeFile(profile, JSON.stringify({ format: "hypit.runtime-local@1", changed: true }), "utf8");
assert.equal((await runtimeProcessStatus(profile, dataRoot)).configuration, "changed");
await assert.rejects(
ensureRuntimeProcess(profile, dataRoot, { command: "must-not-run", args: [] }, 5_000),