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.

retain credential permissions and verify startup recovery

Qunlin Jinc9c5118098aa
diff --git a/packages/credential-store-file/README.md b/packages/credential-store-file/README.md
index 1f363f93..c8ed5914 100644
--- a/packages/credential-store-file/README.md
+++ b/packages/credential-store-file/README.md
@@ -50,6 +50,10 @@ The default directory is `credentials` under the Host state root printed by `hyp
`config.path` explicitly selects a directory, including an absolute directory outside that root;
relative paths resolve against the Host root.
Opening the adapter and reading an absent key do not create files. Keep this directory outside Git.
+On WSL, the default under the Linux home uses normal Linux permissions. If the Host state root is
+on a Windows-mounted drive, set this Store's `config.path` to a private directory in the WSL Linux
+filesystem before login. A Windows mount's reported mode does not establish that its Windows ACL
+protects the secret, so the Store does not waive its owner-private check for that path.
Each key has its own JSON file containing only `secret` and optional `expiresAt`, as defined by
CredentialValue. Filenames use reversible lower-case hex encoding of the key's UTF-16 bytes, with a
diff --git a/packages/credential-store-file/src/store.ts b/packages/credential-store-file/src/store.ts
index f504b3b6..854189c7 100644
--- a/packages/credential-store-file/src/store.ts
+++ b/packages/credential-store-file/src/store.ts
@@ -1,17 +1,10 @@
import { replaceFile } from "@hypit/file-io-node";
import { randomUUID } from "node:crypto";
import { mkdir, open, rm, stat, unlink } from "node:fs/promises";
-import { release } from "node:os";
import { join } from "node:path";
import { verifyCredentialRef } from "@hypit/runtime";
import type { CredentialRef, CredentialValue, WritableCredentialStore } from "@hypit/runtime";
-function isWslOrPermissiveMount(targetPath: string): boolean {
- if (process.platform === "win32") return true;
- const isWsl = process.env.WSL_DISTRO_NAME !== undefined || release().toLowerCase().includes("microsoft");
- return isWsl && (targetPath.startsWith("/mnt/") || targetPath.startsWith("/media/"));
-}
-
function missing(error: unknown): boolean {
return error instanceof Error && "code" in error && error.code === "ENOENT";
}
@@ -44,8 +37,8 @@ export class FileCredentialStore implements WritableCredentialStore {
if (create) await mkdir(this.directory, { recursive: true, mode: 0o700 });
const info = await stat(this.directory);
if (!info.isDirectory()) throw new Error(`Credential path is not a directory: ${this.directory}`);
- if (process.platform !== "win32" && !isWslOrPermissiveMount(this.directory) && (info.mode & 0o077) !== 0) {
- throw new Error(`Credential directory must be owner-private: ${this.directory}`);
+ if (process.platform !== "win32" && (info.mode & 0o077) !== 0) {
+ throw new Error(`Credential directory must be owner-private: ${this.directory}. On WSL, keep credentials in the Linux filesystem rather than a Windows-mounted drive.`);
}
}
@@ -63,8 +56,8 @@ export class FileCredentialStore implements WritableCredentialStore {
}
try {
const info = await file.stat();
- if (process.platform !== "win32" && !isWslOrPermissiveMount(path) && (info.mode & 0o077) !== 0) {
- throw new Error(`Credential file must be owner-private: ${path}`);
+ if (process.platform !== "win32" && (info.mode & 0o077) !== 0) {
+ throw new Error(`Credential file must be owner-private: ${path}. On WSL, keep credentials in the Linux filesystem rather than a Windows-mounted drive.`);
}
const text = await file.readFile("utf8");
// JSON parser messages may include secret bytes. Report the file, never its contents.
diff --git a/packages/credential-store-platform/README.md b/packages/credential-store-platform/README.md
index 8c2dc153..c4566598 100644
--- a/packages/credential-store-platform/README.md
+++ b/packages/credential-store-platform/README.md
@@ -47,6 +47,8 @@ credential stored in a locker stays in that locker; a credential stored in a fil
- `path` selects the directory for Linux file storage, resolved against the Host state root printed by
`hypit paths`. The default is the same `credentials` directory `@hypit/credential-store-file` uses,
so on Linux, switching between the two Stores finds the credential already stored.
+- WSL uses the Linux file Store. If the Host state root is on a Windows-mounted drive, select a
+ private directory in the WSL Linux filesystem with `path`; the Store keeps its permission check.
- `service` selects the locker service name. The OS Store's own default applies when it is absent.
## Storage on each platform
diff --git a/packages/runtime-local/src/supervisor.ts b/packages/runtime-local/src/supervisor.ts
index a3890bef..63ca9038 100644
--- a/packages/runtime-local/src/supervisor.ts
+++ b/packages/runtime-local/src/supervisor.ts
@@ -123,6 +123,7 @@ export async function superviseBuilds(options: {
await carrier.ready;
} catch (error) {
if (accepting === carrier) accepting = undefined;
+ if (options.signal.aborted) break;
await finishInterrupted(build, `Build executor startup failed: ${error instanceof Error ? error.message : String(error)}; create a new Build to continue`);
continue;
}
diff --git a/packages/runtime-local/test/startup-failure.test.ts b/packages/runtime-local/test/startup-failure.test.ts
new file mode 100644
index 00000000..305f2d41
--- /dev/null
+++ b/packages/runtime-local/test/startup-failure.test.ts
@@ -0,0 +1,74 @@
+import assert from "node:assert/strict";
+import { mkdtemp, rm, writeFile } from "node:fs/promises";
+import { tmpdir } from "node:os";
+import { join } from "node:path";
+import { fileURLToPath } from "node:url";
+import { setTimeout as pause } from "node:timers/promises";
+import test from "node:test";
+import { defineBuild } from "@hypit/core";
+import { FileBuildResultRepository } from "@hypit/build-result";
+import { SqliteRuntimeState } from "@hypit/store-sqlite";
+import { createGreetingBuild } from "../../core/test/greeting-fixture.js";
+import { statePath } from "../src/config.js";
+import { superviseBuilds } from "../src/supervisor.js";
+
+const distribution = fileURLToPath(new URL("../../../", import.meta.url));
+
+test("an executor that fails before ready records a failed Build and leaves supervision available", { timeout: 20_000 }, async () => {
+ const root = await mkdtemp(join(tmpdir(), "hypit-executor-startup-"));
+ const dataRoot = join(root, "runtime");
+ const profile = join(root, "profile.json");
+ const result = new FileBuildResultRepository(join(root, "results"));
+ const state = new SqliteRuntimeState(statePath(dataRoot));
+ const abort = new AbortController();
+ let supervision: Promise<void> | undefined;
+ try {
+ const profileValue = { format: "hypit.runtime-local@1", dataRoot, credentials: {}, endpoints: {}, bindings: {} };
+ await writeFile(profile, JSON.stringify(profileValue));
+ const initial = createGreetingBuild();
+ const authored = new Set(initial.program.records.map((record) => record.id));
+ const submit = async (build: string): Promise<void> => {
+ const request = {
+ build,
+ componentPackages: [],
+ result: { root, selection: { use: "@hypit/build-result-fs", config: { path: "results" } } },
+ context: { format: "hypit.local-execution@1", packageRoot: root, hostStateRoot: join(root, "host"),
+ distributionPackageRoot: distribution, profile: profileValue },
+ };
+ await state.submissions.prepare(request);
+ await result.create({ id: build, source: { path: "main.svml" }, targets: ["document"],
+ publishedOutputs: [{ name: "document", output: "document" }] });
+ await state.submissions.commit({ ...request,
+ definition: defineBuild({ program: initial.program,
+ initialRecords: initial.records.filter((record) => !authored.has(record.id)),
+ plan: initial.plan, targets: initial.targets }),
+ catalog: { source: { path: join(root, "main.svml") },
+ publishedOutputs: [{ name: "document", ref: { kind: "logical-output", id: "document" } }] },
+ });
+ };
+ const failed = async (build: string) => {
+ const deadline = Date.now() + 10_000;
+ let recorded = await result.read(build);
+ while (recorded?.outcome === undefined && Date.now() < deadline) {
+ await pause(25);
+ recorded = await result.read(build);
+ }
+ assert.equal(recorded?.outcome, "failed");
+ assert.match(recorded.failure ?? "", /executor startup failed/u);
+ };
+ await submit("bld_20260919T120000000Z_0000000001");
+ supervision = superviseBuilds({ profile, dataRoot, readyFile: join(root, "ready"), owner: "startup-test",
+ launch: { command: process.execPath, args: ["--eval", "process.exit(3)"] },
+ signal: abort.signal, ready: async () => {} });
+ await failed("bld_20260919T120000000Z_0000000001");
+ await submit("bld_20260919T120000001Z_0000000001");
+ await failed("bld_20260919T120000001Z_0000000001");
+ assert.deepEqual(await state.execution.listUnstarted(), []);
+ assert.deepEqual(await state.execution.listCapacity(), []);
+ } finally {
+ abort.abort();
+ await supervision;
+ state.close();
+ await rm(root, { recursive: true, force: true });
+ }
+});
diff --git a/packages/video-cli/src/cli.ts b/packages/video-cli/src/cli.ts
index 92f52c72..661c70f8 100644
--- a/packages/video-cli/src/cli.ts
+++ b/packages/video-cli/src/cli.ts
@@ -6,6 +6,7 @@ import { isMediaCommand, mediaCommands, writeMediaHelp } from "./media.js";
import { writeVocabularyHelp } from "./vocabulary.js";
import { writeCaptureHelp } from "./capture.js";
import { runVersionCli, writeVersionHelp } from "./version.js";
+import { acceptSecretBytes } from "./secret-input.js";
const argv = process.argv.slice(2);
const json = argv.includes("--json");
@@ -26,28 +27,19 @@ async function readSecret(prompt: string): Promise<string> {
}
process.stderr.write(prompt);
return await new Promise<string>((resolve, reject) => {
- const rawBytes: number[] = [];
+ const raw: number[] = [];
const finish = (error?: Error): void => {
process.stdin.off("data", input);
process.stdin.setRawMode(false);
process.stdin.pause();
process.stderr.write("\n");
- if (error === undefined) resolve(Buffer.from(rawBytes).toString("utf8"));
+ if (error === undefined) resolve(Buffer.from(raw).toString("utf8"));
else reject(error);
};
const input = (chunk: Buffer): void => {
- for (const byte of chunk) {
- if (byte === 3) { finish(new Error("credential input cancelled")); return; }
- if (byte === 10 || byte === 13) { finish(); return; }
- if (byte === 8 || byte === 127) {
- while (rawBytes.length > 0 && (rawBytes.at(-1)! & 0xc0) === 0x80) {
- rawBytes.pop();
- }
- rawBytes.pop();
- continue;
- }
- rawBytes.push(byte);
- }
+ const result = acceptSecretBytes(raw, chunk);
+ if (result === "cancelled") finish(new Error("credential input cancelled"));
+ if (result === "done") finish();
};
process.stdin.setRawMode(true);
process.stdin.resume();
diff --git a/packages/video-cli/src/secret-input.ts b/packages/video-cli/src/secret-input.ts
new file mode 100644
index 00000000..2c8c14c8
--- /dev/null
+++ b/packages/video-cli/src/secret-input.ts
@@ -0,0 +1,14 @@
+/** Keep terminal input as bytes until a complete UTF-8 secret can be decoded. */
+export function acceptSecretBytes(raw: number[], chunk: Uint8Array): "continue" | "done" | "cancelled" {
+ for (const byte of chunk) {
+ if (byte === 3) return "cancelled";
+ if (byte === 10 || byte === 13) return "done";
+ if (byte === 8 || byte === 127) {
+ while (raw.length > 0 && (raw.at(-1)! & 0xc0) === 0x80) raw.pop();
+ raw.pop();
+ continue;
+ }
+ raw.push(byte);
+ }
+ return "continue";
+}
diff --git a/packages/video-cli/test/secret-input.test.ts b/packages/video-cli/test/secret-input.test.ts
new file mode 100644
index 00000000..4f4b2ff9
--- /dev/null
+++ b/packages/video-cli/test/secret-input.test.ts
@@ -0,0 +1,19 @@
+import assert from "node:assert/strict";
+import test from "node:test";
+import { acceptSecretBytes } from "../src/secret-input.js";
+
+test("terminal secret input preserves UTF-8 and removes one code point on backspace", () => {
+ const raw: number[] = [];
+ const pasted = Buffer.from("密钥🔑", "utf8");
+ assert.equal(acceptSecretBytes(raw, pasted.subarray(0, 4)), "continue");
+ assert.equal(acceptSecretBytes(raw, pasted.subarray(4)), "continue");
+ assert.equal(Buffer.from(raw).toString("utf8"), "密钥🔑");
+ assert.equal(acceptSecretBytes(raw, Buffer.from([127])), "continue");
+ assert.equal(Buffer.from(raw).toString("utf8"), "密钥");
+ assert.equal(acceptSecretBytes(raw, Buffer.from([13])), "done");
+});
+
+test("terminal secret input reports cancellation without decoding partial bytes", () => {
+ const raw: number[] = [];
+ assert.equal(acceptSecretBytes(raw, Buffer.from([0xe5, 3])), "cancelled");
+});