MemoryModules.tsx

src/components/MemoryModules.tsx

MemoryModules.tsx421 lines← Lessons
1import React from 'react';2import {theme as t} from '../theme';3import {clamp} from '../motion';4import {Boundary, Label, Text} from './Primitives';5import {along, type Point} from './Connections';6import {memoryComposition} from '../simulation/icrustmem';7import {MachineryBoundary} from './MachineryBoundary';89export type MemoryEngine = 'Nyxus' | 'Hylix';10export type MemoryModuleFocus = 'module' | 'data' | 'children' | 'scope';11export type MemoryOwner = 'root' | 'branches' | 'inventory' | 'settings' | 'checkout';12export type MemoryBox = {x: number; y: number; width: number; height: number};1314export const detachedTicketSize = {width: 123, height: 32} as const;15export const DetachedMemoryTicket: React.FC<{x: number; y: number; opacity: number}> = ({x, y, opacity}) => <g transform={`translate(${x} ${y})`} opacity={opacity}>16  <rect {...detachedTicketSize} rx={5} fill={t.actionFill} stroke={t.action} strokeWidth={1.4}/>17  <Text x={detachedTicketSize.width / 2} y={22} size={15} mono color={t.action} anchor="middle">Detached</Text>18</g>;1920/** One drawing for every owned Memory declaration, including the root.21 * A business module may own several of these; all zooms scale this geometry. */22export const memoryModuleSize = {width: 356, height: 236} as const;23export const memoryModuleGeometry = {24  ...memoryModuleSize,25  header: {x: 0, y: 0, width: 356, height: 48},26  data: {x: 16, y: 60, width: 324, height: 83},27  children: {x: 16, y: 154, width: 324, height: 66},28  key: {x: 204, y: 69, width: 126, height: 18},29  service: {x: 0, y: 24},30  attachment: {x: 356, y: 195},31} as const;3233export type MemoryModuleProps = {34  x?: number;35  y?: number;36  owner: string;37  version?: 'v1' | 'v2';38  engine?: MemoryEngine;39  data?: string | string[];40  children?: string[];41  active?: MemoryModuleFocus;42  opacity?: number;43};4445export const MemoryModule: React.FC<MemoryModuleProps> = ({46  x = 0, y = 0, owner, version, engine = 'Nyxus', data = '()', children = [], active, opacity = 1,47}) => {48  const lines = Array.isArray(data) ? data : [data];49  const dataActive = active === 'data' || active === 'scope';50  return <g transform={`translate(${x} ${y})`} opacity={opacity}>51    <rect {...memoryModuleSize} rx={16} fill={t.white} stroke={active === 'module' ? t.state : t.line} strokeWidth={active === 'module' ? 3 : 2}/>52    <line x1={0} x2={356} y1={48} y2={48} stroke={t.line}/>53    <Text x={18} y={32} size={24} weight={600}>{owner}</Text>54    {version && <Text x={175} y={31} size={16} mono color={t.muted}>{version}</Text>}55    <Text x={338} y={31} size={15} mono color={engine === 'Hylix' ? t.archive : t.block} anchor="end">{engine}</Text>5657    <rect {...memoryModuleGeometry.data} rx={9} fill={dataActive ? t.stateFill : t.paper} stroke={dataActive ? t.state : t.line} strokeWidth={dataActive ? 2.5 : 1.2}/>58    <Text x={29} y={85} size={20} weight={500} color={t.state}>Data</Text>59    <g transform="translate(204 69)">60      <rect width={126} height={18} rx={4} fill={active === 'scope' ? t.state : t.white} stroke={t.state} strokeWidth={.9}/>61      <path d="M7 5 H13 V12 H7 Z M13 8 H18 M16 8 V11" fill="none" stroke={active === 'scope' ? t.white : t.state} strokeWidth={1.2}/>62      <Text x={23} y={12.8} size={9.8} mono color={active === 'scope' ? t.white : t.state}>private MemoryKey</Text>63    </g>64    {lines.map((line, i) => <Text key={i} x={29} y={103 + i * 16} size={15.5} mono>{line}</Text>)}6566    <rect {...memoryModuleGeometry.children} rx={9} fill={active === 'children' ? t.blockFill : t.white} stroke={active === 'children' ? t.block : t.line} strokeWidth={active === 'children' ? 2.5 : 1.2}/>67    <Text x={29} y={176} size={18} weight={500} color={t.block}>Children</Text>68    {children.length ? children.map((child, i) => <g key={child}>69      <rect x={29} y={187 + i * 17} width={7} height={7} rx={2} fill={t.blockFill} stroke={t.block}/>70      <Text x={44} y={195 + i * 17} size={14.5} mono color={t.ink}>{child}</Text>71    </g>) : <Text x={29} y={205} size={15} mono color={t.muted}>()</Text>}72  </g>;73};7475export const shopMemoryGeometry = {76  width: 1476, height: 654,77  root: {x: 26, y: 222, ...memoryModuleSize},78  branches: {x: 558, y: 28, ...memoryModuleSize},79  settings: {x: 558, y: 398, ...memoryModuleSize},80  inventory: {x: 1090, y: 28, ...memoryModuleSize},81  checkout: {x: 1090, y: 454, width: 300, height: 104},82} as const;8384const rootBranches: Point[] = [[382, 417], [458, 417], [458, 52], [558, 52]];85const rootSettings: Point[] = [[382, 434], [490, 434], [490, 422], [558, 422]];86const branchInventory: Point[] = [[914, 223], [1000, 223], [1000, 52], [1090, 52]];87const checkoutBranches: Point[] = [[1090, 482], [1030, 482], [1030, 4], [736, 4], [736, 28]];88const checkoutSettings: Point[] = [[1090, 530], [1016, 530], [1016, 422], [914, 422]];8990/** An ownership attachment ends at the opaque module boundary, never its Data. */91const OwnershipPath: React.FC<{points: Point[]; opacity?: number; active?: boolean}> = ({points, opacity = 1, active = false}) => {92  const last = points.at(-1)!, before = points.at(-2)!;93  const angle = Math.atan2(last[1] - before[1], last[0] - before[0]) * 180 / Math.PI;94  return <g opacity={opacity}>95    <path d={`M${points.map(p => p.join(' ')).join(' L')}`} fill="none" stroke={t.state} strokeWidth={active ? 3.5 : 2.5} strokeLinejoin="round"/>96    <rect x={points[0][0] - 4} y={points[0][1] - 4} width={8} height={8} rx={2} fill={t.white} stroke={t.state} strokeWidth={1.5}/>97    <path d="M-9 -5 L0 0 L-9 5" transform={`translate(${last[0]} ${last[1]}) rotate(${angle})`} fill="none" stroke={t.state} strokeWidth={2.2}/>98  </g>;99};100101const ServicePath: React.FC<{points: Point[]; active?: boolean; phase?: number}> = ({points, active = false, phase = 1}) => {102  const at = along(points, clamp(phase));103  return <g opacity={active ? .9 : .38}>104    <path d={`M${points.map(p => p.join(' ')).join(' L')}`} fill="none" stroke={t.reducer} strokeWidth={2} strokeDasharray="5 7" strokeLinejoin="round"/>105    {active && phase > 0 && phase < 1 && <circle cx={at[0]} cy={at[1]} r={5} fill={t.reducer}/>} 106  </g>;107};108109export type ShopMemoryTreeProps = {110  x?: number;111  y?: number;112  /** 0: Inventory; 1: its Branches owner; 2: the whole Actor; 3: transient services. */113  stage?: number;114  active?: MemoryOwner;115  focus?: MemoryModuleFocus;116  phase?: number;117};118119/** The actual Shop tree. Every one of these Memory declarations uses Nyxus. */120export const ShopMemoryTree: React.FC<ShopMemoryTreeProps> = ({x = 0, y = 0, stage = 3, active, focus = 'module', phase = 1}) => {121  const branches = clamp(stage), whole = clamp(stage - 1), services = clamp(stage - 2);122  const emphasis = (owner: MemoryOwner) => active === owner ? focus : undefined;123  return <g transform={`translate(${x} ${y})`}>124    <OwnershipPath points={branchInventory} opacity={branches} active={active === 'branches' || active === 'inventory'}/>125    <OwnershipPath points={rootBranches} opacity={whole} active={active === 'root'}/>126    <OwnershipPath points={rootSettings} opacity={whole} active={active === 'root' || active === 'settings'}/>127    <g opacity={services}>128      <ServicePath points={checkoutBranches} active={active === 'checkout'} phase={phase}/>129      <ServicePath points={checkoutSettings} active={active === 'checkout'} phase={phase}/>130    </g>131    <g opacity={whole}><Text x={26} y={198} size={18} mono color={t.state}>Actor&lt;root::memory::v1::Memory&gt;</Text></g>132    <MemoryModule {...shopMemoryGeometry.root} owner="root" data="()" children={['branches: ChildSlot', 'settings: ChildSlot']} active={emphasis('root')} opacity={whole}/>133    <MemoryModule {...shopMemoryGeometry.branches} owner="branches" data="()" children={['items: ChildMap<u64>']} active={emphasis('branches')} opacity={branches}/>134    <MemoryModule {...shopMemoryGeometry.settings} owner="settings" data="tax: u32" active={emphasis('settings')} opacity={whole}/>135    <MemoryModule {...shopMemoryGeometry.inventory} owner="inventory" data="items: Map<u64, Item>" active={emphasis('inventory')}/>136    <g opacity={branches}>137      <rect x={966} y={140} width={68} height={31} rx={6} fill={t.paper}/>138      <Text x={1000} y={162} size={17} mono color={t.state} anchor="middle">[9]</Text>139    </g>140    <g transform={`translate(${shopMemoryGeometry.checkout.x} ${shopMemoryGeometry.checkout.y})`} opacity={services}>141      <rect width={300} height={104} rx={14} fill={t.white} stroke={t.reducer} strokeWidth={active === 'checkout' ? 2.5 : 1.5} strokeDasharray="4 6"/>142      <Text x={22} y={39} size={24} weight={500} color={t.reducer}>Checkout</Text>143      <Text x={22} y={74} size={16} mono color={t.muted}>transient service</Text>144    </g>145  </g>;146};147148export type EngineMemoryOwner = 'root' | 'inventory' | 'hot' | 'tables' | 'execution' | 'records';149const engineRootInventory: Point[] = [[374, 425], [510, 425], [510, 254], [570, 254]];150const engineInventoryHot: Point[] = [[926, 425], [1040, 425], [1040, 64], [1180, 64]];151const engineInventoryTables: Point[] = [[926, 442], [1090, 442], [1090, 444], [1180, 444]];152const engineRootBox = {x: 18, y: 230, ...memoryModuleSize};153const engineInventoryBox = {x: 570, y: 230, ...memoryModuleSize};154const engineHotBox = {x: 1180, y: 40, ...memoryModuleSize};155const engineTablesBox = {x: 1180, y: 420, ...memoryModuleSize};156const engineHotExit = {x: 1536, y: 142};157const engineTablesExit = {x: 1536, y: 522};158159/** A supported mixed-engine composition, separate from the actual all-Nyxus160 * Shop. Physical storage diagrams connect to dataExits; these solid attachment161 * paths describe ownership and stop at the opaque child module boundary. */162export const engineMemoryGeometry = {163  width: 1600, height: 700,164  root: engineRootBox,165  appRoot: engineRootBox,166  inventory: engineInventoryBox,167  hot: engineHotBox,168  tables: engineTablesBox,169  module: {x: 530, y: 0, width: 1050, height: 700},170  actor: {x: 18, y: 179, width: 400, height: 38},171  ownership: {inventory: engineRootInventory, hot: engineInventoryHot, tables: engineInventoryTables, execution: engineInventoryHot, records: engineInventoryTables},172  dataExits: {hot: engineHotExit, tables: engineTablesExit, execution: engineHotExit, records: engineTablesExit},173  // Scene compatibility aliases; these are not labels in the composition.174  execution: engineHotBox,175  records: engineTablesBox,176} as const;177178export type EngineMemoryTreeProps = {179  x?: number;180  y?: number;181  /** 0: Actor/root; 1: Inventory Memory; 2: HotMemory; 3: TablesMemory. */182  stage?: number;183  active?: EngineMemoryOwner;184  focus?: MemoryModuleFocus;185  phase?: number;186};187188/** One business module owns several private Memory declarations, each with189 * several collection fields. Its composite Memory attaches them beneath the190 * same Actor root. The unchanged canonical cells are reused at every scale.191 * This is a supported composition illustration, not the all-Nyxus Shop. */192export const EngineMemoryTree: React.FC<EngineMemoryTreeProps> = ({x = 0, y = 0, stage = 3, active, focus = 'module', phase = 1}) => {193  const inventory = clamp(stage), hot = clamp(stage - 1), tables = clamp(stage - 2);194  const selected = active === 'execution' ? 'hot' : active === 'records' ? 'tables' : active;195  const emphasis = (owner: EngineMemoryOwner) => selected === owner ? focus : undefined;196  const activePath = selected === 'inventory' ? engineRootInventory : selected === 'hot' ? engineInventoryHot : selected === 'tables' ? engineInventoryTables : undefined;197  const token = activePath ? along(activePath, phase) : undefined;198  const tokenOpacity = selected === 'tables' ? tables : selected === 'hot' ? hot : inventory;199  return <g transform={`translate(${x} ${y})`}>200    <g opacity={inventory}><MachineryBoundary {...engineMemoryGeometry.module} label="module · inventory"/></g>201    {memoryComposition.filter(node => node.parent !== null).map(node => {202      const key = node.id as 'inventory' | 'hot' | 'tables';203      const points = {inventory: engineRootInventory, hot: engineInventoryHot, tables: engineInventoryTables}[key];204      return <OwnershipPath key={key} points={points} opacity={{inventory, hot, tables}[key]} active={selected === node.parent || selected === node.id}/>;205    })}206    <Text x={18} y={206} size={22} mono color={t.state}>Actor&lt;app::Memory&gt;</Text>207    {memoryComposition.map(node => {208      const key = node.id as 'root' | 'inventory' | 'hot' | 'tables';209      const children = memoryComposition.filter(child => child.parent === node.id).map(child => `${child.attachment}: ChildSlot`);210      return <MemoryModule key={key} {...engineMemoryGeometry[key]} owner={node.memory} engine={node.engine} data={node.data} children={children} active={emphasis(key)} opacity={{root: 1, inventory, hot, tables}[key]}/>;211    })}212    {token && phase > 0 && phase < 1 && focus === 'children' && <rect x={token[0] - 5} y={token[1] - 5} width={10} height={10} rx={2} fill={t.stateFill} stroke={t.state} strokeWidth={2} opacity={tokenOpacity}/>} 213  </g>;214};215216export const catalogFingerprintSize = {width: 160, height: 72} as const;217export type CatalogKind = 'source' | 'changed-source' | 'target';218export type CatalogCheck = 'idle' | 'checking' | 'accepted' | 'rejected';219220/** A symbolic contract fingerprint, not a data checksum or cryptographic signature. */221export const CatalogFingerprint: React.FC<{x?: number; y?: number; kind?: CatalogKind; opacity?: number}> = ({x = 0, y = 0, kind = 'source', opacity = 1}) => {222  const color = kind === 'changed-source' ? t.danger : kind === 'target' ? t.block : t.reducer;223  const widths = kind === 'target' ? [26, 14, 30, 22] : kind === 'changed-source' ? [20, 28, 12, 30] : [20, 28, 26, 14];224  return <g transform={`translate(${x} ${y})`} opacity={opacity}>225    <rect {...catalogFingerprintSize} rx={11} fill={t.white} stroke={color} strokeWidth={2}/>226    <rect x={12} y={13} width={42} height={46} rx={5} fill={kind === 'target' ? t.blockFill : t.reducerFill}/>227    {widths.map((width, i) => <line key={i} x1={18} x2={18 + width} y1={22 + i * 9} y2={22 + i * 9} stroke={color} strokeWidth={2} strokeLinecap="round"/>)}228    <Text x={66} y={42} size={18} mono color={color}>Catalog</Text>229  </g>;230};231232const CatalogCheckMark: React.FC<{x: number; y: number; status: CatalogCheck; phase?: number}> = ({x, y, status, phase = 0}) => {233  const color = status === 'rejected' ? t.danger : status === 'accepted' ? t.state : t.block;234  return <g transform={`translate(${x} ${y})`}>235    <rect width={110} height={94} rx={15} fill={t.white} stroke={color} strokeWidth={2}/>236    <circle cx={55} cy={34} r={18} fill={status === 'accepted' ? t.stateFill : t.paper} stroke={color} strokeWidth={1.7}/>237    {status === 'idle' && <><line x1={46} x2={64} y1={30} y2={30} stroke={color} strokeWidth={2}/><line x1={46} x2={64} y1={37} y2={37} stroke={color} strokeWidth={2}/></>}238    {status === 'checking' && <path d="M55 21 A13 13 0 1 1 42 34" transform={`rotate(${clamp(phase) * 360} 55 34)`} fill="none" stroke={color} strokeWidth={2.5} strokeLinecap="round"/>}239    {status === 'accepted' && <path d="M45 34 L52 41 L66 26" fill="none" stroke={color} strokeWidth={2.8} strokeLinecap="round" strokeLinejoin="round"/>}240    {status === 'rejected' && <path d="M47 26 L63 42 M63 26 L47 42" fill="none" stroke={color} strokeWidth={2.8} strokeLinecap="round"/>}241    <Text x={55} y={76} size={16} mono color={color} anchor="middle">check</Text>242  </g>;243};244245export type CatalogGateStage = 'inputs' | 'saved' | 'checking' | 'rejected' | 'accepted' | 'restored' | 'published';246export const catalogGateGeometry = {247  width: 1560, height: 660,248  candidate: {x: 0, y: 0, width: 930, height: 640},249  installed: {x: 985, y: 0, width: 575, height: 640},250  inputs: {x: 28, y: 96, width: 390, height: 360},251  expected: {x: 540, y: 225, ...catalogFingerprintSize},252  saved: {x: 1175, y: 110, ...catalogFingerprintSize},253  target: {x: 540, y: 510, ...catalogFingerprintSize},254  check: {x: 825, y: 215, width: 110, height: 94},255  retained: {x: 1018, y: 365, width: shopMemoryGeometry.width * .33, height: shopMemoryGeometry.height * .33},256} as const;257258const publicationPath: Point[] = [[540, 510], [760, 510], [760, 342], [1070, 342], [1070, 110], [1175, 110]];259260/** Physical pieces, owning type edges, declared meaning and interpretation261 * policies compile to a contract; they are not a scan of saved values. */262const CatalogInputs: React.FC<{progress: number; changedSource: boolean}> = ({progress, changedSource}) => {263  const pieces = [264    {x: 28, y: 103, label: 'Physical layouts'},265    {x: 232, y: 103, label: 'Owning types'},266    {x: 28, y: 296, label: 'Semantic contracts'},267    {x: 232, y: 296, label: 'Runtime policies'},268  ];269  return <>{pieces.map((piece, i) => {270    const color = i === 2 && changedSource ? t.danger : i === 0 || i === 1 ? t.block : t.reducer;271    return <g key={piece.label} opacity={clamp(progress * 5 - i)}>272      <path d={`M${piece.x + 156} ${piece.y + 52} H420 V261 H523`} fill="none" stroke={color} strokeOpacity={.35} strokeWidth={1.5}/>273      <g transform={`translate(${piece.x} ${piece.y})`}>274        <rect width={156} height={104} rx={10} fill={t.white} stroke={color} strokeWidth={i === 2 && changedSource ? 2 : 1.3}/>275        {i === 0 && <g stroke={color} fill={t.blockFill} strokeWidth={1.3}>276          <rect x={17} y={17} width={77} height={30} rx={4}/>277          <line x1={43} x2={43} y1={17} y2={47}/><line x1={69} x2={69} y1={17} y2={47}/>278          <rect x={54} y={65} width={77} height={23} rx={4}/>279          <path d="M82 47 V56 H93 V65" fill="none"/>280        </g>}281        {i === 1 && <g transform="translate(8 18) scale(.094)"><ShopMemoryTree stage={2}/></g>}282        {i === 2 && <g stroke={color} fill="none" strokeWidth={1.5}>283          <path d="M35 16 H106 L121 31 V87 H35 Z M106 16 V31 H121" fill={changedSource ? '#F8EAE4' : t.reducerFill}/>284          <path d="M49 42 H101 M49 54 H93 M49 66 H103 M49 78 H78"/>285          {changedSource && <path d="M86 51 L106 57 L87 64" strokeWidth={3}/>} 286        </g>}287        {i === 3 && <g>288          {[0, 1, 2].map(j => <g key={j}>289            <rect x={19 + j * 7} y={15 + j * 16} width={104} height={24} rx={4} fill={t.reducerFill} stroke={color} strokeWidth={1.2}/>290            <path d={`M${34 + j * 7} ${27 + j * 16} H${99 + j * 7}`} stroke={color} strokeWidth={1.2}/>291          </g>)}292          <Text x={78} y={91} size={11.5} mono color={color} anchor="middle">Collections · Wire</Text>293        </g>}294        <Text x={78} y={133} size={16} color={color} anchor="middle">{piece.label}</Text>295      </g>296    </g>;297  })}</>;298};299300export type CatalogGateProps = {x?: number; y?: number; stage?: CatalogGateStage; changedSource?: boolean; phase?: number};301302/** Admission compares installed memory with the candidate's expected SOURCE.303 * The target is a distinct contract and is published only after restoration. */304export const CatalogGate: React.FC<CatalogGateProps> = ({x = 0, y = 0, stage = 'saved', changedSource = false, phase = 1}) => {305  const p = clamp(phase), mismatch = changedSource || stage === 'rejected';306  const opened = ['accepted', 'restored', 'published'].includes(stage);307  const showSaved = stage !== 'inputs';308  const check: CatalogCheck = stage === 'checking' ? 'checking' : stage === 'rejected' ? 'rejected' : opened ? 'accepted' : 'idle';309  const checkOpacity = ['inputs', 'saved'].includes(stage) ? .28 : 1;310  const published = stage === 'published' && p === 1;311  const publishAt = along(publicationPath, p);312  return <g transform={`translate(${x} ${y})`}>313    <Boundary {...catalogGateGeometry.candidate} label="candidate Wasm"/>314    <Boundary {...catalogGateGeometry.installed} label="installed memory"/>315    <CatalogInputs progress={stage === 'inputs' ? p : 1} changedSource={mismatch}/>316    <Text x={540} y={205} size={20} weight={500}>expected source</Text>317    <CatalogFingerprint {...catalogGateGeometry.expected} kind={mismatch ? 'changed-source' : 'source'} opacity={stage === 'inputs' ? clamp(p * 3 - 1) : 1}/>318    <Text x={540} y={489} size={20} weight={500} color={t.block}>target</Text>319    <CatalogFingerprint {...catalogGateGeometry.target} kind="target" opacity={stage === 'inputs' ? .28 : .75}/>320321    <g opacity={showSaved ? 1 : .2}>322      <Text x={1175} y={92} size={20} weight={500}>saved installed</Text>323      <CatalogFingerprint {...catalogGateGeometry.saved} kind={published ? 'target' : 'source'}/>324      <path d="M1175 146 H962 V280 H935" fill="none" stroke={t.reducer} strokeWidth={2}/>325      <g transform="translate(1018 365) scale(.33)"><ShopMemoryTree stage={2}/></g>326    </g>327    <path d="M700 261 H825" fill="none" stroke={mismatch ? t.danger : t.reducer} strokeWidth={2}/>328    <g opacity={checkOpacity}><CatalogCheckMark x={825} y={215} status={check} phase={p}/></g>329    <path d="M880 309 V452 H1026" fill="none" stroke={opened ? t.state : t.line} strokeWidth={2.5} strokeDasharray={opened ? undefined : '5 7'}/>330    <g transform="translate(968 452)">331      <line x1={0} y1={-29} x2={0} y2={29} stroke={opened ? t.state : stage === 'rejected' ? t.danger : t.muted} strokeWidth={4} strokeLinecap="round" transform={opened ? 'rotate(-66 0 -29)' : undefined}/>332      <circle cx={0} cy={-29} r={4} fill={t.paper} stroke={opened ? t.state : t.muted}/>333    </g>334    {opened && <path d="M1017 446 L1026 452 L1017 458" fill="none" stroke={t.state} strokeWidth={2.5}/>} 335    {opened && stage === 'accepted' && p > 0 && p < 1 && <circle cx={880 + Math.max(0, p - .5) * 292} cy={p < .5 ? 309 + p * 286 : 452} r={5} fill={t.state}/>} 336    {stage === 'restored' || stage === 'published' ? <g>337      <rect x={752} y={528} width={150} height={54} rx={10} fill={t.white} stroke={t.reducer} strokeDasharray="4 5"/>338      <Text x={827} y={562} size={21} mono color={t.reducer} anchor="middle">App</Text>339      <path d="M700 546 H752" fill="none" stroke={t.reducer} strokeWidth={1.6} strokeDasharray="4 5"/>340    </g> : null}341    {stage === 'published' && p < 1 && <CatalogFingerprint x={publishAt[0]} y={publishAt[1]} kind="target"/>}342    {stage === 'rejected' && <Text x={879} y={355} size={19} weight={500} color={t.danger} anchor="middle">mismatch</Text>}343  </g>;344};345346export type RootConversionStage = 'source' | 'candidate' | 'admitted' | 'data' | 'children' | 'rebind' | 'published';347export const rootConversionGeometry = {348  width: 1560, height: 660,349  source: {x: 80, y: 120, ...memoryModuleSize},350  target: {x: 1040, y: 120, ...memoryModuleSize},351  scores: {x: 600, y: 405, ...memoryModuleSize},352  declared: {x: 510, y: 20, width: 350, height: 84},353  targetCatalog: {x: 1040, y: 18, ...catalogFingerprintSize},354  savedCatalog: {x: 1360, y: 490, ...catalogFingerprintSize},355  services: {x: 1110, y: 424, width: 220, height: 88},356} as const;357358const sourceScores: Point[] = [[436, 315], [520, 315], [520, 429], [600, 429]];359const targetScores: Point[] = [[1040, 315], [990, 315], [990, 429], [956, 429]];360const convertPublication: Point[] = [[1040, 18], [1422, 18], [1422, 490], [1360, 490]];361362export type RootConversionProps = {x?: number; y?: number; stage?: RootConversionStage; phase?: number};363364/** Actual root-authoring-probe conversion, illustrated from source rather than365 * presented as an execution capture: () -> revision: 2, same Scores owner. */366export const RootConversion: React.FC<RootConversionProps> = ({x = 0, y = 0, stage = 'source', phase = 1}) => {367  const p = clamp(phase), index = {source: 0, candidate: .5, admitted: 1, data: 2, children: 3, rebind: 4, published: 5}[stage];368  const dataProgress = index > 2 ? 1 : index === 2 ? p : 0;369  const childProgress = index > 3 ? 1 : index === 3 ? p : 0;370  const rebound = index >= 4;371  const childMoving = stage === 'children' && p > 0 && p < 1;372  const ticket = {x: 438 + p * 472, y: 290 + Math.sin(p * Math.PI) * 34};373  const publishAt = along(convertPublication, p);374  const sourceOpacity = 1 - dataProgress * .72;375  const targetOpacity = index === 0 ? 0 : .28 + dataProgress * .72;376  return <g transform={`translate(${x} ${y})`}>377    <Text x={80} y={110} size={18} mono color={t.muted}>root::memory::v1</Text>378    <Text x={1040} y={110} size={18} mono color={t.muted} opacity={index > 0 ? 1 : 0}>root::memory::v2</Text>379    <CatalogFingerprint x={80} y={18}/>380    <g opacity={index >= 1 ? 1 : .25}>381      <path d="M240 54 H510" fill="none" stroke={t.reducer} strokeWidth={2}/>382      <CatalogCheckMark x={510} y={7} status={index >= 1 ? 'accepted' : 'idle'}/>383      <Text x={644} y={45} size={17} mono color={t.reducer}>previous =</Text>384      <Text x={644} y={75} size={17} mono>[memory::v1::Memory]</Text>385    </g>386    <CatalogFingerprint {...rootConversionGeometry.targetCatalog} kind="target" opacity={index > 0 ? .65 : 0}/>387    <OwnershipPath points={sourceScores} opacity={childMoving || childProgress === 1 ? 0 : 1}/>388    <OwnershipPath points={targetScores} opacity={childProgress === 1 ? 1 : 0} active={index >= 3}/>389    <MemoryModule {...rootConversionGeometry.source} owner="root" version="v1" data="()" children={['scores: ChildSlot']} active={stage === 'data' ? 'data' : stage === 'children' ? 'children' : undefined} opacity={sourceOpacity}/>390    <MemoryModule {...rootConversionGeometry.target} owner="root" version="v2" data={dataProgress === 1 ? 'revision: 2' : 'revision: u64'} children={['scores: ChildSlot']} active={stage === 'data' ? 'data' : stage === 'children' ? 'children' : undefined} opacity={targetOpacity}/>391    <MemoryModule {...rootConversionGeometry.scores} owner="scores" version="v1" data="values: Map<u64, u64>" active={stage === 'children' ? 'module' : undefined}/>392    {index >= 2 && <g opacity={index === 2 ? 1 : .45}>393      <path d="M457 223 H1015" fill="none" stroke={t.state} strokeWidth={2.5}/>394      <path d="M1005 217 L1015 223 L1005 229" fill="none" stroke={t.state} strokeWidth={2.5}/>395      <Text x={736} y={198} size={21} mono color={t.state} anchor="middle">Actor::upgrade</Text>396      {stage === 'data' && p > 0 && p < 1 && <g transform={`translate(${448 + p * 510} 202)`}>397        <rect width={56} height={40} rx={8} fill={t.stateFill} stroke={t.state}/>398        <Text x={28} y={27} size={20} mono anchor="middle">()</Text>399      </g>}400    </g>}401    {childMoving && <g>402      <path d={`M${ticket.x + 65} ${ticket.y + 40} V376 H778 V405`} fill="none" stroke={t.state} strokeWidth={2.3}/>403      <g transform={`translate(${ticket.x} ${ticket.y})`}>404        <rect width={130} height={40} rx={8} fill={t.stateFill} stroke={t.state} strokeWidth={2}/>405        <Text x={65} y={27} size={17} mono color={t.state} anchor="middle">Detached</Text>406      </g>407    </g>}408    <g opacity={rebound ? stage === 'rebind' ? p : 1 : 0}>409      <path d="M1218 356 V424 M1110 468 H998 V429 H956" fill="none" stroke={t.reducer} strokeWidth={1.8} strokeDasharray="4 6"/>410      <rect {...rootConversionGeometry.services} rx={13} fill={t.white} stroke={t.reducer} strokeWidth={1.6} strokeDasharray="4 6"/>411      <Text x={1130} y={457} size={21} weight={500} color={t.reducer}>App</Text>412      <Text x={1130} y={490} size={18} mono color={t.reducer}>Scores</Text>413      <Label x={1110} y={542} size={13} color={t.muted}>transient services</Label>414    </g>415    {stage === 'published' && <g>416      <path d="M1330 468 H1343 V526 H1356" fill="none" stroke={t.block} strokeWidth={2}/>417      <Text x={1360} y={469} size={18} color={t.block}>saved Catalog</Text>418      {p < 1 ? <CatalogFingerprint x={publishAt[0]} y={publishAt[1]} kind="target"/> : <CatalogFingerprint {...rootConversionGeometry.savedCatalog} kind="target"/>}419    </g>}420  </g>;421};