Repository navigation
refactor(web): split SettingsComputeUsage into components/ai-usage (L4, pure move) - #2746
Conversation
…4, pure move) Rule 18: the page was 776 lines. AiUsageSection (with AI_PERIODS), BudgetSettingsSection (with BudgetBar) and the cost/token/model formatters move verbatim from main into apps/web/src/components/ai-usage/. Only import lines and five `export` keywords differ. No behaviour change; the integration branch's monthly-cap-unavailable behaviour and its component rename are left for a later slice. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 22 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
|
Playwright screenshots: Settings > Usage, main build vs this branch's build. The images are in the SAM project library under Method: Results:
The links below are the branch's full-content shots; main's are byte-identical.
Quality review: I reviewed every linked image, and the ui-ux-specialist independently reviewed seven shots from both builds. Long and special-character names truncate inside their cards, and HTML renders as text. The exceeded alerts, error card, empty states and edit form render correctly. There is no horizontal overflow or clipping. No visual issues found, and nothing differs from main. |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@coderabbitai review |
Action not completed
|
|



Pure reorganization slice of the self-host landing plan (L4). The coordinator (task
01M7AF82KG9C78WAABTG3V1MN1) verifies the move and merges. Do not merge as author.Summary
apps/web/src/pages/SettingsComputeUsage.tsxis 776 lines on main, over the 500-line limit in.claude/rules/18-file-size-limits.md. This PR moves the AI usage and AI budget sections intoapps/web/src/components/ai-usage/. It is a pure move with no behaviour change. The file names and split points match the integration branchsam/selfhost-pass-2(its own pure-move commit34dbd5d46), so later slices apply as small diffs. Every moved body is main's current code, not the integration branch's.pages/SettingsComputeUsage.tsxformatHours,formatDuration,QuotaProgressBar,SettingsComputeUsagecomponents/ai-usage/format.tsformatCost,formatTokens,truncateModelcomponents/ai-usage/AiUsageSection.tsxAI_PERIODS,AiUsageSectioncomponents/ai-usage/AiBudgetSettingsSection.tsxBudgetBar,BudgetSettingsSectionexportkeywords, onformatCost,formatTokens,truncateModel,AiUsageSectionandBudgetSettingsSection. Everything else that changed is an import line.App.tsxlazy-loadsSettingsComputeUsageby name, andtests/playwright/fixtures/native-hardware-harness.tsximports it the same way. Neither file is touched. Nothing else imported the moved symbols.ai-usage/*, andAiUsageSection/AiBudgetSettingsSection→format..tmp/l4/split.py(scratch, not committed) cut whole line ranges verbatim fromgit show origin/main:apps/web/src/pages/SettingsComputeUsage.tsx. Only the import blocks were written by hand.Left for a later slice
MonthlyCapUnavailableNotecomponentapps/web/src/components/ai-usage/MonthlyCapUnavailableNote.tsxapps/web/src/components/ai-usage/AiBudgetSettingsSection.tsx(branch commitseba74739a,55f8be286)capAvailable/savedCapUsd, clearing the cap on save, "spending" vs "token" header copy, the conditional monthly-cap input and notes. It depends on the newmonthlyCostCapAvailablefield inpackages/shared/src/types/ai-usage.ts.BudgetSettingsSection→AiBudgetSettingsSectionAiBudgetSettingsSection.tsxdeclaration, plus page import and JSX<BudgetSettingsSection />) in the page. Kept main's name. The file name already matches the branch.apps/web/src/components/ai-usage/format.tsline 1 on the branchAiUsageSection.tsxis byte-identical to the integration branch's file. Every item above is a deliberate omission. The task-completion-validator derived the same list independently.Pure-move proof
1. Symbol table and per-symbol extraction comparison
node .tmp/l4/verify.cjs(scratch, not committed, like L2/L3's). It parsesgit show origin/main:<page>and the four new files with the TypeScript compiler API. It matches every top-level statement of main's page by name, and compares the statement text exactly. The only normalisation is dropping a leadingexporton the new side. It then compares old and new line multisets.The script was shown to discriminate. With
No LLM usage yetchanged toNo LLM usage yet!inAiUsageSection.tsx, it reportedAiUsageSection … NO,identical: 10, 2 flagged lines, and exit 1. Withpct >= 80changed topct >= 81inBudgetBar, it reportedBudgetBar … NO. Both edits were reverted; after that the run was clean (exit 0).2. Whole-diff removed vs added lines (multiset), plain git
Every remaining difference is one of these:
exportprefix (five removed lines are matched by fiveexport …added lines)The
(one blank line)above is literally an empty line incomm's output.3. Existing tests pass unchanged
Test edits: none. No test file is in the diff (
git diff --stat origin/main...HEADlists the four source files and the task file only).apps/webvitest, full suite: JSON reportersuccess: true, 409 files, 5,228 tests, 5,228 passed, 0 failed, 0 skipped.pnpm check:fast: exit 0, 22/22 turbo tasks (format ratchet, ESLint incl. SAM boundary rules, type-boundary ratchet).apps/webtsc --noEmit(app and service worker): exit 0.vite build: success.compute-usage-audit.spec.ts,ai-usage-audit.spec.ts, 375x667 + 1280x800): 76 passed and 16 failed on the branch; 76 passed and 16 failed on a cleanorigin/mainworktree. The two failure lists are identical (diffof the sorted test IDs is empty).compute-usage-audit.spec.tspasses in full on both.ai-usage-audit.spec.ts. It waits fortext=LLM Usagewithout mocking the settings shell, which is the stale spec already recorded intasks/backlog/2026-07-17-stale-playwright-audit-specs.md(16 rows). They are pre-existing and unchanged.Validation
pnpm lint(viapnpm check:fast, exit 0)pnpm typecheck(apps/web, exit 0;check:fasttype-boundary ratchet)pnpm test(apps/webvitest 5,228/5,228; no test changes)vite build.quality:file-sizes: every touched file is under 500 lines. The proof scripts and the visual comparison are described above and below.Staging Verification (REQUIRED for all code changes — merge-blocking)
d109a0c6d76cdb483ab98c134a5f9a9889f38f91.app.sammy.partynow serves the route chunkSettingsComputeUsage-DjjqITUD.js(the baseline wasSettingsComputeUsage-BV3B0lJ7.js), so the new code is the code tested.app.sammy.partyas the staging smoke-test user at 1280x800 and 375x667, with one session reused for both captures./api/usage*calls returned 200, with 0 console errors and 0 page errors.Staging Verification Evidence
Window. Staging was claimed on
feature.pr-shepherd-deps-20261111(TAKEN seq195 at 02:15Z) under the root shepherd's handoff, after the P1 owner released it at 02:05Z. FREE was published at 02:41Z (seq196). Nothing was created or changed: no VM, no fixture, no settings and no budget change.Method: before vs after on real staging data. A Playwright script captured
/settings/usageonce on the deploy that was live before this branch, and once after this branch's deploy. Each capture:/api/usage*requests, and the five/api/usage*JSON responses.Results:
BV3B0lJ7)DjjqITUD)/api/usage/ai?period=current-month,?period=7d,/ai/budget,/quota,/compute31mbefore,18mafter). The usage content is pixel-identicalCaveats:
POST /api/t(ERR_ABORTEDwhen the page closes).Screenshots after the deploy (real staging data):
Sign-in note. The stored
SAM_PLAYWRIGHT_PRIMARY_USERtoken returned401fromhttps://api.sammy.party/api/auth/token-logintwice (02:16Z). I did not retry. I used the documented workload-identity sign-in instead (/api/auth/workload-identity-login, 200). Afterwards I signed out (the session then readnull) and deleted the local session files. This is reported on the coordination channel.UI Compliance Checklist (Required for UI changes)
@simple-agent-manager/uiusage)assertNoOverflow(including the clipped-overflow walk) passed in every scenario.UI Screenshot Evidence
All screenshots were taken with Playwright: a main-vs-branch comparison, not only an audit. The full method and results are in the screenshot comment: #2746 (comment)
vite buildof a cleanorigin/mainworktree (4bdaaf61f) and of this branch, each served byvite preview..tmp/l4/compare.spec.ts(scratch) ran the same API mocks and a fixed clock (page.clock.setFixedTime) against both builds at 375x667 and 1280x800. Per scenario it took a viewport and a full-content shot, logged every/api/usage*request with method and body, and logged console errors.cmpreported 28 same and 0 different. The ui-ux-specialist re-checked this with its owncmp.GET /api/usage/compute,/quota,/ai?period=current-month,/ai/budget. After the period click there isGET /api/usage/ai?period=7d. After Save there isPUT /api/usage/ai/budgetwith an identical JSON body, then a budget refetch.notifications/wshandshake noise (no WebSocket mock). The only differences are the port in that message and its retry count.Surface: Settings > Usage, normal data
Surface: Settings > Usage, stress data
<script>alert(n)</script>-田中-🤖model names, 31 models in total), many items (a 30-day trend and 30 active nodes, one with a 204-char name), budget exceeded (180%/225%) and quota exceeded (12.5 of 10).Surface: Settings > Usage, empty state
Surface: Settings > Usage, error and BYOC
/api/usage/aireturns 500, plus a BYOC-exempt quota and a $0.01 cap. A separate/api/usage/compute500 scenario is byte-identical to main and not linked.Surface: Settings > Usage, period switch and budget edit form
End-to-End Verification (Required for multi-component changes)
/settings/usage→App.tsxlazyNamed(import('./pages/SettingsComputeUsage'))→SettingsComputeUsage, which callsfetchComputeUsage+fetchUserQuotaStatusand renders<AiUsageSection />(fetchUserAiUsage(period)) and<BudgetSettingsSection />(fetchUserAiBudget,updateUserAiBudget). This is unchanged from main; only the file boundaries moved. Verified by the identical request logs above and on staging.Data Flow Trace
See above.
Untested Gaps
SettingsComputeUsagechunk. The behaviour is identical, as the comparison above shows.Post-Mortem (Required for bug fix PRs)
N/A: not a bug fix.
What broke
N/A
Root cause
N/A
Class of bug
N/A
Why it wasn't caught
N/A
Process fix included in this PR
N/A
Post-mortem file
N/A
Specialist Review Evidence (Required for agent-authored PRs)
needs-human-reviewlabel added and merge deferred to human: N/A, every reviewer completed.verify.cjsand judged the classifier unable to hide a body change, ran its owncmp(28/28 PNGs identical), and opened 7 screenshots from both builds. Hook order, component identity, the lazy route chunk and other consumers are all unchanged. It found no CRITICAL, HIGH or MEDIUM issues introduced. Pre-existing issues on main, out of scope for a pure move:AiUsageSectionhides loaded data while a period refetch runs (data && !loading, rule 48), and both sections use hand-rolled fetch hooks. Both are covered by the existing TanStack migration task01M0E14DMF42M4RGYEE3RXMA03.eba74739a/55f8be286leaked in. It derived the same "Left for a later slice" list, and confirmed no test changes, all files under 500 lines and that consumers resolve. Two LOW notes were addressed in the task file and here: the checklist now records the evidence and the CodeRabbit / do-not-merge steps, and the WebSocket log noise is explained above.CodeRabbit Review Evidence (Required for agent-authored PRs)
CodeRabbit Notes
Outcome: no CodeRabbit review; not re-triggered (rule 25).
coderabbit-review). Thecoderabbit-bot-review.ymlrun 43669016604 succeeded.d109a0c6dwhen CodeRabbit was requested. The one later commit only touches the task file.Exceptions (If any)
1b930820). This matches refactor(api): move the ws-* proxy out of index.ts (L2, pure move) #2714 and refactor(api): split tts, ai-token-budget and agent-loop (L3, pure move) #2733.Agent Preflight (Required)
Classification
External References
N/A: no external API or library behaviour is involved. Moving module-level React components and pure functions into ES modules, imported by name, does not change rendering, hook order or component identity.
Codebase Impact Analysis
Touched:
apps/web/src/pages/SettingsComputeUsage.tsx, plus the newapps/web/src/components/ai-usage/{format.ts,AiUsageSection.tsx,AiBudgetSettingsSection.tsx}and the task file. The consumers areapps/web/src/App.tsx(lazy route) andapps/web/tests/playwright/fixtures/native-hardware-harness.tsx; neither changed. Same-named formatters elsewhere (AdminCosts,AdminAIProxy,WorkspaceSidebar,AIUsageChart) are independent local copies and are untouched. Overlap check, 2026-11-15 ~01:00Z: no open PR and no active task touchesSettingsComputeUsageorcomponents/ai-usage.Documentation & Specs
N/A: no docs, rules or specs describe this page's internal file layout (I searched
apps/www/src/content/docs,.claude/rules,apps/web/.claude,AGENTS.mdandCLAUDE.md). Backlog task files cite old line numbers inSettingsComputeUsage.tsx. They are historical notes, left as is.Constitution & Risk Check
Head:
572f6fd03108d6d6f03e23ae7b1abbfc365d59fb. Staging ran ond109a0c6d76cdb483ab98c134a5f9a9889f38f91; the only commit after it touches the task file (git diff --stat d109a0c6d 572f6fd03lists onlytasks/active/2026-11-15-l4-web-settings-usage-split.md).🤖 Generated with Claude Code