Grape官方CLI工具,集成了grape对外提供所有API接口对应的CLI命令,同时还集成了gitcode、github、gitlab、git等常见的开发命令行工具,使用统一grape token均可以实现无缝调用,方便agent获取项目上下文;
| Files | Last commit | Last update |
|---|---|---|
| 9 days ago | ||
| 11 days ago | ||
| 2 days ago | ||
| 9 days ago | ||
| 11 days ago | ||
| 2 days ago | ||
| 1 month ago | ||
| 2 days ago | ||
| 1 month ago | ||
| 9 days ago | ||
| 9 days ago | ||
| 9 days ago |
grape CLI
English | 中文
Contract-driven CLI for the Grape Agentic DevOps platform — zero token exposure
Point it at any Grape server — new commands appear automatically.
What is grape CLI · The Problem · Core Features · Install · Quick Start · Configuration & Token · Commands · Exit Codes · Security · Development & Testing · Contributing
What is grape CLI
Grape CLI is the command-line client for the Grape platform,
designed primarily for Agents. It walks the repository's DevOps workflow and gives an Agent the
full context of that repo, so the Agent can precisely understand the project background and turn a
developer's requirements into accurate, implementation-ready actions. It reads the server's OpenAPI
contract, auto-generates grape <group> <verb> commands, and runs native git operations locally
with credentials kept strictly in-process.
In one sentence: add a server endpoint → re-fetch the contract → the CLI gains the command, no source changes.
The Problem
Interacting with a contract-driven API usually means hand-written curl, fragile scripts, and
tokens leaking into shell history:
| Manual | grape CLI | |
|---|---|---|
| Call a new endpoint | Write curl + parse JSON by hand |
grape <group> <verb> auto-generated from OpenAPI |
| Auth | Copy tokens into shell history / files | Token from one-shot args, env, or config — attached automatically |
| Run git against the platform | Persist remote credentials on disk | grape git injects credentials in-process, never persisted |
| Server API changes | Update every client script | Re-fetch contract — CLI updates itself |
Core Features
- Contract-driven commands — OpenAPI 3.x
operationIdbecomes a command tree (tasks_current→grape tasks current); the command set mirrors the connected server. - Automatic auth injection — Bearer token attached by default (client also supports
PRIVATE-TOKEN/?access_token=channels). - Native git passthrough —
grape gitruns realgit, auto-detects the repo, and injects a short-lived credential viaGIT_CONFIGenv vars — never on the command line, never on disk. - Built-in
tasks wait— poll a task until a terminal state (completed/failed/cancelled). - Machine-readable output —
--json-outemits single-line JSON for workers and scripts. - Mode-aware command sets —
GRAPE_CLI_MODE(WORKER / USER / ALL) filters commands by token scope (dual / session-only / user-only).
Install
Three supported channels; the command is always grape (distribution name:
grape-cli). Requires Python >= 3.10.
PyPI (recommended)
pip install grape-cli
# upgrade later
pip install -U grape-cli
From git (fallback)
pip install "git+https://gitcode.com/grape-dev/grape-cli.git@main"
Editable install (development)
git clone https://gitcode.com/grape-dev/grape-cli.git
cd grape-cli
pip install -e .
# Or a dedicated venv (isolated from the system)
python3 -m venv /opt/grape-cli
/opt/grape-cli/bin/pip install -e /path/to/grape-cli
Verify with grape --version.
New-version check
After a command finishes, grape may print one line to stderr when a newer
release is available (grape X.Y.Z is available ... Upgrade: pip install -U grape-cli).
The check runs in a background daemon thread (0.5s connect / 1.5s total timeout),
caches results for 24h in ~/.grape/version-check.json, notifies once per
version, and stays silent when offline or on errors. It is off by default for
non-TTY runs and CI=1.
Disable it explicitly with any of:
grape --no-version-check issues list
export GRAPE_NO_VERSION_CHECK=1
# ~/.grape/config.json
# {"version_check": false}
Quick Start
# One-shot (no env vars required)
grape --base-url https://grape.example.com --token tk_xxx skills list --json-out
# Common setup, then explore
export GRAPE_BASE_URL=https://grape.example.com
export GRAPE_SESSION_TOKEN=tk_xxx # or: export GRAPE_API_TOKEN=grape_xxx
grape commands | head -40
grape skills list --json-out
Configuration & Token
Precedence (highest first):
--token / --base-url / --timeout (one-shot, process-only) > GRAPE_SESSION_TOKEN >
GRAPE_API_TOKEN / GRAPE_BASE_URL > ~/.grape/config.json.
| Source | Example | Notes |
|---|---|---|
| One-shot args (recommended) | grape --token tk_xxx tasks currentgrape --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) |
| 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 |
| Config file | { "base_url": "...", "token": "" } in ~/.grape/config.json |
Persistent defaults; prefer env vars for tokens |
- In
GRAPE_CLI_MODE=USER,GRAPE_API_TOKENtakes priority overGRAPE_SESSION_TOKEN. - Without a token, commands fail with a message telling you how to configure one.
Commands
Global
grape --version / -v # version
grape --help # contract groups + built-ins (git/refresh/commands)
grape commands [pattern] # list contract commands; pipe to filter: grape commands | grep issue
grape refresh # force-fetch the newest OpenAPI contract and refresh the cache
grape tasks wait --task-id 56 --timeout 120 --interval 3 # poll a task until terminal state
grape --timeout 300 tasks current # request timeout (default 30s; git unaffected)
Contract-driven commands (automatic)
Shape: grape <group> <verb> [--options...], derived from operationId:
grape tasks current --json-out
grape tasks complete --json '{"result_text":"done","next_step":"a2a_issue"}'
grape issues list --owner o --repo r --json-out
grape git-repo issues list --owner o --repo r --state open --json-out
grape git-repo contents --owner o --repo r --path README.md --raw # base64-decoded file text
grape skills upload --file skill.zip --scope user --agent_type coding
query/pathparams →--<name>;requestBody→--json '<JSON>';--json-out→ single-line machine-readable JSON. <<<<<<< HEAD- Long bodies:
--json-file <path>reads from a file (recommended),--json @file.jsonis the curl-style equivalent, and--json -/--json-file -/--json @-read from stdin (no shell escaping).--jsonand--json-fileare mutually exclusive. ======= - Long bodies:
--json @file.jsonreads from a file,--json @-reads from stdin (no shell escaping). --jsonfailure 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--jsonvalue →--json value is empty(no request is sent). All failures exit non-zero with a message on stderr.
origin/main
- Multipart endpoints (uploads) use
--file <path>plus form-field options;git-repo contents --rawdecodes a file to raw text. --jsonbodies are validated against the contract — unknown fields / missing required fields fail fast and print the allowed field list.- Discover:
grape <group> --help(verbs) thengrape <group> <verb> --help(params, body fields, examples). Unknown verbs get aDid you mean ...suggestion. - Contract source priority:
{server}/static/openapi.json→{server}/openapi.json→ bundled snapshot. Fetched contracts are cached in~/.grape/openapi-<version>.json;grape refreshbypasses the cache and prints the source.
The exact groups/verbs mirror the connected server's contract — run grape commands to see what is live.
git (local execution, zero token exposure)
grape git is a native git passthrough. It auto-detects the repo — from the
clone URL argument, or from the current directory's remote.origin.url — exchanges
the session token for a short-lived platform credential in-process, and injects it via
GIT_CONFIG env vars: never on the command line, never written to disk, invisible to
the agent. gitcode.com and github.com hosts get credentials; on an exchange failure you get a
warning and git runs natively. grape git --help is identical to git --help.
grape git status # local command (no credential needed)
grape git clone https://gitcode.com/owner/repo.git # repo parsed from URL → credential injected
grape git pull # repo parsed from remote.origin.url
grape git push
grape git checkout -b feat/issue-7
grape git commit -m "fix: ..."
Token scopes & GRAPE_CLI_MODE
Each contract operation carries a token scope: dual, session_only, or user_only.
session_only(e.g. repo workspace / git-credential) — needs atk_session token; API keys are rejected (403).user_only(e.g. agents detail, skills list, chat) — atk_session token is rejected with a hint to setGRAPE_API_TOKEN/ use a Web JWT.GRAPE_CLI_MODEfiltersgrape --helpandgrape commandsto what the current role may run:WORKER(session-only + dual),USER(user-only + dual),ALL(everything, default).
Exit Codes
0 success · 1 generic/config error · 2 usage error ·
>=400 HTTP status passthrough (e.g. 401) · 130 Ctrl+C.
Security
- No create/revoke token subcommands (prevents self-escalation); user-level API keys come from the Web UI.
- Tokens never appear in output/errors; git credentials injected via
GIT_CONFIGstay in-process and are never written to disk. tk_session tokens auto-expire with the task/session;grape_user keys can be revoked.grape gitinjects credentials for gitcode.com / github.com hosts and degrades to plain native git (with a warning) if an exchange fails.
Development & Testing
pip install -e .[dev]
python -m pytest test/ -q
# Release preflight (version is a single source: grape_cli.__version__)
python -m build
python scripts/check_version.py --tag v0.3.4 --dist dist
python -m twine check dist/*
Publishing is tag-driven: pushing a v* tag runs .github/workflows/release.yml
(tests → build → three-way version check → twine check → twine upload). The
PYPI_API_TOKEN CI secret must be configured by a maintainer; it is never stored
in the repository.
Test coverage: config precedence, HTTP client (auth/errors), contract loading & caching, command generation, CLI end-to-end, git passthrough (credential injection / exit codes), new-version check (hit/miss/offline/disabled/TTL/one-shot) and version consistency.
Contributing
- Open an Issue — describe the problem or feature
- Fork & Develop — work on a feature branch (
feat/,fix/,refactor/,docs/,chore/) - Add Tests — include pytest tests for new behavior
- Submit a PR — describe changes, test results, and linked Issue
Feedback
- GitCode Issues: https://gitcode.com/grape-dev/grape-cli/issues
- Bugs: include environment, repro steps, and logs
- Feature suggestions: describe the use case and expected behavior
Introduction
Grape官方CLI工具,集成了grape对外提供所有API接口对应的CLI命令,同时还集成了gitcode、github、gitlab、git等常见的开发命令行工具,使用统一grape token均可以实现无缝调用,方便agent获取项目上下文;
https://gitcode.com/grape-dev/grape-cliCustomize your domain