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.

fix: stop process trees, find configured executables and name paths on Windows

rpone0a9de4167b36
diff --git a/packages/runtime-host-node/src/index.ts b/packages/runtime-host-node/src/index.ts
index 5fe91dc2..6ee93057 100644
--- a/packages/runtime-host-node/src/index.ts
+++ b/packages/runtime-host-node/src/index.ts
@@ -220,10 +220,14 @@ 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));
- const suffixes = process.platform === "win32" && !/\.[^\\/]+$/u.test(value)
+ const extensions = 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}`);
+ : [];
+ // A configured path names one file, and on Windows this asks only whether that file is there, so
+ // it is tried as written before any PATHEXT extension. A bare command name is resolved the way a
+ // shell would resolve it, where an extensionless entry is not something Windows can run.
+ const candidates = (base: string, suffixes: readonly string[]) =>
+ (suffixes.length === 0 ? [""] : suffixes).map((suffix) => `${base}${suffix}`);
const available = async (candidate: string): Promise<boolean> => {
try {
await access(candidate, process.platform === "win32" ? constants.F_OK : constants.X_OK);
@@ -234,11 +238,11 @@ async function executableExists(value: string): Promise<boolean> {
}
};
if (pathLike(value)) {
- for (const candidate of candidates(value)) if (await available(candidate)) return true;
+ for (const candidate of candidates(value, ["", ...extensions])) if (await available(candidate)) return true;
return false;
}
for (const directory of (process.env.PATH ?? "").split(delimiter).filter(Boolean)) {
- for (const candidate of candidates(resolve(directory, value))) {
+ for (const candidate of candidates(resolve(directory, value), extensions)) {
if (await available(candidate)) return true;
}
}
diff --git a/packages/runtime-local/src/process-control.ts b/packages/runtime-local/src/process-control.ts
index d6215eac..85b3a3cd 100644
--- a/packages/runtime-local/src/process-control.ts
+++ b/packages/runtime-local/src/process-control.ts
@@ -30,6 +30,12 @@ function signal(pid: number, force: boolean): ProcessStopResult {
return "gone";
}
+/**
+ * Windows has no SIGTERM, and a process without a message loop — every Node child Hypit starts —
+ * answers a courteous taskkill with "can only be terminated forcefully". The caller asked for the
+ * tree to stop, so a refused courteous call escalates to /F rather than being reported as a failure.
+ * Escalating on any refusal rather than on that sentence keeps this working on a localized Windows.
+ */
function taskkill(pid: number, force: boolean): Promise<ProcessStopResult> {
if (!processAlive(pid)) return Promise.resolve("gone");
return new Promise((resolve, reject) => {
@@ -41,6 +47,7 @@ function taskkill(pid: number, force: boolean): Promise<ProcessStopResult> {
if (error === null) resolve("sent");
else if (!processAlive(pid)) resolve("sent");
else if (errorCode(error) === "EACCES" || errorCode(error) === "EPERM") resolve("denied");
+ else if (!force) resolve(taskkill(pid, true));
else reject(new Error(`taskkill could not stop process tree ${pid}: ${error.message}`));
});
});
diff --git a/packages/studio/src/archive.ts b/packages/studio/src/archive.ts
index 5fcf16fd..c9cd20b1 100644
--- a/packages/studio/src/archive.ts
+++ b/packages/studio/src/archive.ts
@@ -1,4 +1,4 @@
-import { isAbsolute, relative, resolve } from "node:path";
+import { isAbsolute, relative, resolve, sep } from "node:path";
import type { BuildCatalogEntry } from "@hypit/runtime";
import type { NodeRuntimeHost, RuntimeHostStatus } from "@hypit/runtime-host-node";
@@ -28,8 +28,14 @@ function isWithin(root: string, path: string): boolean {
return rel === "" || (!rel.startsWith("..") && !isAbsolute(rel));
}
+/**
+ * A path inside the project reads the same on every platform, so the Studio library shows one Run
+ * under one name wherever it is opened. A path outside the project is the machine's own, and stays
+ * in that machine's form.
+ */
function presentedPath(root: string, path: string): string {
- return isWithin(root, path) ? relative(resolve(root), resolve(path)) || "." : resolve(path);
+ if (!isWithin(root, path)) return resolve(path);
+ return (relative(resolve(root), resolve(path)) || ".").split(sep).join("/");
}
function buildBelongsTo(root: string, entry: BuildCatalogEntry): boolean {