From c18492bee480ed0c987f691505df6080a3197ccc Mon Sep 17 00:00:00 2001 From: JasonFraser Date: Thu, 15 Oct 2026 05:30:14 -0400 Subject: [PATCH] Layout mapper L.8: superuser review screen (completes the L.1-L.8 plan) New AdminLayoutReviewView.vue (/admin/layouts), rendered by App.vue outside the normal authStore-gated shell entirely - a PocketBase superuser is never a `users` record. Its own inline login against pbAdmin's `_superusers` collection; lists every private mapping across every owner (a superuser session bypasses collection rules); each row expands into a read-only SourceDocumentPanel inspection (reusing L.7's labeled-strip pattern) plus an Approve action that promotes straight to shared, independent of the two-user confirmation hook. adminLayoutsService.js gains getSourceDocument()/sourceFileUrl(), both routed through pbAdmin since the mapping's sourceDocument belongs to its owner, not the superuser. Verified end to end against the real running stack (15 assertions via the actual service files, not reimplementations): a fresh app user's private mapping is visible to and approvable by the real superuser, its source file round-trips byte-for-byte, and a completely independent third-party user immediately resolves the now-shared mapping via findByFingerprintHash. npm run build passes; app container rebuilt. Co-Authored-By: Claude Sonnet 5 --- CLAUDE.md | 132 ++++++++++- frontend/src/App.vue | 10 +- frontend/src/assets/main.css | 7 + frontend/src/router/index.js | 6 + frontend/src/services/adminLayoutsService.js | 21 +- frontend/src/views/AdminLayoutReviewView.vue | 222 +++++++++++++++++++ 6 files changed, 385 insertions(+), 13 deletions(-) create mode 100644 frontend/src/views/AdminLayoutReviewView.vue diff --git a/CLAUDE.md b/CLAUDE.md index 0116c44..455da55 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -31,7 +31,7 @@ to rough effort: |---|---|---| | **1** | Extraction + 6 checks + Excel export, dual-engine, measurement harness | **In progress — see gaps below** | | 2 | Review screen, suggested-fix patterns, OCR, 2nd+ bank support | OCR routing + working Docling-fallback (`raw_ocr_extract.py`) built and verified against a real multi-page scan 2026-10-11 — one known single-page edge case remains unreliable, see "OCR / scanned statements" below — **review screen (R.1-R.5) complete as of 2026-10-13** (see "Review screen"/"R.2"/"R.3"/"R.4"/"R.5" under Key decisions & lessons) — R.1 (source-position capture + the pdf.js highlighting viewer), R.2 (plain-language flags + jump-to-flagged navigation), R.3 (the suggested-fix engine - debit/credit swap, transposed digits, OCR digit misread), R.4 (structural row edits - flip sign, insert, split, merge, delete, behind a "more actions" menu), and R.5 (edit log + acknowledge/accept workflow + an optional Excel "Edits" sheet) all shipped; "date format swapped" and a separate "bulk column fix" both investigated and found not to apply to this pipeline's own data shape (see R.3/R.4's own entries) | -| 3 | Layout mapper (fingerprinting, versioning, drift detection) | **Pulled forward and in progress as of 2026-10-14** (see "Layout mapper" under Key decisions & lessons) - staged L.1-L.8, full spec scope (§6/§6.1/§9) plus a superuser-review promotion path beyond what's written. L.1 (a modular "layout quirks" tier for mechanical geometric oddities, ahead of the mapper itself) shipped - fixed a real new statement (an Equals Money account) whose header label wrapped across physical lines, plus two more real differences the same statement surfaced (a "$"-prefixed money format, an ISO-shaped date format). L.2 (fingerprinting + the forced-mapping backend contract, no UI/PocketBase yet) shipped - also surfaced and fixed a real gap (a forced mapping had no page-boundary concept, swallowing a cover page's own letterhead into the first transaction; fixed with a new `start_page` field). L.3 (the `layoutMappings`/`layoutMappingVersions` PocketBase schema + the auto-promotion hook) shipped - found and fixed a real rule gap during testing (an owner could self-promote their own mapping to "shared" via a plain update; PocketBase rules gate who can update, not which fields). L.4 (the frontend fingerprint-lookup orchestration, including a real, clickable confirm dialog in `ExtractorView.vue` - not deferred to L.6) shipped - found and fixed two real bugs in the near-match comparator while testing it against the spec's own documented example (per-line vs per-field label text; a 70% overlap threshold that was too strict for that very example, corrected to 50%). L.5 (multi-highlight `SourceDocumentPanel` + a new click-and-drag region tool, `useRegionDraw.js`) shipped. **L.6 (`ManualMappingView.vue`, the core deliverable) shipped** - the full save-once-apply-forever loop proven end to end against a real synthetic statement; also caught and fixed a real, consequential bug along the way (forced-mapping column zones were unpadded, so a word landing a fraction of a point past a raw boundary - or a human's own imprecise mouse drag - could silently exclude a whole transaction with no error). **L.7 (the Layouts page + drift detection) shipped** - found and fixed two MORE real bugs in the same "computed correctly this session, never actually persisted" category: `startPage` and a new `headerBottom` (the real header row text on the mapped page itself, not just whole pages before it) were both missing from what got saved, meaning every future auto-apply of a saved mapping would have silently corrupted data again. Drift detection now also wired into every recheck, not just the original extraction. L.8 (the superuser review screen) not started yet | +| 3 | Layout mapper (fingerprinting, versioning, drift detection) | **Pulled forward and in progress as of 2026-10-14** (see "Layout mapper" under Key decisions & lessons) - staged L.1-L.8, full spec scope (§6/§6.1/§9) plus a superuser-review promotion path beyond what's written. L.1 (a modular "layout quirks" tier for mechanical geometric oddities, ahead of the mapper itself) shipped - fixed a real new statement (an Equals Money account) whose header label wrapped across physical lines, plus two more real differences the same statement surfaced (a "$"-prefixed money format, an ISO-shaped date format). L.2 (fingerprinting + the forced-mapping backend contract, no UI/PocketBase yet) shipped - also surfaced and fixed a real gap (a forced mapping had no page-boundary concept, swallowing a cover page's own letterhead into the first transaction; fixed with a new `start_page` field). L.3 (the `layoutMappings`/`layoutMappingVersions` PocketBase schema + the auto-promotion hook) shipped - found and fixed a real rule gap during testing (an owner could self-promote their own mapping to "shared" via a plain update; PocketBase rules gate who can update, not which fields). L.4 (the frontend fingerprint-lookup orchestration, including a real, clickable confirm dialog in `ExtractorView.vue` - not deferred to L.6) shipped - found and fixed two real bugs in the near-match comparator while testing it against the spec's own documented example (per-line vs per-field label text; a 70% overlap threshold that was too strict for that very example, corrected to 50%). L.5 (multi-highlight `SourceDocumentPanel` + a new click-and-drag region tool, `useRegionDraw.js`) shipped. **L.6 (`ManualMappingView.vue`, the core deliverable) shipped** - the full save-once-apply-forever loop proven end to end against a real synthetic statement; also caught and fixed a real, consequential bug along the way (forced-mapping column zones were unpadded, so a word landing a fraction of a point past a raw boundary - or a human's own imprecise mouse drag - could silently exclude a whole transaction with no error). **L.7 (the Layouts page + drift detection) shipped** - found and fixed two MORE real bugs in the same "computed correctly this session, never actually persisted" category: `startPage` and a new `headerBottom` (the real header row text on the mapped page itself, not just whole pages before it) were both missing from what got saved, meaning every future auto-apply of a saved mapping would have silently corrupted data again. Drift detection now also wired into every recheck, not just the original extraction. **L.8 (the superuser review screen) shipped 2026-10-15 - completes the full L.1-L.8 plan.** | | 4 | Multi-tenant practice/client accounts, Frappe data model | Not started | | 5 | Free front door, public accuracy page | Not started | | 6 | Append mode, credit cards, multi-account statements | Not started | @@ -368,13 +368,25 @@ security only, not the full SaaS-shaped doc — and the judgment call on what co App.vue — the auth gate, then the full app shell: AppHeader + ProjectSidebar + routed view + AppFooter (see "Enterprise app-shell redesign" under Key decisions & lessons - - modeled on docs/sample_ui.png, same enterprise-light theme) + modeled on docs/sample_ui.png, same enterprise-light theme). + As of layout mapper L.8 (2026-10-15), checked FIRST, + ahead of the auth gate: any route starting with `/admin` + renders its own `` directly, bypassing + LoginView/authStore/the whole shell entirely - a + PocketBase superuser is never a `users` record, so + `/admin/layouts` (AdminLayoutReviewView.vue) has no + relationship to the app's own login at all. /assets/main.css — started as the original CSS moved verbatim; grown substantially since (table/sidebar/account-bar/app-shell sections each added for their own stage - see Key decisions & lessons for which) - /router/index.js — one route today ('/' -> ExtractorView), kept as a real - router per the standards doc's structure + /router/index.js — kept as a real router per the standards doc's + structure. Four routes as of the layout mapper work: + '/' -> ExtractorView, '/map-layout' -> ManualMappingView + (L.6), '/layouts' -> LayoutsView (L.7), '/admin/layouts' + -> AdminLayoutReviewView (L.8 - rendered by App.vue + OUTSIDE the normal authStore-gated shell entirely, see + below) /stores (Pinia) extractionStore.js — a LIST of documents (`documents`, each `{pbId, docKey, fileName, project, previewUrl, isImage, result, @@ -527,9 +539,13 @@ security only, not the full SaaS-shaped doc — and the judgment call on what co `rollbackToVersion`, and promoted `checksPassed` from a private `useBatchExtraction.js` helper to a shared export so drift detection has one definition, not three). - adminLayoutsService.js (NEW 2026-10-14 — the superuser's own - `listPending`/`approve`, ahead of L.8's actual review - screen; uses pbAdmin, never the app user's own `pb`). + adminLayoutsService.js (NEW 2026-10-14, extended + 2026-10-15 for L.8 — the superuser's own `login`/ + `logout`/`isLoggedIn`/`listPending`/`approve`, plus + `getSourceDocument`/`sourceFileUrl` (L.8 - resolves a + mapping's own sourceDocument/file through pbAdmin, since + a superuser session never shares the app user's `pb` + client); uses pbAdmin throughout, never `pb`. /composables — useFileUpload (pure staging concern only as of Stage B.3 — `chosenFiles` accumulate-not-replace with dedup, drag/drop handlers; no longer owns `loadDocuments`, moved @@ -645,6 +661,22 @@ security only, not the full SaaS-shaped doc — and the judgment call on what co scope deviation and the two more real bugs (startPage/ headerBottom never being persisted) this stage's own end-to-end testing caught. + /views/AdminLayoutReviewView.vue — NEW 2026-10-15, layout mapper L.8 (the plan's + final stage) — routed at /admin/layouts, rendered by + App.vue OUTSIDE the normal authStore-gated shell entirely + (no AppHeader/ProjectSidebar/AppFooter — a PocketBase + superuser is never a `users` record). Its own tiny inline + login form against `pbAdmin.collection('_superusers') + .authWithPassword(...)`; once signed in, every + `status = "private"` mapping across every owner (a real + superuser session bypasses PocketBase's rules + automatically), each expanding into a read-only + SourceDocumentPanel with every columnMap field drawn as a + labeled vertical strip (same Inspect pattern L.7's + LayoutsView.vue already established) plus dateFormat/ + signConvention/ignoredRowRules as plain text, and an + Approve button (via ConfirmModal) that promotes straight + to shared. ``` **One real bug caught and fixed during this restructure, server-side:** the production `Dockerfile` serves `frontend/dist` from Flask via a catch-all route @@ -2496,6 +2528,92 @@ FontAwesome set before use. **Not machine-verified:** the actual List/Inspect/ Test/Retire UI click-through in a real browser - same standing limitation as every other UI stage this session. +**L.8 shipped 2026-10-15: the superuser review screen - the final stage, this +completes the full L.1-L.8 layout mapper plan.** New +`frontend/src/views/AdminLayoutReviewView.vue`, routed at `/admin/layouts`, and a +new check in `App.vue` (`route.path.startsWith('/admin')`, checked FIRST, ahead +of the normal `authStore.isAuthenticated` gate) that renders that route's own +`` directly - no `AppHeader`/`ProjectSidebar`/`AppFooter`/`LoginView` +at all. Deliberate: a real PocketBase superuser lives in the separate +`_superusers` auth collection, not `users` - there is no "logged in as the app" +state for this screen to share or be gated by. The view has its own tiny inline +login form against `pbAdmin.collection('_superusers').authWithPassword(...)` +(`adminLayoutsService.login()`), authenticating on `pbAdmin` +(`pocketbaseAdminRepository.js`, already built in L.4) - entirely independent of +the app user's own `pb.authStore` on the same machine. + +Once signed in, `adminLayoutsService.listPending()` lists every `status = +"private"` mapping across EVERY owner in one call - no per-user filtering code +needed anywhere, since a real superuser session bypasses every PocketBase +collection rule automatically (confirmed, not assumed: the same `listRule` that +restricts an ordinary user to `owner = @request.auth.id || status = "shared"` +simply doesn't apply to a `_superusers` session). Each row expands into the same +Inspect pattern L.7's `LayoutsView.vue` already established - a read-only +`SourceDocumentPanel` with every `columnMap` field drawn as a labeled, full-height +vertical strip, plus `dateFormat`/`signConvention`/`ignoredRowRules` as plain +text - except the source document and file URL are resolved through two NEW +`adminLayoutsService.js` functions, `getSourceDocument()`/`sourceFileUrl()`, +both routed through `pbAdmin` rather than `documentsService.js`'s own `pb`-backed +versions: the mapping's `sourceDocument` record belongs to its owner, not the +superuser, so the app user's own client (which may not even be logged in on this +machine at all) could never fetch it - only a real superuser session can, the +same rule-bypass reasoning as `listPending()`. **Approve** calls +`adminLayoutsService.approve(id)` (built in L.4 already) - sets `status: +"shared"`, `promotedReason: "superuser_approved"`, `approvedBySuperuser: `, `promotedAt: now` - behind the same `ConfirmModal` +pattern every other consequential action in this app already uses. + +No backend Python was touched this stage - this is the one layout-mapper stage +that is pure frontend routing/UI over infrastructure (fingerprinting, the schema, +the hook, `pbAdmin`, `listPending`/`approve`) every earlier stage already built +and proved correct. + +**Verified, all real, against the real rebuilt container - a hand-written Node +script executing the ACTUAL, already-committed service files (never +reimplementations: `authService.js`, `documentsService.js`, +`layoutMappingsService.js`, `adminLayoutsService.js`, both real `pb`/`pbAdmin` +client instances), 15 assertions, using the real superuser credentials already +configured via `pocketbase/configure-secrets.sh`:** signed up a fresh app user, +saved a real source document (a real file upload, not a stub), created a +still-`private` mapping pointing at it; signed in as the real superuser and +confirmed `listPending()` surfaces that mapping; confirmed +`getSourceDocument()`/`sourceFileUrl()` fetch the owner-only document record and +its real file bytes - compared byte-for-byte against the original upload, not +just "the request succeeded"; called `approve()` and confirmed on the +RE-FETCHED, persisted record (not the update call's own echoed response) that +`status`/`promotedReason`/`approvedBySuperuser`/`promotedAt` are all correct, and +that the mapping no longer appears in a fresh `listPending()` call; signed the +superuser out and confirmed the session actually cleared; **then signed up a +COMPLETELY independent third-party user and confirmed `findByFingerprintHash` +resolves the now-shared mapping for them immediately** - proving this promotion +path works entirely on its own, independent of L.3's two-different-owner hook +path. All 15 assertions passed on the first run. Test data (the mapping, the +document, both signed-up users and their auto-created default projects) was +deleted from the real running PocketBase afterward via direct superuser REST +calls, in dependency order (mapping → document → each user's own default +project → the user), so none of it lingers as real app data. +`npm run build` passes; every icon class used (`fa-user-shield`, +`fa-right-to-bracket`, `fa-right-from-bracket`, `fa-chevron-down`/`-right`, +`fa-spinner`, `fa-check`, `fa-circle-info`) confirmed present in the installed +FontAwesome set before use; the `app` container was rebuilt and is serving the +new bundle. `backend/measure.py` was not re-run this stage - zero backend Python +was touched, so the standing per-stage rule (re-run after any change to +`table_extract.py`/`extraction_service.py`/`pipeline_service.py`) doesn't apply +here; `git status` confirms the only modified/new files this stage are +`App.vue`, `router/index.js`, `main.css`, `adminLayoutsService.js`, and the new +`AdminLayoutReviewView.vue`. **Not machine-verified:** the actual login form, +the expand/Inspect click-through, and the Approve confirm modal in a real +browser - same standing limitation as every other UI-only stage this session. + +**This closes out the full layout mapper plan (L.1-L.8).** What started as one +real bug report (a never-seen Equals Money statement failing extraction) now has +a complete four-tier pipeline - keyword/geometry auto-detection, a code-based +quirks module for mechanical oddities, fingerprint-based auto-apply with drift +detection, and a manual mapping screen as the true last resort - plus a shared +library two independent users' matching mappings promote into automatically, or +a real PocketBase superuser can push there directly after reviewing it against +the actual source document. + **Governing rule: never silently correct or exclude data.** This shows up in several concrete places, not just as an abstract principle: - A row with an unusual status (e.g. HSBC's "Cancelled" wires) stays in the output and is diff --git a/frontend/src/App.vue b/frontend/src/App.vue index fe68d50..e08f7ad 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -10,20 +10,28 @@ * mirrors the PocketBase SDK's own auth state (which persists/restores * the session token itself) into the Pinia store every other component * reads. + * + * Any /admin-prefixed route (the layout mapper's superuser review screen, + * L.8) renders OUTSIDE this entire gate - a PocketBase superuser is never + * a `users` record, so it has no relationship to authStore/LoginView/the + * normal app shell at all. Checked first, before the normal auth gate. */ import { onMounted } from 'vue' +import { useRoute } from 'vue-router' import { useAuthStore } from './stores/authStore' import LoginView from './views/LoginView.vue' import AppHeader from './components/AppHeader.vue' import AppFooter from './components/AppFooter.vue' import ProjectSidebar from './components/ProjectSidebar.vue' +const route = useRoute() const authStore = useAuthStore() onMounted(authStore.syncWithAuthStore)