An open API service indexing awesome lists of open source software.

https://github.com/studyzy/gongfeng-cli

面向腾讯工蜂的cli工具,专门对AI Agent优化
https://github.com/studyzy/gongfeng-cli

Last synced: 26 days ago
JSON representation

面向腾讯工蜂的cli工具,专门对AI Agent优化

Awesome Lists containing this project

README

          

# gongfeng-cli

面向 AI Agent 的腾讯工蜂命令行工具,通过工蜂 API 实现代码托管核心操作。输出针对最小 token 消耗优化,列表默认紧凑 JSON、详情默认 Markdown。

## 安装

### 方式一:go install(推荐)

```bash
go install github.com/studyzy/gongfeng-cli/cmd/gongfeng@latest
```

### 方式二:从源码构建并安装

```bash
git clone git@github.com:studyzy/gongfeng-cli.git
cd gongfeng-cli
make install # 编译并安装到 $GOPATH/bin
```

### 方式三:仅构建二进制

```bash
git clone git@github.com:studyzy/gongfeng-cli.git
cd gongfeng-cli
make build # 在当前目录生成 ./gongfeng
```

## 认证

使用工蜂 Private Token 进行认证。

```bash
# 命令行登录(写入 ~/.gongfeng.json)
gongfeng auth login --token

# 写入当前目录 .gongfeng.json
gongfeng auth login --token --local

# 或设置环境变量
export GONGFENG_TOKEN=
```

凭据也可以直接写入配置文件 `~/.gongfeng.json` 或当前目录的 `.gongfeng.json`。

**凭据优先级**:环境变量 > `./.gongfeng.json` > `~/.gongfeng.json`,CLI flag(`--token`)可在调用时再次覆盖。

### 自定义工蜂站点地址

如需连接私有部署的工蜂实例,可通过环境变量、配置文件或 `--base-url` 指定:

```bash
# 环境变量
export GONGFENG_BASE_URL=https://your-gongfeng.example.com/
```

或写入配置文件:

```json
{
"token": "your-token",
"base_url": "https://your-gongfeng.example.com/"
}
```

| 配置项 | 环境变量 | JSON 字段 | 默认值 |
|--------|----------|-----------|--------|
| Private Token | `GONGFENG_TOKEN` | `token` | — |
| 项目 ID | `GONGFENG_PROJECT_ID` | `project_id` | — |
| API 地址 | `GONGFENG_BASE_URL` | `base_url` | `https://git.code.tencent.com/` |

## 基本用法

```bash
# 查询项目列表
gongfeng project list

# 查看项目详情(支持 namespace/project 路径或数字 ID)
gongfeng project show namespace/myproject

# 查询 MR 列表
gongfeng mr list

# 创建 MR
gongfeng mr create --source-branch feature/xxx --target-branch main --title "feat: 新功能"

# 合并 MR(参数为全局 id,非 iid)
gongfeng mr accept 42

# 查询分支列表
gongfeng branch list

# 查询提交列表
gongfeng commit list

# 查询缺陷列表
gongfeng issue list

# 创建缺陷
gongfeng issue create --title "Bug: 登录失败" --description "详情..."

# 查看所有命令参考(AI 自发现)
gongfeng --help
```

## 命令一览

以 `gongfeng --help` 实际输出为准,下表用于快速概览:

