@lucern/contracts 0.1.1-alpha.1 → 0.1.2-alpha.1

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 (151) hide show
  1. package/CHANGELOG.md +3 -0
  2. package/README.md +3 -0
  3. package/dist/agents/v1.d.ts +2 -0
  4. package/dist/agents/v1.js +3 -0
  5. package/dist/agents/v1.js.map +1 -0
  6. package/dist/api-enums.contract.d.ts +60 -0
  7. package/dist/api-enums.contract.js +160 -0
  8. package/dist/api-enums.contract.js.map +1 -0
  9. package/dist/auth-context.contract.d.ts +2 -0
  10. package/dist/auth-context.contract.js +48 -0
  11. package/dist/auth-context.contract.js.map +1 -0
  12. package/dist/auth-session.contract.d.ts +2 -0
  13. package/dist/auth-session.contract.js +48 -0
  14. package/dist/auth-session.contract.js.map +1 -0
  15. package/dist/auth.contract.d.ts +92 -0
  16. package/dist/auth.contract.js +48 -0
  17. package/dist/auth.contract.js.map +1 -0
  18. package/dist/beliefs/v1.d.ts +2 -0
  19. package/dist/beliefs/v1.js +3 -0
  20. package/dist/beliefs/v1.js.map +1 -0
  21. package/dist/context-pack.contract.d.ts +496 -0
  22. package/dist/context-pack.contract.js +98 -0
  23. package/dist/context-pack.contract.js.map +1 -0
  24. package/dist/convex-admin.contract.d.ts +7 -0
  25. package/dist/convex-admin.contract.js +3 -0
  26. package/dist/convex-admin.contract.js.map +1 -0
  27. package/dist/events-types.contract.d.ts +1 -0
  28. package/dist/events-types.contract.js +136 -0
  29. package/dist/events-types.contract.js.map +1 -0
  30. package/dist/events.contract.d.ts +178 -0
  31. package/dist/events.contract.js +136 -0
  32. package/dist/events.contract.js.map +1 -0
  33. package/dist/evidence/v1.d.ts +2 -0
  34. package/dist/evidence/v1.js +3 -0
  35. package/dist/evidence/v1.js.map +1 -0
  36. package/dist/gateway.contract.d.ts +79 -0
  37. package/dist/gateway.contract.js +12 -0
  38. package/dist/gateway.contract.js.map +1 -0
  39. package/dist/graph/v1.d.ts +2 -0
  40. package/dist/graph/v1.js +3 -0
  41. package/dist/graph/v1.js.map +1 -0
  42. package/dist/ids.contract.d.ts +9 -0
  43. package/{src/ids.contract.ts → dist/ids.contract.js} +10 -17
  44. package/dist/ids.contract.js.map +1 -0
  45. package/dist/index.d.ts +15 -2004
  46. package/dist/index.js +4 -105
  47. package/dist/index.js.map +1 -0
  48. package/dist/lens-filter.contract.d.ts +72 -0
  49. package/dist/lens-filter.contract.js +71 -0
  50. package/dist/lens-filter.contract.js.map +1 -0
  51. package/dist/lens-workflow.contract.d.ts +87 -0
  52. package/dist/lens-workflow.contract.js +123 -0
  53. package/dist/lens-workflow.contract.js.map +1 -0
  54. package/dist/mcp-tools.contract-D8kXcP6d.d.ts +254 -0
  55. package/dist/mcp-tools.contract.d.ts +1 -0
  56. package/dist/mcp-tools.contract.js +2986 -0
  57. package/dist/mcp-tools.contract.js.map +1 -0
  58. package/dist/ontologies/v1.d.ts +2 -0
  59. package/dist/ontologies/v1.js +3 -0
  60. package/dist/ontologies/v1.js.map +1 -0
  61. package/dist/ontology-matching.contract.d.ts +1 -0
  62. package/dist/ontology-matching.contract.js +346 -0
  63. package/dist/ontology-matching.contract.js.map +1 -0
  64. package/dist/prompt.contract.d.ts +26 -0
  65. package/dist/prompt.contract.js +12 -0
  66. package/dist/prompt.contract.js.map +1 -0
  67. package/dist/questions/v1.d.ts +2 -0
  68. package/dist/questions/v1.js +3 -0
  69. package/dist/questions/v1.js.map +1 -0
  70. package/dist/sdk-methods.contract.d.ts +362 -0
  71. package/dist/sdk-methods.contract.js +3 -0
  72. package/dist/sdk-methods.contract.js.map +1 -0
  73. package/dist/sdk-tools.contract-BnV0hKLp.d.ts +150 -0
  74. package/dist/sdk-tools.contract.d.ts +2 -0
  75. package/dist/sdk-tools.contract.js +4222 -0
  76. package/dist/sdk-tools.contract.js.map +1 -0
  77. package/dist/text-matching.contract.d.ts +55 -0
  78. package/{src/text-matching.contract.ts → dist/text-matching.contract.js} +36 -137
  79. package/dist/text-matching.contract.js.map +1 -0
  80. package/dist/topic-scope.contract.d.ts +1 -0
  81. package/{src/v1/topics/v1.ts → dist/topic-scope.contract.js} +13 -38
  82. package/dist/topic-scope.contract.js.map +1 -0
  83. package/dist/topics/v1.d.ts +2 -0
  84. package/dist/topics/v1.js +3 -0
  85. package/dist/topics/v1.js.map +1 -0
  86. package/dist/v1/agents/v1.d.ts +2 -0
  87. package/dist/v1/agents/v1.js +3 -0
  88. package/dist/v1/agents/v1.js.map +1 -0
  89. package/dist/v1/beliefs/v1.d.ts +2 -0
  90. package/dist/v1/beliefs/v1.js +3 -0
  91. package/dist/v1/beliefs/v1.js.map +1 -0
  92. package/dist/v1/evidence/v1.d.ts +2 -0
  93. package/dist/v1/evidence/v1.js +3 -0
  94. package/dist/v1/evidence/v1.js.map +1 -0
  95. package/dist/v1/graph/v1.d.ts +2 -0
  96. package/dist/v1/graph/v1.js +3 -0
  97. package/dist/v1/graph/v1.js.map +1 -0
  98. package/dist/v1/ontologies/v1.d.ts +78 -0
  99. package/dist/v1/ontologies/v1.js +346 -0
  100. package/dist/v1/ontologies/v1.js.map +1 -0
  101. package/dist/v1/questions/v1.d.ts +2 -0
  102. package/dist/v1/questions/v1.js +3 -0
  103. package/dist/v1/questions/v1.js.map +1 -0
  104. package/dist/v1/topics/v1.d.ts +21 -0
  105. package/dist/v1/topics/v1.js +54 -0
  106. package/dist/v1/topics/v1.js.map +1 -0
  107. package/dist/v1/worktrees/v1.d.ts +2 -0
  108. package/dist/v1/worktrees/v1.js +3 -0
  109. package/dist/v1/worktrees/v1.js.map +1 -0
  110. package/dist/workflow-runtime.contract.d.ts +163 -0
  111. package/dist/workflow-runtime.contract.js +245 -0
  112. package/dist/workflow-runtime.contract.js.map +1 -0
  113. package/dist/worktrees/v1.d.ts +2 -0
  114. package/dist/worktrees/v1.js +3 -0
  115. package/dist/worktrees/v1.js.map +1 -0
  116. package/package.json +23 -7
  117. package/src/agents/v1.ts +0 -8
  118. package/src/api-enums.contract.ts +0 -183
  119. package/src/auth-context.contract.ts +0 -9
  120. package/src/auth-session.contract.ts +0 -9
  121. package/src/auth.contract.ts +0 -162
  122. package/src/beliefs/v1.ts +0 -8
  123. package/src/context-pack.contract.ts +0 -704
  124. package/src/convex-admin.contract.ts +0 -14
  125. package/src/events-types.contract.ts +0 -9
  126. package/src/events.contract.ts +0 -376
  127. package/src/evidence/v1.ts +0 -8
  128. package/src/gateway.contract.ts +0 -151
  129. package/src/graph/v1.ts +0 -8
  130. package/src/index.ts +0 -30
  131. package/src/lens-filter.contract.ts +0 -183
  132. package/src/lens-workflow.contract.ts +0 -162
  133. package/src/mcp-tools.contract.ts +0 -3636
  134. package/src/ontologies/v1.ts +0 -8
  135. package/src/ontology-matching.contract.ts +0 -9
  136. package/src/prompt.contract.ts +0 -50
  137. package/src/questions/v1.ts +0 -8
  138. package/src/sdk-methods.contract.ts +0 -522
  139. package/src/sdk-tools.contract.ts +0 -1545
  140. package/src/topic-scope.contract.ts +0 -9
  141. package/src/topics/v1.ts +0 -8
  142. package/src/v1/agents/v1.ts +0 -8
  143. package/src/v1/beliefs/v1.ts +0 -8
  144. package/src/v1/evidence/v1.ts +0 -8
  145. package/src/v1/graph/v1.ts +0 -8
  146. package/src/v1/ontologies/v1.ts +0 -276
  147. package/src/v1/questions/v1.ts +0 -8
  148. package/src/v1/worktrees/v1.ts +0 -8
  149. package/src/workflow-runtime.contract.ts +0 -440
  150. package/src/worktrees/v1.ts +0 -8
  151. package/tsconfig.json +0 -9
