mtrx-cli 0.1.10 → 0.1.11

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mtrx-cli",
3
- "version": "0.1.10",
3
+ "version": "0.1.11",
4
4
  "description": "MATRX CLI for routing Codex and Claude through Matrx",
5
5
  "homepage": "https://mtrx.so",
6
6
  "repository": {
@@ -1 +1 @@
1
- __version__ = "0.1.10"
1
+ __version__ = "0.1.11"
@@ -38,8 +38,8 @@ from matrx.cli.cursor_config import (
38
38
  read_cursor_settings,
39
39
  restore_cursor_settings,
40
40
  )
41
- from matrx.cli.cursor_proxy import CursorProxyServer
42
41
  from matrx.cli.state import (
42
+ config_dir,
43
43
  ensure_app_url,
44
44
  ensure_root_url,
45
45
  ensure_v1_url,
@@ -74,7 +74,7 @@ def main(argv: list[str] | None = None) -> int:
74
74
  if args.command in {"codex", "claude"}:
75
75
  return _cmd_launch(args.command, args.route, remainder)
76
76
  if args.command == "cursor":
77
- return _cmd_cursor(args.route, args.port)
77
+ return _cmd_cursor(args.route)
78
78
 
79
79
  parser.print_help()
80
80
  return 1
@@ -115,7 +115,6 @@ def _build_parser() -> argparse.ArgumentParser:
115
115
 
116
116
  cursor = subparsers.add_parser("cursor")
117
117
  cursor.add_argument("--route", choices=["direct", "matrx"])
118
- cursor.add_argument("--port", type=int, default=0)
119
118
 
120
119
  return parser
121
120
 
@@ -489,9 +488,30 @@ def _cmd_use(args) -> int:
489
488
  print(f"Saved to {path}")
490
489
  if args.tool == "claude" and args.route == "direct":
491
490
  _print_claude_shell_proxy_hint()
491
+ if args.tool == "cursor" and args.route == "direct":
492
+ _restore_cursor_if_needed()
492
493
  return 0
493
494
 
494
495
 
496
+ def _restore_cursor_if_needed() -> None:
497
+ import json as _json
498
+ prev_path = config_dir() / "cursor-previous-settings.json"
499
+ db_path = cursor_state_db_path()
500
+ if not prev_path.exists() or not db_path.exists():
501
+ return
502
+ try:
503
+ previous = _json.loads(prev_path.read_text(encoding="utf-8"))
504
+ if restore_cursor_settings(previous, db_path=db_path):
505
+ prev_path.unlink(missing_ok=True)
506
+ print("Cursor settings restored to previous values.")
507
+ else:
508
+ print("[warn] Could not auto-restore Cursor settings.")
509
+ except Exception:
510
+ pass
511
+ if cursor_is_running():
512
+ print(" Restart Cursor for settings to take effect.")
513
+
514
+
495
515
  def _cmd_status() -> int:
496
516
  state = load_state()
497
517
  auth = state["auth"]
@@ -780,15 +800,30 @@ def _cmd_launch(tool: str, route: str | None, remainder: list[str]) -> int:
780
800
  return launch(plan)
781
801
 
782
802
 
783
- def _cmd_cursor(route: str | None, port: int) -> int:
784
- import signal as _signal
785
-
803
+ def _cmd_cursor(route: str | None) -> int:
786
804
  state = load_state()
787
805
  route, promoted = _maybe_promote_direct_route(state, "cursor", route)
788
806
  effective_route = resolve_route(state, "cursor", route)
789
807
 
808
+ db_path = cursor_state_db_path()
809
+
790
810
  if effective_route == "direct":
811
+ if db_path.exists():
812
+ previous_json = config_dir() / "cursor-previous-settings.json"
813
+ if previous_json.exists():
814
+ import json as _json
815
+ try:
816
+ previous = _json.loads(previous_json.read_text(encoding="utf-8"))
817
+ if restore_cursor_settings(previous, db_path=db_path):
818
+ previous_json.unlink(missing_ok=True)
819
+ print("Cursor settings restored to previous values.")
820
+ else:
821
+ print("[warn] Could not restore Cursor settings automatically.")
822
+ except Exception:
823
+ pass
791
824
  print("Cursor route set to direct — MTRX proxy disabled.")
825
+ if cursor_is_running():
826
+ print(" Restart Cursor for settings to take effect.")
792
827
  return 0
793
828
 
794
829
  try:
@@ -811,10 +846,7 @@ def _cmd_cursor(route: str | None, port: int) -> int:
811
846
  return 1
812
847
 
813
848
  matrx_base_url = ensure_root_url(state.get("auth", {}).get("matrx", {}).get("base_url"))
814
-
815
- binding = get_workspace_binding(state, cwd=os.getcwd()) or {}
816
- group_id = (os.environ.get("MTRX_GROUP_ID") or binding.get("group_id") or "").strip()
817
- project_id = (os.environ.get("MTRX_PROJECT_ID") or binding.get("project_id") or "").strip()
849
+ proxy_url = f"{matrx_base_url.rstrip('/')}/v1"
818
850
 
819
851
  if initialized or login_changed or promoted:
820
852
  save_state(state)
@@ -824,71 +856,34 @@ def _cmd_cursor(route: str | None, port: int) -> int:
824
856
  "Use `mtrx use cursor direct` to opt out.",
825
857
  )
826
858
 
827
- proxy = CursorProxyServer(
828
- matrx_key=mx_key,
829
- matrx_base_url=matrx_base_url,
830
- group_id=group_id,
831
- project_id=project_id,
832
- port=port,
833
- )
834
- try:
835
- proxy.start_background()
836
- except RuntimeError as exc:
837
- print(f"Failed to start proxy: {exc}", file=sys.stderr)
838
- return 1
839
-
840
- proxy_url = proxy.url
841
- print(f"MTRX Cursor proxy running at {proxy_url}")
842
- print(f" session: {proxy.session_id}")
843
- print(f" matrx_key: {mask_secret(mx_key)}")
844
- print(f" upstream: {matrx_base_url}")
845
- if group_id:
846
- print(f" group: {group_id}")
847
- if project_id:
848
- print(f" project: {project_id}")
849
-
850
- previous_settings = None
851
- db_path = cursor_state_db_path()
852
- if db_path.exists():
853
- if cursor_is_running():
854
- print()
855
- print(" [warn] Cursor is currently running.")
856
- print(" Settings changes may require restarting Cursor to take effect.")
857
- previous_settings = configure_cursor_for_proxy(proxy_url, db_path=db_path)
858
- if previous_settings is not None:
859
- print()
860
- print(" Cursor settings configured automatically.")
861
- print(" Restart Cursor if it is already open.")
862
- else:
863
- print_manual_setup_instructions(proxy_url)
864
- else:
859
+ if not db_path.exists():
865
860
  print_manual_setup_instructions(proxy_url)
861
+ print(f" Use API Key: {mx_key}")
862
+ return 0
866
863
 
867
- print()
868
- print("Press Ctrl+C to stop the proxy and restore settings.")
869
-
870
- stop_event = threading.Event()
871
-
872
- def _on_signal(sig, frame):
873
- stop_event.set()
874
-
875
- _signal.signal(_signal.SIGINT, _on_signal)
876
- _signal.signal(_signal.SIGTERM, _on_signal)
864
+ previous_settings = configure_cursor_for_proxy(
865
+ proxy_url, proxy_api_key=mx_key, db_path=db_path,
866
+ )
867
+ if previous_settings is None:
868
+ print_manual_setup_instructions(proxy_url)
869
+ print(f" Use API Key: {mask_secret(mx_key)}")
870
+ return 0
877
871
 
878
- stop_event.wait()
872
+ import json as _json
873
+ prev_path = config_dir() / "cursor-previous-settings.json"
874
+ config_dir().mkdir(parents=True, exist_ok=True)
875
+ prev_path.write_text(_json.dumps(previous_settings), encoding="utf-8")
879
876
 
877
+ print("Cursor configured to route through MTRX.")
878
+ print(f" base_url: {proxy_url}")
879
+ print(f" api_key: {mask_secret(mx_key)}")
880
880
  print()
881
- print("Shutting down MTRX Cursor proxy...")
882
- proxy.stop()
883
-
884
- if previous_settings is not None:
885
- if restore_cursor_settings(previous_settings, db_path=db_path):
886
- print("Cursor settings restored to previous values.")
887
- else:
888
- print("[warn] Could not restore Cursor settings automatically.")
889
- print(" You may need to reset your OpenAI API Key and Base URL in Cursor Settings > Models.")
890
-
891
- print("Done.")
881
+ if cursor_is_running():
882
+ print(" Cursor is running — restart it for settings to take effect.")
883
+ else:
884
+ print(" Settings will apply next time Cursor starts.")
885
+ print()
886
+ print(" To disable: mtrx use cursor direct")
892
887
  return 0
893
888
 
894
889