# PLAN-W3: Web settle up ## 1. Goal Build the web client's settle-up page (W-7) and settlement detail (W-8) in `web/src/features/settle/`, on W0's foundation, mirroring S-9 and S-10 (SPEC §15.6), with tests. ## 2. Read first 1. SPEC §15 (all), FR-21, FR-11 (AC-11.1 to AC-11.8), FR-12 (AC-12.4), §9.3, §9.4 (allocation proposal), §9.6, §9.8, §14.5.2 (`proposeAllocation`, `validateSettlement`, `overSettledAccounts`), §14.4.3 to §14.4.6, §13.3 rows S-9 and S-10, D-052, D-074, D-080, D-093. 2. `docs/ux/design-spec.md` S-9 and S-10 sections and the components they use; `docs/ux/strings.csv` keys `settle_*` and shared ones. 3. `web/README.md` and W0's report (module map). 4. Files: `web/src/{app,api,lib,components,i18n}/**` (read only), `web/src/features/settle/**` (W0's placeholder). 5. `CLAUDE.md`. ## 3. Already established - W0 owns everything shared; this plan edits only `web/src/features/settle/`. Missing shared pieces are requests to the orchestrator. - Settle up (W-7, mirrors S-9): global from Home (`/app/settle`) or per account (`/app/settle` with the account; one fixed row, direction swap kept, editable amount, D-052); the direction defaults to "the user who owes pays" with a swap control; the amount defaults per AC-11.3; the proposal from W0's `proposeAllocation` over all non-deleted accounts in `created_at` order with nets from `computeBalances` (excluding the settlement being edited); allocation rows with account debt, editable amount and the over-settle warning (`overSettledAccounts`, AC-11.5); the remaining-to-allocate indicator; "Add account"; date; note; when editing, the saved rows count as edited and "Föreslå igen" re-proposes; the info line on untouched accounts per `SettleState.untouched`'s rule (D-093). Confirm validates with `validateSettlement` and writes one `POST /sync` mutation (§15.5); Cancel with the discard dialog (no body, D-080). Computed in the browser as the phone does; E-33 is not needed. - Settlement detail (W-8, mirrors S-10): payer, recipient, amount, date, note, allocations per account, the timeline (AC-12.4); Edit (W-7 with the settlement) and Delete (soft delete, confirmation). - A rejection from `POST /sync` shows its §14.4.6 reason and reloads; nothing is queued. ## 4. Owned paths From SPEC §14.7: `web/src/features/settle/**`. `web/package.json` only for a dependency line. Nothing else. ## 5. Deliverables - W-7 (global, per account, edit) and W-8 (loaded, deleted, missing) with every state of §15.6. - Tests: proposal defaults in both directions, per-account variant, over-settle warning, remaining indicator, "Föreslå igen", untouched info line, validation errors (§14.5.3 tokens mapped to text), write success and rejection, delete. ## 6. Steps 1. Worktree: from `/Users/jhag/projects/kvitt`, `git worktree add .claude/worktrees/agent-w3 -b agent-w3 main`; in it `git reset --hard main`, `tools/install-git-hooks.sh`, `cd web && npm ci`. 2. Read §2. Confirm W0 has landed; if not, stop and report. 3. `npm outdated`; record it. No new library is expected. 4. W-7, then W-8, with tests. 5. Manual check (optional): a throwaway server, `npm run dev`, record and delete a settlement. Never the owner's development stack or the Pi. 6. Gate (§7). Commit on `agent-w3`, `git rebase main`, rerun the gate. Never merge, push or remove the worktree. ## 7. Gate The web gate, from `web/`: `npm run check`. Green: every step passed in this session; Vitest summary quoted. ## 8. HUMAN steps From SPEC §11.2: record and delete a settlement in a browser (yes/no), relayed after landing. ## 9. Out of scope - Home, accounts (W1); expenses, search (W2); analytics (W4); settings (W5); edits outside `web/src/features/settle/`. ## 10. Report - Branch `agent-w3`, head commit after rebasing; gate lines; Vitest counts. - Pages × states covered; `web_` keys added (en, sv); strings missing from `strings.csv`; design-spec mismatches. - Requests for W0's modules; proposed decision entries (numbered from the brief); open questions with SPEC section numbers. ## 11. Numbering Assigned in the start prompt; use `TODO(spec)` if none was given.