forge issue view, pr view: --json and --jq #200

Merged
vnprc merged 2 commits from agent/forge-view-json into master 2026-09-11 20:13:11 +01:00
Member

forge issue view and forge pr view gain --json <fields> and --jq <expression>, copying gh. With --json, the command makes one request and prints exactly the requested fields as a JSON object, so an issue or PR body can be pulled down as it actually is on the forge and edited from there instead of retyped from the rendered view. Without the flags, output is byte-identical to today, and the existing tests pin that. --jq is deliberately a small subset: a dotted field path such as .body, printed raw the way jq -r does; anything else is refused before any request. Nothing changes for callers that never pass the flags. If this is wrong, revert the two commits; no other tool depends on the new flags yet.

Closes allod/tools#190

Risk

R1. Additive read-side flags on two commands; the existing rendering paths are untouched and their tests unchanged. Rollback is a revert.

Known limits, stated in the docs: --jq .body prints the body plus one newline (jq's convention), so a view --jq .body > f; edit --body-file f cycle adds one trailing newline per round trip; the JSON object form is the exact one. A null body renders as the empty string. --body-file still replaces the whole body, so this does not merge concurrent edits.

Validation

  • nix build .#checks.x86_64-linux.go-checks passes on the final commit (gofmt, vet, go test across all tag sets).
  • New tests in cmd/forge/view_json_test.go pin: the body round-trips through --json body --jq .body for a body ending in two newlines, one with CRLF line endings, and one equal to -n; exactly one request in JSON mode; comma-separated and repeated --json produce the same object; object-shaped author, labels, milestone; PR-only headRefName/baseRefName rejected on issues; every validation error (unknown field, empty value, first-line-empty value, --jq without --json, unsupported expression, field not requested) exits non-zero with zero requests.
  • Read-only smoke against the live forge: the worktree binary printed this issue's own body verbatim with --json body --jq .body.
  • Two reviewers from other model families read the diff cold. Confirmed and fixed in the second commit: a --json value whose first line was empty selected no fields and printed {}; two documentation overclaims (byte-for-byte via --jq, and preventing a concurrent writer's edit from being replaced). Discarded as design decisions: full jq expression support, and null body as null rather than the empty string.
`forge issue view` and `forge pr view` gain `--json <fields>` and `--jq <expression>`, copying `gh`. With `--json`, the command makes one request and prints exactly the requested fields as a JSON object, so an issue or PR body can be pulled down as it actually is on the forge and edited from there instead of retyped from the rendered view. Without the flags, output is byte-identical to today, and the existing tests pin that. `--jq` is deliberately a small subset: a dotted field path such as `.body`, printed raw the way `jq -r` does; anything else is refused before any request. Nothing changes for callers that never pass the flags. If this is wrong, revert the two commits; no other tool depends on the new flags yet. Closes allod/tools#190 ## Risk R1. Additive read-side flags on two commands; the existing rendering paths are untouched and their tests unchanged. Rollback is a revert. Known limits, stated in the docs: `--jq .body` prints the body plus one newline (jq's convention), so a `view --jq .body > f; edit --body-file f` cycle adds one trailing newline per round trip; the JSON object form is the exact one. A null body renders as the empty string. `--body-file` still replaces the whole body, so this does not merge concurrent edits. ## Validation - `nix build .#checks.x86_64-linux.go-checks` passes on the final commit (gofmt, vet, `go test` across all tag sets). - New tests in `cmd/forge/view_json_test.go` pin: the body round-trips through `--json body --jq .body` for a body ending in two newlines, one with CRLF line endings, and one equal to `-n`; exactly one request in JSON mode; comma-separated and repeated `--json` produce the same object; object-shaped `author`, `labels`, `milestone`; PR-only `headRefName`/`baseRefName` rejected on issues; every validation error (unknown field, empty value, first-line-empty value, `--jq` without `--json`, unsupported expression, field not requested) exits non-zero with zero requests. - Read-only smoke against the live forge: the worktree binary printed this issue's own body verbatim with `--json body --jq .body`. - Two reviewers from other model families read the diff cold. Confirmed and fixed in the second commit: a `--json` value whose first line was empty selected no fields and printed `{}`; two documentation overclaims (byte-for-byte via `--jq`, and preventing a concurrent writer's edit from being replaced). Discarded as design decisions: full jq expression support, and null body as `null` rather than the empty string.
vnprc force-pushed agent/forge-view-json from 63484394ee to 68ac34def3 2026-09-11 20:12:44 +01:00 Compare
vnprc approved these changes 2026-09-11 20:12:56 +01:00
vnprc merged commit 68ac34def3 into master 2026-09-11 20:13:11 +01:00
vnprc deleted branch agent/forge-view-json 2026-09-11 20:13:11 +01:00
Sign in to join this conversation.
No description provided.