@lucern/contracts 1.0.12 → 1.0.14

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.
Files changed (81) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/function-registry/beliefs.js +48 -11
  3. package/dist/function-registry/beliefs.js.map +1 -1
  4. package/dist/function-registry/coding.js +46 -9
  5. package/dist/function-registry/coding.js.map +1 -1
  6. package/dist/function-registry/context.js +46 -9
  7. package/dist/function-registry/context.js.map +1 -1
  8. package/dist/function-registry/contracts.js +46 -9
  9. package/dist/function-registry/contracts.js.map +1 -1
  10. package/dist/function-registry/coordination.js +46 -9
  11. package/dist/function-registry/coordination.js.map +1 -1
  12. package/dist/function-registry/edges.js +46 -9
  13. package/dist/function-registry/edges.js.map +1 -1
  14. package/dist/function-registry/evidence.js +227 -25
  15. package/dist/function-registry/evidence.js.map +1 -1
  16. package/dist/function-registry/graph.js +46 -9
  17. package/dist/function-registry/graph.js.map +1 -1
  18. package/dist/function-registry/helpers.js +46 -9
  19. package/dist/function-registry/helpers.js.map +1 -1
  20. package/dist/function-registry/identity.js +46 -9
  21. package/dist/function-registry/identity.js.map +1 -1
  22. package/dist/function-registry/index.js +46 -9
  23. package/dist/function-registry/index.js.map +1 -1
  24. package/dist/function-registry/judgments.js +46 -9
  25. package/dist/function-registry/judgments.js.map +1 -1
  26. package/dist/function-registry/legacy.js +46 -9
  27. package/dist/function-registry/legacy.js.map +1 -1
  28. package/dist/function-registry/lenses.js +46 -9
  29. package/dist/function-registry/lenses.js.map +1 -1
  30. package/dist/function-registry/manifest.d.ts +10 -4
  31. package/dist/function-registry/manifest.js +13 -1
  32. package/dist/function-registry/manifest.js.map +1 -1
  33. package/dist/function-registry/nodes.js +46 -9
  34. package/dist/function-registry/nodes.js.map +1 -1
  35. package/dist/function-registry/ontologies.js +46 -9
  36. package/dist/function-registry/ontologies.js.map +1 -1
  37. package/dist/function-registry/pipeline.js +46 -9
  38. package/dist/function-registry/pipeline.js.map +1 -1
  39. package/dist/function-registry/questions.js +46 -9
  40. package/dist/function-registry/questions.js.map +1 -1
  41. package/dist/function-registry/tasks.js +46 -9
  42. package/dist/function-registry/tasks.js.map +1 -1
  43. package/dist/function-registry/topics.js +46 -9
  44. package/dist/function-registry/topics.js.map +1 -1
  45. package/dist/function-registry/worktrees.js +46 -9
  46. package/dist/function-registry/worktrees.js.map +1 -1
  47. package/dist/index.js +160 -16
  48. package/dist/index.js.map +1 -1
  49. package/dist/manifests/invariants/index.js +24 -5
  50. package/dist/manifests/invariants/index.js.map +1 -1
  51. package/dist/manifests/invariants/inv-1-beliefs-append-only.js +24 -5
  52. package/dist/manifests/invariants/inv-1-beliefs-append-only.js.map +1 -1
  53. package/dist/projections/check-convex-args-shape.js +127 -8
  54. package/dist/projections/check-convex-args-shape.js.map +1 -1
  55. package/dist/projections/create-evidence.projection.d.ts +168 -0
  56. package/dist/projections/create-evidence.projection.js +127 -8
  57. package/dist/projections/create-evidence.projection.js.map +1 -1
  58. package/dist/projections/index.d.ts +28 -0
  59. package/dist/projections/index.js +127 -8
  60. package/dist/projections/index.js.map +1 -1
  61. package/dist/proof-attestation.json +1 -1
  62. package/dist/sdk-methods.contract.d.ts +3 -2
  63. package/dist/sdk-tools.contract.js +33 -8
  64. package/dist/sdk-tools.contract.js.map +1 -1
  65. package/dist/sdk-tools.contract.registry.js +33 -8
  66. package/dist/sdk-tools.contract.registry.js.map +1 -1
  67. package/dist/sdk-tools.contract.values.js +33 -8
  68. package/dist/sdk-tools.contract.values.js.map +1 -1
  69. package/dist/tool-contracts.context-orientation.js +2 -1
  70. package/dist/tool-contracts.context-orientation.js.map +1 -1
  71. package/dist/tool-contracts.intelligence-evidence.js +26 -4
  72. package/dist/tool-contracts.intelligence-evidence.js.map +1 -1
  73. package/dist/tool-contracts.js +33 -8
  74. package/dist/tool-contracts.js.map +1 -1
  75. package/dist/tool-contracts.lifecycle.js +2 -2
  76. package/dist/tool-contracts.lifecycle.js.map +1 -1
  77. package/dist/tool-contracts.questions-listing.js +3 -1
  78. package/dist/tool-contracts.questions-listing.js.map +1 -1
  79. package/dist/tool-contracts.values.js +33 -8
  80. package/dist/tool-contracts.values.js.map +1 -1
  81. package/package.json +1 -1
