Grape CLI

When to use the CLI, from installation and connection to the first command, plus exit codes and safe usage.

1. What the grape CLI is

grape is the official command-line tool for Grape. It does two things:

  1. Call the Grape platform API
  2. Run native git on the local machine and inject platform credentials automatically

It suits both manual use and scripts and Agents:

  • For people: multi-line text output by default
  • For scripts and Agents: add --json-out for single-line JSON
  • For success or failure: read the exit code, without parsing error text

CLI commands come from the server contract; they are not hand-written per endpoint. After the server adds an endpoint, grape refresh retrieves the new command.

2. When to use it

The CLI is not something you must use every day. These are the scenarios that use it most:

Scenario Frequency Who uses it Typical operations
Agent task execution Highest Platform Agents / Skills Read Issues, update status, write comments, create PRs, hand off
Local troubleshooting High Development, operations doctor, view the current task, inspect events, view logs
Scripts / CI Medium Automation scripts, Pipelines --json-out, batch queries, wait for a task to finish
Git operations Medium Developers grape git status/log/push, with credentials injected by the CLI
Skill development / upload Medium Skill developers Query Skills, view categories, bind Agents
Platform management Low Administrators Settings, credentials, engines; most of this is done in the web console

The most common use is Agent task execution: many Skills are CLI Skills themselves, and Agents read and write platform objects through grape instead of assembling API requests themselves.

When not to use the CLI

Task Better option
Browse Issues, view the Pipeline, click merge Web console
One-off configuration changes, view charts Web console
Dangerous operations that require manual confirmation Web console or Issue comments
A quick status check Web console

The CLI works best for repeated operations, scripts, Agents, and batch queries in the terminal.

The most common commands

grape doctor                 # confirm the connection and token first
grape tasks current --json-out
grape skills list --json-out
grape git status
grape commands               # list the commands available in this deployment

3. Installation

pip install grape-cli
grape --version

Upgrade:

pip install -U grape-cli

Source code or an intranet environment

pip install "git+https://gitcode.com/grape-dev/grape-cli.git@main"

Development and debugging:

git clone https://gitcode.com/grape-dev/grape-cli.git
cd grape-cli
pip install -e .

Completion criteria: grape --version prints the version number.

4. Connect to the server

The CLI needs two values:

  • Server address
  • Token

Three sources, in descending priority

Source Example Suited for
One-off parameter --base-url / --token Temporary debugging
Environment variable GRAPE_BASE_URL, GRAPE_SESSION_TOKEN, GRAPE_API_TOKEN CI, scripts, Agents
Configuration file ~/.grape/config.json Long-term local default

Address lookup order:

--base-url
  > GRAPE_BASE_URL
    > GRAPE_SERVER_URL
      > ~/.grape/config.json

There are two kinds of token:

token Purpose Lifetime
tk_ Used within a task or session Expires when the task ends, times out, or fails
grape_ Personal long-term API key Valid until revoked manually

Do not put the token in a command-line argument. --token remains in the shell history and the process list, so use environment variables or the configuration file for automation.

export GRAPE_BASE_URL=https://grape.example.com
export GRAPE_SESSION_TOKEN=tk_xxx

Then verify:

grape doctor

grape doctor checks:

  • The token channel
  • base_url
  • Proxy variables
  • The contract cache
  • The CLI version

Each item returns OK / WARN / FAIL, so run it first when the connection fails.

5. Run the first command

List the Skills on the platform first:

grape skills list --json-out

Then view the current task:

grape tasks current --json-out

Finally try native git:

grape git status
grape git log --oneline -5

grape git injects credentials from the in-process configuration; they are not written to .git/config and do not appear on the command line.

6. Common command groups

The command set is determined by the server you connect to, so it may differ slightly between deployments. To view the full list for the current deployment:

grape commands
grape <group> --help

Common groups:

Group Purpose
skills Skill list, upload, categories, Agent binding
tasks / task Current task, task details, wait, logs
issues Issue cards, status, awaiting input and pending review
scenes Scene templates, nodes, apply
runtime Workers, engines, credentials
repos Repository hosting, favorites, default Scene, platform credentials
git-repo Branches, commits, files, Issues/PRs, labels
events Event list, details, redispatch, terminate
settings Platform settings, credentials, engines, event configuration
obs Observability, alerts, log sources, health checks
dashboard Efficiency and operations dashboards
a2a / takeover Agent handoff, takeover sessions
knowledge / org / plugins Knowledge base, organizations, plugin marketplace
chat Conversations, sessions, messages
git Native git passthrough

