@lucern/graph-primitives 1.0.17 → 1.0.19

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 (51) hide show
  1. package/dist/entityLifecycle.js +1 -12
  2. package/dist/entityLifecycle.js.map +1 -1
  3. package/dist/epistemicAnswers.js +1 -12
  4. package/dist/epistemicAnswers.js.map +1 -1
  5. package/dist/epistemicBeliefs.core.js +4 -15
  6. package/dist/epistemicBeliefs.core.js.map +1 -1
  7. package/dist/epistemicBeliefs.internal.js +4 -15
  8. package/dist/epistemicBeliefs.internal.js.map +1 -1
  9. package/dist/epistemicBeliefs.js +62 -19
  10. package/dist/epistemicBeliefs.js.map +1 -1
  11. package/dist/epistemicBeliefs.links.js +59 -16
  12. package/dist/epistemicBeliefs.links.js.map +1 -1
  13. package/dist/epistemicBeliefs.topicAnchor.js +3 -3
  14. package/dist/epistemicBeliefs.topicAnchor.js.map +1 -1
  15. package/dist/epistemicContracts.handlers.js +1 -12
  16. package/dist/epistemicContracts.handlers.js.map +1 -1
  17. package/dist/epistemicContracts.js +1 -12
  18. package/dist/epistemicContracts.js.map +1 -1
  19. package/dist/epistemicEdgeCreation.js +1 -12
  20. package/dist/epistemicEdgeCreation.js.map +1 -1
  21. package/dist/epistemicEdges.helpers.d.ts +1 -1
  22. package/dist/epistemicEvidence.js +1 -12
  23. package/dist/epistemicEvidence.js.map +1 -1
  24. package/dist/epistemicEvidenceMutations.js +1 -12
  25. package/dist/epistemicEvidenceMutations.js.map +1 -1
  26. package/dist/epistemicHelpers.js +1 -12
  27. package/dist/epistemicHelpers.js.map +1 -1
  28. package/dist/epistemicNodeCreation.js +1 -10
  29. package/dist/epistemicNodeCreation.js.map +1 -1
  30. package/dist/epistemicQuestions.create.js +1 -12
  31. package/dist/epistemicQuestions.create.js.map +1 -1
  32. package/dist/epistemicQuestions.evidence.js +1 -12
  33. package/dist/epistemicQuestions.evidence.js.map +1 -1
  34. package/dist/epistemicQuestions.js +1 -12
  35. package/dist/epistemicQuestions.js.map +1 -1
  36. package/dist/epistemicQuestions.tail.js +1 -12
  37. package/dist/epistemicQuestions.tail.js.map +1 -1
  38. package/dist/epistemicSources.js +1 -12
  39. package/dist/epistemicSources.js.map +1 -1
  40. package/dist/globalId-4y9SPpC_.d.ts +10 -0
  41. package/dist/globalId.d.ts +1 -1
  42. package/dist/globalId.js +1 -13
  43. package/dist/globalId.js.map +1 -1
  44. package/dist/helpers.js +1 -12
  45. package/dist/helpers.js.map +1 -1
  46. package/dist/index.d.ts +2 -1
  47. package/dist/index.js +65 -18
  48. package/dist/index.js.map +1 -1
  49. package/dist/proof-attestation.json +1 -1
  50. package/package.json +4 -4
  51. package/dist/globalId-DKh9d_uD.d.ts +0 -20
@@ -1,21 +1,10 @@
1
1
  import { componentsGeneric, anyApi } from 'convex/server';
2
+ import { generateGlobalId } from '@lucern/contracts/ids';
2
3
 
3
4
  // src/convex.ts
4
5
  componentsGeneric();
5
6
  var internal = anyApi;
6
7
 
7
- // src/globalId.ts
8
- function generateGlobalId() {
9
- const bytes = new Uint8Array(16);
10
- crypto.getRandomValues(bytes);
11
- bytes[6] = bytes[6] & 15 | 64;
12
- bytes[8] = bytes[8] & 63 | 128;
13
- const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join(
14
- ""
15
- );
16
- return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
17
- }
18
-
19
8
  // src/epistemicLayerRules.ts
