Skip to content

page-token-widget 0.4.12: an iPhone home screen widget for your quota - #1062

Open
liuzq1103 wants to merge 23 commits into
magpie-community:mainfrom
liuzq1103:feat/page-token-widget
Open

liuzq1103 wants to merge 23 commits into
magpie-community:mainfrom
liuzq1103:feat/page-token-widget

Conversation

@liuzq1103

@liuzq1103 liuzq1103 commented Nov 13, 2026 •

Copy link
Copy Markdown

What this changes

Adds packages/page-token-widget: a page in Magpie's window that puts a quota widget on the home screen of an iPhone.

The window shows a QR code. The camera of the phone opens the pairing page in Safari. That page hands over one file, the widget script, and it carries the one-time code: Scriptable opens it once, it swaps the code for a read-only token of its own, keeps that token in its keychain, and the widget is then added to the home screen. The widget shows the remaining quota of every subscription, the percentage and the reset countdown of the 5-hour and the weekly window, today's tokens, the last seven days and the ranking per provider. The plugin page picks which subscriptions the medium and the large widget show -- and in which order -- and shows the state of Tailscale and the iPhones in the same tailnet.

Tapping the widget opens the page of the phone in Safari: the same numbers, written for a narrow screen. The page carries no token of its own -- the phone brings its own in the address and the page drops it as soon as it has read it. The page keeps it on the phone for a month, and a "断开" button on it wipes that.

The plugin runs the service itself: no install script, no Node.js, no scheduled task, no manual port forwarding. It finds the tailnet address through Tailscale and publishes the port with a tailscale serve --tcp forwarding of its own.

