@lucern/graph-primitives 0.1.0-alpha.3 → 0.3.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/dist/beliefDecay.js +199 -18
  2. package/dist/beliefDecay.js.map +1 -1
  3. package/dist/beliefEvidenceLinks.js.map +1 -1
  4. package/dist/confidencePropagationDispatch.js.map +1 -1
  5. package/dist/contradictions.js.map +1 -1
  6. package/dist/entityBridge.js.map +1 -1
  7. package/dist/entityLifecycle.js.map +1 -1
  8. package/dist/epistemicAnswers.js +21 -36
  9. package/dist/epistemicAnswers.js.map +1 -1
  10. package/dist/epistemicBeliefs.js +92 -651
  11. package/dist/epistemicBeliefs.js.map +1 -1
  12. package/dist/epistemicContracts.js +65 -624
  13. package/dist/epistemicContracts.js.map +1 -1
  14. package/dist/epistemicEdges.js.map +1 -1
  15. package/dist/epistemicEvidence.js +71 -630
  16. package/dist/epistemicEvidence.js.map +1 -1
  17. package/dist/epistemicHelpers.js +3 -2
  18. package/dist/epistemicHelpers.js.map +1 -1
  19. package/dist/epistemicLinking.js.map +1 -1
  20. package/dist/epistemicNodes.js +49 -585
  21. package/dist/epistemicNodes.js.map +1 -1
  22. package/dist/epistemicQuestions.js +46 -590
  23. package/dist/epistemicQuestions.js.map +1 -1
  24. package/dist/epistemicSources.js +29 -565
  25. package/dist/epistemicSources.js.map +1 -1
  26. package/dist/evaluators/index.js +65 -624
  27. package/dist/evaluators/index.js.map +1 -1
  28. package/dist/index.js +304 -905
  29. package/dist/index.js.map +1 -1
  30. package/dist/ontologyApproval.js.map +1 -1
  31. package/dist/ontologyDefinitions.js.map +1 -1
  32. package/dist/ontologyRegistry.js.map +1 -1
  33. package/dist/projectionReconciliation.js.map +1 -1
  34. package/dist/questionEvidenceLinks.js +188 -2
  35. package/dist/questionEvidenceLinks.js.map +1 -1
  36. package/dist/workspaceIsolation.js +30 -581
  37. package/dist/workspaceIsolation.js.map +1 -1
  38. package/package.json +5 -6
@@ -1,5 +1,5 @@
1
1
  import { v } from 'convex/values';
2
- import { componentsGeneric, defineTable, mutationGeneric, anyApi, queryGeneric, internalQueryGeneric, internalMutationGeneric } from 'convex/server';
2
+ import { componentsGeneric, mutationGeneric, anyApi, queryGeneric, internalQueryGeneric, internalMutationGeneric } from 'convex/server';
3
3
 
4
4
  // src/epistemicEvidence.ts
5
5
  var api = anyApi;
@@ -1446,567 +1446,31 @@ var optionalScopeArgs = {
1446
1446
  projectId: v.optional(v.string()),
1447
1447
  topicId: v.optional(v.string())
1448
1448
  };
1449
- v.number();
1450
- v.union(
1451
- v.literal("very_high"),
1452
- // 0.9+
1453
- v.literal("high"),
1454
- // 0.7-0.9
1455
- v.literal("medium"),
1456
- // 0.4-0.7
1457
- v.literal("low"),
1458
- // 0.2-0.4
1459
- v.literal("very_low")
1460
- // 0-0.2
1461
- );
1462
- v.union(
1463
- v.literal(1),
1464
- // Critical
1465
- v.literal(2),
1466
- // High
1467
- v.literal(3),
1468
- // Medium
1469
- v.literal(4),
1470
- // Low
1471
- v.literal(5)
1472
- // Backlog
1473
- );
1474
- v.union(
1475
- v.literal("critical"),
1476
- v.literal("high"),
1477
- v.literal("medium"),
1478
- v.literal("low"),
1479
- v.literal("backlog")
1480
- );
1481
- v.union(
1482
- v.literal("active"),
1483
- v.literal("paused"),
1484
- v.literal("completed"),
1485
- v.literal("archived")
1486
- );
1487
- v.union(
1488
- v.literal("pending"),
1489
- v.literal("processing"),
1490
- v.literal("completed"),
1491
- v.literal("failed")
1492
- );
1493
- v.object({
1494
- crunchbaseId: v.optional(v.string()),
1495
- linkedinUrl: v.optional(v.string()),
1496
- pitchbookId: v.optional(v.string()),
1497
- twitterUrl: v.optional(v.string()),
1498
- domain: v.optional(v.string())
1499
- });
1500
- var sourceType = v.union(
1501
- v.literal("proprietary"),
1502
- // Internal Stack research
1503
- v.literal("primary"),
1504
- // Direct interviews, calls
1505
- v.literal("secondary"),
1506
- // Published sources
1507
- v.literal("ai_generated"),
1508
- // AI-synthesized
1509
- v.literal("user_input"),
1510
- // Manual user entry
1511
- v.literal("inferred")
1512
- // System inference
1513
- );
1514
- v.object({
1515
- sourceType: v.optional(sourceType),
1516
- sourceId: v.optional(v.string()),
1517
- // Reference to source entity
1518
- sourceUrl: v.optional(v.string()),
1519
- sourceDate: v.optional(v.number()),
1520
- sourceName: v.optional(v.string())
1521
- });
1522
- v.object({
1523
- cursor: v.optional(v.string()),
1524
- limit: v.optional(v.number())
1525
- });
1526
- v.object({
1527
- hasMore: v.boolean(),
1528
- nextCursor: v.optional(v.string()),
1529
- totalCount: v.optional(v.number())
1530
- });
1531
- var richTextContent = v.object({
1532
- type: v.literal("doc"),
1533
- content: looseJsonArray
1534
- });
1535
- v.union(v.string(), richTextContent);
1536
- v.object({
1537
- promptTokens: v.optional(v.number()),
1538
- completionTokens: v.optional(v.number()),
1539
- totalTokens: v.optional(v.number())
1540
- });
1541
- v.object({
1542
- fileName: v.optional(v.string()),
1543
- fileSize: v.optional(v.number()),
1544
- mimeType: v.optional(v.string()),
1545
- storageId: v.optional(v.id("_storage")),
1546
- externalUrl: v.optional(v.string())
1547
- });
1548
1449
 
