@lucern/graph-primitives 0.3.0-alpha.6 → 0.3.0-alpha.8

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 (123) hide show
  1. package/dist/{beliefDecay-Q_26RTc-.d.ts → beliefDecay-DZ6tkLYq.d.ts} +1 -1
  2. package/dist/beliefDecay.d.ts +1 -1
  3. package/dist/beliefDecay.js +158 -47
  4. package/dist/beliefDecay.js.map +1 -1
  5. package/dist/{beliefEvidenceLinks-42FlR48t.d.ts → beliefEvidenceLinks-CWOXxxJg.d.ts} +1 -1
  6. package/dist/beliefEvidenceLinks.d.ts +1 -1
  7. package/dist/beliefEvidenceLinks.js +141 -45
  8. package/dist/beliefEvidenceLinks.js.map +1 -1
  9. package/dist/{beliefLifecycle-C-AehZgF.d.ts → beliefLifecycle-y8WLXqQj.d.ts} +1 -1
  10. package/dist/beliefLifecycle.d.ts +1 -1
  11. package/dist/confidencePropagationDispatch.d.ts +1 -1
  12. package/dist/confidencePropagationDispatch.js +1 -3
  13. package/dist/confidencePropagationDispatch.js.map +1 -1
  14. package/dist/{contradictions-Hdwl7zid.d.ts → contradictions-51VLsESq.d.ts} +1 -1
  15. package/dist/contradictions.d.ts +1 -1
  16. package/dist/contradictions.js +67 -8
  17. package/dist/contradictions.js.map +1 -1
  18. package/dist/debug.d.ts +4 -0
  19. package/dist/debug.js +34 -0
  20. package/dist/debug.js.map +1 -0
  21. package/dist/edges/contradicts.js.map +1 -1
  22. package/dist/edges/dependsOn.js.map +1 -1
  23. package/dist/edges/elaborates.js.map +1 -1
  24. package/dist/edges/index.js +1 -3
  25. package/dist/edges/index.js.map +1 -1
  26. package/dist/edges/informs.js +1 -3
  27. package/dist/edges/informs.js.map +1 -1
  28. package/dist/edges/refutes.js +1 -3
  29. package/dist/edges/refutes.js.map +1 -1
  30. package/dist/edges/supports.js.map +1 -1
  31. package/dist/edges/utils.d.ts +3 -3
  32. package/dist/edges/utils.js +2 -4
  33. package/dist/edges/utils.js.map +1 -1
  34. package/dist/embeddingTrigger.js +21 -1
  35. package/dist/embeddingTrigger.js.map +1 -1
  36. package/dist/entityBridge.js +1 -1
  37. package/dist/entityBridge.js.map +1 -1
  38. package/dist/{entityLifecycle-BkhRJ-XI.d.ts → entityLifecycle-CvgSK5FV.d.ts} +1 -1
  39. package/dist/entityLifecycle.d.ts +1 -1
  40. package/dist/entityLifecycle.js +134 -47
  41. package/dist/entityLifecycle.js.map +1 -1
  42. package/dist/{epistemicAnswers-DSP1slZ9.d.ts → epistemicAnswers-C5ib4z6_.d.ts} +1 -1
  43. package/dist/epistemicAnswers.d.ts +1 -1
  44. package/dist/epistemicAnswers.js +67 -8
  45. package/dist/epistemicAnswers.js.map +1 -1
  46. package/dist/{epistemicBeliefs-DtFVTp-k.d.ts → epistemicBeliefs-DzKjZAeC.d.ts} +3 -3
  47. package/dist/epistemicBeliefs.d.ts +2 -2
  48. package/dist/epistemicBeliefs.js +289 -114
  49. package/dist/epistemicBeliefs.js.map +1 -1
  50. package/dist/epistemicContracts.d.ts +1 -1
  51. package/dist/epistemicContracts.js +297 -115
  52. package/dist/epistemicContracts.js.map +1 -1
  53. package/dist/{epistemicEdges-DcA8ErUG.d.ts → epistemicEdges-CvlKnEyy.d.ts} +1 -1
  54. package/dist/epistemicEdges.d.ts +1 -1
  55. package/dist/epistemicEdges.js +192 -60
  56. package/dist/epistemicEdges.js.map +1 -1
  57. package/dist/{epistemicEvidence-Bo638XDP.d.ts → epistemicEvidence-xw6UUrwh.d.ts} +1 -1
  58. package/dist/epistemicEvidence.d.ts +1 -1
  59. package/dist/epistemicEvidence.js +163 -49
  60. package/dist/epistemicEvidence.js.map +1 -1
  61. package/dist/{epistemicHelpers-Bd9xbaib.d.ts → epistemicHelpers-DevrYgPN.d.ts} +1 -1
  62. package/dist/epistemicHelpers.d.ts +1 -1
  63. package/dist/{epistemicLinking-CyeLOIzN.d.ts → epistemicLinking-CfE00tHJ.d.ts} +1 -1
  64. package/dist/epistemicLinking.d.ts +1 -1
  65. package/dist/epistemicLinking.js +1 -1
  66. package/dist/{epistemicNodes-BpD6Koud.d.ts → epistemicNodes-DjSUfvyD.d.ts} +1 -1
  67. package/dist/epistemicNodes.d.ts +1 -1
  68. package/dist/epistemicNodes.js +163 -33
  69. package/dist/epistemicNodes.js.map +1 -1
  70. package/dist/{epistemicQuestions-CmEeY6zQ.d.ts → epistemicQuestions-B_nUclrH.d.ts} +1 -1
  71. package/dist/epistemicQuestions.d.ts +1 -1
  72. package/dist/epistemicQuestions.js +311 -62
  73. package/dist/epistemicQuestions.js.map +1 -1
  74. package/dist/{epistemicSources-ZazxHOK1.d.ts → epistemicSources-dlKj58Jp.d.ts} +1 -1
  75. package/dist/epistemicSources.d.ts +1 -1
  76. package/dist/epistemicSources.js +65 -8
  77. package/dist/epistemicSources.js.map +1 -1
  78. package/dist/evaluators/index.js +297 -115
  79. package/dist/evaluators/index.js.map +1 -1
  80. package/dist/evaluators/lintCheckerEvaluator.js.map +1 -1
  81. package/dist/evaluators/sentryCheckerEvaluator.js.map +1 -1
  82. package/dist/evaluators/shared.js +20 -1
  83. package/dist/evaluators/shared.js.map +1 -1
  84. package/dist/evaluators/testRunnerEvaluator.js +20 -1
  85. package/dist/evaluators/testRunnerEvaluator.js.map +1 -1
  86. package/dist/evaluators/tscCheckerEvaluator.js.map +1 -1
  87. package/dist/index.d.ts +20 -20
  88. package/dist/index.js +729 -206
  89. package/dist/index.js.map +1 -1
  90. package/dist/{ontology-matching-Buhu23ss.d.ts → ontology-matching-C6rrz2VP.d.ts} +1 -1
  91. package/dist/ontology-matching.d.ts +1 -1
  92. package/dist/{ontologyApproval-Ba0Jjk1k.d.ts → ontologyApproval-CFYmqKmk.d.ts} +1 -1
  93. package/dist/ontologyApproval.d.ts +1 -1
  94. package/dist/ontologyDefinitions.js +4 -3
  95. package/dist/ontologyDefinitions.js.map +1 -1
  96. package/dist/ontologyHelpers.d.ts +1 -1
  97. package/dist/ontologyHelpers.js +4 -3
  98. package/dist/ontologyHelpers.js.map +1 -1
  99. package/dist/{projectionReconciliation-CxrXYGaB.d.ts → projectionReconciliation-jww2fBI0.d.ts} +1 -1
  100. package/dist/projectionReconciliation.d.ts +1 -1
  101. package/dist/projectionReconciliation.js +14 -20
  102. package/dist/projectionReconciliation.js.map +1 -1
  103. package/dist/{projectionStaleness-CAdpIsaW.d.ts → projectionStaleness-CmdbpjVK.d.ts} +1 -1
  104. package/dist/projectionStaleness.d.ts +1 -1
  105. package/dist/{questionEvidenceLinks-BdQD0TkM.d.ts → questionEvidenceLinks-DFlyPpAj.d.ts} +1 -1
  106. package/dist/questionEvidenceLinks.d.ts +1 -1
  107. package/dist/questionEvidenceLinks.js +144 -45
  108. package/dist/questionEvidenceLinks.js.map +1 -1
  109. package/dist/resolvers.js +86 -37
  110. package/dist/resolvers.js.map +1 -1
  111. package/dist/scopeResolverCompat.js +64 -7
  112. package/dist/scopeResolverCompat.js.map +1 -1
  113. package/dist/{text-matching-CMn2WnVD.d.ts → text-matching-DNg4M5Wd.d.ts} +1 -1
  114. package/dist/text-matching.d.ts +1 -1
  115. package/dist/topicProjectOverlay.js +56 -13
  116. package/dist/topicProjectOverlay.js.map +1 -1
  117. package/dist/topicScope.js +55 -6
  118. package/dist/topicScope.js.map +1 -1
  119. package/dist/workflowBridge.js +55 -6
  120. package/dist/workflowBridge.js.map +1 -1
  121. package/dist/workspaceIsolation.js +55 -6
  122. package/dist/workspaceIsolation.js.map +1 -1
  123. package/package.json +5 -5
