feat(app): R2 switch — the application runs its domain rules in the Rust core

Consumers now fed by the core (crates/core through @faunosteo/core-wasm):
- the sheet: the bundled payload is parsed and indexed by the core
  (SheetHandle, SheetIndexData); SheetIndex reads precomputed tables only;
- the store: new report, add / remove / move observation, draft restore
  (v2 migration + rebase) through the core, actions answering { ok };
- the editor click chain (zone.click), laterality and vertebra pickers
  (zone.add_sides, vertebra.initial / sync / select), the findings picker
  (finding.toggle by clicked leaf position), zone removal;
- the import: engine byte scan (TypeScript until R4), then the core's
  layered reading and rebase in one call; the export: the core builds the
  sheet snapshot, the frozen TypeScript engine writes the PDF (R4).
Lazy core: Home and the new-report form read the sheet availability from
the bundle and load the module on import / submit only; the auth shell
never references it. Degraded states (core_unavailable, invalid_sheet)
show the validated notice with a retry and never redirect or touch the
draft; an unreadable draft or archive is set aside under
osteo:quarantine:* (only content kinds; a failed write keeps it in place
and the editor stays), a rebase that flags items keeps the raw pre-rebase
draft. Four strings, wording validated by the owner.
Deleted: services/zoneInteraction.ts and its suite (13 cases ported to
cargo), the TypeScript Finding builder and vertebra selection rules of the
pickers, store rules, persistence parsing, hydrateReport. ESLint forbids
@faunosteo/domain in apps/app/src; the report:compare CLI keeps the frozen
domain until R4 (scripts/compare/sheet.ts). App suite 313/313 on the real
core (24 new tests: quarantine, degraded editor, core failures, N-1
reader); step6 goldens and the frozen envelopes unchanged.
This commit is contained in:
bchanot committed 2026-10-14 00:41:34 +02:00
1 parent 794dfd9d0b
commit 74fcb37564
65 files changed
+2227 -1678

No files matched your search

@@ -5,7 +5,7 @@ import type {
LateralSide,
Observation,
ReportZone,
} from '@faunosteo/domain'
} from '@faunosteo/core-wasm/types'
import { AnimatePresence, motion } from 'motion/react'
import Card from '@/components/ui/Card'
import Badge from '@/components/ui/Badge'
@@ -15,7 +15,8 @@ import Textarea from '@/components/ui/Textarea'
import FindingsTreePicker from './FindingsTreePicker'
import FreeTextFindingInput from './FreeTextFindingInput'
import SeveritySelector from './SeveritySelector'
import { isObservable, pickLabel, type SheetIndex } from '@/services/sheetIndex'
import { isObservable, type SheetIndex } from '@/services/sheetIndex'
import { pickLabel } from '@/i18n/pickLocaleLabel'
import { useT } from '@/i18n/useT'
import { useLocaleStore } from '@/state/localeStore'
import type { Locale } from '@/i18n/types'
@@ -96,7 +97,7 @@ function unresolvedFindings(
sheet: SheetIndex,
): Finding[] {
return observation.findings.filter(
(f) => !sheet.nodeAt(f.findingZoneId, f.path),
(f) => !sheet.hasNode(f.findingZoneId, f.path),
)
}
@@ -152,6 +153,23 @@ export default function ObservationCard({
event.stopPropagation()
fn()
}
/** The core builds or removes the finding of the clicked leaf (R2). */
function toggleFinding(
findingZoneId: string,
side: LateralSide | undefined,
path: string[],
leafPosition: number,
) {
const outcome = sheet.ops.toggleFinding({
observation,
findingZoneId,
path,
leafPosition,
...(side ? { side } : {}),
})
if (outcome.ok) onChange(outcome.value)
else window.alert(t('core.action_failed'))
}
const removeFinding = (target: Finding) =>
onChange({
...observation,
@@ -379,11 +397,8 @@ export default function ObservationCard({
zone={zone}
side={side}
selected={observation.findings}
onChange={(next) =>
onChange({
...observation,
findings: next,
})
onToggle={(path, leafPosition) =>
toggleFinding(zone.id, side, path, leafPosition)
}
/>
</div>