@lucern/events 1.0.16 → 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.
package/dist/index.js CHANGED
@@ -60,7 +60,7 @@ var REASONING_METHODS = [
60
60
  // ../contracts/src/tool-contracts.graph.ts
61
61
  var QUERY_LINEAGE = {
62
62
  name: "query_lineage",
63
- 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).",
63
+ 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).",
64
64
  parameters: {
65
65
  nodeId: { type: "string", description: "Starting node to trace from" },
66
66
  depth: {
@@ -259,7 +259,7 @@ var FIND_CONTRADICTIONS = {
259
259
  };
260
260
  var BISECT_CONFIDENCE = {
261
261
  name: "bisect_confidence",
262
- 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.",
262
+ 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.",
263
263
  parameters: {
264
264
  nodeId: { type: "string", description: "The belief to bisect" },
265
265
  expectedDirection: {
@@ -278,7 +278,7 @@ var BISECT_CONFIDENCE = {
278
278
  fields: {
279
279
  beliefId: "string \u2014 canonical belief ID",
280
280
  expectedDirection: "string \u2014 overconfident | underconfident",
281
- inflectionEntry: "object \u2014 the confidence modulation where divergence began",
281
+ inflectionEntry: "object \u2014 the scoring event where divergence began",
282
282
  triggerEvent: "string | null \u2014 what caused the divergence",
283
283
  confidenceBefore: "number | null",
284
284
  confidenceAfter: "number | null",
@@ -572,18 +572,18 @@ var SEARCH_EVIDENCE = {
572
572
  };
573
573
  var CREATE_EVIDENCE = {
574
574
  name: "create_evidence",
575
- 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.",
575
+ 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.",
576
576
  parameters: {
577
577
  topicId: { type: "string", description: "Topic scope" },
578
578
  text: { type: "string", description: "Canonical evidence text" },
579
579
  source: { type: "string", description: "Source URL or source label" },
580
580
  targetId: {
581
581
  type: "string",
582
- description: "Optional belief or question identifier to link immediately"
582
+ description: "Belief identifier to link immediately"
583
583
  },
584
584
  weight: {
585
585
  type: "number",
586
- description: "Optional support weight: -1.0 (contradicts) to +1.0 (supports). If omitted, evidenceRelation + confidence determine the weight."
586
+ description: "Required nonzero signed impact score: -1.0 (contradicts) to +1.0 (supports)."
587
587
  },
588
588
  evidenceRelation: {
589
589
  type: "string",
@@ -592,7 +592,7 @@ var CREATE_EVIDENCE = {
592
592
  },
593
593
  confidence: {
594
594
  type: "number",
595
- description: "Confidence in the evidence relation, 0.0 to 1.0"
595
+ description: "Deprecated hint. Runtime confidence is derived from the signed impact score."
596
596
  },
597
597
  beliefRelations: {
598
598
  type: "array",
@@ -614,7 +614,7 @@ var CREATE_EVIDENCE = {
614
614
  },
615
615
  kind: { type: "string", description: "Optional evidence kind" }
616
616
  },
617
- required: ["text", "rationale"],
617
+ required: ["text", "rationale", "weight"],
618
618
  response: {
619
619
  description: "The created canonical evidence record",
620
620
  fields: {
@@ -689,7 +689,7 @@ var LINK_EVIDENCE = {
689
689
  },
690
690
  rationale: { type: "string", description: "Why this link exists" }
691
691
  },
692
- required: ["evidenceId", "targetId"],
692
+ required: ["evidenceId", "targetId", "weight"],
693
693
  response: {
694
694
  description: "The created canonical evidence edge summary",
695
695
  fields: {
@@ -725,7 +725,7 @@ var LINK_EVIDENCE_TO_BELIEF = {
725
725
  },
726
726
  rationale: { type: "string", description: "Why this evidence is relevant" }
727
727
  },
728
- required: ["evidenceId", "beliefId"],
728
+ required: ["evidenceId", "beliefId", "weight"],
729
729
  response: {
730
730
  description: "The created edge linking evidence to belief",
731
731
  fields: {
@@ -743,15 +743,23 @@ var LINK_EVIDENCE_TO_BELIEF = {
743
743
  // ../contracts/src/tool-contracts.lifecycle.ts
744
744
  var CREATE_BELIEF = {
745
745
  name: "create_belief",
746
- 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.",
746
+ 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.",
747
747
  parameters: {
748
748
  canonicalText: {
749
749
  type: "string",
750
750
  description: "The belief statement \u2014 what the agent holds to be true"
751
751
  },
752
+ topicGlobalId: {
753
+ type: "string",
754
+ description: "Required globalId (UUID) of the topic node in epistemicNodes that anchors the belief"
755
+ },
756
+ topicNodeId: {
757
+ type: "string",
758
+ description: "Optional internal epistemicNodes _id for the topic anchor. Prefer topicGlobalId for public callers."
759
+ },
752
760
  topicId: {
753
761
  type: "string",
754
- description: "Optional topic scope hint for the belief"
762
+ description: "Deprecated compatibility alias for topicGlobalId. Must identify a topic epistemicNode, not a legacy topics-table row."
755
763
  },
756
764
  baseRate: {
757
765
  type: "number",
@@ -766,7 +774,7 @@ var CREATE_BELIEF = {
766
774
  description: "Optional extra metadata merged into the node (e.g., { codeAnchors: ['path/to/file.ts'] } for coding intelligence)"
767
775
  }
768
776
  },
769
- required: ["canonicalText"],
777
+ required: ["canonicalText", "topicGlobalId"],
770
778
  response: {
771
779
  description: "The created canonical belief record",
772
780
  fields: {
@@ -775,7 +783,7 @@ var CREATE_BELIEF = {
775
783
  beliefId: "string \u2014 canonical belief ID",
776
784
  text: "string \u2014 canonical belief formulation",
777
785
  topicId: "string",
778
- status: "string \u2014 active | superseded | archived",
786
+ beliefStatus: "string \u2014 assumption | hypothesis | active | superseded | resolved_true | resolved_false",
779
787
  scoringState: "string \u2014 unscored | scored"
780
788
  }
781
789
  },
@@ -798,7 +806,7 @@ var GET_BELIEF = {
798
806
  beliefId: "string \u2014 canonical belief ID",
799
807
  text: "string \u2014 canonical belief formulation",
800
808
  topicId: "string",
801
- status: "string \u2014 active | superseded | archived",
809
+ beliefStatus: "string \u2014 assumption | hypothesis | active | superseded | resolved_true | resolved_false",
802
810
  scoringState: "string \u2014 unscored | scored"
803
811
  }
804
812
  },
@@ -827,34 +835,24 @@ var REFINE_BELIEF = {
827
835
  ontologyPrimitive: "belief",
828
836
  tier: "showcase"
829
837
  };
830
- var MODULATE_CONFIDENCE = {
831
- name: "modulate_confidence",
832
- 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.",
838
+ var APPEND_SL_SCORING = {
839
+ name: "append_sl_scoring",
840
+ 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.",
833
841
  parameters: {
834
- nodeId: { type: "string", description: "The belief to score" },
835
- belief: {
836
- type: "number",
837
- description: "Subjective-logic belief mass `b` in [0, 1]"
838
- },
842
+ nodeId: { type: "string", description: "The belief receiving the SL score" },
843
+ belief: { type: "number", description: "Subjective Logic belief mass b" },
839
844
  disbelief: {
840
845
  type: "number",
841
- description: "Subjective-logic disbelief mass `d` in [0, 1]"
846
+ description: "Subjective Logic disbelief mass d"
842
847
  },
843
848
  uncertainty: {
844
849
  type: "number",
845
- description: "Subjective-logic uncertainty mass `u` in [0, 1]"
846
- },
847
- baseRate: {
848
- type: "number",
849
- description: "Subjective-logic base rate `a` in [0, 1]. Required for tuple payloads."
850
- },
851
- worktreeId: {
852
- type: "string",
853
- description: "Completed worktree that tested this belief when confidence policy requires merge-backed scoring."
850
+ description: "Subjective Logic uncertainty mass u"
854
851
  },
852
+ baseRate: { type: "number", description: "Subjective Logic base rate a" },
855
853
  trigger: {
856
854
  type: "string",
857
- description: "What caused this confidence change",
855
+ description: "Evidence-bearing cause of the scoring event",
858
856
  enum: [
859
857
  "evidence_added",
860
858
  "evidence_removed",
@@ -865,64 +863,39 @@ var MODULATE_CONFIDENCE = {
865
863
  "worktree_completed",
866
864
  "fusion",
867
865
  "discount",
868
- "deduction"
866
+ "deduction",
867
+ "backfill_synthetic"
869
868
  ]
870
869
  },
871
- triggeringEvidenceId: {
872
- type: "string",
873
- description: "Evidence node that caused an evidence-triggered modulation"
874
- },
875
- triggeringQuestionId: {
876
- type: "string",
877
- description: "Answered question whose resolution supports this modulation"
878
- },
879
- triggeringAnswerId: {
880
- type: "string",
881
- description: "Answer node whose content supports this modulation"
882
- },
883
- triggeringContradictionId: {
884
- type: "string",
885
- description: "Contradiction record that caused a contradiction-triggered modulation"
886
- },
887
- triggeringWorktreeId: {
888
- type: "string",
889
- description: "Completed worktree whose outcome caused a worktree-triggered modulation"
870
+ provenance: {
871
+ type: "object",
872
+ description: "At least one of evidence, question, answer, contradiction, or worktree."
890
873
  },
891
874
  rationale: {
892
875
  type: "string",
893
- description: "Human-readable explanation of why confidence changed"
876
+ description: "Why this evidence-bearing event moved the SL tuple"
894
877
  }
895
878
  },
896
- required: [
897
- "nodeId",
898
- "belief",
899
- "disbelief",
900
- "uncertainty",
901
- "baseRate",
902
- "trigger",
903
- "rationale"
904
- ],
879
+ required: ["nodeId", "belief", "disbelief", "uncertainty", "baseRate", "trigger", "rationale"],
905
880
  response: {
906
- description: "Confidence modulation result",
881
+ description: "Internal SL scoring append receipt",
907
882
  fields: {
908
- beliefId: "string \u2014 canonical belief ID",
909
- nodeId: "string \u2014 canonical belief ID",
910
- newConfidence: "number",
883
+ nodeId: "string",
911
884
  previousConfidence: "number",
912
- trigger: "string",
913
- requestId: "string \u2014 request identifier for the scheduled cascade",
914
- propagationSummary: "object \u2014 bounded inline cascade summary with totalCandidateTargets, inlineTargets, and remainingTargetCount"
885
+ newConfidence: "number",
886
+ beliefConfidenceId: "string"
915
887
  }
916
888
  },
917
889
  ownerModule: "graph-primitives",
918
890
  ontologyPrimitive: "belief",
919
- tier: "showcase"
891
+ tier: "workhorse",
892
+ internal: true
920
893
  };
921
894
  var FORK_BELIEF = {
922
895
  name: "fork_belief",
923
- 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.",
896
+ 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.",
924
897
  parameters: {
925
- nodeId: { type: "string", description: "The scored belief to fork from" },
898
+ nodeId: { type: "string", description: "The belief to fork from" },
926
899
  newFormulation: {
927
900
  type: "string",
928
901
  description: "The evolved belief statement"
@@ -934,12 +907,20 @@ var FORK_BELIEF = {
934
907
  "refinement",
935
908
  "contradiction_response",
936
909
  "scope_change",
937
- "confidence_collapse",
938
- "manual"
910
+ "confidence_collapse"
939
911
  ]
912
+ },
913
+ forkMode: {
914
+ type: "string",
915
+ description: "supersede replaces the parent; branch creates a child while preserving the parent.",
916
+ enum: ["supersede", "branch"]
917
+ },
918
+ triggeringEvidenceId: {
919
+ type: "string",
920
+ description: "Evidence already attached to the parent belief that caused the fork."
940
921
  }
941
922
  },
942
- required: ["nodeId", "newFormulation", "forkReason"],
923
+ required: ["nodeId", "newFormulation", "forkReason", "triggeringEvidenceId"],
943
924
  response: {
944
925
  description: "The forked canonical belief record",
945
926
  fields: {
@@ -2204,7 +2185,7 @@ var TRIGGER_BELIEF_REVIEW = {
2204
2185
  };
2205
2186
  var EVALUATE_CONTRACT = {
2206
2187
  name: "evaluate_contract",
2207
- 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.",
2188
+ 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.",
2208
2189
  parameters: {
2209
2190
  contractId: { type: "string", description: "Which contract to evaluate" },
2210
2191
  trigger: {
@@ -4095,6 +4076,11 @@ var COMPILE_CONTEXT = {
4095
4076
  response: {
4096
4077
  description: "Compiled context pack for the requested topic",
4097
4078
  fields: {
4079
+ contextNarrative: "array \u2014 first field; ordered synthesis blocks with kind/text, starting with executive_summary and canonical narrative blocks before raw objects",
4080
+ narrativeCoverage: "object \u2014 recordsSynthesized, recordsNamed, recordsOmitted, topicsSynthesized, topicsEnriched, topicContentOmitted, enrichmentMode, and blocksEmitted for the narrative",
4081
+ synthesisLints: "array \u2014 inline quality warnings for degenerate synthesis blocks or weak narrative coverage",
4082
+ retrievalReceipt: "object \u2014 candidateCounts, coverageWarning, narrativeCoverage, synthesisLints, and suggestedNextActions",
4083
+ supportingObjects: "object \u2014 raw graph records grouped behind the synthesis: invariants, activeBeliefs, openQuestions, recentEvidence, worktrees, lanes, entities, and contradictions",
4098
4084
  schemaVersion: "string",
4099
4085
  topicId: "string",
4100
4086
  topicName: "string",
@@ -4102,15 +4088,6 @@ var COMPILE_CONTEXT = {
4102
4088
  generatedAt: "number \u2014 deterministic graph-backed reference timestamp for this compilation",
4103
4089
  ranking: "string \u2014 baseline_v1 | weighted_v1",
4104
4090
  summary: "object \u2014 counts and scoped health signals",
4105
- invariants: "array \u2014 high-confidence invariant beliefs",
4106
- activeBeliefs: "array \u2014 current high-signal beliefs",
4107
- openQuestions: "array \u2014 unresolved questions ranked for this query",
4108
- recentEvidence: "array \u2014 recent evidence ranked for this query",
4109
- contradictions: "array \u2014 unresolved contradiction records",
4110
- relatedEntities: "array | undefined \u2014 ranked ontological entities in scope",
4111
- contextNarrative: "array \u2014 ordered synthesis blocks with kind/text, starting with executive_summary and canonical narrative blocks before raw objects",
4112
- retrievalReceipt: "object \u2014 candidateCounts, coverageWarning, narrativeCoverage, synthesisLints, and suggestedNextActions",
4113
- narrativeCoverage: "object \u2014 recordsSynthesized, recordsNamed, recordsOmitted, topicsSynthesized, topicsEnriched, topicContentOmitted, enrichmentMode, and blocksEmitted for the narrative",
4114
4091
  injectionPolicy: "object \u2014 token-budgeted section selections",
4115
4092
  diagnostics: "object \u2014 scoring and utilization telemetry"
4116
4093
  }
@@ -4669,7 +4646,7 @@ var MCP_TOOL_CONTRACTS = {
4669
4646
  create_belief: CREATE_BELIEF,
4670
4647
  get_belief: GET_BELIEF,
4671
4648
  refine_belief: REFINE_BELIEF,
4672
- modulate_confidence: MODULATE_CONFIDENCE,
4649
+ append_sl_scoring: APPEND_SL_SCORING,
4673
4650
  fork_belief: FORK_BELIEF,
4674
4651
  archive_belief: ARCHIVE_BELIEF,
4675
4652
  create_epistemic_contract: CREATE_EPISTEMIC_CONTRACT,
@@ -6467,8 +6444,10 @@ defineTable({
6467
6444
  "beliefStatus": z.object({
6468
6445
  "assumption": z.number(),
6469
6446
  "hypothesis": z.number(),
6470
- "belief": z.number(),
6471
- "fact": z.number()
6447
+ "active": z.number(),
6448
+ "superseded": z.number(),
6449
+ "resolved_true": z.number(),
6450
+ "resolved_false": z.number()
6472
6451
  }).optional(),
6473
6452
  "evidenceTemporalNature": z.object({
6474
6453
  "factual": z.number(),
@@ -6690,8 +6669,8 @@ defineTable({
6690
6669
  "exportClass": z.enum(["internal_only", "client_safe", "public_safe", "restricted"]).optional(),
6691
6670
  "anonymizationClass": z.enum(["none", "standard", "strict"]).optional(),
6692
6671
  "beliefType": z.string().optional(),
6693
- "beliefStatus": z.enum(["assumption", "hypothesis", "belief", "fact"]).optional(),
6694
- "epistemicStatus": z.enum(["hypothesis", "emerging", "established", "challenged", "assumption", "deprecated"]).optional(),
6672
+ "beliefStatus": z.enum(["assumption", "hypothesis", "active", "superseded", "resolved_true", "resolved_false"]).optional(),
6673
+ "epistemicStatus": z.enum(["assumption", "hypothesis", "active", "superseded", "resolved_true", "resolved_false"]).optional(),
6695
6674
  "reversibility": z.enum(["irreversible", "hard_to_reverse", "reversible", "trivial"]).optional(),
6696
6675
  "predictionMeta": z.object({
6697
6676
  "isPrediction": z.boolean(),
@@ -11787,11 +11766,39 @@ var createEvidenceInputSchemaBase = z.object({
11787
11766
  metadata: jsonRecordSchema.optional(),
11788
11767
  trustedBypassAccessCheck: z.boolean().optional()
11789
11768
  }).passthrough();
11790
- function hasNonzeroWeight(value) {
11791
- return typeof value === "number" && Number.isFinite(value) && value !== 0;
11769
+ function isSignedImpactScore(value) {
11770
+ return typeof value === "number" && Number.isFinite(value) && value >= -1 && value <= 1 && value !== 0;
11792
11771
  }
11793
- function hasRelationSignal(value, weight) {
11794
- return Boolean(normalizeRelation(value, weight));
11772
+ function validateSignedImpactScore(value, ctx, path) {
11773
+ if (!isSignedImpactScore(value)) {
11774
+ ctx.addIssue({
11775
+ code: z.ZodIssueCode.custom,
11776
+ message: "evidence-to-belief links require an explicit nonzero signed impact score in [-1, 1]",
11777
+ path
11778
+ });
11779
+ return false;
11780
+ }
11781
+ return true;
11782
+ }
11783
+ function validateRelationImpactConsistency(relation, weight, ctx, path) {
11784
+ const normalized = normalizeRelationAlias(relation);
11785
+ if (!normalized || !isSignedImpactScore(weight)) {
11786
+ return;
11787
+ }
11788
+ if (normalized === "supports" && weight < 0) {
11789
+ ctx.addIssue({
11790
+ code: z.ZodIssueCode.custom,
11791
+ message: "supporting evidence requires a positive impact score",
11792
+ path
11793
+ });
11794
+ }
11795
+ if (normalized === "contradicts" && weight > 0) {
11796
+ ctx.addIssue({
11797
+ code: z.ZodIssueCode.custom,
11798
+ message: "contradicting evidence requires a negative impact score",
11799
+ path
11800
+ });
11801
+ }
11795
11802
  }
11796
11803
  var createEvidenceInputSchema = createEvidenceInputSchemaBase.superRefine(
11797
11804
  (input, ctx) => {
@@ -11808,13 +11815,27 @@ var createEvidenceInputSchema = createEvidenceInputSchemaBase.superRefine(
11808
11815
  input.linkedBeliefNodeId || kind === "belief" || kind === "unknown" && target
11809
11816
  );
11810
11817
  const weight = typeof input.weight === "number" ? input.weight : void 0;
11811
- if (linksPrimaryBelief && !hasRelationSignal(input.evidenceRelation, weight)) {
11818
+ const hasBeliefRelations = (input.beliefRelations?.length ?? 0) > 0;
11819
+ if (!linksPrimaryBelief && !hasBeliefRelations) {
11820
+ ctx.addIssue({
11821
+ code: z.ZodIssueCode.custom,
11822
+ message: "create_evidence requires at least one linked belief; evidence cannot be created as an orphan or linked only to a question/worktree",
11823
+ path: ["linkedBeliefNodeId"]
11824
+ });
11825
+ }
11826
+ if (kind === "question" || kind === "worktree") {
11812
11827
  ctx.addIssue({
11813
11828
  code: z.ZodIssueCode.custom,
11814
- message: "belief-targeted evidence requires evidenceRelation='supports'|'contradicts' or a nonzero signed weight",
11815
- path: ["evidenceRelation"]
11829
+ message: "create_evidence targetId must be a belief. Link evidence to questions/worktrees only after the evidence has a belief impact edge.",
11830
+ path: ["targetId"]
11816
11831
  });
11817
11832
  }
11833
+ if (linksPrimaryBelief) {
11834
+ validateSignedImpactScore(weight, ctx, ["weight"]);
11835
+ validateRelationImpactConsistency(input.evidenceRelation, weight, ctx, [
11836
+ "weight"
11837
+ ]);
11838
+ }
11818
11839
  input.beliefRelations?.forEach((relation, index) => {
11819
11840
  const beliefNodeId = relation.beliefNodeId ?? relation.beliefId ?? relation.targetId;
11820
11841
  if (!beliefNodeId) {
@@ -11825,15 +11846,18 @@ var createEvidenceInputSchema = createEvidenceInputSchemaBase.superRefine(
11825
11846
  });
11826
11847
  }
11827
11848
  const relationWeight2 = typeof relation.weight === "number" ? relation.weight : void 0;
11828
- if (beliefNodeId && !hasRelationSignal(
11829
- relation.evidenceRelation ?? relation.relation,
11830
- relationWeight2
11831
- )) {
11832
- ctx.addIssue({
11833
- code: z.ZodIssueCode.custom,
11834
- message: "beliefRelations entries require evidenceRelation='supports'|'contradicts' or a nonzero signed weight",
11835
- path: ["beliefRelations", index, "evidenceRelation"]
11836
- });
11849
+ if (beliefNodeId) {
11850
+ validateSignedImpactScore(relationWeight2, ctx, [
11851
+ "beliefRelations",
11852
+ index,
11853
+ "weight"
11854
+ ]);
11855
+ validateRelationImpactConsistency(
11856
+ relation.evidenceRelation ?? relation.relation,
11857
+ relationWeight2,
11858
+ ctx,
11859
+ ["beliefRelations", index, "weight"]
11860
+ );
11837
11861
  }
11838
11862
  });
11839
11863
  }
@@ -11887,18 +11911,28 @@ function targetKind(targetId) {
11887
11911
  }
11888
11912
  return "unknown";
11889
11913
  }
11890
- function normalizeRelation(value, weight) {
11914
+ function normalizeRelationAlias(value) {
11891
11915
  if (value === "supports" || value === "supporting") {
11892
11916
  return "supports";
11893
11917
  }
11894
11918
  if (value === "contradicts" || value === "contradicting") {
11895
11919
  return "contradicts";
11896
11920
  }
11921
+ return void 0;
11922
+ }
11923
+ function normalizeRelation(value, weight) {
11924
+ const alias = normalizeRelationAlias(value);
11925
+ if (alias) {
11926
+ return alias;
11927
+ }
11897
11928
  if (weight === void 0 || !hasNonzeroWeight(weight)) {
11898
11929
  return void 0;
11899
11930
  }
11900
11931
  return weight < 0 ? "contradicts" : "supports";
11901
11932
  }
11933
+ function hasNonzeroWeight(value) {
11934
+ return typeof value === "number" && Number.isFinite(value) && value !== 0;
11935
+ }
11902
11936
  function normalizeConfidence(confidence, weight) {
11903
11937
  if (confidence !== void 0) {
11904
11938
  return Math.min(1, Math.max(0, confidence));
@@ -11925,6 +11959,7 @@ function normalizeBeliefRelation(relation) {
11925
11959
  beliefNodeId,
11926
11960
  relation: evidenceRelation,
11927
11961
  confidence: normalizeConfidence(relation.confidence, weight),
11962
+ weight,
11928
11963
  rationale: relation.rationale
11929
11964
  });
11930
11965
  }
@@ -11973,6 +12008,7 @@ var createEvidenceProjection = defineProjection({
11973
12008
  linkedBeliefNodeId,
11974
12009
  evidenceRelation,
11975
12010
  confidence,
12011
+ weight,
11976
12012
  beliefRelations: beliefRelations && beliefRelations.length > 0 ? beliefRelations : void 0,
11977
12013
  rationale: input.rationale,
11978
12014
  trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
@@ -12002,12 +12038,14 @@ var createEvidenceProjection = defineProjection({
12002
12038
  v.literal("contradicts")
12003
12039
  )
12004
12040
  ),
12041
+ weight: v.optional(v.number()),
12005
12042
  beliefRelations: v.optional(
12006
12043
  v.array(
12007
12044
  v.object({
12008
12045
  beliefNodeId: v.string(),
12009
12046
  relation: v.union(v.literal("supports"), v.literal("contradicts")),
12010
12047
  confidence: v.optional(v.number()),
12048
+ weight: v.number(),
12011
12049
  rationale: v.optional(v.string())
12012
12050
  })
12013
12051
  )
@@ -12125,7 +12163,7 @@ var slOpinionProjectionSchema = z.object({
12125
12163
  uncertainty: z.number(),
12126
12164
  baseRate: z.number()
12127
12165
  });
12128
- var modulateConfidenceInputObjectSchema = z.object({
12166
+ var appendSlScoringInputObjectSchema = z.object({
12129
12167
  nodeId: z.string().optional(),
12130
12168
  beliefNodeId: z.string().optional(),
12131
12169
  worktreeId: z.string().optional(),
@@ -12144,23 +12182,23 @@ var modulateConfidenceInputObjectSchema = z.object({
12144
12182
  rationale: z.string(),
12145
12183
  trustedBypassAccessCheck: z.boolean().optional()
12146
12184
  });
12147
- var modulateConfidenceInputSchema = modulateConfidenceInputObjectSchema.superRefine((input, ctx) => {
12185
+ var appendSlScoringInputSchema = appendSlScoringInputObjectSchema.superRefine((input, ctx) => {
12148
12186
  if (hasProvenance(input)) {
12149
12187
  return;
12150
12188
  }
12151
12189
  ctx.addIssue({
12152
12190
  code: z.ZodIssueCode.custom,
12153
- message: "modulate_confidence requires evidence, question, answer, contradiction, or worktree provenance",
12191
+ message: "append_sl_scoring requires evidence, question, answer, contradiction, or worktree provenance",
12154
12192
  path: ["provenance"]
12155
12193
  });
12156
12194
  });
12157
- var modulateConfidenceProjection = defineProjection({
12158
- contractName: "modulate_confidence",
12159
- inputSchema: modulateConfidenceInputSchema,
12195
+ var appendSlScoringProjection = defineProjection({
12196
+ contractName: "append_sl_scoring",
12197
+ inputSchema: appendSlScoringInputSchema,
12160
12198
  project: (input) => {
12161
12199
  const nodeId = input.beliefNodeId ?? input.nodeId;
12162
12200
  if (!nodeId) {
12163
- throw new Error("modulate_confidence requires beliefNodeId or nodeId");
12201
+ throw new Error("append_sl_scoring requires beliefNodeId or nodeId");
12164
12202
  }
12165
12203
  const opinion = input.opinion ?? {
12166
12204
  belief: requireNumber(input.belief, "belief"),
@@ -12217,14 +12255,14 @@ var modulateConfidenceProjection = defineProjection({
12217
12255
  });
12218
12256
  function requireNumber(value, field) {
12219
12257
  if (value === void 0) {
12220
- throw new Error(`modulate_confidence requires ${field}`);
12258
+ throw new Error(`append_sl_scoring requires ${field}`);
12221
12259
  }
12222
12260
  return value;
12223
12261
  }
12224
12262
  function assertProvenance(input) {
12225
12263
  if (!hasProvenance(input)) {
12226
12264
  throw new Error(
12227
- "modulate_confidence requires evidence, question, answer, contradiction, or worktree provenance"
12265
+ "append_sl_scoring requires evidence, question, answer, contradiction, or worktree provenance"
12228
12266
  );
12229
12267
  }
12230
12268
  }
@@ -12567,12 +12605,12 @@ var LUCERN_OPERATION_MANIFEST = {
12567
12605
  internalSystem,
12568
12606
  "Lucern system/background operation. Available to platform code paths, hidden from public MCP discovery."
12569
12607
  ),
12570
- modulate_confidence: {
12571
- name: "modulate_confidence",
12608
+ append_sl_scoring: {
12609
+ name: "append_sl_scoring",
12572
12610
  surfaceClass: "platform_internal",
12573
12611
  surfaceIntent: "system",
12574
12612
  surfaces: internalSdkRestOnly,
12575
- rationale: "Internal SL ledger append primitive. Public callers attach evidence or contradiction relations; confidence is derived algorithmically."
12613
+ rationale: "Internal SL scoring append primitive. Public callers attach evidence or contradiction relations; confidence is derived algorithmically."
12576
12614
  },
12577
12615
  ...entries(
12578
12616
  LEGACY_COMPAT_OPERATION_NAMES,
@@ -13126,7 +13164,15 @@ var predictionMetaSchema = z.object({
13126
13164
  });
13127
13165
  var createBeliefArgs = z.object({
13128
13166
  canonicalText: z.string().describe("The belief statement the agent holds to be true."),
13129
- topicId: z.string().optional().describe("Topic scope hint for the belief."),
13167
+ topicGlobalId: z.string().describe(
13168
+ "Required globalId of the topic epistemicNode that anchors this belief. Belief creation creates a scoped_by edge directly to that topic node."
13169
+ ),
13170
+ topicNodeId: z.string().optional().describe(
13171
+ "Optional internal epistemicNodes _id for the topic anchor. Prefer topicGlobalId for public callers."
13172
+ ),
13173
+ topicId: z.string().optional().describe(
13174
+ "Deprecated compatibility alias for topicGlobalId. Must identify a topic epistemicNode, not a legacy topics-table row."
13175
+ ),
13130
13176
  baseRate: z.number().optional().describe("Prior base rate used to seed the vacuous opinion."),
13131
13177
  beliefType: z.string().optional().describe("Schema belief type."),
13132
13178
  metadata: jsonRecordSchema3.optional().describe("Extra metadata merged into the belief node."),
@@ -13145,9 +13191,14 @@ var forkBeliefArgs = z.object({
13145
13191
  "refinement",
13146
13192
  "contradiction_response",
13147
13193
  "scope_change",
13148
- "confidence_collapse",
13149
- "manual"
13194
+ "confidence_collapse"
13150
13195
  ]).describe("Why this fork was created."),
13196
+ forkMode: z.enum(["supersede", "branch"]).optional().describe(
13197
+ "supersede marks the parent belief superseded; branch preserves the parent and creates a derived child."
13198
+ ),
13199
+ triggeringEvidenceId: z.string().describe(
13200
+ "Evidence already attached to the parent belief through SL scoring; required for every fork."
13201
+ ),
13151
13202
  rationale: z.string().optional().describe("Why the fork is warranted.")
13152
13203
  });
13153
13204
  var beliefLookupInput = (input) => compactRecord4({
@@ -13161,7 +13212,9 @@ var createBeliefInput = (input, context) => {
13161
13212
  return withUserId(
13162
13213
  compactRecord4({
13163
13214
  projectId: input.projectId,
13164
- topicId: input.topicId,
13215
+ topicId: input.topicGlobalId ?? input.topicNodeId ?? input.topicId,
13216
+ topicGlobalId: input.topicGlobalId,
13217
+ topicNodeId: input.topicNodeId,
13165
13218
  formulation: input.formulation ?? input.canonicalText,
13166
13219
  beliefType: input.beliefType,
13167
13220
  rationale: input.rationale,
@@ -13183,20 +13236,22 @@ var forkBeliefInput = (input, context) => withUserId(
13183
13236
  parentNodeId: input.parentNodeId ?? input.nodeId ?? input.id,
13184
13237
  newFormulation: input.newFormulation,
13185
13238
  forkReason: input.forkReason,
13239
+ forkMode: input.forkMode,
13240
+ triggeringEvidenceId: input.triggeringEvidenceId,
13186
13241
  rationale: input.rationale,
13187
13242
  trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
13188
13243
  }),
13189
13244
  context
13190
13245
  );
13191
- var confidenceInput = (input, context) => {
13192
- const parsed = modulateConfidenceProjection.inputSchema.safeParse(input);
13246
+ var appendSlScoringInput = (input, context) => {
13247
+ const parsed = appendSlScoringProjection.inputSchema.safeParse(input);
13193
13248
  if (!parsed.success) {
13194
13249
  throw new Error(
13195
- `modulate_confidence projection input rejected: ${parsed.error.message}`
13250
+ `append_sl_scoring projection input rejected: ${parsed.error.message}`
13196
13251
  );
13197
13252
  }
13198
13253
  return withUserId(
13199
- compactRecord4(modulateConfidenceProjection.project(parsed.data)),
13254
+ compactRecord4(appendSlScoringProjection.project(parsed.data)),
13200
13255
  context
13201
13256
  );
13202
13257
  };
@@ -13274,21 +13329,21 @@ var beliefsContracts = [
13274
13329
  }
13275
13330
  }),
13276
13331
  surfaceContract({
13277
- name: "modulate_confidence",
13332
+ name: "append_sl_scoring",
13278
13333
  kind: "mutation",
13279
13334
  domain: "beliefs",
13280
13335
  surfaceClass: "platform_internal",
13281
- path: "/beliefs/confidence",
13336
+ path: "/beliefs/sl-scoring",
13282
13337
  sdkNamespace: "beliefs",
13283
- sdkMethod: "modulateConfidence",
13284
- summary: "Internal SL ledger append. Public callers should attach evidence or contradiction relations instead.",
13338
+ sdkMethod: "appendSlScoring",
13339
+ summary: "Internal SL scoring append. Public callers attach evidence or contradiction relations instead.",
13285
13340
  convex: {
13286
13341
  module: "beliefs",
13287
- functionName: "modulateConfidence",
13342
+ functionName: "appendSlScoring",
13288
13343
  kind: "mutation",
13289
- inputProjection: confidenceInput
13344
+ inputProjection: appendSlScoringInput
13290
13345
  },
13291
- args: modulateConfidenceInputSchema
13346
+ args: appendSlScoringInputSchema
13292
13347
  }),
13293
13348
  surfaceContract({
13294
13349
  name: "fork_belief",
@@ -13394,8 +13449,12 @@ var beliefRelationSchema2 = z.object({
13394
13449
  targetId: z.string().optional().describe("Belief target ID alias for beliefId/beliefNodeId."),
13395
13450
  relation: z.enum(["supports", "contradicts", "supporting", "contradicting"]).optional().describe("Relation alias for how the evidence bears on the belief."),
13396
13451
  evidenceRelation: evidenceRelationSchema2.optional().describe("Canonical relation: supports or contradicts."),
13397
- confidence: z.number().optional().describe("Confidence in this evidence-to-belief relation."),
13398
- weight: z.number().optional().describe("Support weight from -1.0 to +1.0 for this belief."),
13452
+ confidence: z.number().optional().describe(
13453
+ "Deprecated read-only hint. Runtime SL confidence is derived from signed weight."
13454
+ ),
13455
+ weight: z.number().min(-1).max(1).refine((value) => value !== 0, {
13456
+ message: "Evidence impact weight must be nonzero."
13457
+ }).describe("Required signed impact score from -1.0 to +1.0 for this belief."),
13399
13458
  rationale: z.string().optional().describe("Why this relation exists.")
13400
13459
  });
13401
13460
  var createEvidenceArgs = z.object({
@@ -13404,7 +13463,7 @@ var createEvidenceArgs = z.object({
13404
13463
  source: z.string().optional().describe("Source URL or source label."),
13405
13464
  sourceUrl: z.string().optional().describe("Canonical source URL."),
13406
13465
  targetId: z.string().optional().describe(
13407
- "Belief, question, or worktree identifier to link or preserve on the evidence record. Belief targets require evidenceRelation or a nonzero signed weight."
13466
+ "Belief identifier to link immediately. Evidence creation cannot target only a question or worktree."
13408
13467
  ),
13409
13468
  linkedBeliefNodeId: z.string().optional().describe("Belief node this evidence bears on."),
13410
13469
  evidenceRelation: evidenceRelationSchema2.optional().describe(
@@ -13413,8 +13472,14 @@ var createEvidenceArgs = z.object({
13413
13472
  beliefRelations: z.array(beliefRelationSchema2).optional().describe(
13414
13473
  "Additional belief relations for one evidence record. Use when the same evidence supports or contradicts multiple beliefs."
13415
13474
  ),
13416
- confidence: z.number().optional().describe("Confidence in the evidence relation."),
13417
- weight: z.number().optional().describe("Nonzero support weight from -1.0 to +1.0."),
13475
+ confidence: z.number().optional().describe(
13476
+ "Deprecated hint. Runtime confidence is derived from signed weight."
13477
+ ),
13478
+ weight: z.number().min(-1).max(1).refine((value) => value !== 0, {
13479
+ message: "Evidence impact weight must be nonzero."
13480
+ }).describe(
13481
+ "Required signed impact score from -1.0 to +1.0 for targetId/linkedBeliefNodeId."
13482
+ ),
13418
13483
  metadata: jsonRecordSchema4.optional().describe("Metadata merged into the canonical evidence node."),
13419
13484
  rationale: z.string().describe("Why this evidence should enter the reasoning graph."),
13420
13485
  reasoning: z.string().optional().describe("Reasoning note preserved in evidence metadata."),
@@ -13436,7 +13501,9 @@ var addEvidenceArgs = z.object({
13436
13501
  topicId: z.string().optional().describe("Topic scope hint."),
13437
13502
  sourceUrl: z.string().optional().describe("URL of the source material."),
13438
13503
  targetNodeId: z.string().describe("The belief this evidence bears on."),
13439
- weight: z.number().optional().describe("Support weight from -1.0 to +1.0."),
13504
+ weight: z.number().min(-1).max(1).refine((value) => value !== 0, {
13505
+ message: "Evidence impact weight must be nonzero."
13506
+ }).describe("Required signed impact score from -1.0 to +1.0."),
13440
13507
  reasoning: z.string().describe("Why this evidence is relevant to the target belief."),
13441
13508
  title: z.string().optional().describe("Optional short title."),
13442
13509
  content: z.string().optional().describe("Optional long-form evidence content."),
@@ -13456,19 +13523,21 @@ var createEvidenceInput = (input, context) => {
13456
13523
  );
13457
13524
  };
13458
13525
  function relationWeight(input) {
13459
- if (typeof input.weight === "number" && Number.isFinite(input.weight) && input.weight !== 0) {
13526
+ if (typeof input.weight === "number" && Number.isFinite(input.weight) && input.weight !== 0 && input.weight >= -1 && input.weight <= 1) {
13527
+ const relation = String(
13528
+ input.evidenceRelation ?? input.relation ?? input.type ?? ""
13529
+ );
13530
+ if ((relation === "supports" || relation === "supporting") && input.weight < 0) {
13531
+ throw new Error("Supporting evidence links require positive weight.");
13532
+ }
13533
+ if ((relation === "contradicts" || relation === "contradicting") && input.weight > 0) {
13534
+ throw new Error("Contradicting evidence links require negative weight.");
13535
+ }
13460
13536
  return input.weight;
13461
13537
  }
13462
- const relation = String(
13463
- input.evidenceRelation ?? input.relation ?? input.type ?? ""
13538
+ throw new Error(
13539
+ "Belief evidence links require explicit nonzero weight in [-1, 1]."
13464
13540
  );
13465
- if (relation !== "supports" && relation !== "supporting" && relation !== "contradicts" && relation !== "contradicting") {
13466
- throw new Error(
13467
- "Belief evidence links require evidenceRelation='supports'|'contradicts' or a nonzero signed weight."
13468
- );
13469
- }
13470
- const confidence = typeof input.confidence === "number" ? Math.max(0, Math.min(1, input.confidence)) : 0.7;
13471
- return relation === "contradicts" || relation === "contradicting" ? -confidence : confidence;
13472
13541
  }
13473
13542
  var linkEvidenceToBeliefInput = (input, context) => {
13474
13543
  const weight = relationWeight(input);
@@ -13477,6 +13546,7 @@ var linkEvidenceToBeliefInput = (input, context) => {
13477
13546
  beliefNodeId: input.beliefNodeId ?? input.beliefId ?? input.targetId,
13478
13547
  insightId: input.insightId ?? input.evidenceNodeId ?? input.evidenceId,
13479
13548
  type: weight < 0 ? "contradicting" : "supporting",
13549
+ weight,
13480
13550
  confidence: Math.min(1, Math.abs(weight)),
13481
13551
  rationale: input.rationale ?? input.context,
13482
13552
  trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
@@ -13553,7 +13623,12 @@ var evidenceContracts = [
13553
13623
  functionName: "create",
13554
13624
  kind: "mutation",
13555
13625
  inputProjection: (input, context) => {
13556
- const weight = typeof input.weight === "number" ? input.weight : 0.7;
13626
+ if (typeof input.weight !== "number" || !Number.isFinite(input.weight) || input.weight === 0 || input.weight < -1 || input.weight > 1) {
13627
+ throw new Error(
13628
+ "add_evidence requires explicit nonzero weight in [-1, 1]."
13629
+ );
13630
+ }
13631
+ const weight = input.weight;
13557
13632
  return createEvidenceInput(
13558
13633
  {
13559
13634
  ...input,
@@ -13562,6 +13637,7 @@ var evidenceContracts = [
13562
13637
  linkedBeliefNodeId: input.linkedBeliefNodeId ?? input.targetNodeId ?? input.targetId,
13563
13638
  evidenceRelation: weight < 0 ? "contradicts" : "supports",
13564
13639
  confidence: Math.min(1, Math.max(0, Math.abs(weight))),
13640
+ weight,
13565
13641
  rationale: input.reasoning,
13566
13642
  metadata: {
13567
13643
  ...recordValue2(input.metadata),