@musistudio/claude-code-router 1.0.53 → 1.0.54

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.
Files changed (2) hide show
  1. package/dist/cli.js +272 -26
  2. package/package.json +2 -1
package/dist/cli.js CHANGED
@@ -66054,7 +66054,7 @@ var require_package3 = __commonJS({
66054
66054
  "package.json"(exports2, module2) {
66055
66055
  module2.exports = {
66056
66056
  name: "@musistudio/claude-code-router",
66057
- version: "1.0.53",
66057
+ version: "1.0.54",
66058
66058
  description: "Use Claude Code without an Anthropics account and route it to another LLM provider",
66059
66059
  bin: {
66060
66060
  ccr: "dist/cli.js"
@@ -66078,6 +66078,7 @@ var require_package3 = __commonJS({
66078
66078
  dotenv: "^16.4.7",
66079
66079
  "find-process": "^2.0.0",
66080
66080
  json5: "^2.2.3",
66081
+ minimist: "^1.2.8",
66081
66082
  openurl: "^1.1.1",
66082
66083
  "rotating-file-stream": "^3.2.7",
66083
66084
  "shell-quote": "^1.8.3",
@@ -67751,6 +67752,228 @@ var require_shell_quote = __commonJS({
67751
67752
  }
67752
67753
  });
67753
67754
 
67755
+ // node_modules/.pnpm/minimist@1.2.8/node_modules/minimist/index.js
67756
+ var require_minimist = __commonJS({
67757
+ "node_modules/.pnpm/minimist@1.2.8/node_modules/minimist/index.js"(exports2, module2) {
67758
+ "use strict";
67759
+ function hasKey(obj, keys) {
67760
+ var o = obj;
67761
+ keys.slice(0, -1).forEach(function(key2) {
67762
+ o = o[key2] || {};
67763
+ });
67764
+ var key = keys[keys.length - 1];
67765
+ return key in o;
67766
+ }
67767
+ function isNumber(x) {
67768
+ if (typeof x === "number") {
67769
+ return true;
67770
+ }
67771
+ if (/^0x[0-9a-f]+$/i.test(x)) {
67772
+ return true;
67773
+ }
67774
+ return /^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(x);
67775
+ }
67776
+ function isConstructorOrProto(obj, key) {
67777
+ return key === "constructor" && typeof obj[key] === "function" || key === "__proto__";
67778
+ }
67779
+ module2.exports = function(args, opts) {
67780
+ if (!opts) {
67781
+ opts = {};
67782
+ }
67783
+ var flags = {
67784
+ bools: {},
67785
+ strings: {},
67786
+ unknownFn: null
67787
+ };
67788
+ if (typeof opts.unknown === "function") {
67789
+ flags.unknownFn = opts.unknown;
67790
+ }
67791
+ if (typeof opts.boolean === "boolean" && opts.boolean) {
67792
+ flags.allBools = true;
67793
+ } else {
67794
+ [].concat(opts.boolean).filter(Boolean).forEach(function(key2) {
67795
+ flags.bools[key2] = true;
67796
+ });
67797
+ }
67798
+ var aliases = {};
67799
+ function aliasIsBoolean(key2) {
67800
+ return aliases[key2].some(function(x) {
67801
+ return flags.bools[x];
67802
+ });
67803
+ }
67804
+ Object.keys(opts.alias || {}).forEach(function(key2) {
67805
+ aliases[key2] = [].concat(opts.alias[key2]);
67806
+ aliases[key2].forEach(function(x) {
67807
+ aliases[x] = [key2].concat(aliases[key2].filter(function(y) {
67808
+ return x !== y;
67809
+ }));
67810
+ });
67811
+ });
67812
+ [].concat(opts.string).filter(Boolean).forEach(function(key2) {
67813
+ flags.strings[key2] = true;
67814
+ if (aliases[key2]) {
67815
+ [].concat(aliases[key2]).forEach(function(k) {
67816
+ flags.strings[k] = true;
67817
+ });
67818
+ }
67819
+ });
67820
+ var defaults = opts.default || {};
67821
+ var argv = { _: [] };
67822
+ function argDefined(key2, arg2) {
67823
+ return flags.allBools && /^--[^=]+$/.test(arg2) || flags.strings[key2] || flags.bools[key2] || aliases[key2];
67824
+ }
67825
+ function setKey(obj, keys, value2) {
67826
+ var o = obj;
67827
+ for (var i2 = 0; i2 < keys.length - 1; i2++) {
67828
+ var key2 = keys[i2];
67829
+ if (isConstructorOrProto(o, key2)) {
67830
+ return;
67831
+ }
67832
+ if (o[key2] === void 0) {
67833
+ o[key2] = {};
67834
+ }
67835
+ if (o[key2] === Object.prototype || o[key2] === Number.prototype || o[key2] === String.prototype) {
67836
+ o[key2] = {};
67837
+ }
67838
+ if (o[key2] === Array.prototype) {
67839
+ o[key2] = [];
67840
+ }
67841
+ o = o[key2];
67842
+ }
67843
+ var lastKey = keys[keys.length - 1];
67844
+ if (isConstructorOrProto(o, lastKey)) {
67845
+ return;
67846
+ }
67847
+ if (o === Object.prototype || o === Number.prototype || o === String.prototype) {
67848
+ o = {};
67849
+ }
67850
+ if (o === Array.prototype) {
67851
+ o = [];
67852
+ }
67853
+ if (o[lastKey] === void 0 || flags.bools[lastKey] || typeof o[lastKey] === "boolean") {
67854
+ o[lastKey] = value2;
67855
+ } else if (Array.isArray(o[lastKey])) {
67856
+ o[lastKey].push(value2);
67857
+ } else {
67858
+ o[lastKey] = [o[lastKey], value2];
67859
+ }
67860
+ }
67861
+ function setArg(key2, val, arg2) {
67862
+ if (arg2 && flags.unknownFn && !argDefined(key2, arg2)) {
67863
+ if (flags.unknownFn(arg2) === false) {
67864
+ return;
67865
+ }
67866
+ }
67867
+ var value2 = !flags.strings[key2] && isNumber(val) ? Number(val) : val;
67868
+ setKey(argv, key2.split("."), value2);
67869
+ (aliases[key2] || []).forEach(function(x) {
67870
+ setKey(argv, x.split("."), value2);
67871
+ });
67872
+ }
67873
+ Object.keys(flags.bools).forEach(function(key2) {
67874
+ setArg(key2, defaults[key2] === void 0 ? false : defaults[key2]);
67875
+ });
67876
+ var notFlags = [];
67877
+ if (args.indexOf("--") !== -1) {
67878
+ notFlags = args.slice(args.indexOf("--") + 1);
67879
+ args = args.slice(0, args.indexOf("--"));
67880
+ }
67881
+ for (var i = 0; i < args.length; i++) {
67882
+ var arg = args[i];
67883
+ var key;
67884
+ var next;
67885
+ if (/^--.+=/.test(arg)) {
67886
+ var m = arg.match(/^--([^=]+)=([\s\S]*)$/);
67887
+ key = m[1];
67888
+ var value = m[2];
67889
+ if (flags.bools[key]) {
67890
+ value = value !== "false";
67891
+ }
67892
+ setArg(key, value, arg);
67893
+ } else if (/^--no-.+/.test(arg)) {
67894
+ key = arg.match(/^--no-(.+)/)[1];
67895
+ setArg(key, false, arg);
67896
+ } else if (/^--.+/.test(arg)) {
67897
+ key = arg.match(/^--(.+)/)[1];
67898
+ next = args[i + 1];
67899
+ if (next !== void 0 && !/^(-|--)[^-]/.test(next) && !flags.bools[key] && !flags.allBools && (aliases[key] ? !aliasIsBoolean(key) : true)) {
67900
+ setArg(key, next, arg);
67901
+ i += 1;
67902
+ } else if (/^(true|false)$/.test(next)) {
67903
+ setArg(key, next === "true", arg);
67904
+ i += 1;
67905
+ } else {
67906
+ setArg(key, flags.strings[key] ? "" : true, arg);
67907
+ }
67908
+ } else if (/^-[^-]+/.test(arg)) {
67909
+ var letters = arg.slice(1, -1).split("");
67910
+ var broken = false;
67911
+ for (var j = 0; j < letters.length; j++) {
67912
+ next = arg.slice(j + 2);
67913
+ if (next === "-") {
67914
+ setArg(letters[j], next, arg);
67915
+ continue;
67916
+ }
67917
+ if (/[A-Za-z]/.test(letters[j]) && next[0] === "=") {
67918
+ setArg(letters[j], next.slice(1), arg);
67919
+ broken = true;
67920
+ break;
67921
+ }
67922
+ if (/[A-Za-z]/.test(letters[j]) && /-?\d+(\.\d*)?(e-?\d+)?$/.test(next)) {
67923
+ setArg(letters[j], next, arg);
67924
+ broken = true;
67925
+ break;
67926
+ }
67927
+ if (letters[j + 1] && letters[j + 1].match(/\W/)) {
67928
+ setArg(letters[j], arg.slice(j + 2), arg);
67929
+ broken = true;
67930
+ break;
67931
+ } else {
67932
+ setArg(letters[j], flags.strings[letters[j]] ? "" : true, arg);
67933
+ }
67934
+ }
67935
+ key = arg.slice(-1)[0];
67936
+ if (!broken && key !== "-") {
67937
+ if (args[i + 1] && !/^(-|--)[^-]/.test(args[i + 1]) && !flags.bools[key] && (aliases[key] ? !aliasIsBoolean(key) : true)) {
67938
+ setArg(key, args[i + 1], arg);
67939
+ i += 1;
67940
+ } else if (args[i + 1] && /^(true|false)$/.test(args[i + 1])) {
67941
+ setArg(key, args[i + 1] === "true", arg);
67942
+ i += 1;
67943
+ } else {
67944
+ setArg(key, flags.strings[key] ? "" : true, arg);
67945
+ }
67946
+ }
67947
+ } else {
67948
+ if (!flags.unknownFn || flags.unknownFn(arg) !== false) {
67949
+ argv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));
67950
+ }
67951
+ if (opts.stopEarly) {
67952
+ argv._.push.apply(argv._, args.slice(i + 1));
67953
+ break;
67954
+ }
67955
+ }
67956
+ }
67957
+ Object.keys(defaults).forEach(function(k) {
67958
+ if (!hasKey(argv, k.split("."))) {
67959
+ setKey(argv, k.split("."), defaults[k]);
67960
+ (aliases[k] || []).forEach(function(x) {
67961
+ setKey(argv, x.split("."), defaults[k]);
67962
+ });
67963
+ }
67964
+ });
67965
+ if (opts["--"]) {
67966
+ argv["--"] = notFlags.slice();
67967
+ } else {
67968
+ notFlags.forEach(function(k) {
67969
+ argv._.push(k);
67970
+ });
67971
+ }
67972
+ return argv;
67973
+ };
67974
+ }
67975
+ });
67976
+
67754
67977
  // src/index.ts
67755
67978
  var import_fs5 = require("fs");
67756
67979
  var import_promises5 = require("fs/promises");
@@ -79357,14 +79580,7 @@ var import_fs3 = require("fs");
79357
79580
  init_constants();
79358
79581
  init_utils();
79359
79582
  var import_find_process = __toESM(require_dist6());
79360
- async function isProcessRunning(pid) {
79361
- try {
79362
- const processes = await (0, import_find_process.default)("pid", pid);
79363
- return processes.length > 0;
79364
- } catch (error) {
79365
- return false;
79366
- }
79367
- }
79583
+ var import_child_process2 = require("child_process");
79368
79584
  function incrementReferenceCount() {
79369
79585
  let count = 0;
79370
79586
  if ((0, import_fs3.existsSync)(REFERENCE_COUNT_FILE)) {
@@ -79387,13 +79603,35 @@ function getReferenceCount() {
79387
79603
  }
79388
79604
  return parseInt((0, import_fs3.readFileSync)(REFERENCE_COUNT_FILE, "utf-8")) || 0;
79389
79605
  }
79390
- async function isServiceRunning() {
79606
+ function isServiceRunning() {
79391
79607
  if (!(0, import_fs3.existsSync)(PID_FILE)) {
79392
79608
  return false;
79393
79609
  }
79610
+ let pid;
79394
79611
  try {
79395
- const pid = parseInt((0, import_fs3.readFileSync)(PID_FILE, "utf-8"));
79396
- return await isProcessRunning(pid);
79612
+ const pidStr = (0, import_fs3.readFileSync)(PID_FILE, "utf-8");
79613
+ pid = parseInt(pidStr, 10);
79614
+ if (isNaN(pid)) {
79615
+ cleanupPidFile();
79616
+ return false;
79617
+ }
79618
+ } catch (e) {
79619
+ return false;
79620
+ }
79621
+ try {
79622
+ if (process.platform === "win32") {
79623
+ const command2 = `tasklist /FI "PID eq ${pid}"`;
79624
+ const output = (0, import_child_process2.execSync)(command2, { stdio: "pipe" }).toString();
79625
+ if (output.includes(pid.toString())) {
79626
+ return true;
79627
+ } else {
79628
+ cleanupPidFile();
79629
+ return false;
79630
+ }
79631
+ } else {
79632
+ process.kill(pid, 0);
79633
+ return true;
79634
+ }
79397
79635
  } catch (e) {
79398
79636
  cleanupPidFile();
79399
79637
  return false;
@@ -79441,7 +79679,7 @@ async function getServiceInfo() {
79441
79679
  init_constants();
79442
79680
 
79443
79681
  // node_modules/.pnpm/rotating-file-stream@3.2.7/node_modules/rotating-file-stream/dist/esm/index.js
79444
- var import_child_process2 = require("child_process");
79682
+ var import_child_process3 = require("child_process");
79445
79683
  var import_zlib = require("zlib");
79446
79684
  var import_stream = require("stream");
79447
79685
  var import_fs4 = require("fs");
@@ -79486,7 +79724,7 @@ var RotatingFileStream = class extends import_stream.Writable {
79486
79724
  const { encoding, history, maxFiles, maxSize, path: path6 } = options;
79487
79725
  super({ decodeStrings: true, defaultEncoding: encoding });
79488
79726
  this.createGzip = import_zlib.createGzip;
79489
- this.exec = import_child_process2.exec;
79727
+ this.exec = import_child_process3.exec;
79490
79728
  this.filename = path6 + generator(null);
79491
79729
  this.fsCreateReadStream = import_fs4.createReadStream;
79492
79730
  this.fsCreateWriteStream = import_fs4.createWriteStream;
@@ -82127,7 +82365,7 @@ async function showStatus() {
82127
82365
  }
82128
82366
 
82129
82367
  // src/utils/codeCommand.ts
82130
- var import_child_process3 = require("child_process");
82368
+ var import_child_process4 = require("child_process");
82131
82369
  init_utils();
82132
82370
 
82133
82371
  // src/utils/close.ts
@@ -82157,6 +82395,7 @@ async function closeService() {
82157
82395
 
82158
82396
  // src/utils/codeCommand.ts
82159
82397
  var import_shell_quote = __toESM(require_shell_quote());
82398
+ var import_minimist = __toESM(require_minimist());
82160
82399
  async function executeCodeCommand(args = []) {
82161
82400
  const config = await readConfigFile();
82162
82401
  const port = config.PORT || 3456;
@@ -82194,9 +82433,16 @@ async function executeCodeCommand(args = []) {
82194
82433
  const claudePath = config?.CLAUDE_PATH || process.env.CLAUDE_PATH || "claude";
82195
82434
  const joinedArgs = args.length > 0 ? (0, import_shell_quote.quote)(args) : "";
82196
82435
  const stdioConfig = config.NON_INTERACTIVE_MODE ? ["pipe", "inherit", "inherit"] : "inherit";
82197
- const claudeProcess = (0, import_child_process3.spawn)(
82198
- claudePath + (joinedArgs ? ` ${joinedArgs}` : ""),
82199
- [],
82436
+ const argsObj = (0, import_minimist.default)(args);
82437
+ const argsArr = [];
82438
+ for (const [argsObjKey, argsObjValue] of Object.entries(argsObj)) {
82439
+ if (argsObjKey !== "_" && argsObj[argsObjKey]) {
82440
+ argsArr.push(`${argsObjKey.length === 1 ? "-" : "--"}${argsObjKey} ${JSON.stringify(argsObjValue)}`);
82441
+ }
82442
+ }
82443
+ const claudeProcess = (0, import_child_process4.spawn)(
82444
+ claudePath,
82445
+ argsArr,
82200
82446
  {
82201
82447
  env: process.env,
82202
82448
  stdio: stdioConfig,
@@ -82223,7 +82469,7 @@ async function executeCodeCommand(args = []) {
82223
82469
 
82224
82470
  // src/utils/statusline.ts
82225
82471
  var import_promises6 = __toESM(require("node:fs/promises"));
82226
- var import_child_process4 = require("child_process");
82472
+ var import_child_process5 = require("child_process");
82227
82473
  var import_node_path5 = __toESM(require("node:path"));
82228
82474
  init_constants();
82229
82475
  var import_json53 = __toESM(require_lib());
@@ -82517,7 +82763,7 @@ async function parseStatusLineData(input) {
82517
82763
  const workDir = input.workspace.current_dir;
82518
82764
  let gitBranch = "";
82519
82765
  try {
82520
- gitBranch = (0, import_child_process4.execSync)("git branch --show-current", {
82766
+ gitBranch = (0, import_child_process5.execSync)("git branch --show-current", {
82521
82767
  cwd: workDir,
82522
82768
  stdio: ["pipe", "pipe", "ignore"]
82523
82769
  }).toString().trim();
@@ -82769,7 +83015,7 @@ async function renderPowerlineStyle(theme, variables) {
82769
83015
 
82770
83016
  // src/cli.ts
82771
83017
  var import_package = __toESM(require_package3());
82772
- var import_child_process5 = require("child_process");
83018
+ var import_child_process6 = require("child_process");
82773
83019
  init_constants();
82774
83020
  var import_fs7 = __toESM(require("fs"));
82775
83021
  var import_path6 = require("path");
@@ -82860,7 +83106,7 @@ async function main() {
82860
83106
  if (!isRunning) {
82861
83107
  console.log("Service not running, starting service...");
82862
83108
  const cliPath2 = (0, import_path6.join)(__dirname, "cli.js");
82863
- const startProcess2 = (0, import_child_process5.spawn)("node", [cliPath2, "start"], {
83109
+ const startProcess2 = (0, import_child_process6.spawn)("node", [cliPath2, "start"], {
82864
83110
  detached: true,
82865
83111
  stdio: "ignore"
82866
83112
  });
@@ -82887,7 +83133,7 @@ async function main() {
82887
83133
  if (!isRunning) {
82888
83134
  console.log("Service not running, starting service...");
82889
83135
  const cliPath2 = (0, import_path6.join)(__dirname, "cli.js");
82890
- const startProcess2 = (0, import_child_process5.spawn)("node", [cliPath2, "start"], {
83136
+ const startProcess2 = (0, import_child_process6.spawn)("node", [cliPath2, "start"], {
82891
83137
  detached: true,
82892
83138
  stdio: "ignore"
82893
83139
  });
@@ -82924,7 +83170,7 @@ async function main() {
82924
83170
  console.log(
82925
83171
  "Please edit this file with your actual configuration."
82926
83172
  );
82927
- const restartProcess = (0, import_child_process5.spawn)("node", [cliPath2, "start"], {
83173
+ const restartProcess = (0, import_child_process6.spawn)("node", [cliPath2, "start"], {
82928
83174
  detached: true,
82929
83175
  stdio: "ignore"
82930
83176
  });
@@ -82966,7 +83212,7 @@ async function main() {
82966
83212
  console.error("Unsupported platform for opening browser");
82967
83213
  process.exit(1);
82968
83214
  }
82969
- (0, import_child_process5.exec)(openCommand, (error) => {
83215
+ (0, import_child_process6.exec)(openCommand, (error) => {
82970
83216
  if (error) {
82971
83217
  console.error("Failed to open browser:", error.message);
82972
83218
  process.exit(1);
@@ -82995,7 +83241,7 @@ async function main() {
82995
83241
  }
82996
83242
  console.log("Starting claude code router service...");
82997
83243
  const cliPath = (0, import_path6.join)(__dirname, "cli.js");
82998
- const startProcess = (0, import_child_process5.spawn)("node", [cliPath, "start"], {
83244
+ const startProcess = (0, import_child_process6.spawn)("node", [cliPath, "start"], {
82999
83245
  detached: true,
83000
83246
  stdio: "ignore"
83001
83247
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@musistudio/claude-code-router",
3
- "version": "1.0.53",
3
+ "version": "1.0.54",
4
4
  "description": "Use Claude Code without an Anthropics account and route it to another LLM provider",
5
5
  "bin": {
6
6
  "ccr": "dist/cli.js"
@@ -24,6 +24,7 @@
24
24
  "dotenv": "^16.4.7",
25
25
  "find-process": "^2.0.0",
26
26
  "json5": "^2.2.3",
27
+ "minimist": "^1.2.8",
27
28
  "openurl": "^1.1.1",
28
29
  "rotating-file-stream": "^3.2.7",
29
30
  "shell-quote": "^1.8.3",