@lucern/contracts 1.0.11 → 1.0.13

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 (123) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/function-registry/beliefs.d.ts +1 -1
  3. package/dist/function-registry/beliefs.js +126 -10
  4. package/dist/function-registry/beliefs.js.map +1 -1
  5. package/dist/function-registry/coding.d.ts +1 -1
  6. package/dist/function-registry/coding.js +124 -8
  7. package/dist/function-registry/coding.js.map +1 -1
  8. package/dist/function-registry/context.d.ts +44 -4
  9. package/dist/function-registry/context.js +146 -8
  10. package/dist/function-registry/context.js.map +1 -1
  11. package/dist/function-registry/contracts.d.ts +1 -1
  12. package/dist/function-registry/contracts.js +124 -8
  13. package/dist/function-registry/contracts.js.map +1 -1
  14. package/dist/function-registry/coordination.d.ts +1 -1
  15. package/dist/function-registry/coordination.js +124 -8
  16. package/dist/function-registry/coordination.js.map +1 -1
  17. package/dist/function-registry/edges.d.ts +1 -1
  18. package/dist/function-registry/edges.js +124 -8
  19. package/dist/function-registry/edges.js.map +1 -1
  20. package/dist/function-registry/evidence.d.ts +1 -1
  21. package/dist/function-registry/evidence.js +309 -40
  22. package/dist/function-registry/evidence.js.map +1 -1
  23. package/dist/function-registry/graph.d.ts +1 -1
  24. package/dist/function-registry/graph.js +126 -12
  25. package/dist/function-registry/graph.js.map +1 -1
  26. package/dist/function-registry/helpers.js +124 -8
  27. package/dist/function-registry/helpers.js.map +1 -1
  28. package/dist/function-registry/identity.d.ts +1 -1
  29. package/dist/function-registry/identity.js +124 -8
  30. package/dist/function-registry/identity.js.map +1 -1
  31. package/dist/function-registry/index.js +124 -8
  32. package/dist/function-registry/index.js.map +1 -1
  33. package/dist/function-registry/judgments.d.ts +1 -1
  34. package/dist/function-registry/judgments.js +124 -8
  35. package/dist/function-registry/judgments.js.map +1 -1
  36. package/dist/function-registry/legacy.d.ts +1 -1
  37. package/dist/function-registry/legacy.js +124 -8
  38. package/dist/function-registry/legacy.js.map +1 -1
  39. package/dist/function-registry/lenses.d.ts +1 -1
  40. package/dist/function-registry/lenses.js +124 -8
  41. package/dist/function-registry/lenses.js.map +1 -1
  42. package/dist/function-registry/manifest.d.ts +10 -4
  43. package/dist/function-registry/manifest.js +14 -1
  44. package/dist/function-registry/manifest.js.map +1 -1
  45. package/dist/function-registry/nodes.d.ts +1 -1
  46. package/dist/function-registry/nodes.js +124 -8
  47. package/dist/function-registry/nodes.js.map +1 -1
  48. package/dist/function-registry/ontologies.d.ts +1 -1
  49. package/dist/function-registry/ontologies.js +124 -8
  50. package/dist/function-registry/ontologies.js.map +1 -1
  51. package/dist/function-registry/pipeline.d.ts +1 -1
  52. package/dist/function-registry/pipeline.js +124 -8
  53. package/dist/function-registry/pipeline.js.map +1 -1
  54. package/dist/function-registry/questions.d.ts +1 -1
  55. package/dist/function-registry/questions.js +124 -8
  56. package/dist/function-registry/questions.js.map +1 -1
  57. package/dist/function-registry/tasks.d.ts +1 -1
  58. package/dist/function-registry/tasks.js +124 -8
  59. package/dist/function-registry/tasks.js.map +1 -1
  60. package/dist/function-registry/topics.d.ts +1 -1
  61. package/dist/function-registry/topics.js +126 -12
  62. package/dist/function-registry/topics.js.map +1 -1
  63. package/dist/function-registry/types.d.ts +1 -1
  64. package/dist/function-registry/worktrees.d.ts +1 -1
  65. package/dist/function-registry/worktrees.js +124 -8
  66. package/dist/function-registry/worktrees.js.map +1 -1
  67. package/dist/generated/infisicalRuntimeEnv.js +536 -1
  68. package/dist/generated/infisicalRuntimeEnv.js.map +1 -1
  69. package/dist/index.d.ts +2 -1
  70. package/dist/index.js +941 -14
  71. package/dist/index.js.map +1 -1
  72. package/dist/infisical-runtime.base.d.ts +42 -1
  73. package/dist/infisical-runtime.base.js +50 -1
  74. package/dist/infisical-runtime.base.js.map +1 -1
  75. package/dist/infisical-runtime.contract.d.ts +102 -0
  76. package/dist/infisical-runtime.contract.js +170 -1
  77. package/dist/infisical-runtime.contract.js.map +1 -1
  78. package/dist/infisical-runtime.platform-secrets.d.ts +102 -0
  79. package/dist/infisical-runtime.platform-secrets.js +120 -0
  80. package/dist/infisical-runtime.platform-secrets.js.map +1 -1
  81. package/dist/infisical-runtime.tenant-secrets.js.map +1 -1
  82. package/dist/manifests/infisical-runtime-manifest.d.ts +144 -1
  83. package/dist/manifests/infisical-runtime-manifest.js +170 -1
  84. package/dist/manifests/infisical-runtime-manifest.js.map +1 -1
  85. package/dist/manifests/invariants/index.js +24 -5
  86. package/dist/manifests/invariants/index.js.map +1 -1
  87. package/dist/manifests/invariants/inv-1-beliefs-append-only.js +24 -5
  88. package/dist/manifests/invariants/inv-1-beliefs-append-only.js.map +1 -1
  89. package/dist/projections/check-convex-args-shape.js +138 -5
  90. package/dist/projections/check-convex-args-shape.js.map +1 -1
  91. package/dist/projections/create-evidence.projection.d.ts +168 -0
  92. package/dist/projections/create-evidence.projection.js +138 -5
  93. package/dist/projections/create-evidence.projection.js.map +1 -1
  94. package/dist/projections/index.d.ts +28 -0
  95. package/dist/projections/index.js +138 -5
  96. package/dist/projections/index.js.map +1 -1
  97. package/dist/proof-attestation.json +1 -1
  98. package/dist/schemas/manifest.d.ts +20 -20
  99. package/dist/schemas/tables/kernel/platform.d.ts +4 -4
  100. package/dist/sdk-methods.contract.d.ts +3 -2
  101. package/dist/sdk-tools.contract.js +110 -7
  102. package/dist/sdk-tools.contract.js.map +1 -1
  103. package/dist/sdk-tools.contract.registry.js +110 -7
  104. package/dist/sdk-tools.contract.registry.js.map +1 -1
  105. package/dist/sdk-tools.contract.values.js +110 -7
  106. package/dist/sdk-tools.contract.values.js.map +1 -1
  107. package/dist/tool-contracts.context-orientation.d.ts +5 -0
  108. package/dist/tool-contracts.context-orientation.js +57 -0
  109. package/dist/tool-contracts.context-orientation.js.map +1 -0
  110. package/dist/tool-contracts.d.ts +1 -0
  111. package/dist/tool-contracts.intelligence-evidence.js +26 -4
  112. package/dist/tool-contracts.intelligence-evidence.js.map +1 -1
  113. package/dist/tool-contracts.js +111 -8
  114. package/dist/tool-contracts.js.map +1 -1
  115. package/dist/tool-contracts.lifecycle.js +2 -2
  116. package/dist/tool-contracts.lifecycle.js.map +1 -1
  117. package/dist/tool-contracts.questions-listing.js +27 -1
  118. package/dist/tool-contracts.questions-listing.js.map +1 -1
  119. package/dist/{tool-contracts.values-DjctSW7S.d.ts → tool-contracts.values-BhxfrXS5.d.ts} +3 -1
  120. package/dist/tool-contracts.values.d.ts +1 -0
  121. package/dist/tool-contracts.values.js +111 -8
  122. package/dist/tool-contracts.values.js.map +1 -1
  123. package/package.json +1 -1
