@lucern/events 1.0.15 → 1.0.17

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.
@@ -35,7 +35,7 @@ var REASONING_METHODS = [
35
35
  // ../contracts/src/tool-contracts.graph.ts
36
36
  var QUERY_LINEAGE = {
37
37
  name: "query_lineage",
38
- description: "Trace a belief's full ancestry \u2014 every fork, score, and confidence modulation. Like `git log --graph`. Returns the complete evolution chain showing how understanding developed over time. Lineage is permanent and can never be erased (Invariant #3).",
38
+ description: "Trace a belief's full ancestry \u2014 every fork, score, and SL scoring event. Like `git log --graph`. Returns the complete evolution chain showing how understanding developed over time. Lineage is permanent and can never be erased (Invariant #3).",
39
39
  parameters: {
40
40
  nodeId: { type: "string", description: "Starting node to trace from" },
41
41
  depth: {
@@ -234,7 +234,7 @@ var FIND_CONTRADICTIONS = {
234
234
  };
235
235
  var BISECT_CONFIDENCE = {
236
236
  name: "bisect_confidence",
237
- description: "Find when a belief's confidence diverged from reality. Like `git bisect` \u2014 binary search through the credence history to find the inflection point. Given a belief that is now known to be wrong (or right), traces back through confidence modulations to identify which evidence or event caused the divergence.",
237
+ description: "Find when a belief's confidence diverged from reality. Like `git bisect` \u2014 binary search through the credence history to find the inflection point. Given a belief that is now known to be wrong (or right), traces back through SL scoring events to identify which evidence or event caused the divergence.",
238
238
  parameters: {
239
239
  nodeId: { type: "string", description: "The belief to bisect" },
240
240
  expectedDirection: {
@@ -253,7 +253,7 @@ var BISECT_CONFIDENCE = {
253
253
  fields: {
254
254
  beliefId: "string \u2014 canonical belief ID",
255
255
  expectedDirection: "string \u2014 overconfident | underconfident",
256
- inflectionEntry: "object \u2014 the confidence modulation where divergence began",
256
+ inflectionEntry: "object \u2014 the scoring event where divergence began",
257
257
  triggerEvent: "string | null \u2014 what caused the divergence",
258
258
  confidenceBefore: "number | null",
259
259
  confidenceAfter: "number | null",
@@ -547,18 +547,18 @@ var SEARCH_EVIDENCE = {
547
547
  };
548
548
  var CREATE_EVIDENCE = {
549
549
  name: "create_evidence",
550
- description: "Commit evidence to the reasoning graph. Like `git commit` \u2014 creates a traceable evidence record with canonical public IDs. Optionally links the evidence to a belief or question in the same operation. When evidence bears on beliefs, state whether it supports or contradicts; SL confidence is derived from these evidence relations.",
550
+ description: "Commit evidence to the reasoning graph. Like `git commit` \u2014 creates a traceable evidence record with canonical public IDs. Evidence creation must link to at least one belief and must include a signed impact score. Positive scores support the belief; negative scores contradict it. SL confidence is derived from these weighted evidence relations.",
551
551
  parameters: {
552
552
  topicId: { type: "string", description: "Topic scope" },
553
553
  text: { type: "string", description: "Canonical evidence text" },
554
554
  source: { type: "string", description: "Source URL or source label" },
555
555
  targetId: {
556
556
  type: "string",
557
- description: "Optional belief or question identifier to link immediately"
557
+ description: "Belief identifier to link immediately"
558
558
  },
559
559
  weight: {
560
560
  type: "number",
561
- description: "Optional support weight: -1.0 (contradicts) to +1.0 (supports). If omitted, evidenceRelation + confidence determine the weight."
561
+ description: "Required nonzero signed impact score: -1.0 (contradicts) to +1.0 (supports)."
562
562
  },
563
563
  evidenceRelation: {
564
564
  type: "string",
@@ -567,7 +567,7 @@ var CREATE_EVIDENCE = {
567
567
  },
568
568
  confidence: {
569
569
  type: "number",
570
- description: "Confidence in the evidence relation, 0.0 to 1.0"
570
+ description: "Deprecated hint. Runtime confidence is derived from the signed impact score."
571
571
  },
572
572
  beliefRelations: {
573
573
  type: "array",
@@ -589,7 +589,7 @@ var CREATE_EVIDENCE = {
589
589
  },
590
590
  kind: { type: "string", description: "Optional evidence kind" }
591
591
  },
592
- required: ["text", "rationale"],
592
+ required: ["text", "rationale", "weight"],
593
593
  response: {
594
594
  description: "The created canonical evidence record",
595
595
  fields: {
@@ -664,7 +664,7 @@ var LINK_EVIDENCE = {
664
664
  },
665
665
  rationale: { type: "string", description: "Why this link exists" }
666
666
  },
667
- required: ["evidenceId", "targetId"],
667
+ required: ["evidenceId", "targetId", "weight"],
668
668
  response: {
669
669
  description: "The created canonical evidence edge summary",
670
670
  fields: {
@@ -700,7 +700,7 @@ var LINK_EVIDENCE_TO_BELIEF = {
700
700
  },
701
701
  rationale: { type: "string", description: "Why this evidence is relevant" }
702
702
  },
703
- required: ["evidenceId", "beliefId"],
703
+ required: ["evidenceId", "beliefId", "weight"],
704
704
  response: {
705
705
  description: "The created edge linking evidence to belief",
706
706
  fields: {
@@ -718,15 +718,23 @@ var LINK_EVIDENCE_TO_BELIEF = {
718
718
  // ../contracts/src/tool-contracts.lifecycle.ts
719
719
  var CREATE_BELIEF = {
720
720
  name: "create_belief",
721
- description: "Commit a new belief (knowledge unit) to the reasoning graph. Like `git commit` \u2014 creates an atomic, traceable knowledge object with a prior. Creation stores the vacuous opinion `(0, 0, 1, a)`; attach supporting or contradicting evidence with create_evidence or link_evidence_to_belief to record evidential updates.",
721
+ description: "Commit a new belief (knowledge unit) to the reasoning graph. Like `git commit` \u2014 creates an atomic, traceable knowledge object with a prior. Creation requires a topic epistemic-node anchor and writes a `scoped_by` edge directly from belief node to topic node; orphan beliefs are invalid. Creation stores the vacuous opinion `(0, 0, 1, a)`; attach supporting or contradicting evidence with create_evidence or link_evidence_to_belief to record evidential updates.",
722
722
  parameters: {
723
723
  canonicalText: {
724
724
  type: "string",
725
725
  description: "The belief statement \u2014 what the agent holds to be true"
726
726
  },
727
+ topicGlobalId: {
728
+ type: "string",
729
+ description: "Required globalId (UUID) of the topic node in epistemicNodes that anchors the belief"
730
+ },
731
+ topicNodeId: {
732
+ type: "string",
733
+ description: "Optional internal epistemicNodes _id for the topic anchor. Prefer topicGlobalId for public callers."
734
+ },
727
735
  topicId: {
728
736
  type: "string",
729
- description: "Optional topic scope hint for the belief"
737
+ description: "Deprecated compatibility alias for topicGlobalId. Must identify a topic epistemicNode, not a legacy topics-table row."
730
738
  },
731
739
  baseRate: {
732
740
  type: "number",
@@ -741,7 +749,7 @@ var CREATE_BELIEF = {
741
749
  description: "Optional extra metadata merged into the node (e.g., { codeAnchors: ['path/to/file.ts'] } for coding intelligence)"
742
750
  }
743
751
  },
744
- required: ["canonicalText"],
752
+ required: ["canonicalText", "topicGlobalId"],
745
753
  response: {
746
754
  description: "The created canonical belief record",
747
755
  fields: {
@@ -750,7 +758,7 @@ var CREATE_BELIEF = {
750
758
  beliefId: "string \u2014 canonical belief ID",
751
759
  text: "string \u2014 canonical belief formulation",
752
760
  topicId: "string",
753
- status: "string \u2014 active | superseded | archived",
761
+ beliefStatus: "string \u2014 assumption | hypothesis | active | superseded | resolved_true | resolved_false",
754
762
  scoringState: "string \u2014 unscored | scored"
755
763
  }
756
764
  },
@@ -773,7 +781,7 @@ var GET_BELIEF = {
773
781
  beliefId: "string \u2014 canonical belief ID",
774
782
  text: "string \u2014 canonical belief formulation",
775
783
  topicId: "string",
776
- status: "string \u2014 active | superseded | archived",
784
+ beliefStatus: "string \u2014 assumption | hypothesis | active | superseded | resolved_true | resolved_false",
777
785
  scoringState: "string \u2014 unscored | scored"
778
786
  }
779
787
  },
@@ -802,34 +810,24 @@ var REFINE_BELIEF = {
802
810
  ontologyPrimitive: "belief",
803
811
  tier: "showcase"
804
812
  };
805
- var MODULATE_CONFIDENCE = {
806
- name: "modulate_confidence",
807
- description: "Internal-only subjective-logic ledger append. Like `git commit` to the credence log for the scoring engine \u2014 never an operator-facing way to assert confidence. Agents, SDK callers, CLI users, and MCP clients must instead create or link evidence with `evidenceRelation: supports|contradicts`; the kernel derives the next opinion from that evidence. This compatibility primitive is reserved for governed system scoring paths that already hold a full subjective-logic tuple and truth-bearing provenance.",
813
+ var APPEND_SL_SCORING = {
814
+ name: "append_sl_scoring",
815
+ description: "Internal evidence-backed Subjective Logic scoring append. This is not a public MCP tool: callers should attach supporting or contradicting evidence, and governed system paths append the derived SL tuple.",
808
816
  parameters: {
809
- nodeId: { type: "string", description: "The belief to score" },
810
- belief: {
811
- type: "number",
812
- description: "Subjective-logic belief mass `b` in [0, 1]"
813
- },
817
+ nodeId: { type: "string", description: "The belief receiving the SL score" },
818
+ belief: { type: "number", description: "Subjective Logic belief mass b" },
814
819
  disbelief: {
815
820
  type: "number",
816
- description: "Subjective-logic disbelief mass `d` in [0, 1]"
821
+ description: "Subjective Logic disbelief mass d"
817
822
  },
818
823
  uncertainty: {
819
824
  type: "number",
820
- description: "Subjective-logic uncertainty mass `u` in [0, 1]"
821
- },
822
- baseRate: {
823
- type: "number",
824
- description: "Subjective-logic base rate `a` in [0, 1]. Required for tuple payloads."
825
- },
826
- worktreeId: {
827
- type: "string",
828
- description: "Completed worktree that tested this belief when confidence policy requires merge-backed scoring."
825
+ description: "Subjective Logic uncertainty mass u"
829
826
  },
827
+ baseRate: { type: "number", description: "Subjective Logic base rate a" },
830
828
  trigger: {
831
829
  type: "string",
832
- description: "What caused this confidence change",
830
+ description: "Evidence-bearing cause of the scoring event",
833
831
  enum: [
834
832
  "evidence_added",
835
833
  "evidence_removed",
@@ -840,64 +838,39 @@ var MODULATE_CONFIDENCE = {
840
838
  "worktree_completed",
841
839
  "fusion",
842
840
  "discount",
843
- "deduction"
841
+ "deduction",
842
+ "backfill_synthetic"
844
843
  ]
845
844
  },
846
- triggeringEvidenceId: {
847
- type: "string",
848
- description: "Evidence node that caused an evidence-triggered modulation"
849
- },
850
- triggeringQuestionId: {
851
- type: "string",
852
- description: "Answered question whose resolution supports this modulation"
853
- },
854
- triggeringAnswerId: {
855
- type: "string",
856
- description: "Answer node whose content supports this modulation"
857
- },
858
- triggeringContradictionId: {
859
- type: "string",
860
- description: "Contradiction record that caused a contradiction-triggered modulation"
861
- },
862
- triggeringWorktreeId: {
863
- type: "string",
864
- description: "Completed worktree whose outcome caused a worktree-triggered modulation"
845
+ provenance: {
846
+ type: "object",
847
+ description: "At least one of evidence, question, answer, contradiction, or worktree."
865
848
  },
866
849
  rationale: {
867
850
  type: "string",
868
- description: "Human-readable explanation of why confidence changed"
851
+ description: "Why this evidence-bearing event moved the SL tuple"
869
852
  }
870
853
  },
871
- required: [
872
- "nodeId",
873
- "belief",
874
- "disbelief",
875
- "uncertainty",
876
- "baseRate",
877
- "trigger",
878
- "rationale"
879
- ],
854
+ required: ["nodeId", "belief", "disbelief", "uncertainty", "baseRate", "trigger", "rationale"],
880
855
  response: {
881
- description: "Confidence modulation result",
856
+ description: "Internal SL scoring append receipt",
882
857
  fields: {
883
- beliefId: "string \u2014 canonical belief ID",
884
- nodeId: "string \u2014 canonical belief ID",
885
- newConfidence: "number",
858
+ nodeId: "string",
886
859
  previousConfidence: "number",
887
- trigger: "string",
888
- requestId: "string \u2014 request identifier for the scheduled cascade",
889
- propagationSummary: "object \u2014 bounded inline cascade summary with totalCandidateTargets, inlineTargets, and remainingTargetCount"
860
+ newConfidence: "number",
861
+ beliefConfidenceId: "string"
890
862
  }
891
863
  },
892
864
  ownerModule: "graph-primitives",
893
865
  ontologyPrimitive: "belief",
894
- tier: "showcase"
866
+ tier: "workhorse",
867
+ internal: true
895
868
  };
896
869
  var FORK_BELIEF = {
897
870
  name: "fork_belief",
898
- description: "Branch off a scored belief to create a new version with a different formulation. Like `git fork` \u2014 the parent remains immutable with full history. The new belief gets a `supersedes` edge to the parent. Fork reasons: refinement, contradiction_response, scope_change, confidence_collapse, manual.",
871
+ description: "Branch off an evidence-bearing belief to create a new formulation. Like `git fork` \u2014 the parent remains immutable with full history, and every fork must cite evidence already attached to the parent through SL scoring. `forkMode=supersede` marks the parent superseded and requires contradicting evidence; `forkMode=branch` preserves the parent and creates a derived child.",
899
872
  parameters: {
900
- nodeId: { type: "string", description: "The scored belief to fork from" },
873
+ nodeId: { type: "string", description: "The belief to fork from" },
901
874
  newFormulation: {
902
875
  type: "string",
903
876
  description: "The evolved belief statement"
@@ -909,12 +882,20 @@ var FORK_BELIEF = {
909
882
  "refinement",
910
883
  "contradiction_response",
911
884
  "scope_change",
912
- "confidence_collapse",
913
- "manual"
885
+ "confidence_collapse"
914
886
  ]
887
+ },
888
+ forkMode: {
889
+ type: "string",
890
+ description: "supersede replaces the parent; branch creates a child while preserving the parent.",
891
+ enum: ["supersede", "branch"]
892
+ },
893
+ triggeringEvidenceId: {
894
+ type: "string",
895
+ description: "Evidence already attached to the parent belief that caused the fork."
915
896
  }
916
897
  },
917
- required: ["nodeId", "newFormulation", "forkReason"],
898
+ required: ["nodeId", "newFormulation", "forkReason", "triggeringEvidenceId"],
918
899
  response: {
919
900
  description: "The forked canonical belief record",
920
901
  fields: {
@@ -2179,7 +2160,7 @@ var TRIGGER_BELIEF_REVIEW = {
2179
2160
  };
2180
2161
  var EVALUATE_CONTRACT = {
2181
2162
  name: "evaluate_contract",
2182
- description: "Run a contract evaluation and record the append-only result. Like `git test` for a belief binding \u2014 executes the evaluator, logs the result, and applies any allowed confidence modulation.",
2163
+ description: "Run a contract evaluation and record the append-only result. Like `git test` for a belief binding \u2014 executes the evaluator, logs the result, and applies any allowed SL scoring action.",
2183
2164
  parameters: {
2184
2165
  contractId: { type: "string", description: "Which contract to evaluate" },
2185
2166
  trigger: {
@@ -4053,6 +4034,10 @@ var COMPILE_CONTEXT = {
4053
4034
  type: "number",
4054
4035
  description: "Optional per-section item limit"
4055
4036
  },
4037
+ contentTopicLimit: {
4038
+ type: "number",
4039
+ description: "Dimension-seeded compiles synthesize every matching worktree but bound raw belief/question/evidence enrichment to this many carrier topics (max 16) so hosted Convex queries remain fast. Receipts report any omitted raw topic enrichment."
4040
+ },
4056
4041
  maxDepth: {
4057
4042
  type: "number",
4058
4043
  description: "Optional descendant topic depth for neighborhood expansion"
@@ -4066,6 +4051,11 @@ var COMPILE_CONTEXT = {
4066
4051
  response: {
4067
4052
  description: "Compiled context pack for the requested topic",
4068
4053
  fields: {
4054
+ contextNarrative: "array \u2014 first field; ordered synthesis blocks with kind/text, starting with executive_summary and canonical narrative blocks before raw objects",
4055
+ narrativeCoverage: "object \u2014 recordsSynthesized, recordsNamed, recordsOmitted, topicsSynthesized, topicsEnriched, topicContentOmitted, enrichmentMode, and blocksEmitted for the narrative",
4056
+ synthesisLints: "array \u2014 inline quality warnings for degenerate synthesis blocks or weak narrative coverage",
4057
+ retrievalReceipt: "object \u2014 candidateCounts, coverageWarning, narrativeCoverage, synthesisLints, and suggestedNextActions",
4058
+ supportingObjects: "object \u2014 raw graph records grouped behind the synthesis: invariants, activeBeliefs, openQuestions, recentEvidence, worktrees, lanes, entities, and contradictions",
4069
4059
  schemaVersion: "string",
4070
4060
  topicId: "string",
4071
4061
  topicName: "string",
@@ -4073,15 +4063,6 @@ var COMPILE_CONTEXT = {
4073
4063
  generatedAt: "number \u2014 deterministic graph-backed reference timestamp for this compilation",
4074
4064
  ranking: "string \u2014 baseline_v1 | weighted_v1",
4075
4065
  summary: "object \u2014 counts and scoped health signals",
4076
- invariants: "array \u2014 high-confidence invariant beliefs",
4077
- activeBeliefs: "array \u2014 current high-signal beliefs",
4078
- openQuestions: "array \u2014 unresolved questions ranked for this query",
4079
- recentEvidence: "array \u2014 recent evidence ranked for this query",
4080
- contradictions: "array \u2014 unresolved contradiction records",
4081
- relatedEntities: "array | undefined \u2014 ranked ontological entities in scope",
4082
- contextNarrative: "array \u2014 ordered synthesis blocks with kind/text, starting with executive_summary and canonical narrative blocks before raw objects",
4083
- retrievalReceipt: "object \u2014 candidateCounts, coverageWarning, narrativeCoverage, synthesisLints, and suggestedNextActions",
4084
- narrativeCoverage: "object \u2014 recordsSynthesized, recordsNamed, recordsOmitted, and blocksEmitted for the narrative",
4085
4066
  injectionPolicy: "object \u2014 token-budgeted section selections",
4086
4067
  diagnostics: "object \u2014 scoring and utilization telemetry"
4087
4068
  }
@@ -4640,7 +4621,7 @@ var MCP_TOOL_CONTRACTS = {
4640
4621
  create_belief: CREATE_BELIEF,
4641
4622
  get_belief: GET_BELIEF,
4642
4623
  refine_belief: REFINE_BELIEF,
4643
- modulate_confidence: MODULATE_CONFIDENCE,
4624
+ append_sl_scoring: APPEND_SL_SCORING,
4644
4625
  fork_belief: FORK_BELIEF,
4645
4626
  archive_belief: ARCHIVE_BELIEF,
4646
4627
  create_epistemic_contract: CREATE_EPISTEMIC_CONTRACT,
@@ -6438,8 +6419,10 @@ defineTable({
6438
6419
  "beliefStatus": z.object({
6439
6420
  "assumption": z.number(),
6440
6421
  "hypothesis": z.number(),
6441
- "belief": z.number(),
6442
- "fact": z.number()
6422
+ "active": z.number(),
6423
+ "superseded": z.number(),
6424
+ "resolved_true": z.number(),
6425
+ "resolved_false": z.number()
6443
6426
  }).optional(),
6444
6427
  "evidenceTemporalNature": z.object({
6445
6428
  "factual": z.number(),
@@ -6661,8 +6644,8 @@ defineTable({
6661
6644
  "exportClass": z.enum(["internal_only", "client_safe", "public_safe", "restricted"]).optional(),
6662
6645
  "anonymizationClass": z.enum(["none", "standard", "strict"]).optional(),
6663
6646
  "beliefType": z.string().optional(),
6664
- "beliefStatus": z.enum(["assumption", "hypothesis", "belief", "fact"]).optional(),
6665
- "epistemicStatus": z.enum(["hypothesis", "emerging", "established", "challenged", "assumption", "deprecated"]).optional(),
6647
+ "beliefStatus": z.enum(["assumption", "hypothesis", "active", "superseded", "resolved_true", "resolved_false"]).optional(),
6648
+ "epistemicStatus": z.enum(["assumption", "hypothesis", "active", "superseded", "resolved_true", "resolved_false"]).optional(),
6666
6649
  "reversibility": z.enum(["irreversible", "hard_to_reverse", "reversible", "trivial"]).optional(),
6667
6650
  "predictionMeta": z.object({
6668
6651
  "isPrediction": z.boolean(),
@@ -11628,11 +11611,39 @@ var createEvidenceInputSchemaBase = z.object({
11628
11611
  metadata: jsonRecordSchema.optional(),
11629
11612
  trustedBypassAccessCheck: z.boolean().optional()
11630
11613
  }).passthrough();
11631
- function hasNonzeroWeight(value) {
11632
- return typeof value === "number" && Number.isFinite(value) && value !== 0;
11614
+ function isSignedImpactScore(value) {
11615
+ return typeof value === "number" && Number.isFinite(value) && value >= -1 && value <= 1 && value !== 0;
11633
11616
  }
11634
- function hasRelationSignal(value, weight) {
11635
- return Boolean(normalizeRelation(value, weight));
11617
+ function validateSignedImpactScore(value, ctx, path) {
11618
+ if (!isSignedImpactScore(value)) {
11619
+ ctx.addIssue({
11620
+ code: z.ZodIssueCode.custom,
11621
+ message: "evidence-to-belief links require an explicit nonzero signed impact score in [-1, 1]",
11622
+ path
11623
+ });
11624
+ return false;
11625
+ }
11626
+ return true;
11627
+ }
11628
+ function validateRelationImpactConsistency(relation, weight, ctx, path) {
11629
+ const normalized = normalizeRelationAlias(relation);
11630
+ if (!normalized || !isSignedImpactScore(weight)) {
11631
+ return;
11632
+ }
11633
+ if (normalized === "supports" && weight < 0) {
11634
+ ctx.addIssue({
11635
+ code: z.ZodIssueCode.custom,
11636
+ message: "supporting evidence requires a positive impact score",
11637
+ path
11638
+ });
11639
+ }
11640
+ if (normalized === "contradicts" && weight > 0) {
11641
+ ctx.addIssue({
11642
+ code: z.ZodIssueCode.custom,
11643
+ message: "contradicting evidence requires a negative impact score",
11644
+ path
11645
+ });
11646
+ }
11636
11647
  }
11637
11648
  var createEvidenceInputSchema = createEvidenceInputSchemaBase.superRefine(
11638
11649
  (input, ctx) => {
@@ -11649,13 +11660,27 @@ var createEvidenceInputSchema = createEvidenceInputSchemaBase.superRefine(
11649
11660
  input.linkedBeliefNodeId || kind === "belief" || kind === "unknown" && target
11650
11661
  );
11651
11662
  const weight = typeof input.weight === "number" ? input.weight : void 0;
11652
- if (linksPrimaryBelief && !hasRelationSignal(input.evidenceRelation, weight)) {
11663
+ const hasBeliefRelations = (input.beliefRelations?.length ?? 0) > 0;
11664
+ if (!linksPrimaryBelief && !hasBeliefRelations) {
11665
+ ctx.addIssue({
11666
+ code: z.ZodIssueCode.custom,
11667
+ message: "create_evidence requires at least one linked belief; evidence cannot be created as an orphan or linked only to a question/worktree",
11668
+ path: ["linkedBeliefNodeId"]
11669
+ });
11670
+ }
11671
+ if (kind === "question" || kind === "worktree") {
11653
11672
  ctx.addIssue({
11654
11673
  code: z.ZodIssueCode.custom,
11655
- message: "belief-targeted evidence requires evidenceRelation='supports'|'contradicts' or a nonzero signed weight",
11656
- path: ["evidenceRelation"]
11674
+ message: "create_evidence targetId must be a belief. Link evidence to questions/worktrees only after the evidence has a belief impact edge.",
11675
+ path: ["targetId"]
11657
11676
  });
11658
11677
  }
11678
+ if (linksPrimaryBelief) {
11679
+ validateSignedImpactScore(weight, ctx, ["weight"]);
11680
+ validateRelationImpactConsistency(input.evidenceRelation, weight, ctx, [
11681
+ "weight"
11682
+ ]);
11683
+ }
11659
11684
  input.beliefRelations?.forEach((relation, index) => {
11660
11685
  const beliefNodeId = relation.beliefNodeId ?? relation.beliefId ?? relation.targetId;
11661
11686
  if (!beliefNodeId) {
@@ -11666,15 +11691,18 @@ var createEvidenceInputSchema = createEvidenceInputSchemaBase.superRefine(
11666
11691
  });
11667
11692
  }
11668
11693
  const relationWeight2 = typeof relation.weight === "number" ? relation.weight : void 0;
11669
- if (beliefNodeId && !hasRelationSignal(
11670
- relation.evidenceRelation ?? relation.relation,
11671
- relationWeight2
11672
- )) {
11673
- ctx.addIssue({
11674
- code: z.ZodIssueCode.custom,
11675
- message: "beliefRelations entries require evidenceRelation='supports'|'contradicts' or a nonzero signed weight",
11676
- path: ["beliefRelations", index, "evidenceRelation"]
11677
- });
11694
+ if (beliefNodeId) {
11695
+ validateSignedImpactScore(relationWeight2, ctx, [
11696
+ "beliefRelations",
11697
+ index,
11698
+ "weight"
11699
+ ]);
11700
+ validateRelationImpactConsistency(
11701
+ relation.evidenceRelation ?? relation.relation,
11702
+ relationWeight2,
11703
+ ctx,
11704
+ ["beliefRelations", index, "weight"]
11705
+ );
11678
11706
  }
11679
11707
  });
11680
11708
  }
@@ -11728,18 +11756,28 @@ function targetKind(targetId) {
11728
11756
  }
11729
11757
  return "unknown";
11730
11758
  }
11731
- function normalizeRelation(value, weight) {
11759
+ function normalizeRelationAlias(value) {
11732
11760
  if (value === "supports" || value === "supporting") {
11733
11761
  return "supports";
11734
11762
  }
11735
11763
  if (value === "contradicts" || value === "contradicting") {
11736
11764
  return "contradicts";
11737
11765
  }
11766
+ return void 0;
11767
+ }
11768
+ function normalizeRelation(value, weight) {
11769
+ const alias = normalizeRelationAlias(value);
11770
+ if (alias) {
11771
+ return alias;
11772
+ }
11738
11773
  if (weight === void 0 || !hasNonzeroWeight(weight)) {
11739
11774
  return void 0;
11740
11775
  }
11741
11776
  return weight < 0 ? "contradicts" : "supports";
11742
11777
  }
11778
+ function hasNonzeroWeight(value) {
11779
+ return typeof value === "number" && Number.isFinite(value) && value !== 0;
11780
+ }
11743
11781
  function normalizeConfidence(confidence, weight) {
11744
11782
  if (confidence !== void 0) {
11745
11783
  return Math.min(1, Math.max(0, confidence));
@@ -11766,6 +11804,7 @@ function normalizeBeliefRelation(relation) {
11766
11804
  beliefNodeId,
11767
11805
  relation: evidenceRelation,
11768
11806
  confidence: normalizeConfidence(relation.confidence, weight),
11807
+ weight,
11769
11808
  rationale: relation.rationale
11770
11809
  });
11771
11810
  }
@@ -11814,6 +11853,7 @@ var createEvidenceProjection = defineProjection({
11814
11853
  linkedBeliefNodeId,
11815
11854
  evidenceRelation,
11816
11855
  confidence,
11856
+ weight,
11817
11857
  beliefRelations: beliefRelations && beliefRelations.length > 0 ? beliefRelations : void 0,
11818
11858
  rationale: input.rationale,
11819
11859
  trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
@@ -11843,12 +11883,14 @@ var createEvidenceProjection = defineProjection({
11843
11883
  v.literal("contradicts")
11844
11884
  )
11845
11885
  ),
11886
+ weight: v.optional(v.number()),
11846
11887
  beliefRelations: v.optional(
11847
11888
  v.array(
11848
11889
  v.object({
11849
11890
  beliefNodeId: v.string(),
11850
11891
  relation: v.union(v.literal("supports"), v.literal("contradicts")),
11851
11892
  confidence: v.optional(v.number()),
11893
+ weight: v.number(),
11852
11894
  rationale: v.optional(v.string())
11853
11895
  })
11854
11896
  )
@@ -11966,7 +12008,7 @@ var slOpinionProjectionSchema = z.object({
11966
12008
  uncertainty: z.number(),
11967
12009
  baseRate: z.number()
11968
12010
  });
11969
- var modulateConfidenceInputObjectSchema = z.object({
12011
+ var appendSlScoringInputObjectSchema = z.object({
11970
12012
  nodeId: z.string().optional(),
11971
12013
  beliefNodeId: z.string().optional(),
11972
12014
  worktreeId: z.string().optional(),
@@ -11985,23 +12027,23 @@ var modulateConfidenceInputObjectSchema = z.object({
11985
12027
  rationale: z.string(),
11986
12028
  trustedBypassAccessCheck: z.boolean().optional()
11987
12029
  });
11988
- var modulateConfidenceInputSchema = modulateConfidenceInputObjectSchema.superRefine((input, ctx) => {
12030
+ var appendSlScoringInputSchema = appendSlScoringInputObjectSchema.superRefine((input, ctx) => {
11989
12031
  if (hasProvenance(input)) {
11990
12032
  return;
11991
12033
  }
11992
12034
  ctx.addIssue({
11993
12035
  code: z.ZodIssueCode.custom,
11994
- message: "modulate_confidence requires evidence, question, answer, contradiction, or worktree provenance",
12036
+ message: "append_sl_scoring requires evidence, question, answer, contradiction, or worktree provenance",
11995
12037
  path: ["provenance"]
11996
12038
  });
11997
12039
  });
11998
- var modulateConfidenceProjection = defineProjection({
11999
- contractName: "modulate_confidence",
12000
- inputSchema: modulateConfidenceInputSchema,
12040
+ var appendSlScoringProjection = defineProjection({
12041
+ contractName: "append_sl_scoring",
12042
+ inputSchema: appendSlScoringInputSchema,
12001
12043
  project: (input) => {
12002
12044
  const nodeId = input.beliefNodeId ?? input.nodeId;
12003
12045
  if (!nodeId) {
12004
- throw new Error("modulate_confidence requires beliefNodeId or nodeId");
12046
+ throw new Error("append_sl_scoring requires beliefNodeId or nodeId");
12005
12047
  }
12006
12048
  const opinion = input.opinion ?? {
12007
12049
  belief: requireNumber(input.belief, "belief"),
@@ -12058,14 +12100,14 @@ var modulateConfidenceProjection = defineProjection({
12058
12100
  });
12059
12101
  function requireNumber(value, field) {
12060
12102
  if (value === void 0) {
12061
- throw new Error(`modulate_confidence requires ${field}`);
12103
+ throw new Error(`append_sl_scoring requires ${field}`);
12062
12104
  }
12063
12105
  return value;
12064
12106
  }
12065
12107
  function assertProvenance(input) {
12066
12108
  if (!hasProvenance(input)) {
12067
12109
  throw new Error(
12068
- "modulate_confidence requires evidence, question, answer, contradiction, or worktree provenance"
12110
+ "append_sl_scoring requires evidence, question, answer, contradiction, or worktree provenance"
12069
12111
  );
12070
12112
  }
12071
12113
  }
@@ -12408,12 +12450,12 @@ var LUCERN_OPERATION_MANIFEST = {
12408
12450
  internalSystem,
12409
12451
  "Lucern system/background operation. Available to platform code paths, hidden from public MCP discovery."
12410
12452
  ),
12411
- modulate_confidence: {
12412
- name: "modulate_confidence",
12453
+ append_sl_scoring: {
12454
+ name: "append_sl_scoring",
12413
12455
  surfaceClass: "platform_internal",
12414
12456
  surfaceIntent: "system",
12415
12457
  surfaces: internalSdkRestOnly,
12416
- rationale: "Internal SL ledger append primitive. Public callers attach evidence or contradiction relations; confidence is derived algorithmically."
12458
+ rationale: "Internal SL scoring append primitive. Public callers attach evidence or contradiction relations; confidence is derived algorithmically."
12417
12459
  },
12418
12460
  ...entries(
12419
12461
  LEGACY_COMPAT_OPERATION_NAMES,
@@ -12967,7 +13009,15 @@ var predictionMetaSchema = z.object({
12967
13009
  });
12968
13010
  var createBeliefArgs = z.object({
12969
13011
  canonicalText: z.string().describe("The belief statement the agent holds to be true."),
12970
- topicId: z.string().optional().describe("Topic scope hint for the belief."),
13012
+ topicGlobalId: z.string().describe(
13013
+ "Required globalId of the topic epistemicNode that anchors this belief. Belief creation creates a scoped_by edge directly to that topic node."
13014
+ ),
13015
+ topicNodeId: z.string().optional().describe(
13016
+ "Optional internal epistemicNodes _id for the topic anchor. Prefer topicGlobalId for public callers."
13017
+ ),
13018
+ topicId: z.string().optional().describe(
13019
+ "Deprecated compatibility alias for topicGlobalId. Must identify a topic epistemicNode, not a legacy topics-table row."
13020
+ ),
12971
13021
  baseRate: z.number().optional().describe("Prior base rate used to seed the vacuous opinion."),
12972
13022
  beliefType: z.string().optional().describe("Schema belief type."),
12973
13023
  metadata: jsonRecordSchema3.optional().describe("Extra metadata merged into the belief node."),
@@ -12986,9 +13036,14 @@ var forkBeliefArgs = z.object({
12986
13036
  "refinement",
12987
13037
  "contradiction_response",
12988
13038
  "scope_change",
12989
- "confidence_collapse",
12990
- "manual"
13039
+ "confidence_collapse"
12991
13040
  ]).describe("Why this fork was created."),
13041
+ forkMode: z.enum(["supersede", "branch"]).optional().describe(
13042
+ "supersede marks the parent belief superseded; branch preserves the parent and creates a derived child."
13043
+ ),
13044
+ triggeringEvidenceId: z.string().describe(
13045
+ "Evidence already attached to the parent belief through SL scoring; required for every fork."
13046
+ ),
12992
13047
  rationale: z.string().optional().describe("Why the fork is warranted.")
12993
13048
  });
12994
13049
  var beliefLookupInput = (input) => compactRecord4({
@@ -13002,7 +13057,9 @@ var createBeliefInput = (input, context) => {
13002
13057
  return withUserId(
13003
13058
  compactRecord4({
13004
13059
  projectId: input.projectId,
13005
- topicId: input.topicId,
13060
+ topicId: input.topicGlobalId ?? input.topicNodeId ?? input.topicId,
13061
+ topicGlobalId: input.topicGlobalId,
13062
+ topicNodeId: input.topicNodeId,
13006
13063
  formulation: input.formulation ?? input.canonicalText,
13007
13064
  beliefType: input.beliefType,
13008
13065
  rationale: input.rationale,
@@ -13024,20 +13081,22 @@ var forkBeliefInput = (input, context) => withUserId(
13024
13081
  parentNodeId: input.parentNodeId ?? input.nodeId ?? input.id,
13025
13082
  newFormulation: input.newFormulation,
13026
13083
  forkReason: input.forkReason,
13084
+ forkMode: input.forkMode,
13085
+ triggeringEvidenceId: input.triggeringEvidenceId,
13027
13086
  rationale: input.rationale,
13028
13087
  trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
13029
13088
  }),
13030
13089
  context
13031
13090
  );
13032
- var confidenceInput = (input, context) => {
13033
- const parsed = modulateConfidenceProjection.inputSchema.safeParse(input);
13091
+ var appendSlScoringInput = (input, context) => {
13092
+ const parsed = appendSlScoringProjection.inputSchema.safeParse(input);
13034
13093
  if (!parsed.success) {
13035
13094
  throw new Error(
13036
- `modulate_confidence projection input rejected: ${parsed.error.message}`
13095
+ `append_sl_scoring projection input rejected: ${parsed.error.message}`
13037
13096
  );
13038
13097
  }
13039
13098
  return withUserId(
13040
- compactRecord4(modulateConfidenceProjection.project(parsed.data)),
13099
+ compactRecord4(appendSlScoringProjection.project(parsed.data)),
13041
13100
  context
13042
13101
  );
13043
13102
  };
@@ -13115,21 +13174,21 @@ var beliefsContracts = [
13115
13174
  }
13116
13175
  }),
13117
13176
  surfaceContract({
13118
- name: "modulate_confidence",
13177
+ name: "append_sl_scoring",
13119
13178
  kind: "mutation",
13120
13179
  domain: "beliefs",
13121
13180
  surfaceClass: "platform_internal",
13122
- path: "/beliefs/confidence",
13181
+ path: "/beliefs/sl-scoring",
13123
13182
  sdkNamespace: "beliefs",
13124
- sdkMethod: "modulateConfidence",
13125
- summary: "Internal SL ledger append. Public callers should attach evidence or contradiction relations instead.",
13183
+ sdkMethod: "appendSlScoring",
13184
+ summary: "Internal SL scoring append. Public callers attach evidence or contradiction relations instead.",
13126
13185
  convex: {
13127
13186
  module: "beliefs",
13128
- functionName: "modulateConfidence",
13187
+ functionName: "appendSlScoring",
13129
13188
  kind: "mutation",
13130
- inputProjection: confidenceInput
13189
+ inputProjection: appendSlScoringInput
13131
13190
  },
13132
- args: modulateConfidenceInputSchema
13191
+ args: appendSlScoringInputSchema
13133
13192
  }),
13134
13193
  surfaceContract({
13135
13194
  name: "fork_belief",
@@ -13235,8 +13294,12 @@ var beliefRelationSchema2 = z.object({
13235
13294
  targetId: z.string().optional().describe("Belief target ID alias for beliefId/beliefNodeId."),
13236
13295
  relation: z.enum(["supports", "contradicts", "supporting", "contradicting"]).optional().describe("Relation alias for how the evidence bears on the belief."),
13237
13296
  evidenceRelation: evidenceRelationSchema2.optional().describe("Canonical relation: supports or contradicts."),
13238
- confidence: z.number().optional().describe("Confidence in this evidence-to-belief relation."),
13239
- weight: z.number().optional().describe("Support weight from -1.0 to +1.0 for this belief."),
13297
+ confidence: z.number().optional().describe(
13298
+ "Deprecated read-only hint. Runtime SL confidence is derived from signed weight."
13299
+ ),
13300
+ weight: z.number().min(-1).max(1).refine((value) => value !== 0, {
13301
+ message: "Evidence impact weight must be nonzero."
13302
+ }).describe("Required signed impact score from -1.0 to +1.0 for this belief."),
13240
13303
  rationale: z.string().optional().describe("Why this relation exists.")
13241
13304
  });
13242
13305
  var createEvidenceArgs = z.object({
@@ -13245,7 +13308,7 @@ var createEvidenceArgs = z.object({
13245
13308
  source: z.string().optional().describe("Source URL or source label."),
13246
13309
  sourceUrl: z.string().optional().describe("Canonical source URL."),
13247
13310
  targetId: z.string().optional().describe(
13248
- "Belief, question, or worktree identifier to link or preserve on the evidence record. Belief targets require evidenceRelation or a nonzero signed weight."
13311
+ "Belief identifier to link immediately. Evidence creation cannot target only a question or worktree."
13249
13312
  ),
13250
13313
  linkedBeliefNodeId: z.string().optional().describe("Belief node this evidence bears on."),
13251
13314
  evidenceRelation: evidenceRelationSchema2.optional().describe(
@@ -13254,8 +13317,14 @@ var createEvidenceArgs = z.object({
13254
13317
  beliefRelations: z.array(beliefRelationSchema2).optional().describe(
13255
13318
  "Additional belief relations for one evidence record. Use when the same evidence supports or contradicts multiple beliefs."
13256
13319
  ),
13257
- confidence: z.number().optional().describe("Confidence in the evidence relation."),
13258
- weight: z.number().optional().describe("Nonzero support weight from -1.0 to +1.0."),
13320
+ confidence: z.number().optional().describe(
13321
+ "Deprecated hint. Runtime confidence is derived from signed weight."
13322
+ ),
13323
+ weight: z.number().min(-1).max(1).refine((value) => value !== 0, {
13324
+ message: "Evidence impact weight must be nonzero."
13325
+ }).describe(
13326
+ "Required signed impact score from -1.0 to +1.0 for targetId/linkedBeliefNodeId."
13327
+ ),
13259
13328
  metadata: jsonRecordSchema4.optional().describe("Metadata merged into the canonical evidence node."),
13260
13329
  rationale: z.string().describe("Why this evidence should enter the reasoning graph."),
13261
13330
  reasoning: z.string().optional().describe("Reasoning note preserved in evidence metadata."),
@@ -13277,7 +13346,9 @@ var addEvidenceArgs = z.object({
13277
13346
  topicId: z.string().optional().describe("Topic scope hint."),
13278
13347
  sourceUrl: z.string().optional().describe("URL of the source material."),
13279
13348
  targetNodeId: z.string().describe("The belief this evidence bears on."),
13280
- weight: z.number().optional().describe("Support weight from -1.0 to +1.0."),
13349
+ weight: z.number().min(-1).max(1).refine((value) => value !== 0, {
13350
+ message: "Evidence impact weight must be nonzero."
13351
+ }).describe("Required signed impact score from -1.0 to +1.0."),
13281
13352
  reasoning: z.string().describe("Why this evidence is relevant to the target belief."),
13282
13353
  title: z.string().optional().describe("Optional short title."),
13283
13354
  content: z.string().optional().describe("Optional long-form evidence content."),
@@ -13297,19 +13368,21 @@ var createEvidenceInput = (input, context) => {
13297
13368
  );
13298
13369
  };
13299
13370
  function relationWeight(input) {
13300
- if (typeof input.weight === "number" && Number.isFinite(input.weight) && input.weight !== 0) {
13371
+ if (typeof input.weight === "number" && Number.isFinite(input.weight) && input.weight !== 0 && input.weight >= -1 && input.weight <= 1) {
13372
+ const relation = String(
13373
+ input.evidenceRelation ?? input.relation ?? input.type ?? ""
13374
+ );
13375
+ if ((relation === "supports" || relation === "supporting") && input.weight < 0) {
13376
+ throw new Error("Supporting evidence links require positive weight.");
13377
+ }
13378
+ if ((relation === "contradicts" || relation === "contradicting") && input.weight > 0) {
13379
+ throw new Error("Contradicting evidence links require negative weight.");
13380
+ }
13301
13381
  return input.weight;
13302
13382
  }
13303
- const relation = String(
13304
- input.evidenceRelation ?? input.relation ?? input.type ?? ""
13383
+ throw new Error(
13384
+ "Belief evidence links require explicit nonzero weight in [-1, 1]."
13305
13385
  );
13306
- if (relation !== "supports" && relation !== "supporting" && relation !== "contradicts" && relation !== "contradicting") {
13307
- throw new Error(
13308
- "Belief evidence links require evidenceRelation='supports'|'contradicts' or a nonzero signed weight."
13309
- );
13310
- }
13311
- const confidence = typeof input.confidence === "number" ? Math.max(0, Math.min(1, input.confidence)) : 0.7;
13312
- return relation === "contradicts" || relation === "contradicting" ? -confidence : confidence;
13313
13386
  }
13314
13387
  var linkEvidenceToBeliefInput = (input, context) => {
13315
13388
  const weight = relationWeight(input);
@@ -13318,6 +13391,7 @@ var linkEvidenceToBeliefInput = (input, context) => {
13318
13391
  beliefNodeId: input.beliefNodeId ?? input.beliefId ?? input.targetId,
13319
13392
  insightId: input.insightId ?? input.evidenceNodeId ?? input.evidenceId,
13320
13393
  type: weight < 0 ? "contradicting" : "supporting",
13394
+ weight,
13321
13395
  confidence: Math.min(1, Math.abs(weight)),
13322
13396
  rationale: input.rationale ?? input.context,
13323
13397
  trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
@@ -13394,7 +13468,12 @@ var evidenceContracts = [
13394
13468
  functionName: "create",
13395
13469
  kind: "mutation",
13396
13470
  inputProjection: (input, context) => {
13397
- const weight = typeof input.weight === "number" ? input.weight : 0.7;
13471
+ if (typeof input.weight !== "number" || !Number.isFinite(input.weight) || input.weight === 0 || input.weight < -1 || input.weight > 1) {
13472
+ throw new Error(
13473
+ "add_evidence requires explicit nonzero weight in [-1, 1]."
13474
+ );
13475
+ }
13476
+ const weight = input.weight;
13398
13477
  return createEvidenceInput(
13399
13478
  {
13400
13479
  ...input,
@@ -13403,6 +13482,7 @@ var evidenceContracts = [
13403
13482
  linkedBeliefNodeId: input.linkedBeliefNodeId ?? input.targetNodeId ?? input.targetId,
13404
13483
  evidenceRelation: weight < 0 ? "contradicts" : "supports",
13405
13484
  confidence: Math.min(1, Math.max(0, Math.abs(weight))),
13485
+ weight,
13406
13486
  rationale: input.reasoning,
13407
13487
  metadata: {
13408
13488
  ...recordValue2(input.metadata),