How it is put together:

  • page/ holds a launcher only. The page is in a sandbox frame whose CSP is connect-src 'none', so it cannot fetch anything; it navigates its frame to the local service and the service answers with the console.
  • The host part (index.mjs) starts the service on 127.0.0.1. It listens first and asks Tailscale afterwards, because the host is only given a few seconds to come up.
  • The service reads the local quota API of Magpie (127.0.0.1:3425) and writes nothing in the configuration of Magpie.
  • The phone pairs with a one-time code. The widget script on the pairing page carries that code; the first time Scriptable runs it, it exchanges the code for a token of its own and keeps it in the keychain. To pair without the camera, run scriptable/SetupUsageWidget.js in Scriptable with the address and the read-only token that the plugin page shows.
  • The service knows two rooms instead of one. The console listens on 127.0.0.1:<port> and the phone side on 127.0.0.1:<phonePort>; the forwarding of Tailscale points at the phone side, so a request that comes in through the tailnet is never taken for a request of this computer. The Host header decides nothing: a device in the tailnet cannot read the console or the token whatever it puts in it. Every console route answers 403 on the phone side; the page of the phone and the API of the phone (/api/v1/overview, /api/v1/session, /scriptable/*) answer there instead.

The security gap that was pointed out

The review above asked that "local" be decided by the socket and not by the Host header, and that the tailnet listener refuse a forged Host: 127.0.0.1:<port>. That is how the code of this branch reads now:

  • Every listener is built with one scope, and the scope is the only thing that says what a request may do. The console listener has the scope console; the listener of the tailnet, the door of the LAN and the phone listener have the scope phone (lib/server.mjs).
  • The console routes answer 403 before anything is dispatched, unless the request came in on the console listener; the page that carries the token of the service is served by the console listener and by nothing else.
  • allowedHosts and the origin check are a second guard, not the first one. X-Forwarded-Proto and X-Forwarded-Host are never read.
  • The forwarding of Tailscale points at the port of the phone side, and the console stays on this computer.

Four tests in test/boundary.test.mjs keep that line: the forged Host on the tailnet listener gets the page of the phone (and never the token), the console routes answer 403 there, the console answers only with its own token, the phone still pairs over the tailnet, and the door of the LAN opens the phone side only.

Registry text (verbatim)

{ "package": "@magpie-community/page-token-widget", "name": "iPhone Quota Widget", "kind": "page", "community": true,
  "summary": { "en": "A quota widget on the home screen of your iPhone: scan one code and the widget shows the remaining quota, the reset countdown and the real token usage of Codex, MiniMax and GLM. Unlike the usage pages listed above, the numbers land on another device, and the quota stays the quota window of the subscription rather than a per-model split of tokens; the phone reaches the local service over your Tailscale tailnet.", "zh": "把额度组件放到 iPhone 桌面:扫一次码,组件显示 Codex、MiniMax、GLM 各家套餐的剩余额度、重置倒计时和真实 Token 用量。和上面那些用量页面不同,数字落在另一台设备上;额度保持订阅本身的额度窗口,而不是按模型摊开的 token;手机通过 Tailscale 尾网连进本机服务。" } },

Difference declaration: the registry entry, magpie.summary in package.json and this description carry the same text. test/page.test.mjs says so out loud: the entry of the registry must be the same text as magpie.summary.

The listed usage pages answer on the machine that runs Magpie. This one answers on another device: the home screen of an iPhone, over the tailnet of the user, with the quota window of the subscription itself rather than a per-model split of tokens.

This update

The code of the standalone plugin (0.4.6) comes in, so that the community plugin and the standalone one do not drift apart: the console is a rail and a sheet, the devices can be renamed, revoked and taken off the list for good, the look of the widget is chosen in the plugin window instead of in a Scriptable parameter, the phone keeps its token for a month, the reading of another day is never shown as today's, and the bars of the cards of the widget sit on one line, the unit of a quota window is written the same way for every provider, and the name of a card stands at the left of its card again.

The bars of the cards of the widget sit on one line: a card without an account of its own (MiniMax, GLM) used to keep a space on the line of the account, and the phone measured that space by itself, so its bar sat 11 points higher than the bar of the two cards of Codex. Every line of a card has a height of its own now, and a test reads the line of every bar to keep it that way -- in the medium widget and in the large one, where a row can hold a card with an account and a card without one.

The unit of a quota window is written the same way for every provider: the gateway names one window "5 hours" and another one "4 hours", and the widget wrote "5h" for the first and "4 hours" for the second. Every hour-ish window is now written "h" and every day-ish one "d"; the phone page writes the same window as "5 小时剩余" and "4 小时剩余". The name of a card and the number under it stand at the left of the card again.

The shape of the community is kept: the name @magpie-community/page-token-widget, the port 3498, the data directory page-token-widget, the registry entry that says the same as magpie.summary, and the entry of the plugin exports the plugin and nothing else (the cleanup of the forwarding moved to lib/cleanup.mjs, because the checker of this repository calls every function a package exports).

The version of this package is the version of the standalone plugin (0.4.6), so that the two never drift apart in the eyes of a user.

Testing

  • bun scripts/check.mjs -- every package of the repository passes, the new one included (exit 0, every package ✓).
  • node scripts/run-tests.mjs in packages/page-token-widget -- 184 pass, 1 skipped (a file right on Windows), 0 fail.
  • bun test in packages/page-token-widget -- 184 pass, 1 skip, 0 fail.
  • On a real Magpie (0.1.3681) the page of the plugin opens in the window and draws the console: the QR code, the tailnet address, the subscriptions and the state of Tailscale.
  • The same service answers on the tailnet address, and the phone of the tailnet fetches the widget script with the one-time code.
  • The root of the phone side answers with the page of the phone (200); every console route answers 403 there, with a Host header of 127.0.0.1:<port> and without one. The page of the phone carries no token of the service.

liuzq1103 and others added 2 commits November 13, 2026 09:03
The usage pages that are listed read what magpie already knows and show it
in the window. This one puts the same numbers on another device: the
iPhone shows the remaining quota of Codex, MiniMax and GLM, the reset
countdown and the real token usage on its home screen.

The page in the window is a launcher. It carries no data and reads
nothing: the plugin's host part starts a local service, and the page
navigates its own frame to it. The service reads magpie's local quota
API, holds the phone's read-only token, and publishes its port in the
Tailscale tailnet, so the phone reaches it over the reader's own
network and never over the public internet. The pairing code is worth
one try and then it is spent.

The service answers only to a Host it knows and to a token, and the
console page that holds the token may only be opened by hand, never
fetched from another page.

How it differs from the pages that are listed: usage, page-usage-tree,
page-usage-board and page-model-quota all answer on the machine that
runs magpie, in the window. This one answers on the phone, over the
reader's tailnet, and its numbers are the quota windows of the
subscriptions themselves rather than a model-by-model split of them.

Reviewed at 753a61f. Run (on this machine, Windows, temp HOME):
bun scripts/check.mjs page-token-widget ok; bun scripts/check.mjs all
packages ok; packages/page-token-widget bun test 16 pass 0 fail.
Not tried: an iPhone, and a tailnet other than the reader's own.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…the summary and in Chinese

The summary in registry.json and the Chinese part of the README now say what the
new entry does that the listed usage pages can't: the numbers land on another
device, and the quota stays the quota window of the subscription.
@yetone

yetone commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

Harm scan at 1f6c0af: nothing hostile. The vendored qrcode-generator is npm's 1.4.4 with one change (row/col in renderTo2dContext's fillRect). The plugin talks to the local gateway and to tailscale only.

One security gap to fix before merge: local in lib/server.mjs (line 304) is decided by the Host header, not by where the connection came from. The server also listens on the tailnet IP (line 494), and allowedHosts accepts 127.0.0.1/localhost there. So any device in the tailnet can do

curl -H 'Host: 127.0.0.1:3498' http://<tailnet-ip>:3498/

and get ui/index.html with __SERVICE_TOKEN__ filled in (no Sec-Fetch-Mode from curl, so the navigate check passes), and reach /api/v1/console/state, /console/pair and /console/options. The same holds through the tailscale serve --tcp forward, whose connections arrive from 127.0.0.1 too. A shared-in node or anyone the tailnet ACL lets in reads every subscription's quota and changes the plugin's settings.

Decide "local" by the socket: the 127.0.0.1 listener's requests are local, the tailnet listener's never are, whatever their Host says. Two listeners already exist, so a flag per listener is enough. A test: a request on the tailnet listener with Host: 127.0.0.1:<port> gets 403 on / and the console routes.

Also worth saying in the README: tailscale serve --bg --tcp=3498 is a standing Tailscale setting that outlives the plugin until it is removed.

liuzq1103 and others added 5 commits November 13, 2026 14:14
The console page and its API decide "is this request from this computer"
by the Host header, so a device in the tailnet could send
"Host: 127.0.0.1:3498" and read the console, which carries the token
that lets it read every subscription's quota, and could change the
settings of the plugin.

The service now listens on two sockets: the console on 127.0.0.1:3498,
the phone side on 127.0.0.1:3499. The tailnet reaches the phone side
through "tailscale serve --bg --tcp=3498 tcp://127.0.0.1:3499", so the
port in the tailnet stays 3498 and the widget, the pairing code and the
qr code do not change. Every console route answers 403 on the phone
side, whatever Host says.
Tapping the widget on the home screen asked the service for the root of the
phone, and the root of the phone was the console of the computer. The console
is only opened on the loopback address, so the phone was told that this page
is only opened on the computer of the service.

The service now has two rooms. The console keeps the console and its API; the
phone side answers with the page of the phone, which shows the same numbers.
That page carries no token: the phone brings its own in the address and the
page drops it as soon as it has read it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The standalone plugin has moved on since this package was opened: the
console is a rail and a sheet, the devices can be taken off the list, the
widget is set up on the plugin side instead of in a Scriptable parameter,
and the phone keeps its token for a month.

The security question that was raised on the pull request is answered by
the code that is here now: who may do what is decided by the listener
that took the connection, not by a header a client can write. The console
listens on 127.0.0.1 only, the phone side answers the phone and nothing
else, and a forged Host on the tailnet gets the page of the phone.

Four tests in test/boundary.test.mjs keep that line: the forged Host, the
access across the listeners, the console routes from the wrong side, the
token that does not leak, and the pairing that still works.

The package keeps the shape of the community: the name
@magpie-community/page-token-widget, the port 3498, the data directory
page-token-widget, the registry entry that says the same as magpie.summary,
and the entry of the plugin exports the plugin and nothing else.

Co-Authored-By: Claude Code <noreply@anthropic.com>
The uninstall section pointed at the wrong command: a forwarding of
Tailscale that outlives a killed plugin is removed with
`tailscale serve --tcp=3498 off`, not with the removal of the plugin.

Co-Authored-By: Claude Code <noreply@anthropic.com>
@liuzq1103 liuzq1103 changed the title page-token-widget 0.1.0: an iPhone home screen widget for your quota page-token-widget 0.2.0: an iPhone home screen widget for your quota Nov 14, 2026
@liuzq1103

Copy link
Copy Markdown
Author

Thank you — that was the right thing to point at, and the branch now answers it.

"Local" is decided by the socket. Every listener is built with one scope, and the scope is the only thing that says what a request may do:

  • the console listener (127.0.0.1:<port>) has the scope console;
  • the phone listener, the door of the LAN and the listener of the tailnet have the scope phone.

lib/server.mjs — makeServer(scope) hands the scope to every request it takes. The console routes answer 403 before anything is dispatched, unless the request came in on the console listener:

if (!consoleScope) return json(response, 403, { error: 'This page is only opened on the computer of the service.' });

The page that carries __SERVICE_TOKEN__ is served by the console listener and by nothing else; on the phone side the root answers with the page of the phone (mobile/index.html), and ui/app.js, ui/timing.mjs and ui/style.css are console-only.

allowedHosts and the origin check are a second guard now, not the first one, and X-Forwarded-Proto / X-Forwarded-Host are never read.

A forged Host on the tailnet gets the phone side. curl -H 'Host: 127.0.0.1:3498' http://<tailnet-ip>:3498/ lands on the listener of the tailnet, which is the phone side: it answers with the page of the phone, the console routes answer 403, and nothing on that side carries the token of the service. The forwarding of Tailscale points at the port of the phone side, so a request through the forward lands there too.

The tests are in test/boundary.test.mjs:

  • a request on the tailnet listener is a request of the phone, whatever its Host says — the listener is bound to a local address for the test (options.tailnetAddress), the forged Host: 127.0.0.1:<port> gets the phone page (no token in it), and the console routes answer 403;
  • the console of this computer answers only with its own token — 403 without it, 200 with it;
  • a phone still pairs over the tailnet — the pairing and the numbers still work there;
  • the door of the own network opens the phone side only.

The tailnet listener used to be the tailnet address of the machine, which made the test machine-dependent; the tests now ask the mock for the status of a tailnet, so they say the same thing on every computer.

The tailscale serve --bg --tcp=3498 note is in the README now, in Uninstall: the forwarding of Tailscale is a setting of Tailscale that outlives the plugin, it is taken away when the plugin is stopped or removed (and only when it still points where the plugin left it), and a plugin that was killed cannot clean up after itself — then it is removed by hand with tailscale serve --tcp=3498 off.

@liuzq1103 liuzq1103 changed the title page-token-widget 0.2.0: an iPhone home screen widget for your quota page-token-widget 0.4.4: an iPhone home screen widget for your quota Nov 14, 2026
Nobody has installed this package yet, so the two version lines can be
made one before they are read by anybody: from here on this package
carries the version of the standalone plugin (0.4.4), so that a user who
sees a number in one place sees the same number in the other.

The name, the port (3498) and the data directory (page-token-widget) stay
the community's own.

Co-Authored-By: Claude Code <noreply@anthropic.com>
@yetone

yetone commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

Checked at 0ad2127: the fix holds.

  • makeServer(scope): console routes and the token page answer only on the 127.0.0.1 console listener. The tailnet and LAN listeners are phone, whatever their Host says.
  • node --test test/*.test.mjs on Linux (Ubuntu 24.04, Node 22): 180 pass, 0 fail.
  • Broken by hand (consoleScope = true): boundary.test.mjs goes red on "a request on the tailnet listener is a request of the phone" and "the door of the own network opens the phone side only". So the test guards the fix.

This PR adds a new package with a registry row, a vendored library and a standing tailscale serve setting. Those wait for the maintainer's own look before a merge, so it stays open until then. Nothing else is needed from you right now.

liuzq1103 and others added 2 commits November 14, 2026 20:09
The empty line of the account was a space whose height the phone measured by
itself, so the cards of a vendor without an account put their bar a little
higher than the cards next to them. Every line of a card has a height of its
own now, and a test reads the line of every bar to keep it that way.

Co-Authored-By: Claude Code <noreply@anthropic.com>
A row of the large widget can hold a card with an account and a card without
one; the card without one had no line of the account, so its bar sat 11
points lower. Every card of a row gets the same lines now, and the dense
layout of the large widget keeps the line of the name the same height for
every card.

Co-Authored-By: Claude Code <noreply@anthropic.com>
@liuzq1103 liuzq1103 changed the title page-token-widget 0.4.4: an iPhone home screen widget for your quota page-token-widget 0.4.5: an iPhone home screen widget for your quota Nov 14, 2026
The gateway names one window "5 hours" and another one "4 hours", and the
widget wrote "5h" for the first and "4 hours" for the second. Every
hour-ish window is now written "<n>h" and every day-ish one "<n>d"; the
phone page writes the same window as "5 小时剩余" and "4 小时剩余". The name
of a card and the number under it stand at the left of the card again — the
0.4.5 release centred them to keep the height of the cards the same.

Co-Authored-By: Claude Code <noreply@anthropic.com>
@liuzq1103 liuzq1103 changed the title page-token-widget 0.4.5: an iPhone home screen widget for your quota page-token-widget 0.4.6: an iPhone home screen widget for your quota Nov 14, 2026
…centred

The review of the 0.4.6 change found that the widget wrote "30d" for a
monthly window while the phone wrote it as it came, that a window of one day
without a number was announced as a whole week on the phone, and that the
centring the 0.4.5 release added was vertical, not horizontal: the name of a
card floated in the middle of its own row. Every unit is written the same way
on both sides now, and the text stands at the top of its row.

Co-Authored-By: Claude Code <noreply@anthropic.com>
@liuzq1103 liuzq1103 changed the title page-token-widget 0.4.6: an iPhone home screen widget for your quota page-token-widget 0.4.7: an iPhone home screen widget for your quota Nov 14, 2026
@liuzq1103
liuzq1103 force-pushed the feat/page-token-widget branch from f9113b6 to a489a1f Compare November 14, 2026 15:14
@liuzq1103 liuzq1103 changed the title page-token-widget 0.4.7: an iPhone home screen widget for your quota page-token-widget 0.4.6: an iPhone home screen widget for your quota Nov 14, 2026
The code of the standalone plugin (0.4.12) is now in this package, with the
community's own name, port and data directory kept.

- 0.4.8 the number stands in the middle of its card, and Codex's image
  generation quota has a name of its own
- 0.4.9 every row states where it stands, the word and the number share one
  centre line, the number follows the room of its cell
- 0.4.10 the rows of a card really stand at the left of it, and the bar is
  drawn with the dynamic colours of the widget
- 0.4.11 the word in front of the number is one character, and GLM's quota
  stopped freezing (the gateway's balance row has no windows)
- 0.4.12 the small widget fits its frame again - its column was measured
  against the height of the medium widget, and the line about today's tokens
  was cut off on eight of the twelve known phones - and the note of the large
  widget is split in two, so the two parts no longer read as one sentence

The registry entry did not change: the summary there is the same text as the
summary of the package.

Co-Authored-By: Claude Code <noreply@anthropic.com>
@liuzq1103 liuzq1103 changed the title page-token-widget 0.4.6: an iPhone home screen widget for your quota page-token-widget 0.4.12: an iPhone home screen widget for your quota Nov 16, 2026
@liuzq1103

Copy link
Copy Markdown
Author

The standalone plugin (magpie-page-token-widget) is at 0.4.12 now, so this package follows it there — the two carry the same number, as the note at the end of the README says.

What came in since 0.4.6:

  • 0.4.8 — the number stands in the middle of its card, and Codex's image-generation quota has a name of its own (「图片生成剩余」).
  • 0.4.9 — every row states where it stands, the word and the number share one centre line, and the number of the medium widget follows the room of its cell.
  • 0.4.10 — the rows of a card really stand at the left of it (the notes of 0.4.9 claimed it, the script that went out had not done it), and the bar is drawn with the dynamic colours of the widget instead of a canvas.
  • 0.4.11 — the word in front of the number is one character (「剩」 / 「用」), and GLM's quota stopped freezing: the gateway sends zhipu a balance row without windows, which made the whole group look like a broken reading, so the plugin kept falling back to the stored round. Rows without windows are ignored now.
  • 0.4.12 — the small widget's line about today's tokens was clipped out of its frame on eight of the twelve known phones (its column was measured against the height of the medium widget); the title row is gone, the reading time moved onto the last line, the small family measures with its own square width and the bar follows it. The note of the large widget is split into two parts — 「Token 含缓存」 at the left, 「剩余 · 5h」 at the right — so the two no longer read as one sentence.

The name, the port (3498) and the data directory (page-token-widget) are the community's own and did not change. registry.json did not change either — the summary there is the same text as the summary of the package.

Checks: node scripts/run-tests.mjs in the package (209 tests, 208 pass, 1 skipped), bun test over the repository and bun scripts/check.mjs.

The code of the standalone plugin (0.4.13) comes in, so that the community plugin and the standalone one do not drift apart: the vendor list of the legacy gateway counts every request even when one account fails to load, a new account never shows the usage of the old one, a stop waits for the Tailscale forwarding that is running before it takes the forwards and the listeners of this instance away, the account picker of the small widget follows the same rules as the service, and the medium widget fits five and six cards with the account and the vendor on one line.

The registry row is taken from the current main, so the merge does not carry any other entry back. The name, the port (3498) and the data directory (page-token-widget) are the community's own and did not change.
@liuzq1103

Copy link
Copy Markdown
Author

The standalone plugin (magpie-page-token-widget) is at 0.4.13 now, so this package follows it there — the two carry the same number, as the note at the end of the README says.

What came in since 0.4.12:

  • 0.4.13 — the vendor list of the legacy gateway counts every request: it takes the total the gateway itself reports per vendor, so an account that fails to load no longer hides the usage of the other accounts, and the numbers of the accounts are counted apart from it. A changed account email (or a second account with the same name) drops the stale reading of the old account instead of showing it under the new card. A stop or an immediate restart waits for the Tailscale forwarding that is running before it takes away the forwards and the listeners of this instance. The account picker of the small widget offers the visible accounts of the vendor that was selected, the same way the service decides it. The medium widget fits five and six cards: the account and the vendor stand on one line, the spacing of the rows follows the height the medium widget really has, and the second row is whole on the six measured screens.

The registry row is taken from the current main, so the merge carries no other entry back. The name, the port (3498) and the data directory (page-token-widget) are the community's own and did not change.

Checks in the package: node scripts/run-tests.mjs — 223 tests, 222 pass, 1 skipped, 0 fail. bun scripts/check.mjs over the repository — every package ✓.

bun test fails the same four network tests of this package on Windows as it did on this branch before this change (they pass under Node here); the CI runs on Linux.

@yetone the workflow run needs your approval to start — a click is enough for it to go green.

@liuzq1103

Copy link
Copy Markdown
Author

The standalone plugin (magpie-page-token-widget) is at 0.4.14 now, so this package follows it there — the two carry the same number, as the note at the end of the README says.

What came in since 0.4.13:

  • 0.4.14 — the cards carry the names the software gives the vendors. Magpie calls zhipu "Zhipu GLM" and minimax-cn "MiniMax (China)"; the widget used to carry names of its own ("GLM", "MiniMax"), so the balance in the software and the card on the home screen talked about two different things. Every row under "which subscriptions" has a field of its own now: a name of your own for that subscription, used by the page on the phone and by the widgets; leave it empty and the name of the software is used. The countdown is written at one size — the same words were written at 10pt in the large widget when the page shared one window and at 8 or 9pt when it did not, and the name of the window (5h) in the dense medium layout was pinned at 8pt, a point smaller than everything else on that card. The names are longer now, so the titles of a four-card medium page are 9.7pt on a common phone where they were 12pt; a shorter name of your own brings the size back. The parameter of the small widget knows the names of the software: zhipu and minimax-cn find the same card as glm and minimax.

The registry row is taken from the current main, so the merge carries no other entry back. The name, the port (3498) and the data directory (page-token-widget) are the community's own and did not change.

Checks in the package: node scripts/run-tests.mjs — 233 tests, 232 pass, 1 skipped, 0 fail. bun scripts/check.mjs over the repository — every package ✓.

Ten new tests guard the new behaviour, and all ten of them are red on 0.4.13. bun test still fails the same four network tests of this package on Windows as it did on this branch before this change (they pass under Node here); the CI runs on Linux.

@yetone the workflow run needs your approval to start — a click is enough for it to go green.

@liuzq1103

Copy link
Copy Markdown
Author

同步了独立仓库的 0.4.15(提交 6c1701a):插件页的「小组件」拆成两块,改动有没有存下一眼看得见。

  • 小组件分成两块:显示内容(数字是剩余还是已用,三种尺寸都听它)和 小号组件显示哪一张(只管小号那个看哪张卡)。以前这两组选项挤在同一个列表里,页面上没写哪一组是哪一组。
  • 保存状态可见:每一块下面有一行小字写着保存中/已经记下/没有存上,存不上时跟着一个「重试」。插件页本来就是直接落盘的,现在看得见。
  • 修掉两个真会被咬到的问题:改完名字点别处时整张订阅表被重画、正在输入的另一个名字被冲掉;两个名字一起改时服务端收整张表、后一个把前一个顶掉。现在名字边打边存、一个一个排队发。
  • 最后一家订阅勾不掉:全勾掉组件就没内容了,这时把最后那个勾放回去。

社区包内测试 236 项(235 通过 / 1 跳过 / 0 失败),bun scripts/check.mjs 全包通过。社区特有的部分(包名、端口 3498、magpie plugin options @magpie-community/page-token-widget、脚本头注释与 x-token-widget-service)都原样保留。

独立仓库那边已经发了 tag v0.4.15 和双语 Release,CI 四组全绿,npm 上是 magpie-page-token-widget@0.4.15。

The standalone plugin (magpie-page-token-widget) is at 0.4.16 now: it is
published to npm by GitHub Actions itself, with the identity npm calls a
trusted publisher, so no token is used any more. The workflow asks two
questions before it sends anything - whether the release is on main, and
whether the tag and the version in package.json are the same - and the
package is signed with the provenance of the run.

Nothing in the code moved, so this package is the same code with the same
number as the standalone one. The registry row of this package was taken
from the current main, and the main of the community came in with it, so
the merge carries no other entry back.

The name, the port (3498) and the data directory (page-token-widget) are
the community's own and did not change.

Checks in the package: node scripts/run-tests.mjs - 236 tests, 235 pass,
1 skipped, 0 fail. bun scripts/check.mjs over the repository - every
package passes.
@liuzq1103

Copy link
Copy Markdown
Author

冲突已经解决,独立插件也到 0.4.16 了。

冲突 把社区的 main 合了进来(合并提交 152df92)。registry.json 里冲突的那一处是上游新加的 agent-chatcut 条目,保留上游那一条,@magpie-community/page-token-widget 这一行没有动;README.md 是自动合并的。现在 PR 是 MERGEABLE,不再是 CONFLICTING。

0.4.16 独立插件发到 npm 的方式换了:改用 GitHub Actions 自己的身份发布(npm 叫它 trusted publisher),不用令牌了,工作流发的包带 GitHub Actions 的 provenance 签名。npm 上现在是 magpie-page-token-widget@0.4.16。这一版没有改组件:服务和脚本都和 0.4.15 一样。

这个包 跟着到 0.4.16(提交 f55ba80):代码一个字节都没动,只是版本号跟独立插件走,和这个包 README 里写的「这个包的版本就是独立插件的版本」一致。社区特有的部分(包名、端口 3498、数据目录 page-token-widget、magpie plugin options @magpie-community/page-token-widget、x-token-widget-service)都原样保留。

检查 包内 node scripts/run-tests.mjs:236 项,235 通过 / 1 跳过 / 0 失败。仓库里 bun scripts/check.mjs:每个包 ✓。

@yetone 这次推送之后,CI 又回到 action_required,要点一下批准它才会跑起来。

… the token (0.4.17)

The standalone plugin (magpie-page-token-widget) is at 0.4.17 now. The rules
that decide whether a release may go out are stronger:

- the guard asks the tag which commit it means, instead of asking which
  commit the run happened on - npm trusts a workflow by its name and its
  repository, not by the branch it runs from;
- the commit of the tag has to be on main, and the version in package.json
  of that commit has to be the version of the tag;
- a release may not change the rules itself;
- the workflow has two jobs: the first one reads the code, asks the
  questions, runs the tests and packs the package; the second one takes the
  packed package and publishes it, and runs no code of the repository at
  all, so the code that is about to be published never holds the publishing
  token;
- a pre-release is not published: npm would make the release candidate the
  version everybody gets.

The rules live in one script of the standalone plugin, and the tests of it
run that script against little repositories of their own.

The code of this package did not move: it is the code of the standalone
plugin, and the number follows it, as the README of this package says.

Checks in the package: node scripts/run-tests.mjs - 236 tests, 235 pass,
1 skipped, 0 fail. bun scripts/check.mjs over the repository - every package
passes.

The standalone plugin is published on npm as magpie-page-token-widget@0.4.17,
with the provenance of the run.
@liuzq1103

Copy link
Copy Markdown
Author

同步了独立仓库的 0.4.17(提交 ca4674d):发版的规则变严了,组件代码一个字节没动。

  • 守卫问标签,不问「这次运行的提交」:npm 认的是工作流的名字和仓库,不认分支——一次从标签发起的发布,npm 收下了,它自己的 provenance 里写着 workflow.ref = refs/tags/v0.4.16。所以以前那道「必须在 main 上」的手工触发路径是能绕过去的。现在守卫自己去问 refs/tags/<标签> 是哪个提交,那个提交在不在 main 上,那个提交的 package.json 里的版本号是不是标签里的版本号。
  • 发版代码碰不到发布令牌:工作流拆成两个活——第一个活读代码、问问题、跑测试、打包;第二个活只拿打包好的那个包发到 npm,不跑仓库里任何一行代码。只有第二个活手里有那个一次性的 OIDC 令牌。
  • 发布出去的代码不能改规则本身:标签里改了 publish.yml 或者守卫脚本,这次就不发。
  • 版本号从标签的提交上读,不从工作目录读;整段历史都要在(浅的历史答不出「在不在 main 上」,老标签会被误拒)。
  • 预发布不发:GitHub 的 release: published 对预发布同样触发,而 npm 会把发上去的版本变成所有人默认拿到的那个——一个 RC 会直接变成 everybody 的 latest。
  • 规则是一个脚本(独立仓库里的 scripts/verify-release.mjs),测试拿它去跑真的小仓库:标签在 main 上/老提交上的标签(过),分支上的标签/版本对不上/标签不存在/标签名不是版本号/改了规则/改了工作流/运行的工作流不是 main 上那个/Release 说的提交和标签说的不是一个(不过)。
  • 顺带修了一个坑:发出去那一步写的是 npm publish dist/*.tgz,npm 会把 dist/包名.tgz 读成 GitHub 仓库简写(owner/repo)而去 ssh 找仓库;写成 ./dist/*.tgz 才是本地路径。

社区包内测试 236 项(235 通过 / 1 跳过 / 0 失败),bun scripts/check.mjs 全包通过。社区特有的部分(包名、端口 3498、数据目录 page-token-widget、magpie plugin options @magpie-community/page-token-widget、x-token-widget-service)都原样保留。

独立仓库那边已经发了 tag v0.4.17 和双语 Release,CI 四组全绿,npm 上是 magpie-page-token-widget@0.4.17(带 GitHub Actions 的 provenance 签名)。

@yetone 这次推送之后 CI 又回到 action_required,要点一下批准它才会跑起来。

@liuzq1103

Copy link
Copy Markdown
Author

同步了独立仓库的 0.4.18(提交 61f474e):仍然只改发版规则,组件代码一个字节没动。

  • 两个活现在用同一个 Node。 以前检查规则的那个活没固定 Node,跑的是 runner 镜像自带的那个(今天 ubuntu-26.04,明天可能就换了),于是「测试跑过的代码」和「打包用的 Node」未必是同一个。
  • npm 的版本检查挪到了真正发包的那个活里。 换 OIDC 令牌的是发包活里 setup-node 装的 npm,不是检查规则那个活里的。检查放在错的位置,既可能误拦一次无辜的发版,又拦不住真正该拦的那一次。
  • 守卫现在要求「这次运行的是哪个工作流」必须说得出来。 以前这句话是空的时,那道检查就整个跳过——一次运行不报自己的工作流,就可以在一套没人看过的规则下过去。现在空的被当成问题。
  • Release 说的那个提交认得附注标签的标签对象了,不再必须是提交的 SHA。
  • 预发布那条路有测试钉住了(工作流里 github.event.release.prerelease == false 以前没有测试守着,删掉它测试照样全绿)。
  • npm 那边把令牌的路堵得更死了:包的 Publishing access 现在是「Require two-factor authentication and disallow bypass 2fa tokens (recommended)」,trusted publisher(GitHub Actions,liuzq1103 / magpie-page-token-widget / publish.yml)照旧是 Valid。

独立插件的 0.4.18 已经发到 npm(latest,带签名的 SLSA provenance):
https://www.npmjs.com/package/magpie-page-token-widget

本地的核对:包内 236 项测试 235 过 / 1 跳过 / 0 失败,bun scripts/check.mjs 全包 ✓。
合并冲突已经解决,这个 PR 现在是 MERGEABLE。剩下的只有在 fork 上跑工作流需要维护者点一次「Approve and run workflows」,以及维护者自己的那轮审阅——这两样我们这边推不动。

@liuzq1103

Copy link
Copy Markdown
Author

同步了独立仓库的 0.4.19(提交 eeaba8f):订阅名单不再写死在插件里,Magpie 里新加的订阅下一次刷新就出现。

  • 厂商名单从插件里拿走了:以前插件只认 codex/minimax/zhipu 三家,网关报来的别的厂商(现在是 Qoder CN)被整行丢掉——这就是「在 Magpie 里加了订阅、插件里却没有」的根因。现在网关里合法但插件没写过的 id 自己成一家,用 Magpie 给它的名字和它自己的套餐名。
  • 跟随 Magpie 是默认:插件页「哪几个订阅」的第一行是「全部订阅(跟着 Magpie 走)」。勾上以后,新加的订阅自己出现、删掉的自己消失;写下来的顺序不变,页面有一行小字说明当前用的是哪一种。
  • 今日 Token 和厂商排行也认新厂商:用量行带着厂商的稳定 id,卡片才找得到自己的数;手机上的厂商榜报的是软件给的名字,不是 "Unknown"。
  • 同名的额度窗口编号:三个都叫「Quota」的窗口变成「Quota 1」「Quota 2」「Quota 3」。
  • 几个边角:厂商 id 可以带点和下划线,套餐名可以带大写和空格,厂商名恰好是原型里的关键字也照常计数,地址里带 $& 不会再把手机脚本弄坏。

社区包内测试 251 项(250 通过 / 1 跳过 / 0 失败),bun scripts/check.mjs 全包 ✓(含 page-token-widget)。社区特有的部分(包名、端口 3498、数据目录 page-token-widget、magpie plugin options @magpie-community/page-token-widget、x-token-widget-service)都原样保留。

独立插件那边已经发了 tag v0.4.19 和双语 Release,CI 四组全绿,npm 上是 magpie-page-token-widget@0.4.19(带签名的 SLSA provenance)。

@yetone 这次推送之后 CI 又回到 action_required,要点一下批准它才会跑起来。

@liuzq1103

Copy link
Copy Markdown
Author

0.4.20 is on this branch now (7989ba8), the same code as the standalone plugin magpie-page-token-widget@0.4.20.

中文

  • 跟着 Magpie 走的时候也能挑了:第一行「全部订阅(跟着 Magpie 走)」勾上时,下面每一行照样能勾、照样能拖。五家订阅只想在手机上留四家(不显示 minimax),勾掉 minimax 就行,这个「关掉」是写进 state 文件的(subscriptionHidden),只要它还在 Magpie 里就不会自己回来。
  • 多了一个「刷新订阅」按钮:点了立刻重读网关,把「现在有哪些订阅」摆出来,新出现的标一个「新」,不用等定时刷新。网关没答上来时明说「没有读到网关」,并保留上一次读到的名单。
  • 手机上永远至少有一家可看:把每一家都关掉时服务端回 400,投影里还有一层兜底。
  • 插件页的保存排成队:连着勾两行不会被前一次迟到的回话覆盖,存不上时那一勾会按服务端真的那份弹回去。
  • 手机上的组件脚本一个字没改:不用重跑 SetupUsageWidget.js。

English

  • You can pick while you follow. While the whole list of Magpie is followed, every row can still be ticked and dragged. Untick minimax to show four of five on the phone; the hiding is written down in the state file (subscriptionHidden) and does not come back by itself while the subscription is still in Magpie.
  • A "refresh subscriptions" button. It reads the gateway again at once and shows which subscriptions there are now; a new one is marked "new". When the gateway does not answer, the page says so and keeps the list it had.
  • The phone is never left empty. Turning off every subscription is refused by the service, and the projection has a floor under it.
  • The saves of the page go one after another, and a refused tick is put back the way the service really keeps it.
  • The script of the widget did not change: there is no need to run SetupUsageWidget.js again.

Tests: 288 items in this package (287 pass, 1 skipped) with node; the same 4 network tests fail under bun test as before this change (they fail on the previous commit too — they are not about this package's change).

The workflow runs of this pull request are waiting for a maintainer to approve them (action_required), so they have not run yet on this branch.

@liuzq1103

Copy link
Copy Markdown
Author

Synchronized this PR with standalone

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants