Commit Graph
1052 Commits
Author SHA1 Message Date
Willie a165bf7cf9 Merge branch 'main' into runkids/arch-444-check-resolution 2026-10-07 00:56:06 +08:00
Willie d3d6b57f22 Merge branch 'main' into runkids/arch-450-memory-guidance 2026-10-07 00:50:20 +08:00
Willie 279be8aba6 fix(utils): stream ParseSkillName and ParseFrontmatterField to their key
On main these two readers scanned SKILL.md line by line and returned at
the line they were looking for, keeping nothing. After the refactor they
first collected the whole frontmatter block, so a large block cost its
full size on every call even when name came first, and an unclosed one
cost the rest of the file. Sync, target naming and listing call them
once per skill or agent. Reported by Codex review on #457.

The per-line rule (which line opens and which closes the block) moves
into blockWalk, which locateFrontmatter and the new scanLenientBlock
both use, so the streaming path and the byte locator cannot drift.
ParseSkillName and ParseFrontmatterField stop at their key again; the
list and fields readers collect the block as they always did. Results
are unchanged for every entry point.

Refs #449
2026-10-07 00:34:47 +08:00
Willie 9cc4996fdd test(check): skip the fake-git auth test on Windows
TestGitRemoteHash_DefaultBranchUsesAuth puts an extensionless shell
script named git first on PATH. On Windows exec.LookPath only resolves
names with a PATHEXT extension, so the script is ignored and the real
git.exe probes github.com, which answers "repository not found" for the
made-up repository. The auth env is built without any platform branch,
so the product path is unaffected; only the test double cannot work
there. Skip it for the same reason the fake-git tests in
internal/install/source_fallback_test.go already do.

Refs #444
2026-10-07 00:26:12 +08:00
Willie 90f161fef0 perf(utils): keep only the frontmatter block when reading by path
Rebuilding the path readers on the shared locator made them read the
whole SKILL.md into memory, where they used to scan line by line and
stop at the closing delimiter. They run once per skill or agent during
sync and listing, so a large body, or a large file with no frontmatter
at all, now cost its full size on every call.

readHead goes back to a bufio.Scanner and keeps the lines from the
opening delimiter to the closing one, nothing before and nothing after.
Reading through the real Scanner also replaces the code that imitated
its quirks (64 KiB line cap, one \r dropped per line); ReadSkillBody,
which needs the body, takes them from scanLines. An unclosed block is
still kept to the end of the file, as the list and fields readers always
did.

Review follow-ups in the same files: RewriteFrontmatterList no longer
copies the content to a string and back, ParseFrontmatterField's two
loops no longer share an index, and the tests share one file helper.
Results are unchanged for every entry point.

Refs #449
2026-10-07 00:25:32 +08:00
Willie 9a34f40b6f fix(check): run a sequential resolution on the caller's goroutine
Resolution.Run started a goroutine for every remote, even without
Parallel. The dashboard handlers run sequentially and rely on net/http
recovering a panic, which it only does on the request's goroutine, so a
panic while resolving a remote would have ended the server process
instead of failing one request, as it did before the resolution moved
into internal/check.

The sequential and the parallel path are now separate loops, so the
invariant is visible instead of being spread over three Parallel checks.

Refs #444
2026-10-07 00:18:18 +08:00
Willie 2b05eccba3 refactor(memory): flatten the guidance handlers and state the module's preconditions
Review of the guidance move found no defect, but three things made the new
seam harder to read than it has to be:

- The plan and apply handlers nested the success path inside `if err == nil`
  with one shared error write. They return early again, like the handlers
  next to them.
- The handler derived the scope from IsProjectMode() while GuidanceInput
  derived the same value from ProjectRoot. Scope() is exported so the status
  response and the block inspection read one value.
- (*Server).memoryInstructions had become a one-line passthrough with a
  single caller, so it is inlined.

GuidanceReader is now exported, so its doc states what the server always
guaranteed: at least one source, and Dest indexing one of them. The
ApplyGuidance and Config comments say what callers need to know, and the
architecture paragraph is rewrapped.

No behaviour change.

