grape-cli 0.3.4__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.
- grape_cli-0.3.4/LICENSE +21 -0
- grape_cli-0.3.4/PKG-INFO +274 -0
- grape_cli-0.3.4/README.md +248 -0
- grape_cli-0.3.4/grape_cli/__init__.py +2 -0
- grape_cli-0.3.4/grape_cli/__main__.py +7 -0
- grape_cli-0.3.4/grape_cli/cli.py +354 -0
- grape_cli-0.3.4/grape_cli/client.py +397 -0
- grape_cli-0.3.4/grape_cli/commands/__init__.py +0 -0
- grape_cli-0.3.4/grape_cli/commands/doctor.py +324 -0
- grape_cli-0.3.4/grape_cli/commands/git.py +137 -0
- grape_cli-0.3.4/grape_cli/config.py +221 -0
- grape_cli-0.3.4/grape_cli/contracts.py +281 -0
- grape_cli-0.3.4/grape_cli/data/examples.json +85 -0
- grape_cli-0.3.4/grape_cli/data/openapi.json +1 -0
- grape_cli-0.3.4/grape_cli/data/token-scope.json +17 -0
- grape_cli-0.3.4/grape_cli/registry.py +1193 -0
- grape_cli-0.3.4/grape_cli/update_check.py +290 -0
- grape_cli-0.3.4/grape_cli.egg-info/PKG-INFO +274 -0
- grape_cli-0.3.4/grape_cli.egg-info/SOURCES.txt +37 -0
- grape_cli-0.3.4/grape_cli.egg-info/dependency_links.txt +1 -0
- grape_cli-0.3.4/grape_cli.egg-info/entry_points.txt +2 -0
- grape_cli-0.3.4/grape_cli.egg-info/requires.txt +5 -0
- grape_cli-0.3.4/grape_cli.egg-info/top_level.txt +1 -0
- grape_cli-0.3.4/pyproject.toml +54 -0
- grape_cli-0.3.4/setup.cfg +4 -0
- grape_cli-0.3.4/test/test_cli.py +610 -0
- grape_cli-0.3.4/test/test_client.py +629 -0
- grape_cli-0.3.4/test/test_config.py +248 -0
- grape_cli-0.3.4/test/test_contracts.py +410 -0
- grape_cli-0.3.4/test/test_doctor.py +283 -0
- grape_cli-0.3.4/test/test_dry_run.py +176 -0
- grape_cli-0.3.4/test/test_git.py +247 -0
- grape_cli-0.3.4/test/test_json_file.py +172 -0
- grape_cli-0.3.4/test/test_prefix_overlap.py +371 -0
- grape_cli-0.3.4/test/test_pulls_files_pagination.py +218 -0
- grape_cli-0.3.4/test/test_registry.py +982 -0
- grape_cli-0.3.4/test/test_release_note.py +76 -0
- grape_cli-0.3.4/test/test_update_check.py +190 -0
- grape_cli-0.3.4/test/test_version.py +94 -0
grape_cli-0.3.4/LICENSE
ADDED
|
@@ -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.
|
grape_cli-0.3.4/PKG-INFO
ADDED
|
@@ -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,248 @@
|
|
|
1
|
+
<h1 align="center">grape CLI</h1>
|
|
2
|
+
|
|
3
|
+
<p align="center">English | <a href="README.zh.md">中文</a></p>
|
|
4
|
+
|
|
5
|
+
<p align="center">
|
|
6
|
+
<strong>Contract-driven CLI for the Grape Agentic DevOps platform — zero token exposure</strong>
|
|
7
|
+
<br>
|
|
8
|
+
Point it at any Grape server — new commands appear automatically.
|
|
9
|
+
</p>
|
|
10
|
+
|
|
11
|
+
<p align="center">
|
|
12
|
+
<a href="#what-is-grape-cli">What is grape CLI</a> ·
|
|
13
|
+
<a href="#the-problem">The Problem</a> ·
|
|
14
|
+
<a href="#core-features">Core Features</a> ·
|
|
15
|
+
<a href="#install">Install</a> ·
|
|
16
|
+
<a href="#quick-start">Quick Start</a> ·
|
|
17
|
+
<a href="#configuration--token">Configuration & Token</a> ·
|
|
18
|
+
<a href="#commands">Commands</a> ·
|
|
19
|
+
<a href="#exit-codes">Exit Codes</a> ·
|
|
20
|
+
<a href="#security">Security</a> ·
|
|
21
|
+
<a href="#development--testing">Development & Testing</a> ·
|
|
22
|
+
<a href="#contributing">Contributing</a>
|
|
23
|
+
</p>
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## What is grape CLI
|
|
28
|
+
|
|
29
|
+
Grape CLI is the command-line client for the [Grape](https://gitcode.com/grape-dev/grape) platform,
|
|
30
|
+
**designed primarily for Agents**. It walks the repository's DevOps workflow and gives an Agent the
|
|
31
|
+
full context of that repo, so the Agent can precisely understand the project background and turn a
|
|
32
|
+
developer's requirements into accurate, implementation-ready actions. It reads the server's OpenAPI
|
|
33
|
+
contract, auto-generates `grape <group> <verb>` commands, and runs native `git` operations locally
|
|
34
|
+
with credentials kept strictly in-process.
|
|
35
|
+
|
|
36
|
+
**In one sentence: add a server endpoint → re-fetch the contract → the CLI gains the command, no source changes.**
|
|
37
|
+
|
|
38
|
+
## The Problem
|
|
39
|
+
|
|
40
|
+
Interacting with a contract-driven API usually means hand-written `curl`, fragile scripts, and
|
|
41
|
+
tokens leaking into shell history:
|
|
42
|
+
|
|
43
|
+
| | Manual | grape CLI |
|
|
44
|
+
|-|--------|-----------|
|
|
45
|
+
| Call a new endpoint | Write `curl` + parse JSON by hand | `grape <group> <verb>` auto-generated from OpenAPI |
|
|
46
|
+
| Auth | Copy tokens into shell history / files | Token from one-shot args, env, or config — attached automatically |
|
|
47
|
+
| Run git against the platform | Persist remote credentials on disk | `grape git` injects credentials in-process, never persisted |
|
|
48
|
+
| Server API changes | Update every client script | Re-fetch contract — CLI updates itself |
|
|
49
|
+
|
|
50
|
+
## Core Features
|
|
51
|
+
|
|
52
|
+
- **Contract-driven commands** — OpenAPI 3.x `operationId` becomes a command tree (`tasks_current` → `grape tasks current`); the command set mirrors the connected server.
|
|
53
|
+
- **Automatic auth injection** — Bearer token attached by default (client also supports `PRIVATE-TOKEN` / `?access_token=` channels).
|
|
54
|
+
- **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.
|
|
55
|
+
- **Built-in `tasks wait`** — poll a task until a terminal state (`completed` / `failed` / `cancelled`).
|
|
56
|
+
- **Machine-readable output** — `--json-out` emits single-line JSON for workers and scripts.
|
|
57
|
+
- **Mode-aware command sets** — `GRAPE_CLI_MODE` (WORKER / USER / ALL) filters commands by token scope (dual / session-only / user-only).
|
|
58
|
+
|
|
59
|
+
## Install
|
|
60
|
+
|
|
61
|
+
Three supported channels; the command is always `grape` (distribution name:
|
|
62
|
+
`grape-cli`). Requires Python >= 3.10.
|
|
63
|
+
|
|
64
|
+
### PyPI (recommended)
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
pip install grape-cli
|
|
68
|
+
# upgrade later
|
|
69
|
+
pip install -U grape-cli
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### From git (fallback)
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
pip install "git+https://gitcode.com/grape-dev/grape-cli.git@main"
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Editable install (development)
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
git clone https://gitcode.com/grape-dev/grape-cli.git
|
|
82
|
+
cd grape-cli
|
|
83
|
+
|
|
84
|
+
pip install -e .
|
|
85
|
+
# Or a dedicated venv (isolated from the system)
|
|
86
|
+
python3 -m venv /opt/grape-cli
|
|
87
|
+
/opt/grape-cli/bin/pip install -e /path/to/grape-cli
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Verify with `grape --version`.
|
|
91
|
+
|
|
92
|
+
### New-version check
|
|
93
|
+
|
|
94
|
+
After a command finishes, `grape` may print one line to **stderr** when a newer
|
|
95
|
+
release is available (`grape X.Y.Z is available ... Upgrade: pip install -U grape-cli`).
|
|
96
|
+
The check runs in a background daemon thread (0.5s connect / 1.5s total timeout),
|
|
97
|
+
caches results for 24h in `~/.grape/version-check.json`, notifies once per
|
|
98
|
+
version, and stays silent when offline or on errors. It is off by default for
|
|
99
|
+
non-TTY runs and `CI=1`.
|
|
100
|
+
|
|
101
|
+
Disable it explicitly with any of:
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
grape --no-version-check issues list
|
|
105
|
+
export GRAPE_NO_VERSION_CHECK=1
|
|
106
|
+
# ~/.grape/config.json
|
|
107
|
+
# {"version_check": false}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Quick Start
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
# One-shot (no env vars required)
|
|
114
|
+
grape --base-url https://grape.example.com --token tk_xxx skills list --json-out
|
|
115
|
+
|
|
116
|
+
# Common setup, then explore
|
|
117
|
+
export GRAPE_BASE_URL=https://grape.example.com
|
|
118
|
+
export GRAPE_SESSION_TOKEN=tk_xxx # or: export GRAPE_API_TOKEN=grape_xxx
|
|
119
|
+
grape commands | head -40
|
|
120
|
+
grape skills list --json-out
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## Configuration & Token
|
|
124
|
+
|
|
125
|
+
Precedence (highest first):
|
|
126
|
+
`--token / --base-url / --timeout` (one-shot, process-only) > `GRAPE_SESSION_TOKEN` >
|
|
127
|
+
`GRAPE_API_TOKEN` / `GRAPE_BASE_URL` > `~/.grape/config.json`.
|
|
128
|
+
|
|
129
|
+
| Source | Example | Notes |
|
|
130
|
+
|--------|---------|-------|
|
|
131
|
+
| 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) |
|
|
132
|
+
| 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 |
|
|
133
|
+
| Config file | `{ "base_url": "...", "token": "" }` in `~/.grape/config.json` | Persistent defaults; prefer env vars for tokens |
|
|
134
|
+
|
|
135
|
+
- In `GRAPE_CLI_MODE=USER`, `GRAPE_API_TOKEN` takes priority over `GRAPE_SESSION_TOKEN`.
|
|
136
|
+
- Without a token, commands fail with a message telling you how to configure one.
|
|
137
|
+
|
|
138
|
+
## Commands
|
|
139
|
+
|
|
140
|
+
### Global
|
|
141
|
+
|
|
142
|
+
```bash
|
|
143
|
+
grape --version / -v # version
|
|
144
|
+
grape --help # contract groups + built-ins (git/refresh/commands)
|
|
145
|
+
grape commands [pattern] # list contract commands; pipe to filter: grape commands | grep issue
|
|
146
|
+
grape refresh # force-fetch the newest OpenAPI contract and refresh the cache
|
|
147
|
+
grape tasks wait --task-id 56 --timeout 120 --interval 3 # poll a task until terminal state
|
|
148
|
+
grape --timeout 300 tasks current # request timeout (default 30s; git unaffected)
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### Contract-driven commands (automatic)
|
|
152
|
+
|
|
153
|
+
Shape: `grape <group> <verb> [--options...]`, derived from `operationId`:
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
grape tasks current --json-out
|
|
157
|
+
grape tasks complete --json '{"result_text":"done","next_step":"a2a_issue"}'
|
|
158
|
+
grape issues list --owner o --repo r --json-out
|
|
159
|
+
grape git-repo issues list --owner o --repo r --state open --json-out
|
|
160
|
+
grape git-repo contents --owner o --repo r --path README.md --raw # base64-decoded file text
|
|
161
|
+
grape skills upload --file skill.zip --scope user --agent_type coding
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
- `query` / `path` params → `--<name>`; `requestBody` → `--json '<JSON>'`; `--json-out` → single-line machine-readable JSON.
|
|
165
|
+
<<<<<<< HEAD
|
|
166
|
+
- 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.
|
|
167
|
+
=======
|
|
168
|
+
- Long bodies: `--json @file.json` reads from a file, `--json @-` reads from stdin (no shell escaping).
|
|
169
|
+
- `--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.
|
|
170
|
+
>>>>>>> origin/main
|
|
171
|
+
- Multipart endpoints (uploads) use `--file <path>` plus form-field options; `git-repo contents --raw` decodes a file to raw text.
|
|
172
|
+
- `--json` bodies are validated against the contract — unknown fields / missing required fields fail fast and print the allowed field list.
|
|
173
|
+
- Discover: `grape <group> --help` (verbs) then `grape <group> <verb> --help` (params, body fields, examples). Unknown verbs get a `Did you mean ...` suggestion.
|
|
174
|
+
- 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.
|
|
175
|
+
|
|
176
|
+
The exact groups/verbs mirror the connected server's contract — run `grape commands` to see what is live.
|
|
177
|
+
|
|
178
|
+
### git (local execution, zero token exposure)
|
|
179
|
+
|
|
180
|
+
`grape git` is a **native git passthrough**. It auto-detects the repo — from the
|
|
181
|
+
`clone` URL argument, or from the current directory's `remote.origin.url` — exchanges
|
|
182
|
+
the session token for a short-lived platform credential in-process, and injects it via
|
|
183
|
+
`GIT_CONFIG` env vars: **never on the command line, never written to disk, invisible to
|
|
184
|
+
the agent**. gitcode.com and github.com hosts get credentials; on an exchange failure you get a
|
|
185
|
+
warning and git runs natively. `grape git --help` is identical to `git --help`.
|
|
186
|
+
|
|
187
|
+
```bash
|
|
188
|
+
grape git status # local command (no credential needed)
|
|
189
|
+
grape git clone https://gitcode.com/owner/repo.git # repo parsed from URL → credential injected
|
|
190
|
+
grape git pull # repo parsed from remote.origin.url
|
|
191
|
+
grape git push
|
|
192
|
+
grape git checkout -b feat/issue-7
|
|
193
|
+
grape git commit -m "fix: ..."
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
### Token scopes & GRAPE_CLI_MODE
|
|
197
|
+
|
|
198
|
+
Each contract operation carries a token scope: `dual`, `session_only`, or `user_only`.
|
|
199
|
+
|
|
200
|
+
- `session_only` (e.g. repo workspace / git-credential) — needs a `tk_` session token; API keys are rejected (403).
|
|
201
|
+
- `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.
|
|
202
|
+
- `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).
|
|
203
|
+
|
|
204
|
+
## Exit Codes
|
|
205
|
+
|
|
206
|
+
`0` success · `1` generic/config error · `2` usage error ·
|
|
207
|
+
`>=400` HTTP status passthrough (e.g. `401`) · `130` Ctrl+C.
|
|
208
|
+
|
|
209
|
+
## Security
|
|
210
|
+
|
|
211
|
+
- No create/revoke token subcommands (prevents self-escalation); user-level API keys come from the Web UI.
|
|
212
|
+
- Tokens never appear in output/errors; git credentials injected via `GIT_CONFIG` stay in-process and are never written to disk.
|
|
213
|
+
- `tk_` session tokens auto-expire with the task/session; `grape_` user keys can be revoked.
|
|
214
|
+
- `grape git` injects credentials for gitcode.com / github.com hosts and degrades to plain native git (with a warning) if an exchange fails.
|
|
215
|
+
|
|
216
|
+
## Development & Testing
|
|
217
|
+
|
|
218
|
+
```bash
|
|
219
|
+
pip install -e .[dev]
|
|
220
|
+
python -m pytest test/ -q
|
|
221
|
+
|
|
222
|
+
# Release preflight (version is a single source: grape_cli.__version__)
|
|
223
|
+
python -m build
|
|
224
|
+
python scripts/check_version.py --tag v0.3.4 --dist dist
|
|
225
|
+
python -m twine check dist/*
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
Publishing is tag-driven: pushing a `v*` tag runs `.github/workflows/release.yml`
|
|
229
|
+
(tests → build → three-way version check → twine check → twine upload). The
|
|
230
|
+
`PYPI_API_TOKEN` CI secret must be configured by a maintainer; it is never stored
|
|
231
|
+
in the repository.
|
|
232
|
+
|
|
233
|
+
Test coverage: config precedence, HTTP client (auth/errors), contract loading & caching,
|
|
234
|
+
command generation, CLI end-to-end, git passthrough (credential injection / exit codes),
|
|
235
|
+
new-version check (hit/miss/offline/disabled/TTL/one-shot) and version consistency.
|
|
236
|
+
|
|
237
|
+
## Contributing
|
|
238
|
+
|
|
239
|
+
1. **Open an Issue** — describe the problem or feature
|
|
240
|
+
2. **Fork & Develop** — work on a feature branch (`feat/`, `fix/`, `refactor/`, `docs/`, `chore/`)
|
|
241
|
+
3. **Add Tests** — include pytest tests for new behavior
|
|
242
|
+
4. **Submit a PR** — describe changes, test results, and linked Issue
|
|
243
|
+
|
|
244
|
+
## Feedback
|
|
245
|
+
|
|
246
|
+
- **GitCode Issues**: https://gitcode.com/grape-dev/grape-cli/issues
|
|
247
|
+
- Bugs: include environment, repro steps, and logs
|
|
248
|
+
- Feature suggestions: describe the use case and expected behavior
|