Repository navigation
Conversation
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.
|
Harm scan at 1f6c0af: nothing hostile. The vendored qrcode-generator is npm's 1.4.4 with one change (row/col in One security gap to fix before merge: and get 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 Also worth saying in the README: |
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>
|
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:
if (!consoleScope) return json(response, 403, { error: 'This page is only opened on the computer of the service.' });The page that carries
A forged Host on the tailnet gets the phone side. The tests are in
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 |
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>
|
Checked at 0ad2127: the fix holds.
This PR adds a new package with a registry row, a vendored library and a standing |
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>
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>
…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>
f9113b6 to
a489a1f
Compare
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>
|
The standalone plugin ( What came in since 0.4.6:
The name, the port (3498) and the data directory ( Checks: |
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.
|
The standalone plugin ( What came in since 0.4.12:
The registry row is taken from the current Checks in the package:
@yetone the workflow run needs your approval to start — a click is enough for it to go green. |
|
The standalone plugin ( What came in since 0.4.13:
The registry row is taken from the current Checks in the package: Ten new tests guard the new behaviour, and all ten of them are red on 0.4.13. @yetone the workflow run needs your approval to start — a click is enough for it to go green. |
…t through (0.4.15)
|
同步了独立仓库的 0.4.15(提交
社区包内测试 236 项(235 通过 / 1 跳过 / 0 失败), 独立仓库那边已经发了 tag |
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.
|
冲突已经解决,独立插件也到 0.4.16 了。 冲突 把社区的 0.4.16 独立插件发到 npm 的方式换了:改用 GitHub Actions 自己的身份发布(npm 叫它 trusted publisher),不用令牌了,工作流发的包带 GitHub Actions 的 provenance 签名。npm 上现在是 这个包 跟着到 0.4.16(提交 检查 包内 @yetone 这次推送之后,CI 又回到 |
… 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.
|
同步了独立仓库的 0.4.17(提交
社区包内测试 236 项(235 通过 / 1 跳过 / 0 失败), 独立仓库那边已经发了 tag @yetone 这次推送之后 CI 又回到 |
|
同步了独立仓库的 0.4.18(提交
独立插件的 0.4.18 已经发到 npm( 本地的核对:包内 236 项测试 235 过 / 1 跳过 / 0 失败, |
…hows up by itself (0.4.19)
|
同步了独立仓库的 0.4.19(提交
社区包内测试 251 项(250 通过 / 1 跳过 / 0 失败), 独立插件那边已经发了 tag @yetone 这次推送之后 CI 又回到 |
…he list can be read again (0.4.20)
|
0.4.20 is on this branch now ( 中文
English
Tests: 288 items in this package (287 pass, 1 skipped) with node; the same 4 network tests fail under The workflow runs of this pull request are waiting for a maintainer to approve them ( |
|
Synchronized this PR with standalone |
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 --tcpforwarding of its own.How it is put together:
page/holds a launcher only. The page is in a sandbox frame whose CSP isconnect-src 'none', so it cannot fetch anything; it navigates its frame to the local service and the service answers with the console.index.mjs) starts the service on127.0.0.1. It listens first and asks Tailscale afterwards, because the host is only given a few seconds to come up.127.0.0.1:3425) and writes nothing in the configuration of Magpie.scriptable/SetupUsageWidget.jsin Scriptable with the address and the read-only token that the plugin page shows.127.0.0.1:<port>and the phone side on127.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:console; the listener of the tailnet, the door of the LAN and the phone listener have the scopephone(lib/server.mjs).allowedHostsand the origin check are a second guard, not the first one.X-Forwarded-ProtoandX-Forwarded-Hostare never read.Four tests in
test/boundary.test.mjskeep 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.summaryinpackage.jsonand this description carry the same text.test/page.test.mjssays so out loud: the entry of the registry must be the same text asmagpie.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 directorypage-token-widget, the registry entry that says the same asmagpie.summary, and the entry of the plugin exports the plugin and nothing else (the cleanup of the forwarding moved tolib/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.mjsinpackages/page-token-widget-- 184 pass, 1 skipped (a file right on Windows), 0 fail.bun testinpackages/page-token-widget-- 184 pass, 1 skip, 0 fail.Hostheader of127.0.0.1:<port>and without one. The page of the phone carries no token of the service.