@lucern/sdk 0.2.0-alpha.5 → 0.2.0-alpha.7

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 (166) hide show
  1. package/.turbo/turbo-build.log +7 -0
  2. package/.turbo/turbo-typecheck.log +4 -0
  3. package/CHANGELOG.md +13 -0
  4. package/examples/README.md +69 -0
  5. package/examples/contradiction.ts +94 -0
  6. package/examples/investigation-context.ts +118 -0
  7. package/examples/questions-and-tasks.ts +55 -0
  8. package/examples/quickstart.ts +97 -0
  9. package/examples/shared.ts +318 -0
  10. package/examples/strict-public-types.ts +143 -0
  11. package/examples/worktree-lifecycle.ts +79 -0
  12. package/package.json +16 -59
  13. package/src/README.md +6 -0
  14. package/src/adminClient.ts +789 -0
  15. package/{dist/lib/platform/sdk/answersClient.d.ts → src/answersClient.ts} +17 -4
  16. package/src/audiencesClient.ts +209 -0
  17. package/src/auditClient.ts +50 -0
  18. package/src/beliefsClient.ts +319 -0
  19. package/src/client.ts +2647 -0
  20. package/src/contextClient.ts +130 -0
  21. package/src/contextFacade.ts +15 -0
  22. package/src/contextPackCompiler.ts +828 -0
  23. package/src/contextPackSchema.ts +251 -0
  24. package/src/contextTypes.ts +153 -0
  25. package/src/contracts/api-enums.contract.ts +202 -0
  26. package/src/contracts/auth-session.contract.ts +109 -0
  27. package/src/contracts/context-pack.contract.ts +700 -0
  28. package/src/contracts/contextPack.ts +1 -0
  29. package/src/contracts/index.ts +10 -0
  30. package/src/contracts/lens-filter.contract.ts +183 -0
  31. package/src/contracts/lens-workflow.contract.ts +162 -0
  32. package/src/contracts/lensFilter.ts +1 -0
  33. package/src/contracts/lensWorkflow.ts +1 -0
  34. package/src/contracts/mcp-tools.contract.ts +3636 -0
  35. package/src/contracts/mcpTools.ts +1 -0
  36. package/src/contracts/prompt.contract.ts +50 -0
  37. package/src/contracts/prompt.ts +1 -0
  38. package/src/contracts/sdk-tools.contract.ts +1457 -0
  39. package/src/contracts/sdkTools.ts +1 -0
  40. package/src/contracts/workflow-runtime.contract.ts +440 -0
  41. package/src/contracts/workflowRuntime.ts +1 -0
  42. package/src/controlObjectOwnership.ts +286 -0
  43. package/src/coreClient.ts +570 -0
  44. package/src/customTools.ts +398 -0
  45. package/src/decisionsClient.ts +286 -0
  46. package/src/domainContext.ts +15 -0
  47. package/src/events.ts +531 -0
  48. package/src/eventsCore.ts +168 -0
  49. package/src/facade/beliefs.ts +83 -0
  50. package/src/facade/context.ts +110 -0
  51. package/src/facade/contradictions.ts +29 -0
  52. package/src/facade/edges.ts +30 -0
  53. package/src/facade/events.ts +23 -0
  54. package/src/facade/evidence.ts +41 -0
  55. package/src/facade/graph.ts +38 -0
  56. package/src/facade/identity.ts +16 -0
  57. package/src/facade/ontologies.ts +34 -0
  58. package/src/facade/questions.ts +59 -0
  59. package/src/facade/search.ts +16 -0
  60. package/src/facade/tasks.ts +37 -0
  61. package/src/facade/topics.ts +42 -0
  62. package/src/facade/webhooks.ts +58 -0
  63. package/src/facade/worktrees.ts +51 -0
  64. package/src/gatewayFacades.ts +1666 -0
  65. package/src/graphClient.ts +529 -0
  66. package/src/harnessClient.ts +585 -0
  67. package/src/identityClient.ts +278 -0
  68. package/{dist/lib/platform/sdk/index.d.ts → src/index.ts} +3 -0
  69. package/src/learningClient.ts +95 -0
  70. package/src/mcpParityClient.ts +240 -0
  71. package/src/mcpParitySurface.ts +70 -0
  72. package/src/ontologyClient.ts +275 -0
  73. package/src/packRuntime.ts +3 -0
  74. package/src/packsClient.ts +260 -0
  75. package/src/policyClient.ts +572 -0
  76. package/src/promptCatalog.ts +1 -0
  77. package/src/realtime/index.ts +51 -0
  78. package/src/realtime/refs.ts +17 -0
  79. package/src/reportsClient.ts +99 -0
  80. package/src/schemaClient.ts +129 -0
  81. package/src/sdkSurface.ts +190 -0
  82. package/src/topicsClient.ts +243 -0
  83. package/src/types.ts +807 -0
  84. package/src/workflowClient.ts +826 -0
  85. package/tsconfig.json +9 -0
  86. package/dist/.generated +0 -2
  87. package/dist/index.d.ts +0 -3
  88. package/dist/index.js +0 -3
  89. package/dist/lib/platform/auth/credentials.d.ts +0 -5
  90. package/dist/lib/platform/auth/credentials.js +0 -40
  91. package/dist/lib/platform/sdk/adminClient.d.ts +0 -404
  92. package/dist/lib/platform/sdk/adminClient.js +0 -384
  93. package/dist/lib/platform/sdk/answersClient.js +0 -21
  94. package/dist/lib/platform/sdk/audiencesClient.d.ts +0 -93
  95. package/dist/lib/platform/sdk/audiencesClient.js +0 -111
  96. package/dist/lib/platform/sdk/auditClient.d.ts +0 -24
  97. package/dist/lib/platform/sdk/auditClient.js +0 -21
  98. package/dist/lib/platform/sdk/beliefsClient.d.ts +0 -157
  99. package/dist/lib/platform/sdk/beliefsClient.js +0 -124
  100. package/dist/lib/platform/sdk/client.d.ts +0 -2369
  101. package/dist/lib/platform/sdk/client.js +0 -1831
  102. package/dist/lib/platform/sdk/contextClient.d.ts +0 -21
  103. package/dist/lib/platform/sdk/contextClient.js +0 -86
  104. package/dist/lib/platform/sdk/contextPackCompiler.d.ts +0 -100
  105. package/dist/lib/platform/sdk/contextPackCompiler.js +0 -534
  106. package/dist/lib/platform/sdk/contextTypes.d.ts +0 -133
  107. package/dist/lib/platform/sdk/contextTypes.js +0 -1
  108. package/dist/lib/platform/sdk/controlObjectOwnership.d.ts +0 -308
  109. package/dist/lib/platform/sdk/controlObjectOwnership.js +0 -220
  110. package/dist/lib/platform/sdk/coreClient.d.ts +0 -139
  111. package/dist/lib/platform/sdk/coreClient.js +0 -366
  112. package/dist/lib/platform/sdk/customTools.d.ts +0 -83
  113. package/dist/lib/platform/sdk/customTools.js +0 -247
  114. package/dist/lib/platform/sdk/decisionsClient.d.ts +0 -106
  115. package/dist/lib/platform/sdk/decisionsClient.js +0 -129
  116. package/dist/lib/platform/sdk/domainContext.d.ts +0 -1
  117. package/dist/lib/platform/sdk/domainContext.js +0 -1
  118. package/dist/lib/platform/sdk/events.d.ts +0 -176
  119. package/dist/lib/platform/sdk/events.js +0 -261
  120. package/dist/lib/platform/sdk/gatewayFacades.d.ts +0 -586
  121. package/dist/lib/platform/sdk/gatewayFacades.js +0 -845
  122. package/dist/lib/platform/sdk/graphClient.d.ts +0 -266
  123. package/dist/lib/platform/sdk/graphClient.js +0 -235
  124. package/dist/lib/platform/sdk/harnessClient.d.ts +0 -309
  125. package/dist/lib/platform/sdk/harnessClient.js +0 -219
  126. package/dist/lib/platform/sdk/identityClient.d.ts +0 -134
  127. package/dist/lib/platform/sdk/identityClient.js +0 -131
  128. package/dist/lib/platform/sdk/index.js +0 -46
  129. package/dist/lib/platform/sdk/learningClient.d.ts +0 -40
  130. package/dist/lib/platform/sdk/learningClient.js +0 -53
  131. package/dist/lib/platform/sdk/mcpParityClient.d.ts +0 -69
  132. package/dist/lib/platform/sdk/mcpParityClient.js +0 -196
  133. package/dist/lib/platform/sdk/mcpParitySurface.d.ts +0 -10
  134. package/dist/lib/platform/sdk/mcpParitySurface.js +0 -57
  135. package/dist/lib/platform/sdk/ontologyClient.d.ts +0 -131
  136. package/dist/lib/platform/sdk/ontologyClient.js +0 -161
  137. package/dist/lib/platform/sdk/packRuntime.d.ts +0 -1
  138. package/dist/lib/platform/sdk/packRuntime.js +0 -1
  139. package/dist/lib/platform/sdk/packsClient.d.ts +0 -126
  140. package/dist/lib/platform/sdk/packsClient.js +0 -157
  141. package/dist/lib/platform/sdk/policyClient.d.ts +0 -293
  142. package/dist/lib/platform/sdk/policyClient.js +0 -277
  143. package/dist/lib/platform/sdk/promptCatalog.d.ts +0 -1
  144. package/dist/lib/platform/sdk/promptCatalog.js +0 -1
  145. package/dist/lib/platform/sdk/reportsClient.d.ts +0 -34
  146. package/dist/lib/platform/sdk/reportsClient.js +0 -64
  147. package/dist/lib/platform/sdk/schemaClient.d.ts +0 -59
  148. package/dist/lib/platform/sdk/schemaClient.js +0 -71
  149. package/dist/lib/platform/sdk/sdkSurface.d.ts +0 -56
  150. package/dist/lib/platform/sdk/sdkSurface.js +0 -140
  151. package/dist/lib/platform/sdk/topicsClient.d.ts +0 -78
  152. package/dist/lib/platform/sdk/topicsClient.js +0 -118
  153. package/dist/lib/platform/sdk/types.d.ts +0 -692
  154. package/dist/lib/platform/sdk/types.js +0 -1
  155. package/dist/lib/platform/sdk/version.d.ts +0 -2
  156. package/dist/lib/platform/sdk/workflowClient.d.ts +0 -313
  157. package/dist/lib/platform/sdk/workflowClient.js +0 -366
  158. package/dist/lucern/contracts/src/api-enums.contract.d.ts +0 -58
  159. package/dist/lucern/contracts/src/api-enums.contract.js +0 -147
  160. package/dist/lucern/contracts/src/lens-filter.contract.d.ts +0 -70
  161. package/dist/lucern/contracts/src/lens-filter.contract.js +0 -95
  162. package/dist/lucern/contracts/src/lens-workflow.contract.d.ts +0 -84
  163. package/dist/lucern/contracts/src/lens-workflow.contract.js +0 -54
  164. package/dist/lucern/contracts/src/mcp-tools.contract.d.ts +0 -151
  165. package/dist/lucern/contracts/src/mcp-tools.contract.js +0 -3281
  166. /package/{dist/lib/platform/sdk/version.js → src/version.ts} +0 -0
