Skip to content

feat(source): add the sourcewalk walker and sourcefs write boundary for proposal 274 - #385

Merged
runkids merged 15 commits into
mainfrom
runkids/274-rollout-steps-1-2
Oct 4, 2026
Merged

runkids merged 15 commits into
mainfrom
runkids/274-rollout-steps-1-2

Conversation

@runkids

@runkids runkids commented Oct 4, 2026 •

Copy link
Copy Markdown
Owner

Type

  • Bug fix
  • Small improvement (docs, typo, minor refactor)
  • Feature (rollout steps 1 and 2 of an approved proposal)

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. doctor prints an info line for each first-level symlink or Windows junction in the skills source, in global and project mode, and reports them as undeclared_source_links in doctor --json. Links are detected with utils.IsLinkMode, never followed, and never read. With no links the output is unchanged.

Step 2a: one source walker. New internal/sourcewalk package (Walk, WalkDir, ReadDir, plus an empty Options reserved for the follow set) with the same SkipDir, 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 plus SkillKind.Discover in internal/resource/skill.go, which the table missed. migrateSkillSidecars, walkSkillDir, and NestedRepos stay raw on purpose, as the proposal says. A go/parser ratchet (internal/sourcewalk/guard_test.go) fails make test on any new unclassified filepath.Walk/WalkDir/fs.WalkDir/os.ReadDir call under cmd/ and internal/; the 122 remaining calls carry a reason in internal/sourcewalk/allowlist.json. The reason vocabulary is wider than the proposal's list (adds config, assets, plugin, hooks, memory, project, test-fixture) so that every entry is truthful.

Step 2b: the write boundary. New internal/sourcefs package wrapping an *os.Root opened at the skills source. Before Remove, RemoveAll, an overwriting write, or a Rename onto an existing path it runs Lstat through the root on every path component and refuses when any component is a link. WriteFileAtomic creates 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 --force onto an existing linked _repo is refused; the link and the external repo stay byte-identical.
  • Dashboard skill edits go through WriteFileAtomic; editing a SKILL.md that is a link returns 409.
  • --into, dashboard into, and config-install group creation go through the handle.
  • The init built-in skill fallback goes through the handle.
  • CLI and server uninstall, and the update prune check, verify the in-source side before MoveToTrash (the test showed an external child being moved to trash before the fix).
  • Staged install and update swap in through the handle, including --force removal.

A second ratchet (internal/sourcefs/ratchet_test.go) covers raw os write calls. Its 511-entry allowlist in internal/sourcefs/testdata/raw_writes.tsv tags 69 remaining skills-source writes as source-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 swapStagedIntoSource used the raw copyDir, which is not constrained by the handle. Fixed in 9a3685d: the fallback runs only for a cross-device rename error (sourcefs.IsCrossDevice, EXDEV on Unix and ERROR_NOT_SAME_DEVICE on Windows) and copies through the new sourcefs.CopyIn, which creates every directory and file through the root. Every other MoveIn failure is returned. A Linux test stages on /dev/shm so 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.md gains the rule that skills-source writes go through internal/sourcefs.

  • The proposal should be updated in a follow-up: add SkillKind.Discover to the §2 table, record the extended ratchet vocabulary, and list the 69 source-unmigrated writes as remaining step 2 work.

  • Pre-existing, not fixed here: single-target non-JSON uninstall output 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

  • I've read CONTRIBUTING.md
  • Tests included and passing (make check in a container from the devcontainer image)
  • No unrelated changes in the diff
  • Scope is focused — one concern per PR

runkids added 13 commits October 4, 2026 14:46
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.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 4, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-04T06:54:15.294768Z a0964e5 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread internal/install/source_write.go Outdated
return err
}
// Rename failed (possibly cross-device), try copy instead
if err := copyDir(staged, destPath); err != nil {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
@runkids
runkids merged commit 8c60f51 into main Oct 4, 2026
8 checks passed
runkids added a commit that referenced this pull request Oct 4, 2026
#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.
@runkids
runkids deleted the runkids/274-rollout-steps-1-2 branch October 4, 2026 20:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant