已关闭
feat(cli): add missing --json support for remaining read-only inspection commands #158
aflyingto创建于  4月14日关闭于  5月1日
aflyingto成员
4月14日 创建

Summary

当前 agent-friendly 读路径仍不连续,多个只读检查命令缺少 --json,导致脚本和 AI 只能解析面向人类的文本输出。

受影响的命令至少包括:

  • pr comments
  • issue prs
  • repo stats
  • milestone view
  • commit comments view
  • commit comments list
  • commit comments list-by-sha

Most Urgent Gap

pr comments 是 pr reply --discussion 的上游发现命令,但它没有任何结构化输出入口。调用方如果要自动发现 Discussion ID,只能从终端文本里抓取。

Evidence

  • pr comments 的帮助说明明确写了会展示 Discussion ID 供后续回复使用
  • issue comments 已经支持 --json
  • spec/foundations/agent-friendly-cli.md 要求对外暴露数据结构的命令优先支持 --json
  • gc schema 也能直接证明这些命令当前没有 --json

相关代码位置:

  • pkg/cmd/pr/comments/comments.go
  • pkg/cmd/issue/comments/comments.go
  • pkg/cmd/issue/prs/prs.go
  • pkg/cmd/repo/stats/stats.go
  • pkg/cmd/milestone/view/view.go
  • pkg/cmd/commit/comments/view/view.go
  • pkg/cmd/commit/comments/list/list.go
  • pkg/cmd/commit/comments/listbysha/listbysha.go

Expected Result

  • 优先为上述命令补齐 --json
  • 把 schema/help/docs 一并同步
  • 增加最小单测或回归覆盖,防止读路径再次出现结构化能力断层
likedislike
Aaflyingto成员
4月14日 添加了label:risk/mediumscope/cli, status/triage,type/feature
Aaflyingto成员
4月27日 关联了里程碑:2026-04 Open Issue Priority Plan
Aaflyingto成员
5月1日 添加了label:status/verified;删除了label:status/triage
aflyingto成员
5月1日 评论:

阶段记录

  • 阶段: verified
  • 当前验证版本或分支: origin/main
  • 复现命令:
    • gc schema 'pr comments'
    • gc schema 'issue prs'
    • gc schema 'repo stats'
    • gc schema 'milestone view'
    • gc schema 'commit comments view'
    • gc schema 'commit comments list'
    • gc schema 'commit comments list-by-sha'
  • 实际结果: 上述命令 schema 均存在,但 flags 中未暴露 json flag。
  • 结论: #158 仍然有效,继续修复;本批优先补齐 issue 中列出的剩余只读 inspection 命令,并同步 help/schema/docs/tests。
likedislike
Aaflyingto成员
5月1日 添加了label:status/in-progress;删除了label:status/verified
aflyingto成员
5月1日 评论:

阶段记录

  • 阶段: in-progress
  • 结论: 已基于最新 origin/main 创建开发分支 feature/issue-158,开始补齐剩余只读 inspection 命令的 --json。
  • 证据: issue 已 verified;工作树路径 ../gitcode-cli-issue-158;分支 feature/issue-158。
  • 下一步: 实现、补测试、同步 docs/REGRESSION/docs/COMMANDS/AI-GUIDE,并执行本地门禁和真实命令验证。
likedislike
Aaflyingto成员
5月1日 关联了pull request:[WIP]feat: add json output for read inspection commands
Aaflyingto成员
5月1日 删除了label:status/in-progress
Aaflyingto成员
5月1日 添加了label:status/ready-for-review
aflyingto成员
5月1日 评论:

阶段记录

  • 阶段: ready-for-review
  • 结论: #158 的实现、自测、文档同步、真实命令验证和风险分级已完成,PR !113 已创建并完成作者自检。
  • 证据: go test ./...、go build -o ./gc ./cmd/gc、7 个目标命令 schema 检查、./scripts/regression-core.sh、infra-test/gctest1 真实命令验证均通过;风险分级为 risk=medium。
  • 下一步: 将 PR !113 标记为 ready-for-review,并进入独立执行主体评审。
