grape-cli 0.3.4__py3-none-any.whl
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.
- grape_cli/__init__.py +2 -0
- grape_cli/__main__.py +7 -0
- grape_cli/cli.py +354 -0
- grape_cli/client.py +397 -0
- grape_cli/commands/__init__.py +0 -0
- grape_cli/commands/doctor.py +324 -0
- grape_cli/commands/git.py +137 -0
- grape_cli/config.py +221 -0
- grape_cli/contracts.py +281 -0
- grape_cli/data/examples.json +85 -0
- grape_cli/data/openapi.json +1 -0
- grape_cli/data/token-scope.json +17 -0
- grape_cli/registry.py +1193 -0
- grape_cli/update_check.py +290 -0
- grape_cli-0.3.4.dist-info/METADATA +274 -0
- grape_cli-0.3.4.dist-info/RECORD +20 -0
- grape_cli-0.3.4.dist-info/WHEEL +5 -0
- grape_cli-0.3.4.dist-info/entry_points.txt +2 -0
- grape_cli-0.3.4.dist-info/licenses/LICENSE +21 -0
- grape_cli-0.3.4.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
"""启动时异步新版本检查(grape-dev/grape-cli#202)。
|
|
2
|
+
|
|
3
|
+
约束:
|
|
4
|
+
- 完全异步:daemon 线程探测,命令结束后非阻塞取结果;不阻塞、不重试。
|
|
5
|
+
- 有界:连接 0.5s / 总 1.5s 超时。
|
|
6
|
+
- 静默降级:非 200、解析失败、断网、超时、任何异常 → 不提示、不改退出码。
|
|
7
|
+
- 24h 本地缓存(``~/.grape/version-check.json``),同一新版本只提示一次。
|
|
8
|
+
- 提示只写 stderr,避免污染 ``--json-out`` 与脚本管道。
|
|
9
|
+
- 三通道开关:``--no-version-check`` / ``GRAPE_NO_VERSION_CHECK=1`` /
|
|
10
|
+
config ``version_check=false``(优先级:命令行 > 环境变量 > 配置文件)。
|
|
11
|
+
- 非 TTY 与 ``CI=1`` 默认关闭。
|
|
12
|
+
"""
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
import json
|
|
16
|
+
import os
|
|
17
|
+
import queue
|
|
18
|
+
import re
|
|
19
|
+
import sys
|
|
20
|
+
import threading
|
|
21
|
+
import time
|
|
22
|
+
from pathlib import Path
|
|
23
|
+
from typing import Any, TextIO
|
|
24
|
+
|
|
25
|
+
from grape_cli import __version__, config
|
|
26
|
+
|
|
27
|
+
RELEASES_LATEST_URL = (
|
|
28
|
+
"https://api.gitcode.com/api/v5/repos/grape-dev/grape-cli/releases/latest"
|
|
29
|
+
)
|
|
30
|
+
TAGS_URL = "https://api.gitcode.com/api/v5/repos/grape-dev/grape-cli/tags"
|
|
31
|
+
CACHE_FILE = Path.home() / ".grape" / "version-check.json"
|
|
32
|
+
CONNECT_TIMEOUT = 0.5
|
|
33
|
+
TOTAL_TIMEOUT = 1.5
|
|
34
|
+
CACHE_TTL = 24 * 60 * 60
|
|
35
|
+
|
|
36
|
+
_TRUTHY = {"1", "true", "yes", "on"}
|
|
37
|
+
_VERSION_PART = re.compile(r"\d+")
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def _env(env: dict | None) -> Any:
|
|
41
|
+
return os.environ if env is None else env
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def _truthy(value: Any) -> bool:
|
|
45
|
+
return str(value or "").strip().lower() in _TRUTHY
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def _is_ci(env: dict | None = None) -> bool:
|
|
49
|
+
return _truthy(_env(env).get("CI"))
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def _stderr_isatty() -> bool:
|
|
53
|
+
try:
|
|
54
|
+
return bool(sys.stderr.isatty())
|
|
55
|
+
except Exception:
|
|
56
|
+
return False
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def enabled(*, no_version_check: bool = False, is_tty: bool | None = None,
|
|
60
|
+
env: dict | None = None,
|
|
61
|
+
config_path: Path | str | None = None) -> bool:
|
|
62
|
+
"""是否允许本次启动检查(CLI > env > config;非 TTY / CI 默认关闭)。"""
|
|
63
|
+
if config.version_check_disabled(
|
|
64
|
+
no_version_check=no_version_check, env=env, config_path=config_path
|
|
65
|
+
):
|
|
66
|
+
return False
|
|
67
|
+
if is_tty is None:
|
|
68
|
+
is_tty = _stderr_isatty()
|
|
69
|
+
if not is_tty:
|
|
70
|
+
return False
|
|
71
|
+
if _is_ci(env):
|
|
72
|
+
return False
|
|
73
|
+
return True
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def _version_parts(version: Any) -> tuple[int, ...]:
|
|
77
|
+
return tuple(int(part) for part in _VERSION_PART.findall(str(version or "")))
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def _clean(version: Any) -> str:
|
|
81
|
+
return str(version or "").strip().lstrip("vV")
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def is_newer(latest: Any, current: Any) -> bool:
|
|
85
|
+
"""纯数字段比较;解析不出数字或相等 → False(不打扰)。"""
|
|
86
|
+
latest_parts = _version_parts(latest)
|
|
87
|
+
current_parts = _version_parts(current)
|
|
88
|
+
if not latest_parts or not current_parts:
|
|
89
|
+
return False
|
|
90
|
+
return latest_parts > current_parts
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def _request_json(url: str, timeout: Any) -> Any:
|
|
94
|
+
import httpx
|
|
95
|
+
|
|
96
|
+
response = httpx.get(url, timeout=timeout, follow_redirects=True)
|
|
97
|
+
if not 200 <= response.status_code < 300:
|
|
98
|
+
return None
|
|
99
|
+
return response.json()
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def _latest_from_release(data: Any) -> str:
|
|
103
|
+
if isinstance(data, dict):
|
|
104
|
+
for key in ("tag_name", "version"):
|
|
105
|
+
value = _clean(data.get(key))
|
|
106
|
+
if value:
|
|
107
|
+
return value
|
|
108
|
+
return ""
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def _latest_from_tags(data: Any) -> str:
|
|
112
|
+
if not isinstance(data, list):
|
|
113
|
+
return ""
|
|
114
|
+
versions = [_clean(item.get("name")) for item in data
|
|
115
|
+
if isinstance(item, dict) and _clean(item.get("name"))]
|
|
116
|
+
if not versions:
|
|
117
|
+
return ""
|
|
118
|
+
return max(versions, key=_version_parts)
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def fetch_latest_version(*, current: str = __version__,
|
|
122
|
+
total_timeout: float = TOTAL_TIMEOUT,
|
|
123
|
+
connect_timeout: float = CONNECT_TIMEOUT) -> str | None:
|
|
124
|
+
"""取最新已发布版本:releases/latest 优先,陈旧/不可用时合并 tags 取最大。
|
|
125
|
+
|
|
126
|
+
共享一个总超时预算;任何异常一律 None(静默)。保留 tags 回退是因为
|
|
127
|
+
releases/latest 可能停留在旧的预发布版本(如 v0.3.2-pre)。
|
|
128
|
+
"""
|
|
129
|
+
try:
|
|
130
|
+
import httpx
|
|
131
|
+
|
|
132
|
+
deadline = time.monotonic() + max(0.0, total_timeout)
|
|
133
|
+
|
|
134
|
+
def _remaining() -> float:
|
|
135
|
+
return max(0.05, deadline - time.monotonic())
|
|
136
|
+
|
|
137
|
+
def _timeout_for(remaining: float) -> Any:
|
|
138
|
+
return httpx.Timeout(remaining, connect=min(connect_timeout, remaining))
|
|
139
|
+
|
|
140
|
+
release = ""
|
|
141
|
+
try:
|
|
142
|
+
release = _latest_from_release(
|
|
143
|
+
_request_json(RELEASES_LATEST_URL, _timeout_for(_remaining()))
|
|
144
|
+
)
|
|
145
|
+
except Exception:
|
|
146
|
+
release = ""
|
|
147
|
+
if release and _version_parts(release) >= _version_parts(current):
|
|
148
|
+
return release
|
|
149
|
+
|
|
150
|
+
tags = ""
|
|
151
|
+
if time.monotonic() < deadline:
|
|
152
|
+
try:
|
|
153
|
+
tags = _latest_from_tags(
|
|
154
|
+
_request_json(TAGS_URL, _timeout_for(_remaining()))
|
|
155
|
+
)
|
|
156
|
+
except Exception:
|
|
157
|
+
tags = ""
|
|
158
|
+
candidates = [version for version in (release, tags) if version]
|
|
159
|
+
return max(candidates, key=_version_parts) if candidates else None
|
|
160
|
+
except Exception:
|
|
161
|
+
return None
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
def load_cache(cache_path: Path | str | None = None) -> dict:
|
|
165
|
+
path = Path(cache_path) if cache_path is not None else CACHE_FILE
|
|
166
|
+
try:
|
|
167
|
+
data = json.loads(path.read_text(encoding="utf-8"))
|
|
168
|
+
return data if isinstance(data, dict) else {}
|
|
169
|
+
except Exception:
|
|
170
|
+
return {}
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
def save_cache(state: dict, cache_path: Path | str | None = None) -> None:
|
|
174
|
+
path = Path(cache_path) if cache_path is not None else CACHE_FILE
|
|
175
|
+
try:
|
|
176
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
177
|
+
tmp = path.with_name(f"{path.name}.{os.getpid()}.tmp")
|
|
178
|
+
tmp.write_text(json.dumps(state, ensure_ascii=False), encoding="utf-8")
|
|
179
|
+
os.replace(tmp, path)
|
|
180
|
+
except Exception:
|
|
181
|
+
pass
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
def notice(current: str, latest: Any, state: dict) -> str | None:
|
|
185
|
+
"""命中更高版本且未提示过 → 返回一行提示;否则 None。"""
|
|
186
|
+
latest_clean = _clean(latest)
|
|
187
|
+
if not latest_clean or not is_newer(latest_clean, current):
|
|
188
|
+
return None
|
|
189
|
+
if str(state.get("last_notified") or "") == latest_clean:
|
|
190
|
+
return None
|
|
191
|
+
return (f"grape {latest_clean} is available (current {current}). "
|
|
192
|
+
f"Upgrade: pip install -U grape-cli")
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
class Checker:
|
|
196
|
+
"""一次异步检查的句柄:线程在后台探测,finish() 非阻塞取结果。"""
|
|
197
|
+
|
|
198
|
+
def __init__(self, current: str = __version__,
|
|
199
|
+
cache_path: Path | str | None = None):
|
|
200
|
+
self.current = current
|
|
201
|
+
self.cache_path = cache_path
|
|
202
|
+
self._queue: queue.Queue = queue.Queue(maxsize=1)
|
|
203
|
+
self._thread = threading.Thread(
|
|
204
|
+
target=self._run, name="grape-version-check", daemon=True
|
|
205
|
+
)
|
|
206
|
+
|
|
207
|
+
def start(self) -> "Checker":
|
|
208
|
+
self._thread.start()
|
|
209
|
+
return self
|
|
210
|
+
|
|
211
|
+
def _run(self) -> None:
|
|
212
|
+
try:
|
|
213
|
+
state = load_cache(self.cache_path)
|
|
214
|
+
now = time.time()
|
|
215
|
+
latest = _clean(state.get("latest"))
|
|
216
|
+
try:
|
|
217
|
+
last_checked = float(state.get("last_checked") or 0)
|
|
218
|
+
except (TypeError, ValueError):
|
|
219
|
+
last_checked = 0.0
|
|
220
|
+
if not latest or now - last_checked >= CACHE_TTL:
|
|
221
|
+
fetched = fetch_latest_version(current=self.current)
|
|
222
|
+
if fetched:
|
|
223
|
+
latest = fetched
|
|
224
|
+
state["latest"] = latest
|
|
225
|
+
state["last_checked"] = now
|
|
226
|
+
save_cache(state, self.cache_path)
|
|
227
|
+
self._queue.put((self.current, latest, state))
|
|
228
|
+
except Exception:
|
|
229
|
+
try:
|
|
230
|
+
self._queue.put((self.current, None, {}))
|
|
231
|
+
except Exception:
|
|
232
|
+
pass
|
|
233
|
+
|
|
234
|
+
def finish(self, *, wait: float = 0.0) -> str | None:
|
|
235
|
+
try:
|
|
236
|
+
if wait and wait > 0:
|
|
237
|
+
current, latest, state = self._queue.get(timeout=wait)
|
|
238
|
+
else:
|
|
239
|
+
current, latest, state = self._queue.get_nowait()
|
|
240
|
+
except Exception:
|
|
241
|
+
return None
|
|
242
|
+
message = notice(current, latest, state)
|
|
243
|
+
if message:
|
|
244
|
+
state["last_notified"] = _clean(latest)
|
|
245
|
+
save_cache(state, self.cache_path)
|
|
246
|
+
return message
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
def start(*, no_version_check: bool = False, current: str = __version__,
|
|
250
|
+
cache_path: Path | str | None = None, is_tty: bool | None = None,
|
|
251
|
+
env: dict | None = None,
|
|
252
|
+
config_path: Path | str | None = None) -> Checker | None:
|
|
253
|
+
"""开关全关或非交互场景 → None(零线程、零网络)。"""
|
|
254
|
+
if not enabled(no_version_check=no_version_check, is_tty=is_tty, env=env,
|
|
255
|
+
config_path=config_path):
|
|
256
|
+
return None
|
|
257
|
+
return Checker(current=current, cache_path=cache_path).start()
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
def emit(checker: Checker | None, *, stream: TextIO | None = None,
|
|
261
|
+
wait: float = 0.0) -> str | None:
|
|
262
|
+
"""命令结束后调用:取结果并只写 stderr;异常静默。"""
|
|
263
|
+
if checker is None:
|
|
264
|
+
return None
|
|
265
|
+
message = checker.finish(wait=wait)
|
|
266
|
+
if message:
|
|
267
|
+
out = stream if stream is not None else sys.stderr
|
|
268
|
+
try:
|
|
269
|
+
out.write(message + "\n")
|
|
270
|
+
out.flush()
|
|
271
|
+
except Exception:
|
|
272
|
+
pass
|
|
273
|
+
return message
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
__all__ = [
|
|
277
|
+
"CACHE_FILE",
|
|
278
|
+
"CACHE_TTL",
|
|
279
|
+
"Checker",
|
|
280
|
+
"CONNECT_TIMEOUT",
|
|
281
|
+
"TOTAL_TIMEOUT",
|
|
282
|
+
"emit",
|
|
283
|
+
"enabled",
|
|
284
|
+
"fetch_latest_version",
|
|
285
|
+
"is_newer",
|
|
286
|
+
"load_cache",
|
|
287
|
+
"notice",
|
|
288
|
+
"save_cache",
|
|
289
|
+
"start",
|
|
290
|
+
]
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: grape-cli
|
|
3
|
+
Version: 0.3.4
|
|
4
|
+
Summary: Agentic DevOps CLI: contract-driven command generation + native git passthrough (zero token exposure)
|
|
5
|
+
Author-email: Yuzhe Liao <jansonzhe@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://gitcode.com/grape-dev/grape-cli
|
|
8
|
+
Project-URL: Source, https://gitcode.com/grape-dev/grape-cli
|
|
9
|
+
Project-URL: Issues, https://gitcode.com/grape-dev/grape-cli/issues
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Environment :: Console
|
|
17
|
+
Classifier: Intended Audience :: Developers
|
|
18
|
+
Requires-Python: >=3.10
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
Requires-Dist: click>=8.0
|
|
22
|
+
Requires-Dist: httpx>=0.24
|
|
23
|
+
Provides-Extra: dev
|
|
24
|
+
Requires-Dist: pytest>=7; extra == "dev"
|
|
25
|
+
Dynamic: license-file
|
|
26
|
+
|
|
27
|
+
<h1 align="center">grape CLI</h1>
|
|
28
|
+
|
|
29
|
+
<p align="center">English | <a href="README.zh.md">中文</a></p>
|
|
30
|
+
|
|
31
|
+
<p align="center">
|
|
32
|
+
<strong>Contract-driven CLI for the Grape Agentic DevOps platform — zero token exposure</strong>
|
|
33
|
+
<br>
|
|
34
|
+
Point it at any Grape server — new commands appear automatically.
|
|
35
|
+
</p>
|
|
36
|
+
|
|
37
|
+
<p align="center">
|
|
38
|
+
<a href="#what-is-grape-cli">What is grape CLI</a> ·
|
|
39
|
+
<a href="#the-problem">The Problem</a> ·
|
|
40
|
+
<a href="#core-features">Core Features</a> ·
|
|
41
|
+
<a href="#install">Install</a> ·
|
|
42
|
+
<a href="#quick-start">Quick Start</a> ·
|
|
43
|
+
<a href="#configuration--token">Configuration & Token</a> ·
|
|
44
|
+
<a href="#commands">Commands</a> ·
|
|
45
|
+
<a href="#exit-codes">Exit Codes</a> ·
|
|
46
|
+
<a href="#security">Security</a> ·
|
|
47
|
+
<a href="#development--testing">Development & Testing</a> ·
|
|
48
|
+
<a href="#contributing">Contributing</a>
|
|
49
|
+
</p>
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## What is grape CLI
|
|
54
|
+
|
|
55
|
+
Grape CLI is the command-line client for the [Grape](https://gitcode.com/grape-dev/grape) platform,
|
|
56
|
+
**designed primarily for Agents**. It walks the repository's DevOps workflow and gives an Agent the
|
|
57
|
+
full context of that repo, so the Agent can precisely understand the project background and turn a
|
|
58
|
+
developer's requirements into accurate, implementation-ready actions. It reads the server's OpenAPI
|
|
59
|
+
contract, auto-generates `grape <group> <verb>` commands, and runs native `git` operations locally
|
|
60
|
+
with credentials kept strictly in-process.
|
|
61
|
+
|
|
62
|
+
**In one sentence: add a server endpoint → re-fetch the contract → the CLI gains the command, no source changes.**
|
|
63
|
+
|
|
64
|
+
## The Problem
|
|
65
|
+
|
|
66
|
+
Interacting with a contract-driven API usually means hand-written `curl`, fragile scripts, and
|
|
67
|
+
tokens leaking into shell history:
|
|
68
|
+
|
|
69
|
+
| | Manual | grape CLI |
|
|
70
|
+
|-|--------|-----------|
|
|
71
|
+
| Call a new endpoint | Write `curl` + parse JSON by hand | `grape <group> <verb>` auto-generated from OpenAPI |
|
|
72
|
+
| Auth | Copy tokens into shell history / files | Token from one-shot args, env, or config — attached automatically |
|
|
73
|
+
| Run git against the platform | Persist remote credentials on disk | `grape git` injects credentials in-process, never persisted |
|
|
74
|
+
| Server API changes | Update every client script | Re-fetch contract — CLI updates itself |
|
|
75
|
+
|
|
76
|
+
## Core Features
|
|
77
|
+
|
|
78
|
+
- **Contract-driven commands** — OpenAPI 3.x `operationId` becomes a command tree (`tasks_current` → `grape tasks current`); the command set mirrors the connected server.
|
|
79
|
+
- **Automatic auth injection** — Bearer token attached by default (client also supports `PRIVATE-TOKEN` / `?access_token=` channels).
|
|
80
|
+
- **Native git passthrough** — `grape git` runs real `git`, auto-detects the repo, and injects a short-lived credential via `GIT_CONFIG` env vars — never on the command line, never on disk.
|
|
81
|
+
- **Built-in `tasks wait`** — poll a task until a terminal state (`completed` / `failed` / `cancelled`).
|
|
82
|
+
- **Machine-readable output** — `--json-out` emits single-line JSON for workers and scripts.
|
|
83
|
+
- **Mode-aware command sets** — `GRAPE_CLI_MODE` (WORKER / USER / ALL) filters commands by token scope (dual / session-only / user-only).
|
|
84
|
+
|
|
85
|
+
## Install
|
|
86
|
+
|
|
87
|
+
Three supported channels; the command is always `grape` (distribution name:
|
|
88
|
+
`grape-cli`). Requires Python >= 3.10.
|
|
89
|
+
|
|
90
|
+
### PyPI (recommended)
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
pip install grape-cli
|
|
94
|
+
# upgrade later
|
|
95
|
+
pip install -U grape-cli
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### From git (fallback)
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
pip install "git+https://gitcode.com/grape-dev/grape-cli.git@main"
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Editable install (development)
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
git clone https://gitcode.com/grape-dev/grape-cli.git
|
|
108
|
+
cd grape-cli
|
|
109
|
+
|
|
110
|
+
pip install -e .
|
|
111
|
+
# Or a dedicated venv (isolated from the system)
|
|
112
|
+
python3 -m venv /opt/grape-cli
|
|
113
|
+
/opt/grape-cli/bin/pip install -e /path/to/grape-cli
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Verify with `grape --version`.
|
|
117
|
+
|
|
118
|
+
### New-version check
|
|
119
|
+
|
|
120
|
+
After a command finishes, `grape` may print one line to **stderr** when a newer
|
|
121
|
+
release is available (`grape X.Y.Z is available ... Upgrade: pip install -U grape-cli`).
|
|
122
|
+
The check runs in a background daemon thread (0.5s connect / 1.5s total timeout),
|
|
123
|
+
caches results for 24h in `~/.grape/version-check.json`, notifies once per
|
|
124
|
+
version, and stays silent when offline or on errors. It is off by default for
|
|
125
|
+
non-TTY runs and `CI=1`.
|
|
126
|
+
|
|
127
|
+
Disable it explicitly with any of:
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
grape --no-version-check issues list
|
|
131
|
+
export GRAPE_NO_VERSION_CHECK=1
|
|
132
|
+
# ~/.grape/config.json
|
|
133
|
+
# {"version_check": false}
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## Quick Start
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
# One-shot (no env vars required)
|
|
140
|
+
grape --base-url https://grape.example.com --token tk_xxx skills list --json-out
|
|
141
|
+
|
|
142
|
+
# Common setup, then explore
|
|
143
|
+
export GRAPE_BASE_URL=https://grape.example.com
|
|
144
|
+
export GRAPE_SESSION_TOKEN=tk_xxx # or: export GRAPE_API_TOKEN=grape_xxx
|
|
145
|
+
grape commands | head -40
|
|
146
|
+
grape skills list --json-out
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## Configuration & Token
|
|
150
|
+
|
|
151
|
+
Precedence (highest first):
|
|
152
|
+
`--token / --base-url / --timeout` (one-shot, process-only) > `GRAPE_SESSION_TOKEN` >
|
|
153
|
+
`GRAPE_API_TOKEN` / `GRAPE_BASE_URL` > `~/.grape/config.json`.
|
|
154
|
+
|
|
155
|
+
| Source | Example | Notes |
|
|
156
|
+
|--------|---------|-------|
|
|
157
|
+
| One-shot args (**recommended**) | `grape --token tk_xxx tasks current`<br>`grape --base-url https://grape.example.com --grape-api-token grape_xxx skills list --json-out` | Never persisted; `--token` / `--grape-api-token` / `--grape_api_token` are synonyms; `--timeout` sets the request timeout (default 30s, git unaffected) |
|
|
158
|
+
| Env vars | `export GRAPE_SESSION_TOKEN=tk_xxx` | `tk_` session token (task-level, auto-expires); `grape_` long-lived user key; `GRAPE_BASE_URL` (fallback `GRAPE_SERVER_URL`), default `http://localhost:8000`; `GRAPE_CLI_MODE=WORKER\|USER\|ALL` (default ALL); `GRAPE_TRUST_ENV=0` (or `--no-proxy`) ignores `*_proxy`/`NO_PROXY` env vars |
|
|
159
|
+
| Config file | `{ "base_url": "...", "token": "" }` in `~/.grape/config.json` | Persistent defaults; prefer env vars for tokens |
|
|
160
|
+
|
|
161
|
+
- In `GRAPE_CLI_MODE=USER`, `GRAPE_API_TOKEN` takes priority over `GRAPE_SESSION_TOKEN`.
|
|
162
|
+
- Without a token, commands fail with a message telling you how to configure one.
|
|
163
|
+
|
|
164
|
+
## Commands
|
|
165
|
+
|
|
166
|
+
### Global
|
|
167
|
+
|
|
168
|
+
```bash
|
|
169
|
+
grape --version / -v # version
|
|
170
|
+
grape --help # contract groups + built-ins (git/refresh/commands)
|
|
171
|
+
grape commands [pattern] # list contract commands; pipe to filter: grape commands | grep issue
|
|
172
|
+
grape refresh # force-fetch the newest OpenAPI contract and refresh the cache
|
|
173
|
+
grape tasks wait --task-id 56 --timeout 120 --interval 3 # poll a task until terminal state
|
|
174
|
+
grape --timeout 300 tasks current # request timeout (default 30s; git unaffected)
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### Contract-driven commands (automatic)
|
|
178
|
+
|
|
179
|
+
Shape: `grape <group> <verb> [--options...]`, derived from `operationId`:
|
|
180
|
+
|
|
181
|
+
```bash
|
|
182
|
+
grape tasks current --json-out
|
|
183
|
+
grape tasks complete --json '{"result_text":"done","next_step":"a2a_issue"}'
|
|
184
|
+
grape issues list --owner o --repo r --json-out
|
|
185
|
+
grape git-repo issues list --owner o --repo r --state open --json-out
|
|
186
|
+
grape git-repo contents --owner o --repo r --path README.md --raw # base64-decoded file text
|
|
187
|
+
grape skills upload --file skill.zip --scope user --agent_type coding
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
- `query` / `path` params → `--<name>`; `requestBody` → `--json '<JSON>'`; `--json-out` → single-line machine-readable JSON.
|
|
191
|
+
<<<<<<< HEAD
|
|
192
|
+
- Long bodies: `--json-file <path>` reads from a file (recommended), `--json @file.json` is the curl-style equivalent, and `--json -` / `--json-file -` / `--json @-` read from stdin (no shell escaping). `--json` and `--json-file` are mutually exclusive.
|
|
193
|
+
=======
|
|
194
|
+
- Long bodies: `--json @file.json` reads from a file, `--json @-` reads from stdin (no shell escaping).
|
|
195
|
+
- `--json` failure semantics: missing file → `cannot read --json file '<path>': ...`; empty/blank file or stdin → `--json file '<path>' is empty`; invalid JSON → `invalid JSON in --json file '<path>'|inline --json string: <msg> (line L column C)`; empty `--json` value → `--json value is empty` (no request is sent). All failures exit non-zero with a message on stderr.
|
|
196
|
+
>>>>>>> origin/main
|
|
197
|
+
- Multipart endpoints (uploads) use `--file <path>` plus form-field options; `git-repo contents --raw` decodes a file to raw text.
|
|
198
|
+
- `--json` bodies are validated against the contract — unknown fields / missing required fields fail fast and print the allowed field list.
|
|
199
|
+
- Discover: `grape <group> --help` (verbs) then `grape <group> <verb> --help` (params, body fields, examples). Unknown verbs get a `Did you mean ...` suggestion.
|
|
200
|
+
- Contract source priority: `{server}/static/openapi.json` → `{server}/openapi.json` → bundled snapshot. Fetched contracts are cached in `~/.grape/openapi-<version>.json`; `grape refresh` bypasses the cache and prints the source.
|
|
201
|
+
|
|
202
|
+
The exact groups/verbs mirror the connected server's contract — run `grape commands` to see what is live.
|
|
203
|
+
|
|
204
|
+
### git (local execution, zero token exposure)
|
|
205
|
+
|
|
206
|
+
`grape git` is a **native git passthrough**. It auto-detects the repo — from the
|
|
207
|
+
`clone` URL argument, or from the current directory's `remote.origin.url` — exchanges
|
|
208
|
+
the session token for a short-lived platform credential in-process, and injects it via
|
|
209
|
+
`GIT_CONFIG` env vars: **never on the command line, never written to disk, invisible to
|
|
210
|
+
the agent**. gitcode.com and github.com hosts get credentials; on an exchange failure you get a
|
|
211
|
+
warning and git runs natively. `grape git --help` is identical to `git --help`.
|
|
212
|
+
|
|
213
|
+
```bash
|
|
214
|
+
grape git status # local command (no credential needed)
|
|
215
|
+
grape git clone https://gitcode.com/owner/repo.git # repo parsed from URL → credential injected
|
|
216
|
+
grape git pull # repo parsed from remote.origin.url
|
|
217
|
+
grape git push
|
|
218
|
+
grape git checkout -b feat/issue-7
|
|
219
|
+
grape git commit -m "fix: ..."
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
### Token scopes & GRAPE_CLI_MODE
|
|
223
|
+
|
|
224
|
+
Each contract operation carries a token scope: `dual`, `session_only`, or `user_only`.
|
|
225
|
+
|
|
226
|
+
- `session_only` (e.g. repo workspace / git-credential) — needs a `tk_` session token; API keys are rejected (403).
|
|
227
|
+
- `user_only` (e.g. agents detail, skills list, chat) — a `tk_` session token is rejected with a hint to set `GRAPE_API_TOKEN` / use a Web JWT.
|
|
228
|
+
- `GRAPE_CLI_MODE` filters `grape --help` and `grape commands` to what the current role may run: `WORKER` (session-only + dual), `USER` (user-only + dual), `ALL` (everything, default).
|
|
229
|
+
|
|
230
|
+
## Exit Codes
|
|
231
|
+
|
|
232
|
+
`0` success · `1` generic/config error · `2` usage error ·
|
|
233
|
+
`>=400` HTTP status passthrough (e.g. `401`) · `130` Ctrl+C.
|
|
234
|
+
|
|
235
|
+
## Security
|
|
236
|
+
|
|
237
|
+
- No create/revoke token subcommands (prevents self-escalation); user-level API keys come from the Web UI.
|
|
238
|
+
- Tokens never appear in output/errors; git credentials injected via `GIT_CONFIG` stay in-process and are never written to disk.
|
|
239
|
+
- `tk_` session tokens auto-expire with the task/session; `grape_` user keys can be revoked.
|
|
240
|
+
- `grape git` injects credentials for gitcode.com / github.com hosts and degrades to plain native git (with a warning) if an exchange fails.
|
|
241
|
+
|
|
242
|
+
## Development & Testing
|
|
243
|
+
|
|
244
|
+
```bash
|
|
245
|
+
pip install -e .[dev]
|
|
246
|
+
python -m pytest test/ -q
|
|
247
|
+
|
|
248
|
+
# Release preflight (version is a single source: grape_cli.__version__)
|
|
249
|
+
python -m build
|
|
250
|
+
python scripts/check_version.py --tag v0.3.4 --dist dist
|
|
251
|
+
python -m twine check dist/*
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
Publishing is tag-driven: pushing a `v*` tag runs `.github/workflows/release.yml`
|
|
255
|
+
(tests → build → three-way version check → twine check → twine upload). The
|
|
256
|
+
`PYPI_API_TOKEN` CI secret must be configured by a maintainer; it is never stored
|
|
257
|
+
in the repository.
|
|
258
|
+
|
|
259
|
+
Test coverage: config precedence, HTTP client (auth/errors), contract loading & caching,
|
|
260
|
+
command generation, CLI end-to-end, git passthrough (credential injection / exit codes),
|
|
261
|
+
new-version check (hit/miss/offline/disabled/TTL/one-shot) and version consistency.
|
|
262
|
+
|
|
263
|
+
## Contributing
|
|
264
|
+
|
|
265
|
+
1. **Open an Issue** — describe the problem or feature
|
|
266
|
+
2. **Fork & Develop** — work on a feature branch (`feat/`, `fix/`, `refactor/`, `docs/`, `chore/`)
|
|
267
|
+
3. **Add Tests** — include pytest tests for new behavior
|
|
268
|
+
4. **Submit a PR** — describe changes, test results, and linked Issue
|
|
269
|
+
|
|
270
|
+
## Feedback
|
|
271
|
+
|
|
272
|
+
- **GitCode Issues**: https://gitcode.com/grape-dev/grape-cli/issues
|
|
273
|
+
- Bugs: include environment, repro steps, and logs
|
|
274
|
+
- Feature suggestions: describe the use case and expected behavior
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
grape_cli/__init__.py,sha256=rqKsH-iqvsXcnRGf56PDCcAz7YS2CuJYGlWXEnkmolY,67
|
|
2
|
+
grape_cli/__main__.py,sha256=qa7Ghc9ncnDyh5LZN2b_vX8-YksVxVK0h1rrPIzVh0E,144
|
|
3
|
+
grape_cli/cli.py,sha256=wMqnq--jMVZ5k5kC16tz1sgiZgFONcYLEn3NYPQFuNQ,14472
|
|
4
|
+
grape_cli/client.py,sha256=efeNHLpS74yfMINX4AG0PMkACGdyVzG6qNdp1LRuTlI,19052
|
|
5
|
+
grape_cli/config.py,sha256=3wImfT3aNCEy5yLND7xFHpOhdONNLCyfxN46E9q5v5s,9479
|
|
6
|
+
grape_cli/contracts.py,sha256=zG1sRDyW1xgXo_lWSXuWVaVJT3KCQO-mb841jWX4OBI,12041
|
|
7
|
+
grape_cli/registry.py,sha256=I8FkN0jBTKBPjHueHR1o7INdt5z98dbyPUYFNALeXmQ,52933
|
|
8
|
+
grape_cli/update_check.py,sha256=HxXNO3xujVB7pclFj3EpfPKa88-Rde7dpFuo7YAVJWM,9574
|
|
9
|
+
grape_cli/commands/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
10
|
+
grape_cli/commands/doctor.py,sha256=48SqCbA_FMsq-YLH1Mel2SC7RLsASkIeUL7t5sfep4Y,15748
|
|
11
|
+
grape_cli/commands/git.py,sha256=Rb1b5xPVjPJuoM6Txl81hu6Bsu-NtNC7UKIfXBrwLRU,5328
|
|
12
|
+
grape_cli/data/examples.json,sha256=4hdvw7z-BLGbiec53bGOKOp4ajwDzd-w88O55CrxbuE,4937
|
|
13
|
+
grape_cli/data/openapi.json,sha256=wshm1CRg2JUlwTu96PTIVDJS2CYviPbPfRcsUO9Oj4Y,187368
|
|
14
|
+
grape_cli/data/token-scope.json,sha256=uYpKZHGNmWSouZxnRZ699hs77gsDfCTZSYVnfPA7_DE,291
|
|
15
|
+
grape_cli-0.3.4.dist-info/licenses/LICENSE,sha256=JeD9XPxk2Yq2p5sG3weUsokpKkTRYoiWIrI1c0p3B4Q,1065
|
|
16
|
+
grape_cli-0.3.4.dist-info/METADATA,sha256=IrpfC1ZI4NpthHglZlgxYT8nrtZ-FJGUvefpq40HfNQ,13119
|
|
17
|
+
grape_cli-0.3.4.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
18
|
+
grape_cli-0.3.4.dist-info/entry_points.txt,sha256=grA7beaLTT2d56inirXYOqPEKSjM5fyEK7mGUR6mgnk,45
|
|
19
|
+
grape_cli-0.3.4.dist-info/top_level.txt,sha256=QZcYRBgRoY6C8qzUC2zRKOPr01d9zFSvqFaTKc2_Pow,10
|
|
20
|
+
grape_cli-0.3.4.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 grape-dev
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
grape_cli
|