Commit Graph
223 Commits
Author SHA1 Message Date
Rusty Shackleford 71ff2d9e14 fix(discovery): find repository-root .agents/skills (#801)
A repository-root .agents/skills now counts as a skill anchor only when the repository has no other SKILL.md outside .git and target directories, so tracked checkouts that author skills there are discovered, while repos that commit .agents/skills copies keep discovering only their authored skills.

Fixes #800
2026-11-10 16:04:20 +08:00
Rusty ShacklefordandWillie 85bcf589a7 feat(sync): recognize and route agent-specific skill variants (#649)
* docs(proposals): propose agent-specific skill variants

Tracked repositories can ship different files for the same skill across
agents. Counting and syncing each copy independently sends incompatible
instructions to every target unless users maintain routing filters.

Propose repository-scoped logical identity and exact variant routing while
preserving source files, explicit controls, and existing naming behavior.
Leave activation and compatibility decisions for maintainer review.

Refs #648

* docs(proposals): clarify variant routing compatibility

Explain how recognition affects universal-only targets and how existing
per-variant overrides preserve the desired routing. Fix the precedence
between variant identity and generic host-style path inference.

Include analyze, move, and catalog consumers while preserving physical
identifiers and actual context-cost accounting.

Refs #648

* docs(proposals): clarify activation assumptions and scope

Make acceptance cases conditional on maintainer-approved recognition being
enabled for the tracked source. Separate the provisional implementation
estimate from this proposal-only PR so its size is clear.

Refs #648

* docs(proposals): qualify naming and opt-in assumptions

State that the reproduced routing behavior uses default flat target
naming. Leave any opt-in surface with the maintainer's activation decision
without ruling out future CLI or config fields.

Refs #648

* feat: recognize and route tracked agent skill variants

Count tracked variants as logical skills in source and repository summaries,
while preserving physical paths, sync operations, and context costs. Select
matching canonical agent variants, including account targets, through shared
discovery and selection with existing explicit routing precedence.

Refs #648

* fix: count logical skills in sync inventory summaries

Use shared logical and physical inventory counts in global and project sync
closing lines while preserving each target's operation totals.

Refs #648

* fix: preserve variant routing diagnostics across previews

Resolve target selections once so CLI and server previews keep ambiguity
reasons and physical skip counts. Explain managed variants removed by
automatic agent routing, and report logical inventory in doctor.

Keep warning rows read-only, document upgrade recovery in translated
filtering references, and remove the optional README-only addition.

Refs #648

* fix: align sync matrix previews with shared variant selection

Classify the full source selection once per target so matrix previews honor
canonical aliases, account identity, exact-agent routing, and ambiguous
variant skips. Preserve each rejected physical path's existing diagnostic
and draft filter disambiguation; skipped preview rows remain read-only.

Refs #648

* test: expect singular skill wording in doctor source checks

Keep the undiscovered-link count assertion aligned with logical source
inventory formatting for one skill in global and project mode.

Refs #648

* fix: retain selection diagnostics in catalog and diff verdicts

Report warning-only diff targets as requiring attention while preserving
local-only folder semantics. Reuse shared per-path selection diagnostics
in target-scoped catalogs without applying target naming to served paths.

Compute source counts once in summary callers and require variant counts
in the source status formatter.

Refs #648

* test: tighten tracked variant preview fixtures

Use a real committed tracked repository for status counts, verify sync
preview banners retain server warnings, and use emitted ambiguity reason
text in target preview fixtures.

Refs #648

* fix(sync): keep agent variants in shared target folders

Compatible targets sharing a skills folder need a combined selection so
Codex and universal do not prune one another in merge or copy mode.
Carry every shared reader through selection, pruning and previews,
including project targets, account identities and path aliases.

Require a matching skill suffix under two distinct agents before
inferring variants, keeping ordinary agent-named categories unrestricted.
Separate naming warnings from ambiguous selection in diff and explain
ambiguous removals. Add global/project regression coverage for repeated
sync, target-only sync, status JSON, diff and API consumers.

* fix(variants): align consumer counts, hints and diagnostics

Use logical source counts in list, tracked install and init summaries while matching audit caches against physical variants. Restore localized dashboard skip hints and explain symlink routing limits in status and doctor, including project and JSON output.

Document paired-agent detection and compatible shared-folder selection in the proposal, built-in skill and English plus translated command pages. Add focused regressions for the affected consumers.

* fix(sync): cover initial sync and ignored variant diagnostics

Init syncs a fresh in-memory config, so resolve shared target identities
before its first sync as well as when loading saved configuration.

A whole-directory symlink exposes ignored skills too. Diagnose agent
variants using physical inventory when active discovery has none, while
keeping logical counts and merge/copy selection restricted to enabled
skills. Cover global/project JSON status and doctor with regressions.

Reuse sourcewalk directory and canonical-path helpers so traversal guards
remain enforced and path resolution has a single existing owner.

* fix(variants): address conversion, counts and selection diagnostics

Ignore runtime agent identities when comparing convertible project targets and count logical skills during init. Keep selection warnings separate from naming warnings and preserve agent-named parent skills as ordinary skills.

Cover account sync/prune, project ambiguity and overrides in merge/copy modes, and init/status agreement. Focused verification ran in an isolated Linux Codex container, not the devcontainer, as authorized.

* refactor(variants): remove obsolete selection helpers

Remove the unused FilterSkillsByTarget wrapper and prune agent parameter, cache canonical target aliases once, and restore catalog skip ordering to avoid an unrelated behavior change. Completes the optional cleanup from PR 649 review.

* fix(ui): expose localized variant selection diagnostics

Show target warnings with source paths, localize ambiguity across preview and detail consumers, and let skipped preview rows add a physical exclude pattern. Show tracked repository variant counts alongside logical skills.

Drop display-only rendered cases while retaining mutation protection and plain TypeScript logic coverage. Inspect target states in Clean/Playful light/dark and Traditional Chinese.

* docs(variants): explain diagnostics and add sync runbook

Document doctor variant_routing and logical/physical counts, diff selection skips, and the nested parent-skill boundary. Keep all four command translations aligned and add isolated account/project E2E scenarios.

Both runbook steps passed in the authorized Linux Codex container with separate HOME/XDG/TMPDIR fixtures. Website typecheck and all five locale builds passed.

* test(config): use native paths in project conversion fixture

The shared-agent regression fixture appended slash-separated suffixes to Windows temporary paths, so project path matching returned no candidates. Build each path with filepath.Join and preserve all conversion assertions.

Focused project configuration tests passed in the authorized isolated Linux Codex container, not the devcontainer. Windows CI verifies the platform-specific fixture correction.

* fix(ui): recompute shared skill routing for filter previews

Evaluate edited include/exclude settings in the complete target map before
classifying the draft, so a formerly shared folder no longer keeps its old
union when the filters differ. Preserve the saved target configuration.

* fix(mcp): keep parent skills when peer variants route elsewhere

Do not treat an otherwise eligible variant for another agent as an unserved
nested skill. Continue blocking parent publication for explicitly filtered,
disabled, ambiguous, or invalid children so filters still hide their files.

* fix(ui): distinguish agent selection from naming skips

Expose separate naming and selection skip counts on target summaries.
Show each applicable remedy in target details and sync previews so ambiguity
keeps its filter/override guidance alongside naming and collision hints.

* fix(list): include disabled rows in tracked repository counts

Count the complete inventory that list displays, including ignored skills
and physical variants, without changing the enabled counts used by status,
install, or sync. Clone rows before counting to preserve disabled state.

* docs: align variant counts and routing recovery guidance

Show logical skill and physical variant counts in list/install documentation
and keep the four translations aligned with the filtering examples. Explain
that agent-named skill parents keep ordinary nested skills and retain the
devcontainer-only runbook environment. Removal warnings now recommend a
source-local override, since include filters cannot undo agent routing.

* fix(mcp): preserve explicit target restrictions on nested variants

Limit the differently routed child exemption to automatic layout inference.
Frontmatter targets and dashboard source-local overrides must still prevent
a parent from publishing files explicitly restricted to another target.

* fix(ui): fill target name in naming warning guidance

Pass the current target name when rendering localized warning hints so the
same naming guidance shown beside the controls does not expose a placeholder
in the warning banner. Verified in the populated target preview.

---------

Co-authored-by: Willie <egg358358@gmail.com>
2026-10-29 16:47:38 +08:00
Rusty ShacklefordandClaude Opus 5.5 cbcb7a21ab refactor(sync): build agent ignore reports from the synced snapshot (#611)
Dashboard sync and project sync JSON scanned the agents source again just
for the ignore summary. Carry the full discovery snapshot through sync so
the response describes the agents that were synced, including ignored ones.
Skills-only syncs keep the existing fallback scan.

Cover the handler and project JSON paths when the source changes after
discovery. Check syncProject returns ignored agents and an empty discovery
stays non-nil through execution, so neither path silently rescans.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 01:55:34 +08:00
Rusty Shackleford 5729eee088 feat(project): manage global registrations from the CLI (#603)
Add global project list, show, add, edit, sync and remove so setup scripts
can register repositories without editing YAML or opening the dashboard.
Keep dry runs read-only and report completed work when a target fails.

Reuse the shared project service and sync runners. Include command docs,
translations, completions and regression coverage. Quote overlap hints for
their shell and log partial project syncs consistently with ordinary sync.
2026-10-26 01:38:04 +08:00
Rusty Shackleford d23a44aec9 refactor(projects): share safe dashboard and CLI operations (#602) 2026-10-23 02:07:54 +08:00
Krishnaswamy SubramanianandWillie dabe06a297 feat(targets): support OpenCode config directory accounts (#594)
* feat(targets): support OpenCode config directory accounts

OpenCode v2 introduces support for custom configuration directories
via OPENCODE_CONFIG_DIR, storing opencode.json and agent directories.

Previously, skillshare rejected OpenCode accounts configured with a
custom config directory because OpenCode was missing config_dir and
was excluded from accountAgents in hooks and MCP services.

- Define default config_dir (~/.config/opencode) in targets.yaml
- Add OpenCode to account agents and register OPENCODE_CONFIG_DIR
  across hooks and MCP service handlers
- Route OpenCode account MCP configuration to opencode.json inside
  the account config directory

Resolves #593.

* fix(targets): add OpenCode to schemas, completions and docs

Add opencode to the targetConfig.agent enum and config_dir description
in schemas/config.schema.json so configurations containing OpenCode
account targets pass schema validation.

Include opencode in the target --agent completion scripts for Bash,
Zsh, Fish, PowerShell, and Nushell.

Update website documentation and built-in skill references to describe
OpenCode accounts and OPENCODE_CONFIG_DIR management alongside other
account agents.

* fix(targets): support plugin accounts and overlap

Add OpenCode account recognition and OPENCODE_CONFIG_DIR resolution to
the plugin service so plugin sync works for OpenCode account targets.

Introduce TargetScanPaths to resolve cross-runtime scan paths using
TargetConfig.Agent for account targets while retaining the account's
own primary directory. Update path overlap detection, doctor checks,
and LeakedSkills to warn about leaked skills for account targets.

Update localized docs (zh-Hans, zh-Hant, ja, ko) and plugin references
to document OpenCode account targets and OPENCODE_CONFIG_DIR. Update
the available targets handler test to expect OpenCode's configDir.

* fix(targets): isolate OpenCode accounts and scan paths

Reject OPENCODE_CONFIG overrides when operating on OpenCode accounts
and clear OPENCODE_CONFIG in the account execution environment so
plugin operations target the account directory.

In TargetScanPaths, remap config-root paths to the account directory
while preserving external scan paths like Codex's ~/.agents/skills.

* fix(plugins): use account target in OpenCode update probe

Pass c.Target instead of a hardcoded "opencode" when probing whether
OpenCode supports plugin updates, ensuring account-configured CLI
binaries and account environment variables are used during preview.

* test(mcp): isolate XDG_CONFIG_HOME in account test service

Isolate XDG_CONFIG_HOME to the temporary test directory in
agentAccountService to prevent runner environment variables from leaking
into TestAccountEnvOverrideDoesNotPruneDefaultHome when testing OpenCode
account shell overrides.

---------

Co-authored-by: Willie <egg358358@gmail.com>
2026-10-22 21:50:06 +08:00
Willie ac1d4b4387 fix(list): show every target sync placed a skill or agent in (#562)
* fix(list): show every target sync placed a skill or agent in

The Targets row of the list detail panel only looked for a symlink named
after the skill's flat name in the target's skills folder. It therefore
left out targets that sync fills in copy mode, targets linked whole in
symlink mode, targets using standard or prefixed naming, and every agent
target (agents were looked up in the skills folder). Targets with skills
turned off were still listed.

The row now asks sync's own name resolution and manifest which entry a
target holds for the skill, and checks agents in their resolved agents
folder by mode or extension output. Each target is resolved once per load
so moving through a large source under standard naming stays fast.

* fix(list): drop a skill's targets as soon as it is disabled in the TUI

Pressing t updated the row's disabled flag but not the discovered skills
that sync's name resolution reads, so the open list kept showing the
skill's targets while a reopened list, which rediscovers it as disabled,
showed none. The toggle now updates that flag too, so both agree: a
disabled skill lists no target, since the next sync removes its entries.
2026-10-14 01:47:30 +08:00
Willie 111dd71a53 fix(sync): let prefixed naming keep skills whose name differs from their folder (#531)
Prefixed naming rewrites name: in every copy to the entry name, so the
target folder and name: always agree. Requiring name: to equal the source
folder only skipped skills it could sync: a tracked repo that is itself a
skill lives in _<repo>, so its root SKILL.md could never pass.

Only standard naming now requires the match; name format rules still
apply to both. Sync lists the skills named this way, so a user looking
for _ooux in the target finds ooux.

The dashboard's skipped-skills hint always blamed folders that end in the
same name, even when skills were skipped for their name. The diff API now
reports naming skips apart from collisions and the hint names the cause.

Refs #530
2026-10-12 13:59:59 +08:00
Willie d2f5936be9 fix(sourcewalk): never skip the source root as a target dotdir (#514)
SkipTargetDotDir only exempted dotdirs directly under the walk root, never
the root itself. ProjectTargetDotDirs() always contains ".skillshare", so a
source whose basename is a target dotdir (".skillshare", ".claude", ...) had
its first Walk callback return SkipDir. Discovery then saw an empty source:
`skillshare list` returned [] and sync pruned previously managed links.

Exempt path == walkRoot in the shared helper so both callers
(sync discovery and resource skill discovery) are fixed. Nested target
dotdirs are still skipped and first-level ones stay visible.

Fixes #511
2026-10-10 21:43:35 +08:00
Willie 2ce46834e2 fix(collect,install): collect only real skills; let --track take a local git path (#508)
* fix(collect,install): collect only real skills; let --track take a local git path

collect treated every directory in a target as a local skill, so a scratch
folder was listed and `collect --force` copied it into the source. A folder
now counts only when it holds SKILL.md; the dashboard scan shares
FindLocalSkills and the dashboard collect request rejects such a folder.

`install /path/to/repo --track` failed with "requires a git repository
source" while file:///path worked. A local path that is a git repository
root is now normalized to the same file:// clone URL for --track (also past
the --branch guard); other local folders get an error that names file://.
Help text, docs (English and i18n) and the built-in skill reference follow.

* fix(install): keep the drive letter in file:// clone URLs for local --track paths

A Windows path such as C:/repo produced file://C:/repo, which makes C: the
URI authority instead of part of the path, so a tracked install from a local
Windows repository could clone the wrong location. Prefix the missing slash
so the URL is file:///C:/repo; POSIX paths are unchanged. Also cover the
dashboard install endpoint with a local-path --track test.

* fix(collect,install): keep UNC file URLs intact; require SKILL.md to be a file

The drive-letter fix lived in the helper shared with explicit file:// URLs,
which rewrote file://server/share/repo into a local path. Keep the slash
logic in the local-path --track case only and leave explicit URLs as parsed.

A subdirectory named SKILL.md passed the existence check, so a scratch folder
holding one was still collected. Both collect entry points (scan and the
dashboard request) now share sync.HasSkillFile, which rejects directories.

* fix(install): escape the local path in the file:// URL used by --track

Git decodes a file:// URL, so a repository path containing %20, %2F, a space
or # was cloned from a different path than the one IsGitRepo accepted. Build
the URL with net/url so those characters are escaped; drive-letter and POSIX
paths keep their form. The integration test now installs from a directory
whose name contains a space and a literal %20.

* fix(install): accept a local bare repository path for --track

A bare repository has HEAD and objects at its root but no .git entry, so the
local-path check rejected it while file:///same/path cloned fine. Add
IsLocalGitRepo (working tree or bare) and use it for both the --track
normalization and the --branch guard.

* test(install): build the bare repo path from a Windows file URL correctly

makeRemote returns file:///C:/dir on Windows; trimming only file:// left
/C:/dir, which filepath.Abs turned into D:\C:\dir, so the bare-repo test
failed on the Windows runner. Drop the slash before the drive letter.

* fix(install): refuse a --track local source that is the install destination

--force removes the tracked destination before cloning. When the local path
given to --track is that same directory, the removal deleted the only clone
source (and any unpushed work) before the clone failed. Compare the two with
os.SameFile, which also covers symlinked paths, and stop before touching the
destination.

* fix(install,collect): keep a tracked source inside its destination; reject special SKILL.md files

--track --force removed the destination before cloning, so a local source
nested below it (or given as an explicit file:// URL) was deleted along with
any unpushed work, and the clone then failed. Resolve the source and refuse
when it is the destination or lies under it, for dry runs too.

HasSkillFile used a not-a-directory test, so a FIFO named SKILL.md counted as
a skill and the collect copy blocked on it. Require a regular file; a
symlinked SKILL.md still resolves through os.Stat.

* fix(install): treat file://localhost URLs as local clone sources

Git clones file://localhost/path from the local filesystem, but the
containment guard only recognised an empty authority, so --track --force
could still delete a source given that way. Accept localhost (any case) as
local.

* test(install): build the localhost file URL from a slash path

On Windows the temp path starts with a drive letter, so prefixing it onto
file://localhost produced file://localhostC:\... instead of a valid URL and
the case failed on the Windows runner. Convert to slashes and add the
separator explicitly.

* fix(install): clone --track --force into a staging dir and swap it in last

--force removed the existing tracked repo before cloning, so any source that
lived under it (plain path, file:///, file://localhost, UNC, symlink or 8.3
alias) was destroyed before git could read it, and a failed clone also lost
the old repo. Clone beside the destination, run the checks and the audit on
the staging copy, then move the old repo aside, rename the new one in and
drop the backup; on any failure the staging copy is removed and the old repo
stays. The pre-removal containment refusal now covers plain local paths only
(the url.Parse special-casing is gone).

* fix(install): refuse a file:// --track source inside the forced destination

The staged swap in 7375400 still lost data for a file:///, file://localhost
or UNC source nested under the destination: the clone succeeded, the old repo
(with the source inside it) was renamed to the backup, and removing the backup
deleted the source's uncommitted work, which a clone cannot carry.

Restore the file URL to local path mapping (now including UNC hosts) so the
containment refusal covers every local spelling, not only plain paths. The
test now keeps an uncommitted file in the source and requires it to survive.

* fix(install): apply the source-inside-destination refusal only to --force

The refusal ran before the --update branch, so `install <tracked repo path>
--track --update` was rejected even though an update pulls the existing
checkout in place and removes nothing. Only the forced replacement can
destroy a source that lives under the destination, so check there.

* fix(install): report a forced clone's root skill under its tracked name

With --force the repo is discovered in the .skillshare-clone-<stamp> staging
directory, and discoverSkills names a root SKILL.md after the directory, so
the CLI summary, dashboard response and oplog listed a random staging name
instead of _foo. Use the tracked name for the root entry.

* fix(install): stage fresh tracked clones so cleanup never hits another installer

A fresh tracked install cloned straight into the destination, and the
deferred cleanup removed it on any failure. If another process created the
same tracked repo between the existence check and the clone, the failing
install deleted that process's checkout. Clone every install into its own
staging directory and rename it in last; a claimed destination makes the
rename fail and only the staging copy is removed.
2026-10-10 01:06:23 +08:00
Willie c638b46096 fix(sync): replace copy-mode copies with links when switching back to merge (#506)
* fix(sync): replace copy-mode copies with links when switching back to merge

Switching a target from copy back to merge left every copy whose entry name
did not change as a real folder. Merge sync treated it as the user's own
folder, so status and doctor kept saying "run skillshare sync" while sync
changed nothing, and only `sync --force` turned it into a link.

Copy mode already replaces merge-mode links with copies on its own, so merge
sync now replaces a folder the manifest records with a checksum (a copy-mode
copy) with a link, without --force. Folders the manifest does not record, or
records as a link, stay untouched. The pre-sync target backup is unchanged.

The CLI and dashboard diffs name these entries as copies sync replaces
instead of suggesting --force, and the sync-modes docs describe the switch.

* fix(sync): keep copy-mode copies the user edited when switching to merge

The first version replaced any folder the manifest recorded as a copy-mode
copy. The manifest checksum is only a record, so a copy edited since copy
mode made it was deleted too, and `sync --json` and project-mode dashboard
sync take no pre-sync backup to restore it from.

Replace the folder only while it still hashes to the recorded checksum
(Manifest.OwnsCopy). An edited copy is kept and `sync --force` still
replaces it; diff keeps suggesting --force for it. A copy whose name: was
rewritten by prefixed naming, or that was made with custom ignore patterns,
no longer hashes to the source checksum and is kept the same way.

* fix(ui): say a copy-mode copy in a merge target is replaced by a link

The Sync page picks a row's text from the diff item's action alone. The
copy-mode copy that merge sync now replaces comes from the server as an
update, which the page worded as "Link is broken or points elsewhere. Will
be relinked" even though no link exists yet.

Match the server's reason and show "Copy made by copy mode. Will be replaced
by a link" instead, in all eleven dashboard languages.

* docs(sync): say only unedited copy-mode copies are replaced on merge sync

The sync-modes paragraph promised that copies copy mode made are replaced
with links without --force. Merge sync keeps a copy that no longer hashes to
the checksum copy mode recorded, so an edited copy, or one whose name: copy
mode rewrote for prefixed naming, still needs --force.

State the three cases in sync-modes and qualify the diff Modified and Local
override labels, in English and the ja, ko, zh-Hans and zh-Hant copies.

* fix(sync): keep the copy until its replacement link exists

Replacing a copy-mode copy removed the folder first and then created the
link. If creating the link failed (no symlink or junction rights on a
Windows or network filesystem), sync returned an error with the skill gone
from the target. This path now also runs on a plain sync, not only on
--force.

Park the folder beside the entry, create the link, then delete the parked
folder; on failure the folder is moved back. A parked folder left by a run
that died mid-way may be the only copy, so the next sync stops with a message
instead of deleting it. The manifest also forgets the copy-mode mtime and
naming records of an entry that is now a link.

* test(sourcefs): register replaceWithLink's target writes in the raw-write ratchet

The previous commit moved the merge-mode folder replacement into
replaceWithLink, which the ratchet reports as new raw os calls and the old
os.RemoveAll allowance as stale. All of them act on the sync target, not the
skills source, like the neighbouring entries.

* fix(sync): bound the parked copy's name and document the naming exception

The folder parked while a link is created was named after the entry, so an
entry near the 255-byte filename limit (a long flattened nested skill)
could not be moved aside and its replacement failed. The parked name is now
a fixed-length hash of the entry name.

sync-modes also says what happens when `target_naming` changes in the same
sync: the copy gets a new entry name and the prune pass removes it as an
orphan whether or not it was edited, as it did before this change.
2026-10-10 00:13:29 +08:00
Willie ec2a8ab3aa fix(sync): close gaps found while simulating the prefixed naming switch (#504)
* fix(sync): close gaps found while simulating the prefixed naming switch

Simulating the #497 reporter's switch from merge + flat to copy + prefixed
turned up four problems:

- `target X --mode copy --target-naming prefixed` applied only --mode, since
  the setter dispatch returned after the first flag. Both flags given
  together now check the final pair, then apply in an order that keeps the
  saved pair valid (copy mode first, any other mode last).
- Skipped skills were only counted, so a prefixed name over 64 characters
  vanished with "1 skill(s) skipped". Sync now names the first five with
  their reason; the cap keeps huge sources from flooding the output.
- In copy mode a merge-mode link to the skill was not a managed entry, so
  when a local folder held the new name the old link was pruned and the
  skill left the target, contrary to the documented "old managed entry is
  preserved". Copy mode now migrates such links like managed copies.
- PATCH /api/targets validated the mode/naming pair against the current
  skills state, so disabling skills while changing mode was rejected. It now
  checks the state the request leaves the target in.

* docs(target): drop stray space in the Japanese mode+naming sentence

* fix(diff): save paired target settings once and report kept legacy entries

- `target X --mode M --target-naming N` ran the two setters, each saving
  the config, so a failed second save left half the change behind (Codex
  on #504). Both fields are now set and saved once, after the final pair
  is checked.
- When a local folder holds the name a skill's naming now gives it, sync
  keeps the skill under its old entry and leaves the folder alone, even
  with --force. diff still called the folder a "local copy" and suggested
  `sync --force`, which does nothing for it. CLI and Web API diff, copy
  and merge mode, now report the folder and the entry the skill stays at.

* fix(sync): migrate only links the manifest records as merge-made

Copy mode treated any link to the skill's source at an old naming's name as
the entry merge mode left behind, so a user's own link was renamed and
replaced with a copy (Codex on #504). A link now migrates only when the
manifest records it as "symlink", which merge mode writes for links it makes;
other links stay as the user left them. The value is now a named constant.

* fix(diff): mark kept legacy entries as unaffected by force

Two problems Codex found on #504:

- The Web API diff sent a local folder on a skill's new name as a "skip",
  which the dashboard shows as an edited entry that Force replaces. Sync
  keeps that folder and the legacy entry even with force, so the preview
  promised a change that never happens. It is now its own "kept" action,
  shown with its reason and not counted.
- `target X --mode M --target-naming N` printed the target's own naming as
  the old value, so a target inheriting standard or prefixed showed
  "flat -> ...". It now prints the naming the target had in effect.

* fix(diff): keep kept-name conflicts out of the sync count

Two problems Codex found on #504:

- A local folder on a skill's new name counted toward "N to sync" and
  fell through to the plain `skillshare sync` hint, though sync changes
  nothing there until the folder is renamed or removed. Such rows now
  carry a kept flag, count as neither sync nor local, and print their own
  hint; a target whose only row is kept still shows that row.
- The dashboard grouped targets by row name and icon only, so two targets
  keeping the same skill at different old entries merged and showed one
  target's old location for both. The row detail is now part of the key.

* fix(diff): do not list a kept local folder's files as deletions

A kept row (a local folder on a skill's new name) still pointed at that
folder, so `diff --stat` and `--patch` listed each of its files as removed,
though sync never touches the folder (Codex on #504). Kept rows no longer
point at a target directory, so no file-level diff is built for them in the
CLI or the TUI.

* fix(diff): report kept skills consistently in every diff view

An exhaustive review of the kept-row change (prompted by two Codex findings
on #504) found the same gap in several places:

- A target whose only rows were kept was summarized as "in sync", and mixed
  summaries left it out of every count. Such targets now count as "N kept
  under old name" with a warning mark, and the scan progress counts them.
- Plain output and the TUI hid where the skill stays; rows now read
  "name (stays at old-name)". The TUI also lacked the kept Next hint and
  called kept-only targets "differs"; it now matches the plain output.
- `diff --json` emitted kept rows as "remove", indistinguishable from
  local-only folders; it now emits "kept", as the Web API does. The diff
  docs' JSON example also showed actions the CLI never emits.
- Renamed rows whose old entry is a merge-made link showed a bogus file
  stat, because the link was walked as a file; a link now stands for the
  folder it points to.
- A dry-run migration printed "Would copy" to the old path; it now names
  the new one.

* fix(sync): stop reporting kept folders and skipped skills as pending work (#509)

Three reports told users to do something sync cannot do, or hid what it
did:

- Copy and merge sync kept a folder the user made on a skill's name but
  counted it as "up to date" with no hint. Sync now counts it as local and
  adds one capped line per target naming the folders and saying that
  `sync --force` replaces them. The line is added in SyncSkillTarget, so
  the dashboard gets it too.
- status and doctor counted skills that sync skips on purpose (invalid
  names under standard or prefixed naming, name collisions) as "not
  synced — run skillshare sync". Running sync can never add them, so the
  advice looped. They now compare against the skills sync places.
- diff marked a target whose only items were local-only folders as "to
  sync" and `synced: false`. Those items are still listed, but they no
  longer make the target pending.

* fix(target): apply every setting flag, require flag values, report no-ops as unchanged (#507)

* fix(target): apply every setting flag, require flag values, report no-ops as unchanged

`skillshare target <name>` dispatched --mode, --agent-mode and
--target-naming through an if-chain that returned after the first match,
so `--agent-mode copy --target-naming prefixed` applied one setting and
silently dropped the other. Filters, --skills and --dry-run had the same
early-return problem.

- Check --mode, --agent-mode and --target-naming as a whole and save
  once, in global and project mode (one targetSettingsUpdate replaces six
  per-flag functions).
- Reject --mode/--agent-mode/--target-naming combined with filters or
  --skills, and --dry-run without --skills, instead of dropping them.
- A value flag followed by another flag (or an empty string) now reports
  "<flag> requires a value"; `--target-naming -p` used to report an
  invalid naming '-p'.
- A value the target already has is reported as unchanged and the config
  is not rewritten.

* fix(target): leave the skills pair alone on agents-only changes

A target with skills off may keep target_naming prefixed with a merge
mode it cannot sync; validateGlobalTarget and validateProjectTarget only
check that pair for enabled skills. The combined settings update ran the
pair check for every setting, so `target claude --agent-mode copy` was
refused on such a target although the old agent-mode handler never looked
at skills settings. Check the pair only when --mode or --target-naming is
given.

* docs(target): show combined settings in --help and the built-in skill

The combined --mode/--agent-mode/--target-naming form is now the way to
move a target to copy + prefixed in one step, but neither the help
examples nor the built-in skill's target reference showed it.
2026-10-09 23:59:47 +08:00
Willie 9c994faa17 fix(frontmatter): read and rewrite SKILL.md that starts with a UTF-8 BOM (#505)
* fix(frontmatter): read and rewrite SKILL.md that starts with a UTF-8 BOM

Windows editors such as Notepad write a BOM before the opening ---. The
lenient readers (ParseSkillName, ParseFrontmatterField/Fields/List, ReadSkillBody)
did not skip it, so under target_naming standard/prefixed the skill had no
readable name and was silently skipped. Strip the BOM in the shared frontmatter
locator and the line scanner, and in the hub, search, audit and sync/context
readers that split lines themselves (utils.TrimBOM).

The writers kept working on the unstripped text, so SetFrontmatterValue
prepended a second block and ToggleFrontmatterFlag/RewriteFrontmatterList
could leave a BOM in the middle of the file. They now split the BOM off and
put it back in front, rewriting only the name value (or flag/list) as before.

* fix(frontmatter): cover the dashboard parser and stop auditing a leading BOM

A consumer sweep after the first BOM commit found two more places that
mishandled a SKILL.md written by Notepad:

- audit reported the leading BOM as a HIGH hidden-unicode finding (U+FEFF is
  in the zero-width rule), so every such skill showed a risk score. A BOM at
  the very start of a file is its encoding mark and hides nothing; one past
  the start is still reported.
- the dashboard's parseSkillMarkdown saw no frontmatter, so the skill editor
  would treat the whole file as body and write a second block on save.

The audit-engine page and its four translations note the exemption.

* fix(ui): keep the BOM when the skill editor saves a SKILL.md

parseSkillMarkdown dropped the BOM so the editor could see the frontmatter,
but SkillEditor writes the composed text back through PUT .../content, so every
dashboard edit silently removed the marker from a Notepad-written file. The
parse result now carries the BOM and composeSkillMarkdown puts it back in front,
matching the Go rewrite paths.
2026-10-09 23:58:56 +08:00
Willie 7febeb9007 fix(sync): keep Unicode letters and digits in the repo prefix
The prefix kept only [a-z0-9], while skill names allow lowercase letters
and digits in any script after NFKC. A repo named _技能 got no prefix
at all and _café collapsed to caf, which could collide with _caf.
Normalize the repo name the way the name validator reads it.
2026-10-09 12:24:38 +08:00
Willie 2ff8bdeb59 fix(diff): report a copy recorded under another naming as modified
Sync re-copies a managed copy whose recorded naming differs from the
current one, for example after a migration stopped between the rename
and the re-copy. Diff skipped it on the mtime fast path and reported the
target in sync while its SKILL.md kept the old name. Check the recorded
naming first in both the CLI and the dashboard diff.
2026-10-09 12:10:08 +08:00
Willie c0d2d0409a fix(sync): rewrite the prefixed name of a read-only SKILL.md
A copy keeps the source file's mode, so a read-only SKILL.md (e.g. from
a read-only checkout) could not be reopened for the name rewrite and a
non-root sync failed, dropping the skill from the target mid-migration.
Lift the write bit for the rewrite only and restore the mode afterwards.
2026-10-09 10:37:50 +08:00
Willie 0477f1e837 fix(diff): report a target naming migration as a rename
After target_naming changes, sync renames the managed entry in place,
but diff looked only under the new name, so the CLI and the dashboard
showed the skill as new while hiding the old entry. Resolve the legacy
entry and report it as a rename instead.
2026-10-09 10:29:36 +08:00
Willie f5f45e56ea refactor(sync): return the legacy entry as a namedTarget
findLegacyTargetEntry returned the old entry's name and naming as two loose strings although namedTarget already pairs them; returning the struct keeps the pair together for both callers.
2026-10-09 01:03:08 +08:00
Willie 096de1ad9b fix(sync): drop a copy whose prefixed name could not be written
When the name: rewrite failed after the copy, the new folder stayed in the
target with no manifest entry, so later syncs took it for a user's folder
and never refreshed it. The copy helper now removes the folder it just made
before returning the error; the next sync copies it again.
2026-10-09 01:02:43 +08:00
Willie e0b930cad0 refactor(sync): trim the naming migration's I/O and manifest bookkeeping
The legacy lookup stat'ed the skill's current entry before looking for old
names, adding syscalls to every flat sync; it now stats only the candidate
names other than the current one (usually none exist) and checks the
current entry only once an old managed entry is found. ReadManifest now
always returns a Naming map, Manifest.Remove drops an entry's records in
one place, copySkillToTarget takes the name to write instead of deciding
it, and diff reads the manifest only for copy targets.
2026-10-09 00:58:34 +08:00
Willie 1e00939512 fix(sync): keep naming migration from claiming another skill's entry
The legacy lookup checks a skill's flat, standard and prefixed names. With
a manifest that has no naming records yet, aaa/dev looked at "dev", found
the top-level dev skill's managed copy and synced into it, because nothing
said the entry belonged to someone else. A skill that already has its
current entry now skips the lookup, and names other skills sync to in the
same run are never treated as old names.
2026-10-09 00:53:13 +08:00
Willie 35f3bb0e28 feat(sync): add target_naming: prefixed for copy-mode targets
Two tracked repos that ship a skill with the same name cannot both reach a
tool today: standard drops both, flat keeps both folders but tools list
skills by name:. Prefixed gives a skill inside a tracked repo the folder and
name: <repo>-<name> in the copy, so both stay usable and the name shows
where the skill came from. It is copy-only because a merge symlink points
at the source, where name: must not change; config validation rejects it
elsewhere, per target, like extension does.

Switching naming used to know only the flat name as the old one, so
standard <-> prefixed would orphan entries. The migration now checks the
skill's name under every naming, and the copy manifest records the naming
that produced each entry: a switch finds the exact old entry, and a renamed
copy is re-copied so its name: matches even when the source is unchanged.
Manifests without the record fall back to flat, standard, prefixed in turn.
A rename is written to the manifest at once, so a later failure cannot
leave the renamed folder looking user-owned.
2026-10-09 00:44:47 +08:00
Willie fb43038179 test(sync): skip the uninspectable-target case on Windows
Windows reports a path under a regular file as not-exist rather than
ENOTDIR, so ClearExtraTarget correctly treats it as missing and the
test's error case cannot occur there. This failed the Windows CI job
since e5dcaa5f6.
2026-10-08 16:48:52 +08:00
Willie 18d6b11347 test: test each rule once, in the package that owns it
Many integration and handler tests re-checked rules that internal/
packages already test, duplicated each other, or ran no product code at
all (a few re-implemented the logic inline, two could never fail). They
slowed the suite without catching anything new.

Delete those, keeping tests for CLI wiring, JSON output, exit codes,
project/global mode and cmd-only logic. Move the agents/extras overlap
check into sync.AgentTargetPaths so the CLI and the server share one
implementation and it is covered by unit tests instead of seven
integration tests.
2026-10-08 16:41:09 +08:00
Willie 0127a150db fix(extras): only treat an actual link as linking to the source
ResolveLinkTarget falls back to EvalSymlinks, which also resolves a real
directory. A real directory reached through a symlinked ancestor of the
source then counted as a link to it, so --remove-target --prune failed with
"not a symlink" instead of keeping the directory. LinksTo now requires the
path itself to be a symlink or junction.

Refs #491
2026-10-08 16:33:19 +08:00
Willie e5dcaa5f64 fix(extras): keep a target in config when it cannot be inspected
ClearExtraTarget treated every Lstat failure on a symlink-mode target as
"nothing there", so a permission or I/O error made the CLI drop the target
from the config and report nothing pruned. Only a missing target is now
forgotten; other errors are returned so the config is kept for a retry.

Refs #491
2026-10-08 16:27:58 +08:00
Willie 44e8bd5927 fix(extras): recognize junctions as links to the extra's source
On Windows without Developer Mode, directory links fall back to junctions,
which os.Readlink can fail to read. LinksTo then treated a skillshare-made
target as foreign, so --remove-target --prune dropped the config entry and
left the junction behind. It now uses utils.ResolveLinkTarget, which falls
back to EvalSymlinks, and compares with utils.PathsEqual.

Refs #491
2026-10-08 16:22:02 +08:00
Willie 36113be45e fix(extras): prune a symlink target only when it links to the source
The CLI's `--remove-target --prune` removed a symlink-mode target no matter
where it pointed, while the dashboard removed it only when it still linked
to the extra's source folder. A user who repointed that link at their own
folder could lose it from the CLI. Both now go through one shared
sync.ClearExtraTarget, so the safer rule applies everywhere; the CLI warns
and leaves anything that is not a link to the source instead of failing.

Refs #491
2026-10-08 16:19:32 +08:00
Willie b90bf2086f Merge pull request #493 from runkids/runkids/extras-sync-api
refactor(extras): pass targets to sync and filter them in one discovery function
2026-10-08 16:17:22 +08:00
Willie d61b25bcf2 refactor(extras): apply target filters in one discovery function
The extras diff, list, status and remove-target commands and the
server's list and diff handlers each discovered an extra's source and
then filtered it with ExtraTargetFiles. A new view that forgot the
filter step would silently show the wrong file count or status.

DiscoverExtraTargetFiles now discovers and filters in one call and
returns the unmatched-include warnings that sync reports. Every caller,
including sync itself, uses it, and ExtraTargetFiles is gone. No
behavior change.

Refs #487
2026-10-08 16:08:03 +08:00
Willie 7a4103b9a8 refactor(extras): validate every mode change and share special extra names
cmdExtrasMode only ran ValidateExtraConfig behind a growing list of
conditions, so each new restriction needed another clause. For a plain
folder extra the full check adds only the mode-name and flatten+symlink
rules, which sync already rejects, so validating unconditionally cannot
refuse a config that syncs today.

The agents and memory extra names were string literals in sync, the
server handlers, the memory store, and the CLI. They now live in
internal/config, and the rename guard moves to ValidateExtraRename so a
future CLI rename reuses it instead of copying the check.

Refs #489
2026-10-08 16:08:03 +08:00
Willie 5c50cc4b2b refactor(sync): pass extra targets instead of long argument lists
syncExtraDir took ten positional arguments, three of them bools, and
CollectExtraFiles took nine. Every new target field meant changing each
signature and every call site, and swapped bools compiled silently.

Both now take the target as config.ExtraTargetConfig plus an
ExtraSyncOptions for dry run, force and project root; SyncExtraTarget
takes the same options. The SyncExtra wrapper only served tests, so it
is gone and the tests call syncExtraDir directly. No behavior change.

Refs #486
2026-10-08 16:08:03 +08:00
Willie 7740ee8798 fix(extras): relink symlinks to a missing source and accept negated includes
- Pointing a symlink-mode extra at a new source after its old folder was
  moved or deleted left the target broken: the old link no longer resolved,
  so it was not recognised as ours, and the next sync skipped it as pointing
  elsewhere. The link text is now compared with the old source as well.
- A negated include such as "!draft.md" only narrows earlier rules, so on
  its own it never matches and was always reported as matching no file.
  Negations are no longer checked for matches.

Refs #435
2026-10-08 15:52:47 +08:00
Willie a9ae5349a2 feat(extras): choose which files each target syncs, and edit targets in place
A directory extra used to sync every file to every target, so a tool that
only wanted a few docs got the whole folder. Each target can now set
gitignore-style include/exclude patterns, matched on the path inside the
source. Merge targets prune links to files that stop matching; copy targets
keep earlier copies, since nothing records which copied files are ours.
Filters are rejected for symlink mode and single-file extras, and sync warns
when an include matches nothing.

The dashboard previously forced users to delete and re-add a target or an
extra to change it. Edit target now changes the folder, file name, mode,
flatten and filters with a live preview; Edit extra renames an extra or
points it at another source folder. A moved target or source drops the
links left at the old place and syncs right away.

CLI: --include/--exclude on extras init, and --add-include, --add-exclude,
--remove-include, --remove-exclude on extras <name>.

Refs #435
2026-10-08 15:31:51 +08:00
Willie 81e0824396 fix(sync): skip unmatched include notices when the source is incomplete
When a followed source link cannot be read, the skill list is partial and
pruning is already skipped. Reporting a filter as unmatched in that state
told users the target gets no skills and sent them to edit a filter that
may be fine.
2026-10-08 14:59:59 +08:00
Willie 47be5105f5 fix(sync): link each target's unmatched filter and ignore blank includes
Two global targets with the same unmatched filter were merged into one
notice whose Edit filter link opened only the first target, leaving the
other unfixed. Only a project's targets share a filter, so other targets
now keep their own notice and link.

A target whose includes were an unmatched pattern plus a blank entry was
not marked as getting no skills, because the check counted the raw list
while filtering drops blanks. It now counts the effective patterns.
2026-10-08 14:48:29 +08:00
Willie 5d5b0f3efb feat(sync): explain include filters that select no skill
The dashboard showed the CLI's raw line, "api-server@claude: include pattern
"*review*" matches no skill in the source", once per target. It named a
config field, did not say the target ends up with no skills, and gave no way
to fix it. Sync now returns these as structured entries; the Sync page
groups a project's targets into one localized notice that says what happens
and links to where the filter is edited. The CLI line also says the filter
adds nothing to the target.
2026-10-08 14:26:41 +08:00
Willie c9b649143d refactor: return slash repo paths and simplify --into repo lookup
GetTrackedRepos returned OS-native paths, so every caller that compared
them with slash paths (RepoRelPath, dashboard repoPath, metadata keys)
had to convert first. Two callers in install_queries already did, and
this branch added four more. It now returns slash paths on every OS,
matching GetMissingTrackedRepos; filepath.Join and filepath.Base accept
them on Windows, and `update org/_repo` now also matches by full path
there. The per-call-site conversions are gone.

Smaller cleanups in the same code:
- repoOf takes the slash relPath and looks up prefixes by substring, so
  the walk no longer splits and joins per directory;
- repo .skillignore matchers are keyed by the same slash rel path, so
  isSkillIgnored no longer needs walkRoot;
- batch uninstall uses utils.IsTrackedRepoDir instead of a literal "_";
- the dashboard uses repoOf where it spelled out isInRepo && folderOf;
- the new tests reuse postBatchUninstall and share one --into sandbox.
2026-10-07 21:35:05 +08:00
Willie 4dd62d4ce5 fix: treat tracked repos installed with --into as repos
`install --track --into org` clones to org/_repo, but skill discovery
only marked a skill as in-repo when the first path segment started with
"_". Everything downstream also assumed the repo name was that first
segment. Skills of such a repo were therefore treated as loose skills:
no source in the dashboard, not grouped under the repo, a skill count of
0 in `status`, and an install hint that pointed at the wrong name.

Discovery now records each skill's tracked repo root (RepoRelPath). A
first-segment "_" folder still counts as before; a deeper one counts
only when the walk saw it as a git clone, so a plain org/_drafts folder
stays a folder. The repo's .skillignore is looked up by the same root.

Consumers move from "first segment" to that root:
- the API exposes it as repoPath, and the dashboard groups, updates and
  uninstalls repos by it;
- `list` and `status` use it for repo names and counts;
- batch uninstall accepts a nested repo name, so the dashboard can still
  remove an --into repo now that its skills are in-repo;
- repo names sent to the dashboard by check and update-all use slash
  paths, so they match repoPath on Windows too;
- the install hint suggests `skillshare update org/_repo`.

Fixes #470
2026-10-07 21:23:26 +08:00
Willie 920b18510a fix(doctor): count only folders with SKILL.md as hand-kept skills
An empty or cache folder in claude's skills folder was reported as a
skill OpenCode loads, and any same-named path in OpenCode's folder hid
a real one. OpenCode loads only folders with SKILL.md, so check for it
on both sides.

Refs #458
2026-10-07 13:07:25 +08:00
Willie 3ec60a3732 fix(doctor): count skills kept by hand in another target's folder
The leak check compared only source skills, so a skill the user keeps
in ~/.claude/skills (which merge mode preserves) passed as harmless,
although OpenCode loads it. Read the writer's folder too and count
entries sync did not put there and OpenCode's own folder lacks.

The wording no longer says these skills are left out by filters, and
the suggestion asks to sync them to opencode, which fits both causes.

Refs #458
2026-10-07 12:58:22 +08:00
Willie 20807579a1 refactor(doctor): keep OpenCode's one-skill-per-name fact in targets.yaml
The rule that OpenCode loads one skill per name lived in a Go map
while its other facts (also_scans, disabled_by_env) live in
targets.yaml. Move it there as one_skill_per_name so a newly verified
runtime needs only a data change.

Also fold doctor's two cross-target warning branches into one, so the
leak and generic messages cannot drift apart, and reuse cmp.Or for the
symlink-mode check.

Refs #458
2026-10-07 11:46:19 +08:00
Willie 03cde2b098 fix(doctor): keep the overlap warning for symlink-mode writers
A symlink-mode target folder is the source itself, so it also exposes
skills that .skillignore hides. Doctor, sync, and the dashboard pass
discovery results without those skills, so a symlink-mode claude
target looked harmless to OpenCode even when OpenCode loaded an
ignored skill through it. Treat that pairing as unknown and keep the
previous warning, unless OpenCode links the source as well.

Refs #458
2026-10-07 11:16:30 +08:00
Willie 834f88efb9 fix(doctor): compare resolved skills when judging OpenCode overlap
OpenCode loads skill files concurrently, so which copy of a name wins
is not fixed; its own folder does not reliably win. A source skill
synced to both folders is harmless anyway because both copies have
the same content. Count only source skills in OpenCode's folder, so a
local skill there no longer marks a same-named skill from another
folder as already present.

The comparison used each target's filtered selection, which skips the
target_naming: standard validation and collision handling sync applies.
When two skills named dev collide in OpenCode's standard folder, sync
writes neither there, yet a claude target filtered to one of them
still delivered it to OpenCode and no warning appeared. Use the
resolved skills that sync writes instead.

Refs #458
2026-10-07 11:10:30 +08:00
Willie d055f9c22a fix(doctor): warn about OpenCode overlap only when skills leak
OpenCode reads .claude/skills and .agents/skills first and its own
skills folder last, keeping the last skill of each name. A skill synced
to both opencode and claude therefore loads once, yet doctor and the
sync summary warned on every setup with both targets, with no way to
silence it.

The real effect is different: skills kept out of opencode by targets:
or include/exclude still reach it through another target's folder.
For opencode, count only those skills, name them in doctor, and point
at OpenCode's OPENCODE_DISABLE_CLAUDE_CODE_SKILLS and
OPENCODE_DISABLE_EXTERNAL_SKILLS. Other runtimes keep the old check
until their rule for same-named skills is verified.

Refs #458
2026-10-07 11:00:05 +08:00
Willie ede7f29aea fix(extras): read written blocks back and keep user lines in block-created files
Two gaps found by the fifth Codex review of #451:

- A source line that reads as a block marker, such as an unfenced
  end marker, was copied into the body, so the freshly written target
  parsed as damaged and every later sync, collect and detach failed.
  The block is now parsed back before writing, and a source whose block
  would not read back as itself is refused.
- When a block had created the target and the user then added lines
  outside it, switching to symlink or copy kept the "created" record,
  so restoring the link later removed the file and the user's lines
  with it. Those lines are now recorded as the restore point.

Refs #436
2026-10-07 00:43:13 +08:00
Willie 15dc6f47e3 fix(extras): guard block targets against source links, open fences and sibling reordering
Four gaps found by the fourth Codex review of #451:

- The check that refuses a target linked to another extra's source ran
  for import only, so a prepend or append target linked that way had
  its block written straight into that source. It now runs for every
  mode that edits the target in place.
- Switching a target with a damaged block to symlink or copy recorded
  the damaged block as the user's restore point, so detaching later
  brought it back. Recording the restore point now fails on a damaged
  block.
- Appending to a file that ends inside an open code fence put the begin
  marker inside that fence, so the next sync missed the block and
  appended another. Such an append is refused. Separately, a block body
  with an unclosed fence now ends at the end marker whose body matches
  the block's hash, even when the user's own code follows.
- A second prepend block counted its sibling above it as misplacing it,
  so each sync moved one ahead of the other. Placement now ignores other
  managed blocks on the same side.

Refs #436
2026-10-07 00:37:40 +08:00
Willie 876e165f25 fix(extras): refuse damaged blocks and plan block defaults without the leaving files
Five gaps found by the third Codex review of #451:

- Switching a target with a damaged block (a deleted end marker) to
  import ignored the parse error and added the @ line, so the tool read
  the stale block as well. The switch now fails until the block is
  repaired.
- Detaching such a target reported success without touching the file,
  so Assign dropped the connection and left the block with nothing
  configured to remove it. Detach now returns the error.
- PlanAssign decided whether a non-import target could take several
  files, and Assign chose each new file's mode, from the extras before
  the files being detached were gone. Removing the only block holder
  while adding two files therefore passed the plan, then gave both new
  files a link, the second replacing the first. The plan now detaches
  first and Assign applies the modes the plan validated.
- When the last block left a file it had created but the user had since
  added lines to, the created record stayed, so a later link attach and
  restore deleted the user's file. The attach record is cleared once no
  managed block or import line remains.
- A source with a fence that never closes swallowed the block's own end
  marker on the next parse, so a freshly written target read as
  damaged. An open block's end marker now ends it when the fence never
  closes.

Refs #436
2026-10-07 00:30:34 +08:00
Willie c88b7ff341 fix(extras): drop the old representation when a target enters or leaves a block mode
The mode picker stores the new mode before syncing, so the block and
import handlers saw the previous mode's output as the user's content:
copy → prepend kept the whole copied source beside the new block,
import → prepend kept the @ line, and prepend → import kept the block.
The tool then read the instructions twice, and detaching removed only
the new representation.

Entering a block mode now rebuilds a leftover copy from the attach-time
base (backing up an edited copy as a mode-switch drift, as import does)
and drops this extra's @ line; entering import mode drops this extra's
block, keeping a hand-edited one as a drift backup.

Refs #436
2026-10-07 00:21:01 +08:00
Willie 899b52a78e fix(extras): keep block edits and placement straight across mode changes
Four gaps in the managed-block modes, found by Codex review of #451:

- Switching a block target to symlink or copy recorded the restore point
  from the file as it stood, block included, so restoring the target
  later brought back instructions the user had removed. The restore
  point now strips this extra's block, as it already stripped its
  import line.
- Detaching a target whose block had been edited by hand dropped the
  edit outright. The edited file is now kept as a drift backup first,
  as an edited copy or link is.
- Fences were only tracked outside a block, so a source that quoted a
  marker in a fenced example produced a target that read as damaged on
  the next sync. Fences are tracked inside the block body too.
- Changing a synced target between prepend and append left the block
  where the old mode had put it, since body and hash still matched. A
  block in the other mode's place is moved.

Refs #436
2026-10-07 00:13:50 +08:00