Repository navigation
feat(source): add the sourcewalk walker and sourcefs write boundary for proposal 274 - #385
Conversation
Route skills source discovery through a dependency-light traversal package while preserving root resolution, callback semantics, and child-link behavior. Reserve traversal options for the later opt-in following rollout. Classify remaining raw directory scans with an import-aware parser ratchet that rejects new calls and stale allowances. Cover wrapper parity, symlink roots, errors, and guard failure cases without changing existing tests.
Review of the .skillfollow proposal (#274) kept finding writes that reached outside the skills source through a link before any check ran. A list of guarded call sites does not hold, so writes get a filesystem handle instead: sourcefs wraps an *os.Root opened at the source root, which refuses any path that resolves outside the root through a link. os.Root alone still acts on a link that is the last component (Remove deletes it, Rename replaces it) and allows a relative link that stays inside the root. Every write therefore runs Lstat on each component first and refuses with "<path> is a link; edit its target directly". Unlink is the only way to remove a first-level link, and MoveIn checks the in-source side of a move that crosses the root's edge. The tests reproduce the proposal's os.Root evidence table on Linux.
With --force, install --track removed the existing repo path with os.RemoveAll and cloned a real directory in its place. When that path was a link, the link was replaced and the repo it pointed to was silently disconnected from the source. The tracked install now writes through the sourcefs handle: the existing path, the --into directory, and the cleanup after a failed clone are all checked for links, and a link is refused even in a dry run. Agents tracked repos share this function, so the same refusal applies to the agents source.
writeFileAtomic started with os.CreateTemp in the skill's directory, so an edit of a skill reached through a link created a temp file in the external tree before anything could refuse it, and the rename replaced a SKILL.md that is a link with a plain file. Skill edits now go through sourcefs: the temp file and the rename stay inside the source root, and a linked SKILL.md is refused with 409 and a message to edit its target. Agent edits are outside the skills source and keep the existing helper.
…handle install --into, the dashboard's into field, and config install's group directories all ran os.MkdirAll on a path joined from the source string. When a component of that path was a link, the directories were created in the link's target before anything else ran. They now go through sourcefs.MkdirAllIn, which refuses a path with a link component, so an explicit path through an undeclared link is refused instead of written through. This is the behavior change named in the #274 proposal.
When the skillshare skill could not be downloaded, init fell back to os.MkdirAll and os.WriteFile on a path joined from the source string, so a refused or failed install could still write through a skillshare folder that is a link. Both the install and the fallback now go through the sourcefs handle, and a linked folder is refused before either runs.
A move to the trash crosses the source root's edge, so it cannot go through Root.Rename. An explicit name such as `uninstall alias/child`, where alias is a link in the source, moved the link target's content into the trash. sourcefs.CheckMoveOut now checks the path through the root first and refuses a link above the entry; the entry itself may still be a link, because a rename moves the link and never its target. CLI and dashboard uninstall and update's prune of stale skills use it. The plain single-target uninstall output does not print the trash error, so the integration test reads it from --json.
…handle Staged installs and updates removed the existing skill with os.RemoveAll and renamed the temp directory in with os.Rename, and --force removed an existing skill the same way. A skill that is a link, or a path below one, had its link replaced or its target's content removed. The removal now goes through the sourcefs handle, and the rename-in, which crosses the root's edge, checks the in-source side first. A link refusal never falls back to the cross-device copy.
The write boundary only holds if new writes to the skills source go through it. The ratchet parses every non-test .go file under cmd/ and internal/ with go/parser, follows the file's import of "os" so aliases count, and records each call to or reference of a raw write function with its file, enclosing function, callee, and path-argument expression. testdata/raw_writes.tsv holds one allowance per call with a reason that says what the call writes. A new call fails, including a second identical call in a function already listed, and so does an allowance whose call no longer exists. Writes that still reach the skills source are tagged source-unmigrated, which makes the follow-up list explicit instead of hiding it under another tag. SOURCEFS_RATCHET_UPDATE=1 regenerates the list and keeps existing reasons.
New code that writes the skills source should use the sourcefs handle, and the ratchet test fails on a new raw os write call without telling the author where the rule is written down. The CLI development topic now names the package, the ratchet, and its allowlist.
Expose skipped source symlinks and Windows junctions as informational checks in global and project mode without following them or changing discovery. Preserve output when no source links exist and document the text and JSON diagnostics.
The undeclared-link check was written against main before the sourcewalk package existed. Routing it through sourcewalk.ReadDir keeps the raw-walk ratchet green and makes the check follow the same source root resolution as every other source scan.
The parallel-range download change on main (#381) removed one of the two os.Remove(tmp.Name()) calls in both downloadArchive and downloadToTemp. The ratchet reports an allowance whose call no longer exists, so the duplicate rows go away.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a0964e5b77
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| return err | ||
| } | ||
| // Rename failed (possibly cross-device), try copy instead | ||
| if err := copyDir(staged, destPath); err != nil { |
There was a problem hiding this comment.
Keep fallback copies inside the source boundary
When a staged install or update cannot be renamed—commonly because the staging directory and skills source are on different filesystems—this falls back to the raw copyDir. If the destination or one of its parents is replaced by a link after MoveIn checks it, or MoveIn reports that a concurrently created destination already exists, copyDir uses unrestricted MkdirAll/OpenFile calls and follows that link, allowing writes outside the skills source. Restrict the fallback to the actual cross-device error and perform the copy through sourcefs (or stage on the destination filesystem) so the new write boundary remains effective.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 9a3685d. The fallback now runs only when sourcefs.IsCrossDevice(err) reports a cross-device rename (EXDEV on Unix, ERROR_NOT_SAME_DEVICE on Windows) and copies through the new sourcefs.CopyIn, which checks the destination like MoveIn and then creates every directory and file through the root, so a link that appears at or above the destination is still refused by the handle. Every other MoveIn failure, including "already exists", is returned. A Linux test stages on /dev/shm so the fallback path really runs; the external tree is asserted unchanged.
…oundary When a staged install or update cannot be renamed into the skills source, the fallback copied with the raw copyDir, whose MkdirAll and OpenFile calls are not constrained by the source handle. A link that appeared at or above the destination after MoveIn's check, or a destination that already existed, would have been written through. The fallback now runs only for a cross-device rename error and copies through sourcefs.CopyIn, which creates every directory and file through the root; every other MoveIn failure is returned. Release-As: 0.24.3
#385 documented the new Source link info row and its --json check in the English doctor page only; the ja, ko, zh-Hans and zh-Hant pages now carry the same row and paragraph.
Type
Summary
Implements rollout steps 1 and 2 of
proposals/274-skillfollow.md. Nothing in this PR follows a link, parses.skillfollow, or changes discovery results. It puts the infrastructure in place that step 3 needs, and it fixes the write-boundary gaps the proposal found in review.Step 1: visibility.
doctorprints an info line for each first-level symlink or Windows junction in the skills source, in global and project mode, and reports them asundeclared_source_linksindoctor --json. Links are detected withutils.IsLinkMode, never followed, and never read. With no links the output is unchanged.Step 2a: one source walker. New
internal/sourcewalkpackage (Walk,WalkDir,ReadDir, plus an emptyOptionsreserved for the follow set) with the sameSkipDir, callback, error, and symlinked-root semantics as the raw calls it replaces. Thirteen raw walks of the skills source move onto it: the twelve from the proposal's §2 table plusSkillKind.Discoverininternal/resource/skill.go, which the table missed.migrateSkillSidecars,walkSkillDir, andNestedReposstay raw on purpose, as the proposal says. Ago/parserratchet (internal/sourcewalk/guard_test.go) failsmake teston any new unclassifiedfilepath.Walk/WalkDir/fs.WalkDir/os.ReadDircall undercmd/andinternal/; the 122 remaining calls carry a reason ininternal/sourcewalk/allowlist.json. The reason vocabulary is wider than the proposal's list (addsconfig,assets,plugin,hooks,memory,project,test-fixture) so that every entry is truthful.Step 2b: the write boundary. New
internal/sourcefspackage wrapping an*os.Rootopened at the skills source. BeforeRemove,RemoveAll, an overwriting write, or aRenameonto an existing path it runsLstatthrough the root on every path component and refuses when any component is a link.WriteFileAtomiccreates the temp file inside the root.Unlink(entry)is the only way to remove a first-level link. The six write sites the proposal named as review regressions move onto it, each with an integration test that was red before the fix:install --track --forceonto an existing linked_repois refused; the link and the external repo stay byte-identical.WriteFileAtomic; editing aSKILL.mdthat is a link returns 409.--into, dashboardinto, and config-install group creation go through the handle.initbuilt-in skill fallback goes through the handle.MoveToTrash(the test showed an external child being moved to trash before the fix).--forceremoval.A second ratchet (
internal/sourcefs/ratchet_test.go) covers rawoswrite calls. Its 511-entry allowlist ininternal/sourcefs/testdata/raw_writes.tsvtags 69 remaining skills-source writes assource-unmigrated; that list is the explicit follow-up for the rest of step 2.Behavior change. The only intended one is the one the proposal names: an explicit path that crosses a link inside the skills source is now refused instead of written through. No existing test was changed.
Review notes
Codex review: the cross-device fallback in
swapStagedIntoSourceused the rawcopyDir, which is not constrained by the handle. Fixed in 9a3685d: the fallback runs only for a cross-device rename error (sourcefs.IsCrossDevice,EXDEVon Unix andERROR_NOT_SAME_DEVICEon Windows) and copies through the newsourcefs.CopyIn, which creates every directory and file through the root. Every otherMoveInfailure is returned. A Linux test stages on/dev/shmso the fallback really runs.Versioning: this is a feature, but the maintainer wants it in a patch release. The final commit carries
Release-As: 0.24.3; the squash commit message must keep that footer.wiki/cli-development.mdgains the rule that skills-source writes go throughinternal/sourcefs.The proposal should be updated in a follow-up: add
SkillKind.Discoverto the §2 table, record the extended ratchet vocabulary, and list the 69source-unmigratedwrites as remaining step 2 work.Pre-existing, not fixed here: single-target non-JSON
uninstalloutput drops the trash error. The new uninstall test uses--json.Linked Issue
Refs #274. Implements steps 1 and 2 of the proposal merged in #369.
Checklist
make checkin a container from the devcontainer image)