Skip to content

feat(skillfollow): opt-in discovery of linked skill groups and tracked repos - #390

Closed
runkids wants to merge 174 commits into
mainfrom
runkids/274-step3
Closed

runkids wants to merge 174 commits into
mainfrom
runkids/274-step3

Conversation

@runkids

@runkids runkids commented Oct 4, 2026 •

Copy link
Copy Markdown
Owner

Type

  • Bug fix
  • Small improvement (docs, typo, minor refactor)
  • Feature (rollout step 3 of an approved proposal, plus the rest of step 2)

Summary

Implements rollout step 3 of proposals/274-skillfollow.md on top of the step 1 and 2 work merged in #385, and finishes the step 2 write migration that #385 left open. The feature is opt-in and experimental: with no .skillfollow file every command's output is unchanged, and the behavior matrix tests pin that.

Step 2, finished. The 69 skills-source writes that #385 tagged source-unmigrated are migrated onto internal/sourcefs (64 rows), with a sourcefs.Writer interface so helpers that also serve non-source folders take either the handle or the plain os adapter. Five rows stay raw with a documented reason: the .gitignore writers in internal/git/scope.go and internal/install/gitignore.go serve the source, the config folder, and project folders through callers that do not name the scope.

Step 3: .skillfollow. A .skillfollow (plus .skillfollow.local) at the skills source root lists first-level link names that discovery may follow, one hop, for groups and tracked repositories.

  • Parsing and classification (internal/sourcewalk): strict names, the proposal's state order (missing, not-link, invalid-target, cycle, target-overlap, inside-git-root, entry-overlap, single-skill, followed, undeclared-link), a junction-aware canonicalizer, and a FollowSet built once per operation. Followed skills get logical paths everywhere (_repo/a, group/c); undeclared links stay invisible as before. Single-skill entries are rejected until step 4.
  • Identity, ownership, status (internal/sync): skill links keep the followed entry in their text and sync converges; prune owns a managed link only when it resolves inside the source or a currently followed target; status counts a followed link as linked only when it is in the manifest.
  • Unavailable entries pause prune: while any declared entry is not followed or not-link, prune is paused on every skills target including --force, unprovable standard-naming copies are kept, new links are still created, and reconcile keeps metadata only under the unavailable prefix. sync, status, and doctor name the blocking entry and the recovery step. CLI and dashboard behave the same.
  • Git safety (internal/git, internal/install): followed tracked repos update fast-forward only through one shared policy (CLI single/quick/batch/project, dashboard single/all/SSE, install --update); --force, dirty, and diverged repos are refused per item and the other repos continue. The post-update audit scans through the resolved root, treats a zero-eligible-file scan of a non-empty root as a scan error, and still rolls back by hard reset. Commit, push, and init refuse to stage an indexed or unignored declared link and print the exact /_name ignore line; source pull, reset, and dashboard checkout refuse an incoming revision that passes through a link.
  • Consumers: every CLI, hub, and dashboard reader of the source discovers followed skills; dashboard writes, toggles, uninstalls, and source changes on a followed tree are refused with the existing sourcefs link error. list --no-tui shows → <resolved> for followed repos.
  • Docs: README (five locales), a new reference/skillfollow website page plus notes on twelve command pages (four locales), the built-in skill, the proposal reconciled with what shipped, and wiki/history/proposal-274-step-3.md.

The work was done as six slices on separate branches and merged here; each slice has a handoff report under ai_docs/reports/ (3a to 3e). The behavior matrix lives in tests/integration/skillfollow_matrix_test.go and internal/server/handler_skillfollow_test.go.

Deviations from the proposal text, recorded in the proposal: write refusals use the generic sourcefs link message rather than followed-specific wording; the proposed doctor sidecar check did not ship; FollowSet.SourceRoot() was added for the staging guard; the dashboard source-change refusal stands on its own because metadata lookup still refuses linked entries.

