Commit Graph
7 Commits
Author SHA1 Message Date
yetone c48fccfad7 plugin: the dist index is read from GitHub beside jsDelivr's copy, so a plugin npm doesn't have is offered its newer version
star21321321124 on Discord: CodeArts 0.2.3 showed "已自动更新", the page said
every plugin was up to date, and Update did nothing, with 0.2.4 on the
plugins repo's dist branch. npm has neither CodeArts nor River (E404), so
npmAsk's version is the dist index's latest. With the 「国内镜像」 switch on,
index.json was read from jsDelivr first, and a 200 from it was final. A
jsDelivr edge serves the branch as it was when it cached it (s-maxage=43200):
on 10-28 gcore.jsdelivr.net served the index with codearts latest 0.2.3
(age 6631s) while raw.githubusercontent.com, cdn and fastly had 0.2.4. So
the hourly update, Check for updates and Update all saw 0.2.3.

readDistIndex now asks raw.githubusercontent.com beside the mirror (with
the switch on) and merges the two copies: every version either names,
each package's newer latest. Each version keeps the sha512 its own copy of
the branch names, which installDist checks the tarball against as before.
GitHub is waited for 5s (distGrace) past the mirror's answer; unreachable,
the mirror's copy is read alone, as before. Switch off: one read, as before.

River: on dist at 0.1.0 only, nothing newer; the test holds it "current".