@@ -0,0 +1,496 @@
1
+ /**
2
+ * Context-Pack Contract v1
3
+ *
4
+ * Canonical TypeScript types and constants for the context-pack output schema.
5
+ * This is the external contract consumed by:
6
+ * - MCP tool `compile_context` (canonical compiler read)
7
+ * - SDK/HTTP consumers that read compiled context packs programmatically
8
+ * - Benchmark harnesses (context-pack-ab)
9
+ *
10
+ * BREAKING CHANGE RULES:
11
+ * - Adding optional fields to ContextPackV1 is NON-breaking
12
+ * - Removing fields or changing types is BREAKING (bump CONTEXT_PACK_SCHEMA_VERSION)
13
+ * - Changing section budget ratios or ranking weights is NON-breaking (tuning)
14
+ * - Changing the version string is BREAKING (consumers check it)
15
+ */
16
+ /** Canonical version string. Consumers MUST check this field for compatibility. */
17
+ declare const CONTEXT_PACK_SCHEMA_VERSION: "1.0.0";
18
+ /**
19
+ * Available ranking profiles for context-pack assembly.
20
+ *
21
+ * - `baseline_v1`: Simple token-hit counting. Items with zero query hits are excluded.
22
+ * - `weighted_v1`: Multi-signal scoring combining query relevance, recency, confidence,
23
+ * belief type, priority, and severity with section-specific weight vectors.
24
+ */
25
+ type ContextRankingProfile = "baseline_v1" | "weighted_v1";
26
+ declare const CONTEXT_RANKING_PROFILES: readonly ContextRankingProfile[];
27
+ declare const DEFAULT_RANKING_PROFILE: ContextRankingProfile;
28
+ /**
29
+ * Context compilation mode.
30
+ *
31
+ * - `standard`: Default — ranked beliefs, questions, evidence, contradictions.
32
+ * - `delta`: Diff-aware — adds failure context, verification obligations,
33
+ * and worktree ledger analysis to the standard context pack.
34
+ */
35
+ type ContextCompilationMode = "standard" | "delta";
36
+ declare const DEFAULT_COMPILATION_MODE: ContextCompilationMode;
37
+ /**
38
+ * The five canonical sections of a context pack.
39
+ * Order matters: invariants are injected first, contradictions last.
40
+ */
41
+ type ContextPackSectionKey = "invariants" | "activeBeliefs" | "openQuestions" | "recentEvidence" | "contradictions";
42
+ declare const CONTEXT_PACK_SECTION_KEYS: readonly ContextPackSectionKey[];
43
+ /**
44
+ * Token budget allocation ratios per section.
45
+ * These sum to 1.0 and determine how the total tokenBudget is divided.
46
+ *
47
+ * Rationale:
48
+ * - invariants (0.28): Highest-priority constraints, injected first
49
+ * - activeBeliefs (0.30): Largest section, carries domain knowledge
50
+ * - openQuestions (0.17): Unresolved work items guide agent behavior
51
+ * - recentEvidence (0.17): Implementation context for grounding
52
+ * - contradictions (0.08): Tension signals, smallest section
53
+ */
54
+ declare const SECTION_BUDGET_RATIOS: Readonly<Record<ContextPackSectionKey, number>>;
55
+ /** Minimum allowed token budget. Below this, context packs lose utility. */
56
+ declare const MIN_TOKEN_BUDGET = 400;
57
+ /** Maximum allowed token budget. Above this, context packs bloat prompts. */
58
+ declare const MAX_TOKEN_BUDGET = 8000;
59
+ /** Default token budget when caller does not specify. */
60
+ declare const DEFAULT_TOKEN_BUDGET = 1800;
61
+ /** Default max items per section. */
62
+ declare const DEFAULT_SECTION_LIMIT = 8;
63
+ /** Hard ceiling on items per section. */
64
+ declare const MAX_SECTION_LIMIT = 25;
65
+ /** Minimum contradiction section budget floor (tokens). */
66
+ declare const MIN_CONTRADICTION_BUDGET = 40;
67
+ /**
68
+ * Weight vectors for the weighted_v1 ranking profile.
69
+ * Each section has a different signal mix:
70
+ *
71
+ * - query: How many query tokens appear in the candidate text
72
+ * - recency: Exponential decay from updatedAt (half-life = 30 days)
73
+ * - confidence: Belief confidence score [0,1]
74
+ * - beliefType: Bonus for invariant > tenet > principle > other
75
+ * - priority: Question priority (critical > high > medium > low)
76
+ * - severity: Contradiction severity (critical > high > medium > low)
77
+ */
78
+ type RankingWeightVector = {
79
+ query: number;
80
+ recency: number;
81
+ confidence?: number;
82
+ beliefType?: number;
83
+ priority?: number;
84
+ severity?: number;
85
+ };
86
+ declare const RANKING_WEIGHTS: Readonly<Record<ContextPackSectionKey, RankingWeightVector>>;
87
+ /** Recency decay half-life in days. After 30 days, recency score = 0.5. */
88
+ declare const RECENCY_HALF_LIFE_DAYS = 30;
89
+ /**
90
+ * Ranking weight vector for the relatedEntities section.
91
+ * Entities are ranked by query relevance and connectivity (bridge edge count).
92
+ * Separate from RANKING_WEIGHTS because entities are not part of the
93
+ * token-budgeted injection plan.
94
+ */
95
+ declare const ENTITY_RANKING_WEIGHTS: {
96
+ readonly query: 0.4;
97
+ readonly connectivity: 0.6;
98
+ };
99
+ /** Default max entities to include in the context pack. */
100
+ declare const DEFAULT_ENTITY_LIMIT = 10;
101
+ /** Hard ceiling on entities per context pack. */
102
+ declare const MAX_ENTITY_LIMIT = 50;
103
+ /**
104
+ * Bonus multiplier for belief types in ranking.
105
+ * Invariants get 1.0, unknown types get 0.4.
106
+ */
107
+ declare const BELIEF_TYPE_BONUS: Readonly<Record<string, number>>;
108
+ declare const DEFAULT_BELIEF_TYPE_BONUS = 0.4;
109
+ declare const PRIORITY_SCORES: Readonly<Record<string, number>>;
110
+ declare const DEFAULT_PRIORITY_SCORE = 0.5;
111
+ declare const SEVERITY_SCORES: Readonly<Record<string, number>>;
112
+ declare const DEFAULT_SEVERITY_SCORE = 0.5;
113
+ /** A ranked belief in the invariants or activeBeliefs section. */
114
+ type ContextPackBelief = {
115
+ nodeId: string;
116
+ canonicalText: string;
117
+ confidence: number | null;
118
+ beliefType: string | null;
119
+ score: number;
120
+ /** Present in activeBeliefs, absent in invariants */
121
+ status?: string;
122
+ updatedAt?: number | null;
123
+ /** Human-readable explanation of why this item was ranked here (RS-2). */
124
+ justification?: string;
125
+ };
126
+ /** A ranked question in the openQuestions section. */
127
+ type ContextPackQuestion = {
128
+ questionId: string;
129
+ text: string;
130
+ status: string;
131
+ priority: string;
132
+ updatedAt?: number | null;
133
+ score: number;
134
+ /** Human-readable explanation of why this item was ranked here (RS-2). */
135
+ justification?: string;
136
+ };
137
+ /** A ranked evidence item in the recentEvidence section. */
138
+ type ContextPackEvidence = {
139
+ nodeId: string;
140
+ canonicalText: string;
141
+ sourceUrl: string | null;
142
+ kind: string;
143
+ createdAt: number | null;
144
+ score: number;
145
+ /** Human-readable explanation of why this item was ranked here (RS-2). */
146
+ justification?: string;
147
+ };
148
+ /** A ranked contradiction in the contradictions section. */
149
+ type ContextPackContradiction = {
150
+ contradictionId: string;
151
+ severity: string;
152
+ status: string;
153
+ description: string;
154
+ score: number;
155
+ /** Human-readable explanation of why this item was ranked here (RS-2). */
156
+ justification?: string;
157
+ };
158
+ /**
159
+ * An entity from the ontological layer surfaced in the context pack.
160
+ * Entities are domain objects (companies, people, functions, etc.) connected
161
+ * to beliefs via bridge edges. They provide the "reality anchor" that makes
162
+ * the reasoning graph domain-aware.
163
+ */
164
+ type ContextPackEntity = {
165
+ /** Convex document ID of the entity node. */
166
+ nodeId: string;
167
+ /** Entity type (e.g., "company", "person", "function"). */
168
+ entityType: string;
169
+ /** Human-readable title/name of the entity. */
170
+ title: string;
171
+ /** Number of beliefs connected to this entity via bridge edges. */
172
+ connectedBeliefCount: number;
173
+ /** Number of evidence items referencing this entity. */
174
+ connectedEvidenceCount: number;
175
+ /** Relevance score from ranking algorithm. */
176
+ score: number;
177
+ /** Entity metadata (structured per ontology schema). */
178
+ metadata?: Record<string, unknown>;
179
+ };
180
+ /**
181
+ * A lattice seed entry representing a belief that was auto-generated
182
+ * to cover an ontology entity type within a topic scope.
183
+ */
184
+ type BeliefLatticeSeed = {
185
+ /** The belief node ID that was created or already existed. */
186
+ beliefNodeId: string;
187
+ /** The entity type this seed belief covers. */
188
+ entityType: string;
189
+ /** Whether this seed was newly created or already existed. */
190
+ created: boolean;
191
+ /** The canonical text of the seed belief. */
192
+ canonicalText: string;
193
+ };
194
+ /** Counts and scoped health signals for the context pack. */
195
+ type ContextPackSummary = {
196
+ totalBeliefs: number;
197
+ invariants: number;
198
+ openQuestions: number;
199
+ evidenceItems: number;
200
+ contradictions: number;
201
+ /** Number of ontological entities in scope (optional, present when entity graph is active). */
202
+ relatedEntities?: number;
203
+ scopedTopics: number;
204
+ descendantDepth: number;
205
+ query: string | null;
206
+ };
207
+ /** A failed approach surfaced from the failure log for anti-repetition. */
208
+ type ContextPackFailure = {
209
+ /** Lucern attempt/evidence node ID. */
210
+ attemptId: string;
211
+ /** What was tried. */
212
+ approach: string;
213
+ /** Why it failed. */
214
+ outcome: string;
215
+ /** When the attempt was recorded (ms since epoch). */
216
+ recordedAt: number;
217
+ /** Relevance score from ranking algorithm. */
218
+ score: number;
219
+ };
220
+ /** Failure context section appended to context packs in delta mode. */
221
+ type ContextPackFailureContext = {
222
+ /** Ranked failed approaches relevant to the current query. */
223
+ failures: ContextPackFailure[];
224
+ /** IDs of items suppressed from other sections due to anti-repetition. */
225
+ suppressedIds: string[];
226
+ };
227
+ /** A verification obligation surfaced by delta compilation. */
228
+ type VerificationObligation = {
229
+ /** What must be verified. */
230
+ description: string;
231
+ /** Source of the obligation (e.g., "belief:xyz confidence drop"). */
232
+ source: string;
233
+ /** Severity: how important it is to verify. */
234
+ severity: "critical" | "high" | "medium" | "low";
235
+ };
236
+ /** Delta report appended to context packs when mode = "delta". */
237
+ type ContextPackDeltaReport = {
238
+ /** Items that changed since the reference point (new, updated, removed). */
239
+ changedItems: Array<{
240
+ id: string;
241
+ section: ContextPackSectionKey;
242
+ changeType: "added" | "updated" | "removed" | "confidence_changed";
243
+ summary: string;
244
+ }>;
245
+ /** Obligations the consuming session must verify. */
246
+ verificationObligations: VerificationObligation[];
247
+ /** Reference point for the delta (worktree ID, timestamp, or commit SHA). */
248
+ referencePoint: string;
249
+ };
250
+ /**
251
+ * Per-section weight overrides that domain packs can apply.
252
+ * Overrides merge with RANKING_WEIGHTS — only specified fields replace defaults.
253
+ */
254
+ type PackWeightOverride = {
255
+ /** Which section to override weights for. */
256
+ section: ContextPackSectionKey;
257
+ /** Partial weight vector — only specified fields replace defaults. */
258
+ weights: Partial<RankingWeightVector>;
259
+ };
260
+ /** Token-budgeted section selections for prompt injection. */
261
+ type ContextPackInjectionPolicy = {
262
+ /** Total token budget for the entire context pack. */
263
+ tokenBudget: number;
264
+ /** Estimated tokens consumed across all sections. */
265
+ estimatedTokens: number;
266
+ /** Per-section token budgets derived from SECTION_BUDGET_RATIOS. */
267
+ sectionBudgets: Record<ContextPackSectionKey, number>;
268
+ /** Actual token usage per section after greedy fill. */
269
+ sectionUsage: Record<ContextPackSectionKey, number>;
270
+ /** Node/question IDs selected for injection, per section. */
271
+ selected: Record<ContextPackSectionKey, string[]>;
272
+ /** Items that were scored but excluded from injection, with reason (RS-2). */
273
+ excludedItems?: Array<{
274
+ id: string;
275
+ section: ContextPackSectionKey;
276
+ reason: "budget_exceeded" | "anti_repetition" | "below_threshold";
277
+ score: number;
278
+ }>;
279
+ };
280
+ /** Telemetry for context pack assembly. */
281
+ type ContextPackDiagnostics = {
282
+ /** Total candidates scored across all sections. */
283
+ itemsScored: number;
284
+ /** Ratio of estimatedTokens / tokenBudget. Range [0, 1+]. */
285
+ tokenBudgetUtilization: number;
286
+ };
287
+ /**
288
+ * Public context surface returned by the SDK-facing context client.
289
+ *
290
+ * This preserves the existing external shape while the canonical compiler
291
+ * contract evolves in parallel as ContextPackV1.
292
+ */
293
+ type PublicContextBelief = {
294
+ beliefId: string;
295
+ text: string;
296
+ confidence: number | null;
297
+ beliefType?: string | null;
298
+ status?: string;
299
+ updatedAt?: number | null;
300
+ score: number;
301
+ justification?: string;
302
+ };
303
+ type PublicContextQuestion = {
304
+ questionId: string;
305
+ text: string;
306
+ status: string;
307
+ priority: string;
308
+ updatedAt?: number | null;
309
+ score: number;
310
+ justification?: string;
311
+ };
312
+ type PublicContextEvidence = {
313
+ evidenceId: string;
314
+ text: string;
315
+ sourceUrl?: string | null;
316
+ kind: string;
317
+ createdAt?: number | null;
318
+ score: number;
319
+ justification?: string;
320
+ };
321
+ type PublicContextContradiction = {
322
+ contradictionId: string;
323
+ severity: string;
324
+ status: string;
325
+ description: string;
326
+ score: number;
327
+ justification?: string;
328
+ };
329
+ type PublicContextEntity = {
330
+ entityId: string;
331
+ entityType: string;
332
+ title: string;
333
+ text?: string;
334
+ connectedBeliefCount: number;
335
+ connectedEvidenceCount: number;
336
+ score: number;
337
+ metadata?: Record<string, unknown>;
338
+ };
339
+ type PublicContextInjectionPolicy = {
340
+ tokenBudget: number;
341
+ estimatedTokens: number;
342
+ sectionBudgets: Record<string, number>;
343
+ sectionUsage: Record<string, number>;
344
+ selected: Record<string, string[]>;
345
+ excludedItems?: Array<{
346
+ id: string;
347
+ section: string;
348
+ reason: "budget_exceeded" | "anti_repetition" | "below_threshold";
349
+ score: number;
350
+ }>;
351
+ };
352
+ type PublicCompiledContext = {
353
+ schemaVersion: string;
354
+ topicId: string;
355
+ topicName: string;
356
+ scopedTopicIds: string[];
357
+ generatedAt: number;
358
+ ranking: ContextRankingProfile;
359
+ summary: Record<string, unknown>;
360
+ invariants: PublicContextBelief[];
361
+ activeBeliefs: PublicContextBelief[];
362
+ openQuestions: PublicContextQuestion[];
363
+ recentEvidence: PublicContextEvidence[];
364
+ contradictions: PublicContextContradiction[];
365
+ relatedEntities?: PublicContextEntity[];
366
+ contextNarrative: string[];
367
+ injectionPolicy: PublicContextInjectionPolicy;
368
+ diagnostics: Record<string, unknown>;
369
+ compilationMode?: string;
370
+ failureContext?: {
371
+ failures: Array<{
372
+ attemptId: string;
373
+ approach: string;
374
+ outcome: string;
375
+ recordedAt: number;
376
+ score: number;
377
+ }>;
378
+ suppressedIds: string[];
379
+ };
380
+ deltaReport?: {
381
+ changedItems: Array<{
382
+ id: string;
383
+ section: string;
384
+ changeType: string;
385
+ summary: string;
386
+ }>;
387
+ verificationObligations: Array<{
388
+ description: string;
389
+ source: string;
390
+ severity: "critical" | "high" | "medium" | "low";
391
+ }>;
392
+ referencePoint: string;
393
+ };
394
+ appliedWeightOverrides?: unknown[];
395
+ };
396
+ /**
397
+ * The canonical output schema for context compilation responses.
398
+ *
399
+ * This is the contract that consumers depend on. All fields are required
400
+ * in the output. Adding optional fields is non-breaking; removing or
401
+ * changing types is breaking (requires version bump).
402
+ */
403
+ type ContextPackV1 = {
404
+ /** Schema version for compatibility checking. */
405
+ schemaVersion: typeof CONTEXT_PACK_SCHEMA_VERSION;
406
+ /** Deprecated compatibility alias for the requested scope ID. */
407
+ projectId?: string;
408
+ /** Resolved topic ID after scope resolution. */
409
+ topicId: string;
410
+ /** Human-readable topic name. */
411
+ topicName: string;
412
+ /** All topic IDs included in the neighborhood expansion. */
413
+ scopedTopicIds: string[];
414
+ /** Deterministic freshness watermark for this pack (ms since epoch). */
415
+ generatedAt: number;
416
+ /** Which ranking profile was used. */
417
+ rankingProfile: ContextRankingProfile;
418
+ /** Aggregate counts and health signals. */
419
+ summary: ContextPackSummary;
420
+ /** High-confidence invariant beliefs (beliefType = "invariant"). */
421
+ invariants: ContextPackBelief[];
422
+ /** Active beliefs ranked by query relevance. */
423
+ activeBeliefs: ContextPackBelief[];
424
+ /** Open questions ranked by relevance and priority. */
425
+ openQuestions: ContextPackQuestion[];
426
+ /** Recent evidence ranked by relevance and recency. */
427
+ recentEvidence: ContextPackEvidence[];
428
+ /** Active contradictions ranked by severity. */
429
+ contradictions: ContextPackContradiction[];
430
+ /**
431
+ * Ontological entities connected to beliefs in scope, ranked by connectivity.
432
+ * Optional — present when entity graph substrate is active for this topic.
433
+ * NON-BREAKING addition per contract rules.
434
+ */
435
+ relatedEntities?: ContextPackEntity[];
436
+ /** Concise instructions for agent context injection. */
437
+ contextNarrative: string[];
438
+ /** Token-budgeted injection selections. */
439
+ injectionPolicy: ContextPackInjectionPolicy;
440
+ /** Assembly telemetry. */
441
+ diagnostics: ContextPackDiagnostics;
442
+ /** Compilation mode used to generate this pack (RS-2). Default: "standard". */
443
+ compilationMode?: ContextCompilationMode;
444
+ /** Failure context for anti-repetition (RS-2). Present when failures are relevant. */
445
+ failureContext?: ContextPackFailureContext;
446
+ /** Delta report (RS-2). Present only when compilationMode = "delta". */
447
+ deltaReport?: ContextPackDeltaReport;
448
+ /** Pack weight overrides applied during ranking (RS-2). */
449
+ appliedWeightOverrides?: PackWeightOverride[];
450
+ };
451
+ /**
452
+ * The canonical input schema for `compile_context`.
453
+ * `topicId` is canonical. `projectId` remains an optional compatibility alias.
454
+ */
455
+ type ContextPackRequestV1 = {
456
+ /** Topic scope ID (required). */
457
+ topicId: string;
458
+ /** Deprecated compatibility alias for older callers. */
459
+ projectId?: string;
460
+ /** Focus query for relevance ranking. */
461
+ query?: string;
462
+ /** Max items per section. Default: DEFAULT_SECTION_LIMIT. */
463
+ limit?: number;
464
+ /** Ranking profile. Default: DEFAULT_RANKING_PROFILE. */
465
+ rankingProfile?: ContextRankingProfile;
466
+ /** Total token budget. Default: DEFAULT_TOKEN_BUDGET. */
467
+ tokenBudget?: number;
468
+ /** Descendant topic depth for neighborhood expansion. */
469
+ maxDepth?: number;
470
+ /** Include ontological entities connected to beliefs in scope. Default: true. */
471
+ includeEntities?: boolean;
472
+ /** Compilation mode (RS-2). Default: "standard". */
473
+ mode?: ContextCompilationMode;
474
+ /** Include failure log context for anti-repetition (RS-2). Default: false. */
475
+ includeFailures?: boolean;
476
+ /** Active worktree ID for delta mode reference point (RS-2). */
477
+ worktreeId?: string;
478
+ /** Session ID for anti-repetition dedup (RS-2). */
479
+ sessionId?: string;
480
+ /** Pack weight overrides from domain pack binding (RS-2). */
481
+ packWeightOverrides?: PackWeightOverride[];
482
+ };
483
+ /**
484
+ * Question statuses that are considered "resolved" (not open).
485
+ * Used to filter which questions appear in the openQuestions section.
486
+ */
487
+ declare const RESOLVED_QUESTION_STATUSES: readonly string[];
488
+ /**
489
+ * Tokens-per-word multiplier for rough token estimation.
490
+ * Conservative estimate: ~1.35 tokens per whitespace-delimited word.
491
+ */
492
+ declare const TOKENS_PER_WORD = 1.35;
493
+ /** Minimum token estimate for any non-empty string. */
494
+ declare const MIN_TOKEN_ESTIMATE = 8;
495
+
496
+ 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 };
@@ -0,0 +1,98 @@
1
+ // src/context-pack.contract.ts
2
+ var CONTEXT_PACK_SCHEMA_VERSION = "1.0.0";
3
+ var CONTEXT_RANKING_PROFILES = [
4
+ "baseline_v1",
5
+ "weighted_v1"
6
+ ];
7
+ var DEFAULT_RANKING_PROFILE = "weighted_v1";
8
+ var DEFAULT_COMPILATION_MODE = "standard";
9
+ var CONTEXT_PACK_SECTION_KEYS = [
10
+ "invariants",
11
+ "activeBeliefs",
12
+ "openQuestions",
13
+ "recentEvidence",
14
+ "contradictions"
15
+ ];
16
+ var SECTION_BUDGET_RATIOS = {
17
+ invariants: 0.28,
18
+ activeBeliefs: 0.3,
19
+ openQuestions: 0.17,
20
+ recentEvidence: 0.17,
21
+ contradictions: 0.08
22
+ };
23
+ var MIN_TOKEN_BUDGET = 400;
24
+ var MAX_TOKEN_BUDGET = 8e3;
25
+ var DEFAULT_TOKEN_BUDGET = 1800;
26
+ var DEFAULT_SECTION_LIMIT = 8;
27
+ var MAX_SECTION_LIMIT = 25;
28
+ var MIN_CONTRADICTION_BUDGET = 40;
29
+ var RANKING_WEIGHTS = {
30
+ invariants: {
31
+ query: 0.35,
32
+ recency: 0.1,
33
+ confidence: 0.4,
34
+ beliefType: 0.15
35
+ },
36
+ activeBeliefs: {
37
+ query: 0.5,
38
+ recency: 0.2,
39
+ confidence: 0.2,
40
+ beliefType: 0.1
41
+ },
42
+ openQuestions: {
43
+ query: 0.55,
44
+ recency: 0.2,
45
+ priority: 0.25
46
+ },
47
+ recentEvidence: {
48
+ query: 0.6,
49
+ recency: 0.4
50
+ },
51
+ contradictions: {
52
+ query: 0.4,
53
+ recency: 0.2,
54
+ severity: 0.4
55
+ }
56
+ };
57
+ var RECENCY_HALF_LIFE_DAYS = 30;
58
+ var ENTITY_RANKING_WEIGHTS = {
59
+ query: 0.4,
60
+ connectivity: 0.6
61
+ };
62
+ var DEFAULT_ENTITY_LIMIT = 10;
63
+ var MAX_ENTITY_LIMIT = 50;
64
+ var BELIEF_TYPE_BONUS = {
65
+ invariant: 1,
66
+ tenet: 0.8,
67
+ principle: 0.6
68
+ };
69
+ var DEFAULT_BELIEF_TYPE_BONUS = 0.4;
70
+ var PRIORITY_SCORES = {
71
+ critical: 1,
72
+ high: 0.85,
73
+ medium: 0.55,
74
+ low: 0.35
75
+ };
76
+ var DEFAULT_PRIORITY_SCORE = 0.5;
77
+ var SEVERITY_SCORES = {
78
+ critical: 1,
79
+ high: 0.85,
80
+ medium: 0.6,
81
+ low: 0.35
82
+ };
83
+ var DEFAULT_SEVERITY_SCORE = 0.5;
84
+ var RESOLVED_QUESTION_STATUSES = [
85
+ "answered",
86
+ "archived",
87
+ "closed",
88
+ "resolved",
89
+ "resolved_support",
90
+ "resolved_contra",
91
+ "belief_forked"
92
+ ];
93
+ var TOKENS_PER_WORD = 1.35;
94
+ var MIN_TOKEN_ESTIMATE = 8;
95
+
96
+ export { BELIEF_TYPE_BONUS, CONTEXT_PACK_SCHEMA_VERSION, CONTEXT_PACK_SECTION_KEYS, CONTEXT_RANKING_PROFILES, 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, RANKING_WEIGHTS, RECENCY_HALF_LIFE_DAYS, RESOLVED_QUESTION_STATUSES, SECTION_BUDGET_RATIOS, SEVERITY_SCORES, TOKENS_PER_WORD };
97
+ //# sourceMappingURL=context-pack.contract.js.map
98
+ //# sourceMappingURL=context-pack.contract.js.map
@@ -0,0 +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;AA2b/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 canonical. `projectId` remains an optional compatibility alias.\n */\nexport type ContextPackRequestV1 = {\n /** Topic scope ID (required). */\n topicId: string;\n /** Deprecated compatibility alias for older callers. */\n projectId?: string;\n /** Focus query for relevance ranking. */\n query?: 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"]}
@@ -0,0 +1,7 @@
1
+ interface ConvexAdminClient {
2
+ query<T = unknown>(functionReference: unknown, args: Record<string, unknown>): Promise<T>;
3
+ mutation<T = unknown>(functionReference: unknown, args: Record<string, unknown>): Promise<T>;
4
+ action<T = unknown>(functionReference: unknown, args: Record<string, unknown>): Promise<T>;
5
+ }
6
+
7
+ export type { ConvexAdminClient };
@@ -0,0 +1,3 @@
1
+
2
+ //# sourceMappingURL=convex-admin.contract.js.map
3
+ //# sourceMappingURL=convex-admin.contract.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"convex-admin.contract.js"}
@@ -0,0 +1 @@
1
+ export { CreateDomainEventInput, DOMAIN_EVENT_TYPES, DOMAIN_EVENT_VERSION, DomainActorType, DomainEvent, DomainEventData, DomainEventType, DomainResourceType, EVENT_RETENTION_DEFAULT_DAYS, EventCursor, EventListQuery, EventListResult, ReplayEventsInput, ReplayEventsResult, WEBHOOK_MAX_ATTEMPTS, WEBHOOK_RETRY_DELAYS_MS, WebhookCreateInput, WebhookDeliveriesResult, WebhookDeliveryAttemptRecord, WebhookDeliveryRecord, WebhookDeliveryStatus, WebhookHealthResult, WebhookRecord, WebhookSecretMode, WebhookTestResult, WebhookUpdateInput, buildDomainEvent, compareEventCursor, createEventId, decodeEventCursor, emitDomainEvent, encodeEventCursor, inferActorType, isAfterCursor, normalizeRetentionDays, sortEventsByCursor } from './events.contract.js';