Refs #450
2026-10-07 00:18:02 +08:00
Willie aeaa8337bc refactor(utils): locate frontmatter in one place under a named policy
Each reader in internal/utils found the --- delimiters with its own
loop, under four different rules that were only visible by reading all
of them, and the list reader existed twice with a path copy and a bytes
copy that had drifted apart. A fix to one reader, like the mcp serve
fixes to the strict one, did not reach the others, and nobody could say
which rule an entry point followed without tracing it.

locateFrontmatter now does the locating for every reader, and the rule
is a frontmatterPolicy value: strictBlock, lenientBlock, bodyBlock and
rewriteBlock name the rules that exist and the entry points that use
them. The rules themselves are not unified; every entry point returns
what it returned before, including the bufio.Scanner quirks of the
readers that take a path (a line of 64 KiB or more ends the content,
one \r is dropped per line), which now live in scannable. The strict
reader still walks only to the closing delimiter and copies nothing.

Two more cases found by comparing old and new code on random input are
pinned: a block scalar on the last frontmatter line, and \r\r\n endings.

Refs #449
2026-10-07 00:09:14 +08:00
Willie c23daf8ccc refactor(memory): move guidance plan and apply out of the dashboard handler
The guidance rules (status ranking, mixed_modes, multiple_blocks, the plan
token, and check -> backup -> recheck -> write) were methods on *Server, so
they could only be exercised over HTTP with a configured server, and the
recheck after backup depended on callers using the right helper.

internal/memory now owns status, plan, and apply behind GuidanceStatus,
PlanGuidance, and ApplyGuidance. The server resolves targets, assignments,
shared extras, and project reach into a GuidanceInput, syncs shared copies
through a callback after each written file, and maps results to JSON. Only
ApplyGuidance reaches the write steps, so the recheck cannot be skipped.

Note creation and guidance creation shared a copied O_EXCL create with
delete-on-failure; both now use createExclusive. Each keeps its own
behaviour: notes still chmod to 0644, guidance still creates parents.

HTTP routes, shapes, status codes, and error codes are unchanged. The raw
write allowances follow the calls to their new functions.

Refs #450
2026-10-07 00:03:50 +08:00
Willie 1bc009c668 refactor(check): resolve update status in internal/check
The CLI, GET /api/check and the check stream each wrote out the same
sequence: group skills by URL and branch, ask the remote hash, skip the
tree fetch when every skill matches, otherwise compare tree hashes and
assign a status. A fix such as branch handling had to be made three
times, and the sequence could only be tested against real repositories.

internal/check now owns it as Plan and Resolution.Run, with the remote
hash source injected and a per-remote progress callback. The CLI
progress bar and the SSE counter are adapters on that callback; the JSON
handler passes none.

The callers disagreed in two places, and both behaviours are kept: the
dashboard reports a skill removed upstream as update_available where the
CLI says stale, and gives no source or version for a skill without a
remote. The server adapter narrows the result accordingly.

Refs #444
2026-10-07 00:03:34 +08:00
Willie 1f3e61b830 test(check): pin update-status resolution for the CLI and dashboard
The CLI, GET /api/check and the check stream each carry their own copy of
the resolution sequence, and only its leaf helpers were tested. Pin what
each caller reports for every outcome, against local bare remotes, so the
copies can be merged without changing output.

Refs #444
2026-10-07 00:03:34 +08:00
Willie 8f2d4d12a7 test(utils): pin what each frontmatter entry point returns today
The readers in internal/utils locate the --- delimiters under different
rules, so the same SKILL.md can give different answers depending on the
entry point. Before they are rebuilt on one locator, these cases record
each entry point's current result on the inputs where the rules differ
(indented or late delimiters, unclosed and empty blocks, trailing
spaces, CRLF, BOM, delimiters in the body) and on a line longer than the
bufio.Scanner cap that the path readers silently stop at.

