@lucern/contracts 1.0.16 → 1.0.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. package/CHANGELOG.md +3 -0
  2. package/dist/api-enums.contract.d.ts +2 -2
  3. package/dist/api-enums.contract.js +2 -8
  4. package/dist/api-enums.contract.js.map +1 -1
  5. package/dist/context-pack.contract.d.ts +27 -7
  6. package/dist/context-pack.contract.js.map +1 -1
  7. package/dist/function-registry/beliefs.js +109 -115
  8. package/dist/function-registry/beliefs.js.map +1 -1
  9. package/dist/function-registry/coding.js +68 -91
  10. package/dist/function-registry/coding.js.map +1 -1
  11. package/dist/function-registry/context.js +68 -91
  12. package/dist/function-registry/context.js.map +1 -1
  13. package/dist/function-registry/contracts.js +68 -91
  14. package/dist/function-registry/contracts.js.map +1 -1
  15. package/dist/function-registry/coordination.js +68 -91
  16. package/dist/function-registry/coordination.js.map +1 -1
  17. package/dist/function-registry/edges.js +68 -91
  18. package/dist/function-registry/edges.js.map +1 -1
  19. package/dist/function-registry/evidence.js +182 -125
  20. package/dist/function-registry/evidence.js.map +1 -1
  21. package/dist/function-registry/graph.js +68 -91
  22. package/dist/function-registry/graph.js.map +1 -1
  23. package/dist/function-registry/helpers.js +68 -91
  24. package/dist/function-registry/helpers.js.map +1 -1
  25. package/dist/function-registry/identity.js +68 -91
  26. package/dist/function-registry/identity.js.map +1 -1
  27. package/dist/function-registry/index.js +68 -91
  28. package/dist/function-registry/index.js.map +1 -1
  29. package/dist/function-registry/judgments.js +68 -91
  30. package/dist/function-registry/judgments.js.map +1 -1
  31. package/dist/function-registry/legacy.js +68 -91
  32. package/dist/function-registry/legacy.js.map +1 -1
  33. package/dist/function-registry/lenses.js +68 -91
  34. package/dist/function-registry/lenses.js.map +1 -1
  35. package/dist/function-registry/manifest.d.ts +3 -3
  36. package/dist/function-registry/manifest.js +3 -3
  37. package/dist/function-registry/manifest.js.map +1 -1
  38. package/dist/function-registry/nodes.js +68 -91
  39. package/dist/function-registry/nodes.js.map +1 -1
  40. package/dist/function-registry/ontologies.js +68 -91
  41. package/dist/function-registry/ontologies.js.map +1 -1
  42. package/dist/function-registry/pipeline.js +68 -91
  43. package/dist/function-registry/pipeline.js.map +1 -1
  44. package/dist/function-registry/questions.js +68 -91
  45. package/dist/function-registry/questions.js.map +1 -1
  46. package/dist/function-registry/tasks.js +68 -91
  47. package/dist/function-registry/tasks.js.map +1 -1
  48. package/dist/function-registry/topics.js +68 -91
  49. package/dist/function-registry/topics.js.map +1 -1
  50. package/dist/function-registry/worktrees.js +68 -91
  51. package/dist/function-registry/worktrees.js.map +1 -1
  52. package/dist/generated/convexSchemas.js +2 -2
  53. package/dist/generated/convexSchemas.js.map +1 -1
  54. package/dist/index.d.ts +4 -4
  55. package/dist/index.js +162 -130
  56. package/dist/index.js.map +1 -1
  57. package/dist/manifests/invariant-manifest.d.ts +1 -1
  58. package/dist/manifests/invariants/index.d.ts +1 -1
  59. package/dist/manifests/invariants/index.js +1 -1
  60. package/dist/manifests/invariants/index.js.map +1 -1
  61. package/dist/manifests/invariants/inv-1-beliefs-append-only.d.ts +1 -1
  62. package/dist/manifests/invariants/inv-14-no-silent-transitions.d.ts +1 -1
  63. package/dist/manifests/invariants/manifest-1-projections-declare-audit.d.ts +1 -1
  64. package/dist/manifests/invariants/manifest-1-projections-declare-audit.js +1 -1
  65. package/dist/manifests/invariants/manifest-1-projections-declare-audit.js.map +1 -1
  66. package/dist/projections/{modulate-confidence.projection.d.ts → append-sl-scoring.projection.d.ts} +69 -69
  67. package/dist/projections/{modulate-confidence.projection.js → append-sl-scoring.projection.js} +14 -14
  68. package/dist/projections/append-sl-scoring.projection.js.map +1 -0
  69. package/dist/projections/check-convex-args-shape.js +88 -29
  70. package/dist/projections/check-convex-args-shape.js.map +1 -1
  71. package/dist/projections/create-evidence.projection.js +76 -17
  72. package/dist/projections/create-evidence.projection.js.map +1 -1
  73. package/dist/projections/index.d.ts +47 -47
  74. package/dist/projections/index.js +88 -29
  75. package/dist/projections/index.js.map +1 -1
  76. package/dist/proof-attestation.json +3 -3
  77. package/dist/schemas/index.js +6 -4
  78. package/dist/schemas/index.js.map +1 -1
  79. package/dist/schemas/manifest.d.ts +110 -60
  80. package/dist/schemas/manifest.js +6 -4
  81. package/dist/schemas/manifest.js.map +1 -1
  82. package/dist/schemas/tables/kernel/intelligence.d.ts +20 -10
  83. package/dist/schemas/tables/kernel/intelligence.js +4 -2
  84. package/dist/schemas/tables/kernel/intelligence.js.map +1 -1
  85. package/dist/schemas/tables/kernel/spine.d.ts +2 -2
  86. package/dist/schemas/tables/kernel/spine.js +2 -2
  87. package/dist/schemas/tables/kernel/spine.js.map +1 -1
  88. package/dist/schemas.values.js +6 -4
  89. package/dist/schemas.values.js.map +1 -1
  90. package/dist/sdk-methods.contract.d.ts +6 -16
  91. package/dist/sdk-tools.contract.js +65 -88
  92. package/dist/sdk-tools.contract.js.map +1 -1
  93. package/dist/sdk-tools.contract.registry.js +65 -88
  94. package/dist/sdk-tools.contract.registry.js.map +1 -1
  95. package/dist/sdk-tools.contract.values.js +65 -88
  96. package/dist/sdk-tools.contract.values.js.map +1 -1
  97. package/dist/tool-contracts.d.ts +1 -1
  98. package/dist/tool-contracts.graph.js +3 -3
  99. package/dist/tool-contracts.graph.js.map +1 -1
  100. package/dist/tool-contracts.intelligence-evidence.js +7 -7
  101. package/dist/tool-contracts.intelligence-evidence.js.map +1 -1
  102. package/dist/tool-contracts.js +66 -89
  103. package/dist/tool-contracts.js.map +1 -1
  104. package/dist/tool-contracts.lifecycle.d.ts +2 -2
  105. package/dist/tool-contracts.lifecycle.js +49 -68
  106. package/dist/tool-contracts.lifecycle.js.map +1 -1
  107. package/dist/tool-contracts.pipeline-coordination.js +1 -1
  108. package/dist/tool-contracts.pipeline-coordination.js.map +1 -1
  109. package/dist/tool-contracts.questions-listing.js +5 -9
  110. package/dist/tool-contracts.questions-listing.js.map +1 -1
  111. package/dist/{tool-contracts.values-BhxfrXS5.d.ts → tool-contracts.values-CCoI3qQY.d.ts} +3 -3
  112. package/dist/tool-contracts.values.d.ts +1 -1
  113. package/dist/tool-contracts.values.js +66 -89
  114. package/dist/tool-contracts.values.js.map +1 -1
  115. package/package.json +1 -1
  116. package/dist/projections/modulate-confidence.projection.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -55,3 +55,6 @@ All notable changes to `@lucern/contracts` are tracked in this repository.
55
55
 
56
56
  ## [1.0.16] - 2026-06-01
57
57
  - Release notes pending.
58
+
59
+ ## [1.0.17] - 2026-06-01
60
+ - Release notes pending.
@@ -13,10 +13,10 @@ type ReasoningMethod = (typeof REASONING_METHODS)[number];
13
13
  * Removing or renaming an existing value is a BREAKING CHANGE.
14
14
  */
15
15
  /** Fork reasons — why a scored belief was branched */
16
- declare const FORK_REASONS: readonly ["refinement", "contradiction_response", "scope_change", "confidence_collapse", "manual"];
16
+ declare const FORK_REASONS: readonly ["refinement", "contradiction_response", "scope_change", "confidence_collapse"];
17
17
  type ForkReason = (typeof FORK_REASONS)[number];
18
18
  /** Confidence modulation triggers — what caused a confidence change */
19
- declare const CONFIDENCE_TRIGGERS: readonly ["evidence_added", "evidence_removed", "contradiction_detected", "contradiction_resolved", "manual", "decay", "agent_assessment", "worktree_outcome", "worktree_completed", "fusion", "discount", "deduction"];
19
+ declare const CONFIDENCE_TRIGGERS: readonly ["evidence_added", "evidence_removed", "contradiction_detected", "contradiction_resolved", "agent_assessment", "worktree_outcome", "worktree_completed", "fusion", "discount", "deduction"];
20
20
  type ConfidenceTrigger = (typeof CONFIDENCE_TRIGGERS)[number];
21
21
  /** Belief status — lifecycle state */
22
22
  declare const BELIEF_STATUSES: readonly ["unscored", "scored", "archived"];
@@ -20,10 +20,8 @@ var FORK_REASONS = [
20
20
  // Created in response to a detected contradiction
21
21
  "scope_change",
22
22
  // Belief scope narrowed or broadened
23
- "confidence_collapse",
23
+ "confidence_collapse"
24
24
  // Confidence dropped below viability threshold
25
- "manual"
26
- // User-initiated fork without specific trigger
27
25
  ];