20
9
  function getNodeLayer(nodeType) {
21
10
  switch (nodeType) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/convex.ts","../src/globalId.ts","../src/epistemicLayerRules.ts","../src/epistemicEdgeCreation.ts"],"names":[],"mappings":";;;AAc0B,iBAAA;AACnB,IAAM,QAAA,GAAW,MAAA;;;ACFjB,SAAS,gBAAA,GAA2B;AACzC,EAAA,MAAM,KAAA,GAAQ,IAAI,UAAA,CAAW,EAA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M,QAAA,GAAW,WAAW,SAAS,CAAA;AAErC,IAAA,OAAO,QAAA,IAAY,MAAA,CAAO,QAAQ,CAAA,KAAM,WAAA;AAAA,EAC1C,CAAC,CAAA;AAED,EAAA,IAAI,CAAC,KAAA,EAAO;AACV,IAAA,OAAA,CAAQ,GAAA;AAAA,MACN,CAAA,oCAAA,EAAuC,UAAU,CAAA,CAAA,EAAI,WAAW,cAAc,KAAA,CAAM,MAAM,IAAI,QAAQ,CAAA,MAAA;AAAA,KACxG;AAAA,EACF;AAEA,EAAA,OAAO,OAAO,GAAA,IAAO,IAAA;AACvB","file":"epistemicEdgeCreation.js","sourcesContent":["import {\n actionGeneric,\n anyApi,\n componentsGeneric,\n httpActionGeneric,\n internalActionGeneric,\n internalMutationGeneric,\n internalQueryGeneric,\n mutationGeneric,\n queryGeneric,\n} from \"convex/server\";\nimport type { GenericId } from \"convex/values\";\n\nexport const api = anyApi as any;\nexport const components = componentsGeneric() as any;\nexport const internal = anyApi as any;\n\nexport type TableNames = string;\nexport type Id<TableName extends TableNames = string> = GenericId<TableName>;\nexport type Doc<TableName extends TableNames = string> = any;\nexport type DataModel = any;\ntype IndexRangeBuilder = {\n field(fieldName: string): string;\n eq(fieldName: string, value: unknown): IndexRangeBuilder;\n gt(fieldName: string, value: unknown): IndexRangeBuilder;\n gte(fieldName: string, value: unknown): IndexRangeBuilder;\n lt(fieldName: string, value: unknown): IndexRangeBuilder;\n lte(fieldName: string, value: unknown): IndexRangeBuilder;\n};\ntype FilterBuilder = {\n eq(left: unknown, right: unknown): unknown;\n neq(left: unknown, right: unknown): unknown;\n gt(left: unknown, right: unknown): unknown;\n gte(left: unknown, right: unknown): unknown;\n lt(left: unknown, right: unknown): unknown;\n lte(left: unknown, right: unknown): unknown;\n and(...clauses: unknown[]): unknown;\n or(...clauses: unknown[]): unknown;\n field(fieldName: string): unknown;\n};\ntype QueryInitializer<TableName extends TableNames> = {\n withIndex(\n indexName: string,\n range?: (q: any) => unknown\n ): QueryInitializer<TableName>;\n filter(predicate: (q: any) => unknown): QueryInitializer<TableName>;\n order(direction: \"asc\" | \"desc\"): QueryInitializer<TableName>;\n collect(): Promise<Doc<TableName>[]>;\n take(limit: number): Promise<Doc<TableName>[]>;\n first(): Promise<Doc<TableName> | null>;\n unique(): Promise<Doc<TableName> | null>;\n};\nexport type DatabaseReader = {\n get<TableName extends TableNames>(\n id: Id<TableName>\n ): Promise<Doc<TableName> | null>;\n query<TableName extends TableNames>(\n tableName: TableName\n ): QueryInitializer<TableName>;\n normalizeId?<TableName extends TableNames>(\n tableName: TableName,\n id: string\n ): Id<TableName> | null;\n};\nexport type DatabaseWriter = DatabaseReader & {\n insert<TableName extends TableNames>(\n tableName: TableName,\n value: Record<string, unknown>\n ): Promise<Id<TableName>>;\n patch<TableName extends TableNames>(\n id: Id<TableName>,\n value: Record<string, unknown>\n ): Promise<void>;\n replace<TableName extends TableNames>(\n id: Id<TableName>,\n value: Record<string, unknown>\n ): Promise<void>;\n delete<TableName extends TableNames>(id: Id<TableName>): Promise<void>;\n};\ntype Scheduler = {\n runAfter(delayMs: number, functionReference: unknown, args?: unknown): Promise<void>;\n};\ntype AuthReader = {\n getUserIdentity(): Promise<unknown>;\n};\ntype RuntimeInvoker = {\n runQuery(functionReference: unknown, args?: unknown): Promise<any>;\n runMutation(functionReference: unknown, args?: unknown): Promise<any>;\n runAction(functionReference: unknown, args?: unknown): Promise<any>;\n};\nexport type QueryCtx = RuntimeInvoker & {\n auth: AuthReader;\n db: DatabaseReader;\n scheduler: Scheduler;\n};\nexport type MutationCtx = RuntimeInvoker & {\n auth: AuthReader;\n db: DatabaseWriter;\n scheduler: Scheduler;\n};\nexport type ActionCtx = RuntimeInvoker & {\n auth: AuthReader;\n scheduler: Scheduler;\n};\n\ntype ConvexFunctionBuilder<Ctx> = <\n Definition extends { handler?: (ctx: Ctx, args: any) => any },\n>(\n definition: Definition\n) => any;\n\nexport const action = actionGeneric as unknown as ConvexFunctionBuilder<ActionCtx>;\nexport const httpAction =\n httpActionGeneric as unknown as ConvexFunctionBuilder<ActionCtx>;\nexport const internalAction =\n internalActionGeneric as unknown as ConvexFunctionBuilder<ActionCtx>;\nexport const internalMutation =\n internalMutationGeneric as unknown as ConvexFunctionBuilder<MutationCtx>;\nexport const internalQuery =\n internalQueryGeneric as unknown as ConvexFunctionBuilder<QueryCtx>;\nexport const mutation =\n mutationGeneric as unknown as ConvexFunctionBuilder<MutationCtx>;\nexport const query = queryGeneric as unknown as ConvexFunctionBuilder<QueryCtx>;\n","/**\n * Shared UUID v4 generator for global IDs.\n *\n * Uses crypto.getRandomValues() for collision-safe generation.\n * Replaces the Math.random()-based UUID pattern that was duplicated\n * across 7+ files.\n *\n * @module convex/lib/globalId\n */\n\n/**\n * Generate a UUID v4 global ID using crypto-safe random bytes.\n */\nexport function generateGlobalId(): string {\n const bytes = new Uint8Array(16);\n crypto.getRandomValues(bytes);\n // Set version (4) and variant (RFC 4122)\n bytes[6] = (bytes[6] & 0x0f) | 0x40;\n bytes[8] = (bytes[8] & 0x3f) | 0x80;\n const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, \"0\")).join(\n \"\"\n );\n return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;\n}\n","/**\n * Epistemic Spine helper module split from epistemicHelpers.ts.\n */\n\nimport type { Id } from \"./convex\";\n\n// =============================================================================\n// TYPE MAPPINGS\n// =============================================================================\n\ntype EpistemicNodeType =\n // L4: Audit targets\n | \"decision\"\n // L3: Traversal anchors\n | \"belief\"\n | \"question\"\n | \"theme\"\n | \"deal\"\n // L2: Compression boundary\n | \"claim\"\n | \"evidence\"\n | \"synthesis\"\n | \"answer\"\n // L1: Terminal leaves\n | \"atomic_fact\"\n | \"excerpt\"\n | \"source\";\n\ntype OntologicalNodeType =\n | \"company\"\n | \"person\"\n | \"investor\"\n | \"function\"\n | \"value_chain\";\n\ntype NodeType = EpistemicNodeType | OntologicalNodeType;\n\n// =============================================================================\n// EPISTEMIC LAYER ARCHITECTURE (Lucern Invariant Compliance)\n// =============================================================================\n\n/**\n * Epistemic Layer - governs traversal rules\n * L4 → L3 → L2 → L1 (never skip layers)\n */\nexport type EpistemicLayer =\n | \"L4\"\n | \"L3\"\n | \"L2\"\n | \"L1\"\n | \"ontological\"\n | \"organizational\";\n\n/**\n * Map nodeType to its epistemic layer\n *\n * Layer semantics:\n * - L4: Audit targets (decisions, outcomes) - what we committed to\n * - L3: Traversal anchors (beliefs, questions, themes) - epistemic structure\n * - L2: Compression boundary (claims, evidence, synthesis) - minimum reasoning unit\n * - L1: Terminal leaves (atomic_fact, excerpt, source) - non-traversable grounding\n * - ontological: Entities in the world (companies, people) - not epistemic\n * - organizational: Structural containers (topics, lenses, worktrees) - not epistemic\n */\nexport function getNodeLayer(nodeType: string): EpistemicLayer {\n switch (nodeType) {\n // L4: Audit targets\n case \"decision\":\n return \"L4\";\n\n // L3: Traversal anchors\n case \"belief\":\n case \"question\":\n case \"theme\":\n case \"deal\":\n return \"L3\";\n\n // L2: Compression boundary\n case \"claim\":\n case \"evidence\":\n case \"synthesis\":\n case \"answer\":\n return \"L2\";\n\n // L1: Terminal leaves\n case \"atomic_fact\":\n case \"excerpt\":\n case \"source\":\n return \"L1\";\n\n // Ontological entities\n case \"company\":\n case \"person\":\n case \"investor\":\n case \"function\":\n case \"value_chain\":\n return \"ontological\";\n\n // Organizational containers\n case \"topic\":\n return \"organizational\";\n\n default:\n // Unknown types default to L2 (safest for traversal)\n console.warn(\n `[EpistemicLayer] Unknown nodeType: ${nodeType}, defaulting to L2`\n );\n return \"L2\";\n }\n}\n\n/**\n * Layer traversal rules\n * Key constraint: Cannot skip layers during traversal\n */\nexport const LAYER_TRAVERSAL_RULES = {\n L4: {\n canReach: [\"L3\", \"L4\"], // Decisions can reach beliefs/questions\n mustPassThrough: \"L3\", // Must go through L3 to reach L2\n },\n L3: {\n canReach: [\"L2\", \"L3\", \"L4\"], // Beliefs can reach evidence, other beliefs, or decisions\n mustPassThrough: \"L2\", // Must go through L2 to reach L1\n },\n L2: {\n canReach: [\"L1\", \"L2\", \"L3\"], // Evidence can reach sources, other evidence, or beliefs\n mustPassThrough: null, // L2 can reach L1 directly\n },\n L1: {\n canReach: [\"L1\"], // Sources can only reach other sources\n mustPassThrough: null, // Terminal - no traversal beyond\n },\n ontological: {\n canReach: [\"L3\", \"L2\", \"ontological\"], // Entities can link to epistemic structure\n mustPassThrough: null, // No layer constraints for entities\n },\n organizational: {\n canReach: [\"L3\", \"L2\", \"organizational\"], // Containers scope epistemic structure + nest\n mustPassThrough: null, // No layer constraints for containers\n },\n} as const;\n\n/**\n * Check if a direct edge between two layers is allowed\n */\nexport function isValidLayerConnection(\n fromLayer: EpistemicLayer,\n toLayer: EpistemicLayer\n): boolean {\n const rules = LAYER_TRAVERSAL_RULES[fromLayer];\n return (rules.canReach as readonly string[]).includes(toLayer);\n}\n\n/**\n * Get layer hierarchy number (for comparison)\n * Higher number = higher layer\n */\nexport function getLayerDepth(layer: EpistemicLayer): number {\n switch (layer) {\n case \"L4\":\n return 4;\n case \"L3\":\n return 3;\n case \"L2\":\n return 2;\n case \"L1\":\n return 1;\n case \"ontological\":\n return 0; // Ontological exists outside the epistemic hierarchy\n case \"organizational\":\n return 0; // Organizational exists outside the epistemic hierarchy\n default:\n return 2;\n }\n}\n\n/**\n * Check if we can traverse from one layer to another\n * (considering intermediate layers)\n */\nexport function canTraverseToLayer(\n fromLayer: EpistemicLayer,\n toLayer: EpistemicLayer\n): boolean {\n const fromDepth = getLayerDepth(fromLayer);\n const toDepth = getLayerDepth(toLayer);\n\n // Ontological/organizational layers are special - use explicit rules\n if (\n fromLayer === \"ontological\" ||\n toLayer === \"ontological\" ||\n fromLayer === \"organizational\" ||\n toLayer === \"organizational\"\n ) {\n return isValidLayerConnection(fromLayer, toLayer);\n }\n\n // Can always stay at same layer\n if (fromDepth === toDepth) {\n return true;\n }\n\n // Can go up (L1→L2→L3→L4) or down (L4→L3→L2→L1)\n // But must respect layer rules\n return isValidLayerConnection(fromLayer, toLayer);\n}\n\n// =============================================================================\n// PHASE 2D: LAYER-AWARE TRAVERSAL\n// =============================================================================\n\n/**\n * Traversal mode - determines how to traverse the graph\n *\n * anchor_down: Start at L3 belief, traverse to L2 evidence, stop at L1 sources\n * anchor_up: Start at L2 evidence, traverse to L3 beliefs it supports\n * same_layer: Traverse within a single layer (e.g., belief → belief)\n * decision_trace: Start at L4 decision, traverse to L3 beliefs it was based on\n */\nexport type TraversalMode =\n | \"anchor_down\"\n | \"anchor_up\"\n | \"same_layer\"\n | \"decision_trace\";\n\n/**\n * Traversal options for layer-aware queries\n */\nexport type TraversalOptions = {\n /** Starting node ID */\n startNodeId: Id<\"epistemicNodes\">;\n /** Traversal mode */\n mode: TraversalMode;\n /** Edge types to follow (empty = all valid for mode) */\n allowedEdgeTypes?: string[];\n /** Maximum depth */\n maxDepth?: number;\n /** Minimum layer to stop at (L1 = 1, L4 = 4) */\n minLayer?: number;\n /** Maximum layer to reach */\n maxLayer?: number;\n};\n\n/**\n * Check if traversal should continue based on layer constraints\n */\nexport function shouldContinueTraversal(\n currentLayer: EpistemicLayer,\n targetLayer: EpistemicLayer,\n options: {\n mode: TraversalMode;\n minLayer?: number;\n maxLayer?: number;\n }\n): boolean {\n const currentDepth = getLayerDepth(currentLayer);\n const targetDepth = getLayerDepth(targetLayer);\n\n // Check min/max layer constraints\n if (options.minLayer !== undefined && targetDepth < options.minLayer) {\n return false; // Would go below minimum layer\n }\n if (options.maxLayer !== undefined && targetDepth > options.maxLayer) {\n return false; // Would go above maximum layer\n }\n\n // Mode-specific rules\n switch (options.mode) {\n case \"anchor_down\":\n // Can only go down (L4→L3→L2→L1)\n return targetDepth < currentDepth || targetDepth === currentDepth;\n\n case \"anchor_up\":\n // Can only go up (L1→L2→L3→L4)\n return targetDepth > currentDepth || targetDepth === currentDepth;\n\n case \"same_layer\":\n // Must stay at same layer\n return targetDepth === currentDepth;\n\n case \"decision_trace\":\n // Decisions (L4) can trace to beliefs (L3), stop there\n return currentDepth === 4\n ? targetDepth === 3\n : targetDepth === currentDepth;\n\n default:\n return true;\n }\n}\n\n/**\n * Get default minLayer for a traversal mode\n */\nexport function getDefaultMinLayer(mode: TraversalMode): number {\n switch (mode) {\n case \"anchor_down\":\n return 1; // Can go all the way to L1 sources\n case \"anchor_up\":\n return 2; // Start at L2 evidence minimum\n case \"same_layer\":\n return 1; // No constraint\n case \"decision_trace\":\n return 3; // Stop at L3 beliefs (don't go to L2 evidence)\n default:\n return 1;\n }\n}\n\n/**\n * Get allowed edge types for a traversal mode\n */\nexport function getDefaultEdgeTypesForMode(mode: TraversalMode): string[] {\n switch (mode) {\n case \"anchor_down\":\n // From beliefs/questions down to evidence and sources\n return [\n \"informs\", // evidence → belief (traverse backwards)\n \"derived_from\", // evidence → source (provenance) + evidence → question\n ];\n case \"anchor_up\":\n // From evidence up to beliefs\n return [\"informs\", \"derived_from\"];\n case \"same_layer\":\n // Within-layer relationships\n return [\n // L3: Belief ↔ Belief\n \"depends_on\",\n \"supports\",\n \"contains\",\n // L3: Question ↔ Question\n \"prerequisite_for\",\n \"parallel_to\",\n // L2: Evidence ↔ Evidence\n \"corroborates\",\n \"extends\",\n \"same_source_as\",\n \"same_theme_as\",\n ];\n case \"decision_trace\":\n // From decisions to beliefs\n return [\n \"derived_from\",\n \"depends_on\",\n \"contains\",\n ];\n default:\n return [];\n }\n}\n\n// =============================================================================\n// PHASE 2C: EDGE LAYER RULES\n// =============================================================================\n\n/**\n * Edge Layer Rules - defines valid layer combinations for each edge type\n *\n * Format: { from: [allowed source layers], to: [allowed target layers] }\n *\n * Key rules:\n * - L4 edges: Decision → L3 (beliefs, questions, themes)\n * - Cross-layer edges: L2 → L3 (evidence informs beliefs)\n * - Same-layer edges: L3 → L3, L2 → L2 (beliefs depend on beliefs)\n * - Downward edges: L2 → L1 (evidence extracted from source)\n * - Lifecycle edges: same layer only (supersedes)\n */\nexport const EDGE_LAYER_RULES: Record<\n string,\n { from: EpistemicLayer[]; to: EpistemicLayer[]; description: string }\n> = {\n // === L4 Decision Edges ===\n based_on_belief: {\n from: [\"L4\"],\n to: [\"L3\"],\n description: \"Decision → Belief (L4 → L3)\",\n },\n based_on_question: {\n from: [\"L4\"],\n to: [\"L3\"],\n description: \"Decision → Question (L4 → L3)\",\n },\n blocked_by_contradiction: {\n from: [\"L4\"],\n to: [\"L3\"],\n description: \"Decision → Contradiction (L4 → L3)\",\n },\n informed_by_theme: {\n from: [\"L4\"],\n to: [\"L3\"],\n description: \"Decision → Theme (L4 → L3)\",\n },\n\n // === Evidence Flow (L2 → L3, L2 → L1) ===\n derived_from: {\n from: [\"L2\", \"L3\", \"L4\"],\n to: [\"L1\", \"L2\", \"L3\"],\n description: \"A was produced from B (provenance chain)\",\n },\n answers: {\n from: [\"L2\"],\n to: [\"L3\"],\n description: \"Evidence → Question (L2 → L3)\",\n },\n responds_to: {\n from: [\"L2\"],\n to: [\"L3\"],\n description: \"Answer → Question (L2 → L3)\",\n },\n informs: {\n from: [\"L2\"],\n to: [\"L3\"],\n description: \"Evidence → Belief (L2 → L3)\",\n },\n qualifies: {\n from: [\"L2\"],\n to: [\"L3\"],\n description: \"Evidence → Belief (L2 → L3)\",\n },\n\n // === Question → Belief (L3 → L3) ===\n tests: {\n from: [\"L3\"],\n to: [\"L3\"],\n description: \"Question → Belief (L3 → L3)\",\n },\n explores: {\n from: [\"L3\"],\n to: [\"L3\"],\n description: \"Question → Belief assumption (L3 → L3)\",\n },\n\n // === Synthesis (L2 → L2, L2 → L1) ===\n based_on: {\n from: [\"L2\"],\n to: [\"L2\", \"L1\"],\n description: \"Synthesis → Evidence/Source (L2 → L2/L1)\",\n },\n\n // === Theme Relationships (L3 → L3) ===\n relates_to_thesis: {\n from: [\"L3\"],\n to: [\"L3\"],\n description: \"Belief → Theme (L3 → L3)\",\n },\n belongs_to: {\n from: [\"L3\", \"L2\"], // Can belong to theme from L3 or L2\n to: [\"L3\"],\n description: \"Any → Theme (L3/L2 → L3)\",\n },\n plays_theme: {\n from: [\"L3\"],\n to: [\"L3\"],\n description: \"Deal → Theme (L3 → L3)\",\n },\n\n // === Topic Hierarchy (L3 → organizational) ===\n scoped_by: {\n from: [\"L3\"],\n to: [\"organizational\"],\n description: \"Belief/Question → Topic (L3 → organizational)\",\n },\n\n // === Deal/Company ===\n evaluates: {\n from: [\"L3\"],\n to: [\"ontological\"],\n description: \"Deal → Company (L3 → ontological)\",\n },\n\n // === People (ontological → ontological, ontological → L3) ===\n perspective_on: {\n from: [\"ontological\"],\n to: [\"L3\"],\n description: \"Person → Belief/Theme (ontological → L3)\",\n },\n works_at: {\n from: [\"ontological\"],\n to: [\"ontological\"],\n description: \"Person → Company (ontological → ontological)\",\n },\n\n // === Value Chain (ontological) ===\n participates_in: {\n from: [\"ontological\"],\n to: [\"ontological\"],\n description: \"Company → ValueChain (ontological → ontological)\",\n },\n performs: {\n from: [\"ontological\"],\n to: [\"ontological\"],\n description: \"Company → Function (ontological → ontological)\",\n },\n function_in: {\n from: [\"ontological\"],\n to: [\"ontological\"],\n description: \"Function → ValueChain (ontological → ontological)\",\n },\n impacts: {\n from: [\"L3\"],\n to: [\"ontological\"],\n description: \"Theme → ValueChain (L3 → ontological)\",\n },\n\n // === Investment (ontological) ===\n invested_in: {\n from: [\"ontological\"],\n to: [\"ontological\"],\n description: \"Investor → Company (ontological → ontological)\",\n },\n raised_from: {\n from: [\"ontological\"],\n to: [\"ontological\"],\n description: \"Company → Investor (ontological → ontological)\",\n },\n\n // === Entity↔Belief Bridge (OE-B) ===\n about_entity: {\n from: [\"L3\"],\n to: [\"ontological\"],\n description: \"Belief/Question/Theme → Entity (L3 → ontological)\",\n },\n entity_referenced_in: {\n from: [\"ontological\"],\n to: [\"L2\"],\n description: \"Entity → Evidence (ontological → L2)\",\n },\n mentioned_in: {\n from: [\"ontological\"],\n to: [\"L1\"],\n description: \"Entity → Source document (ontological → L1)\",\n },\n founded_by: {\n from: [\"ontological\"],\n to: [\"ontological\"],\n description: \"Company → Person (ontological → ontological)\",\n },\n competes_with: {\n from: [\"ontological\"],\n to: [\"ontological\"],\n description: \"Company → Company (ontological → ontological)\",\n },\n contains: {\n from: [\"ontological\"],\n to: [\"ontological\"],\n description: \"ValueChain → Function (ontological → ontological)\",\n },\n\n // === Lifecycle (same layer only) ===\n supersedes: {\n from: [\"L4\", \"L3\", \"L2\", \"L1\", \"ontological\", \"organizational\"],\n to: [\"L4\", \"L3\", \"L2\", \"L1\", \"ontological\", \"organizational\"],\n description: \"NewNode → OldNode (same layer only - validated separately)\",\n },\n same_as: {\n from: [\"L4\", \"L3\", \"L2\", \"L1\", \"ontological\", \"organizational\"],\n to: [\"L4\", \"L3\", \"L2\", \"L1\", \"ontological\", \"organizational\"],\n description: \"Duplicate detection (same layer only - validated separately)\",\n },\n\n // === Same-Type: Belief ↔ Belief (L3 → L3) ===\n depends_on: {\n from: [\"L3\"],\n to: [\"L3\"],\n description: \"Belief B requires Belief A (L3 → L3)\",\n },\n reinforces: {\n from: [\"L3\"],\n to: [\"L3\"],\n description: \"Beliefs strengthen each other (L3 → L3)\",\n },\n parent_of: {\n from: [\"L3\", \"organizational\"],\n to: [\"L3\", \"organizational\"],\n description:\n \"A is higher-level than B (L3 → L3, organizational → organizational)\",\n },\n child_of: {\n from: [\"L3\"],\n to: [\"L3\"],\n description: \"Belief A is more specific (L3 → L3)\",\n },\n\n // === Same-Type: Question ↔ Question (L3 → L3) ===\n prerequisite_for: {\n from: [\"L3\"],\n to: [\"L3\"],\n description: \"Question A must be answered first (L3 → L3)\",\n },\n parallel_to: {\n from: [\"L3\"],\n to: [\"L3\"],\n description: \"Same topic, different angles (L3 → L3)\",\n },\n\n // === Same-Type: Evidence ↔ Evidence (L2 → L2) ===\n corroborates: {\n from: [\"L2\"],\n to: [\"L2\"],\n description: \"Independent support (L2 → L2)\",\n },\n extends: {\n from: [\"L2\"],\n to: [\"L2\"],\n description: \"Adds depth (L2 → L2)\",\n },\n same_source_as: {\n from: [\"L2\"],\n to: [\"L2\"],\n description: \"Same document/study (L2 → L2)\",\n },\n same_theme_as: {\n from: [\"L2\"],\n to: [\"L2\"],\n description: \"Same topic/entity (L2 → L2)\",\n },\n\n // === NEW: Deep Epistemic Analysis Edges (Phase: Schema Upgrade) ===\n assumes: {\n from: [\"L3\"],\n to: [\"L3\"],\n description:\n \"Hidden dependency - Belief B implicitly assumes Belief A (L3 → L3)\",\n },\n would_predict: {\n from: [\"L3\"],\n to: [\"L2\"],\n description:\n \"Pre-registered prediction - If Belief true, expect Evidence (L3 → L2)\",\n },\n analogous_to: {\n from: [\"L3\"],\n to: [\"L3\"],\n description: \"Explicit analogy - Belief A is like Belief B (L3 → L3)\",\n },\n independent_of: {\n from: [\"L2\"],\n to: [\"L2\"],\n description:\n \"True evidence independence - Evidence A independent of B (L2 → L2)\",\n },\n\n // NOTE: Deprecated edge types (supports, contradicts, derived_from, cites,\n // summarizes, related_to, partially_answers, blocks, refines, branches_from)\n // have been REMOVED from the system. Use compliant alternatives instead.\n};\n\n/**\n * Validate an edge against layer rules\n *\n * Returns { valid: true } or { valid: false, reason: string }\n */\nexport function validateEdgeLayers(\n edgeType: string,\n fromLayer: EpistemicLayer,\n toLayer: EpistemicLayer\n): { valid: boolean; reason?: string } {\n const rules = EDGE_LAYER_RULES[edgeType];\n\n // Unknown edge type - allow but warn\n if (!rules) {\n console.warn(\n `[EdgeValidation] Unknown edge type: ${edgeType}, allowing by default`\n );\n return { valid: true };\n }\n\n // Special handling for same-layer edges (supersedes)\n if (edgeType === \"supersedes\") {\n if (fromLayer !== toLayer) {\n return {\n valid: false,\n reason: `${edgeType} edges must be between nodes of the same layer. Got ${fromLayer} → ${toLayer}`,\n };\n }\n return { valid: true };\n }\n\n // Check from layer\n if (!rules.from.includes(fromLayer)) {\n return {\n valid: false,\n reason: `Edge type '${edgeType}' does not allow source layer ${fromLayer}. Allowed: ${rules.from.join(\", \")}`,\n };\n }\n\n // Check to layer\n if (!rules.to.includes(toLayer)) {\n return {\n valid: false,\n reason: `Edge type '${edgeType}' does not allow target layer ${toLayer}. Allowed: ${rules.to.join(\", \")}`,\n };\n }\n\n return { valid: true };\n}\n\n","/**\n * Epistemic Spine helper module split from epistemicHelpers.ts.\n */\n\nimport { internal } from \"./convex\";\nimport type { Id, MutationCtx } from \"./convex\";\nimport { generateGlobalId } from \"./globalId\";\nimport { getNodeLayer, validateEdgeLayers } from \"./epistemicLayerRules\";\n\ntype NodeTypeIndexQuery = {\n eq(field: string, value: unknown): NodeTypeIndexQuery;\n};\n\n/**\n * Edge type union for createEpistemicEdge\n * Phase 2C: Updated to include L4 edges and modern edge types\n * Phase 3: Added full epistemic impact edges for confidence propagation\n */\ntype EpistemicEdgeType =\n // Canonical edge types (K-tier compliant)\n | \"derived_from\" // replaces: answers, extracted_from, based_on, same_as, based_on_belief, based_on_question\n | \"supports\" // replaces: reinforces, strengthened_by, validated_by, weakened_by, alternative_to, falsified_by, exclusive_with (with appropriate weight)\n | \"contains\" // replaces: parent_of, child_of, about_entity, entity_referenced_in, subsumes, informed_by_theme\n | \"depends_on\" // replaces: collapses_if, cascade_from, required_for, blocks, blocked_by_contradiction\n | \"informs\"\n | \"tests\" // replaces: explores\n | \"responds_to\"\n // Theme relationships\n | \"relates_to_thesis\"\n | \"belongs_to\"\n | \"plays_theme\"\n // Lifecycle\n | \"supersedes\"\n // Same-type: Belief - Cluster Mapping (Thesis Validation Sprints)\n | \"counterfactual_of\"\n | \"cascade_to\"\n | \"mutually_exclusive\"\n | \"correlates_with\"\n | \"amplifies\"\n | \"precondition_for\"\n | \"in_tension_with\"\n // Same-type: Belief - Deep Epistemic Analysis (Tier 2)\n | \"assumes\"\n | \"would_predict\"\n | \"analogous_to\"\n | \"independent_of\"\n // Same-type: Question\n | \"prerequisite_for\"\n | \"parallel_to\"\n // Same-type: Evidence\n | \"corroborates\"\n | \"extends\"\n | \"same_source_as\"\n | \"same_theme_as\"\n // Ontological\n | \"evaluates\"\n | \"perspective_on\"\n | \"works_at\"\n | \"participates_in\"\n | \"performs\"\n | \"function_in\"\n | \"impacts\"\n | \"invested_in\"\n | \"raised_from\"\n // People/Entity References\n | \"mentioned_in\"\n | \"founded_by\"\n | \"competes_with\";\n\n// NOTE: Deprecated edge types have been REMOVED from this type.\n// See schema.ts for the list of removed types and their compliant alternatives.\n\n// =============================================================================\n// CONFIDENCE NORMALIZATION\n// =============================================================================\n\n/**\n * Normalize confidence to a 0-1 number regardless of input format.\n *\n * Handles:\n * - number (0-1): returned as-is\n * - number (1-100): divided by 100\n * - string (\"high\"/\"medium\"/\"low\"): mapped to 0.8/0.5/0.3\n * - undefined/null/other: returns 0.5 default\n *\n * This is the canonical way to read confidence from any source.\n */\nexport function normalizeConfidence(confidence: unknown): number {\n if (typeof confidence === \"number\") {\n return confidence > 1 ? confidence / 100 : confidence;\n }\n if (typeof confidence === \"string\") {\n switch (confidence) {\n case \"high\":\n return 0.8;\n case \"medium\":\n return 0.5;\n case \"low\":\n return 0.3;\n default:\n return 0.5;\n }\n }\n return 0.5;\n}\n\n/**\n * Epistemic Edge Propagation Semantics\n *\n * Each edge type has specific propagation rules for confidence cascades:\n *\n * | Edge Type | Direction | Propagation Rule |\n * |-------------------|--------------|-----------------------------------------------------------|\n * | depends_on | B → A | A.conf = min(A.conf, B.conf + 0.2) |\n * | reinforces | A ↔ B | Both get boost when either validated |\n * | falsified_by | B → A | A.conf = 1 - B.conf (inverse) |\n * | exclusive_with | A ↔ B | A.conf + B.conf ≤ 1.0 (redistribute on evidence) |\n * | contradicts | A ↔ B | Creates tension - neither can be validated without fork |\n * | collapses_if | A → B | If A.conf < threshold, B.conf → 0 |\n * | cascade_from | A → B | B.conf_delta = A.conf_delta * damping_factor |\n * | strengthened_by | A → B | B.conf += A.conf_delta * correlation |\n * | weakened_by | A → B | B.conf -= A.conf_delta * correlation |\n * | alternative_to | A ↔ B | Evidence for A reduces B, and vice versa |\n * | subsumes | A → B | A.conf >= B.conf always |\n * | validated_by | A → B | If A validated, B gains confidence |\n * | required_for | A → B | B cannot be validated until A is validated |\n * | blocks | A → B | B resolution blocked until A resolved |\n */\n\n/**\n * Create an epistemic edge between two nodes\n *\n * Phase 1 (Graph Architecture): Writes to Neo4j directly - Neo4j is source of truth.\n * Returns globalId (string) instead of Convex edge ID.\n *\n * Phase 2C: Validates layer rules before creation\n */\nexport async function createEpistemicEdge(\n ctx: MutationCtx,\n params: {\n fromNodeId: Id<\"epistemicNodes\">;\n toNodeId: Id<\"epistemicNodes\">;\n edgeType: EpistemicEdgeType;\n weight?: number;\n confidence?: number;\n context?: string;\n // NOTE: 'relation' field has been removed. Use 'weight' instead.\n projectId?: string;\n createdBy: string;\n // Phase 2C: Allow skipping validation for migrations\n skipLayerValidation?: boolean;\n }\n): Promise<string> {\n const globalId = generateGlobalId();\n\n // Get node types for denormalization\n const fromNode = await ctx.db.get(params.fromNodeId);\n const toNode = await ctx.db.get(params.toNodeId);\n\n if (!fromNode || !toNode) {\n throw new Error(\"One or both nodes not found\");\n }\n\n // Phase 2C: Get layers (use stored or derive from nodeType)\n const fromLayer = fromNode.epistemicLayer || getNodeLayer(fromNode.nodeType);\n const toLayer = toNode.epistemicLayer || getNodeLayer(toNode.nodeType);\n\n // Phase 2C: Validate layer rules\n if (!params.skipLayerValidation) {\n const validation = validateEdgeLayers(params.edgeType, fromLayer, toLayer);\n if (!validation.valid) {\n throw new Error(\n `[EdgeValidation] Invalid edge: ${validation.reason}. ` +\n `Attempted: ${params.edgeType} from ${fromNode.nodeType}(${fromLayer}) → ${toNode.nodeType}(${toLayer})`\n );\n }\n }\n\n // Phase 1 (Graph Architecture): Write to Neo4j directly - Neo4j is source of truth\n await ctx.scheduler.runAfter(0, internal.neo4jEdgeAPI.createEdge, {\n globalId,\n fromGlobalId: fromNode.globalId,\n toGlobalId: toNode.globalId,\n edgeType: params.edgeType,\n weight: params.weight,\n confidence: params.confidence,\n context: params.context,\n createdBy: params.createdBy,\n topicId: params.projectId ? String(params.projectId) : undefined,\n fromNodeType: fromNode.nodeType,\n toNodeType: toNode.nodeType,\n fromLayer,\n toLayer,\n });\n\n return globalId;\n}\n\n/**\n * Create an edge when linking an insight to a question\n * This creates a \"derived_from\" edge (evidence answers/informs question)\n */\nexport async function createEdgeForInsightQuestionLink(\n ctx: MutationCtx,\n questionId: Id<\"epistemicNodes\">,\n insightId: Id<\"epistemicNodes\">,\n createdBy: string\n): Promise<string | null> {\n console.log(\"[EpistemicSpine] Creating edge for insight-question link:\", {\n questionId: String(questionId),\n insightId: String(insightId),\n });\n\n // Find the epistemic nodes for both entities\n const questionNode = await findNodeByLegacyId(ctx, \"question\", questionId);\n const insightNode = await findNodeByLegacyId(ctx, \"insight\", insightId);\n\n console.log(\"[EpistemicSpine] Found nodes:\", {\n questionNode: questionNode ? String(questionNode) : null,\n insightNode: insightNode ? String(insightNode) : null,\n });\n\n if (!questionNode || !insightNode) {\n // Nodes don't exist yet - this can happen for legacy data\n // They'll be created during backfill\n console.log(\"[EpistemicSpine] Missing nodes, skipping edge creation\");\n return null;\n }\n\n // Get the question for projectId\n const question = await ctx.db.get(questionId);\n const projectId = question?.projectId;\n\n // Create the edge: Evidence -> Question\n // Use \"derived_from\" - canonical replacement for \"answers\" edge type\n return await createEpistemicEdge(ctx, {\n fromNodeId: insightNode,\n toNodeId: questionNode,\n edgeType: \"derived_from\",\n projectId,\n createdBy,\n context: \"Linked from questions workspace\",\n });\n}\n\n/**\n * Find an epistemic node by its legacy ID (stored in metadata)\n */\nasync function findNodeByLegacyId(\n ctx: MutationCtx,\n legacyType: \"insight\" | \"belief\" | \"question\" | \"artifact\",\n legacyId: Id<\"epistemicNodes\"> | Id<\"finalArtifacts\">\n): Promise<Id<\"epistemicNodes\"> | null> {\n // Query all nodes and find the one with matching legacy ID\n // This is not ideal for performance, but works for now\n // TODO: Add a dedicated index for legacy IDs\n const nodeType =\n legacyType === \"insight\"\n ? \"evidence\"\n : legacyType === \"artifact\"\n ? \"source\"\n : legacyType;\n\n const nodes = await ctx.db\n .query(\"epistemicNodes\")\n .withIndex(\"by_nodeType\", (q: NodeTypeIndexQuery) =>\n q.eq(\"nodeType\", nodeType),\n )\n .collect();\n\n const legacyKey = `legacy${legacyType.charAt(0).toUpperCase() + legacyType.slice(1)}Id`;\n\n // Convert legacyId to string for comparison (Convex Id objects need string comparison)\n const legacyIdStr = String(legacyId);\n\n const found = nodes.find((n) => {\n const metadata = n.metadata as Record<string, unknown> | undefined;\n const storedId = metadata?.[legacyKey];\n // Compare as strings to handle Convex Id serialization\n return storedId && String(storedId) === legacyIdStr;\n });\n\n if (!found) {\n console.log(\n `[EpistemicSpine] Node not found for ${legacyType}:${legacyIdStr}, searched ${nodes.length} ${nodeType} nodes`\n );\n }\n\n return found?._id ?? null;\n}\n"]}
