@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, internalMutationGeneric, mutationGeneric, anyApi, queryGeneric, internalQueryGeneric } from 'convex/server';
2
+ import { componentsGeneric, internalMutationGeneric, mutationGeneric, anyApi, queryGeneric, internalQueryGeneric } from 'convex/server';
3
3
 
4
4
  // src/epistemicBeliefs.ts
5
5
 
@@ -1283,10 +1283,8 @@ async function getCurrentUserId(ctx) {
1283
1283
  const identity = await ctx.auth.getUserIdentity();
1284
1284
  return identity?.subject ?? null;
1285
1285
  }
1286
- componentsGeneric();
1287
- var internal = anyApi;
1288
1286
 
1289
- // ../schema-management/src/enumValidation.ts
1287
+ // ../../packages/contracts/src/schema-helpers/enumValidation.ts
1290
1288
  var BUILTIN_ENUM_FALLBACK = {
1291
1289
  topic_type: /* @__PURE__ */ new Set([
1292
1290
  "domain",
@@ -1329,7 +1327,6 @@ var BUILTIN_ENUM_FALLBACK = {
1329
1327
  "tradeoff",
1330
1328
  "policy",
1331
1329
  "implementation_choice",
1332
- // Coding intelligence domain
1333
1330
  "implementation_decision",
1334
1331
  "interface_contract",
1335
1332
  "migration_state",
@@ -1337,25 +1334,16 @@ var BUILTIN_ENUM_FALLBACK = {
1337
1334
  "deprecation_notice"
1338
1335
  ]),
1339
1336
  edge_type: /* @__PURE__ */ new Set([
1340
- // === 6 CANONICAL EPISTEMIC TYPES ===
1341
1337
  "supports",
1342
- // L3↔L3: belief bears on belief (weight -1 to +1)
1343
1338
  "informs",
1344
- // L2→L3: evidence bears on belief
1345
1339
  "depends_on",
1346
- // L3→L3, Q→Q: structural gate
1347
1340
  "derived_from",
1348
- // Any→Any: provenance chain
1349
1341
  "contains",
1350
- // Any→Any: hierarchy, scoping, membership
1351
1342
  "tests",
1352
- // Q→L3: question interrogates belief
1353
- // === STRUCTURAL / LIFECYCLE ===
1354
1343
  "supersedes",
1355
1344
  "responds_to",
1356
1345
  "belongs_to",
1357
1346
  "relates_to_thesis",
1358
- // === ONTOLOGICAL (tenant-extensible) ===
1359
1347
  "works_at",
1360
1348
  "invested_in",
1361
1349
  "competes_with",
@@ -1404,27 +1392,12 @@ var BUILTIN_ENUM_FALLBACK = {
1404
1392
  function normalizeEnumValue(value) {
1405
1393
  return value.trim().toLowerCase();
1406
1394
  }
1407
- async function validateSchemaEnumValue(ctx, args) {
1395
+ async function validateSchemaEnumValue(_ctx, args) {
1408
1396
  const normalized = normalizeEnumValue(args.value);
1409
1397
  if (!normalized) {
1410
1398
  return { valid: false, source: "none" };
1411
1399
  }
1412
- try {
1413
- const validFromSchema = await ctx.runQuery(
1414
- internal.schemaConfig.internalValidate,
1415
- {
1416
- category: args.category,
1417
- value: normalized,
1418
- tenantId: args.tenantId
1419
- }
1420
- );
1421
- if (validFromSchema) {
1422
- return { valid: true, source: "schema" };
1423
- }
1424
- } catch {
1425
- }
1426
- const fallback = BUILTIN_ENUM_FALLBACK[args.category];
1427
- if (fallback.has(normalized)) {
1400
+ if (BUILTIN_ENUM_FALLBACK[args.category].has(normalized)) {
1428
1401
  return { valid: true, source: "builtin" };
1429
1402
  }
1430
1403
  return { valid: false, source: "none" };
@@ -1445,7 +1418,7 @@ async function assertSchemaEnumValue(ctx, args) {
1445
1418
  if (!validation.valid) {
1446
1419
  const tenantHint = args.tenantId ? ` for tenant ${args.tenantId}` : "";
1447
1420
  throw new Error(
1448
- `[${args.context}] Invalid value "${normalized}" for category "${args.category}"${tenantHint}. Add it to schemaEnumConfig before use.`
1421
+ `[${args.context}] Invalid value "${normalized}" for category "${args.category}"${tenantHint}. Add it to the contracts schema enum manifest before use.`
1449
1422
  );
1450
1423
  }
1451
1424
  return normalized;
@@ -1478,30 +1451,30 @@ var RESOLVED_PREDICTION_OUTCOMES = [
1478
1451
  function isBeliefLifecycleStatus(value) {
1479
1452
  return typeof value === "string" && BELIEF_STATUS_VALUES.includes(value);
1480
1453
  }
1481
- function normalizeBeliefConfidence(confidence2) {
1482
- if (typeof confidence2 !== "number" || !Number.isFinite(confidence2)) {
1454
+ function normalizeBeliefConfidence(confidence) {
1455
+ if (typeof confidence !== "number" || !Number.isFinite(confidence)) {
1483
1456
  return null;
1484
1457
  }
1485
- if (confidence2 >= 0 && confidence2 <= 1) {
1486
- return confidence2;
1458
+ if (confidence >= 0 && confidence <= 1) {
1459
+ return confidence;
1487
1460
  }
1488
- if (confidence2 > 1 && confidence2 <= 100) {
1489
- return confidence2 / 100;
1461
+ if (confidence > 1 && confidence <= 100) {
1462
+ return confidence / 100;
1490
1463
  }
1491
1464
  return null;
1492
1465
  }
1493
- function isResolvedByConfidence(confidence2) {
1494
- const normalized = normalizeBeliefConfidence(confidence2);
1466
+ function isResolvedByConfidence(confidence) {
1467
+ const normalized = normalizeBeliefConfidence(confidence);
1495
1468
  if (normalized === null) {
1496
1469
  return false;
1497
1470
  }
1498
1471
  return normalized <= 0 || normalized >= 1;
1499
1472
  }
1500
- function hasResolvedPredictionOutcome(predictionMeta2) {
1501
- if (!predictionMeta2 || typeof predictionMeta2 !== "object") {
1473
+ function hasResolvedPredictionOutcome(predictionMeta) {
1474
+ if (!predictionMeta || typeof predictionMeta !== "object") {
1502
1475
  return false;
1503
1476
  }
1504
- const outcome = predictionMeta2.outcome;
1477
+ const outcome = predictionMeta.outcome;
1505
1478
  return typeof outcome === "string" && RESOLVED_PREDICTION_OUTCOMES.includes(outcome);
1506
1479
  }
1507
1480
  function getPredictionMetaFromMetadata(metadata) {
@@ -1555,7 +1528,7 @@ function promoteBeliefStatusAfterScoring(status, opts) {
1555
1528
  }
1556
1529
  var api2 = anyApi;
1557
1530
  componentsGeneric();
1558
- var internal2 = anyApi;
1531
+ var internal = anyApi;
1559
1532
  var internalMutation = internalMutationGeneric;
1560
1533
  var internalQuery = internalQueryGeneric;
1561
1534
  var mutation = mutationGeneric;
@@ -1839,567 +1812,31 @@ function getTraversalDirections(direction) {
1839
1812
  }
1840
1813
  return ["outgoing", "incoming"];
1841
1814
  }
1842
- v.number();
1843
- v.union(
1844
- v.literal("very_high"),
1845
- // 0.9+
1846
- v.literal("high"),
1847
- // 0.7-0.9
1848
- v.literal("medium"),
1849
- // 0.4-0.7
1850
- v.literal("low"),
1851
- // 0.2-0.4
1852
- v.literal("very_low")
1853
- // 0-0.2
1854
- );
1855
- v.union(
1856
- v.literal(1),
1857
- // Critical
1858
- v.literal(2),
1859
- // High
1860
- v.literal(3),
1861
- // Medium
1862
- v.literal(4),
1863
- // Low
1864
- v.literal(5)
1865
- // Backlog
1866
- );
1867
- v.union(
1868
- v.literal("critical"),
1869
- v.literal("high"),
1870
- v.literal("medium"),
1871
- v.literal("low"),
1872
- v.literal("backlog")
1873
- );
1874
- v.union(
1875
- v.literal("active"),
1876
- v.literal("paused"),
1877
- v.literal("completed"),
1878
- v.literal("archived")
1879
- );
1880
- v.union(
1881
- v.literal("pending"),
1882
- v.literal("processing"),
1883
- v.literal("completed"),
1884
- v.literal("failed")
1885
- );
1886
- v.object({
1887
- crunchbaseId: v.optional(v.string()),
1888
- linkedinUrl: v.optional(v.string()),
1889
- pitchbookId: v.optional(v.string()),
1890
- twitterUrl: v.optional(v.string()),
1891
- domain: v.optional(v.string())
1892
- });
1893
- var sourceType = v.union(
1894
- v.literal("proprietary"),
1895
- // Internal Stack research
1896
- v.literal("primary"),
1897
- // Direct interviews, calls
1898
- v.literal("secondary"),
1899
- // Published sources
1900
- v.literal("ai_generated"),
1901
- // AI-synthesized
1902
- v.literal("user_input"),
1903
- // Manual user entry
1904
- v.literal("inferred")
1905
- // System inference
1906
- );
1907
- v.object({
1908
- sourceType: v.optional(sourceType),
1909
- sourceId: v.optional(v.string()),
1910
- // Reference to source entity
1911
- sourceUrl: v.optional(v.string()),
1912
- sourceDate: v.optional(v.number()),
1913
- sourceName: v.optional(v.string())
1914
- });
1915
- v.object({
1916
- cursor: v.optional(v.string()),
1917
- limit: v.optional(v.number())
1918
- });
1919
- v.object({
1920
- hasMore: v.boolean(),
1921
- nextCursor: v.optional(v.string()),
1922
- totalCount: v.optional(v.number())
1923
- });
1924
- var richTextContent = v.object({
1925
- type: v.literal("doc"),
1926
- content: looseJsonArray
1927
- });
1928
- v.union(v.string(), richTextContent);
1929
- v.object({
1930
- promptTokens: v.optional(v.number()),
1931
- completionTokens: v.optional(v.number()),
1932
- totalTokens: v.optional(v.number())
1933
- });
1934
- v.object({
1935
- fileName: v.optional(v.string()),
1936
- fileSize: v.optional(v.number()),
1937
- mimeType: v.optional(v.string()),
1938
- storageId: v.optional(v.id("_storage")),
1939
- externalUrl: v.optional(v.string())
1940
- });
1941
1815
 
1942
- // ../schema-management/src/spine/tables/epistemicNodes.ts
1943
- var nodeType = v.union(
1944
- // --- L4: Audit Targets (decisions, outcomes) ---
1945
- v.literal("decision"),
1946
- // Investment decision with knowledge horizon snapshot
1947
- // --- L3: Traversal Anchors (epistemic structure) ---
1948
- v.literal("belief"),
1949
- // Structured conviction (immutable formulation)
1950
- v.literal("question"),
1951
- // Unit of uncertainty
1952
- v.literal("theme"),
1953
- // Investment thesis / conviction cluster
1954
- v.literal("deal"),
1955
- // Investment evaluation process
1956
- v.literal("topic"),
1957
- // Hierarchical knowledge container
1958
- // --- L2: Compression Boundary (minimum reasoning unit) ---
1959
- v.literal("claim"),
1960
- // Atomic assertion that can be true/false
1961
- v.literal("evidence"),
1962
- // Interpreted signal linked to beliefs
1963
- v.literal("synthesis"),
1964
- // Primers, deep research
1965
- v.literal("answer"),
1966
- // Immutable answer snapshot for a question
1967
- // --- L1: Terminal Leaves (non-traversable, grounding) ---
1968
- v.literal("atomic_fact"),
1969
- // Raw fact from source (not interpreted)
1970
- v.literal("excerpt"),
1971
- // Direct quote from source document
1972
- v.literal("source"),
1973
- // News, documents, transcripts
1974
- // --- Ontological Entities (things in the world) ---
1975
- v.literal("company"),
1976
- // Organization (subtype: private, corporate, portfolio)
1977
- v.literal("person"),
1978
- // Individual (founder, expert, LP, contact)
1979
- v.literal("investor"),
1980
- // Investment entity (subtype: vc, lp, cvc, pe, family_office, angel)
1981
- v.literal("function"),
1982
- // What a company does (from classifier)
1983
- v.literal("value_chain")
1984
- // Market structure / value flow
1985
- );
1986
- var epistemicLayer = v.union(
1987
- v.literal("L4"),
1988
- // Decisions, outcomes - audit targets
1989
- v.literal("L3"),
1990
- // Beliefs, questions, themes - traversal anchors
1991
- v.literal("L2"),
1992
- // Claims, evidence, synthesis - compression boundary
1993
- v.literal("L1"),
1994
- // Atomic facts, excerpts, sources - terminal leaves
1995
- v.literal("ontological"),
1996
- // Companies, people, etc - not epistemic
1997
- v.literal("organizational")
1998
- // Topics, lenses, worktrees — structural containers
1999
- );
2000
- var nodeStatus = v.union(
2001
- v.literal("active"),
2002
- v.literal("superseded"),
2003
- // Replaced by newer version
2004
- v.literal("archived"),
2005
- v.literal("deleted")
2006
- );
2007
- var sourceType2 = v.union(
2008
- v.literal("human"),
2009
- // User created directly
2010
- v.literal("ai_extracted"),
2011
- // LLM extracted from a source
2012
- v.literal("ai_generated"),
2013
- // LLM synthesized/created
2014
- v.literal("imported"),
2015
- // External system import
2016
- v.literal("system"),
2017
- // System-generated (migrations, classifiers)
2018
- v.literal("verified"),
2019
- // Human-verified source
2020
- v.literal("proprietary")
2021
- // Proprietary/internal data
2022
- );
2023
- var verificationStatus = v.union(
2024
- v.literal("unverified"),
2025
- v.literal("human_verified"),
2026
- v.literal("ai_verified"),
2027
- v.literal("contradicted"),
2028
- v.literal("outdated")
2029
- );
2030
- var syncStatus = v.union(
2031
- v.literal("synced"),
2032
- // Node and edges fully synced to Neo4j
2033
- v.literal("pending_edges"),
2034
- // Node created, edges being created
2035
- v.literal("edge_creation_failed")
2036
- // Edge creation failed, needs retry
2037
- );
2038
- var audienceLabel = v.string();
2039
- var sensitivityTier = v.union(
2040
- v.literal("low"),
2041
- v.literal("medium"),
2042
- v.literal("high"),
2043
- v.literal("restricted")
2044
- );
2045
- var exportClass = v.union(
2046
- v.literal("internal_only"),
2047
- v.literal("client_safe"),
2048
- v.literal("public_safe"),
2049
- v.literal("restricted")
2050
- );
2051
- var anonymizationClass = v.union(
2052
- v.literal("none"),
2053
- v.literal("standard"),
2054
- v.literal("strict")
2055
- );
2056
- var epistemicStatus = v.union(
2057
- v.literal("hypothesis"),
2058
- // Initial conjecture, low evidence
2059
- v.literal("emerging"),
2060
- // Building evidence, gaining traction
2061
- v.literal("established"),
2062
- // Well-evidenced, core to thesis
2063
- v.literal("challenged"),
2064
- // Contradicting evidence appeared
2065
- v.literal("assumption"),
2066
- // Taken as given, not actively tested
2067
- v.literal("deprecated")
2068
- // Superseded or abandoned
2069
- );
2070
- var beliefStatus = v.union(
2071
- v.literal("assumption"),
2072
- v.literal("hypothesis"),
2073
- v.literal("belief"),
2074
- v.literal("fact")
2075
- );
2076
- var reversibility = v.union(
2077
- v.literal("irreversible"),
2078
- // One-way door decision
2079
- v.literal("hard_to_reverse"),
2080
- // Significant cost to undo
2081
- v.literal("reversible"),
2082
- // Can change course with moderate effort
2083
- v.literal("trivial")
2084
- // Easy to adjust
2085
- );
2086
- var predictionOutcome = v.union(
2087
- v.literal("pending"),
2088
- v.literal("confirmed"),
2089
- v.literal("disconfirmed"),
2090
- v.literal("partial"),
2091
- v.literal("expired")
2092
- );
2093
- var predictionMeta = v.object({
2094
- isPrediction: v.boolean(),
2095
- registeredAt: v.number(),
2096
- // When prediction was made
2097
- expectedBy: v.optional(v.number()),
2098
- // When we expect resolution
2099
- outcome: v.optional(predictionOutcome),
2100
- outcomeRecordedAt: v.optional(v.number()),
2101
- outcomeEvidenceId: v.optional(v.string()),
2102
- // globalId of confirming evidence
2103
- confidenceAtPrediction: v.optional(v.number()),
2104
- // 0-1
2105
- actualVsPredicted: v.optional(v.string())
2106
- // Notes on how outcome compared
2107
- });
2108
- var methodology = v.union(
2109
- // Primary Research (high value)
2110
- v.literal("primary_research"),
2111
- // Direct investigation
2112
- v.literal("expert_interview"),
2113
- // Expert call/interview
2114
- v.literal("customer_interview"),
2115
- // Customer research
2116
- v.literal("field_observation"),
2117
- // On-site observation
2118
- v.literal("proprietary_data"),
2119
- // Internal data analysis
2120
- // Secondary Research
2121
- v.literal("desk_research"),
2122
- // Public sources
2123
- v.literal("regulatory_filing"),
2124
- // SEC, regulatory docs
2125
- v.literal("news_article"),
2126
- // News/press
2127
- v.literal("academic_paper"),
2128
- // Academic research
2129
- // AI-Assisted
2130
- v.literal("ai_synthesis"),
2131
- // AI-generated synthesis
2132
- v.literal("ai_extraction")
2133
- // AI-extracted from source
2134
- );
2135
- var informationAsymmetry = v.union(
2136
- v.literal("proprietary"),
2137
- // Only we have this
2138
- v.literal("early"),
2139
- // We're early but others will get it
2140
- v.literal("common")
2141
- // Everyone has access
2142
- );
2143
- var temporalNature = v.union(
2144
- v.literal("factual"),
2145
- // Resolved outcome. Grounded in reality.
2146
- v.literal("forecast"),
2147
- // Prediction. Will resolve. Discounted weight.
2148
- v.literal("unknown")
2149
- // Not yet classified.
2150
- );
2151
- var questionType = v.union(
2152
- v.literal("validation"),
2153
- // Does evidence support this belief?
2154
- v.literal("falsification"),
2155
- // What would prove this belief wrong?
2156
- v.literal("assumption_probe"),
2157
- // Is this unstated assumption true?
2158
- v.literal("prediction_test"),
2159
- // Will this predicted outcome occur?
2160
- v.literal("counterfactual"),
2161
- // What would we expect if X were false?
2162
- v.literal("discovery"),
2163
- // What don't we know yet?
2164
- v.literal("clarification"),
2165
- // What does X actually mean?
2166
- v.literal("comparison"),
2167
- // How does X compare to Y?
2168
- v.literal("causal"),
2169
- // What caused X?
2170
- v.literal("mechanism"),
2171
- // How does X work?
2172
- v.literal("general")
2173
- // Unclassified
2174
- );
2175
- var questionPriority = v.union(
2176
- v.literal("critical"),
2177
- // Blocks decision-making
2178
- v.literal("high"),
2179
- // Important for thesis
2180
- v.literal("medium"),
2181
- // Would be nice to know
2182
- v.literal("low")
2183
- // Background/curiosity
2184
- );
2185
- var answerQuality = v.union(
2186
- v.literal("definitive"),
2187
- // Clear, well-supported
2188
- v.literal("strong"),
2189
- // Good evidence, high confidence
2190
- v.literal("moderate"),
2191
- // Some evidence
2192
- v.literal("weak"),
2193
- // Limited evidence
2194
- v.literal("speculative"),
2195
- // Mostly conjecture
2196
- v.literal("unanswered")
2197
- // No answer yet
2198
- );
2199
- var consensusView = v.union(
2200
- v.literal("aligned"),
2201
- // We agree with market consensus
2202
- v.literal("ahead_of"),
2203
- // We see this before consensus does
2204
- v.literal("contrarian"),
2205
- // We actively disagree with consensus
2206
- v.literal("orthogonal"),
2207
- // We're looking at something consensus isn't discussing
2208
- v.literal("unknown")
2209
- // We don't know what consensus thinks
2210
- );
2211
- var themeConviction = v.union(
2212
- v.literal("high"),
2213
- // Strong conviction, actively deploying
2214
- v.literal("medium"),
2215
- // Building conviction
2216
- v.literal("low"),
2217
- // Exploring, not convicted
2218
- v.literal("negative")
2219
- // Actively avoiding
2220
- );
2221
- var decisionType = v.union(
2222
- v.literal("invest"),
2223
- v.literal("pass"),
2224
- v.literal("follow_on"),
2225
- v.literal("exit"),
2226
- v.literal("deep_dive"),
2227
- v.literal("monitor"),
2228
- v.literal("deprioritize"),
2229
- v.literal("thesis_adopt"),
2230
- v.literal("thesis_revise"),
2231
- v.literal("thesis_abandon")
2232
- );
2233
- var decisionOutcome = v.union(
2234
- v.literal("pending"),
2235
- v.literal("successful"),
2236
- v.literal("unsuccessful"),
2237
- v.literal("mixed"),
2238
- v.literal("unknown")
2239
- );
2240
- var externalIds2 = v.object({
2241
- crunchbase: v.optional(v.string()),
2242
- linkedin: v.optional(v.string()),
2243
- pitchbook: v.optional(v.string()),
2244
- twitter: v.optional(v.string()),
2245
- website: v.optional(v.string())
2246
- });
2247
- defineTable({
2248
- // === IDENTITY ===
2249
- globalId: v.string(),
2250
- // UUID - survives migration to Neo4j
2251
- // === TYPE ===
2252
- nodeType,
2253
- // === EPISTEMIC LAYER ===
2254
- epistemicLayer: v.optional(epistemicLayer),
2255
- // === SUBTYPE (for typed entities) ===
2256
- subtype: v.optional(v.string()),
2257
- // company: private|corporate|portfolio, investor: vc|lp|cvc|pe|family_office|angel
2258
- // === CONTENT ===
2259
- canonicalText: v.string(),
2260
- // The core content (belief statement, company name, etc.)
2261
- contentHash: v.string(),
2262
- // SHA256(nodeType + canonicalText) for deduplication
2263
- // Extended content (for sources/syntheses)
2264
- content: v.optional(v.string()),
2265
- // Full text for documents/articles
2266
- contentType: v.optional(v.string()),
2267
- // "markdown", "html", "pdf", "text"
2268
- // === METADATA ===
2269
- title: v.optional(v.string()),
2270
- // Display title
2271
- tags: v.optional(v.array(v.string())),
2272
- domain: v.optional(v.string()),
2273
- // For companies: website domain
2274
- // Type-specific metadata (flexible object - LEGACY)
2275
- // New code should use the typed fields below when available
2276
- metadata: v.optional(looseJsonObject),
2277
- // === POLICY / ENTITLEMENT ===
2278
- tenantId: v.optional(v.string()),
2279
- workspaceId: v.optional(v.string()),
2280
- ownerPrincipalId: v.optional(v.string()),
2281
- audienceLabel: v.optional(audienceLabel),
2282
- policyTags: v.optional(v.array(v.string())),
2283
- sensitivityTier: v.optional(sensitivityTier),
2284
- exportClass: v.optional(exportClass),
2285
- anonymizationClass: v.optional(anonymizationClass),
2286
- // === PUBLICATION (visibility-based, not copy-based) ===
2287
- // Publication expands who can see a workspace-local node — the node stays
2288
- // in its workspace, like a microservice exposing part of its API surface.
2289
- // Rules-based: pack/tenant-level publicationRules auto-evaluate on
2290
- // confidence changes and node creation. No manual click-by-click.
2291
- publicationStatus: v.optional(
2292
- v.union(
2293
- v.literal("unpublished"),
2294
- // Default: workspace-local only
2295
- v.literal("published"),
2296
- // Visible at tenant scope (rules matched)
2297
- v.literal("suppressed")
2298
- // Manually blocked even if rules match
2299
- )
2300
- ),
2301
- publishedAt: v.optional(v.number()),
2302
- // When publication status last changed to published
2303
- publishedBy: v.optional(v.string()),
2304
- // userId or "system:publication_rules" for auto-publish
2305
- // === TYPED METADATA FIELDS ===
2306
- // --- Belief ---
2307
- // Belief type — validated against schemaEnumConfig category "belief_type"
2308
- // Platform core: hypothesis, belief, principle, invariant, assumption,
2309
- // tenet, prior, preference, goal, forecast
2310
- beliefType: v.optional(v.string()),
2311
- beliefStatus: v.optional(beliefStatus),
2312
- epistemicStatus: v.optional(epistemicStatus),
2313
- reversibility: v.optional(reversibility),
2314
- predictionMeta: v.optional(predictionMeta),
2315
- // Consensus tracking (for non-consensus detection)
2316
- consensusView: v.optional(consensusView),
2317
- consensusConfidence: v.optional(v.number()),
2318
- // 0-1: What we think consensus confidence is
2319
- consensusSource: v.optional(v.string()),
2320
- // Where we got the consensus view (twitter, reports, etc.)
2321
- // --- Evidence ---
2322
- methodology: v.optional(methodology),
2323
- informationAsymmetry: v.optional(informationAsymmetry),
2324
- temporalNature: v.optional(temporalNature),
2325
- // --- Question ---
2326
- questionType: v.optional(questionType),
2327
- questionPriority: v.optional(questionPriority),
2328
- answerQuality: v.optional(answerQuality),
2329
- // --- Theme ---
2330
- themeConviction: v.optional(themeConviction),
2331
- // Market timing (for "early on theme" detection)
2332
- marketAwarenessDate: v.optional(v.number()),
2333
- // When this theme became broadly discussed
2334
- marketAwarenessSource: v.optional(v.string()),
2335
- // How we know (first major report, twitter volume spike, etc.)
2336
- earlySignalIds: v.optional(v.array(v.string())),
2337
- // globalIds of evidence we had before market awareness
2338
- // --- Decision ---
2339
- decisionType: v.optional(decisionType),
2340
- decisionOutcome: v.optional(decisionOutcome),
2341
- // === EXTERNAL IDS (for ontological entities) ===
2342
- externalIds: v.optional(externalIds2),
2343
- // === PROVENANCE ===
2344
- sourceType: sourceType2,
2345
- aiProvider: v.optional(v.string()),
2346
- // "claude", "gemini", "gpt-4", etc.
2347
- extractedFromNodeId: v.optional(v.id("epistemicNodes")),
2348
- // Quick reference to source
2349
- // === EXTRACTION CONTEXT ===
2350
- extractionModel: v.optional(v.string()),
2351
- // "claude-sonnet-4-20250514"
2352
- extractionPromptName: v.optional(v.string()),
2353
- // "lucern/extract-evidence"
2354
- extractionPromptVersion: v.optional(v.number()),
2355
- extractionTemperature: v.optional(v.number()),
2356
- extractionLangfuseTraceId: v.optional(v.string()),
2357
- // === GROUNDING VERIFICATION ===
2358
- groundingVerified: v.optional(v.boolean()),
2359
- groundingConfidence: v.optional(v.number()),
2360
- // 0-1 match quality
2361
- groundingMatchedText: v.optional(v.string()),
2362
- // Actual text from source
2363
- groundingStartOffset: v.optional(v.number()),
2364
- groundingEndOffset: v.optional(v.number()),
2365
- groundingRejectionReason: v.optional(v.string()),
2366
- // === CONFIDENCE & VERIFICATION ===
2367
- confidence: v.optional(v.number()),
2368
- // 0-1 projected probability P(x) = b + a*u
2369
- verificationStatus: v.optional(verificationStatus),
2370
- // === SL OPINION (Subjective Logic — Kernel v2) ===
2371
- // Replaces scalar confidence with rich epistemic state.
2372
- // b + d + u = 1. P(x) = b + a*u is stored in `confidence` for backward compat.
2373
- opinion_b: v.optional(v.number()),
2374
- // Belief: evidence FOR (0-1)
2375
- opinion_d: v.optional(v.number()),
2376
- // Disbelief: evidence AGAINST (0-1)
2377
- opinion_u: v.optional(v.number()),
2378
- // Uncertainty: absence of evidence (0-1)
2379
- opinion_a: v.optional(v.number()),
2380
- // Base rate / prior probability (0-1)
2381
- tupleContradicted: v.optional(v.boolean()),
2382
- // Single-belief tuple-space contradiction flag
2383
- // === LIFECYCLE ===
2384
- status: nodeStatus,
2385
- supersededBy: v.optional(v.id("epistemicNodes")),
2386
- // === OWNERSHIP ===
2387
- topicId: v.optional(v.string()),
2388
- // Canonical scope container (topic-first model)
2389
- projectId: v.optional(v.string()),
2390
- // DEPRECATED: Use belongs_to edges
2391
- createdBy: v.string(),
2392
- // Clerk user ID
2393
- createdAt: v.number(),
2394
- updatedAt: v.number(),
2395
- // === NEO4J SYNC STATUS ===
2396
- syncStatus: v.optional(syncStatus),
2397
- syncError: v.optional(v.string())
2398
- // Error message if sync failed
2399
- }).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", {
2400
- searchField: "canonicalText",
2401
- filterFields: ["nodeType", "projectId", "topicId", "status"]
2402
- });
1816
+ // ../../packages/contracts/src/schema-helpers/spine/tables/epistemicNodes.ts
1817
+ var NODE_TYPES = [
1818
+ "decision",
1819
+ "belief",
1820
+ "question",
1821
+ "theme",
1822
+ "deal",
1823
+ "topic",
1824
+ "claim",
1825
+ "evidence",
1826
+ "synthesis",
1827
+ "answer",
1828
+ "atomic_fact",
1829
+ "excerpt",
1830
+ "source",
1831
+ "company",
1832
+ "person",
1833
+ "investor",
1834
+ "function",
1835
+ "value_chain"
1836
+ ];
1837
+ function isNodeType(value) {
1838
+ return NODE_TYPES.includes(value);
1839
+ }
2403
1840
  function getLayerForNodeType(type) {
2404
1841
  switch (type) {
2405
1842
  case "decision":
@@ -2633,7 +2070,7 @@ function throwWorkspaceIsolationError(args) {
2633
2070
  throw error;
2634
2071
  }
2635
2072
  function assertWorkspaceScopedEpistemicNodeScope(args) {
2636
- const layer = getLayerForNodeType(args.nodeType);
2073
+ const layer = isNodeType(args.nodeType) ? getLayerForNodeType(args.nodeType) : void 0;
2637
2074
  if (layer === "ontological") {
2638
2075
  return;
2639
2076
  }
@@ -2661,11 +2098,11 @@ function nodeMatchesWorkspaceReasoningScope(node, scope) {
2661
2098
  const scopeWorkspaceId = normalizeScopeValue2(scope.workspaceId);
2662
2099
  const nodeTenantId = normalizeScopeValue2(node.tenantId);
2663
2100
  const nodeWorkspaceId = normalizeScopeValue2(node.workspaceId);
2664
- const epistemicLayer2 = typeof node.epistemicLayer === "string" ? node.epistemicLayer : void 0;
2101
+ const epistemicLayer = typeof node.epistemicLayer === "string" ? node.epistemicLayer : void 0;
2665
2102
  if (scopeTenantId && nodeTenantId && scopeTenantId !== nodeTenantId) {
2666
2103
  return false;
2667
2104
  }
2668
- if (epistemicLayer2 === "ontological" && nodeWorkspaceId === void 0) {
2105
+ if (epistemicLayer === "ontological" && nodeWorkspaceId === void 0) {
2669
2106
  return true;
2670
2107
  }
2671
2108
  if (!scopeWorkspaceId && node.publicationStatus === "published") {
@@ -2693,11 +2130,11 @@ function edgeMatchesWorkspaceReasoningScope(edge, scope) {
2693
2130
  return scopeWorkspaceId === edgeWorkspaceId;
2694
2131
  }
2695
2132
  async function resolveNodeScopeForWorkspaceIsolation(ctx, node) {
2696
- const epistemicLayer2 = typeof node?.epistemicLayer === "string" ? node.epistemicLayer : void 0;
2133
+ const epistemicLayer = typeof node?.epistemicLayer === "string" ? node.epistemicLayer : void 0;
2697
2134
  const resolved = {
2698
2135
  tenantId: normalizeScopeValue2(node?.tenantId),
2699
2136
  workspaceId: normalizeScopeValue2(node?.workspaceId),
2700
- epistemicLayer: epistemicLayer2,
2137
+ epistemicLayer,
2701
2138
  nodeType: typeof node?.nodeType === "string" ? node.nodeType : void 0
2702
2139
  };
2703
2140
  if (!node) {
@@ -3347,10 +2784,10 @@ function deriveSyntheticBackfillOpinion(source) {
3347
2784
  a: 0.5
3348
2785
  });
3349
2786
  }
3350
- const confidence2 = clamp012(readFiniteNumber(source.confidence) ?? 0);
2787
+ const confidence = clamp012(readFiniteNumber(source.confidence) ?? 0);
3351
2788
  return {
3352
- b: confidence2,
3353
- d: 1 - confidence2,
2789
+ b: confidence,
2790
+ d: 1 - confidence,
3354
2791
  u: 0,
3355
2792
  a: 0.5
3356
2793
  };
@@ -3394,10 +2831,10 @@ function formatTupleContradictionDescription(args) {
3394
2831
  return `Tuple-space contradiction detected: b=${args.opinion.b.toFixed(2)} > ${args.policy.beliefThreshold.toFixed(2)} and d=${args.opinion.d.toFixed(2)} > ${args.policy.disbeliefThreshold.toFixed(2)}.`;
3395
2832
  }
3396
2833
  function generateContentHash(text) {
3397
- const content2 = `belief:${text.trim().toLowerCase().replace(/\s+/g, " ")}`;
2834
+ const content = `belief:${text.trim().toLowerCase().replace(/\s+/g, " ")}`;
3398
2835
  let hash = 5381;
3399
- for (let i = 0; i < content2.length; i++) {
3400
- hash = (hash << 5) + hash + content2.charCodeAt(i);
2836
+ for (let i = 0; i < content.length; i++) {
2837
+ hash = (hash << 5) + hash + content.charCodeAt(i);
3401
2838
  hash &= hash;
3402
2839
  }
3403
2840
  return Math.abs(hash).toString(16).padStart(8, "0");
@@ -3440,14 +2877,14 @@ async function markBeliefGraphDirty(ctx, scope) {
3440
2877
  if (projectId) {
3441
2878
  await ctx.scheduler.runAfter(
3442
2879
  0,
3443
- internal2.graphAnalysisCache.markCacheStaleInternal,
2880
+ internal.graphAnalysisCache.markCacheStaleInternal,
3444
2881
  { projectId }
3445
2882
  );
3446
2883
  }
3447
2884
  if (topicId) {
3448
2885
  await ctx.scheduler.runAfter(
3449
2886
  0,
3450
- internal2.graphAnalysisCache.markCacheStaleByTopic,
2887
+ internal.graphAnalysisCache.markCacheStaleByTopic,
3451
2888
  { topicId }
3452
2889
  );
3453
2890
  }
@@ -3474,8 +2911,8 @@ async function resolveBeliefScopeOrNull(ctx, args) {
3474
2911
  }
3475
2912
  async function getBeliefNodesForScope(ctx, scope, args) {
3476
2913
  const baseQuery = ctx.db.query("epistemicNodes").withIndex(
3477
- scope.topicId ? "by_topic_type" : "by_project_type",
3478
- (q) => scope.topicId ? q.eq("topicId", scope.topicId).eq("nodeType", "belief") : q.eq("projectId", scope.projectId).eq("nodeType", "belief")
2914
+ "by_topic_type",
2915
+ (q) => q.eq("topicId", scope.topicId).eq("nodeType", "belief")
3479
2916
  );
3480
2917
  const nodes = typeof args?.scanLimit === "number" ? await baseQuery.order("desc").take(args.scanLimit) : await baseQuery.collect();
3481
2918
  const scopedNodes = nodes.filter(
@@ -3626,7 +3063,7 @@ async function applyBeliefConfidenceChange(ctx, args) {
3626
3063
  }
3627
3064
  }
3628
3065
  const previousConfidence = node.confidence || 0.5;
3629
- const predictionMeta2 = node.predictionMeta || existingMetadata.predictionMeta;
3066
+ const predictionMeta = node.predictionMeta || existingMetadata.predictionMeta;
3630
3067
  const previousOpinion = readBeliefOpinionSnapshot(node, existingMetadata);
3631
3068
  const slB = args.belief;
3632
3069
  const slD = args.disbelief;
@@ -3653,7 +3090,7 @@ async function applyBeliefConfidenceChange(ctx, args) {
3653
3090
  currentBeliefStatus,
3654
3091
  {
3655
3092
  confidence: derivedConfidence,
3656
- predictionMeta: predictionMeta2,
3093
+ predictionMeta,
3657
3094
  metadata: existingMetadata
3658
3095
  }
3659
3096
  );
@@ -3698,7 +3135,7 @@ async function applyBeliefConfidenceChange(ctx, args) {
3698
3135
  const themeNodes = await ctx.db.query("epistemicNodes").withIndex("by_topic", (q) => q.eq("topicId", nodeTopicId || node.projectId)).filter((q) => q.eq(q.field("nodeType"), "theme")).collect();
3699
3136
  for (const theme of themeNodes) {
3700
3137
  if (theme.globalId && node.globalId) {
3701
- await ctx.scheduler.runAfter(0, internal2.neo4jEdgeAPI.createEdge, {
3138
+ await ctx.scheduler.runAfter(0, internal.neo4jEdgeAPI.createEdge, {
3702
3139
  globalId: `edge-${node.globalId}-relates_to_thesis-${theme.globalId}`,
3703
3140
  fromGlobalId: node.globalId,
3704
3141
  toGlobalId: theme.globalId,
@@ -3732,7 +3169,7 @@ async function applyBeliefConfidenceChange(ctx, args) {
3732
3169
  triggeringWorktreeId: args.triggeringWorktreeId
3733
3170
  })
3734
3171
  });
3735
- await ctx.scheduler.runAfter(0, internal2.neo4jSync.syncNodeToNeo4j, {
3172
+ await ctx.scheduler.runAfter(0, internal.neo4jSync.syncNodeToNeo4j, {
3736
3173
  nodeId: args.nodeId,
3737
3174
  operation: "upsert"
3738
3175
  });
@@ -3783,7 +3220,7 @@ async function applyBeliefConfidenceChange(ctx, args) {
3783
3220
  if (Math.abs(derivedConfidence - previousConfidence) >= 0.15) {
3784
3221
  await ctx.scheduler.runAfter(
3785
3222
  5e3,
3786
- internal2.bi.contradictionSemanticDetector.scanAffectedBeliefs,
3223
+ internal.bi.contradictionSemanticDetector.scanAffectedBeliefs,
3787
3224
  {
3788
3225
  beliefId: args.nodeId,
3789
3226
  projectId: node.projectId
@@ -3793,7 +3230,7 @@ async function applyBeliefConfidenceChange(ctx, args) {
3793
3230
  if (node.workspaceId && node.tenantId) {
3794
3231
  await ctx.scheduler.runAfter(
3795
3232
  0,
3796
- internal2.publication.evaluateNodePublication,
3233
+ internal.publication.evaluateNodePublication,
3797
3234
  { nodeId: args.nodeId }
3798
3235
  );
3799
3236
  }
@@ -4037,7 +3474,7 @@ var create = mutation({
4037
3474
  slOperator: "manual_assessment"
4038
3475
  })
4039
3476
  );
4040
- await ctx.scheduler.runAfter(0, internal2.neo4jSync.syncNodeToNeo4j, {
3477
+ await ctx.scheduler.runAfter(0, internal.neo4jSync.syncNodeToNeo4j, {
4041
3478
  nodeId,
4042
3479
  operation: "upsert"
4043
3480
  });
@@ -4096,7 +3533,7 @@ Rationale: ${args.rationale}` : args.formulation
4096
3533
  await ctx.scheduler.runAfter(
4097
3534
  2e3,
4098
3535
  // 2 second delay
4099
- internal2.nodeClassification.scheduleClassification,
3536
+ internal.nodeClassification.scheduleClassification,
4100
3537
  {
4101
3538
  nodeId,
4102
3539
  nodeType: "belief",
@@ -4120,7 +3557,7 @@ Rationale: ${args.rationale}` : args.formulation
4120
3557
  await ctx.scheduler.runAfter(
4121
3558
  3e3,
4122
3559
  // 3 second delay — after entity extraction
4123
- internal2.beliefTemporalClassifier.classifyBelief,
3560
+ internal.beliefTemporalClassifier.classifyBelief,
4124
3561
  {
4125
3562
  nodeId,
4126
3563
  projectId: scope.projectId,
@@ -4221,7 +3658,7 @@ var refineBelief = mutation({
4221
3658
  patch.content = args.rationale;
4222
3659
  }
4223
3660
  await ctx.db.patch(args.nodeId, patch);
4224
- await ctx.scheduler.runAfter(0, internal2.neo4jSync.syncNodeToNeo4j, {
3661
+ await ctx.scheduler.runAfter(0, internal.neo4jSync.syncNodeToNeo4j, {
4225
3662
  nodeId: args.nodeId,
4226
3663
  operation: "upsert"
4227
3664
  });
@@ -4307,8 +3744,8 @@ var getByProject = query({
4307
3744
  }
4308
3745
  }
4309
3746
  const query2 = ctx.db.query("epistemicNodes").withIndex(
4310
- scope.topicId ? "by_topic_type" : "by_project_type",
4311
- (q) => scope.topicId ? q.eq("topicId", scope.topicId).eq("nodeType", "belief") : q.eq("projectId", scope.projectId).eq("nodeType", "belief")
3747
+ "by_topic_type",
3748
+ (q) => q.eq("topicId", scope.topicId).eq("nodeType", "belief")
4312
3749
  );
4313
3750
  const nodes = await query2.order("desc").take(scanLimit);
4314
3751
  const scopedNodes = nodes.filter(
@@ -4457,11 +3894,11 @@ var forkBelief = mutation({
4457
3894
  })
4458
3895
  );
4459
3896
  }
4460
- await ctx.scheduler.runAfter(0, internal2.neo4jSync.syncNodeToNeo4j, {
3897
+ await ctx.scheduler.runAfter(0, internal.neo4jSync.syncNodeToNeo4j, {
4461
3898
  nodeId: newNodeId,
4462
3899
  operation: "upsert"
4463
3900
  });
4464
- await ctx.scheduler.runAfter(5e3, internal2.neo4jEdgeAPI.createEdge, {
3901
+ await ctx.scheduler.runAfter(5e3, internal.neo4jEdgeAPI.createEdge, {
4465
3902
  globalId: generateGlobalId(),
4466
3903
  fromGlobalId: newBeliefGlobalId,
4467
3904
  toGlobalId: parent.globalId,
@@ -4517,7 +3954,7 @@ var forkBelief = mutation({
4517
3954
  }
4518
3955
  await ctx.scheduler.runAfter(
4519
3956
  3e3,
4520
- internal2.beliefTemporalClassifier.classifyBelief,
3957
+ internal.beliefTemporalClassifier.classifyBelief,
4521
3958
  {
4522
3959
  nodeId: newNodeId,
4523
3960
  projectId: parent.projectId,
@@ -4595,7 +4032,7 @@ var modulateConfidence = mutation({
4595
4032
  if (Math.abs(result.newConfidence - result.previousConfidence) >= 0.01) {
4596
4033
  await ctx.scheduler.runAfter(
4597
4034
  0,
4598
- internal2.epistemicBeliefs.propagateConfidenceChange,
4035
+ internal.epistemicBeliefs.propagateConfidenceChange,
4599
4036
  {
4600
4037
  nodeId: args.nodeId,
4601
4038
  opinion_b: args.belief,
@@ -4647,7 +4084,7 @@ var updateStatus = mutation({
4647
4084
  status: args.status
4648
4085
  }
4649
4086
  });
4650
- await ctx.scheduler.runAfter(0, internal2.neo4jSync.syncNodeToNeo4j, {
4087
+ await ctx.scheduler.runAfter(0, internal.neo4jSync.syncNodeToNeo4j, {
4651
4088
  nodeId: args.nodeId,
4652
4089
  operation: "upsert"
4653
4090
  });
@@ -4684,7 +4121,7 @@ var archive = mutation({
4684
4121
  await requireProjectWriteAccess(ctx, node.projectId, authenticatedUserId);
4685
4122
  return await ctx.runMutation(
4686
4123
  // Use updateStatus internally
4687
- internal2.epistemicBeliefs.updateStatusInternal,
4124
+ internal.epistemicBeliefs.updateStatusInternal,
4688
4125
  {
4689
4126
  nodeId: args.nodeId,
4690
4127
  status: "archived",
@@ -4722,7 +4159,7 @@ var updateRationale = mutation({
4722
4159
  },
4723
4160
  updatedAt: now
4724
4161
  });
4725
- await ctx.scheduler.runAfter(0, internal2.neo4jSync.syncNodeToNeo4j, {
4162
+ await ctx.scheduler.runAfter(0, internal.neo4jSync.syncNodeToNeo4j, {
4726
4163
  nodeId: args.nodeId,
4727
4164
  operation: "upsert"
4728
4165
  });
@@ -4918,7 +4355,7 @@ var updatePillar = mutation({
4918
4355
  },
4919
4356
  updatedAt: now
4920
4357
  });
4921
- await ctx.scheduler.runAfter(0, internal2.neo4jSync.syncNodeToNeo4j, {
4358
+ await ctx.scheduler.runAfter(0, internal.neo4jSync.syncNodeToNeo4j, {
4922
4359
  nodeId: args.nodeId,
4923
4360
  operation: "upsert"
4924
4361
  });
@@ -4946,9 +4383,13 @@ var getCountByStatus = query({
4946
4383
  },
4947
4384
  returns: permissiveReturn,
4948
4385
  handler: async (ctx, args) => {
4386
+ const scope = await resolveBeliefScopeOrNull(ctx, args);
4387
+ if (!scope) {
4388
+ return { active: 0, superseded: 0, archived: 0, total: 0 };
4389
+ }
4949
4390
  const nodes = await ctx.db.query("epistemicNodes").withIndex(
4950
- args.topicId ? "by_topic_type" : "by_project_type",
4951
- (q) => args.topicId ? q.eq("topicId", args.topicId).eq("nodeType", "belief") : q.eq("projectId", args.projectId).eq("nodeType", "belief")
4391
+ "by_topic_type",
4392
+ (q) => q.eq("topicId", scope.topicId).eq("nodeType", "belief")
4952
4393
  ).collect();
4953
4394
  const counts = {
4954
4395
  active: 0,
@@ -5011,7 +4452,7 @@ var linkBeliefs = mutation({
5011
4452
  );
5012
4453
  const now = Date.now();
5013
4454
  const edgeGlobalId = generateGlobalId();
5014
- await ctx.scheduler.runAfter(0, internal2.neo4jEdgeAPI.createEdge, {
4455
+ await ctx.scheduler.runAfter(0, internal.neo4jEdgeAPI.createEdge, {
5015
4456
  globalId: edgeGlobalId,
5016
4457
  fromGlobalId: fromNode.globalId,
5017
4458
  toGlobalId: toNode.globalId,
@@ -5073,7 +4514,7 @@ var linkEvidence = mutation({
5073
4514
  const weight = args.type === "supporting" ? 1 : -1;
5074
4515
  const logicalRole = evidenceNodeId ? await computeLogicalRole(ctx, evidenceNodeId, args.beliefNodeId) : "contributory";
5075
4516
  const edgeGlobalId = generateGlobalId();
5076
- await ctx.scheduler.runAfter(0, internal2.neo4jEdgeAPI.createEdge, {
4517
+ await ctx.scheduler.runAfter(0, internal.neo4jEdgeAPI.createEdge, {
5077
4518
  globalId: edgeGlobalId,
5078
4519
  fromGlobalId: evidenceGlobalId,
5079
4520
  toGlobalId: belief.globalId,
@@ -5128,7 +4569,7 @@ var unlinkEvidence = mutation({
5128
4569
  (q) => q.eq("fromNodeId", evidenceNode._id).eq("toNodeId", args.beliefNodeId)
5129
4570
  ).first();
5130
4571
  if (edge) {
5131
- await ctx.scheduler.runAfter(0, internal2.neo4jEdgeAPI.deleteEdge, {
4572
+ await ctx.scheduler.runAfter(0, internal.neo4jEdgeAPI.deleteEdge, {
5132
4573
  globalId: edge.globalId
5133
4574
  });
5134
4575
  await ctx.db.delete(edge._id);
@@ -5244,7 +4685,7 @@ var deleteRelationship = mutation({
5244
4685
  toNodeId: edge.toNodeId,
5245
4686
  edgeType: edge.edgeType
5246
4687
  };
5247
- await ctx.scheduler.runAfter(0, internal2.neo4jEdgeAPI.deleteEdge, {
4688
+ await ctx.scheduler.runAfter(0, internal.neo4jEdgeAPI.deleteEdge, {
5248
4689
  globalId: edge.globalId
5249
4690
  });
5250
4691
  await ctx.db.delete(args.edgeId);
@@ -5295,7 +4736,7 @@ var updateCriticality = mutation({
5295
4736
  },
5296
4737
  updatedAt: now
5297
4738
  });
5298
- await ctx.scheduler.runAfter(0, internal2.neo4jSync.syncNodeToNeo4j, {
4739
+ await ctx.scheduler.runAfter(0, internal.neo4jSync.syncNodeToNeo4j, {
5299
4740
  nodeId: args.nodeId,
5300
4741
  operation: "upsert"
5301
4742
  });
@@ -5373,7 +4814,7 @@ var batchUpdateCriticality = mutation({
5373
4814
  },
5374
4815
  updatedAt: now
5375
4816
  });
5376
- await ctx.scheduler.runAfter(0, internal2.neo4jSync.syncNodeToNeo4j, {
4817
+ await ctx.scheduler.runAfter(0, internal.neo4jSync.syncNodeToNeo4j, {
5377
4818
  nodeId: node._id,
5378
4819
  operation: "upsert"
5379
4820
  });
@@ -5513,8 +4954,8 @@ var getByPillar = query({
5513
4954
  return [];
5514
4955
  }
5515
4956
  const nodes = await ctx.db.query("epistemicNodes").withIndex(
5516
- scope.topicId ? "by_topic_type" : "by_project_type",
5517
- (q) => scope.topicId ? q.eq("topicId", scope.topicId).eq("nodeType", "belief") : q.eq("projectId", scope.projectId).eq("nodeType", "belief")
4957
+ "by_topic_type",
4958
+ (q) => q.eq("topicId", scope.topicId).eq("nodeType", "belief")
5518
4959
  ).collect();
5519
4960
  return nodes.filter((n) => {
5520
4961
  const metadata = n.metadata;
@@ -5817,7 +5258,7 @@ var internalCreate = internalMutation({
5817
5258
  slOperator: "manual_assessment"
5818
5259
  })
5819
5260
  );
5820
- await ctx.scheduler.runAfter(0, internal2.neo4jSync.syncNodeToNeo4j, {
5261
+ await ctx.scheduler.runAfter(0, internal.neo4jSync.syncNodeToNeo4j, {
5821
5262
  nodeId,
5822
5263
  operation: "upsert"
5823
5264
  });
@@ -6226,7 +5667,7 @@ var backfillScoredBeliefEdges = internalMutation({
6226
5667
  continue;
6227
5668
  }
6228
5669
  if (!dryRun) {
6229
- await ctx.scheduler.runAfter(0, internal2.neo4jEdgeAPI.createEdge, {
5670
+ await ctx.scheduler.runAfter(0, internal.neo4jEdgeAPI.createEdge, {
6230
5671
  globalId: edgeGlobalId,
6231
5672
  fromGlobalId: belief.globalId,
6232
5673
  toGlobalId: theme.globalId,