Step 4 (added after the Codex rounds). The follow-up slices that the proposal lists as step 4 are integrated here as well, so the feature ships whole; each slice keeps its own commits and report (ai_docs/reports/274-discovery-entry.md, 274-follow-cmd.md, 274-skillfollow-ui.md, 274-step4-integration.md).

  • Commands skillshare follow <name> [--to <dir>] [--local] and skillshare unfollow <name> [--local] [--keep-link]: edit .skillfollow/.skillfollow.local through sourcefs, create the link (symlink, or junction on Windows) with --to, write the managed .gitignore line, and print the entry's state. Docs: reference/commands/follow.md, unfollow.md (four locales), completions for five shells, runbook ai_docs/tests/skillfollow_follow_cmd_runbook.md.
  • Dashboard Settings → Files → .skillfollow tab backed by GET/PUT /api/skillfollow: shows both files, entry states, warnings and prune pauses; validates names before writing; never links, edits .gitignore, or syncs. Strings in all 11 dashboard locales.
  • Discovery entry hardening: the follow snapshot is a plain *sourcewalk.FollowSet parameter everywhere in cmd/skillshare and internal/server, follow-less discovery entry points are test-only or deleted, and TestFollowSnapshotGuard (with follow_allowlist.json) fails any new call that drops the snapshot. doctor now validates followed entries under skills_validity; the audit TUI skills tab includes followed skills.
  • Codex review rounds 13 to 21 are folded in (ai_docs/reports/274-codex-round13.md … round21.md): fail-closed write guards through FollowSet.WriteBoundary with the TestFollowWriteGuard ratchet, the Git source-mutation guard for declared prefixes, project-mode snapshot pairing, doctor skipped-check reporting, the single-skill dashboard audit through the resolved root, and Windows case-insensitive declared-name matching.
  • Windows: scripts/windows/e2e-skillfollow.ps1 ran on a Windows 11 ARM64 guest for the step-3 junction cases (ai_docs/reports/274-windows-skillfollow.md); follow --to's junction path and case-insensitive matching are cross-compiled and unit-tested only, as the reference page's Limits section states.

Checks run

  • make check (docs-check, fmt, lint, all four ratchets, unit and integration tests) in the devcontainer on the final commit: all green. Dashboard vitest (99 files, 891 tests) and the follow-cmd runbook (7/7) in a throwaway container.
  • Website typecheck and production build for all five locales in the devcontainer.
  • python3 scripts/ai-context.py check.
  • Windows: GOOS=windows go vet ./..., plus scripts/windows/e2e-skillfollow.ps1 on a Windows 11 ARM64 guest for the step-3 junction cases. Step-4 Windows paths (follow --to junction, case-insensitive names) are not run on a real guest.

Follow-ups

Tracked as issues so this PR can merge without them: #402 (audit route path escape, pre-existing), #403 (follow/unfollow command follow-ups), #404 (Windows verification of step 4), #405 (structural consolidation), #406 (efficiency), #407 (small cleanups).

Versioning

This is a feature and should go out as a minor release; no Release-As footer is set.

Linked Issue

Refs #274. Follows #369 (proposal) and #385 (steps 1 and 2).

Checklist

  • I've read CONTRIBUTING.md
  • Tests included and passing (make check) — for code changes
  • No unrelated changes in the diff
  • Scope is focused — one concern per PR: this PR carries the step 2 migration residual and all of step 3 because the proposal requires the migration to be complete before step 3 ships, and the slices share the same walker and write-handle APIs.

