Repository navigation
fix(repos): allow explicitly empty file content - #3884
Elon-Jiang wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues block the change enabling intentionally empty file writes.
No open issues 🎉
What changed in this PR
Fixes #3883 by allowing create_or_update_file to create empty files or intentionally clear existing files without changing its public input type or schema.
Changes:
- Accepts explicit
content: ""while continuing to reject missing or null content. - Adds regression cases for empty creation, clearing existing files, and missing/null content.
- Documents empty writes and the current-SHA requirement for clearing existing files.
| File | Description |
|---|---|
pkg/skills/catalog/skills/repository-content-changes/SKILL.md |
Documents intentionally empty writes. |
pkg/github/repositories.go |
Distinguishes explicit empty content from missing or null values. |
pkg/github/repositories_test.go |
Adds empty-write and missing/null regression cases. |
Review effort: Balanced (adaptive)
SoulmatelynchVFX
left a comment
There was a problem hiding this comment.
这个分支把「content 是空串」和「content 缺失」分开的判据放在 handler 里,二次反序列化 req.Params.Arguments(repositories.go:521-532)。同一文件里 push_files 用的是类型层方案:PushFileInput.Content 声明为 *string(repository_tool_types.go:68-71),取值处 if file.Content == nil 报缺参、否则 content := *file.Content(repositories.go:1730-1733),所以 content: "" 在那里本来就是合法输入。把 CreateOrUpdateFileInput.Content 同样声明为 *string,这个二次解包就不需要,也不必依赖调用方把参数留在 Arguments 里。
二次解包没有像包内其它解包点那样加前置守卫:issues.go:2859 是 if req != nil && req.Params != nil && len(req.Params.Arguments) > 0 才 json.Unmarshal。这里直接解包的后果是:Arguments 为空时返回 unexpected end of JSON input(nil result + error),而不是其它缺参分支统一的 missing required parameter: content 工具级错误;req 为 nil 时会在 req.Params 上 panic。按代码顺序,经 MCP 传输进来的调用走不到这两条——owner/repo/path 三个检查在 content 之前,能过它们就说明 Arguments 非空。所以这是稳健性问题,不是当前可复现的缺陷。
只做了静态阅读:本机没有 Go 工具链,没有跑 go test ./pkg/github/;也没有验证 schema 层(Required 只判存在、不判空)在客户端 strict 校验下的表现。
以上由 AI 辅助审阅,结论基于 refs/pull/3884/head 的代码阅读。
Summary
Allow
create_or_update_fileto create empty files and intentionally clear existing files whencontent: ""is explicitly supplied.Why
Fixes #3883. Agents cannot currently create empty package markers (
__init__.py,.gitkeep) or clear a file: an empty string is treated as a missing parameter before any request reaches GitHub. The Contents API accepts base64 file content, and the tool schema does not impose a minimum length.What changed
MCP impact
Prompts tested (tool changes only)
The tests invoke tool arguments directly; no LLM prompt execution is claimed. The corresponding use cases are “create an empty package marker on this branch” and “clear this ordinary file using its current blob SHA.” The HTTP transport substitutes GitHub's service; the public tool handler, validation and REST serialization run normally. No live account file write was used in testing.
Security / limits
Tool renaming
Lint & tests
./script/lint(Go 1.27.4, pinned golangci-lint 2.14.0): passed../script/test(go test -race ./...): passed.UPDATE_TOOLSNAPS=true go test ./...: passed; no snapshot changes.Baseline: the two empty-write cases fail; 15 existing controls pass. After the fix, all 19 cases pass, including the two new absent/null controls.
After the maintainer merged main into this branch (
f650c53), I reviewed the update and reran all 19 handler cases, lint, the full race-enabled suite, and documentation generation on Go 1.27.4. The three fix files are unchanged by that main merge; the generated documentation leaves the checkout clean.Docs
./script/generate-docspassed without README changes.Skills
Prepared with AI assistance. No claim of independent human review is made.