1
+ {"version":3,"sources":["../src/convex.ts","../src/epistemicLayerRules.ts","../src/epistemicEdgeCreation.ts"],"names":[],"mappings":";;;;AAc0B,iBAAA;AACnB,IAAM,QAAA,GAAW,MAAA;;;ACiDjB,SAAS,aAAa,QAAA,EAAkC;AAC7D,EAAA,QAAQ,QAAA;AAAU;AAAA,IAEhB,KAAK,UAAA;AACH,MAAA,OAAO,IAAA;AAAA;AAAA,IAGT,KAAK,QAAA;AAAA,IACL,KAAK,UAAA;AAAA,IACL,KAAK,OAAA;AAAA,IACL,KAAK,MAAA;AACH,MAAA,OAAO,IAAA;AAAA;AAAA,IAGT,KAAK,OAAA;AAAA,IACL,KAAK,UAAA;AAAA,IACL,KAAK,WAAA;AAAA,IACL,KAAK,QAAA;AACH,MAAA,OAAO,IAAA;AAAA;AAAA,IAGT,KAAK,aAAA;AAAA,IACL,KAAK,SAAA;AAAA,IACL,KAAK,QAAA;AACH,MAAA,OAAO,IAAA;AAAA;AAAA,IAGT,KAAK,SAAA;AAAA,IACL,KAAK,QAAA;AAAA,IACL,KAAK,UAAA;AAAA,IACL,KAAK,UAAA;AAAA,IACL,KAAK,aAAA;AACH,MAAA,OAAO,aAAA;AAAA;AAAA,IAG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AAA,OAAA,CAAQ,GAAA;AAAA,MACN,CAAA,oCAAA,EAAuC,UAAU,CAAA,CAAA,EAAI,WAAW,cAAc,KAAA,CAAM,MAAM,IAAI,QAAQ,CAAA,MAAA;AAAA,KACxG;AAAA,EACF;AAEA,EAAA,OAAO,OAAO,GAAA,IAAO,IAAA;AACvB","file":"epistemicEdgeCreation.js","sourcesContent":["import {\n actionGeneric,\n anyApi,\n componentsGeneric,\n httpActionGeneric,\n internalActionGeneric,\n internalMutationGeneric,\n internalQueryGeneric,\n mutationGeneric,\n queryGeneric,\n} from \"convex/server\";\nimport type { GenericId } from \"convex/values\";\n\nexport const api = anyApi as any;\nexport const components = componentsGeneric() as any;\nexport const internal = anyApi as any;\n\nexport type TableNames = string;\nexport type Id<TableName extends TableNames = string> = GenericId<TableName>;\nexport type Doc<TableName extends TableNames = string> = any;\nexport type DataModel = any;\ntype IndexRangeBuilder = {\n field(fieldName: string): string;\n eq(fieldName: string, value: unknown): IndexRangeBuilder;\n gt(fieldName: string, value: unknown): IndexRangeBuilder;\n gte(fieldName: string, value: unknown): IndexRangeBuilder;\n lt(fieldName: string, value: unknown): IndexRangeBuilder;\n lte(fieldName: string, value: unknown): IndexRangeBuilder;\n};\ntype FilterBuilder = {\n eq(left: unknown, right: unknown): unknown;\n neq(left: unknown, right: unknown): unknown;\n gt(left: unknown, right: unknown): unknown;\n gte(left: unknown, right: unknown): unknown;\n lt(left: unknown, right: unknown): unknown;\n lte(left: unknown, right: unknown): unknown;\n and(...clauses: unknown[]): unknown;\n or(...clauses: unknown[]): unknown;\n field(fieldName: string): unknown;\n};\ntype QueryInitializer<TableName extends TableNames> = {\n withIndex(\n indexName: string,\n range?: (q: any) => unknown\n ): QueryInitializer<TableName>;\n filter(predicate: (q: any) => unknown): QueryInitializer<TableName>;\n order(direction: \"asc\" | \"desc\"): QueryInitializer<TableName>;\n collect(): Promise<Doc<TableName>[]>;\n take(limit: number): Promise<Doc<TableName>[]>;\n first(): Promise<Doc<TableName> | null>;\n unique(): Promise<Doc<TableName> | null>;\n};\nexport type DatabaseReader = {\n get<TableName extends TableNames>(\n id: Id<TableName>\n ): Promise<Doc<TableName> | null>;\n query<TableName extends TableNames>(\n tableName: TableName\n ): QueryInitializer<TableName>;\n normalizeId?<TableName extends TableNames>(\n tableName: TableName,\n id: string\n ): Id<TableName> | null;\n};\nexport type DatabaseWriter = DatabaseReader & {\n insert<TableName extends TableNames>(\n tableName: TableName,\n value: Record<string, unknown>\n ): Promise<Id<TableName>>;\n patch<TableName extends TableNames>(\n id: Id<TableName>,\n value: Record<string, unknown>\n ): Promise<void>;\n replace<TableName extends TableNames>(\n id: Id<TableName>,\n value: Record<string, unknown>\n ): Promise<void>;\n delete<TableName extends TableNames>(id: Id<TableName>): Promise<void>;\n};\ntype Scheduler = {\n runAfter(delayMs: number, functionReference: unknown, args?: unknown): Promise<void>;\n};\ntype AuthReader = {\n getUserIdentity(): Promise<unknown>;\n};\ntype RuntimeInvoker = {\n runQuery(functionReference: unknown, args?: unknown): Promise<any>;\n runMutation(functionReference: unknown, args?: unknown): Promise<any>;\n runAction(functionReference: unknown, args?: unknown): Promise<any>;\n};\nexport type QueryCtx = RuntimeInvoker & {\n auth: AuthReader;\n db: DatabaseReader;\n scheduler: Scheduler;\n};\nexport type MutationCtx = RuntimeInvoker & {\n auth: AuthReader;\n db: DatabaseWriter;\n scheduler: Scheduler;\n};\nexport type ActionCtx = RuntimeInvoker & {\n auth: AuthReader;\n scheduler: Scheduler;\n};\n\ntype ConvexFunctionBuilder<Ctx> = <\n Definition extends { handler?: (ctx: Ctx, args: any) => any },\n>(\n definition: Definition\n) => any;\n\nexport const action = actionGeneric as unknown as ConvexFunctionBuilder<ActionCtx>;\nexport const httpAction =\n httpActionGeneric as unknown as ConvexFunctionBuilder<ActionCtx>;\nexport const internalAction =\n internalActionGeneric as unknown as ConvexFunctionBuilder<ActionCtx>;\nexport const internalMutation =\n internalMutationGeneric as unknown as ConvexFunctionBuilder<MutationCtx>;\nexport const internalQuery =\n internalQueryGeneric as unknown as ConvexFunctionBuilder<QueryCtx>;\nexport const mutation =\n mutationGeneric as unknown as ConvexFunctionBuilder<MutationCtx>;\nexport const query = queryGeneric as unknown as ConvexFunctionBuilder<QueryCtx>;\n","/**\n * Epistemic Spine helper module split from epistemicHelpers.ts.\n */\n\nimport type { Id } from \"./convex\";\n\n// =============================================================================\n// TYPE MAPPINGS\n// =============================================================================\n\ntype EpistemicNodeType =\n // L4: Audit targets\n | \"decision\"\n // L3: Traversal anchors\n | \"belief\"\n | \"question\"\n | \"theme\"\n | \"deal\"\n // L2: Compression boundary\n | \"claim\"\n | \"evidence\"\n | \"synthesis\"\n | \"answer\"\n // L1: Terminal leaves\n | \"atomic_fact\"\n | \"excerpt\"\n | \"source\";\n\ntype OntologicalNodeType =\n | \"company\"\n | \"person\"\n | \"investor\"\n | \"function\"\n | \"value_chain\";\n\ntype NodeType = EpistemicNodeType | OntologicalNodeType;\n\n// =============================================================================\n// EPISTEMIC LAYER ARCHITECTURE (Lucern Invariant Compliance)\n// =============================================================================\n\n/**\n * Epistemic Layer - governs traversal rules\n * L4 → L3 → L2 → L1 (never skip layers)\n */\nexport type EpistemicLayer =\n | \"L4\"\n | \"L3\"\n | \"L2\"\n | \"L1\"\n | \"ontological\"\n | \"organizational\";\n\n/**\n * Map nodeType to its epistemic layer\n *\n * Layer semantics:\n * - L4: Audit targets (decisions, outcomes) - what we committed to\n * - L3: Traversal anchors (beliefs, questions, themes) - epistemic structure\n * - L2: Compression boundary (claims, evidence, synthesis) - minimum reasoning unit\n * - L1: Terminal leaves (atomic_fact, excerpt, source) - non-traversable grounding\n * - ontological: Entities in the world (companies, people) - not epistemic\n * - organizational: Structural containers (topics, lenses, worktrees) - not epistemic\n */\nexport function getNodeLayer(nodeType: string): EpistemicLayer {\n switch (nodeType) {\n // L4: Audit targets\n case \"decision\":\n return \"L4\";\n\n // L3: Traversal anchors\n case \"belief\":\n case \"question\":\n case \"theme\":\n case \"deal\":\n return \"L3\";\n\n // L2: Compression boundary\n case \"claim\":\n case \"evidence\":\n case \"synthesis\":\n case \"answer\":\n return \"L2\";\n\n // L1: Terminal leaves\n case \"atomic_fact\":\n case \"excerpt\":\n case \"source\":\n return \"L1\";\n\n // Ontological entities\n case \"company\":\n case \"person\":\n case \"investor\":\n case \"function\":\n case \"value_chain\":\n return \"ontological\";\n\n // Organizational containers\n case \"topic\":\n return \"organizational\";\n\n default:\n // Unknown types default to L2 (safest for traversal)\n console.warn(\n `[EpistemicLayer] Unknown nodeType: ${nodeType}, defaulting to L2`\n );\n return \"L2\";\n }\n}\n\n/**\n * Layer traversal rules\n * Key constraint: Cannot skip layers during traversal\n */\nexport const LAYER_TRAVERSAL_RULES = {\n L4: {\n canReach: [\"L3\", \"L4\"], // Decisions can reach beliefs/questions\n mustPassThrough: \"L3\", // Must go through L3 to reach L2\n },\n L3: {\n canReach: [\"L2\", \"L3\", \"L4\"], // Beliefs can reach evidence, other beliefs, or decisions\n mustPassThrough: \"L2\", // Must go through L2 to reach L1\n },\n L2: {\n canReach: [\"L1\", \"L2\", \"L3\"], // Evidence can reach sources, other evidence, or beliefs\n mustPassThrough: null, // L2 can reach L1 directly\n },\n L1: {\n canReach: [\"L1\"], // Sources can only reach other sources\n mustPassThrough: null, // Terminal - no traversal beyond\n },\n ontological: {\n canReach: [\"L3\", \"L2\", \"ontological\"], // Entities can link to epistemic structure\n mustPassThrough: null, // No layer constraints for entities\n },\n organizational: {\n canReach: [\"L3\", \"L2\", \"organizational\"], // Containers scope epistemic structure + nest\n mustPassThrough: null, // No layer constraints for containers\n },\n} as const;\n\n/**\n * Check if a direct edge between two layers is allowed\n */\nexport function isValidLayerConnection(\n fromLayer: EpistemicLayer,\n toLayer: EpistemicLayer\n): boolean {\n const rules = LAYER_TRAVERSAL_RULES[fromLayer];\n return (rules.canReach as readonly string[]).includes(toLayer);\n}\n\n/**\n * Get layer hierarchy number (for comparison)\n * Higher number = higher layer\n */\nexport function getLayerDepth(layer: EpistemicLayer): number {\n switch (layer) {\n case \"L4\":\n return 4;\n case \"L3\":\n return 3;\n case \"L2\":\n return 2;\n case \"L1\":\n return 1;\n case \"ontological\":\n return 0; // Ontological exists outside the epistemic hierarchy\n case \"organizational\":\n return 0; // Organizational exists outside the epistemic hierarchy\n default:\n return 2;\n }\n}\n\n/**\n * Check if we can traverse from one layer to another\n * (considering intermediate layers)\n */\nexport function canTraverseToLayer(\n fromLayer: EpistemicLayer,\n toLayer: EpistemicLayer\n): boolean {\n const fromDepth = getLayerDepth(fromLayer);\n const toDepth = getLayerDepth(toLayer);\n\n // Ontological/organizational layers are special - use explicit rules\n if (\n fromLayer === \"ontological\" ||\n toLayer === \"ontological\" ||\n fromLayer === \"organizational\" ||\n toLayer === \"organizational\"\n ) {\n return isValidLayerConnection(fromLayer, toLayer);\n }\n\n // Can always stay at same layer\n if (fromDepth === toDepth) {\n return true;\n }\n\n // Can go up (L1→L2→L3→L4) or down (L4→L3→L2→L1)\n // But must respect layer rules\n return isValidLayerConnection(fromLayer, toLayer);\n}\n\n// =============================================================================\n// PHASE 2D: LAYER-AWARE TRAVERSAL\n// =============================================================================\n\n/**\n * Traversal mode - determines how to traverse the graph\n *\n * anchor_down: Start at L3 belief, traverse to L2 evidence, stop at L1 sources\n * anchor_up: Start at L2 evidence, traverse to L3 beliefs it supports\n * same_layer: Traverse within a single layer (e.g., belief → belief)\n * decision_trace: Start at L4 decision, traverse to L3 beliefs it was based on\n */\nexport type TraversalMode =\n | \"anchor_down\"\n | \"anchor_up\"\n | \"same_layer\"\n | \"decision_trace\";\n\n/**\n * Traversal options for layer-aware queries\n */\nexport type TraversalOptions = {\n /** Starting node ID */\n startNodeId: Id<\"epistemicNodes\">;\n /** Traversal mode */\n mode: TraversalMode;\n /** Edge types to follow (empty = all valid for mode) */\n allowedEdgeTypes?: string[];\n /** Maximum depth */\n maxDepth?: number;\n /** Minimum layer to stop at (L1 = 1, L4 = 4) */\n minLayer?: number;\n /** Maximum layer to reach */\n maxLayer?: number;\n};\n\n/**\n * Check if traversal should continue based on layer constraints\n */\nexport function shouldContinueTraversal(\n currentLayer: EpistemicLayer,\n targetLayer: EpistemicLayer,\n options: {\n mode: TraversalMode;\n minLayer?: number;\n maxLayer?: number;\n }\n): boolean {\n const currentDepth = getLayerDepth(currentLayer);\n const targetDepth = getLayerDepth(targetLayer);\n\n // Check min/max layer constraints\n if (options.minLayer !== undefined && targetDepth < options.minLayer) {\n return false; // Would go below minimum layer\n }\n if (options.maxLayer !== undefined && targetDepth > options.maxLayer) {\n return false; // Would go above maximum layer\n }\n\n // Mode-specific rules\n switch (options.mode) {\n case \"anchor_down\":\n // Can only go down (L4→L3→L2→L1)\n return targetDepth < currentDepth || targetDepth === currentDepth;\n\n case \"anchor_up\":\n // Can only go up (L1→L2→L3→L4)\n return targetDepth > currentDepth || targetDepth === currentDepth;\n\n case \"same_layer\":\n // Must stay at same layer\n return targetDepth === currentDepth;\n\n case \"decision_trace\":\n // Decisions (L4) can trace to beliefs (L3), stop there\n return currentDepth === 4\n ? targetDepth === 3\n : targetDepth === currentDepth;\n\n default:\n return true;\n }\n}\n\n/**\n * Get default minLayer for a traversal mode\n */\nexport function getDefaultMinLayer(mode: TraversalMode): number {\n switch (mode) {\n case \"anchor_down\":\n return 1; // Can go all the way to L1 sources\n case \"anchor_up\":\n return 2; // Start at L2 evidence minimum\n case \"same_layer\":\n return 1; // No constraint\n case \"decision_trace\":\n return 3; // Stop at L3 beliefs (don't go to L2 evidence)\n default:\n return 1;\n }\n}\n\n/**\n * Get allowed edge types for a traversal mode\n */\nexport function getDefaultEdgeTypesForMode(mode: TraversalMode): string[] {\n switch (mode) {\n case \"anchor_down\":\n // From beliefs/questions down to evidence and sources\n return [\n \"informs\", // evidence → belief (traverse backwards)\n \"derived_from\", // evidence → source (provenance) + evidence → question\n ];\n case \"anchor_up\":\n // From evidence up to beliefs\n return [\"informs\", \"derived_from\"];\n case \"same_layer\":\n // Within-layer relationships\n return [\n // L3: Belief ↔ Belief\n \"depends_on\",\n \"supports\",\n \"contains\",\n // L3: Question ↔ Question\n \"prerequisite_for\",\n \"parallel_to\",\n // L2: Evidence ↔ Evidence\n \"corroborates\",\n \"extends\",\n \"same_source_as\",\n \"same_theme_as\",\n ];\n case \"decision_trace\":\n // From decisions to beliefs\n return [\n \"derived_from\",\n \"depends_on\",\n \"contains\",\n ];\n default:\n return [];\n }\n}\n\n// =============================================================================\n// PHASE 2C: EDGE LAYER RULES\n// =============================================================================\n\n/**\n * Edge Layer Rules - defines valid layer combinations for each edge type\n *\n * Format: { from: [allowed source layers], to: [allowed target layers] }\n *\n * Key rules:\n * - L4 edges: Decision → L3 (beliefs, questions, themes)\n * - Cross-layer edges: L2 → L3 (evidence informs beliefs)\n * - Same-layer edges: L3 → L3, L2 → L2 (beliefs depend on beliefs)\n * - Downward edges: L2 → L1 (evidence extracted from source)\n * - Lifecycle edges: same layer only (supersedes)\n */\nexport const EDGE_LAYER_RULES: Record<\n string,\n { from: EpistemicLayer[]; to: EpistemicLayer[]; description: string }\n> = {\n // === L4 Decision Edges ===\n based_on_belief: {\n from: [\"L4\"],\n to: [\"L3\"],\n description: \"Decision → Belief (L4 → L3)\",\n },\n based_on_question: {\n from: [\"L4\"],\n to: [\"L3\"],\n description: \"Decision → Question (L4 → L3)\",\n },\n blocked_by_contradiction: {\n from: [\"L4\"],\n to: [\"L3\"],\n description: \"Decision → Contradiction (L4 → L3)\",\n },\n informed_by_theme: {\n from: [\"L4\"],\n to: [\"L3\"],\n description: \"Decision → Theme (L4 → L3)\",\n },\n\n // === Evidence Flow (L2 → L3, L2 → L1) ===\n derived_from: {\n from: [\"L2\", \"L3\", \"L4\"],\n to: [\"L1\", \"L2\", \"L3\"],\n description: \"A was produced from B (provenance chain)\",\n },\n answers: {\n from: [\"L2\"],\n to: [\"L3\"],\n description: \"Evidence → Question (L2 → L3)\",\n },\n responds_to: {\n from: [\"L2\"],\n to: [\"L3\"],\n description: \"Answer → Question (L2 → L3)\",\n },\n informs: {\n from: [\"L2\"],\n to: [\"L3\"],\n description: \"Evidence → Belief (L2 → L3)\",\n },\n qualifies: {\n from: [\"L2\"],\n to: [\"L3\"],\n description: \"Evidence → Belief (L2 → L3)\",\n },\n\n // === Question → Belief (L3 → L3) ===\n tests: {\n from: [\"L3\"],\n to: [\"L3\"],\n description: \"Question → Belief (L3 → L3)\",\n },\n explores: {\n from: [\"L3\"],\n to: [\"L3\"],\n description: \"Question → Belief assumption (L3 → L3)\",\n },\n\n // === Synthesis (L2 → L2, L2 → L1) ===\n based_on: {\n from: [\"L2\"],\n to: [\"L2\", \"L1\"],\n description: \"Synthesis → Evidence/Source (L2 → L2/L1)\",\n },\n\n // === Theme Relationships (L3 → L3) ===\n relates_to_thesis: {\n from: [\"L3\"],\n to: [\"L3\"],\n description: \"Belief → Theme (L3 → L3)\",\n },\n belongs_to: {\n from: [\"L3\", \"L2\"], // Can belong to theme from L3 or L2\n to: [\"L3\"],\n description: \"Any → Theme (L3/L2 → L3)\",\n },\n plays_theme: {\n from: [\"L3\"],\n to: [\"L3\"],\n description: \"Deal → Theme (L3 → L3)\",\n },\n\n // === Topic Hierarchy (L3 → organizational) ===\n scoped_by: {\n from: [\"L3\"],\n to: [\"organizational\"],\n description: \"Belief/Question → Topic (L3 → organizational)\",\n },\n\n // === Deal/Company ===\n evaluates: {\n from: [\"L3\"],\n to: [\"ontological\"],\n description: \"Deal → Company (L3 → ontological)\",\n },\n\n // === People (ontological → ontological, ontological → L3) ===\n perspective_on: {\n from: [\"ontological\"],\n to: [\"L3\"],\n description: \"Person → Belief/Theme (ontological → L3)\",\n },\n works_at: {\n from: [\"ontological\"],\n to: [\"ontological\"],\n description: \"Person → Company (ontological → ontological)\",\n },\n\n // === Value Chain (ontological) ===\n participates_in: {\n from: [\"ontological\"],\n to: [\"ontological\"],\n description: \"Company → ValueChain (ontological → ontological)\",\n },\n performs: {\n from: [\"ontological\"],\n to: [\"ontological\"],\n description: \"Company → Function (ontological → ontological)\",\n },\n function_in: {\n from: [\"ontological\"],\n to: [\"ontological\"],\n description: \"Function → ValueChain (ontological → ontological)\",\n },\n impacts: {\n from: [\"L3\"],\n to: [\"ontological\"],\n description: \"Theme → ValueChain (L3 → ontological)\",\n },\n\n // === Investment (ontological) ===\n invested_in: {\n from: [\"ontological\"],\n to: [\"ontological\"],\n description: \"Investor → Company (ontological → ontological)\",\n },\n raised_from: {\n from: [\"ontological\"],\n to: [\"ontological\"],\n description: \"Company → Investor (ontological → ontological)\",\n },\n\n // === Entity↔Belief Bridge (OE-B) ===\n about_entity: {\n from: [\"L3\"],\n to: [\"ontological\"],\n description: \"Belief/Question/Theme → Entity (L3 → ontological)\",\n },\n entity_referenced_in: {\n from: [\"ontological\"],\n to: [\"L2\"],\n description: \"Entity → Evidence (ontological → L2)\",\n },\n mentioned_in: {\n from: [\"ontological\"],\n to: [\"L1\"],\n description: \"Entity → Source document (ontological → L1)\",\n },\n founded_by: {\n from: [\"ontological\"],\n to: [\"ontological\"],\n description: \"Company → Person (ontological → ontological)\",\n },\n competes_with: {\n from: [\"ontological\"],\n to: [\"ontological\"],\n description: \"Company → Company (ontological → ontological)\",\n },\n contains: {\n from: [\"ontological\"],\n to: [\"ontological\"],\n description: \"ValueChain → Function (ontological → ontological)\",\n },\n\n // === Lifecycle (same layer only) ===\n supersedes: {\n from: [\"L4\", \"L3\", \"L2\", \"L1\", \"ontological\", \"organizational\"],\n to: [\"L4\", \"L3\", \"L2\", \"L1\", \"ontological\", \"organizational\"],\n description: \"NewNode → OldNode (same layer only - validated separately)\",\n },\n same_as: {\n from: [\"L4\", \"L3\", \"L2\", \"L1\", \"ontological\", \"organizational\"],\n to: [\"L4\", \"L3\", \"L2\", \"L1\", \"ontological\", \"organizational\"],\n description: \"Duplicate detection (same layer only - validated separately)\",\n },\n\n // === Same-Type: Belief ↔ Belief (L3 → L3) ===\n depends_on: {\n from: [\"L3\"],\n to: [\"L3\"],\n description: \"Belief B requires Belief A (L3 → L3)\",\n },\n reinforces: {\n from: [\"L3\"],\n to: [\"L3\"],\n description: \"Beliefs strengthen each other (L3 → L3)\",\n },\n parent_of: {\n from: [\"L3\", \"organizational\"],\n to: [\"L3\", \"organizational\"],\n description:\n \"A is higher-level than B (L3 → L3, organizational → organizational)\",\n },\n child_of: {\n from: [\"L3\"],\n to: [\"L3\"],\n description: \"Belief A is more specific (L3 → L3)\",\n },\n\n // === Same-Type: Question ↔ Question (L3 → L3) ===\n prerequisite_for: {\n from: [\"L3\"],\n to: [\"L3\"],\n description: \"Question A must be answered first (L3 → L3)\",\n },\n parallel_to: {\n from: [\"L3\"],\n to: [\"L3\"],\n description: \"Same topic, different angles (L3 → L3)\",\n },\n\n // === Same-Type: Evidence ↔ Evidence (L2 → L2) ===\n corroborates: {\n from: [\"L2\"],\n to: [\"L2\"],\n description: \"Independent support (L2 → L2)\",\n },\n extends: {\n from: [\"L2\"],\n to: [\"L2\"],\n description: \"Adds depth (L2 → L2)\",\n },\n same_source_as: {\n from: [\"L2\"],\n to: [\"L2\"],\n description: \"Same document/study (L2 → L2)\",\n },\n same_theme_as: {\n from: [\"L2\"],\n to: [\"L2\"],\n description: \"Same topic/entity (L2 → L2)\",\n },\n\n // === NEW: Deep Epistemic Analysis Edges (Phase: Schema Upgrade) ===\n assumes: {\n from: [\"L3\"],\n to: [\"L3\"],\n description:\n \"Hidden dependency - Belief B implicitly assumes Belief A (L3 → L3)\",\n },\n would_predict: {\n from: [\"L3\"],\n to: [\"L2\"],\n description:\n \"Pre-registered prediction - If Belief true, expect Evidence (L3 → L2)\",\n },\n analogous_to: {\n from: [\"L3\"],\n to: [\"L3\"],\n description: \"Explicit analogy - Belief A is like Belief B (L3 → L3)\",\n },\n independent_of: {\n from: [\"L2\"],\n to: [\"L2\"],\n description:\n \"True evidence independence - Evidence A independent of B (L2 → L2)\",\n },\n\n // NOTE: Deprecated edge types (supports, contradicts, derived_from, cites,\n // summarizes, related_to, partially_answers, blocks, refines, branches_from)\n // have been REMOVED from the system. Use compliant alternatives instead.\n};\n\n/**\n * Validate an edge against layer rules\n *\n * Returns { valid: true } or { valid: false, reason: string }\n */\nexport function validateEdgeLayers(\n edgeType: string,\n fromLayer: EpistemicLayer,\n toLayer: EpistemicLayer\n): { valid: boolean; reason?: string } {\n const rules = EDGE_LAYER_RULES[edgeType];\n\n // Unknown edge type - allow but warn\n if (!rules) {\n console.warn(\n `[EdgeValidation] Unknown edge type: ${edgeType}, allowing by default`\n );\n return { valid: true };\n }\n\n // Special handling for same-layer edges (supersedes)\n if (edgeType === \"supersedes\") {\n if (fromLayer !== toLayer) {\n return {\n valid: false,\n reason: `${edgeType} edges must be between nodes of the same layer. Got ${fromLayer} → ${toLayer}`,\n };\n }\n return { valid: true };\n }\n\n // Check from layer\n if (!rules.from.includes(fromLayer)) {\n return {\n valid: false,\n reason: `Edge type '${edgeType}' does not allow source layer ${fromLayer}. Allowed: ${rules.from.join(\", \")}`,\n };\n }\n\n // Check to layer\n if (!rules.to.includes(toLayer)) {\n return {\n valid: false,\n reason: `Edge type '${edgeType}' does not allow target layer ${toLayer}. Allowed: ${rules.to.join(\", \")}`,\n };\n }\n\n return { valid: true };\n}\n\n","/**\n * Epistemic Spine helper module split from epistemicHelpers.ts.\n */\n\nimport { internal } from \"./convex\";\nimport type { Id, MutationCtx } from \"./convex\";\nimport { generateGlobalId } from \"./globalId\";\nimport { getNodeLayer, validateEdgeLayers } from \"./epistemicLayerRules\";\n\ntype NodeTypeIndexQuery = {\n eq(field: string, value: unknown): NodeTypeIndexQuery;\n};\n\n/**\n * Edge type union for createEpistemicEdge\n * Phase 2C: Updated to include L4 edges and modern edge types\n * Phase 3: Added full epistemic impact edges for confidence propagation\n */\ntype EpistemicEdgeType =\n // Canonical edge types (K-tier compliant)\n | \"derived_from\" // replaces: answers, extracted_from, based_on, same_as, based_on_belief, based_on_question\n | \"supports\" // replaces: reinforces, strengthened_by, validated_by, weakened_by, alternative_to, falsified_by, exclusive_with (with appropriate weight)\n | \"contains\" // replaces: parent_of, child_of, about_entity, entity_referenced_in, subsumes, informed_by_theme\n | \"depends_on\" // replaces: collapses_if, cascade_from, required_for, blocks, blocked_by_contradiction\n | \"informs\"\n | \"tests\" // replaces: explores\n | \"responds_to\"\n // Theme relationships\n | \"relates_to_thesis\"\n | \"belongs_to\"\n | \"plays_theme\"\n // Lifecycle\n | \"supersedes\"\n // Same-type: Belief - Cluster Mapping (Thesis Validation Sprints)\n | \"counterfactual_of\"\n | \"cascade_to\"\n | \"mutually_exclusive\"\n | \"correlates_with\"\n | \"amplifies\"\n | \"precondition_for\"\n | \"in_tension_with\"\n // Same-type: Belief - Deep Epistemic Analysis (Tier 2)\n | \"assumes\"\n | \"would_predict\"\n | \"analogous_to\"\n | \"independent_of\"\n // Same-type: Question\n | \"prerequisite_for\"\n | \"parallel_to\"\n // Same-type: Evidence\n | \"corroborates\"\n | \"extends\"\n | \"same_source_as\"\n | \"same_theme_as\"\n // Ontological\n | \"evaluates\"\n | \"perspective_on\"\n | \"works_at\"\n | \"participates_in\"\n | \"performs\"\n | \"function_in\"\n | \"impacts\"\n | \"invested_in\"\n | \"raised_from\"\n // People/Entity References\n | \"mentioned_in\"\n | \"founded_by\"\n | \"competes_with\";\n\n// NOTE: Deprecated edge types have been REMOVED from this type.\n// See schema.ts for the list of removed types and their compliant alternatives.\n\n// =============================================================================\n// CONFIDENCE NORMALIZATION\n// =============================================================================\n\n/**\n * Normalize confidence to a 0-1 number regardless of input format.\n *\n * Handles:\n * - number (0-1): returned as-is\n * - number (1-100): divided by 100\n * - string (\"high\"/\"medium\"/\"low\"): mapped to 0.8/0.5/0.3\n * - undefined/null/other: returns 0.5 default\n *\n * This is the canonical way to read confidence from any source.\n */\nexport function normalizeConfidence(confidence: unknown): number {\n if (typeof confidence === \"number\") {\n return confidence > 1 ? confidence / 100 : confidence;\n }\n if (typeof confidence === \"string\") {\n switch (confidence) {\n case \"high\":\n return 0.8;\n case \"medium\":\n return 0.5;\n case \"low\":\n return 0.3;\n default:\n return 0.5;\n }\n }\n return 0.5;\n}\n\n/**\n * Epistemic Edge Propagation Semantics\n *\n * Each edge type has specific propagation rules for confidence cascades:\n *\n * | Edge Type | Direction | Propagation Rule |\n * |-------------------|--------------|-----------------------------------------------------------|\n * | depends_on | B → A | A.conf = min(A.conf, B.conf + 0.2) |\n * | reinforces | A ↔ B | Both get boost when either validated |\n * | falsified_by | B → A | A.conf = 1 - B.conf (inverse) |\n * | exclusive_with | A ↔ B | A.conf + B.conf ≤ 1.0 (redistribute on evidence) |\n * | contradicts | A ↔ B | Creates tension - neither can be validated without fork |\n * | collapses_if | A → B | If A.conf < threshold, B.conf → 0 |\n * | cascade_from | A → B | B.conf_delta = A.conf_delta * damping_factor |\n * | strengthened_by | A → B | B.conf += A.conf_delta * correlation |\n * | weakened_by | A → B | B.conf -= A.conf_delta * correlation |\n * | alternative_to | A ↔ B | Evidence for A reduces B, and vice versa |\n * | subsumes | A → B | A.conf >= B.conf always |\n * | validated_by | A → B | If A validated, B gains confidence |\n * | required_for | A → B | B cannot be validated until A is validated |\n * | blocks | A → B | B resolution blocked until A resolved |\n */\n\n/**\n * Create an epistemic edge between two nodes\n *\n * Phase 1 (Graph Architecture): Writes to Neo4j directly - Neo4j is source of truth.\n * Returns globalId (string) instead of Convex edge ID.\n *\n * Phase 2C: Validates layer rules before creation\n */\nexport async function createEpistemicEdge(\n ctx: MutationCtx,\n params: {\n fromNodeId: Id<\"epistemicNodes\">;\n toNodeId: Id<\"epistemicNodes\">;\n edgeType: EpistemicEdgeType;\n weight?: number;\n confidence?: number;\n context?: string;\n // NOTE: 'relation' field has been removed. Use 'weight' instead.\n projectId?: string;\n createdBy: string;\n // Phase 2C: Allow skipping validation for migrations\n skipLayerValidation?: boolean;\n }\n): Promise<string> {\n const globalId = generateGlobalId();\n\n // Get node types for denormalization\n const fromNode = await ctx.db.get(params.fromNodeId);\n const toNode = await ctx.db.get(params.toNodeId);\n\n if (!fromNode || !toNode) {\n throw new Error(\"One or both nodes not found\");\n }\n\n // Phase 2C: Get layers (use stored or derive from nodeType)\n const fromLayer = fromNode.epistemicLayer || getNodeLayer(fromNode.nodeType);\n const toLayer = toNode.epistemicLayer || getNodeLayer(toNode.nodeType);\n\n // Phase 2C: Validate layer rules\n if (!params.skipLayerValidation) {\n const validation = validateEdgeLayers(params.edgeType, fromLayer, toLayer);\n if (!validation.valid) {\n throw new Error(\n `[EdgeValidation] Invalid edge: ${validation.reason}. ` +\n `Attempted: ${params.edgeType} from ${fromNode.nodeType}(${fromLayer}) → ${toNode.nodeType}(${toLayer})`\n );\n }\n }\n\n // Phase 1 (Graph Architecture): Write to Neo4j directly - Neo4j is source of truth\n await ctx.scheduler.runAfter(0, internal.neo4jEdgeAPI.createEdge, {\n globalId,\n fromGlobalId: fromNode.globalId,\n toGlobalId: toNode.globalId,\n edgeType: params.edgeType,\n weight: params.weight,\n confidence: params.confidence,\n context: params.context,\n createdBy: params.createdBy,\n topicId: params.projectId ? String(params.projectId) : undefined,\n fromNodeType: fromNode.nodeType,\n toNodeType: toNode.nodeType,\n fromLayer,\n toLayer,\n });\n\n return globalId;\n}\n\n/**\n * Create an edge when linking an insight to a question\n * This creates a \"derived_from\" edge (evidence answers/informs question)\n */\nexport async function createEdgeForInsightQuestionLink(\n ctx: MutationCtx,\n questionId: Id<\"epistemicNodes\">,\n insightId: Id<\"epistemicNodes\">,\n createdBy: string\n): Promise<string | null> {\n console.log(\"[EpistemicSpine] Creating edge for insight-question link:\", {\n questionId: String(questionId),\n insightId: String(insightId),\n });\n\n // Find the epistemic nodes for both entities\n const questionNode = await findNodeByLegacyId(ctx, \"question\", questionId);\n const insightNode = await findNodeByLegacyId(ctx, \"insight\", insightId);\n\n console.log(\"[EpistemicSpine] Found nodes:\", {\n questionNode: questionNode ? String(questionNode) : null,\n insightNode: insightNode ? String(insightNode) : null,\n });\n\n if (!questionNode || !insightNode) {\n // Nodes don't exist yet - this can happen for legacy data\n // They'll be created during backfill\n console.log(\"[EpistemicSpine] Missing nodes, skipping edge creation\");\n return null;\n }\n\n // Get the question for projectId\n const question = await ctx.db.get(questionId);\n const projectId = question?.projectId;\n\n // Create the edge: Evidence -> Question\n // Use \"derived_from\" - canonical replacement for \"answers\" edge type\n return await createEpistemicEdge(ctx, {\n fromNodeId: insightNode,\n toNodeId: questionNode,\n edgeType: \"derived_from\",\n projectId,\n createdBy,\n context: \"Linked from questions workspace\",\n });\n}\n\n/**\n * Find an epistemic node by its legacy ID (stored in metadata)\n */\nasync function findNodeByLegacyId(\n ctx: MutationCtx,\n legacyType: \"insight\" | \"belief\" | \"question\" | \"artifact\",\n legacyId: Id<\"epistemicNodes\"> | Id<\"finalArtifacts\">\n): Promise<Id<\"epistemicNodes\"> | null> {\n // Query all nodes and find the one with matching legacy ID\n // This is not ideal for performance, but works for now\n // TODO: Add a dedicated index for legacy IDs\n const nodeType =\n legacyType === \"insight\"\n ? \"evidence\"\n : legacyType === \"artifact\"\n ? \"source\"\n : legacyType;\n\n const nodes = await ctx.db\n .query(\"epistemicNodes\")\n .withIndex(\"by_nodeType\", (q: NodeTypeIndexQuery) =>\n q.eq(\"nodeType\", nodeType),\n )\n .collect();\n\n const legacyKey = `legacy${legacyType.charAt(0).toUpperCase() + legacyType.slice(1)}Id`;\n\n // Convert legacyId to string for comparison (Convex Id objects need string comparison)\n const legacyIdStr = String(legacyId);\n\n const found = nodes.find((n) => {\n const metadata = n.metadata as Record<string, unknown> | undefined;\n const storedId = metadata?.[legacyKey];\n // Compare as strings to handle Convex Id serialization\n return storedId && String(storedId) === legacyIdStr;\n });\n\n if (!found) {\n console.log(\n `[EpistemicSpine] Node not found for ${legacyType}:${legacyIdStr}, searched ${nodes.length} ${nodeType} nodes`\n );\n }\n\n return found?._id ?? null;\n}\n"]}
@@ -15,7 +15,7 @@ declare const subjectiveOpinionValidator: convex_values.VObject<{
15
15
  u: convex_values.VFloat64<number, "required">;
16
16
  a: convex_values.VFloat64<number, "required">;
17
17
  }, "required", "b" | "d" | "u" | "a">;
