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

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