-
Notifications
You must be signed in to change notification settings - Fork 0
Description
PRD: Agent-First Gitee CLI for gitee.com
Problem Statement
There is no focused CLI for gitee.com that AI agents and automation scripts can call reliably for core collaboration workflows. Today, common tasks such as creating pull requests, creating issues, reading issue history, reviewing prior comments, and posting follow-up comments usually require a mix of manual website actions, raw Git commands, or hand-written HTTP requests.
That creates several problems:
- Agents cannot complete high-frequency Gitee workflows through a stable, scriptable, non-interactive interface.
- The Gitee web UI is optimized for human interaction, not unattended automation.
- Calling the Gitee OpenAPI directly forces every caller to reimplement authentication, repository context resolution, pagination, output shaping, and error handling.
- Teams that already use GitHub
ghas a mental model do not have an equivalent Gitee-focused tool for shared human and agent workflows.
The goal is to build a Gitee CLI inspired by GitHub gh, but with a different priority order: v1 must be optimized first for AI agents and automation scripts, and only second for interactive human usage. The initial scope should cover the highest-value workflows: authentication, repository context inspection, pull request creation and inspection, issue creation and inspection, comment history retrieval, and posting replies to issues or pull requests.
This product is not intended to be a thin wrapper around the entire Gitee OpenAPI. It should provide a small, opinionated, high-value command surface with stable behavior and strong testability.
Solution
Build an agent-first CLI for gitee.com that follows the general workflow style of GitHub gh, while explicitly preferring deterministic, non-interactive automation over prompt-driven UX.
The v1 solution should:
- Provide a small, high-frequency command set centered on
auth,repo,pr, andissue. - Default to human-readable output, while requiring all core commands to support stable
--jsonoutput for machine consumption. - Prefer explicit inputs from flags, stdin, files, or repository context; missing prerequisites should fail fast rather than trigger hidden prompts.
- Integrate deeply with the local Git repository to infer
owner/repo, current branch, upstream branch, and default branch when safe. - Use a minimum-cost authentication strategy: Personal Access Token plus environment variables and a local config file.
- Wrap high-frequency Gitee APIs instead of exposing a raw API passthrough command.
- Use Rust as the
v1implementation language, with a conventional Rust CLI stack, to match the desired long-term direction even though Go would be more familiar.
Recommended v1 command surface:
gitee auth logingitee auth statusgitee auth logoutgitee repo viewgitee repo clonegitee pr creategitee pr viewgitee pr listgitee pr statusgitee pr checkoutgitee pr commentgitee issue creategitee issue viewgitee issue listgitee issue comment
Core agent-facing behavior:
- Every core command supports
--jsonwith a stable field contract. - Successful output goes to
stdout; errors go tostderr. - Exit codes are stable and distinguish authentication failures, argument errors, missing resources, local Git precondition failures, and API/network failures.
- The CLI never silently summarizes or truncates important remote state.
- Comment retrieval is explicit; callers must choose whether to fetch comments, how many to fetch, and whether to paginate.
- All write operations accept content from flags, files, or stdin so they can be driven by an agent without prompts.
User Stories
- As an AI coding agent, I want to authenticate with a Gitee personal access token, so that I can call Gitee APIs without browser-based OAuth.
- As an AI coding agent, I want the CLI to read credentials from environment variables or a local config file, so that I can run unattended in scripts and sandboxed environments.
- As an AI coding agent, I want
auth statusto verify the current login and identity, so that I can fail fast before starting a workflow. - As an AI coding agent, I want every core command to support
--json, so that I can parse results without scraping human-readable text. - As an AI coding agent, I want stable exit codes, so that I can branch my workflow on auth failures, invalid arguments, missing resources, and local Git problems.
- As an AI coding agent, I want the CLI to infer the current repository from local Git remotes, so that I do not need to repeat
owner/repoon every command. - As an AI coding agent, I want to override repository inference with an explicit
--repo, so that I can target a repository deterministically outside a local checkout. - As an AI coding agent, I want
repo viewto return canonical repository metadata and the default branch, so that downstream PR and issue operations have a trusted context. - As an AI coding agent, I want
repo cloneto clone by repository slug and explicit transport preference, so that I can bootstrap a working copy predictably. - As an AI coding agent, I want
pr createto create a pull request from the current branch with explicit title and body inputs, so that I can publish a code change without visiting the website. - As an AI coding agent, I want
pr createto derive a sensible default base branch from repository metadata, so that the common case needs fewer flags. - As an AI coding agent, I want
pr createto fail clearly when the local branch is not pushed or cannot be resolved safely, so that I do not create a PR against the wrong head branch. - As an AI coding agent, I want
pr createto accept body content from a file or stdin, so that I can generate and submit long-form PR descriptions programmatically. - As an AI coding agent, I want
pr viewto fetch a single pull request with structured metadata, so that I can inspect status, author, branches, URLs, and merge state. - As an AI coding agent, I want
pr listto filter by state, author, assignee, base, or head, so that I can find the exact PR I need to reason about. - As an AI coding agent, I want
pr statusto summarize pull requests related to the current user or current branch, so that I can understand outstanding work quickly. - As an AI coding agent, I want
pr checkoutto fetch and check out the head branch of an existing pull request, so that I can inspect or continue work locally. - As an AI coding agent, I want
pr commentto post a general pull request comment from a string, file, or stdin, so that I can publish review conclusions back to the PR thread. - As an AI coding agent, I want
issue createto create a new issue with explicit title and body inputs, so that I can report bugs, tasks, or follow-up work without visiting the website. - As an AI coding agent, I want
issue createto accept body content from a string, file, or stdin, so that I can generate detailed issue descriptions programmatically. - As an AI coding agent, I want
issue createto work with either explicit--repoinput or inferred local repository context, so that I can open issues deterministically in scripts and local checkouts. - As an AI coding agent, I want
issue listto filter by state and keyword, so that I can discover relevant bug reports before making changes. - As an AI coding agent, I want
issue viewto fetch the issue body and, when requested, its full comment history, so that I can understand prior discussion before attempting a fix. - As an AI coding agent, I want
issue commentto reply to an issue thread programmatically, so that I can report findings or remediation steps after making a change. - As a human developer, I want readable default terminal output, so that I can use the same tool manually without always requesting JSON.
- As a human developer, I want explicit, actionable error messages, so that I can correct missing authentication, repository context, or branch state quickly.
- As a maintainer, I want a small and stable
v1command surface, so that documentation, compatibility guarantees, and tests remain manageable. - As a maintainer, I want a deep repository-context module, so that Git parsing logic is centralized and independently testable rather than duplicated across commands.
- As a maintainer, I want a deep Gitee API client module, so that token injection, pagination, retries, and error normalization are implemented once and reused everywhere.
- As a maintainer, I want command handlers to stay thin, so that the product can evolve without repeated CLI glue rewrites.
- As a future contributor, I want core domain and transport contracts to be implementation-stable, so that internals can evolve without changing user-visible behavior.
Implementation Decisions
v1is intentionally agent-first rather than a full reimplementation of GitHubghinteraction patterns.v1supports onlygitee.comand does not target self-hosted or enterprise-private Gitee deployments.v1does not include a raw API passthrough command.- Rust is the primary implementation language for
v1. - The CLI layer should use a conventional Rust command framework so that subcommands, help output, argument validation, and shell completion remain predictable.
- Rust is chosen deliberately even though Go would be faster to deliver initially, because the desired direction is to invest in the Rust implementation rather than treat it as a later rewrite.
- The command layer should remain thin and focus on argument parsing, output rendering, and exit-code mapping.
- A dedicated configuration and authentication module should own token source precedence, config loading, secure file writes, and login-state verification.
- Token precedence should be explicit: login writes to local config, while runtime reads prefer environment variables first and config file second.
- A repository-context module should infer
owner/repo, current branch, upstream branch, and default branch from local Git state when safe. - A Gitee API client module should centralize HTTP transport, token injection, pagination, retries where appropriate, and normalized error handling.
- An output module should centralize text rendering and stable
--jsonserialization so commands do not format output independently. - JSON field stability is a product contract; changes to that contract should be treated as compatibility events.
- The CLI should define stable exit codes for at least these classes: success, generic failure, invalid arguments, authentication failure, not found, and local Git precondition failure.
repo viewshould return core repository metadata including canonical identifier, default branch, repository URL, clone URLs, and fork status.repo cloneshould clone byowner/repoand support an explicit transport choice such as SSH or HTTPS.pr createshould cover the highest-frequency case: creating a pull request from the current branch or an explicit--headinto an explicit or inferred--base.pr createshould not automatically create forks or attempt to support complex multi-remote collaboration topologies inv1.pr createshould support--title,--body,--body-file, stdin input, and explicit--repo.pr createshould fail rather than guess when the local branch has not been pushed, the remote mapping is ambiguous, or repository context cannot be resolved safely.pr viewandpr listshould wrap the official pull request APIs and expose only the most useful filters inv1.pr statusshould summarize the pull request state around the current user and current repository context rather than attempt to replace advanced search.pr checkoutshould integrate with local Git, fetch the relevant remote refs, create or switch a local branch, and report the resulting checkout state.pr commentshould support general pull request comments inv1, which is sufficient for the primary review-reply use case.- Line-level diff comments are supported by the upstream API but are out of scope for the initial release in order to keep the command model simple.
issue createshould be part of thev1command surface so issue authoring is covered alongside issue reading and commenting.issue createshould support--title,--body,--body-file, stdin input, and explicit--repo.issue createshould reuse repository-context resolution so it works both inside a local checkout and against an explicitly targeted repository.issue createshould fail rather than guess when required title input is missing, repository context is ambiguous, or repository resolution cannot be performed safely.issue listandissue viewshould prioritize reading issue history and discussion context.issue viewshould support explicit comment inclusion, but should not silently fetch unbounded comment history by default.issue commentshould support content from direct flags, files, or stdin.- All read commands should expose explicit pagination or count controls to avoid hidden truncation and unpredictable network usage.
- All write commands should remain non-interactive by default and fail fast when required input is missing.
- Configuration persistence should use a local config file with strict file permissions; system keychain integration is out of scope for
v1. - The architecture should keep domain behavior decoupled from transport details so the implementation stays testable and maintainable.
Recommended deep modules:
- Configuration and authentication: token discovery, config persistence, login-state validation.
- Repository context: Git remote parsing, branch inference, repository identity resolution.
- Gitee API client: transport, token injection, pagination, and normalized remote errors.
- Pull request workflows: create, view, list, status, checkout, and comment behavior.
- Issue workflows: create, view, list, and comment behavior.
- Output rendering: stable text and JSON contracts.
Testing Decisions
- A good test validates external behavior rather than internal implementation details.
- Tests should primarily cover visible outcomes: exit codes, stdout and stderr behavior, HTTP request intent, Git precondition handling, and
--jsonoutput shape. - Tests should not become brittle when internal function boundaries, command wiring, or transport helpers are refactored.
- The configuration and authentication module must be tested.
- The repository-context module must be tested.
- The Gitee API client module must be tested.
pr createparameter resolution and failure paths must be tested.issue createparameter resolution and failure paths must be tested.- Issue and pull request comment retrieval plus structured output must be tested.
pr checkoutshould be tested against controlled Git fixtures or fake remotes so fetch and checkout behavior is validated through observable results.--jsonoutput should be covered by contract tests or golden tests that lock down field names and key semantics.- The API client should use HTTP mock servers to cover success cases, authentication failures, not found responses, pagination, and multiple remote error shapes.
- Repository-context tests should use temporary Git repositories to cover HTTPS remotes, SSH remotes, missing upstreams, detached HEAD state, and default-branch lookup failures.
- Write commands should test title and body input via direct flags, body files, and stdin.
- The repository is currently empty, so there is no prior art in the codebase for tests.
- A fresh testing baseline should be established with table-driven unit tests, HTTP mock integration tests, Git fixture tests, and JSON golden tests.
Out of Scope
- Support for self-hosted or enterprise-private Gitee deployments.
- Raw OpenAPI passthrough commands.
- Browser OAuth, device flow, or keychain-based authentication.
- Full feature parity with every GitHub
ghcommand and flag. - Automatic fork creation and full cross-fork pull request workflows.
- Line-level diff review comments and complex review approval workflows.
- Labels, milestones, releases, actions, notifications, and other non-core command groups.
- Prompt-heavy interactive forms, wizards, or terminal UIs.
- Maintaining a separate Go implementation in parallel with the Rust implementation.
Further Notes
- The current Gitee Swagger documentation exposes the API surface needed for this
v1scope, including pull requests, issues, issue comments, pull request comments, forks, and authenticated user lookups. - The current Gitee OpenAPI widely uses
access_tokenin query or form parameters, which makes a PAT plus config-file approach viable forv1. - If delivery pressure increases, the project should still preserve behavior-first contracts such as JSON output shape, exit codes, and command semantics rather than weakening them for short-term speed.
- Future expansions could include JSON Lines output, templated rendering, richer review-comment support, or more advanced pagination helpers, but those should not be forced into the initial release.