18
- declare const edgeTypeValidator: convex_values.VUnion<"supports" | "informs" | "depends_on" | "derived_from" | "contains" | "tests" | "based_on_belief" | "based_on_question" | "blocked_by_contradiction" | "informed_by_theme" | "works_at" | "invested_in" | "competes_with" | "participates_in" | "founded_by" | "evaluates" | "performs" | "function_in" | "impacts" | "raised_from" | "mentioned_in" | "perspective_on" | "supersedes" | "responds_to" | "belongs_to" | "relates_to_thesis" | "plays_theme" | "contradicts" | "scoped_by" | "prerequisite_for" | "parallel_to" | "corroborates" | "extends" | "same_source_as" | "same_theme_as" | "qualifies" | "explores" | "same_as" | "assumes" | "would_predict" | "analogous_to" | "independent_of" | "counterfactual_of" | "cascade_to" | "mutually_exclusive" | "correlates_with" | "amplifies" | "precondition_for" | "in_tension_with" | "cascade_from" | "falsified_by" | "exclusive_with" | "collapses_if" | "strengthened_by" | "weakened_by" | "alternative_to" | "subsumes" | "validated_by" | "required_for" | "blocks", [convex_values.VLiteral<"based_on_belief", "required">, convex_values.VLiteral<"based_on_question", "required">, convex_values.VLiteral<"blocked_by_contradiction", "required">, convex_values.VLiteral<"informed_by_theme", "required">, convex_values.VLiteral<"derived_from", "required">, convex_values.VLiteral<"responds_to", "required">, convex_values.VLiteral<"informs", "required">, convex_values.VLiteral<"tests", "required">, convex_values.VLiteral<"explores", "required">, convex_values.VLiteral<"qualifies", "required">, convex_values.VLiteral<"relates_to_thesis", "required">, convex_values.VLiteral<"belongs_to", "required">, convex_values.VLiteral<"plays_theme", "required">, convex_values.VLiteral<"scoped_by", "required">, convex_values.VLiteral<"evaluates", "required">, convex_values.VLiteral<"perspective_on", "required">, convex_values.VLiteral<"works_at", "required">, convex_values.VLiteral<"mentioned_in", "required">, convex_values.VLiteral<"founded_by", "required">, convex_values.VLiteral<"participates_in", "required">, convex_values.VLiteral<"performs", "required">, convex_values.VLiteral<"function_in", "required">, convex_values.VLiteral<"impacts", "required">, convex_values.VLiteral<"invested_in", "required">, convex_values.VLiteral<"raised_from", "required">, convex_values.VLiteral<"supersedes", "required">, convex_values.VLiteral<"same_as", "required">, convex_values.VLiteral<"depends_on", "required">, convex_values.VLiteral<"supports", "required">, convex_values.VLiteral<"contains", "required">, convex_values.VLiteral<"counterfactual_of", "required">, convex_values.VLiteral<"cascade_to", "required">, convex_values.VLiteral<"cascade_from", "required">, convex_values.VLiteral<"mutually_exclusive", "required">, convex_values.VLiteral<"correlates_with", "required">, convex_values.VLiteral<"amplifies", "required">, convex_values.VLiteral<"precondition_for", "required">, convex_values.VLiteral<"in_tension_with", "required">, convex_values.VLiteral<"falsified_by", "required">, convex_values.VLiteral<"exclusive_with", "required">, convex_values.VLiteral<"contradicts", "required">, convex_values.VLiteral<"collapses_if", "required">, convex_values.VLiteral<"strengthened_by", "required">, convex_values.VLiteral<"weakened_by", "required">, convex_values.VLiteral<"alternative_to", "required">, convex_values.VLiteral<"subsumes", "required">, convex_values.VLiteral<"validated_by", "required">, convex_values.VLiteral<"required_for", "required">, convex_values.VLiteral<"blocks", "required">, convex_values.VLiteral<"prerequisite_for", "required">, convex_values.VLiteral<"parallel_to", "required">, convex_values.VLiteral<"corroborates", "required">, convex_values.VLiteral<"extends", "required">, convex_values.VLiteral<"same_source_as", "required">, convex_values.VLiteral<"same_theme_as", "required">, convex_values.VLiteral<"assumes", "required">, convex_values.VLiteral<"would_predict", "required">, convex_values.VLiteral<"analogous_to", "required">, convex_values.VLiteral<"independent_of", "required">, convex_values.VLiteral<"competes_with", "required">], "required", never>;
18
+ declare const edgeTypeValidator: convex_values.VUnion<"supports" | "informs" | "depends_on" | "derived_from" | "contains" | "tests" | "based_on_belief" | "based_on_question" | "blocked_by_contradiction" | "informed_by_theme" | "works_at" | "invested_in" | "competes_with" | "participates_in" | "founded_by" | "evaluates" | "performs" | "function_in" | "impacts" | "raised_from" | "mentioned_in" | "perspective_on" | "supersedes" | "responds_to" | "belongs_to" | "relates_to_thesis" | "plays_theme" | "contradicts" | "prerequisite_for" | "parallel_to" | "corroborates" | "extends" | "same_source_as" | "same_theme_as" | "qualifies" | "explores" | "scoped_by" | "same_as" | "assumes" | "would_predict" | "analogous_to" | "independent_of" | "counterfactual_of" | "cascade_to" | "mutually_exclusive" | "correlates_with" | "amplifies" | "precondition_for" | "in_tension_with" | "cascade_from" | "falsified_by" | "exclusive_with" | "collapses_if" | "strengthened_by" | "weakened_by" | "alternative_to" | "subsumes" | "validated_by" | "required_for" | "blocks", [convex_values.VLiteral<"based_on_belief", "required">, convex_values.VLiteral<"based_on_question", "required">, convex_values.VLiteral<"blocked_by_contradiction", "required">, convex_values.VLiteral<"informed_by_theme", "required">, convex_values.VLiteral<"derived_from", "required">, convex_values.VLiteral<"responds_to", "required">, convex_values.VLiteral<"informs", "required">, convex_values.VLiteral<"tests", "required">, convex_values.VLiteral<"explores", "required">, convex_values.VLiteral<"qualifies", "required">, convex_values.VLiteral<"relates_to_thesis", "required">, convex_values.VLiteral<"belongs_to", "required">, convex_values.VLiteral<"plays_theme", "required">, convex_values.VLiteral<"scoped_by", "required">, convex_values.VLiteral<"evaluates", "required">, convex_values.VLiteral<"perspective_on", "required">, convex_values.VLiteral<"works_at", "required">, convex_values.VLiteral<"mentioned_in", "required">, convex_values.VLiteral<"founded_by", "required">, convex_values.VLiteral<"participates_in", "required">, convex_values.VLiteral<"performs", "required">, convex_values.VLiteral<"function_in", "required">, convex_values.VLiteral<"impacts", "required">, convex_values.VLiteral<"invested_in", "required">, convex_values.VLiteral<"raised_from", "required">, convex_values.VLiteral<"supersedes", "required">, convex_values.VLiteral<"same_as", "required">, convex_values.VLiteral<"depends_on", "required">, convex_values.VLiteral<"supports", "required">, convex_values.VLiteral<"contains", "required">, convex_values.VLiteral<"counterfactual_of", "required">, convex_values.VLiteral<"cascade_to", "required">, convex_values.VLiteral<"cascade_from", "required">, convex_values.VLiteral<"mutually_exclusive", "required">, convex_values.VLiteral<"correlates_with", "required">, convex_values.VLiteral<"amplifies", "required">, convex_values.VLiteral<"precondition_for", "required">, convex_values.VLiteral<"in_tension_with", "required">, convex_values.VLiteral<"falsified_by", "required">, convex_values.VLiteral<"exclusive_with", "required">, convex_values.VLiteral<"contradicts", "required">, convex_values.VLiteral<"collapses_if", "required">, convex_values.VLiteral<"strengthened_by", "required">, convex_values.VLiteral<"weakened_by", "required">, convex_values.VLiteral<"alternative_to", "required">, convex_values.VLiteral<"subsumes", "required">, convex_values.VLiteral<"validated_by", "required">, convex_values.VLiteral<"required_for", "required">, convex_values.VLiteral<"blocks", "required">, convex_values.VLiteral<"prerequisite_for", "required">, convex_values.VLiteral<"parallel_to", "required">, convex_values.VLiteral<"corroborates", "required">, convex_values.VLiteral<"extends", "required">, convex_values.VLiteral<"same_source_as", "required">, convex_values.VLiteral<"same_theme_as", "required">, convex_values.VLiteral<"assumes", "required">, convex_values.VLiteral<"would_predict", "required">, convex_values.VLiteral<"analogous_to", "required">, convex_values.VLiteral<"independent_of", "required">, convex_values.VLiteral<"competes_with", "required">], "required", never>;
19
19
  declare function buildEdgeStatusSuccessResult(): EdgeStatusResult;
