Commit Graph
5 Commits
Author SHA1 Message Date
ggbdpq 3993853079 library: an empty GitHub answer is said so, and latestRTK says a cut one (#3045)
Rebase of this issue's patch onto current main, narrowed to what main
still misses: 33ccc6188 (#2794) took ye4241's patch and gave apiGet its
read error ("couldn't read GitHub's answer") and its over-cap error, so
the read-error half of ours is dropped here. What is left of ours:

- apiGet refuses a 200 whose body is empty ("GitHub answered nothing"):
  without it an empty answer under cacheBody is kept for a 304, and
  every later ask of the same URL is answered nothing forever.
- latestRTK read its answer with `body, _ :=`, so a cut-off one came
  back as a parse failure or "no version in"; it now says the read
  broke, and its cut-short test rides along.

Run: TestAPIGetEmptyAnswer fails without the empty-body check and
TestLatestRTKCutAnswer fails without the latestRTK wrap, both pass with
them; the whole internal/library package passes; gofmt/vet/builds clean.

Generated-by: GLM-5.3-Flash (ZCode)
2026-11-01 16:43:21 +08:00
yetoneandye4241 33ccc61884 library: one market skill from a huge repository installs alone; GitHub's file list is never cut (#2794)
Adding clean-code from sickn33/agentic-awesome-skills in the market
failed with "GitHub's list of sickn33/agentic-awesome-skills's files
wasn't understood: unexpected end of JSON input" (CaiusLuo; stablyai/
orca the same, ye4241). The repository's download is over 200 MB, so
its skills are fetched file by file from GitHub's list of its files
(#1941), and that list is 11.3 MB: apiGet cut every answer at 8 MB and
dropped the read's error, so JSON was handed a cut-off body.

From ye4241's patch on the issue (made on 75e769a9, applied as is):
apiGet takes the most its caller reads and reads one byte past it; a
200 over it is an error naming the cap, a read that breaks is a read
error, a rate limit is told from the status and headers before either,
and only answers up to 8 MB are kept for a 304. The file list's cap is
64 MB (maxTree), lastCommit keeps 8 MB.

That alone wasn't enough for the reporter's case: the 8,589 skills of
that repository come to 287 MB together, over maxFetch, so the install
would then fail as "too big to install". On top of the patch:
- fetchSkillFiles fetches only what the caller reads: the skills under
  src.Path, and for the market only the folders named as the skill it
  installs (InstallMarketSkill -> cachedProbeFor/probeSkills; such a
  probe is kept under its own key so a whole probe never takes it).
  When no folder has that name every skill under the path is fetched,
  as before.
- with a path (a link to a folder, an update, a check for new skills
  under newBase) the list asked for is that folder's own, git's
  ref:path (treeUnder; a few KB instead of 11 MB, and small enough to
  be kept for a 304). When it can't be had (404, a ref git can't read
  that way, cut off) the whole list is read, which says for sure what
  is there, so goneFrom never trusts a 404. A rate limit is said at once.
- the fetcher kept one fetch per repository and ref for every skill of
  it. A fetch narrowed to one skill's folder is now kept to that folder
  (fetcher.get): another skill of the same repository gets a fetch of
  its own, where it was read as removed upstream (broken by hand below).
- a CC Switch skill being adopted looks in the whole repository, since
  its Path is only the folder's name.
- a probe of a folder whose skills are all too big lists it empty and
  names them, as before; the whole repository's still fails.
- GitHub's own truncated list is errTooBig, by path or not
  (TestTruncatedListIsTooBig).
- apiGet's client waits 2 minutes, not 20s, for an answer over 8 MB.

docs/subsystems/library.md says how far a big repository is fetched.

Tests (no network; fake codeload, API and raw):
- TestMarketSkillFromAHugeRepository: an 11 MB list, a download over
  the limit and skills over it together. The market installs one, raw
  is asked only for its files, and UpdateSkills of two of its skills
  updates both, each asking for its own folder's list.
- TestRepoTreeBigList, TestApiGetWholeAnswer: ye4241's.
- the fake trees in skilltree_test and skillnew_test answer git's
  ref:path as GitHub does (checked against api.github.com: HEAD:skills/
  clean-code lists that folder, HEAD:nonexist is 404).

Broken by hand, each red, then restored:
- apiGet back to the 8 MB cut with the error dropped: both
  TestRepoTreeBigList and TestMarketSkillFromAHugeRepository fail with
  "unexpected end of JSON input".
- no name narrowing: "the skills in vectorize-io/hindsight are too big
  to install".
- the fetcher sharing a narrowed fetch: Gone:[hindsight-docs].
- no ref:path list: the update listed ["HEAD" "HEAD"].

Run at this tree (65ee8c65c plus this change):
- gofmt -l internal: clean
- go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go
  vet ./...: clean
- go test -count=1 -timeout 45m ./internal/library/: ok 131s
- real: a throwaway realnet test in a sandbox HOME, no GitHub token,
  InstallMarketSkill("sickn33/agentic-awesome-skills", "clean-code"):
  installed in 15s, SKILL.md 5,202 bytes, Path skills/clean-code;
  UpdateSkill then took 0.6s through its folder's list. The same test
  at origin/main 65ee8c65c: "unexpected end of JSON input".

Not tried: the full ./... suite (only internal/library changed, other
sessions' suites were running); Windows and Linux runs (vet only); the
GUI (no GUI text changed); stablyai/orca for real.

Co-authored-by: ye4241 <ye4241@users.noreply.github.com>
2026-10-27 09:31:57 +08:00
yetone 431707944e plugin, library: Check for updates asks GitHub with the GitHub token from Settings, and says when GitHub's rate limit is used up (#1942, bingqilinweimaotai)
What changed: a plugin installed from GitHub (github:owner/repo) is
checked by asking GitHub's API for its branch's commit (githubHead,
through fetchJSON). That request went without a token, so a token saved
in Settings → Network and sharing did nothing for it: the check stayed
at GitHub's 60 requests an hour for the whole address, which a shared
proxy exit uses up, and the row said only "<url>: 403 Forbidden".

- The token lookup, where a token may go and how a rate limit is told
  move from internal/library into a new internal/ghtoken, shared by the
  library and the plugin package (plugin can't import library).
  The order is unchanged: Settings, then GITHUB_TOKEN, then GH_TOKEN.
- plugin's fetchJSON has a request to GitHub's API's host (githubAPI)
  carry it, which covers the git plugins' check and the Plugins page's
  topic search. Raw files, npm and every other host never get it, and
  source.Do already sends nothing with Authorization to a mirror.
- An answer from GitHub's API that is a rate limit (429, or 403 with
  X-RateLimit-Remaining 0, Retry-After or a rate-limit message) is a
  ghtoken.Limited: the check's row has Why "limited" and Limited {until,
  token} for the page, as the library's skill check already had. A 401
  to a request with a token names which token was refused, never the
  token.

What was run:
- TestGitPluginCheckCarriesGitHubToken (new, internal/plugin): asks with
  no token / GH_TOKEN / GITHUB_TOKEN / Settings in that order of
  precedence, a 403 rate limit with and without a token, a 429 with
  Retry-After, a refused GH_TOKEN, and a raw-file host that must get no
  Authorization. Broken by hand twice: with fetchJSON's Authorize removed
  it fails "GH_TOKEN: GitHub's API was asked with Authorization "", want
  "Bearer gh-env"" (and the other two sources); with the limit check
  removed it fails with Why "registry", Limited nil, "403 Forbidden".
- go test -tags nogui -count=1 ./internal/library ./internal/plugin
  (temp HOME, pinned caches): ok, the library's TestGitHubToken*,
  TestGitHubRateLimitSaid among them.
- gofmt -l clean; go vet -tags nogui on darwin, GOOS=linux and
  GOOS=windows for internal/plugin, library, ghtoken, gui: clean.
- Not tried against the real api.github.com (tests stay off the network).
2026-10-13 15:19:53 +08:00
yetone 92469ee9f9 library, gui: a check for updates lists the skills a repository added beside the library's skills from it, to Add or Ignore (Raven on Discord)
Raven: "check for updates" only updated skills already in the library; when
dontbesilent2025/dbskill or mattpocock/skills adds a skill, magpie never said.
CheckSkills now asks GitHub's git trees API once per repo@ref (ETag-cached, a
304 is free) and only when a skill folder under the installed skills' common
folder (newBase) is neither in the library nor already offered does findNew
fetch the tarball for names and descriptions. library.json's seenSkills keeps,
per repo@ref, the paths the install picker showed and the ones set aside, so
an offered skill is offered once. The Skills page shows them under "Also in
their repositories" with Add (to the agents that have the repo's other skills)
and Ignore, plus Add all / Ignore all (/api/library/skills/{add-new,ignore-new}).

