Skip to content

Commit d02c0e7

Browse files
jrusso1020claude
andcommitted
fix(cli): count only agent-run shells as unattended, and exit 2 for missing arguments
isUnattended() used the telemetry fingerprint detectAgentRuntime(), which also matches a person typing in Cursor's or Windsurf's terminal (TERM_PROGRAM) and any Replit shell (REPL_ID, REPLIT_USER). It now uses isAgentDriven(), which keeps only markers an agent sets on the shells it runs: CURSOR_AGENT counts, TERM_PROGRAM=cursor, TERM_PROGRAM=windsurf and the Replit variables do not. The hand-written argument checks in lambda, cloudrun, lambda policies, capture, remove-background, init (--resolution), tts (--lang) and cloud render (--idempotency-key, --dry-run) exited 1. They are usage errors and now exit 2. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 625bd9c commit d02c0e7

16 files changed

Lines changed: 119 additions & 45 deletions

‎packages/cli/src/cli.agentMode.test.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,16 @@ describe("agent-mode contract", () => {
140140
},
141141
);
142142
});
143+
144+
it.each([
145+
["lambda progress"],
146+
["cloudrun progress"],
147+
["capture"],
148+
["remove-background in.mp4"],
149+
["init demo --resolution huge --non-interactive"],
150+
])("`%s` is missing or misusing an argument, a usage error with exit 2", async (args) => {
151+
const run = await runAsAgent(args.split(" "));
152+
expectQuiet(run);
153+
expect(run.code, run.stderr).toBe(2);
154+
});
143155
});