runkids added 30 commits October 4, 2026 15:24
Merge root and local declarations as a stable union and report invalid names with file and line context before discovery can follow them.
Provide an operation-scoped FollowSet with ordered safety states and portable junction-aware canonicalization, retaining unavailable declarations for subsequent discovery and ownership consumers.
Keep nil-follow traversal unchanged, descend only through declared first-level entries, and retain read failures on the operation FollowSet so incomplete discovery cannot be mistaken for success.
Add compatible options-bearing discovery and tracked-repo entry points, and share one FollowSet in global/project list, status, doctor, and sync. Existing callers retain nil-follow behavior without ambient config or an install/config import cycle.
Prevent nested consumers that reuse an operation FollowSet from applying first-level declarations again inside a followed tree.
Expose declaration counts and states without changing output when declarations are absent. Cover global and project discovery fixtures, undeclared invisibility, tracked repository counts, and read-only source behavior.
Document the exact FollowSet API, CLI-first scope approved by the coordinator, validation evidence, and remaining nil-follow callers for the next rollout slices.
Relative skill links were computed from the fully resolved source path, so
a link to a skill under a followed entry stored the external path. The
lexical compare in merge sync then never matched, and every sync removed,
recreated, and reported the link as updated.

Skill links now take an explicit source root and logical tail: relative
text runs from the link's canonical parent to the canonical source root
plus the logical tail, so the followed entry stays in the link text.
Agents and extras keep resolving the whole destination. Merge sync
compares with sameSkillLink, which accepts exactly the skill's logical
path, the canonical source root plus the tail, or the skill's fully
resolved path, so a second sync updates nothing.

While a followed entry is unavailable, a relinked name is reported with a
warning, because the manifest records no origin for the old link.

Refs #274
A managed link that resolves through a followed entry's physical target,
through a source root that is itself a link, or relative to a linked
target parent fell into the external branch and was never pruned when
filters changed.

With a follow policy, a live link is pruned only when it is in the
manifest and resolves inside the logical source, the canonical source
root, or a currently followed entry's resolved target; --force keeps the
existing escape hatch. Links created through a followed entry stay inside
the source after unfollow and are pruned as orphans. A managed link to a
physical external path is kept with an explicit after-unfollow warning.
Without .skillfollow, prune is unchanged.

Refs #274
When a declared entry is missing or rejected, discovery is incomplete and
the manifest cannot say which names came from it. Prune would then remove
links and, in copy mode, managed copies that may be the only remaining
copy of the unavailable content.

While any entry is unavailable, merge and copy prune remove nothing on
every skills target, even with --force, and report the blocking entries.
In standard naming an existing managed copy whose origin cannot be proven
is kept rather than overwritten; flat names carry the logical prefix and
proceed. Merge links may still be replaced, with the warning added in the
identity change, and new links and copies are still created. Once the
entry is restored or undeclared, prune resumes.

Copy sync and copy prune take the follow policy through CopyOptions and a
new PruneOrphanCopiesWithOptions; the existing functions keep nil-follow
behavior.

Refs #274
CheckStatusMerge only counted links whose lexical target was under the
logical source. A relative link through a followed entry, read from a
linked target parent or a linked source root, or a managed link stored
as the fully resolved path, counted as local, so doctor reported sync
drift after a clean sync.

CheckStatusMergeWithOptions keeps in-source classification exactly as
before and also counts a link as linked when the manifest records it and
it resolves inside a currently followed entry's resolved target. Status
stays an aggregate connectivity count with no per-name mapping, and
unmanaged links stay local until sync adopts them. The CLI status and
doctor target checks pass their follow set.

Refs #274
Reconcile never walked declared links, so metadata for skills under a
followed entry was pruned as stale. Walking them with the ordinary rules
would instead create and refresh metadata, including tracked: true
entries, for a tree that belongs to the user.

With a follow policy, names under a followed entry that already have
metadata, or are git repos, are marked live; reconcile never sets or
refreshes their metadata, so following never creates a tracked entry.
While an entry is unavailable, metadata under its logical prefix is kept
and everything else is pruned normally. ReconcileGlobalSkillsWithOptions
and ReconcileProjectSkillsWithOptions carry the policy; the existing
functions keep nil-follow behavior.

Refs #274
The sync engine can now pause prune and keep managed copies while a
followed entry is unavailable, but the CLI did not pass its follow set to
the per-target runner and nothing told the user why cleanup stopped or
how to resume it.