Run (mote, at this tree rebased on f20118304):
- go test -tags nogui ./internal/plugin ./internal/source: ok
- go build ./...; go vet (darwin, linux, windows) of both packages: ok
- gofmt -l: clean
Broken by hand: the index read mirror-first again (the old rule) turns
TestDistOnlyPluginUpdatesPastAStaleMirror red in both subtests with
"Status:current Latest:0.2.3", what the user saw. The pure no-mirror case
(npm 404, dist 0.2.3/0.2.4, 0.2.3 installed) already passed on the old code.
Not run: full suite, GUI suite.
Not tried: a real magpie with the switch on against a stale edge (tests
can't reach the network); the stale gcore edge and fresh raw copy were
checked with curl only.
2026-10-28 13:55:16 +08:00
yetone e4ccf67b11 plugin: GitHub's search gets 60s a page, and a mirror is asked without the token (#3923)
MYCF711 (#3923) measured a page of GitHub's search from mainland China:
29-36s straight to api.github.com, 3-7s through gh-proxy. The Plugins
page's GitHub list was empty there, for two reasons:

- askTagged's taggedWait (8s) bounded the search pages as well as the
  wait for the repositories' reads. The first page timed out, the ask
  failed whole, and nothing was cached. Each search page now has its own
  taggedSearch (60s). taggedWait starts after the search and bounds only
  the reads, as before. Through a mirror, candidateContext gives the
  official address half of the 60s and the mirror the rest.
- source.Do never used a mirror for a request carrying Authorization,
  and ghtoken sets it on every api.github.com request when a GitHub
  token is set. With a token in Settings, MAGPIE_MIRRORS did nothing.
  A request to a GitHub host whose only credential is Authorization
  (bare) now goes to the official address with the token and to the
  mirror without it. A cookie, a key header, a token in the query, URL
  userinfo, or any other host still keeps the request official. The
  caller's request keeps its header.
- ghtoken.Do now reads who answered from resp.Request: a mirror's answer
  to the bare request doesn't count as carrying the token, and a 401 from
  a mirror doesn't mark the token refused.

Tests:
- TestTaggedReposSlowSearch: a search answering after 3x taggedWait
  still lists; one that never answers fails at taggedSearch.
- TestDoKeepsCredentialsOfficial, rewritten to the new contract: the
  official address gets the token, the mirror gets none, and the
  caller's request is unchanged. Cookie, query token and npm still stay
  official.
- TestMirrorAnswerIsNotTheToken (ghtoken).

Run on mote:
- go test -tags nogui -count=1 ./internal/source ./internal/ghtoken
  ./internal/plugin ./internal/library: all ok.
- Broken by hand: with the old source.go, ghtoken.go and github.go, all
  three tests went red ("requests = [https://api.github.com/repos/o/r]";
  "token=true"; "context deadline exceeded" at taggedWait).
- Locally: gofmt -l clean; go vet for linux and windows on the three
  packages; go build -tags nogui ./...

Not tried:
- The real network from mainland China.
- A live gh-proxy answer to an anonymous api.github.com search.
- Not changed: the mirror for api.github.com still waits for
  MAGPIE_MIRRORS. Without it, the 60s alone covers the ~30s page.
- No GUI file was run: the page's fixtures fake /api/plugins/github, and
  nothing in the window changed.

Reported by MYCF711.
2026-10-28 03:57:51 +08:00
yetone 3a89dd53c0 pii: the masking model downloads through magpie's proxy, and from hf-mirror when huggingface.co fails (hh0592821 on Discord)
hh0592821 (China) couldn't download the local masking model: "EOF",
"x509: certificate is valid for *.facebook.com ... not huggingface.co",
"net/http: TLS handshake timeout", while the same file came through
their proxy outside magpie.

Cause: internal/pii's download client cloned http.DefaultTransport when
the package loaded, before netproxy.Install set its Proxy, so it kept
only ProxyFromEnvironment. An app started from the Dock has no
HTTPS_PROXY, so the proxy set in magpie and the system's were both
skipped, and the request went direct to a poisoned huggingface.co. Every
other client magpie builds (update, mcp_check, mcpauth, gateway/mcp)
sets t.Proxy = netproxy.Func; pii was the only one built at init without
it. And hf-mirror was asked only with the 「国内镜像」 switch on.

Fix:
- pii's client: t.Proxy = netproxy.Func, through netproxy.Dispatch,
  ResponseHeaderTimeout kept.
- source.URLs: a masking model's file (the two pinned repos' /resolve/
  paths, https, no query; modelMirror) has hf-mirror after
  huggingface.co with the switch off and no MAGPIE_MIRRORS; with the
  switch on it stays first, once. fetch still checks each file against
  its pinned sha256, so a mirror can't hand over anything else.
- docs/subsystems/gateway-routing.md says both.

Checked against the real mirror (curl, outside the tests): hf-mirror.com
serves AstrLink Guard's three files at 7216b6a3 with their pinned sizes
and sha256 (model_int8.onnx 330781 0a070d31..., model_int8.onnx_data
37124608 0ba34216..., tokenizer.json 1502881 0cf3b235...). For Privacy
Filter's gguf it answers 308 back to huggingface.co, so the mirror
helps AstrLink Guard (the default) only.

Tests, none reaching the network: TestFetchGoesThroughMagpiesProxy (proxy
set in Settings is an httptest server; a fetch of a TEST-NET-1 URL is
answered by it), TestModelFromTheMirrorWhenHuggingFaceFails (huggingface.co
failing with the reporter's certificate error, a handshake timeout and
EOF: the file comes from hf-mirror; a mirror file that isn't the pinned
one fails the checksum), TestModelMirrorWithoutTheSwitch,
TestModelFallsToTheMirror (source).

Broken by hand, each red then restored: without t.Proxy =
netproxy.Func, TestFetchGoesThroughMagpiesProxy is red (context deadline,
direct dial); with modelMirror out of URLs, the three mirror tests are
red.

Run: the full suite (go test -tags nogui -timeout 45m ./..., sandbox
HOME) at 7065e3734, this change on the zoecats commit on 11dcc743f,
while the disk was full (1 GB free, other sessions' runs and a 57 GB
shared Go cache): internal/pii 134s, internal/source and 69 more
packages ok; agent, gateway and library red only on "no space left on
device" (TempDir and file writes); provider on the synctest crash open
as #3632. Rerun at that head: internal/pii, internal/source and
internal/netproxy ok, and the gateway's 429/patience tests ok.
The previous commit's full run at its base had every package ok but
provider (#3632).
gofmt -l clean; go vet ./..., GOOS=linux go vet -tags nogui ./...,
GOOS=windows go vet ./... clean; go build for darwin, linux (nogui) and
windows ok.

Not tried: a download from China through a real poisoned DNS, or with
the reporter's proxy; ModelScope for Privacy Filter's gguf.
2026-10-27 13:20:52 +08:00
yetone 0db804999e pii: AstrLink Guard as a second local model (#3578)
pii.Model is a local model (ID, Supported, Installed, Size, Find, Now,
Download, Cancel, Warm, Stop, Remove); pii.Models lists Privacy Filter
and AstrLink Guard, pii.Of finds one by id. pii.Choose decides which
one runs: the user's pick; else Privacy Filter for a user who has it on
or downloaded, so no one's model changes under them; else AstrLink
Guard, the default for everyone who turns the model on from now on.

Why AstrLink Guard as the default. On 234 segments of real code and
config (131 KB: Go, TS, lockfiles, go.sum, CI and agent configs),
Privacy Filter found 100 spans in 26 segments, 39 after redact's checks
(38 go.sum hashes and "Zed"); AstrLink Guard found 2, 1 after the
checks. On the masking eval (42 values to mask, 113 to keep), the
model alone: Privacy Filter 40/42 and 47/113 wrongly, AstrLink Guard
38/42 and 3/113; with the rules and checks both are 41/42 and 1/113.
It is 39 MB, not 1.6 GB, runs on any CPU in magpie's process, and
needs no native helper.

Its three files come from Hugging Face at revision 7216b6a3 (v0.1.3),
each checked against the sha256 in the publisher's SHA256SUMS:
int8/model_int8.onnx 0a070d31…, int8/model_int8.onnx_data 0ba34216…,
int8/tokenizer.json 0cf3b235…; from hf-mirror first in China, as
Privacy Filter's are. It is loaded on the first request and let go
after 10 minutes with none; a failure holds requests back with the
same backoff as Privacy Filter's. Its labels are named as Privacy
Filter's, so redact's checks read both alike.

TestGuardFilesAreThePublishers holds each pinned path and sha256 to
the publisher's SHA256SUMS lines (testdata); it is red with the
tokenizer at the repo root, which is a 404 (found by a real download).

Run: go test -race -count=2 ./internal/pii ./internal/source; a real
download from huggingface.co into a sandbox HOME through
Of(Choose("", false)).Download (8.7s), then Find: 张伟, 13800138000,
zhangwei@example.cn, 北京市朝阳区建国路88号 and an sk-proj key found,
nothing in a go.sum line or "gpt-5.1-codex, go 1.26.8, README.md";
load 104 ms, three texts in 177 ms. All at the pushed head.
Not tried: a real download on Windows or Linux.
2026-10-27 02:01:16 +08:00
yetone c0dad80da1 redact, pii: a local model finds what the masking rules can't (#1977)
WIP on pf/serve, recovered after the scratchpad holding it was wiped.
internal/pii downloads OpenAI's Privacy Filter (q8 GGUF, sha256 pinned)
and pf-serve, runs it on the GPU first, and answers redact's Model;
settings.RedactModel turns it on, per computer. Off by default.

Run: go vet and go test -race on internal/redact, pii, source,
settings (all ok). Not yet released: pf-serve's serveSHA is empty
until pf-v1 is tagged.
2026-10-18 23:12:41 +08:00
yetone 860ed6618d plugins: a 「国内镜像」 switch on the Plugins page downloads the list, plugins and Bun from mirrors in China first (Discord, akic404: GitHub/npm are slow from the mainland; asked for ghproxy) — Plugins › Mirrors in China, off by default, kept in settings (chinaMirror). On, source asks a copy of the very file before its official address: npm's registry (packages, versions, search) at registry.npmmirror.com, Bun's release zips at registry.npmmirror.com/-/binary/bun, and the community registry.json at cdn.jsdelivr.net/gh/magpie-community/plugins@<branch>; bun add gets BUN_CONFIG_REGISTRY=npmmirror unless the environment names a registry. No proxy: gh-proxy (MAGPIE_MIRRORS' GitHub fallback) handles nothing the switch sends, since a proxy could hand back other code. A mirror asked first that can't answer (404/403/5xx, e.g. a version it hasn't synced) falls through to the official address; npm's weekly downloads stay api.npmjs.org's (npmmirror counts its own). Checked by hand: npmmirror's bun-v1.4.2 darwin-aarch64 zip has the SHA-256 pinned in bun.go, jsDelivr's registry.json is byte-identical to raw.githubusercontent's, and bun 1.4.2 add through npmmirror locks the same sha512 integrity npmjs gives. TestChinaFirst, TestChinaComesFirst, TestChinaMirrorAnswers, TestChinaMirrorsMissIsAskedOfficially, TestDoFaithful, TestBunInstallsFromChinaMirror and TestPluginsMirrorSwitch cover it. A live run with the switch on fetched the list from jsDelivr, npm info from npmmirror and Bun from npmmirror (checksum passed); a sandbox magpie web showed the switch in the Plugins head, saved it, kept it after a reload, and a click didn't move the page. go vet, builds (darwin, GOOS=linux, GOOS=windows) and go test -tags nogui -count=1 ./... under a temp HOME pass. Not tried from inside mainland China. 2026-10-03 15:14:45 +08:00
YAYOI27 cb82822f3d source: add opt-in China mirror fallback (#566) 2026-10-03 09:50:59 +08:00