@@ -1,5 +1,5 @@
1
1
  import { Id, MutationCtx } from './convex.js';
2
- import { EpistemicContractEvaluationResult, EpistemicContractRecord } from '@lucern/confidence';
2
+ import { EpistemicContractRecord, EpistemicContractEvaluationResult } from '@lucern/confidence';
3
3
  import 'convex/values';
4
4
 
5
5
  type BeliefNodeDoc = {
@@ -2,7 +2,7 @@ import { v } from 'convex/values';
2
2
  import { checkScopeAccess, checkProjectAccess } from '@lucern/access-control/access';
3
3
  import { getCurrentUserId } from '@lucern/access-control/auth';
4
4
  import { permissiveReturn } from '@lucern/contracts/schema-helpers/validators';
5
- import { componentsGeneric, internalMutationGeneric, mutationGeneric, anyApi, queryGeneric, internalQueryGeneric } from 'convex/server';
5
+ import { componentsGeneric, anyApi, internalMutationGeneric, mutationGeneric, queryGeneric, internalQueryGeneric } from 'convex/server';
6
6
  import { normalizeTupleContradictionPolicy, mkOpinion, createInheritedContractRecord, confidenceFromSL, conditionalDeduction, project, dampedDependencyCascade, hasProjectedOpinionChanged, detectTupleContradiction, evaluateTupleContradictionTransition, readOpinionFromRecord, deriveContractModulationPlan, deriveContractStatus, trustDiscount, applyNegativeSupport, cumulativeFusion, applyNegativeEvidence, parseEvidentialEvaluatorConfig, compareMetricValue, buildEvidentialRationale, parseMetricCheckerConfig, getEvaluatorInputRecord, pickFiniteNumber, resolveComparisonResult, buildComparisonRationale, parseReferenceCheckCounterConfig, parseTemporalDeadlineConfig, parseMarketIndexComparatorConfig } from '@lucern/confidence';
7
7
  import { canAudienceClassAccess, normalizeAudienceKey, classFromAudienceKey } from '@lucern/access-control/audience';
8
8
  import { listAudienceRegistryRows } from '@lucern/access-control/audienceRegistry';
@@ -169,9 +169,7 @@ function propagateNegativeSupportWithMetadata(sourceOpinion, targetOpinion, edge
169
169
  readEdgeMetadata(edge)
170
170
  );
171
171
  }