Global and project sync pass the follow set they discover with to every
skills target. Sync reports "prune paused" with the blocking entries and
lists copies kept from replacement, also as prune_paused and kept in the
JSON target details. Status and doctor name each blocking entry with the
recovery step: restore or fix it, or remove it from .skillfollow[.local].
All new output is absent without an unavailable entry.

Refs #274
Windows reports a junction as an irregular file, not a symlink or a
directory, so the proposal requires a simulated junction case: discovered
when declared, invisible when not. The test uses the operation-local link
seam to cover both through the follow-aware walker.

Refs #274
Coordinators and the 3c/3d workers need the exact options-bearing API,
the behavior per contract, and the callers still on nil-follow wrappers.

Refs #274
Share the command follow policy with analyze, diff, init discovery and uninstall resolution while preserving legacy nil-policy entry points. Refuse followed uninstall targets before planning dry runs and show resolved tracked-repo targets in plain list output.
Add options-bearing index and draft-candidate entry points so callers can expose followed skills at their logical paths. Keep the original entry points as nil-follow wrappers and let discovery reject incomplete followed reads.
Build the same target-aware follow policy for each handler operation, using the project staging boundary in project mode. Share it across overview discovery and preserve complete-result error handling; refuse linked uninstall, toggle and target edits before any mutation.
Exercise the five-entry fixture across CLI discovery and routed dashboard endpoints, including read-only linked mutation refusals and byte preservation. Record current check, update, audit and ownership expectations with pending slice markers so later integrations can deliberately update the contract.
# Conflicts:
#	cmd/skillshare/skillfollow.go
Share followed repository update policy across CLI, dashboard, and install paths so force, dirty, status, and divergence refusals remain visible per item. Resolve audit roots and retain rollback so linked child content cannot escape scanning, while preserving ordinary repository behavior.
Check physical link reachability before staging and refuse incoming revisions that could replace declared or undeclared links. Share the checks across CLI, dashboard, and init paths, report exact ignore remediation in doctor, and preserve ignored links during discard.
Record policy placement, discovery callers, additive queries, regression coverage, integration seams, and verified platform limits for the coordinator.
# Conflicts:
#	cmd/skillshare/skillfollow.go
#	internal/server/skillfollow.go
Slice 3d pinned the check, update, audit, and status rows to the
pre-3b/3c behavior so the other slices only had to flip expectations.
With 3b and 3c merged, check lists the followed repo, update --all
refuses the dirty followed repo per item, audit scans through resolved
roots, and status reports the prune pause for the missing declaration.
Helpers such as copy, frontmatter, and ignore-file edits write both the
skills source and trees outside it (targets, trash, agents, extras). A
Writer addressed by absolute paths lets one implementation serve both:
the source side passes Root.Writer, which refuses links as the Root
does, and everything else passes sourcefs.OS.

The ratchet now counts every reference to sourcefs.OS as a raw write, so
passing the plain writer still needs a reviewed reason, and an allowance
may carry a note that explains why a call keeps its reason.
Copy helpers pass the mode they read from Stat, which carries the
directory bit. os.MkdirAll ignores it, but os.Root rejects any bit
outside 0o777, so a copy through a Root's Writer failed. Keeping only
the permission bits matches what the plain writer does.
Local, discovery, and subdirectory installs copied into the skills
source with raw os calls, so a destination below a link in the source
wrote into the link's target. The copies now go through a sourcefs
handle at the source (or at the staging folder for staged updates),
and .metadata.json, sidecars, and the old registry.yaml are written or
removed through a handle at their folder, so a link is refused instead
of written through or replaced.

The failed-install cleanup hook keeps its signature for tests and now
removes through a handle at the parent folder. The temp-clone remover is
retagged tmp. The .gitignore writer stays source-unmigrated: its folder
may be the source, a project folder, or the config folder, and callers
do not say which.
collect --force removed an existing skill with os.RemoveAll and copied
the target's copy in its place, so a skill that is a link was replaced
by a real directory. Merging a target into an existing source also
copied through any link in the source. Both now write through a
sourcefs handle, so a link is refused and its target is left alone.

