useBatchExtraction.js gets an else-if branch for needs_value_confirmation,
parallel to the existing needs_mapping one - reuses resolveNeedsMapping()
as-is (it's already fingerprint-only, agnostic to why resolution was
needed) and routes 'no_match' to a new layoutMapperStore.setPendingValueConfirmation()
instead of setPending().
ManualMappingView.vue gains a second mode (told apart by whether
pendingCandidateRow is set): a "Confirm values" card replacing region-
drawing - one row per field, raw text as read, an editable correction,
validated inline (empty-value and non-substring rejection, per explicit
requirement). The derived {stripPrefix?, stripSuffix?} per field is the
only thing sent as forcedMapping - no columnMap, letting auto-detection
resolve everything else.
Two real bugs caught by this stage's own testing: hasRequiredShape (the
region-drawing mode's Preview gate) stays permanently false in the new
mode since columnMap never populates there - fixed with a new canPreview
that branches per mode. The validation/diff logic's own substring check
didn't separate a leading "-" before comparing, so correcting a negative
value like "-CAD50.00" to "-50.00" failed validation outright (not a
contiguous substring) - the same bug already fixed on the backend earlier
the same day, reintroduced independently since the logic isn't shared.
LayoutsView.vue's own separate forcedMappingFor() (used by "Test") gets
the same valuePatterns key; Inspect gains a note for an empty columnMap
and a new card showing the saved cleanup rule itself.
Verified end to end against the real stack (19 assertions, actual
service/composable files): upload triggers needs_value_confirmation,
the derived pattern previews and saves correctly with no columnMap, the
real PocketBase superuser approves it via the existing L.8 review screen
unmodified, and a completely independent third-party user auto-applies
it via exact fingerprint match. measure.py byte-identical to baseline.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
New /layouts route (LayoutsView.vue, linked from AppHeader.vue): List (own + shared
mappings with usage/failure stats), Inspect (source document with each column drawn
as a labeled vertical strip), Test (an unsaved dry run against any of the user's own
documents), Version history + Roll back (append-only - a rollback creates a new
version rather than editing history), and Retire. The plan's own "Edit" (reopening
ManualMappingView pre-populated) was deliberately dropped - columnMap never persists
page/vertical position, so there's no real data to re-populate a visual editor with.
Drift detection now runs on every recheck, not just the original extraction -
useRowEditing.js and TransactionRow.vue both call the same recordUsage() useBatchExtraction.js
already used, via a newly shared layoutMappingsService.checksPassed(). Required
threading layoutMappingUsed/layoutMappingVersionUsed onto the in-memory document
object too (extractionStore/useDocuments/useBatchExtraction), not just the PocketBase
record.
Found and fixed two real bugs via this stage's own end-to-end testing, both in the
same "computed correctly this session, never persisted" category as L.6's zone-padding
fix: startPage itself was never saved, so every future auto-apply of a saved mapping
would have silently reset to page 1, reintroducing the cover-page bug L.2 already
fixed once. Worse: startPage alone only skips whole pages - it does nothing about the
real header row text still sitting on the start page itself, which would have
corrupted essentially every real manually-mapped statement. Fixed with two new
persisted fields (startPage, headerBottom) and a new header_bottom parameter in
table_extract.py, using the same zone-padding margin as a safety buffer.
Verified against the real rebuilt container: a 2-page synthetic statement confirmed
both bugs real before their fixes and confirmed both fixed together; a second,
independent upload auto-applies the saved mapping with both fields carried through;
sourceDocument backfill, version history/rollback, retire, and real three-user
promotion all confirmed against the real PocketBase; a separate test confirmed the
recheck-triggered drift detection itself, flipping a real mapping to stale after a
deliberately broken running-balance edit. measure.py byte-identical throughout; npm
run build passes.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
useBatchExtraction.js now reacts to a needs_mapping:true response: looks up an
exact or near-match layout mapping (layoutMappingsService.js), applies it silently
on an exact match, asks for confirmation on a stale exact match or a near match via
a real ConfirmModal wired through ExtractorView.vue (not a placeholder), and falls
through to reason:'no_match' when nothing matches (the manual mapping screen's own
entry point, not built yet). A used mapping's usage is recorded for drift detection
and persisted onto the saved document record.
Found and fixed two real bugs in the near-match comparator by testing it against
the spec's own documented example (Debit/Credit renamed to Withdrawals/Deposits):
compute_fingerprint was building header_labels from whole header LINES instead of
per-field label text, making a two-word rename indistinguishable from a totally
different layout; added a field_labels map so the comparison is per-field. Even
after that, the first 70% overlap threshold still failed the documented example
itself (a 4-field rename of 2 fields is exactly 50%) - corrected to 50%, derived
from the example's own real numbers.
Verified: 18 assertions against the real layoutMappingsService/useLayoutMapping
(hard gates, the corrected per-field overlap, real PocketBase ownership/sharing
rules, stale-mapping decline/accept, no-match reporting); the real rebuilt
container's /api/process response now carries the fixed field_labels shape;
measure.py byte-identical throughout; npm run build passes.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>