Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

ProviderInstanceRegistryLive.fixture.mjs

77 lines2.5 KB

1#!/usr/bin/env node
2import * as NodeFS from "node:fs";
3import * as NodeReadline from "node:readline";
4// Opt-in: act like a `claude` wrapper that only runs inside one directory.
5const requiredCwd = process.env.T3_CLAUDE_REQUIRED_CWD;
6if (requiredCwd && process.cwd() !== NodeFS.realpathSync(requiredCwd)) {
7 process.stderr.write(`claude: refusing to run outside ${requiredCwd}\n`);
8 process.exit(1);
9}
10if (process.argv.includes("--version")) {
11 process.stdout.write("claude 2.1.219\n");
12 process.exit(0);
14const lines = NodeReadline.createInterface({ input: process.stdin });
15lines.on("line", (line) => {
16 const message = JSON.parse(line);
17 if (message.type !== "control_request") return;
18 if (message.request?.subtype === "get_usage") {
19 const marker = process.env.T3_CLAUDE_RESET_MARKER;
20 if (process.env.T3_CLAUDE_USAGE_FAILS_AFTER_CLAIM && marker && NodeFS.existsSync(marker)) {
21 process.stdout.write(
22 JSON.stringify({
23 type: "control_response",
24 response: { subtype: "error", request_id: message.request_id, error: "usage failed" },
25 }) + "\n",
26 );
27 return;
28 }
29 process.stdout.write(
30 JSON.stringify({
31 type: "control_response",
32 response: {
33 subtype: "success",
34 request_id: message.request_id,
35 response: {
36 session: {},
37 subscription_type: "pro",
38 rate_limits_available: true,
39 rate_limits: {
40 five_hour: {
41 utilization: marker && NodeFS.existsSync(marker) ? 0 : 100,
42 resets_at: null,
43 },
44 },
45 },
46 },
47 }) + "\n",
48 );
49 return;
50 }
51 if (message.request?.subtype !== "initialize") return;
52 process.stdout.write(
53 JSON.stringify({
54 type: "control_response",
55 response: {
56 subtype: "success",
57 request_id: message.request_id,
58 response: {
59 commands: [],
60 agents: [],
61 models: [],
62 output_style: "default",
63 available_output_styles: ["default"],
64 account: { email: "test@example.com", subscriptionType: "pro", tokenSource: "oauth" },
65 },
66 },
67 }) + "\n",
68 );
69});
70// Stay alive for follow-up control requests, but never outlive the
71// parent: the probe aborts the SDK without awaiting the child, so an
72// unconditional interval would strand this process until reboot.
73const keepAlive = setInterval(() => {}, 1_000);
74lines.on("close", () => {
75 clearInterval(keepAlive);
76 process.exit(0);
77});