@@ -0,0 +1,251 @@
1
+ const CONTEXT_PACK_SCHEMA_VERSION = "1.0.0" as const;
2
+
3
+ type ValidationResult = {
4
+ valid: boolean;
5
+ errors: string[];
6
+ };
7
+
8
+ function isObject(value: unknown): value is Record<string, unknown> {
9
+ return typeof value === "object" && value !== null && !Array.isArray(value);
10
+ }
11
+
12
+ function isString(value: unknown): value is string {
13
+ return typeof value === "string";
14
+ }
15
+
16
+ function isNumber(value: unknown): value is number {
17
+ return typeof value === "number" && Number.isFinite(value);
18
+ }
19
+
20
+ function isNullableNumber(value: unknown): boolean {
21
+ return value === null || isNumber(value);
22
+ }
23
+
24
+ function isStringArray(value: unknown): value is string[] {
25
+ return Array.isArray(value) && value.every((entry) => isString(entry));
26
+ }
27
+
28
+ function requireObject(
29
+ parent: Record<string, unknown>,
30
+ key: string,
31
+ errors: string[]
32
+ ): Record<string, unknown> | null {
33
+ const value = parent[key];
34
+ if (!isObject(value)) {
35
+ errors.push(`Expected '${key}' to be an object`);
36
+ return null;
37
+ }
38
+ return value;
39
+ }
40
+
41
+ function validateBeliefArray(
42
+ key: string,
43
+ value: unknown,
44
+ errors: string[]
45
+ ): void {
46
+ if (!Array.isArray(value)) {
47
+ errors.push(`Expected '${key}' to be an array`);
48
+ return;
49
+ }
50
+ for (let index = 0; index < value.length; index += 1) {
51
+ const row = value[index];
52
+ if (!isObject(row)) {
53
+ errors.push(`Expected '${key}[${index}]' to be an object`);
54
+ continue;
55
+ }
56
+ if (!isString(row.nodeId)) {
57
+ errors.push(`Expected '${key}[${index}].nodeId' to be a string`);
58
+ }
59
+ if (!isString(row.canonicalText)) {
60
+ errors.push(`Expected '${key}[${index}].canonicalText' to be a string`);
61
+ }
62
+ if (!isNullableNumber(row.confidence)) {
63
+ errors.push(`Expected '${key}[${index}].confidence' to be number|null`);
64
+ }
65
+ }
66
+ }
67
+
68
+ function validateQuestionArray(
69
+ key: string,
70
+ value: unknown,
71
+ errors: string[]
72
+ ): void {
73
+ if (!Array.isArray(value)) {
74
+ errors.push(`Expected '${key}' to be an array`);
75
+ return;
76
+ }
77
+ for (let index = 0; index < value.length; index += 1) {
78
+ const row = value[index];
79
+ if (!isObject(row)) {
80
+ errors.push(`Expected '${key}[${index}]' to be an object`);
81
+ continue;
82
+ }
83
+ if (!isString(row.questionId)) {
84
+ errors.push(`Expected '${key}[${index}].questionId' to be a string`);
85
+ }
86
+ if (!isString(row.text)) {
87
+ errors.push(`Expected '${key}[${index}].text' to be a string`);
88
+ }
89
+ if (!isString(row.status)) {
90
+ errors.push(`Expected '${key}[${index}].status' to be a string`);
91
+ }
92
+ }
93
+ }
94
+
95
+ function validateEvidenceArray(
96
+ key: string,
97
+ value: unknown,
98
+ errors: string[]
99
+ ): void {
100
+ if (!Array.isArray(value)) {
101
+ errors.push(`Expected '${key}' to be an array`);
102
+ return;
103
+ }
104
+ for (let index = 0; index < value.length; index += 1) {
105
+ const row = value[index];
106
+ if (!isObject(row)) {
107
+ errors.push(`Expected '${key}[${index}]' to be an object`);
108
+ continue;
109
+ }
110
+ if (!isString(row.nodeId)) {
111
+ errors.push(`Expected '${key}[${index}].nodeId' to be a string`);
112
+ }
113
+ if (!isString(row.canonicalText)) {
114
+ errors.push(`Expected '${key}[${index}].canonicalText' to be a string`);
115
+ }
116
+ }
117
+ }
118
+
119
+ function validateEntityArray(
120
+ key: string,
121
+ value: unknown,
122
+ errors: string[]
123
+ ): void {
124
+ if (!Array.isArray(value)) {
125
+ errors.push(`Expected '${key}' to be an array`);
126
+ return;
127
+ }
128
+ for (let index = 0; index < value.length; index += 1) {
129
+ const row = value[index];
130
+ if (!isObject(row)) {
131
+ errors.push(`Expected '${key}[${index}]' to be an object`);
132
+ continue;
133
+ }
134
+ if (!isString(row.nodeId)) {
135
+ errors.push(`Expected '${key}[${index}].nodeId' to be a string`);
136
+ }
137
+ if (!isString(row.entityType)) {
138
+ errors.push(`Expected '${key}[${index}].entityType' to be a string`);
139
+ }
140
+ if (!isString(row.title)) {
141
+ errors.push(`Expected '${key}[${index}].title' to be a string`);
142
+ }
143
+ if (!isNumber(row.connectedBeliefCount)) {
144
+ errors.push(`Expected '${key}[${index}].connectedBeliefCount' to be a number`);
145
+ }
146
+ if (!isNumber(row.connectedEvidenceCount)) {
147
+ errors.push(`Expected '${key}[${index}].connectedEvidenceCount' to be a number`);
148
+ }
149
+ if (!isNumber(row.score)) {
150
+ errors.push(`Expected '${key}[${index}].score' to be a number`);
151
+ }
152
+ }
153
+ }
154
+
155
+ function validateContradictionArray(
156
+ key: string,
157
+ value: unknown,
158
+ errors: string[]
159
+ ): void {
160
+ if (!Array.isArray(value)) {
161
+ errors.push(`Expected '${key}' to be an array`);
162
+ return;
163
+ }
164
+ for (let index = 0; index < value.length; index += 1) {
165
+ const row = value[index];
166
+ if (!isObject(row)) {
167
+ errors.push(`Expected '${key}[${index}]' to be an object`);
168
+ continue;
169
+ }
170
+ if (!isString(row.contradictionId)) {
171
+ errors.push(`Expected '${key}[${index}].contradictionId' to be a string`);
172
+ }
173
+ if (!isString(row.status)) {
174
+ errors.push(`Expected '${key}[${index}].status' to be a string`);
175
+ }
176
+ }
177
+ }
178
+
179
+ export function validateContextPackSchema(payload: unknown): ValidationResult {
180
+ const errors: string[] = [];
181
+
182
+ if (!isObject(payload)) {
183
+ return {
184
+ valid: false,
185
+ errors: ["Expected context pack payload to be an object"],
186
+ };
187
+ }
188
+
189
+ if (payload.schemaVersion !== CONTEXT_PACK_SCHEMA_VERSION) {
190
+ errors.push(
191
+ `Expected schemaVersion='${CONTEXT_PACK_SCHEMA_VERSION}', received '${String(
192
+ payload.schemaVersion
193
+ )}'`
194
+ );
195
+ }
196
+
197
+ if (!isString(payload.topicId)) {
198
+ errors.push("Expected 'topicId' to be a string");
199
+ }
200
+ if (!isString(payload.topicName)) {
201
+ errors.push("Expected 'topicName' to be a string");
202
+ }
203
+ if (!isStringArray(payload.scopedTopicIds)) {
204
+ errors.push("Expected 'scopedTopicIds' to be string[]");
205
+ }
206
+ if (!isNumber(payload.generatedAt)) {
207
+ errors.push("Expected 'generatedAt' to be a number");
208
+ }
209
+ if (!isString(payload.ranking)) {
210
+ errors.push("Expected 'ranking' to be a string");
211
+ }
212
+
213
+ validateBeliefArray("invariants", payload.invariants, errors);
214
+ validateBeliefArray("activeBeliefs", payload.activeBeliefs, errors);
215
+ validateQuestionArray("openQuestions", payload.openQuestions, errors);
216
+ validateEvidenceArray("recentEvidence", payload.recentEvidence, errors);
217
+ validateContradictionArray("contradictions", payload.contradictions, errors);
218
+
219
+ if (
220
+ payload.relatedEntities !== undefined &&
221
+ payload.relatedEntities !== null
222
+ ) {
223
+ validateEntityArray("relatedEntities", payload.relatedEntities, errors);
224
+ }
225
+
226
+ if (!Array.isArray(payload.contextNarrative)) {
227
+ errors.push("Expected 'contextNarrative' to be an array");
228
+ }
229
+
230
+ const injectionPolicy = requireObject(payload, "injectionPolicy", errors);
231
+ if (injectionPolicy) {
232
+ if (!isNumber(injectionPolicy.tokenBudget)) {
233
+ errors.push("Expected 'injectionPolicy.tokenBudget' to be a number");
234
+ }
235
+ if (!isNumber(injectionPolicy.estimatedTokens)) {
236
+ errors.push("Expected 'injectionPolicy.estimatedTokens' to be a number");
237
+ }
238
+ }
239
+
240
+ if (!isObject(payload.summary)) {
241
+ errors.push("Expected 'summary' to be an object");
242
+ }
243
+ if (!isObject(payload.diagnostics)) {
244
+ errors.push("Expected 'diagnostics' to be an object");
245
+ }
246
+
247
+ return {
248
+ valid: errors.length === 0,
249
+ errors,
250
+ };
251
+ }
@@ -0,0 +1,153 @@
1
+ export type ContextRankingProfile =
2
+ | "baseline_v1"
3
+ | "hybrid_v1"
4
+ | "weighted_v1";
5
+
6
+ export type ContextCompilationMode = "standard" | "delta";
7
+
8
+ export type ContextPackSectionKey =
9
+ | "invariants"
10
+ | "activeBeliefs"
11
+ | "openQuestions"
12
+ | "recentEvidence"
13
+ | "contradictions";
14
+
15
+ export type RankingWeightVector = {
16
+ query: number;
17
+ recency: number;
18
+ confidence?: number;
19
+ beliefType?: number;
20
+ priority?: number;
21
+ severity?: number;
22
+ };
23
+
24
+ export type PackWeightOverride = {
25
+ section: ContextPackSectionKey;
26
+ weights: Partial<RankingWeightVector>;
27
+ };
28
+
29
+ export type CompileContextInput = {
30
+ query?: string;
31
+ budget?: number;
32
+ ranking?: ContextRankingProfile;
33
+ limit?: number;
34
+ maxDepth?: number;
35
+ includeEntities?: boolean;
36
+ mode?: ContextCompilationMode;
37
+ includeFailures?: boolean;
38
+ worktreeId?: string;
39
+ sessionId?: string;
40
+ packWeightOverrides?: PackWeightOverride[];
41
+ tokenBudget?: number;
42
+ rankingProfile?: ContextRankingProfile;
43
+ };
44
+
45
+ export type PublicContextBelief = {
46
+ beliefId: string;
47
+ text: string;
48
+ confidence: number | null;
49
+ beliefType?: string | null;
50
+ status?: string;
51
+ updatedAt?: number | null;
52
+ score: number;
53
+ justification?: string;
54
+ };
55
+
56
+ export type PublicContextQuestion = {
57
+ questionId: string;
58
+ text: string;
59
+ status: string;
60
+ priority: string;
61
+ updatedAt?: number | null;
62
+ score: number;
63
+ justification?: string;
64
+ };
65
+
66
+ export type PublicContextEvidence = {
67
+ evidenceId: string;
68
+ text: string;
69
+ sourceUrl?: string | null;
70
+ kind: string;
71
+ createdAt?: number | null;
72
+ score: number;
73
+ justification?: string;
74
+ };
75
+
76
+ export type PublicContextContradiction = {
77
+ contradictionId: string;
78
+ severity: string;
79
+ status: string;
80
+ description: string;
81
+ score: number;
82
+ justification?: string;
83
+ };
84
+
85
+ export type PublicContextEntity = {
86
+ entityId: string;
87
+ entityType: string;
88
+ title: string;
89
+ text?: string;
90
+ connectedBeliefCount: number;
91
+ connectedEvidenceCount: number;
92
+ score: number;
93
+ metadata?: Record<string, unknown>;
94
+ };
95
+
96
+ export type PublicContextInjectionPolicy = {
97
+ tokenBudget: number;
98
+ estimatedTokens: number;
99
+ sectionBudgets: Record<string, number>;
100
+ sectionUsage: Record<string, number>;
101
+ selected: Record<string, string[]>;
102
+ excludedItems?: Array<{
103
+ id: string;
104
+ section: string;
105
+ reason: "budget_exceeded" | "anti_repetition" | "below_threshold";
106
+ score: number;
107
+ }>;
108
+ };
109
+
110
+ export type PublicCompiledContext = {
111
+ schemaVersion: string;
112
+ topicId: string;
113
+ topicName: string;
114
+ scopedTopicIds: string[];
115
+ generatedAt: number;
116
+ ranking: ContextRankingProfile;
117
+ summary: Record<string, unknown>;
118
+ invariants: PublicContextBelief[];
119
+ activeBeliefs: PublicContextBelief[];
120
+ openQuestions: PublicContextQuestion[];
121
+ recentEvidence: PublicContextEvidence[];
122
+ contradictions: PublicContextContradiction[];
123
+ relatedEntities?: PublicContextEntity[];
124
+ contextNarrative: string[];
125
+ injectionPolicy: PublicContextInjectionPolicy;
126
+ diagnostics: Record<string, unknown>;
127
+ compilationMode?: string;
128
+ failureContext?: {
129
+ failures: Array<{
130
+ attemptId: string;
131
+ approach: string;
132
+ outcome: string;
133
+ recordedAt: number;
134
+ score: number;
135
+ }>;
136
+ suppressedIds: string[];
137
+ };
138
+ deltaReport?: {
139
+ changedItems: Array<{
140
+ id: string;
141
+ section: string;
142
+ changeType: string;
143
+ summary: string;
144
+ }>;
145
+ verificationObligations: Array<{
146
+ description: string;
147
+ source: string;
148
+ severity: "critical" | "high" | "medium" | "low";
149
+ }>;
150
+ referencePoint: string;
151
+ };
152
+ appliedWeightOverrides?: unknown[];
153
+ };
@@ -0,0 +1,202 @@
1
+ /**
2
+ * API Enum Contract Definitions
3
+ *
4
+ * Canonical enum values for all API-facing enumerations.
5
+ * These MUST match the kernel schema validators exactly.
6
+ *
7
+ * Source of truth: lucern/packages/reasoning-kernel/src/adapters/schema/spine/
8
+ */
9
+
10
+ // =============================================================================
11
+ // BELIEF STATUS
12
+ // =============================================================================
13
+
14
+ /**
15
+ * Belief epistemic lifecycle — tracks maturity from raw claim to verified fact.
16
+ *
17
+ * - assumption: Untested raw claim, lowest epistemic standing
18
+ * - hypothesis: Under active investigation, being tested against evidence
19
+ * - belief: Validated through investigation, carries confidence score
20
+ * - fact: Resolved outcome anchored by strong evidence
21
+ */
22
+ export const BELIEF_STATUSES = [
23
+ "assumption",
24
+ "hypothesis",
25
+ "belief",
26
+ "fact",
27
+ ] as const;
28
+ export type BeliefStatus = (typeof BELIEF_STATUSES)[number];
29
+
30
+ // =============================================================================
31
+ // FORK REASONS
32
+ // =============================================================================
33
+
34
+ /** Why a scored belief was branched into a new version */
35
+ export const FORK_REASONS = [
36
+ "refinement",
37
+ "contradiction_response",
38
+ "scope_change",
39
+ "confidence_collapse",
40
+ "manual",
41
+ ] as const;
42
+ export type ForkReason = (typeof FORK_REASONS)[number];
43
+
44
+ // =============================================================================
45
+ // CONFIDENCE TRIGGERS
46
+ // =============================================================================
47
+
48
+ /** What caused a confidence change — every modulation must declare its trigger */
49
+ export const CONFIDENCE_TRIGGERS = [
50
+ "evidence_added",
51
+ "contradiction_detected",
52
+ "merge_outcome",
53
+ "worktree_outcome",
54
+ "manual",
55
+ "decay",
56
+ ] as const;
57
+ export type ConfidenceTrigger = (typeof CONFIDENCE_TRIGGERS)[number];
58
+
59
+ // =============================================================================
60
+ // EDGE TYPES — The 6 canonical epistemic edge types
61
+ // =============================================================================
62
+
63
+ /**
64
+ * Core epistemic edge types — the grammar of reasoning relationships.
65
+ *
66
+ * - supports: Evidence or belief reinforces another belief (weight = strength)
67
+ * - informs: Evidence bears on a belief (directional, weighted)
68
+ * - depends_on: Belief B requires belief A to hold
69
+ * - derived_from: Belief was derived from another (lineage)
70
+ * - contains: Structural containment (topic contains beliefs)
71
+ * - tests: Question tests a belief (falsification link)
72
+ */
73
+ export const EPISTEMIC_EDGE_TYPES = [
74
+ "supports",
75
+ "informs",
76
+ "depends_on",
77
+ "derived_from",
78
+ "contains",
79
+ "tests",
80
+ ] as const;
81
+ export type EpistemicEdgeType = (typeof EPISTEMIC_EDGE_TYPES)[number];
82
+
83
+ /** Structural and lifecycle edges — required for graph integrity */
84
+ export const STRUCTURAL_EDGE_TYPES = [
85
+ "supersedes",
86
+ "responds_to",
87
+ "belongs_to",
88
+ "relates_to_thesis",
89
+ ] as const;
90
+ export type StructuralEdgeType = (typeof STRUCTURAL_EDGE_TYPES)[number];
91
+
92
+ /** All valid edge types (epistemic + structural) */
93
+ export const EDGE_TYPES = [
94
+ ...EPISTEMIC_EDGE_TYPES,
95
+ ...STRUCTURAL_EDGE_TYPES,
96
+ ] as const;
97
+ export type EdgeType = EpistemicEdgeType | StructuralEdgeType;
98
+
99
+ // =============================================================================
100
+ // REASONING METHODS
101
+ // =============================================================================
102
+
103
+ /** How an edge relationship was determined */
104
+ export const REASONING_METHODS = [
105
+ "deductive",
106
+ "inductive",
107
+ "abductive",
108
+ "analogical",
109
+ "empirical",
110
+ ] as const;
111
+ export type ReasoningMethod = (typeof REASONING_METHODS)[number];
112
+
113
+ // =============================================================================
114
+ // CONTRADICTION ENUMS
115
+ // =============================================================================
116
+
117
+ /** Defeat types (Pollock taxonomy) — how a contradiction operates */
118
+ export const DEFEAT_TYPES = [
119
+ "rebuts",
120
+ "undercuts",
121
+ "undermines",
122
+ ] as const;
123
+ export type DefeatType = (typeof DEFEAT_TYPES)[number];
124
+
125
+ /** Contradiction severity */
126
+ export const CONTRADICTION_SEVERITIES = [
127
+ "low",
128
+ "medium",
129
+ "high",
130
+ "critical",
131
+ ] as const;
132
+ export type ContradictionSeverity = (typeof CONTRADICTION_SEVERITIES)[number];
133
+
134
+ /** Contradiction resolution status */
135
+ export const CONTRADICTION_STATUSES = [
136
+ "unresolved",
137
+ "resolved",
138
+ "accepted",
139
+ ] as const;
140
+ export type ContradictionStatus = (typeof CONTRADICTION_STATUSES)[number];
141
+
142
+ // =============================================================================
143
+ // WORKTREE ENUMS
144
+ // =============================================================================
145
+
146
+ /** How a worktree investigation concluded */
147
+ export const MERGE_OUTCOMES = [
148
+ "validated",
149
+ "invalidated",
150
+ "forked",
151
+ "inconclusive",
152
+ ] as const;
153
+ export type MergeOutcome = (typeof MERGE_OUTCOMES)[number];
154
+
155
+ /** Investigation phases within a worktree */
156
+ export const WORKTREE_PHASES = [
157
+ "hypothesis",
158
+ "investigation",
159
+ "evaluation",
160
+ "resolution",
161
+ ] as const;
162
+ export type WorktreePhase = (typeof WORKTREE_PHASES)[number];
163
+
164
+ // =============================================================================
165
+ // EPISTEMIC LAYERS
166
+ // =============================================================================
167
+
168
+ /**
169
+ * The knowledge hierarchy — each layer builds on the one below it.
170
+ *
171
+ * - L1: Sources — raw inputs (documents, APIs, observations)
172
+ * - L2: Evidence — interpreted facts with context and weight
173
+ * - L3: Beliefs — structural claims that carry confidence
174
+ * - L4: Judgments — irreversible commitments based on the epistemic state
175
+ */
176
+ export const EPISTEMIC_LAYERS = [
177
+ "L1",
178
+ "L2",
179
+ "L3",
180
+ "L4",
181
+ ] as const;
182
+ export type EpistemicLayer = (typeof EPISTEMIC_LAYERS)[number];
183
+
184
+ // =============================================================================
185
+ // JUDGMENT TYPES
186
+ // =============================================================================
187
+
188
+ /**
189
+ * Classification of L4 judgments — irreversible determinations.
190
+ *
191
+ * Judgments are evaluated against the knowledge horizon that existed
192
+ * when they were made. They cannot be retroactively invalidated —
193
+ * only new judgments can supersede old ones.
194
+ */
195
+ export const JUDGMENT_TYPES = [
196
+ "thesis",
197
+ "thesis_maturity",
198
+ "contradiction_ruling",
199
+ "scope_determination",
200
+ "confidence_ruling",
201
+ ] as const;
202
+ export type JudgmentType = (typeof JUDGMENT_TYPES)[number];
@@ -0,0 +1,109 @@
1
+ /**
2
+ * Session + Delegation Contract
3
+ *
4
+ * Canonical session lifecycle vocabulary shared by platform gateway auth,
5
+ * hosted MCP auth, Master Control persistence, and SDK session tokens.
6
+ */
7
+
8
+ export const SESSION_AUTH_MODES = [
9
+ "interactive_user",
10
+ "service_principal",
11
+ "tenant_api_key",
12
+ "session_token",
13
+ ] as const;
14
+ export type SessionAuthMode = (typeof SESSION_AUTH_MODES)[number];
15
+
16
+ export const SESSION_PRINCIPAL_TYPES = ["human", "service", "agent"] as const;
17
+ export type SessionPrincipalType = (typeof SESSION_PRINCIPAL_TYPES)[number];
18
+
19
+ export const SESSION_LIFECYCLE_STATUSES = [
20
+ "active",
21
+ "expired",
22
+ "revoked",
23
+ ] as const;
24
+ export type SessionLifecycleStatus =
25
+ (typeof SESSION_LIFECYCLE_STATUSES)[number];
26
+
27
+ export type SessionDelegationHop = {
28
+ principalId: string;
29
+ principalType: SessionPrincipalType;
30
+ authMode?: SessionAuthMode;
31
+ sessionId?: string;
32
+ delegatedAt?: number;
33
+ reason?: string;
34
+ };
35
+
36
+ export type SessionAuditOutcome =
37
+ | "accepted"
38
+ | "rejected"
39
+ | "revoked"
40
+ | "expired";
41
+
42
+ export type SessionAuditEnvelope = {
43
+ sessionId: string;
44
+ authMode: SessionAuthMode;
45
+ principalId: string;
46
+ principalType: SessionPrincipalType;
47
+ tenantId: string;
48
+ workspaceId?: string;
49
+ apiKeyId?: string;
50
+ scopes: readonly string[];
51
+ roles?: readonly string[];
52
+ delegationChain?: readonly SessionDelegationHop[];
53
+ sourceSessionId?: string;
54
+ expiresAt?: number;
55
+ request?: {
56
+ endpoint?: string;
57
+ method?: string;
58
+ correlationId?: string;
59
+ };
60
+ result?: {
61
+ outcome: SessionAuditOutcome;
62
+ reason?: string;
63
+ };
64
+ };
65
+
66
+ export function inferSessionPrincipalType(
67
+ principalId: string
68
+ ): SessionPrincipalType {
69
+ if (principalId.startsWith("user:")) {
70
+ return "human";
71
+ }
72
+ if (principalId.startsWith("agent:")) {
73
+ return "agent";
74
+ }
75
+ return "service";
76
+ }
77
+
78
+ export function normalizeDelegationChain(args: {
79
+ delegationChain?: readonly SessionDelegationHop[];
80
+ delegatedBy?: string;
81
+ delegatedByType?: SessionPrincipalType;
82
+ delegatedAt?: number;
83
+ reason?: string;
84
+ }): SessionDelegationHop[] | undefined {
85
+ if (args.delegationChain && args.delegationChain.length > 0) {
86
+ return [...args.delegationChain];
87
+ }
88
+ if (!args.delegatedBy) {
89
+ return;
90
+ }
91
+ return [
92
+ {
93
+ principalId: args.delegatedBy,
94
+ principalType:
95
+ args.delegatedByType ?? inferSessionPrincipalType(args.delegatedBy),
96
+ delegatedAt: args.delegatedAt,
97
+ reason: args.reason,
98
+ },
99
+ ];
100
+ }
101
+
102
+ export function lastDelegator(
103
+ delegationChain?: readonly SessionDelegationHop[]
104
+ ): string | undefined {
105
+ if (!delegationChain || delegationChain.length === 0) {
106
+ return;
107
+ }
108
+ return delegationChain[delegationChain.length - 1]?.principalId;
109
+ }