@lucern/contracts 0.1.2-alpha.4 → 0.3.0-alpha.0

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 (214) hide show
  1. package/dist/defineFunction-DO97DKs4.d.ts +14 -0
  2. package/dist/defineTable-CBQ03FXl.d.ts +36 -0
  3. package/dist/dsl-BgpoVOVQ.d.ts +110 -0
  4. package/dist/dsl.d.ts +5 -0
  5. package/dist/dsl.js +675 -0
  6. package/dist/dsl.js.map +1 -0
  7. package/dist/function-registry/beliefs.d.ts +519 -0
  8. package/dist/function-registry/beliefs.js +4326 -0
  9. package/dist/function-registry/beliefs.js.map +1 -0
  10. package/dist/function-registry/coding.d.ts +347 -0
  11. package/dist/function-registry/coding.js +4268 -0
  12. package/dist/function-registry/coding.js.map +1 -0
  13. package/dist/function-registry/context.d.ts +218 -0
  14. package/dist/function-registry/context.js +4175 -0
  15. package/dist/function-registry/context.js.map +1 -0
  16. package/dist/function-registry/contracts.d.ts +218 -0
  17. package/dist/function-registry/contracts.js +4143 -0
  18. package/dist/function-registry/contracts.js.map +1 -0
  19. package/dist/function-registry/coordination.d.ts +476 -0
  20. package/dist/function-registry/coordination.js +4254 -0
  21. package/dist/function-registry/coordination.js.map +1 -0
  22. package/dist/function-registry/edges.d.ts +175 -0
  23. package/dist/function-registry/edges.js +4150 -0
  24. package/dist/function-registry/edges.js.map +1 -0
  25. package/dist/function-registry/evidence.d.ts +433 -0
  26. package/dist/function-registry/evidence.js +4302 -0
  27. package/dist/function-registry/evidence.js.map +1 -0
  28. package/dist/function-registry/graph.d.ts +648 -0
  29. package/dist/function-registry/graph.js +4329 -0
  30. package/dist/function-registry/graph.js.map +1 -0
  31. package/dist/function-registry/helpers.d.ts +86 -0
  32. package/dist/function-registry/helpers.js +4131 -0
  33. package/dist/function-registry/helpers.js.map +1 -0
  34. package/dist/function-registry/identity.d.ts +218 -0
  35. package/dist/function-registry/identity.js +4154 -0
  36. package/dist/function-registry/identity.js.map +1 -0
  37. package/dist/function-registry/index.d.ts +32 -0
  38. package/dist/function-registry/index.js +4235 -0
  39. package/dist/function-registry/index.js.map +1 -0
  40. package/dist/function-registry/judgments.d.ts +175 -0
  41. package/dist/function-registry/judgments.js +4157 -0
  42. package/dist/function-registry/judgments.js.map +1 -0
  43. package/dist/function-registry/legacy.d.ts +132 -0
  44. package/dist/function-registry/legacy.js +4118 -0
  45. package/dist/function-registry/legacy.js.map +1 -0
  46. package/dist/function-registry/lenses.d.ts +261 -0
  47. package/dist/function-registry/lenses.js +4160 -0
  48. package/dist/function-registry/lenses.js.map +1 -0
  49. package/dist/function-registry/manifest.d.ts +36 -0
  50. package/dist/function-registry/manifest.js +366 -0
  51. package/dist/function-registry/manifest.js.map +1 -0
  52. package/dist/function-registry/ontologies.d.ts +562 -0
  53. package/dist/function-registry/ontologies.js +4292 -0
  54. package/dist/function-registry/ontologies.js.map +1 -0
  55. package/dist/function-registry/pipeline.d.ts +218 -0
  56. package/dist/function-registry/pipeline.js +4143 -0
  57. package/dist/function-registry/pipeline.js.map +1 -0
  58. package/dist/function-registry/questions.d.ts +605 -0
  59. package/dist/function-registry/questions.js +4329 -0
  60. package/dist/function-registry/questions.js.map +1 -0
  61. package/dist/function-registry/tasks.d.ts +261 -0
  62. package/dist/function-registry/tasks.js +4166 -0
  63. package/dist/function-registry/tasks.js.map +1 -0
  64. package/dist/function-registry/topics.d.ts +304 -0
  65. package/dist/function-registry/topics.js +4193 -0
  66. package/dist/function-registry/topics.js.map +1 -0
  67. package/dist/function-registry/types.d.ts +84 -0
  68. package/dist/function-registry/types.js +3 -0
  69. package/dist/function-registry/types.js.map +1 -0
  70. package/dist/function-registry/worktrees.d.ts +476 -0
  71. package/dist/function-registry/worktrees.js +4277 -0
  72. package/dist/function-registry/worktrees.js.map +1 -0
  73. package/dist/generated/convexSchemas.d.ts +20 -0
  74. package/dist/generated/convexSchemas.js +160 -0
  75. package/dist/generated/convexSchemas.js.map +1 -0
  76. package/dist/generated/schema-manifest.json +5179 -0
  77. package/dist/generated/tableOwnership.d.ts +127 -0
  78. package/dist/generated/tableOwnership.js +276 -0
  79. package/dist/generated/tableOwnership.js.map +1 -0
  80. package/dist/generated/tier-expectations.json +360 -0
  81. package/dist/idOf-DR8tkhQS.d.ts +10 -0
  82. package/dist/index-DoDXl8KS.d.ts +19 -0
  83. package/dist/index.d.ts +11 -2
  84. package/dist/index.js +5739 -315
  85. package/dist/index.js.map +1 -1
  86. package/dist/schema-helpers/enumValidation.d.ts +17 -0
  87. package/dist/schema-helpers/enumValidation.js +143 -0
  88. package/dist/schema-helpers/enumValidation.js.map +1 -0
  89. package/dist/schema-helpers/spine/nodes/decision.d.ts +19 -0
  90. package/dist/schema-helpers/spine/nodes/decision.js +81 -0
  91. package/dist/schema-helpers/spine/nodes/decision.js.map +1 -0
  92. package/dist/schema-helpers/spine/tables/epistemicNodes.d.ts +9 -0
  93. package/dist/schema-helpers/spine/tables/epistemicNodes.js +62 -0
  94. package/dist/schema-helpers/spine/tables/epistemicNodes.js.map +1 -0
  95. package/dist/schema-helpers/topicIds.d.ts +17 -0
  96. package/dist/schema-helpers/topicIds.js +21 -0
  97. package/dist/schema-helpers/topicIds.js.map +1 -0
  98. package/dist/schema-helpers/topicLegacyScope.d.ts +19 -0
  99. package/dist/schema-helpers/topicLegacyScope.js +44 -0
  100. package/dist/schema-helpers/topicLegacyScope.js.map +1 -0
  101. package/dist/schema-helpers/validators.d.ts +8 -0
  102. package/dist/schema-helpers/validators.js +18 -0
  103. package/dist/schema-helpers/validators.js.map +1 -0
  104. package/dist/schemas/enums.d.ts +12 -0
  105. package/dist/schemas/enums.js +11 -0
  106. package/dist/schemas/enums.js.map +1 -0
  107. package/dist/schemas/index.d.ts +5 -0
  108. package/dist/schemas/index.js +4240 -0
  109. package/dist/schemas/index.js.map +1 -0
  110. package/dist/schemas/manifest.d.ts +24521 -0
  111. package/dist/schemas/manifest.js +4242 -0
  112. package/dist/schemas/manifest.js.map +1 -0
  113. package/dist/schemas/tables/identity/agent.d.ts +21 -0
  114. package/dist/schemas/tables/identity/agent.js +41 -0
  115. package/dist/schemas/tables/identity/agent.js.map +1 -0
  116. package/dist/schemas/tables/identity/epistemic.d.ts +18 -0
  117. package/dist/schemas/tables/identity/epistemic.js +38 -0
  118. package/dist/schemas/tables/identity/epistemic.js.map +1 -0
  119. package/dist/schemas/tables/identity/model.d.ts +62 -0
  120. package/dist/schemas/tables/identity/model.js +110 -0
  121. package/dist/schemas/tables/identity/model.js.map +1 -0
  122. package/dist/schemas/tables/identity/platform.d.ts +392 -0
  123. package/dist/schemas/tables/identity/platform.js +475 -0
  124. package/dist/schemas/tables/identity/platform.js.map +1 -0
  125. package/dist/schemas/tables/identity/project.d.ts +22 -0
  126. package/dist/schemas/tables/identity/project.js +48 -0
  127. package/dist/schemas/tables/identity/project.js.map +1 -0
  128. package/dist/schemas/tables/identity/user.d.ts +26 -0
  129. package/dist/schemas/tables/identity/user.js +47 -0
  130. package/dist/schemas/tables/identity/user.js.map +1 -0
  131. package/dist/schemas/tables/kernel/config.d.ts +20 -0
  132. package/dist/schemas/tables/kernel/config.js +39 -0
  133. package/dist/schemas/tables/kernel/config.js.map +1 -0
  134. package/dist/schemas/tables/kernel/coordination.d.ts +30 -0
  135. package/dist/schemas/tables/kernel/coordination.js +57 -0
  136. package/dist/schemas/tables/kernel/coordination.js.map +1 -0
  137. package/dist/schemas/tables/kernel/decision.d.ts +246 -0
  138. package/dist/schemas/tables/kernel/decision.js +371 -0
  139. package/dist/schemas/tables/kernel/decision.js.map +1 -0
  140. package/dist/schemas/tables/kernel/embedding.d.ts +18 -0
  141. package/dist/schemas/tables/kernel/embedding.js +48 -0
  142. package/dist/schemas/tables/kernel/embedding.js.map +1 -0
  143. package/dist/schemas/tables/kernel/epistemic.d.ts +315 -0
  144. package/dist/schemas/tables/kernel/epistemic.js +327 -0
  145. package/dist/schemas/tables/kernel/epistemic.js.map +1 -0
  146. package/dist/schemas/tables/kernel/idempotency.d.ts +13 -0
  147. package/dist/schemas/tables/kernel/idempotency.js +31 -0
  148. package/dist/schemas/tables/kernel/idempotency.js.map +1 -0
  149. package/dist/schemas/tables/kernel/infra.d.ts +171 -0
  150. package/dist/schemas/tables/kernel/infra.js +160 -0
  151. package/dist/schemas/tables/kernel/infra.js.map +1 -0
  152. package/dist/schemas/tables/kernel/intelligence.d.ts +293 -0
  153. package/dist/schemas/tables/kernel/intelligence.js +207 -0
  154. package/dist/schemas/tables/kernel/intelligence.js.map +1 -0
  155. package/dist/schemas/tables/kernel/lens.d.ts +192 -0
  156. package/dist/schemas/tables/kernel/lens.js +122 -0
  157. package/dist/schemas/tables/kernel/lens.js.map +1 -0
  158. package/dist/schemas/tables/kernel/ontology.d.ts +89 -0
  159. package/dist/schemas/tables/kernel/ontology.js +91 -0
  160. package/dist/schemas/tables/kernel/ontology.js.map +1 -0
  161. package/dist/schemas/tables/kernel/platform.d.ts +353 -0
  162. package/dist/schemas/tables/kernel/platform.js +349 -0
  163. package/dist/schemas/tables/kernel/platform.js.map +1 -0
  164. package/dist/schemas/tables/kernel/spine.d.ts +206 -0
  165. package/dist/schemas/tables/kernel/spine.js +243 -0
  166. package/dist/schemas/tables/kernel/spine.js.map +1 -0
  167. package/dist/schemas/tables/kernel/task.d.ts +614 -0
  168. package/dist/schemas/tables/kernel/task.js +189 -0
  169. package/dist/schemas/tables/kernel/task.js.map +1 -0
  170. package/dist/schemas/tables/kernel/topic.d.ts +25 -0
  171. package/dist/schemas/tables/kernel/topic.js +62 -0
  172. package/dist/schemas/tables/kernel/topic.js.map +1 -0
  173. package/dist/schemas/tables/kernel/workflow.d.ts +45 -0
  174. package/dist/schemas/tables/kernel/workflow.js +94 -0
  175. package/dist/schemas/tables/kernel/workflow.js.map +1 -0
  176. package/dist/schemas/tables/kernel/worktree.d.ts +823 -0
  177. package/dist/schemas/tables/kernel/worktree.js +328 -0
  178. package/dist/schemas/tables/kernel/worktree.js.map +1 -0
  179. package/dist/schemas/tables/mc/identity.d.ts +134 -0
  180. package/dist/schemas/tables/mc/identity.js +221 -0
  181. package/dist/schemas/tables/mc/identity.js.map +1 -0
  182. package/dist/schemas/tables/mc/methodology.d.ts +46 -0
  183. package/dist/schemas/tables/mc/methodology.js +69 -0
  184. package/dist/schemas/tables/mc/methodology.js.map +1 -0
  185. package/dist/schemas/tables/mc/pack.d.ts +540 -0
  186. package/dist/schemas/tables/mc/pack.js +294 -0
  187. package/dist/schemas/tables/mc/pack.js.map +1 -0
  188. package/dist/schemas/tables/mc/policy.d.ts +57 -0
  189. package/dist/schemas/tables/mc/policy.js +121 -0
  190. package/dist/schemas/tables/mc/policy.js.map +1 -0
  191. package/dist/schemas/tables/mc/registry.d.ts +155 -0
  192. package/dist/schemas/tables/mc/registry.js +164 -0
  193. package/dist/schemas/tables/mc/registry.js.map +1 -0
  194. package/dist/schemas/tables/mc/runtime.d.ts +119 -0
  195. package/dist/schemas/tables/mc/runtime.js +199 -0
  196. package/dist/schemas/tables/mc/runtime.js.map +1 -0
  197. package/dist/schemas/tables/mc/tenant.d.ts +106 -0
  198. package/dist/schemas/tables/mc/tenant.js +114 -0
  199. package/dist/schemas/tables/mc/tenant.js.map +1 -0
  200. package/dist/schemas/tables/mc/workspace.d.ts +28 -0
  201. package/dist/schemas/tables/mc/workspace.js +52 -0
  202. package/dist/schemas/tables/mc/workspace.js.map +1 -0
  203. package/dist/{sdk-tools.contract-BnV0hKLp.d.ts → sdk-tools.contract-C2kQN_Xk.d.ts} +3 -7
  204. package/dist/sdk-tools.contract.d.ts +2 -2
  205. package/dist/sdk-tools.contract.js +664 -175
  206. package/dist/sdk-tools.contract.js.map +1 -1
  207. package/dist/tool-contracts-WCnuE9DW.d.ts +288 -0
  208. package/dist/tool-contracts.d.ts +1 -0
  209. package/dist/{mcp-tools.contract.js → tool-contracts.js} +666 -116
  210. package/dist/tool-contracts.js.map +1 -0
  211. package/package.json +119 -2
  212. package/dist/mcp-tools.contract-D8kXcP6d.d.ts +0 -254
  213. package/dist/mcp-tools.contract.d.ts +0 -1
  214. package/dist/mcp-tools.contract.js.map +0 -1