Verified: TestCheckSkillsFindsNewOnes (fake repo: nothing offered after
install, no tarball on a second check; two added skills offered, a nested one
and a .wip one not; Add installs with the repo's agents; Ignore keeps it out
on the next check via 304; remove clears) fails without the change (no
NewSkills / findNew) and passes -race -count=10; TestNewBase. A real run in a
sandbox HOME against GitHub: tdd from mattpocock/skills/skills/engineering
offered its 19 siblings; dbs from dbskill offered nothing (the picker showed
all), 33 with seenSkills wiped, and Add installed dbs-action. GUI:
skill-new-in-repo.test.cjs (Chromium+WebKit, 860/440px, en+zh) fails on
main's library.js and passes; gui-ja, gui-de, click-scroll, library-items,
every-skill, pick-skills, import/remove-all-skills, skill-groups,
skill-repo-groups, github-token, library-all pass. -race on library, gui,
tui; gofmt, vet, darwin/linux/windows builds.
2026-10-07 00:26:54 +08:00
yetone 41cbe54a14 library: which skills from GitHub have changed there can be checked — Check for updates asks GitHub for the last commit to each skill's folder (one request per folder, a repository's skills together; once GitHub limits requests the rest are left unknown, each skill's trouble its own) and a changed one carries an Update available pill whose tooltip has the commit's summary and date, a click opening the changes on GitHub; Update N fetches just those. The library keeps a hash of a skill's files as fetched and, once a check finds GitHub's files to be the same, the commit they're at, so a later check needs only the API; a skill installed before this is compared by its files, the repository fetched once 2026-09-28 13:11:25 +08:00