fix(cli): quote the project name in init's printed cd commands (#7608)

`hyperframes init --non-interactive` closes with `cd <name> && npm run …`
lines for the person or agent to paste. The name went in as typed, so a
name with a space or a quote printed a command that fails as written:
`cd my first video` (bash: "cd: my: No such file or directory", zsh: "too
many arguments") and `cd it's mine` (an unterminated quote).

A new `shellArg` quotes a word only when a shell would split or expand
it: double quotes, or single quotes when the text holds `$`, a backtick,
`\`, `"` or `!`; on Windows, double quotes, with `\` paths left bare.
`hyperframes open` / `preview --stop` hints (desktopApp's `shownDir`)
already quoted whitespace with JSON.stringify and now use it too, so a
name like `it's` or `a&b` is covered there as well.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
wonjang
2026-11-14 03:47:58 +00:00
committed by GitHub
co-authored by Claude Opus 5.5
parent 2f31cc14b1
commit 213f7c5383
4 changed files with 74 additions and 6 deletions
+5 -4
View File
@@ -63,6 +63,7 @@ import {
} from "@hyperframes/parsers";
import { decodableAudioStream } from "@hyperframes/parsers/media-streams";
import { cliSourced } from "../utils/sourceTag.js";
import { shellArg } from "../utils/shellArg.js";
function resolveScaffoldTemplateId(exampleFlag: string | undefined, hasMediaFile: boolean): string {
const example = exampleFlag === "agent" ? "blank" : exampleFlag;
@@ -1044,7 +1045,7 @@ export default defineCommand({
console.log();
console.log(` ${c.accent("2.")} Open this project with your AI coding agent:`);
console.log(
` ${c.accent(`cd ${name}`)} then start ${c.accent("Claude Code")}, ${c.accent("Cursor")}, or your preferred agent`,
` ${c.accent(`cd ${shellArg(name)}`)} then start ${c.accent("Claude Code")}, ${c.accent("Cursor")}, or your preferred agent`,
);
console.log();
console.log(` ${c.accent("3.")} Try a starter prompt:`);
@@ -1056,13 +1057,13 @@ export default defineCommand({
);
console.log();
console.log(` ${c.accent("4.")} Preview in the browser:`);
console.log(` ${c.accent(`cd ${name}`)} && ${c.accent("npm run dev")}`);
console.log(` ${c.accent(`cd ${shellArg(name)}`)} && ${c.accent("npm run dev")}`);
console.log();
console.log(` ${c.accent("5.")} Check the composition:`);
console.log(` ${c.accent(`cd ${name}`)} && ${c.accent("npm run check")}`);
console.log(` ${c.accent(`cd ${shellArg(name)}`)} && ${c.accent("npm run check")}`);
console.log();
console.log(` ${c.accent("6.")} Render to MP4 when ready:`);
console.log(` ${c.accent(`cd ${name}`)} && ${c.accent("npm run render")}`);
console.log(` ${c.accent(`cd ${shellArg(name)}`)} && ${c.accent("npm run render")}`);
console.log();
console.log(` ${c.dim(`Full docs: ${cliSourced("https://hyperframes.heygen.com")}`)}`);
return;
+2 -2
View File
@@ -8,6 +8,7 @@ import { createProjectConfig } from "./projectConfig.js";
import { isCI } from "./attendedTerminal.js";
import { isAgentDriven } from "../telemetry/agent_runtime.js";
import { readRecord, removeRecord, writeRecord } from "./projectRecords.js";
import { shellArg } from "./shellArg.js";
// The HyperFrames desktop app, then builds named in HYPERFRAMES_DESKTOP_BUNDLE_IDS / _APP_NAMES (comma-separated).
const list = (name: string): string[] =>
@@ -247,8 +248,7 @@ function leaveIntent(dir: string, cta?: string, doc?: "storyboard"): () => void
}
function shownDir(dir: string, cwd: string): string {
const shown = relative(cwd, dir) || ".";
return /\s/.test(shown) ? JSON.stringify(shown) : shown;
return shellArg(relative(cwd, dir) || ".");
}
/** The `hyperframes open` line for a project, relative to where the person is. */
+56
View File
@@ -0,0 +1,56 @@
import { execFileSync } from "node:child_process";
import { mkdirSync, mkdtempSync, realpathSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { afterAll, describe, expect, it } from "vitest";
import { shellArg } from "./shellArg.js";
const NAMES = [
"my-video",
"서울여행",
"films/a",
"my first video",
"it's mine",
"it's",
"a&b",
"$HOME",
"o'neil $x",
"서울 여행 브이로그",
];
describe("shellArg", () => {
it("leaves a plain name alone and quotes one the shell would split or expand", () => {
expect(NAMES.map((name) => shellArg(name, "darwin"))).toEqual([
"my-video",
"서울여행",
"films/a",
'"my first video"',
`"it's mine"`,
`"it's"`,
'"a&b"',
"'$HOME'",
`'o'\\''neil $x'`,
'"서울 여행 브이로그"',
]);
});
it("uses double quotes on Windows, where a backslash path needs none", () => {
expect(shellArg("films\\a", "win32")).toBe("films\\a");
expect(shellArg("my first video", "win32")).toBe('"my first video"');
expect(shellArg("it's mine", "win32")).toBe(`"it's mine"`);
});
const root = mkdtempSync(join(tmpdir(), "hf-shell-arg-"));
afterAll(() => rmSync(root, { recursive: true, force: true }));
it.skipIf(process.platform === "win32")("prints a cd that a POSIX shell runs as written", () => {
for (const name of NAMES) {
mkdirSync(join(root, name), { recursive: true });
const pwd = execFileSync("/bin/sh", ["-c", `cd ${shellArg(name)} && pwd -P`], {
cwd: root,
encoding: "utf8",
});
expect(pwd.trim()).toBe(realpathSync(join(root, name)));
}
});
});
+11
View File
@@ -0,0 +1,11 @@
const PLAIN = /^[\p{L}\p{M}\p{N}_./@:+,=-]+$/u;
const PLAIN_WINDOWS_PATH = /^[\p{L}\p{M}\p{N}_./@:+,=\\-]+$/u;
const SPECIAL_IN_DOUBLE_QUOTES = /["$`\\!]/;
/** `text` as one word of a command printed for the person to paste into their shell. */
export function shellArg(text: string, platform: NodeJS.Platform = process.platform): string {
if (platform === "win32") return PLAIN_WINDOWS_PATH.test(text) ? text : `"${text}"`;
if (PLAIN.test(text)) return text;
if (!SPECIAL_IN_DOUBLE_QUOTES.test(text)) return `"${text}"`;
return `'${text.replaceAll("'", "'\\''")}'`;
}