@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/types.js CHANGED
@@ -34,7 +34,7 @@ var REASONING_METHODS = [
34
34
  // ../contracts/src/tool-contracts.graph.ts
35
35
  var QUERY_LINEAGE = {
36
36
  name: "query_lineage",
37
- 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).",
37
+ 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).",
38
38
  parameters: {
39
39
  nodeId: { type: "string", description: "Starting node to trace from" },
40
40
  depth: {
@@ -233,7 +233,7 @@ var FIND_CONTRADICTIONS = {
233
233
  };
234
234
  var BISECT_CONFIDENCE = {
235
235
  name: "bisect_confidence",
236
- 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.",
236
+ 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.",
237
237
  parameters: {
238
238
  nodeId: { type: "string", description: "The belief to bisect" },
239
239
  expectedDirection: {
@@ -252,7 +252,7 @@ var BISECT_CONFIDENCE = {
252
252
  fields: {
253
253
  beliefId: "string \u2014 canonical belief ID",
254
254
  expectedDirection: "string \u2014 overconfident | underconfident",
255
- inflectionEntry: "object \u2014 the confidence modulation where divergence began",
255
+ inflectionEntry: "object \u2014 the scoring event where divergence began",
256
256
  triggerEvent: "string | null \u2014 what caused the divergence",
257
257
  confidenceBefore: "number | null",
258
258
  confidenceAfter: "number | null",
@@ -546,18 +546,18 @@ var SEARCH_EVIDENCE = {
546
546
  };
547
547
  var CREATE_EVIDENCE = {
548
548
  name: "create_evidence",
549
- 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.",
549
+ 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.",
550
550
  parameters: {
551
551
  topicId: { type: "string", description: "Topic scope" },
552
552
  text: { type: "string", description: "Canonical evidence text" },
553
553
  source: { type: "string", description: "Source URL or source label" },
554
554
  targetId: {
555
555
  type: "string",
556
- description: "Optional belief or question identifier to link immediately"
556
+ description: "Belief identifier to link immediately"
557
557
  },
558
558
  weight: {
559
559
  type: "number",
560
- description: "Optional support weight: -1.0 (contradicts) to +1.0 (supports). If omitted, evidenceRelation + confidence determine the weight."
560
+ description: "Required nonzero signed impact score: -1.0 (contradicts) to +1.0 (supports)."
561
561
  },
562
562
  evidenceRelation: {
563
563
  type: "string",
@@ -566,7 +566,7 @@ var CREATE_EVIDENCE = {
566
566
  },
567
567
  confidence: {
568
568
  type: "number",
569
- description: "Confidence in the evidence relation, 0.0 to 1.0"
569
+ description: "Deprecated hint. Runtime confidence is derived from the signed impact score."
570
570
  },
571
571
  beliefRelations: {
572
572
  type: "array",
@@ -588,7 +588,7 @@ var CREATE_EVIDENCE = {
588
588
  },
589
589
  kind: { type: "string", description: "Optional evidence kind" }
590
590
  },
591
- required: ["text", "rationale"],
591
+ required: ["text", "rationale", "weight"],
592
592
  response: {
593
593
  description: "The created canonical evidence record",
594
594
  fields: {
@@ -663,7 +663,7 @@ var LINK_EVIDENCE = {
663
663
  },
664
664
  rationale: { type: "string", description: "Why this link exists" }
665
665
  },
666
- required: ["evidenceId", "targetId"],
666
+ required: ["evidenceId", "targetId", "weight"],
667
667
  response: {
668
668
  description: "The created canonical evidence edge summary",
669
669
  fields: {
@@ -699,7 +699,7 @@ var LINK_EVIDENCE_TO_BELIEF = {
699
699
  },
700
700
  rationale: { type: "string", description: "Why this evidence is relevant" }
701
701
  },
702
- required: ["evidenceId", "beliefId"],
702
+ required: ["evidenceId", "beliefId", "weight"],
703
703
  response: {
704
704
  description: "The created edge linking evidence to belief",
705
705
  fields: {
@@ -717,15 +717,23 @@ var LINK_EVIDENCE_TO_BELIEF = {
717
717
  // ../contracts/src/tool-contracts.lifecycle.ts
718
718
  var CREATE_BELIEF = {
719
719
  name: "create_belief",
720
- 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.",
720
+ 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.",
721
721
  parameters: {
722
722
  canonicalText: {
723
723
  type: "string",
724
724
  description: "The belief statement \u2014 what the agent holds to be true"
725
725
  },
726
+ topicGlobalId: {
727
+ type: "string",
728
+ description: "Required globalId (UUID) of the topic node in epistemicNodes that anchors the belief"
729
+ },
730
+ topicNodeId: {
731
+ type: "string",
732
+ description: "Optional internal epistemicNodes _id for the topic anchor. Prefer topicGlobalId for public callers."
733
+ },
726
734
  topicId: {
727
735
  type: "string",
728
- description: "Optional topic scope hint for the belief"
736
+ description: "Deprecated compatibility alias for topicGlobalId. Must identify a topic epistemicNode, not a legacy topics-table row."
729
737
  },
730
738
  baseRate: {
731
739
  type: "number",
@@ -740,7 +748,7 @@ var CREATE_BELIEF = {
740
748
  description: "Optional extra metadata merged into the node (e.g., { codeAnchors: ['path/to/file.ts'] } for coding intelligence)"
741
749
  }
742
750
  },
743
- required: ["canonicalText"],
751
+ required: ["canonicalText", "topicGlobalId"],
744
752
  response: {
745
753
  description: "The created canonical belief record",
746
754
  fields: {
@@ -749,7 +757,7 @@ var CREATE_BELIEF = {
749
757
  beliefId: "string \u2014 canonical belief ID",
750
758
  text: "string \u2014 canonical belief formulation",
751
759
  topicId: "string",
752
- status: "string \u2014 active | superseded | archived",
760
+ beliefStatus: "string \u2014 assumption | hypothesis | active | superseded | resolved_true | resolved_false",
753
761
  scoringState: "string \u2014 unscored | scored"
754
762
  }
755
763
  },
@@ -772,7 +780,7 @@ var GET_BELIEF = {
772
780
  beliefId: "string \u2014 canonical belief ID",
773
781
  text: "string \u2014 canonical belief formulation",
774
782
  topicId: "string",
775
- status: "string \u2014 active | superseded | archived",
783
+ beliefStatus: "string \u2014 assumption | hypothesis | active | superseded | resolved_true | resolved_false",
776
784
  scoringState: "string \u2014 unscored | scored"
777
785
  }
778
786
  },
@@ -801,34 +809,24 @@ var REFINE_BELIEF = {
801
809
  ontologyPrimitive: "belief",
802
810
  tier: "showcase"
803
811
  };
804
- var MODULATE_CONFIDENCE = {
805
- name: "modulate_confidence",
806
- 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.",
812
+ var APPEND_SL_SCORING = {
813
+ name: "append_sl_scoring",
814
+ 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.",
807
815
  parameters: {
808
- nodeId: { type: "string", description: "The belief to score" },
809
- belief: {
810
- type: "number",
811
- description: "Subjective-logic belief mass `b` in [0, 1]"
812
- },
816
+ nodeId: { type: "string", description: "The belief receiving the SL score" },
817
+ belief: { type: "number", description: "Subjective Logic belief mass b" },
813
818
  disbelief: {
814
819
  type: "number",
815
- description: "Subjective-logic disbelief mass `d` in [0, 1]"
820
+ description: "Subjective Logic disbelief mass d"
816
821
  },
817
822
  uncertainty: {
818
823
  type: "number",
819
- description: "Subjective-logic uncertainty mass `u` in [0, 1]"
820
- },
821
- baseRate: {
822
- type: "number",
823
- description: "Subjective-logic base rate `a` in [0, 1]. Required for tuple payloads."
824
- },
825
- worktreeId: {
826
- type: "string",
827
- description: "Completed worktree that tested this belief when confidence policy requires merge-backed scoring."
824
+ description: "Subjective Logic uncertainty mass u"
828
825
  },
826
+ baseRate: { type: "number", description: "Subjective Logic base rate a" },
829
827
  trigger: {
830
828
  type: "string",
831
- description: "What caused this confidence change",
829
+ description: "Evidence-bearing cause of the scoring event",
832
830
  enum: [
833
831
  "evidence_added",
834
832
  "evidence_removed",
@@ -839,64 +837,39 @@ var MODULATE_CONFIDENCE = {
839
837
  "worktree_completed",
840
838
  "fusion",
841
839
  "discount",
842
- "deduction"
840
+ "deduction",
841
+ "backfill_synthetic"
843
842
  ]
844
843
  },
845
- triggeringEvidenceId: {
846
- type: "string",
847
- description: "Evidence node that caused an evidence-triggered modulation"
848
- },
849
- triggeringQuestionId: {
850
- type: "string",
851
- description: "Answered question whose resolution supports this modulation"
852
- },
853
- triggeringAnswerId: {
854
- type: "string",
855
- description: "Answer node whose content supports this modulation"
856
- },
857
- triggeringContradictionId: {
858
- type: "string",
859
- description: "Contradiction record that caused a contradiction-triggered modulation"
860
- },
861
- triggeringWorktreeId: {
862
- type: "string",
863
- description: "Completed worktree whose outcome caused a worktree-triggered modulation"
844
+ provenance: {
845
+ type: "object",
846
+ description: "At least one of evidence, question, answer, contradiction, or worktree."
864
847
  },
865
848
  rationale: {
866
849
  type: "string",
867
- description: "Human-readable explanation of why confidence changed"
850
+ description: "Why this evidence-bearing event moved the SL tuple"
868
851
  }
869
852
  },
870
- required: [
871
- "nodeId",
872
- "belief",
873
- "disbelief",
874
- "uncertainty",
875
- "baseRate",
876
- "trigger",
877
- "rationale"
878
- ],
853
+ required: ["nodeId", "belief", "disbelief", "uncertainty", "baseRate", "trigger", "rationale"],
879
854
  response: {
880
- description: "Confidence modulation result",
855
+ description: "Internal SL scoring append receipt",
881
856
  fields: {
882
- beliefId: "string \u2014 canonical belief ID",
883
- nodeId: "string \u2014 canonical belief ID",
884
- newConfidence: "number",
857
+ nodeId: "string",
885
858
  previousConfidence: "number",
886
- trigger: "string",
887
- requestId: "string \u2014 request identifier for the scheduled cascade",
888
- propagationSummary: "object \u2014 bounded inline cascade summary with totalCandidateTargets, inlineTargets, and remainingTargetCount"
859
+ newConfidence: "number",
860
+ beliefConfidenceId: "string"
889
861
  }
890
862
  },
891
863
  ownerModule: "graph-primitives",
892
864
  ontologyPrimitive: "belief",
893
- tier: "showcase"
865
+ tier: "workhorse",
866
+ internal: true
894
867
  };
895
868
  var FORK_BELIEF = {
896
869
  name: "fork_belief",
897
- 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.",
870
+ 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.",
898
871
  parameters: {
899
- nodeId: { type: "string", description: "The scored belief to fork from" },
872
+ nodeId: { type: "string", description: "The belief to fork from" },
900
873
  newFormulation: {
901
874
  type: "string",
902
875
  description: "The evolved belief statement"
@@ -908,12 +881,20 @@ var FORK_BELIEF = {
908
881
  "refinement",
909
882
  "contradiction_response",
910
883
  "scope_change",
911
- "confidence_collapse",
912
- "manual"
884
+ "confidence_collapse"
913
885
  ]
886
+ },
887
+ forkMode: {
888
+ type: "string",
889
+ description: "supersede replaces the parent; branch creates a child while preserving the parent.",
890
+ enum: ["supersede", "branch"]
891
+ },
892
+ triggeringEvidenceId: {
893
+ type: "string",
894
+ description: "Evidence already attached to the parent belief that caused the fork."
914
895
  }
915
896
  },
916
- required: ["nodeId", "newFormulation", "forkReason"],
897
+ required: ["nodeId", "newFormulation", "forkReason", "triggeringEvidenceId"],
917
898
  response: {
918
899
  description: "The forked canonical belief record",
919
900
  fields: {
@@ -2178,7 +2159,7 @@ var TRIGGER_BELIEF_REVIEW = {
2178
2159
  };
2179
2160
  var EVALUATE_CONTRACT = {
2180
2161
  name: "evaluate_contract",
2181
- 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.",
2162
+ 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.",
2182
2163
  parameters: {
2183
2164
  contractId: { type: "string", description: "Which contract to evaluate" },
2184
2165
  trigger: {
@@ -4069,6 +4050,11 @@ var COMPILE_CONTEXT = {
4069
4050
  response: {
4070
4051
  description: "Compiled context pack for the requested topic",
4071
4052
  fields: {
4053
+ contextNarrative: "array \u2014 first field; ordered synthesis blocks with kind/text, starting with executive_summary and canonical narrative blocks before raw objects",
4054
+ narrativeCoverage: "object \u2014 recordsSynthesized, recordsNamed, recordsOmitted, topicsSynthesized, topicsEnriched, topicContentOmitted, enrichmentMode, and blocksEmitted for the narrative",
4055
+ synthesisLints: "array \u2014 inline quality warnings for degenerate synthesis blocks or weak narrative coverage",
4056
+ retrievalReceipt: "object \u2014 candidateCounts, coverageWarning, narrativeCoverage, synthesisLints, and suggestedNextActions",
4057
+ supportingObjects: "object \u2014 raw graph records grouped behind the synthesis: invariants, activeBeliefs, openQuestions, recentEvidence, worktrees, lanes, entities, and contradictions",
4072
4058
  schemaVersion: "string",
4073
4059
  topicId: "string",
4074
4060
  topicName: "string",
@@ -4076,15 +4062,6 @@ var COMPILE_CONTEXT = {
4076
4062
  generatedAt: "number \u2014 deterministic graph-backed reference timestamp for this compilation",
4077
4063
  ranking: "string \u2014 baseline_v1 | weighted_v1",
4078
4064
  summary: "object \u2014 counts and scoped health signals",
4079
- invariants: "array \u2014 high-confidence invariant beliefs",
4080
- activeBeliefs: "array \u2014 current high-signal beliefs",
4081
- openQuestions: "array \u2014 unresolved questions ranked for this query",
4082
- recentEvidence: "array \u2014 recent evidence ranked for this query",
4083
- contradictions: "array \u2014 unresolved contradiction records",
4084
- relatedEntities: "array | undefined \u2014 ranked ontological entities in scope",
4085
- contextNarrative: "array \u2014 ordered synthesis blocks with kind/text, starting with executive_summary and canonical narrative blocks before raw objects",
4086
- retrievalReceipt: "object \u2014 candidateCounts, coverageWarning, narrativeCoverage, synthesisLints, and suggestedNextActions",
4087
- narrativeCoverage: "object \u2014 recordsSynthesized, recordsNamed, recordsOmitted, topicsSynthesized, topicsEnriched, topicContentOmitted, enrichmentMode, and blocksEmitted for the narrative",
4088
4065
  injectionPolicy: "object \u2014 token-budgeted section selections",
4089
4066
  diagnostics: "object \u2014 scoring and utilization telemetry"
4090
4067
  }
@@ -4643,7 +4620,7 @@ var MCP_TOOL_CONTRACTS = {
4643
4620
  create_belief: CREATE_BELIEF,
4644
4621
  get_belief: GET_BELIEF,
4645
4622
  refine_belief: REFINE_BELIEF,
4646
- modulate_confidence: MODULATE_CONFIDENCE,
4623
+ append_sl_scoring: APPEND_SL_SCORING,
4647
4624
  fork_belief: FORK_BELIEF,
4648
4625
  archive_belief: ARCHIVE_BELIEF,
4649
4626
  create_epistemic_contract: CREATE_EPISTEMIC_CONTRACT,
@@ -6441,8 +6418,10 @@ defineTable({
6441
6418
  "beliefStatus": z.object({
6442
6419
  "assumption": z.number(),
6443
6420
  "hypothesis": z.number(),
6444
- "belief": z.number(),
6445
- "fact": z.number()
6421
+ "active": z.number(),
6422
+ "superseded": z.number(),
6423
+ "resolved_true": z.number(),
6424
+ "resolved_false": z.number()
6446
6425
  }).optional(),
6447
6426
  "evidenceTemporalNature": z.object({
6448
6427
  "factual": z.number(),
@@ -6664,8 +6643,8 @@ defineTable({
6664
6643
  "exportClass": z.enum(["internal_only", "client_safe", "public_safe", "restricted"]).optional(),
6665
6644
  "anonymizationClass": z.enum(["none", "standard", "strict"]).optional(),
6666
6645
  "beliefType": z.string().optional(),
6667
- "beliefStatus": z.enum(["assumption", "hypothesis", "belief", "fact"]).optional(),
6668
- "epistemicStatus": z.enum(["hypothesis", "emerging", "established", "challenged", "assumption", "deprecated"]).optional(),
6646
+ "beliefStatus": z.enum(["assumption", "hypothesis", "active", "superseded", "resolved_true", "resolved_false"]).optional(),
6647
+ "epistemicStatus": z.enum(["assumption", "hypothesis", "active", "superseded", "resolved_true", "resolved_false"]).optional(),
6669
6648
  "reversibility": z.enum(["irreversible", "hard_to_reverse", "reversible", "trivial"]).optional(),
6670
6649
  "predictionMeta": z.object({
6671
6650
  "isPrediction": z.boolean(),
@@ -11670,11 +11649,39 @@ var createEvidenceInputSchemaBase = z.object({
11670
11649
  metadata: jsonRecordSchema.optional(),
11671
11650
  trustedBypassAccessCheck: z.boolean().optional()
11672
11651
  }).passthrough();
11673
- function hasNonzeroWeight(value) {
11674
- return typeof value === "number" && Number.isFinite(value) && value !== 0;
11652
+ function isSignedImpactScore(value) {
11653
+ return typeof value === "number" && Number.isFinite(value) && value >= -1 && value <= 1 && value !== 0;
11675
11654
  }
11676
- function hasRelationSignal(value, weight) {
11677
- return Boolean(normalizeRelation(value, weight));
11655
+ function validateSignedImpactScore(value, ctx, path) {
11656
+ if (!isSignedImpactScore(value)) {
11657
+ ctx.addIssue({
11658
+ code: z.ZodIssueCode.custom,
11659
+ message: "evidence-to-belief links require an explicit nonzero signed impact score in [-1, 1]",
11660
+ path
11661
+ });
11662
+ return false;
11663
+ }
11664
+ return true;
11665
+ }
11666
+ function validateRelationImpactConsistency(relation, weight, ctx, path) {
11667
+ const normalized = normalizeRelationAlias(relation);
11668
+ if (!normalized || !isSignedImpactScore(weight)) {
11669
+ return;
11670
+ }
11671
+ if (normalized === "supports" && weight < 0) {
11672
+ ctx.addIssue({
11673
+ code: z.ZodIssueCode.custom,
11674
+ message: "supporting evidence requires a positive impact score",
11675
+ path
11676
+ });
11677
+ }
11678
+ if (normalized === "contradicts" && weight > 0) {
11679
+ ctx.addIssue({
11680
+ code: z.ZodIssueCode.custom,
11681
+ message: "contradicting evidence requires a negative impact score",
11682
+ path
11683
+ });
11684
+ }
11678
11685
  }
11679
11686
  var createEvidenceInputSchema = createEvidenceInputSchemaBase.superRefine(
11680
11687
  (input, ctx) => {
@@ -11691,13 +11698,27 @@ var createEvidenceInputSchema = createEvidenceInputSchemaBase.superRefine(
11691
11698
  input.linkedBeliefNodeId || kind === "belief" || kind === "unknown" && target
11692
11699
  );
11693
11700
  const weight = typeof input.weight === "number" ? input.weight : void 0;
11694
- if (linksPrimaryBelief && !hasRelationSignal(input.evidenceRelation, weight)) {
11701
+ const hasBeliefRelations = (input.beliefRelations?.length ?? 0) > 0;
11702
+ if (!linksPrimaryBelief && !hasBeliefRelations) {
11703
+ ctx.addIssue({
11704
+ code: z.ZodIssueCode.custom,
11705
+ message: "create_evidence requires at least one linked belief; evidence cannot be created as an orphan or linked only to a question/worktree",
11706
+ path: ["linkedBeliefNodeId"]
11707
+ });
11708
+ }
11709
+ if (kind === "question" || kind === "worktree") {
11695
11710
  ctx.addIssue({
11696
11711
  code: z.ZodIssueCode.custom,
11697
- message: "belief-targeted evidence requires evidenceRelation='supports'|'contradicts' or a nonzero signed weight",
11698
- path: ["evidenceRelation"]
11712
+ message: "create_evidence targetId must be a belief. Link evidence to questions/worktrees only after the evidence has a belief impact edge.",
11713
+ path: ["targetId"]
11699
11714
  });
11700
11715
  }
11716
+ if (linksPrimaryBelief) {
11717
+ validateSignedImpactScore(weight, ctx, ["weight"]);
11718
+ validateRelationImpactConsistency(input.evidenceRelation, weight, ctx, [
11719
+ "weight"
11720
+ ]);
11721
+ }
11701
11722
  input.beliefRelations?.forEach((relation, index) => {
11702
11723
  const beliefNodeId = relation.beliefNodeId ?? relation.beliefId ?? relation.targetId;
11703
11724
  if (!beliefNodeId) {
@@ -11708,15 +11729,18 @@ var createEvidenceInputSchema = createEvidenceInputSchemaBase.superRefine(
11708
11729
  });
11709
11730
  }
11710
11731
  const relationWeight2 = typeof relation.weight === "number" ? relation.weight : void 0;
11711
- if (beliefNodeId && !hasRelationSignal(
11712
- relation.evidenceRelation ?? relation.relation,
11713
- relationWeight2
11714
- )) {
11715
- ctx.addIssue({
11716
- code: z.ZodIssueCode.custom,
11717
- message: "beliefRelations entries require evidenceRelation='supports'|'contradicts' or a nonzero signed weight",
11718
- path: ["beliefRelations", index, "evidenceRelation"]
11719
- });
11732
+ if (beliefNodeId) {
11733
+ validateSignedImpactScore(relationWeight2, ctx, [
11734
+ "beliefRelations",
11735
+ index,
11736
+ "weight"
11737
+ ]);
11738
+ validateRelationImpactConsistency(
11739
+ relation.evidenceRelation ?? relation.relation,
11740
+ relationWeight2,
11741
+ ctx,
11742
+ ["beliefRelations", index, "weight"]
11743
+ );
11720
11744
  }
11721
11745
  });
11722
11746
  }
@@ -11770,18 +11794,28 @@ function targetKind(targetId) {
11770
11794
  }
11771
11795
  return "unknown";
11772
11796
  }
11773
- function normalizeRelation(value, weight) {
11797
+ function normalizeRelationAlias(value) {
11774
11798
  if (value === "supports" || value === "supporting") {
11775
11799
  return "supports";
11776
11800
  }
11777
11801
  if (value === "contradicts" || value === "contradicting") {
11778
11802
  return "contradicts";
11779
11803
  }
11804
+ return void 0;
11805
+ }
11806
+ function normalizeRelation(value, weight) {
11807
+ const alias = normalizeRelationAlias(value);
11808
+ if (alias) {
11809
+ return alias;
11810
+ }
11780
11811
  if (weight === void 0 || !hasNonzeroWeight(weight)) {
11781
11812
  return void 0;
11782
11813
  }
11783
11814
  return weight < 0 ? "contradicts" : "supports";
11784
11815
  }
11816
+ function hasNonzeroWeight(value) {
11817
+ return typeof value === "number" && Number.isFinite(value) && value !== 0;
11818
+ }
11785
11819
  function normalizeConfidence(confidence, weight) {
11786
11820
  if (confidence !== void 0) {
11787
11821
  return Math.min(1, Math.max(0, confidence));
@@ -11808,6 +11842,7 @@ function normalizeBeliefRelation(relation) {
11808
11842
  beliefNodeId,
11809
11843
  relation: evidenceRelation,
11810
11844
  confidence: normalizeConfidence(relation.confidence, weight),
11845
+ weight,
11811
11846
  rationale: relation.rationale
11812
11847
  });
11813
11848
  }
@@ -11856,6 +11891,7 @@ var createEvidenceProjection = defineProjection({
11856
11891
  linkedBeliefNodeId,
11857
11892
  evidenceRelation,
11858
11893
  confidence,
11894
+ weight,
11859
11895
  beliefRelations: beliefRelations && beliefRelations.length > 0 ? beliefRelations : void 0,
11860
11896
  rationale: input.rationale,
11861
11897
  trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
@@ -11885,12 +11921,14 @@ var createEvidenceProjection = defineProjection({
11885
11921
  v.literal("contradicts")
11886
11922
  )
11887
11923
  ),
11924
+ weight: v.optional(v.number()),
11888
11925
  beliefRelations: v.optional(
11889
11926
  v.array(
11890
11927
  v.object({
11891
11928
  beliefNodeId: v.string(),
11892
11929
  relation: v.union(v.literal("supports"), v.literal("contradicts")),
11893
11930
  confidence: v.optional(v.number()),
11931
+ weight: v.number(),
11894
11932
  rationale: v.optional(v.string())
11895
11933
  })
11896
11934
  )
@@ -12008,7 +12046,7 @@ var slOpinionProjectionSchema = z.object({
12008
12046
  uncertainty: z.number(),
12009
12047
  baseRate: z.number()
12010
12048
  });
12011
- var modulateConfidenceInputObjectSchema = z.object({
12049
+ var appendSlScoringInputObjectSchema = z.object({
12012
12050
  nodeId: z.string().optional(),
12013
12051
  beliefNodeId: z.string().optional(),
12014
12052
  worktreeId: z.string().optional(),
@@ -12027,23 +12065,23 @@ var modulateConfidenceInputObjectSchema = z.object({
12027
12065
  rationale: z.string(),
12028
12066
  trustedBypassAccessCheck: z.boolean().optional()
12029
12067
  });
12030
- var modulateConfidenceInputSchema = modulateConfidenceInputObjectSchema.superRefine((input, ctx) => {
12068
+ var appendSlScoringInputSchema = appendSlScoringInputObjectSchema.superRefine((input, ctx) => {
12031
12069
  if (hasProvenance(input)) {
12032
12070
  return;
12033
12071
  }
12034
12072
  ctx.addIssue({
12035
12073
  code: z.ZodIssueCode.custom,
12036
- message: "modulate_confidence requires evidence, question, answer, contradiction, or worktree provenance",
12074
+ message: "append_sl_scoring requires evidence, question, answer, contradiction, or worktree provenance",
12037
12075
  path: ["provenance"]
12038
12076
  });
12039
12077
  });
12040
- var modulateConfidenceProjection = defineProjection({
12041
- contractName: "modulate_confidence",
12042
- inputSchema: modulateConfidenceInputSchema,
12078
+ var appendSlScoringProjection = defineProjection({
12079
+ contractName: "append_sl_scoring",
12080
+ inputSchema: appendSlScoringInputSchema,
12043
12081
  project: (input) => {
12044
12082
  const nodeId = input.beliefNodeId ?? input.nodeId;
12045
12083
  if (!nodeId) {
12046
- throw new Error("modulate_confidence requires beliefNodeId or nodeId");
12084
+ throw new Error("append_sl_scoring requires beliefNodeId or nodeId");
12047
12085
  }
12048
12086
  const opinion = input.opinion ?? {
12049
12087
  belief: requireNumber(input.belief, "belief"),
@@ -12100,14 +12138,14 @@ var modulateConfidenceProjection = defineProjection({
12100
12138
  });
12101
12139
  function requireNumber(value, field) {
12102
12140
  if (value === void 0) {
12103
- throw new Error(`modulate_confidence requires ${field}`);
12141
+ throw new Error(`append_sl_scoring requires ${field}`);
12104
12142
  }
12105
12143
  return value;
12106
12144
  }
12107
12145
  function assertProvenance(input) {
12108
12146
  if (!hasProvenance(input)) {
12109
12147
  throw new Error(
12110
- "modulate_confidence requires evidence, question, answer, contradiction, or worktree provenance"
12148
+ "append_sl_scoring requires evidence, question, answer, contradiction, or worktree provenance"
12111
12149
  );
12112
12150
  }
12113
12151
  }
@@ -12450,12 +12488,12 @@ var LUCERN_OPERATION_MANIFEST = {
12450
12488
  internalSystem,
12451
12489
  "Lucern system/background operation. Available to platform code paths, hidden from public MCP discovery."
12452
12490
  ),
12453
- modulate_confidence: {
12454
- name: "modulate_confidence",
12491
+ append_sl_scoring: {
12492
+ name: "append_sl_scoring",
12455
12493
  surfaceClass: "platform_internal",
12456
12494
  surfaceIntent: "system",
12457
12495
  surfaces: internalSdkRestOnly,
12458
- rationale: "Internal SL ledger append primitive. Public callers attach evidence or contradiction relations; confidence is derived algorithmically."
12496
+ rationale: "Internal SL scoring append primitive. Public callers attach evidence or contradiction relations; confidence is derived algorithmically."
12459
12497
  },
12460
12498
  ...entries(
12461
12499
  LEGACY_COMPAT_OPERATION_NAMES,
@@ -13009,7 +13047,15 @@ var predictionMetaSchema = z.object({
13009
13047
  });
13010
13048
  var createBeliefArgs = z.object({
13011
13049
  canonicalText: z.string().describe("The belief statement the agent holds to be true."),
13012
- topicId: z.string().optional().describe("Topic scope hint for the belief."),
13050
+ topicGlobalId: z.string().describe(
13051
+ "Required globalId of the topic epistemicNode that anchors this belief. Belief creation creates a scoped_by edge directly to that topic node."
13052
+ ),
13053
+ topicNodeId: z.string().optional().describe(
13054
+ "Optional internal epistemicNodes _id for the topic anchor. Prefer topicGlobalId for public callers."
13055
+ ),
13056
+ topicId: z.string().optional().describe(
13057
+ "Deprecated compatibility alias for topicGlobalId. Must identify a topic epistemicNode, not a legacy topics-table row."
13058
+ ),
13013
13059
  baseRate: z.number().optional().describe("Prior base rate used to seed the vacuous opinion."),
13014
13060
  beliefType: z.string().optional().describe("Schema belief type."),
13015
13061
  metadata: jsonRecordSchema3.optional().describe("Extra metadata merged into the belief node."),
@@ -13028,9 +13074,14 @@ var forkBeliefArgs = z.object({
13028
13074
  "refinement",
13029
13075
  "contradiction_response",
13030
13076
  "scope_change",
13031
- "confidence_collapse",
13032
- "manual"
13077
+ "confidence_collapse"
13033
13078
  ]).describe("Why this fork was created."),
13079
+ forkMode: z.enum(["supersede", "branch"]).optional().describe(
13080
+ "supersede marks the parent belief superseded; branch preserves the parent and creates a derived child."
13081
+ ),
13082
+ triggeringEvidenceId: z.string().describe(
13083
+ "Evidence already attached to the parent belief through SL scoring; required for every fork."
13084
+ ),
13034
13085
  rationale: z.string().optional().describe("Why the fork is warranted.")
13035
13086
  });
13036
13087
  var beliefLookupInput = (input) => compactRecord4({
@@ -13044,7 +13095,9 @@ var createBeliefInput = (input, context) => {
13044
13095
  return withUserId(
13045
13096
  compactRecord4({
13046
13097
  projectId: input.projectId,
13047
- topicId: input.topicId,
13098
+ topicId: input.topicGlobalId ?? input.topicNodeId ?? input.topicId,
13099
+ topicGlobalId: input.topicGlobalId,
13100
+ topicNodeId: input.topicNodeId,
13048
13101
  formulation: input.formulation ?? input.canonicalText,
13049
13102
  beliefType: input.beliefType,
13050
13103
  rationale: input.rationale,
@@ -13066,20 +13119,22 @@ var forkBeliefInput = (input, context) => withUserId(
13066
13119
  parentNodeId: input.parentNodeId ?? input.nodeId ?? input.id,
13067
13120
  newFormulation: input.newFormulation,
13068
13121
  forkReason: input.forkReason,
13122
+ forkMode: input.forkMode,
13123
+ triggeringEvidenceId: input.triggeringEvidenceId,
13069
13124
  rationale: input.rationale,
13070
13125
  trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
13071
13126
  }),
13072
13127
  context
13073
13128
  );
13074
- var confidenceInput = (input, context) => {
13075
- const parsed = modulateConfidenceProjection.inputSchema.safeParse(input);
13129
+ var appendSlScoringInput = (input, context) => {
13130
+ const parsed = appendSlScoringProjection.inputSchema.safeParse(input);
13076
13131
  if (!parsed.success) {
13077
13132
  throw new Error(
13078
- `modulate_confidence projection input rejected: ${parsed.error.message}`
13133
+ `append_sl_scoring projection input rejected: ${parsed.error.message}`
13079
13134
  );
13080
13135
  }
13081
13136
  return withUserId(
13082
- compactRecord4(modulateConfidenceProjection.project(parsed.data)),
13137
+ compactRecord4(appendSlScoringProjection.project(parsed.data)),
13083
13138
  context
13084
13139
  );
13085
13140
  };
@@ -13157,21 +13212,21 @@ var beliefsContracts = [
13157
13212
  }
13158
13213
  }),
13159
13214
  surfaceContract({
13160
- name: "modulate_confidence",
13215
+ name: "append_sl_scoring",
13161
13216
  kind: "mutation",
13162
13217
  domain: "beliefs",
13163
13218
  surfaceClass: "platform_internal",
13164
- path: "/beliefs/confidence",
13219
+ path: "/beliefs/sl-scoring",
13165
13220
  sdkNamespace: "beliefs",
13166
- sdkMethod: "modulateConfidence",
13167
- summary: "Internal SL ledger append. Public callers should attach evidence or contradiction relations instead.",
13221
+ sdkMethod: "appendSlScoring",
13222
+ summary: "Internal SL scoring append. Public callers attach evidence or contradiction relations instead.",
13168
13223
  convex: {
13169
13224
  module: "beliefs",
13170
- functionName: "modulateConfidence",
13225
+ functionName: "appendSlScoring",
13171
13226
  kind: "mutation",
13172
- inputProjection: confidenceInput
13227
+ inputProjection: appendSlScoringInput
13173
13228
  },
13174
- args: modulateConfidenceInputSchema
13229
+ args: appendSlScoringInputSchema
13175
13230
  }),
13176
13231
  surfaceContract({
13177
13232
  name: "fork_belief",
@@ -13277,8 +13332,12 @@ var beliefRelationSchema2 = z.object({
13277
13332
  targetId: z.string().optional().describe("Belief target ID alias for beliefId/beliefNodeId."),
13278
13333
  relation: z.enum(["supports", "contradicts", "supporting", "contradicting"]).optional().describe("Relation alias for how the evidence bears on the belief."),
13279
13334
  evidenceRelation: evidenceRelationSchema2.optional().describe("Canonical relation: supports or contradicts."),
13280
- confidence: z.number().optional().describe("Confidence in this evidence-to-belief relation."),
13281
- weight: z.number().optional().describe("Support weight from -1.0 to +1.0 for this belief."),
13335
+ confidence: z.number().optional().describe(
13336
+ "Deprecated read-only hint. Runtime SL confidence is derived from signed weight."
13337
+ ),
13338
+ weight: z.number().min(-1).max(1).refine((value) => value !== 0, {
13339
+ message: "Evidence impact weight must be nonzero."
13340
+ }).describe("Required signed impact score from -1.0 to +1.0 for this belief."),
13282
13341
  rationale: z.string().optional().describe("Why this relation exists.")
13283
13342
  });
13284
13343
  var createEvidenceArgs = z.object({
@@ -13287,7 +13346,7 @@ var createEvidenceArgs = z.object({
13287
13346
  source: z.string().optional().describe("Source URL or source label."),
13288
13347
  sourceUrl: z.string().optional().describe("Canonical source URL."),
13289
13348
  targetId: z.string().optional().describe(
13290
- "Belief, question, or worktree identifier to link or preserve on the evidence record. Belief targets require evidenceRelation or a nonzero signed weight."
13349
+ "Belief identifier to link immediately. Evidence creation cannot target only a question or worktree."
13291
13350
  ),
13292
13351
  linkedBeliefNodeId: z.string().optional().describe("Belief node this evidence bears on."),
13293
13352
  evidenceRelation: evidenceRelationSchema2.optional().describe(
@@ -13296,8 +13355,14 @@ var createEvidenceArgs = z.object({
13296
13355
  beliefRelations: z.array(beliefRelationSchema2).optional().describe(
13297
13356
  "Additional belief relations for one evidence record. Use when the same evidence supports or contradicts multiple beliefs."
13298
13357
  ),
13299
- confidence: z.number().optional().describe("Confidence in the evidence relation."),
13300
- weight: z.number().optional().describe("Nonzero support weight from -1.0 to +1.0."),
13358
+ confidence: z.number().optional().describe(
13359
+ "Deprecated hint. Runtime confidence is derived from signed weight."
13360
+ ),
13361
+ weight: z.number().min(-1).max(1).refine((value) => value !== 0, {
13362
+ message: "Evidence impact weight must be nonzero."
13363
+ }).describe(
13364
+ "Required signed impact score from -1.0 to +1.0 for targetId/linkedBeliefNodeId."
13365
+ ),
13301
13366
  metadata: jsonRecordSchema4.optional().describe("Metadata merged into the canonical evidence node."),
13302
13367
  rationale: z.string().describe("Why this evidence should enter the reasoning graph."),
13303
13368
  reasoning: z.string().optional().describe("Reasoning note preserved in evidence metadata."),
@@ -13319,7 +13384,9 @@ var addEvidenceArgs = z.object({
13319
13384
  topicId: z.string().optional().describe("Topic scope hint."),
13320
13385
  sourceUrl: z.string().optional().describe("URL of the source material."),
13321
13386
  targetNodeId: z.string().describe("The belief this evidence bears on."),
13322
- weight: z.number().optional().describe("Support weight from -1.0 to +1.0."),
13387
+ weight: z.number().min(-1).max(1).refine((value) => value !== 0, {
13388
+ message: "Evidence impact weight must be nonzero."
13389
+ }).describe("Required signed impact score from -1.0 to +1.0."),
13323
13390
  reasoning: z.string().describe("Why this evidence is relevant to the target belief."),
13324
13391
  title: z.string().optional().describe("Optional short title."),
13325
13392
  content: z.string().optional().describe("Optional long-form evidence content."),
@@ -13339,19 +13406,21 @@ var createEvidenceInput = (input, context) => {
13339
13406
  );
13340
13407
  };
13341
13408
  function relationWeight(input) {
13342
- if (typeof input.weight === "number" && Number.isFinite(input.weight) && input.weight !== 0) {
13409
+ if (typeof input.weight === "number" && Number.isFinite(input.weight) && input.weight !== 0 && input.weight >= -1 && input.weight <= 1) {
13410
+ const relation = String(
13411
+ input.evidenceRelation ?? input.relation ?? input.type ?? ""
13412
+ );
13413
+ if ((relation === "supports" || relation === "supporting") && input.weight < 0) {
13414
+ throw new Error("Supporting evidence links require positive weight.");
13415
+ }
13416
+ if ((relation === "contradicts" || relation === "contradicting") && input.weight > 0) {
13417
+ throw new Error("Contradicting evidence links require negative weight.");
13418
+ }
13343
13419
  return input.weight;
13344
13420
  }
13345
- const relation = String(
13346
- input.evidenceRelation ?? input.relation ?? input.type ?? ""
13421
+ throw new Error(
13422
+ "Belief evidence links require explicit nonzero weight in [-1, 1]."
13347
13423
  );
13348
- if (relation !== "supports" && relation !== "supporting" && relation !== "contradicts" && relation !== "contradicting") {
13349
- throw new Error(
13350
- "Belief evidence links require evidenceRelation='supports'|'contradicts' or a nonzero signed weight."
13351
- );
13352
- }
13353
- const confidence = typeof input.confidence === "number" ? Math.max(0, Math.min(1, input.confidence)) : 0.7;
13354
- return relation === "contradicts" || relation === "contradicting" ? -confidence : confidence;
13355
13424
  }
13356
13425
  var linkEvidenceToBeliefInput = (input, context) => {
13357
13426
  const weight = relationWeight(input);
@@ -13360,6 +13429,7 @@ var linkEvidenceToBeliefInput = (input, context) => {
13360
13429
  beliefNodeId: input.beliefNodeId ?? input.beliefId ?? input.targetId,
13361
13430
  insightId: input.insightId ?? input.evidenceNodeId ?? input.evidenceId,
13362
13431
  type: weight < 0 ? "contradicting" : "supporting",
13432
+ weight,
13363
13433
  confidence: Math.min(1, Math.abs(weight)),
13364
13434
  rationale: input.rationale ?? input.context,
13365
13435
  trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
@@ -13436,7 +13506,12 @@ var evidenceContracts = [
13436
13506
  functionName: "create",
13437
13507
  kind: "mutation",
13438
13508
  inputProjection: (input, context) => {
13439
- const weight = typeof input.weight === "number" ? input.weight : 0.7;
13509
+ if (typeof input.weight !== "number" || !Number.isFinite(input.weight) || input.weight === 0 || input.weight < -1 || input.weight > 1) {
13510
+ throw new Error(
13511
+ "add_evidence requires explicit nonzero weight in [-1, 1]."
13512
+ );
13513
+ }
13514
+ const weight = input.weight;
13440
13515
  return createEvidenceInput(
13441
13516
  {
13442
13517
  ...input,
@@ -13445,6 +13520,7 @@ var evidenceContracts = [
13445
13520
  linkedBeliefNodeId: input.linkedBeliefNodeId ?? input.targetNodeId ?? input.targetId,
13446
13521
  evidenceRelation: weight < 0 ? "contradicts" : "supports",
13447
13522
  confidence: Math.min(1, Math.max(0, Math.abs(weight))),
13523
+ weight,
13448
13524
  rationale: input.reasoning,
13449
13525
  metadata: {
13450
13526
  ...recordValue2(input.metadata),