已关闭
feat(cli): add missing --json support for remaining read-only inspection commands #158
aflyingto创建于 4月14日关闭于 5月1日
aflyingto
5月1日 评论:
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 中未暴露
jsonflag。 - 结论: #158 仍然有效,继续修复;本批优先补齐 issue 中列出的剩余只读 inspection 命令,并同步 help/schema/docs/tests。


aflyingto
5月1日 评论:
5月1日 评论:
aflyingto
5月1日 评论:
5月1日 评论:
aflyingto
5月1日 评论:
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 ...


aflyingto
5月1日 评论:
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, stderrMergeRequest Not Found./gc issue prs 999999 -R infra-test/gctest1 --json-> exit 3, stdout 0 bytes, stderrIssue Not Found./gc milestone view 999999 -R infra-test/gctest1 --json-> exit 3, stdout 0 bytes, stderrMilestone not found in project./gc commit comments view 999999999 -R infra-test/gctest1 --json-> exit 3, stdout 0 bytes, stderrnote 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


aflyingto
5月1日 评论:
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包含合并提交为准。


Summary
当前 agent-friendly 读路径仍不连续,多个只读检查命令缺少
--json,导致脚本和 AI 只能解析面向人类的文本输出。受影响的命令至少包括:
pr commentsissue prsrepo statsmilestone viewcommit comments viewcommit comments listcommit comments list-by-shaMost Urgent Gap
pr comments是pr reply --discussion的上游发现命令,但它没有任何结构化输出入口。调用方如果要自动发现 Discussion ID,只能从终端文本里抓取。Evidence
pr comments的帮助说明明确写了会展示 Discussion ID 供后续回复使用issue comments已经支持--jsonspec/foundations/agent-friendly-cli.md要求对外暴露数据结构的命令优先支持--jsongc schema也能直接证明这些命令当前没有--json相关代码位置:
pkg/cmd/pr/comments/comments.gopkg/cmd/issue/comments/comments.gopkg/cmd/issue/prs/prs.gopkg/cmd/repo/stats/stats.gopkg/cmd/milestone/view/view.gopkg/cmd/commit/comments/view/view.gopkg/cmd/commit/comments/list/list.gopkg/cmd/commit/comments/listbysha/listbysha.goExpected Result
--json