The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import * as NodeFS from "node:fs"; |
| 2 | |
| 3 | const argv = process.argv.slice(2); |
| 4 | const args = argv.join(" "); |
| 5 | |
| 6 | function fail(message, code) { |
| 7 | process.stderr.write(message + "\n"); |
| 8 | process.exit(code); |
| 9 | } |
| 10 | |
| 11 | const permissionIndex = argv.indexOf("--permission-mode"); |
| 12 | if (permissionIndex === -1 || argv[permissionIndex + 1] !== "dontAsk") { |
| 13 | fail("text generation must deny permission prompts", 12); |
| 14 | } |
| 15 | const toolsIndex = argv.indexOf("--tools"); |
| 16 | if ( |
| 17 | toolsIndex === -1 || |
| 18 | argv[toolsIndex + 1] !== (process.env.T3_FAKE_CLAUDE_EXPECTED_TOOLS ?? "") |
| 19 | ) { |
| 20 | fail("text generation did not receive the expected tool set", 6); |
| 21 | } |
| 22 | if (argv.includes("--dangerously-skip-permissions")) { |
| 23 | fail("text generation must not bypass permissions", 7); |
| 24 | } |
| 25 | if (!argv.includes("--disable-slash-commands")) { |
| 26 | fail("text generation must disable skills", 8); |
| 27 | } |
| 28 | if (!argv.includes("--strict-mcp-config")) { |
| 29 | fail("text generation must not load configured MCP servers", 9); |
| 30 | } |
| 31 | if (process.env.T3_FAKE_CLAUDE_REJECTS_NO_SESSION_PERSISTENCE === "1") { |
| 32 | if (argv.includes("--no-session-persistence")) { |
| 33 | fail("error: unknown option '--no-session-persistence'", 1); |
| 34 | } |
| 35 | } else if (!argv.includes("--no-session-persistence")) { |
| 36 | fail("text generation must not save a resumable session", 16); |
| 37 | } |
| 38 | const settingsIndex = argv.indexOf("--settings"); |
| 39 | if (settingsIndex === -1 || JSON.parse(argv[settingsIndex + 1]).disableAllHooks !== true) { |
| 40 | fail("text generation must disable hooks", 10); |
| 41 | } |
| 42 | const cwdMustNotBe = process.env.T3_FAKE_CLAUDE_CWD_MUST_NOT_BE; |
| 43 | if (cwdMustNotBe && NodeFS.realpathSync(process.cwd()) === NodeFS.realpathSync(cwdMustNotBe)) { |
| 44 | fail("text generation ran in the project directory", 11); |
| 45 | } |
| 46 | |
| 47 | let stdinContent = ""; |
| 48 | if (!process.stdin.isTTY) { |
| 49 | const chunks = []; |
| 50 | for await (const chunk of process.stdin) { |
| 51 | chunks.push(chunk); |
| 52 | } |
| 53 | stdinContent = Buffer.concat(chunks).toString("utf8"); |
| 54 | } |
| 55 | |
| 56 | const argsMustContain = process.env.T3_FAKE_CLAUDE_ARGS_MUST_CONTAIN; |
| 57 | if (argsMustContain && !args.includes(argsMustContain)) { |
| 58 | fail("args missing expected content", 2); |
| 59 | } |
| 60 | |
| 61 | const argsMustNotContain = process.env.T3_FAKE_CLAUDE_ARGS_MUST_NOT_CONTAIN; |
| 62 | if (argsMustNotContain && args.includes(argsMustNotContain)) { |
| 63 | fail("args contained forbidden content", 3); |
| 64 | } |
| 65 | |
| 66 | const stdinMustContain = process.env.T3_FAKE_CLAUDE_STDIN_MUST_CONTAIN; |
| 67 | if (stdinMustContain && !stdinContent.includes(stdinMustContain)) { |
| 68 | fail("stdin missing expected content", 4); |
| 69 | } |
| 70 | |
| 71 | if (process.env.T3_FAKE_CLAUDE_REJECTS_IMAGES === "1" && stdinContent.includes('"type":"image"')) { |
| 72 | process.stdout.write( |
| 73 | JSON.stringify({ |
| 74 | type: "result", |
| 75 | subtype: "success", |
| 76 | is_error: true, |
| 77 | api_error_status: 400, |
| 78 | result: "API Error: 400 Image inputs are not supported by this model", |
| 79 | }) + "\n", |
| 80 | ); |
| 81 | process.exit(1); |
| 82 | } |
| 83 | |
| 84 | const configDirMustBe = process.env.T3_FAKE_CLAUDE_CONFIG_DIR_MUST_BE; |
| 85 | if (configDirMustBe && process.env.CLAUDE_CONFIG_DIR !== configDirMustBe) { |
| 86 | fail("CLAUDE_CONFIG_DIR was " + (process.env.CLAUDE_CONFIG_DIR ?? ""), 5); |
| 87 | } |
| 88 | |
| 89 | const stderrText = process.env.T3_FAKE_CLAUDE_STDERR; |
| 90 | if (stderrText) { |
| 91 | process.stderr.write(stderrText + "\n"); |
| 92 | } |
| 93 | |
| 94 | process.stdout.write(process.env.T3_FAKE_CLAUDE_OUTPUT ?? ""); |
| 95 | process.exitCode = Number(process.env.T3_FAKE_CLAUDE_EXIT_CODE ?? 0); |