172
- function propagateNegativeInform(sourceOpinion, targetOpinion, edgeWeight) {
173
- return applyNegativeEvidence(sourceOpinion, targetOpinion, edgeWeight);
174
- }
172
+ var propagateNegativeInform = applyNegativeEvidence;
175
173
 
176
174
  // src/edges/contradicts.ts
177
175
  var contradictsPropagationSpec = {
@@ -394,6 +392,20 @@ function getTraversalDirections(direction) {
394
392
  }
395
393
  return ["outgoing", "incoming"];
396
394
  }
395
+
396
+ // src/debug.ts
397
+ function isGraphPrimitiveDebugEnabled() {
398
+ const env = globalThis.process?.env;
399
+ return env?.LUCERN_COMPAT_FALLBACK_DEBUG === "1" || env?.LUCERN_GRAPH_DEBUG === "1";
400
+ }
401
+ function debugGraphPrimitiveFallback(message, context) {
402
+ if (!isGraphPrimitiveDebugEnabled()) {
403
+ return;
404
+ }
405
+ console.debug(message, context ?? {});
406
+ }
407
+
408
+ // src/topicScope.ts
397
409
  var LEGACY_SCOPE_FIELD = "graphScopeProjectId";
398
410
  function asMappedProjectId(topic) {
399
411
  if (!topic) {
@@ -435,7 +447,14 @@ async function findTopicsByScopeAlias(ctx, scopeId) {
435
447
  "by_graph_scope_project",
436
448
  (q) => q.eq(LEGACY_SCOPE_FIELD, scopeId)
437
449
  ).collect();
438
- } catch {
450
+ } catch (error) {
451
+ debugGraphPrimitiveFallback(
452
+ "[topicScope] Failed to resolve scope alias via index",
453
+ {
454
+ error,
455
+ scopeId
456
+ }
457
+ );
439
458
  const topics = await ctx.db.query("topics").collect();
440
459
  return topics.filter((topic) => {
441
460
  const normalizedGlobalId = normalizeScopeValue(topic.globalId);
@@ -452,7 +471,14 @@ async function tryResolveHostTopicById(ctx, topicId) {
452
471
  return await ctx.runQuery(api.topics.get, {
453
472
  id: topicId
454
473
  }) ?? null;
455
- } catch {
474
+ } catch (error) {
475
+ debugGraphPrimitiveFallback(
476
+ "[topicScope] Failed to resolve topic by host query",
477
+ {
478
+ error,
479
+ topicId
480
+ }
481
+ );
456
482
  return null;
457
483
  }
458
484
  }
@@ -464,7 +490,14 @@ async function tryResolveHostTopicByLegacyScope(ctx, legacyScopeId) {
464
490
  return await ctx.runQuery(api.topics.getByLegacyScopeId, {
465
491
  projectId: legacyScopeId
466
492
  }) ?? null;
467
- } catch {
493
+ } catch (error) {
494
+ debugGraphPrimitiveFallback(
495
+ "[topicScope] Failed to resolve topic by legacy scope",
496
+ {
497
+ error,
498
+ legacyScopeId
499
+ }
500
+ );
468
501
  return null;
469
502
  }
470
503
  }
@@ -493,8 +526,17 @@ async function resolveTopicProjectScope(ctx, args) {
493
526
  if (args.topicId) {
494
527
  let topic = null;
495
528
  try {
496
- topic = await ctx.db.get(args.topicId);
497
- } catch {
529
+ topic = await ctx.db.get(
530
+ args.topicId
531
+ );
532
+ } catch (error) {
533
+ debugGraphPrimitiveFallback(
534
+ "[topicScope] Failed to load topic by direct id",
535
+ {
536
+ error,
537
+ topicId: args.topicId
538
+ }
539
+ );
498
540
  }
499
541
  if (!topic) {
500
542
  topic = await tryResolveHostTopicById(ctx, String(args.topicId));
@@ -531,7 +573,14 @@ async function resolveTopicProjectScope(ctx, args) {
531
573
  directTopic = await ctx.db.get(
532
574
  args.projectId
533
575
  );
534
- } catch {
576
+ } catch (error) {
577
+ debugGraphPrimitiveFallback(
578
+ "[topicScope] Failed to load direct project topic",
579
+ {
580
+ error,
581
+ projectId: args.projectId
582
+ }
583
+ );
535
584
  }
536
585
  if (directTopic) {
537
586
  const inherited = await resolveInheritedWorkspaceScope(ctx, directTopic);
@@ -875,7 +924,15 @@ async function scheduleEmbeddingGeneration(args) {
875
924
  confidence: args.confidence
876
925
  }
877
926
  );
878
- } catch {
927
+ } catch (error) {
928
+ debugGraphPrimitiveFallback(
929
+ "[embeddingTrigger] Failed to schedule embedding generation",
930
+ {
931
+ error,
932
+ nodeId: String(args.nodeId),
933
+ nodeType: args.nodeType
934
+ }
935
+ );
879
936
  }
880
937
  }
881
938
 
@@ -997,19 +1054,37 @@ function isProjectLikeTopic(topic) {
997
1054
  return topic.type === "theme" || topic.type === "thematic" || topic.type === "deal" || topic.type === "monitoring" || readLegacyProjectId(topic) !== void 0 || readNonEmptyString(metadata.projectType) !== void 0;
998
1055
  }
999
1056
  function isMissingLucernChildComponentError(error) {
1000
- const message = error instanceof Error ? error.message : String(error);
1057
+ const message = getErrorMessage(error);
1001
1058
  return message.includes(
1002
1059
  'Child component ComponentName(Identifier("lucern")) not found'
1003
1060
  ) || message.includes("Child component") && message.includes("lucern") && message.includes("not found");
1004
1061
  }
1062
+ function getErrorMessage(error) {
1063
+ if (error instanceof Error) {
1064
+ return error.message;
1065
+ }
1066
+ if (typeof error === "object" && error !== null && "message" in error && typeof error.message === "string") {
1067
+ return error.message;
1068
+ }
1069
+ return "unknown error";
1070
+ }
1005
1071
  async function resolveTopicDoc(ctx, scopeId) {
1006
1072
  if (ctx?.db && typeof ctx.db.get === "function") {
1007
1073
  try {
1008
- const directTopic = await ctx.db.get(scopeId);
1074
+ const directTopic = await ctx.db.get(
1075
+ scopeId
1076
+ );
1009
1077
  if (directTopic) {
1010
1078
  return directTopic;
1011
1079
  }
1012
- } catch {
1080
+ } catch (error) {
1081
+ debugGraphPrimitiveFallback(
1082
+ "[topicProjectOverlay] Failed to resolve topic by direct ID",
1083
+ {
1084
+ error,
1085
+ scopeId
1086
+ }
1087
+ );
1013
1088
  }
1014
1089
  }
1015
1090
  if (typeof ctx.runQuery !== "function") {
@@ -1022,7 +1097,14 @@ async function resolveTopicDoc(ctx, scopeId) {
1022
1097
  if (topic?.name !== void 0 && topic?.type !== void 0) {
1023
1098
  return topic;
1024
1099
  }
1025
- } catch {
1100
+ } catch (error) {
1101
+ debugGraphPrimitiveFallback(
1102
+ "[topicProjectOverlay] Failed to resolve topic by ID query",
1103
+ {
1104
+ error,
1105
+ scopeId
1106
+ }
1107
+ );
1026
1108
  }
1027
1109
  try {
1028
1110
  const topic = await ctx.runQuery(api.topics.getByLegacyScopeId, {
@@ -1031,7 +1113,11 @@ async function resolveTopicDoc(ctx, scopeId) {
1031
1113
  if (topic?.name !== void 0 && topic?.type !== void 0) {
1032
1114
  return topic;
1033
1115
  }
1034
- } catch {
1116
+ } catch (error) {
1117
+ debugGraphPrimitiveFallback(
1118
+ "[topicProjectOverlay] Failed to resolve topic by legacy scope ID",
1119
+ { error, scopeId }
1120
+ );
1035
1121
  }
1036
1122
  return null;
1037
1123
  }
@@ -1085,7 +1171,11 @@ async function listTopicProjectOverlays(ctx, options = {}) {
1085
1171
  if (ctx?.db?.query && typeof ctx.db.query === "function") {
1086
1172
  try {
1087
1173
  allTopics = await ctx.db.query("topics").collect();
1088
- } catch {
1174
+ } catch (error) {
1175
+ debugGraphPrimitiveFallback(
1176
+ "[topicProjectOverlay] Failed to read topics table; falling back to API",
1177
+ { error }
1178
+ );
1089
1179
  allTopics = [];
1090
1180
  }
1091
1181
  }
@@ -1180,19 +1270,28 @@ async function patchTopicProjectOverlay(ctx, scopeId, value) {
1180
1270
  "Cannot patch topic without component adapter (ctx.runMutation unavailable)"
1181
1271
  );
1182
1272
  }
1183
- return materializeTopicProjectOverlay(
1184
- {
1185
- ...topic,
1186
- ...patch,
1187
- metadata: nextMetadata
1188
- }
1189
- );
1273
+ return materializeTopicProjectOverlay({
1274
+ ...topic,
1275
+ ...patch,
1276
+ metadata: nextMetadata
1277
+ });
1190
1278
  }
1191
1279
 
1192
1280
  // src/resolvers.ts
1193
1281
  function isMissingLucernChildComponentError2(error) {
1194
- const message = error instanceof Error ? error.message : String(error);
1195
- return message.includes('Child component ComponentName(Identifier("lucern")) not found') || message.includes("Child component") && message.includes("lucern") && message.includes("not found");
1282
+ const message = getErrorMessage2(error);
1283
+ return message.includes(
1284
+ 'Child component ComponentName(Identifier("lucern")) not found'
1285
+ ) || message.includes("Child component") && message.includes("lucern") && message.includes("not found");
1286
+ }
1287
+ function getErrorMessage2(error) {
1288
+ if (error instanceof Error) {
1289
+ return error.message;
1290
+ }
1291
+ if (typeof error === "object" && error !== null && "message" in error && typeof error.message === "string") {
1292
+ return error.message;
1293
+ }
1294
+ return "unknown error";
1196
1295
  }
1197
1296
  function isAdvisoryTopicPatch(value) {
1198
1297
  const advisoryKeys = /* @__PURE__ */ new Set(["lastActivityAt", "updatedAt"]);
@@ -1206,32 +1305,27 @@ async function patchProjectWithTolerance(ctx, projectId, value) {
1206
1305
  if (!isAdvisoryTopicPatch(value) || !isMissingLucernChildComponentError2(error)) {
1207
1306
  throw error;
1208
1307
  }
1209
- console.warn("[lucern graph-primitives] Non-fatal advisory topic patch failure", {
1210
- projectId,
1211
- keys: Object.keys(value),
1212
- error: error instanceof Error ? error.message : error
1213
- });
1308
+ console.warn(
1309
+ "[lucern graph-primitives] Non-fatal advisory topic patch failure",
1310
+ {
1311
+ projectId,
1312
+ keys: Object.keys(value),
1313
+ error: getErrorMessage2(error)
1314
+ }
1315
+ );
1214
1316
  }
1215
1317
  }
1216
1318
  function defaultResolvers() {
1217
1319
  return {
1218
- async getProject(ctx, projectId) {
1219
- return await resolveTopicProjectOverlay(ctx, projectId, {
1220
- idMode: "legacy",
1221
- projectLikeOnly: false
1222
- });
1223
- },
1224
- async patchProject(ctx, projectId, value) {
1225
- await patchProjectWithTolerance(ctx, projectId, value);
1226
- },
1227
- async listTopics(ctx) {
1228
- return await listTopicProjectOverlays(ctx, {
1229
- idMode: "legacy"
1230
- });
1231
- },
1232
- async getFinalArtifact(ctx, artifactId) {
1233
- return await ctx.db.get(artifactId);
1234
- }
1320
+ getProject: (ctx, projectId) => resolveTopicProjectOverlay(ctx, projectId, {
1321
+ idMode: "legacy",
1322
+ projectLikeOnly: false
1323
+ }),
1324
+ patchProject: (ctx, projectId, value) => patchProjectWithTolerance(ctx, projectId, value),
1325
+ listTopics: (ctx) => listTopicProjectOverlays(ctx, {
1326
+ idMode: "legacy"
1327
+ }),
1328
+ getFinalArtifact: (ctx, artifactId) => ctx.db.get(artifactId)
1235
1329
  };
1236
1330
  }
1237
1331
  var resolverOverrides = {};
@@ -1307,6 +1401,15 @@ function buildBeliefConfidenceRow(args) {
1307
1401
  ...args.triggeringWorktreeId ? { triggeringWorktreeId: args.triggeringWorktreeId } : {}
1308
1402
  };
1309
1403
  }
1404
+ function buildBeliefStatusSuccessResult() {
1405
+ return { success: true };
1406
+ }
1407
+ function buildBeliefEvidenceNotFoundResult() {
1408
+ const result = {};
1409
+ result.success = false;
1410
+ result.message = "Evidence node not found";
1411
+ return result;
1412
+ }
1310
1413
  function deriveSyntheticBackfillOpinion(source) {
1311
1414
  const belief = readFiniteNumber(source.opinion_b) ?? readFiniteNumber(source.belief);
1312
1415
  const disbelief = readFiniteNumber(source.opinion_d) ?? readFiniteNumber(source.disbelief);
@@ -1315,7 +1418,13 @@ function deriveSyntheticBackfillOpinion(source) {
1315
1418
  if (belief !== void 0 || disbelief !== void 0 || uncertainty !== void 0 || baseRate !== void 0) {
1316
1419
  try {
1317
1420
  return readOpinionFromRecord(source);
1318
- } catch {
1421
+ } catch (error) {
1422
+ debugGraphPrimitiveFallback(
1423
+ "[epistemicBeliefs] Failed to decode legacy belief opinion",
1424
+ {
1425
+ error
1426
+ }
1427
+ );
1319
1428
  return mkOpinion(0, 0, 1, 0.5);
1320
1429
  }
1321
1430
  }
@@ -1343,7 +1452,14 @@ function readBeliefOpinionSnapshot(node, metadata) {
1343
1452
  opinion_u: node.opinion_u,
1344
1453
  opinion_a: node.opinion_a
1345
1454
  });
1346
- } catch {
1455
+ } catch (error) {
1456
+ debugGraphPrimitiveFallback(
1457
+ "[epistemicBeliefs] Failed to read belief opinion snapshot",
1458
+ {
1459
+ error,
1460
+ beliefId: node._id
1461
+ }
1462
+ );
1347
1463
  return mkOpinion(0, 0, 1, 0.5);
1348
1464
  }
1349
1465
  }
@@ -1436,7 +1552,15 @@ async function resolveBeliefScopeOrNull(ctx, args) {
1436
1552
  projectId: args.projectId ?? void 0,
1437
1553
  topicId: args.topicId ?? void 0
1438
1554
  });
1439
- } catch {
1555
+ } catch (error) {
1556
+ debugGraphPrimitiveFallback(
1557
+ "[epistemicBeliefs] Failed to resolve belief scope",
1558
+ {
1559
+ error,
1560
+ projectId: args.projectId,
1561
+ topicId: args.topicId
1562
+ }
1563
+ );
1440
1564
  return null;
1441
1565
  }
1442
1566
  }
@@ -1536,7 +1660,13 @@ async function getActiveConfidencePolicy(ctx) {
1536
1660
  activeConfig?.tupleContradictionPolicy
1537
1661
  )
1538
1662
  };