likedislike
Aaflyingto成员
5月1日 删除了label:risk/medium
Aaflyingto成员
5月1日 删除了label:status/ready-for-review
Aaflyingto成员
5月1日 添加了label:risk/highstatus/ready-for-review
aflyingto成员
5月1日 评论:

补充真实命令验证

  • 验证类型: 默认文本输出兼容性抽查
  • 测试仓库: infra-test/gctest1
  • 结论: 通过;新增 --json 未破坏默认文本输出路径。
  • 命令:
    • ./gc pr comments 11 -R infra-test/gctest1 -> 文本输出 157 行
    • ./gc issue prs 7 -R infra-test/gctest1 -> No pull requests associated with issue #7
    • ./gc repo stats -R infra-test/gctest1 --branch main -> 输出 Total commits: 1 和 By Author 表格
    • ./gc commit comments list -R infra-test/gctest1 -> 输出 #166568558 aflyingto Test comment from Issue #53
    • ./gc commit comments view 166568558 -R infra-test/gctest1 -> 输出评论详情和正文
    • ./gc commit comments list-by-sha 22440f40f8359201911d482418ae34e9ea39d8aa -R infra-test/gctest1 -> No comments found for commit ...
likedislike
aflyingto成员
5月1日 评论:

第二轮补充真实命令验证

  • 验证类型: JSON 错误路径 stdout 纯净度、空结果语义、limit/pagination 行为
  • 测试仓库: infra-test/gctest1
  • 结论: 通过;失败路径 stdout 为空,成功空结果保持可解析 JSON。
  • 错误路径 stdout 纯净度:
    • ./gc pr comments 999999 -R infra-test/gctest1 --json -> exit 3, stdout 0 bytes, stderr MergeRequest Not Found
    • ./gc issue prs 999999 -R infra-test/gctest1 --json -> exit 3, stdout 0 bytes, stderr Issue Not Found
    • ./gc milestone view 999999 -R infra-test/gctest1 --json -> exit 3, stdout 0 bytes, stderr Milestone not found in project
    • ./gc commit comments view 999999999 -R infra-test/gctest1 --json -> exit 3, stdout 0 bytes, stderr note not found by noteId
  • 成功空结果语义:
    • ./gc repo stats -R infra-test/gctest1 --branch __missing_branch__ --json -> 可解析 JSON 对象,total: 0
    • ./gc commit comments list-by-sha __missing_sha__ -R infra-test/gctest1 --json -> []
    • ./gc commit comments list-by-sha 22440f40f8359201911d482418ae34e9ea39d8aa -R infra-test/gctest1 --json -> []
  • limit / pagination:
    • ./gc pr comments 11 -R infra-test/gctest1 --limit 0 --json -> list 长度 22
    • ./gc pr comments 11 -R infra-test/gctest1 --limit 1 --json -> list 长度 1
    • ./gc commit comments list -R infra-test/gctest1 --page 1 --per-page 1 --json -> list 长度 1
likedislike
Aaflyingto成员
5月1日 关闭了 issue
Aaflyingto成员
5月1日 删除了label:status/ready-for-review
Aaflyingto成员
5月1日 添加了label:status/merged
aflyingto成员
5月1日 评论:

阶段记录

  • 阶段: merged
  • 结论: PR !113 已合入主干,#158 交付完成。
  • 主干事实: origin/main 已更新到 a94c8ad !113 merge feature/issue-158 into main,包含实现提交 0ca364b feat: add json output for read inspection commands。
  • 合并前门禁: 作者自检、全量测试、构建、schema 检查、核心回归、两轮 infra-test/gctest1 真实命令验证、独立 AI 评审均完成;本 PR 按 risk/high 由用户在会话中回复“继续”作为人工最终确认后合并。
  • 备注: PR API 回读显示 state=merged、merged_at=2026-05-01T08:15:22+08:00,但 merged 布尔字段仍为 false;最终完成判定以 merged PR state 和 origin/main 包含合并提交为准。
likedislike