Files
plugins/packages/day-card/page/index.html
T
ming_jiang 4b0aef5327 amp-usage: Amp usage page with background collection; day-card 0.3.1 (#1000)
Adds packages/amp-usage (@magpie-community/page-amp-usage 0.1.0). It is a magpie page that reads Amp's local thread files and the gateway's usage.jsonl and shows per-day usage. The service listens on loopback only and requires a per-start service token on every API call. The page that carries the token is served only to a navigation (Sec-Fetch-Mode). The gateway log is read incrementally from a saved offset, whole lines only, and is re-indexed on rotation. The UI words are in ui/words.js (en, zh).

Also bumps packages/day-card to 0.3.1.

Round 3 (13c1f33) adds three things:
- a test that bytes before the gateway-log offset are never re-read;
- ui.test.mjs, which checks that every error code the server can return has words in each language, and that an unknown code falls back;
- words.js, moved out of app.js, served at /words.js and included in the pack.

What ran, at 13c1f33 merged with main 14187408, on mica:
- amp-usage `node --test`: 47/47.
- `bun test packages/amp-usage packages/day-card`: 65 pass, 0 fail.
- `bun scripts/check.mjs`, all packages: ok.
- `npm pack --dry-run`: amp-usage 0.1.0 has 19 files including ui/words.js; day-card 0.3.1 has 17 files.
- Root `bun test` with a temp HOME: 8362 pass, 0 fail (8382 tests, 590 files).
- Render smoke in Chromium and WebKit at 1200 and 420px, en and zh: words.js loads, both languages show their own words, no page errors, no horizontal overflow.

Broken by hand, each run with node and bun:
- collector.mjs:102 made to re-read the whole file every scan: the new offset test goes red.
- `const cut = buf.length`, so a partial line is taken: red.
- Raw error codes shown instead of their words (`w.err[code] || code`): red.
- A zh string deleted: red.

Not tried:
- A real Amp account or the real `amp` CLI.
- Changing the auto-refresh default from 300 to 60 fails no test. The author left it untested and round 2 called it optional.

Rounds 1 and 2 also ran the 1M-line log probe (rss steady at about 363MB, scans of 70 to 114ms after the first), the bad-record and paging probes, and the full render matrix including dark mode.
2026-11-11 21:43:59 +08:00

51 lines
2.8 KiB
HTML

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Day card</title>
<link rel="stylesheet" href="style.css">
<script src="_magpie/bridge.js"></script>
<script src="fonts.js"></script>
<script src="icons.js"></script>
<script src="view.js"></script>
<script src="backgrounds.js"></script>
<script src="app.js" defer></script>
</head>
<body>
<header>
<div class="spans" id="spans" role="radiogroup" data-t-label="spanLabel">
<button type="button" role="radio" data-span="day" data-t="spanDay">Day</button>
<button type="button" role="radio" data-span="week" data-t="spanWeek">Week</button>
<button type="button" role="radio" data-span="month" data-t="spanMonth">Month</button>
<button type="button" role="radio" data-span="all" data-t="spanAll">All</button>
</div>
<div class="days">
<button type="button" class="step" id="prev" aria-label="Previous day" data-t-label="prev"><svg viewBox="0 0 16 16" aria-hidden="true"><path d="M10 3.5 5.5 8l4.5 4.5"/></svg></button>
<div class="pick">
<button type="button" id="date" aria-haspopup="listbox" aria-expanded="false"><span id="date-text"></span><svg viewBox="0 0 16 16" aria-hidden="true"><path d="m4.5 6.5 3.5 3.5 3.5-3.5"/></svg></button>
<ul id="menu" role="listbox" hidden></ul>
</div>
<button type="button" class="step" id="next" aria-label="Next day" data-t-label="next"><svg viewBox="0 0 16 16" aria-hidden="true"><path d="M6 3.5 10.5 8 6 12.5"/></svg></button>
<button type="button" id="today" data-t="today">Today</button>
</div>
<div class="share">
<div class="bgpick">
<button type="button" id="bg" aria-haspopup="dialog" aria-expanded="false"><canvas id="bg-chip" aria-hidden="true"></canvas><span data-t="background">Background</span></button>
<div id="bg-pop" role="dialog" data-t-label="background" hidden>
<div id="bg-grid" role="radiogroup" data-t-label="background"></div>
<label class="slider pad-only"><span data-t="padding">Padding</span><input type="range" id="pad" min="24" max="160" step="4"></label>
<label class="slider photo-only"><span data-t="blur">Blur</span><input type="range" id="blur" min="0" max="20" step="1"></label>
<label class="slider photo-only"><span data-t="dim">Dim</span><input type="range" id="dim" min="0" max="60" step="1"></label>
<input type="file" id="file" accept="image/png,image/jpeg,image/webp" hidden>
</div>
</div>
<button type="button" id="copy" data-t="copy" disabled>Copy image</button>
<button type="button" id="save" data-t="save" disabled>Save PNG</button>
</div>
</header>
<p class="status" id="status" role="status"></p>
<main id="main"><canvas id="card"></canvas></main>
</body>
</html>