@@ -0,0 +1,4242 @@
1
+ import { z } from 'zod';
2
+
3
+ // src/schemas/tables/kernel/coordination.ts
4
+
5
+ // src/dsl/defineTable.ts
6
+ function defineTable(spec) {
7
+ return spec;
8
+ }
9
+ var CONVEX_ID_TABLE = /* @__PURE__ */ Symbol.for("lucern.contracts.convexIdTable");
10
+ function idOf(table) {
11
+ const schema = z.string().brand();
12
+ Object.defineProperty(schema, CONVEX_ID_TABLE, {
13
+ configurable: false,
14
+ enumerable: false,
15
+ value: table,
16
+ writable: false
17
+ });
18
+ return schema;
19
+ }
20
+
21
+ // src/schemas/tables/kernel/coordination.ts
22
+ var agentMessages = defineTable({
23
+ name: "agentMessages",
24
+ component: "kernel",
25
+ category: "coordination",
26
+ shape: z.object({
27
+ "fromSessionId": z.string(),
28
+ "toSessionId": z.string(),
29
+ "content": z.string(),
30
+ "messageType": z.enum(["note", "question", "answer", "alert", "handoff"]),
31
+ "relatedBeliefId": z.string().optional(),
32
+ "relatedWorktreeId": z.string().optional(),
33
+ "readAt": z.number().optional(),
34
+ "expiresAt": z.number().optional(),
35
+ "createdAt": z.number()
36
+ }),
37
+ indices: [
38
+ { kind: "index", name: "by_toSessionId", columns: ["toSessionId", "createdAt"] },
39
+ { kind: "index", name: "by_fromSessionId", columns: ["fromSessionId", "createdAt"] }
40
+ ]
41
+ });
42
+ var agentSessions = defineTable({
43
+ name: "agentSessions",
44
+ component: "kernel",
45
+ category: "coordination",
46
+ shape: z.object({
47
+ "sessionId": z.string(),
48
+ "sessionName": z.string().optional(),
49
+ "agentType": z.string().optional(),
50
+ "topicId": z.string().optional(),
51
+ "worktreeId": z.string().optional(),
52
+ "gitBranch": z.string().optional(),
53
+ "touchedFiles": z.array(z.string()).optional(),
54
+ "status": z.enum(["active", "idle", "ended"]),
55
+ "lastHeartbeatAt": z.number(),
56
+ "startedAt": z.number(),
57
+ "endedAt": z.number().optional(),
58
+ "metadata": z.any().optional()
59
+ }),
60
+ indices: [
61
+ { kind: "index", name: "by_status", columns: ["status"] },
62
+ { kind: "index", name: "by_sessionId", columns: ["sessionId"] }
63
+ ]
64
+ });
65
+ var agentRegistryEntries = defineTable({
66
+ name: "agentRegistryEntries",
67
+ component: "mc",
68
+ category: "registry",
69
+ shape: z.object({
70
+ "tenantId": idOf("tenants"),
71
+ "workspaceId": idOf("workspaces").optional(),
72
+ "agentDefinitionId": z.string(),
73
+ "agentKey": z.string(),
74
+ "displayName": z.string(),
75
+ "description": z.string(),
76
+ "version": z.string(),
77
+ "status": z.enum(["active", "deprecated", "disabled"]),
78
+ "executionAdapter": z.enum(["convex_mutation", "convex_action", "http_callback", "mcp_tool", "sdk_invocation", "external_observed"]),
79
+ "scopeRequirements": z.array(z.string()),
80
+ "promptReleaseChannel": z.enum(["dev", "staging", "prod"]),
81
+ "promptName": z.string().optional(),
82
+ "systemPrompt": z.string().optional(),
83
+ "toolIds": z.array(z.string()).optional(),
84
+ "modelSlot": z.string().optional(),
85
+ "requiredModelCapabilities": z.array(z.string()).optional(),
86
+ "parameterSchema": z.record(z.any()),
87
+ "outputSchema": z.record(z.any()).optional(),
88
+ "guardrails": z.object({
89
+ "isolationMode": z.enum(["direct", "sandbox"]).optional(),
90
+ "maxExecutionMs": z.number().optional(),
91
+ "heartbeatIntervalMs": z.number().optional(),
92
+ "maxToolCalls": z.number().optional(),
93
+ "allowNetworkEgress": z.boolean().optional(),
94
+ "allowedOrigins": z.array(z.string()).optional()
95
+ }).optional(),
96
+ "runtimeConfig": z.object({
97
+ "entryPoint": z.string().optional(),
98
+ "callbackUrl": z.string().optional(),
99
+ "modelRouting": z.enum(["model_machine", "tenant_proxy", "bring_your_own"]).optional(),
100
+ "auditMode": z.enum(["harness", "master_control"]).optional()
101
+ }).optional(),
102
+ "exampleInvocations": z.array(z.object({
103
+ "input": z.record(z.any()),
104
+ "expectedOutput": z.record(z.any()).optional()
105
+ })),
106
+ "metadata": z.record(z.any()).optional(),
107
+ "createdBy": z.string(),
108
+ "createdAt": z.number(),
109
+ "updatedAt": z.number()
110
+ }),
111
+ indices: [
112
+ { kind: "index", name: "by_agentDefinitionId", columns: ["agentDefinitionId"] },
113
+ { kind: "index", name: "by_tenant_agentDefinitionId", columns: ["tenantId", "agentDefinitionId"] },
114
+ { kind: "index", name: "by_tenant_agentDefinitionId_version", columns: ["tenantId", "agentDefinitionId", "version"] },
115
+ { kind: "index", name: "by_tenant_agentKey", columns: ["tenantId", "agentKey"] },
116
+ { kind: "index", name: "by_tenant_agentKey_version", columns: ["tenantId", "agentKey", "version"] },
117
+ { kind: "index", name: "by_workspace_agentKey_version", columns: ["workspaceId", "agentKey", "version"] },
118
+ { kind: "index", name: "by_tenant_status", columns: ["tenantId", "status"] }
119
+ ]
120
+ });
121
+ var toolCatalog = defineTable({
122
+ name: "toolCatalog",
123
+ component: "mc",
124
+ category: "registry",
125
+ shape: z.object({
126
+ "toolName": z.string(),
127
+ "description": z.string(),
128
+ "version": z.string(),
129
+ "distribution": z.enum(["base", "pack_only"]),
130
+ "status": z.enum(["active", "deprecated", "draft"]),
131
+ "category": z.enum(["read", "write", "admin", "system"]),
132
+ "requiredRole": z.enum(["platform_admin", "tenant_admin", "workspace_admin", "editor", "viewer", "auditor", "service_agent"]),
133
+ "requiredAction": z.enum(["read", "mutate", "admin", "summarize", "export", "create", "delete", "grant", "revoke"]),
134
+ "surfaces": z.array(z.enum(["mcp", "chat", "voice", "sprint", "api", "sdk", "cli"])),
135
+ "parameterSchema": z.record(z.any()).optional(),
136
+ "returnSchema": z.record(z.any()).optional(),
137
+ "handlerRef": z.string().optional(),
138
+ "executionAdapter": z.enum(["convex_mutation", "convex_action", "http_callback", "mcp_tool", "sdk_invocation", "external_observed"]).optional(),
139
+ "safetyMetadata": z.object({
140
+ "readOnly": z.boolean(),
141
+ "idempotent": z.boolean(),
142
+ "sideEffectLevel": z.enum(["none", "low", "high"])
143
+ }).optional(),
144
+ "metadata": z.record(z.any()).optional(),
145
+ "createdAt": z.number(),
146
+ "updatedAt": z.number()
147
+ }),
148
+ indices: [
149
+ { kind: "index", name: "by_toolName", columns: ["toolName"] },
150
+ { kind: "index", name: "by_status", columns: ["status"] },
151
+ { kind: "index", name: "by_distribution", columns: ["distribution"] },
152
+ { kind: "index", name: "by_distribution_status", columns: ["distribution", "status"] },
153
+ { kind: "index", name: "by_category", columns: ["category"] },
154
+ { kind: "index", name: "by_requiredRole", columns: ["requiredRole"] }
155
+ ]
156
+ });
157
+ var toolRegistryEntries = defineTable({
158
+ name: "toolRegistryEntries",
159
+ component: "mc",
160
+ category: "registry",
161
+ shape: z.object({
162
+ "tenantId": idOf("tenants"),
163
+ "workspaceId": idOf("workspaces").optional(),
164
+ "toolId": z.string(),
165
+ "toolName": z.string(),
166
+ "description": z.string(),
167
+ "version": z.string(),
168
+ "status": z.enum(["active", "deprecated", "disabled"]),
169
+ "executionAdapter": z.enum(["convex_mutation", "convex_action", "http_callback", "mcp_tool", "sdk_invocation", "external_observed"]),
170
+ "gateClassification": z.enum(["core", "shimmed"]),
171
+ "scopeRequirements": z.array(z.string()),
172
+ "parameterSchema": z.record(z.any()),
173
+ "safetyMetadata": z.object({
174
+ "readOnly": z.boolean(),
175
+ "idempotent": z.boolean(),
176
+ "sideEffectLevel": z.enum(["none", "low", "high"])
177
+ }),
178
+ "exampleInvocations": z.array(z.object({
179
+ "input": z.record(z.any()),
180
+ "expectedOutput": z.record(z.any()).optional()
181
+ })),
182
+ "requiredRole": z.enum(["platform_admin", "tenant_admin", "workspace_admin", "editor", "viewer", "auditor", "service_agent"]).optional(),
183
+ "requiredAction": z.enum(["read", "mutate", "admin", "summarize", "export", "create", "delete", "grant", "revoke"]).optional(),
184
+ "surfaces": z.array(z.enum(["mcp", "chat", "voice", "sprint", "api", "sdk", "cli"])).optional(),
185
+ "approvalGateId": z.string().optional(),
186
+ "isCore": z.boolean().optional(),
187
+ "category": z.enum(["read", "write", "admin", "system"]).optional(),
188
+ "metadata": z.record(z.any()).optional(),
189
+ "createdBy": z.string(),
190
+ "createdAt": z.number(),
191
+ "updatedAt": z.number()
192
+ }),
193
+ indices: [
194
+ { kind: "index", name: "by_toolId", columns: ["toolId"] },
195
+ { kind: "index", name: "by_tenant_toolId", columns: ["tenantId", "toolId"] },
196
+ { kind: "index", name: "by_tenant_toolId_version", columns: ["tenantId", "toolId", "version"] },
197
+ { kind: "index", name: "by_tenant_toolName", columns: ["tenantId", "toolName"] },
198
+ { kind: "index", name: "by_tenant_toolName_version", columns: ["tenantId", "toolName", "version"] },
199
+ { kind: "index", name: "by_workspace_toolName_version", columns: ["workspaceId", "toolName", "version"] },
200
+ { kind: "index", name: "by_tenant_gateClassification", columns: ["tenantId", "gateClassification"] },
201
+ { kind: "index", name: "by_tenant_status", columns: ["tenantId", "status"] }
202
+ ]
203
+ });
204
+ var agents = defineTable({
205
+ name: "agents",
206
+ component: "identity",
207
+ category: "agent",
208
+ shape: z.object({
209
+ "slug": z.string(),
210
+ "displayName": z.string().optional(),
211
+ "principalId": z.string(),
212
+ "principalType": z.literal("service"),
213
+ "tenantId": z.string(),
214
+ "workspaceId": z.string(),
215
+ "roles": z.array(z.string()),
216
+ "permittedToolNames": z.array(z.string()).optional(),
217
+ "permittedPackKeys": z.array(z.string()).optional(),
218
+ "groupIds": z.array(z.string()).optional(),
219
+ "status": z.enum(["active", "suspended", "disabled"]),
220
+ "createdAt": z.number(),
221
+ "updatedAt": z.number(),
222
+ "createdBy": z.string()
223
+ }),
224
+ indices: [
225
+ { kind: "index", name: "by_slug", columns: ["slug"] },
226
+ { kind: "index", name: "by_principalId", columns: ["principalId"] },
227
+ { kind: "index", name: "by_tenantId", columns: ["tenantId"] },
228
+ { kind: "index", name: "by_status", columns: ["status"] }
229
+ ]
230
+ });
231
+ var apiKeys = defineTable({
232
+ name: "apiKeys",
233
+ component: "mc",
234
+ category: "tenant",
235
+ shape: z.object({
236
+ "tenantId": idOf("tenants"),
237
+ "keyPrefix": z.enum(["luc", "stk"]),
238
+ "keyHash": z.string(),
239
+ "keyHint": z.string(),
240
+ "label": z.string().optional(),
241
+ "status": z.enum(["active", "revoked", "expired"]),
242
+ "expiresAt": z.number().optional(),
243
+ "lastUsedAt": z.number().optional(),
244
+ "revokedAt": z.number().optional(),
245
+ "revokedBy": z.string().optional(),
246
+ "createdBy": z.string(),
247
+ "createdAt": z.number(),
248
+ "updatedAt": z.number()
249
+ }),
250
+ indices: [
251
+ { kind: "index", name: "by_tenantId", columns: ["tenantId"] },
252
+ { kind: "index", name: "by_keyHash", columns: ["keyHash"] },
253
+ { kind: "index", name: "by_tenant_prefix", columns: ["tenantId", "keyPrefix"] },
254
+ { kind: "index", name: "by_status", columns: ["status"] }
255
+ ]
256
+ });
257
+ var auditLog = defineTable({
258
+ name: "auditLog",
259
+ component: "mc",
260
+ category: "tenant",
261
+ shape: z.object({
262
+ "tenantId": idOf("tenants").optional(),
263
+ "apiKeyId": idOf("apiKeys").optional(),
264
+ "action": z.enum(["key_created", "key_revoked", "key_expired", "key_used", "tenant_secret_created", "tenant_secret_rotated", "tenant_secret_revoked", "tenant_slot_binding_upserted", "tenant_slot_binding_revoked", "proxy_token_minted", "proxy_request_recorded", "tenant_created", "tenant_updated", "tenant_suspended", "tenant_archived", "tenant_reactivated", "principal_created", "principal_updated", "principal_suspended", "membership_created", "membership_updated", "membership_revoked", "group_created", "group_updated", "group_deleted", "group_member_added", "group_member_removed", "workspace_created", "workspace_updated", "workspace_archived", "workspace_deployment_set", "workspace_deployment_removed", "service_key_created", "service_key_rotated", "service_key_revoked", "service_key_used", "service_key_auth_failed", "session_created", "session_validated", "session_revoked", "session_cascade_revoked", "session_expired", "sandbox_created", "sandbox_secret_injected", "sandbox_execution_started", "sandbox_execution_completed", "sandbox_limit_violated", "policy_created", "policy_updated", "policy_enforced", "policy_archived", "agent_registered", "agent_updated", "tool_registered", "tool_updated", "pack_entitled", "pack_installed", "pack_enabled", "pack_disabled", "pack_entitlement_revoked", "pack_upgraded", "pack_upgrade_committed", "pack_upgrade_rolled_back", "pack_group_assigned", "pack_group_unassigned", "methodology_pack_created", "methodology_pack_updated", "methodology_pack_assigned", "methodology_pack_removed", "pack_assigned_to_group", "pack_revoked_from_group", "pack_ontology_materialized", "pack_ontology_topic_bound", "cutover_flag_set", "cutover_flag_cleared"]),
265
+ "actorClerkId": z.string(),
266
+ "details": z.any().optional(),
267
+ "createdAt": z.number()
268
+ }),
269
+ indices: [
270
+ { kind: "index", name: "by_tenantId", columns: ["tenantId", "createdAt"] },
271
+ { kind: "index", name: "by_apiKeyId", columns: ["apiKeyId", "createdAt"] },
272
+ { kind: "index", name: "by_action", columns: ["action", "createdAt"] }
273
+ ]
274
+ });
275
+ var tenants = defineTable({
276
+ name: "tenants",
277
+ component: "mc",
278
+ category: "tenant",
279
+ shape: z.object({
280
+ "slug": z.string(),
281
+ "name": z.string(),
282
+ "status": z.enum(["provisioning", "active", "suspended", "archived"]),
283
+ "tier": z.enum(["free", "developer", "team", "enterprise"]),
284
+ "kernelDeployment": z.object({
285
+ "devUrl": z.string(),
286
+ "devId": z.string(),
287
+ "stagingUrl": z.string().optional(),
288
+ "stagingId": z.string().optional(),
289
+ "prodUrl": z.string().optional(),
290
+ "prodId": z.string().optional()
291
+ }).optional(),
292
+ "lucernDeployment": z.object({
293
+ "devUrl": z.string(),
294
+ "devId": z.string(),
295
+ "stagingUrl": z.string().optional(),
296
+ "stagingId": z.string().optional(),
297
+ "prodUrl": z.string().optional(),
298
+ "prodId": z.string().optional()
299
+ }).optional(),
300
+ "appDeployment": z.object({
301
+ "devUrl": z.string(),
302
+ "devId": z.string(),
303
+ "stagingUrl": z.string().optional(),
304
+ "stagingId": z.string().optional(),
305
+ "prodUrl": z.string().optional(),
306
+ "prodId": z.string().optional()
307
+ }).optional(),
308
+ "ownerClerkId": z.string(),
309
+ "ownerEmail": z.string().optional(),
310
+ "metadata": z.any().optional(),
311
+ "createdAt": z.number(),
312
+ "updatedAt": z.number()
313
+ }),
314
+ indices: [
315
+ { kind: "index", name: "by_slug", columns: ["slug"] },
316
+ { kind: "index", name: "by_status", columns: ["status"] },
317
+ { kind: "index", name: "by_ownerClerkId", columns: ["ownerClerkId"] }
318
+ ]
319
+ });
320
+ var autofixJobs = defineTable({
321
+ name: "autofixJobs",
322
+ component: "kernel",
323
+ category: "infra",
324
+ shape: z.object({
325
+ "sentryIssueId": z.string(),
326
+ "sentryEventId": z.string(),
327
+ "fingerprint": z.string(),
328
+ "dedupeKey": z.string(),
329
+ "errorType": z.string(),
330
+ "errorMessage": z.string(),
331
+ "stackTrace": z.string().optional(),
332
+ "filePaths": z.array(z.string()),
333
+ "environment": z.string(),
334
+ "sentryProjectSlug": z.string(),
335
+ "sentryOrgSlug": z.string(),
336
+ "sentryIssueUrl": z.string().optional(),
337
+ "triggeredRule": z.string(),
338
+ "sentryPayload": z.record(z.any()),
339
+ "allowlistEligible": z.boolean(),
340
+ "allowlistReason": z.string(),
341
+ "status": z.enum(["pending", "claimed", "running", "iterating", "succeeded", "failed", "cancelled"]),
342
+ "claimedBy": z.string().optional(),
343
+ "claimedAt": z.number().optional(),
344
+ "startedAt": z.number().optional(),
345
+ "completedAt": z.number().optional(),
346
+ "error": z.string().optional(),
347
+ "prNumber": z.number().optional(),
348
+ "prUrl": z.string().optional(),
349
+ "commitSha": z.string().optional(),
350
+ "branchName": z.string().optional(),
351
+ "harnessReceipt": z.object({
352
+ "runnerSessionId": z.string(),
353
+ "startedAt": z.number(),
354
+ "completedAt": z.number(),
355
+ "fixDescription": z.string().optional(),
356
+ "filesChanged": z.array(z.string()),
357
+ "verificationResults": z.array(z.object({
358
+ "command": z.string(),
359
+ "status": z.enum(["pass", "fail", "skipped"]),
360
+ "summary": z.string().optional()
361
+ })),
362
+ "commitShas": z.array(z.string()),
363
+ "prCreated": z.boolean(),
364
+ "errorSummary": z.string().optional()
365
+ }).optional(),
366
+ "iterationReceipts": z.array(z.object({
367
+ "iteration": z.number(),
368
+ "startedAt": z.number(),
369
+ "completedAt": z.number(),
370
+ "checkConclusion": z.string(),
371
+ "failureSummary": z.string().optional(),
372
+ "actionTaken": z.string(),
373
+ "commitSha": z.string().optional(),
374
+ "filesChanged": z.array(z.string()).optional(),
375
+ "agentConfidence": z.number().optional(),
376
+ "errorSignature": z.string().optional()
377
+ })).optional(),
378
+ "iterationCount": z.number().optional(),
379
+ "maxIterations": z.number().optional(),
380
+ "lastCheckConclusion": z.string().optional(),
381
+ "stopReason": z.string().optional(),
382
+ "iterationPolicy": z.object({
383
+ "maxIterations": z.number(),
384
+ "pollIntervalMs": z.number(),
385
+ "flakeThreshold": z.number(),
386
+ "confidenceFloor": z.number()
387
+ }).optional(),
388
+ "attemptCount": z.number(),
389
+ "maxAttempts": z.number(),
390
+ "createdAt": z.number(),
391
+ "updatedAt": z.number()
392
+ }),
393
+ indices: [
394
+ { kind: "index", name: "by_status", columns: ["status"] },
395
+ { kind: "index", name: "by_dedupeKey", columns: ["dedupeKey"] },
396
+ { kind: "index", name: "by_sentryIssueId", columns: ["sentryIssueId"] },
397
+ { kind: "index", name: "by_status_createdAt", columns: ["status", "createdAt"] },
398
+ { kind: "index", name: "by_environment", columns: ["environment"] },
399
+ { kind: "index", name: "by_claimedBy", columns: ["claimedBy"] },
400
+ { kind: "index", name: "by_createdAt", columns: ["createdAt"] }
401
+ ]
402
+ });
403
+ var backgroundJobRuns = defineTable({
404
+ name: "backgroundJobRuns",
405
+ component: "kernel",
406
+ category: "infra",
407
+ shape: z.object({
408
+ "jobKey": z.string(),
409
+ "scheduler": z.string(),
410
+ "triggeredBy": z.string(),
411
+ "status": z.enum(["running", "completed", "failed", "skipped"]),
412
+ "startedAt": z.number(),
413
+ "completedAt": z.number().optional(),
414
+ "durationMs": z.number().optional(),
415
+ "resultSummary": z.string().optional(),
416
+ "error": z.string().optional()
417
+ }),
418
+ indices: [
419
+ { kind: "index", name: "by_jobKey", columns: ["jobKey"] },
420
+ { kind: "index", name: "by_startedAt", columns: ["startedAt"] },
421
+ { kind: "index", name: "by_jobKey_startedAt", columns: ["jobKey", "startedAt"] },
422
+ { kind: "index", name: "by_status", columns: ["status"] }
423
+ ]
424
+ });
425
+ var backgroundJobSettings = defineTable({
426
+ name: "backgroundJobSettings",
427
+ component: "kernel",
428
+ category: "infra",
429
+ shape: z.object({
430
+ "jobKey": z.string(),
431
+ "enabled": z.boolean(),
432
+ "notes": z.string().optional(),
433
+ "updatedAt": z.number(),
434
+ "updatedBy": z.string()
435
+ }),
436
+ indices: [
437
+ { kind: "index", name: "by_jobKey", columns: ["jobKey"] },
438
+ { kind: "index", name: "by_enabled", columns: ["enabled"] },
439
+ { kind: "index", name: "by_updatedAt", columns: ["updatedAt"] }
440
+ ]
441
+ });
442
+ var systemLogs = defineTable({
443
+ name: "systemLogs",
444
+ component: "kernel",
445
+ category: "infra",
446
+ shape: z.object({
447
+ "chatId": z.string().optional(),
448
+ "workflowId": z.string().optional(),
449
+ "threadId": z.string().optional(),
450
+ "level": z.string(),
451
+ "source": z.string(),
452
+ "message": z.string(),
453
+ "metadata": z.record(z.any()).optional(),
454
+ "traceId": z.string().optional(),
455
+ "createdAt": z.number()
456
+ }),
457
+ indices: [
458
+ { kind: "index", name: "by_chatId", columns: ["chatId"] },
459
+ { kind: "index", name: "by_workflowId", columns: ["workflowId"] },
460
+ { kind: "index", name: "by_threadId", columns: ["threadId"] },
461
+ { kind: "index", name: "by_traceId", columns: ["traceId"] },
462
+ { kind: "index", name: "by_level", columns: ["level"] },
463
+ { kind: "index", name: "by_source", columns: ["source"] }
464
+ ]
465
+ });
466
+ var beliefConfidence = defineTable({
467
+ name: "beliefConfidence",
468
+ component: "kernel",
469
+ category: "epistemic",
470
+ shape: z.object({
471
+ "beliefId": z.string(),
472
+ "belief": z.number().optional(),
473
+ "disbelief": z.number().optional(),
474
+ "uncertainty": z.number().optional(),
475
+ "baseRate": z.number(),
476
+ "slOperator": z.string().optional(),
477
+ "confidence": z.number(),
478
+ "confidenceLevel": z.enum(["high", "medium", "low"]).optional(),
479
+ "valence": z.number().optional(),
480
+ "certainty": z.number().optional(),
481
+ "assessedAt": z.number(),
482
+ "assessedBy": z.string(),
483
+ "trigger": z.enum(["initial", "evidence_added", "evidence_removed", "contradiction_detected", "contradiction_resolved", "manual", "decay", "propagation", "agent_assessment", "worktree_outcome", "worktree_completed", "fusion", "discount", "deduction", "backfill_synthetic"]),
484
+ "rationale": z.string().optional(),
485
+ "triggeringEvidenceId": z.string().optional(),
486
+ "triggeringEvidenceIds": z.array(z.string()).optional(),
487
+ "triggeringContradictionId": idOf("contradictions").optional(),
488
+ "triggeringWorktreeId": z.string().optional(),
489
+ "triggeringAgentId": z.string().optional(),
490
+ "isAgentAssessment": z.boolean().optional()
491
+ }),
492
+ indices: [
493
+ { kind: "index", name: "by_beliefId", columns: ["beliefId"] },
494
+ { kind: "index", name: "by_beliefId_time", columns: ["beliefId", "assessedAt"] },
495
+ { kind: "index", name: "by_trigger", columns: ["trigger"] }
496
+ ]
497
+ });
498
+ var beliefEvidenceLinks = defineTable({
499
+ name: "beliefEvidenceLinks",
500
+ component: "kernel",
501
+ category: "epistemic",
502
+ shape: z.object({
503
+ "beliefId": z.string(),
504
+ "insightId": z.string(),
505
+ "relation": z.enum(["supports", "contradicts"]),
506
+ "confidence": z.number().optional(),
507
+ "rationale": z.string().optional(),
508
+ "status": z.enum(["suggested", "approved", "dismissed"]).optional(),
509
+ "createdBy": z.string(),
510
+ "createdAt": z.number()
511
+ }),
512
+ indices: [
513
+ { kind: "index", name: "by_beliefId", columns: ["beliefId"] },
514
+ { kind: "index", name: "by_insightId", columns: ["insightId"] },
515
+ { kind: "index", name: "by_relation", columns: ["beliefId", "relation"] },
516
+ { kind: "index", name: "by_status", columns: ["status"] }
517
+ ]
518
+ });
519
+ var beliefHistory = defineTable({
520
+ name: "beliefHistory",
521
+ component: "kernel",
522
+ category: "epistemic",
523
+ shape: z.object({
524
+ "beliefId": z.string(),
525
+ "timestamp": z.number(),
526
+ "previousStatus": z.string().optional(),
527
+ "newStatus": z.string(),
528
+ "justification": z.string().optional(),
529
+ "triggeredByEvidenceIds": z.array(z.string()).optional(),
530
+ "triggeredByUserId": z.string().optional()
531
+ }),
532
+ indices: [
533
+ { kind: "index", name: "by_beliefId", columns: ["beliefId"] }
534
+ ]
535
+ });
536
+ var beliefScenarios = defineTable({
537
+ name: "beliefScenarios",
538
+ component: "kernel",
539
+ category: "epistemic",
540
+ shape: z.object({
541
+ "topicId": z.string().optional(),
542
+ "testedBeliefId": z.string(),
543
+ "scenarioType": z.enum(["falsification", "strengthening", "alternative", "collapse", "critical_path"]),
544
+ "assumedState": z.enum(["false", "true", "weakened", "strengthened"]),
545
+ "title": z.string(),
546
+ "description": z.string(),
547
+ "cascadeEffects": z.array(z.object({
548
+ "beliefId": z.string(),
549
+ "beliefText": z.string(),
550
+ "currentConfidence": z.string(),
551
+ "projectedConfidence": z.string(),
552
+ "reason": z.string()
553
+ })),
554
+ "thesisImpact": z.enum(["thesis_fails", "thesis_weakens", "pillar_fails", "localized", "minimal"]),
555
+ "pillarImpacts": z.array(z.object({
556
+ "pillar": z.string(),
557
+ "impactLevel": z.string(),
558
+ "reason": z.string()
559
+ })).optional(),
560
+ "keyInsights": z.array(z.string()),
561
+ "recommendedActions": z.array(z.object({
562
+ "action": z.string(),
563
+ "priority": z.string(),
564
+ "rationale": z.string()
565
+ })).optional(),
566
+ "sourceWorktreeId": z.string().optional(),
567
+ "sourceChatId": idOf("chats").optional(),
568
+ "sourceMessageId": idOf("messages").optional(),
569
+ "createdAt": z.number(),
570
+ "createdBy": z.string()
571
+ }),
572
+ indices: [
573
+ { kind: "index", name: "by_topicId", columns: ["topicId"] },
574
+ { kind: "index", name: "by_topic_scenarioType", columns: ["topicId", "scenarioType"] },
575
+ { kind: "index", name: "by_topic_thesisImpact", columns: ["topicId", "thesisImpact"] },
576
+ { kind: "index", name: "by_testedBelief", columns: ["testedBeliefId"] },
577
+ { kind: "index", name: "by_sourceWorktreeId", columns: ["sourceWorktreeId"] }
578
+ ]
579
+ });
580
+ var contractEvaluations = defineTable({
581
+ name: "contractEvaluations",
582
+ component: "kernel",
583
+ category: "epistemic",
584
+ shape: z.object({
585
+ "contractId": z.string(),
586
+ "beliefNodeId": z.string(),
587
+ "result": z.enum(["confirmed", "disconfirmed", "partial", "expired", "error", "inconclusive"]),
588
+ "evaluatedAt": z.number(),
589
+ "evaluator": z.string(),
590
+ "trigger": z.string(),
591
+ "resultData": z.union([z.string(), z.number(), z.boolean(), z.null(), z.record(z.any()), z.array(z.any())]).optional(),
592
+ "modulationApplied": z.boolean(),
593
+ "confidenceDelta": z.number().optional(),
594
+ "confidenceBefore": z.number().optional(),
595
+ "confidenceAfter": z.number().optional(),
596
+ "beliefConfidenceId": idOf("beliefConfidence").optional(),
597
+ "modulationRationale": z.string().optional(),
598
+ "topicId": z.string().optional()
599
+ }),
600
+ indices: [
601
+ { kind: "index", name: "by_contract", columns: ["contractId"] },
602
+ { kind: "index", name: "by_contract_time", columns: ["contractId", "evaluatedAt"] },
603
+ { kind: "index", name: "by_belief", columns: ["beliefNodeId"] },
604
+ { kind: "index", name: "by_result", columns: ["result"] },
605
+ { kind: "index", name: "by_time", columns: ["evaluatedAt"] },
606
+ { kind: "index", name: "by_topic_time", columns: ["topicId", "evaluatedAt"] }
607
+ ]
608
+ });
609
+ var contradictions = defineTable({
610
+ name: "contradictions",
611
+ component: "kernel",
612
+ category: "epistemic",
613
+ shape: z.object({
614
+ "topicId": z.string().optional(),
615
+ "beliefId": z.string(),
616
+ "supportingInsightIds": z.array(z.string()),
617
+ "contradictingInsightIds": z.array(z.string()),
618
+ "resolutionStatus": z.enum(["unresolved", "investigating", "accepted_as_permanent", "resolved_by_fork", "resolved_by_evidence", "resolved_by_reinterpretation", "superseded"]),
619
+ "status": z.enum(["unresolved", "investigating", "resolved_support", "resolved_contra", "belief_forked"]).optional(),
620
+ "blocksDecisionFinalization": z.boolean().optional(),
621
+ "blockingReason": z.string().optional(),
622
+ "severity": z.enum(["critical", "significant", "minor"]),
623
+ "aiAnalysis": z.object({
624
+ "summary": z.string(),
625
+ "likelyExplanation": z.string(),
626
+ "suggestedResolution": z.string(),
627
+ "confidenceInAnalysis": z.number(),
628
+ "analyzedAt": z.number()
629
+ }).optional(),
630
+ "resolutionWorktreeId": z.string().optional(),
631
+ "resolution": z.object({
632
+ "verdict": z.string(),
633
+ "reasoning": z.string(),
634
+ "beliefUpdate": z.string(),
635
+ "resolvedBy": z.string()
636
+ }).optional(),
637
+ "resultingBeliefIds": z.array(z.string()).optional(),
638
+ "detectionMethod": z.enum(["semantic", "keyword", "manual", "agent"]).optional(),
639
+ "similarityScore": z.number().optional(),
640
+ "detectedAt": z.number(),
641
+ "resolvedAt": z.number().optional(),
642
+ "lastReviewedAt": z.number().optional(),
643
+ "createdBy": z.string()
644
+ }),
645
+ indices: [
646
+ { kind: "index", name: "by_topicId", columns: ["topicId"] },
647
+ { kind: "index", name: "by_topic_resolutionStatus", columns: ["topicId", "resolutionStatus"] },
648
+ { kind: "index", name: "by_topic_status", columns: ["topicId", "status"] },
649
+ { kind: "index", name: "by_topic_severity", columns: ["topicId", "severity"] },
650
+ { kind: "index", name: "by_topic_blocking", columns: ["topicId", "blocksDecisionFinalization"] },
651
+ { kind: "index", name: "by_beliefId", columns: ["beliefId"] }
652
+ ]
653
+ });
654
+ var epistemicAudit = defineTable({
655
+ name: "epistemicAudit",
656
+ component: "kernel",
657
+ category: "epistemic",
658
+ shape: z.object({
659
+ "entityType": z.enum(["belief", "evidence", "question", "answer", "contradiction", "decision", "proposal", "edge", "node", "entity", "source", "belief_conditional", "belief_scenario", "ontologyDefinition", "ontologyVersion"]),
660
+ "entityId": z.string(),
661
+ "changeType": z.enum(["created", "status_changed", "confidence_changed", "criticality_changed", "formulation_modified", "forked", "superseded", "archived", "resolved", "severity_changed", "edge_added", "edge_removed", "annotated", "blocked", "unblocked", "decision_finalized", "proposal_accepted", "proposal_rejected", "pillar_changed", "updated", "deleted", "entity_merged", "entity_attributes_updated", "entity_archived", "published", "deprecated", "source_created", "source_metadata_updated"]),
662
+ "changedAt": z.number(),
663
+ "changedBy": z.string(),
664
+ "isAgent": z.boolean(),
665
+ "agentType": z.string().optional(),
666
+ "previousState": z.union([z.record(z.any()), z.null()]).optional(),
667
+ "newState": z.union([z.record(z.any()), z.null()]).optional(),
668
+ "rationale": z.string().optional(),
669
+ "triggeringAction": z.string().optional(),
670
+ "topicId": z.string().optional(),
671
+ "proposalId": z.string().optional(),
672
+ "mcpSessionId": z.string().optional(),
673
+ "mcpToolName": z.string().optional(),
674
+ "sourceCommit": z.string().optional()
675
+ }),
676
+ indices: [
677
+ { kind: "index", name: "by_entityId", columns: ["entityId"] },
678
+ { kind: "index", name: "by_entityType", columns: ["entityType"] },
679
+ { kind: "index", name: "by_entityType_id", columns: ["entityType", "entityId"] },
680
+ { kind: "index", name: "by_changedAt", columns: ["changedAt"] },
681
+ { kind: "index", name: "by_changedBy", columns: ["changedBy"] },
682
+ { kind: "index", name: "by_topicId", columns: ["topicId"] },
683
+ { kind: "index", name: "by_changeType", columns: ["changeType"] },
684
+ { kind: "index", name: "by_mcpSessionId", columns: ["mcpSessionId"] }
685
+ ]
686
+ });
687
+ var epistemicContracts = defineTable({
688
+ name: "epistemicContracts",
689
+ component: "kernel",
690
+ category: "epistemic",
691
+ shape: z.object({
692
+ "beliefNodeId": z.string(),
693
+ "contractId": z.string(),
694
+ "title": z.string(),
695
+ "description": z.string().optional(),
696
+ "conditionType": z.enum(["assertion", "temporal", "evidential", "threshold", "composite"]),
697
+ "direction": z.enum(["confirms", "falsifies"]),
698
+ "condition": z.object({
699
+ "expression": z.string(),
700
+ "evaluator": z.string(),
701
+ "evaluatorConfig": z.union([z.string(), z.number(), z.boolean(), z.null(), z.record(z.any()), z.array(z.any())]).optional()
702
+ }),
703
+ "deadline": z.number().optional(),
704
+ "compositeOf": z.array(z.string()).optional(),
705
+ "compositeOperator": z.enum(["all", "any", "majority"]).optional(),
706
+ "modulation": z.object({
707
+ "onConfirmed": z.object({
708
+ "delta": z.number(),
709
+ "ceiling": z.number().optional()
710
+ }),
711
+ "onDisconfirmed": z.object({
712
+ "delta": z.number(),
713
+ "floor": z.number().optional()
714
+ }),
715
+ "onExpired": z.object({
716
+ "delta": z.number()
717
+ }).optional(),
718
+ "onPartial": z.object({
719
+ "threshold": z.number(),
720
+ "delta": z.number()
721
+ }).optional()
722
+ }),
723
+ "evaluationSchedule": z.enum(["on_demand", "on_evidence", "periodic", "event_driven"]),
724
+ "periodicIntervalMs": z.number().optional(),
725
+ "status": z.enum(["active", "satisfied", "violated", "expired", "suspended", "archived"]),
726
+ "lineageSource": z.enum(["declared", "inherited"]),
727
+ "inheritedFromContractId": z.string().optional(),
728
+ "inheritedFromBeliefNodeId": z.string().optional(),
729
+ "inheritedAt": z.number().optional(),
730
+ "lastEvaluatedAt": z.number().optional(),
731
+ "evaluationCount": z.number().optional(),
732
+ "topicId": z.string().optional(),
733
+ "createdAt": z.number(),
734
+ "createdBy": z.string(),
735
+ "updatedAt": z.number()
736
+ }),
737
+ indices: [
738
+ { kind: "index", name: "by_contractId", columns: ["contractId"] },
739
+ { kind: "index", name: "by_belief", columns: ["beliefNodeId"] },
740
+ { kind: "index", name: "by_status", columns: ["status"] },
741
+ { kind: "index", name: "by_evaluator", columns: ["condition.evaluator"] },
742
+ { kind: "index", name: "by_topic", columns: ["topicId"] },
743
+ { kind: "index", name: "by_schedule", columns: ["evaluationSchedule"] }
744
+ ]
745
+ });
746
+ var questionEvidenceLinks = defineTable({
747
+ name: "questionEvidenceLinks",
748
+ component: "kernel",
749
+ category: "epistemic",
750
+ shape: z.object({
751
+ "questionId": z.string(),
752
+ "insightId": z.string(),
753
+ "helpsAnswer": z.boolean(),
754
+ "relevance": z.number().optional(),
755
+ "rationale": z.string().optional(),
756
+ "impactScore": z.number().optional(),
757
+ "impact": z.enum(["supports", "contradicts", "neutral"]).optional(),
758
+ "status": z.enum(["suggested", "approved", "dismissed"]).optional(),
759
+ "createdBy": z.string(),
760
+ "createdAt": z.number()
761
+ }),
762
+ indices: [
763
+ { kind: "index", name: "by_questionId", columns: ["questionId"] },
764
+ { kind: "index", name: "by_insightId", columns: ["insightId"] },
765
+ { kind: "index", name: "by_status", columns: ["status"] }
766
+ ]
767
+ });
768
+ var beliefVotes = defineTable({
769
+ name: "beliefVotes",
770
+ component: "kernel",
771
+ category: "decision",
772
+ shape: z.object({
773
+ "decisionEventId": idOf("decisionEvents"),
774
+ "topicId": z.string().optional(),
775
+ "tenantId": z.string().optional(),
776
+ "workspaceId": z.string().optional(),
777
+ "voterPrincipalId": z.string(),
778
+ "voterUserId": z.string().optional(),
779
+ "voterRole": z.enum(["owner", "facilitator", "decision_maker", "advisor", "observer", "recorder"]).optional(),
780
+ "stakeholderGroupId": idOf("stakeholderGroups").optional(),
781
+ "beliefId": idOf("epistemicNodes"),
782
+ "domainCategory": z.string().optional(),
783
+ "voteDirection": z.enum(["support", "oppose", "abstain", "uncertain"]),
784
+ "confidence": z.number(),
785
+ "probability": z.number().optional(),
786
+ "comment": z.string().optional(),
787
+ "isHingeVote": z.boolean().optional(),
788
+ "status": z.enum(["active", "superseded", "withdrawn"]),
789
+ "supersedesVoteId": idOf("beliefVotes").optional(),
790
+ "supersededByVoteId": idOf("beliefVotes").optional(),
791
+ "weightingModelVersion": z.string(),
792
+ "weightingInput": z.record(z.any()).optional(),
793
+ "effectiveWeight": z.number().optional(),
794
+ "policyTraceId": z.string().optional(),
795
+ "createdBy": z.string(),
796
+ "createdAt": z.number(),
797
+ "updatedAt": z.number()
798
+ }),
799
+ indices: [
800
+ { kind: "index", name: "by_decisionEventId", columns: ["decisionEventId"] },
801
+ { kind: "index", name: "by_topicId", columns: ["topicId"] },
802
+ { kind: "index", name: "by_decision_belief", columns: ["decisionEventId", "beliefId"] },
803
+ { kind: "index", name: "by_decision_belief_voter", columns: ["decisionEventId", "beliefId", "voterPrincipalId"] },
804
+ { kind: "index", name: "by_decision_status", columns: ["decisionEventId", "status"] },
805
+ { kind: "index", name: "by_supersedesVoteId", columns: ["supersedesVoteId"] }
806
+ ]
807
+ });
808
+ var calibrationScores = defineTable({
809
+ name: "calibrationScores",
810
+ component: "kernel",
811
+ category: "decision",
812
+ shape: z.object({
813
+ "principalId": z.string(),
814
+ "topicId": z.string().optional(),
815
+ "tenantId": z.string().optional(),
816
+ "workspaceId": z.string().optional(),
817
+ "decisionEventId": idOf("decisionEvents").optional(),
818
+ "snapshotId": idOf("decisionSnapshots").optional(),
819
+ "scoreType": z.enum(["confidence_alignment", "outcome_accuracy", "weighting_alignment", "readiness_alignment", "brier"]),
820
+ "score": z.number(),
821
+ "inputCount": z.number().optional(),
822
+ "windowStartAt": z.number().optional(),
823
+ "windowEndAt": z.number().optional(),
824
+ "metadata": z.record(z.any()).optional(),
825
+ "createdAt": z.number()
826
+ }),
827
+ indices: [
828
+ { kind: "index", name: "by_principal_createdAt", columns: ["principalId", "createdAt"] },
829
+ { kind: "index", name: "by_topicId", columns: ["topicId"] },
830
+ { kind: "index", name: "by_topic_principal_createdAt", columns: ["topicId", "principalId", "createdAt"] },
831
+ { kind: "index", name: "by_decisionEventId", columns: ["decisionEventId"] },
832
+ { kind: "index", name: "by_snapshotId", columns: ["snapshotId"] },
833
+ { kind: "index", name: "by_tenant_createdAt", columns: ["tenantId", "createdAt"] }
834
+ ]
835
+ });
836
+ var decisionComputedSummaries = defineTable({
837
+ name: "decisionComputedSummaries",
838
+ component: "kernel",
839
+ category: "decision",
840
+ shape: z.object({
841
+ "decisionEventId": idOf("decisionEvents"),
842
+ "topicId": z.string().optional(),
843
+ "tenantId": z.string().optional(),
844
+ "workspaceId": z.string().optional(),
845
+ "summaryKind": z.enum(["contradiction_map", "hinge_fragility", "certainty_map", "unknown_concentration", "risk_ledger_draft", "readiness_breakdown", "quorum_suggestion", "vote_weighting", "cross_group_divergence", "cross_theme_concentration"]),
846
+ "schemaVersion": z.string(),
847
+ "status": z.enum(["draft", "current", "superseded"]),
848
+ "payload": z.record(z.any()),
849
+ "inputHash": z.string().optional(),
850
+ "policyTraceId": z.string().optional(),
851
+ "supersededBySummaryId": idOf("decisionComputedSummaries").optional(),
852
+ "computedBy": z.string().optional(),
853
+ "computedAt": z.number(),
854
+ "createdAt": z.number(),
855
+ "updatedAt": z.number()
856
+ }),
857
+ indices: [
858
+ { kind: "index", name: "by_decisionEventId", columns: ["decisionEventId"] },
859
+ { kind: "index", name: "by_topicId", columns: ["topicId"] },
860
+ { kind: "index", name: "by_topic_kind_createdAt", columns: ["topicId", "summaryKind", "computedAt"] },
861
+ { kind: "index", name: "by_decision_kind_createdAt", columns: ["decisionEventId", "summaryKind", "computedAt"] },
862
+ { kind: "index", name: "by_decision_status", columns: ["decisionEventId", "status"] }
863
+ ]
864
+ });
865
+ var decisionEvents = defineTable({
866
+ name: "decisionEvents",
867
+ component: "kernel",
868
+ category: "decision",
869
+ shape: z.object({
870
+ "eventKey": z.string(),
871
+ "topicId": z.string().optional(),
872
+ "tenantId": z.string().optional(),
873
+ "workspaceId": z.string().optional(),
874
+ "ownerPrincipalId": z.string().optional(),
875
+ "audienceLabel": z.string().optional(),
876
+ "policyTags": z.array(z.string()).optional(),
877
+ "sensitivityTier": z.enum(["low", "medium", "high"]).optional(),
878
+ "exportClass": z.enum(["public_safe", "client_safe", "internal_only"]).optional(),
879
+ "anonymizationClass": z.enum(["none", "standard", "strict"]).optional(),
880
+ "title": z.string(),
881
+ "summary": z.string().optional(),
882
+ "eventType": z.enum(["investment", "deal", "portfolio", "strategy", "operations", "other"]),
883
+ "status": z.enum(["draft", "pre_ic_preparing", "pre_ic_ready", "ic_in_session", "risk_confirmed", "snapshot_locked", "finalized", "reopened", "superseded"]),
884
+ "outcome": z.enum(["approve", "conditional", "defer", "reject", "reopen_on_trigger"]).optional(),
885
+ "scheduledAt": z.number().optional(),
886
+ "startedAt": z.number().optional(),
887
+ "riskConfirmedAt": z.number().optional(),
888
+ "snapshotLockedAt": z.number().optional(),
889
+ "finalizedAt": z.number().optional(),
890
+ "supersedesDecisionEventId": idOf("decisionEvents").optional(),
891
+ "supersededByDecisionEventId": idOf("decisionEvents").optional(),
892
+ "weightingModelVersion": z.string(),
893
+ "weightingParameters": z.record(z.any()).optional(),
894
+ "advisoryReadinessScore": z.number().optional(),
895
+ "advisoryReadinessFactors": z.record(z.any()).optional(),
896
+ "policyTraceId": z.string().optional(),
897
+ "metadata": z.record(z.any()).optional(),
898
+ "createdBy": z.string(),
899
+ "updatedBy": z.string().optional(),
900
+ "createdAt": z.number(),
901
+ "updatedAt": z.number()
902
+ }),
903
+ indices: [
904
+ { kind: "index", name: "by_eventKey", columns: ["eventKey"] },
905
+ { kind: "index", name: "by_topicId", columns: ["topicId"] },
906
+ { kind: "index", name: "by_topic_status", columns: ["topicId", "status"] },
907
+ { kind: "index", name: "by_topic_updatedAt", columns: ["topicId", "updatedAt"] },
908
+ { kind: "index", name: "by_status_scheduledAt", columns: ["status", "scheduledAt"] },
909
+ { kind: "index", name: "by_supersedesDecisionEventId", columns: ["supersedesDecisionEventId"] },
910
+ { kind: "index", name: "by_supersededByDecisionEventId", columns: ["supersededByDecisionEventId"] }
911
+ ]
912
+ });
913
+ var decisionParticipants = defineTable({
914
+ name: "decisionParticipants",
915
+ component: "kernel",
916
+ category: "decision",
917
+ shape: z.object({
918
+ "decisionEventId": idOf("decisionEvents"),
919
+ "topicId": z.string().optional(),
920
+ "tenantId": z.string().optional(),
921
+ "workspaceId": z.string().optional(),
922
+ "principalId": z.string(),
923
+ "userId": z.string().optional(),
924
+ "role": z.enum(["owner", "facilitator", "decision_maker", "advisor", "observer", "recorder"]),
925
+ "stakeholderGroupId": idOf("stakeholderGroups").optional(),
926
+ "weight": z.number().optional(),
927
+ "calibrationWeight": z.number().optional(),
928
+ "status": z.enum(["active", "invited", "removed"]),
929
+ "metadata": z.record(z.any()).optional(),
930
+ "createdBy": z.string(),
931
+ "createdAt": z.number(),
932
+ "updatedAt": z.number()
933
+ }),
934
+ indices: [
935
+ { kind: "index", name: "by_decisionEventId", columns: ["decisionEventId"] },
936
+ { kind: "index", name: "by_topicId", columns: ["topicId"] },
937
+ { kind: "index", name: "by_decision_principal", columns: ["decisionEventId", "principalId"] },
938
+ { kind: "index", name: "by_decision_role", columns: ["decisionEventId", "role"] },
939
+ { kind: "index", name: "by_group", columns: ["stakeholderGroupId"] }
940
+ ]
941
+ });
942
+ var decisionRiskLedger = defineTable({
943
+ name: "decisionRiskLedger",
944
+ component: "kernel",
945
+ category: "decision",
946
+ shape: z.object({
947
+ "decisionEventId": idOf("decisionEvents"),
948
+ "topicId": z.string().optional(),
949
+ "tenantId": z.string().optional(),
950
+ "workspaceId": z.string().optional(),
951
+ "riskType": z.string(),
952
+ "riskDescription": z.string(),
953
+ "relatedBeliefId": idOf("epistemicNodes").optional(),
954
+ "probabilityBand": z.enum(["very_low", "low", "medium", "high", "very_high"]),
955
+ "impactBand": z.enum(["very_low", "low", "medium", "high", "very_high"]),
956
+ "ownerPrincipalId": z.string().optional(),
957
+ "triggerCondition": z.string().optional(),
958
+ "monitoringPlan": z.string().optional(),
959
+ "status": z.enum(["draft", "confirmed", "resolved", "dismissed"]),
960
+ "confirmationMetadata": z.record(z.any()).optional(),
961
+ "confirmedAt": z.number().optional(),
962
+ "confirmedBy": z.string().optional(),
963
+ "metadata": z.record(z.any()).optional(),
964
+ "createdBy": z.string(),
965
+ "createdAt": z.number(),
966
+ "updatedAt": z.number()
967
+ }),
968
+ indices: [
969
+ { kind: "index", name: "by_decisionEventId", columns: ["decisionEventId"] },
970
+ { kind: "index", name: "by_topicId", columns: ["topicId"] },
971
+ { kind: "index", name: "by_topic_status", columns: ["topicId", "status"] },
972
+ { kind: "index", name: "by_decision_status", columns: ["decisionEventId", "status"] }
973
+ ]
974
+ });
975
+ var decisionSnapshots = defineTable({
976
+ name: "decisionSnapshots",
977
+ component: "kernel",
978
+ category: "decision",
979
+ shape: z.object({
980
+ "decisionEventId": idOf("decisionEvents"),
981
+ "topicId": z.string().optional(),
982
+ "tenantId": z.string().optional(),
983
+ "workspaceId": z.string().optional(),
984
+ "ownerPrincipalId": z.string().optional(),
985
+ "audienceLabel": z.string().optional(),
986
+ "policyTags": z.array(z.string()).optional(),
987
+ "sensitivityTier": z.enum(["low", "medium", "high"]).optional(),
988
+ "exportClass": z.enum(["public_safe", "client_safe", "internal_only"]).optional(),
989
+ "anonymizationClass": z.enum(["none", "standard", "strict"]).optional(),
990
+ "version": z.number(),
991
+ "snapshotLabel": z.string().optional(),
992
+ "payload": z.record(z.any()),
993
+ "payloadHash": z.string(),
994
+ "weightingModelVersion": z.string(),
995
+ "weightingParameters": z.record(z.any()).optional(),
996
+ "outcome": z.enum(["approve", "conditional", "defer", "reject", "reopen_on_trigger"]).optional(),
997
+ "lineageParentSnapshotId": idOf("decisionSnapshots").optional(),
998
+ "lineageParentDecisionEventId": idOf("decisionEvents").optional(),
999
+ "policyTraceId": z.string().optional(),
1000
+ "metadata": z.record(z.any()).optional(),
1001
+ "lockedBy": z.string(),
1002
+ "lockedAt": z.number(),
1003
+ "createdAt": z.number()
1004
+ }),
1005
+ indices: [
1006
+ { kind: "index", name: "by_decisionEventId", columns: ["decisionEventId"] },
1007
+ { kind: "index", name: "by_topicId", columns: ["topicId"] },
1008
+ { kind: "index", name: "by_topic_lockedAt", columns: ["topicId", "lockedAt"] },
1009
+ { kind: "index", name: "by_decision_version", columns: ["decisionEventId", "version"] },
1010
+ { kind: "index", name: "by_decision_lockedAt", columns: ["decisionEventId", "lockedAt"] },
1011
+ { kind: "index", name: "by_payloadHash", columns: ["payloadHash"] }
1012
+ ]
1013
+ });
1014
+ var deliberationContributions = defineTable({
1015
+ name: "deliberationContributions",
1016
+ component: "kernel",
1017
+ category: "decision",
1018
+ shape: z.object({
1019
+ "sessionId": idOf("deliberationSessions"),
1020
+ "topicId": z.string().optional(),
1021
+ "principalId": z.string(),
1022
+ "slot": z.string(),
1023
+ "modelKey": z.string().optional(),
1024
+ "promptName": z.string().optional(),
1025
+ "role": z.enum(["support", "oppose", "uncertain", "synthesize"]),
1026
+ "answer": z.string(),
1027
+ "confidence": z.number(),
1028
+ "reasoningChain": z.array(z.string()),
1029
+ "uncertaintyZones": z.array(z.object({
1030
+ "label": z.string(),
1031
+ "explanation": z.string()
1032
+ })),
1033
+ "escalationQuestions": z.array(z.string()),
1034
+ "contradictionHypotheses": z.array(z.string()),
1035
+ "rawResponse": z.string(),
1036
+ "parsedResponse": z.any().optional(),
1037
+ "traceId": z.string().optional(),
1038
+ "createdAt": z.number(),
1039
+ "updatedAt": z.number()
1040
+ }),
1041
+ indices: [
1042
+ { kind: "index", name: "by_sessionId", columns: ["sessionId"] },
1043
+ { kind: "index", name: "by_topicId", columns: ["topicId"] },
1044
+ { kind: "index", name: "by_session_slot", columns: ["sessionId", "slot"] }
1045
+ ]
1046
+ });
1047
+ var deliberationSessions = defineTable({
1048
+ name: "deliberationSessions",
1049
+ component: "kernel",
1050
+ category: "decision",
1051
+ shape: z.object({
1052
+ "topicId": z.string().optional(),
1053
+ "tenantId": z.string().optional(),
1054
+ "workspaceId": z.string().optional(),
1055
+ "principalId": z.string(),
1056
+ "question": z.string(),
1057
+ "status": z.enum(["running", "completed", "failed"]),
1058
+ "modelSlots": z.array(z.string()),
1059
+ "linkedBeliefNodeId": idOf("epistemicNodes").optional(),
1060
+ "replayBaselineAt": z.number(),
1061
+ "replayHeadAt": z.number().optional(),
1062
+ "replayBaseline": z.any().optional(),
1063
+ "replayDelta": z.any().optional(),
1064
+ "contextBrief": z.string().optional(),
1065
+ "contextSnapshot": z.any().optional(),
1066
+ "contradictionIds": z.array(idOf("contradictions")),
1067
+ "escalationQuestionIds": z.array(idOf("epistemicNodes")),
1068
+ "uncertaintyZones": z.array(z.object({
1069
+ "label": z.string(),
1070
+ "explanation": z.string(),
1071
+ "slots": z.array(z.string())
1072
+ })),
1073
+ "outcomeSummary": z.any().optional(),
1074
+ "traceId": z.string().optional(),
1075
+ "error": z.string().optional(),
1076
+ "createdBy": z.string(),
1077
+ "createdAt": z.number(),
1078
+ "updatedAt": z.number(),
1079
+ "completedAt": z.number().optional()
1080
+ }),
1081
+ indices: [
1082
+ { kind: "index", name: "by_topicId", columns: ["topicId"] },
1083
+ { kind: "index", name: "by_status", columns: ["status"] },
1084
+ { kind: "index", name: "by_topic_status", columns: ["topicId", "status"] },
1085
+ { kind: "index", name: "by_createdBy", columns: ["createdBy"] }
1086
+ ]
1087
+ });
1088
+ var stakeholderGroups = defineTable({
1089
+ name: "stakeholderGroups",
1090
+ component: "kernel",
1091
+ category: "decision",
1092
+ shape: z.object({
1093
+ "decisionEventId": idOf("decisionEvents"),
1094
+ "topicId": z.string().optional(),
1095
+ "tenantId": z.string().optional(),
1096
+ "workspaceId": z.string().optional(),
1097
+ "groupKey": z.string(),
1098
+ "name": z.string(),
1099
+ "description": z.string().optional(),
1100
+ "weight": z.number(),
1101
+ "status": z.enum(["active", "archived"]),
1102
+ "metadata": z.record(z.any()).optional(),
1103
+ "createdBy": z.string(),
1104
+ "createdAt": z.number(),
1105
+ "updatedAt": z.number()
1106
+ }),
1107
+ indices: [
1108
+ { kind: "index", name: "by_decisionEventId", columns: ["decisionEventId"] },
1109
+ { kind: "index", name: "by_topicId", columns: ["topicId"] },
1110
+ { kind: "index", name: "by_decision_groupKey", columns: ["decisionEventId", "groupKey"] },
1111
+ { kind: "index", name: "by_decision_status", columns: ["decisionEventId", "status"] }
1112
+ ]
1113
+ });
1114
+ var compatibilityShims = defineTable({
1115
+ name: "compatibilityShims",
1116
+ component: "mc",
1117
+ category: "runtime",
1118
+ shape: z.object({
1119
+ "shimId": z.string(),
1120
+ "gateId": z.string(),
1121
+ "removalDate": z.string(),
1122
+ "removalPriority": z.enum(["P1", "P2", "P3"]),
1123
+ "description": z.string(),
1124
+ "owner": z.string(),
1125
+ "createdAt": z.string(),
1126
+ "status": z.enum(["active", "overdue", "removed"]),
1127
+ "bridgeType": z.enum(["tool", "agent"]),
1128
+ "bridgeTarget": z.object({
1129
+ "type": z.enum(["tool", "agent"]),
1130
+ "legacyPath": z.string(),
1131
+ "harnessPath": z.string()
1132
+ }),
1133
+ "shimBehavior": z.enum(["passthrough_with_logging", "adapter", "feature_flag_gate"]),
1134
+ "producesLedgerEntries": z.boolean(),
1135
+ "lastAuditedAt": z.number(),
1136
+ "metadata": z.record(z.any()).optional()
1137
+ }),
1138
+ indices: [
1139
+ { kind: "index", name: "by_shimId", columns: ["shimId"] },
1140
+ { kind: "index", name: "by_status", columns: ["status"] },
1141
+ { kind: "index", name: "by_bridgeType_status", columns: ["bridgeType", "status"] }
1142
+ ]
1143
+ });
1144
+ var cutoverFlags = defineTable({
1145
+ name: "cutoverFlags",
1146
+ component: "mc",
1147
+ category: "runtime",
1148
+ shape: z.object({
1149
+ "domain": z.enum(["graph", "schema", "identity", "policy", "audit", "admin", "agent", "tool", "prompt", "intelligence"]),
1150
+ "state": z.enum(["legacy", "cutover", "disabled"]),
1151
+ "metadata": z.record(z.any()).optional(),
1152
+ "updatedBy": z.string(),
1153
+ "createdAt": z.number(),
1154
+ "updatedAt": z.number()
1155
+ }),
1156
+ indices: [
1157
+ { kind: "index", name: "by_domain", columns: ["domain"] },
1158
+ { kind: "index", name: "by_state", columns: ["state"] }
1159
+ ]
1160
+ });
1161
+ var tenantDeploymentCredentials = defineTable({
1162
+ name: "tenantDeploymentCredentials",
1163
+ component: "mc",
1164
+ category: "runtime",
1165
+ shape: z.object({
1166
+ "credentialRef": z.string(),
1167
+ "tenantId": idOf("tenants"),
1168
+ "target": z.enum(["kernelDeployment", "appDeployment"]),
1169
+ "environment": z.enum(["dev", "prod"]),
1170
+ "encryptedDeployKey": z.string(),
1171
+ "encryptionVersion": z.string(),
1172
+ "keyFingerprint": z.string(),
1173
+ "keyHint": z.string(),
1174
+ "status": z.enum(["active", "revoked"]),
1175
+ "rotatedFromCredentialRef": z.string().optional(),
1176
+ "revokedAt": z.number().optional(),
1177
+ "revokedBy": z.string().optional(),
1178
+ "lastUsedAt": z.number().optional(),
1179
+ "metadata": z.record(z.any()).optional(),
1180
+ "createdBy": z.string(),
1181
+ "createdAt": z.number(),
1182
+ "updatedAt": z.number()
1183
+ }),
1184
+ indices: [
1185
+ { kind: "index", name: "by_credentialRef", columns: ["credentialRef"] },
1186
+ { kind: "index", name: "by_tenantId", columns: ["tenantId"] },
1187
+ { kind: "index", name: "by_tenant_target", columns: ["tenantId", "target"] },
1188
+ { kind: "index", name: "by_tenant_target_environment", columns: ["tenantId", "target", "environment"] },
1189
+ { kind: "index", name: "by_tenant_target_environment_status", columns: ["tenantId", "target", "environment", "status"] },
1190
+ { kind: "index", name: "by_status", columns: ["status"] }
1191
+ ]
1192
+ });
1193
+ var controlPlaneTenantModelSlotBindings = defineTable({
1194
+ name: "controlPlaneTenantModelSlotBindings",
1195
+ component: "mc",
1196
+ category: "runtime",
1197
+ shape: z.object({
1198
+ "bindingId": z.string(),
1199
+ "tenantId": idOf("tenants"),
1200
+ "providerId": z.string(),
1201
+ "modelSlotId": z.string(),
1202
+ "secretRef": z.string(),
1203
+ "status": z.enum(["active", "revoked"]),
1204
+ "passThroughOnly": z.boolean(),
1205
+ "revokedAt": z.number().optional(),
1206
+ "revokedBy": z.string().optional(),
1207
+ "metadata": z.record(z.any()).optional(),
1208
+ "createdBy": z.string(),
1209
+ "createdAt": z.number(),
1210
+ "updatedAt": z.number()
1211
+ }),
1212
+ indices: [
1213
+ { kind: "index", name: "by_bindingId", columns: ["bindingId"] },
1214
+ { kind: "index", name: "by_tenantId", columns: ["tenantId"] },
1215
+ { kind: "index", name: "by_tenant_slot", columns: ["tenantId", "modelSlotId"] },
1216
+ { kind: "index", name: "by_tenant_provider_slot", columns: ["tenantId", "providerId", "modelSlotId"] },
1217
+ { kind: "index", name: "by_secretRef", columns: ["secretRef"] },
1218
+ { kind: "index", name: "by_status", columns: ["status"] }
1219
+ ]
1220
+ });
1221
+ var controlPlaneTenantProviderSecrets = defineTable({
1222
+ name: "controlPlaneTenantProviderSecrets",
1223
+ component: "mc",
1224
+ category: "runtime",
1225
+ shape: z.object({
1226
+ "secretRef": z.string(),
1227
+ "tenantId": idOf("tenants"),
1228
+ "providerId": z.string(),
1229
+ "label": z.string().optional(),
1230
+ "encryptedSecret": z.string(),
1231
+ "encryptionVersion": z.string(),
1232
+ "secretFingerprint": z.string(),
1233
+ "keyHint": z.string(),
1234
+ "status": z.enum(["active", "revoked"]),
1235
+ "rotatedFromSecretRef": z.string().optional(),
1236
+ "revokedAt": z.number().optional(),
1237
+ "revokedBy": z.string().optional(),
1238
+ "lastUsedAt": z.number().optional(),
1239
+ "metadata": z.record(z.any()).optional(),
1240
+ "createdBy": z.string(),
1241
+ "createdAt": z.number(),
1242
+ "updatedAt": z.number()
1243
+ }),
1244
+ indices: [
1245
+ { kind: "index", name: "by_secretRef", columns: ["secretRef"] },
1246
+ { kind: "index", name: "by_tenantId", columns: ["tenantId"] },
1247
+ { kind: "index", name: "by_tenant_provider", columns: ["tenantId", "providerId"] },
1248
+ { kind: "index", name: "by_tenant_provider_status", columns: ["tenantId", "providerId", "status"] },
1249
+ { kind: "index", name: "by_status", columns: ["status"] }
1250
+ ]
1251
+ });
1252
+ var controlPlaneTenantProxyGatewayUsage = defineTable({
1253
+ name: "controlPlaneTenantProxyGatewayUsage",
1254
+ component: "mc",
1255
+ category: "runtime",
1256
+ shape: z.object({
1257
+ "usageId": z.string(),
1258
+ "tenantId": idOf("tenants"),
1259
+ "providerId": z.string(),
1260
+ "modelSlotId": z.string(),
1261
+ "secretRef": z.string(),
1262
+ "proxyTokenId": z.string(),
1263
+ "sessionId": z.string(),
1264
+ "principalId": z.string(),
1265
+ "workspaceId": z.string().optional(),
1266
+ "modelId": z.string().optional(),
1267
+ "requestPath": z.string(),
1268
+ "status": z.enum(["success", "error"]),
1269
+ "responseStatus": z.number().optional(),
1270
+ "inputTokens": z.number().optional(),
1271
+ "outputTokens": z.number().optional(),
1272
+ "tokenCount": z.number().optional(),
1273
+ "latencyMs": z.number(),
1274
+ "estimatedCostUsd": z.number().optional(),
1275
+ "failureCode": z.string().optional(),
1276
+ "metadata": z.record(z.any()).optional(),
1277
+ "createdAt": z.number(),
1278
+ "updatedAt": z.number()
1279
+ }),
1280
+ indices: [
1281
+ { kind: "index", name: "by_usageId", columns: ["usageId"] },
1282
+ { kind: "index", name: "by_tenantId", columns: ["tenantId", "createdAt"] },
1283
+ { kind: "index", name: "by_tenant_provider", columns: ["tenantId", "providerId", "createdAt"] },
1284
+ { kind: "index", name: "by_proxyTokenId", columns: ["proxyTokenId", "createdAt"] },
1285
+ { kind: "index", name: "by_sessionId", columns: ["sessionId", "createdAt"] }
1286
+ ]
1287
+ });
1288
+ var crossProjectConnections = defineTable({
1289
+ name: "crossProjectConnections",
1290
+ component: "kernel",
1291
+ category: "intelligence",
1292
+ shape: z.object({
1293
+ "sourceProjectId": z.string().optional(),
1294
+ "sourceTopicId": idOf("topics").optional(),
1295
+ "sourceNodeId": idOf("epistemicNodes"),
1296
+ "targetProjectId": z.string().optional(),
1297
+ "targetTopicId": idOf("topics").optional(),
1298
+ "targetNodeId": idOf("epistemicNodes"),
1299
+ "semanticSimilarity": z.number(),
1300
+ "matchSignals": z.object({
1301
+ "beliefTextSimilarity": z.number(),
1302
+ "themeOverlap": z.boolean(),
1303
+ "sharedThemeNames": z.array(z.string()).optional(),
1304
+ "themeSimilarity": z.number().optional(),
1305
+ "ontologyOverlap": z.boolean(),
1306
+ "sharedFunctions": z.array(z.string()).optional(),
1307
+ "sharedValueChains": z.array(z.string()).optional()
1308
+ }),
1309
+ "suggestedEdgeType": z.string(),
1310
+ "suggestedWeight": z.number().optional(),
1311
+ "rationale": z.string(),
1312
+ "decision": z.enum(["pending", "accepted", "declined"]),
1313
+ "acceptedEdgeId": idOf("epistemicEdges").optional(),
1314
+ "declineReason": z.string().optional(),
1315
+ "declineCategory": z.enum(["not_relevant", "too_generic", "already_known", "different_context", "wrong_relationship", "premature", "other"]).optional(),
1316
+ "surfacedDuring": z.enum(["worktree_clustering", "chat", "morning_brief", "manual"]),
1317
+ "worktreeId": z.string().optional(),
1318
+ "userId": z.string(),
1319
+ "createdAt": z.number(),
1320
+ "decidedAt": z.number().optional()
1321
+ }),
1322
+ indices: [
1323
+ { kind: "index", name: "by_source_project", columns: ["sourceProjectId"] },
1324
+ { kind: "index", name: "by_sourceTopicId", columns: ["sourceTopicId"] },
1325
+ { kind: "index", name: "by_target_project", columns: ["targetProjectId"] },
1326
+ { kind: "index", name: "by_targetTopicId", columns: ["targetTopicId"] },
1327
+ { kind: "index", name: "by_source_node", columns: ["sourceNodeId"] },
1328
+ { kind: "index", name: "by_decision", columns: ["decision"] },
1329
+ { kind: "index", name: "by_user_decision", columns: ["userId", "decision"] }
1330
+ ]
1331
+ });
1332
+ var graphAnalysisCache = defineTable({
1333
+ name: "graphAnalysisCache",
1334
+ component: "kernel",
1335
+ category: "intelligence",
1336
+ shape: z.object({
1337
+ "topicId": z.string().optional(),
1338
+ "healthScore": z.number(),
1339
+ "findings": z.array(z.object({
1340
+ "id": z.string(),
1341
+ "severity": z.enum(["critical", "warning", "info"]),
1342
+ "category": z.enum(["structural_risk", "evidence_gap", "reasoning_flaw", "staleness", "opportunity", "propagation_risk", "epistemology", "temporal", "semantic_gap"]),
1343
+ "title": z.string(),
1344
+ "description": z.string(),
1345
+ "nodeIds": z.array(z.string()),
1346
+ "nodeLabels": z.array(z.string()),
1347
+ "detector": z.string(),
1348
+ "importance": z.number().optional(),
1349
+ "totalCount": z.number().optional()
1350
+ })),
1351
+ "stats": z.object({
1352
+ "totalNodes": z.number(),
1353
+ "totalEdges": z.number(),
1354
+ "beliefs": z.number(),
1355
+ "questions": z.number(),
1356
+ "evidence": z.number(),
1357
+ "cycleCount": z.number(),
1358
+ "ungroundedCount": z.number(),
1359
+ "bridgeNodeCount": z.number(),
1360
+ "orphanCount": z.number(),
1361
+ "overconfidentCount": z.number(),
1362
+ "communityCount": z.number(),
1363
+ "sccCount": z.number(),
1364
+ "algebraicConnectivity": z.number(),
1365
+ "coherenceScore": z.number(),
1366
+ "averageResilience": z.number(),
1367
+ "tensionPairs": z.number(),
1368
+ "propagationRisks": z.number(),
1369
+ "temporalDecayCount": z.number(),
1370
+ "beliefStatus": z.object({
1371
+ "assumption": z.number(),
1372
+ "hypothesis": z.number(),
1373
+ "belief": z.number(),
1374
+ "fact": z.number()
1375
+ }).optional(),
1376
+ "evidenceTemporalNature": z.object({
1377
+ "factual": z.number(),
1378
+ "forecast": z.number(),
1379
+ "unknown": z.number()
1380
+ }).optional()
1381
+ }),
1382
+ "killerQueryResults": z.object({
1383
+ "confirmationBias": z.array(z.any()).optional(),
1384
+ "anchoringBias": z.array(z.any()).optional(),
1385
+ "sourceConcentration": z.array(z.any()).optional(),
1386
+ "contradictionTensions": z.array(z.any()).optional(),
1387
+ "reasoningDepth": z.array(z.any()).optional(),
1388
+ "knowledgeFrontier": z.array(z.any()).optional(),
1389
+ "portfolioConviction": z.array(z.any()).optional(),
1390
+ "staleThemes": z.array(z.any()).optional(),
1391
+ "missingQuestions": z.array(z.any()).optional(),
1392
+ "nonConsensusBeliefs": z.array(z.any()).optional(),
1393
+ "minimumFalsificationSet": z.union([z.string(), z.number(), z.boolean(), z.null(), z.record(z.any()), z.array(z.any())]).optional()
1394
+ }).optional(),
1395
+ "analyzedAt": z.number(),
1396
+ "isStale": z.boolean(),
1397
+ "changesSinceRefresh": z.number(),
1398
+ "lastGraphChange": z.number().optional(),
1399
+ "analysisVersion": z.string()
1400
+ }),
1401
+ indices: [
1402
+ { kind: "index", name: "by_topic", columns: ["topicId"] },
1403
+ { kind: "index", name: "by_topic_stale", columns: ["topicId", "isStale"] },
1404
+ { kind: "index", name: "by_analyzedAt", columns: ["analyzedAt"] }
1405
+ ]
1406
+ });
1407
+ var graphAnalysisResults = defineTable({
1408
+ name: "graphAnalysisResults",
1409
+ component: "kernel",
1410
+ category: "intelligence",
1411
+ shape: z.object({
1412
+ "topicId": z.string().optional(),
1413
+ "userId": z.string(),
1414
+ "findingId": z.string().optional(),
1415
+ "customQuery": z.string().optional(),
1416
+ "mode": z.enum(["explain", "query"]),
1417
+ "analysisText": z.string(),
1418
+ "modelId": z.string().optional(),
1419
+ "findingSnapshot": z.object({
1420
+ "title": z.string(),
1421
+ "description": z.string(),
1422
+ "severity": z.string(),
1423
+ "category": z.string(),
1424
+ "nodeIds": z.array(z.string()),
1425
+ "nodeLabels": z.array(z.string())
1426
+ }).optional(),
1427
+ "status": z.enum(["active", "archived", "deleted"]),
1428
+ "createdAt": z.number(),
1429
+ "archivedAt": z.number().optional()
1430
+ }),
1431
+ indices: [
1432
+ { kind: "index", name: "by_topicId", columns: ["topicId"] },
1433
+ { kind: "index", name: "by_topic_user", columns: ["topicId", "userId"] },
1434
+ { kind: "index", name: "by_topic_finding", columns: ["topicId", "findingId"] },
1435
+ { kind: "index", name: "by_topic_status", columns: ["topicId", "status"] },
1436
+ { kind: "index", name: "by_createdAt", columns: ["createdAt"] }
1437
+ ]
1438
+ });
1439
+ var graphSuggestions = defineTable({
1440
+ name: "graphSuggestions",
1441
+ component: "kernel",
1442
+ category: "intelligence",
1443
+ shape: z.object({
1444
+ "topicId": z.string().optional(),
1445
+ "userId": z.string(),
1446
+ "analysisResultId": idOf("graphAnalysisResults"),
1447
+ "suggestionHash": z.string(),
1448
+ "suggestionType": z.string(),
1449
+ "title": z.string(),
1450
+ "rationale": z.string(),
1451
+ "priority": z.enum(["critical", "high", "medium", "low"]),
1452
+ "targetNodeId": z.string().optional(),
1453
+ "secondaryNodeId": z.string().optional(),
1454
+ "payload": z.union([z.string(), z.number(), z.boolean(), z.null(), z.record(z.any()), z.array(z.any())]),
1455
+ "status": z.enum(["pending", "accepted", "declined", "failed", "superseded"]),
1456
+ "resultNodeId": z.string().optional(),
1457
+ "errorMessage": z.string().optional(),
1458
+ "createdAt": z.number(),
1459
+ "actedAt": z.number().optional()
1460
+ }),
1461
+ indices: [
1462
+ { kind: "index", name: "by_analysis", columns: ["analysisResultId"] },
1463
+ { kind: "index", name: "by_suggestion_hash", columns: ["topicId", "suggestionHash"] },
1464
+ { kind: "index", name: "by_topicId", columns: ["topicId"] },
1465
+ { kind: "index", name: "by_topic_user", columns: ["topicId", "userId"] },
1466
+ { kind: "index", name: "by_topic_status", columns: ["topicId", "status"] },
1467
+ { kind: "index", name: "by_createdAt", columns: ["createdAt"] }
1468
+ ]
1469
+ });
1470
+ var NODE_TYPE = z.enum(["decision", "belief", "question", "theme", "deal", "topic", "claim", "evidence", "synthesis", "answer", "atomic_fact", "excerpt", "source", "company", "person", "investor", "function", "value_chain"]);
1471
+ var EDGE_TYPE = z.enum(["supports", "informs", "depends_on", "extracted_from", "contains", "tests", "supersedes", "responds_to", "belongs_to", "relates_to_thesis", "works_at", "invested_in", "competes_with", "participates_in", "founded_by", "evaluates", "performs", "function_in", "impacts", "raised_from", "mentioned_in", "perspective_on", "plays_theme", "answers", "explores", "qualifies", "based_on", "based_on_belief", "based_on_question", "blocked_by_contradiction", "informed_by_theme", "same_as", "reinforces", "parent_of", "child_of", "falsified_by", "exclusive_with", "collapses_if", "cascade_from", "counterfactual_of", "cascade_to", "mutually_exclusive", "correlates_with", "amplifies", "precondition_for", "in_tension_with", "strengthened_by", "weakened_by", "alternative_to", "subsumes", "validated_by", "required_for", "blocks", "prerequisite_for", "parallel_to", "corroborates", "extends", "same_source_as", "same_theme_as", "assumes", "would_predict", "analogous_to", "independent_of", "implements", "violates", "co_changes_with", "migrating_from", "migrating_to", "scoped_by", "about_entity", "entity_referenced_in", "contradicts", "cites", "summarizes", "related_to", "partially_answers", "refines", "branches_from"]);
1472
+ var TOPIC_STATUS = z.enum(["active", "archived", "watching"]);
1473
+ var TOPIC_VISIBILITY = z.enum(["private", "team", "firm", "external", "public"]);
1474
+
1475
+ // src/schemas/tables/kernel/spine.ts
1476
+ var epistemicEdges = defineTable({
1477
+ name: "epistemicEdges",
1478
+ component: "kernel",
1479
+ category: "spine",
1480
+ shape: z.object({
1481
+ "globalId": z.string(),
1482
+ "fromNodeId": z.string(),
1483
+ "toNodeId": z.string().optional(),
1484
+ "sourceGlobalId": z.string().optional(),
1485
+ "targetGlobalId": z.string().optional(),
1486
+ "edgeType": EDGE_TYPE,
1487
+ "edgeTier": z.string().optional(),
1488
+ "domainNamespace": z.string().optional(),
1489
+ "constraint": z.string().optional(),
1490
+ "normalization": z.string().optional(),
1491
+ "causal": z.boolean().optional(),
1492
+ "propagation": z.string().optional(),
1493
+ "blocking": z.boolean().optional(),
1494
+ "implicit": z.boolean().optional(),
1495
+ "conditionalA": z.object({
1496
+ "b": z.number(),
1497
+ "d": z.number(),
1498
+ "u": z.number(),
1499
+ "a": z.number()
1500
+ }).optional(),
1501
+ "conditionalNotA": z.object({
1502
+ "b": z.number(),
1503
+ "d": z.number(),
1504
+ "u": z.number(),
1505
+ "a": z.number()
1506
+ }).optional(),
1507
+ "derivation": z.string().optional(),
1508
+ "containment": z.string().optional(),
1509
+ "interrogation": z.string().optional(),
1510
+ "weight": z.number().optional(),
1511
+ "confidence": z.number().optional(),
1512
+ "context": z.string().optional(),
1513
+ "reasoningMethod": z.enum(["deductive", "inductive", "abductive", "analogical", "causal", "correlational", "testimonial", "statistical", "implicit", "pattern_match"]).optional(),
1514
+ "logicalRole": z.enum(["necessary", "sufficient", "necessary_sufficient", "contributory", "corroborative"]).optional(),
1515
+ "surpriseScore": z.number().optional(),
1516
+ "validFrom": z.number().optional(),
1517
+ "validUntil": z.number().optional(),
1518
+ "temporalClass": z.enum(["structural", "cyclical", "transient", "point_in_time"]).optional(),
1519
+ "analogyBasis": z.string().optional(),
1520
+ "disanalogies": z.array(z.string()).optional(),
1521
+ "analogyStrength": z.number().optional(),
1522
+ "defeatType": z.enum(["rebuts", "undercuts", "undermines"]).optional(),
1523
+ "predictionFulfilled": z.boolean().optional(),
1524
+ "predictionFulfilledAt": z.number().optional(),
1525
+ "predictionFulfilledBy": z.string().optional(),
1526
+ "derivationType": z.string().optional(),
1527
+ "startDate": z.number().optional(),
1528
+ "endDate": z.number().optional(),
1529
+ "keywords": z.array(z.string()).optional(),
1530
+ "evidence": z.string().optional(),
1531
+ "metadata": z.record(z.any()).optional(),
1532
+ "tenantId": z.string().optional(),
1533
+ "workspaceId": z.string().optional(),
1534
+ "ownerPrincipalId": z.string().optional(),
1535
+ "audienceLabel": z.string().optional(),
1536
+ "policyTags": z.array(z.string()).optional(),
1537
+ "sensitivityTier": z.enum(["low", "medium", "high", "restricted"]).optional(),
1538
+ "exportClass": z.enum(["internal_only", "client_safe", "public_safe", "restricted"]).optional(),
1539
+ "anonymizationClass": z.enum(["none", "standard", "strict"]).optional(),
1540
+ "createdBy": z.string(),
1541
+ "createdAt": z.number(),
1542
+ "updatedAt": z.number().optional(),
1543
+ "topicId": z.string().optional(),
1544
+ "projectId": z.string().optional(),
1545
+ "fromNodeType": z.string().optional(),
1546
+ "toNodeType": z.string().optional(),
1547
+ "fromLayer": z.enum(["L4", "L3", "L2", "L1", "ontological", "organizational"]).optional(),
1548
+ "toLayer": z.enum(["L4", "L3", "L2", "L1", "ontological", "organizational"]).optional()
1549
+ }),
1550
+ indices: [
1551
+ { kind: "index", name: "by_globalId", columns: ["globalId"] },
1552
+ { kind: "index", name: "by_from", columns: ["fromNodeId"] },
1553
+ { kind: "index", name: "by_to", columns: ["toNodeId"] },
1554
+ { kind: "index", name: "by_from_type", columns: ["fromNodeId", "edgeType"] },
1555
+ { kind: "index", name: "by_to_type", columns: ["toNodeId", "edgeType"] },
1556
+ { kind: "index", name: "by_topic", columns: ["topicId"] },
1557
+ { kind: "index", name: "by_tenantId", columns: ["tenantId"] },
1558
+ { kind: "index", name: "by_workspaceId", columns: ["workspaceId"] },
1559
+ { kind: "index", name: "by_tenant_workspace", columns: ["tenantId", "workspaceId"] },
1560
+ { kind: "index", name: "by_audienceLabel", columns: ["audienceLabel"] },
1561
+ { kind: "index", name: "by_sensitivityTier", columns: ["sensitivityTier"] },
1562
+ { kind: "index", name: "by_exportClass", columns: ["exportClass"] },
1563
+ { kind: "index", name: "by_type", columns: ["edgeType"] },
1564
+ { kind: "index", name: "by_from_to", columns: ["fromNodeId", "toNodeId"] },
1565
+ { kind: "index", name: "by_fromLayer", columns: ["fromLayer"] },
1566
+ { kind: "index", name: "by_toLayer", columns: ["toLayer"] },
1567
+ { kind: "index", name: "by_layer_pair", columns: ["fromLayer", "toLayer"] },
1568
+ { kind: "index", name: "by_source_global_id", columns: ["sourceGlobalId"] },
1569
+ { kind: "index", name: "by_target_global_id", columns: ["targetGlobalId"] },
1570
+ { kind: "index", name: "by_reasoning_method", columns: ["edgeType", "reasoningMethod"] },
1571
+ { kind: "index", name: "by_logical_role", columns: ["edgeType", "logicalRole"] },
1572
+ { kind: "index", name: "by_temporal_class", columns: ["temporalClass", "validUntil"] },
1573
+ { kind: "index", name: "by_surprise", columns: ["edgeType", "surpriseScore"] }
1574
+ ]
1575
+ });
1576
+ var epistemicNodes = defineTable({
1577
+ name: "epistemicNodes",
1578
+ component: "kernel",
1579
+ category: "spine",
1580
+ shape: z.object({
1581
+ "globalId": z.string(),
1582
+ "nodeType": NODE_TYPE,
1583
+ "epistemicLayer": z.enum(["L4", "L3", "L2", "L1", "ontological", "organizational"]).optional(),
1584
+ "subtype": z.string().optional(),
1585
+ "canonicalText": z.string(),
1586
+ "contentHash": z.string(),
1587
+ "content": z.string().optional(),
1588
+ "contentType": z.string().optional(),
1589
+ "title": z.string().optional(),
1590
+ "tags": z.array(z.string()).optional(),
1591
+ "domain": z.string().optional(),
1592
+ "metadata": z.record(z.any()).optional(),
1593
+ "tenantId": z.string().optional(),
1594
+ "workspaceId": z.string().optional(),
1595
+ "ownerPrincipalId": z.string().optional(),
1596
+ "audienceLabel": z.string().optional(),
1597
+ "policyTags": z.array(z.string()).optional(),
1598
+ "sensitivityTier": z.enum(["low", "medium", "high", "restricted"]).optional(),
1599
+ "exportClass": z.enum(["internal_only", "client_safe", "public_safe", "restricted"]).optional(),
1600
+ "anonymizationClass": z.enum(["none", "standard", "strict"]).optional(),
1601
+ "beliefType": z.string().optional(),
1602
+ "beliefStatus": z.enum(["assumption", "hypothesis", "belief", "fact"]).optional(),
1603
+ "epistemicStatus": z.enum(["hypothesis", "emerging", "established", "challenged", "assumption", "deprecated"]).optional(),
1604
+ "reversibility": z.enum(["irreversible", "hard_to_reverse", "reversible", "trivial"]).optional(),
1605
+ "predictionMeta": z.object({
1606
+ "isPrediction": z.boolean(),
1607
+ "registeredAt": z.number(),
1608
+ "expectedBy": z.number().optional(),
1609
+ "outcome": z.enum(["pending", "confirmed", "disconfirmed", "partial", "expired"]).optional(),
1610
+ "outcomeRecordedAt": z.number().optional(),
1611
+ "outcomeEvidenceId": z.string().optional(),
1612
+ "confidenceAtPrediction": z.number().optional(),
1613
+ "actualVsPredicted": z.string().optional()
1614
+ }).optional(),
1615
+ "consensusView": z.enum(["aligned", "ahead_of", "contrarian", "orthogonal", "unknown"]).optional(),
1616
+ "consensusConfidence": z.number().optional(),
1617
+ "consensusSource": z.string().optional(),
1618
+ "methodology": z.enum(["primary_research", "expert_interview", "customer_interview", "field_observation", "proprietary_data", "desk_research", "regulatory_filing", "news_article", "academic_paper", "ai_synthesis", "ai_extraction"]).optional(),
1619
+ "informationAsymmetry": z.enum(["proprietary", "early", "common"]).optional(),
1620
+ "temporalNature": z.enum(["factual", "forecast", "unknown"]).optional(),
1621
+ "questionType": z.enum(["validation", "falsification", "assumption_probe", "prediction_test", "counterfactual", "discovery", "clarification", "comparison", "causal", "mechanism", "general"]).optional(),
1622
+ "questionPriority": z.enum(["critical", "high", "medium", "low"]).optional(),
1623
+ "answerQuality": z.enum(["definitive", "strong", "moderate", "weak", "speculative", "unanswered"]).optional(),
1624
+ "themeConviction": z.enum(["high", "medium", "low", "negative"]).optional(),
1625
+ "decisionType": z.enum(["invest", "pass", "follow_on", "exit", "deep_dive", "monitor", "deprioritize", "thesis_adopt", "thesis_revise", "thesis_abandon"]).optional(),
1626
+ "decisionOutcome": z.enum(["pending", "successful", "unsuccessful", "mixed", "unknown"]).optional(),
1627
+ "externalIds": z.object({
1628
+ "crunchbase": z.string().optional(),
1629
+ "linkedin": z.string().optional(),
1630
+ "pitchbook": z.string().optional(),
1631
+ "twitter": z.string().optional(),
1632
+ "website": z.string().optional()
1633
+ }).optional(),
1634
+ "sourceType": z.enum(["human", "ai_extracted", "ai_generated", "imported", "system", "verified", "proprietary"]),
1635
+ "aiProvider": z.string().optional(),
1636
+ "extractedFromNodeId": idOf("epistemicNodes").optional(),
1637
+ "extractionModel": z.string().optional(),
1638
+ "extractionPromptName": z.string().optional(),
1639
+ "extractionPromptVersion": z.number().optional(),
1640
+ "extractionTemperature": z.number().optional(),
1641
+ "extractionLangfuseTraceId": z.string().optional(),
1642
+ "groundingVerified": z.boolean().optional(),
1643
+ "groundingConfidence": z.number().optional(),
1644
+ "groundingMatchedText": z.string().optional(),
1645
+ "groundingStartOffset": z.number().optional(),
1646
+ "groundingEndOffset": z.number().optional(),
1647
+ "groundingRejectionReason": z.string().optional(),
1648
+ "confidence": z.number().optional(),
1649
+ "verificationStatus": z.enum(["unverified", "human_verified", "ai_verified", "contradicted", "outdated"]).optional(),
1650
+ "status": z.enum(["active", "superseded", "archived", "deleted"]),
1651
+ "supersededBy": idOf("epistemicNodes").optional(),
1652
+ "topicId": z.string().optional(),
1653
+ "projectId": z.string().optional(),
1654
+ "createdBy": z.string(),
1655
+ "createdAt": z.number(),
1656
+ "updatedAt": z.number(),
1657
+ "syncStatus": z.enum(["synced", "pending_edges", "edge_creation_failed"]).optional(),
1658
+ "syncError": z.string().optional()
1659
+ }),
1660
+ indices: [
1661
+ { kind: "index", name: "by_globalId", columns: ["globalId"] },
1662
+ { kind: "index", name: "by_contentHash", columns: ["contentHash"] },
1663
+ { kind: "index", name: "by_nodeType", columns: ["nodeType"] },
1664
+ { kind: "index", name: "by_subtype", columns: ["nodeType", "subtype"] },
1665
+ { kind: "index", name: "by_domain", columns: ["domain"] },
1666
+ { kind: "index", name: "by_topic", columns: ["topicId"] },
1667
+ { kind: "index", name: "by_topic_type", columns: ["topicId", "nodeType"] },
1668
+ { kind: "index", name: "by_tenantId", columns: ["tenantId"] },
1669
+ { kind: "index", name: "by_workspaceId", columns: ["workspaceId"] },
1670
+ { kind: "index", name: "by_tenant_workspace", columns: ["tenantId", "workspaceId"] },
1671
+ { kind: "index", name: "by_audienceLabel", columns: ["audienceLabel"] },
1672
+ { kind: "index", name: "by_sensitivityTier", columns: ["sensitivityTier"] },
1673
+ { kind: "index", name: "by_exportClass", columns: ["exportClass"] },
1674
+ { kind: "index", name: "by_status", columns: ["status"] },
1675
+ { kind: "index", name: "by_sourceType", columns: ["sourceType"] },
1676
+ { kind: "index", name: "by_verification", columns: ["verificationStatus"] },
1677
+ { kind: "index", name: "by_layer", columns: ["epistemicLayer"] },
1678
+ { kind: "index", name: "by_layer_type", columns: ["epistemicLayer", "nodeType"] },
1679
+ { kind: "index", name: "by_syncStatus", columns: ["syncStatus"] },
1680
+ { kind: "index", name: "by_belief_status", columns: ["nodeType", "beliefStatus"] },
1681
+ { kind: "index", name: "by_epistemic_status", columns: ["nodeType", "epistemicStatus"] },
1682
+ { kind: "index", name: "by_temporal_nature", columns: ["nodeType", "temporalNature"] },
1683
+ { kind: "index", name: "by_methodology", columns: ["nodeType", "methodology"] },
1684
+ { kind: "index", name: "by_reversibility", columns: ["nodeType", "reversibility"] },
1685
+ { kind: "index", name: "by_questionType", columns: ["nodeType", "questionType"] },
1686
+ { kind: "index", name: "by_questionPriority", columns: ["nodeType", "questionPriority"] },
1687
+ { kind: "search", name: "search_canonicalText", searchField: "canonicalText", filterFields: ["nodeType", "topicId", "topicId", "status"] }
1688
+ ]
1689
+ });
1690
+ var epistemicNodeEmbeddings = defineTable({
1691
+ name: "epistemicNodeEmbeddings",
1692
+ component: "kernel",
1693
+ category: "embedding",
1694
+ shape: z.object({
1695
+ "nodeId": idOf("epistemicNodes"),
1696
+ "topicId": z.string().optional(),
1697
+ "nodeType": z.enum(["belief", "question", "evidence", "answer", "synthesis", "theme", "source"]),
1698
+ "embedding": z.array(z.number()),
1699
+ "createdBy": z.string(),
1700
+ "hasAnswer": z.boolean().optional(),
1701
+ "confidence": z.number().optional(),
1702
+ "importance": z.enum(["critical", "high", "medium", "low"]).optional(),
1703
+ "createdAt": z.number(),
1704
+ "updatedAt": z.number().optional()
1705
+ }),
1706
+ indices: [
1707
+ { kind: "index", name: "by_nodeId", columns: ["nodeId"] },
1708
+ { kind: "index", name: "by_topicId_type", columns: ["topicId", "nodeType"] },
1709
+ { kind: "index", name: "by_topicId", columns: ["topicId"] },
1710
+ { kind: "vector", name: "by_embedding", vectorField: "embedding", dimensions: 1024, filterFields: ["nodeType", "createdBy"] }
1711
+ ]
1712
+ });
1713
+ var groupMemberships = defineTable({
1714
+ name: "groupMemberships",
1715
+ component: "mc",
1716
+ category: "identity",
1717
+ shape: z.object({
1718
+ "groupId": idOf("groups"),
1719
+ "principalId": z.string(),
1720
+ "tenantId": idOf("tenants"),
1721
+ "workspaceId": idOf("workspaces").optional(),
1722
+ "status": z.enum(["active", "invited", "revoked"]),
1723
+ "addedBy": z.string().optional(),
1724
+ "createdAt": z.number(),
1725
+ "updatedAt": z.number()
1726
+ }),
1727
+ indices: [
1728
+ { kind: "index", name: "by_groupId", columns: ["groupId"] },
1729
+ { kind: "index", name: "by_principalId", columns: ["principalId"] },
1730
+ { kind: "index", name: "by_principal_group", columns: ["principalId", "groupId"] },
1731
+ { kind: "index", name: "by_status", columns: ["status"] }
1732
+ ]
1733
+ });
1734
+ var groups = defineTable({
1735
+ name: "groups",
1736
+ component: "mc",
1737
+ category: "identity",
1738
+ shape: z.object({
1739
+ "tenantId": idOf("tenants"),
1740
+ "workspaceId": idOf("workspaces").optional(),
1741
+ "groupKey": z.string(),
1742
+ "name": z.string(),
1743
+ "groupType": z.enum(["internal", "external", "system"]),
1744
+ "description": z.string().optional(),
1745
+ "metadata": z.record(z.any()).optional(),
1746
+ "createdAt": z.number(),
1747
+ "updatedAt": z.number()
1748
+ }),
1749
+ indices: [
1750
+ { kind: "index", name: "by_tenantId", columns: ["tenantId"] },
1751
+ { kind: "index", name: "by_workspaceId", columns: ["workspaceId"] },
1752
+ { kind: "index", name: "by_tenantId_groupKey", columns: ["tenantId", "groupKey"] }
1753
+ ]
1754
+ });
1755
+ var memberships = defineTable({
1756
+ name: "memberships",
1757
+ component: "mc",
1758
+ category: "identity",
1759
+ shape: z.object({
1760
+ "principalId": z.string(),
1761
+ "principalRefId": idOf("principals").optional(),
1762
+ "tenantId": idOf("tenants"),
1763
+ "workspaceId": idOf("workspaces").optional(),
1764
+ "role": z.enum(["platform_admin", "tenant_admin", "workspace_admin", "editor", "viewer", "auditor", "service_agent"]),
1765
+ "status": z.enum(["active", "invited", "revoked"]),
1766
+ "source": z.enum(["manual", "sso", "bootstrap", "api", "scim"]),
1767
+ "grantedBy": z.string().optional(),
1768
+ "createdAt": z.number(),
1769
+ "updatedAt": z.number()
1770
+ }),
1771
+ indices: [
1772
+ { kind: "index", name: "by_principalId", columns: ["principalId"] },
1773
+ { kind: "index", name: "by_principal_tenant", columns: ["principalId", "tenantId"] },
1774
+ { kind: "index", name: "by_workspace_principal", columns: ["workspaceId", "principalId"] },
1775
+ { kind: "index", name: "by_tenant_role", columns: ["tenantId", "role"] },
1776
+ { kind: "index", name: "by_status", columns: ["status"] }
1777
+ ]
1778
+ });
1779
+ var principals = defineTable({
1780
+ name: "principals",
1781
+ component: "mc",
1782
+ category: "identity",
1783
+ shape: z.object({
1784
+ "principalId": z.string(),
1785
+ "principalType": z.enum(["user", "group", "service", "external_viewer"]),
1786
+ "clerkId": z.string().optional(),
1787
+ "email": z.string().optional(),
1788
+ "displayName": z.string().optional(),
1789
+ "groupIds": z.array(idOf("groups")).optional(),
1790
+ "tenantId": idOf("tenants").optional(),
1791
+ "workspaceId": idOf("workspaces").optional(),
1792
+ "status": z.enum(["active", "invited", "suspended", "disabled"]),
1793
+ "metadata": z.record(z.any()).optional(),
1794
+ "createdAt": z.number(),
1795
+ "updatedAt": z.number()
1796
+ }),
1797
+ indices: [
1798
+ { kind: "index", name: "by_principalId", columns: ["principalId"] },
1799
+ { kind: "index", name: "by_clerkId", columns: ["clerkId"] },
1800
+ { kind: "index", name: "by_tenantId", columns: ["tenantId"] },
1801
+ { kind: "index", name: "by_workspaceId", columns: ["workspaceId"] },
1802
+ { kind: "index", name: "by_status", columns: ["status"] }
1803
+ ]
1804
+ });
1805
+ var rateLimitWindows = defineTable({
1806
+ name: "rateLimitWindows",
1807
+ component: "mc",
1808
+ category: "identity",
1809
+ shape: z.object({
1810
+ "principalId": z.string(),
1811
+ "keyId": z.string().optional(),
1812
+ "tenantId": idOf("tenants").optional(),
1813
+ "windowType": z.enum(["minute", "hour"]),
1814
+ "windowStartMs": z.number(),
1815
+ "windowEndMs": z.number(),
1816
+ "requestCount": z.number(),
1817
+ "limit": z.number(),
1818
+ "tier": z.enum(["free", "developer", "partner"]),
1819
+ "createdAt": z.number(),
1820
+ "updatedAt": z.number()
1821
+ }),
1822
+ indices: [
1823
+ { kind: "index", name: "by_principal_window", columns: ["principalId", "windowType", "windowStartMs"] },
1824
+ { kind: "index", name: "by_window_type_start", columns: ["windowType", "windowStartMs"] },
1825
+ { kind: "index", name: "by_window_end", columns: ["windowEndMs"] },
1826
+ { kind: "index", name: "by_tier_window_end", columns: ["tier", "windowEndMs"] }
1827
+ ]
1828
+ });
1829
+ var servicePrincipalKeys = defineTable({
1830
+ name: "servicePrincipalKeys",
1831
+ component: "mc",
1832
+ category: "identity",
1833
+ shape: z.object({
1834
+ "keyId": z.string(),
1835
+ "tokenHash": z.string(),
1836
+ "principalId": z.string(),
1837
+ "tenantId": idOf("tenants"),
1838
+ "workspaceId": idOf("workspaces").optional(),
1839
+ "scopes": z.array(z.string()),
1840
+ "environment": z.enum(["sandbox", "production"]),
1841
+ "status": z.enum(["active", "rotating", "rotated", "expired", "revoked"]),
1842
+ "expiresAt": z.number(),
1843
+ "rotationGracePeriod": z.number().optional(),
1844
+ "rotatedToKeyId": z.string().optional(),
1845
+ "rateLimitTier": z.enum(["free", "developer", "partner"]).optional(),
1846
+ "metadata": z.record(z.any()).optional(),
1847
+ "createdBy": z.string(),
1848
+ "revokedBy": z.string().optional(),
1849
+ "revokedAt": z.number().optional(),
1850
+ "lastUsedAt": z.number().optional(),
1851
+ "createdAt": z.number(),
1852
+ "updatedAt": z.number()
1853
+ }),
1854
+ indices: [
1855
+ { kind: "index", name: "by_keyId", columns: ["keyId"] },
1856
+ { kind: "index", name: "by_tokenHash", columns: ["tokenHash"] },
1857
+ { kind: "index", name: "by_principalId", columns: ["principalId"] },
1858
+ { kind: "index", name: "by_tenantId", columns: ["tenantId"] },
1859
+ { kind: "index", name: "by_workspaceId", columns: ["workspaceId"] },
1860
+ { kind: "index", name: "by_status", columns: ["status"] },
1861
+ { kind: "index", name: "by_principal_status", columns: ["principalId", "status"] }
1862
+ ]
1863
+ });
1864
+ var userSessions = defineTable({
1865
+ name: "userSessions",
1866
+ component: "mc",
1867
+ category: "identity",
1868
+ shape: z.object({
1869
+ "sessionId": z.string(),
1870
+ "tenantId": idOf("tenants"),
1871
+ "clerkUserId": z.string(),
1872
+ "principalId": z.string().optional(),
1873
+ "principalType": z.enum(["human", "service", "agent"]).optional(),
1874
+ "workspaceId": z.string().optional(),
1875
+ "apiKeyId": idOf("apiKeys"),
1876
+ "sessionType": z.enum(["user", "agent"]),
1877
+ "authMode": z.enum(["interactive_user", "service_principal", "tenant_api_key", "session_token"]).optional(),
1878
+ "role": z.string().optional(),
1879
+ "scopes": z.array(z.string()).optional(),
1880
+ "delegationChain": z.array(z.object({
1881
+ "principalId": z.string(),
1882
+ "principalType": z.enum(["human", "service", "agent"]),
1883
+ "authMode": z.enum(["interactive_user", "service_principal", "tenant_api_key", "session_token"]).optional(),
1884
+ "sessionId": z.string().optional(),
1885
+ "delegatedAt": z.number().optional(),
1886
+ "reason": z.string().optional()
1887
+ })).optional(),
1888
+ "sourceSessionId": z.string().optional(),
1889
+ "status": z.enum(["active", "expired", "revoked"]),
1890
+ "sessionExpiresAt": z.number().optional(),
1891
+ "jwtIssuedAt": z.number().optional(),
1892
+ "jwtExpiresAt": z.number().optional(),
1893
+ "lastActivityAt": z.number(),
1894
+ "lastValidatedAt": z.number().optional(),
1895
+ "revokedAt": z.number().optional(),
1896
+ "revokedBy": z.string().optional(),
1897
+ "revokeReason": z.string().optional(),
1898
+ "createdAt": z.number(),
1899
+ "updatedAt": z.number()
1900
+ }),
1901
+ indices: [
1902
+ { kind: "index", name: "by_sessionId", columns: ["sessionId"] },
1903
+ { kind: "index", name: "by_sourceSessionId", columns: ["sourceSessionId"] },
1904
+ { kind: "index", name: "by_tenantId", columns: ["tenantId"] },
1905
+ { kind: "index", name: "by_clerkUserId", columns: ["clerkUserId"] },
1906
+ { kind: "index", name: "by_status", columns: ["status"] }
1907
+ ]
1908
+ });
1909
+ var harnessReplays = defineTable({
1910
+ name: "harnessReplays",
1911
+ component: "kernel",
1912
+ category: "platform",
1913
+ shape: z.object({
1914
+ "replayId": z.string(),
1915
+ "runId": z.string(),
1916
+ "traceVersion": z.string(),
1917
+ "status": z.enum(["captured", "partial", "failed"]),
1918
+ "entrypoints": z.array(z.string()),
1919
+ "steps": z.array(z.object({
1920
+ "stepId": z.string(),
1921
+ "phase": z.string(),
1922
+ "kind": z.string(),
1923
+ "status": z.enum(["completed", "failed", "skipped"]),
1924
+ "startedAt": z.number(),
1925
+ "completedAt": z.number().optional(),
1926
+ "summary": z.string().optional(),
1927
+ "metadata": z.record(z.any()).optional()
1928
+ })),
1929
+ "inputSnapshot": z.record(z.any()).optional(),
1930
+ "outputSnapshot": z.record(z.any()).optional(),
1931
+ "sandboxAudit": z.array(z.record(z.any())).optional(),
1932
+ "workflowReceipt": z.record(z.any()).optional(),
1933
+ "metadata": z.record(z.any()).optional(),
1934
+ "createdAt": z.number()
1935
+ }),
1936
+ indices: [
1937
+ { kind: "index", name: "by_replayId", columns: ["replayId"] },
1938
+ { kind: "index", name: "by_runId", columns: ["runId"] },
1939
+ { kind: "index", name: "by_status_createdAt", columns: ["status", "createdAt"] }
1940
+ ]
1941
+ });
1942
+ var harnessRuns = defineTable({
1943
+ name: "harnessRuns",
1944
+ component: "kernel",
1945
+ category: "platform",
1946
+ shape: z.object({
1947
+ "runId": z.string(),
1948
+ "replayId": z.string().optional(),
1949
+ "agentId": z.string(),
1950
+ "agentVersion": z.string().optional(),
1951
+ "runKind": z.enum(["sandbox", "live_runner", "workflow", "bi", "chat", "sdk", "mcp", "external"]),
1952
+ "executionAdapter": z.enum(["convex_mutation", "convex_action", "http_callback", "mcp_tool", "sdk_invocation", "external_observed"]),
1953
+ "principalId": z.string(),
1954
+ "tenantId": z.string(),
1955
+ "workspaceId": z.string().optional(),
1956
+ "authMode": z.enum(["interactive_user", "service_principal"]),
1957
+ "environment": z.enum(["sandbox", "production"]),
1958
+ "promptReleaseChannel": z.enum(["dev", "staging", "prod"]),
1959
+ "isolationMode": z.enum(["sandbox", "direct", "workflow", "observed"]).optional(),
1960
+ "langfuseTraceId": z.string().optional(),
1961
+ "chatId": z.string().optional(),
1962
+ "worktreeId": z.string().optional(),
1963
+ "topicId": z.string().optional(),
1964
+ "startedAt": z.number(),
1965
+ "completedAt": z.number().optional(),
1966
+ "durationMs": z.number().optional(),
1967
+ "status": z.enum(["running", "completed", "failed", "timeout"]),
1968
+ "outcome": z.object({
1969
+ "verdict": z.enum(["success", "partial", "failure", "timeout", "cancelled"]),
1970
+ "summary": z.string(),
1971
+ "errorCategory": z.enum(["policy_denied", "tool_execution", "prompt_resolution", "model_error", "timeout", "heartbeat_timeout", "input_validation", "internal", "external_service"]).optional(),
1972
+ "errorMessage": z.string().optional()
1973
+ }),
1974
+ "toolCalls": z.array(z.object({
1975
+ "toolCallId": z.string(),
1976
+ "toolName": z.string(),
1977
+ "success": z.boolean(),
1978
+ "durationMs": z.number(),
1979
+ "policyDecisionId": z.string().optional(),
1980
+ "gateClassification": z.enum(["core", "shimmed"]).optional(),
1981
+ "requiredScopes": z.array(z.string()).optional(),
1982
+ "graphWriteCount": z.number().optional(),
1983
+ "metadata": z.record(z.any()).optional()
1984
+ })),
1985
+ "toolCallCount": z.number(),
1986
+ "graphReads": z.array(z.object({
1987
+ "operationId": z.string(),
1988
+ "surface": z.enum(["belief", "question", "evidence", "worktree", "workflow", "topic", "document", "external"]),
1989
+ "action": z.string(),
1990
+ "targetId": z.string().optional(),
1991
+ "summary": z.string().optional(),
1992
+ "metadata": z.record(z.any()).optional()
1993
+ })),
1994
+ "graphReadCount": z.number(),
1995
+ "graphWrites": z.array(z.object({
1996
+ "operationId": z.string(),
1997
+ "surface": z.enum(["belief", "question", "evidence", "worktree", "workflow", "topic", "document", "external"]),
1998
+ "action": z.string(),
1999
+ "targetId": z.string().optional(),
2000
+ "summary": z.string().optional(),
2001
+ "metadata": z.record(z.any()).optional()
2002
+ })),
2003
+ "graphWriteCount": z.number(),
2004
+ "workflow": z.object({
2005
+ "workflowId": z.string(),
2006
+ "workflowVersion": z.string().optional(),
2007
+ "triggerKind": z.enum(["manual", "schedule", "hook"]),
2008
+ "mutationTier": z.enum(["read_only", "low_risk_write", "high_risk_write"]).optional(),
2009
+ "approvalMode": z.enum(["none", "audit_only", "human_required", "auto_approve"]).optional(),
2010
+ "actionCount": z.number().optional()
2011
+ }).optional(),
2012
+ "cost": z.object({
2013
+ "totalInputTokens": z.number().optional(),
2014
+ "totalOutputTokens": z.number().optional(),
2015
+ "estimatedTotalCostUsd": z.number().optional(),
2016
+ "llmCallCount": z.number().optional(),
2017
+ "toolCallCount": z.number().optional(),
2018
+ "modelsUsed": z.array(z.string()).optional()
2019
+ }).optional(),
2020
+ "metadata": z.record(z.any()).optional(),
2021
+ "createdAt": z.number(),
2022
+ "updatedAt": z.number()
2023
+ }),
2024
+ indices: [
2025
+ { kind: "index", name: "by_runId", columns: ["runId"] },
2026
+ { kind: "index", name: "by_status_startedAt", columns: ["status", "startedAt"] },
2027
+ { kind: "index", name: "by_tenant_status", columns: ["tenantId", "status"] },
2028
+ { kind: "index", name: "by_workspace_status", columns: ["workspaceId", "status"] },
2029
+ { kind: "index", name: "by_agent_createdAt", columns: ["agentId", "createdAt"] },
2030
+ { kind: "index", name: "by_runKind_createdAt", columns: ["runKind", "createdAt"] },
2031
+ { kind: "index", name: "by_topicId", columns: ["topicId"] }
2032
+ ]
2033
+ });
2034
+ var platformAgentRunPolicyDecisions = defineTable({
2035
+ name: "platformAgentRunPolicyDecisions",
2036
+ component: "kernel",
2037
+ category: "platform",
2038
+ shape: z.object({
2039
+ "runId": z.string(),
2040
+ "decisionId": z.string(),
2041
+ "action": z.string(),
2042
+ "result": z.enum(["allow", "deny", "shadow_allow"]),
2043
+ "reasonCode": z.string(),
2044
+ "scopesChecked": z.array(z.string()),
2045
+ "scopesGranted": z.array(z.string()),
2046
+ "evaluatedAt": z.number(),
2047
+ "createdAt": z.number()
2048
+ }),
2049
+ indices: [
2050
+ { kind: "index", name: "by_decisionId", columns: ["decisionId"] },
2051
+ { kind: "index", name: "by_run_createdAt", columns: ["runId", "createdAt"] }
2052
+ ]
2053
+ });
2054
+ var platformAgentRunPromptResolutions = defineTable({
2055
+ name: "platformAgentRunPromptResolutions",
2056
+ component: "kernel",
2057
+ category: "platform",
2058
+ shape: z.object({
2059
+ "runId": z.string(),
2060
+ "promptResolutionId": z.string(),
2061
+ "sequenceIndex": z.number(),
2062
+ "promptName": z.string(),
2063
+ "promptVersion": z.string(),
2064
+ "releaseChannel": z.enum(["dev", "staging", "prod"]),
2065
+ "usedFallback": z.boolean(),
2066
+ "modelSlot": z.string(),
2067
+ "modelKey": z.string(),
2068
+ "provider": z.string(),
2069
+ "inputTokens": z.number().optional(),
2070
+ "outputTokens": z.number().optional(),
2071
+ "durationMs": z.number().optional(),
2072
+ "estimatedCostUsd": z.number().optional(),
2073
+ "resolvedAt": z.number(),
2074
+ "metadata": z.record(z.any()).optional(),
2075
+ "createdAt": z.number()
2076
+ }),
2077
+ indices: [
2078
+ { kind: "index", name: "by_promptResolutionId", columns: ["promptResolutionId"] },
2079
+ { kind: "index", name: "by_run_createdAt", columns: ["runId", "createdAt"] },
2080
+ { kind: "index", name: "by_prompt_createdAt", columns: ["promptName", "createdAt"] }
2081
+ ]
2082
+ });
2083
+ var platformAgentRuns = defineTable({
2084
+ name: "platformAgentRuns",
2085
+ component: "kernel",
2086
+ category: "platform",
2087
+ shape: z.object({
2088
+ "runId": z.string(),
2089
+ "reportingToken": z.string(),
2090
+ "agentDefinitionId": z.string(),
2091
+ "agentVersion": z.string(),
2092
+ "principalId": z.string(),
2093
+ "tenantId": z.string(),
2094
+ "workspaceId": z.string().optional(),
2095
+ "authMode": z.enum(["interactive_user", "service_principal"]),
2096
+ "executionAdapter": z.enum(["convex_mutation", "convex_action", "http_callback", "mcp_tool", "sdk_invocation", "external_observed"]),
2097
+ "environment": z.enum(["sandbox", "production"]),
2098
+ "promptReleaseChannel": z.enum(["dev", "staging", "prod"]),
2099
+ "status": z.enum(["running", "completed", "failed", "timeout"]),
2100
+ "startedAt": z.number(),
2101
+ "finalizedAt": z.number().optional(),
2102
+ "durationMs": z.number().optional(),
2103
+ "lastHeartbeatAt": z.number().optional(),
2104
+ "langfuseTraceId": z.string().optional(),
2105
+ "chatId": z.string().optional(),
2106
+ "topicId": z.string().optional(),
2107
+ "error": z.object({
2108
+ "category": z.enum(["policy_denied", "tool_execution", "prompt_resolution", "model_error", "timeout", "heartbeat_timeout", "input_validation", "internal", "external_service"]),
2109
+ "message": z.string(),
2110
+ "code": z.string().optional(),
2111
+ "stack": z.string().optional()
2112
+ }).optional(),
2113
+ "costMetrics": z.record(z.any()).optional(),
2114
+ "metadata": z.record(z.any()).optional(),
2115
+ "createdAt": z.number(),
2116
+ "updatedAt": z.number()
2117
+ }),
2118
+ indices: [
2119
+ { kind: "index", name: "by_runId", columns: ["runId"] },
2120
+ { kind: "index", name: "by_status_lastHeartbeatAt", columns: ["status", "lastHeartbeatAt"] },
2121
+ { kind: "index", name: "by_status_startedAt", columns: ["status", "startedAt"] },
2122
+ { kind: "index", name: "by_tenant_status", columns: ["tenantId", "status"] },
2123
+ { kind: "index", name: "by_workspace_status", columns: ["workspaceId", "status"] },
2124
+ { kind: "index", name: "by_principal_createdAt", columns: ["principalId", "createdAt"] },
2125
+ { kind: "index", name: "by_agentDefinition_createdAt", columns: ["agentDefinitionId", "createdAt"] },
2126
+ { kind: "index", name: "by_topicId", columns: ["topicId"] }
2127
+ ]
2128
+ });
2129
+ var platformAgentRunToolCalls = defineTable({
2130
+ name: "platformAgentRunToolCalls",
2131
+ component: "kernel",
2132
+ category: "platform",
2133
+ shape: z.object({
2134
+ "runId": z.string(),
2135
+ "toolCallId": z.string(),
2136
+ "sequenceIndex": z.number(),
2137
+ "toolName": z.string(),
2138
+ "toolVersion": z.string().optional(),
2139
+ "policyDecisionId": z.string(),
2140
+ "requiredScopes": z.array(z.string()),
2141
+ "policyResult": z.enum(["allowed", "denied", "shadow_allowed"]),
2142
+ "policyReasonCode": z.string(),
2143
+ "executionAdapter": z.enum(["convex_mutation", "convex_action", "http_callback", "mcp_tool", "sdk_invocation", "external_observed"]),
2144
+ "inputHash": z.string(),
2145
+ "outputHash": z.string(),
2146
+ "durationMs": z.number().optional(),
2147
+ "success": z.boolean(),
2148
+ "error": z.string().optional(),
2149
+ "startedAt": z.number(),
2150
+ "completedAt": z.number(),
2151
+ "metadata": z.record(z.any()).optional(),
2152
+ "createdAt": z.number()
2153
+ }),
2154
+ indices: [
2155
+ { kind: "index", name: "by_toolCallId", columns: ["toolCallId"] },
2156
+ { kind: "index", name: "by_run_createdAt", columns: ["runId", "createdAt"] },
2157
+ { kind: "index", name: "by_tool_createdAt", columns: ["toolName", "createdAt"] }
2158
+ ]
2159
+ });
2160
+ var platformHarnessShadowAudit = defineTable({
2161
+ name: "platformHarnessShadowAudit",
2162
+ component: "kernel",
2163
+ category: "platform",
2164
+ shape: z.object({
2165
+ "shadowAuditId": z.string(),
2166
+ "runId": z.string(),
2167
+ "toolCallId": z.string(),
2168
+ "policyDecisionId": z.string(),
2169
+ "toolName": z.string(),
2170
+ "gateClassification": z.enum(["core", "shimmed"]),
2171
+ "requiredScopes": z.array(z.string()),
2172
+ "grantedScopes": z.array(z.string()),
2173
+ "shadowResult": z.literal("shadow_allow"),
2174
+ "wouldHaveDenied": z.boolean(),
2175
+ "reason": z.string(),
2176
+ "retentionExpiresAt": z.number(),
2177
+ "createdAt": z.number(),
2178
+ "metadata": z.record(z.any()).optional()
2179
+ }),
2180
+ indices: [
2181
+ { kind: "index", name: "by_shadowAuditId", columns: ["shadowAuditId"] },
2182
+ { kind: "index", name: "by_run_createdAt", columns: ["runId", "createdAt"] },
2183
+ { kind: "index", name: "by_policyDecisionId", columns: ["policyDecisionId"] },
2184
+ { kind: "index", name: "by_retentionExpiresAt", columns: ["retentionExpiresAt"] }
2185
+ ]
2186
+ });
2187
+ var publicationRules = defineTable({
2188
+ name: "publicationRules",
2189
+ component: "kernel",
2190
+ category: "platform",
2191
+ shape: z.object({
2192
+ "tenantId": z.string(),
2193
+ "packKey": z.string().optional(),
2194
+ "workspaceId": z.string().optional(),
2195
+ "name": z.string(),
2196
+ "description": z.string().optional(),
2197
+ "conditionType": z.enum(["confidence_threshold", "node_type_match", "epistemic_layer_match", "tag_match", "composite"]),
2198
+ "conditions": z.any(),
2199
+ "enabled": z.boolean(),
2200
+ "priority": z.number().optional(),
2201
+ "createdBy": z.string(),
2202
+ "createdAt": z.number(),
2203
+ "updatedAt": z.number()
2204
+ }),
2205
+ indices: [
2206
+ { kind: "index", name: "by_tenantId", columns: ["tenantId"] },
2207
+ { kind: "index", name: "by_tenantId_enabled", columns: ["tenantId", "enabled"] },
2208
+ { kind: "index", name: "by_tenantId_packKey", columns: ["tenantId", "packKey"] },
2209
+ { kind: "index", name: "by_tenantId_workspaceId", columns: ["tenantId", "workspaceId"] }
2210
+ ]
2211
+ });
2212
+ var researchJobs = defineTable({
2213
+ name: "researchJobs",
2214
+ component: "kernel",
2215
+ category: "platform",
2216
+ shape: z.object({
2217
+ "tenantId": z.string(),
2218
+ "jobId": z.string(),
2219
+ "type": z.enum(["search", "deep_research", "scrape"]),
2220
+ "query": z.string(),
2221
+ "topicId": z.string().optional(),
2222
+ "depth": z.string().optional(),
2223
+ "integrationKey": z.string(),
2224
+ "status": z.enum(["pending", "running", "completed", "failed", "cancelled"]),
2225
+ "results": z.record(z.any()).optional(),
2226
+ "resultCount": z.number().optional(),
2227
+ "error": z.string().optional(),
2228
+ "langfuseTraceId": z.string().optional(),
2229
+ "autoCommitEvidence": z.boolean(),
2230
+ "committedEvidenceIds": z.array(z.string()).optional(),
2231
+ "requestedBy": z.string(),
2232
+ "createdAt": z.number(),
2233
+ "startedAt": z.number().optional(),
2234
+ "completedAt": z.number().optional(),
2235
+ "durationMs": z.number().optional()
2236
+ }),
2237
+ indices: [
2238
+ { kind: "index", name: "by_tenant", columns: ["tenantId"] },
2239
+ { kind: "index", name: "by_jobId", columns: ["jobId"] },
2240
+ { kind: "index", name: "by_tenant_status", columns: ["tenantId", "status"] },
2241
+ { kind: "index", name: "by_topic", columns: ["topicId"] }
2242
+ ]
2243
+ });
2244
+ var idempotencyTokens = defineTable({
2245
+ name: "idempotencyTokens",
2246
+ component: "kernel",
2247
+ category: "idempotency",
2248
+ shape: z.object({
2249
+ "tenantId": z.string(),
2250
+ "fnName": z.string(),
2251
+ "key": z.string(),
2252
+ "resultJson": z.string(),
2253
+ "recordedAt": z.number(),
2254
+ "expiresAt": z.number()
2255
+ }),
2256
+ indices: [
2257
+ { kind: "index", name: "by_tenant_fn_key", columns: ["tenantId", "fnName", "key"] },
2258
+ { kind: "index", name: "by_expiry", columns: ["expiresAt"] }
2259
+ ]
2260
+ });
2261
+ var lenses = defineTable({
2262
+ name: "lenses",
2263
+ component: "kernel",
2264
+ category: "lens",
2265
+ shape: z.object({
2266
+ "globalId": z.string(),
2267
+ "name": z.string(),
2268
+ "description": z.string().optional(),
2269
+ "workspaceId": z.string(),
2270
+ "topicId": z.string().optional(),
2271
+ "perspectiveType": z.string(),
2272
+ "promptTemplates": z.array(z.object({
2273
+ "key": z.string(),
2274
+ "promptRef": z.string(),
2275
+ "phase": z.string().optional(),
2276
+ "role": z.string().optional(),
2277
+ "version": z.string().optional(),
2278
+ "required": z.boolean().optional(),
2279
+ "metadata": z.any().optional()
2280
+ })),
2281
+ "workflowTemplates": z.array(z.object({
2282
+ "key": z.string(),
2283
+ "name": z.string(),
2284
+ "description": z.string().optional(),
2285
+ "steps": z.array(z.object({
2286
+ "key": z.string(),
2287
+ "title": z.string(),
2288
+ "description": z.string().optional(),
2289
+ "promptTemplateKey": z.string().optional(),
2290
+ "taskTemplateKeys": z.array(z.string()).optional(),
2291
+ "metadata": z.any().optional()
2292
+ })),
2293
+ "metadata": z.any().optional()
2294
+ })),
2295
+ "taskTemplates": z.array(z.object({
2296
+ "key": z.string(),
2297
+ "title": z.string(),
2298
+ "description": z.string().optional(),
2299
+ "priority": z.enum(["critical", "high", "medium", "low"]).optional(),
2300
+ "phase": z.string().optional(),
2301
+ "metadata": z.any().optional()
2302
+ })),
2303
+ "questionTemplates": z.array(z.object({
2304
+ "key": z.string(),
2305
+ "text": z.string(),
2306
+ "priority": z.enum(["critical", "high", "medium", "low"]).optional(),
2307
+ "linkedBeliefKey": z.string().optional(),
2308
+ "metadata": z.any().optional()
2309
+ })).optional(),
2310
+ "filterCriteria": z.object({
2311
+ "version": z.literal(1),
2312
+ "kind": z.literal("taxonomy"),
2313
+ "entityTypeFilters": z.array(z.object({
2314
+ "entityTypeValue": z.string(),
2315
+ "subtypeValues": z.array(z.string()).optional()
2316
+ })),
2317
+ "ontologyScope": z.object({
2318
+ "ontologyKey": z.string().optional()
2319
+ }).optional()
2320
+ }).optional(),
2321
+ "metadata": z.any().optional(),
2322
+ "status": z.enum(["draft", "active", "archived"]),
2323
+ "createdBy": z.string(),
2324
+ "createdAt": z.number(),
2325
+ "updatedAt": z.number()
2326
+ }),
2327
+ indices: [
2328
+ { kind: "index", name: "by_workspace", columns: ["workspaceId"] },
2329
+ { kind: "index", name: "by_workspace_status", columns: ["workspaceId", "status"] },
2330
+ { kind: "index", name: "by_workspace_perspective", columns: ["workspaceId", "perspectiveType"] },
2331
+ { kind: "index", name: "by_topic", columns: ["topicId"] }
2332
+ ]
2333
+ });
2334
+ var lensTopicBindings = defineTable({
2335
+ name: "lensTopicBindings",
2336
+ component: "kernel",
2337
+ category: "lens",
2338
+ shape: z.object({
2339
+ "lensId": idOf("lenses"),
2340
+ "topicId": z.string(),
2341
+ "workspaceId": z.string(),
2342
+ "status": z.enum(["active", "removed"]),
2343
+ "metadata": z.any().optional(),
2344
+ "appliedBy": z.string(),
2345
+ "appliedAt": z.number(),
2346
+ "removedBy": z.string().optional(),
2347
+ "removedAt": z.number().optional(),
2348
+ "updatedAt": z.number()
2349
+ }),
2350
+ indices: [
2351
+ { kind: "index", name: "by_lens", columns: ["lensId"] },
2352
+ { kind: "index", name: "by_lens_status", columns: ["lensId", "status"] },
2353
+ { kind: "index", name: "by_topic", columns: ["topicId"] },
2354
+ { kind: "index", name: "by_topic_status", columns: ["topicId", "status"] },
2355
+ { kind: "index", name: "by_topic_lens", columns: ["topicId", "lensId"] }
2356
+ ]
2357
+ });
2358
+ var mcpWritePolicy = defineTable({
2359
+ name: "mcpWritePolicy",
2360
+ component: "identity",
2361
+ category: "platform",
2362
+ shape: z.object({
2363
+ "topicId": z.string().optional(),
2364
+ "role": z.string(),
2365
+ "toolCategory": z.string(),
2366
+ "permission": z.enum(["allow", "deny", "review_required"]),
2367
+ "maxWritesPerSession": z.number().optional(),
2368
+ "enabled": z.boolean(),
2369
+ "rationale": z.string().optional(),
2370
+ "createdAt": z.number(),
2371
+ "updatedAt": z.number(),
2372
+ "createdBy": z.string()
2373
+ }),
2374
+ indices: [
2375
+ { kind: "index", name: "by_topicId", columns: ["topicId"] },
2376
+ { kind: "index", name: "by_role", columns: ["role"] },
2377
+ { kind: "index", name: "by_topicId_role", columns: ["topicId", "role"] },
2378
+ { kind: "index", name: "by_enabled", columns: ["enabled"] }
2379
+ ]
2380
+ });
2381
+ var platformAudienceGrants = defineTable({
2382
+ name: "platformAudienceGrants",
2383
+ component: "identity",
2384
+ category: "platform",
2385
+ shape: z.object({
2386
+ "tenantId": z.string(),
2387
+ "workspaceId": z.string().optional(),
2388
+ "principalId": z.string().optional(),
2389
+ "groupId": z.string().optional(),
2390
+ "audienceKey": z.string(),
2391
+ "audienceClass": z.enum(["internal", "restricted_external", "public"]),
2392
+ "status": z.enum(["active", "revoked", "expired"]),
2393
+ "grantedBy": z.string().optional(),
2394
+ "expiresAt": z.number().optional(),
2395
+ "metadata": z.record(z.any()).optional(),
2396
+ "createdAt": z.number(),
2397
+ "updatedAt": z.number()
2398
+ }),
2399
+ indices: [
2400
+ { kind: "index", name: "by_tenant_principal", columns: ["tenantId", "principalId"] },
2401
+ { kind: "index", name: "by_tenant_group", columns: ["tenantId", "groupId"] },
2402
+ { kind: "index", name: "by_tenant_audienceKey", columns: ["tenantId", "audienceKey"] },
2403
+ { kind: "index", name: "by_principal_status", columns: ["principalId", "status"] },
2404
+ { kind: "index", name: "by_group_status", columns: ["groupId", "status"] }
2405
+ ]
2406
+ });
2407
+ var platformAudiences = defineTable({
2408
+ name: "platformAudiences",
2409
+ component: "identity",
2410
+ category: "platform",
2411
+ shape: z.object({
2412
+ "tenantId": z.string(),
2413
+ "workspaceId": z.string().optional(),
2414
+ "audienceKey": z.string(),
2415
+ "audienceLabel": z.string(),
2416
+ "audienceClass": z.enum(["internal", "restricted_external", "public"]),
2417
+ "status": z.enum(["active", "disabled", "archived"]),
2418
+ "description": z.string().optional(),
2419
+ "metadata": z.record(z.any()).optional(),
2420
+ "createdBy": z.string().optional(),
2421
+ "createdAt": z.number(),
2422
+ "updatedAt": z.number()
2423
+ }),
2424
+ indices: [
2425
+ { kind: "index", name: "by_tenantId", columns: ["tenantId"] },
2426
+ { kind: "index", name: "by_workspaceId", columns: ["workspaceId"] },
2427
+ { kind: "index", name: "by_tenant_audienceKey", columns: ["tenantId", "audienceKey"] },
2428
+ { kind: "index", name: "by_tenant_workspace_audienceKey", columns: ["tenantId", "workspaceId", "audienceKey"] },
2429
+ { kind: "index", name: "by_tenant_status", columns: ["tenantId", "status"] }
2430
+ ]
2431
+ });
2432
+ var platformPolicyDecisionLogs = defineTable({
2433
+ name: "platformPolicyDecisionLogs",
2434
+ component: "identity",
2435
+ category: "platform",
2436
+ shape: z.object({
2437
+ "principalId": z.string(),
2438
+ "tenantId": z.string().optional(),
2439
+ "workspaceId": z.string().optional(),
2440
+ "topicId": z.string().optional(),
2441
+ "resourceType": z.string(),
2442
+ "resourceId": z.string(),
2443
+ "action": z.enum(["read", "summarize", "export", "mutate", "admin", "comment", "escalate", "resolve", "vote"]),
2444
+ "decision": z.enum(["allow", "deny"]),
2445
+ "reasonCode": z.string(),
2446
+ "policyVersion": z.string(),
2447
+ "policyBundleId": z.string().optional(),
2448
+ "audienceKey": z.string().optional(),
2449
+ "audienceClass": z.enum(["internal", "restricted_external", "public"]).optional(),
2450
+ "audienceMode": z.string().optional(),
2451
+ "traceId": z.string().optional(),
2452
+ "packKey": z.string().optional(),
2453
+ "metadata": z.record(z.any()).optional(),
2454
+ "createdAt": z.number()
2455
+ }),
2456
+ indices: [
2457
+ { kind: "index", name: "by_principal_createdAt", columns: ["principalId", "createdAt"] },
2458
+ { kind: "index", name: "by_tenant_createdAt", columns: ["tenantId", "createdAt"] },
2459
+ { kind: "index", name: "by_pack_createdAt", columns: ["packKey", "createdAt"] },
2460
+ { kind: "index", name: "by_audienceKey_createdAt", columns: ["audienceKey", "createdAt"] },
2461
+ { kind: "index", name: "by_audienceClass_createdAt", columns: ["audienceClass", "createdAt"] },
2462
+ { kind: "index", name: "by_decision_createdAt", columns: ["decision", "createdAt"] },
2463
+ { kind: "index", name: "by_traceId", columns: ["traceId"] },
2464
+ { kind: "index", name: "by_topicId", columns: ["topicId"] },
2465
+ { kind: "index", name: "by_topic_createdAt", columns: ["topicId", "createdAt"] }
2466
+ ]
2467
+ });
2468
+ var tenantApiKeys = defineTable({
2469
+ name: "tenantApiKeys",
2470
+ component: "identity",
2471
+ category: "platform",
2472
+ shape: z.object({
2473
+ "tenantId": z.string(),
2474
+ "workspaceId": z.string().optional(),
2475
+ "label": z.string().optional(),
2476
+ "keyPrefix": z.string(),
2477
+ "hashedKey": z.string(),
2478
+ "scopes": z.array(z.string()),
2479
+ "status": z.enum(["active", "revoked", "expired"]),
2480
+ "expiresAt": z.number().optional(),
2481
+ "lastUsedAt": z.number().optional(),
2482
+ "revokedAt": z.number().optional(),
2483
+ "revokedBy": z.string().optional(),
2484
+ "createdBy": z.string(),
2485
+ "createdAt": z.number(),
2486
+ "updatedAt": z.number()
2487
+ }),
2488
+ indices: [
2489
+ { kind: "index", name: "by_tenantId", columns: ["tenantId"] },
2490
+ { kind: "index", name: "by_workspaceId", columns: ["workspaceId"] },
2491
+ { kind: "index", name: "by_hashedKey", columns: ["hashedKey"] },
2492
+ { kind: "index", name: "by_tenant_status", columns: ["tenantId", "status"] }
2493
+ ]
2494
+ });
2495
+ var tenantConfig = defineTable({
2496
+ name: "tenantConfig",
2497
+ component: "identity",
2498
+ category: "platform",
2499
+ shape: z.object({
2500
+ "tenantId": z.string(),
2501
+ "authPolicyMode": z.enum(["open", "invite_only", "sso_required"]),
2502
+ "defaultSessionTTL": z.number(),
2503
+ "defaultTopicVisibility": z.enum(["private", "tenant", "public"]),
2504
+ "featureFlags": z.record(z.boolean()),
2505
+ "maxWorkspaceCount": z.number(),
2506
+ "defaultModelSlotOverrides": z.record(z.string()),
2507
+ "updatedAt": z.number(),
2508
+ "updatedBy": z.string()
2509
+ }),
2510
+ indices: [
2511
+ { kind: "index", name: "by_tenantId", columns: ["tenantId"] }
2512
+ ]
2513
+ });
2514
+ var tenantIntegrations = defineTable({
2515
+ name: "tenantIntegrations",
2516
+ component: "identity",
2517
+ category: "platform",
2518
+ shape: z.object({
2519
+ "tenantId": z.string(),
2520
+ "integrationKey": z.string(),
2521
+ "displayName": z.string(),
2522
+ "description": z.string().optional(),
2523
+ "category": z.enum(["search", "scraper", "llm", "analysis", "custom"]),
2524
+ "capabilities": z.array(z.enum(["search", "deep_research", "scrape", "summarize", "generate"])),
2525
+ "config": z.object({
2526
+ "apiBaseUrl": z.string(),
2527
+ "authType": z.enum(["api_key", "bearer", "basic", "none"]),
2528
+ "authHeaderName": z.string().optional(),
2529
+ "credentialSecretName": z.string().optional(),
2530
+ "defaultParams": z.record(z.any()).optional(),
2531
+ "timeout": z.number().optional(),
2532
+ "customHeaders": z.record(z.any()).optional()
2533
+ }),
2534
+ "endpoints": z.object({
2535
+ "search": z.object({
2536
+ "path": z.string(),
2537
+ "method": z.string().optional(),
2538
+ "queryParamName": z.string().optional(),
2539
+ "resultPath": z.string().optional()
2540
+ }).optional(),
2541
+ "deepResearch": z.object({
2542
+ "path": z.string(),
2543
+ "method": z.string().optional(),
2544
+ "resultPath": z.string().optional(),
2545
+ "async": z.boolean().optional(),
2546
+ "pollPath": z.string().optional(),
2547
+ "pollIntervalMs": z.number().optional()
2548
+ }).optional(),
2549
+ "scrape": z.object({
2550
+ "path": z.string(),
2551
+ "method": z.string().optional(),
2552
+ "resultPath": z.string().optional()
2553
+ }).optional()
2554
+ }).optional(),
2555
+ "status": z.enum(["active", "disabled", "error"]),
2556
+ "lastUsedAt": z.number().optional(),
2557
+ "lastError": z.string().optional(),
2558
+ "usageCount": z.number().optional(),
2559
+ "createdAt": z.number(),
2560
+ "updatedAt": z.number(),
2561
+ "createdBy": z.string().optional()
2562
+ }),
2563
+ indices: [
2564
+ { kind: "index", name: "by_tenant", columns: ["tenantId"] },
2565
+ { kind: "index", name: "by_tenant_key", columns: ["tenantId", "integrationKey"] },
2566
+ { kind: "index", name: "by_tenant_status", columns: ["tenantId", "status"] }
2567
+ ]
2568
+ });
2569
+ var tenantModelSlotBindings = defineTable({
2570
+ name: "tenantModelSlotBindings",
2571
+ component: "identity",
2572
+ category: "platform",
2573
+ shape: z.object({
2574
+ "bindingId": z.string(),
2575
+ "tenantId": z.string(),
2576
+ "providerId": z.string(),
2577
+ "modelSlotId": z.string(),
2578
+ "secretRef": z.string(),
2579
+ "status": z.enum(["active", "revoked"]),
2580
+ "passThroughOnly": z.boolean(),
2581
+ "revokedAt": z.number().optional(),
2582
+ "revokedBy": z.string().optional(),
2583
+ "metadata": z.record(z.any()).optional(),
2584
+ "createdBy": z.string(),
2585
+ "createdAt": z.number(),
2586
+ "updatedAt": z.number()
2587
+ }),
2588
+ indices: [
2589
+ { kind: "index", name: "by_bindingId", columns: ["bindingId"] },
2590
+ { kind: "index", name: "by_tenantId", columns: ["tenantId"] },
2591
+ { kind: "index", name: "by_tenant_slot", columns: ["tenantId", "modelSlotId"] },
2592
+ { kind: "index", name: "by_tenant_provider_slot", columns: ["tenantId", "providerId", "modelSlotId"] },
2593
+ { kind: "index", name: "by_secretRef", columns: ["secretRef"] },
2594
+ { kind: "index", name: "by_status", columns: ["status"] }
2595
+ ]
2596
+ });
2597
+ var tenantPolicies = defineTable({
2598
+ name: "tenantPolicies",
2599
+ component: "identity",
2600
+ category: "platform",
2601
+ shape: z.object({
2602
+ "tenantId": z.string(),
2603
+ "workspaceId": z.string().optional(),
2604
+ "roleName": z.string(),
2605
+ "description": z.string().optional(),
2606
+ "permissions": z.array(z.object({
2607
+ "resource": z.string(),
2608
+ "actions": z.array(z.string())
2609
+ })),
2610
+ "groupBindings": z.array(z.string()),
2611
+ "createdAt": z.number(),
2612
+ "updatedAt": z.number(),
2613
+ "createdBy": z.string(),
2614
+ "updatedBy": z.string().optional()
2615
+ }),
2616
+ indices: [
2617
+ { kind: "index", name: "by_tenantId", columns: ["tenantId"] },
2618
+ { kind: "index", name: "by_workspaceId", columns: ["workspaceId"] },
2619
+ { kind: "index", name: "by_tenant_roleName", columns: ["tenantId", "roleName"] }
2620
+ ]
2621
+ });
2622
+ var tenantProviderSecrets = defineTable({
2623
+ name: "tenantProviderSecrets",
2624
+ component: "identity",
2625
+ category: "platform",
2626
+ shape: z.object({
2627
+ "secretRef": z.string(),
2628
+ "tenantId": z.string(),
2629
+ "providerId": z.string(),
2630
+ "label": z.string().optional(),
2631
+ "encryptedSecret": z.string(),
2632
+ "encryptionVersion": z.string(),
2633
+ "secretFingerprint": z.string(),
2634
+ "keyHint": z.string(),
2635
+ "status": z.enum(["active", "rotated", "revoked"]),
2636
+ "rotatedFromSecretRef": z.string().optional(),
2637
+ "revokedAt": z.number().optional(),
2638
+ "revokedBy": z.string().optional(),
2639
+ "lastUsedAt": z.number().optional(),
2640
+ "metadata": z.record(z.any()).optional(),
2641
+ "createdBy": z.string(),
2642
+ "createdAt": z.number(),
2643
+ "updatedAt": z.number()
2644
+ }),
2645
+ indices: [
2646
+ { kind: "index", name: "by_secretRef", columns: ["secretRef"] },
2647
+ { kind: "index", name: "by_tenantId", columns: ["tenantId"] },
2648
+ { kind: "index", name: "by_tenant_provider", columns: ["tenantId", "providerId"] },
2649
+ { kind: "index", name: "by_tenant_provider_status", columns: ["tenantId", "providerId", "status"] },
2650
+ { kind: "index", name: "by_status", columns: ["status"] }
2651
+ ]
2652
+ });
2653
+ var tenantProxyGatewayUsage = defineTable({
2654
+ name: "tenantProxyGatewayUsage",
2655
+ component: "identity",
2656
+ category: "platform",
2657
+ shape: z.object({
2658
+ "usageId": z.string(),
2659
+ "tenantId": z.string(),
2660
+ "providerId": z.string(),
2661
+ "modelSlotId": z.string(),
2662
+ "secretRef": z.string(),
2663
+ "proxyTokenId": z.string(),
2664
+ "sessionId": z.string(),
2665
+ "principalId": z.string(),
2666
+ "workspaceId": z.string().optional(),
2667
+ "modelId": z.string().optional(),
2668
+ "requestPath": z.string(),
2669
+ "status": z.enum(["success", "error"]),
2670
+ "responseStatus": z.number().optional(),
2671
+ "inputTokens": z.number().optional(),
2672
+ "outputTokens": z.number().optional(),
2673
+ "tokenCount": z.number().optional(),
2674
+ "latencyMs": z.number(),
2675
+ "estimatedCostUsd": z.number().optional(),
2676
+ "failureCode": z.string().optional(),
2677
+ "metadata": z.record(z.any()).optional(),
2678
+ "createdAt": z.number(),
2679
+ "updatedAt": z.number()
2680
+ }),
2681
+ indices: [
2682
+ { kind: "index", name: "by_usageId", columns: ["usageId"] },
2683
+ { kind: "index", name: "by_tenantId", columns: ["tenantId", "createdAt"] },
2684
+ { kind: "index", name: "by_tenant_provider", columns: ["tenantId", "providerId", "createdAt"] },
2685
+ { kind: "index", name: "by_proxyTokenId", columns: ["proxyTokenId", "createdAt"] }
2686
+ ]
2687
+ });
2688
+ var tenantProxyTokenMints = defineTable({
2689
+ name: "tenantProxyTokenMints",
2690
+ component: "identity",
2691
+ category: "platform",
2692
+ shape: z.object({
2693
+ "proxyTokenId": z.string(),
2694
+ "tenantId": z.string(),
2695
+ "providerId": z.string(),
2696
+ "modelSlotId": z.string(),
2697
+ "sessionId": z.string(),
2698
+ "principalId": z.string(),
2699
+ "workspaceId": z.string().optional(),
2700
+ "secretRef": z.string(),
2701
+ "expiresAt": z.number(),
2702
+ "metadata": z.record(z.any()).optional(),
2703
+ "createdAt": z.number()
2704
+ }),
2705
+ indices: [
2706
+ { kind: "index", name: "by_proxyTokenId", columns: ["proxyTokenId"] },
2707
+ { kind: "index", name: "by_tenantId", columns: ["tenantId", "createdAt"] },
2708
+ { kind: "index", name: "by_sessionId", columns: ["sessionId", "createdAt"] }
2709
+ ]
2710
+ });
2711
+ var tenantSandboxAuditEvents = defineTable({
2712
+ name: "tenantSandboxAuditEvents",
2713
+ component: "identity",
2714
+ category: "platform",
2715
+ shape: z.object({
2716
+ "eventId": z.string(),
2717
+ "tenantId": z.string(),
2718
+ "actorClerkId": z.string(),
2719
+ "action": z.enum(["sandbox_created", "sandbox_secret_injected", "sandbox_execution_started", "sandbox_execution_completed", "sandbox_limit_violated"]),
2720
+ "executionId": z.string(),
2721
+ "sessionId": z.string().optional(),
2722
+ "principalId": z.string().optional(),
2723
+ "workspaceId": z.string().optional(),
2724
+ "providerId": z.string().optional(),
2725
+ "secretRef": z.string().optional(),
2726
+ "toolCallId": z.string().optional(),
2727
+ "correlationId": z.string().optional(),
2728
+ "sandboxDir": z.string().optional(),
2729
+ "timeoutMs": z.number().optional(),
2730
+ "memoryLimitMb": z.number().optional(),
2731
+ "allowedOrigins": z.array(z.string()).optional(),
2732
+ "limitName": z.string().optional(),
2733
+ "outcome": z.string().optional(),
2734
+ "responseStatus": z.number().optional(),
2735
+ "durationMs": z.number().optional(),
2736
+ "metadata": z.record(z.any()).optional(),
2737
+ "createdAt": z.number()
2738
+ }),
2739
+ indices: [
2740
+ { kind: "index", name: "by_eventId", columns: ["eventId"] },
2741
+ { kind: "index", name: "by_executionId", columns: ["executionId", "createdAt"] },
2742
+ { kind: "index", name: "by_tenantId", columns: ["tenantId", "createdAt"] }
2743
+ ]
2744
+ });
2745
+ var tenantSecrets = defineTable({
2746
+ name: "tenantSecrets",
2747
+ component: "identity",
2748
+ category: "platform",
2749
+ shape: z.object({
2750
+ "tenantId": z.string(),
2751
+ "workspaceId": z.string().optional(),
2752
+ "name": z.string(),
2753
+ "description": z.string().optional(),
2754
+ "encryptedValue": z.string(),
2755
+ "lastRotated": z.number(),
2756
+ "createdBy": z.string(),
2757
+ "updatedBy": z.string().optional(),
2758
+ "createdAt": z.number(),
2759
+ "updatedAt": z.number()
2760
+ }),
2761
+ indices: [
2762
+ { kind: "index", name: "by_tenantId", columns: ["tenantId"] },
2763
+ { kind: "index", name: "by_workspaceId", columns: ["workspaceId"] },
2764
+ { kind: "index", name: "by_tenant_name", columns: ["tenantId", "name"] }
2765
+ ]
2766
+ });
2767
+ var toolAcls = defineTable({
2768
+ name: "toolAcls",
2769
+ component: "identity",
2770
+ category: "platform",
2771
+ shape: z.object({
2772
+ "role": z.enum(["platform_admin", "tenant_admin", "workspace_admin", "editor", "viewer", "auditor", "service_agent"]),
2773
+ "toolName": z.string(),
2774
+ "createdBy": z.string().optional(),
2775
+ "createdAt": z.number().optional()
2776
+ }),
2777
+ indices: [
2778
+ { kind: "index", name: "by_role", columns: ["role"] },
2779
+ { kind: "index", name: "by_toolName", columns: ["toolName"] }
2780
+ ]
2781
+ });
2782
+ var toolRegistry = defineTable({
2783
+ name: "toolRegistry",
2784
+ component: "identity",
2785
+ category: "platform",
2786
+ shape: z.object({
2787
+ "toolName": z.string(),
2788
+ "description": z.string().optional(),
2789
+ "version": z.string().optional(),
2790
+ "status": z.enum(["active", "deprecated", "disabled"]),
2791
+ "requiredRole": z.enum(["platform_admin", "tenant_admin", "workspace_admin", "editor", "viewer", "auditor", "service_agent"]).optional(),
2792
+ "requiredAction": z.enum(["read", "mutate", "admin", "summarize", "export", "create", "delete", "grant", "revoke"]).optional(),
2793
+ "surfaces": z.array(z.enum(["mcp", "chat", "voice", "sprint", "api", "sdk", "cli"])).optional(),
2794
+ "approvalGateId": z.string().optional(),
2795
+ "category": z.enum(["read", "write", "admin", "system"]).optional(),
2796
+ "parameterSchema": z.record(z.any()).optional(),
2797
+ "handlerRef": z.string().optional(),
2798
+ "returnSchema": z.record(z.any()).optional(),
2799
+ "executionAdapter": z.enum(["convex_mutation", "convex_action", "http_callback", "mcp_tool", "sdk_invocation", "external_observed"]).optional(),
2800
+ "safetyMetadata": z.object({
2801
+ "readOnly": z.boolean(),
2802
+ "idempotent": z.boolean(),
2803
+ "sideEffectLevel": z.enum(["none", "low", "high"])
2804
+ }).optional(),
2805
+ "packKey": z.string().optional(),
2806
+ "packVersion": z.string().optional(),
2807
+ "isCore": z.boolean(),
2808
+ "mcVersion": z.string().optional(),
2809
+ "registeredBy": z.string().optional(),
2810
+ "registeredAt": z.number().optional()
2811
+ }),
2812
+ indices: [
2813
+ { kind: "index", name: "by_toolName", columns: ["toolName"] },
2814
+ { kind: "index", name: "by_status", columns: ["status"] },
2815
+ { kind: "index", name: "by_isCore", columns: ["isCore"] },
2816
+ { kind: "index", name: "by_packKey", columns: ["packKey"] }
2817
+ ]
2818
+ });
2819
+ var methodologyPacks = defineTable({
2820
+ name: "methodologyPacks",
2821
+ component: "mc",
2822
+ category: "methodology",
2823
+ shape: z.object({
2824
+ "packId": z.string(),
2825
+ "name": z.string(),
2826
+ "description": z.string(),
2827
+ "version": z.string(),
2828
+ "enforcementLevel": z.enum(["strict", "guided", "advisory"]),
2829
+ "phases": z.array(z.object({
2830
+ "name": z.string(),
2831
+ "title": z.string(),
2832
+ "description": z.string(),
2833
+ "requiredTools": z.array(z.string()),
2834
+ "gate": z.string().optional(),
2835
+ "instructions": z.string()
2836
+ })),
2837
+ "principles": z.array(z.string()),
2838
+ "status": z.enum(["active", "draft", "archived"]),
2839
+ "createdAt": z.number(),
2840
+ "updatedAt": z.number()
2841
+ }),
2842
+ indices: [
2843
+ { kind: "index", name: "by_packId", columns: ["packId"] },
2844
+ { kind: "index", name: "by_status", columns: ["status"] }
2845
+ ]
2846
+ });
2847
+ var tenantMethodologyAssignments = defineTable({
2848
+ name: "tenantMethodologyAssignments",
2849
+ component: "mc",
2850
+ category: "methodology",
2851
+ shape: z.object({
2852
+ "tenantId": idOf("tenants"),
2853
+ "methodologyPackId": idOf("methodologyPacks"),
2854
+ "isDefault": z.boolean(),
2855
+ "assignedAt": z.number(),
2856
+ "assignedBy": z.string()
2857
+ }),
2858
+ indices: [
2859
+ { kind: "index", name: "by_tenantId", columns: ["tenantId"] },
2860
+ { kind: "index", name: "by_methodologyPackId", columns: ["methodologyPackId"] }
2861
+ ]
2862
+ });
2863
+ var modelCallLogs = defineTable({
2864
+ name: "modelCallLogs",
2865
+ component: "identity",
2866
+ category: "model",
2867
+ shape: z.object({
2868
+ "slot": z.string(),
2869
+ "modelKey": z.string(),
2870
+ "provider": z.string(),
2871
+ "inputTokens": z.number().optional(),
2872
+ "outputTokens": z.number().optional(),
2873
+ "durationMs": z.number().optional(),
2874
+ "cost": z.number().optional(),
2875
+ "success": z.boolean(),
2876
+ "error": z.string().optional(),
2877
+ "userId": z.string().optional(),
2878
+ "sessionId": z.string().optional(),
2879
+ "traceId": z.string().optional(),
2880
+ "timestamp": z.number()
2881
+ }),
2882
+ indices: [
2883
+ { kind: "index", name: "by_slot", columns: ["slot"] },
2884
+ { kind: "index", name: "by_model", columns: ["modelKey"] },
2885
+ { kind: "index", name: "by_timestamp", columns: ["timestamp"] },
2886
+ { kind: "index", name: "by_user", columns: ["userId"] }
2887
+ ]
2888
+ });
2889
+ var modelFunctionSlots = defineTable({
2890
+ name: "modelFunctionSlots",
2891
+ component: "identity",
2892
+ category: "model",
2893
+ shape: z.object({
2894
+ "slot": z.string(),
2895
+ "category": z.string(),
2896
+ "description": z.string(),
2897
+ "modelKey": z.string(),
2898
+ "promptName": z.string().optional(),
2899
+ "temperature": z.number().optional(),
2900
+ "maxTokens": z.number().optional(),
2901
+ "requiredCapabilities": z.array(z.string()).optional(),
2902
+ "enabled": z.boolean(),
2903
+ "isDefault": z.boolean(),
2904
+ "notes": z.string().optional(),
2905
+ "createdAt": z.number(),
2906
+ "updatedAt": z.number()
2907
+ }),
2908
+ indices: [
2909
+ { kind: "index", name: "by_slot", columns: ["slot"] },
2910
+ { kind: "index", name: "by_category", columns: ["category"] },
2911
+ { kind: "index", name: "by_enabled", columns: ["enabled"] }
2912
+ ]
2913
+ });
2914
+ var modelRegistry = defineTable({
2915
+ name: "modelRegistry",
2916
+ component: "identity",
2917
+ category: "model",
2918
+ shape: z.object({
2919
+ "key": z.string(),
2920
+ "name": z.string(),
2921
+ "modelId": z.string(),
2922
+ "provider": z.string(),
2923
+ "capabilities": z.array(z.string()),
2924
+ "contextWindow": z.number(),
2925
+ "maxOutputTokens": z.number(),
2926
+ "defaultTemperature": z.number(),
2927
+ "inputCostPer1M": z.number(),
2928
+ "outputCostPer1M": z.number(),
2929
+ "recommended": z.boolean(),
2930
+ "enabled": z.boolean(),
2931
+ "notes": z.string().optional(),
2932
+ "createdAt": z.number(),
2933
+ "updatedAt": z.number()
2934
+ }),
2935
+ indices: [
2936
+ { kind: "index", name: "by_key", columns: ["key"] },
2937
+ { kind: "index", name: "by_provider", columns: ["provider"] },
2938
+ { kind: "index", name: "by_enabled", columns: ["enabled"] }
2939
+ ]
2940
+ });
2941
+ var modelSlotConfigs = defineTable({
2942
+ name: "modelSlotConfigs",
2943
+ component: "identity",
2944
+ category: "model",
2945
+ shape: z.object({
2946
+ "slot": z.string(),
2947
+ "modelKey": z.string(),
2948
+ "temperature": z.number().optional(),
2949
+ "maxTokens": z.number().optional(),
2950
+ "enabled": z.boolean(),
2951
+ "notes": z.string().optional(),
2952
+ "createdAt": z.number(),
2953
+ "updatedAt": z.number()
2954
+ }),
2955
+ indices: [
2956
+ { kind: "index", name: "by_slot", columns: ["slot"] }
2957
+ ]
2958
+ });
2959
+ var ontologyDefinitions = defineTable({
2960
+ name: "ontologyDefinitions",
2961
+ component: "kernel",
2962
+ category: "ontology",
2963
+ shape: z.object({
2964
+ "ontologyKey": z.string(),
2965
+ "name": z.string(),
2966
+ "description": z.string().optional(),
2967
+ "tenantId": z.string().optional(),
2968
+ "tier": z.enum(["platform", "pack", "tenant"]),
2969
+ "parentOntologyId": idOf("ontologyDefinitions").optional(),
2970
+ "status": z.enum(["draft", "active", "deprecated", "archived"]),
2971
+ "createdBy": z.string(),
2972
+ "createdAt": z.number(),
2973
+ "updatedAt": z.number()
2974
+ }),
2975
+ indices: [
2976
+ { kind: "index", name: "by_ontologyKey", columns: ["ontologyKey"] },
2977
+ { kind: "index", name: "by_tenant_ontologyKey", columns: ["tenantId", "ontologyKey"] },
2978
+ { kind: "index", name: "by_tier", columns: ["tier"] },
2979
+ { kind: "index", name: "by_status", columns: ["status"] },
2980
+ { kind: "index", name: "by_tenant_status", columns: ["tenantId", "status"] },
2981
+ { kind: "index", name: "by_parentOntologyId", columns: ["parentOntologyId"] }
2982
+ ]
2983
+ });
2984
+ var ontologyVersions = defineTable({
2985
+ name: "ontologyVersions",
2986
+ component: "kernel",
2987
+ category: "ontology",
2988
+ shape: z.object({
2989
+ "ontologyId": idOf("ontologyDefinitions"),
2990
+ "ontologyKey": z.string(),
2991
+ "version": z.string(),
2992
+ "status": z.enum(["draft", "published", "deprecated"]),
2993
+ "entityTypes": z.array(z.object({
2994
+ "value": z.string(),
2995
+ "label": z.string(),
2996
+ "description": z.string().optional(),
2997
+ "schema": z.any().optional(),
2998
+ "subtypes": z.array(z.object({
2999
+ "value": z.string(),
3000
+ "label": z.string(),
3001
+ "description": z.string().optional()
3002
+ })).optional()
3003
+ })),
3004
+ "edgeTypes": z.array(z.object({
3005
+ "value": z.string(),
3006
+ "label": z.string(),
3007
+ "description": z.string().optional(),
3008
+ "sourceTypes": z.array(z.string()).optional(),
3009
+ "targetTypes": z.array(z.string()).optional(),
3010
+ "constraintSeverity": z.enum(["warn", "info"]).optional()
3011
+ })),
3012
+ "releaseNotes": z.string().optional(),
3013
+ "publishedBy": z.string().optional(),
3014
+ "publishedAt": z.number().optional(),
3015
+ "createdAt": z.number()
3016
+ }),
3017
+ indices: [
3018
+ { kind: "index", name: "by_ontologyId", columns: ["ontologyId"] },
3019
+ { kind: "index", name: "by_ontologyKey", columns: ["ontologyKey"] },
3020
+ { kind: "index", name: "by_ontologyKey_version", columns: ["ontologyKey", "version"] },
3021
+ { kind: "index", name: "by_status", columns: ["status"] },
3022
+ { kind: "index", name: "by_publishedAt", columns: ["publishedAt"] }
3023
+ ]
3024
+ });
3025
+ var packAssignments = defineTable({
3026
+ name: "packAssignments",
3027
+ component: "mc",
3028
+ category: "pack",
3029
+ shape: z.object({
3030
+ "groupId": idOf("groups"),
3031
+ "packKey": z.string(),
3032
+ "tenantId": idOf("tenants"),
3033
+ "status": z.enum(["active", "revoked"]),
3034
+ "assignedBy": z.string(),
3035
+ "createdAt": z.number(),
3036
+ "updatedAt": z.number()
3037
+ }),
3038
+ indices: [
3039
+ { kind: "index", name: "by_groupId", columns: ["groupId"] },
3040
+ { kind: "index", name: "by_tenantId", columns: ["tenantId"] },
3041
+ { kind: "index", name: "by_tenant_packKey", columns: ["tenantId", "packKey"] },
3042
+ { kind: "index", name: "by_group_packKey", columns: ["groupId", "packKey"] },
3043
+ { kind: "index", name: "by_status", columns: ["status"] }
3044
+ ]
3045
+ });
3046
+ var packDefinitions = defineTable({
3047
+ name: "packDefinitions",
3048
+ component: "mc",
3049
+ category: "pack",
3050
+ shape: z.object({
3051
+ "packKey": z.string(),
3052
+ "name": z.string(),
3053
+ "description": z.string().optional(),
3054
+ "category": z.enum(["developer", "strategy", "data", "methodology", "ontology", "custom"]),
3055
+ "lifecycle": z.enum(["active", "beta", "experimental"]),
3056
+ "tierRequirement": z.enum(["free", "developer", "team", "enterprise"]),
3057
+ "installScope": z.enum(["tenant", "workspace"]).optional(),
3058
+ "toolNames": z.array(z.string()),
3059
+ "promptNames": z.array(z.string()).optional(),
3060
+ "agentKeys": z.array(z.string()).optional(),
3061
+ "methodologyPackIds": z.array(z.string()).optional(),
3062
+ "ontologyConfig": z.object({
3063
+ "ontologyKey": z.string(),
3064
+ "ontologyVersion": z.string().optional(),
3065
+ "topicBindings": z.array(z.object({
3066
+ "topicType": z.string(),
3067
+ "autoBindNewTopics": z.boolean()
3068
+ })).optional()
3069
+ }).optional(),
3070
+ "lensConfig": z.array(z.object({
3071
+ "lensKey": z.string(),
3072
+ "perspectiveType": z.string()
3073
+ })).optional(),
3074
+ "configTemplates": z.record(z.any()).optional(),
3075
+ "topicIds": z.array(z.string()).optional(),
3076
+ "status": z.enum(["draft", "active", "archived"]),
3077
+ "createdBy": z.string(),
3078
+ "createdAt": z.number(),
3079
+ "updatedAt": z.number()
3080
+ }),
3081
+ indices: [
3082
+ { kind: "index", name: "by_packKey", columns: ["packKey"] },
3083
+ { kind: "index", name: "by_category", columns: ["category"] },
3084
+ { kind: "index", name: "by_lifecycle", columns: ["lifecycle"] },
3085
+ { kind: "index", name: "by_status", columns: ["status"] },
3086
+ { kind: "index", name: "by_tierRequirement", columns: ["tierRequirement"] }
3087
+ ]
3088
+ });
3089
+ var packEntitlements = defineTable({
3090
+ name: "packEntitlements",
3091
+ component: "mc",
3092
+ category: "pack",
3093
+ shape: z.object({
3094
+ "tenantId": idOf("tenants"),
3095
+ "workspaceId": idOf("workspaces").optional(),
3096
+ "packKey": z.string(),
3097
+ "status": z.enum(["active", "disabled", "revoked"]),
3098
+ "allowedLifecycles": z.array(z.enum(["active", "beta", "experimental"])).optional(),
3099
+ "minVersion": z.string().optional(),
3100
+ "maxVersion": z.string().optional(),
3101
+ "metadata": z.record(z.any()).optional(),
3102
+ "grantedBy": z.string().optional(),
3103
+ "createdAt": z.number(),
3104
+ "updatedAt": z.number()
3105
+ }),
3106
+ indices: [
3107
+ { kind: "index", name: "by_packKey", columns: ["packKey"] },
3108
+ { kind: "index", name: "by_tenantId", columns: ["tenantId"] },
3109
+ { kind: "index", name: "by_workspaceId", columns: ["workspaceId"] },
3110
+ { kind: "index", name: "by_tenant_packKey", columns: ["tenantId", "packKey"] },
3111
+ { kind: "index", name: "by_tenant_workspace_packKey", columns: ["tenantId", "workspaceId", "packKey"] },
3112
+ { kind: "index", name: "by_tenant_status", columns: ["tenantId", "status"] },
3113
+ { kind: "index", name: "by_workspace_status", columns: ["workspaceId", "status"] }
3114
+ ]
3115
+ });
3116
+ var packGroupAssignments = defineTable({
3117
+ name: "packGroupAssignments",
3118
+ component: "mc",
3119
+ category: "pack",
3120
+ shape: z.object({
3121
+ "groupId": idOf("groups"),
3122
+ "tenantId": idOf("tenants"),
3123
+ "packKey": z.string(),
3124
+ "packVersion": z.string().optional(),
3125
+ "status": z.enum(["active", "disabled"]),
3126
+ "assignedBy": z.string(),
3127
+ "createdAt": z.number(),
3128
+ "updatedAt": z.number()
3129
+ }),
3130
+ indices: [
3131
+ { kind: "index", name: "by_groupId", columns: ["groupId"] },
3132
+ { kind: "index", name: "by_tenantId", columns: ["tenantId"] },
3133
+ { kind: "index", name: "by_tenant_packKey", columns: ["tenantId", "packKey"] },
3134
+ { kind: "index", name: "by_group_packKey", columns: ["groupId", "packKey"] }
3135
+ ]
3136
+ });
3137
+ var packInstallations = defineTable({
3138
+ name: "packInstallations",
3139
+ component: "mc",
3140
+ category: "pack",
3141
+ shape: z.object({
3142
+ "tenantId": idOf("tenants"),
3143
+ "workspaceId": idOf("workspaces").optional(),
3144
+ "installScope": z.enum(["tenant", "workspace"]).optional(),
3145
+ "packKey": z.string(),
3146
+ "packVersion": z.string(),
3147
+ "candidateVersion": z.string().optional(),
3148
+ "versionWindowState": z.enum(["none", "prepared", "canary", "committed", "rolled_back"]).optional(),
3149
+ "upgradeStartedAt": z.number().optional(),
3150
+ "upgradeCompletedAt": z.number().optional(),
3151
+ "runtimeState": z.enum(["registered", "validated", "installed", "enabled", "degraded", "disabled", "removed"]),
3152
+ "healthStatus": z.enum(["unknown", "healthy", "degraded", "failing"]),
3153
+ "installStatus": z.enum(["installing", "installed", "partial_failure", "uninstalling"]).optional(),
3154
+ "componentStatus": z.record(z.any()).optional(),
3155
+ "lastError": z.string().optional(),
3156
+ "installedBy": z.string().optional(),
3157
+ "enabledBy": z.string().optional(),
3158
+ "disabledBy": z.string().optional(),
3159
+ "lastHealthCheckAt": z.number().optional(),
3160
+ "metadata": z.record(z.any()).optional(),
3161
+ "createdAt": z.number(),
3162
+ "updatedAt": z.number()
3163
+ }),
3164
+ indices: [
3165
+ { kind: "index", name: "by_tenantId", columns: ["tenantId"] },
3166
+ { kind: "index", name: "by_workspaceId", columns: ["workspaceId"] },
3167
+ { kind: "index", name: "by_packKey", columns: ["packKey"] },
3168
+ { kind: "index", name: "by_packKey_version", columns: ["packKey", "packVersion"] },
3169
+ { kind: "index", name: "by_tenant_packKey", columns: ["tenantId", "packKey"] },
3170
+ { kind: "index", name: "by_tenant_workspace_packKey", columns: ["tenantId", "workspaceId", "packKey"] },
3171
+ { kind: "index", name: "by_tenant_runtimeState", columns: ["tenantId", "runtimeState"] },
3172
+ { kind: "index", name: "by_workspace_runtimeState", columns: ["workspaceId", "runtimeState"] },
3173
+ { kind: "index", name: "by_tenant_healthStatus", columns: ["tenantId", "healthStatus"] },
3174
+ { kind: "index", name: "by_workspace_healthStatus", columns: ["workspaceId", "healthStatus"] }
3175
+ ]
3176
+ });
3177
+ var packVersions = defineTable({
3178
+ name: "packVersions",
3179
+ component: "mc",
3180
+ category: "pack",
3181
+ shape: z.object({
3182
+ "packKey": z.string(),
3183
+ "version": z.string(),
3184
+ "status": z.enum(["draft", "published", "deprecated"]),
3185
+ "toolManifest": z.array(z.object({
3186
+ "toolName": z.string(),
3187
+ "toolVersion": z.string(),
3188
+ "description": z.string().optional(),
3189
+ "category": z.enum(["read", "write", "admin", "system"]).optional(),
3190
+ "requiredRole": z.enum(["platform_admin", "tenant_admin", "workspace_admin", "editor", "viewer", "auditor", "service_agent"]).optional(),
3191
+ "requiredAction": z.enum(["read", "mutate", "admin", "summarize", "export", "create", "delete", "grant", "revoke"]).optional(),
3192
+ "surfaces": z.array(z.enum(["mcp", "chat", "voice", "sprint", "api", "sdk", "cli"])).optional(),
3193
+ "handlerRef": z.string().optional(),
3194
+ "parameterSchema": z.record(z.any()).optional(),
3195
+ "returnSchema": z.record(z.any()).optional(),
3196
+ "executionAdapter": z.enum(["convex_mutation", "convex_action", "http_callback", "mcp_tool", "sdk_invocation", "external_observed"]).optional(),
3197
+ "safetyMetadata": z.object({
3198
+ "readOnly": z.boolean(),
3199
+ "idempotent": z.boolean(),
3200
+ "sideEffectLevel": z.enum(["none", "low", "high"])
3201
+ }).optional()
3202
+ })),
3203
+ "promptManifest": z.array(z.string()).optional(),
3204
+ "agentManifest": z.array(z.string()).optional(),
3205
+ "methodologyManifest": z.array(z.string()).optional(),
3206
+ "ontologySnapshot": z.object({
3207
+ "ontologyKey": z.string(),
3208
+ "version": z.string(),
3209
+ "entityTypes": z.array(z.object({
3210
+ "value": z.string(),
3211
+ "label": z.string(),
3212
+ "description": z.string().optional(),
3213
+ "schema": z.any().optional(),
3214
+ "subtypes": z.array(z.object({
3215
+ "value": z.string(),
3216
+ "label": z.string(),
3217
+ "description": z.string().optional()
3218
+ })).optional()
3219
+ })),
3220
+ "edgeTypes": z.array(z.object({
3221
+ "value": z.string(),
3222
+ "label": z.string(),
3223
+ "description": z.string().optional(),
3224
+ "sourceTypes": z.array(z.string()).optional(),
3225
+ "targetTypes": z.array(z.string()).optional(),
3226
+ "constraintSeverity": z.enum(["warn", "info"]).optional()
3227
+ })),
3228
+ "topicBindings": z.array(z.object({
3229
+ "topicType": z.string(),
3230
+ "autoBindNewTopics": z.boolean()
3231
+ })).optional()
3232
+ }).optional(),
3233
+ "lensManifest": z.array(z.object({
3234
+ "lensKey": z.string(),
3235
+ "name": z.string(),
3236
+ "description": z.string().optional(),
3237
+ "perspectiveType": z.string(),
3238
+ "promptTemplates": z.array(z.object({
3239
+ "key": z.string(),
3240
+ "promptRef": z.string(),
3241
+ "phase": z.string().optional(),
3242
+ "role": z.string().optional(),
3243
+ "version": z.string().optional(),
3244
+ "required": z.boolean().optional(),
3245
+ "metadata": z.any().optional()
3246
+ })),
3247
+ "workflowTemplates": z.array(z.object({
3248
+ "key": z.string(),
3249
+ "name": z.string(),
3250
+ "description": z.string().optional(),
3251
+ "steps": z.array(z.object({
3252
+ "key": z.string(),
3253
+ "title": z.string(),
3254
+ "description": z.string().optional(),
3255
+ "promptTemplateKey": z.string().optional(),
3256
+ "taskTemplateKeys": z.array(z.string()).optional(),
3257
+ "metadata": z.any().optional()
3258
+ })),
3259
+ "metadata": z.any().optional()
3260
+ })),
3261
+ "taskTemplates": z.array(z.object({
3262
+ "key": z.string(),
3263
+ "title": z.string(),
3264
+ "description": z.string().optional(),
3265
+ "priority": z.enum(["critical", "high", "medium", "low"]).optional(),
3266
+ "phase": z.string().optional(),
3267
+ "metadata": z.any().optional()
3268
+ })),
3269
+ "questionTemplates": z.array(z.object({
3270
+ "key": z.string(),
3271
+ "text": z.string(),
3272
+ "priority": z.enum(["critical", "high", "medium", "low"]).optional(),
3273
+ "linkedBeliefKey": z.string().optional(),
3274
+ "metadata": z.any().optional()
3275
+ })).optional(),
3276
+ "filterCriteria": z.any().optional(),
3277
+ "topicTypeAffinity": z.array(z.string()).optional(),
3278
+ "metadata": z.any().optional()
3279
+ })).optional(),
3280
+ "configSnapshot": z.record(z.any()).optional(),
3281
+ "topicIds": z.array(z.string()).optional(),
3282
+ "releaseNotes": z.string().optional(),
3283
+ "releasedBy": z.string(),
3284
+ "publishedAt": z.number().optional(),
3285
+ "createdAt": z.number()
3286
+ }),
3287
+ indices: [
3288
+ { kind: "index", name: "by_packKey", columns: ["packKey"] },
3289
+ { kind: "index", name: "by_packKey_version", columns: ["packKey", "version"] },
3290
+ { kind: "index", name: "by_status", columns: ["status"] },
3291
+ { kind: "index", name: "by_publishedAt", columns: ["publishedAt"] }
3292
+ ]
3293
+ });
3294
+ var policyBundles = defineTable({
3295
+ name: "policyBundles",
3296
+ component: "mc",
3297
+ category: "policy",
3298
+ shape: z.object({
3299
+ "bundleKey": z.string(),
3300
+ "version": z.number(),
3301
+ "scope": z.enum(["platform", "tenant", "workspace"]),
3302
+ "tenantId": idOf("tenants").optional(),
3303
+ "workspaceId": idOf("workspaces").optional(),
3304
+ "status": z.enum(["draft", "validated", "enforced", "archived"]),
3305
+ "policyHash": z.string().optional(),
3306
+ "rules": z.record(z.any()),
3307
+ "metadata": z.record(z.any()).optional(),
3308
+ "createdBy": z.string().optional(),
3309
+ "createdAt": z.number(),
3310
+ "updatedAt": z.number()
3311
+ }),
3312
+ indices: [
3313
+ { kind: "index", name: "by_bundle_key", columns: ["bundleKey"] },
3314
+ { kind: "index", name: "by_bundle_key_version", columns: ["bundleKey", "version"] },
3315
+ { kind: "index", name: "by_scope_status", columns: ["scope", "status"] },
3316
+ { kind: "index", name: "by_tenant_status", columns: ["tenantId", "status"] },
3317
+ { kind: "index", name: "by_workspace_status", columns: ["workspaceId", "status"] }
3318
+ ]
3319
+ });
3320
+ var policyDecisionLogs = defineTable({
3321
+ name: "policyDecisionLogs",
3322
+ component: "mc",
3323
+ category: "policy",
3324
+ shape: z.object({
3325
+ "principalId": z.string(),
3326
+ "tenantId": idOf("tenants").optional(),
3327
+ "workspaceId": idOf("workspaces").optional(),
3328
+ "resourceType": z.string(),
3329
+ "resourceId": z.string(),
3330
+ "action": z.enum(["read", "summarize", "export", "mutate", "admin", "comment", "escalate", "resolve", "vote"]),
3331
+ "decision": z.enum(["allow", "deny"]),
3332
+ "reasonCode": z.string(),
3333
+ "policyVersion": z.string(),
3334
+ "policyBundleId": idOf("policyBundles").optional(),
3335
+ "audienceKey": z.string().optional(),
3336
+ "audienceClass": z.enum(["internal", "restricted_external", "public"]).optional(),
3337
+ "audienceMode": z.string().optional(),
3338
+ "traceId": z.string().optional(),
3339
+ "packKey": z.string().optional(),
3340
+ "metadata": z.record(z.any()).optional(),
3341
+ "createdAt": z.number()
3342
+ }),
3343
+ indices: [
3344
+ { kind: "index", name: "by_principal_createdAt", columns: ["principalId", "createdAt"] },
3345
+ { kind: "index", name: "by_tenant_createdAt", columns: ["tenantId", "createdAt"] },
3346
+ { kind: "index", name: "by_pack_createdAt", columns: ["packKey", "createdAt"] },
3347
+ { kind: "index", name: "by_audienceKey_createdAt", columns: ["audienceKey", "createdAt"] },
3348
+ { kind: "index", name: "by_decision_createdAt", columns: ["decision", "createdAt"] },
3349
+ { kind: "index", name: "by_traceId", columns: ["traceId"] }
3350
+ ]
3351
+ });
3352
+ var policySimulations = defineTable({
3353
+ name: "policySimulations",
3354
+ component: "mc",
3355
+ category: "policy",
3356
+ shape: z.object({
3357
+ "simulationKey": z.string(),
3358
+ "tenantId": idOf("tenants").optional(),
3359
+ "workspaceId": idOf("workspaces").optional(),
3360
+ "actorPrincipalId": z.string(),
3361
+ "input": z.record(z.any()),
3362
+ "result": z.record(z.any()),
3363
+ "metadata": z.record(z.any()).optional(),
3364
+ "createdAt": z.number()
3365
+ }),
3366
+ indices: [
3367
+ { kind: "index", name: "by_simulation_key", columns: ["simulationKey"] },
3368
+ { kind: "index", name: "by_tenant_createdAt", columns: ["tenantId", "createdAt"] },
3369
+ { kind: "index", name: "by_workspace_createdAt", columns: ["workspaceId", "createdAt"] },
3370
+ { kind: "index", name: "by_actor_createdAt", columns: ["actorPrincipalId", "createdAt"] }
3371
+ ]
3372
+ });
3373
+ var controlPlaneToolAcls = defineTable({
3374
+ name: "controlPlaneToolAcls",
3375
+ component: "mc",
3376
+ category: "policy",
3377
+ shape: z.object({
3378
+ "tenantId": idOf("tenants"),
3379
+ "role": z.string(),
3380
+ "toolName": z.string(),
3381
+ "createdBy": z.string(),
3382
+ "createdAt": z.number(),
3383
+ "updatedAt": z.number()
3384
+ }),
3385
+ indices: [
3386
+ { kind: "index", name: "by_tenant_role", columns: ["tenantId", "role"] },
3387
+ { kind: "index", name: "by_tenant_toolName", columns: ["tenantId", "toolName"] }
3388
+ ]
3389
+ });
3390
+ var projectGrants = defineTable({
3391
+ name: "projectGrants",
3392
+ component: "identity",
3393
+ category: "project",
3394
+ shape: z.object({
3395
+ "projectId": z.string().optional(),
3396
+ "topicId": z.string().optional(),
3397
+ "beliefClusterId": z.string().optional(),
3398
+ "tenantId": z.string().optional(),
3399
+ "workspaceId": z.string().optional(),
3400
+ "subjectType": z.enum(["principal", "group"]),
3401
+ "principalId": z.string().optional(),
3402
+ "groupId": z.string().optional(),
3403
+ "role": z.enum(["viewer", "editor", "owner_delegate"]),
3404
+ "status": z.enum(["active", "revoked", "expired"]),
3405
+ "source": z.enum(["owner_share", "group_share", "external_share", "policy", "api", "migration"]),
3406
+ "grantedBy": z.string().optional(),
3407
+ "expiresAt": z.number().optional(),
3408
+ "createdAt": z.number(),
3409
+ "updatedAt": z.number()
3410
+ }),
3411
+ indices: [
3412
+ { kind: "index", name: "by_principal_status", columns: ["principalId", "status"] },
3413
+ { kind: "index", name: "by_group_status", columns: ["groupId", "status"] },
3414
+ { kind: "index", name: "by_tenant_workspace", columns: ["tenantId", "workspaceId"] },
3415
+ { kind: "index", name: "by_status", columns: ["status"] },
3416
+ { kind: "index", name: "by_topicId", columns: ["topicId"] },
3417
+ { kind: "index", name: "by_topic_status", columns: ["topicId", "status"] },
3418
+ { kind: "index", name: "by_topic_principal", columns: ["topicId", "principalId"] },
3419
+ { kind: "index", name: "by_topic_group", columns: ["topicId", "groupId"] },
3420
+ { kind: "index", name: "by_topic_cluster", columns: ["topicId", "beliefClusterId"] },
3421
+ { kind: "index", name: "by_topic_cluster_status", columns: ["topicId", "beliefClusterId", "status"] }
3422
+ ]
3423
+ });
3424
+ var reasoningPermissions = defineTable({
3425
+ name: "reasoningPermissions",
3426
+ component: "identity",
3427
+ category: "epistemic",
3428
+ shape: z.object({
3429
+ "topicId": z.string().optional(),
3430
+ "principalId": z.string(),
3431
+ "nodeType": z.enum(["belief", "evidence", "action", "approval", "artifact"]),
3432
+ "action": z.enum(["view_conclusion", "view_evidence", "propose_action", "approve_action", "view_derived_artifact"]),
3433
+ "effect": z.enum(["allow", "deny"]),
3434
+ "policyReference": z.string().optional(),
3435
+ "rationale": z.string().optional(),
3436
+ "metadata": z.record(z.any()).optional(),
3437
+ "createdAt": z.number(),
3438
+ "createdBy": z.string(),
3439
+ "updatedAt": z.number()
3440
+ }),
3441
+ indices: [
3442
+ { kind: "index", name: "by_topic_principal", columns: ["topicId", "principalId"] },
3443
+ { kind: "index", name: "by_topic_principal_action", columns: ["topicId", "principalId", "action"] },
3444
+ { kind: "index", name: "by_topic_principal_node_action", columns: ["topicId", "principalId", "nodeType", "action"] },
3445
+ { kind: "index", name: "by_principal_action", columns: ["principalId", "action"] }
3446
+ ]
3447
+ });
3448
+ var schemaEnumConfig = defineTable({
3449
+ name: "schemaEnumConfig",
3450
+ component: "kernel",
3451
+ category: "config",
3452
+ shape: z.object({
3453
+ "tenantId": z.string().optional(),
3454
+ "category": z.string(),
3455
+ "value": z.string(),
3456
+ "label": z.string(),
3457
+ "description": z.string().optional(),
3458
+ "tier": z.enum(["platform", "tenant"]),
3459
+ "domainNamespace": z.string().optional(),
3460
+ "metadata": z.any().optional(),
3461
+ "isDefault": z.boolean().optional(),
3462
+ "sortOrder": z.number().optional(),
3463
+ "status": z.enum(["active", "deprecated"]),
3464
+ "createdAt": z.number(),
3465
+ "updatedAt": z.number()
3466
+ }),
3467
+ indices: [
3468
+ { kind: "index", name: "by_category", columns: ["category"] },
3469
+ { kind: "index", name: "by_tenant_category", columns: ["tenantId", "category"] },
3470
+ { kind: "index", name: "by_category_value", columns: ["category", "value"] }
3471
+ ]
3472
+ });
3473
+ var tasks = defineTable({
3474
+ name: "tasks",
3475
+ component: "kernel",
3476
+ category: "task",
3477
+ shape: z.object({
3478
+ "topicId": z.string().optional(),
3479
+ "tenantId": z.string().optional(),
3480
+ "workspaceId": z.string().optional(),
3481
+ "title": z.string(),
3482
+ "description": z.string().optional(),
3483
+ "status": z.enum(["todo", "in_progress", "blocked", "done"]),
3484
+ "priority": z.enum(["urgent", "high", "medium", "low"]),
3485
+ "dueDate": z.number().optional(),
3486
+ "linkedWorktreeId": idOf("worktrees").optional(),
3487
+ "linkedBeliefId": z.string().optional(),
3488
+ "linkedQuestionId": z.string().optional(),
3489
+ "taskType": z.enum(["general", "find_evidence", "verify_claim", "research", "review", "interview", "analysis", "track_metrics"]).optional(),
3490
+ "assigneeId": z.string().optional(),
3491
+ "blockedReason": z.string().optional(),
3492
+ "blockedBy": z.array(idOf("tasks")).optional(),
3493
+ "blocks": z.array(idOf("tasks")).optional(),
3494
+ "sortOrder": z.number().optional(),
3495
+ "executionOrder": z.number().optional(),
3496
+ "subtasks": z.array(z.object({
3497
+ "id": z.string(),
3498
+ "title": z.string(),
3499
+ "completed": z.boolean(),
3500
+ "completedAt": z.number().optional()
3501
+ })).optional(),
3502
+ "comments": z.array(z.object({
3503
+ "id": z.string(),
3504
+ "userId": z.string(),
3505
+ "content": z.string(),
3506
+ "createdAt": z.number()
3507
+ })).optional(),
3508
+ "attachments": z.array(z.object({
3509
+ "id": z.string(),
3510
+ "type": z.enum(["call_script", "email_template", "research_plan", "framework", "checklist", "note", "file", "transcript"]),
3511
+ "title": z.string(),
3512
+ "content": z.string(),
3513
+ "metadata": z.object({
3514
+ "items": z.array(z.object({
3515
+ "id": z.string(),
3516
+ "text": z.string(),
3517
+ "completed": z.boolean()
3518
+ })).optional(),
3519
+ "fileUrl": z.string().optional(),
3520
+ "fileName": z.string().optional(),
3521
+ "fileSize": z.number().optional(),
3522
+ "frameworkType": z.string().optional(),
3523
+ "variables": z.array(z.string()).optional(),
3524
+ "mappedQuestions": z.array(z.object({
3525
+ "id": z.string(),
3526
+ "questionText": z.string(),
3527
+ "linkedQuestionId": z.string().optional(),
3528
+ "linkedBeliefId": z.string().optional(),
3529
+ "category": z.string().optional(),
3530
+ "priority": z.enum(["must_ask", "nice_to_have"]).optional(),
3531
+ "answered": z.boolean().optional(),
3532
+ "answerExcerpt": z.string().optional(),
3533
+ "answerTimestamp": z.string().optional(),
3534
+ "capturedAsInsight": z.boolean().optional(),
3535
+ "insightId": idOf("epistemicNodes").optional()
3536
+ })).optional(),
3537
+ "linkedCallScriptId": z.string().optional(),
3538
+ "editable": z.boolean().optional(),
3539
+ "executionTool": z.string().optional(),
3540
+ "linkedQuestionId": z.string().optional(),
3541
+ "linkedBeliefId": z.string().optional(),
3542
+ "workflowStepId": z.string().optional(),
3543
+ "workflowOrder": z.number().optional(),
3544
+ "dependsOnStepIds": z.array(z.string()).optional(),
3545
+ "runCondition": z.string().optional(),
3546
+ "continueOnFailure": z.boolean().optional(),
3547
+ "stepStatus": z.enum(["pending", "running", "completed", "failed", "skipped"]).optional(),
3548
+ "stepRunCount": z.number().optional(),
3549
+ "stepLastRunAt": z.number().optional(),
3550
+ "stepOutputSummary": z.string().optional(),
3551
+ "stepOutputData": z.string().optional(),
3552
+ "stepFailureReason": z.string().optional(),
3553
+ "researchResult": z.string().optional(),
3554
+ "researchStatus": z.enum(["pending", "running", "completed", "failed"]).optional(),
3555
+ "researchCompletedAt": z.number().optional(),
3556
+ "researchCitations": z.array(z.union([z.string(), z.object({
3557
+ "url": z.string(),
3558
+ "title": z.string().optional(),
3559
+ "snippet": z.string().optional()
3560
+ })])).optional(),
3561
+ "generatedPersonas": z.array(z.any()).optional(),
3562
+ "personasGeneratedAt": z.number().optional(),
3563
+ "expertSearchResults": z.array(z.any()).optional(),
3564
+ "expertSearchAt": z.number().optional(),
3565
+ "capturedAsEvidence": z.boolean().optional(),
3566
+ "capturedInsightId": z.string().optional(),
3567
+ "capturedAt": z.number().optional(),
3568
+ "capturedImpact": z.number().optional(),
3569
+ "tools": z.array(z.object({
3570
+ "tool": z.string(),
3571
+ "purpose": z.string(),
3572
+ "suggestedQuery": z.string()
3573
+ })).optional(),
3574
+ "metrics": z.array(z.object({
3575
+ "metric": z.string(),
3576
+ "source": z.string(),
3577
+ "frequency": z.string(),
3578
+ "currentValue": z.string().optional()
3579
+ })).optional(),
3580
+ "personas": z.array(z.object({
3581
+ "role": z.string(),
3582
+ "title": z.string(),
3583
+ "company": z.string(),
3584
+ "rationale": z.string()
3585
+ })).optional(),
3586
+ "experts": z.array(z.object({
3587
+ "expertise": z.string(),
3588
+ "potentialSources": z.array(z.string()),
3589
+ "questions": z.array(z.string()),
3590
+ "searchStrategy": z.string().optional()
3591
+ })).optional(),
3592
+ "factChecker": z.object({
3593
+ "claimsToVerify": z.array(z.string()),
3594
+ "sourcesToCheck": z.array(z.string()),
3595
+ "verificationCriteria": z.array(z.string())
3596
+ }).optional()
3597
+ }).optional(),
3598
+ "capturedAsEvidence": z.boolean().optional(),
3599
+ "capturedInsightId": idOf("epistemicNodes").optional(),
3600
+ "capturedAt": z.number().optional(),
3601
+ "createdBy": z.string(),
3602
+ "createdAt": z.number()
3603
+ })).optional(),
3604
+ "tags": z.array(z.string()).optional(),
3605
+ "executionType": z.enum(["research_search", "find_news", "identify_experts", "market_research", "generate_primer", "verify_claim", "manual", "mcp_research", "mcp_web_search", "mcp_capture", "mcp_network_search"]).optional(),
3606
+ "executionStatus": z.enum(["pending", "running", "completed", "failed"]).optional(),
3607
+ "executionResults": z.union([z.string(), z.number(), z.boolean(), z.null(), z.record(z.any()), z.array(z.any())]).optional(),
3608
+ "executionStartedAt": z.number().optional(),
3609
+ "executionCompletedAt": z.number().optional(),
3610
+ "executionError": z.string().optional(),
3611
+ "mcpDatasetIds": z.array(z.string()).optional(),
3612
+ "mcpSkillIds": z.array(z.string()).optional(),
3613
+ "mcpExecutionId": z.string().optional(),
3614
+ "linkedChatId": z.string().optional(),
3615
+ "createdBy": z.string(),
3616
+ "createdAt": z.number(),
3617
+ "updatedAt": z.number(),
3618
+ "completedAt": z.number().optional(),
3619
+ "completedBy": z.string().optional()
3620
+ }),
3621
+ indices: [
3622
+ { kind: "index", name: "by_topicId", columns: ["topicId"] },
3623
+ { kind: "index", name: "by_topicId_status", columns: ["topicId", "status"] },
3624
+ { kind: "index", name: "by_tenantId", columns: ["tenantId"] },
3625
+ { kind: "index", name: "by_workspaceId", columns: ["workspaceId"] },
3626
+ { kind: "index", name: "by_worktreeId", columns: ["linkedWorktreeId"] },
3627
+ { kind: "index", name: "by_beliefId", columns: ["linkedBeliefId"] },
3628
+ { kind: "index", name: "by_questionId", columns: ["linkedQuestionId"] },
3629
+ { kind: "index", name: "by_status", columns: ["status"] },
3630
+ { kind: "index", name: "by_assigneeId", columns: ["assigneeId"] },
3631
+ { kind: "index", name: "by_dueDate", columns: ["dueDate"] },
3632
+ { kind: "index", name: "by_priority", columns: ["priority"] },
3633
+ { kind: "index", name: "by_executionType", columns: ["executionType"] },
3634
+ { kind: "index", name: "by_executionStatus", columns: ["executionStatus"] }
3635
+ ]
3636
+ });
3637
+ var topics = defineTable({
3638
+ name: "topics",
3639
+ component: "kernel",
3640
+ category: "topic",
3641
+ shape: z.object({
3642
+ "globalId": z.string(),
3643
+ "name": z.string(),
3644
+ "description": z.string().optional(),
3645
+ "parentTopicId": idOf("topics").optional(),
3646
+ "depth": z.number(),
3647
+ "path": z.array(z.string()),
3648
+ "type": z.string(),
3649
+ "ontologyId": idOf("ontologyDefinitions").optional(),
3650
+ "graphScopeProjectId": z.string().optional(),
3651
+ "metadata": z.any().optional(),
3652
+ "tenantId": z.string().optional(),
3653
+ "workspaceId": z.string().optional(),
3654
+ "status": TOPIC_STATUS,
3655
+ "visibility": TOPIC_VISIBILITY.optional(),
3656
+ "createdBy": z.string(),
3657
+ "createdAt": z.number(),
3658
+ "updatedAt": z.number()
3659
+ }),
3660
+ indices: [
3661
+ { kind: "index", name: "by_parent", columns: ["parentTopicId"] },
3662
+ { kind: "index", name: "by_type", columns: ["type"] },
3663
+ { kind: "index", name: "by_graph_scope_project", columns: ["graphScopeProjectId"] },
3664
+ { kind: "index", name: "by_tenant", columns: ["tenantId"] },
3665
+ { kind: "index", name: "by_ontology", columns: ["ontologyId"] },
3666
+ { kind: "index", name: "by_path", columns: ["path"] },
3667
+ { kind: "search", name: "search_name", searchField: "name", filterFields: ["tenantId", "type"] }
3668
+ ]
3669
+ });
3670
+ var users = defineTable({
3671
+ name: "users",
3672
+ component: "identity",
3673
+ category: "user",
3674
+ shape: z.object({
3675
+ "clerkId": z.string(),
3676
+ "email": z.string(),
3677
+ "name": z.string().optional(),
3678
+ "imageUrl": z.string().optional(),
3679
+ "lastSeenAt": z.number(),
3680
+ "chatCount": z.number(),
3681
+ "messageCount": z.number(),
3682
+ "isAdmin": z.boolean().optional(),
3683
+ "mcRole": z.enum(["platform_admin", "tenant_admin", "workspace_admin", "editor", "viewer", "auditor", "service_agent"]).optional(),
3684
+ "mcRoleSyncedAt": z.number().optional(),
3685
+ "defaultTenantId": z.string().optional(),
3686
+ "defaultWorkspaceId": z.string().optional(),
3687
+ "defaultPrincipalId": z.string().optional(),
3688
+ "principalGroupIds": z.array(z.string()).optional(),
3689
+ "permittedPackKeys": z.array(z.string()).optional(),
3690
+ "permittedToolNames": z.array(z.string()).optional(),
3691
+ "governanceGrantsSyncedAt": z.number().optional(),
3692
+ "createdAt": z.number(),
3693
+ "updatedAt": z.number()
3694
+ }),
3695
+ indices: [
3696
+ { kind: "index", name: "by_clerkId", columns: ["clerkId"] },
3697
+ { kind: "index", name: "by_email", columns: ["email"] },
3698
+ { kind: "index", name: "by_lastSeenAt", columns: ["lastSeenAt"] },
3699
+ { kind: "index", name: "by_defaultTenantId", columns: ["defaultTenantId"] },
3700
+ { kind: "index", name: "by_defaultWorkspaceId", columns: ["defaultWorkspaceId"] }
3701
+ ]
3702
+ });
3703
+ var workflowDefinitions = defineTable({
3704
+ name: "workflowDefinitions",
3705
+ component: "kernel",
3706
+ category: "workflow",
3707
+ shape: z.object({
3708
+ "tenantId": z.string(),
3709
+ "name": z.string(),
3710
+ "displayName": z.string(),
3711
+ "description": z.string().optional(),
3712
+ "status": z.enum(["draft", "active", "deprecated"]),
3713
+ "version": z.number(),
3714
+ "metadata": z.record(z.any()).optional(),
3715
+ "createdBy": z.string(),
3716
+ "createdAt": z.number(),
3717
+ "updatedAt": z.number()
3718
+ }),
3719
+ indices: [
3720
+ { kind: "index", name: "by_tenant", columns: ["tenantId"] },
3721
+ { kind: "index", name: "by_tenant_name", columns: ["tenantId", "name"] },
3722
+ { kind: "index", name: "by_tenant_status", columns: ["tenantId", "status"] }
3723
+ ]
3724
+ });
3725
+ var workflowPullRequests = defineTable({
3726
+ name: "workflowPullRequests",
3727
+ component: "kernel",
3728
+ category: "workflow",
3729
+ shape: z.object({
3730
+ "topicId": z.string().optional(),
3731
+ "worktreeId": idOf("worktrees"),
3732
+ "status": z.enum(["pending_review", "changes_requested", "approved", "blocked"]),
3733
+ "summary": z.string(),
3734
+ "reviewers": z.array(z.string()).optional(),
3735
+ "createdBy": z.string(),
3736
+ "createdAt": z.number(),
3737
+ "updatedAt": z.number(),
3738
+ "resolvedAt": z.number().optional(),
3739
+ "resolvedBy": z.string().optional(),
3740
+ "metadata": z.record(z.any()).optional()
3741
+ }),
3742
+ indices: [
3743
+ { kind: "index", name: "by_worktreeId", columns: ["worktreeId"] },
3744
+ { kind: "index", name: "by_status", columns: ["status"] },
3745
+ { kind: "index", name: "by_topicId", columns: ["topicId"] },
3746
+ { kind: "index", name: "by_topic_status", columns: ["topicId", "status"] }
3747
+ ]
3748
+ });
3749
+ var workflowStages = defineTable({
3750
+ name: "workflowStages",
3751
+ component: "kernel",
3752
+ category: "workflow",
3753
+ shape: z.object({
3754
+ "workflowDefinitionId": idOf("workflowDefinitions"),
3755
+ "name": z.string(),
3756
+ "displayName": z.string(),
3757
+ "description": z.string().optional(),
3758
+ "order": z.number(),
3759
+ "entryConditions": z.record(z.any()).optional(),
3760
+ "exitConditions": z.record(z.any()).optional(),
3761
+ "gateRules": z.record(z.any()).optional(),
3762
+ "isOptional": z.boolean().optional(),
3763
+ "metadata": z.record(z.any()).optional(),
3764
+ "createdAt": z.number(),
3765
+ "updatedAt": z.number()
3766
+ }),
3767
+ indices: [
3768
+ { kind: "index", name: "by_workflow", columns: ["workflowDefinitionId"] },
3769
+ { kind: "index", name: "by_workflow_order", columns: ["workflowDefinitionId", "order"] }
3770
+ ]
3771
+ });
3772
+ var workspaces = defineTable({
3773
+ name: "workspaces",
3774
+ component: "mc",
3775
+ category: "workspace",
3776
+ shape: z.object({
3777
+ "tenantId": idOf("tenants"),
3778
+ "key": z.string(),
3779
+ "slug": z.string(),
3780
+ "name": z.string(),
3781
+ "status": z.enum(["active", "archived"]),
3782
+ "defaultProjectVisibility": z.enum(["private", "team", "firm", "external", "public"]).optional(),
3783
+ "deployments": z.record(z.object({
3784
+ "url": z.string(),
3785
+ "encryptedDeployKey": z.string()
3786
+ })).optional(),
3787
+ "metadata": z.record(z.any()).optional(),
3788
+ "createdBy": z.string().optional(),
3789
+ "createdAt": z.number(),
3790
+ "updatedAt": z.number()
3791
+ }),
3792
+ indices: [
3793
+ { kind: "index", name: "by_tenantId", columns: ["tenantId"] },
3794
+ { kind: "index", name: "by_tenantId_key", columns: ["tenantId", "key"] },
3795
+ { kind: "index", name: "by_tenantId_slug", columns: ["tenantId", "slug"] },
3796
+ { kind: "index", name: "by_status", columns: ["status"] }
3797
+ ]
3798
+ });
3799
+ var worktreeBeliefCluster = defineTable({
3800
+ name: "worktreeBeliefCluster",
3801
+ component: "kernel",
3802
+ category: "worktree",
3803
+ shape: z.object({
3804
+ "worktreeId": idOf("worktrees"),
3805
+ "beliefId": z.string(),
3806
+ "relationType": z.enum(["primary", "counterfactual", "dependency", "cascade", "conditional", "supporting", "contradicting", "alternative", "prerequisite"]),
3807
+ "relationDescription": z.string().optional(),
3808
+ "counterfactualText": z.string().optional(),
3809
+ "dependencyText": z.string().optional(),
3810
+ "cascadeText": z.string().optional(),
3811
+ "initialConfidence": z.number().optional(),
3812
+ "initialEvidenceCount": z.number().optional(),
3813
+ "finalConfidence": z.number().optional(),
3814
+ "finalEvidenceCount": z.number().optional(),
3815
+ "confidenceDelta": z.number().optional(),
3816
+ "llmValence": z.number().optional(),
3817
+ "llmCertainty": z.number().optional(),
3818
+ "llmReasoning": z.string().optional(),
3819
+ "llmEvidenceScores": z.string().optional(),
3820
+ "llmAssessedAt": z.number().optional(),
3821
+ "addedAt": z.number(),
3822
+ "updatedAt": z.number()
3823
+ }),
3824
+ indices: [
3825
+ { kind: "index", name: "by_worktree", columns: ["worktreeId"] },
3826
+ { kind: "index", name: "by_belief", columns: ["beliefId"] },
3827
+ { kind: "index", name: "by_worktree_relation", columns: ["worktreeId", "relationType"] }
3828
+ ]
3829
+ });
3830
+ var worktrees = defineTable({
3831
+ name: "worktrees",
3832
+ component: "kernel",
3833
+ category: "worktree",
3834
+ shape: z.object({
3835
+ "topicId": z.string().optional(),
3836
+ "index": z.number(),
3837
+ "name": z.string(),
3838
+ "beliefFocus": z.string().optional(),
3839
+ "objective": z.string(),
3840
+ "worktreeType": z.string().optional(),
3841
+ "rationale": z.string().optional(),
3842
+ "confidenceImpact": z.enum(["high", "medium", "low"]).optional(),
3843
+ "hypothesis": z.string().optional(),
3844
+ "executionOrder": z.number().optional(),
3845
+ "dependsOn": z.array(idOf("worktrees")).optional(),
3846
+ "blocks": z.array(idOf("worktrees")).optional(),
3847
+ "gate": z.string().optional(),
3848
+ "track": z.string().optional(),
3849
+ "trackPosition": z.number().optional(),
3850
+ "executionBand": z.number().optional(),
3851
+ "startDate": z.number(),
3852
+ "endDate": z.number(),
3853
+ "durationWeeks": z.number(),
3854
+ "status": z.enum(["suggested", "planning", "active", "paused", "completed", "dismissed", "abandoned"]),
3855
+ "generatedBy": z.string().optional(),
3856
+ "epistemicOrigin": z.string().optional(),
3857
+ "priority": z.number().optional(),
3858
+ "dismissedReason": z.string().optional(),
3859
+ "userId": z.string().optional(),
3860
+ "createdAt": z.number().optional(),
3861
+ "updatedAt": z.number().optional(),
3862
+ "chatId": z.string().optional(),
3863
+ "tasks": z.union([z.string(), z.number(), z.boolean(), z.null(), z.record(z.any()), z.array(z.any())]).optional(),
3864
+ "targetBeliefIds": z.array(z.string()),
3865
+ "targetQuestionIds": z.array(z.string()),
3866
+ "keyQuestions": z.array(z.object({
3867
+ "question": z.string(),
3868
+ "status": z.enum(["open", "answered", "forked"]),
3869
+ "answer": z.string().optional(),
3870
+ "answerConfidence": z.enum(["high", "medium", "low"]).optional(),
3871
+ "linkedQuestionId": z.string().optional()
3872
+ })).optional(),
3873
+ "evidenceSignals": z.array(z.object({
3874
+ "signal": z.string(),
3875
+ "collected": z.boolean(),
3876
+ "progress": z.string().optional(),
3877
+ "notes": z.string().optional()
3878
+ })).optional(),
3879
+ "decisionGate": z.object({
3880
+ "goCriteria": z.array(z.string()),
3881
+ "noGoSignals": z.array(z.string()),
3882
+ "verdict": z.enum(["go", "no_go", "pivot", "pending"]).optional(),
3883
+ "verdictRationale": z.string().optional(),
3884
+ "decidedAt": z.number().optional(),
3885
+ "decidedBy": z.string().optional()
3886
+ }).optional(),
3887
+ "beliefRefinement": z.object({
3888
+ "isRefined": z.boolean(),
3889
+ "refinedAt": z.number().optional(),
3890
+ "refinedBy": z.string().optional(),
3891
+ "originalText": z.string().optional(),
3892
+ "refinedText": z.string().optional(),
3893
+ "testingCriteria": z.string().optional(),
3894
+ "measurableCriteria": z.string().optional(),
3895
+ "timeframe": z.string().optional(),
3896
+ "checklist": z.object({
3897
+ "hasSpecificClaim": z.boolean(),
3898
+ "hasTimeframe": z.boolean(),
3899
+ "hasMeasurableCriteria": z.boolean(),
3900
+ "hasTestability": z.boolean()
3901
+ }).optional()
3902
+ }).optional(),
3903
+ "beliefRefinements": z.array(z.any()).optional(),
3904
+ "startingConfidence": z.object({
3905
+ "overall": z.number(),
3906
+ "beliefConfidences": z.array(z.object({
3907
+ "beliefId": z.string(),
3908
+ "confidence": z.number()
3909
+ }))
3910
+ }).optional(),
3911
+ "endingConfidence": z.object({
3912
+ "overall": z.number(),
3913
+ "beliefConfidences": z.array(z.object({
3914
+ "beliefId": z.string(),
3915
+ "confidence": z.number()
3916
+ }))
3917
+ }).optional(),
3918
+ "outcome": z.object({
3919
+ "verdict": z.enum(["validated", "invalidated", "forked", "inconclusive"]),
3920
+ "summary": z.string(),
3921
+ "whatChanged": z.string(),
3922
+ "confidenceChange": z.number()
3923
+ }).optional(),
3924
+ "epistemicChain": z.object({
3925
+ "capturedAt": z.number(),
3926
+ "capturedBy": z.string(),
3927
+ "worktreeId": idOf("worktrees"),
3928
+ "topicId": z.string().optional(),
3929
+ "primaryBelief": z.object({
3930
+ "id": z.string(),
3931
+ "text": z.string(),
3932
+ "startingConfidence": z.number(),
3933
+ "startingConfidenceLabel": z.string().optional(),
3934
+ "endingConfidence": z.number(),
3935
+ "endingConfidenceLabel": z.string().optional(),
3936
+ "confidenceScore": z.number().optional(),
3937
+ "status": z.string().optional(),
3938
+ "criticality": z.string().optional()
3939
+ }).optional(),
3940
+ "clusterEdges": z.array(z.object({
3941
+ "edgeId": z.string().optional(),
3942
+ "edgeType": z.string(),
3943
+ "sourceId": z.string(),
3944
+ "targetId": z.string(),
3945
+ "weight": z.number().optional(),
3946
+ "createdAt": z.number().optional()
3947
+ })),
3948
+ "relatedBeliefs": z.array(z.object({
3949
+ "id": z.string(),
3950
+ "text": z.string().optional(),
3951
+ "confidence": z.string().optional(),
3952
+ "confidenceScore": z.number().optional()
3953
+ })).optional(),
3954
+ "questions": z.array(z.object({
3955
+ "id": z.string(),
3956
+ "text": z.string(),
3957
+ "status": z.string(),
3958
+ "priority": z.string().optional(),
3959
+ "answer": z.string().optional(),
3960
+ "answerStatus": z.string().optional(),
3961
+ "answeredBy": z.string().optional(),
3962
+ "answeredAt": z.number().optional(),
3963
+ "evidenceCount": z.number()
3964
+ })),
3965
+ "evidence": z.array(z.object({
3966
+ "id": z.string(),
3967
+ "text": z.string(),
3968
+ "sourceType": z.string().optional(),
3969
+ "verificationStatus": z.string().optional(),
3970
+ "verified": z.boolean(),
3971
+ "createdAt": z.number().optional()
3972
+ })),
3973
+ "tasksCompleted": z.number().optional(),
3974
+ "totalTasks": z.number().optional(),
3975
+ "outcome": z.object({
3976
+ "verdict": z.string(),
3977
+ "summary": z.string(),
3978
+ "confidenceChange": z.number(),
3979
+ "startingConfidence": z.number(),
3980
+ "endingConfidence": z.number()
3981
+ }),
3982
+ "confidenceHistory": z.array(z.object({
3983
+ "beliefId": z.string(),
3984
+ "recentChanges": z.array(z.object({
3985
+ "confidence": z.string().optional(),
3986
+ "trigger": z.string().optional(),
3987
+ "timestamp": z.number().optional()
3988
+ }))
3989
+ })).optional()
3990
+ }).optional(),
3991
+ "keyFindings": z.array(z.string()).optional(),
3992
+ "decisionsReached": z.array(z.string()).optional(),
3993
+ "nextSteps": z.array(z.string()).optional(),
3994
+ "retrospective": z.object({
3995
+ "whatWorked": z.array(z.string()),
3996
+ "whatDidnt": z.array(z.string()),
3997
+ "lessonsLearned": z.array(z.string()),
3998
+ "confidenceChange": z.number()
3999
+ }).optional(),
4000
+ "thesisReportId": z.string().optional(),
4001
+ "branchThesis": z.object({
4002
+ "content": z.string(),
4003
+ "memoContent": z.string().optional(),
4004
+ "status": z.enum(["ai_draft", "user_draft", "final"]),
4005
+ "generatedAt": z.number().optional(),
4006
+ "approvedAt": z.number().optional(),
4007
+ "approvedBy": z.string().optional(),
4008
+ "generationMetadata": z.object({
4009
+ "modelUsed": z.string(),
4010
+ "promptName": z.string(),
4011
+ "langfuseTraceId": z.string().optional()
4012
+ }).optional()
4013
+ }).optional(),
4014
+ "generatedAt": z.number().optional(),
4015
+ "sourceProposalId": z.string().optional(),
4016
+ "triggerReason": z.string().optional(),
4017
+ "linkedEvidenceIds": z.array(z.string()).optional(),
4018
+ "linkedDocumentIds": z.array(z.string()).optional(),
4019
+ "linkedCallIds": z.array(z.string()).optional(),
4020
+ "linkedNewsIds": z.array(z.string()).optional(),
4021
+ "linkedPrimerIds": z.array(z.string()).optional(),
4022
+ "linkedDeepResearchIds": z.array(z.string()).optional(),
4023
+ "notes": z.array(z.object({
4024
+ "id": z.string(),
4025
+ "content": z.string(),
4026
+ "createdAt": z.number(),
4027
+ "createdBy": z.string(),
4028
+ "linkedTaskId": z.string().optional(),
4029
+ "linkedQuestionId": z.string().optional(),
4030
+ "linkedBeliefId": z.string().optional()
4031
+ })).optional(),
4032
+ "targetBranch": z.string().optional(),
4033
+ "worktreeScope": z.enum(["belief", "branch"]).optional(),
4034
+ "synthesisState": z.object({
4035
+ "originalBeliefIds": z.array(z.string()),
4036
+ "synthesizedBeliefIds": z.array(z.string()),
4037
+ "synthesisComplete": z.boolean(),
4038
+ "synthesisRationale": z.string().optional(),
4039
+ "synthesisCompletedAt": z.number().optional(),
4040
+ "synthesisCompletedBy": z.string().optional()
4041
+ }).optional(),
4042
+ "evidenceReviewState": z.object({
4043
+ "existingEvidenceReviewed": z.boolean(),
4044
+ "evidenceGaps": z.array(z.string()),
4045
+ "strengthAreas": z.array(z.string()),
4046
+ "evidenceQuestionMapping": z.array(z.object({
4047
+ "evidenceId": z.string(),
4048
+ "questionIds": z.array(z.string()),
4049
+ "coverageNote": z.string().optional()
4050
+ })).optional(),
4051
+ "reviewCompletedAt": z.number().optional(),
4052
+ "reviewCompletedBy": z.string().optional()
4053
+ }).optional(),
4054
+ "phase": z.string().optional(),
4055
+ "clusterStatus": z.object({
4056
+ "totalConditionals": z.number(),
4057
+ "hasCounterfactuals": z.boolean(),
4058
+ "hasDependencies": z.boolean(),
4059
+ "hasCascades": z.boolean(),
4060
+ "conditionalsByType": z.object({
4061
+ "counterfactuals": z.number(),
4062
+ "dependencies": z.number(),
4063
+ "cascades": z.number(),
4064
+ "other": z.number()
4065
+ }).optional(),
4066
+ "mappingCompletedAt": z.number().optional(),
4067
+ "mappingCompletedBy": z.string().optional()
4068
+ }).optional(),
4069
+ "phaseHistory": z.array(z.object({
4070
+ "phase": z.string(),
4071
+ "enteredAt": z.number(),
4072
+ "pausedAt": z.number().optional(),
4073
+ "resumedAt": z.number().optional(),
4074
+ "completedAt": z.number().optional(),
4075
+ "completedBy": z.string().optional()
4076
+ })).optional(),
4077
+ "questionsCoverage": z.object({
4078
+ "totalQuestions": z.number(),
4079
+ "clusterNodesCovered": z.number(),
4080
+ "coveragePercent": z.number(),
4081
+ "gapsIdentified": z.array(z.string()).optional()
4082
+ }).optional(),
4083
+ "researchEfficiency": z.object({
4084
+ "totalTasks": z.number(),
4085
+ "questionsPerTask": z.number(),
4086
+ "clusterCoverage": z.number(),
4087
+ "efficiencyScore": z.number()
4088
+ }).optional(),
4089
+ "createdBy": z.string(),
4090
+ "metadata": z.any().optional()
4091
+ }),
4092
+ indices: [
4093
+ { kind: "index", name: "by_topicId", columns: ["topicId"] },
4094
+ { kind: "index", name: "by_topicId_status", columns: ["topicId", "status"] },
4095
+ { kind: "index", name: "by_topicId_index", columns: ["topicId", "index"] },
4096
+ { kind: "index", name: "by_worktreeType", columns: ["topicId", "worktreeType"] },
4097
+ { kind: "index", name: "by_topicId_priority", columns: ["topicId", "priority"] },
4098
+ { kind: "index", name: "by_topicId_branch", columns: ["topicId", "targetBranch"] },
4099
+ { kind: "index", name: "by_topicId_scope", columns: ["topicId", "worktreeScope"] }
4100
+ ]
4101
+ });
4102
+
4103
+ // src/schemas/manifest.ts
4104
+ var KERNEL_TABLE_CONTRACTS = [
4105
+ schemaEnumConfig,
4106
+ agentMessages,
4107
+ agentSessions,
4108
+ beliefVotes,
4109
+ calibrationScores,
4110
+ decisionComputedSummaries,
4111
+ decisionEvents,
4112
+ decisionParticipants,
4113
+ decisionRiskLedger,
4114
+ decisionSnapshots,
4115
+ deliberationContributions,
4116
+ deliberationSessions,
4117
+ stakeholderGroups,
4118
+ epistemicNodeEmbeddings,
4119
+ beliefConfidence,
4120
+ beliefEvidenceLinks,
4121
+ beliefHistory,
4122
+ beliefScenarios,
4123
+ contractEvaluations,
4124
+ contradictions,
4125
+ epistemicAudit,
4126
+ epistemicContracts,
4127
+ questionEvidenceLinks,
4128
+ idempotencyTokens,
4129
+ autofixJobs,
4130
+ backgroundJobRuns,
4131
+ backgroundJobSettings,
4132
+ systemLogs,
4133
+ crossProjectConnections,
4134
+ graphAnalysisCache,
4135
+ graphAnalysisResults,
4136
+ graphSuggestions,
4137
+ lenses,
4138
+ lensTopicBindings,
4139
+ ontologyDefinitions,
4140
+ ontologyVersions,
4141
+ harnessReplays,
4142
+ harnessRuns,
4143
+ platformAgentRunPolicyDecisions,
4144
+ platformAgentRunPromptResolutions,
4145
+ platformAgentRuns,
4146
+ platformAgentRunToolCalls,
4147
+ platformHarnessShadowAudit,
4148
+ publicationRules,
4149
+ researchJobs,
4150
+ epistemicEdges,
4151
+ epistemicNodes,
4152
+ tasks,
4153
+ topics,
4154
+ workflowDefinitions,
4155
+ workflowPullRequests,
4156
+ workflowStages,
4157
+ worktreeBeliefCluster,
4158
+ worktrees
4159
+ ];
4160
+ var IDENTITY_TABLE_CONTRACTS = [
4161
+ agents,
4162
+ reasoningPermissions,
4163
+ modelCallLogs,
4164
+ modelFunctionSlots,
4165
+ modelRegistry,
4166
+ modelSlotConfigs,
4167
+ mcpWritePolicy,
4168
+ platformAudienceGrants,
4169
+ platformAudiences,
4170
+ platformPolicyDecisionLogs,
4171
+ tenantApiKeys,
4172
+ tenantConfig,
4173
+ tenantIntegrations,
4174
+ tenantModelSlotBindings,
4175
+ tenantPolicies,
4176
+ tenantProviderSecrets,
4177
+ tenantProxyGatewayUsage,
4178
+ tenantProxyTokenMints,
4179
+ tenantSandboxAuditEvents,
4180
+ tenantSecrets,
4181
+ toolAcls,
4182
+ toolRegistry,
4183
+ projectGrants,
4184
+ users
4185
+ ];
4186
+ var MC_TABLE_CONTRACTS = [
4187
+ groupMemberships,
4188
+ groups,
4189
+ memberships,
4190
+ principals,
4191
+ rateLimitWindows,
4192
+ servicePrincipalKeys,
4193
+ userSessions,
4194
+ methodologyPacks,
4195
+ tenantMethodologyAssignments,
4196
+ packAssignments,
4197
+ packDefinitions,
4198
+ packEntitlements,
4199
+ packGroupAssignments,
4200
+ packInstallations,
4201
+ packVersions,
4202
+ policyBundles,
4203
+ policyDecisionLogs,
4204
+ policySimulations,
4205
+ controlPlaneToolAcls,
4206
+ agentRegistryEntries,
4207
+ toolCatalog,
4208
+ toolRegistryEntries,
4209
+ compatibilityShims,
4210
+ cutoverFlags,
4211
+ tenantDeploymentCredentials,
4212
+ controlPlaneTenantModelSlotBindings,
4213
+ controlPlaneTenantProviderSecrets,
4214
+ controlPlaneTenantProxyGatewayUsage,
4215
+ apiKeys,
4216
+ auditLog,
4217
+ tenants,
4218
+ workspaces
4219
+ ];
4220
+ var TABLE_CONTRACTS_BY_COMPONENT = {
4221
+ kernel: KERNEL_TABLE_CONTRACTS,
4222
+ identity: IDENTITY_TABLE_CONTRACTS,
4223
+ mc: MC_TABLE_CONTRACTS,
4224
+ "developer-pack": []
4225
+ };
4226
+ var ALL_TABLE_CONTRACTS = [
4227
+ ...KERNEL_TABLE_CONTRACTS,
4228
+ ...IDENTITY_TABLE_CONTRACTS,
4229
+ ...MC_TABLE_CONTRACTS
4230
+ ];
4231
+ function listTableContractsByName(name) {
4232
+ return ALL_TABLE_CONTRACTS.filter((contract) => contract.name === name);
4233
+ }
4234
+ function getTableContract(name, component) {
4235
+ return ALL_TABLE_CONTRACTS.find(
4236
+ (contract) => contract.name === name && (component ? contract.component === component : true)
4237
+ );
4238
+ }
4239
+
4240
+ export { ALL_TABLE_CONTRACTS, IDENTITY_TABLE_CONTRACTS, KERNEL_TABLE_CONTRACTS, MC_TABLE_CONTRACTS, TABLE_CONTRACTS_BY_COMPONENT, getTableContract, listTableContractsByName };
4241
+ //# sourceMappingURL=manifest.js.map
4242
+ //# sourceMappingURL=manifest.js.map