1539
- } catch {
1663
+ } catch (error) {
1664
+ debugGraphPrimitiveFallback(
1665
+ "[epistemicBeliefs] Failed to load active confidence policy",
1666
+ {
1667
+ error
1668
+ }
1669
+ );
1540
1670
  return DEFAULT_CONFIDENCE_POLICY;
1541
1671
  }
1542
1672
  }
@@ -1573,7 +1703,11 @@ async function applyBeliefConfidenceChange(ctx, args) {
1573
1703
  details: { nodeId: args.nodeId }
1574
1704
  });
1575
1705
  }
1576
- await requireProjectWriteAccess(ctx, node.projectId, args.authenticatedUserId);
1706
+ await requireProjectWriteAccess(
1707
+ ctx,
1708
+ node.projectId,
1709
+ args.authenticatedUserId
1710
+ );
1577
1711
  const existingMetadata = node.metadata || {};
1578
1712
  const currentBeliefStatus = resolveBeliefStatus(node, existingMetadata);
1579
1713
  const confidencePolicy = await getActiveConfidencePolicy(ctx);
@@ -1617,29 +1751,29 @@ async function applyBeliefConfidenceChange(ctx, args) {
1617
1751
  opinion: nextOpinion,
1618
1752
  policy: tupleTransition.policy
1619
1753
  });
