@lucern/graph-primitives 0.3.0-alpha.1 → 0.3.0-alpha.10
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.
- package/dist/{beliefDecay-Q_26RTc-.d.ts → beliefDecay-DZ6tkLYq.d.ts} +1 -1
- package/dist/beliefDecay.d.ts +1 -1
- package/dist/beliefDecay.js +158 -47
- package/dist/beliefDecay.js.map +1 -1
- package/dist/{beliefEvidenceLinks-42FlR48t.d.ts → beliefEvidenceLinks-CWOXxxJg.d.ts} +1 -1
- package/dist/beliefEvidenceLinks.d.ts +1 -1
- package/dist/beliefEvidenceLinks.js +141 -45
- package/dist/beliefEvidenceLinks.js.map +1 -1
- package/dist/{beliefLifecycle-C-AehZgF.d.ts → beliefLifecycle-y8WLXqQj.d.ts} +1 -1
- package/dist/beliefLifecycle.d.ts +1 -1
- package/dist/confidencePropagationDispatch.d.ts +1 -1
- package/dist/confidencePropagationDispatch.js +1 -3
- package/dist/confidencePropagationDispatch.js.map +1 -1
- package/dist/{contradictions-Hdwl7zid.d.ts → contradictions-51VLsESq.d.ts} +1 -1
- package/dist/contradictions.d.ts +1 -1
- package/dist/contradictions.js +67 -8
- package/dist/contradictions.js.map +1 -1
- package/dist/debug.d.ts +4 -0
- package/dist/debug.js +34 -0
- package/dist/debug.js.map +1 -0
- package/dist/edges/contradicts.js.map +1 -1
- package/dist/edges/dependsOn.js.map +1 -1
- package/dist/edges/elaborates.js.map +1 -1
- package/dist/edges/index.js +1 -3
- package/dist/edges/index.js.map +1 -1
- package/dist/edges/informs.js +1 -3
- package/dist/edges/informs.js.map +1 -1
- package/dist/edges/refutes.js +1 -3
- package/dist/edges/refutes.js.map +1 -1
- package/dist/edges/supports.js.map +1 -1
- package/dist/edges/utils.d.ts +3 -3
- package/dist/edges/utils.js +2 -4
- package/dist/edges/utils.js.map +1 -1
- package/dist/embeddingTrigger.js +21 -1
- package/dist/embeddingTrigger.js.map +1 -1
- package/dist/entityBridge.js +1 -1
- package/dist/entityBridge.js.map +1 -1
- package/dist/{entityLifecycle-BkhRJ-XI.d.ts → entityLifecycle-CvgSK5FV.d.ts} +1 -1
- package/dist/entityLifecycle.d.ts +1 -1
- package/dist/entityLifecycle.js +134 -47
- package/dist/entityLifecycle.js.map +1 -1
- package/dist/{epistemicAnswers-DSP1slZ9.d.ts → epistemicAnswers-C5ib4z6_.d.ts} +1 -1
- package/dist/epistemicAnswers.d.ts +1 -1
- package/dist/epistemicAnswers.js +67 -8
- package/dist/epistemicAnswers.js.map +1 -1
- package/dist/{epistemicBeliefs-DtFVTp-k.d.ts → epistemicBeliefs-DzKjZAeC.d.ts} +3 -3
- package/dist/epistemicBeliefs.d.ts +2 -2
- package/dist/epistemicBeliefs.js +289 -114
- package/dist/epistemicBeliefs.js.map +1 -1
- package/dist/epistemicContracts.d.ts +1 -1
- package/dist/epistemicContracts.js +297 -115
- package/dist/epistemicContracts.js.map +1 -1
- package/dist/{epistemicEdges-DcA8ErUG.d.ts → epistemicEdges-CD5vxmlH.d.ts} +3 -3
- package/dist/epistemicEdges.d.ts +1 -1
- package/dist/epistemicEdges.js +192 -60
- package/dist/epistemicEdges.js.map +1 -1
- package/dist/{epistemicEvidence-Bo638XDP.d.ts → epistemicEvidence-xw6UUrwh.d.ts} +1 -1
- package/dist/epistemicEvidence.d.ts +1 -1
- package/dist/epistemicEvidence.js +163 -49
- package/dist/epistemicEvidence.js.map +1 -1
- package/dist/{epistemicHelpers-Bd9xbaib.d.ts → epistemicHelpers-DevrYgPN.d.ts} +1 -1
- package/dist/epistemicHelpers.d.ts +1 -1
- package/dist/{epistemicLinking-CyeLOIzN.d.ts → epistemicLinking-CfE00tHJ.d.ts} +1 -1
- package/dist/epistemicLinking.d.ts +1 -1
- package/dist/epistemicLinking.js +1 -1
- package/dist/{epistemicNodes-BpD6Koud.d.ts → epistemicNodes-NBrPW7fk.d.ts} +2 -2
- package/dist/epistemicNodes.d.ts +1 -1
- package/dist/epistemicNodes.js +163 -33
- package/dist/epistemicNodes.js.map +1 -1
- package/dist/{epistemicQuestions-CmEeY6zQ.d.ts → epistemicQuestions-B_nUclrH.d.ts} +1 -1
- package/dist/epistemicQuestions.d.ts +1 -1
- package/dist/epistemicQuestions.js +311 -62
- package/dist/epistemicQuestions.js.map +1 -1
- package/dist/{epistemicSources-ZazxHOK1.d.ts → epistemicSources-dlKj58Jp.d.ts} +1 -1
- package/dist/epistemicSources.d.ts +1 -1
- package/dist/epistemicSources.js +65 -8
- package/dist/epistemicSources.js.map +1 -1
- package/dist/evaluators/index.js +297 -115
- package/dist/evaluators/index.js.map +1 -1
- package/dist/evaluators/lintCheckerEvaluator.js.map +1 -1
- package/dist/evaluators/sentryCheckerEvaluator.js.map +1 -1
- package/dist/evaluators/shared.js +20 -1
- package/dist/evaluators/shared.js.map +1 -1
- package/dist/evaluators/testRunnerEvaluator.js +20 -1
- package/dist/evaluators/testRunnerEvaluator.js.map +1 -1
- package/dist/evaluators/tscCheckerEvaluator.js.map +1 -1
- package/dist/index.d.ts +20 -20
- package/dist/index.js +729 -206
- package/dist/index.js.map +1 -1
- package/dist/{ontology-matching-Buhu23ss.d.ts → ontology-matching-C6rrz2VP.d.ts} +1 -1
- package/dist/ontology-matching.d.ts +1 -1
- package/dist/{ontologyApproval-Ba0Jjk1k.d.ts → ontologyApproval-CFYmqKmk.d.ts} +1 -1
- package/dist/ontologyApproval.d.ts +1 -1
- package/dist/ontologyDefinitions.js +4 -3
- package/dist/ontologyDefinitions.js.map +1 -1
- package/dist/ontologyHelpers.d.ts +1 -1
- package/dist/ontologyHelpers.js +4 -3
- package/dist/ontologyHelpers.js.map +1 -1
- package/dist/{projectionReconciliation-CxrXYGaB.d.ts → projectionReconciliation-jww2fBI0.d.ts} +1 -1
- package/dist/projectionReconciliation.d.ts +1 -1
- package/dist/projectionReconciliation.js +14 -20
- package/dist/projectionReconciliation.js.map +1 -1
- package/dist/{projectionStaleness-CAdpIsaW.d.ts → projectionStaleness-CmdbpjVK.d.ts} +1 -1
- package/dist/projectionStaleness.d.ts +1 -1
- package/dist/{questionEvidenceLinks-BdQD0TkM.d.ts → questionEvidenceLinks-DFlyPpAj.d.ts} +1 -1
- package/dist/questionEvidenceLinks.d.ts +1 -1
- package/dist/questionEvidenceLinks.js +144 -45
- package/dist/questionEvidenceLinks.js.map +1 -1
- package/dist/resolvers.js +86 -37
- package/dist/resolvers.js.map +1 -1
- package/dist/scopeResolverCompat.js +64 -7
- package/dist/scopeResolverCompat.js.map +1 -1
- package/dist/{text-matching-CMn2WnVD.d.ts → text-matching-DNg4M5Wd.d.ts} +1 -1
- package/dist/text-matching.d.ts +1 -1
- package/dist/topicProjectOverlay.js +56 -13
- package/dist/topicProjectOverlay.js.map +1 -1
- package/dist/topicScope.js +55 -6
- package/dist/topicScope.js.map +1 -1
- package/dist/workflowBridge.js +55 -6
- package/dist/workflowBridge.js.map +1 -1
- package/dist/workspaceIsolation.js +55 -6
- package/dist/workspaceIsolation.js.map +1 -1
- package/package.json +5 -5
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Id, MutationCtx } from './convex.js';
|
|
2
|
-
import {
|
|
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,
|
|
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
|
-
|
|
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(
|
|
497
|
-
|
|
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 =
|
|
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(
|
|
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
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
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 =
|
|
1195
|
-
return message.includes(
|
|
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(
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
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
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
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(
|
|
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
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
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(
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
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(
|
|
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, {
|
|
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(
|
|
2535
|
-
v.
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
3364
|
-
|
|
3365
|
-
|
|
3366
|
-
|
|
3367
|
-
|
|
3368
|
-
} catch {
|
|
3369
|
-
|
|
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, {
|
|
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(
|
|
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: {
|
|
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
|
-
|
|
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
|
}
|