1549
- // ../schema-management/src/spine/tables/epistemicNodes.ts
1550
- var nodeType = v.union(
1551
- // --- L4: Audit Targets (decisions, outcomes) ---
1552
- v.literal("decision"),
1553
- // Investment decision with knowledge horizon snapshot
1554
- // --- L3: Traversal Anchors (epistemic structure) ---
1555
- v.literal("belief"),
1556
- // Structured conviction (immutable formulation)
1557
- v.literal("question"),
1558
- // Unit of uncertainty
1559
- v.literal("theme"),
1560
- // Investment thesis / conviction cluster
1561
- v.literal("deal"),
1562
- // Investment evaluation process
1563
- v.literal("topic"),
1564
- // Hierarchical knowledge container
1565
- // --- L2: Compression Boundary (minimum reasoning unit) ---
1566
- v.literal("claim"),
1567
- // Atomic assertion that can be true/false
1568
- v.literal("evidence"),
1569
- // Interpreted signal linked to beliefs
1570
- v.literal("synthesis"),
1571
- // Primers, deep research
1572
- v.literal("answer"),
1573
- // Immutable answer snapshot for a question
1574
- // --- L1: Terminal Leaves (non-traversable, grounding) ---
1575
- v.literal("atomic_fact"),
1576
- // Raw fact from source (not interpreted)
1577
- v.literal("excerpt"),
1578
- // Direct quote from source document
1579
- v.literal("source"),
1580
- // News, documents, transcripts
1581
- // --- Ontological Entities (things in the world) ---
1582
- v.literal("company"),
1583
- // Organization (subtype: private, corporate, portfolio)
1584
- v.literal("person"),
1585
- // Individual (founder, expert, LP, contact)
1586
- v.literal("investor"),
1587
- // Investment entity (subtype: vc, lp, cvc, pe, family_office, angel)
1588
- v.literal("function"),
1589
- // What a company does (from classifier)
1590
- v.literal("value_chain")
1591
- // Market structure / value flow
1592
- );
1593
- var epistemicLayer = v.union(
1594
- v.literal("L4"),
1595
- // Decisions, outcomes - audit targets
1596
- v.literal("L3"),
1597
- // Beliefs, questions, themes - traversal anchors
1598
- v.literal("L2"),
1599
- // Claims, evidence, synthesis - compression boundary
1600
- v.literal("L1"),
1601
- // Atomic facts, excerpts, sources - terminal leaves
1602
- v.literal("ontological"),
1603
- // Companies, people, etc - not epistemic
1604
- v.literal("organizational")
1605
- // Topics, lenses, worktrees — structural containers
1606
- );
1607
- var nodeStatus = v.union(
1608
- v.literal("active"),
1609
- v.literal("superseded"),
1610
- // Replaced by newer version
1611
- v.literal("archived"),
1612
- v.literal("deleted")
1613
- );
1614
- var sourceType2 = v.union(
1615
- v.literal("human"),
1616
- // User created directly
1617
- v.literal("ai_extracted"),
1618
- // LLM extracted from a source
1619
- v.literal("ai_generated"),
1620
- // LLM synthesized/created
1621
- v.literal("imported"),
1622
- // External system import
1623
- v.literal("system"),
1624
- // System-generated (migrations, classifiers)
1625
- v.literal("verified"),
1626
- // Human-verified source
1627
- v.literal("proprietary")
1628
- // Proprietary/internal data
1629
- );
1630
- var verificationStatus = v.union(
1631
- v.literal("unverified"),
1632
- v.literal("human_verified"),
1633
- v.literal("ai_verified"),
1634
- v.literal("contradicted"),
1635
- v.literal("outdated")
1636
- );
1637
- var syncStatus = v.union(
1638
- v.literal("synced"),
1639
- // Node and edges fully synced to Neo4j
1640
- v.literal("pending_edges"),
1641
- // Node created, edges being created
1642
- v.literal("edge_creation_failed")
1643
- // Edge creation failed, needs retry
1644
- );
1645
- var audienceLabel = v.string();
1646
- var sensitivityTier = v.union(
1647
- v.literal("low"),
1648
- v.literal("medium"),
1649
- v.literal("high"),
1650
- v.literal("restricted")
1651
- );
1652
- var exportClass = v.union(
1653
- v.literal("internal_only"),
1654
- v.literal("client_safe"),
1655
- v.literal("public_safe"),
1656
- v.literal("restricted")
1657
- );
1658
- var anonymizationClass = v.union(
1659
- v.literal("none"),
1660
- v.literal("standard"),
1661
- v.literal("strict")
1662
- );
1663
- var epistemicStatus = v.union(
1664
- v.literal("hypothesis"),
1665
- // Initial conjecture, low evidence
1666
- v.literal("emerging"),
1667
- // Building evidence, gaining traction
1668
- v.literal("established"),
1669
- // Well-evidenced, core to thesis
1670
- v.literal("challenged"),
1671
- // Contradicting evidence appeared
1672
- v.literal("assumption"),
1673
- // Taken as given, not actively tested
1674
- v.literal("deprecated")
1675
- // Superseded or abandoned
1676
- );
1677
- var beliefStatus = v.union(
1678
- v.literal("assumption"),
1679
- v.literal("hypothesis"),
1680
- v.literal("belief"),
1681
- v.literal("fact")
1682
- );
1683
- var reversibility = v.union(
1684
- v.literal("irreversible"),
1685
- // One-way door decision
1686
- v.literal("hard_to_reverse"),
1687
- // Significant cost to undo
1688
- v.literal("reversible"),
1689
- // Can change course with moderate effort
1690
- v.literal("trivial")
1691
- // Easy to adjust
1692
- );
1693
- var predictionOutcome = v.union(
1694
- v.literal("pending"),
1695
- v.literal("confirmed"),
1696
- v.literal("disconfirmed"),
1697
- v.literal("partial"),
1698
- v.literal("expired")
1699
- );
1700
- var predictionMeta = v.object({
1701
- isPrediction: v.boolean(),
1702
- registeredAt: v.number(),
1703
- // When prediction was made
1704
- expectedBy: v.optional(v.number()),
1705
- // When we expect resolution
1706
- outcome: v.optional(predictionOutcome),
1707
- outcomeRecordedAt: v.optional(v.number()),
1708
- outcomeEvidenceId: v.optional(v.string()),
1709
- // globalId of confirming evidence
1710
- confidenceAtPrediction: v.optional(v.number()),
1711
- // 0-1
1712
- actualVsPredicted: v.optional(v.string())
1713
- // Notes on how outcome compared
1714
- });
1715
- var methodology = v.union(
1716
- // Primary Research (high value)
1717
- v.literal("primary_research"),
1718
- // Direct investigation
1719
- v.literal("expert_interview"),
1720
- // Expert call/interview
1721
- v.literal("customer_interview"),
1722
- // Customer research
1723
- v.literal("field_observation"),
1724
- // On-site observation
1725
- v.literal("proprietary_data"),
1726
- // Internal data analysis
1727
- // Secondary Research
1728
- v.literal("desk_research"),
1729
- // Public sources
1730
- v.literal("regulatory_filing"),
1731
- // SEC, regulatory docs
1732
- v.literal("news_article"),
1733
- // News/press
1734
- v.literal("academic_paper"),
1735
- // Academic research
1736
- // AI-Assisted
1737
- v.literal("ai_synthesis"),
1738
- // AI-generated synthesis
1739
- v.literal("ai_extraction")
1740
- // AI-extracted from source
1741
- );
1742
- var informationAsymmetry = v.union(
1743
- v.literal("proprietary"),
1744
- // Only we have this
1745
- v.literal("early"),
1746
- // We're early but others will get it
1747
- v.literal("common")
1748
- // Everyone has access
1749
- );
1750
- var temporalNature = v.union(
1751
- v.literal("factual"),
1752
- // Resolved outcome. Grounded in reality.
1753
- v.literal("forecast"),
1754
- // Prediction. Will resolve. Discounted weight.
1755
- v.literal("unknown")
1756
- // Not yet classified.
1757
- );
1758
- var questionType = v.union(
1759
- v.literal("validation"),
1760
- // Does evidence support this belief?
1761
- v.literal("falsification"),
1762
- // What would prove this belief wrong?
1763
- v.literal("assumption_probe"),
1764
- // Is this unstated assumption true?
1765
- v.literal("prediction_test"),
1766
- // Will this predicted outcome occur?
1767
- v.literal("counterfactual"),
1768
- // What would we expect if X were false?
1769
- v.literal("discovery"),
1770
- // What don't we know yet?
1771
- v.literal("clarification"),
1772
- // What does X actually mean?
1773
- v.literal("comparison"),
1774
- // How does X compare to Y?
1775
- v.literal("causal"),
1776
- // What caused X?
1777
- v.literal("mechanism"),
1778
- // How does X work?
1779
- v.literal("general")
1780
- // Unclassified
1781
- );
1782
- var questionPriority = v.union(
1783
- v.literal("critical"),
1784
- // Blocks decision-making
1785
- v.literal("high"),
1786
- // Important for thesis
1787
- v.literal("medium"),
1788
- // Would be nice to know
1789
- v.literal("low")
1790
- // Background/curiosity
1791
- );
1792
- var answerQuality = v.union(
1793
- v.literal("definitive"),
1794
- // Clear, well-supported
1795
- v.literal("strong"),
1796
- // Good evidence, high confidence
1797
- v.literal("moderate"),
1798
- // Some evidence
1799
- v.literal("weak"),
1800
- // Limited evidence
1801
- v.literal("speculative"),
1802
- // Mostly conjecture
1803
- v.literal("unanswered")
1804
- // No answer yet
1805
- );
1806
- var consensusView = v.union(
1807
- v.literal("aligned"),
1808
- // We agree with market consensus
1809
- v.literal("ahead_of"),
1810
- // We see this before consensus does
1811
- v.literal("contrarian"),
1812
- // We actively disagree with consensus
1813
- v.literal("orthogonal"),
1814
- // We're looking at something consensus isn't discussing
1815
- v.literal("unknown")
1816
- // We don't know what consensus thinks
1817
- );
1818
- var themeConviction = v.union(
1819
- v.literal("high"),
1820
- // Strong conviction, actively deploying
1821
- v.literal("medium"),
1822
- // Building conviction
1823
- v.literal("low"),
1824
- // Exploring, not convicted
1825
- v.literal("negative")
1826
- // Actively avoiding
1827
- );
1828
- var decisionType = v.union(
1829
- v.literal("invest"),
1830
- v.literal("pass"),
1831
- v.literal("follow_on"),
1832
- v.literal("exit"),
1833
- v.literal("deep_dive"),
1834
- v.literal("monitor"),
1835
- v.literal("deprioritize"),
1836
- v.literal("thesis_adopt"),
1837
- v.literal("thesis_revise"),
1838
- v.literal("thesis_abandon")
1839
- );
1840
- var decisionOutcome = v.union(
1841
- v.literal("pending"),
1842
- v.literal("successful"),
1843
- v.literal("unsuccessful"),
1844
- v.literal("mixed"),
1845
- v.literal("unknown")
1846
- );
1847
- var externalIds2 = v.object({
1848
- crunchbase: v.optional(v.string()),
1849
- linkedin: v.optional(v.string()),
1850
- pitchbook: v.optional(v.string()),
1851
- twitter: v.optional(v.string()),
1852
- website: v.optional(v.string())
1853
- });
1854
- defineTable({
1855
- // === IDENTITY ===
1856
- globalId: v.string(),
1857
- // UUID - survives migration to Neo4j
1858
- // === TYPE ===
1859
- nodeType,
1860
- // === EPISTEMIC LAYER ===
1861
- epistemicLayer: v.optional(epistemicLayer),
1862
- // === SUBTYPE (for typed entities) ===
1863
- subtype: v.optional(v.string()),
1864
- // company: private|corporate|portfolio, investor: vc|lp|cvc|pe|family_office|angel
1865
- // === CONTENT ===
1866
- canonicalText: v.string(),
1867
- // The core content (belief statement, company name, etc.)
1868
- contentHash: v.string(),
1869
- // SHA256(nodeType + canonicalText) for deduplication
1870
- // Extended content (for sources/syntheses)
1871
- content: v.optional(v.string()),
1872
- // Full text for documents/articles
1873
- contentType: v.optional(v.string()),
1874
- // "markdown", "html", "pdf", "text"
1875
- // === METADATA ===
1876
- title: v.optional(v.string()),
1877
- // Display title
1878
- tags: v.optional(v.array(v.string())),
1879
- domain: v.optional(v.string()),
1880
- // For companies: website domain
1881
- // Type-specific metadata (flexible object - LEGACY)
1882
- // New code should use the typed fields below when available
1883
- metadata: v.optional(looseJsonObject),
1884
- // === POLICY / ENTITLEMENT ===
1885
- tenantId: v.optional(v.string()),
1886
- workspaceId: v.optional(v.string()),
1887
- ownerPrincipalId: v.optional(v.string()),
1888
- audienceLabel: v.optional(audienceLabel),
1889
- policyTags: v.optional(v.array(v.string())),
1890
- sensitivityTier: v.optional(sensitivityTier),
1891
- exportClass: v.optional(exportClass),
1892
- anonymizationClass: v.optional(anonymizationClass),
1893
- // === PUBLICATION (visibility-based, not copy-based) ===
1894
- // Publication expands who can see a workspace-local node — the node stays
1895
- // in its workspace, like a microservice exposing part of its API surface.
1896
- // Rules-based: pack/tenant-level publicationRules auto-evaluate on
1897
- // confidence changes and node creation. No manual click-by-click.
1898
- publicationStatus: v.optional(
1899
- v.union(
1900
- v.literal("unpublished"),
1901
- // Default: workspace-local only
1902
- v.literal("published"),
1903
- // Visible at tenant scope (rules matched)
1904
- v.literal("suppressed")
1905
- // Manually blocked even if rules match
1906
- )
1907
- ),
1908
- publishedAt: v.optional(v.number()),
1909
- // When publication status last changed to published
1910
- publishedBy: v.optional(v.string()),
1911
- // userId or "system:publication_rules" for auto-publish
1912
- // === TYPED METADATA FIELDS ===
1913
- // --- Belief ---
1914
- // Belief type — validated against schemaEnumConfig category "belief_type"
1915
- // Platform core: hypothesis, belief, principle, invariant, assumption,
1916
- // tenet, prior, preference, goal, forecast
1917
- beliefType: v.optional(v.string()),
1918
- beliefStatus: v.optional(beliefStatus),
1919
- epistemicStatus: v.optional(epistemicStatus),
1920
- reversibility: v.optional(reversibility),
1921
- predictionMeta: v.optional(predictionMeta),
1922
- // Consensus tracking (for non-consensus detection)
1923
- consensusView: v.optional(consensusView),
1924
- consensusConfidence: v.optional(v.number()),
1925
- // 0-1: What we think consensus confidence is
1926
- consensusSource: v.optional(v.string()),
1927
- // Where we got the consensus view (twitter, reports, etc.)
1928
- // --- Evidence ---
1929
- methodology: v.optional(methodology),
1930
- informationAsymmetry: v.optional(informationAsymmetry),
1931
- temporalNature: v.optional(temporalNature),
1932
- // --- Question ---
1933
- questionType: v.optional(questionType),
1934
- questionPriority: v.optional(questionPriority),
1935
- answerQuality: v.optional(answerQuality),
1936
- // --- Theme ---
1937
- themeConviction: v.optional(themeConviction),
1938
- // Market timing (for "early on theme" detection)
1939
- marketAwarenessDate: v.optional(v.number()),
1940
- // When this theme became broadly discussed
1941
- marketAwarenessSource: v.optional(v.string()),
1942
- // How we know (first major report, twitter volume spike, etc.)
1943
- earlySignalIds: v.optional(v.array(v.string())),
1944
- // globalIds of evidence we had before market awareness
1945
- // --- Decision ---
1946
- decisionType: v.optional(decisionType),
1947
- decisionOutcome: v.optional(decisionOutcome),
1948
- // === EXTERNAL IDS (for ontological entities) ===
1949
- externalIds: v.optional(externalIds2),
1950
- // === PROVENANCE ===
1951
- sourceType: sourceType2,
1952
- aiProvider: v.optional(v.string()),
1953
- // "claude", "gemini", "gpt-4", etc.
1954
- extractedFromNodeId: v.optional(v.id("epistemicNodes")),
1955
- // Quick reference to source
1956
- // === EXTRACTION CONTEXT ===
1957
- extractionModel: v.optional(v.string()),
1958
- // "claude-sonnet-4-20250514"
1959
- extractionPromptName: v.optional(v.string()),
1960
- // "lucern/extract-evidence"
1961
- extractionPromptVersion: v.optional(v.number()),
1962
- extractionTemperature: v.optional(v.number()),
1963
- extractionLangfuseTraceId: v.optional(v.string()),
1964
- // === GROUNDING VERIFICATION ===
1965
- groundingVerified: v.optional(v.boolean()),
1966
- groundingConfidence: v.optional(v.number()),
1967
- // 0-1 match quality
1968
- groundingMatchedText: v.optional(v.string()),
1969
- // Actual text from source
1970
- groundingStartOffset: v.optional(v.number()),
1971
- groundingEndOffset: v.optional(v.number()),
1972
- groundingRejectionReason: v.optional(v.string()),
1973
- // === CONFIDENCE & VERIFICATION ===
1974
- confidence: v.optional(v.number()),
1975
- // 0-1 projected probability P(x) = b + a*u
1976
- verificationStatus: v.optional(verificationStatus),
1977
- // === SL OPINION (Subjective Logic — Kernel v2) ===
1978
- // Replaces scalar confidence with rich epistemic state.
1979
- // b + d + u = 1. P(x) = b + a*u is stored in `confidence` for backward compat.
1980
- opinion_b: v.optional(v.number()),
1981
- // Belief: evidence FOR (0-1)
1982
- opinion_d: v.optional(v.number()),
1983
- // Disbelief: evidence AGAINST (0-1)
1984
- opinion_u: v.optional(v.number()),
1985
- // Uncertainty: absence of evidence (0-1)
1986
- opinion_a: v.optional(v.number()),
1987
- // Base rate / prior probability (0-1)
1988
- tupleContradicted: v.optional(v.boolean()),
1989
- // Single-belief tuple-space contradiction flag
1990
- // === LIFECYCLE ===
1991
- status: nodeStatus,
1992
- supersededBy: v.optional(v.id("epistemicNodes")),
1993
- // === OWNERSHIP ===
1994
- topicId: v.optional(v.string()),
1995
- // Canonical scope container (topic-first model)
1996
- projectId: v.optional(v.string()),
1997
- // DEPRECATED: Use belongs_to edges
1998
- createdBy: v.string(),
1999
- // Clerk user ID
2000
- createdAt: v.number(),
2001
- updatedAt: v.number(),
2002
- // === NEO4J SYNC STATUS ===
2003
- syncStatus: v.optional(syncStatus),
2004
- syncError: v.optional(v.string())
2005
- // Error message if sync failed
2006
- }).index("by_globalId", ["globalId"]).index("by_contentHash", ["contentHash"]).index("by_nodeType", ["nodeType"]).index("by_subtype", ["nodeType", "subtype"]).index("by_domain", ["domain"]).index("by_project", ["projectId"]).index("by_project_type", ["projectId", "nodeType"]).index("by_topic", ["topicId"]).index("by_topic_type", ["topicId", "nodeType"]).index("by_tenantId", ["tenantId"]).index("by_workspaceId", ["workspaceId"]).index("by_tenant_workspace", ["tenantId", "workspaceId"]).index("by_audienceLabel", ["audienceLabel"]).index("by_sensitivityTier", ["sensitivityTier"]).index("by_exportClass", ["exportClass"]).index("by_status", ["status"]).index("by_sourceType", ["sourceType"]).index("by_verification", ["verificationStatus"]).index("by_layer", ["epistemicLayer"]).index("by_layer_type", ["epistemicLayer", "nodeType"]).index("by_syncStatus", ["syncStatus"]).index("by_publicationStatus", ["publicationStatus"]).index("by_tenant_publicationStatus", ["tenantId", "publicationStatus"]).index("by_belief_status", ["nodeType", "beliefStatus"]).index("by_epistemic_status", ["nodeType", "epistemicStatus"]).index("by_temporal_nature", ["nodeType", "temporalNature"]).index("by_methodology", ["nodeType", "methodology"]).index("by_reversibility", ["nodeType", "reversibility"]).index("by_questionType", ["nodeType", "questionType"]).index("by_questionPriority", ["nodeType", "questionPriority"]).searchIndex("search_canonicalText", {
2007
- searchField: "canonicalText",
2008
- filterFields: ["nodeType", "projectId", "topicId", "status"]
2009
- });
1450
+ // ../../packages/contracts/src/schema-helpers/spine/tables/epistemicNodes.ts
1451
+ var NODE_TYPES = [
1452
+ "decision",
1453
+ "belief",
1454
+ "question",
1455
+ "theme",
1456
+ "deal",
1457
+ "topic",
1458
+ "claim",
1459
+ "evidence",
1460
+ "synthesis",
1461
+ "answer",
1462
+ "atomic_fact",
1463
+ "excerpt",
1464
+ "source",
1465
+ "company",
1466
+ "person",
1467
+ "investor",
1468
+ "function",
1469
+ "value_chain"
1470
+ ];
1471
+ function isNodeType(value) {
1472
+ return NODE_TYPES.includes(value);
1473
+ }
2010
1474
  function getLayerForNodeType(type) {
2011
1475
  switch (type) {
2012
1476
  case "decision":
@@ -2054,7 +1518,7 @@ function throwWorkspaceIsolationError(args) {
2054
1518
  throw error;
2055
1519
  }
2056
1520
  function assertWorkspaceScopedEpistemicNodeScope(args) {
2057
- const layer = getLayerForNodeType(args.nodeType);
1521
+ const layer = isNodeType(args.nodeType) ? getLayerForNodeType(args.nodeType) : void 0;
2058
1522
  if (layer === "ontological") {
2059
1523
  return;
2060
1524
  }
@@ -2082,11 +1546,11 @@ function nodeMatchesWorkspaceReasoningScope(node, scope) {
2082
1546
  const scopeWorkspaceId = normalizeScopeValue2(scope.workspaceId);
2083
1547
  const nodeTenantId = normalizeScopeValue2(node.tenantId);
2084
1548
  const nodeWorkspaceId = normalizeScopeValue2(node.workspaceId);
2085
- const epistemicLayer2 = typeof node.epistemicLayer === "string" ? node.epistemicLayer : void 0;
1549
+ const epistemicLayer = typeof node.epistemicLayer === "string" ? node.epistemicLayer : void 0;
2086
1550
  if (scopeTenantId && nodeTenantId && scopeTenantId !== nodeTenantId) {
2087
1551
  return false;
2088
1552
  }
2089
- if (epistemicLayer2 === "ontological" && nodeWorkspaceId === void 0) {
1553
+ if (epistemicLayer === "ontological" && nodeWorkspaceId === void 0) {
2090
1554
  return true;
2091
1555
  }
2092
1556
  if (!scopeWorkspaceId && node.publicationStatus === "published") {
@@ -2133,10 +1597,10 @@ function assertTenantPackWorkspaceMutationAllowed(args) {
2133
1597
 
2134
1598
  // src/epistemicEvidence.ts
2135
1599
  function generateContentHash(text) {
2136
- const content2 = `evidence:${text.trim().toLowerCase().replace(/\s+/g, " ").slice(0, 500)}`;
1600
+ const content = `evidence:${text.trim().toLowerCase().replace(/\s+/g, " ").slice(0, 500)}`;
2137
1601
  let hash = 5381;
2138
- for (let i = 0; i < content2.length; i++) {
2139
- hash = (hash << 5) + hash + content2.charCodeAt(i);
1602
+ for (let i = 0; i < content.length; i++) {
1603
+ hash = (hash << 5) + hash + content.charCodeAt(i);
2140
1604
  hash &= hash;
2141
1605
  }
2142
1606
  return Math.abs(hash).toString(16).padStart(8, "0");
@@ -2155,9 +1619,9 @@ function normalizeKind(kind) {
2155
1619
  ];
2156
1620
  return validKinds.find((k) => kind.toLowerCase() === k) || "observation";
2157
1621
  }
2158
- function normalizeSourceType(sourceType3) {
2159
- if (sourceType3 === "proprietary" || sourceType3 === "verified") {
2160
- return sourceType3;
1622
+ function normalizeSourceType(sourceType) {
1623
+ if (sourceType === "proprietary" || sourceType === "verified") {
1624
+ return sourceType;
2161
1625
  }
2162
1626
  return "ai_generated";
2163
1627
  }
@@ -2245,23 +1709,14 @@ async function resolveEvidenceScopeOrNull(ctx, args) {
2245
1709
  }
2246
1710
  async function getEvidenceNodesForScope(ctx, scope, args) {
2247
1711
  const scanLimit = typeof args?.scanLimit === "number" ? args.scanLimit : void 0;
2248
- const [topicNodes, projectNodes] = await Promise.all([
2249
- scope.topicId ? scanLimit ? ctx.db.query("epistemicNodes").withIndex(
2250
- "by_topic_type",
2251
- (q) => q.eq("topicId", scope.topicId).eq("nodeType", "evidence")
2252
- ).order("desc").take(scanLimit) : ctx.db.query("epistemicNodes").withIndex(
2253
- "by_topic_type",
2254
- (q) => q.eq("topicId", scope.topicId).eq("nodeType", "evidence")
2255
- ).collect() : Promise.resolve([]),
2256
- scope.projectId ? scanLimit ? ctx.db.query("epistemicNodes").withIndex(
2257
- "by_project_type",
2258
- (q) => q.eq("projectId", scope.projectId).eq("nodeType", "evidence")
2259
- ).order("desc").take(scanLimit) : ctx.db.query("epistemicNodes").withIndex(
2260
- "by_project_type",
2261
- (q) => q.eq("projectId", scope.projectId).eq("nodeType", "evidence")
2262
- ).collect() : Promise.resolve([])
2263
- ]);
2264
- return dedupeEvidenceNodes([...topicNodes, ...projectNodes]).filter(
1712
+ const topicNodes = await (scanLimit ? ctx.db.query("epistemicNodes").withIndex(
1713
+ "by_topic_type",
1714
+ (q) => q.eq("topicId", scope.topicId).eq("nodeType", "evidence")
1715
+ ).order("desc").take(scanLimit) : ctx.db.query("epistemicNodes").withIndex(
1716
+ "by_topic_type",
1717
+ (q) => q.eq("topicId", scope.topicId).eq("nodeType", "evidence")
1718
+ ).collect());
1719
+ return dedupeEvidenceNodes(topicNodes).filter(
2265
1720
  (node) => evidenceMatchesScope(node, scope)
2266
1721
  );
2267
1722
  }
@@ -2342,7 +1797,7 @@ var create = mutation({
2342
1797
  const globalId = generateGlobalId();
2343
1798
  const contentHash = generateContentHash(args.text);
2344
1799
  const kind = normalizeKind(args.kind);
2345
- const sourceType3 = normalizeSourceType(args.sourceType);
1800
+ const sourceType = normalizeSourceType(args.sourceType);
2346
1801
  const additionalMetadata = args.metadata && typeof args.metadata === "object" ? args.metadata : {};
2347
1802
  const nodeId = await ctx.db.insert("epistemicNodes", {
2348
1803
  globalId,
@@ -2359,7 +1814,7 @@ var create = mutation({
2359
1814
  status: "active",
2360
1815
  epistemicLayer: "L2",
2361
1816
  // L2: Compression Boundary (Evidence/Claims)
2362
- sourceType: sourceType3,
1817
+ sourceType,
2363
1818
  createdAt: now,
2364
1819
  updatedAt: now,
2365
1820
  createdBy: args.userId,
@@ -2425,7 +1880,7 @@ var create = mutation({
2425
1880
  newState: {
2426
1881
  text: args.text.slice(0, 200),
2427
1882
  kind,
2428
- sourceType: sourceType3,
1883
+ sourceType,
2429
1884
  linkedBeliefNodeId: args.linkedBeliefNodeId,
2430
1885
  evidenceRelation: args.evidenceRelation
2431
1886
  }
@@ -2484,8 +1939,8 @@ var createAndLink = mutation({
2484
1939
  const globalId = generateGlobalId();
2485
1940
  const contentHash = generateContentHash(args.text);
2486
1941
  const kind = normalizeKind(args.kind);
2487
- const sourceType3 = normalizeSourceType(args.sourceType);
2488
- const confidence2 = args.confidence ?? 0.7;
1942
+ const sourceType = normalizeSourceType(args.sourceType);
1943
+ const confidence = args.confidence ?? 0.7;
2489
1944
  const nodeId = await ctx.db.insert("epistemicNodes", {
2490
1945
  globalId,
2491
1946
  topicId: scope.topicId,
@@ -2497,7 +1952,7 @@ var createAndLink = mutation({
2497
1952
  contentHash,
2498
1953
  status: "active",
2499
1954
  epistemicLayer: "L2",
2500
- sourceType: sourceType3,
1955
+ sourceType,
2501
1956
  createdAt: now,
2502
1957
  updatedAt: now,
2503
1958
  createdBy: args.userId,
@@ -2506,7 +1961,7 @@ var createAndLink = mutation({
2506
1961
  tags: args.tags || [],
2507
1962
  linkedBeliefNodeId: args.beliefNodeId,
2508
1963
  evidenceRelation: args.relation,
2509
- confidence: confidence2
1964
+ confidence
2510
1965
  }
2511
1966
  });
2512
1967
  await ctx.scheduler.runAfter(0, internal.neo4jSync.syncNodeToNeo4j, {
@@ -2517,7 +1972,7 @@ var createAndLink = mutation({
2517
1972
  if (!beliefNode) {
2518
1973
  throw new Error("Belief node not found for edge creation");
2519
1974
  }
2520
- const weight = args.relation === "supports" ? confidence2 : -confidence2;
1975
+ const weight = args.relation === "supports" ? confidence : -confidence;
2521
1976
  const edgeGlobalId = crypto.randomUUID();
2522
1977
  await ctx.scheduler.runAfter(5e3, internal.neo4jEdgeAPI.createEdge, {
2523
1978
  globalId: edgeGlobalId,
@@ -2533,7 +1988,7 @@ var createAndLink = mutation({
2533
1988
  toLayer: "L3",
2534
1989
  metadata: {
2535
1990
  relation: args.relation,
2536
- confidence: confidence2
1991
+ confidence
2537
1992
  }
2538
1993
  });
2539
1994
  await markProjectGraphDirty(ctx, scope.projectId, String(scope.topicId));
@@ -2634,20 +2089,13 @@ var getByProject = query({
2634
2089
  return [];
2635
2090
  }
2636
2091
  }
2637
- const [topicNodes, projectNodes] = await Promise.all([
2638
- scope.topicId ? ctx.db.query("epistemicNodes").withIndex(
2639
- "by_topic_type",
2640
- (q) => q.eq("topicId", scope.topicId).eq("nodeType", "evidence")
2641
- ).order("desc").take(scanLimit) : Promise.resolve([]),
2642
- scope.projectId ? ctx.db.query("epistemicNodes").withIndex(
2643
- "by_project_type",
2644
- (q) => q.eq("projectId", scope.projectId).eq("nodeType", "evidence")
2645
- ).order("desc").take(scanLimit) : Promise.resolve([])
2646
- ]);
2647
- const scopedNodes = dedupeEvidenceNodes([
2648
- ...topicNodes,
2649
- ...projectNodes
2650
- ]).filter((node) => evidenceMatchesScope(node, scope));
2092
+ const topicNodes = await ctx.db.query("epistemicNodes").withIndex(
2093
+ "by_topic_type",
2094
+ (q) => q.eq("topicId", scope.topicId).eq("nodeType", "evidence")
2095
+ ).order("desc").take(scanLimit);
2096
+ const scopedNodes = dedupeEvidenceNodes(topicNodes).filter(
2097
+ (node) => evidenceMatchesScope(node, scope)
2098
+ );
2651
2099
  const filteredNodes = args.status ? scopedNodes.filter((node) => node.status === args.status) : scopedNodes;
2652
2100
  return filteredNodes.map(flattenEvidenceNode).slice(0, pageSize);
2653
2101
  }
@@ -2664,20 +2112,13 @@ var getByTopic = query({
2664
2112
  const pageSize = clampEvidenceLimit(args.limit);
2665
2113
  const scanLimit = Math.min(pageSize * 3, MAX_EVIDENCE_PAGE_SIZE);
2666
2114
  const scope = await resolveTopicProjectScope(ctx, { topicId: args.topicId });
2667
- const [topicNodes, projectNodes] = await Promise.all([
2668
- ctx.db.query("epistemicNodes").withIndex(
2669
- "by_topic_type",
2670
- (q) => q.eq("topicId", args.topicId).eq("nodeType", "evidence")
2671
- ).order("desc").take(scanLimit),
2672
- scope.projectId ? ctx.db.query("epistemicNodes").withIndex(
2673
- "by_project_type",
2674
- (q) => q.eq("projectId", scope.projectId).eq("nodeType", "evidence")
2675
- ).order("desc").take(scanLimit) : Promise.resolve([])
2676
- ]);
2677
- const scopedNodes = dedupeEvidenceNodes([
2678
- ...topicNodes,
2679
- ...projectNodes
2680
- ]).filter((node) => evidenceMatchesScope(node, scope));
2115
+ const topicNodes = await ctx.db.query("epistemicNodes").withIndex(
2116
+ "by_topic_type",
2117
+ (q) => q.eq("topicId", scope.topicId).eq("nodeType", "evidence")
2118
+ ).order("desc").take(scanLimit);
2119
+ const scopedNodes = dedupeEvidenceNodes(topicNodes).filter(
2120
+ (node) => evidenceMatchesScope(node, scope)
2121
+ );
2681
2122
  const filteredNodes = args.status ? scopedNodes.filter((node) => node.status === args.status) : scopedNodes;
2682
2123
  return filteredNodes.map(flattenEvidenceNode).slice(0, pageSize);
2683
2124
  }
@@ -2879,7 +2320,7 @@ var internalCreate = internalMutation({
2879
2320
  const globalId = generateGlobalId();
2880
2321
  const contentHash = generateContentHash(args.text);
2881
2322
  const kind = normalizeKind(args.kind);
2882
- const sourceType3 = normalizeSourceType(args.sourceType);
2323
+ const sourceType = normalizeSourceType(args.sourceType);
2883
2324
  const additionalMetadata = args.metadata && typeof args.metadata === "object" ? args.metadata : {};
2884
2325
  const nodeId = await ctx.db.insert("epistemicNodes", {
2885
2326
  globalId,
@@ -2895,7 +2336,7 @@ var internalCreate = internalMutation({
2895
2336
  ...typeof args.contentType === "string" && args.contentType.trim().length > 0 ? { contentType: args.contentType.trim() } : {},
2896
2337
  status: "active",
2897
2338
  epistemicLayer: "L2",
2898
- sourceType: sourceType3,
2339
+ sourceType,
2899
2340
  createdAt: now,
2900
2341
  updatedAt: now,
2901
2342
  createdBy: args.userId,
@@ -2922,7 +2363,7 @@ var internalCreate = internalMutation({
2922
2363
  newState: {
2923
2364
  text: args.text.slice(0, 200),
2924
2365
  kind,
2925
- sourceType: sourceType3,
2366
+ sourceType,
2926
2367
  externalSourceType: args.externalSourceType,
2927
2368
  sourceUrl: args.sourceUrl,
2928
2369
  linkedBeliefNodeId: args.linkedBeliefNodeId,
@@ -2938,8 +2379,8 @@ var internalCreate = internalMutation({
2938
2379
  if (args.linkedBeliefNodeId && args.evidenceRelation) {
2939
2380
  const beliefNode = await ctx.db.get(args.linkedBeliefNodeId);
2940
2381
  if (beliefNode) {
2941
- const confidence2 = args.confidence ?? 0.7;
2942
- const weight = args.evidenceRelation === "supports" ? confidence2 : -confidence2;
2382
+ const confidence = args.confidence ?? 0.7;
2383
+ const weight = args.evidenceRelation === "supports" ? confidence : -confidence;
2943
2384
  await ctx.scheduler.runAfter(5e3, internal.neo4jEdgeAPI.createEdge, {
2944
2385
  globalId: crypto.randomUUID(),
2945
2386
  fromGlobalId: globalId,
@@ -2954,7 +2395,7 @@ var internalCreate = internalMutation({
2954
2395
  toLayer: "L3",
2955
2396
  metadata: {
2956
2397
  relation: args.evidenceRelation,
2957
- confidence: confidence2
2398
+ confidence
2958
2399
  }
2959
2400
  });
2960
2401
  }