token-cut-cli 0.1.4__tar.gz → 0.1.6__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: token-cut-cli
3
- Version: 0.1.4
3
+ Version: 0.1.6
4
4
  Summary: Verify Token-Cut API integration from the terminal (no repo clone required)
5
5
  Project-URL: Homepage, https://www.token-cut.com
6
6
  Project-URL: Documentation, https://www.token-cut.com
@@ -28,7 +28,7 @@ Public **client** for [Token-Cut](https://www.token-cut.com). Your proprietary A
28
28
  |------|---------|-------|
29
29
  | This PyPI package (`token-cut-cli`) | Yes | Free to install |
30
30
  | `cc_live_…` API key | — | Yes (your Stripe plans) |
31
- | Optimization + Graphify on **your** API | Private server | Metered per key |
31
+ | Optimization + repo index on **your** API | Private server | Metered per key |
32
32
 
33
33
  The CLI cannot optimize without a valid key against **your** deployment.
34
34
 
@@ -8,7 +8,7 @@ Public **client** for [Token-Cut](https://www.token-cut.com). Your proprietary A
8
8
  |------|---------|-------|
9
9
  | This PyPI package (`token-cut-cli`) | Yes | Free to install |
10
10
  | `cc_live_…` API key | — | Yes (your Stripe plans) |
11
- | Optimization + Graphify on **your** API | Private server | Metered per key |
11
+ | Optimization + repo index on **your** API | Private server | Metered per key |
12
12
 
13
13
  The CLI cannot optimize without a valid key against **your** deployment.
14
14
 
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "token-cut-cli"
7
- version = "0.1.4"
7
+ version = "0.1.6"
8
8
  description = "Verify Token-Cut API integration from the terminal (no repo clone required)"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
@@ -0,0 +1 @@
1
+ __version__ = "0.1.6"
@@ -19,7 +19,7 @@ def main(argv: list[str] | None = None) -> int:
19
19
 
20
20
  v = sub.add_parser(
21
21
  "verify",
22
- help="Check API key, optimize, and Graphify on a public repo (~1 min)",
22
+ help="Check API key, optimize, and repo index on a public repo (~1 min)",
23
23
  )
24
24
  v.add_argument(
25
25
  "--api-url",
@@ -45,7 +45,7 @@ def main(argv: list[str] | None = None) -> int:
45
45
  v.add_argument(
46
46
  "--no-graph",
47
47
  action="store_true",
48
- help="Only check API key + optimize (skip Graphify; safe on small Railway pods)",
48
+ help="Only check API key + optimize (skip repo graph; safe on small Railway pods)",
49
49
  )
50
50
 
51
51
  o = sub.add_parser("optimize", help="Run one optimize call and print JSON")
@@ -1,4 +1,4 @@
1
- """Token-Cut MCP server — shipped in token-cut-cli (calls your cloud API with cc_live_ key)."""
1
+ """Token-Cut MCP server — any MCP host (Cursor, Claude, Copilot, )."""
2
2
 
3
3
  from __future__ import annotations
4
4
 
@@ -7,10 +7,22 @@ import os
7
7
  import sys
8
8
 
9
9
  from token_cut_cli import __version__
10
- from token_cut_cli.client import DEFAULT_API_URL, api_base, api_key
10
+ from token_cut_cli.client import api_base, api_key
11
+ from token_cut_cli.workspace import detect_workspace, workspace_forward_headers
11
12
 
12
13
 
13
- def _post(path: str, body: dict) -> dict:
14
+ def _resolve_repo(args: dict) -> str | None:
15
+ for val in (
16
+ args.get("repo_path"),
17
+ os.getenv("TOKEN_CUT_REPO_PATH") or os.getenv("CONTEXT_CUT_REPO_PATH"),
18
+ detect_workspace(),
19
+ ):
20
+ if val and str(val).strip():
21
+ return str(val).strip()
22
+ return None
23
+
24
+
25
+ def _post(path: str, body: dict, *, repo: str | None = None) -> dict:
14
26
  import urllib.request
15
27
 
16
28
  base = api_base().rstrip("/")
@@ -18,10 +30,14 @@ def _post(path: str, body: dict) -> dict:
18
30
  if not key:
19
31
  raise RuntimeError("Set TOKEN_CUT_API_KEY=cc_live_…")
20
32
 
33
+ headers = {"Content-Type": "application/json", "x-api-key": key}
34
+ if repo:
35
+ headers.update(workspace_forward_headers(repo))
36
+
21
37
  req = urllib.request.Request(
22
38
  f"{base}{path}",
23
39
  data=json.dumps(body).encode(),
24
- headers={"Content-Type": "application/json", "x-api-key": key},
40
+ headers=headers,
25
41
  method="POST",
26
42
  )
27
43
  timeout = int(os.getenv("TOKEN_CUT_HTTP_TIMEOUT", "360"))
@@ -39,14 +55,17 @@ def _tool_list() -> dict:
39
55
  {
40
56
  "name": "optimize_prompt",
41
57
  "description": (
42
- "Optimize a prompt (Token-Cut cloud). Auto-builds graph.json when missing. "
43
- "Requires cc_live_ API key. IDE still runs the LLM on your plan."
58
+ "Optimize a prompt. Open workspace auto-detected from the host IDE. "
59
+ "Requires cc_live_ API key (or local API URL). IDE still runs the LLM."
44
60
  ),
45
61
  "inputSchema": {
46
62
  "type": "object",
47
63
  "properties": {
48
64
  "prompt": {"type": "string"},
49
- "repo_path": {"type": "string"},
65
+ "repo_path": {
66
+ "type": "string",
67
+ "description": "Optional override; default is IDE open folder.",
68
+ },
50
69
  "repo_url": {"type": "string"},
51
70
  "auto_build_graph": {"type": "boolean"},
52
71
  },
@@ -55,7 +74,7 @@ def _tool_list() -> dict:
55
74
  },
56
75
  {
57
76
  "name": "build_repo_graph",
58
- "description": "Build Graphify graph for a repo (Token-Cut cloud).",
77
+ "description": "Build repo knowledge graph for a path (Token-Cut cloud).",
59
78
  "inputSchema": {
60
79
  "type": "object",
61
80
  "properties": {
@@ -68,10 +87,6 @@ def _tool_list() -> dict:
68
87
  }
69
88
 
70
89
 
71
- def _env_repo_path() -> str | None:
72
- return os.getenv("TOKEN_CUT_REPO_PATH") or os.getenv("CONTEXT_CUT_REPO_PATH")
73
-
74
-
75
90
  def _env_repo_url() -> str | None:
76
91
  return os.getenv("TOKEN_CUT_REPO_URL") or os.getenv("CONTEXT_CUT_REPO_URL")
77
92
 
@@ -82,16 +97,18 @@ def _handle_tools_call(msg: dict) -> None:
82
97
  args = params.get("arguments", {})
83
98
  try:
84
99
  if name == "optimize_prompt":
100
+ repo = _resolve_repo(args)
85
101
  data = _post(
86
102
  "/v1/optimize",
87
103
  {
88
104
  "prompt": args["prompt"],
89
- "repo_path": args.get("repo_path") or _env_repo_path(),
105
+ "repo_path": repo,
90
106
  "repo_url": args.get("repo_url") or _env_repo_url(),
91
107
  "model": "gpt-4o",
92
108
  "use_graph": True,
93
109
  "auto_build_graph": args.get("auto_build_graph", True),
94
110
  },
111
+ repo=repo,
95
112
  )
96
113
  graph_line = ""
97
114
  if data.get("graph_ready"):
@@ -105,12 +122,14 @@ def _handle_tools_call(msg: dict) -> None:
105
122
  f"{data['optimized_prompt'][:8000]}"
106
123
  )
107
124
  elif name == "build_repo_graph":
125
+ repo = _resolve_repo(args)
108
126
  data = _post(
109
127
  "/v1/graph/build",
110
128
  {
111
- "repo_path": args.get("repo_path"),
129
+ "repo_path": repo,
112
130
  "repo_url": args.get("repo_url"),
113
131
  },
132
+ repo=repo,
114
133
  )
115
134
  text = json.dumps(data, indent=2)
116
135
  else:
@@ -90,7 +90,7 @@ def run_verify(
90
90
 
91
91
  if not with_graph:
92
92
  if not quiet:
93
- print("\n Skipped graph test (--no-graph). For full Graphify: token-cut verify")
93
+ print("\n Skipped graph test (--no-graph). For full repo index check: token-cut verify")
94
94
  return 0
95
95
 
96
96
  # Phase 2: graph path (cloud may build in background)
@@ -118,9 +118,9 @@ def run_verify(
118
118
 
119
119
  if graph_ready:
120
120
  cache = "built now" if graph_built else "cached"
121
- _ok(f"Graphify: {nodes:,} nodes ({cache})")
121
+ _ok(f"Repo graph: {nodes:,} nodes ({cache})")
122
122
  elif "background" in msg.lower():
123
- _ok("Graphify queued on server (background — avoids OOM)")
123
+ _ok("Repo index queued on server (background — avoids OOM)")
124
124
  if not quiet:
125
125
  print(" … waiting 90s then retrying once …")
126
126
  time.sleep(90)
@@ -133,7 +133,7 @@ def run_verify(
133
133
  )
134
134
  if retry.get("graph_ready"):
135
135
  nodes = int(retry.get("graph_nodes") or 0)
136
- _ok(f"Graphify ready after background build: {nodes:,} nodes")
136
+ _ok(f"Repo graph ready after background build: {nodes:,} nodes")
137
137
  graph_ready = True
138
138
  except Exception:
139
139
  pass
@@ -0,0 +1,96 @@
1
+ """IDE-agnostic open-folder detection for MCP (pip-installed CLI)."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import os
6
+ from pathlib import Path
7
+
8
+ # Keep in sync with api/app/workspace.py IDE_WORKSPACE_ENV_KEYS
9
+ IDE_WORKSPACE_ENV_KEYS = (
10
+ "CURSOR_WORKSPACE_FOLDER",
11
+ "CURSOR_PROJECT_DIR",
12
+ "CURSOR_WORKSPACE",
13
+ "VSCODE_CWD",
14
+ "VSCODE_WORKSPACE_FOLDER",
15
+ "VSCODE_WORKSPACE",
16
+ "CODE_WORKSPACE_FOLDER",
17
+ "WINDSURF_WORKSPACE_FOLDER",
18
+ "CODEIUM_WORKSPACE",
19
+ "CLAUDE_PROJECT_ROOT",
20
+ "CLAUDE_CODE_PROJECT_DIR",
21
+ "CLAUDE_PROJECT_DIR",
22
+ "ZED_WORKSPACE",
23
+ "ZED_ROOT",
24
+ "IDEA_INITIAL_DIRECTORY",
25
+ "PROJECT_DIR",
26
+ "PROJECT_ROOT",
27
+ "WORKSPACE_FOLDER",
28
+ "WORKSPACE",
29
+ "REPO_ROOT",
30
+ "INIT_CWD",
31
+ "GITHUB_WORKSPACE",
32
+ "PWD",
33
+ )
34
+
35
+
36
+ def _find_git_root(start: Path) -> Path | None:
37
+ current = start.resolve()
38
+ for _ in range(32):
39
+ if (current / ".git").exists():
40
+ return current
41
+ parent = current.parent
42
+ if parent == current:
43
+ break
44
+ current = parent
45
+ return None
46
+
47
+
48
+ def _looks_like_repo(path: Path) -> bool:
49
+ if not path.is_dir():
50
+ return False
51
+ if (path / ".git").is_dir() or (path / ".git").is_file():
52
+ return True
53
+ markers = ("package.json", "pyproject.toml", "go.mod", "Cargo.toml", "requirements.txt")
54
+ return any((path / m).exists() for m in markers)
55
+
56
+
57
+ def detect_workspace() -> str | None:
58
+ candidates: list[Path] = []
59
+ for key in IDE_WORKSPACE_ENV_KEYS:
60
+ v = os.getenv(key)
61
+ if v:
62
+ candidates.append(Path(v).expanduser())
63
+ env_repo = os.getenv("TOKEN_CUT_REPO_PATH") or os.getenv("CONTEXT_CUT_REPO_PATH")
64
+ if env_repo:
65
+ candidates.append(Path(env_repo).expanduser())
66
+ try:
67
+ candidates.append(Path.cwd())
68
+ except OSError:
69
+ pass
70
+
71
+ seen: set[str] = set()
72
+ for raw in candidates:
73
+ try:
74
+ p = raw.resolve()
75
+ except OSError:
76
+ continue
77
+ key = str(p)
78
+ if key in seen:
79
+ continue
80
+ seen.add(key)
81
+ root = _find_git_root(p) if p.is_dir() else None
82
+ if root and _looks_like_repo(root):
83
+ return str(root)
84
+ if _looks_like_repo(p):
85
+ return str(p)
86
+ return None
87
+
88
+
89
+ def workspace_forward_headers(repo_path: str) -> dict[str, str]:
90
+ path = str(repo_path).strip()
91
+ return {
92
+ "x-repo-path": path,
93
+ "x-workspace-path": path,
94
+ "x-workspace-folder": path,
95
+ "x-project-root": path,
96
+ }
@@ -1 +0,0 @@
1
- __version__ = "0.1.4"
File without changes