Refs #449
2026-10-06 23:59:56 +08:00
Willie 6b4c34dec4 test(sourcefs): move the download write allowances to writeDownloadedFile
The raw write ratchet listed the os calls of downloadFile,
giteaDownloadFile and cnbWriteBlob. Those now go through
writeDownloadedFile, so the list names that function instead, with the
same clone reason.
2026-10-06 22:47:31 +08:00
Willie 7a501cecfa Merge branch 'main' into runkids/fix-visible-project-schema-execbit 2026-10-06 22:36:09 +08:00
Willie 7b3d84e7b8 fix(install): keep scripts executable on content API downloads
The GitHub, Gitea and CNB content API fallbacks wrote every file as
0644, so a skill's scripts lost their exec bit whenever sparse checkout
was not available. The APIs do not report the git mode, so a file that
starts with #! is now written as 0755; anything the kernel could run
directly carries one. The mode is set on both branches, because
O_TRUNC keeps the mode of a file that already existed.

Refs #439
2026-10-06 22:34:27 +08:00
Willie b2dc1ed6c9 fix(schema): list every config key the structs accept
Both schemas reject unknown keys, but plugins, cnb_hosts and
gitea_hosts were missing from both, the global schema also lacked
extras_source and log, and skillEntry had no kind, so editors flagged
valid configs. A test now compares the yaml tags of Config and
ProjectConfig with the schema properties.

Refs #438
2026-10-06 22:34:27 +08:00
Willie 627eecd5e7 fix(dashboard): detect a visible project directory
Two handlers checked for a project's own config by statting
.skillshare/config.yaml directly, so a project created with
init -p --visible (directory skillshare/) was reported as not having
one, and the MCP page missed its override conflict. Both now ask
projectdir.Find, which the CLI already uses.

Refs #437
2026-10-06 22:34:27 +08:00
Willie 2ef704a77b fix(sync): isolate extension modules and condense diagnostics
Keep bundled CommonJS converters working inside ESM projects. Show concise sync failures with expandable original diagnostics and clarify that the last-sync card covers skills and agents only.
2026-10-06 21:36:04 +08:00
Willie a3ddb88f99 fix(mcp): rebuild the catalog when discovery changes during a build
Discovery and the package loads read the tree separately. A nested skill
created in between was published only as a file of its parent, with no
entry of its own. Discover again after the loads and rebuild, up to three
times, until both agree.
2026-10-06 17:13:44 +08:00
Willie 69f7dfa89b fix(mcp): require an unindented closing frontmatter delimiter
The closing --- was matched after trimming spaces, so an indented line,
which is YAML content, closed the frontmatter. It now has to be exactly
---, like the opening one; a CRLF ending is still fine.
2026-10-06 17:08:41 +08:00
Willie 1c7cf1259c fix(mcp): read only the file the link check saw
Files were checked with Lstat and then opened by path, so one replaced
by a link in between was followed and published. Each read now checks
that the opened file is the one Lstat described, and skips the skill
otherwise.
2026-10-06 16:59:50 +08:00
Willie 321d3beeed fix(mcp): keep a nested skill's file entries when its parent disagrees
A parent lists its nested skills' files under the same URIs and was
loaded after them, so a file changed between the two reads had the
nested skill's entry overwritten by the parent's newer digest, and reads
of it no longer matched what the nested skill advertised. The parent is
now skipped for that build and served after the next refresh.
2026-10-06 16:51:34 +08:00
Willie 699dcb86ec fix(mcp): refuse cross-origin browser requests to mcp serve --http
The Streamable HTTP handler had no cross-origin check, so a web page
could call a loopback server that runs without a token. It now uses the
SDK's CrossOriginProtection, which refuses cross-site browser requests
and leaves non-browser clients alone.
2026-10-06 16:44:57 +08:00
Willie db3840b031 fix(mcp): keep an edited serve command's -p and reject padded names
Changing the served target rebuilt the command from the dashboard scope,
so editing `skillshare mcp serve -p --target old` in the global
dashboard silently dropped -p; the command now keeps its own flag.