1620
- const newBeliefStatus = promoteBeliefStatusAfterScoring(
1621
- currentBeliefStatus,
1622
- {
1623
- confidence: derivedConfidence,
1624
- predictionMeta,
1625
- metadata: existingMetadata
1626
- }
1627
- );
1754
+ const newBeliefStatus = promoteBeliefStatusAfterScoring(currentBeliefStatus, {
1755
+ confidence: derivedConfidence,
1756
+ predictionMeta,
1757
+ metadata: existingMetadata
1758
+ });
1628
1759
  let tupleContradictionId;
1629
1760
  if (tupleTransition.crossedIntoTupleContradiction) {
1630
- tupleContradictionId = await ctx.runMutation("contradictions:create", {
1631
- projectId: node.projectId,
1632
- topicId: node.topicId,
1633
- beliefId: args.nodeId,
1634
- beliefBId: args.nodeId,
1635
- supportingInsightIds: [],
1636
- contradictingInsightIds: [],
1637
- severity: deriveTupleContradictionSeverity(node),
1638
- source: "tuple_space",
1639
- detectionMethod: "agent",
1640
- description: tupleContradictionDescription,
1641
- createdBy: args.authenticatedUserId
1642
- });
1761
+ tupleContradictionId = await ctx.runMutation(
1762
+ "contradictions:create",
1763
+ {
1764
+ projectId: node.projectId,
1765
+ topicId: node.topicId,
1766
+ beliefId: args.nodeId,
1767
+ beliefBId: args.nodeId,
1768
+ supportingInsightIds: [],
1769
+ contradictingInsightIds: [],
1770
+ severity: deriveTupleContradictionSeverity(node),
1771
+ source: "tuple_space",
1772
+ detectionMethod: "agent",
1773
+ description: tupleContradictionDescription,
1774
+ createdBy: args.authenticatedUserId
1775
+ }
1776
+ );
1643
1777
  }
