@lucern/contracts 0.1.2-alpha.5 → 0.3.0-alpha.1

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