@lucern/events 1.0.15 → 1.0.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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: {
@@ -4052,6 +4033,10 @@ var COMPILE_CONTEXT = {
4052
4033
  type: "number",
4053
4034
  description: "Optional per-section item limit"
4054
4035
  },
4036
+ contentTopicLimit: {
4037
+ type: "number",
4038
+ description: "Dimension-seeded compiles synthesize every matching worktree but bound raw belief/question/evidence enrichment to this many carrier topics (max 16) so hosted Convex queries remain fast. Receipts report any omitted raw topic enrichment."
4039
+ },
4055
4040
  maxDepth: {
4056
4041
  type: "number",
4057
4042
  description: "Optional descendant topic depth for neighborhood expansion"
@@ -4065,6 +4050,11 @@ var COMPILE_CONTEXT = {
4065
4050
  response: {
4066
4051
  description: "Compiled context pack for the requested topic",
4067
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",
4068
4058
  schemaVersion: "string",
4069
4059
  topicId: "string",
4070
4060
  topicName: "string",
@@ -4072,15 +4062,6 @@ var COMPILE_CONTEXT = {
4072
4062
  generatedAt: "number \u2014 deterministic graph-backed reference timestamp for this compilation",
4073
4063
  ranking: "string \u2014 baseline_v1 | weighted_v1",
4074
4064
  summary: "object \u2014 counts and scoped health signals",
4075
- invariants: "array \u2014 high-confidence invariant beliefs",
4076
- activeBeliefs: "array \u2014 current high-signal beliefs",
4077
- openQuestions: "array \u2014 unresolved questions ranked for this query",
4078
- recentEvidence: "array \u2014 recent evidence ranked for this query",
4079
- contradictions: "array \u2014 unresolved contradiction records",
4080
- relatedEntities: "array | undefined \u2014 ranked ontological entities in scope",
4081
- contextNarrative: "array \u2014 ordered synthesis blocks with kind/text, starting with executive_summary and canonical narrative blocks before raw objects",
4082
- retrievalReceipt: "object \u2014 candidateCounts, coverageWarning, narrativeCoverage, synthesisLints, and suggestedNextActions",
4083
- narrativeCoverage: "object \u2014 recordsSynthesized, recordsNamed, recordsOmitted, and blocksEmitted for the narrative",
4084
4065
  injectionPolicy: "object \u2014 token-budgeted section selections",
4085
4066
  diagnostics: "object \u2014 scoring and utilization telemetry"
4086
4067
  }
@@ -4639,7 +4620,7 @@ var MCP_TOOL_CONTRACTS = {
4639
4620
  create_belief: CREATE_BELIEF,
4640
4621
  get_belief: GET_BELIEF,
4641
4622
  refine_belief: REFINE_BELIEF,
4642
- modulate_confidence: MODULATE_CONFIDENCE,
4623
+ append_sl_scoring: APPEND_SL_SCORING,
4643
4624
  fork_belief: FORK_BELIEF,
4644
4625
  archive_belief: ARCHIVE_BELIEF,
4645
4626
  create_epistemic_contract: CREATE_EPISTEMIC_CONTRACT,
@@ -6437,8 +6418,10 @@ defineTable({
6437
6418
  "beliefStatus": z.object({
6438
6419
  "assumption": z.number(),
6439
6420
  "hypothesis": z.number(),
6440
- "belief": z.number(),
6441
- "fact": z.number()
6421
+ "active": z.number(),
6422
+ "superseded": z.number(),
6423
+ "resolved_true": z.number(),
6424
+ "resolved_false": z.number()
6442
6425
  }).optional(),
6443
6426
  "evidenceTemporalNature": z.object({
6444
6427
  "factual": z.number(),
@@ -6660,8 +6643,8 @@ defineTable({
6660
6643
  "exportClass": z.enum(["internal_only", "client_safe", "public_safe", "restricted"]).optional(),
6661
6644
  "anonymizationClass": z.enum(["none", "standard", "strict"]).optional(),
6662
6645
  "beliefType": z.string().optional(),
6663
- "beliefStatus": z.enum(["assumption", "hypothesis", "belief", "fact"]).optional(),
6664
- "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(),
6665
6648
  "reversibility": z.enum(["irreversible", "hard_to_reverse", "reversible", "trivial"]).optional(),
6666
6649
  "predictionMeta": z.object({
6667
6650
  "isPrediction": z.boolean(),
@@ -11718,11 +11701,39 @@ var createEvidenceInputSchemaBase = z.object({
11718
11701
  metadata: jsonRecordSchema.optional(),
11719
11702
  trustedBypassAccessCheck: z.boolean().optional()
11720
11703
  }).passthrough();
11721
- function hasNonzeroWeight(value) {
11722
- 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;
11723
11706
  }
11724
- function hasRelationSignal(value, weight) {
11725
- 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
+ }
11726
11737
  }
11727
11738
  var createEvidenceInputSchema = createEvidenceInputSchemaBase.superRefine(
11728
11739
  (input, ctx) => {
@@ -11739,13 +11750,27 @@ var createEvidenceInputSchema = createEvidenceInputSchemaBase.superRefine(
11739
11750
  input.linkedBeliefNodeId || kind === "belief" || kind === "unknown" && target
11740
11751
  );
11741
11752
  const weight = typeof input.weight === "number" ? input.weight : void 0;
11742
- 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") {
11743
11762
  ctx.addIssue({
11744
11763
  code: z.ZodIssueCode.custom,
11745
- message: "belief-targeted evidence requires evidenceRelation='supports'|'contradicts' or a nonzero signed weight",
11746
- 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"]
11747
11766
  });
11748
11767
  }
11768
+ if (linksPrimaryBelief) {
11769
+ validateSignedImpactScore(weight, ctx, ["weight"]);
11770
+ validateRelationImpactConsistency(input.evidenceRelation, weight, ctx, [
11771
+ "weight"
11772
+ ]);
11773
+ }
11749
11774
  input.beliefRelations?.forEach((relation, index) => {
11750
11775
  const beliefNodeId = relation.beliefNodeId ?? relation.beliefId ?? relation.targetId;
11751
11776
  if (!beliefNodeId) {
@@ -11756,15 +11781,18 @@ var createEvidenceInputSchema = createEvidenceInputSchemaBase.superRefine(
11756
11781
  });
11757
11782
  }
11758
11783
  const relationWeight2 = typeof relation.weight === "number" ? relation.weight : void 0;
11759
- if (beliefNodeId && !hasRelationSignal(
11760
- relation.evidenceRelation ?? relation.relation,
11761
- relationWeight2
11762
- )) {
11763
- ctx.addIssue({
11764
- code: z.ZodIssueCode.custom,
11765
- message: "beliefRelations entries require evidenceRelation='supports'|'contradicts' or a nonzero signed weight",
11766
- path: ["beliefRelations", index, "evidenceRelation"]
11767
- });
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
+ );
11768
11796
  }
11769
11797
  });
11770
11798
  }
@@ -11818,18 +11846,28 @@ function targetKind(targetId) {
11818
11846
  }
11819
11847
  return "unknown";
11820
11848
  }
11821
- function normalizeRelation(value, weight) {
11849
+ function normalizeRelationAlias(value) {
11822
11850
  if (value === "supports" || value === "supporting") {
11823
11851
  return "supports";
11824
11852
  }
11825
11853
  if (value === "contradicts" || value === "contradicting") {
11826
11854
  return "contradicts";
11827
11855
  }
11856
+ return void 0;
11857
+ }
11858
+ function normalizeRelation(value, weight) {
11859
+ const alias = normalizeRelationAlias(value);
11860
+ if (alias) {
11861
+ return alias;
11862
+ }
11828
11863
  if (weight === void 0 || !hasNonzeroWeight(weight)) {
11829
11864
  return void 0;
11830
11865
  }
11831
11866
  return weight < 0 ? "contradicts" : "supports";
11832
11867
  }
11868
+ function hasNonzeroWeight(value) {
11869
+ return typeof value === "number" && Number.isFinite(value) && value !== 0;
11870
+ }
11833
11871
  function normalizeConfidence(confidence, weight) {
11834
11872
  if (confidence !== void 0) {
11835
11873
  return Math.min(1, Math.max(0, confidence));
@@ -11856,6 +11894,7 @@ function normalizeBeliefRelation(relation) {
11856
11894
  beliefNodeId,
11857
11895
  relation: evidenceRelation,
11858
11896
  confidence: normalizeConfidence(relation.confidence, weight),
11897
+ weight,
11859
11898
  rationale: relation.rationale
11860
11899
  });
11861
11900
  }
@@ -11904,6 +11943,7 @@ var createEvidenceProjection = defineProjection({
11904
11943
  linkedBeliefNodeId,
11905
11944
  evidenceRelation,
11906
11945
  confidence,
11946
+ weight,
11907
11947
  beliefRelations: beliefRelations && beliefRelations.length > 0 ? beliefRelations : void 0,
11908
11948
  rationale: input.rationale,
11909
11949
  trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
@@ -11933,12 +11973,14 @@ var createEvidenceProjection = defineProjection({
11933
11973
  v.literal("contradicts")
11934
11974
  )
11935
11975
  ),
11976
+ weight: v.optional(v.number()),
11936
11977
  beliefRelations: v.optional(
11937
11978
  v.array(
11938
11979
  v.object({
11939
11980
  beliefNodeId: v.string(),
11940
11981
  relation: v.union(v.literal("supports"), v.literal("contradicts")),
11941
11982
  confidence: v.optional(v.number()),
11983
+ weight: v.number(),
11942
11984
  rationale: v.optional(v.string())
11943
11985
  })
11944
11986
  )
@@ -12056,7 +12098,7 @@ var slOpinionProjectionSchema = z.object({
12056
12098
  uncertainty: z.number(),
12057
12099
  baseRate: z.number()
12058
12100
  });
12059
- var modulateConfidenceInputObjectSchema = z.object({
12101
+ var appendSlScoringInputObjectSchema = z.object({
12060
12102
  nodeId: z.string().optional(),
12061
12103
  beliefNodeId: z.string().optional(),
12062
12104
  worktreeId: z.string().optional(),
@@ -12075,23 +12117,23 @@ var modulateConfidenceInputObjectSchema = z.object({
12075
12117
  rationale: z.string(),
12076
12118
  trustedBypassAccessCheck: z.boolean().optional()
12077
12119
  });
12078
- var modulateConfidenceInputSchema = modulateConfidenceInputObjectSchema.superRefine((input, ctx) => {
12120
+ var appendSlScoringInputSchema = appendSlScoringInputObjectSchema.superRefine((input, ctx) => {
12079
12121
  if (hasProvenance(input)) {
12080
12122
  return;
12081
12123
  }
12082
12124
  ctx.addIssue({
12083
12125
  code: z.ZodIssueCode.custom,
12084
- message: "modulate_confidence requires evidence, question, answer, contradiction, or worktree provenance",
12126
+ message: "append_sl_scoring requires evidence, question, answer, contradiction, or worktree provenance",
12085
12127
  path: ["provenance"]
12086
12128
  });
12087
12129
  });
12088
- var modulateConfidenceProjection = defineProjection({
12089
- contractName: "modulate_confidence",
12090
- inputSchema: modulateConfidenceInputSchema,
12130
+ var appendSlScoringProjection = defineProjection({
12131
+ contractName: "append_sl_scoring",
12132
+ inputSchema: appendSlScoringInputSchema,
12091
12133
  project: (input) => {
12092
12134
  const nodeId = input.beliefNodeId ?? input.nodeId;
12093
12135
  if (!nodeId) {
12094
- throw new Error("modulate_confidence requires beliefNodeId or nodeId");
12136
+ throw new Error("append_sl_scoring requires beliefNodeId or nodeId");
12095
12137
  }
12096
12138
  const opinion = input.opinion ?? {
12097
12139
  belief: requireNumber(input.belief, "belief"),
@@ -12148,14 +12190,14 @@ var modulateConfidenceProjection = defineProjection({
12148
12190
  });
12149
12191
  function requireNumber(value, field) {
12150
12192
  if (value === void 0) {
12151
- throw new Error(`modulate_confidence requires ${field}`);
12193
+ throw new Error(`append_sl_scoring requires ${field}`);
12152
12194
  }
12153
12195
  return value;
12154
12196
  }
12155
12197
  function assertProvenance(input) {
12156
12198
  if (!hasProvenance(input)) {
12157
12199
  throw new Error(
12158
- "modulate_confidence requires evidence, question, answer, contradiction, or worktree provenance"
12200
+ "append_sl_scoring requires evidence, question, answer, contradiction, or worktree provenance"
12159
12201
  );
12160
12202
  }
12161
12203
  }
@@ -12498,12 +12540,12 @@ var LUCERN_OPERATION_MANIFEST = {
12498
12540
  internalSystem,
12499
12541
  "Lucern system/background operation. Available to platform code paths, hidden from public MCP discovery."
12500
12542
  ),
12501
- modulate_confidence: {
12502
- name: "modulate_confidence",
12543
+ append_sl_scoring: {
12544
+ name: "append_sl_scoring",
12503
12545
  surfaceClass: "platform_internal",
12504
12546
  surfaceIntent: "system",
12505
12547
  surfaces: internalSdkRestOnly,
12506
- 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."
12507
12549
  },
12508
12550
  ...entries(
12509
12551
  LEGACY_COMPAT_OPERATION_NAMES,
@@ -13057,7 +13099,15 @@ var predictionMetaSchema = z.object({
13057
13099
  });
13058
13100
  var createBeliefArgs = z.object({
13059
13101
  canonicalText: z.string().describe("The belief statement the agent holds to be true."),
13060
- 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
+ ),
13061
13111
  baseRate: z.number().optional().describe("Prior base rate used to seed the vacuous opinion."),
13062
13112
  beliefType: z.string().optional().describe("Schema belief type."),
13063
13113
  metadata: jsonRecordSchema3.optional().describe("Extra metadata merged into the belief node."),
@@ -13076,9 +13126,14 @@ var forkBeliefArgs = z.object({
13076
13126
  "refinement",
13077
13127
  "contradiction_response",
13078
13128
  "scope_change",
13079
- "confidence_collapse",
13080
- "manual"
13129
+ "confidence_collapse"
13081
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
+ ),
13082
13137
  rationale: z.string().optional().describe("Why the fork is warranted.")
13083
13138
  });
13084
13139
  var beliefLookupInput = (input) => compactRecord4({
@@ -13092,7 +13147,9 @@ var createBeliefInput = (input, context) => {
13092
13147
  return withUserId(
13093
13148
  compactRecord4({
13094
13149
  projectId: input.projectId,
13095
- topicId: input.topicId,
13150
+ topicId: input.topicGlobalId ?? input.topicNodeId ?? input.topicId,
13151
+ topicGlobalId: input.topicGlobalId,
13152
+ topicNodeId: input.topicNodeId,
13096
13153
  formulation: input.formulation ?? input.canonicalText,
13097
13154
  beliefType: input.beliefType,
13098
13155
  rationale: input.rationale,
@@ -13114,20 +13171,22 @@ var forkBeliefInput = (input, context) => withUserId(
13114
13171
  parentNodeId: input.parentNodeId ?? input.nodeId ?? input.id,
13115
13172
  newFormulation: input.newFormulation,
13116
13173
  forkReason: input.forkReason,
13174
+ forkMode: input.forkMode,
13175
+ triggeringEvidenceId: input.triggeringEvidenceId,
13117
13176
  rationale: input.rationale,
13118
13177
  trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
13119
13178
  }),
13120
13179
  context
13121
13180
  );
13122
- var confidenceInput = (input, context) => {
13123
- const parsed = modulateConfidenceProjection.inputSchema.safeParse(input);
13181
+ var appendSlScoringInput = (input, context) => {
13182
+ const parsed = appendSlScoringProjection.inputSchema.safeParse(input);
13124
13183
  if (!parsed.success) {
13125
13184
  throw new Error(
13126
- `modulate_confidence projection input rejected: ${parsed.error.message}`
13185
+ `append_sl_scoring projection input rejected: ${parsed.error.message}`
13127
13186
  );
13128
13187
  }
13129
13188
  return withUserId(
13130
- compactRecord4(modulateConfidenceProjection.project(parsed.data)),
13189
+ compactRecord4(appendSlScoringProjection.project(parsed.data)),
13131
13190
  context
13132
13191
  );
13133
13192
  };
@@ -13205,21 +13264,21 @@ var beliefsContracts = [
13205
13264
  }
13206
13265
  }),
13207
13266
  surfaceContract({
13208
- name: "modulate_confidence",
13267
+ name: "append_sl_scoring",
13209
13268
  kind: "mutation",
13210
13269
  domain: "beliefs",
13211
13270
  surfaceClass: "platform_internal",
13212
- path: "/beliefs/confidence",
13271
+ path: "/beliefs/sl-scoring",
13213
13272
  sdkNamespace: "beliefs",
13214
- sdkMethod: "modulateConfidence",
13215
- 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.",
13216
13275
  convex: {
13217
13276
  module: "beliefs",
13218
- functionName: "modulateConfidence",
13277
+ functionName: "appendSlScoring",
13219
13278
  kind: "mutation",
13220
- inputProjection: confidenceInput
13279
+ inputProjection: appendSlScoringInput
13221
13280
  },
13222
- args: modulateConfidenceInputSchema
13281
+ args: appendSlScoringInputSchema
13223
13282
  }),
13224
13283
  surfaceContract({
13225
13284
  name: "fork_belief",
@@ -13325,8 +13384,12 @@ var beliefRelationSchema2 = z.object({
13325
13384
  targetId: z.string().optional().describe("Belief target ID alias for beliefId/beliefNodeId."),
13326
13385
  relation: z.enum(["supports", "contradicts", "supporting", "contradicting"]).optional().describe("Relation alias for how the evidence bears on the belief."),
13327
13386
  evidenceRelation: evidenceRelationSchema2.optional().describe("Canonical relation: supports or contradicts."),
13328
- confidence: z.number().optional().describe("Confidence in this evidence-to-belief relation."),
13329
- 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."),
13330
13393
  rationale: z.string().optional().describe("Why this relation exists.")
13331
13394
  });
13332
13395
  var createEvidenceArgs = z.object({
@@ -13335,7 +13398,7 @@ var createEvidenceArgs = z.object({
13335
13398
  source: z.string().optional().describe("Source URL or source label."),
13336
13399
  sourceUrl: z.string().optional().describe("Canonical source URL."),
13337
13400
  targetId: z.string().optional().describe(
13338
- "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."
13339
13402
  ),
13340
13403
  linkedBeliefNodeId: z.string().optional().describe("Belief node this evidence bears on."),
13341
13404
  evidenceRelation: evidenceRelationSchema2.optional().describe(
@@ -13344,8 +13407,14 @@ var createEvidenceArgs = z.object({
13344
13407
  beliefRelations: z.array(beliefRelationSchema2).optional().describe(
13345
13408
  "Additional belief relations for one evidence record. Use when the same evidence supports or contradicts multiple beliefs."
13346
13409
  ),
13347
- confidence: z.number().optional().describe("Confidence in the evidence relation."),
13348
- 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
+ ),
13349
13418
  metadata: jsonRecordSchema4.optional().describe("Metadata merged into the canonical evidence node."),
13350
13419
  rationale: z.string().describe("Why this evidence should enter the reasoning graph."),
13351
13420
  reasoning: z.string().optional().describe("Reasoning note preserved in evidence metadata."),
@@ -13367,7 +13436,9 @@ var addEvidenceArgs = z.object({
13367
13436
  topicId: z.string().optional().describe("Topic scope hint."),
13368
13437
  sourceUrl: z.string().optional().describe("URL of the source material."),
13369
13438
  targetNodeId: z.string().describe("The belief this evidence bears on."),
13370
- 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."),
13371
13442
  reasoning: z.string().describe("Why this evidence is relevant to the target belief."),
13372
13443
  title: z.string().optional().describe("Optional short title."),
13373
13444
  content: z.string().optional().describe("Optional long-form evidence content."),
@@ -13387,19 +13458,21 @@ var createEvidenceInput = (input, context) => {
13387
13458
  );
13388
13459
  };
13389
13460
  function relationWeight(input) {
13390
- 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
+ }
13391
13471
  return input.weight;
13392
13472
  }
13393
- const relation = String(
13394
- input.evidenceRelation ?? input.relation ?? input.type ?? ""
13473
+ throw new Error(
13474
+ "Belief evidence links require explicit nonzero weight in [-1, 1]."
13395
13475
  );
13396
- if (relation !== "supports" && relation !== "supporting" && relation !== "contradicts" && relation !== "contradicting") {
13397
- throw new Error(
13398
- "Belief evidence links require evidenceRelation='supports'|'contradicts' or a nonzero signed weight."
13399
- );
13400
- }
13401
- const confidence = typeof input.confidence === "number" ? Math.max(0, Math.min(1, input.confidence)) : 0.7;
13402
- return relation === "contradicts" || relation === "contradicting" ? -confidence : confidence;
13403
13476
  }
13404
13477
  var linkEvidenceToBeliefInput = (input, context) => {
13405
13478
  const weight = relationWeight(input);
@@ -13408,6 +13481,7 @@ var linkEvidenceToBeliefInput = (input, context) => {
13408
13481
  beliefNodeId: input.beliefNodeId ?? input.beliefId ?? input.targetId,
13409
13482
  insightId: input.insightId ?? input.evidenceNodeId ?? input.evidenceId,
13410
13483
  type: weight < 0 ? "contradicting" : "supporting",
13484
+ weight,
13411
13485
  confidence: Math.min(1, Math.abs(weight)),
13412
13486
  rationale: input.rationale ?? input.context,
13413
13487
  trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
@@ -13484,7 +13558,12 @@ var evidenceContracts = [
13484
13558
  functionName: "create",
13485
13559
  kind: "mutation",
13486
13560
  inputProjection: (input, context) => {
13487
- 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;
13488
13567
  return createEvidenceInput(
13489
13568
  {
13490
13569
  ...input,
@@ -13493,6 +13572,7 @@ var evidenceContracts = [
13493
13572
  linkedBeliefNodeId: input.linkedBeliefNodeId ?? input.targetNodeId ?? input.targetId,
13494
13573
  evidenceRelation: weight < 0 ? "contradicts" : "supports",
13495
13574
  confidence: Math.min(1, Math.max(0, Math.abs(weight))),
13575
+ weight,
13496
13576
  rationale: input.reasoning,
13497
13577
  metadata: {
13498
13578
  ...recordValue2(input.metadata),