Skip to content

Add canonical facts system and factor component library#4

Open
OAGr wants to merge 2 commits intomainfrom
claude/move-facts-longterm-next-xQ3D1
Open

Add canonical facts system and factor component library#4
OAGr wants to merge 2 commits intomainfrom
claude/move-facts-longterm-next-xQ3D1

Conversation

@OAGr
Copy link
Contributor

@OAGr OAGr commented Feb 9, 2026

Summary

This PR introduces a comprehensive canonical facts system for the longterm-next application, along with a new library of reusable factor-related MDX components. The facts system reads from YAML files, parses numeric values, and evaluates computed expressions at build time. The new components enable rich, data-driven content in MDX pages.

Key Changes

Canonical Facts System (src/data/facts.ts)

  • YAML-based fact store: Facts are now defined in src/data/facts/*.yaml files instead of being synced from the database
  • Numeric parsing: Automatically parses human-readable values like "$13 billion", "40%", "$76,001/year" into numeric values
  • Computed expressions: Supports safe expression evaluation with references to other facts (e.g., {anthropic.valuation} * {jaan-tallinn.anthropic-ownership})
  • Topological sorting: Resolves computed facts in dependency order to handle complex calculations
  • Build-time processing: All parsing and computation happens at build/server-component time using Node.js fs

Fact Data Files

  • Added three initial entity fact files:
    • anthropic.yaml: Valuation, revenue, margins, team composition
    • openai.yaml: Investment, valuation, revenue, model performance metrics
    • sam-altman.yaml: Net worth, investments, company metrics
    • jaan-tallinn.yaml: Ownership stakes with computed values based on Anthropic valuation

New Factor Components

Six new MDX-compatible components for displaying structured factor data:

  • FactorKeyDebates: Displays key debates/disagreements from YAML with topic and core questions
  • FactorRatings: Shows 0-100 scores for changeability, x-risk impact, trajectory impact, and uncertainty with interpretations
  • FactorScope: Renders scope definitions with includes/excludes sections
  • FactorRelatedContent: Links to related risks, responses, models, and cruxes
  • FactorRelationshipDiagram: Mermaid-based flowchart showing factor relationships (incoming/outgoing/both directions)
  • FullModelDiagram: Complete model visualization showing all factors, scenarios, and outcomes
  • FactorStatusBadge: Status indicator component (stub)

All components support both direct data props and dynamic lookup via nodeId + subItemLabel.

Integration Updates

  • Updated mdxComponents.ts to register new components and remove stubs for FactorRelationshipDiagram and FullModelDiagram
  • Modified src/data/index.ts to load facts from YAML files instead of database
  • Updated facts page documentation to reflect new YAML-based system

Testing

  • Added fact-consistency test rule that validates hardcoded fact values in content against canonical facts
  • Suggests using <F> component for fact references
  • Informational logging of potential fact consistency issues

Implementation Details

  • Safe expression evaluation: Custom recursive descent parser (no eval()) supporting +, -, *, /, parentheses, and fact references
  • Circular dependency detection: Topological sort validates computed fact DAG
  • Caching: Facts are loaded once and cached in memory for the process lifetime
  • Error handling: Graceful degradation with warnings for unparseable values or circular dependencies
  • Currency detection: Automatically detects currency-denominated facts for proper formatting

Files Modified

  • apps/longterm-next/src/app/internal/facts/page.tsx
  • apps/longterm-next/src/components/mdx-components.tsx
  • apps/longterm-next/src/data/index.ts
  • apps/longterm-next/src/lib/__tests__/validate-content.test.ts

Files Added

  • apps/longterm-next/src/data/facts.ts (445 lines)
  • apps/longterm-next/src/components/wiki/FactorKeyDebates.tsx
  • apps/longterm-next/src/components/wiki/FactorRatings.tsx

https://claude.ai/code/session_019sD1zo6gTDKeJCWc7Rz7u5

- Copy canonical fact YAML files (anthropic, openai, sam-altman, jaan-tallinn)
  to apps/longterm-next/src/data/facts/
- Create facts.ts module with self-contained YAML loading, numeric parsing,
  expression evaluation, and computed fact resolution (ported from build-data.mjs)
- Update data/index.ts to load facts from local YAML files instead of database.json,
  making longterm-next fully self-sufficient for canonical facts
- Port 5 missing Factor components: FactorKeyDebates, FactorRatings, FactorScope,
  FactorRelatedContent, FactorRelationshipDiagram (with FullModelDiagram)
- Register all new Factor components in mdx-components.tsx and remove from stubs
- Add fact-consistency validation test to detect hardcoded values that should
  use the <F> component
- Update Facts Dashboard page to reference new local file location

https://claude.ai/code/session_019sD1zo6gTDKeJCWc7Rz7u5
Remove "use client" directive from FactorRelationshipDiagram since it
imports fs-based parameter-graph-data functions. The component only
computes a Mermaid chart string (no hooks/state/browser APIs) and passes
it to MermaidDiagram, which is the actual client component.

https://claude.ai/code/session_019sD1zo6gTDKeJCWc7Rz7u5
@vercel
Copy link

vercel bot commented Feb 9, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
cairn Ready Ready Preview Feb 9, 2026 3:29pm
cairn-meta Ready Ready Preview Feb 9, 2026 3:29pm
longtermwiki Ready Ready Preview Feb 9, 2026 3:29pm

Request Review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants