@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/webhooks.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(),
@@ -11631,11 +11610,39 @@ var createEvidenceInputSchemaBase = z.object({
11631
11610
  metadata: jsonRecordSchema.optional(),
11632
11611
  trustedBypassAccessCheck: z.boolean().optional()
11633
11612
  }).passthrough();
11634
- function hasNonzeroWeight(value) {
11635
- return typeof value === "number" && Number.isFinite(value) && value !== 0;
11613
+ function isSignedImpactScore(value) {
11614
+ return typeof value === "number" && Number.isFinite(value) && value >= -1 && value <= 1 && value !== 0;
11636
11615
  }
11637
- function hasRelationSignal(value, weight) {
11638
- return Boolean(normalizeRelation(value, weight));
11616
+ function validateSignedImpactScore(value, ctx, path) {
11617
+ if (!isSignedImpactScore(value)) {
11618
+ ctx.addIssue({
11619
+ code: z.ZodIssueCode.custom,
11620
+ message: "evidence-to-belief links require an explicit nonzero signed impact score in [-1, 1]",
11621
+ path
11622
+ });
11623
+ return false;
11624
+ }
11625
+ return true;
11626
+ }
11627
+ function validateRelationImpactConsistency(relation, weight, ctx, path) {
11628
+ const normalized = normalizeRelationAlias(relation);
11629
+ if (!normalized || !isSignedImpactScore(weight)) {
11630
+ return;
11631
+ }
11632
+ if (normalized === "supports" && weight < 0) {
11633
+ ctx.addIssue({
11634
+ code: z.ZodIssueCode.custom,
11635
+ message: "supporting evidence requires a positive impact score",
11636
+ path
11637
+ });
11638
+ }
11639
+ if (normalized === "contradicts" && weight > 0) {
11640
+ ctx.addIssue({
11641
+ code: z.ZodIssueCode.custom,
11642
+ message: "contradicting evidence requires a negative impact score",
11643
+ path
11644
+ });
11645
+ }
11639
11646
  }
11640
11647
  var createEvidenceInputSchema = createEvidenceInputSchemaBase.superRefine(
11641
11648
  (input, ctx) => {
@@ -11652,13 +11659,27 @@ var createEvidenceInputSchema = createEvidenceInputSchemaBase.superRefine(
11652
11659
  input.linkedBeliefNodeId || kind === "belief" || kind === "unknown" && target
11653
11660
  );
11654
11661
  const weight = typeof input.weight === "number" ? input.weight : void 0;
11655
- if (linksPrimaryBelief && !hasRelationSignal(input.evidenceRelation, weight)) {
11662
+ const hasBeliefRelations = (input.beliefRelations?.length ?? 0) > 0;
11663
+ if (!linksPrimaryBelief && !hasBeliefRelations) {
11664
+ ctx.addIssue({
11665
+ code: z.ZodIssueCode.custom,
11666
+ message: "create_evidence requires at least one linked belief; evidence cannot be created as an orphan or linked only to a question/worktree",
11667
+ path: ["linkedBeliefNodeId"]
11668
+ });
11669
+ }
11670
+ if (kind === "question" || kind === "worktree") {
11656
11671
  ctx.addIssue({
11657
11672
  code: z.ZodIssueCode.custom,
11658
- message: "belief-targeted evidence requires evidenceRelation='supports'|'contradicts' or a nonzero signed weight",
11659
- path: ["evidenceRelation"]
11673
+ message: "create_evidence targetId must be a belief. Link evidence to questions/worktrees only after the evidence has a belief impact edge.",
11674
+ path: ["targetId"]
11660
11675
  });
11661
11676
  }
11677
+ if (linksPrimaryBelief) {
11678
+ validateSignedImpactScore(weight, ctx, ["weight"]);
11679
+ validateRelationImpactConsistency(input.evidenceRelation, weight, ctx, [
11680
+ "weight"
11681
+ ]);
11682
+ }
11662
11683
  input.beliefRelations?.forEach((relation, index) => {
11663
11684
  const beliefNodeId = relation.beliefNodeId ?? relation.beliefId ?? relation.targetId;
11664
11685
  if (!beliefNodeId) {
@@ -11669,15 +11690,18 @@ var createEvidenceInputSchema = createEvidenceInputSchemaBase.superRefine(
11669
11690
  });
11670
11691
  }
11671
11692
  const relationWeight2 = typeof relation.weight === "number" ? relation.weight : void 0;
11672
- if (beliefNodeId && !hasRelationSignal(
11673
- relation.evidenceRelation ?? relation.relation,
11674
- relationWeight2
11675
- )) {
11676
- ctx.addIssue({
11677
- code: z.ZodIssueCode.custom,
11678
- message: "beliefRelations entries require evidenceRelation='supports'|'contradicts' or a nonzero signed weight",
11679
- path: ["beliefRelations", index, "evidenceRelation"]
11680
- });
11693
+ if (beliefNodeId) {
11694
+ validateSignedImpactScore(relationWeight2, ctx, [
11695
+ "beliefRelations",
11696
+ index,
11697
+ "weight"
11698
+ ]);
11699
+ validateRelationImpactConsistency(
11700
+ relation.evidenceRelation ?? relation.relation,
11701
+ relationWeight2,
11702
+ ctx,
11703
+ ["beliefRelations", index, "weight"]
11704
+ );
11681
11705
  }
11682
11706
  });
11683
11707
  }
@@ -11731,18 +11755,28 @@ function targetKind(targetId) {
11731
11755
  }
11732
11756
  return "unknown";
11733
11757
  }
11734
- function normalizeRelation(value, weight) {
11758
+ function normalizeRelationAlias(value) {
11735
11759
  if (value === "supports" || value === "supporting") {
11736
11760
  return "supports";
11737
11761
  }
11738
11762
  if (value === "contradicts" || value === "contradicting") {
11739
11763
  return "contradicts";
11740
11764
  }
11765
+ return void 0;
11766
+ }
11767
+ function normalizeRelation(value, weight) {
11768
+ const alias = normalizeRelationAlias(value);
11769
+ if (alias) {
11770
+ return alias;
11771
+ }
11741
11772
  if (weight === void 0 || !hasNonzeroWeight(weight)) {
11742
11773
  return void 0;
11743
11774
  }
11744
11775
  return weight < 0 ? "contradicts" : "supports";
11745
11776
  }
11777
+ function hasNonzeroWeight(value) {
11778
+ return typeof value === "number" && Number.isFinite(value) && value !== 0;
11779
+ }
11746
11780
  function normalizeConfidence(confidence, weight) {
11747
11781
  if (confidence !== void 0) {
11748
11782
  return Math.min(1, Math.max(0, confidence));
@@ -11769,6 +11803,7 @@ function normalizeBeliefRelation(relation) {
11769
11803
  beliefNodeId,
11770
11804
  relation: evidenceRelation,
11771
11805
  confidence: normalizeConfidence(relation.confidence, weight),
11806
+ weight,
11772
11807
  rationale: relation.rationale
11773
11808
  });
11774
11809
  }
@@ -11817,6 +11852,7 @@ var createEvidenceProjection = defineProjection({
11817
11852
  linkedBeliefNodeId,
11818
11853
  evidenceRelation,
11819
11854
  confidence,
11855
+ weight,
11820
11856
  beliefRelations: beliefRelations && beliefRelations.length > 0 ? beliefRelations : void 0,
11821
11857
  rationale: input.rationale,
11822
11858
  trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
@@ -11846,12 +11882,14 @@ var createEvidenceProjection = defineProjection({
11846
11882
  v.literal("contradicts")
11847
11883
  )
11848
11884
  ),
11885
+ weight: v.optional(v.number()),
11849
11886
  beliefRelations: v.optional(
11850
11887
  v.array(
11851
11888
  v.object({
11852
11889
  beliefNodeId: v.string(),
11853
11890
  relation: v.union(v.literal("supports"), v.literal("contradicts")),
11854
11891
  confidence: v.optional(v.number()),
11892
+ weight: v.number(),
11855
11893
  rationale: v.optional(v.string())
11856
11894
  })
11857
11895
  )
@@ -11969,7 +12007,7 @@ var slOpinionProjectionSchema = z.object({
11969
12007
  uncertainty: z.number(),
11970
12008
  baseRate: z.number()
11971
12009
  });
11972
- var modulateConfidenceInputObjectSchema = z.object({
12010
+ var appendSlScoringInputObjectSchema = z.object({
11973
12011
  nodeId: z.string().optional(),
11974
12012
  beliefNodeId: z.string().optional(),
11975
12013
  worktreeId: z.string().optional(),
@@ -11988,23 +12026,23 @@ var modulateConfidenceInputObjectSchema = z.object({
11988
12026
  rationale: z.string(),
11989
12027
  trustedBypassAccessCheck: z.boolean().optional()
11990
12028
  });
11991
- var modulateConfidenceInputSchema = modulateConfidenceInputObjectSchema.superRefine((input, ctx) => {
12029
+ var appendSlScoringInputSchema = appendSlScoringInputObjectSchema.superRefine((input, ctx) => {
11992
12030
  if (hasProvenance(input)) {
11993
12031
  return;
11994
12032
  }
11995
12033
  ctx.addIssue({
11996
12034
  code: z.ZodIssueCode.custom,
11997
- message: "modulate_confidence requires evidence, question, answer, contradiction, or worktree provenance",
12035
+ message: "append_sl_scoring requires evidence, question, answer, contradiction, or worktree provenance",
11998
12036
  path: ["provenance"]
11999
12037
  });
12000
12038
  });
12001
- var modulateConfidenceProjection = defineProjection({
12002
- contractName: "modulate_confidence",
12003
- inputSchema: modulateConfidenceInputSchema,
12039
+ var appendSlScoringProjection = defineProjection({
12040
+ contractName: "append_sl_scoring",
12041
+ inputSchema: appendSlScoringInputSchema,
12004
12042
  project: (input) => {
12005
12043
  const nodeId = input.beliefNodeId ?? input.nodeId;
12006
12044
  if (!nodeId) {
12007
- throw new Error("modulate_confidence requires beliefNodeId or nodeId");
12045
+ throw new Error("append_sl_scoring requires beliefNodeId or nodeId");
12008
12046
  }
12009
12047
  const opinion = input.opinion ?? {
12010
12048
  belief: requireNumber(input.belief, "belief"),
@@ -12061,14 +12099,14 @@ var modulateConfidenceProjection = defineProjection({
12061
12099
  });
12062
12100
  function requireNumber(value, field) {
12063
12101
  if (value === void 0) {
12064
- throw new Error(`modulate_confidence requires ${field}`);
12102
+ throw new Error(`append_sl_scoring requires ${field}`);
12065
12103
  }
12066
12104
  return value;
12067
12105
  }
12068
12106
  function assertProvenance(input) {
12069
12107
  if (!hasProvenance(input)) {
12070
12108
  throw new Error(
12071
- "modulate_confidence requires evidence, question, answer, contradiction, or worktree provenance"
12109
+ "append_sl_scoring requires evidence, question, answer, contradiction, or worktree provenance"
12072
12110
  );
12073
12111
  }
12074
12112
  }
@@ -12411,12 +12449,12 @@ var LUCERN_OPERATION_MANIFEST = {
12411
12449
  internalSystem,
12412
12450
  "Lucern system/background operation. Available to platform code paths, hidden from public MCP discovery."
12413
12451
  ),
12414
- modulate_confidence: {
12415
- name: "modulate_confidence",
12452
+ append_sl_scoring: {
12453
+ name: "append_sl_scoring",
12416
12454
  surfaceClass: "platform_internal",
12417
12455
  surfaceIntent: "system",
12418
12456
  surfaces: internalSdkRestOnly,
12419
- rationale: "Internal SL ledger append primitive. Public callers attach evidence or contradiction relations; confidence is derived algorithmically."
12457
+ rationale: "Internal SL scoring append primitive. Public callers attach evidence or contradiction relations; confidence is derived algorithmically."
12420
12458
  },
12421
12459
  ...entries(
12422
12460
  LEGACY_COMPAT_OPERATION_NAMES,
@@ -12970,7 +13008,15 @@ var predictionMetaSchema = z.object({
12970
13008
  });
12971
13009
  var createBeliefArgs = z.object({
12972
13010
  canonicalText: z.string().describe("The belief statement the agent holds to be true."),
12973
- topicId: z.string().optional().describe("Topic scope hint for the belief."),
13011
+ topicGlobalId: z.string().describe(
13012
+ "Required globalId of the topic epistemicNode that anchors this belief. Belief creation creates a scoped_by edge directly to that topic node."
13013
+ ),
13014
+ topicNodeId: z.string().optional().describe(
13015
+ "Optional internal epistemicNodes _id for the topic anchor. Prefer topicGlobalId for public callers."
13016
+ ),
13017
+ topicId: z.string().optional().describe(
13018
+ "Deprecated compatibility alias for topicGlobalId. Must identify a topic epistemicNode, not a legacy topics-table row."
13019
+ ),
12974
13020
  baseRate: z.number().optional().describe("Prior base rate used to seed the vacuous opinion."),
12975
13021
  beliefType: z.string().optional().describe("Schema belief type."),
12976
13022
  metadata: jsonRecordSchema3.optional().describe("Extra metadata merged into the belief node."),
@@ -12989,9 +13035,14 @@ var forkBeliefArgs = z.object({
12989
13035
  "refinement",
12990
13036
  "contradiction_response",
12991
13037
  "scope_change",
12992
- "confidence_collapse",
12993
- "manual"
13038
+ "confidence_collapse"
12994
13039
  ]).describe("Why this fork was created."),
13040
+ forkMode: z.enum(["supersede", "branch"]).optional().describe(
13041
+ "supersede marks the parent belief superseded; branch preserves the parent and creates a derived child."
13042
+ ),
13043
+ triggeringEvidenceId: z.string().describe(
13044
+ "Evidence already attached to the parent belief through SL scoring; required for every fork."
13045
+ ),
12995
13046
  rationale: z.string().optional().describe("Why the fork is warranted.")
12996
13047
  });
12997
13048
  var beliefLookupInput = (input) => compactRecord4({
@@ -13005,7 +13056,9 @@ var createBeliefInput = (input, context) => {
13005
13056
  return withUserId(
13006
13057
  compactRecord4({
13007
13058
  projectId: input.projectId,
13008
- topicId: input.topicId,
13059
+ topicId: input.topicGlobalId ?? input.topicNodeId ?? input.topicId,
13060
+ topicGlobalId: input.topicGlobalId,
13061
+ topicNodeId: input.topicNodeId,
13009
13062
  formulation: input.formulation ?? input.canonicalText,
13010
13063
  beliefType: input.beliefType,
13011
13064
  rationale: input.rationale,
@@ -13027,20 +13080,22 @@ var forkBeliefInput = (input, context) => withUserId(
13027
13080
  parentNodeId: input.parentNodeId ?? input.nodeId ?? input.id,
13028
13081
  newFormulation: input.newFormulation,
13029
13082
  forkReason: input.forkReason,
13083
+ forkMode: input.forkMode,
13084
+ triggeringEvidenceId: input.triggeringEvidenceId,
13030
13085
  rationale: input.rationale,
13031
13086
  trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
13032
13087
  }),
13033
13088
  context
13034
13089
  );
13035
- var confidenceInput = (input, context) => {
13036
- const parsed = modulateConfidenceProjection.inputSchema.safeParse(input);
13090
+ var appendSlScoringInput = (input, context) => {
13091
+ const parsed = appendSlScoringProjection.inputSchema.safeParse(input);
13037
13092
  if (!parsed.success) {
13038
13093
  throw new Error(
13039
- `modulate_confidence projection input rejected: ${parsed.error.message}`
13094
+ `append_sl_scoring projection input rejected: ${parsed.error.message}`
13040
13095
  );
13041
13096
  }
13042
13097
  return withUserId(
13043
- compactRecord4(modulateConfidenceProjection.project(parsed.data)),
13098
+ compactRecord4(appendSlScoringProjection.project(parsed.data)),
13044
13099
  context
13045
13100
  );
13046
13101
  };
@@ -13118,21 +13173,21 @@ var beliefsContracts = [
13118
13173
  }
13119
13174
  }),
13120
13175
  surfaceContract({
13121
- name: "modulate_confidence",
13176
+ name: "append_sl_scoring",
13122
13177
  kind: "mutation",
13123
13178
  domain: "beliefs",
13124
13179
  surfaceClass: "platform_internal",
13125
- path: "/beliefs/confidence",
13180
+ path: "/beliefs/sl-scoring",
13126
13181
  sdkNamespace: "beliefs",
13127
- sdkMethod: "modulateConfidence",
13128
- summary: "Internal SL ledger append. Public callers should attach evidence or contradiction relations instead.",
13182
+ sdkMethod: "appendSlScoring",
13183
+ summary: "Internal SL scoring append. Public callers attach evidence or contradiction relations instead.",
13129
13184
  convex: {
13130
13185
  module: "beliefs",
13131
- functionName: "modulateConfidence",
13186
+ functionName: "appendSlScoring",
13132
13187
  kind: "mutation",
13133
- inputProjection: confidenceInput
13188
+ inputProjection: appendSlScoringInput
13134
13189
  },
13135
- args: modulateConfidenceInputSchema
13190
+ args: appendSlScoringInputSchema
13136
13191
  }),
13137
13192
  surfaceContract({
13138
13193
  name: "fork_belief",
@@ -13238,8 +13293,12 @@ var beliefRelationSchema2 = z.object({
13238
13293
  targetId: z.string().optional().describe("Belief target ID alias for beliefId/beliefNodeId."),
13239
13294
  relation: z.enum(["supports", "contradicts", "supporting", "contradicting"]).optional().describe("Relation alias for how the evidence bears on the belief."),
13240
13295
  evidenceRelation: evidenceRelationSchema2.optional().describe("Canonical relation: supports or contradicts."),
13241
- confidence: z.number().optional().describe("Confidence in this evidence-to-belief relation."),
13242
- weight: z.number().optional().describe("Support weight from -1.0 to +1.0 for this belief."),
13296
+ confidence: z.number().optional().describe(
13297
+ "Deprecated read-only hint. Runtime SL confidence is derived from signed weight."
13298
+ ),
13299
+ weight: z.number().min(-1).max(1).refine((value) => value !== 0, {
13300
+ message: "Evidence impact weight must be nonzero."
13301
+ }).describe("Required signed impact score from -1.0 to +1.0 for this belief."),
13243
13302
  rationale: z.string().optional().describe("Why this relation exists.")
13244
13303
  });
13245
13304
  var createEvidenceArgs = z.object({
@@ -13248,7 +13307,7 @@ var createEvidenceArgs = z.object({
13248
13307
  source: z.string().optional().describe("Source URL or source label."),
13249
13308
  sourceUrl: z.string().optional().describe("Canonical source URL."),
13250
13309
  targetId: z.string().optional().describe(
13251
- "Belief, question, or worktree identifier to link or preserve on the evidence record. Belief targets require evidenceRelation or a nonzero signed weight."
13310
+ "Belief identifier to link immediately. Evidence creation cannot target only a question or worktree."
13252
13311
  ),
13253
13312
  linkedBeliefNodeId: z.string().optional().describe("Belief node this evidence bears on."),
13254
13313
  evidenceRelation: evidenceRelationSchema2.optional().describe(
@@ -13257,8 +13316,14 @@ var createEvidenceArgs = z.object({
13257
13316
  beliefRelations: z.array(beliefRelationSchema2).optional().describe(
13258
13317
  "Additional belief relations for one evidence record. Use when the same evidence supports or contradicts multiple beliefs."
13259
13318
  ),
13260
- confidence: z.number().optional().describe("Confidence in the evidence relation."),
13261
- weight: z.number().optional().describe("Nonzero support weight from -1.0 to +1.0."),
13319
+ confidence: z.number().optional().describe(
13320
+ "Deprecated hint. Runtime confidence is derived from signed weight."
13321
+ ),
13322
+ weight: z.number().min(-1).max(1).refine((value) => value !== 0, {
13323
+ message: "Evidence impact weight must be nonzero."
13324
+ }).describe(
13325
+ "Required signed impact score from -1.0 to +1.0 for targetId/linkedBeliefNodeId."
13326
+ ),
13262
13327
  metadata: jsonRecordSchema4.optional().describe("Metadata merged into the canonical evidence node."),
13263
13328
  rationale: z.string().describe("Why this evidence should enter the reasoning graph."),
13264
13329
  reasoning: z.string().optional().describe("Reasoning note preserved in evidence metadata."),
@@ -13280,7 +13345,9 @@ var addEvidenceArgs = z.object({
13280
13345
  topicId: z.string().optional().describe("Topic scope hint."),
13281
13346
  sourceUrl: z.string().optional().describe("URL of the source material."),
13282
13347
  targetNodeId: z.string().describe("The belief this evidence bears on."),
13283
- weight: z.number().optional().describe("Support weight from -1.0 to +1.0."),
13348
+ weight: z.number().min(-1).max(1).refine((value) => value !== 0, {
13349
+ message: "Evidence impact weight must be nonzero."
13350
+ }).describe("Required signed impact score from -1.0 to +1.0."),
13284
13351
  reasoning: z.string().describe("Why this evidence is relevant to the target belief."),
13285
13352
  title: z.string().optional().describe("Optional short title."),
13286
13353
  content: z.string().optional().describe("Optional long-form evidence content."),
@@ -13300,19 +13367,21 @@ var createEvidenceInput = (input, context) => {
13300
13367
  );
13301
13368
  };
13302
13369
  function relationWeight(input) {
13303
- if (typeof input.weight === "number" && Number.isFinite(input.weight) && input.weight !== 0) {
13370
+ if (typeof input.weight === "number" && Number.isFinite(input.weight) && input.weight !== 0 && input.weight >= -1 && input.weight <= 1) {
13371
+ const relation = String(
13372
+ input.evidenceRelation ?? input.relation ?? input.type ?? ""
13373
+ );
13374
+ if ((relation === "supports" || relation === "supporting") && input.weight < 0) {
13375
+ throw new Error("Supporting evidence links require positive weight.");
13376
+ }
13377
+ if ((relation === "contradicts" || relation === "contradicting") && input.weight > 0) {
13378
+ throw new Error("Contradicting evidence links require negative weight.");
13379
+ }
13304
13380
  return input.weight;
13305
13381
  }
13306
- const relation = String(
13307
- input.evidenceRelation ?? input.relation ?? input.type ?? ""
13382
+ throw new Error(
13383
+ "Belief evidence links require explicit nonzero weight in [-1, 1]."
13308
13384
  );
13309
- if (relation !== "supports" && relation !== "supporting" && relation !== "contradicts" && relation !== "contradicting") {
13310
- throw new Error(
13311
- "Belief evidence links require evidenceRelation='supports'|'contradicts' or a nonzero signed weight."
13312
- );
13313
- }
13314
- const confidence = typeof input.confidence === "number" ? Math.max(0, Math.min(1, input.confidence)) : 0.7;
13315
- return relation === "contradicts" || relation === "contradicting" ? -confidence : confidence;
13316
13385
  }
13317
13386
  var linkEvidenceToBeliefInput = (input, context) => {
13318
13387
  const weight = relationWeight(input);
@@ -13321,6 +13390,7 @@ var linkEvidenceToBeliefInput = (input, context) => {
13321
13390
  beliefNodeId: input.beliefNodeId ?? input.beliefId ?? input.targetId,
13322
13391
  insightId: input.insightId ?? input.evidenceNodeId ?? input.evidenceId,
13323
13392
  type: weight < 0 ? "contradicting" : "supporting",
13393
+ weight,
13324
13394
  confidence: Math.min(1, Math.abs(weight)),
13325
13395
  rationale: input.rationale ?? input.context,
13326
13396
  trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
@@ -13397,7 +13467,12 @@ var evidenceContracts = [
13397
13467
  functionName: "create",
13398
13468
  kind: "mutation",
13399
13469
  inputProjection: (input, context) => {
13400
- const weight = typeof input.weight === "number" ? input.weight : 0.7;
13470
+ if (typeof input.weight !== "number" || !Number.isFinite(input.weight) || input.weight === 0 || input.weight < -1 || input.weight > 1) {
13471
+ throw new Error(
13472
+ "add_evidence requires explicit nonzero weight in [-1, 1]."
13473
+ );
13474
+ }
13475
+ const weight = input.weight;
13401
13476
  return createEvidenceInput(
13402
13477
  {
13403
13478
  ...input,
@@ -13406,6 +13481,7 @@ var evidenceContracts = [
13406
13481
  linkedBeliefNodeId: input.linkedBeliefNodeId ?? input.targetNodeId ?? input.targetId,
13407
13482
  evidenceRelation: weight < 0 ? "contradicts" : "supports",
13408
13483
  confidence: Math.min(1, Math.max(0, Math.abs(weight))),
13484
+ weight,
13409
13485
  rationale: input.reasoning,
13410
13486
  metadata: {
13411
13487
  ...recordValue2(input.metadata),