@adithya-13/cc-switch 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/cclaude.js +21 -9
- package/package.json +1 -1
package/bin/cclaude.js
CHANGED
|
@@ -57,22 +57,34 @@ const settings = readSettings();
|
|
|
57
57
|
const current = getCurrentProvider(settings);
|
|
58
58
|
|
|
59
59
|
const child = spawn("claude", process.argv.slice(2), {
|
|
60
|
-
stdio: ["inherit", "
|
|
60
|
+
stdio: ["inherit", "pipe", "pipe"], // intercept both stdout and stderr
|
|
61
61
|
});
|
|
62
62
|
|
|
63
|
-
let
|
|
63
|
+
let combinedBuffer = "";
|
|
64
|
+
let notified = false;
|
|
64
65
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
process.stderr.write(data); // still show to user
|
|
69
|
-
|
|
70
|
-
const isRateLimit = RATE_LIMIT_PATTERNS.some((p) => p.test(stderrBuffer));
|
|
66
|
+
function checkRateLimit(text) {
|
|
67
|
+
if (notified) return;
|
|
68
|
+
const isRateLimit = RATE_LIMIT_PATTERNS.some((p) => p.test(text));
|
|
71
69
|
if (isRateLimit) {
|
|
72
70
|
const fallbacks = getAvailableFallbacks(current);
|
|
73
71
|
notifyRateLimit(current, fallbacks);
|
|
74
|
-
|
|
72
|
+
notified = true; // only notify once
|
|
75
73
|
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
child.stdout.on("data", (data) => {
|
|
77
|
+
const text = data.toString();
|
|
78
|
+
combinedBuffer += text;
|
|
79
|
+
process.stdout.write(data); // forward to user
|
|
80
|
+
checkRateLimit(combinedBuffer);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
child.stderr.on("data", (data) => {
|
|
84
|
+
const text = data.toString();
|
|
85
|
+
combinedBuffer += text;
|
|
86
|
+
process.stderr.write(data); // forward to user
|
|
87
|
+
checkRateLimit(combinedBuffer);
|
|
76
88
|
});
|
|
77
89
|
|
|
78
90
|
child.on("exit", (code) => process.exit(code ?? 0));
|