fix(repos): gitea_repo_contents returns the path, not the file body #3
Labels
No labels
area/dsh
area/forgejo
experiment
priority/later
priority/next
priority/now
type/bug
type/task
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
dsh-plugins/dsh-gitea#3
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Symptom
gitea_repo_contentsreturns a filename, not the file:path: AGENTS.md→AGENTS.mdpath: README.md→README.mdSo the tool cannot be used to read a file at all — which is its entire purpose, and the only fallback for an agent that cannot clone.
path: ""additionally errors withinvalid owner, repo, or filePath, so directories cannot be listed either.Root cause
This branch fires before anything content-aware. The API payload is complete:
GET /repos/pvlb-infra/vps-setup/contents/AGENTS.mdreturnsencoding: "base64"pluscontent,size,html_url,download_url.Separately,
lib/gitea-client.js:494rejects an empty path, so the root directory (where the API returns an array) is unreachable.Fix
gitea_repo_contentsformatter: decode base64 for files; truncate large bodies (say 20 KB) with an explicit note and always includehtml_url/download_url.path: ""to list the root; the generic array formatter already handles{name, path}entries.pathin the output so the reader knows what was fetched.Acceptance
AGENTS.md→ its first ~20 KB of text plus a download link.Fixed in
077ffc6(PR #16).gitea_repo_contentsnow decodes the API's base64contentand rendersFile: <path> (<size>, encoding)withhtml_urlanddownload_url. Files larger than 20 000 chars are truncated with an explicit note and a download link. An emptypathnow requests/contentsand lists the repository root;../traversal is still rejected.Live through the running plugin:
AGENTS.md→File: AGENTS.md (38003 bytes, encoding: base64)+ body, truncated at 20 000 chars with the raw download URL.path: ""→ root listing (.forgejo,AGENTS.md,lib,test, …).Tests:
test/repo-contents.test.mjs(body/links, unicode, truncation bound, empty/missing content, root request, path encoding/traversal);npm test66/66.