Skill names were trimmed before validation, so a name and directory
padded with the same spaces passed. Names are no longer trimmed, and the
spaces fail the character rule.
2026-10-06 16:36:51 +08:00
Willie 76a49ada77 fix(mcp): find the frontmatter without splitting the whole SKILL.md
Splitting the file into lines cost one string header per line, so a
16 MiB newline-heavy body allocated about 256 MiB per parse. The parser
now scans lines up to the closing --- and keeps only offsets.
2026-10-06 16:26:49 +08:00
Willie a6166ed27b fix(mcp): match a skill's name to its directory exactly
The name rules are checked after NFKC, but the directory is the skill
path's last segment, which the Skills extension requires to equal the
name. A fullwidth abc in directory abc passed and was published under
a URI that did not match its name; the comparison is now exact.
2026-10-06 16:18:03 +08:00
Willie 7980c08a2d refactor(mcp): read each skill file once in skillpkg.Load
The review fixes left the per-file size and digest split across two
packages: a stat-based budget in the walk, a second bounded read in the
catalog, a SKILL.md special case hashed once per file, and the digest
format written out three times. skillpkg.Load now reads every file once
within one package budget and records its digest and size, so the
catalog only maps them, and skillpkg.Digest is the one digest format.

Also: Build settles skills in one deepest-first loop, the skills/list
cursor uses sort.Search, ParseFrontmatterMap splits the file once, mcp
serve names each value flag once, and the migration report is not
called twice in main.
2026-10-06 16:16:25 +08:00
Willie a8edbc715f fix(mcp): follow the reference validator for names and bound SKILL.md reads
The Agent Skills reference validator accepts lowercase Unicode letters
and digits after NFKC normalization and counts the 64-character limit in
characters, so names such as 技能-審查 or café were skipped although they
are valid. ValidateName now applies the same rules. sync's target naming
shares it and accepts those names too. golang.org/x/text becomes a
direct dependency at the version already in the module graph.

SKILL.md was size-checked and then read whole, so a file that grew in
between was still read into memory; the read itself now stops past 16 MiB.
2026-10-06 15:57:02 +08:00
Willie 97844aa7f8 fix(mcp): hash SKILL.md from the bytes its frontmatter came from
SKILL.md was parsed, then read again to hash, so a save in between paired
old frontmatter with the new file's digest and size, and hosts that
compare frontmatter against the file rejected the skill. The digest now
comes from the parsed bytes; a later read of a changed file is refused
until the next refresh.
2026-10-06 15:46:48 +08:00
Willie 6285e490e6 fix(mcp): reject an empty compatibility
The Agent Skills format requires a compatibility value, when present, to
hold 1 to 500 characters, so an empty one is skipped like an overlong one.
2026-10-06 15:39:06 +08:00
Willie 4f7f2d8151 fix(mcp): continue skills/list from a URI and cap the bytes hashed
The cursor was an offset, so a catalog rebuilt between pages shifted the
next page when a skill was added or removed ahead of it, repeating or
dropping entries. Skills are now ordered by URI and the cursor is the
last URI returned.

Hashing now stops past the package's remaining size budget, so a file
that grew after the walk is skipped rather than advertised over 16 MiB
or hashed without bound.
2026-10-06 15:32:06 +08:00
Willie 2ac0926cce fix(mcp): take a file's manifest size and digest from one read
The size came from the directory walk and the digest from a later read,
so a file replaced in between was listed with an old size and a new
digest, which verifying clients reject. Both now come from the same read.
2026-10-06 15:25:33 +08:00
Willie 78857ad6f1 fix(mcp): skip a linked SKILL.md and an indented opening delimiter
The manifest lists no links, so a skill whose SKILL.md is a link was
published without its own file and could not be read. It is now skipped
with a warning.

The Agent Skills reference parser requires the file to begin with ---
exactly, so an indented delimiter no longer opens frontmatter. A CRLF
file still parses.
2026-10-06 15:16:35 +08:00
Willie b5bad20e50 fix(mcp): serve only bytes that match the listed digest
The catalog is reused for up to 5 s, so a file edited after skills/list
was read live and failed the client's digest check. A read now hashes
what it returns and reports the file as changed when the digest no
longer matches; the next refresh lists it again.

Also: a BOM-prefixed SKILL.md is parsed from the stripped bytes instead
of being skipped, a non-text compatibility is rejected rather than
treated as absent, and an oversized SKILL.md is skipped before it is
read into memory.
2026-10-06 15:09:34 +08:00
Willie d13e03adfc fix(mcp): skip skills whose compatibility exceeds the format limit
The Agent Skills format caps compatibility at 500 characters, and hosts
that validate entries reject longer ones, so serve skips such a skill
with a warning, as it does for an overlong description.