@@ -6,7 +6,7 @@ import { v } from 'convex/values';
6
6
  // src/tool-contracts.lifecycle.ts
7
7
  var CREATE_BELIEF = {
8
8
  name: "create_belief",
9
- 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)`; use modulate_confidence to record the first evidential update.",
9
+ 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.",
10
10
  parameters: {
11
11
  canonicalText: {
12
12
  type: "string",
@@ -92,7 +92,7 @@ var REFINE_BELIEF = {
92
92
  };
93
93
  var MODULATE_CONFIDENCE = {
94
94
  name: "modulate_confidence",
95
- description: "Record a confidence change for a belief. Like `git commit` to the credence log \u2014 an atomic, append-only write. Each modulation is a new entry in the history, not an overwrite. Scoring happens via merge; this tool records the individual data points. Pass the full subjective-logic tuple (`belief`, `disbelief`, `uncertainty`, `baseRate`) directly. If a caller only has a scalar probability, use `@lucern/sdk` helpers `opinionFromBaseRate`, `opinionFromDogmatic`, or `opinionFromProjected` to name the intended interpretation before calling this tool. Every modulation must cite a truth-bearing artifact: triggeringEvidenceId, triggeringQuestionId, triggeringAnswerId, triggeringContradictionId, or triggeringWorktreeId. Triggers: evidence_added, evidence_removed, contradiction_detected, contradiction_resolved, agent_assessment, worktree_outcome, worktree_completed, fusion, discount, deduction.",
95
+ 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.",
96
96
  parameters: {
97
97
  nodeId: { type: "string", description: "The belief to score" },
98
98
  belief: {
@@ -1700,10 +1700,11 @@ var LUCERN_ORIENT = {
1700
1700
  workflow: "array - recommended branch -> investigate -> prove gate -> merge workflow",
1701
1701
  grammarMap: "array - primitive-to-git-analogy map for topics, campaigns, worktrees, beliefs, questions, evidence, edges, contradictions, and gates",
1702
1702
  firstMoves: "array - recommended first tools for a cold-start agent",
1703
- receiptRules: "array - how to interpret candidateCounts, broadening, coverageWarning, and noDefaultGlobalScan",
1703
+ receiptRules: "array - how to interpret candidateCounts, broadening, coverageWarning, narrativeCoverage, synthesisLints, and noDefaultGlobalScan",
1704
1704
  safetyRules: "array - mutation and completion rules that preserve reasoning lineage",
1705
1705
  toolMap: "array | undefined - situation-to-tool routing map when requested",
1706
1706
  examples: "array | undefined - concrete tool-call examples when requested",
1707
+ futureCapabilities: "array | undefined - exemplar, gauntlet, trace-corpus, and native-model-training capabilities when requested",
1707
1708
  suggestedNextCalls: "array - safe next tool calls for the current situation"
1708
1709
  }
1709
1710
  },
@@ -1866,7 +1867,7 @@ var SEARCH_EVIDENCE = {
1866
1867
  };
1867
1868
  var CREATE_EVIDENCE = {
1868
1869
  name: "create_evidence",
1869
- 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.",
1870
+ 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.",
1870
1871
  parameters: {
1871
1872
  topicId: { type: "string", description: "Topic scope" },
1872
1873
  text: { type: "string", description: "Canonical evidence text" },
@@ -1877,7 +1878,20 @@ var CREATE_EVIDENCE = {
1877
1878
  },
1878
1879
  weight: {
1879
1880
  type: "number",
1880
- description: "Support weight: -1.0 (contradicts) to +1.0 (supports)"
1881
+ description: "Optional support weight: -1.0 (contradicts) to +1.0 (supports). If omitted, evidenceRelation + confidence determine the weight."
1882
+ },
1883
+ evidenceRelation: {
1884
+ type: "string",
1885
+ enum: ["supports", "contradicts"],
1886
+ description: "Canonical relation to targetId/linkedBeliefNodeId. Prefer this over relying on signed weight inference."
1887
+ },
1888
+ confidence: {
1889
+ type: "number",
1890
+ description: "Confidence in the evidence relation, 0.0 to 1.0"
1891
+ },
1892
+ beliefRelations: {
1893
+ type: "array",
1894
+ description: "Optional additional belief relations: [{ beliefId|beliefNodeId|targetId, evidenceRelation|relation, confidence?, weight?, rationale? }]. Use one evidence node with multiple relations when the same fact supports or contradicts several beliefs."
1881
1895
  },
1882
1896
  metadata: {
1883
1897
  type: "object",
@@ -1987,7 +2001,7 @@ var LINK_EVIDENCE = {
1987
2001
  };
1988
2002
  var LINK_EVIDENCE_TO_BELIEF = {
1989
2003
  name: "link_evidence_to_belief",
1990
- description: "Link evidence to a belief with a support weight. Like `git add` \u2014 stages evidence in support of (or against) a belief. The weight ranges from -1.0 (strongly contradicts) to +1.0 (strongly supports).",
2004
+ description: "Link evidence to a belief with a support weight. Like `git add` \u2014 stages evidence in support of (or against) a belief. The weight ranges from -1.0 (strongly contradicts) to +1.0 (strongly supports). This relation appends to the SL confidence ledger; do not hand-write confidence separately.",
1991
2005
  parameters: {
1992
2006
  evidenceId: { type: "string", description: "The evidence node ID" },
1993
2007
  beliefId: { type: "string", description: "The belief node ID" },
@@ -1995,9 +2009,18 @@ var LINK_EVIDENCE_TO_BELIEF = {
1995
2009
  type: "number",
1996
2010
  description: "Support weight: -1.0 (contradicts) to +1.0 (supports)"
1997
2011
  },
2012
+ evidenceRelation: {
2013
+ type: "string",
2014
+ enum: ["supports", "contradicts"],
2015
+ description: "Canonical semantic relation. If omitted, the sign of weight is used."
2016
+ },
2017
+ confidence: {
2018
+ type: "number",
2019
+ description: "Confidence in this evidence-to-belief relation, 0.0 to 1.0"
2020
+ },
1998
2021
  rationale: { type: "string", description: "Why this evidence is relevant" }
1999
2022
  },
2000
- required: ["evidenceId", "beliefId", "weight"],
2023
+ required: ["evidenceId", "beliefId"],
2001
2024
  response: {
2002
2025
  description: "The created edge linking evidence to belief",
2003
2026
  fields: {
@@ -2825,7 +2848,9 @@ var COMPILE_CONTEXT = {
2825
2848
  recentEvidence: "array \u2014 recent evidence ranked for this query",
2826
2849
  contradictions: "array \u2014 unresolved contradiction records",
2827
2850
  relatedEntities: "array | undefined \u2014 ranked ontological entities in scope",
2828
- contextNarrative: "array \u2014 guidance for prompt assembly",
2851
+ contextNarrative: "array \u2014 ordered synthesis blocks with kind/text, starting with executive_summary and canonical narrative blocks before raw objects",
2852
+ retrievalReceipt: "object \u2014 candidateCounts, coverageWarning, narrativeCoverage, synthesisLints, and suggestedNextActions",
2853
+ narrativeCoverage: "object \u2014 recordsSynthesized, recordsNamed, recordsOmitted, and blocksEmitted for the narrative",
2829
2854
  injectionPolicy: "object \u2014 token-budgeted section selections",
2830
2855
  diagnostics: "object \u2014 scoring and utilization telemetry"
2831
2856
  }
@@ -4773,6 +4798,12 @@ var internalSystem = {
4773
4798
  mcp: "internal",
4774
4799
  cli: "internal"
4775
4800
  };
4801
+ var internalSdkRestOnly = {
4802
+ sdk: "internal",
4803
+ rest: "internal",
4804
+ mcp: "none",
4805
+ cli: "none"
4806
+ };
4776
4807
  var publicWithInternalMcp = {
4777
4808
  sdk: "public",
4778
4809
  rest: "public",
@@ -4822,7 +4853,6 @@ var MCP_CORE_OPERATION_NAMES = [
4822
4853
  "get_belief",
4823
4854
  "list_beliefs",
4824
4855
  "refine_belief",
4825
- "modulate_confidence",
4826
4856
  "fork_belief",
4827
4857
  "archive_belief",
4828
4858
  "search_beliefs",
@@ -5090,6 +5120,13 @@ var LUCERN_OPERATION_MANIFEST = {
5090
5120
  internalSystem,
5091
5121
  "Lucern system/background operation. Available to platform code paths, hidden from public MCP discovery."
5092
5122
  ),
5123
+ modulate_confidence: {
5124
+ name: "modulate_confidence",
5125
+ surfaceClass: "platform_internal",
5126
+ surfaceIntent: "system",
5127
+ surfaces: internalSdkRestOnly,
5128
+ rationale: "Internal SL ledger append primitive. Public callers attach evidence or contradiction relations; confidence is derived algorithmically."
5129
+ },
5093
5130
  ...entries(
5094
5131
  LEGACY_COMPAT_OPERATION_NAMES,
5095
5132
  "legacy_compat",
@@ -5429,6 +5466,23 @@ function defineProjection(def) {
5429
5466
 
5430
5467
  // src/projections/create-evidence.projection.ts
5431
5468
  var jsonRecordSchema = z.record(z.unknown());
5469
+ var evidenceRelationSchema = z.enum(["supports", "contradicts"]);
5470
+ var evidenceRelationAliasSchema = z.enum([
5471
+ "supports",
5472
+ "contradicts",
5473
+ "supporting",
5474
+ "contradicting"
5475
+ ]);
5476
+ var beliefRelationSchema = z.object({
5477
+ beliefId: z.string().optional(),
5478
+ beliefNodeId: z.string().optional(),
5479
+ targetId: z.string().optional(),
5480
+ relation: evidenceRelationAliasSchema.optional(),
5481
+ evidenceRelation: evidenceRelationSchema.optional(),
5482
+ confidence: z.number().optional(),
5483
+ weight: z.number().optional(),
5484
+ rationale: z.string().optional()
5485
+ });
5432
5486
  var createEvidenceInputSchemaBase = z.object({
5433
5487
  projectId: z.string().optional(),
5434
5488
  topicId: z.string().optional(),
@@ -5450,7 +5504,8 @@ var createEvidenceInputSchemaBase = z.object({
5450
5504
  targetId: z.string().optional(),
5451
5505
  targetNodeId: z.string().optional(),
5452
5506
  linkedBeliefNodeId: z.string().optional(),
5453
- evidenceRelation: z.enum(["supports", "contradicts"]).optional(),
5507
+ evidenceRelation: evidenceRelationSchema.optional(),
5508
+ beliefRelations: z.array(beliefRelationSchema).optional(),
5454
5509
  confidence: z.number().optional(),
5455
5510
  weight: z.number().optional(),
5456
5511
  reasoning: z.string().optional(),
@@ -5458,11 +5513,55 @@ var createEvidenceInputSchemaBase = z.object({
5458
5513
  metadata: jsonRecordSchema.optional(),
5459
5514
  trustedBypassAccessCheck: z.boolean().optional()
5460
5515
  }).passthrough();
5461
- var createEvidenceInputSchema = createEvidenceInputSchemaBase.refine(
5462
- (input) => Boolean(input.text ?? input.canonicalText),
5463
- {
5464
- message: "create_evidence requires text",
5465
- path: ["text"]
5516
+ function hasNonzeroWeight(value) {
5517
+ return typeof value === "number" && Number.isFinite(value) && value !== 0;
5518
+ }
5519
+ function hasRelationSignal(value, weight) {
5520
+ return Boolean(normalizeRelation(value, weight));
5521
+ }
5522
+ var createEvidenceInputSchema = createEvidenceInputSchemaBase.superRefine(
5523
+ (input, ctx) => {
5524
+ if (!input.text && !input.canonicalText) {
5525
+ ctx.addIssue({
5526
+ code: z.ZodIssueCode.custom,
5527
+ message: "create_evidence requires text",
5528
+ path: ["text"]
5529
+ });
5530
+ }
5531
+ const target = input.targetId ?? input.targetNodeId;
5532
+ const kind = targetKind(target);
5533
+ const linksPrimaryBelief = Boolean(
5534
+ input.linkedBeliefNodeId || kind === "belief" || kind === "unknown" && target
5535
+ );
5536
+ const weight = typeof input.weight === "number" ? input.weight : void 0;
5537
+ if (linksPrimaryBelief && !hasRelationSignal(input.evidenceRelation, weight)) {
5538
+ ctx.addIssue({
5539
+ code: z.ZodIssueCode.custom,
5540
+ message: "belief-targeted evidence requires evidenceRelation='supports'|'contradicts' or a nonzero signed weight",
5541
+ path: ["evidenceRelation"]
5542
+ });
5543
+ }
5544
+ input.beliefRelations?.forEach((relation, index) => {
5545
+ const beliefNodeId = relation.beliefNodeId ?? relation.beliefId ?? relation.targetId;
5546
+ if (!beliefNodeId) {
5547
+ ctx.addIssue({
5548
+ code: z.ZodIssueCode.custom,
5549
+ message: "beliefRelations entries require beliefId, beliefNodeId, or targetId",
5550
+ path: ["beliefRelations", index, "beliefNodeId"]
5551
+ });
5552
+ }
5553
+ const relationWeight2 = typeof relation.weight === "number" ? relation.weight : void 0;
5554
+ if (beliefNodeId && !hasRelationSignal(
5555
+ relation.evidenceRelation ?? relation.relation,
5556
+ relationWeight2
5557
+ )) {
5558
+ ctx.addIssue({
5559
+ code: z.ZodIssueCode.custom,
5560
+ message: "beliefRelations entries require evidenceRelation='supports'|'contradicts' or a nonzero signed weight",
5561
+ path: ["beliefRelations", index, "evidenceRelation"]
5562
+ });
5563
+ }
5564
+ });
5466
5565
  }
5467
5566
  );
5468
5567
  function compactRecord2(input) {
@@ -5514,6 +5613,47 @@ function targetKind(targetId) {
5514
5613
  }
5515
5614
  return "unknown";
5516
5615
  }
5616
+ function normalizeRelation(value, weight) {
5617
+ if (value === "supports" || value === "supporting") {
5618
+ return "supports";
5619
+ }
5620
+ if (value === "contradicts" || value === "contradicting") {
5621
+ return "contradicts";
5622
+ }
5623
+ if (weight === void 0 || !hasNonzeroWeight(weight)) {
5624
+ return void 0;
5625
+ }
5626
+ return weight < 0 ? "contradicts" : "supports";
5627
+ }
5628
+ function normalizeConfidence(confidence, weight) {
5629
+ if (confidence !== void 0) {
5630
+ return Math.min(1, Math.max(0, confidence));
5631
+ }
5632
+ if (weight === void 0) {
5633
+ return void 0;
5634
+ }
5635
+ return Math.min(1, Math.max(0, Math.abs(weight)));
5636
+ }
5637
+ function normalizeBeliefRelation(relation) {
5638
+ const beliefNodeId = relation.beliefNodeId ?? relation.beliefId ?? relation.targetId;
5639
+ if (!beliefNodeId) {
5640
+ return void 0;
5641
+ }
5642
+ const weight = typeof relation.weight === "number" ? relation.weight : void 0;
5643
+ const evidenceRelation = normalizeRelation(
5644
+ relation.evidenceRelation ?? relation.relation,
5645
+ weight
5646
+ );
5647
+ if (!evidenceRelation) {
5648
+ return void 0;
5649
+ }
5650
+ return compactRecord2({
5651
+ beliefNodeId,
5652
+ relation: evidenceRelation,
5653
+ confidence: normalizeConfidence(relation.confidence, weight),
5654
+ rationale: relation.rationale
5655
+ });
5656
+ }
5517
5657
  var createEvidenceProjection = defineProjection({
5518
5658
  contractName: "create_evidence",
5519
5659
  inputSchema: createEvidenceInputSchema,
@@ -5524,6 +5664,11 @@ var createEvidenceProjection = defineProjection({
5524
5664
  const kind = targetKind(target);
5525
5665
  const linkedWorktreeId = kind === "worktree" ? normalizeWorktreeId(target) : void 0;
5526
5666
  const linkedBeliefNodeId = input.linkedBeliefNodeId ?? (kind === "belief" || kind === "unknown" ? input.targetNodeId ?? input.targetId : void 0);
5667
+ const evidenceRelation = linkedBeliefNodeId ? normalizeRelation(input.evidenceRelation, weight) : void 0;
5668
+ const confidence = evidenceRelation ? normalizeConfidence(input.confidence, weight) : void 0;
5669
+ const beliefRelations = input.beliefRelations?.map(normalizeBeliefRelation).filter(
5670
+ (relation) => relation !== void 0
5671
+ );
5527
5672
  return compactRecord2({
5528
5673
  projectId: input.projectId,
5529
5674
  topicId: normalizeTopicIdForKernel(input.topicId),
@@ -5552,8 +5697,9 @@ var createEvidenceProjection = defineProjection({
5552
5697
  rationale: input.rationale
5553
5698
  }),
5554
5699
  linkedBeliefNodeId,
5555
- evidenceRelation: input.evidenceRelation ?? (weight === void 0 ? void 0 : weight < 0 ? "contradicts" : "supports"),
5556
- confidence: input.confidence ?? (weight === void 0 ? void 0 : Math.min(1, Math.max(0, Math.abs(weight)))),
5700
+ evidenceRelation,
5701
+ confidence,
5702
+ beliefRelations: beliefRelations && beliefRelations.length > 0 ? beliefRelations : void 0,
5557
5703
  rationale: input.rationale,
5558
5704
  trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
5559
5705
  });
@@ -5582,23 +5728,50 @@ var createEvidenceProjection = defineProjection({
5582
5728
  v.literal("contradicts")
5583
5729
  )
5584
5730
  ),
5731
+ beliefRelations: v.optional(
5732
+ v.array(
5733
+ v.object({
5734
+ beliefNodeId: v.string(),
5735
+ relation: v.union(v.literal("supports"), v.literal("contradicts")),
5736
+ confidence: v.optional(v.number()),
5737
+ rationale: v.optional(v.string())
5738
+ })
5739
+ )
5740
+ ),
5585
5741
  confidence: v.optional(v.number()),
5586
5742
  rationale: v.string(),
5587
5743
  trustedBypassAccessCheck: v.optional(v.boolean())
5588
5744
  })
5589
5745
  });
5590
5746
  var jsonRecordSchema2 = z.record(z.unknown());
5591
- var evidenceRelationSchema = z.enum(["supports", "contradicts"]);
5747
+ var evidenceRelationSchema2 = z.enum(["supports", "contradicts"]);
5748
+ var beliefRelationSchema2 = z.object({
5749
+ beliefId: z.string().optional().describe("Belief ID this evidence bears on."),
5750
+ beliefNodeId: z.string().optional().describe("Belief node ID this evidence bears on."),
5751
+ targetId: z.string().optional().describe("Belief target ID alias for beliefId/beliefNodeId."),
5752
+ relation: z.enum(["supports", "contradicts", "supporting", "contradicting"]).optional().describe("Relation alias for how the evidence bears on the belief."),
5753
+ evidenceRelation: evidenceRelationSchema2.optional().describe("Canonical relation: supports or contradicts."),
5754
+ confidence: z.number().optional().describe("Confidence in this evidence-to-belief relation."),
5755
+ weight: z.number().optional().describe("Support weight from -1.0 to +1.0 for this belief."),
5756
+ rationale: z.string().optional().describe("Why this relation exists.")
5757
+ });
5592
5758
  var createEvidenceArgs = z.object({
5593
5759
  topicId: z.string().optional().describe("Topic scope for the evidence."),
5594
5760
  text: z.string().describe("Canonical evidence text."),
5595
5761
  source: z.string().optional().describe("Source URL or source label."),
5596
5762
  sourceUrl: z.string().optional().describe("Canonical source URL."),
5597
- targetId: z.string().optional().describe("Belief, question, or worktree identifier to link or preserve on the evidence record."),
5763
+ targetId: z.string().optional().describe(
5764
+ "Belief, question, or worktree identifier to link or preserve on the evidence record. Belief targets require evidenceRelation or a nonzero signed weight."
5765
+ ),
5598
5766
  linkedBeliefNodeId: z.string().optional().describe("Belief node this evidence bears on."),
5599
- evidenceRelation: evidenceRelationSchema.optional().describe("How the evidence relates to the linked belief."),
5767
+ evidenceRelation: evidenceRelationSchema2.optional().describe(
5768
+ "How the evidence relates to the linked belief. Use supports for proof/fixes; use contradicts for bugs, regressions, or falsifying observations."
5769
+ ),
5770
+ beliefRelations: z.array(beliefRelationSchema2).optional().describe(
5771
+ "Additional belief relations for one evidence record. Use when the same evidence supports or contradicts multiple beliefs."
5772
+ ),
5600
5773
  confidence: z.number().optional().describe("Confidence in the evidence relation."),
5601
- weight: z.number().optional().describe("Support weight from -1.0 to +1.0."),
5774
+ weight: z.number().optional().describe("Nonzero support weight from -1.0 to +1.0."),
5602
5775
  metadata: jsonRecordSchema2.optional().describe("Metadata merged into the canonical evidence node."),
5603
5776
  rationale: z.string().describe("Why this evidence should enter the reasoning graph."),
5604
5777
  reasoning: z.string().optional().describe("Reasoning note preserved in evidence metadata."),
@@ -5639,6 +5812,35 @@ var createEvidenceInput = (input, context) => {
5639
5812
  context
5640
5813
  );
5641
5814
  };
5815
+ function relationWeight(input) {
5816
+ if (typeof input.weight === "number" && Number.isFinite(input.weight) && input.weight !== 0) {
5817
+ return input.weight;
5818
+ }
5819
+ const relation = String(
5820
+ input.evidenceRelation ?? input.relation ?? input.type ?? ""
5821
+ );
5822
+ if (relation !== "supports" && relation !== "supporting" && relation !== "contradicts" && relation !== "contradicting") {
5823
+ throw new Error(
5824
+ "Belief evidence links require evidenceRelation='supports'|'contradicts' or a nonzero signed weight."
5825
+ );
5826
+ }
5827
+ const confidence = typeof input.confidence === "number" ? Math.max(0, Math.min(1, input.confidence)) : 0.7;
5828
+ return relation === "contradicts" || relation === "contradicting" ? -confidence : confidence;
5829
+ }
5830
+ var linkEvidenceToBeliefInput = (input, context) => {
5831
+ const weight = relationWeight(input);
5832
+ return withUserId(
5833
+ compactRecord({
5834
+ beliefNodeId: input.beliefNodeId ?? input.beliefId ?? input.targetId,
5835
+ insightId: input.insightId ?? input.evidenceNodeId ?? input.evidenceId,
5836
+ type: weight < 0 ? "contradicting" : "supporting",
5837
+ confidence: Math.min(1, Math.abs(weight)),
5838
+ rationale: input.rationale ?? input.context,
5839
+ trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
5840
+ }),
5841
+ context
5842
+ );
5843
+ };
5642
5844
  var linkEvidenceToBeliefEdgeInput = (input, context) => withCreatedBy(
5643
5845
  compactRecord({
5644
5846
  fromNodeId: input.insightId ?? input.evidenceNodeId ?? input.evidenceId,
@@ -5649,7 +5851,7 @@ var linkEvidenceToBeliefEdgeInput = (input, context) => withCreatedBy(
5649
5851
  )}:${String(
5650
5852
  input.beliefNodeId ?? input.beliefId ?? input.targetId
5651
5853
  )}:informs`,
5652
- weight: typeof input.weight === "number" ? input.weight : input.type === "contradicting" ? -1 : 1,
5854
+ weight: relationWeight(input),
5653
5855
  context: input.rationale ?? input.context,
5654
5856
  skipLayerValidation: true,
5655
5857
  topicId: input.topicId,
@@ -5781,10 +5983,10 @@ var evidenceContracts = [
5781
5983
  sdkMethod: "linkEvidenceToBelief",
5782
5984
  summary: "Link evidence to a belief.",
5783
5985
  convex: {
5784
- module: "edges",
5785
- functionName: "create",
5986
+ module: "beliefs",
5987
+ functionName: "linkEvidence",
5786
5988
  kind: "mutation",
5787
- inputProjection: linkEvidenceToBeliefEdgeInput
5989
+ inputProjection: linkEvidenceToBeliefInput
5788
5990
  }
5789
5991
  }),
5790
5992
  surfaceContract({