28
26
  var CONFIDENCE_TRIGGERS = [
29
27
  "evidence_added",
@@ -34,12 +32,8 @@ var CONFIDENCE_TRIGGERS = [
34
32
  // A contradiction was flagged involving this belief
35
33
  "contradiction_resolved",
36
34
  // A contradiction was resolved
37
- "manual",
38
- // User manually adjusted confidence
39
- "decay",
40
- // Time-based confidence erosion
41
35
  "agent_assessment",
42
- // An agent provided a structured assessment
36
+ // An agent-proposed scoring event with concrete provenance
43
37
  "worktree_outcome",
44
38
  // Worktree outcome determined this confidence
45
39
  "worktree_completed",
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/types/reasoning-method.ts","../src/api-enums.contract.ts"],"names":[],"mappings":";AACO,IAAM,iBAAA,GAAoB;AAAA,EAC/B,WAAA;AAAA,EACA,WAAA;AAAA,EACA,WAAA;AAAA,EACA,YAAA;AAAA,EACA,QAAA;AAAA,EACA,eAAA;AAAA,EACA,aAAA;AAAA,EACA,aAAA;AAAA,EACA,UAAA;AAAA,EACA;AACF;;;ACIO,IAAM,YAAA,GAAe;AAAA,EAC1B,YAAA;AAAA;AAAA,EACA,wBAAA;AAAA;AAAA,EACA,cAAA;AAAA;AAAA,EACA,qBAAA;AAAA;AAAA,EACA;AAAA;AACF;AAIO,IAAM,mBAAA,GAAsB;AAAA,EACjC,gBAAA;AAAA;AAAA,EACA,kBAAA;AAAA;AAAA,EACA,wBAAA;AAAA;AAAA,EACA,wBAAA;AAAA;AAAA,EACA,QAAA;AAAA;AAAA,EACA,OAAA;AAAA;AAAA,EACA,kBAAA;AAAA;AAAA,EACA,kBAAA;AAAA;AAAA,EACA,oBAAA;AAAA;AAAA,EACA,QAAA;AAAA;AAAA,EACA,UAAA;AAAA;AAAA,EACA;AAAA;AACF;AAIO,IAAM,eAAA,GAAkB;AAAA,EAC7B,UAAA;AAAA;AAAA,EACA,QAAA;AAAA;AAAA,EACA;AAAA;AACF;AAaO,IAAM,YAAA,GAAe;AAAA,EAC1B,QAAA;AAAA;AAAA,EACA,WAAA;AAAA;AAAA,EACA;AAAA;AACF;AAIO,IAAM,wBAAA,GAA2B;AAAA,EACtC,KAAA;AAAA;AAAA,EACA,QAAA;AAAA;AAAA,EACA,MAAA;AAAA;AAAA,EACA;AAAA;AACF;AAIO,IAAM,sBAAA,GAAyB;AAAA,EACpC,YAAA;AAAA;AAAA,EACA,UAAA;AAAA;AAAA,EACA;AAAA;AACF;AAQO,IAAM,cAAA,GAAiB;AAAA,EAC5B,WAAA;AAAA;AAAA,EACA,aAAA;AAAA;AAAA,EACA,QAAA;AAAA;AAAA,EACA;AAAA;AACF;AAIO,IAAM,eAAA,GAAkB;AAAA,EAC7B,YAAA;AAAA;AAAA,EACA,eAAA;AAAA;AAAA,EACA,YAAA;AAAA;AAAA,EACA;AAAA;AACF;AAQO,IAAM,eAAA,GAAkB;AAAA,EAC7B,SAAA;AAAA;AAAA,EACA,QAAA;AAAA;AAAA,EACA;AAAA;AACF;AAQO,IAAM,qBAAA,GAAwB;AAAA,EACnC,gBAAA;AAAA;AAAA,EACA,mBAAA;AAAA;AAAA,EACA,UAAA;AAAA;AAAA,EACA;AAAA;AACF;AAQO,IAAM,gBAAA,GAAmB;AAAA,EAC9B,IAAA;AAAA;AAAA,EACA,IAAA;AAAA;AAAA,EACA,IAAA;AAAA;AAAA,EACA;AAAA;AACF;AAcO,IAAM,cAAA,GAAiB;AAAA,EAC5B,mBAAA;AAAA;AAAA,EACA,iBAAA;AAAA;AAAA,EACA,sBAAA;AAAA;AAAA,EACA,qBAAA;AAAA;AAAA,EACA;AAAA;AACF;AAQO,IAAM,sBAAA,GAAyB;AAAA;AAAA,EAEpC,SAAA;AAAA;AAAA,EACA,SAAA;AAAA;AAAA,EACA,SAAA;AAAA;AAAA;AAAA,EAEA,aAAA;AAAA;AAAA,EACA,UAAA;AAAA;AAAA;AAAA,EAEA,YAAA;AAAA;AAAA,EACA,cAAA;AAAA;AAAA,EACA,UAAA;AAAA;AAAA,EACA,YAAA;AAAA;AAAA,EACA;AAAA;AACF","file":"api-enums.contract.js","sourcesContent":["/** Reasoning methods supported by the kernel edge schema. */\nexport const REASONING_METHODS = [\n \"deductive\",\n \"inductive\",\n \"abductive\",\n \"analogical\",\n \"causal\",\n \"correlational\",\n \"testimonial\",\n \"statistical\",\n \"implicit\",\n \"pattern_match\",\n] as const;\n\nexport type ReasoningMethod = (typeof REASONING_METHODS)[number];\n","/**\n * API Enum Contract Definitions\n *\n * Canonical enum values for all API-facing enumerations.\n * These are co-equal with MCP contracts as external contracts.\n * SDK types are DERIVED from these — not independently authored.\n *\n * CONTRACT SURFACE: Adding a new enum value is additive (non-breaking).\n * Removing or renaming an existing value is a BREAKING CHANGE.\n */\n\n// =============================================================================\n// BELIEF ENUMS\n// =============================================================================\n\n/** Fork reasons — why a scored belief was branched */\nexport const FORK_REASONS = [\n \"refinement\", // Belief text evolved based on new understanding\n \"contradiction_response\", // Created in response to a detected contradiction\n \"scope_change\", // Belief scope narrowed or broadened\n \"confidence_collapse\", // Confidence dropped below viability threshold\n \"manual\", // User-initiated fork without specific trigger\n] as const;\nexport type ForkReason = (typeof FORK_REASONS)[number];\n\n/** Confidence modulation triggers — what caused a confidence change */\nexport const CONFIDENCE_TRIGGERS = [\n \"evidence_added\", // New evidence bore on the belief\n \"evidence_removed\", // Evidence was removed or invalidated\n \"contradiction_detected\", // A contradiction was flagged involving this belief\n \"contradiction_resolved\", // A contradiction was resolved\n \"manual\", // User manually adjusted confidence\n \"decay\", // Time-based confidence erosion\n \"agent_assessment\", // An agent provided a structured assessment\n \"worktree_outcome\", // Worktree outcome determined this confidence\n \"worktree_completed\", // Worktree completed and closed this scoring loop\n \"fusion\", // Confidence came from subjective-logic fusion\n \"discount\", // Confidence came from trust discounting\n \"deduction\", // Confidence came from conditional deduction\n] as const;\nexport type ConfidenceTrigger = (typeof CONFIDENCE_TRIGGERS)[number];\n\n/** Belief status — lifecycle state */\nexport const BELIEF_STATUSES = [\n \"unscored\", // Draft — editable in worktree (on feature branch, pre-merge)\n \"scored\", // Merged — formulation frozen (merged to main)\n \"archived\", // Soft-deleted — preserved in history (git rm)\n] as const;\nexport type BeliefStatus = (typeof BELIEF_STATUSES)[number];\n\n// =============================================================================\n// EDGE ENUMS\n// =============================================================================\n\nexport {\n REASONING_METHODS,\n type ReasoningMethod,\n} from \"./types/reasoning-method.js\";\n\n/** Defeat types (Pollock taxonomy) — how a contradiction operates */\nexport const DEFEAT_TYPES = [\n \"rebuts\", // Direct contradiction — reasons for the negation\n \"undercuts\", // Breaks the inference link between evidence and belief\n \"undermines\", // Attacks a premise the belief depends on\n] as const;\nexport type DefeatType = (typeof DEFEAT_TYPES)[number];\n\n/** Contradiction severity levels */\nexport const CONTRADICTION_SEVERITIES = [\n \"low\", // Minor tension, may not require action\n \"medium\", // Moderate conflict, should be investigated\n \"high\", // Significant contradiction, likely needs resolution\n \"critical\", // Blocks progress — must be addressed before judgment\n] as const;\nexport type ContradictionSeverity = (typeof CONTRADICTION_SEVERITIES)[number];\n\n/** Contradiction resolution status */\nexport const CONTRADICTION_STATUSES = [\n \"unresolved\", // Open conflict — may persist indefinitely\n \"resolved\", // Conflict addressed (one belief forked, archived, or confidence adjusted)\n \"accepted\", // Explicitly accepted as irreconcilable — both beliefs maintained\n] as const;\nexport type ContradictionStatus = (typeof CONTRADICTION_STATUSES)[number];\n\n// =============================================================================\n// WORKTREE ENUMS (git worktree lifecycle)\n// =============================================================================\n\n/** Merge outcome types — how a worktree merge resolved */\nexport const MERGE_OUTCOMES = [\n \"validated\", // Beliefs confirmed — clean merge to main\n \"invalidated\", // Defeat recorded — confidence collapsed (merge with revert)\n \"forked\", // Beliefs split into competing versions (fork from merge point)\n \"inconclusive\", // Insufficient evidence — stashed (git stash)\n] as const;\nexport type MergeOutcome = (typeof MERGE_OUTCOMES)[number];\n\n/** Worktree phases — investigation lifecycle within a checked-out worktree */\nexport const WORKTREE_PHASES = [\n \"hypothesis\", // Form testable claims (write the code — commits)\n \"investigation\", // Collect evidence (run the tests — more commits)\n \"evaluation\", // Update credences (review the results — amend as needed)\n \"resolution\", // Determine outcome (merge to main, fork, or stash)\n] as const;\nexport type WorktreePhase = (typeof WORKTREE_PHASES)[number];\n\n// =============================================================================\n// BRANCH ENUMS (git branch lifecycle)\n// =============================================================================\n\n/** Branch status — thematic branch lifecycle */\nexport const BRANCH_STATUSES = [\n \"dormant\", // Branch exists but no active worktree (no one investigating)\n \"active\", // At least one worktree is investigating this branch\n \"archived\", // Branch retired — no longer a relevant thematic container\n] as const;\nexport type BranchStatus = (typeof BRANCH_STATUSES)[number];\n\n// =============================================================================\n// PULL REQUEST ENUMS (git pull request lifecycle)\n// =============================================================================\n\n/** Pull request status — review lifecycle before merge */\nexport const PULL_REQUEST_STATUSES = [\n \"pending_review\", // PR opened — awaiting reviewer feedback\n \"changes_requested\", // Reviewer requests changes before merge\n \"approved\", // Approved — ready to merge\n \"blocked\", // Blocked — cannot merge until contradiction is resolved\n] as const;\nexport type PullRequestStatus = (typeof PULL_REQUEST_STATUSES)[number];\n\n// =============================================================================\n// LAYER ENUMS\n// =============================================================================\n\n/** Epistemic layers — the hierarchy of knowledge */\nexport const EPISTEMIC_LAYERS = [\n \"L1\", // Source — the given (vendored deps)\n \"L2\", // Evidence — the interpreted (test suite)\n \"L3\", // Belief — the structural (source files)\n \"L4\", // Judgment — the committed (release tags)\n] as const;\nexport type EpistemicLayer = (typeof EPISTEMIC_LAYERS)[number];\n\n// =============================================================================\n// JUDGMENT ENUMS (Phase 1: new vocabulary)\n// =============================================================================\n\n/**\n * Judgment type — classification of the determination.\n *\n * Phase 1: These are new enum values for the Judgment (L4) vocabulary.\n * The existing code uses \"Decision\" — these are the forward-looking terms\n * that will eventually replace the Decision vocabulary (Phase 2-3).\n */\nexport const JUDGMENT_TYPES = [\n \"investment_thesis\", // Judgment on an investment opportunity\n \"thesis_maturity\", // Judgment that a thesis is ready for IC presentation\n \"contradiction_ruling\", // Judgment on how to handle an irreconcilable contradiction\n \"scope_determination\", // Judgment that defines or redefines investigation scope\n \"confidence_ruling\", // Judgment that overrides automated confidence for policy reasons\n] as const;\nexport type JudgmentType = (typeof JUDGMENT_TYPES)[number];\n\n// =============================================================================\n// SUPPORT RELATION ENUMS\n// =============================================================================\n\n/** Core edge types used in the Integration Surfaces */\nexport const INTEGRATION_EDGE_TYPES = [\n // Support relations\n \"informs\", // Evidence bears on a belief (weight = direction/strength)\n \"grounds\", // Source provides raw basis for evidence\n \"answers\", // Evidence or belief resolves a question\n // Defeat relations (Pollock) — weight carries direction\n \"contradicts\", // Rebuts — direct contradiction\n \"supports\", // Weight carries valence (negative = weakens/undercuts)\n // Structural relations\n \"depends_on\", // Belief B requires Belief A\n \"derived_from\", // Provenance lineage\n \"contains\", // Hierarchical containment\n \"supersedes\", // New version replaces old (lineage)\n \"tests\", // Question tests a belief\n] as const;\nexport type IntegrationEdgeType = (typeof INTEGRATION_EDGE_TYPES)[number];\n"]}
1
+ {"version":3,"sources":["../src/types/reasoning-method.ts","../src/api-enums.contract.ts"],"names":[],"mappings":";AACO,IAAM,iBAAA,GAAoB;AAAA,EAC/B,WAAA;AAAA,EACA,WAAA;AAAA,EACA,WAAA;AAAA,EACA,YAAA;AAAA,EACA,QAAA;AAAA,EACA,eAAA;AAAA,EACA,aAAA;AAAA,EACA,aAAA;AAAA,EACA,UAAA;AAAA,EACA;AACF;;;ACIO,IAAM,YAAA,GAAe;AAAA,EAC1B,YAAA;AAAA;AAAA,EACA,wBAAA;AAAA;AAAA,EACA,cAAA;AAAA;AAAA,EACA;AAAA;AACF;AAIO,IAAM,mBAAA,GAAsB;AAAA,EACjC,gBAAA;AAAA;AAAA,EACA,kBAAA;AAAA;AAAA,EACA,wBAAA;AAAA;AAAA,EACA,wBAAA;AAAA;AAAA,EACA,kBAAA;AAAA;AAAA,EACA,kBAAA;AAAA;AAAA,EACA,oBAAA;AAAA;AAAA,EACA,QAAA;AAAA;AAAA,EACA,UAAA;AAAA;AAAA,EACA;AAAA;AACF;AAIO,IAAM,eAAA,GAAkB;AAAA,EAC7B,UAAA;AAAA;AAAA,EACA,QAAA;AAAA;AAAA,EACA;AAAA;AACF;AAaO,IAAM,YAAA,GAAe;AAAA,EAC1B,QAAA;AAAA;AAAA,EACA,WAAA;AAAA;AAAA,EACA;AAAA;AACF;AAIO,IAAM,wBAAA,GAA2B;AAAA,EACtC,KAAA;AAAA;AAAA,EACA,QAAA;AAAA;AAAA,EACA,MAAA;AAAA;AAAA,EACA;AAAA;AACF;AAIO,IAAM,sBAAA,GAAyB;AAAA,EACpC,YAAA;AAAA;AAAA,EACA,UAAA;AAAA;AAAA,EACA;AAAA;AACF;AAQO,IAAM,cAAA,GAAiB;AAAA,EAC5B,WAAA;AAAA;AAAA,EACA,aAAA;AAAA;AAAA,EACA,QAAA;AAAA;AAAA,EACA;AAAA;AACF;AAIO,IAAM,eAAA,GAAkB;AAAA,EAC7B,YAAA;AAAA;AAAA,EACA,eAAA;AAAA;AAAA,EACA,YAAA;AAAA;AAAA,EACA;AAAA;AACF;AAQO,IAAM,eAAA,GAAkB;AAAA,EAC7B,SAAA;AAAA;AAAA,EACA,QAAA;AAAA;AAAA,EACA;AAAA;AACF;AAQO,IAAM,qBAAA,GAAwB;AAAA,EACnC,gBAAA;AAAA;AAAA,EACA,mBAAA;AAAA;AAAA,EACA,UAAA;AAAA;AAAA,EACA;AAAA;AACF;AAQO,IAAM,gBAAA,GAAmB;AAAA,EAC9B,IAAA;AAAA;AAAA,EACA,IAAA;AAAA;AAAA,EACA,IAAA;AAAA;AAAA,EACA;AAAA;AACF;AAcO,IAAM,cAAA,GAAiB;AAAA,EAC5B,mBAAA;AAAA;AAAA,EACA,iBAAA;AAAA;AAAA,EACA,sBAAA;AAAA;AAAA,EACA,qBAAA;AAAA;AAAA,EACA;AAAA;AACF;AAQO,IAAM,sBAAA,GAAyB;AAAA;AAAA,EAEpC,SAAA;AAAA;AAAA,EACA,SAAA;AAAA;AAAA,EACA,SAAA;AAAA;AAAA;AAAA,EAEA,aAAA;AAAA;AAAA,EACA,UAAA;AAAA;AAAA;AAAA,EAEA,YAAA;AAAA;AAAA,EACA,cAAA;AAAA;AAAA,EACA,UAAA;AAAA;AAAA,EACA,YAAA;AAAA;AAAA,EACA;AAAA;AACF","file":"api-enums.contract.js","sourcesContent":["/** Reasoning methods supported by the kernel edge schema. */\nexport const REASONING_METHODS = [\n \"deductive\",\n \"inductive\",\n \"abductive\",\n \"analogical\",\n \"causal\",\n \"correlational\",\n \"testimonial\",\n \"statistical\",\n \"implicit\",\n \"pattern_match\",\n] as const;\n\nexport type ReasoningMethod = (typeof REASONING_METHODS)[number];\n","/**\n * API Enum Contract Definitions\n *\n * Canonical enum values for all API-facing enumerations.\n * These are co-equal with MCP contracts as external contracts.\n * SDK types are DERIVED from these — not independently authored.\n *\n * CONTRACT SURFACE: Adding a new enum value is additive (non-breaking).\n * Removing or renaming an existing value is a BREAKING CHANGE.\n */\n\n// =============================================================================\n// BELIEF ENUMS\n// =============================================================================\n\n/** Fork reasons — why a scored belief was branched */\nexport const FORK_REASONS = [\n \"refinement\", // Belief text evolved based on new understanding\n \"contradiction_response\", // Created in response to a detected contradiction\n \"scope_change\", // Belief scope narrowed or broadened\n \"confidence_collapse\", // Confidence dropped below viability threshold\n] as const;\nexport type ForkReason = (typeof FORK_REASONS)[number];\n\n/** Confidence modulation triggers — what caused a confidence change */\nexport const CONFIDENCE_TRIGGERS = [\n \"evidence_added\", // New evidence bore on the belief\n \"evidence_removed\", // Evidence was removed or invalidated\n \"contradiction_detected\", // A contradiction was flagged involving this belief\n \"contradiction_resolved\", // A contradiction was resolved\n \"agent_assessment\", // An agent-proposed scoring event with concrete provenance\n \"worktree_outcome\", // Worktree outcome determined this confidence\n \"worktree_completed\", // Worktree completed and closed this scoring loop\n \"fusion\", // Confidence came from subjective-logic fusion\n \"discount\", // Confidence came from trust discounting\n \"deduction\", // Confidence came from conditional deduction\n] as const;\nexport type ConfidenceTrigger = (typeof CONFIDENCE_TRIGGERS)[number];\n\n/** Belief status — lifecycle state */\nexport const BELIEF_STATUSES = [\n \"unscored\", // Draft — editable in worktree (on feature branch, pre-merge)\n \"scored\", // Merged — formulation frozen (merged to main)\n \"archived\", // Soft-deleted — preserved in history (git rm)\n] as const;\nexport type BeliefStatus = (typeof BELIEF_STATUSES)[number];\n\n// =============================================================================\n// EDGE ENUMS\n// =============================================================================\n\nexport {\n REASONING_METHODS,\n type ReasoningMethod,\n} from \"./types/reasoning-method.js\";\n\n/** Defeat types (Pollock taxonomy) — how a contradiction operates */\nexport const DEFEAT_TYPES = [\n \"rebuts\", // Direct contradiction — reasons for the negation\n \"undercuts\", // Breaks the inference link between evidence and belief\n \"undermines\", // Attacks a premise the belief depends on\n] as const;\nexport type DefeatType = (typeof DEFEAT_TYPES)[number];\n\n/** Contradiction severity levels */\nexport const CONTRADICTION_SEVERITIES = [\n \"low\", // Minor tension, may not require action\n \"medium\", // Moderate conflict, should be investigated\n \"high\", // Significant contradiction, likely needs resolution\n \"critical\", // Blocks progress — must be addressed before judgment\n] as const;\nexport type ContradictionSeverity = (typeof CONTRADICTION_SEVERITIES)[number];\n\n/** Contradiction resolution status */\nexport const CONTRADICTION_STATUSES = [\n \"unresolved\", // Open conflict — may persist indefinitely\n \"resolved\", // Conflict addressed (one belief forked, archived, or confidence adjusted)\n \"accepted\", // Explicitly accepted as irreconcilable — both beliefs maintained\n] as const;\nexport type ContradictionStatus = (typeof CONTRADICTION_STATUSES)[number];\n\n// =============================================================================\n// WORKTREE ENUMS (git worktree lifecycle)\n// =============================================================================\n\n/** Merge outcome types — how a worktree merge resolved */\nexport const MERGE_OUTCOMES = [\n \"validated\", // Beliefs confirmed — clean merge to main\n \"invalidated\", // Defeat recorded — confidence collapsed (merge with revert)\n \"forked\", // Beliefs split into competing versions (fork from merge point)\n \"inconclusive\", // Insufficient evidence — stashed (git stash)\n] as const;\nexport type MergeOutcome = (typeof MERGE_OUTCOMES)[number];\n\n/** Worktree phases — investigation lifecycle within a checked-out worktree */\nexport const WORKTREE_PHASES = [\n \"hypothesis\", // Form testable claims (write the code — commits)\n \"investigation\", // Collect evidence (run the tests — more commits)\n \"evaluation\", // Update credences (review the results — amend as needed)\n \"resolution\", // Determine outcome (merge to main, fork, or stash)\n] as const;\nexport type WorktreePhase = (typeof WORKTREE_PHASES)[number];\n\n// =============================================================================\n// BRANCH ENUMS (git branch lifecycle)\n// =============================================================================\n\n/** Branch status — thematic branch lifecycle */\nexport const BRANCH_STATUSES = [\n \"dormant\", // Branch exists but no active worktree (no one investigating)\n \"active\", // At least one worktree is investigating this branch\n \"archived\", // Branch retired — no longer a relevant thematic container\n] as const;\nexport type BranchStatus = (typeof BRANCH_STATUSES)[number];\n\n// =============================================================================\n// PULL REQUEST ENUMS (git pull request lifecycle)\n// =============================================================================\n\n/** Pull request status — review lifecycle before merge */\nexport const PULL_REQUEST_STATUSES = [\n \"pending_review\", // PR opened — awaiting reviewer feedback\n \"changes_requested\", // Reviewer requests changes before merge\n \"approved\", // Approved — ready to merge\n \"blocked\", // Blocked — cannot merge until contradiction is resolved\n] as const;\nexport type PullRequestStatus = (typeof PULL_REQUEST_STATUSES)[number];\n\n// =============================================================================\n// LAYER ENUMS\n// =============================================================================\n\n/** Epistemic layers — the hierarchy of knowledge */\nexport const EPISTEMIC_LAYERS = [\n \"L1\", // Source — the given (vendored deps)\n \"L2\", // Evidence — the interpreted (test suite)\n \"L3\", // Belief — the structural (source files)\n \"L4\", // Judgment — the committed (release tags)\n] as const;\nexport type EpistemicLayer = (typeof EPISTEMIC_LAYERS)[number];\n\n// =============================================================================\n// JUDGMENT ENUMS (Phase 1: new vocabulary)\n// =============================================================================\n\n/**\n * Judgment type — classification of the determination.\n *\n * Phase 1: These are new enum values for the Judgment (L4) vocabulary.\n * The existing code uses \"Decision\" — these are the forward-looking terms\n * that will eventually replace the Decision vocabulary (Phase 2-3).\n */\nexport const JUDGMENT_TYPES = [\n \"investment_thesis\", // Judgment on an investment opportunity\n \"thesis_maturity\", // Judgment that a thesis is ready for IC presentation\n \"contradiction_ruling\", // Judgment on how to handle an irreconcilable contradiction\n \"scope_determination\", // Judgment that defines or redefines investigation scope\n \"confidence_ruling\", // Judgment that overrides automated confidence for policy reasons\n] as const;\nexport type JudgmentType = (typeof JUDGMENT_TYPES)[number];\n\n// =============================================================================\n// SUPPORT RELATION ENUMS\n// =============================================================================\n\n/** Core edge types used in the Integration Surfaces */\nexport const INTEGRATION_EDGE_TYPES = [\n // Support relations\n \"informs\", // Evidence bears on a belief (weight = direction/strength)\n \"grounds\", // Source provides raw basis for evidence\n \"answers\", // Evidence or belief resolves a question\n // Defeat relations (Pollock) — weight carries direction\n \"contradicts\", // Rebuts — direct contradiction\n \"supports\", // Weight carries valence (negative = weakens/undercuts)\n // Structural relations\n \"depends_on\", // Belief B requires Belief A\n \"derived_from\", // Provenance lineage\n \"contains\", // Hierarchical containment\n \"supersedes\", // New version replaces old (lineage)\n \"tests\", // Question tests a belief\n] as const;\nexport type IntegrationEdgeType = (typeof INTEGRATION_EDGE_TYPES)[number];\n"]}
@@ -349,7 +349,28 @@ type PublicContextInjectionPolicy = {
349
349
  score: number;
350
350
  }>;
351
351
  };