‎packages/cli/src/commands/capture.test.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ import {
1212
import { tmpdir } from "node:os";
1313
import { join } from "node:path";
1414
import { pathToFileURL } from "node:url";
15-
import { CliRuntimeError, registerRootExitRequester } from "../utils/commandResult.js";
15+
import {
16+
CliRuntimeError,
17+
CliUsageError,
18+
registerRootExitRequester,
19+
} from "../utils/commandResult.js";
1620
import { CAPTURE_PHASE_SCHEMA } from "../capture/types.js";
1721

1822
const { captureWebsiteMock } = vi.hoisted(() => ({
@@ -228,7 +232,7 @@ describe("capture command — vision control", () => {
228232
captureCommand.run!({
229233
args: { ...target, output: "/tmp/hf-local-refused", json: true },
230234
} as never),
231-
).rejects.toThrow(CliRuntimeError);
235+
).rejects.toThrow("local-root" in target ? CliUsageError : CliRuntimeError);
232236
expect(error.mock.calls.flat().join("\n")).toContain(message);
233237
expect(captureWebsiteMock).not.toHaveBeenCalled();
234238
});

‎packages/cli/src/commands/capture.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { DEFAULT_MAX_SCREENSHOTS } from "../capture/types.js";
2-
import { failCommand, scheduleCliExit } from "../utils/commandResult.js";
2+
import { failCommand, scheduleCliExit, failUsage } from "../utils/commandResult.js";
33
import { defineCommand } from "../utils/defineCommand.js";
44
import { resolve } from "node:path";
55
import type { Example } from "./_examples.js";
@@ -163,13 +163,13 @@ export default defineCommand({
163163
} else {
164164
if (localRoot !== undefined) {
165165
console.error("--local-root requires --local-file.");
166-
failCommand();
166+
failUsage();
167167
}
168168
if (!url) {
169169
console.error(
170170
"Missing URL. Pass a website URL, --local-file <path>, or --video <project> for video download.",
171171
);
172-
failCommand();
172+
failUsage();
173173
}
174174
try {
175175
new URL(url);

‎packages/cli/src/commands/cloud/render.test.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
validateDryRunSource,
1212
type ProjectInputSource,
1313
} from "./render.js";
14-
import { CliRuntimeError } from "../../utils/commandResult.js";
14+
import { CliRuntimeError, CliUsageError } from "../../utils/commandResult.js";
1515

1616
const cliEntry = resolve(fileURLToPath(import.meta.url), "..", "..", "..", "cli.ts");
1717

@@ -39,11 +39,11 @@ describe("validateDryRunSource", () => {
3939
it("accepts a local directory and rejects already-uploaded sources", () => {
4040
expect(() => validateDryRunSource({ kind: "dir", dir: "." }, true)).not.toThrow();
4141
expect(() => validateDryRunSource({ kind: "asset_id", assetId: "asst_123" }, true)).toThrow(
42-
CliRuntimeError,
42+
CliUsageError,
4343
);
4444
expect(() =>
4545
validateDryRunSource({ kind: "url", url: "https://example.com/project.zip" }, true),
46-
).toThrow(CliRuntimeError);
46+
).toThrow(CliUsageError);
4747
});
4848
});
4949

‎packages/cli/src/commands/cloud/render.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { failCommand } from "../../utils/commandResult.js";
1+
import { failCommand, failUsage } from "../../utils/commandResult.js";
22
/**
33
* `hyperframes cloud render` — orchestrate a cloud-rendered HyperFrames
44
* composition end-to-end:
@@ -384,7 +384,7 @@ function validateIdempotencyKey(key: string | undefined): void {
384384
if (key === undefined) return;
385385
if (!IDEMPOTENCY_KEY_RE.test(key)) {
386386
errorBox("Invalid --idempotency-key", `Got "${key}". Must be 1-255 chars from [A-Za-z0-9_:.-]`);
387-
failCommand();
387+
failUsage();
388388
}
389389
}
390390

@@ -394,7 +394,7 @@ export function validateDryRunSource(source: ProjectInputSource, dryRun: boolean
394394
"Invalid --dry-run input",
395395
"--dry-run inspects a local project directory and cannot be combined with --asset-id or --url.",
396396
);
397-
failCommand();
397+
failUsage();
398398
}
399399

400400
// ---------------------------------------------------------------------------

‎packages/cli/src/commands/cloudrun.ts‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// fallow-ignore-file code-duplication
2-
import { failCommand } from "../utils/commandResult.js";
2+
import { failCommand, failUsage } from "../utils/commandResult.js";
33
/**
44
* `hyperframes cloudrun` — deploy + drive distributed renders on Google
55
* Cloud Run + Cloud Workflows.
@@ -327,7 +327,7 @@ async function runDeploy(args: Record<string, unknown>): Promise<void> {
327327
const project = args.project as string | undefined;
328328
if (!project) {
329329
console.error("[cloudrun deploy] --project <gcp-project-id> is required.");
330-
failCommand();
330+
failUsage();
331331
}
332332
const region = (args.region as string | undefined) ?? "us-central1";
333333
const repo = (args.repo as string | undefined) ?? "hyperframes";
@@ -355,7 +355,7 @@ async function runDeploy(args: Record<string, unknown>): Promise<void> {
355355
console.error(
356356
"[cloudrun deploy] --image is required when not running from a hyperframes checkout (no Dockerfile context found).",
357357
);
358-
failCommand();
358+
failUsage();
359359
}
360360
// Ensure the Artifact Registry repo exists.
361361
const exists =
@@ -497,7 +497,7 @@ async function runSites(args: Record<string, unknown>): Promise<void> {
497497
const projectDir = args.extra as string | undefined;
498498
if (!projectDir) {
499499
console.error("[cloudrun sites create] usage: hyperframes cloudrun sites create <projectDir>");
500-
failCommand();
500+
failUsage();
501501
}
502502
const state = readState(args);
503503
const { deploySite } = await loadCloudRunAdapter();
@@ -538,7 +538,7 @@ async function runRender(args: Record<string, unknown>): Promise<void> {
538538
console.error(
539539
"[cloudrun render] usage: hyperframes cloudrun render <projectDir> --width <px> --height <px>",
540540
);
541-
failCommand();
541+
failUsage();
542542
}
543543
const width = parsePositiveInt(args.width, "--width");
544544
const height = parsePositiveInt(args.height, "--height");
@@ -604,7 +604,7 @@ async function runProgress(args: Record<string, unknown>): Promise<void> {
604604
const executionName = args.target as string | undefined;
605605
if (!executionName) {
606606
console.error("[cloudrun progress] usage: hyperframes cloudrun progress <executionName>");
607-
failCommand();
607+
failUsage();
608608
}
609609
const { getRenderProgress } = await loadCloudRunAdapter();
610610
const progress = await getRenderProgress({ executionName });
@@ -644,7 +644,7 @@ async function runRenderBatch(args: Record<string, unknown>): Promise<void> {
644644
console.error(
645645
"[cloudrun render-batch] usage: hyperframes cloudrun render-batch <projectDir> --batch <file.jsonl> --width <px> --height <px>",
646646
);
647-
failCommand();
647+
failUsage();
648648
}
649649
const width = parsePositiveInt(args.width, "--width");
650650
const height = parsePositiveInt(args.height, "--height");
@@ -774,7 +774,7 @@ async function runDestroy(args: Record<string, unknown>): Promise<void> {
774774
const image = (args.image as string | undefined) ?? "unused:latest";
775775
if (!project) {
776776
console.error("[cloudrun destroy] --project is required (or deploy first to cache it).");
777-
failCommand();
777+
failUsage();
778778
}
779779
const vars = [
780780
"-var",

‎packages/cli/src/commands/init.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ describe("applyResolutionPreset", () => {
682682
"--non-interactive",
683683
"--skip-skills",
684684
]);
685-
expect(res.status).toBe(1);
685+
expect(res.status).toBe(2);
686686
expect(res.stderr).toContain("Invalid --resolution");
687687
expect(existsSync(target)).toBe(false);
688688
} finally {

‎packages/cli/src/commands/init.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// This branch only repointed the scaffolded npm scripts; the refactor is its
44
// own task.
55
// fallow-ignore-file complexity
6-
import { failCommand, finishCommand } from "../utils/commandResult.js";
6+
import { failCommand, finishCommand, failUsage } from "../utils/commandResult.js";
77
import { writeNewFileSync } from "../utils/writeNewFile.js";
88
import { runCommand } from "citty";
99
import { defineCommand } from "../utils/defineCommand.js";
@@ -838,7 +838,7 @@ export default defineCommand({
838838
`(or aliases 1080p, 4k, uhd, 1080p-square, square-1080p, 4k-square).`,
839839
),
840840
);
841-
failCommand();
841+
failUsage();
842842
}
843843
}
844844

‎packages/cli/src/commands/lambda.ts‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { failCommand } from "../utils/commandResult.js";
1+
import { failCommand, failUsage } from "../utils/commandResult.js";
22
/**
33
* `hyperframes lambda` — top-level dispatcher for AWS Lambda subcommands.
44
*
@@ -296,7 +296,7 @@ export default defineCommand({
296296
console.error(
297297
"[lambda sites create] usage: hyperframes lambda sites create <projectDir>",
298298
);
299-
failCommand();
299+
failUsage();
300300
}
301301
const { runSitesCreate } = await import("./lambda/sites.js");
302302
await runSitesCreate({
@@ -313,7 +313,7 @@ export default defineCommand({
313313
console.error(
314314
"[lambda render] usage: hyperframes lambda render <projectDir> --width <px> --height <px>",
315315
);
316-
failCommand();
316+
failUsage();
317317
}
318318
const width = parsePositiveInt(args.width, "--width");
319319
const height = parsePositiveInt(args.height, "--height");
@@ -363,14 +363,14 @@ export default defineCommand({
363363
console.error(
364364
"[lambda render-batch] usage: hyperframes lambda render-batch <projectDir> --batch <path.jsonl> --width <px> --height <px>",
365365
);
366-
failCommand();
366+
failUsage();
367367
}
368368
const batch = args.batch as string | undefined;
369369
if (!batch) {
370370
console.error(
371371
"[lambda render-batch] --batch <path.jsonl> is required. Each line is a JSON object with at least { outputKey: '...' }.",
372372
);
373-
failCommand();
373+
failUsage();
374374
}
375375
const width = parsePositiveInt(args.width, "--width");
376376
const height = parsePositiveInt(args.height, "--height");
@@ -417,7 +417,7 @@ export default defineCommand({
417417
console.error(
418418
"[lambda progress] usage: hyperframes lambda progress <renderId | executionArn>",
419419
);
420-
failCommand();
420+
failUsage();
421421
}
422422
const { runProgress } = await import("./lambda/progress.js");
423423
await runProgress({ target, stackName, json: Boolean(args.json) });
@@ -434,7 +434,7 @@ export default defineCommand({
434434
console.error(
435435
`[lambda policies] usage: hyperframes lambda policies <role|user|validate> [args]`,
436436
);
437-
failCommand();
437+
failUsage();
438438
}
439439
const { runPolicies } = await import("./lambda/policies.js");
440440
await runPolicies({

‎packages/cli/src/commands/lambda/policies.ts‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { setCommandExitCode } from "../../utils/commandResult.js";
1+
import { CliUsageError, failUsage, setCommandExitCode } from "../../utils/commandResult.js";
22
/**
33
* `hyperframes lambda policies role|user|validate` — IAM bootstrap.
44
*
@@ -265,10 +265,9 @@ export async function runPolicies(args: PoliciesArgs): Promise<void> {
265265
"[lambda policies validate] usage: hyperframes lambda policies validate <policy.json>";
266266
if (args.json) {
267267
console.log(JSON.stringify({ ok: false, error: msg }, null, 2));
268-
setCommandExitCode(1);
269-
return;
268+
failUsage();
270269
}
271-
throw new Error(msg);
270+
throw new CliUsageError(msg);
272271
}
273272
let result: ValidateResult;
274273
try {

0 commit comments

Comments
 (0)