@lucern/contracts 1.0.15 → 1.0.16

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 (62) hide show
  1. package/CHANGELOG.md +3 -0
  2. package/dist/context-pack.contract.d.ts +6 -0
  3. package/dist/context-pack.contract.js.map +1 -1
  4. package/dist/function-registry/beliefs.js +5 -1
  5. package/dist/function-registry/beliefs.js.map +1 -1
  6. package/dist/function-registry/coding.js +5 -1
  7. package/dist/function-registry/coding.js.map +1 -1
  8. package/dist/function-registry/context.js +5 -1
  9. package/dist/function-registry/context.js.map +1 -1
  10. package/dist/function-registry/contracts.js +5 -1
  11. package/dist/function-registry/contracts.js.map +1 -1
  12. package/dist/function-registry/coordination.js +5 -1
  13. package/dist/function-registry/coordination.js.map +1 -1
  14. package/dist/function-registry/edges.js +5 -1
  15. package/dist/function-registry/edges.js.map +1 -1
  16. package/dist/function-registry/evidence.js +5 -1
  17. package/dist/function-registry/evidence.js.map +1 -1
  18. package/dist/function-registry/graph.js +5 -1
  19. package/dist/function-registry/graph.js.map +1 -1
  20. package/dist/function-registry/helpers.js +5 -1
  21. package/dist/function-registry/helpers.js.map +1 -1
  22. package/dist/function-registry/identity.js +5 -1
  23. package/dist/function-registry/identity.js.map +1 -1
  24. package/dist/function-registry/index.js +5 -1
  25. package/dist/function-registry/index.js.map +1 -1
  26. package/dist/function-registry/judgments.js +5 -1
  27. package/dist/function-registry/judgments.js.map +1 -1
  28. package/dist/function-registry/legacy.js +5 -1
  29. package/dist/function-registry/legacy.js.map +1 -1
  30. package/dist/function-registry/lenses.js +5 -1
  31. package/dist/function-registry/lenses.js.map +1 -1
  32. package/dist/function-registry/nodes.js +5 -1
  33. package/dist/function-registry/nodes.js.map +1 -1
  34. package/dist/function-registry/ontologies.js +5 -1
  35. package/dist/function-registry/ontologies.js.map +1 -1
  36. package/dist/function-registry/pipeline.js +5 -1
  37. package/dist/function-registry/pipeline.js.map +1 -1
  38. package/dist/function-registry/questions.js +5 -1
  39. package/dist/function-registry/questions.js.map +1 -1
  40. package/dist/function-registry/tasks.js +5 -1
  41. package/dist/function-registry/tasks.js.map +1 -1
  42. package/dist/function-registry/topics.js +5 -1
  43. package/dist/function-registry/topics.js.map +1 -1
  44. package/dist/function-registry/worktrees.js +5 -1
  45. package/dist/function-registry/worktrees.js.map +1 -1
  46. package/dist/index.js +5 -1
  47. package/dist/index.js.map +1 -1
  48. package/dist/proof-attestation.json +1 -1
  49. package/dist/sdk-methods.contract.d.ts +6 -0
  50. package/dist/sdk-tools.contract.js +5 -1
  51. package/dist/sdk-tools.contract.js.map +1 -1
  52. package/dist/sdk-tools.contract.registry.js +5 -1
  53. package/dist/sdk-tools.contract.registry.js.map +1 -1
  54. package/dist/sdk-tools.contract.values.js +5 -1
  55. package/dist/sdk-tools.contract.values.js.map +1 -1
  56. package/dist/tool-contracts.js +5 -1
  57. package/dist/tool-contracts.js.map +1 -1
  58. package/dist/tool-contracts.questions-listing.js +5 -1
  59. package/dist/tool-contracts.questions-listing.js.map +1 -1
  60. package/dist/tool-contracts.values.js +5 -1
  61. package/dist/tool-contracts.values.js.map +1 -1
  62. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -52,3 +52,6 @@ All notable changes to `@lucern/contracts` are tracked in this repository.
52
52
 
53
53
  ## [1.0.15] - 2026-06-01
54
54
  - Release notes pending.
55
+
56
+ ## [1.0.16] - 2026-06-01
57
+ - Release notes pending.
@@ -491,6 +491,12 @@ type ContextPackRequestV1 = {
491
491
  sessionId?: string;
492
492
  /** Pack weight overrides from domain pack binding (RS-2). */
493
493
  packWeightOverrides?: PackWeightOverride[];
494
+ /**
495
+ * Maximum carrier topics to enrich with raw belief/question/evidence rows for
496
+ * explicit dimension-seeded compiles. The full dimension is still synthesized
497
+ * through worktrees and receipts; this only bounds raw content fan-out.
498
+ */
499
+ contentTopicLimit?: number;
494
500
  };
495
501
  /**
496
502
  * Question statuses that are considered "resolved" (not open).
@@ -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;AAuc/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\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;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"]}
@@ -2822,6 +2822,10 @@ var COMPILE_CONTEXT = {
2822
2822
  type: "number",
2823
2823
  description: "Optional per-section item limit"
2824
2824
  },
2825
+ contentTopicLimit: {
2826
+ type: "number",
2827
+ description: "Dimension-seeded compiles synthesize every matching worktree but bound raw belief/question/evidence enrichment to this many carrier topics (max 16) so hosted Convex queries remain fast. Receipts report any omitted raw topic enrichment."
2828
+ },
2825
2829
  maxDepth: {
2826
2830
  type: "number",
2827
2831
  description: "Optional descendant topic depth for neighborhood expansion"
@@ -2850,7 +2854,7 @@ var COMPILE_CONTEXT = {
2850
2854
  relatedEntities: "array | undefined \u2014 ranked ontological entities in scope",
2851
2855
  contextNarrative: "array \u2014 ordered synthesis blocks with kind/text, starting with executive_summary and canonical narrative blocks before raw objects",
2852
2856
  retrievalReceipt: "object \u2014 candidateCounts, coverageWarning, narrativeCoverage, synthesisLints, and suggestedNextActions",
2853
- narrativeCoverage: "object \u2014 recordsSynthesized, recordsNamed, recordsOmitted, and blocksEmitted for the narrative",
2857
+ narrativeCoverage: "object \u2014 recordsSynthesized, recordsNamed, recordsOmitted, topicsSynthesized, topicsEnriched, topicContentOmitted, enrichmentMode, and blocksEmitted for the narrative",
2854
2858
  injectionPolicy: "object \u2014 token-budgeted section selections",
2855
2859
  diagnostics: "object \u2014 scoring and utilization telemetry"
2856
2860
  }