metadata is deliberately not held to the format's string values: lists
there are common, tool-fallback clients read them fine, and skipping
those skills would hide them from every client to satisfy a few.
2026-10-06 15:00:35 +08:00
Willie 64898e145b fix(mcp): keep migration notices off stdout and require closed frontmatter
The first command after an upgrade reports legacy data it moved. For
mcp serve that notice landed on stdout ahead of the handshake, so it now
goes to stderr like serve's other messages.

A SKILL.md that opens frontmatter but never closes it could still parse,
so serve published a file hosts read as having no frontmatter; it is now
skipped with a warning.
2026-10-06 14:57:49 +08:00
Willie 96593f9411 fix(mcp): quote the served target and cap skill descriptions
A managed project's name may hold spaces, so the Skillshare tab built
`--target my app@claude`, which the save path split into two words and
serve rejected as an unknown target. The command is now joined from
quoted words.

The Agent Skills format caps a description at 1,024 characters, and
hosts validating entries reject longer ones, so serve skips such a skill
with a warning instead of advertising it. The docs list every skip reason.
2026-10-06 14:47:41 +08:00
Willie fd4f499be7 fix(mcp): keep serve digests and stdout trustworthy
Size and mtime cannot prove a file is unchanged (cp -p, rsync -t), and a
stale digest makes hosts that verify digests reject the file for good,
so every rebuild hashes every file again; 1,000 skills rebuild in about
140 ms, at most once per refresh interval.

Serve errors now go to stderr: stdout is the protocol stream, and a
startup error printed there is not JSON-RPC.

SKILL.md must begin with its frontmatter, as the Agent Skills format
requires; a later --- block no longer passes.
2026-10-06 14:39:21 +08:00
Willie 0ad3ffab5a fix(mcp): address review findings on mcp serve and its dashboard tab
A root under mcp.projects is served from the global config, where its
project targets (app@claude) live, so the Skillshare tab now offers that
project's targets beside the global ones and saves no -p, which would
fail in a folder with no .skillshare/.

A nested skill skipped for any reason, not only one left unselected, now
skips its parents too: they were settled before the child was validated
and published its files as their own.

Also from review: a skill whose frontmatter JSON cannot carry (a
non-string key) is skipped instead of failing the whole skills/list page;
a listed file with a backslash in its name can be read; and stdio serve
exits 0 on SIGINT/SIGTERM without writing to stdout after the session.
2026-10-06 14:30:17 +08:00
Willie 5e02ef7ef0 refactor(sync): select a target's skills through SelectTargetSkills
Status, doctor, diff, the dashboard's target and diff handlers and analyze each
repeated FilterSkills followed by FilterSkillsByTarget, and only some dropped
disabled skills first. Routing them through SelectTargetSkills keeps their
answers identical to sync and mcp serve when a selection rule changes.

The callers that did not drop disabled skills get discoveries without them, so
their output does not change.
2026-10-06 14:18:20 +08:00
Willie cc7d802411 feat(mcp): serve skills over MCP with the SEP-2640 Skills extension
Agents on a disposable VM, in a hosted assistant or behind an MCP gateway can
reach an MCP endpoint but not the folder skills sync to, so they got tools and
none of the user's skills (#428).

`skillshare mcp serve` is a read-only server for the skills skillshare already
manages. It declares io.modelcontextprotocol/skills and implements skills/list,
skills/get and resources/read: one entry per skill, its URI from the source
path, the full frontmatter, and every file with a sha256 digest and size.
--target applies that target's selection, and the source is reread at most
every 5 seconds so install, update, enable and disable show up without a
restart; unchanged files keep their digest. stdio is the default; --http
serves Streamable HTTP and needs SKILLSHARE_MCP_TOKEN off loopback.

Skills the extension cannot carry are skipped with a warning instead of being
published incomplete: a name that breaks the Agent Skills rules or differs from
its directory, more than 512 files or 16 MiB, or a nested skill that is not
served. --check lists them without serving. The naming rules moved to
internal/skillpkg so sync and the server share them.