```
gongfeng
├── auth login
├── project list | owned | show | create | update | delete | search
│ members | member-show | share | shares | unshare
│ events | star | unstar | star-status | stars
├── mr list | show | create | update | accept
│ changes | commits | comments | download-files
├── commit list | show | diff | refs | comments | create-comment
├── commit-status list | create | result
├── branch list | show | create | delete
├── tag list | show | create | delete
├── issue list | my-list | show | create | update
│ subscribe | unsubscribe
├── release list | show | create | update | delete
├── review invite | remove | mr-show | approve | reject | mr-reopen | mr-cancel
│ commit-list | commit-show | commit-create | commit-update
│ commit-approve | commit-reject | commit-reopen
├── repo tree | file | create-file | update-file | delete-file
│ compare | raw | commit-blob
├── group list | show | create | update | delete | members
├── namespace list
├── label list | create | update | delete
├── milestone list | show | create | update | delete | issues
├── note mr-list | mr-show | mr-create | mr-update
│ issue-list | issue-show | issue-create | issue-update
│ review-list | review-show | review-create | review-update
├── fork create | link | unlink
├── user list | show | me | watched
│ ssh-keys | ssh-key-show | ssh-key-create | ssh-key-delete
│ emails | email-show | email-create | email-delete
│ find-by-email
├── watcher list | status | watch | unwatch
├── webhook list | show | create | update | delete
└── skill init
```

`gongfeng --version` 打印版本号。

## 全局标志

| 标志 | 说明 |
|------|------|
| `--project-id ` | 项目 ID 或 `namespace/project` 路径(覆盖配置)。支持整数 ID 或字符串路径 |
| `--token ` | 工蜂 Private Token(覆盖配置) |
| `--base-url ` | 工蜂实例 URL(覆盖配置) |
| `--json` | 强制 JSON 输出(列表默认已是 JSON,详情默认 Markdown 更省 token) |
| `--pretty` | 输出带缩进的 JSON,仅供人类阅读;AI Agent 不应使用(浪费 token),隐含 `--json` |

## 配置文件

配置文件为 `~/.gongfeng.json`(全局)或 `./.gongfeng.json`(项目级),两者可共存,项目级优先。

```json
{
"token": "your-private-token",
"project_id": "namespace/project",
"base_url": "https://git.code.tencent.com/"
}
```

## 输出格式

- **列表命令**:默认输出紧凑 JSON(无缩进),最小化 token 消耗
- **详情命令**:默认输出 Markdown 格式,加 `--json` 可切换为 JSON
- **人类阅读**:使用 `--pretty` 输出带缩进的 JSON

## AI Coding 工具集成

为 Cursor / Codex / Claude Code 等 AI Coding 工具一键生成 SKILL 指令文件:

```bash
gongfeng skill init
```

命令会扫描当前目录、交互式选择需要生成的工具,并在对应位置写入 `SKILL.md`,让 AI Agent 自动发现 gongfeng CLI 的使用规范。

## SDK

工蜂 Go SDK 已独立为单独的模块,可直接引入使用:

```bash
go get github.com/studyzy/gongfeng-sdk-go@latest
```

详见 [gongfeng-sdk-go](https://github.com/studyzy/gongfeng-sdk-go)。

## 开发

```bash
make build # 构建
make install # 安装到 $GOPATH/bin
make test # 运行测试(含 -race 与覆盖率)
make coverage # 生成 HTML 覆盖率报告
make lint # gofmt-check + go vet + golangci-lint
make fmt # gofmt -w + goimports -w
make ci # 本地完整复现 GitHub CI 流程
make tidy # go mod tidy
make release-check # 校验 .goreleaser.yml
make release-snapshot # 本地快照构建(不发布),生成跨平台产物到 dist/
make clean # 清理构建产物
```

CI 由 [`.github/workflows/ci.yml`](.github/workflows/ci.yml) 定义,包含 build / test / lint 三个并行 Job。

## 发布

推送 `v*` 形式的 tag 时,[`.github/workflows/release.yml`](.github/workflows/release.yml) 会自动通过 [GoReleaser](https://goreleaser.com) 构建并发布到 GitHub Releases,包含以下产物:

- `gongfeng__linux_x86_64.tar.gz`
- `gongfeng__macos_arm64.tar.gz`
- `gongfeng__windows_x86_64.zip`
- `checksums.txt`(SHA-256)

发布流程:

```bash
git tag v0.1.0
git push origin v0.1.0
```

构建配置见 [`.goreleaser.yml`](.goreleaser.yml),本地试跑可执行 `make release-snapshot`。

## 许可证

Apache License 2.0