@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/outbox.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(),
@@ -11722,11 +11701,39 @@ var createEvidenceInputSchemaBase = z.object({
11722
11701
  metadata: jsonRecordSchema.optional(),
11723
11702
  trustedBypassAccessCheck: z.boolean().optional()
11724
11703
  }).passthrough();
11725
- function hasNonzeroWeight(value) {
11726
- return typeof value === "number" && Number.isFinite(value) && value !== 0;
11704
+ function isSignedImpactScore(value) {
11705
+ return typeof value === "number" && Number.isFinite(value) && value >= -1 && value <= 1 && value !== 0;
11727
11706
  }
11728
- function hasRelationSignal(value, weight) {
11729
- return Boolean(normalizeRelation(value, weight));
11707
+ function validateSignedImpactScore(value, ctx, path) {
11708
+ if (!isSignedImpactScore(value)) {
11709
+ ctx.addIssue({
11710
+ code: z.ZodIssueCode.custom,
11711
+ message: "evidence-to-belief links require an explicit nonzero signed impact score in [-1, 1]",
11712
+ path
11713
+ });
11714
+ return false;
11715
+ }
11716
+ return true;
11717
+ }
11718
+ function validateRelationImpactConsistency(relation, weight, ctx, path) {
11719
+ const normalized = normalizeRelationAlias(relation);
11720
+ if (!normalized || !isSignedImpactScore(weight)) {
11721
+ return;
11722
+ }
11723
+ if (normalized === "supports" && weight < 0) {
11724
+ ctx.addIssue({
11725
+ code: z.ZodIssueCode.custom,
11726
+ message: "supporting evidence requires a positive impact score",
11727
+ path
11728
+ });
11729
+ }
11730
+ if (normalized === "contradicts" && weight > 0) {
11731
+ ctx.addIssue({
11732
+ code: z.ZodIssueCode.custom,
11733
+ message: "contradicting evidence requires a negative impact score",
11734
+ path
11735
+ });
11736
+ }
11730
11737
  }
11731
11738
  var createEvidenceInputSchema = createEvidenceInputSchemaBase.superRefine(
11732
11739
  (input, ctx) => {
@@ -11743,13 +11750,27 @@ var createEvidenceInputSchema = createEvidenceInputSchemaBase.superRefine(
11743
11750
  input.linkedBeliefNodeId || kind === "belief" || kind === "unknown" && target
11744
11751
  );
11745
11752
  const weight = typeof input.weight === "number" ? input.weight : void 0;
11746
- if (linksPrimaryBelief && !hasRelationSignal(input.evidenceRelation, weight)) {
11753
+ const hasBeliefRelations = (input.beliefRelations?.length ?? 0) > 0;
11754
+ if (!linksPrimaryBelief && !hasBeliefRelations) {
11755
+ ctx.addIssue({
11756
+ code: z.ZodIssueCode.custom,
11757
+ message: "create_evidence requires at least one linked belief; evidence cannot be created as an orphan or linked only to a question/worktree",
11758
+ path: ["linkedBeliefNodeId"]
11759
+ });
11760
+ }
11761
+ if (kind === "question" || kind === "worktree") {
11747
11762
  ctx.addIssue({
11748
11763
  code: z.ZodIssueCode.custom,
11749
- message: "belief-targeted evidence requires evidenceRelation='supports'|'contradicts' or a nonzero signed weight",
11750
- path: ["evidenceRelation"]
11764
+ message: "create_evidence targetId must be a belief. Link evidence to questions/worktrees only after the evidence has a belief impact edge.",
11765
+ path: ["targetId"]
11751
11766
  });
11752
11767
  }
11768
+ if (linksPrimaryBelief) {
11769
+ validateSignedImpactScore(weight, ctx, ["weight"]);
11770
+ validateRelationImpactConsistency(input.evidenceRelation, weight, ctx, [
11771
+ "weight"
11772
+ ]);
11773
+ }
11753
11774
  input.beliefRelations?.forEach((relation, index) => {
11754
11775
  const beliefNodeId = relation.beliefNodeId ?? relation.beliefId ?? relation.targetId;
11755
11776
  if (!beliefNodeId) {
@@ -11760,15 +11781,18 @@ var createEvidenceInputSchema = createEvidenceInputSchemaBase.superRefine(
11760
11781
  });
11761
11782
  }
11762
11783
  const relationWeight2 = typeof relation.weight === "number" ? relation.weight : void 0;
11763
- if (beliefNodeId && !hasRelationSignal(
11764
- relation.evidenceRelation ?? relation.relation,
11765
- relationWeight2
11766
- )) {
11767
- ctx.addIssue({
11768
- code: z.ZodIssueCode.custom,
11769
- message: "beliefRelations entries require evidenceRelation='supports'|'contradicts' or a nonzero signed weight",
11770
- path: ["beliefRelations", index, "evidenceRelation"]
11771
- });
11784
+ if (beliefNodeId) {
11785
+ validateSignedImpactScore(relationWeight2, ctx, [
11786
+ "beliefRelations",
11787
+ index,
11788
+ "weight"
11789
+ ]);
11790
+ validateRelationImpactConsistency(
11791
+ relation.evidenceRelation ?? relation.relation,
11792
+ relationWeight2,
11793
+ ctx,
11794
+ ["beliefRelations", index, "weight"]
11795
+ );
11772
11796
  }
11773
11797
  });
11774
11798
  }
@@ -11822,18 +11846,28 @@ function targetKind(targetId) {
11822
11846
  }
11823
11847
  return "unknown";
11824
11848
  }
11825
- function normalizeRelation(value, weight) {
11849
+ function normalizeRelationAlias(value) {
11826
11850
  if (value === "supports" || value === "supporting") {
11827
11851
  return "supports";
11828
11852
  }
11829
11853
  if (value === "contradicts" || value === "contradicting") {
11830
11854
  return "contradicts";
11831
11855
  }
11856
+ return void 0;
11857
+ }
11858
+ function normalizeRelation(value, weight) {
11859
+ const alias = normalizeRelationAlias(value);
11860
+ if (alias) {
11861
+ return alias;
11862
+ }
11832
11863
  if (weight === void 0 || !hasNonzeroWeight(weight)) {
11833
11864
  return void 0;
11834
11865
  }
11835
11866
  return weight < 0 ? "contradicts" : "supports";
11836
11867
  }
11868
+ function hasNonzeroWeight(value) {
11869
+ return typeof value === "number" && Number.isFinite(value) && value !== 0;
11870
+ }
11837
11871
  function normalizeConfidence(confidence, weight) {
11838
11872
  if (confidence !== void 0) {
11839
11873
  return Math.min(1, Math.max(0, confidence));
@@ -11860,6 +11894,7 @@ function normalizeBeliefRelation(relation) {
11860
11894
  beliefNodeId,
11861
11895
  relation: evidenceRelation,
11862
11896
  confidence: normalizeConfidence(relation.confidence, weight),
11897
+ weight,
11863
11898
  rationale: relation.rationale
11864
11899
  });
11865
11900
  }
@@ -11908,6 +11943,7 @@ var createEvidenceProjection = defineProjection({
11908
11943
  linkedBeliefNodeId,
11909
11944
  evidenceRelation,
11910
11945
  confidence,
11946
+ weight,
11911
11947
  beliefRelations: beliefRelations && beliefRelations.length > 0 ? beliefRelations : void 0,
11912
11948
  rationale: input.rationale,
11913
11949
  trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
@@ -11937,12 +11973,14 @@ var createEvidenceProjection = defineProjection({
11937
11973
  v.literal("contradicts")
11938
11974
  )
11939
11975
  ),
11976
+ weight: v.optional(v.number()),
11940
11977
  beliefRelations: v.optional(
11941
11978
  v.array(
11942
11979
  v.object({
11943
11980
  beliefNodeId: v.string(),
11944
11981
  relation: v.union(v.literal("supports"), v.literal("contradicts")),
11945
11982
  confidence: v.optional(v.number()),
11983
+ weight: v.number(),
11946
11984
  rationale: v.optional(v.string())
11947
11985
  })
11948
11986
  )
@@ -12060,7 +12098,7 @@ var slOpinionProjectionSchema = z.object({
12060
12098
  uncertainty: z.number(),
12061
12099
  baseRate: z.number()
12062
12100
  });
12063
- var modulateConfidenceInputObjectSchema = z.object({
12101
+ var appendSlScoringInputObjectSchema = z.object({
12064
12102
  nodeId: z.string().optional(),
12065
12103
  beliefNodeId: z.string().optional(),
12066
12104
  worktreeId: z.string().optional(),
@@ -12079,23 +12117,23 @@ var modulateConfidenceInputObjectSchema = z.object({
12079
12117
  rationale: z.string(),
12080
12118
  trustedBypassAccessCheck: z.boolean().optional()
12081
12119
  });
12082
- var modulateConfidenceInputSchema = modulateConfidenceInputObjectSchema.superRefine((input, ctx) => {
12120
+ var appendSlScoringInputSchema = appendSlScoringInputObjectSchema.superRefine((input, ctx) => {
12083
12121
  if (hasProvenance(input)) {
12084
12122
  return;
12085
12123
  }
12086
12124
  ctx.addIssue({
12087
12125
  code: z.ZodIssueCode.custom,
12088
- message: "modulate_confidence requires evidence, question, answer, contradiction, or worktree provenance",
12126
+ message: "append_sl_scoring requires evidence, question, answer, contradiction, or worktree provenance",
12089
12127
  path: ["provenance"]
12090
12128
  });
12091
12129
  });
12092
- var modulateConfidenceProjection = defineProjection({
12093
- contractName: "modulate_confidence",
12094
- inputSchema: modulateConfidenceInputSchema,
12130
+ var appendSlScoringProjection = defineProjection({
12131
+ contractName: "append_sl_scoring",
12132
+ inputSchema: appendSlScoringInputSchema,
12095
12133
  project: (input) => {
12096
12134
  const nodeId = input.beliefNodeId ?? input.nodeId;
12097
12135
  if (!nodeId) {
12098
- throw new Error("modulate_confidence requires beliefNodeId or nodeId");
12136
+ throw new Error("append_sl_scoring requires beliefNodeId or nodeId");
12099
12137
  }
12100
12138
  const opinion = input.opinion ?? {
12101
12139
  belief: requireNumber(input.belief, "belief"),
@@ -12152,14 +12190,14 @@ var modulateConfidenceProjection = defineProjection({
12152
12190
  });
12153
12191
  function requireNumber(value, field) {
12154
12192
  if (value === void 0) {
12155
- throw new Error(`modulate_confidence requires ${field}`);
12193
+ throw new Error(`append_sl_scoring requires ${field}`);
12156
12194
  }
12157
12195
  return value;
12158
12196
  }
12159
12197
  function assertProvenance(input) {
12160
12198
  if (!hasProvenance(input)) {
12161
12199
  throw new Error(
12162
- "modulate_confidence requires evidence, question, answer, contradiction, or worktree provenance"
12200
+ "append_sl_scoring requires evidence, question, answer, contradiction, or worktree provenance"
12163
12201
  );
12164
12202
  }
12165
12203
  }
@@ -12502,12 +12540,12 @@ var LUCERN_OPERATION_MANIFEST = {
12502
12540
  internalSystem,
12503
12541
  "Lucern system/background operation. Available to platform code paths, hidden from public MCP discovery."
12504
12542
  ),
12505
- modulate_confidence: {
12506
- name: "modulate_confidence",
12543
+ append_sl_scoring: {
12544
+ name: "append_sl_scoring",
12507
12545
  surfaceClass: "platform_internal",
12508
12546
  surfaceIntent: "system",
12509
12547
  surfaces: internalSdkRestOnly,
12510
- rationale: "Internal SL ledger append primitive. Public callers attach evidence or contradiction relations; confidence is derived algorithmically."
12548
+ rationale: "Internal SL scoring append primitive. Public callers attach evidence or contradiction relations; confidence is derived algorithmically."
12511
12549
  },
12512
12550
  ...entries(
12513
12551
  LEGACY_COMPAT_OPERATION_NAMES,
@@ -13061,7 +13099,15 @@ var predictionMetaSchema = z.object({
13061
13099
  });
13062
13100
  var createBeliefArgs = z.object({
13063
13101
  canonicalText: z.string().describe("The belief statement the agent holds to be true."),
13064
- topicId: z.string().optional().describe("Topic scope hint for the belief."),
13102
+ topicGlobalId: z.string().describe(
13103
+ "Required globalId of the topic epistemicNode that anchors this belief. Belief creation creates a scoped_by edge directly to that topic node."
13104
+ ),
13105
+ topicNodeId: z.string().optional().describe(
13106
+ "Optional internal epistemicNodes _id for the topic anchor. Prefer topicGlobalId for public callers."
13107
+ ),
13108
+ topicId: z.string().optional().describe(
13109
+ "Deprecated compatibility alias for topicGlobalId. Must identify a topic epistemicNode, not a legacy topics-table row."
13110
+ ),
13065
13111
  baseRate: z.number().optional().describe("Prior base rate used to seed the vacuous opinion."),
13066
13112
  beliefType: z.string().optional().describe("Schema belief type."),
13067
13113
  metadata: jsonRecordSchema3.optional().describe("Extra metadata merged into the belief node."),
@@ -13080,9 +13126,14 @@ var forkBeliefArgs = z.object({
13080
13126
  "refinement",
13081
13127
  "contradiction_response",
13082
13128
  "scope_change",
13083
- "confidence_collapse",
13084
- "manual"
13129
+ "confidence_collapse"
13085
13130
  ]).describe("Why this fork was created."),
13131
+ forkMode: z.enum(["supersede", "branch"]).optional().describe(
13132
+ "supersede marks the parent belief superseded; branch preserves the parent and creates a derived child."
13133
+ ),
13134
+ triggeringEvidenceId: z.string().describe(
13135
+ "Evidence already attached to the parent belief through SL scoring; required for every fork."
13136
+ ),
13086
13137
  rationale: z.string().optional().describe("Why the fork is warranted.")
13087
13138
  });
13088
13139
  var beliefLookupInput = (input) => compactRecord4({
@@ -13096,7 +13147,9 @@ var createBeliefInput = (input, context) => {
13096
13147
  return withUserId(
13097
13148
  compactRecord4({
13098
13149
  projectId: input.projectId,
13099
- topicId: input.topicId,
13150
+ topicId: input.topicGlobalId ?? input.topicNodeId ?? input.topicId,
13151
+ topicGlobalId: input.topicGlobalId,
13152
+ topicNodeId: input.topicNodeId,
13100
13153
  formulation: input.formulation ?? input.canonicalText,
13101
13154
  beliefType: input.beliefType,
13102
13155
  rationale: input.rationale,
@@ -13118,20 +13171,22 @@ var forkBeliefInput = (input, context) => withUserId(
13118
13171
  parentNodeId: input.parentNodeId ?? input.nodeId ?? input.id,
13119
13172
  newFormulation: input.newFormulation,
13120
13173
  forkReason: input.forkReason,
13174
+ forkMode: input.forkMode,
13175
+ triggeringEvidenceId: input.triggeringEvidenceId,
13121
13176
  rationale: input.rationale,
13122
13177
  trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
13123
13178
  }),
13124
13179
  context
13125
13180
  );
13126
- var confidenceInput = (input, context) => {
13127
- const parsed = modulateConfidenceProjection.inputSchema.safeParse(input);
13181
+ var appendSlScoringInput = (input, context) => {
13182
+ const parsed = appendSlScoringProjection.inputSchema.safeParse(input);
13128
13183
  if (!parsed.success) {
13129
13184
  throw new Error(
13130
- `modulate_confidence projection input rejected: ${parsed.error.message}`
13185
+ `append_sl_scoring projection input rejected: ${parsed.error.message}`
13131
13186
  );
13132
13187
  }
13133
13188
  return withUserId(
13134
- compactRecord4(modulateConfidenceProjection.project(parsed.data)),
13189
+ compactRecord4(appendSlScoringProjection.project(parsed.data)),
13135
13190
  context
13136
13191
  );
13137
13192
  };
@@ -13209,21 +13264,21 @@ var beliefsContracts = [
13209
13264
  }
13210
13265
  }),
13211
13266
  surfaceContract({
13212
- name: "modulate_confidence",
13267
+ name: "append_sl_scoring",
13213
13268
  kind: "mutation",
13214
13269
  domain: "beliefs",
13215
13270
  surfaceClass: "platform_internal",
13216
- path: "/beliefs/confidence",
13271
+ path: "/beliefs/sl-scoring",
13217
13272
  sdkNamespace: "beliefs",
13218
- sdkMethod: "modulateConfidence",
13219
- summary: "Internal SL ledger append. Public callers should attach evidence or contradiction relations instead.",
13273
+ sdkMethod: "appendSlScoring",
13274
+ summary: "Internal SL scoring append. Public callers attach evidence or contradiction relations instead.",
13220
13275
  convex: {
13221
13276
  module: "beliefs",
13222
- functionName: "modulateConfidence",
13277
+ functionName: "appendSlScoring",
13223
13278
  kind: "mutation",
13224
- inputProjection: confidenceInput
13279
+ inputProjection: appendSlScoringInput
13225
13280
  },
13226
- args: modulateConfidenceInputSchema
13281
+ args: appendSlScoringInputSchema
13227
13282
  }),
13228
13283
  surfaceContract({
13229
13284
  name: "fork_belief",
@@ -13329,8 +13384,12 @@ var beliefRelationSchema2 = z.object({
13329
13384
  targetId: z.string().optional().describe("Belief target ID alias for beliefId/beliefNodeId."),
13330
13385
  relation: z.enum(["supports", "contradicts", "supporting", "contradicting"]).optional().describe("Relation alias for how the evidence bears on the belief."),
13331
13386
  evidenceRelation: evidenceRelationSchema2.optional().describe("Canonical relation: supports or contradicts."),
13332
- confidence: z.number().optional().describe("Confidence in this evidence-to-belief relation."),
13333
- weight: z.number().optional().describe("Support weight from -1.0 to +1.0 for this belief."),
13387
+ confidence: z.number().optional().describe(
13388
+ "Deprecated read-only hint. Runtime SL confidence is derived from signed weight."
13389
+ ),
13390
+ weight: z.number().min(-1).max(1).refine((value) => value !== 0, {
13391
+ message: "Evidence impact weight must be nonzero."
13392
+ }).describe("Required signed impact score from -1.0 to +1.0 for this belief."),
13334
13393
  rationale: z.string().optional().describe("Why this relation exists.")
13335
13394
  });
13336
13395
  var createEvidenceArgs = z.object({
@@ -13339,7 +13398,7 @@ var createEvidenceArgs = z.object({
13339
13398
  source: z.string().optional().describe("Source URL or source label."),
13340
13399
  sourceUrl: z.string().optional().describe("Canonical source URL."),
13341
13400
  targetId: z.string().optional().describe(
13342
- "Belief, question, or worktree identifier to link or preserve on the evidence record. Belief targets require evidenceRelation or a nonzero signed weight."
13401
+ "Belief identifier to link immediately. Evidence creation cannot target only a question or worktree."
13343
13402
  ),
13344
13403
  linkedBeliefNodeId: z.string().optional().describe("Belief node this evidence bears on."),
13345
13404
  evidenceRelation: evidenceRelationSchema2.optional().describe(
@@ -13348,8 +13407,14 @@ var createEvidenceArgs = z.object({
13348
13407
  beliefRelations: z.array(beliefRelationSchema2).optional().describe(
13349
13408
  "Additional belief relations for one evidence record. Use when the same evidence supports or contradicts multiple beliefs."
13350
13409
  ),
13351
- confidence: z.number().optional().describe("Confidence in the evidence relation."),
13352
- weight: z.number().optional().describe("Nonzero support weight from -1.0 to +1.0."),
13410
+ confidence: z.number().optional().describe(
13411
+ "Deprecated hint. Runtime confidence is derived from signed weight."
13412
+ ),
13413
+ weight: z.number().min(-1).max(1).refine((value) => value !== 0, {
13414
+ message: "Evidence impact weight must be nonzero."
13415
+ }).describe(
13416
+ "Required signed impact score from -1.0 to +1.0 for targetId/linkedBeliefNodeId."
13417
+ ),
13353
13418
  metadata: jsonRecordSchema4.optional().describe("Metadata merged into the canonical evidence node."),
13354
13419
  rationale: z.string().describe("Why this evidence should enter the reasoning graph."),
13355
13420
  reasoning: z.string().optional().describe("Reasoning note preserved in evidence metadata."),
@@ -13371,7 +13436,9 @@ var addEvidenceArgs = z.object({
13371
13436
  topicId: z.string().optional().describe("Topic scope hint."),
13372
13437
  sourceUrl: z.string().optional().describe("URL of the source material."),
13373
13438
  targetNodeId: z.string().describe("The belief this evidence bears on."),
13374
- weight: z.number().optional().describe("Support weight from -1.0 to +1.0."),
13439
+ weight: z.number().min(-1).max(1).refine((value) => value !== 0, {
13440
+ message: "Evidence impact weight must be nonzero."
13441
+ }).describe("Required signed impact score from -1.0 to +1.0."),
13375
13442
  reasoning: z.string().describe("Why this evidence is relevant to the target belief."),
13376
13443
  title: z.string().optional().describe("Optional short title."),
13377
13444
  content: z.string().optional().describe("Optional long-form evidence content."),
@@ -13391,19 +13458,21 @@ var createEvidenceInput = (input, context) => {
13391
13458
  );
13392
13459
  };
13393
13460
  function relationWeight(input) {
13394
- if (typeof input.weight === "number" && Number.isFinite(input.weight) && input.weight !== 0) {
13461
+ if (typeof input.weight === "number" && Number.isFinite(input.weight) && input.weight !== 0 && input.weight >= -1 && input.weight <= 1) {
13462
+ const relation = String(
13463
+ input.evidenceRelation ?? input.relation ?? input.type ?? ""
13464
+ );
13465
+ if ((relation === "supports" || relation === "supporting") && input.weight < 0) {
13466
+ throw new Error("Supporting evidence links require positive weight.");
13467
+ }
13468
+ if ((relation === "contradicts" || relation === "contradicting") && input.weight > 0) {
13469
+ throw new Error("Contradicting evidence links require negative weight.");
13470
+ }
13395
13471
  return input.weight;
13396
13472
  }
13397
- const relation = String(
13398
- input.evidenceRelation ?? input.relation ?? input.type ?? ""
13473
+ throw new Error(
13474
+ "Belief evidence links require explicit nonzero weight in [-1, 1]."
13399
13475
  );
13400
- if (relation !== "supports" && relation !== "supporting" && relation !== "contradicts" && relation !== "contradicting") {
13401
- throw new Error(
13402
- "Belief evidence links require evidenceRelation='supports'|'contradicts' or a nonzero signed weight."
13403
- );
13404
- }
13405
- const confidence = typeof input.confidence === "number" ? Math.max(0, Math.min(1, input.confidence)) : 0.7;
13406
- return relation === "contradicts" || relation === "contradicting" ? -confidence : confidence;
13407
13476
  }
13408
13477
  var linkEvidenceToBeliefInput = (input, context) => {
13409
13478
  const weight = relationWeight(input);
@@ -13412,6 +13481,7 @@ var linkEvidenceToBeliefInput = (input, context) => {
13412
13481
  beliefNodeId: input.beliefNodeId ?? input.beliefId ?? input.targetId,
13413
13482
  insightId: input.insightId ?? input.evidenceNodeId ?? input.evidenceId,
13414
13483
  type: weight < 0 ? "contradicting" : "supporting",
13484
+ weight,
13415
13485
  confidence: Math.min(1, Math.abs(weight)),
13416
13486
  rationale: input.rationale ?? input.context,
13417
13487
  trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
@@ -13488,7 +13558,12 @@ var evidenceContracts = [
13488
13558
  functionName: "create",
13489
13559
  kind: "mutation",
13490
13560
  inputProjection: (input, context) => {
13491
- const weight = typeof input.weight === "number" ? input.weight : 0.7;
13561
+ if (typeof input.weight !== "number" || !Number.isFinite(input.weight) || input.weight === 0 || input.weight < -1 || input.weight > 1) {
13562
+ throw new Error(
13563
+ "add_evidence requires explicit nonzero weight in [-1, 1]."
13564
+ );
13565
+ }
13566
+ const weight = input.weight;
13492
13567
  return createEvidenceInput(
13493
13568
  {
13494
13569
  ...input,
@@ -13497,6 +13572,7 @@ var evidenceContracts = [
13497
13572
  linkedBeliefNodeId: input.linkedBeliefNodeId ?? input.targetNodeId ?? input.targetId,
13498
13573
  evidenceRelation: weight < 0 ? "contradicts" : "supports",
13499
13574
  confidence: Math.min(1, Math.max(0, Math.abs(weight))),
13575
+ weight,
13500
13576
  rationale: input.reasoning,
13501
13577
  metadata: {
13502
13578
  ...recordValue2(input.metadata),