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.

feat(v2): separate build archives from egress

kashorin4514d3fe180a
diff --git a/README.md b/README.md
index f5387c19..bf1c60a8 100644
--- a/README.md
+++ b/README.md
@@ -109,10 +109,17 @@ credentials:
```bash
pnpm svml:v2 build examples/talking-film-live/build.svrun \
--runtime examples/talking-film-live/svml.runtime.json \
- --follow \
- --out examples/talking-film-live/output/final.mp4
+ --build-id talking-film-live \
+ --follow
+
+pnpm svml:v2 get talking-film-live \
+ --runtime examples/talking-film-live/svml.runtime.json \
+ --to examples/talking-film-live/output/final.mp4
```
+The Build archives every accepted intermediate Record and Artifact before `get` makes an optional
+human-readable copy of the sole target.
+
Read its [deployment requirements](examples/talking-film-live/README.md) before running it. Paid
credentials, presenter assets, local databases and generated outputs are not committed.
diff --git a/docs/README.md b/docs/README.md
index 40858f9f..216579e2 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -22,6 +22,8 @@ the working tree contains only documents that should inform current implementati
locking and facet activation.
- [`local-developer-runtime-v1.md`](./local-developer-runtime-v1.md) — local SQLite/filesystem
Runtime, recovery and environment replacement.
+- [`build-archive-and-egress-v1.md`](./build-archive-and-egress-v1.md) — Targets, durable Records,
+ Artifact retention and optional Host materialization as four separate concerns.
- package READMEs under [`../packages`](../packages) — executable APIs and ownership.
## Video-domain specifications
diff --git a/examples/talking-film-live/README.md b/examples/talking-film-live/README.md
index 780efa45..5414258c 100644
--- a/examples/talking-film-live/README.md
+++ b/examples/talking-film-live/README.md
@@ -18,13 +18,22 @@ Run the complete graph through the explicit Run Graph and declarative local Runt
```bash
pnpm svml:v2 build examples/talking-film-live/build.svrun \
--runtime examples/talking-film-live/svml.runtime.json \
- --follow \
- --out examples/talking-film-live/output/final.mp4
+ --build-id talking-film-live \
+ --follow
+
+pnpm svml:v2 inspect talking-film-live \
+ --runtime examples/talking-film-live/svml.runtime.json
+
+pnpm svml:v2 get talking-film-live \
+ --runtime examples/talking-film-live/svml.runtime.json \
+ --to examples/talking-film-live/output/final.mp4
```
`build.svrun` owns the selected Target and fidelity. `svml.runtime.json` owns Provider instances,
-permissions and concurrency. The existing `svml.runtime.ts` shows the advanced executable embedding
-API and remains supported.
+permissions and concurrency. The Build archives all accepted intermediate Records and referenced
+Artifacts even when no destination path is requested. `get` only makes an optional copy of the
+already archived sole target. The existing `svml.runtime.ts` shows the advanced executable
+embedding API and remains supported.
To reuse the paid shot outputs from a verified earlier Build, add two zero-input Build Record
Candidates and their explicit Satisfaction edges to another `.svrun`:
diff --git a/packages/cli/README.md b/packages/cli/README.md
index 77b67b55..5466096e 100644
--- a/packages/cli/README.md
+++ b/packages/cli/README.md
@@ -24,9 +24,11 @@ pnpm svml:v2 check path/to/main.svml --package-lock ./svml.packages.lock --root
pnpm svml:v2 plan path/to/main.svml --target component.result
pnpm svml:v2 check path/to/build.svrun
pnpm svml:v2 plan path/to/build.svrun
-pnpm svml:v2 build path/to/build.svrun --runtime ./svml.runtime.json --follow --out ./final.mp4
-pnpm svml:v2 build path/to/main.svml --target final.video --runtime ./svml.runtime.ts --pin shot=<prior-build-id> --accept-substitute --follow --out ./variant.mp4
+pnpm svml:v2 build path/to/build.svrun --runtime ./svml.runtime.json --build-id delivery-01 --follow
+pnpm svml:v2 build path/to/main.svml --target final.video --runtime ./svml.runtime.ts --pin shot=<prior-build-id> --accept-substitute --build-id variant-01 --follow
pnpm svml:v2 status <build-id> --runtime ./svml.runtime.json
+pnpm svml:v2 inspect <build-id> --runtime ./svml.runtime.json
+pnpm svml:v2 get <build-id> --runtime ./svml.runtime.json --to ./final.mp4
pnpm svml:v2 cancel <build-id> --runtime ./svml.runtime.json
```
@@ -47,9 +49,13 @@ non-retryable failure, cancellation or `--max-wait-ms`. `status` reads durable v
`cancel` invokes active endpoints and then records the resulting terminal Build failure. None of
these commands creates a second ready-command queue.
-`--out` accepts exactly one completed media target, reads its content-addressed bytes through the
-selected Runtime ArtifactStore and writes the requested file. It does not treat a CAS path as a
-public filename or bypass Record identity verification.
+`build` archives every accepted Record in the demanded closure and every referenced byte Artifact,
+whether or not the user wants a conventional filesystem copy. `inspect` lists Targets, demanded
+Logical Outputs, accepted Records and their Artifact references. `get` reads one accepted Record;
+without a selector it requires one distinct target, while `--record` and `--output` select any
+accepted Record or demanded Logical Output. `--artifact` selects any nested BlobRef that the Build
+actually references. `--to` copies an Artifact or writes an inline structured value as JSON. It is
+Host egress only and never changes Build identity or retention.
`--pin output=<prior-build-id>` is temporary CLI compatibility language, not a Core primitive. The Host
verifies the prior Build only to extract a typed Record, attaches it as an ordinary zero-input
diff --git a/packages/cli/src/archive.ts b/packages/cli/src/archive.ts
new file mode 100644
index 00000000..40c24084
--- /dev/null
+++ b/packages/cli/src/archive.ts
@@ -0,0 +1,168 @@
+import { mkdir, writeFile } from "node:fs/promises";
+import { dirname } from "node:path";
+
+import type { LocalRuntime } from "@svml/local";
+import { isDigest } from "@svml/protocol";
+import type { BuildState, Digest, TypedRecord } from "@svml/protocol";
+
+type ArtifactIdentity = {
+ readonly digest: Digest;
+ readonly size: number;
+ readonly mediaType: string;
+};
+
+export type ArchivedArtifactReference = ArtifactIdentity & {
+ readonly record: string;
+ readonly path: string;
+};
+
+function artifactIdentity(value: unknown): ArtifactIdentity | undefined {
+ if (value === null || Array.isArray(value) || typeof value !== "object") return undefined;
+ const candidate = value as Readonly<Record<string, unknown>>;
+ if (typeof candidate.digest !== "string" || !isDigest(candidate.digest)
+ || typeof candidate.size !== "number" || !Number.isSafeInteger(candidate.size) || candidate.size < 0
+ || typeof candidate.mediaType !== "string" || candidate.mediaType.trim().length === 0) return undefined;
+ return { digest: candidate.digest, size: candidate.size, mediaType: candidate.mediaType };
+}
+
+function recordArtifact(record: TypedRecord): ArtifactIdentity | undefined {
+ if (record.value.kind === "blob") return artifactIdentity(record.value);
+ return artifactIdentity(record.value.value);
+}
+
+export async function materializeRecord(
+ runtime: Pick<LocalRuntime, "readArtifact">,
+ record: TypedRecord,
+ destination: string,
+): Promise<
+ | { readonly kind: "artifact"; readonly path: string; readonly digest: string; readonly size: number; readonly mediaType: string }
+ | { readonly kind: "json"; readonly path: string; readonly size: number }
+> {
+ await mkdir(dirname(destination), { recursive: true });
+ const artifact = recordArtifact(record);
+ if (artifact !== undefined) {
+ return await materializeArtifact(runtime, artifact, destination, `Record ${record.id}`);
+ }
+ const inline = record.value.kind === "inline" ? record.value.value : record.value;
+ const bytes = Buffer.from(`${JSON.stringify(inline, null, 2)}\n`, "utf8");
+ await writeFile(destination, bytes);
+ return { kind: "json", path: destination, size: bytes.byteLength };
+}
+
+export async function materializeArtifact(
+ runtime: Pick<LocalRuntime, "readArtifact">,
+ artifact: ArtifactIdentity,
+ destination: string,
+ subject = "Build archive",
+): Promise<{ readonly kind: "artifact"; readonly path: string; readonly digest: string; readonly size: number; readonly mediaType: string }> {
+ const bytes = await runtime.readArtifact(artifact.digest);
+ if (bytes === undefined) throw new Error(`Artifact ${artifact.digest} is absent from the selected ArtifactStore`);
+ if (bytes.byteLength !== artifact.size) throw new Error(`Artifact ${artifact.digest} size differs from ${subject}`);
+ await mkdir(dirname(destination), { recursive: true });
+ await writeFile(destination, bytes);
+ return { kind: "artifact", path: destination, ...artifact };
+}
+
+export function collectArtifacts(
+ value: unknown,
+ path = "$",
+ found: { path: string; artifact: ArtifactIdentity }[] = [],
+): readonly {
+ readonly path: string;
+ readonly digest: Digest;
+ readonly size: number;
+ readonly mediaType: string;
+}[] {
+ const artifact = artifactIdentity(value);
+ if (artifact !== undefined) found.push({ path, artifact });
+ if (Array.isArray(value)) {
+ value.forEach((item, index) => collectArtifacts(item, `${path}[${index}]`, found));
+ } else if (value !== null && typeof value === "object") {
+ for (const [key, item] of Object.entries(value)) collectArtifacts(item, `${path}.${key}`, found);
+ }
+ return found.map((item) => ({ path: item.path, ...item.artifact }));
+}
+
+export function findArchivedArtifact(state: BuildState, digest: string): readonly ArchivedArtifactReference[] {
+ if (!isDigest(digest)) throw new Error(`--artifact requires a valid sha256 digest, received ${digest}`);
+ return state.records.flatMap((record) => {
+ const value = record.value.kind === "blob" ? record.value : record.value.value;
+ return collectArtifacts(value)
+ .filter((artifact) => artifact.digest === digest)
+ .map((artifact) => ({ record: record.id, ...artifact }));
+ });
+}
+
+function summarizeRecord(record: TypedRecord) {
+ const value = record.value.kind === "blob" ? record.value : record.value.value;
+ return {
+ id: record.id,
+ type: record.type,
+ digest: record.digest,
+ conformance: record.conformance,
+ origin: record.origin,
+ storage: record.value.kind,
+ artifacts: collectArtifacts(value),
+ };
+}
+
+export function selectArchivedRecord(
+ state: BuildState,
+ options: { readonly record?: string; readonly output?: string },
+): TypedRecord {
+ if (options.record !== undefined && options.output !== undefined) {
+ throw new Error("get accepts either --record or --output, not both");
+ }
+ let id = options.record;
+ if (options.output !== undefined) {
+ const selection = state.plan.selections.find((item) => item.output === options.output);
+ if (selection === undefined) throw new Error(`Build has no demanded Logical Output ${options.output}`);
+ id = selection.record;
+ }
+ if (id === undefined) {
+ const goals = [...new Set(state.plan.goals.map((goal) => goal.record))];
+ if (goals.length !== 1) {
+ throw new Error("get without --record or --output requires exactly one distinct target Record");
+ }
+ [id] = goals;
+ }
+ const record = state.records.find((item) => item.id === id);
+ if (record === undefined) throw new Error(`Record ${id} has not been accepted by this Build`);
+ return record;
+}
+
+export function inspectBuild(state: BuildState) {
+ const records = new Map(state.records.map((record) => [record.id, record]));
+ const selections = new Map(state.plan.selections.map((selection) => [selection.output, selection]));
+ return {
+ core: state.id,
+ status: state.status,
+ graph: state.graph.id,
+ request: state.request.digest,
+ targets: state.request.targets.map((target) => {
+ const selection = selections.get(target.output);
+ const record = selection === undefined ? undefined : records.get(selection.record);
+ return {
+ output: target.output,
+ accepts: target.accepts,
+ ...(selection === undefined ? {} : {
+ candidate: selection.candidate,
+ fidelity: selection.fidelity,
+ record: selection.record,
+ accepted: record !== undefined,
+ }),
+ };
+ }),
+ demandedOutputs: state.plan.selections.map((selection) => ({
+ output: selection.output,
+ candidate: selection.candidate,
+ fidelity: selection.fidelity,
+ record: selection.record,
+ accepted: records.has(selection.record),
+ })),
+ records: state.records.map(summarizeRecord),
+ receipts: state.receipts.length,
+ derivations: state.derivations.length,
+ diagnostics: state.diagnostics,
+ };
+}
diff --git a/packages/cli/src/index.ts b/packages/cli/src/index.ts
index 5f2d466d..b8415eed 100644
--- a/packages/cli/src/index.ts
+++ b/packages/cli/src/index.ts
@@ -1,3 +1,4 @@
export { createOfficialNodeCompiler } from "./host.js";
export type { OfficialCompilerOptions } from "./host.js";
-export { materializeSingleGoal, runCli } from "./main.js";
+export { materializeArtifact, materializeRecord } from "./archive.js";
+export { runCli } from "./main.js";
diff --git a/packages/cli/src/main.ts b/packages/cli/src/main.ts
index a6dda297..584fecde 100644
--- a/packages/cli/src/main.ts
+++ b/packages/cli/src/main.ts
@@ -1,9 +1,7 @@
-import { mkdir, writeFile } from "node:fs/promises";
import { dirname, extname, resolve } from "node:path";
import { pathToFileURL } from "node:url";
import type { LocalRuntime } from "@svml/local";
-import { isDigest } from "@svml/protocol";
import {
createBuildRecordCandidate,
sealRealizationOverlay,
@@ -15,6 +13,14 @@ import {
} from "@svml/package-loader-node";
import { createOfficialNodeCompiler, officialNodePackages } from "./host.js";
+import {
+ collectArtifacts,
+ findArchivedArtifact,
+ inspectBuild,
+ materializeArtifact,
+ materializeRecord,
+ selectArchivedRecord,
+} from "./archive.js";
import { loadRunFile } from "./run-file.js";
import { createOfficialRuntimeFromConfig } from "./runtime-config.js";
@@ -34,7 +40,10 @@ type ParsedArgs = {
readonly maxWaitMs: number | undefined;
readonly packageLock: string | undefined;
readonly packages: readonly string[];
- readonly out: string | undefined;
+ readonly record: string | undefined;
+ readonly output: string | undefined;
+ readonly artifact: string | undefined;
+ readonly to: string | undefined;
readonly pins: readonly { readonly output: string; readonly build: string }[];
};
@@ -49,7 +58,10 @@ function parseArgs(argv: readonly string[]): ParsedArgs {
let packageLock: string | undefined;
const packages: string[] = [];
let substitute = false;
- let out: string | undefined;
+ let record: string | undefined;
+ let output: string | undefined;
+ let artifact: string | undefined;
+ let to: string | undefined;
const pins: { output: string; build: string }[] = [];
for (let index = 0; index < rest.length; index += 1) {
const item = rest[index];
@@ -93,9 +105,33 @@ function parseArgs(argv: readonly string[]): ParsedArgs {
continue;
}
if (item === "--out") {
+ throw new Error("--out was removed: Build always archives accepted Records; use `get <build-id> --to <path>` for an optional copy");
+ }
+ if (item === "--record") {
+ const value = rest[index + 1];
+ if (value === undefined || value.startsWith("--")) throw new Error("--record requires a Record id");
+ record = value;
+ index += 1;
+ continue;
+ }
+ if (item === "--output") {
+ const value = rest[index + 1];
+ if (value === undefined || value.startsWith("--")) throw new Error("--output requires a Logical Output id");
+ output = value;
+ index += 1;
+ continue;
+ }
+ if (item === "--artifact") {
+ const value = rest[index + 1];
+ if (value === undefined || value.startsWith("--")) throw new Error("--artifact requires a content digest");
+ artifact = value;
+ index += 1;
+ continue;
+ }
+ if (item === "--to") {
const value = rest[index + 1];
- if (value === undefined || value.startsWith("--")) throw new Error("--out requires a file path");
- out = resolve(value);
+ if (value === undefined || value.startsWith("--")) throw new Error("--to requires a file path");
+ to = resolve(value);
index += 1;
continue;
}
@@ -143,7 +179,10 @@ function parseArgs(argv: readonly string[]): ParsedArgs {
maxWaitMs,
packageLock,
packages,
- out,
+ record,
+ output,
+ artifact,
+ to,
pins,
};
}
@@ -155,9 +194,11 @@ function usage(): string {
" svml-v2 check <file.svml|file.svrun> [--runtime profile.json] [--package-lock file] [--root directory]",
" svml-v2 plan <file.svml> --target export [--target export] [--accept-substitute] [--package-lock file]",
" svml-v2 plan <file.svrun> [--runtime profile.json] [--package-lock file]",
- " svml-v2 build <file.svml> --target export --runtime ./svml.runtime.ts [--pin output=prior-build --accept-substitute] [--follow] [--out video.mp4]",
- " svml-v2 build <file.svrun> --runtime profile.json [--follow] [--out video.mp4]",
+ " svml-v2 build <file.svml> --target export --runtime ./svml.runtime.ts [--pin output=prior-build --accept-substitute] [--follow]",
+ " svml-v2 build <file.svrun> --runtime profile.json [--follow]",
" svml-v2 status <build-id> --runtime profile.json|./svml.runtime.ts",
+ " svml-v2 inspect <build-id> --runtime profile.json|./svml.runtime.ts",
+ " svml-v2 get <build-id> --runtime profile.json|./svml.runtime.ts [--record record-id|--output logical-output-id|--artifact digest] [--to path]",
" svml-v2 cancel <build-id> --runtime profile.json|./svml.runtime.ts",
].join("\n");
}
@@ -189,38 +230,11 @@ async function loadLocalRuntime(path: string): Promise<LocalRuntime> {
return candidate;
}
-export async function materializeSingleGoal(
- runtime: Pick<LocalRuntime, "readArtifact">,
- built: Awaited<ReturnType<LocalRuntime["build"]>>,
- output: string,
-): Promise<{ readonly path: string; readonly digest: string; readonly size: number }> {
- if (built.status !== "complete") throw new Error("--out requires a completed Build");
- if (built.state.plan.goals.length !== 1) throw new Error("--out requires exactly one target");
- const goal = built.state.plan.goals[0]!;
- const record = built.state.records.find((item) => item.id === goal.record);
- const value = record?.value.kind === "inline" ? record.value.value : undefined;
- if (value === null || Array.isArray(value) || typeof value !== "object") {
- throw new Error("--out target is not a materializable media Artifact");
- }
- const artifact = value as Readonly<Record<string, unknown>>;
- const digest = artifact.digest;
- const size = artifact.size;
- if (typeof digest !== "string" || !isDigest(digest) || typeof size !== "number" || !Number.isSafeInteger(size)) {
- throw new Error("--out target has no valid Artifact identity");
- }
- const bytes = await runtime.readArtifact(digest);
- if (bytes === undefined) throw new Error(`Artifact ${digest} is absent from the selected ArtifactStore`);
- if (bytes.byteLength !== size) throw new Error(`Artifact ${digest} size differs from its target Record`);
- await mkdir(dirname(output), { recursive: true });
- await writeFile(output, bytes);
- return { path: output, digest, size };
-}
-
export async function runCli(argv: readonly string[], io: CliIo): Promise<void> {
const args = parseArgs(argv);
if (args.file === undefined
|| (args.command !== "lock-packages" && args.command !== "check" && args.command !== "plan" && args.command !== "build"
- && args.command !== "status" && args.command !== "cancel")) {
+ && args.command !== "status" && args.command !== "inspect" && args.command !== "get" && args.command !== "cancel")) {
throw new Error(usage());
}
if (args.command === "lock-packages") {
@@ -233,12 +247,15 @@ export async function runCli(argv: readonly string[], io: CliIo): Promise<void>
io.write(`${JSON.stringify({ ok: true, packageLock: output, digest: lock.digest, packages: lock.packages }, null, 2)}\n`);
return;
}
- if (args.out !== undefined && args.command !== "build") throw new Error("--out is only valid for build");
+ if ((args.record !== undefined || args.output !== undefined || args.artifact !== undefined || args.to !== undefined)
+ && args.command !== "get") {
+ throw new Error("--record, --output, --artifact and --to are only valid for get");
+ }
if (args.pins.length > 0 && args.command !== "build") throw new Error("--pin is only valid for build");
if (args.pins.length > 0 && !args.substitute) {
throw new Error("--pin attaches substitute Candidates; add --accept-substitute");
}
- if (args.command === "status" || args.command === "cancel") {
+ if (args.command === "status" || args.command === "inspect" || args.command === "get" || args.command === "cancel") {
if (args.runtime === undefined) throw new Error(`${args.command} requires --runtime`);
const runtime = await loadLocalRuntime(args.runtime);
try {
@@ -262,6 +279,66 @@ export async function runCli(argv: readonly string[], io: CliIo): Promise<void>
...(operation.failure === undefined ? {} : { failure: operation.failure }),
})),
}, null, 2)}\n`);
+ } else if (args.command === "inspect") {
+ const status = await runtime.status(args.file);
+ if (status.build === undefined) throw new Error(`Build ${args.file} does not exist`);
+ io.write(`${JSON.stringify({
+ build: status.build.build,
+ revision: status.build.revision,
+ archive: inspectBuild(status.build.state),
+ operations: status.operations.map((operation) => ({
+ id: operation.id,
+ command: operation.command,
+ endpoint: operation.endpoint,
+ attempt: operation.attempt,
+ status: operation.status,
+ ...(operation.wakeAt === undefined ? {} : { wakeAt: operation.wakeAt }),
+ ...(operation.failure === undefined ? {} : { failure: operation.failure }),
+ })),
+ }, null, 2)}\n`);
+ } else if (args.command === "get") {
+ const status = await runtime.status(args.file);
+ if (status.build === undefined) throw new Error(`Build ${args.file} does not exist`);
+ if (args.artifact !== undefined && (args.record !== undefined || args.output !== undefined)) {
+ throw new Error("get accepts one of --record, --output or --artifact");
+ }
+ if (args.artifact !== undefined) {
+ const references = findArchivedArtifact(status.build.state, args.artifact);
+ if (references.length === 0) throw new Error(`Build ${args.file} does not reference Artifact ${args.artifact}`);
+ if (args.to === undefined) {
+ io.write(`${JSON.stringify({ build: status.build.build, artifact: args.artifact, references }, null, 2)}\n`);
+ } else {
+ const [first] = references;
+ if (first === undefined) throw new Error(`Build ${args.file} does not reference Artifact ${args.artifact}`);
+ const materialized = await materializeArtifact(runtime, first, args.to, `Build ${args.file}`);
+ io.write(`${JSON.stringify({
+ build: status.build.build,
+ artifact: args.artifact,
+ references,
+ materialized,
+ }, null, 2)}\n`);
+ }
+ return;
+ }
+ const record = selectArchivedRecord(status.build.state, {
+ ...(args.record === undefined ? {} : { record: args.record }),
+ ...(args.output === undefined ? {} : { output: args.output }),
+ });
+ if (args.to === undefined) {
+ io.write(`${JSON.stringify({
+ build: status.build.build,
+ revision: status.build.revision,
+ record,
+ artifacts: collectArtifacts(record.value.kind === "blob" ? record.value : record.value.value),
+ }, null, 2)}\n`);
+ } else {
+ const materialized = await materializeRecord(runtime, record, args.to);
+ io.write(`${JSON.stringify({
+ build: status.build.build,
+ record: record.id,
+ materialized,
+ }, null, 2)}\n`);
+ }
} else {
const result = await runtime.cancel(args.file);
io.write(`${JSON.stringify({
@@ -402,10 +479,6 @@ export async function runCli(argv: readonly string[], io: CliIo): Promise<void>
follow: args.follow,
...(args.maxWaitMs === undefined ? {} : { maxWaitMs: args.maxWaitMs }),
});
- let materialized: { readonly path: string; readonly digest: string; readonly size: number } | undefined;
- if (args.out !== undefined && built.status === "complete") {
- materialized = await materializeSingleGoal(runtime, built, args.out);
- }
io.write(`${JSON.stringify({
build: built.id,
core: built.state.id,
@@ -422,8 +495,6 @@ export async function runCli(argv: readonly string[], io: CliIo): Promise<void>
blocked: built.blocked,
journal: built.journal,
...(pinSummary.length === 0 ? {} : { pins: pinSummary }),
- ...(args.out !== undefined && materialized === undefined ? { pendingOutput: args.out } : {}),
- ...(materialized === undefined ? {} : { output: materialized }),
}, null, 2)}\n`);
} finally {
await runtime.close();
diff --git a/packages/cli/test/cli.test.ts b/packages/cli/test/cli.test.ts
index e4768ffd..68a42f93 100644
--- a/packages/cli/test/cli.test.ts
+++ b/packages/cli/test/cli.test.ts
@@ -5,7 +5,7 @@ import { tmpdir } from "node:os";
import { join } from "node:path";
import test from "node:test";
-import { materializeSingleGoal, runCli } from "@svml/cli";
+import { materializeRecord, runCli } from "@svml/cli";
test("CLI Pin is explicit substitute selection rather than an exact-history privilege", async () => {
await assert.rejects(
@@ -19,6 +19,15 @@ test("CLI Pin is explicit substitute selection rather than an exact-history priv
);
});
+test("CLI does not confuse Build persistence with the removed --out convenience", async () => {
+ await assert.rejects(
+ async () => await runCli([
+ "build", "unused.svrun", "--runtime", "unused-runtime.ts", "--out", "final.mp4",
+ ], { write() {} }),
+ /Build always archives accepted Records/u,
+ );
+});
+
test("official v2 CLI checks a real Script source through the Node compiler host", async () => {
const root = await mkdtemp(join(tmpdir(), "svml-cli-"));
const file = join(root, "main.svml");
@@ -404,25 +413,134 @@ test("CLI package lock activates an installed package without changing the offic
assert.deepEqual(checked.modules, ["example.empty@1"]);
});
-test("materializeSingleGoal writes one verified target through the Runtime ArtifactStore seam", async () => {
- const root = await mkdtemp(join(tmpdir(), "svml-cli-out-"));
+test("materializeRecord copies an archived Artifact without requiring a completed Build", async () => {
+ const root = await mkdtemp(join(tmpdir(), "svml-cli-get-"));
const bytes = Buffer.from("final-video-bytes");
const artifactDigest = `sha256:${createHash("sha256").update(bytes).digest("hex")}`;
const output = join(root, "out", "final.mp4");
const runtime = {
async readArtifact(digest: string) { return digest === artifactDigest ? bytes : undefined; },
- } as Parameters<typeof materializeSingleGoal>[0];
- const built = {
- status: "complete",
- state: {
- plan: { goals: [{ record: "final.video" }] },
- records: [{
- id: "final.video",
- value: { kind: "inline", value: { digest: artifactDigest, size: bytes.byteLength, mediaType: "video/mp4" } },
+ } as Parameters<typeof materializeRecord>[0];
+ const record = {
+ id: "final.video",
+ value: { kind: "inline", value: { digest: artifactDigest, size: bytes.byteLength, mediaType: "video/mp4" } },
+ } as unknown as Parameters<typeof materializeRecord>[1];
+ const result = await materializeRecord(runtime, record, output);
+ assert.deepEqual(await readFile(output), bytes);
+ assert.deepEqual(result, {
+ kind: "artifact",
+ path: output,
+ digest: artifactDigest,
+ size: bytes.byteLength,
+ mediaType: "video/mp4",
+ });
+});
+
+test("materializeRecord writes structured intermediate facts as JSON", async () => {
+ const root = await mkdtemp(join(tmpdir(), "svml-cli-get-json-"));
+ const output = join(root, "evidence.json");
+ const record = {
+ id: "whisperx.evidence",
+ value: { kind: "inline", value: { words: [{ text: "hello", start: 0, end: 0.4 }] } },
+ } as unknown as Parameters<typeof materializeRecord>[1];
+ const result = await materializeRecord({ async readArtifact() { return undefined; } }, record, output);
+ assert.equal(result.kind, "json");
+ if (record.value.kind !== "inline") assert.fail("fixture must be inline");
+ assert.deepEqual(JSON.parse(await readFile(output, "utf8")), record.value.value);
+});
+
+test("CLI inspect and get read the durable Build archive independently of build execution", async () => {
+ const root = await mkdtemp(join(tmpdir(), "svml-cli-archive-"));
+ const runtimePath = join(root, "runtime.mjs");
+ const destination = join(root, "final.mp4");
+ const rawDestination = join(root, "whisperx-raw.json");
+ const bytes = Buffer.from("archived-video");
+ const rawBytes = Buffer.from('{"segments":[]}');
+ const artifactDigest = `sha256:${createHash("sha256").update(bytes).digest("hex")}`;
+ const rawDigest = `sha256:${createHash("sha256").update(rawBytes).digest("hex")}`;
+ const recordDigest = `sha256:${"1".repeat(64)}`;
+ const buildDigest = `sha256:${"2".repeat(64)}`;
+ const requestDigest = `sha256:${"3".repeat(64)}`;
+ const state = {
+ id: buildDigest,
+ status: "active",
+ graph: { id: `sha256:${"4".repeat(64)}` },
+ request: {
+ digest: requestDigest,
+ targets: [{ output: "logical:final", accepts: "exact" }],
+ },
+ plan: {
+ goals: [{ record: "record:final" }],
+ selections: [{
+ output: "logical:final",
+ candidate: "candidate:render",
+ fidelity: "exact",
+ record: "record:final",
}],
},
- } as unknown as Parameters<typeof materializeSingleGoal>[1];
- const result = await materializeSingleGoal(runtime, built, output);
- assert.deepEqual(await readFile(output), bytes);
- assert.deepEqual(result, { path: output, digest: artifactDigest, size: bytes.byteLength });
+ records: [{
+ id: "record:final",
+ type: { module: { name: "example", version: "1" }, name: "Artifact" },
+ value: { kind: "inline", value: { digest: artifactDigest, size: bytes.byteLength, mediaType: "video/mp4" } },
+ digest: recordDigest,
+ conformance: "exact",
+ origin: { kind: "authored", module: "example" },
+ }, {
+ id: "record:whisperx",
+ type: { module: { name: "example", version: "1" }, name: "Evidence" },
+ value: { kind: "inline", value: {
+ words: [],
+ rawEvidenceArtifact: { kind: "blob", digest: rawDigest, size: rawBytes.byteLength, mediaType: "application/json" },
+ } },
+ digest: `sha256:${"5".repeat(64)}`,
+ conformance: "exact",
+ origin: { kind: "authored", module: "example" },
+ }],
+ receipts: [],
+ derivations: [],
+ diagnostics: [],
+ };
+ await writeFile(runtimePath, `const bytes = Buffer.from(${JSON.stringify(bytes.toString("base64"))}, "base64");
+const rawBytes = Buffer.from(${JSON.stringify(rawBytes.toString("base64"))}, "base64");
+export default {
+ async build() { throw new Error("not used"); },
+ async status(id) { return { build: id === "archive-1" ? { build: id, revision: 7, state: ${JSON.stringify(state)} } : undefined, operations: [] }; },
+ async readArtifact(digest) {
+ if (digest === ${JSON.stringify(artifactDigest)}) return bytes;
+ if (digest === ${JSON.stringify(rawDigest)}) return rawBytes;
+ return undefined;
+ },
+ async close() {},
+};\n`, "utf8");
+
+ let inspectedOutput = "";
+ await runCli(["inspect", "archive-1", "--runtime", runtimePath], {
+ write: (text) => { inspectedOutput += text; },
+ });
+ const inspected = JSON.parse(inspectedOutput) as {
+ readonly archive: {
+ readonly status: string;
+ readonly targets: readonly { readonly accepted: boolean }[];
+ readonly records: readonly { readonly artifacts: readonly { readonly digest: string }[] }[];
+ };
+ };
+ assert.equal(inspected.archive.status, "active");
+ assert.equal(inspected.archive.targets[0]?.accepted, true);
+ assert.equal(inspected.archive.records[0]?.artifacts[0]?.digest, artifactDigest);
+
+ let getOutput = "";
+ await runCli([
+ "get", "archive-1", "--runtime", runtimePath,
+ "--output", "logical:final", "--to", destination,
+ ], { write: (text) => { getOutput += text; } });
+ assert.deepEqual(await readFile(destination), bytes);
+ const got = JSON.parse(getOutput) as { readonly materialized: { readonly kind: string; readonly digest: string } };
+ assert.equal(got.materialized.kind, "artifact");
+ assert.equal(got.materialized.digest, artifactDigest);
+
+ await runCli([
+ "get", "archive-1", "--runtime", runtimePath,
+ "--artifact", rawDigest, "--to", rawDestination,
+ ], { write() {} });
+ assert.deepEqual(await readFile(rawDestination), rawBytes);
});
diff --git a/packages/local/README.md b/packages/local/README.md
index 045272d7..99826fc0 100644
--- a/packages/local/README.md
+++ b/packages/local/README.md
@@ -73,8 +73,10 @@ When several instances provide the same role, `runtimeSelection` must name the e
The same mechanism covers Postgres, S3, keychains and replacement Schedulers; none requires a
change to `@svml/local`. Advanced hosts may still call `createLocalRuntime` with raw ports.
-`LocalRuntime.readArtifact(digest)` is the generic egress seam used by CLI `--out`. It exposes
-content-addressed bytes, not filesystem layout, so filesystem and S3 stores remain interchangeable.
+`LocalRuntime.status(build)` exposes the verified durable Build archive, and
+`LocalRuntime.readArtifact(digest)` is the generic byte-egress seam used by CLI `get`. They expose
+Record and content identities, not private filesystem layout, so filesystem and S3 stores remain
+interchangeable. Egress never determines whether a Build result is retained.
`LocalBuildRequest.attachments` is the explicit ingress from a trusted Host into the selected
ArtifactStore. Each attachment carries claimed `BlobRef` metadata plus bytes; Local Runtime copies