Skip to content

Commit 1ccbcfa

Browse files
authored
fix(v0.6.2): repo view takes positional OWNER/NAME, repo file handles dirs (#8)
Two real failures we just saw the corvidagent hit on a corvid-verify PR #5 lookup: 1. `github repo view CorvidLabs/corvid-verify` failed with `unknown argument 'CorvidLabs/corvid-verify'`. `gh repo view` takes the repo as a positional natively, and the agent reasonably tried the same shape. Accept it when the token looks like `owner/name` (contains a `/`); -R still works for explicit form. 2. `github repo file Sources -R CorvidLabs/corvid-verify` died with `jq: expected an object but got: array`. The contents API returns an array for directories; we were piping that into a jq filter that assumed an object with a .content field. Probe the response type once, then render: file -> decoded contents (unchanged), directory -> name<TAB>type<TAB>size listing. Same command for both, agent can now browse a remote repo with one tool instead of getting stuck.
1 parent 7c22867 commit 1ccbcfa

3 files changed

Lines changed: 55 additions & 10 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## [v0.6.2] - 2026-05-21
4+
5+
### Fixes
6+
7+
- `repo view` now also accepts `OWNER/NAME` as a positional argument, matching `gh repo view`'s native syntax. Previously the agent's natural-looking `repo view CorvidLabs/corvid-verify` failed with `unknown argument` and forced an awkward retry with `-R`.
8+
- `repo file` now detects whether the path resolves to a file or a directory and renders accordingly: file → decoded contents (as before), directory → `name<TAB>type<TAB>size` listing. Previously a directory path hit `jq: expected an object but got: array` and the agent had no way to browse remote repos.
9+
310
## [v0.6.1] - 2026-05-21
411

512
### Fixes

bin/fledge-github-repo

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@ if [ $# -gt 0 ] && [ "${1:0:1}" != "-" ]; then
2020
view)
2121
ACTION="view"
2222
shift
23+
# gh's native `gh repo view <OWNER/NAME>` takes the repo as a
24+
# positional. Mirror that so the agent can call either
25+
# `repo view CorvidLabs/x` or `repo view -R CorvidLabs/x` and
26+
# land in the same place. Only accept it when it looks like
27+
# owner/name (i.e. contains a /) — bare words are typos.
28+
if [ $# -gt 0 ] && [ "${1:0:1}" != "-" ] && [[ "$1" == */* ]]; then
29+
REPO="$1"
30+
shift
31+
fi
2332
;;
2433
file)
2534
ACTION="file"
@@ -42,18 +51,25 @@ while [ $# -gt 0 ]; do
4251
fledge github repo — read repo metadata and file contents via the gh CLI
4352
4453
USAGE:
45-
fledge github repo [view] View repo metadata (default)
46-
fledge github repo file <PATH> Read a file from the repo
54+
fledge github repo [view] [OWNER/NAME] View repo metadata (default)
55+
fledge github repo file <PATH> Read a file OR list a directory
4756
4857
OPTIONS:
49-
-R, --repo <OWNER/NAME> Target repo (default: current working repo)
58+
-R, --repo <OWNER/NAME> Target repo (default: current working repo).
59+
view also accepts OWNER/NAME as a positional.
5060
-r, --ref <REF> Branch / tag / SHA (file only; default: repo default)
5161
--json Output JSON
5262
63+
The `file` action returns the file's decoded contents when PATH is a
64+
file, or a tab-separated listing (name<TAB>type<TAB>size) when PATH
65+
is a directory — same command, agent can browse and read with one tool.
66+
5367
EXAMPLES:
5468
fledge github repo
55-
fledge github repo view -R CorvidLabs/merlin
69+
fledge github repo view CorvidLabs/merlin
70+
fledge github repo view -R CorvidLabs/merlin --json
5671
fledge github repo file CHANGELOG.md
72+
fledge github repo file Sources -R CorvidLabs/corvid-verify
5773
fledge github repo file README.md -R CorvidLabs/fledge-plugin-github
5874
fledge github repo file Cargo.toml -r v0.3.0
5975
EOF
@@ -114,15 +130,37 @@ if [ "$ACTION" = "file" ]; then
114130
ENDPOINT="${ENDPOINT}?ref=${REF}"
115131
fi
116132

133+
# The contents API returns:
134+
# - an object with .content (base64-encoded) when PATH is a file,
135+
# - an array of entries when PATH is a directory.
136+
# Previously we blindly piped .content into base64(1), which croaked
137+
# on dirs with `expected an object but got: array`. Probe the type
138+
# once, then render appropriately so the agent can use the SAME
139+
# command for both file and dir lookups.
117140
if [ "$JSON" = "true" ]; then
118141
# Pass through the raw API response — caller decodes content
119142
# themselves if they want the base64.
120143
gh api "$ENDPOINT"
121-
else
122-
# Default: emit just the decoded file contents. The contents API
123-
# returns base64-encoded content for files; the .content field
124-
# holds it with embedded newlines that base64(1) tolerates.
125-
gh api "$ENDPOINT" --jq '.content' | base64 -d
144+
exit 0
126145
fi
146+
147+
RAW="$(gh api "$ENDPOINT")"
148+
KIND="$(printf '%s' "$RAW" | jq -r 'if type == "array" then "dir" elif type == "object" and .type == "file" then "file" else "other" end')"
149+
case "$KIND" in
150+
file)
151+
printf '%s' "$RAW" | jq -r '.content' | base64 -d
152+
;;
153+
dir)
154+
# Directory: print a brief listing. One line per entry, sorted
155+
# like `ls -F` (trailing / for dirs). The agent can then call
156+
# `repo file <subpath>` on whichever entry it wants.
157+
printf '%s' "$RAW" | jq -r 'sort_by(.type, .name) | .[] | "\(if .type == "dir" then .name + "/" else .name end)\t\(.type)\t\(.size // "")"'
158+
;;
159+
*)
160+
# Symlink, submodule, or something else we don't render. Dump the
161+
# JSON so the caller can see what it is.
162+
printf '%s\n' "$RAW"
163+
;;
164+
esac
127165
exit 0
128166
fi

plugin.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[plugin]
22
name = "fledge-plugin-github"
3-
version = "0.6.1"
3+
version = "0.6.2"
44
description = "GitHub commands for fledge — list/view/create/comment/review/merge PRs, list/view/create/comment/close issues, read repo files, view CI checks, and poll for daemon events via the gh CLI"
55
author = "0xLeif"
66
license = "MIT"

0 commit comments

Comments
 (0)