20
20
  declare function buildEdgeNotFoundResult(): EdgeStatusResult;
21
21
  declare function buildEdgeMirrorSkippedResult(): EdgeStatusResult;
@@ -3,6 +3,7 @@ import { componentsGeneric, anyApi, mutationGeneric, internalMutationGeneric, qu
3
3
  import { v } from 'convex/values';
4
4
  import { requireProjectAccess, checkProjectAccess, checkScopeAccess } from '@lucern/access-control/access';
5
5
  import { permissiveReturn } from '@lucern/contracts/schema-helpers/validators';
6
+ import { generateGlobalId } from '@lucern/contracts/ids';
6
7
  import { isNodeType, getLayerForNodeType } from '@lucern/contracts/schema-helpers/spine/tables/epistemicNodes';
7
8
  import { listAudienceRegistryRows } from '@lucern/access-control/audienceRegistry';
8
9
 
@@ -800,18 +801,6 @@ async function scheduleEmbeddingGeneration(args) {
800
801
  );
801
802
  }
802
803
  }
803
-
804
- // src/globalId.ts
805
- function generateGlobalId() {
806
- const bytes = new Uint8Array(16);
807
- crypto.getRandomValues(bytes);
808
- bytes[6] = bytes[6] & 15 | 64;
809
- bytes[8] = bytes[8] & 63 | 128;
810
- const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join(
811
- ""
812
- );
813
- return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
814
- }
815
804
  function normalizeScopeValue2(value) {
816
805
  if (typeof value !== "string") {
817
806
  return;