@@ -69,7 +69,7 @@ type FunctionConvexTarget = {
69
69
  outputProjection?: ContractOutputProjection;
70
70
  };
71
71
  type FunctionGatewayTarget = {
72
- handler: "identity.whoami" | "beliefs.list" | "evidence.list" | "questions.list" | "worktrees.get" | "tasks.create" | "tasks.list" | "tasks.update" | "tasks.complete";
72
+ handler: "identity.whoami" | "beliefs.list" | "evidence.get" | "evidence.list" | "evidence.search" | "questions.list" | "worktrees.get" | "tasks.create" | "tasks.list" | "tasks.update" | "tasks.complete" | "context.lucernOrient" | "graph.listIntelligenceQueries" | "topics.graphSpine";
73
73
  };
74
74
 
75
75
  declare const evidenceContracts: readonly [{
@@ -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: {
@@ -1659,6 +1659,60 @@ var REMOVE_LENS_FROM_TOPIC = {
1659
1659
  tier: "workhorse"
1660
1660
  };
1661
1661
 
1662
+ // src/tool-contracts.context-orientation.ts
1663
+ var LUCERN_ORIENT = {
1664
+ name: "lucern_orient",
1665
+ description: "Load the Lucern reasoning grammar before operating. Like `git help` plus a repository CONTRIBUTING guide for reasoning state - teaches the git-shaped model of topics, campaigns, lanes, worktrees, beliefs, questions, evidence, receipts, gates, and merges.",
1666
+ parameters: {
1667
+ audience: {
1668
+ type: "string",
1669
+ description: "Audience for the primer: agent, human, operator, or developer.",
1670
+ enum: ["agent", "human", "operator", "developer"]
1671
+ },
1672
+ depth: {
1673
+ type: "string",
1674
+ description: "Orientation depth: quick, standard, or deep.",
1675
+ enum: ["quick", "standard", "deep"]
1676
+ },
1677
+ situation: {
1678
+ type: "string",
1679
+ description: "Optional task or query context used to tailor suggested next calls."
1680
+ },
1681
+ includeExamples: {
1682
+ type: "boolean",
1683
+ description: "Whether to include concrete tool-call examples."
1684
+ },
1685
+ includeToolMap: {
1686
+ type: "boolean",
1687
+ description: "Whether to include situation-to-tool routing guidance."
1688
+ },
1689
+ includeFuture: {
1690
+ type: "boolean",
1691
+ description: "Whether to include future exemplar, gauntlet, and training-data capabilities."
1692
+ }
1693
+ },
1694
+ required: [],
1695
+ response: {
1696
+ description: "Canonical operator primer for Lucern's git-shaped reasoning substrate.",
1697
+ fields: {
1698
+ schemaVersion: "string - lucern_orientation.v1",
1699
+ canonicalMentalModel: "object - concise model of Lucern as git-shaped reasoning state",
1700
+ workflow: "array - recommended branch -> investigate -> prove gate -> merge workflow",
1701
+ grammarMap: "array - primitive-to-git-analogy map for topics, campaigns, worktrees, beliefs, questions, evidence, edges, contradictions, and gates",
1702
+ firstMoves: "array - recommended first tools for a cold-start agent",
1703
+ receiptRules: "array - how to interpret candidateCounts, broadening, coverageWarning, narrativeCoverage, synthesisLints, and noDefaultGlobalScan",
1704
+ safetyRules: "array - mutation and completion rules that preserve reasoning lineage",
1705
+ toolMap: "array | undefined - situation-to-tool routing map when requested",
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",
1708
+ suggestedNextCalls: "array - safe next tool calls for the current situation"
1709
+ }
1710
+ },
1711
+ ownerModule: "reasoning-kernel",
1712
+ ontologyPrimitive: "graph",
1713
+ tier: "showcase"
1714
+ };
1715
+
1662
1716
  // src/tool-contracts.intelligence-evidence.ts
1663
1717
  var DETECT_CONFIRMATION_BIAS = {
1664
1718
  name: "detect_confirmation_bias",
@@ -1813,7 +1867,7 @@ var SEARCH_EVIDENCE = {
1813
1867
  };
1814
1868
  var CREATE_EVIDENCE = {
1815
1869
  name: "create_evidence",
1816
- 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.",
1817
1871
  parameters: {
1818
1872
  topicId: { type: "string", description: "Topic scope" },
1819
1873
  text: { type: "string", description: "Canonical evidence text" },
@@ -1824,7 +1878,20 @@ var CREATE_EVIDENCE = {
1824
1878
  },
1825
1879
  weight: {
1826
1880
  type: "number",
1827
- 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."
1828
1895
  },
1829
1896
  metadata: {
1830
1897
  type: "object",
@@ -1934,7 +2001,7 @@ var LINK_EVIDENCE = {
1934
2001
  };
1935
2002
  var LINK_EVIDENCE_TO_BELIEF = {
1936
2003
  name: "link_evidence_to_belief",
1937
- 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.",
1938
2005
  parameters: {
1939
2006
  evidenceId: { type: "string", description: "The evidence node ID" },
1940
2007
  beliefId: { type: "string", description: "The belief node ID" },
@@ -1942,9 +2009,18 @@ var LINK_EVIDENCE_TO_BELIEF = {
1942
2009
  type: "number",
1943
2010
  description: "Support weight: -1.0 (contradicts) to +1.0 (supports)"
1944
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
+ },
1945
2021
  rationale: { type: "string", description: "Why this evidence is relevant" }
1946
2022
  },
1947
- required: ["evidenceId", "beliefId", "weight"],
2023
+ required: ["evidenceId", "beliefId"],
1948
2024
  response: {
1949
2025
  description: "The created edge linking evidence to belief",
1950
2026
  fields: {
@@ -2709,10 +2785,34 @@ var COMPILE_CONTEXT = {
2709
2785
  type: "string",
2710
2786
  description: "Optional source kind used as a resolver signal, such as cli, worktree, commit, or docs."
2711
2787
  },
2788
+ campaign: {
2789
+ type: "number",
2790
+ description: "Optional campaign dimension seed. When supplied without topicId, the compiler fans out across all carrier topics for that campaign instead of resolving a single topic."
2791
+ },
2792
+ lane: {
2793
+ type: "string",
2794
+ description: "Optional lane dimension seed. When supplied without topicId, the compiler reads all matching worktrees and their carrier topics."
2795
+ },
2796
+ status: {
2797
+ type: "string",
2798
+ description: "Optional state/status dimension seed for worktrees and graph rows."
2799
+ },
2800
+ principalId: {
2801
+ type: "string",
2802
+ description: "Optional principal seed for work authored, touched, or owned by a human, agent, group, or service principal."
2803
+ },
2804
+ workspaceId: {
2805
+ type: "string",
2806
+ description: "Optional workspace seed used by hosted MCP and SDK clients when compiling tenant-scoped context."
2807
+ },
2712
2808
  budget: {
2713
2809
  type: "number",
2714
2810
  description: "Token budget for prompt injection planning"
2715
2811
  },
2812
+ tokenBudget: {
2813
+ type: "number",
2814
+ description: "Compatibility alias for budget. External MCP clients may send tokenBudget when requesting prompt injection planning."
2815
+ },
2716
2816
  ranking: {
2717
2817
  type: "string",
2718
2818
  description: "Ranking profile for context ordering",
@@ -2748,7 +2848,9 @@ var COMPILE_CONTEXT = {
2748
2848
  recentEvidence: "array \u2014 recent evidence ranked for this query",
2749
2849
  contradictions: "array \u2014 unresolved contradiction records",
2750
2850
  relatedEntities: "array | undefined \u2014 ranked ontological entities in scope",
2751
- 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",
2752
2854
  injectionPolicy: "object \u2014 token-budgeted section selections",
2753
2855
  diagnostics: "object \u2014 scoring and utilization telemetry"
2754
2856
  }
@@ -4619,6 +4721,7 @@ var MCP_TOOL_CONTRACTS = {
4619
4721
  update_worktree_metadata: UPDATE_WORKTREE_METADATA,
4620
4722
  identity_whoami: IDENTITY_WHOAMI,
4621
4723
  resolve_interactive_principal: RESOLVE_INTERACTIVE_PRINCIPAL,
4724
+ lucern_orient: LUCERN_ORIENT,
4622
4725
  compile_context: COMPILE_CONTEXT,
4623
4726
  record_scope_learning: RECORD_SCOPE_LEARNING,
4624
4727
  pipeline_snapshot: PIPELINE_SNAPSHOT,
@@ -4695,6 +4798,12 @@ var internalSystem = {
4695
4798
  mcp: "internal",
4696
4799
  cli: "internal"
4697
4800
  };
4801
+ var internalSdkRestOnly = {
4802
+ sdk: "internal",
4803
+ rest: "internal",
4804
+ mcp: "none",
4805
+ cli: "none"
4806
+ };
4698
4807
  var publicWithInternalMcp = {
4699
4808
  sdk: "public",
4700
4809
  rest: "public",
@@ -4734,6 +4843,7 @@ function entries(names, surfaceClass, surfaceIntent, surfaces, rationale) {
4734
4843
  );
4735
4844
  }
4736
4845
  var MCP_CORE_OPERATION_NAMES = [
4846
+ "lucern_orient",
4737
4847
  "compile_context",
4738
4848
  "identity_whoami",
4739
4849
  "resolve_interactive_principal",
@@ -4743,7 +4853,6 @@ var MCP_CORE_OPERATION_NAMES = [
4743
4853
  "get_belief",
4744
4854
  "list_beliefs",
4745
4855
  "refine_belief",
4746
- "modulate_confidence",
4747
4856
  "fork_belief",
4748
4857
  "archive_belief",
4749
4858
  "search_beliefs",
@@ -5011,6 +5120,13 @@ var LUCERN_OPERATION_MANIFEST = {
5011
5120
  internalSystem,
5012
5121
  "Lucern system/background operation. Available to platform code paths, hidden from public MCP discovery."
5013
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
+ },
5014
5130
  ...entries(
5015
5131
  LEGACY_COMPAT_OPERATION_NAMES,
5016
5132
  "legacy_compat",
@@ -5329,6 +5445,20 @@ function surfaceContract(args) {
5329
5445
  });
5330
5446
  }
5331
5447
 
5448
+ // src/ids.contract.ts
5449
+ var PREFIXED_ID_PATTERN = /^([a-z][a-z0-9]*)_(.+)$/;
5450
+ function decodePrefixedId(id) {
5451
+ const normalized = id.trim();
5452
+ const match = PREFIXED_ID_PATTERN.exec(normalized);
5453
+ if (!match) {
5454
+ throw new Error(`Invalid prefixed ID: ${id}`);
5455
+ }
5456
+ return {
5457
+ prefix: match[1],
5458
+ value: match[2]
5459
+ };
5460
+ }
5461
+
5332
5462
  // src/projections/projection-dsl.ts
5333
5463
  function defineProjection(def) {
5334
5464
  return def;
@@ -5336,6 +5466,23 @@ function defineProjection(def) {
5336
5466
 
5337
5467
  // src/projections/create-evidence.projection.ts
5338
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
+ });
5339
5486
  var createEvidenceInputSchemaBase = z.object({
5340
5487
  projectId: z.string().optional(),
5341
5488
  topicId: z.string().optional(),
@@ -5357,7 +5504,8 @@ var createEvidenceInputSchemaBase = z.object({
5357
5504
  targetId: z.string().optional(),
5358
5505
  targetNodeId: z.string().optional(),
5359
5506
  linkedBeliefNodeId: z.string().optional(),
5360
- evidenceRelation: z.enum(["supports", "contradicts"]).optional(),
5507
+ evidenceRelation: evidenceRelationSchema.optional(),
5508
+ beliefRelations: z.array(beliefRelationSchema).optional(),
5361
5509
  confidence: z.number().optional(),
5362
5510
  weight: z.number().optional(),
5363
5511
  reasoning: z.string().optional(),
@@ -5383,15 +5531,103 @@ function isRecord(value) {
5383
5531
  function recordValue2(value) {
5384
5532
  return isRecord(value) ? value : {};
5385
5533
  }
5534
+ function normalizeTopicIdForKernel(topicId) {
5535
+ const normalized = topicId?.trim();
5536
+ if (!normalized) {
5537
+ return void 0;
5538
+ }
5539
+ try {
5540
+ const decoded = decodePrefixedId(normalized);
5541
+ return decoded.prefix === "top" ? decoded.value : normalized;
5542
+ } catch {
5543
+ return normalized;
5544
+ }
5545
+ }
5546
+ function normalizeWorktreeId(value) {
5547
+ const normalized = value?.trim();
5548
+ if (!normalized) {
5549
+ return void 0;
5550
+ }
5551
+ if (normalized.startsWith("wt_")) {
5552
+ return normalized.slice("wt_".length);
5553
+ }
5554
+ return normalized;
5555
+ }
5556
+ function targetKind(targetId) {
5557
+ const normalized = targetId?.trim();
5558
+ if (!normalized) {
5559
+ return "unknown";
5560
+ }
5561
+ if (normalized.startsWith("wt_") || /^tn[a-z0-9]+$/i.test(normalized)) {
5562
+ return "worktree";
5563
+ }
5564
+ if (normalized.startsWith("que_")) {
5565
+ return "question";
5566
+ }
5567
+ if (normalized.startsWith("bel_")) {
5568
+ return "belief";
5569
+ }
5570
+ return "unknown";
5571
+ }
5572
+ function normalizeRelation(value, weight) {
5573
+ if (value === "supports" || value === "supporting") {
5574
+ return "supports";
5575
+ }
5576
+ if (value === "contradicts" || value === "contradicting") {
5577
+ return "contradicts";
5578
+ }
5579
+ if (weight === void 0) {
5580
+ return void 0;
5581
+ }
5582
+ return weight < 0 ? "contradicts" : "supports";
5583
+ }
5584
+ function normalizeConfidence(confidence, weight) {
5585
+ if (confidence !== void 0) {
5586
+ return Math.min(1, Math.max(0, confidence));
5587
+ }
5588
+ if (weight === void 0) {
5589
+ return void 0;
5590
+ }
5591
+ return Math.min(1, Math.max(0, Math.abs(weight)));
5592
+ }
5593
+ function normalizeBeliefRelation(relation) {
5594
+ const beliefNodeId = relation.beliefNodeId ?? relation.beliefId ?? relation.targetId;
5595
+ if (!beliefNodeId) {
5596
+ return void 0;
5597
+ }
5598
+ const weight = typeof relation.weight === "number" ? relation.weight : void 0;
5599
+ const evidenceRelation = normalizeRelation(
5600
+ relation.evidenceRelation ?? relation.relation,
5601
+ weight
5602
+ );
5603
+ if (!evidenceRelation) {
5604
+ return void 0;
5605
+ }
5606
+ return compactRecord2({
5607
+ beliefNodeId,
5608
+ relation: evidenceRelation,
5609
+ confidence: normalizeConfidence(relation.confidence, weight),
5610
+ rationale: relation.rationale
5611
+ });
5612
+ }
5386
5613
  var createEvidenceProjection = defineProjection({
5387
5614
  contractName: "create_evidence",
5388
5615
  inputSchema: createEvidenceInputSchema,
5389
5616
  project: (input) => {
5390
5617
  const text = input.text ?? input.canonicalText;
5391
5618
  const weight = typeof input.weight === "number" ? input.weight : void 0;
5619
+ const target = input.targetId ?? input.targetNodeId;
5620
+ const kind = targetKind(target);
5621
+ const linkedWorktreeId = kind === "worktree" ? normalizeWorktreeId(target) : void 0;
5622
+ const linkedBeliefNodeId = input.linkedBeliefNodeId ?? (kind === "belief" || kind === "unknown" ? input.targetNodeId ?? input.targetId : void 0);
5623
+ const evidenceRelation = linkedBeliefNodeId ? normalizeRelation(input.evidenceRelation, weight) : void 0;
5624
+ const confidence = evidenceRelation ? normalizeConfidence(input.confidence, weight) : void 0;
5625
+ const beliefRelations = input.beliefRelations?.map(normalizeBeliefRelation).filter(
5626
+ (relation) => relation !== void 0
5627
+ );
5392
5628
  return compactRecord2({
5393
5629
  projectId: input.projectId,
5394
- topicId: input.topicId,
5630
+ topicId: normalizeTopicIdForKernel(input.topicId),
5395
5631
  text,
5396
5632
  title: input.title ?? text,
5397
5633
  content: input.content ?? text,
@@ -5410,13 +5646,16 @@ var createEvidenceProjection = defineProjection({
5410
5646
  source: input.source,
5411
5647
  targetId: input.targetId,
5412
5648
  targetNodeId: input.targetNodeId,
5649
+ targetKind: kind === "unknown" ? void 0 : kind,
5650
+ linkedWorktreeId,
5413
5651
  weight,
5414
5652
  reasoning: input.reasoning,
5415
5653
  rationale: input.rationale
5416
5654
  }),
5417
- linkedBeliefNodeId: input.linkedBeliefNodeId ?? input.targetNodeId ?? input.targetId,
5418
- evidenceRelation: input.evidenceRelation ?? (weight === void 0 ? void 0 : weight < 0 ? "contradicts" : "supports"),
5419
- confidence: input.confidence ?? (weight === void 0 ? void 0 : Math.min(1, Math.max(0, Math.abs(weight)))),
5655
+ linkedBeliefNodeId,
5656
+ evidenceRelation,
5657
+ confidence,
5658
+ beliefRelations: beliefRelations && beliefRelations.length > 0 ? beliefRelations : void 0,
5420
5659
  rationale: input.rationale,
5421
5660
  trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
5422
5661
  });
@@ -5445,21 +5684,44 @@ var createEvidenceProjection = defineProjection({
5445
5684
  v.literal("contradicts")
5446
5685
  )
5447
5686
  ),
5687
+ beliefRelations: v.optional(
5688
+ v.array(
5689
+ v.object({
5690
+ beliefNodeId: v.string(),
5691
+ relation: v.union(v.literal("supports"), v.literal("contradicts")),
5692
+ confidence: v.optional(v.number()),
5693
+ rationale: v.optional(v.string())
5694
+ })
5695
+ )
5696
+ ),
5448
5697
  confidence: v.optional(v.number()),
5449
5698
  rationale: v.string(),
5450
5699
  trustedBypassAccessCheck: v.optional(v.boolean())
5451
5700
  })
5452
5701
  });
5453
5702
  var jsonRecordSchema2 = z.record(z.unknown());
5454
- var evidenceRelationSchema = z.enum(["supports", "contradicts"]);
5703
+ var evidenceRelationSchema2 = z.enum(["supports", "contradicts"]);
5704
+ var beliefRelationSchema2 = z.object({
5705
+ beliefId: z.string().optional().describe("Belief ID this evidence bears on."),
5706
+ beliefNodeId: z.string().optional().describe("Belief node ID this evidence bears on."),
5707
+ targetId: z.string().optional().describe("Belief target ID alias for beliefId/beliefNodeId."),
5708
+ relation: z.enum(["supports", "contradicts", "supporting", "contradicting"]).optional().describe("Relation alias for how the evidence bears on the belief."),
5709
+ evidenceRelation: evidenceRelationSchema2.optional().describe("Canonical relation: supports or contradicts."),
5710
+ confidence: z.number().optional().describe("Confidence in this evidence-to-belief relation."),
5711
+ weight: z.number().optional().describe("Support weight from -1.0 to +1.0 for this belief."),
5712
+ rationale: z.string().optional().describe("Why this relation exists.")
5713
+ });
5455
5714
  var createEvidenceArgs = z.object({
5456
5715
  topicId: z.string().optional().describe("Topic scope for the evidence."),
5457
5716
  text: z.string().describe("Canonical evidence text."),
5458
5717
  source: z.string().optional().describe("Source URL or source label."),
5459
5718
  sourceUrl: z.string().optional().describe("Canonical source URL."),
5460
- targetId: z.string().optional().describe("Belief or question identifier to link immediately."),
5719
+ targetId: z.string().optional().describe("Belief, question, or worktree identifier to link or preserve on the evidence record."),
5461
5720
  linkedBeliefNodeId: z.string().optional().describe("Belief node this evidence bears on."),
5462
- evidenceRelation: evidenceRelationSchema.optional().describe("How the evidence relates to the linked belief."),
5721
+ evidenceRelation: evidenceRelationSchema2.optional().describe("How the evidence relates to the linked belief."),
5722
+ beliefRelations: z.array(beliefRelationSchema2).optional().describe(
5723
+ "Additional belief relations for one evidence record. Use when the same evidence supports or contradicts multiple beliefs."
5724
+ ),
5463
5725
  confidence: z.number().optional().describe("Confidence in the evidence relation."),
5464
5726
  weight: z.number().optional().describe("Support weight from -1.0 to +1.0."),
5465
5727
  metadata: jsonRecordSchema2.optional().describe("Metadata merged into the canonical evidence node."),
@@ -5490,11 +5752,6 @@ var addEvidenceArgs = z.object({
5490
5752
  contentType: z.string().optional().describe("Content format or MIME hint."),
5491
5753
  metadata: jsonRecordSchema2.optional().describe("Optional metadata merged into the evidence node.")
5492
5754
  });
5493
- var evidenceIdInput = (input) => compactRecord({
5494
- evidenceId: input.evidenceId,
5495
- insightId: input.insightId,
5496
- nodeId: input.nodeId ?? input.id ?? input.evidenceId
5497
- });
5498
5755
  var createEvidenceInput = (input, context) => {
5499
5756
  const parsed = createEvidenceProjection.inputSchema.safeParse(input);
5500
5757
  if (!parsed.success) {
@@ -5507,6 +5764,30 @@ var createEvidenceInput = (input, context) => {
5507
5764
  context
5508
5765
  );
5509
5766
  };
5767
+ function relationWeight(input) {
5768
+ if (typeof input.weight === "number") {
5769
+ return input.weight;
5770
+ }
5771
+ const confidence = typeof input.confidence === "number" ? Math.max(0, Math.min(1, input.confidence)) : 0.7;
5772
+ const relation = String(
5773
+ input.evidenceRelation ?? input.relation ?? input.type ?? ""
5774
+ );
5775
+ return relation === "contradicts" || relation === "contradicting" ? -confidence : confidence;
5776
+ }
5777
+ var linkEvidenceToBeliefInput = (input, context) => {
5778
+ const weight = relationWeight(input);
5779
+ return withUserId(
5780
+ compactRecord({
5781
+ beliefNodeId: input.beliefNodeId ?? input.beliefId ?? input.targetId,
5782
+ insightId: input.insightId ?? input.evidenceNodeId ?? input.evidenceId,
5783
+ type: weight < 0 ? "contradicting" : "supporting",
5784
+ confidence: Math.min(1, Math.abs(weight)),
5785
+ rationale: input.rationale ?? input.context,
5786
+ trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
5787
+ }),
5788
+ context
5789
+ );
5790
+ };
5510
5791
  var linkEvidenceToBeliefEdgeInput = (input, context) => withCreatedBy(
5511
5792
  compactRecord({
5512
5793
  fromNodeId: input.insightId ?? input.evidenceNodeId ?? input.evidenceId,
@@ -5608,11 +5889,8 @@ var evidenceContracts = [
5608
5889
  sdkNamespace: "evidence",
5609
5890
  sdkMethod: "getEvidence",
5610
5891
  summary: "Get evidence.",
5611
- convex: {
5612
- module: "evidence",
5613
- functionName: "getById",
5614
- kind: "query",
5615
- inputProjection: evidenceIdInput
5892
+ gateway: {
5893
+ handler: "evidence.get"
5616
5894
  }
5617
5895
  }),
5618
5896
  surfaceContract({
@@ -5638,17 +5916,8 @@ var evidenceContracts = [
5638
5916
  sdkNamespace: "evidence",
5639
5917
  sdkMethod: "searchEvidence",
5640
5918
  summary: "Search evidence.",
5641
- convex: {
5642
- module: "nodes",
5643
- functionName: "search",
5644
- kind: "query",
5645
- inputProjection: (input) => compactRecord({
5646
- searchQuery: input.searchQuery ?? input.q ?? input.query,
5647
- projectId: input.projectId,
5648
- topicId: input.topicId,
5649
- nodeType: "evidence",
5650
- limit: input.limit
5651
- })
5919
+ gateway: {
5920
+ handler: "evidence.search"
5652
5921
  }
5653
5922
  }),
5654
5923
  surfaceContract({
@@ -5661,10 +5930,10 @@ var evidenceContracts = [
5661
5930
  sdkMethod: "linkEvidenceToBelief",
5662
5931
  summary: "Link evidence to a belief.",
5663
5932
  convex: {
5664
- module: "edges",
5665
- functionName: "create",
5933
+ module: "beliefs",
5934
+ functionName: "linkEvidence",
5666
5935
  kind: "mutation",
5667
- inputProjection: linkEvidenceToBeliefEdgeInput
5936
+ inputProjection: linkEvidenceToBeliefInput
5668
5937
  }
5669
5938
  }),
5670
5939
  surfaceContract({