Few clients support the extension yet, so the server also offers list_skills
and read_skill tools. A client that declares the extension does not see them,
so it never gets each skill twice.

sync.SelectTargetSkills is the one place that turns discovered skills into a
target's selection (enabled, include/exclude, frontmatter targets).

Refs: #428
2026-10-06 14:18:16 +08:00
Willie bfbce09a12 test(windows): compare against resolved paths for 8.3 temp dirs
The windows-latest runner's TEMP is an 8.3 short path
(C:\Users\RUNNER~1\...), while the product reports the resolved long
path. Four tests compared the short form and failed only on the runner;
the local guest has no short names. Resolve the expected path first.

Refs #344
2026-10-06 10:58:15 +08:00
Willie 8b01e9f5a4 Merge branch 'main' into runkids/sync-windows-tests 2026-10-06 10:51:56 +08:00
Willie 92183d5a09 test(windows): run audit, config, install, mcp and cmd tests on Windows CI
These packages were left out of the windows-test job because of failures
that came from test assumptions (POSIX paths, permission bits, HOME,
bash shims posing as git), not product behavior. Fix them and add the
packages to the list so they stay green.

Two failures were real product bugs:
- swapStagedIntoSource named its backup like the temp that
  sourcefs.MoveIn creates beside it. On a coarse clock (Windows) both
  names matched, the failed move removed the temp and with it the
  backup, and the old skill was lost.
- MetadataStore.GetByPath looked up OS-native paths in slash-form keys,
  so `update --group` missed nested skills on Windows.

The test sandbox now also sets USERPROFILE, which os.UserHomeDir reads
on Windows; tests were reading the real profile.

Refs #344
2026-10-06 10:46:37 +08:00
Willie c0f200f7d6 Merge branch 'main' into runkids/pi-cimd-validation 2026-10-06 10:36:04 +08:00
Willie 8f79733b4f fix(mcp): validate Pi CIMD OAuth settings
Reject unsupported client registration values and CIMD client or callback conflicts before syncing invalid settings to Pi. Keep dcr and custom Pi options supported, identify the legacy codemode alias, and document current Pi launch behavior.
2026-10-06 09:52:16 +08:00
Willie 8e9ef1c806 test(sync): make the tests pass on Windows and run them in CI
Ten tests assumed POSIX behaviour:

- Five asserted os.ModeSymlink, but Windows links with a junction;
  check utils.IsLinkMode instead.
- Two used `/abs/...` as an absolute path, which has no volume on
  Windows; give the fixtures one.
- Windows has no permission bits to preserve, so the 0600 check is
  skipped there.
- Reading a file as a directory reports not-exist on Windows, which
  prune ignores, so that prune-error test is skipped there.
- A single-file extension relies on the shebang and the executable bit,
  so ListExtensions finds only directory extensions on Windows, as the
  extras docs describe.

Add ./internal/sync and ./internal/trash to the windows-test package
list so they stay green.

Refs #344
2026-10-06 09:40:50 +08:00
Willie 8f47b5962a test(trash): make the link tests pass on Windows
Three link tests assumed POSIX behaviour:

- alias/../checkout is resolved lexically on Windows, before the alias
  is followed, so the traversal case cannot hold and is skipped there.
- Windows drops `..` when it creates a relative symlink, so the expected
  link text is cleaned first.
- Windows stores `assets/note.txt` as `assets\note.txt`, so the nested
  link target is compared in slash form.

Refs #344
2026-10-06 09:40:49 +08:00
Willie e031274207 fix(utils): refuse a network path as a junction target
A junction cannot point at a UNC path; mklink /J exits 1 for one. The
reparse-point API would instead write an unusable mount point, so return
an error up front and leave nothing behind, as mklink did.

Refs #420
2026-10-06 01:28:55 +08:00
Willie 05b2f12023 fix(utils): detect junctions under GODEBUG=winsymlink=0
With winsymlink=0 Go reports a junction as ModeSymlink instead of
ModeIrregular, so IsJunction returned false and the trash fallback
recreated the junction with os.Symlink again. Read the reparse tag for
both modes.

Refs #420
2026-10-06 01:16:37 +08:00