Some groups are hidden depending on the credential type: with a task-level tk_, user-facing groups such as chat are hidden until you set GRAPE_CLI_MODE=USER / ALL or configure GRAPE_API_TOKEN.

Do not memorize commands; run grape commands first, then grape <group> --help.

7. Write operations and long request bodies

Write commands accept a request body in three ways. The examples below update issue metadata (issues has no update verb; to change issue metadata, use git-repo issues update):

# Recommended: read from a file, suitable for long text
grape git-repo issues update --owner o --repo r --number 7 --json-file body.json

# curl style
grape git-repo issues update --owner o --repo r --number 7 --json @body.json

# Read from stdin
grape git-repo issues update --owner o --repo r --number 7 --json - < body.json
  • --json-file is recommended for multi-line text, long text, and special characters
  • --json -, --json-file -, and --json @- all read from stdin
  • --json and --json-file are mutually exclusive; using both returns an error

Write operations (POST/PUT/PATCH/DELETE) accept --dry-run:

grape git-repo issues update --owner o --repo r --number 7 --dry-run

It prints only the redacted method, path, query, and body. It does not send the request and produces no side effects.

8. Use with scripts and Agents

Need Usage
Machine-readable output --json-out, single-line JSON
Determine success or failure Read the exit code; a failure is non-zero
Wait for a task to finish grape tasks wait --task-id <id> --timeout 120 --interval 3
List only the commands available to the current token GRAPE_CLI_MODE=WORKER
Avoid exposing git credentials Use grape git; do not assemble tokens yourself

9. Exit codes

Exit code Meaning
0 Success
1 General or configuration error: address, token, network
2 Usage error: missing arguments, unknown subcommand
>=400 HTTP status passthrough, such as 401 for an invalid token or 403 for insufficient permission
130 Interrupted with Ctrl+C

In scripts, check the exit code rather than matching error text.

10. Security conventions

  • The CLI provides settings key create / settings key delete --key_id <id> for user-level API keys (the plaintext is returned only once at creation; revocation is an immediate soft delete). Both are user_only endpoints that require a grape_ key or a web login session: a tk_ session gets 403, and they are hidden by default under GRAPE_CLI_MODE=WORKER (grape commands --all still lists them, marked [user_only]). tk_ session tokens are issued by the platform for the duration of a task; the CLI neither creates nor revokes them.
  • Tokens do not appear in output or error messages
  • Credentials injected by grape git are not written to disk or to .git/config
  • Do not use --token for automation; use environment variables or ~/.grape/config.json instead
  • Agents usually use tk_; use grape_ for long-running management operations, and do not mix them

11. Common issues

grape doctor reports FAIL

Fix the FAIL items first. Common causes:

  • base_url is not an address reachable from the browser or the local machine
  • The token has expired or has the wrong type
  • Proxy variables interfere; add --no-proxy
  • The contract cache is stale; run grape refresh

401 / invalid token

tk_ session tokens expire when the task ends. Obtain a new session token, or switch to grape_.

Connection failure or timeout

Run grape doctor first to check the address and the token channel; in environments with self-signed certificates, confirm that the scheme and host are actually reachable.

The command list does not match the documentation

Run grape refresh first. If it still does not match, the connected server has a different contract version. grape commands is the authoritative list for the current deployment.

Change the address temporarily

One-off parameters take precedence over environment variables and the configuration file:

grape --base-url https://other.example.com --timeout 300 tasks current --json-out

12. Completion criteria

  • [ ] grape --version produces output.
  • [ ] grape doctor reports OK for every item.
  • [ ] You can list Skills or the current task.
  • [ ] You can operate on a repository with grape git status.
  • [ ] You know what --json-out and the exit codes are for.
  • [ ] The token is not placed in command-line arguments.

Runtime and Worker | Agent overview | Account activation and login | Chat Agent and IM channels