mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-19 11:26:02 +00:00
* feat(cli): add agent markers other detectors use, verified upstream Compared std-env, @vercel/detect-agent, am-i-vibing and agent-cli-detector against our rules and kept only markers the agent itself sets on the shells it spawns: Auggie AUGMENT_AGENT, Amp AMP_CURRENT_THREAD_ID, Cursor CURSOR_CONVERSATION_ID and CURSOR_SANDBOX, Cline CLI CLINE_WRAPPER_PATH, Muse MUSE_RELEASE_INFO, and Warp Oz OZ_RUN_ID (after the harnesses it wraps). Claude Code now keys on CLAUDE_CODE_CHILD_SESSION or CLAUDE_CODE_ENTRYPOINT. Its IDE extensions also set CLAUDECODE in the integrated terminal a person types into, so CLAUDECODE alone counted that person as an agent: no prompts, agent-mode login. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * docs(cli): trim comments and fix citations the comment gates flag Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * chore: raise the cli packed size budget to its measured size main already sat at the edge of the 1% tolerance; the new agent rules put the packed CLI 842 bytes past it (8062664 vs 7982002 + 1%). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
105 lines
3.3 KiB
TypeScript
105 lines
3.3 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
|
|
// `driven: undefined` runs the real detection against process.env.
|
|
const agent = vi.hoisted(() => ({ driven: false as boolean | undefined }));
|
|
vi.mock("../telemetry/agent_runtime.js", async (importOriginal) => {
|
|
const actual = await importOriginal<typeof import("../telemetry/agent_runtime.js")>();
|
|
return { ...actual, isAgentDriven: () => agent.driven ?? actual.isAgentDriven() };
|
|
});
|
|
|
|
const ttys = { stdin: process.stdin.isTTY, stdout: process.stdout.isTTY };
|
|
|
|
function setTty(stdin: boolean, stdout: boolean): void {
|
|
Object.defineProperty(process.stdin, "isTTY", { value: stdin, configurable: true });
|
|
Object.defineProperty(process.stdout, "isTTY", { value: stdout, configurable: true });
|
|
}
|
|
|
|
async function load() {
|
|
vi.resetModules();
|
|
return import("./attendedTerminal.js");
|
|
}
|
|
|
|
describe("isCI", () => {
|
|
afterEach(() => vi.unstubAllEnvs());
|
|
|
|
it.each([
|
|
["true", true],
|
|
["1", true],
|
|
["github-actions", true],
|
|
["false", false],
|
|
["0", false],
|
|
["", false],
|
|
])("CI=%j is CI: %s", async (value, expected) => {
|
|
vi.stubEnv("CI", value);
|
|
expect((await load()).isCI()).toBe(expected);
|
|
});
|
|
});
|
|
|
|
describe("isUnattended", () => {
|
|
beforeEach(() => {
|
|
vi.stubEnv("CI", "");
|
|
vi.stubEnv("HYPERFRAMES_AGENT", "");
|
|
agent.driven = false;
|
|
setTty(true, true);
|
|
});
|
|
afterEach(() => {
|
|
vi.unstubAllEnvs();
|
|
setTty(ttys.stdin === true, ttys.stdout === true);
|
|
});
|
|
|
|
it("is attended at a terminal with no CI and no agent", async () => {
|
|
expect((await load()).isUnattended()).toBe(false);
|
|
});
|
|
|
|
it.each([
|
|
[false, true],
|
|
[true, false],
|
|
])("is unattended when stdin is a TTY: %s, stdout is a TTY: %s", async (stdin, stdout) => {
|
|
setTty(stdin, stdout);
|
|
expect((await load()).isUnattended()).toBe(true);
|
|
});
|
|
|
|
it("is unattended in CI", async () => {
|
|
vi.stubEnv("CI", "buildkite");
|
|
expect((await load()).isUnattended()).toBe(true);
|
|
});
|
|
|
|
it("is unattended when a coding agent is detected", async () => {
|
|
agent.driven = true;
|
|
expect((await load()).isUnattended()).toBe(true);
|
|
});
|
|
|
|
it.each([
|
|
["TERM_PROGRAM", "cursor"],
|
|
["TERM_PROGRAM", "windsurf"],
|
|
["REPL_ID", "abc"],
|
|
])(
|
|
"a person in an editor or hosted terminal (%s=%s) at a TTY is attended",
|
|
async (name, value) => {
|
|
for (const key of Object.keys(process.env)) {
|
|
if (
|
|
/^(CLAUDE|CODEX_|CURSOR_|BOBSHELL|GEMINI_CLI|CLINE_|HERMES_|PI_CODING|CRUSH|OPENCLAW|AI_AGENT$|AGENT$|WORKBUDDY_|CODEBUDDY_|ICUBE_|TRAE_|AUTO_PIPPIT|PIPPIT_|DOUBAO_|AILY_|GROK_|KIMI_AGENT|ZCODE_|SWE_AGENT|AUGMENT_AGENT|AMP_CURRENT|MUSE_RELEASE|OZ_RUN|DSH_|COPILOT_|KILO|OPENCODE|QWEN_CODE|JUNIE_|ANTIGRAVITY_|QODER_|AGENT_(DISPLAY|CONTEXT)_OUT)/.test(
|
|
key,
|
|
)
|
|
) {
|
|
vi.stubEnv(key, undefined);
|
|
}
|
|
}
|
|
vi.stubEnv(name, value);
|
|
agent.driven = undefined;
|
|
expect((await load()).isUnattended()).toBe(false);
|
|
},
|
|
);
|
|
|
|
it("Cursor's agent shell is unattended", async () => {
|
|
vi.stubEnv("CURSOR_AGENT", "1");
|
|
agent.driven = undefined;
|
|
expect((await load()).isUnattended()).toBe(true);
|
|
});
|
|
|
|
it("is unattended with HYPERFRAMES_AGENT=1", async () => {
|
|
vi.stubEnv("HYPERFRAMES_AGENT", "1");
|
|
expect((await load()).isUnattended()).toBe(true);
|
|
});
|
|
});
|