352
+ type PublicContextNarrativeBlock = {
353
+ kind: string;
354
+ text: string;
355
+ recordsNamed?: number;
356
+ };
357
+ type PublicContextSupportingObjects = {
358
+ invariants?: PublicContextBelief[];
359
+ activeBeliefs?: PublicContextBelief[];
360
+ openQuestions?: PublicContextQuestion[];
361
+ recentEvidence?: PublicContextEvidence[];
362
+ contradictions?: PublicContextContradiction[];
363
+ relatedEntities?: PublicContextEntity[];
364
+ worktrees?: unknown[];
365
+ lanes?: string[];
366
+ entities?: unknown[];
367
+ };
352
368
  type PublicCompiledContext = {
369
+ contextNarrative: Array<string | PublicContextNarrativeBlock>;
370
+ narrativeCoverage?: Record<string, unknown>;
371
+ synthesisLints?: Array<Record<string, unknown>>;
372
+ retrievalReceipt?: Record<string, unknown>;
373
+ supportingObjects?: PublicContextSupportingObjects;
353
374
  schemaVersion: string;
354
375
  topicId: string;
355
376
  topicName: string;
@@ -357,13 +378,12 @@ type PublicCompiledContext = {
357
378
  generatedAt: number;
358
379
  ranking: ContextRankingProfile;
359
380
  summary: Record<string, unknown>;
360
- invariants: PublicContextBelief[];
361
- activeBeliefs: PublicContextBelief[];
362
- openQuestions: PublicContextQuestion[];
363
- recentEvidence: PublicContextEvidence[];
364
- contradictions: PublicContextContradiction[];
381
+ invariants?: PublicContextBelief[];
382
+ activeBeliefs?: PublicContextBelief[];
383
+ openQuestions?: PublicContextQuestion[];
384
+ recentEvidence?: PublicContextEvidence[];
385
+ contradictions?: PublicContextContradiction[];
365
386
  relatedEntities?: PublicContextEntity[];
366
- contextNarrative: string[];
367
387
  injectionPolicy: PublicContextInjectionPolicy;
368
388
  diagnostics: Record<string, unknown>;
369
389
  compilationMode?: string;
@@ -511,4 +531,4 @@ declare const TOKENS_PER_WORD = 1.35;
511
531
  /** Minimum token estimate for any non-empty string. */
512
532
  declare const MIN_TOKEN_ESTIMATE = 8;
513
533
 
514
- export { BELIEF_TYPE_BONUS, type BeliefLatticeSeed, CONTEXT_PACK_SCHEMA_VERSION, CONTEXT_PACK_SECTION_KEYS, CONTEXT_RANKING_PROFILES, type ContextCompilationMode, type ContextPackBelief, type ContextPackContradiction, type ContextPackDeltaReport, type ContextPackDiagnostics, type ContextPackEntity, type ContextPackEvidence, type ContextPackFailure, type ContextPackFailureContext, type ContextPackInjectionPolicy, type ContextPackQuestion, type ContextPackRequestV1, type ContextPackSectionKey, type ContextPackSummary, type ContextPackV1, type ContextRankingProfile, DEFAULT_BELIEF_TYPE_BONUS, DEFAULT_COMPILATION_MODE, DEFAULT_ENTITY_LIMIT, DEFAULT_PRIORITY_SCORE, DEFAULT_RANKING_PROFILE, DEFAULT_SECTION_LIMIT, DEFAULT_SEVERITY_SCORE, DEFAULT_TOKEN_BUDGET, ENTITY_RANKING_WEIGHTS, MAX_ENTITY_LIMIT, MAX_SECTION_LIMIT, MAX_TOKEN_BUDGET, MIN_CONTRADICTION_BUDGET, MIN_TOKEN_BUDGET, MIN_TOKEN_ESTIMATE, PRIORITY_SCORES, type PackWeightOverride, type PublicCompiledContext, type PublicContextBelief, type PublicContextContradiction, type PublicContextEntity, type PublicContextEvidence, type PublicContextInjectionPolicy, type PublicContextQuestion, RANKING_WEIGHTS, RECENCY_HALF_LIFE_DAYS, RESOLVED_QUESTION_STATUSES, type RankingWeightVector, SECTION_BUDGET_RATIOS, SEVERITY_SCORES, TOKENS_PER_WORD, type VerificationObligation };
534
+ export { BELIEF_TYPE_BONUS, type BeliefLatticeSeed, CONTEXT_PACK_SCHEMA_VERSION, CONTEXT_PACK_SECTION_KEYS, CONTEXT_RANKING_PROFILES, type ContextCompilationMode, type ContextPackBelief, type ContextPackContradiction, type ContextPackDeltaReport, type ContextPackDiagnostics, type ContextPackEntity, type ContextPackEvidence, type ContextPackFailure, type ContextPackFailureContext, type ContextPackInjectionPolicy, type ContextPackQuestion, type ContextPackRequestV1, type ContextPackSectionKey, type ContextPackSummary, type ContextPackV1, type ContextRankingProfile, DEFAULT_BELIEF_TYPE_BONUS, DEFAULT_COMPILATION_MODE, DEFAULT_ENTITY_LIMIT, DEFAULT_PRIORITY_SCORE, DEFAULT_RANKING_PROFILE, DEFAULT_SECTION_LIMIT, DEFAULT_SEVERITY_SCORE, DEFAULT_TOKEN_BUDGET, ENTITY_RANKING_WEIGHTS, MAX_ENTITY_LIMIT, MAX_SECTION_LIMIT, MAX_TOKEN_BUDGET, MIN_CONTRADICTION_BUDGET, MIN_TOKEN_BUDGET, MIN_TOKEN_ESTIMATE, PRIORITY_SCORES, type PackWeightOverride, type PublicCompiledContext, type PublicContextBelief, type PublicContextContradiction, type PublicContextEntity, type PublicContextEvidence, type PublicContextInjectionPolicy, type PublicContextNarrativeBlock, type PublicContextQuestion, type PublicContextSupportingObjects, RANKING_WEIGHTS, RECENCY_HALF_LIFE_DAYS, RESOLVED_QUESTION_STATUSES, type RankingWeightVector, SECTION_BUDGET_RATIOS, SEVERITY_SCORES, TOKENS_PER_WORD, type VerificationObligation };
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/context-pack.contract.ts"],"names":[],"mappings":";AAqBO,IAAM,2BAAA,GAA8B;AAepC,IAAM,wBAAA,GAA6D;AAAA,EACxE,aAAA;AAAA,EACA;AACF;AAEO,IAAM,uBAAA,GAAiD;AAevD,IAAM,wBAAA,GAAmD;AAiBzD,IAAM,yBAAA,GAA8D;AAAA,EACzE,YAAA;AAAA,EACA,eAAA;AAAA,EACA,eAAA;AAAA,EACA,gBAAA;AAAA,EACA;AACF;AAiBO,IAAM,qBAAA,GAET;AAAA,EACF,UAAA,EAAY,IAAA;AAAA,EACZ,aAAA,EAAe,GAAA;AAAA,EACf,aAAA,EAAe,IAAA;AAAA,EACf,cAAA,EAAgB,IAAA;AAAA,EAChB,cAAA,EAAgB;AAClB;AAOO,IAAM,gBAAA,GAAmB;AAGzB,IAAM,gBAAA,GAAmB;AAGzB,IAAM,oBAAA,GAAuB;AAG7B,IAAM,qBAAA,GAAwB;AAG9B,IAAM,iBAAA,GAAoB;AAG1B,IAAM,wBAAA,GAA2B;AA0BjC,IAAM,eAAA,GAET;AAAA,EACF,UAAA,EAAY;AAAA,IACV,KAAA,EAAO,IAAA;AAAA,IACP,OAAA,EAAS,GAAA;AAAA,IACT,UAAA,EAAY,GAAA;AAAA,IACZ,UAAA,EAAY;AAAA,GACd;AAAA,EACA,aAAA,EAAe;AAAA,IACb,KAAA,EAAO,GAAA;AAAA,IACP,OAAA,EAAS,GAAA;AAAA,IACT,UAAA,EAAY,GAAA;AAAA,IACZ,UAAA,EAAY;AAAA,GACd;AAAA,EACA,aAAA,EAAe;AAAA,IACb,KAAA,EAAO,IAAA;AAAA,IACP,OAAA,EAAS,GAAA;AAAA,IACT,QAAA,EAAU;AAAA,GACZ;AAAA,EACA,cAAA,EAAgB;AAAA,IACd,KAAA,EAAO,GAAA;AAAA,IACP,OAAA,EAAS;AAAA,GACX;AAAA,EACA,cAAA,EAAgB;AAAA,IACd,KAAA,EAAO,GAAA;AAAA,IACP,OAAA,EAAS,GAAA;AAAA,IACT,QAAA,EAAU;AAAA;AAEd;AAGO,IAAM,sBAAA,GAAyB;AAQ/B,IAAM,sBAAA,GAAyB;AAAA,EACpC,KAAA,EAAO,GAAA;AAAA,EACP,YAAA,EAAc;AAChB;AAGO,IAAM,oBAAA,GAAuB;AAG7B,IAAM,gBAAA,GAAmB;AAUzB,IAAM,iBAAA,GAAsD;AAAA,EACjE,SAAA,EAAW,CAAA;AAAA,EACX,KAAA,EAAO,GAAA;AAAA,EACP,SAAA,EAAW;AACb;AAEO,IAAM,yBAAA,GAA4B;AAMlC,IAAM,eAAA,GAAoD;AAAA,EAC/D,QAAA,EAAU,CAAA;AAAA,EACV,IAAA,EAAM,IAAA;AAAA,EACN,MAAA,EAAQ,IAAA;AAAA,EACR,GAAA,EAAK;AACP;AAEO,IAAM,sBAAA,GAAyB;AAE/B,IAAM,eAAA,GAAoD;AAAA,EAC/D,QAAA,EAAU,CAAA;AAAA,EACV,IAAA,EAAM,IAAA;AAAA,EACN,MAAA,EAAQ,GAAA;AAAA,EACR,GAAA,EAAK;AACP;AAEO,IAAM,sBAAA,GAAyB;AA6c/B,IAAM,0BAAA,GAAgD;AAAA,EAC3D,UAAA;AAAA,EACA,UAAA;AAAA,EACA,QAAA;AAAA,EACA,UAAA;AAAA,EACA,kBAAA;AAAA,EACA,iBAAA;AAAA,EACA;AACF;AAUO,IAAM,eAAA,GAAkB;AAGxB,IAAM,kBAAA,GAAqB","file":"context-pack.contract.js","sourcesContent":["/**\n * Context-Pack Contract v1\n *\n * Canonical TypeScript types and constants for the context-pack output schema.\n * This is the external contract consumed by:\n * - MCP tool `compile_context` (canonical compiler read)\n * - SDK/HTTP consumers that read compiled context packs programmatically\n * - Benchmark harnesses (context-pack-ab)\n *\n * BREAKING CHANGE RULES:\n * - Adding optional fields to ContextPackV1 is NON-breaking\n * - Removing fields or changing types is BREAKING (bump CONTEXT_PACK_SCHEMA_VERSION)\n * - Changing section budget ratios or ranking weights is NON-breaking (tuning)\n * - Changing the version string is BREAKING (consumers check it)\n */\n\n// =============================================================================\n// SCHEMA VERSION\n// =============================================================================\n\n/** Canonical version string. Consumers MUST check this field for compatibility. */\nexport const CONTEXT_PACK_SCHEMA_VERSION = \"1.0.0\" as const;\n\n// =============================================================================\n// RANKING PROFILES\n// =============================================================================\n\n/**\n * Available ranking profiles for context-pack assembly.\n *\n * - `baseline_v1`: Simple token-hit counting. Items with zero query hits are excluded.\n * - `weighted_v1`: Multi-signal scoring combining query relevance, recency, confidence,\n * belief type, priority, and severity with section-specific weight vectors.\n */\nexport type ContextRankingProfile = \"baseline_v1\" | \"weighted_v1\";\n\nexport const CONTEXT_RANKING_PROFILES: readonly ContextRankingProfile[] = [\n \"baseline_v1\",\n \"weighted_v1\",\n] as const;\n\nexport const DEFAULT_RANKING_PROFILE: ContextRankingProfile = \"weighted_v1\";\n\n// =============================================================================\n// COMPILATION MODE (RS-2)\n// =============================================================================\n\n/**\n * Context compilation mode.\n *\n * - `standard`: Default — ranked beliefs, questions, evidence, contradictions.\n * - `delta`: Diff-aware — adds failure context, verification obligations,\n * and worktree ledger analysis to the standard context pack.\n */\nexport type ContextCompilationMode = \"standard\" | \"delta\";\n\nexport const DEFAULT_COMPILATION_MODE: ContextCompilationMode = \"standard\";\n\n// =============================================================================\n// SECTION KEYS\n// =============================================================================\n\n/**\n * The five canonical sections of a context pack.\n * Order matters: invariants are injected first, contradictions last.\n */\nexport type ContextPackSectionKey =\n | \"invariants\"\n | \"activeBeliefs\"\n | \"openQuestions\"\n | \"recentEvidence\"\n | \"contradictions\";\n\nexport const CONTEXT_PACK_SECTION_KEYS: readonly ContextPackSectionKey[] = [\n \"invariants\",\n \"activeBeliefs\",\n \"openQuestions\",\n \"recentEvidence\",\n \"contradictions\",\n] as const;\n\n// =============================================================================\n// SECTION BUDGET RATIOS\n// =============================================================================\n\n/**\n * Token budget allocation ratios per section.\n * These sum to 1.0 and determine how the total tokenBudget is divided.\n *\n * Rationale:\n * - invariants (0.28): Highest-priority constraints, injected first\n * - activeBeliefs (0.30): Largest section, carries domain knowledge\n * - openQuestions (0.17): Unresolved work items guide agent behavior\n * - recentEvidence (0.17): Implementation context for grounding\n * - contradictions (0.08): Tension signals, smallest section\n */\nexport const SECTION_BUDGET_RATIOS: Readonly<\n Record<ContextPackSectionKey, number>\n> = {\n invariants: 0.28,\n activeBeliefs: 0.3,\n openQuestions: 0.17,\n recentEvidence: 0.17,\n contradictions: 0.08,\n} as const;\n\n// =============================================================================\n// TOKEN BUDGET CONSTRAINTS\n// =============================================================================\n\n/** Minimum allowed token budget. Below this, context packs lose utility. */\nexport const MIN_TOKEN_BUDGET = 400;\n\n/** Maximum allowed token budget. Above this, context packs bloat prompts. */\nexport const MAX_TOKEN_BUDGET = 8000;\n\n/** Default token budget when caller does not specify. */\nexport const DEFAULT_TOKEN_BUDGET = 1800;\n\n/** Default max items per section. */\nexport const DEFAULT_SECTION_LIMIT = 8;\n\n/** Hard ceiling on items per section. */\nexport const MAX_SECTION_LIMIT = 25;\n\n/** Minimum contradiction section budget floor (tokens). */\nexport const MIN_CONTRADICTION_BUDGET = 40;\n\n// =============================================================================\n// RANKING WEIGHT VECTORS\n// =============================================================================\n\n/**\n * Weight vectors for the weighted_v1 ranking profile.\n * Each section has a different signal mix:\n *\n * - query: How many query tokens appear in the candidate text\n * - recency: Exponential decay from updatedAt (half-life = 30 days)\n * - confidence: Belief confidence score [0,1]\n * - beliefType: Bonus for invariant > tenet > principle > other\n * - priority: Question priority (critical > high > medium > low)\n * - severity: Contradiction severity (critical > high > medium > low)\n */\nexport type RankingWeightVector = {\n query: number;\n recency: number;\n confidence?: number;\n beliefType?: number;\n priority?: number;\n severity?: number;\n};\n\nexport const RANKING_WEIGHTS: Readonly<\n Record<ContextPackSectionKey, RankingWeightVector>\n> = {\n invariants: {\n query: 0.35,\n recency: 0.1,\n confidence: 0.4,\n beliefType: 0.15,\n },\n activeBeliefs: {\n query: 0.5,\n recency: 0.2,\n confidence: 0.2,\n beliefType: 0.1,\n },\n openQuestions: {\n query: 0.55,\n recency: 0.2,\n priority: 0.25,\n },\n recentEvidence: {\n query: 0.6,\n recency: 0.4,\n },\n contradictions: {\n query: 0.4,\n recency: 0.2,\n severity: 0.4,\n },\n} as const;\n\n/** Recency decay half-life in days. After 30 days, recency score = 0.5. */\nexport const RECENCY_HALF_LIFE_DAYS = 30;\n\n/**\n * Ranking weight vector for the relatedEntities section.\n * Entities are ranked by query relevance and connectivity (bridge edge count).\n * Separate from RANKING_WEIGHTS because entities are not part of the\n * token-budgeted injection plan.\n */\nexport const ENTITY_RANKING_WEIGHTS = {\n query: 0.4,\n connectivity: 0.6,\n} as const;\n\n/** Default max entities to include in the context pack. */\nexport const DEFAULT_ENTITY_LIMIT = 10;\n\n/** Hard ceiling on entities per context pack. */\nexport const MAX_ENTITY_LIMIT = 50;\n\n// =============================================================================\n// BELIEF TYPE BONUS MAP\n// =============================================================================\n\n/**\n * Bonus multiplier for belief types in ranking.\n * Invariants get 1.0, unknown types get 0.4.\n */\nexport const BELIEF_TYPE_BONUS: Readonly<Record<string, number>> = {\n invariant: 1.0,\n tenet: 0.8,\n principle: 0.6,\n} as const;\n\nexport const DEFAULT_BELIEF_TYPE_BONUS = 0.4;\n\n// =============================================================================\n// PRIORITY / SEVERITY SCORE MAPS\n// =============================================================================\n\nexport const PRIORITY_SCORES: Readonly<Record<string, number>> = {\n critical: 1.0,\n high: 0.85,\n medium: 0.55,\n low: 0.35,\n} as const;\n\nexport const DEFAULT_PRIORITY_SCORE = 0.5;\n\nexport const SEVERITY_SCORES: Readonly<Record<string, number>> = {\n critical: 1.0,\n high: 0.85,\n medium: 0.6,\n low: 0.35,\n} as const;\n\nexport const DEFAULT_SEVERITY_SCORE = 0.5;\n\n// =============================================================================\n// SECTION ITEM TYPES\n// =============================================================================\n\n/** A ranked belief in the invariants or activeBeliefs section. */\nexport type ContextPackBelief = {\n nodeId: string;\n canonicalText: string;\n confidence: number | null;\n beliefType: string | null;\n score: number;\n /** Present in activeBeliefs, absent in invariants */\n status?: string;\n updatedAt?: number | null;\n /** Human-readable explanation of why this item was ranked here (RS-2). */\n justification?: string;\n};\n\n/** A ranked question in the openQuestions section. */\nexport type ContextPackQuestion = {\n questionId: string;\n text: string;\n status: string;\n priority: string;\n updatedAt?: number | null;\n score: number;\n /** Human-readable explanation of why this item was ranked here (RS-2). */\n justification?: string;\n};\n\n/** A ranked evidence item in the recentEvidence section. */\nexport type ContextPackEvidence = {\n nodeId: string;\n canonicalText: string;\n sourceUrl: string | null;\n kind: string;\n createdAt: number | null;\n score: number;\n /** Human-readable explanation of why this item was ranked here (RS-2). */\n justification?: string;\n};\n\n/** A ranked contradiction in the contradictions section. */\nexport type ContextPackContradiction = {\n contradictionId: string;\n severity: string;\n status: string;\n description: string;\n score: number;\n /** Human-readable explanation of why this item was ranked here (RS-2). */\n justification?: string;\n};\n\n/**\n * An entity from the ontological layer surfaced in the context pack.\n * Entities are domain objects (companies, people, functions, etc.) connected\n * to beliefs via bridge edges. They provide the \"reality anchor\" that makes\n * the reasoning graph domain-aware.\n */\nexport type ContextPackEntity = {\n /** Convex document ID of the entity node. */\n nodeId: string;\n /** Entity type (e.g., \"company\", \"person\", \"function\"). */\n entityType: string;\n /** Human-readable title/name of the entity. */\n title: string;\n /** Number of beliefs connected to this entity via bridge edges. */\n connectedBeliefCount: number;\n /** Number of evidence items referencing this entity. */\n connectedEvidenceCount: number;\n /** Relevance score from ranking algorithm. */\n score: number;\n /** Entity metadata (structured per ontology schema). */\n metadata?: Record<string, unknown>;\n};\n\n/**\n * A lattice seed entry representing a belief that was auto-generated\n * to cover an ontology entity type within a topic scope.\n */\nexport type BeliefLatticeSeed = {\n /** The belief node ID that was created or already existed. */\n beliefNodeId: string;\n /** The entity type this seed belief covers. */\n entityType: string;\n /** Whether this seed was newly created or already existed. */\n created: boolean;\n /** The canonical text of the seed belief. */\n canonicalText: string;\n};\n\n// =============================================================================\n// SUMMARY\n// =============================================================================\n\n/** Counts and scoped health signals for the context pack. */\nexport type ContextPackSummary = {\n totalBeliefs: number;\n invariants: number;\n openQuestions: number;\n evidenceItems: number;\n contradictions: number;\n /** Number of ontological entities in scope (optional, present when entity graph is active). */\n relatedEntities?: number;\n scopedTopics: number;\n descendantDepth: number;\n query: string | null;\n};\n\n// =============================================================================\n// FAILURE CONTEXT (RS-2)\n// =============================================================================\n\n/** A failed approach surfaced from the failure log for anti-repetition. */\nexport type ContextPackFailure = {\n /** Lucern attempt/evidence node ID. */\n attemptId: string;\n /** What was tried. */\n approach: string;\n /** Why it failed. */\n outcome: string;\n /** When the attempt was recorded (ms since epoch). */\n recordedAt: number;\n /** Relevance score from ranking algorithm. */\n score: number;\n};\n\n/** Failure context section appended to context packs in delta mode. */\nexport type ContextPackFailureContext = {\n /** Ranked failed approaches relevant to the current query. */\n failures: ContextPackFailure[];\n /** IDs of items suppressed from other sections due to anti-repetition. */\n suppressedIds: string[];\n};\n\n// =============================================================================\n// DELTA REPORT (RS-2)\n// =============================================================================\n\n/** A verification obligation surfaced by delta compilation. */\nexport type VerificationObligation = {\n /** What must be verified. */\n description: string;\n /** Source of the obligation (e.g., \"belief:xyz confidence drop\"). */\n source: string;\n /** Severity: how important it is to verify. */\n severity: \"critical\" | \"high\" | \"medium\" | \"low\";\n};\n\n/** Delta report appended to context packs when mode = \"delta\". */\nexport type ContextPackDeltaReport = {\n /** Items that changed since the reference point (new, updated, removed). */\n changedItems: Array<{\n id: string;\n section: ContextPackSectionKey;\n changeType: \"added\" | \"updated\" | \"removed\" | \"confidence_changed\";\n summary: string;\n }>;\n /** Obligations the consuming session must verify. */\n verificationObligations: VerificationObligation[];\n /** Reference point for the delta (worktree ID, timestamp, or commit SHA). */\n referencePoint: string;\n};\n\n// =============================================================================\n// PACK WEIGHT OVERRIDES (RS-2)\n// =============================================================================\n\n/**\n * Per-section weight overrides that domain packs can apply.\n * Overrides merge with RANKING_WEIGHTS — only specified fields replace defaults.\n */\nexport type PackWeightOverride = {\n /** Which section to override weights for. */\n section: ContextPackSectionKey;\n /** Partial weight vector — only specified fields replace defaults. */\n weights: Partial<RankingWeightVector>;\n};\n\n// =============================================================================\n// INJECTION POLICY\n// =============================================================================\n\n/** Token-budgeted section selections for prompt injection. */\nexport type ContextPackInjectionPolicy = {\n /** Total token budget for the entire context pack. */\n tokenBudget: number;\n /** Estimated tokens consumed across all sections. */\n estimatedTokens: number;\n /** Per-section token budgets derived from SECTION_BUDGET_RATIOS. */\n sectionBudgets: Record<ContextPackSectionKey, number>;\n /** Actual token usage per section after greedy fill. */\n sectionUsage: Record<ContextPackSectionKey, number>;\n /** Node/question IDs selected for injection, per section. */\n selected: Record<ContextPackSectionKey, string[]>;\n /** Items that were scored but excluded from injection, with reason (RS-2). */\n excludedItems?: Array<{\n id: string;\n section: ContextPackSectionKey;\n reason: \"budget_exceeded\" | \"anti_repetition\" | \"below_threshold\";\n score: number;\n }>;\n};\n\n// =============================================================================\n// DIAGNOSTICS\n// =============================================================================\n\n/** Telemetry for context pack assembly. */\nexport type ContextPackDiagnostics = {\n /** Total candidates scored across all sections. */\n itemsScored: number;\n /** Ratio of estimatedTokens / tokenBudget. Range [0, 1+]. */\n tokenBudgetUtilization: number;\n};\n\n// =============================================================================\n// PUBLIC COMPILED CONTEXT TYPES\n// =============================================================================\n\n/**\n * Public context surface returned by the SDK-facing context client.\n *\n * This preserves the existing external shape while the canonical compiler\n * contract evolves in parallel as ContextPackV1.\n */\nexport type PublicContextBelief = {\n beliefId: string;\n text: string;\n confidence: number | null;\n beliefType?: string | null;\n status?: string;\n updatedAt?: number | null;\n score: number;\n justification?: string;\n};\n\nexport type PublicContextQuestion = {\n questionId: string;\n text: string;\n status: string;\n priority: string;\n updatedAt?: number | null;\n score: number;\n justification?: string;\n};\n\nexport type PublicContextEvidence = {\n evidenceId: string;\n text: string;\n sourceUrl?: string | null;\n kind: string;\n createdAt?: number | null;\n score: number;\n justification?: string;\n};\n\nexport type PublicContextContradiction = {\n contradictionId: string;\n severity: string;\n status: string;\n description: string;\n score: number;\n justification?: string;\n};\n\nexport type PublicContextEntity = {\n entityId: string;\n entityType: string;\n title: string;\n text?: string;\n connectedBeliefCount: number;\n connectedEvidenceCount: number;\n score: number;\n metadata?: Record<string, unknown>;\n};\n\nexport type PublicContextInjectionPolicy = {\n tokenBudget: number;\n estimatedTokens: number;\n sectionBudgets: Record<string, number>;\n sectionUsage: Record<string, number>;\n selected: Record<string, string[]>;\n excludedItems?: Array<{\n id: string;\n section: string;\n reason: \"budget_exceeded\" | \"anti_repetition\" | \"below_threshold\";\n score: number;\n }>;\n};\n\nexport type PublicCompiledContext = {\n schemaVersion: string;\n topicId: string;\n topicName: string;\n scopedTopicIds: string[];\n generatedAt: number;\n ranking: ContextRankingProfile;\n summary: Record<string, unknown>;\n invariants: PublicContextBelief[];\n activeBeliefs: PublicContextBelief[];\n openQuestions: PublicContextQuestion[];\n recentEvidence: PublicContextEvidence[];\n contradictions: PublicContextContradiction[];\n relatedEntities?: PublicContextEntity[];\n contextNarrative: string[];\n injectionPolicy: PublicContextInjectionPolicy;\n diagnostics: Record<string, unknown>;\n compilationMode?: string;\n failureContext?: {\n failures: Array<{\n attemptId: string;\n approach: string;\n outcome: string;\n recordedAt: number;\n score: number;\n }>;\n suppressedIds: string[];\n };\n deltaReport?: {\n changedItems: Array<{\n id: string;\n section: string;\n changeType: string;\n summary: string;\n }>;\n verificationObligations: Array<{\n description: string;\n source: string;\n severity: \"critical\" | \"high\" | \"medium\" | \"low\";\n }>;\n referencePoint: string;\n };\n appliedWeightOverrides?: unknown[];\n};\n\n// =============================================================================\n// CONTEXT PACK V1 (TOP-LEVEL OUTPUT)\n// =============================================================================\n\n/**\n * The canonical output schema for context compilation responses.\n *\n * This is the contract that consumers depend on. All fields are required\n * in the output. Adding optional fields is non-breaking; removing or\n * changing types is breaking (requires version bump).\n */\nexport type ContextPackV1 = {\n /** Schema version for compatibility checking. */\n schemaVersion: typeof CONTEXT_PACK_SCHEMA_VERSION;\n /** Deprecated compatibility alias for the requested scope ID. */\n projectId?: string;\n /** Resolved topic ID after scope resolution. */\n topicId: string;\n /** Human-readable topic name. */\n topicName: string;\n /** All topic IDs included in the neighborhood expansion. */\n scopedTopicIds: string[];\n /** Deterministic freshness watermark for this pack (ms since epoch). */\n generatedAt: number;\n /** Which ranking profile was used. */\n rankingProfile: ContextRankingProfile;\n /** Aggregate counts and health signals. */\n summary: ContextPackSummary;\n /** High-confidence invariant beliefs (beliefType = \"invariant\"). */\n invariants: ContextPackBelief[];\n /** Active beliefs ranked by query relevance. */\n activeBeliefs: ContextPackBelief[];\n /** Open questions ranked by relevance and priority. */\n openQuestions: ContextPackQuestion[];\n /** Recent evidence ranked by relevance and recency. */\n recentEvidence: ContextPackEvidence[];\n /** Active contradictions ranked by severity. */\n contradictions: ContextPackContradiction[];\n /**\n * Ontological entities connected to beliefs in scope, ranked by connectivity.\n * Optional — present when entity graph substrate is active for this topic.\n * NON-BREAKING addition per contract rules.\n */\n relatedEntities?: ContextPackEntity[];\n /** Concise instructions for agent context injection. */\n contextNarrative: string[];\n /** Token-budgeted injection selections. */\n injectionPolicy: ContextPackInjectionPolicy;\n /** Assembly telemetry. */\n diagnostics: ContextPackDiagnostics;\n /** Compilation mode used to generate this pack (RS-2). Default: \"standard\". */\n compilationMode?: ContextCompilationMode;\n /** Failure context for anti-repetition (RS-2). Present when failures are relevant. */\n failureContext?: ContextPackFailureContext;\n /** Delta report (RS-2). Present only when compilationMode = \"delta\". */\n deltaReport?: ContextPackDeltaReport;\n /** Pack weight overrides applied during ranking (RS-2). */\n appliedWeightOverrides?: PackWeightOverride[];\n};\n\n// =============================================================================\n// CONTEXT PACK REQUEST V1 (INPUT)\n// =============================================================================\n\n/**\n * The canonical input schema for `compile_context`.\n * `topicId` is optional for query-first callers. When omitted, the platform\n * resolves the best topic from the query and other available signals.\n * `projectId` remains an optional compatibility alias.\n */\nexport type ContextPackRequestV1 = {\n /** Topic scope ID. Omit to resolve by query. */\n topicId?: string;\n /** Deprecated compatibility alias for older callers. */\n projectId?: string;\n /** Focus query for relevance ranking. */\n query?: string;\n /** Optional natural-language topic hint for query-first topic resolution. */\n topicHint?: string;\n /** Optional resolver tags for query-first topic resolution. */\n tags?: string[];\n /** Optional path signals for query-first topic resolution. */\n touchedPaths?: string[];\n /** Optional source reference signal for query-first topic resolution. */\n sourceRef?: string;\n /** Optional source kind signal for query-first topic resolution. */\n sourceKind?: string;\n /** Max items per section. Default: DEFAULT_SECTION_LIMIT. */\n limit?: number;\n /** Ranking profile. Default: DEFAULT_RANKING_PROFILE. */\n rankingProfile?: ContextRankingProfile;\n /** Total token budget. Default: DEFAULT_TOKEN_BUDGET. */\n tokenBudget?: number;\n /** Descendant topic depth for neighborhood expansion. */\n maxDepth?: number;\n /** Include ontological entities connected to beliefs in scope. Default: true. */\n includeEntities?: boolean;\n /** Compilation mode (RS-2). Default: \"standard\". */\n mode?: ContextCompilationMode;\n /** Include failure log context for anti-repetition (RS-2). Default: false. */\n includeFailures?: boolean;\n /** Active worktree ID for delta mode reference point (RS-2). */\n worktreeId?: string;\n /** Session ID for anti-repetition dedup (RS-2). */\n sessionId?: string;\n /** Pack weight overrides from domain pack binding (RS-2). */\n packWeightOverrides?: PackWeightOverride[];\n /**\n * Maximum carrier topics to enrich with raw belief/question/evidence rows for\n * explicit dimension-seeded compiles. The full dimension is still synthesized\n * through worktrees and receipts; this only bounds raw content fan-out.\n */\n contentTopicLimit?: number;\n};\n\n// =============================================================================\n// RESOLVED QUESTION STATUSES\n// =============================================================================\n\n/**\n * Question statuses that are considered \"resolved\" (not open).\n * Used to filter which questions appear in the openQuestions section.\n */\nexport const RESOLVED_QUESTION_STATUSES: readonly string[] = [\n \"answered\",\n \"archived\",\n \"closed\",\n \"resolved\",\n \"resolved_support\",\n \"resolved_contra\",\n \"belief_forked\",\n] as const;\n\n// =============================================================================\n// TOKEN ESTIMATION\n// =============================================================================\n\n/**\n * Tokens-per-word multiplier for rough token estimation.\n * Conservative estimate: ~1.35 tokens per whitespace-delimited word.\n */\nexport const TOKENS_PER_WORD = 1.35;\n\n/** Minimum token estimate for any non-empty string. */\nexport const MIN_TOKEN_ESTIMATE = 8;\n"]}
1
+ {"version":3,"sources":["../src/context-pack.contract.ts"],"names":[],"mappings":";AAqBO,IAAM,2BAAA,GAA8B;AAepC,IAAM,wBAAA,GAA6D;AAAA,EACxE,aAAA;AAAA,EACA;AACF;AAEO,IAAM,uBAAA,GAAiD;AAevD,IAAM,wBAAA,GAAmD;AAiBzD,IAAM,yBAAA,GAA8D;AAAA,EACzE,YAAA;AAAA,EACA,eAAA;AAAA,EACA,eAAA;AAAA,EACA,gBAAA;AAAA,EACA;AACF;AAiBO,IAAM,qBAAA,GAET;AAAA,EACF,UAAA,EAAY,IAAA;AAAA,EACZ,aAAA,EAAe,GAAA;AAAA,EACf,aAAA,EAAe,IAAA;AAAA,EACf,cAAA,EAAgB,IAAA;AAAA,EAChB,cAAA,EAAgB;AAClB;AAOO,IAAM,gBAAA,GAAmB;AAGzB,IAAM,gBAAA,GAAmB;AAGzB,IAAM,oBAAA,GAAuB;AAG7B,IAAM,qBAAA,GAAwB;AAG9B,IAAM,iBAAA,GAAoB;AAG1B,IAAM,wBAAA,GAA2B;AA0BjC,IAAM,eAAA,GAET;AAAA,EACF,UAAA,EAAY;AAAA,IACV,KAAA,EAAO,IAAA;AAAA,IACP,OAAA,EAAS,GAAA;AAAA,IACT,UAAA,EAAY,GAAA;AAAA,IACZ,UAAA,EAAY;AAAA,GACd;AAAA,EACA,aAAA,EAAe;AAAA,IACb,KAAA,EAAO,GAAA;AAAA,IACP,OAAA,EAAS,GAAA;AAAA,IACT,UAAA,EAAY,GAAA;AAAA,IACZ,UAAA,EAAY;AAAA,GACd;AAAA,EACA,aAAA,EAAe;AAAA,IACb,KAAA,EAAO,IAAA;AAAA,IACP,OAAA,EAAS,GAAA;AAAA,IACT,QAAA,EAAU;AAAA,GACZ;AAAA,EACA,cAAA,EAAgB;AAAA,IACd,KAAA,EAAO,GAAA;AAAA,IACP,OAAA,EAAS;AAAA,GACX;AAAA,EACA,cAAA,EAAgB;AAAA,IACd,KAAA,EAAO,GAAA;AAAA,IACP,OAAA,EAAS,GAAA;AAAA,IACT,QAAA,EAAU;AAAA;AAEd;AAGO,IAAM,sBAAA,GAAyB;AAQ/B,IAAM,sBAAA,GAAyB;AAAA,EACpC,KAAA,EAAO,GAAA;AAAA,EACP,YAAA,EAAc;AAChB;AAGO,IAAM,oBAAA,GAAuB;AAG7B,IAAM,gBAAA,GAAmB;AAUzB,IAAM,iBAAA,GAAsD;AAAA,EACjE,SAAA,EAAW,CAAA;AAAA,EACX,KAAA,EAAO,GAAA;AAAA,EACP,SAAA,EAAW;AACb;AAEO,IAAM,yBAAA,GAA4B;AAMlC,IAAM,eAAA,GAAoD;AAAA,EAC/D,QAAA,EAAU,CAAA;AAAA,EACV,IAAA,EAAM,IAAA;AAAA,EACN,MAAA,EAAQ,IAAA;AAAA,EACR,GAAA,EAAK;AACP;AAEO,IAAM,sBAAA,GAAyB;AAE/B,IAAM,eAAA,GAAoD;AAAA,EAC/D,QAAA,EAAU,CAAA;AAAA,EACV,IAAA,EAAM,IAAA;AAAA,EACN,MAAA,EAAQ,GAAA;AAAA,EACR,GAAA,EAAK;AACP;AAEO,IAAM,sBAAA,GAAyB;AAme/B,IAAM,0BAAA,GAAgD;AAAA,EAC3D,UAAA;AAAA,EACA,UAAA;AAAA,EACA,QAAA;AAAA,EACA,UAAA;AAAA,EACA,kBAAA;AAAA,EACA,iBAAA;AAAA,EACA;AACF;AAUO,IAAM,eAAA,GAAkB;AAGxB,IAAM,kBAAA,GAAqB","file":"context-pack.contract.js","sourcesContent":["/**\n * Context-Pack Contract v1\n *\n * Canonical TypeScript types and constants for the context-pack output schema.\n * This is the external contract consumed by:\n * - MCP tool `compile_context` (canonical compiler read)\n * - SDK/HTTP consumers that read compiled context packs programmatically\n * - Benchmark harnesses (context-pack-ab)\n *\n * BREAKING CHANGE RULES:\n * - Adding optional fields to ContextPackV1 is NON-breaking\n * - Removing fields or changing types is BREAKING (bump CONTEXT_PACK_SCHEMA_VERSION)\n * - Changing section budget ratios or ranking weights is NON-breaking (tuning)\n * - Changing the version string is BREAKING (consumers check it)\n */\n\n// =============================================================================\n// SCHEMA VERSION\n// =============================================================================\n\n/** Canonical version string. Consumers MUST check this field for compatibility. */\nexport const CONTEXT_PACK_SCHEMA_VERSION = \"1.0.0\" as const;\n\n// =============================================================================\n// RANKING PROFILES\n// =============================================================================\n\n/**\n * Available ranking profiles for context-pack assembly.\n *\n * - `baseline_v1`: Simple token-hit counting. Items with zero query hits are excluded.\n * - `weighted_v1`: Multi-signal scoring combining query relevance, recency, confidence,\n * belief type, priority, and severity with section-specific weight vectors.\n */\nexport type ContextRankingProfile = \"baseline_v1\" | \"weighted_v1\";\n\nexport const CONTEXT_RANKING_PROFILES: readonly ContextRankingProfile[] = [\n \"baseline_v1\",\n \"weighted_v1\",\n] as const;\n\nexport const DEFAULT_RANKING_PROFILE: ContextRankingProfile = \"weighted_v1\";\n\n// =============================================================================\n// COMPILATION MODE (RS-2)\n// =============================================================================\n\n/**\n * Context compilation mode.\n *\n * - `standard`: Default — ranked beliefs, questions, evidence, contradictions.\n * - `delta`: Diff-aware — adds failure context, verification obligations,\n * and worktree ledger analysis to the standard context pack.\n */\nexport type ContextCompilationMode = \"standard\" | \"delta\";\n\nexport const DEFAULT_COMPILATION_MODE: ContextCompilationMode = \"standard\";\n\n// =============================================================================\n// SECTION KEYS\n// =============================================================================\n\n/**\n * The five canonical sections of a context pack.\n * Order matters: invariants are injected first, contradictions last.\n */\nexport type ContextPackSectionKey =\n | \"invariants\"\n | \"activeBeliefs\"\n | \"openQuestions\"\n | \"recentEvidence\"\n | \"contradictions\";\n\nexport const CONTEXT_PACK_SECTION_KEYS: readonly ContextPackSectionKey[] = [\n \"invariants\",\n \"activeBeliefs\",\n \"openQuestions\",\n \"recentEvidence\",\n \"contradictions\",\n] as const;\n\n// =============================================================================\n// SECTION BUDGET RATIOS\n// =============================================================================\n\n/**\n * Token budget allocation ratios per section.\n * These sum to 1.0 and determine how the total tokenBudget is divided.\n *\n * Rationale:\n * - invariants (0.28): Highest-priority constraints, injected first\n * - activeBeliefs (0.30): Largest section, carries domain knowledge\n * - openQuestions (0.17): Unresolved work items guide agent behavior\n * - recentEvidence (0.17): Implementation context for grounding\n * - contradictions (0.08): Tension signals, smallest section\n */\nexport const SECTION_BUDGET_RATIOS: Readonly<\n Record<ContextPackSectionKey, number>\n> = {\n invariants: 0.28,\n activeBeliefs: 0.3,\n openQuestions: 0.17,\n recentEvidence: 0.17,\n contradictions: 0.08,\n} as const;\n\n// =============================================================================\n// TOKEN BUDGET CONSTRAINTS\n// =============================================================================\n\n/** Minimum allowed token budget. Below this, context packs lose utility. */\nexport const MIN_TOKEN_BUDGET = 400;\n\n/** Maximum allowed token budget. Above this, context packs bloat prompts. */\nexport const MAX_TOKEN_BUDGET = 8000;\n\n/** Default token budget when caller does not specify. */\nexport const DEFAULT_TOKEN_BUDGET = 1800;\n\n/** Default max items per section. */\nexport const DEFAULT_SECTION_LIMIT = 8;\n\n/** Hard ceiling on items per section. */\nexport const MAX_SECTION_LIMIT = 25;\n\n/** Minimum contradiction section budget floor (tokens). */\nexport const MIN_CONTRADICTION_BUDGET = 40;\n\n// =============================================================================\n// RANKING WEIGHT VECTORS\n// =============================================================================\n\n/**\n * Weight vectors for the weighted_v1 ranking profile.\n * Each section has a different signal mix:\n *\n * - query: How many query tokens appear in the candidate text\n * - recency: Exponential decay from updatedAt (half-life = 30 days)\n * - confidence: Belief confidence score [0,1]\n * - beliefType: Bonus for invariant > tenet > principle > other\n * - priority: Question priority (critical > high > medium > low)\n * - severity: Contradiction severity (critical > high > medium > low)\n */\nexport type RankingWeightVector = {\n query: number;\n recency: number;\n confidence?: number;\n beliefType?: number;\n priority?: number;\n severity?: number;\n};\n\nexport const RANKING_WEIGHTS: Readonly<\n Record<ContextPackSectionKey, RankingWeightVector>\n> = {\n invariants: {\n query: 0.35,\n recency: 0.1,\n confidence: 0.4,\n beliefType: 0.15,\n },\n activeBeliefs: {\n query: 0.5,\n recency: 0.2,\n confidence: 0.2,\n beliefType: 0.1,\n },\n openQuestions: {\n query: 0.55,\n recency: 0.2,\n priority: 0.25,\n },\n recentEvidence: {\n query: 0.6,\n recency: 0.4,\n },\n contradictions: {\n query: 0.4,\n recency: 0.2,\n severity: 0.4,\n },\n} as const;\n\n/** Recency decay half-life in days. After 30 days, recency score = 0.5. */\nexport const RECENCY_HALF_LIFE_DAYS = 30;\n\n/**\n * Ranking weight vector for the relatedEntities section.\n * Entities are ranked by query relevance and connectivity (bridge edge count).\n * Separate from RANKING_WEIGHTS because entities are not part of the\n * token-budgeted injection plan.\n */\nexport const ENTITY_RANKING_WEIGHTS = {\n query: 0.4,\n connectivity: 0.6,\n} as const;\n\n/** Default max entities to include in the context pack. */\nexport const DEFAULT_ENTITY_LIMIT = 10;\n\n/** Hard ceiling on entities per context pack. */\nexport const MAX_ENTITY_LIMIT = 50;\n\n// =============================================================================\n// BELIEF TYPE BONUS MAP\n// =============================================================================\n\n/**\n * Bonus multiplier for belief types in ranking.\n * Invariants get 1.0, unknown types get 0.4.\n */\nexport const BELIEF_TYPE_BONUS: Readonly<Record<string, number>> = {\n invariant: 1.0,\n tenet: 0.8,\n principle: 0.6,\n} as const;\n\nexport const DEFAULT_BELIEF_TYPE_BONUS = 0.4;\n\n// =============================================================================\n// PRIORITY / SEVERITY SCORE MAPS\n// =============================================================================\n\nexport const PRIORITY_SCORES: Readonly<Record<string, number>> = {\n critical: 1.0,\n high: 0.85,\n medium: 0.55,\n low: 0.35,\n} as const;\n\nexport const DEFAULT_PRIORITY_SCORE = 0.5;\n\nexport const SEVERITY_SCORES: Readonly<Record<string, number>> = {\n critical: 1.0,\n high: 0.85,\n medium: 0.6,\n low: 0.35,\n} as const;\n\nexport const DEFAULT_SEVERITY_SCORE = 0.5;\n\n// =============================================================================\n// SECTION ITEM TYPES\n// =============================================================================\n\n/** A ranked belief in the invariants or activeBeliefs section. */\nexport type ContextPackBelief = {\n nodeId: string;\n canonicalText: string;\n confidence: number | null;\n beliefType: string | null;\n score: number;\n /** Present in activeBeliefs, absent in invariants */\n status?: string;\n updatedAt?: number | null;\n /** Human-readable explanation of why this item was ranked here (RS-2). */\n justification?: string;\n};\n\n/** A ranked question in the openQuestions section. */\nexport type ContextPackQuestion = {\n questionId: string;\n text: string;\n status: string;\n priority: string;\n updatedAt?: number | null;\n score: number;\n /** Human-readable explanation of why this item was ranked here (RS-2). */\n justification?: string;\n};\n\n/** A ranked evidence item in the recentEvidence section. */\nexport type ContextPackEvidence = {\n nodeId: string;\n canonicalText: string;\n sourceUrl: string | null;\n kind: string;\n createdAt: number | null;\n score: number;\n /** Human-readable explanation of why this item was ranked here (RS-2). */\n justification?: string;\n};\n\n/** A ranked contradiction in the contradictions section. */\nexport type ContextPackContradiction = {\n contradictionId: string;\n severity: string;\n status: string;\n description: string;\n score: number;\n /** Human-readable explanation of why this item was ranked here (RS-2). */\n justification?: string;\n};\n\n/**\n * An entity from the ontological layer surfaced in the context pack.\n * Entities are domain objects (companies, people, functions, etc.) connected\n * to beliefs via bridge edges. They provide the \"reality anchor\" that makes\n * the reasoning graph domain-aware.\n */\nexport type ContextPackEntity = {\n /** Convex document ID of the entity node. */\n nodeId: string;\n /** Entity type (e.g., \"company\", \"person\", \"function\"). */\n entityType: string;\n /** Human-readable title/name of the entity. */\n title: string;\n /** Number of beliefs connected to this entity via bridge edges. */\n connectedBeliefCount: number;\n /** Number of evidence items referencing this entity. */\n connectedEvidenceCount: number;\n /** Relevance score from ranking algorithm. */\n score: number;\n /** Entity metadata (structured per ontology schema). */\n metadata?: Record<string, unknown>;\n};\n\n/**\n * A lattice seed entry representing a belief that was auto-generated\n * to cover an ontology entity type within a topic scope.\n */\nexport type BeliefLatticeSeed = {\n /** The belief node ID that was created or already existed. */\n beliefNodeId: string;\n /** The entity type this seed belief covers. */\n entityType: string;\n /** Whether this seed was newly created or already existed. */\n created: boolean;\n /** The canonical text of the seed belief. */\n canonicalText: string;\n};\n\n// =============================================================================\n// SUMMARY\n// =============================================================================\n\n/** Counts and scoped health signals for the context pack. */\nexport type ContextPackSummary = {\n totalBeliefs: number;\n invariants: number;\n openQuestions: number;\n evidenceItems: number;\n contradictions: number;\n /** Number of ontological entities in scope (optional, present when entity graph is active). */\n relatedEntities?: number;\n scopedTopics: number;\n descendantDepth: number;\n query: string | null;\n};\n\n// =============================================================================\n// FAILURE CONTEXT (RS-2)\n// =============================================================================\n\n/** A failed approach surfaced from the failure log for anti-repetition. */\nexport type ContextPackFailure = {\n /** Lucern attempt/evidence node ID. */\n attemptId: string;\n /** What was tried. */\n approach: string;\n /** Why it failed. */\n outcome: string;\n /** When the attempt was recorded (ms since epoch). */\n recordedAt: number;\n /** Relevance score from ranking algorithm. */\n score: number;\n};\n\n/** Failure context section appended to context packs in delta mode. */\nexport type ContextPackFailureContext = {\n /** Ranked failed approaches relevant to the current query. */\n failures: ContextPackFailure[];\n /** IDs of items suppressed from other sections due to anti-repetition. */\n suppressedIds: string[];\n};\n\n// =============================================================================\n// DELTA REPORT (RS-2)\n// =============================================================================\n\n/** A verification obligation surfaced by delta compilation. */\nexport type VerificationObligation = {\n /** What must be verified. */\n description: string;\n /** Source of the obligation (e.g., \"belief:xyz confidence drop\"). */\n source: string;\n /** Severity: how important it is to verify. */\n severity: \"critical\" | \"high\" | \"medium\" | \"low\";\n};\n\n/** Delta report appended to context packs when mode = \"delta\". */\nexport type ContextPackDeltaReport = {\n /** Items that changed since the reference point (new, updated, removed). */\n changedItems: Array<{\n id: string;\n section: ContextPackSectionKey;\n changeType: \"added\" | \"updated\" | \"removed\" | \"confidence_changed\";\n summary: string;\n }>;\n /** Obligations the consuming session must verify. */\n verificationObligations: VerificationObligation[];\n /** Reference point for the delta (worktree ID, timestamp, or commit SHA). */\n referencePoint: string;\n};\n\n// =============================================================================\n// PACK WEIGHT OVERRIDES (RS-2)\n// =============================================================================\n\n/**\n * Per-section weight overrides that domain packs can apply.\n * Overrides merge with RANKING_WEIGHTS — only specified fields replace defaults.\n */\nexport type PackWeightOverride = {\n /** Which section to override weights for. */\n section: ContextPackSectionKey;\n /** Partial weight vector — only specified fields replace defaults. */\n weights: Partial<RankingWeightVector>;\n};\n\n// =============================================================================\n// INJECTION POLICY\n// =============================================================================\n\n/** Token-budgeted section selections for prompt injection. */\nexport type ContextPackInjectionPolicy = {\n /** Total token budget for the entire context pack. */\n tokenBudget: number;\n /** Estimated tokens consumed across all sections. */\n estimatedTokens: number;\n /** Per-section token budgets derived from SECTION_BUDGET_RATIOS. */\n sectionBudgets: Record<ContextPackSectionKey, number>;\n /** Actual token usage per section after greedy fill. */\n sectionUsage: Record<ContextPackSectionKey, number>;\n /** Node/question IDs selected for injection, per section. */\n selected: Record<ContextPackSectionKey, string[]>;\n /** Items that were scored but excluded from injection, with reason (RS-2). */\n excludedItems?: Array<{\n id: string;\n section: ContextPackSectionKey;\n reason: \"budget_exceeded\" | \"anti_repetition\" | \"below_threshold\";\n score: number;\n }>;\n};\n\n// =============================================================================\n// DIAGNOSTICS\n// =============================================================================\n\n/** Telemetry for context pack assembly. */\nexport type ContextPackDiagnostics = {\n /** Total candidates scored across all sections. */\n itemsScored: number;\n /** Ratio of estimatedTokens / tokenBudget. Range [0, 1+]. */\n tokenBudgetUtilization: number;\n};\n\n// =============================================================================\n// PUBLIC COMPILED CONTEXT TYPES\n// =============================================================================\n\n/**\n * Public context surface returned by the SDK-facing context client.\n *\n * This preserves the existing external shape while the canonical compiler\n * contract evolves in parallel as ContextPackV1.\n */\nexport type PublicContextBelief = {\n beliefId: string;\n text: string;\n confidence: number | null;\n beliefType?: string | null;\n status?: string;\n updatedAt?: number | null;\n score: number;\n justification?: string;\n};\n\nexport type PublicContextQuestion = {\n questionId: string;\n text: string;\n status: string;\n priority: string;\n updatedAt?: number | null;\n score: number;\n justification?: string;\n};\n\nexport type PublicContextEvidence = {\n evidenceId: string;\n text: string;\n sourceUrl?: string | null;\n kind: string;\n createdAt?: number | null;\n score: number;\n justification?: string;\n};\n\nexport type PublicContextContradiction = {\n contradictionId: string;\n severity: string;\n status: string;\n description: string;\n score: number;\n justification?: string;\n};\n\nexport type PublicContextEntity = {\n entityId: string;\n entityType: string;\n title: string;\n text?: string;\n connectedBeliefCount: number;\n connectedEvidenceCount: number;\n score: number;\n metadata?: Record<string, unknown>;\n};\n\nexport type PublicContextInjectionPolicy = {\n tokenBudget: number;\n estimatedTokens: number;\n sectionBudgets: Record<string, number>;\n sectionUsage: Record<string, number>;\n selected: Record<string, string[]>;\n excludedItems?: Array<{\n id: string;\n section: string;\n reason: \"budget_exceeded\" | \"anti_repetition\" | \"below_threshold\";\n score: number;\n }>;\n};\n\nexport type PublicContextNarrativeBlock = {\n kind: string;\n text: string;\n recordsNamed?: number;\n};\n\nexport type PublicContextSupportingObjects = {\n invariants?: PublicContextBelief[];\n activeBeliefs?: PublicContextBelief[];\n openQuestions?: PublicContextQuestion[];\n recentEvidence?: PublicContextEvidence[];\n contradictions?: PublicContextContradiction[];\n relatedEntities?: PublicContextEntity[];\n worktrees?: unknown[];\n lanes?: string[];\n entities?: unknown[];\n};\n\nexport type PublicCompiledContext = {\n contextNarrative: Array<string | PublicContextNarrativeBlock>;\n narrativeCoverage?: Record<string, unknown>;\n synthesisLints?: Array<Record<string, unknown>>;\n retrievalReceipt?: Record<string, unknown>;\n supportingObjects?: PublicContextSupportingObjects;\n schemaVersion: string;\n topicId: string;\n topicName: string;\n scopedTopicIds: string[];\n generatedAt: number;\n ranking: ContextRankingProfile;\n summary: Record<string, unknown>;\n invariants?: PublicContextBelief[];\n activeBeliefs?: PublicContextBelief[];\n openQuestions?: PublicContextQuestion[];\n recentEvidence?: PublicContextEvidence[];\n contradictions?: PublicContextContradiction[];\n relatedEntities?: PublicContextEntity[];\n injectionPolicy: PublicContextInjectionPolicy;\n diagnostics: Record<string, unknown>;\n compilationMode?: string;\n failureContext?: {\n failures: Array<{\n attemptId: string;\n approach: string;\n outcome: string;\n recordedAt: number;\n score: number;\n }>;\n suppressedIds: string[];\n };\n deltaReport?: {\n changedItems: Array<{\n id: string;\n section: string;\n changeType: string;\n summary: string;\n }>;\n verificationObligations: Array<{\n description: string;\n source: string;\n severity: \"critical\" | \"high\" | \"medium\" | \"low\";\n }>;\n referencePoint: string;\n };\n appliedWeightOverrides?: unknown[];\n};\n\n// =============================================================================\n// CONTEXT PACK V1 (TOP-LEVEL OUTPUT)\n// =============================================================================\n\n/**\n * The canonical output schema for context compilation responses.\n *\n * This is the contract that consumers depend on. All fields are required\n * in the output. Adding optional fields is non-breaking; removing or\n * changing types is breaking (requires version bump).\n */\nexport type ContextPackV1 = {\n /** Schema version for compatibility checking. */\n schemaVersion: typeof CONTEXT_PACK_SCHEMA_VERSION;\n /** Deprecated compatibility alias for the requested scope ID. */\n projectId?: string;\n /** Resolved topic ID after scope resolution. */\n topicId: string;\n /** Human-readable topic name. */\n topicName: string;\n /** All topic IDs included in the neighborhood expansion. */\n scopedTopicIds: string[];\n /** Deterministic freshness watermark for this pack (ms since epoch). */\n generatedAt: number;\n /** Which ranking profile was used. */\n rankingProfile: ContextRankingProfile;\n /** Aggregate counts and health signals. */\n summary: ContextPackSummary;\n /** High-confidence invariant beliefs (beliefType = \"invariant\"). */\n invariants: ContextPackBelief[];\n /** Active beliefs ranked by query relevance. */\n activeBeliefs: ContextPackBelief[];\n /** Open questions ranked by relevance and priority. */\n openQuestions: ContextPackQuestion[];\n /** Recent evidence ranked by relevance and recency. */\n recentEvidence: ContextPackEvidence[];\n /** Active contradictions ranked by severity. */\n contradictions: ContextPackContradiction[];\n /**\n * Ontological entities connected to beliefs in scope, ranked by connectivity.\n * Optional — present when entity graph substrate is active for this topic.\n * NON-BREAKING addition per contract rules.\n */\n relatedEntities?: ContextPackEntity[];\n /** Concise instructions for agent context injection. */\n contextNarrative: string[];\n /** Token-budgeted injection selections. */\n injectionPolicy: ContextPackInjectionPolicy;\n /** Assembly telemetry. */\n diagnostics: ContextPackDiagnostics;\n /** Compilation mode used to generate this pack (RS-2). Default: \"standard\". */\n compilationMode?: ContextCompilationMode;\n /** Failure context for anti-repetition (RS-2). Present when failures are relevant. */\n failureContext?: ContextPackFailureContext;\n /** Delta report (RS-2). Present only when compilationMode = \"delta\". */\n deltaReport?: ContextPackDeltaReport;\n /** Pack weight overrides applied during ranking (RS-2). */\n appliedWeightOverrides?: PackWeightOverride[];\n};\n\n// =============================================================================\n// CONTEXT PACK REQUEST V1 (INPUT)\n// =============================================================================\n\n/**\n * The canonical input schema for `compile_context`.\n * `topicId` is optional for query-first callers. When omitted, the platform\n * resolves the best topic from the query and other available signals.\n * `projectId` remains an optional compatibility alias.\n */\nexport type ContextPackRequestV1 = {\n /** Topic scope ID. Omit to resolve by query. */\n topicId?: string;\n /** Deprecated compatibility alias for older callers. */\n projectId?: string;\n /** Focus query for relevance ranking. */\n query?: string;\n /** Optional natural-language topic hint for query-first topic resolution. */\n topicHint?: string;\n /** Optional resolver tags for query-first topic resolution. */\n tags?: string[];\n /** Optional path signals for query-first topic resolution. */\n touchedPaths?: string[];\n /** Optional source reference signal for query-first topic resolution. */\n sourceRef?: string;\n /** Optional source kind signal for query-first topic resolution. */\n sourceKind?: string;\n /** Max items per section. Default: DEFAULT_SECTION_LIMIT. */\n limit?: number;\n /** Ranking profile. Default: DEFAULT_RANKING_PROFILE. */\n rankingProfile?: ContextRankingProfile;\n /** Total token budget. Default: DEFAULT_TOKEN_BUDGET. */\n tokenBudget?: number;\n /** Descendant topic depth for neighborhood expansion. */\n maxDepth?: number;\n /** Include ontological entities connected to beliefs in scope. Default: true. */\n includeEntities?: boolean;\n /** Compilation mode (RS-2). Default: \"standard\". */\n mode?: ContextCompilationMode;\n /** Include failure log context for anti-repetition (RS-2). Default: false. */\n includeFailures?: boolean;\n /** Active worktree ID for delta mode reference point (RS-2). */\n worktreeId?: string;\n /** Session ID for anti-repetition dedup (RS-2). */\n sessionId?: string;\n /** Pack weight overrides from domain pack binding (RS-2). */\n packWeightOverrides?: PackWeightOverride[];\n /**\n * Maximum carrier topics to enrich with raw belief/question/evidence rows for\n * explicit dimension-seeded compiles. The full dimension is still synthesized\n * through worktrees and receipts; this only bounds raw content fan-out.\n */\n contentTopicLimit?: number;\n};\n\n// =============================================================================\n// RESOLVED QUESTION STATUSES\n// =============================================================================\n\n/**\n * Question statuses that are considered \"resolved\" (not open).\n * Used to filter which questions appear in the openQuestions section.\n */\nexport const RESOLVED_QUESTION_STATUSES: readonly string[] = [\n \"answered\",\n \"archived\",\n \"closed\",\n \"resolved\",\n \"resolved_support\",\n \"resolved_contra\",\n \"belief_forked\",\n] as const;\n\n// =============================================================================\n// TOKEN ESTIMATION\n// =============================================================================\n\n/**\n * Tokens-per-word multiplier for rough token estimation.\n * Conservative estimate: ~1.35 tokens per whitespace-delimited word.\n */\nexport const TOKENS_PER_WORD = 1.35;\n\n/** Minimum token estimate for any non-empty string. */\nexport const MIN_TOKEN_ESTIMATE = 8;\n"]}