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

ProviderInstanceRegistryLive.fixture.mjs

76 lines2.4 KB

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