1644
1778
  await ctx.db.patch(args.nodeId, {
1645
1779
  confidence: derivedConfidence,
@@ -1663,7 +1797,10 @@ async function applyBeliefConfidenceChange(ctx, args) {
1663
1797
  });
1664
1798
  if (isFirstScoring) {
1665
1799
  const nodeTopicId = node.topicId;
1666
- 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();
1800
+ const themeNodes = await ctx.db.query("epistemicNodes").withIndex(
1801
+ "by_topic",
1802
+ (q) => q.eq("topicId", nodeTopicId || node.projectId)
1803
+ ).filter((q) => q.eq(q.field("nodeType"), "theme")).collect();
1667
1804
  for (const theme of themeNodes) {
1668
1805
  if (theme.globalId && node.globalId) {
1669
1806
  await ctx.scheduler.runAfter(0, internal.neo4jEdgeAPI.createEdge, {
@@ -2261,7 +2398,15 @@ query({
2261
2398
  projectId: args.projectId,
2262
2399
  topicId: args.topicId
2263
2400
  });
2264
- } catch {
2401
+ } catch (error) {
2402
+ debugGraphPrimitiveFallback(
2403
+ "[epistemicBeliefs] Failed to resolve project scope",
2404
+ {
2405
+ error,
2406
+ projectId: args.projectId,
2407
+ topicId: args.topicId
2408
+ }
2409
+ );
2265
2410
  return [];
2266
2411
  }
2267
2412
  if (args.userId) {
@@ -2305,7 +2450,9 @@ query({
2305
2450
  handler: async (ctx, args) => {
2306
2451
  const pageSize = clampBeliefLimit(args.limit);
2307
2452
  const scanLimit = Math.min(pageSize * 3, MAX_PROJECT_BELIEF_LIMIT);
2308
- const scope = await resolveTopicProjectScope(ctx, { topicId: args.topicId });
2453
+ const scope = await resolveTopicProjectScope(ctx, {
2454
+ topicId: args.topicId
2455
+ });
2309
2456
  const query2 = ctx.db.query("epistemicNodes").withIndex(
2310
2457
  "by_topic_type",
2311
2458
  (q) => q.eq("topicId", args.topicId).eq("nodeType", "belief")
@@ -2531,16 +2678,18 @@ mutation({
2531
2678
  rationale: v.optional(v.string()),
2532
2679
  userId: v.string(),
2533
2680
  // SL operator provenance (optional — defaults to manual_assessment)
2534
- slOperator: v.optional(v.union(
2535
- v.literal("cumulative_fusion"),
2536
- v.literal("averaging_fusion"),
2537
- v.literal("trust_discount"),
2538
- v.literal("conditional_deduction"),
2539
- v.literal("dependency_cascade"),
2540
- v.literal("negation"),
2541
- v.literal("constraint_fusion"),
2542
- v.literal("manual_assessment")
2543
- )),
2681
+ slOperator: v.optional(
2682
+ v.union(
2683
+ v.literal("cumulative_fusion"),
2684
+ v.literal("averaging_fusion"),
2685
+ v.literal("trust_discount"),
2686
+ v.literal("conditional_deduction"),
2687
+ v.literal("dependency_cascade"),
2688
+ v.literal("negation"),
2689
+ v.literal("constraint_fusion"),
2690
+ v.literal("manual_assessment")
2691
+ )
2692
+ ),
2544
2693
  triggeringEvidenceId: v.optional(v.id("epistemicNodes")),
2545
2694
  triggeringWorktreeId: v.optional(v.string())
2546
2695
  },
@@ -2771,10 +2920,7 @@ query({
2771
2920
  if (!node || node.nodeType !== "belief") {
2772
2921
  return [];
2773
2922
  }
2774
- return await ctx.db.query("beliefConfidence").withIndex(
2775
- "by_beliefId_time",
2776
- (q) => q.eq("beliefId", args.nodeId)
2777
- ).order("asc").collect();
2923
+ return await ctx.db.query("beliefConfidence").withIndex("by_beliefId_time", (q) => q.eq("beliefId", args.nodeId)).order("asc").collect();
2778
2924
  }
2779
2925
  });
2780
2926
  query({
@@ -3078,7 +3224,7 @@ mutation({
3078
3224
  const now = Date.now();
3079
3225
  const evidenceNode = await ctx.db.get(args.insightId);
3080
3226
  if (!evidenceNode || evidenceNode.nodeType !== "evidence") {
3081
- return { success: false, message: "Evidence node not found" };
3227
+ return buildBeliefEvidenceNotFoundResult();
3082
3228
  }
3083
3229
  if (!evidenceNode.projectId) {
3084
3230
  throw new Error("Evidence has no project scope");
@@ -3119,7 +3265,7 @@ mutation({
3119
3265
  projectId: evidenceNode.projectId
3120
3266
  });
3121
3267
  }
3122
- return { success: true };
3268
+ return buildBeliefStatusSuccessResult();
3123
3269
  }
3124
3270
  });
3125
3271
  query({
@@ -3231,7 +3377,7 @@ mutation({
3231
3377
  changedAt: now,
3232
3378
  projectId: edge.projectId
3233
3379
  });
3234
- return { success: true };
3380
+ return buildBeliefStatusSuccessResult();
3235
3381
  }
3236
3382
  });
3237
3383
  mutation({
@@ -3360,13 +3506,23 @@ mutation({
3360
3506
  changedAt: now,
3361
3507
  projectId: node.projectId
3362
3508
  });
3363
- results.push({
3364
- beliefId: update.beliefId,
3365
- nodeId: node._id,
3366
- success: true
3367
- });
3368
- } catch {
3369
- results.push({ beliefId: update.beliefId, success: false });
3509
+ const result = {};
3510
+ result.beliefId = update.beliefId;
3511
+ result.nodeId = node._id;
3512
+ result.success = true;
3513
+ results.push(result);
3514
+ } catch (error) {
3515
+ debugGraphPrimitiveFallback(
3516
+ "[epistemicBeliefs] Failed to update belief criticality",
3517
+ {
3518
+ error,
3519
+ beliefId: update.beliefId
3520
+ }
3521
+ );
3522
+ const result = {};
3523
+ result.beliefId = update.beliefId;
3524
+ result.success = false;
3525
+ results.push(result);
3370
3526
  }
3371
3527
  }
3372
3528
  return { results, updatedCount: results.filter((r) => r.success).length };
@@ -3481,7 +3637,15 @@ query({
3481
3637
  projectId: args.projectId,
3482
3638
  topicId: args.topicId
3483
3639
  });
3484
- } catch {
3640
+ } catch (error) {
3641
+ debugGraphPrimitiveFallback(
3642
+ "[epistemicBeliefs] Failed to resolve criticality scope",
3643
+ {
3644
+ error,
3645
+ projectId: args.projectId,
3646
+ topicId: args.topicId
3647
+ }
3648
+ );
3485
3649
  return [];
3486
3650
  }
3487
3651
  const nodes = await ctx.db.query("epistemicNodes").withIndex(
@@ -3602,7 +3766,9 @@ internalQuery({
3602
3766
  const pageSize = clampBeliefLimit(args.limit, 500);
3603
3767
  const scanLimit = Math.min(pageSize * 3, MAX_PROJECT_BELIEF_LIMIT);
3604
3768
  const audienceMode = args.audienceMode ?? "internal";
3605
- const scope = await resolveTopicProjectScope(ctx, { topicId: args.topicId });
3769
+ const scope = await resolveTopicProjectScope(ctx, {
3770
+ topicId: args.topicId
3771
+ });
3606
3772
  const registryRows = await listAudienceRegistryRows(ctx, {
3607
3773
  tenantId: scope.tenantId,
3608
3774
  workspaceId: scope.workspaceId
@@ -3947,7 +4113,9 @@ internalMutation({
3947
4113
  skippedHasHistory++;
3948
4114
  continue;
3949
4115
  }
3950
- const opinion = deriveSyntheticBackfillOpinion(node);
4116
+ const opinion = deriveSyntheticBackfillOpinion(
4117
+ node
4118
+ );
3951
4119
  await ctx.db.insert(
3952
4120
  "beliefConfidence",
3953
4121
  buildBeliefConfidenceRow({
@@ -4253,7 +4421,13 @@ query({
4253
4421
  return {
4254
4422
  positions: {},
4255
4423
  hasClusters: false,
4256
- counts: { raw: 0, hypothesis: 0, conditional: 0, unprocessed: 0, total: 0 }
4424
+ counts: {
4425
+ raw: 0,
4426
+ hypothesis: 0,
4427
+ conditional: 0,
4428
+ unprocessed: 0,
4429
+ total: 0
4430
+ }
4257
4431
  };
4258
4432
  }
4259
4433
  const allBeliefNodes = await getBeliefNodesForScope(ctx, scope);
@@ -4315,14 +4489,8 @@ mutation({
4315
4489
  let connectedReassigned = 0;
4316
4490
  const alreadyReassigned = /* @__PURE__ */ new Set();
4317
4491
  for (const beliefId of movedBeliefIds) {
4318
- const outbound = await ctx.db.query("epistemicEdges").withIndex(
4319
- "by_from",
4320
- (q) => q.eq("fromNodeId", beliefId)
4321
- ).collect();
4322
- const inbound = await ctx.db.query("epistemicEdges").withIndex(
4323
- "by_to",
4324
- (q) => q.eq("toNodeId", beliefId)
4325
- ).collect();
4492
+ const outbound = await ctx.db.query("epistemicEdges").withIndex("by_from", (q) => q.eq("fromNodeId", beliefId)).collect();
4493
+ const inbound = await ctx.db.query("epistemicEdges").withIndex("by_to", (q) => q.eq("toNodeId", beliefId)).collect();
4326
4494
  const connectedNodeIds = /* @__PURE__ */ new Set();
4327
4495
  for (const edge of outbound) {
4328
4496
  if (edge.toNodeId) connectedNodeIds.add(String(edge.toNodeId));
@@ -4345,7 +4513,14 @@ mutation({
4345
4513
  alreadyReassigned.add(connectedId);
4346
4514
  connectedReassigned++;
4347
4515
  }
4348
- } catch {
4516
+ } catch (error) {
4517
+ debugGraphPrimitiveFallback(
4518
+ "[epistemicBeliefs] Failed to reassign connected node",
4519
+ {
4520
+ error,
4521
+ connectedId
4522
+ }
4523
+ );
4349
4524
  }
4350
4525
  }
4351
4526
  }
@@ -4424,7 +4599,14 @@ function parseJsonCandidate(value) {
4424
4599
  }
4425
4600
  try {
4426
4601
  return JSON.parse(value);
4427
- } catch {
4602
+ } catch (error) {
4603
+ debugGraphPrimitiveFallback(
4604
+ "[evaluators/shared] Failed to parse JSON candidate",
4605
+ {
4606
+ error,
4607
+ valueType: typeof value
4608
+ }
4609
+ );
4428
4610
  return null;
4429
4611
  }
4430
4612
  }