ac4af582301a4e8a29245dbba767eba31334ddf9
3
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
497100488a |
provider, library: a .git is a repository only when git takes it for one (#3675)
TestPluginToldWhereTheAgentWorks was red on any machine with an empty .git above its temp folder. GitOnDisk took the first .git it met going up as a repository, and on this box /tmp/.git is an empty folder (owned by nobody), so every folder under /tmp read "yes". git passes such a folder over and goes on up: git rev-parse under it says "not a git repository". GitOnDisk now reads each .git on the way as git's own search does (repo_discovery_find_dir in git 2.56's setup.c), through GitAt: - A folder counts when git takes it for a repository (is_git_directory): a HEAD git takes (a link into refs/, "ref: refs/...", or a commit's id), and objects and refs folders, in the folder its commondir names for a linked worktree. Any other folder, an empty one say, is passed over and the walk goes on up. - A file counts when it is "gitdir: <folder>" naming such a folder, relative to the .git's own folder (a linked worktree's, a submodule's). Any other file, one over git's 1 MB, or one that is neither file nor folder is "no": git stops there with "not a git repository" (a worktree whose repository has gone) or "invalid gitfile format". (git 2.34 passed a .git that is neither file nor folder over; 2.55 and 2.56, CI's, stop at it.) - A .git it can't read is unknown, and the header is left off. git passes such a folder over and stops at such a file, but either way it can't tell an empty .git from a repository it isn't let into (another user's, through a shared magpie), and a failed read is unknown here. A bare repository kept as a folder's .git (git init --bare .git) is still "yes": git finds one there, though no work tree. Not mirrored: the filesystem boundary, GIT_CEILING_DIRECTORIES and safe.directory's ownership check. Cost: the same one stat per folder on the way up; at a .git, a read of HEAD (255 bytes at most) and stats of commondir, objects and refs. What a user sees: a request to a plugin provider from an agent that doesn't say whether its folder is a repository (Codex, Pi) was told "yes" for a project under a stray empty .git, under a worktree whose repository was deleted, or under a .git file that names nothing. The community ZCode plugin then tells the model "- <git label>: yes" and Command Code's sends isGitRepo: true, so the model may run git commands that fail with "not a git repository". They are now told "no", and with a .git on the way magpie can't read, nothing (ZCode's plugin leaves the line out, Command Code's sends false). Claude Code's and OpenCode's requests say it themselves and are passed on as they say it, so nothing changes for them; Claude Code 2.1.310's own check takes any .git, an empty one too. The only caller of GitOnDisk is tellWorkPlace (workdir.go), which needs no change. The library's skill groups had the same first-.git walk: gitRepoOf took the first .git within four folders of a linked skill for its checkout, so an empty one between a skill and its clone left the skill in no group, and gave one imported from there no From. gitRepoOf now asks provider.GitAt, passes such a .git over to the clone's, and reads the origin from the folder GitAt names (a linked worktree's common one), which replaces gitdirConfig. gitdirConfig also took "gitdir:" with no space after it, or with spaces around the line, which git doesn't take; such a .git now traces to nothing, as git finds nothing there. Checkouts git made are traced as before; the test's fake ones had only a config and now have a HEAD, objects and refs. Every other .git folder in the Go code is one a walk skips when it copies, hashes or checks a skill (carry.go, skillcheck.go, skills.go, skill_edits.go), or the one magpie removes from its own fetch of a skill (skillgit.go), not a decision about a repository. The Claude bridge's claudeWorkDir takes the temp folder for one in no repository; Claude Code decides that for itself, and its git status is off for every run (CLAUDE_CODE_DISABLE_GIT_INSTRUCTIONS), so it stays. TestPluginToldWhereTheAgentWorks gets a real repository for "in a repository" (HEAD, objects, refs; an empty .git was all it had) and a case under an empty .git in its own temp folder, so it fails without this on any machine. Its "not in one" cases, and the new provider tests' "no" ones, still need no repository above the temp folder, as the test did before. TestGitOnDiskIsWhatGitFinds lays out each kind of .git by hand; TestGitOnDiskAgreesWithGit asks git rev-parse --git-common-dir in each of those folders and in ones git made (init, worktree add, a worktree whose record was removed, --separate-git-dir, init --bare .git), for yes or no and where; TestGitOnDiskUnreadIsUnknown locks a .git folder and a worktree's .git file. provider-plugins.md and library.md say the same. What was run (tree 9a4504d9, on origin/main |
||
|
|
65e80405b8 |
gateway: TestPluginToldWhereTheAgentWorks counts a case's tries, not one request (#3347)
Cause: the test said a case's request reached the vendor exactly once. A lone account whose try fails with a 5xx is asked again after a moment by design (TestLastOneLeftIsTriedAgain), so one failed first try gives the vendor two requests and the client a 200. That is what CI hit at |
||
|
|
1075991f90 |
gateway: a plugin's fetch is told the folder the agent works in and whether it is a git repository, never seeing magpie's own (plugins #86, Hipple)
A plugin runs in magpie's plugin host, so its process.cwd() is magpie's folder. The ZCode plugin's Start Plan request said that folder (C:\Users\<user>\.config\magpie) as the agent's "Primary working directory", with "Is a git repository: no", and the model looked there. forwardOnce now calls tellWorkPlace on every request to a plugin's provider. It reads the request as sent to the plugin with workPlace (the same reading rules by folder use) and sets two headers on the plugin's fetch: - x-magpie-work-dir (provider.WorkDirHeader): the folder, percent-encoded (url.PathEscape; decodeURIComponent reads it); - x-magpie-work-git (provider.WorkGitHeader): yes/no. The agent's own word beside the folder (Claude Code's "Is a git repository: true/false", OpenCode's "Is directory a git repo: yes/no") wins. Otherwise it is a .git in the folder or above it, when the folder is on this computer (provider.GitSaid, provider.GitOnDisk in the new workplace.go). Each is left off when unknown; a folder that isn't on this computer and that the agent didn't call a repository has no git value, never "no". host.js's fetch (unsaid) takes both headers off every request a plugin sends, so a plugin that forwards the headers it was given sends them to no vendor. Documented in docs/subsystems/provider-plugins.md. Run: TestPluginToldWhereTheAgentWorks (new) sends the captured Claude Code and Codex requests, and Pi-style ones from a temp repo subfolder and a plain folder, through the fake plugin to fake-claude and fake-1. It checks what the plugin read and that the vendor got neither header. Broken by hand: without the tellWorkPlace call every case fails; without unsaid in host.js it fails with "the vendor got X-Magpie-Work-Dir". go test internal/gateway (-timeout 40m), internal/provider, internal/plugin; gofmt -l; go vet on darwin, GOOS=linux and GOOS=windows for the three packages. |