The copy helpers take a sourcefs.Writer; target, agent, and extras
copies pass sourcefs.OS with their own reason. Creating a missing
source root from a target is retagged source-root.
…andle

Restoring a nested trash entry such as org/_team-skills created and
renamed into destDir/org even when org is a link, so the skill landed
in the link's target. Restore now creates the parent and moves the
entry in through a sourcefs handle at the skills source, and its copy
fallback writes through the same handle. init copies imported skills
through a handle as well.

The trash and cmd copy helpers take a sourcefs.Writer: moving into the
trash and copying back into unlinked targets pass sourcefs.OS with
their own reason.
runkids added 17 commits October 5, 2026 02:57
…ite fails

Review finding (P2, test gap): runFollow unlinks the link it just
created when AddEntry fails, but no test reached that branch. The new
test makes .skillfollow a link so the write is refused, then checks the
JSON error, that <source>/x is gone, and that the linked file is
unchanged. It fails when the Unlink call is removed.
…atch real output

Review findings (docs): the README .skillfollow section still taught
only the manual ln -s setup and called Windows junction verification
pending, while the reference lists the verified global-mode cases. It
now leads with follow --to / unfollow, keeps ln -s as the manual path,
and states what passed scripts/windows/e2e-skillfollow.ps1 and what has
not run on a real Windows machine.

The follow target-overlap and indexed samples and the unfollow
--keep-link sample now show the Next block the binary prints, and both
pages say argument errors stay plain text under --json. The built-in
skill reference uses the website's single-skill wording and lists
update refusal among the verified Windows cases.
Lists each review finding with its commit, change, and covering test,
the verification run, and the findings left as follow-ups, so the
merge review can check the last fix round in one place.
Resolves the Settings row of the localized ui.md pages: keep the .skillfollow tab sentence from this branch and add main's .skillignore.local/.agentignore.local note, matching the English page.
The reuse/simplification review found about a dozen `follow != nil &&`
prefixes and two wrappers (skillfollowPauses, followScope.unavailable)
whose only job was guarding a method call on a nil snapshot. FollowSet
query methods now take pointer receivers and return the zero value on a
nil set, as WriteBoundary already did, so those guards and wrappers go.
Nil checks that decide something else stay.

No behavior change.
The reuse review found cmd's skillFollowSet and the server's followSetFor
had identical bodies. The body now lives once in sync.FollowSetFor, which
both packages already import without a cycle; cmd keeps its short helper
name as a one-line call and the server copy is gone.

No behavior change.
The efficiency review found Follow canonicalized the targets and git root
and listed the source root even when no declaration file exists. No
production caller reads entries from such a set: the snapshot constructors
return nil for it, and the bare Follow callers only use WriteBoundary. Follow
now returns right after reading declarations in that case. An unreadable
declaration still takes the full path.

The junction test that read undeclared entries from a set with no
declaration file now declares an unrelated name for that assertion, and
keeps the not-traversed check on the inactive set.

No behavior change.
The efficiency review found both follow walkers ran followedChild, a scan
of every declared entry, for each child at every depth before testing
whether the directory was the source root. The walkers now decide that
once per directory and only look up followed entries at the root.

No behavior change.
The simplification review found the same state conditions ("not an
undeclared link", "followed or a real directory") written out by hand in
sourcewalk, doctor, status, follow, and the server's skillfollow view.
State now has Declared and Available predicates and FollowSet has a
Declared list, and those sites use them. The predicates sit on State so
follow's result struct, which carries a bare State, can use them too.
JSON arrays that were never null stay non-null.

No behavior change.
The simplification review found PrunePaused and KeepsManagedCopies took a
source path only to build a followScope whose canonical roots they never
read. They now take the snapshot alone, and the scope method they wrapped
is folded into PrunePaused, which merge and copy sync call directly.

No behavior change.
…dlers

The reuse review found followedSkillWriteError was WriteBoundary plus a
filepath.ToSlash that InFollowed, which WriteBoundary calls, already
applies along with filepath.Clean. The wrapper is gone and its callers use
WriteBoundary; the same redundant ToSlash conversions in front of
InFollowed and WriteBoundary calls are dropped.

No behavior change.
The reuse review found two install error paths hand-wrote the ErrLink to
409, otherwise 500 mapping that followWriteStatus already provides. Both
now call it; their fallback was already 500.

No behavior change.
The simplification review found two near-identical helpers that differ
only by a leading `-C dir`. UntrackCommand now takes the directory and
omits `-C` when it is empty, so every printed command is unchanged.

No behavior change.
The efficiency review found the update stream rebuilt the follow snapshot
for every repository under the write lock, and updateRegularSkill and
auditGateTrackedRepo rebuilt it again, although the request already holds
one. The stream and updateAll now pass the request snapshot down, and both
helpers take it as a parameter, as updateTrackedRepo already did. Neither
helper walks the source root with it, so no item can mark an entry missing
for a later one, and InFollowed answers the same for a followed repository
before and after its pull.

No behavior change.
The reuse review found FollowSet.Owns had no production caller while
sync's inFollowedTarget re-implemented its followed-target loop. Owns'
source-root clause cannot be reused there: followedLink must not count a
link into the source itself. Owns becomes FollowedTargetContains, holding
only the followed-target loop, and inFollowedTarget calls it; its existing
test assertions carry over unchanged.

No behavior change.
The reuse review found ConfigPage invalidated the same four discovery
queries (diff, overview, skills, doctor) after saving .skillignore,
.skillfollow, and .agentignore. invalidateDiscovery in lib/sync.ts now
holds that list, next to invalidateAfterSync, and the three sites call it.

No behavior change.
Records each simplification commit, the deviations from the review brief,
the verification results, and the follow-ups left out of this batch.
runkids added a commit that referenced this pull request Oct 5, 2026
* fix(audit): keep the skills source when auditing agents only

`skillshare audit --agents` replaced sourcePath with the agents source
before building auditTUIContext, so the TUI's Skills tab discovered
skills inside the agents directory. The agents-only branches now read
agentsSourcePath themselves and the skills source is left alone.

Also from the #390 review, independent of .skillfollow:

- /api/skillignore reads the source through skillsSource() like the
  other routes (equal in project mode today; consistency only).
- scripts/windows/e2e-file-links.ps1 checked doctor output for a
  "Config:" line that no longer exists and could not match the ~-shortened
  path, so the run always aborted. It now checks status --json
  source.path, as e2e-skillfollow.ps1 does.
- windows-test runs internal/sourcewalk; GOOS=windows vet passes and the
  job on this PR is the first real run.

Refs #404, #407.

* fix(audit): relativize agent names against the agents source

With discovery moved to the agents source, auditInstalled and
auditFiltered still printed the header and computed SkillName against
the skills source, so `audit agents --json` reported names such as
`../agents/helper.md` when the two sources are siblings (Codex review on
#412). auditScanRoot now picks the root per kind for discovery, header,
and relativization; the skills source is kept only for TUI tab switching.

Also drops internal/sourcewalk from windows-test again: the first run on
windows-latest fails TestWalkParity, TestWalkDirParity and
TestSymlinkRoot (callback paths come from the canonical root, so
filepath.Rel against the test's root yields `..\..` chains). Logged on
#344.
@runkids

runkids commented Oct 5, 2026 •

Copy link
Copy Markdown
Owner Author

Closing without merging. The reference implementation in #274 was about 40 lines; this PR reached +20k lines across 396 files, most of it on guards around the external-mutation boundary, and the result has not been used on a real repo yet. That is too much to carry for an opt-in feature with one known user. The need in #274 stays open and will be re-scoped from there. The branch runkids/274-step3 stays for reference.

@runkids runkids closed this Oct 5, 2026
@runkids
runkids deleted the runkids/274-step3 branch October 6, 2026 03:59
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